diff options
Diffstat (limited to 'tests/general/extlvals.icn')
-rw-r--r-- | tests/general/extlvals.icn | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/tests/general/extlvals.icn b/tests/general/extlvals.icn new file mode 100644 index 0000000..0f394ba --- /dev/null +++ b/tests/general/extlvals.icn @@ -0,0 +1,71 @@ +# Test use of external values with dynamic loading, using demo cfunc. + +link cfunc + +record complex(r, i) + +procedure main() + local e, l, v1, v2, v3, v4 + local r1,r2,r3,r4, s1, s2, s3, s4 + + # test simple creation, type(), copy() + xwrite("v1", v1 := extxmin()) + xwrite("v2", v2 := extxmin()) + xwrite("v3", v3 := v1) + xwrite("v4", v4 := copy(v1)) + + # test string-based external example + xwrite("s1", s1 := extxstr("bite")) + xwrite("s2", s2 := extxstr("the")) + xwrite("s3", s3 := extxstr("wax")) + xwrite("s4", s4 := extxstr("tadpole")) + + # test real-based external example + xwrite("r1", r1 := extxreal(111.1)) + xwrite("r2", r2 := extxreal(222.2)) + xwrite("r3", r3 := extxreal(333.3)) + xwrite("r4", r4 := copy(r1)) + + # test === and ~=== + teqv(v1, v3, v2) + teqv(v1, v4, v2) + teqv(s2, copy(s2), s3) + teqv(r1, r1, copy(r1)) + teqv(s1, s1, s3) + teqv(r2, r2, r4) + teqv(s3, s3, r3) + + # test sorting + l := [ v1, s2, r3, v4, s1, r2, complex(8,9), v3, s4, r1, v2, s3, r4 ] + write() + every xwrite("before", !l) + write() + every xwrite("sorted", !sort(l)) + +end + + +# write label, type(xval), image(xval) + +procedure xwrite(label, xval) + write(label, ": ", type(xval), ": ",image(xval)) + return +end + + +# test equivalence of id1 and id2, and nonequivalence of diff + +procedure teqv(id1, id2, diff) + if id1 ~=== id2 then + write("nonequivalent: ", image(id1), " and ", image(id2)) + if id2 ~=== id1 then + write("nonequivalent: ", image(id2), " and ", image(id1)) + if not (id1 === id2) then + write("not equivalent: ", image(id1), " and ", image(id2)) + + if id1 === diff then + write("false equivalence: ", image(id1), " and ", image(diff)) + if id2 === diff then + write("false equivalence: ", image(id2), " and ", image(diff)) + return +end |