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