| 1 |
$ Test program for Aprepro |
| 2 |
$ |
| 3 |
Test number representations |
| 4 |
{1} {10e-1} {10.e-1} {.1e+1} {.1e1} |
| 5 |
{1} {10E-1} {10.E-1} {.1E+1} {.1E1} |
| 6 |
|
| 7 |
Test assign statements: |
| 8 |
{_a = 5} {b=_a} $ Should print 5 5 |
| 9 |
{_a +=b} {_a} $ Should print 10 10 |
| 10 |
{_a -=b} {_a} $ Should print 5 5 |
| 11 |
{_a *=b} {_a} $ Should print 25 25 |
| 12 |
{_a /=b} {_a} $ Should print 5 5 |
| 13 |
{_a ^=b} {_a} $ Should print 3125 3125 |
| 14 |
{_a = b} {_a**=b} {_a} $ Should print 5 3125 3125 |
| 15 |
|
| 16 |
Test trigonometric functions (radians) |
| 17 |
{pi = d2r(180)} {atan2(0,-1)} {4*atan(1.0)} $ Three values of pi |
| 18 |
{_a = sin(pi/4)} {pi-4*asin(_a)} $ sin(pi/4) |
| 19 |
{_b = cos(pi/4)} {pi-4*acos(_b)} $ cos(pi/4) |
| 20 |
{_c = tan(pi/4)} {pi-4*atan(_c)} $ tan(pi/4) |
| 21 |
|
| 22 |
Test trigonometric functions (degrees) |
| 23 |
{r2d(pi)} {pid = atan2d(0,-1)} {4 * atand(1.0)} |
| 24 |
{ad = sind(180/4)} {180-4*asind(ad)} $ sin(180/4) |
| 25 |
{bd = cosd(180/4)} {180-4*acosd(bd)} $ cos(180/4) |
| 26 |
{cd = tand(180/4)} {180-4*atand(cd)} $ tan(180/4) |
| 27 |
|
| 28 |
Test max, min, sign, dim, abs |
| 29 |
{pmin = min(0.5, 1.0)} {nmin = min(-0.5, -1.0)} $ Should be 0.5, -1 |
| 30 |
{pmax = max(0.5, 1.0)} {nmax = max(-0.5, -1.0)} $ Should be 1.0, -0.5 |
| 31 |
{zero = 0} {sign(0.5, zero) + sign(0.5, -zero)} $ Should be 0 1 |
| 32 |
{nonzero = 1} {sign(0.5, nonzero) + sign(0.5, -nonzero)} $ Should be 1 0 |
| 33 |
{dim(5.5, 4.5)} {dim(4.5, 5.5)} $ Should be 1 0 |
| 34 |
|
| 35 |
{ifyes = 1} {ifno = 0} |
| 36 |
$ Test ternary... |
| 37 |
{ifyes == 1 ? "correct" : "incorrect"} |
| 38 |
{ifno == 1 ? "incorrect" : "correct"} |
| 39 |
|
| 40 |
$ Test ifdef lines |
| 41 |
{Ifdef(ifyes)} |
| 42 |
This line should be echoed. (a) |
| 43 |
{Endif} |
| 44 |
This line should be echoed. (b) |
| 45 |
{Ifdef(ifno)} |
| 46 |
This line should not be echoed |
| 47 |
{Endif} |
| 48 |
This line should be echoed. (c) |
| 49 |
{Ifdef(ifundefined)} |
| 50 |
This line should not be echoed |
| 51 |
{Endif} |
| 52 |
This line should be echoed. (d) |
| 53 |
|
| 54 |
$ Test ifdef - else lines |
| 55 |
{Ifdef(ifyes)} |
| 56 |
This line should be echoed. (1) |
| 57 |
{Else} |
| 58 |
This line should not be echoed (2) |
| 59 |
{Endif} |
| 60 |
{Ifdef(ifno)} |
| 61 |
This line should not be echoed. (3) |
| 62 |
{Else} |
| 63 |
This line should be echoed (4) |
| 64 |
{Endif} |
| 65 |
|
| 66 |
$ Test ifndef - else lines |
| 67 |
{Ifndef(ifyes)} |
| 68 |
This line should not be echoed. (5) |
| 69 |
{Else} |
| 70 |
This line should be echoed (6) |
| 71 |
{Endif} |
| 72 |
{Ifndef(ifno)} |
| 73 |
This line should be echoed. (7) |
| 74 |
{Else} |
| 75 |
This line should not be echoed (8) |
| 76 |
{Endif} |
| 77 |
$ Lines a, b, c, d, 1, 4, 6, 7 should be echoed |
| 78 |
$ Check line counting -- should be on line 78: {Parse Error} |
| 79 |
{ifdef(ifyes)} {This should be an error} |
| 80 |
{endif} |
| 81 |
|
| 82 |
$ ======================================================================== |
| 83 |
$ Test string if lines |
| 84 |
{if("Greg")} |
| 85 |
This line should be echoed ("greg") |
| 86 |
{else} |
| 87 |
This line should not be echoed ("greg") |
| 88 |
{endif} |
| 89 |
|
| 90 |
{empty=""} |
| 91 |
{if(empty)} |
| 92 |
This line should not be echoed (empty) |
| 93 |
{else} |
| 94 |
This line should be echoed (empty) |
| 95 |
{endif} |
| 96 |
|
| 97 |
|
| 98 |
$ ======================================================================== |
| 99 |
$ Test if lines |
| 100 |
{if(sqrt(4) == 2)} |
| 101 |
This line should be echoed. (a) |
| 102 |
{endif} |
| 103 |
This line should be echoed. (b) |
| 104 |
{if(sqrt(2) == 2 || sqrt(3) == 2)} |
| 105 |
This line should not be echoed |
| 106 |
{endif} |
| 107 |
This line should be echoed. (c) |
| 108 |
|
| 109 |
{diff = sqrt(3)*sqrt(3) - 3} |
| 110 |
$ Test if - else lines |
| 111 |
{if(sqrt(3)*sqrt(3) - 3 == diff)} |
| 112 |
complex if works |
| 113 |
{else} |
| 114 |
complex if does not work |
| 115 |
{endif} |
| 116 |
|
| 117 |
{if (sqrt(4) == 2)} |
| 118 |
{if (sqrt(9) == 3)} |
| 119 |
{if (sqrt(16) == 4)} |
| 120 |
square roots work |
| 121 |
{else} |
| 122 |
sqrt(16) does not work |
| 123 |
{endif} |
| 124 |
{else} |
| 125 |
sqrt(9) does not work |
| 126 |
{endif} |
| 127 |
{else} |
| 128 |
sqrt(4) does not work |
| 129 |
{endif} |
| 130 |
|
| 131 |
{v1 = 1} {v2 = 2} |
| 132 |
{if (v1 == v2)} |
| 133 |
Bad if |
| 134 |
{if (v1 != v2)} |
| 135 |
should not see (1) |
| 136 |
{else} |
| 137 |
should not see (2) |
| 138 |
{endif} |
| 139 |
should not see (3) |
| 140 |
{else} |
| 141 |
{if (v1 != v2)} |
| 142 |
good nested if |
| 143 |
{else} |
| 144 |
bad nested if |
| 145 |
{endif} |
| 146 |
good |
| 147 |
make sure it is still good |
| 148 |
{endif} |
| 149 |
$ ======================================================================== |
| 150 |
$ Test switch |
| 151 |
{switch(PI)} |
| 152 |
This is in a switch, but prior to any case, it should not run |
| 153 |
{a = 0.5} Should not execute |
| 154 |
|
| 155 |
{case (1)} |
| 156 |
This should not echo |
| 157 |
{a = 1} |
| 158 |
|
| 159 |
{case (2)} |
| 160 |
This should not echo |
| 161 |
{a = 2} |
| 162 |
|
| 163 |
{case (PI)} |
| 164 |
This should echo |
| 165 |
{a = PI} |
| 166 |
|
| 167 |
{case (PI)} |
| 168 |
This should not echo since a previous case matched. |
| 169 |
{a = 2} |
| 170 |
|
| 171 |
{default} |
| 172 |
{a=4} |
| 173 |
|
| 174 |
{endswitch} |
| 175 |
|
| 176 |
This should be equal to PI -- {PI} |
| 177 |
$ Test int and [] (shortcut for int) |
| 178 |
{int(5.01)} {int(-5.01)} |
| 179 |
{[5.01]} {[-5.01]} |
| 180 |
|
| 181 |
$ Test looping - print sin, cos from 0 to 90 by 5 |
| 182 |
{Loop(19, _angle, 0, 5)} |
| 183 |
{_angle} {_sa=sind(_angle)} {_ca=cosd(_angle)} {hypot(_sa, _ca)} |
| 184 |
{EndLoop} |
| 185 |
|
| 186 |
$$$$ Test formatting and string concatenation |
| 187 |
{_SAVE = _FORMAT} |
| 188 |
{loop(20)} |
| 189 |
{IO(__loop_1+1)} Using the format {_FORMAT = "%." // tostring(__loop_1+1) // "g"}, PI = {PI} |
| 190 |
{endloop} |
| 191 |
Reset format to default: {_FORMAT = _SAVE} |
| 192 |
|
| 193 |
$$$$ Test string rescanning and executing |
| 194 |
{ECHO(OFF)} |
| 195 |
{Test = ' This is line 1: {a = atan2(0,-1)} |
| 196 |
This is line 2: {sin(a/4)} |
| 197 |
This is line 3: {cos(a/4)}'} |
| 198 |
{Test2 = 'This has an embedded string: {T = "This is a string"}'} |
| 199 |
{ECHO(ON)} |
| 200 |
Original String: |
| 201 |
{Test} |
| 202 |
Rescanned String: |
| 203 |
{rescan(Test)} |
| 204 |
Original String: |
| 205 |
{Test2} |
| 206 |
Print Value of variable T = {T} |
| 207 |
Rescanned String: |
| 208 |
{rescan(Test2)} |
| 209 |
Print Value of variable T = {T} |
| 210 |
|
| 211 |
Original String: {t1 = "atan2(0,-1)"} |
| 212 |
Executed String: {execute(t1)} |
| 213 |
|
| 214 |
string = {_string = " one two, three"} |
| 215 |
delimiter "{_delm = " ,"}" |
| 216 |
word count = {word_count(_string,_delm)} |
| 217 |
second word = "{get_word(2,_string,_delm)}" |
| 218 |
|
| 219 |
string = {_string = " (one two, three * four - five"} |
| 220 |
delimiter "{_delm = " ,(*-"}" |
| 221 |
word count = {word_count(_string,_delm)} |
| 222 |
second word = "{get_word(2,_string,_delm)}" |
| 223 |
|
| 224 |
|
| 225 |
string = {_string = " one two, three"} |
| 226 |
delimiter "{_delm = " ,"}" |
| 227 |
word count = { iwords = word_count(_string,_delm)} |
| 228 |
|
| 229 |
{loop(iwords, _n, 1)} |
| 230 |
word {_n} = "{get_word(_n,_string,_delm)}" |
| 231 |
{endloop} |
| 232 |
|
| 233 |
$ Check parsing of escaped braces... |
| 234 |
\{ int a = b + {PI/2} \} |
| 235 |
\{ \} |
| 236 |
|
| 237 |
$ Test variable deletion |
| 238 |
{new_var = sqrt(2) * sqrt(3)} |
| 239 |
{new_var} |
| 240 |
{delete("new_var")} |
| 241 |
{new_var} This should print warning about undefined variable |
| 242 |
|
| 243 |
$ Test extract |
| 244 |
{ex_found = extract("The test string is found", "test", "")} |
| 245 |
{ex_null = extract("The test string is not found", "xxxx", "yyyy")} |
| 246 |
|
| 247 |
$ Test string tokenization optimization |
| 248 |
{list1 ='51,52,53,54,61,62,63,64'} |
| 249 |
{list2 ='71,72,73,74,81,82,83,84'} |
| 250 |
{loop(8, _i, 1)} |
| 251 |
Word {_i} of list1 and list2 are {get_word(_i,list1,',')} and {get_word(_i,list2,',')} |
| 252 |
{endloop} |
| 253 |
|
| 254 |
$End of test file |