!
! Macro to test "RESULTS" intrinsic Strings and tables using escape characters
!
startmacro 

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!! NOTE: This test case needs to be either called from test_results.mm or have the 
!!!       ENV IOOPTION to enable escape sequences (which is done in test_results.mm.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE
  switch BASELINE    baseline GET DEF=FALSE SDEF=TRUE
  switch "DEBUG" dbg GET DEF=1


  RESULTS s:str1 "[A]\n[B]"
  assert/text="^reg.main.name: Results with escape Strings: " str1.length eq 7

  ! Start Interactive test section to verify RESULTS output
  if interAct then
  
    res inst " 1. Each string in the shellgui should be displayed as it describes itself. &
               \n\n 2. Type in several escape codes below in the Unicode format (\\u + 4 hex digits) &
               (e.g. \\u0128) and observe the translation. Some examples: \n &
               \t \\u0128    ===>  \u0128 \n &
               \t \\u00ff    ===>  \u00ff \n &
               \t \\u0067    ===>  \u0067 \n\n &
               Note 1: Many Unicode escapes have no printable character.\n &
               Note 2: You will not see the escapes unless this test was called from test_results.mm."

    pipe on
      panel/msgid=MAIN/setup/controls=gc
      gcontrol label macro "MACRO"
      gcontrol menu main "Exit with Status = " "PASS,FAIL" /tleft
      set gc.main.itemColors {PASS=GREEN,FAIL=RED}
      gcontrol text idtext "Instructions" "^inst" 24 15 /title
      
      gcontrol label lbl1 "Enter \\u+4 hex digits code below"
      gcontrol prompt hexcode "Code: "  ""
      gcontrol prompt showRes "Translation: " "" /noedit

      shellgui/id=idshellgui/attach
      say ""
      say " You should see a string with a newline between [A] & [B]."
      res str1
      
      say ""
      say "You should see a string with a plus-minus sign between [A] & [B]."
      RESULTS s:str2 "[A]\u00B1[B]"
      res str2
      
    pipe off
   
  endif
  ! End Interactive test section
  
  
endmacro

!******************************************************************************!
! process messages for interactive tests
procedure processMessage m:msg
  !say "msg.name ^msg.name, data ^msg.data"

  if msg.name eqs "MAIN" then
    assert/text="^reg.main.name: Results with escape Strings: " msg.data eqss "PASS"
    pipe stop
  elseif msg.name eqs "HEXCODE" then
    set s:daCode gc.hexcode.value
    invoke s:converted nxm.sys.lib.StringUtil.unescapeString(daCode)
    set gc.showRes.value converted
  else
    say "^reg.main.name: Unhandled message name: ^msg.name from fid: ^msg.fid data: ^msg.data"
  endif
return