blob: 42c0e95577394373a586be48adb658e90bb13812 [file] [log] [blame]
Abdullah Alamoudiac683db2016-02-23 00:59:31 +03001/////////////////////////////////
2echo Testing basic math...
3eval x = (1 + 2)
4same $x, 3
5eval x = (3 - 1)
6same $x, 2
7eval x = (2 * 3)
8same $x, 6
9eval x = (8 / 2)
10same $x, 4
11
12echo Testing extreme numbers...
13same string(real("INF")), "real(\"INF\")"
14same string(real("-INF")), "real(\"-INF\")"
15same string(real("NaN")), "real(\"NaN\")"
16diff real("NaN"), real("NaN")
17same real("INF"), real("INF")
18same real("-INF"), real("-INF")
19diff real("INF"), real("-INF")
20same 0.0, -(0.0)
21same 0.0, real("-0.0")
22same string(0.0), "0.0"
23same string(-0.0), "-0.0"
24
25/////////////////////////////////
26echo Testing basic attributes in a ClassAd...
27eval x = [
28 a = 1;
29 b = 2.0;
30 c = "alain";
31 d = true;
32 atime = absTime("2004-01-01");
33 rtime = relTime("2+25:14:16.123");
34 l = {1, 1, 2, 3, 5};
35 e = error;
36 u = undefined;
37 ]
38same $x.a, 1
39same $x.b, 2.0
40same $x.c, "alain"
41same $x.d, true
42same $x.atime, absTime("2004-01-01");
43same $x.rtime, relTime("2+25:14:16.123");
44same $x.l, {1, 1, 2, 3, 5}
45same $x.l[4], 5
46same $x.e, error
47same $x.u, undefined
48same isinteger($x.a), true
49same isinteger($x.b), false
50same isreal($x.b), true
51same isreal($x.c), false
52same isstring($x.c), true
53same isstring($x.d), false
54same isboolean($x.d), true
55same isboolean($x.c), false
56same isabstime($x.atime), true
57same isabstime($x.rtime), false
58same isreltime($x.rtime), true
59same isreltime($x.atime), false
60same islist($x.l), true
61same islist($x.a), false
62same iserror($x.e), true
63same iserror($x.u), false
64same isundefined($x.u), true
65same isundefined($x.e), false
66
67// Note that testing XML relies on the ClassAd from
68// the above testing.
69// echo Testing XML...
70// eval y = [ a = 2; b = "Lisp rocks"; ]
71// writexml tmp.xml {$x, $y}
72// readxml z tmp.xml
73// same $x, $z[0]
74// same $y, $z[1]
75
76/////////////////////////////////
77echo Testing select on lists...
78eval x = {
79 [a = 3; b = "I see London"],
80 [a = 2; b = "I see France"],
81 [a = 1; b = "I see Alain's funky pants"]
82 }
83same $x.a, {3, 2, 1}
84same $x.b, {"I see London", "I see France", "I see Alain's funky pants"}
85same $x.c, {undefined, undefined, undefined}
86same {}.a, {}
87
88/////////////////////////////////
89echo Testing subscripts
90eval x = [
91 a = 3;
92 b = "alain";
93 ab = 4;
94 ]
95same $x["a"], 3
96same $x["b"], "alain"
97same $x["c"], error
98eval d = $x["c"]
99same $x[strcat("a", "b")], 4
100eval x = {"a", "b", "c"}
101same $x[0], "a"
102same $x[1], "b"
103same $x[2], "c"
104same $x[3], error
105
106/////////////////////////////////
107echo Testing multiple semicolons...
108eval x = [
109 ;;
110 a = 3;;
111 b = 4;;
112 ]
113
114/////////////////////////////////
115echo Testing functions...
116same int(3), 3
117same int(3.9), 3
118same int("3.9"), 3
119same int(absTime("1970-01-01T:00:00:01Z")), 1
120same int(reltime("01:00:01")), 3601
121eval y = int(absTime("1970-01-01T:00:00:01Z"))
122same $y, 1
123
124same real(3), 3.0
125same real(3.9), 3.9
126same real("3.9"), 3.9
127same real(absTime("1970-01-01T:00:00:01Z")), 1.0
128same real(reltime("01:00:01")), 3601.0
129
130same string("alain"), "alain"
131same string(1), "1"
132
133same floor(3.9), 3
134same floor("3.9"), 3
135
136same ceiling(3.9), 4
137same ceiling("3.9"), 4
138
139same round(3.1), 3
140same round(3.9), 4
141
142same strcat("", "roy"), "roy"
143same strcat("alain", ""), "alain"
144same strcat("alain", "roy"), "alainroy"
145same strcat(14, " bottles of root beer"), "14 bottles of root beer"
146
147same substr("abcde", 1), "bcde"
148same substr("abcde", 4), "e"
149same substr("abcde", 5), ""
150same substr("abcde", 1, 2), "bc"
151same substr("abcde", 4, 2), "e"
152
153same strcmp("alain", "roy") < 0, true
154same strcmp("roy", "alain") > 0, true
155same strcmp("alain", "alain"), 0
156
157same stricmp("alain", "ALAIN"), 0
158same stricmp("alain", "roy") < 0, true
159
160same tolower("ALAIN"), "alain")
161same toupper("alain"), "ALAIN")
162same tolower(true), "true")
163same toupper(true), "TRUE")
164
165same member(1, {1, 2, 3}), true
166same member(4, {1, 2, 3}), false
167
168same regexp("Alain.*Roy", "Alain Aslag Roy"), true
169same regexp("alain.*roy", "Alain Aslag Roy"), false
170same regexp("alain.*roy", "Alain Aslag Roy", "i"), true
171
172//same regexpMember("b.*", {}), false
173//same regexpMember("b.*", {"aa"}), false
174//same regexpMember("b.*", {"aa", "bb"}), true
175//same regexpMember("b.*", {"bb", "aa"}), true
176//same regexpMember("b.*", {1, "bb"} ), error
177
178
179eval t = absTime("1970-01-02T:03:04:05Z")
180same splitTime($t).year, 1970
181same splitTime($t).month, 1
182same splitTime($t).day, 2
183same splitTime($t).hours, 3
184same splitTime($t).minutes, 4
185same splitTime($t).seconds, 5
186same splitTime($t).offset, 0
187
188
189
190eval t = absTime("1970-01-02T:03:04:05-06:00")
191eval tt = splitTime($t)
192same splitTime($t).year, 1970
193same splitTime($t).month, 1
194same splitTime($t).day, 2
195same splitTime($t).hours, 3
196same splitTime($t).minutes, 4
197same splitTime($t).seconds, 5
198same splitTime($t).offset, -21600
199
200
201
202eval t = relTime("1d2h3m4.5s")
203eval tt = splitTime($t)
204same splitTime($t).days, 1
205same splitTime($t).hours, 2
206same splitTime($t).minutes, 3
207same splittime($t).seconds, 4.5
208eval tt = splitTime($t)
209
210
211eval t = absTime("1997-08-30T16:04:05-0500")
212eval f = formatTime($t, "%m %d %Y")
213same $f, "08 30 1997"
214eval f = formatTime($t, "%H %M %S")
215same $f, "16 04 05"
216eval f = formatTime($t, "%A %a")
217same $f, "Saturday Sat"
218eval f = formatTime($t, "%B %b")
219same $f, "August Aug"
220eval f = formatTime(splitTime($t), "%H:%M:%S")
221same $f, "16:04:05"
222eval f = formatTime($t)
223same $f, "Sat Aug 30 16:04:05 1997"
224
225same size({}), 0
226same size({1}), 1
227same size({1, 2, 3, 4, 5}), 5
228same size([]), 0
229same size([a = 1;]), 1
230same size([a = 1; b = 2;]), 2
231same size(""), 0
232same size("a"), 1
233same size("ab"), 2
234same size(3), error
235same size(3.4), error
236
237eval list0 = {}
238eval list1 = {1}
239eval list5 = {1, 2, 3, 4, 5}
240
241same sum($list0), undefined
242same avg($list0), undefined
243same min($list0), undefined
244same max($list0), undefined
245// #### Do we really want these to be false and true?
246same anycompare("<", $list0, 3), false
247same allcompare("<", $list0, 3), true
248
249same sum($list1), 1
250same avg($list1), 1.0
251same min($list1), 1
252same max($list1), 1
253same anycompare("<", $list1, 3), true
254same allcompare("<", $list1, 3), true
255
256same sum($list5), 15
257same avg($list5), 3.0
258same min($list5), 1
259same max($list5), 5
260same anycompare("<", $list5, 3), true
261same allcompare("<", $list5, 3), false
262
263same ifThenElse(1+1==2, 3, 4), 3
264same ifThenElse(1+1==3,3,4), 4
265same ifThenElse(ERROR,3,4), ERROR
266same ifThenElse(UNDEFINED,3,4), UNDEFINED
267
268same interval(1), "1"
269same interval(60*2 + 1), "2:01"
270same interval(3600*3 + 60*2 + 1), "3:02:01"
271same interval(3600*24*4 + 3600*3 + 60*2 + 1), "4+03:02:01"
272
273//same regexps("[abc]*([def]*)[ghi]*","aaaabbbbcccccdddeeefffggghhhiii","\\1"), "dddeeefff"
274//same regexps("[abc]*([def]*)[ghi]*","abcdefghi","\\0"), "abcdefghi"
275//same regexps("[abc]*([def]*)[ghi]*","abcdefghi","\\2"), error
276//same regexps("[abc]*([def]*)[ghi]*","NO","\\0"), ""
277
278
279echo Testing eval
280same eval("1+1"), 2
281same eval(1+1), 2
282same eval("1+"), ERROR
283eval x = [ A = 1; B = 2; C = eval("A+B"); ]
284same $x.C, 3
285
286echo Testing boolean expressions
287echo Testing && operator
288same false, false && false
289same false, false && undefined
290same false, false && true
291same false, false && error
292
293same false, undefined && false
294same undefined, undefined && undefined
295same undefined, undefined && true
296same error, undefined && error
297
298same false, true && false
299same undefined, true && undefined
300same true, true && true
301same error, true && error
302
303same error, error && false
304same error, error && undefined
305same error, error && true
306same error, error && error
307
308
309echo Testing || operator
310same false, false || false
311same undefined, false || undefined
312same true, false || true
313same error, false || error
314
315same undefined, undefined || false
316same undefined, undefined || undefined
317same true, undefined || true
318same error, undefined || error
319
320same true, true || false
321same true, true || undefined
322same true, true || true
323same true, true || error
324
325same error, error || false
326same error, error || undefined
327same error, error || true
328same error, error || error
329
330
331echo Testing ! operator
332same true, !false
333same undefined, !undefined
334same false, !true
335same error, !error
336
337
338echo Testing ? operator
339same false, false ? true : false
340same true, false ? false : true
341same undefined, false ? true : undefined
342same true, false ? undefined : true
343
344same true, true ? true : false
345same false, true ? false : true
346same true, true ? true : undefined
347same undefined, true ? undefined : true
348
349echo Testing characters with negative ascii values
350// # the following used to not even parse on some systems
351same "–", "–"
352
353echo Testing stringListsIntersect()
354same true, stringListsIntersect("one,two","two,three")
355same false, stringListsIntersect("one,two","three,four")
356same false, stringListsIntersect("one,two","three,four",";")
357same true, stringListsIntersect("one,two","one")
358same true, stringListsIntersect("one, two","two, three")
359same true, stringListsIntersect("one,two","two,three",",")
360same true, stringListsIntersect("one;two","two;three",";")
361same undefined, stringListsIntersect("one,two",undefined)
362same undefined, stringListsIntersect(undefined,"one,two" )