! Tests the use of WildCard (*) when listing the keywords from a file. Most
! of these tests are related to either Bug 1478 (Pattern matching in keyword
! list) or Bug 2692 (Add option to list sorted).
!
! @author  J. Czechowski IV / Jim Roush
! @since   NeXtMidas 2.7.0
!
startmacro
  switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE
  switch BASELINE    baseline GET DEF=FALSE SDEF=TRUE

  header/create ram:test_file
  key ram:test_file  SET I:IKEY 1
  key ram:test_file  SET L:LKEY 100000
  key ram:test_file  SET D:DKEY 99.0
  key ram:test_file  SET A:AKEY "ASCII_TEXT"
  key ram:test_file  SET S:SKEY "STRING_TEXT"


  header/create ram:many_keys
  key ram:many_keys  SET I:IKEY 1

  do i 13 15
    key ram:many_keys SET D:VAL^{i} i
  enddo
  key ram:many_keys  SET S:SKEY "STRING_TEXT"
  do i 0 5
    key ram:many_keys SET D:VAL^{i} i
  enddo
  key ram:many_keys  SET A:AKEY "ASCII_TEXT"
  do i 12 6 -1
    key ram:many_keys SET D:VAL^{i} i
  enddo
  key ram:many_keys  SET L:LKEY 100000
  key ram:many_keys  SET D:DKEY 99.0


  res testCases {}

  res testCases.LIST1 {CMD="KEYWORD ram:test_file LIST",&
                      INST="Should see a listing with all of the keywords &
                            from both the main and the extended header."}

  res testCases.LIST2 {CMD="KEYWORD ram:test_file LIST CREATOR",&
                      INST="Should see a listing that includes the 'CREATOR' &
                            keyword."}

  res testCases.LIST3 {CMD="KEYWORD ram:test_file LIST D*",&
                      INST="Should see a listing with keywords that start &
                            with 'D'."}

  res testCases.LIST4 {CMD="KEYWORD ram:test_file LIST *E*",&
                      INST="Should see a listing with keywords contain an 'E' &
                            in them."}

  res testCases.LIST5 {CMD="KEYWORD ram:test_file LIST *R",&
                      INST="Should see a listing with keywords that end &
                            with 'R'."}

  res testCases.LIST6 {CMD="KEYWORD ram:test_file LIST *E?",&
                      INST="Should see a listing with keywords that have an &
                            'E' *before* the last character."}

  res testCases.LIST7 {CMD="KEYWORD ram:test_file LIST ??E*",&
                      INST="Should see a listing with keywords that have an &
                            'E' as the third character."}

  res testCases.SORT1 {CMD="KEYWORD ram:many_keys LIST",&
                      INST="Should see a listing with many keywords. They &
                            should *not* be in alphabetical order."}

  res testCases.SORT2 {CMD="KEYWORD ram:many_keys LIST/S",&
                      INST="Should see a listing with many keywords. They &
                            should be in alphabetical order. Note that &
                            the VAL* keywords should be ordered &
                            VAL0,..,VAL9, VAL10,VAL11,..,VAL15. (Note that &
                            MAIN and EXTENDED header keywords are sorted &
                            independently.)"}

  if interAct then
    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" "Click on one of the tests..." 24 16 /title

      
      table testCases GETKEYS/S testNames
      gcontrol menu testid "Test files to STATUS" "^testNames"  /nc=1
      shellgui/id=idshellgui/attach
    pipe off
  endif
endmacro

!**************************************************************************************************!
procedure processMessage m:msg
  !say "msg.name ^msg.name, data ^msg.data"

  if (msg.name EQS "MAIN") then
    assert/text="^reg.main.name: Interactive tests for STATUS" msg.data eqs "PASS"
    pipe stop

  elseif (msg.name EQS "TESTID") then
    ! clear text in SHELLGUI before next test case
    message func=sendx id=idshellgui name="CLEAR"

    res testCase testCases.^{msg.data}

    res gc.idtext.value testCase.inst

    say "nM> ^{testCase.CMD}"
    run testCase.CMD

  else
    say "^reg.main.name: Unhandled message name: ^msg.name from fid: ^msg.fid data: ^msg.data"
  endif
return
