!******************************************************************************!
! Test initialization with ENDFOR
!
! Arguments: None
!
! @bug      NXM-3619 Intrinsic Initialization
! @author:  Zachary Matthews
! @since    NeXtMidas 3.9.4
!******************************************************************************!
startmacro
  switch INTERACTIVE interAct GET DEF=FALSE  SDEF=TRUE  ! for normal interactive test(s)
  switch BASELINE    baseline GET DEF=FALSE SDEF=TRUE  ! for defects or more obscure test case(s)

  set forTable1 {X=1,Y=2,Z=3}
  set forTable2 {A=1,B=2,C=3}
  set forTable3 {HI=1,HELLO=2,BYE=3}

  do count 1 3 1
    foreach key intable forTable^count
      call setValidKeys
    endfor
  enddo
endmacro

!******************************************************************************!
! Main process message for this macro. Should be right after the ENDMACRO.
!******************************************************************************!
procedure processMessage m:msg
  if msg.name eqs "MAIN" then
    assert/text="^reg.main.name: User indicated tests" msg.data eqss "PASS"
    pipe stop
  else
    say "Unhandled message name: ^msg.name from fid: ^msg.fid data: ^msg.data"
  endif
return

!******************************************************************************!
! If an unexpected exception is caught, mark test as failed, unless it is expected
!******************************************************************************!
procedure processException m:emsg
  if expectedException REXISTS then
    assert/text="^reg.main.name: Expected ERROR starts with: ^{expectedException}" expectedException EQSS emsg.data.message
    remove expectedException
  else
    assert/text="^reg.main.name: Caught unexpected exception ^{emsg.data}" "FALSE" isTrue
    if "Trace" SUBS ENV.DEBUG then invoke ,, emsg.data.printStackTrace()
  endif
return

procedure setValidKeys
  if count eq 1 then
    if key EQS X or KEY EQS Y or KEY EQS Z then
      res Z:validkeys true
    else
      res Z:validkeys false
    endif
    assert/text="^reg.main.name: top is valid because IN is untranslated loop ^count" validKeys ISTRUE
  elseif count eq 2 then
    if key EQS A or KEY EQS B or KEY EQS C then
      res Z:validkeys true
    else
      res Z:validkeys false
    endif
    assert/text="^reg.main.name: top is valid because IN is untranslated loop ^count" validKeys ISTRUE
  elseif count eq 3 then
    if key EQS HI or KEY EQS HELLO or KEY EQS BYE then
      res Z:validkeys true
    else
      res Z:validkeys false
    endif
    assert/text="^reg.main.name: top is valid because IN is untranslated: loop ^count key ^key" validKeys ISTRUE
  endif

return
