@@ -3,19 +3,152 @@ module test
33foreign handler MCNumberCreateWithInteger(in value as int, out value_ref as number) as bool binds to "<builtin>"
44foreign handler MCBooleanCreateWithBool(in value as bool, out value_ref as boolean) as bool binds to "<builtin>"
55
6+ foreign handler MCProperListCreate(in pValues as optional pointer, in pValueCount as uint, out value_ref as list) as bool binds to "<builtin>"
7+
68public handler test()
7- variable tVar as number
8- variable tResult as boolean
9- MCBooleanCreateWithBool(MCNumberCreateWithInteger(100, tVar), tResult)
10- if MCNumberCreateWithInteger(200, tVar) then
9+ variable tResults as list
10+ MCProperListCreate(undefined, 0, tResults)
11+
12+ variable tDelimiter as string
13+ put newline into tDelimiter
14+
15+ --testLogic(tResults)
16+ -- testList(tResults)
17+ --testSort(tResults)
18+ --testArithmetic(tResults)
19+
20+ variable tVar as list
21+ MCProperListCreate(undefined, 0, tVar)
22+ push 2 onto tVar
23+ if the head of tVar is 2 then
24+ push "success" onto tResults
25+ end if
26+
27+ variable tResultString as string
28+ put "" into tResultString
29+ combine tResults with tDelimiter into tResultString
30+
31+ return tResultString
32+ end handler
33+
34+ public handler testLog(in pModule as string, in pTest as string, in pResult as bool, inout xResults as list)
35+ variable tStringResult as string
36+ if pResult then
37+ put "SUCCESS" into tStringResult
38+ else
39+ put "FAILURE" into tStringResult
1140 end if
12- variable tVar2 as string
13- put "" into tVar2
14- put "Hello World" after tVar2
15- put "!" after tVar2
16- put 0 into tVar
17- add 100 to tVar
18- return tVar2
41+
42+ push pModule & "_" & pTest & ":" && tStringResult onto xResults
43+ end handler
44+
45+ public handler testLogic(inout xResults as list)
46+ variable tVar as bool
47+ put not false into tVar
48+
49+ testLog("Logic", "Not", tVar, xResults)
50+ end handler
51+
52+ public handler testArithmetic(inout xResults as list) as undefined
53+
54+ variable tInt as int
55+ variable tReal as real
56+ --variable tNumber
57+
58+ put 10 into tInt
59+ put 10 into tReal
60+ --put 10 into tNumber
61+
62+ add 2 to tInt
63+ add 2 to tReal
64+ --add 2 to tNumber
65+
66+ testLog("Arithmetic", "AddToInt", tInt is 12, xResults)
67+ testLog("Arithmetic", "AddToReal", tReal is 12, xResults)
68+ --testLog("Arithmetic", "AddToNum", tNumber is 12, xResults)
69+
70+ subtract 2 from tInt
71+ subtract 2 from tReal
72+ --subtract 2 from tNumber
73+
74+ testLog("Arithmetic", "SubtractFromInt", tInt is 10, xResults)
75+ testLog("Arithmetic", "SubtractFromReal", tReal is 10, xResults)
76+ --testLog("Arithmetic", "SubtractFromNum", tNumber is 10, xResults)
77+
78+ multiply tInt by 2
79+ multiply tReal by 2
80+ --multiply tNumber by 2
81+
82+ testLog("Arithmetic", "MultiplyInt", tInt is 20, xResults)
83+ testLog("Arithmetic", "MultiplyReal", tReal is 20, xResults)
84+ --testLog("Arithmetic", "MultiplyNum", tNumber is 20, xResults)
85+
86+ divide tInt by 40
87+ divide tReal by 40
88+ --divide tNumber by 40
89+
90+ testLog("Arithmetic", "DivideInt", tInt is 0, xResults)
91+ testLog("Arithmetic", "DivideReal", tReal is 0.5, xResults)
92+ --testLog("Arithmetic", "DivideNum", tNumber is 0.5, xResults)
93+
94+ end handler
95+
96+ public handler testList(inout xResults as list) as undefined
97+ variable tTestList as list
98+ MCProperListCreate(undefined, 0, tTestList)
99+
100+ push "xyz" onto tTestList
101+ push 2 onto tTestList
102+ push "abcd" onto tTestList
103+ push 1 onto tTestList
104+
105+ testLog("List", "NumberOfElements", the number of elements in tTestList is 4, xResults)
106+ testLog("List", "HeadOf", the head of tTestList is "xyz", xResults)
107+ testLog("List", "TailOf", the tail of tTestList is 1, xResults)
108+
109+ testLog("List", "ElementOf", element 2 of tTestList is 2, xResults)
110+ testLog("List", "ElementRangeOf", element 2 of element 3 to -1 of tTestList is 1, xResults)
111+
112+ variable tSubList as list
113+ put element -2 to -1 of tTestList into tSubList
114+ testLog("List", "Contains", tTestList contains element -2 to -1 of tTestList, xResults)
115+
116+ testLog("List", "IsIn", "abcd" is in tSubList, xResults)
117+ testLog("List", "IsNotIn", not tSubList is in tTestList, xResults)
118+
119+ variable tString as string
120+ pop front of tSubList into tString
121+
122+ testLog("List", "Pop", tString is "abcd", xResults)
123+ testLog("List", "Pop", the number of elements in tSubList is 1, xResults)
124+
125+ splice tTestList after element 1 of tSubList
126+
127+ testLog("List", "SpliceAfter", the number of elements in tSubList is 5, xResults)
128+ testLog("List", "SpliceAfter", the tail of tSubList is 1, xResults)
129+ testLog("List", "SpliceAfter", tSubList contains tTestList, xResults)
130+
131+ end handler
132+
133+ public handler testSort(inout xResults as list) as undefined
134+ variable tTestList as list
135+ MCProperListCreate(undefined, 0, tTestList)
136+
137+ push "xyz" onto tTestList
138+ push 2 onto tTestList
139+ push "abcd" onto tTestList
140+ push 1 onto tTestList
141+
142+ sort tTestList in ascending numeric order
143+
144+ testLog("Sort", "AscendingNumeric", the head of tTestList is 1, xResults)
145+ testLog("Sort", "NumericStable", the tail of tTestList is "abcd", xResults)
146+
147+ sort tTestList in ascending text order
148+
149+ testLog("Sort", "AscendingText", the head of tTestList is "abcd", xResults)
150+ testLog("Sort", "TextStable", the tail of tTestList is 2, xResults)
151+
19152end handler
20153
21- end module
154+ end module
0 commit comments