!
!  Purpose: Test the SET intrinsic
!   Author: Mike King, J. Czechowski IV
!  Version: $Id: test_set.mm,v 1.5 2007/10/24 01:08:57 jxc Exp $
!------------------------------------------------------------------------------ 
startmacro
  call basic_tests
  call set_object_values
  call test_auto_set_mode
endmacro

procedure basic_tests
  set s:foo "Bar"
  assert/text="SET: Mixed-case String" foo eqs "Bar"
  
  set s:foo "BAR"
  assert/text="SET: Upper-case String" foo eqs "BAR"

  set s:foo "bar"
  assert/text="SET: Lower-case String" foo eqs "bar"

  set u:foo "bar"
  assert/text="SET: Untranslated String" foo eqs "bar"

  set B:bignegbyte -128
  assert/text="SET: Byte (max. negative byte value)"  bignegbyte eqt -128

  set B:bigposbyte 127
  assert/text="SET: Byte (max. positive byte value)"  bigposbyte eqt 127

  set I:maxnegint -32768
  assert/text="SET: Integer (max. negative integer value)" maxnegint eqt -32768

  set I:maxposint 32767
  assert/text="SET: Integer (max. positive integer value)" maxposint eqt 32767

  set L:bigneglong -2147483647
  assert/text="SET: Long (max. negative long value)" bigneglong eqt -2147483647

  set L:bigposlong 2147483647
  assert/text="SET: Long (max. positive long value)" bigposlong eqt 2147483647

  set F:bignegfloat -3.4028235E+38
  assert/text="SET: Float (max. negative float value)"  bignegfloat eqt -3.4028235E+38

  set F:bigposfloat 3.4028235E+38
  assert/text="SET: Float (max. positive float value)"  bigposfloat eqt 3.4028235E+38

  set D:bignegdouble -1.7976931348623157E+108
  assert/text="SET: Double (max. negative double value)"  bignegdouble eqt -1.7976931348623157E+108

  set D:bigposdouble 1.7976931348623157E+108
  assert/text="SET: Double (max. positive double value)"  bigposdouble eqt 1.7976931348623157E+108
return

! Tests setting of object values, these tests are similar to the examples in the
! explain file.
procedure set_object_values
  new nxm.sys.test.test_set obj
  
  assert/text="SET: initial value of A=''" "" eqs obj.a
  assert/text="SET: initial value of B=''" "" eqs obj.b
  
  set obj.a "ONE"
  set obj.b "ONE"
  assert/text="SET: set obj.a 'ONE' -> obj.a" "ONE" eqs obj.a
  assert/text="SET: set obj.b 'ONE' -> obj.b" "ONE" eqs obj.b

  set obj.a("TWO")
  set obj.b("TWO")
  assert/text="SET: set obj.a('TWO') -> obj.a" "TWO" eqs obj.a
  assert/text="SET: set obj.b('TWO') -> obj.b" "TWO" eqs obj.b

  set obj.ab("A1") "B1"
  assert/text="SET: set obj.ab('A1') 'B1' -> obj.a" "A1" eqs obj.a
  assert/text="SET: set obj.ab('A1') 'B1' -> obj.b" "B1" eqs obj.b

  set obj.ab("A2","B2")
  assert/text="SET: set obj.ab('A2','B2') -> obj.a" "A2" eqs obj.a
  assert/text="SET: set obj.ab('A2','B2') -> obj.b" "B2" eqs obj.b
return


! Tests the automatic mode conversions. This tests a feature present in NXM 2.4.2
! and earlier where 1..4 element array was automatically set to mode=S/C/V/D. This
! test varifies that the fix for Bug 1154 does not break the old functionality.
procedure test_auto_set_mode
  foreach type inlist "D,F,X,L,I,B"
    set ^{type}:temp (1)
    assert/text="^reg.main.name: Check mode for  1-element array (^{type}:)" temp.format eqs "S^{type}"
    set ^{type}:temp (1,2)
    assert/text="^reg.main.name: Check mode for  2-element array (^{type}:)" temp.format eqs "C^{type}"
    set ^{type}:temp (1,2,3)
    assert/text="^reg.main.name: Check mode for  3-element array (^{type}:)" temp.format eqs "V^{type}"
    set ^{type}:temp (1,2,3,4)
    assert/text="^reg.main.name: Check mode for  4-element array (^{type}:)" temp.format eqs "Q^{type}"
  endfor
return
