!******************************************************************************!
! Test initialization with ENDDO
!
! 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 forTable {X=1,Y=2,Z=3}
  foreach key intable forTable
    set sum 0
    do count 1 ^forTable.^key 1
      call incrementSum ^forTable.^key
    enddo

    calc expected ^forTable.^key ^forTable.^key *
    assert/text="^reg.main.name: top is valid because IN is untranslated: for key ^key=^forTable.^key, &
                  its square is ^expected" ^sum eq ^expected
  endfor
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 incrementSum D:num
  calc sum sum num +
return
