$ Test program for Aprepro
$
Test number representations
{1}	{10e-1}	{10.e-1}	{.1e+1}	{.1e1}
{1}	{10E-1}	{10.E-1}	{.1E+1}	{.1E1}
	
Test assign statements:
{_a = 5}	{b=_a}	$ Should print 5 5
{_a +=b}	{_a} 	$ Should print 10 10
{_a -=b}	{_a}	$ Should print 5 5
{_a *=b}	{_a}	$ Should print 25 25
{_a /=b}	{_a}	$ Should print 5 5
{_a ^=b}	{_a}	$ Should print 3125 3125
{_a = b}	{_a**=b}	{_a}	$ Should print 5 3125 3125

Test trigonometric functions (radians)
{pi = d2r(180)} {atan2(0,-1)} {4*atan(1.0)} $ Three values of pi
{_a = sin(pi/4)}	{pi-4*asin(_a)}	$ sin(pi/4)
{_b = cos(pi/4)}	{pi-4*acos(_b)}	$ cos(pi/4)
{_c = tan(pi/4)}	{pi-4*atan(_c)}	$ tan(pi/4)

Test trigonometric functions (degrees)
{r2d(pi)}	{pid = atan2d(0,-1)}	{4 * atand(1.0)}
{ad = sind(180/4)}	{180-4*asind(ad)}	$ sin(180/4)
{bd = cosd(180/4)}	{180-4*acosd(bd)}	$ cos(180/4)
{cd = tand(180/4)}	{180-4*atand(cd)}	$ tan(180/4)

Test max, min, sign, dim, abs
{pmin = min(0.5, 1.0)}	{nmin = min(-0.5, -1.0)} $ Should be 0.5, -1
{pmax = max(0.5, 1.0)}	{nmax = max(-0.5, -1.0)} $ Should be 1.0, -0.5
{zero = 0} {sign(0.5, zero) + sign(0.5, -zero)}	$ Should be 0 1
{nonzero = 1} {sign(0.5, nonzero) + sign(0.5, -nonzero)} $ Should be 1 0
{dim(5.5, 4.5)}	{dim(4.5, 5.5)}	$ Should be 1 0

{ifyes = 1} {ifno = 0}
$ Test ternary...
{ifyes == 1 ? "correct" : "incorrect"}
{ifno == 1 ? "incorrect" : "correct"}

$ Test ifdef lines
	{Ifdef(ifyes)}
This line should be echoed. (a)
 {Endif}
This line should be echoed. (b)
     {Ifdef(ifno)}
This line should not be echoed
 	 {Endif}
This line should be echoed. (c)
  {Ifdef(ifundefined)}
This line should not be echoed
        {Endif}
This line should be echoed. (d)

$ Test ifdef - else lines
             {Ifdef(ifyes)}
This line should be echoed. (1)
			{Else}
This line should not be echoed (2)
	{Endif}
		{Ifdef(ifno)}
This line should not be echoed. (3)
 {Else}
This line should be echoed (4)
   {Endif}

$ Test ifndef - else lines
 {Ifndef(ifyes)}
This line should not be echoed. (5)
  {Else}
This line should be echoed (6)
   {Endif}
    {Ifndef(ifno)}
This line should be echoed. (7)
 {Else}
This line should not be echoed (8)
  {Endif}
$ Lines a, b, c, d, 1, 4, 6, 7 should be echoed
$ Check line counting -- should be on line 78: {Parse Error}
{ifdef(ifyes)} {This should be an error}
{endif}

$ ========================================================================
$ Test string if lines
{if("Greg")}
 This line should be echoed ("greg")
{else}
 This line should not be echoed ("greg")
{endif}

{empty=""}
{if(empty)}
 This line should not be echoed (empty)
{else}
 This line should be echoed (empty)
{endif}


$ ========================================================================
$ Test if lines
{if(sqrt(4) == 2)}
  This line should be echoed. (a)
{endif}
  This line should be echoed. (b)
{if(sqrt(2) == 2 || sqrt(3) == 2)}
 This line should not be echoed
{endif}
This line should be echoed. (c)

{diff = sqrt(3)*sqrt(3) - 3}
$ Test if - else lines
{if(sqrt(3)*sqrt(3) - 3 == diff)}
 complex if works
{else}
 complex if does not work
{endif}

{if (sqrt(4) == 2)}
 {if (sqrt(9) == 3)}
  {if (sqrt(16) == 4)}
    square roots work
  {else}
    sqrt(16) does not work
  {endif}
 {else}
   sqrt(9) does not work
 {endif}
{else}
  sqrt(4) does not work
{endif}

{v1 = 1} {v2 = 2}
{if (v1 == v2)}
  Bad if
  {if (v1 != v2)}
   should not see (1)
  {else}
   should not see (2)
  {endif}
   should not see (3)
{else}
  {if (v1 != v2)}
   good nested if
  {else}
   bad nested if
  {endif}
  good
  make sure it is still good
{endif}
$ ========================================================================
$ Test switch
{switch(PI)}
This is in a switch, but prior to any case, it should not run
{a = 0.5} Should not execute

{case (1)}
This should not echo
{a = 1}

{case (2)}
This should not echo
{a = 2}

{case (PI)}
This should echo
{a = PI}

{case (PI)}
This should not echo since a previous case matched.
{a = 2}

{default}
{a=4}

{endswitch}

This should be equal to PI --  {PI}
$ Test int and [] (shortcut for int)
{int(5.01)}	{int(-5.01)}
{[5.01]}	{[-5.01]}

$ Test looping - print sin, cos from 0 to 90 by 5
{_angle = -5}
{Loop(19)}
{_angle += 5}	{_sa=sind(_angle)}	{_ca=cosd(_angle)} {hypot(_sa, _ca)} 
{EndLoop}

$$$$ Test formatting and string concatenation
{_i = 0} {_SAVE = _FORMAT}
{loop(20)}
{IO(++_i)} Using the format {_FORMAT = "%." // tostring(_i) // "g"},	PI = {PI}
{endloop}
Reset format to default: {_FORMAT = _SAVE}

$$$$ Test string rescanning and executing
{ECHO(OFF)}
{Test = '	This is line 1: {a = atan2(0,-1)}
        This is line 2: {sin(a/4)}
	This is line 3: {cos(a/4)}'}
{Test2 = 'This has an embedded string: {T = "This is a string"}'}
{ECHO(ON)}
Original String:
{Test}
Rescanned String:
{rescan(Test)} 
Original String:
{Test2}
Print Value of variable T = {T}
Rescanned String:
{rescan(Test2)} 
Print Value of variable T = {T}

Original String: {t1 = "atan2(0,-1)"}
Executed String: {execute(t1)}

string = {_string = " one two, three"}
delimiter "{_delm = " ,"}"
word count = {word_count(_string,_delm)}
second word = "{get_word(2,_string,_delm)}"

string = {_string = " (one two, three * four - five"}
delimiter "{_delm = " ,(*-"}"
word count = {word_count(_string,_delm)}
second word = "{get_word(2,_string,_delm)}"


string = {_string = " one two, three"}
delimiter "{_delm = " ,"}"
word count = { iwords = word_count(_string,_delm)}

{_n = 0}
	{loop(iwords)}
word {++_n} = "{get_word(_n,_string,_delm)}"
   {endloop}

$ Check parsing of escaped braces...
\{ int a = b + {PI/2} \}
\{ \}

$ Test variable deletion
{new_var = sqrt(2) * sqrt(3)}
{new_var}
{delete("new_var")}
{new_var}  This should print warning about undefined variable

$ Test extract
{ex_found = extract("The test string is found", "test", "")}
{ex_null  = extract("The test string is not found", "xxxx", "yyyy")}

$ Test string tokenization optimization
{_i=1}
{list1 ='51,52,53,54,61,62,63,64'}
{list2 ='71,72,73,74,81,82,83,84'}
{loop(8)}
Word {_i} of list1 and list2 are {get_word(_i,list1,',')} and {get_word(_i++,list2,',')}
{endloop}

$End of test file
