316 lines
12 KiB
Plaintext
316 lines
12 KiB
Plaintext
@pragma entry main
|
|
@pragma implicit off
|
|
|
|
@include "tap.inc";
|
|
|
|
function f(a, b, c)
|
|
{
|
|
return a + b + c;
|
|
}
|
|
|
|
function call_by_ref_1(&a, b, &c)
|
|
{
|
|
c = "hello, world";
|
|
return b * a;
|
|
}
|
|
|
|
function call_by_ref_2(a, &b)
|
|
{
|
|
b[1] = b[1] * a;
|
|
b[2] = "perfect";
|
|
return a;
|
|
}
|
|
|
|
function call_by_ref_3(&x)
|
|
{
|
|
x = "hello world";
|
|
}
|
|
|
|
function main()
|
|
{
|
|
{
|
|
tap_ensure (@b"" !== "", 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (@b"" === "", 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (@b"" != "", 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (@b"" == "", 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
|
|
tap_ensure (@b' ' !== ' ', 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (@b' ' === ' ', 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (@b' ' != ' ', 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (@b' ' == ' ', 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
|
|
tap_ensure ((@nil == 'A'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((@nil != 'A'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((@nil > 'A'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((@nil < 'A'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((@nil >= 'A'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((@nil <= 'A'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
|
|
tap_ensure ((@nil == @b'A'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((@nil != @b'A'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((@nil > @b'A'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((@nil < @b'A'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((@nil >= @b'A'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((@nil <= @b'A'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
|
|
tap_ensure (('A' == @b'A'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (('\u00FF' == @b'\xFF'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (('A' < @b'\xFF'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((@b'A' < @b'\xFF'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (('A' > @b'\xFF'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((@b'A' > @b'\xFF'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (('A' < @b'B'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((@b'A' < @b'B'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (('A' > @b'B'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((@b'A' > @b'B'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
|
|
tap_ensure (("10" == 10), 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (("10" == 10.00), 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (("10.0" == 10), 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (("10.00" == 10), 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
|
|
tap_ensure ((@b"10" == 10), 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((@b"10" == 10.00), 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((@b"10.0" == 10), 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((@b"10.00" == 10), 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
|
|
tap_ensure ((79 < '8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((79 <= '8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((79 > '8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((79 >= '8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((79 == '8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((79 != '8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
|
|
tap_ensure ((99 < '8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((99 <= '8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((99 > '8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((99 >= '8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((99 == '8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((99 != '8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
|
|
tap_ensure ((8 < '8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((8 <= '8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((8 > '8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((8 >= '8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((8 == '8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((8 != '8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
|
|
tap_ensure ((8.00 < '8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((8.00 <= '8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((8.00 > '8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((8.00 >= '8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((8.00 == '8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((8.00 != '8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
|
|
tap_ensure ((79 < @b'8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((79 <= @b'8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((79 > @b'8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((79 >= @b'8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((79 == @b'8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((79 != @b'8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
|
|
tap_ensure ((99 < @b'8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((99 <= @b'8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((99 > @b'8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((99 >= @b'8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((99 == @b'8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((99 != @b'8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
|
|
tap_ensure ((8 < @b'8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((8 <= @b'8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((8 > @b'8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((8 >= @b'8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((8 == @b'8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((8 != @b'8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
|
|
tap_ensure ((8.00 < @b'8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((8.00 <= @b'8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((8.00 > @b'8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((8.00 >= @b'8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((8.00 == @b'8'), 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((8.00 != @b'8'), 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
}
|
|
|
|
{
|
|
@local x, y, z, r;
|
|
|
|
x = 20;
|
|
y = 90;
|
|
r = call_by_ref_1(x, y, z);
|
|
tap_ensure (r, 1800, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (x, 20, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (y, 90, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (z, "hello, world", @SCRIPTNAME, @SCRIPTLINE);
|
|
}
|
|
|
|
## TODO: add a new special word, @FILENAME, @FILELINE, @LINE <--- which are understood by the parser and swapped to the actual value
|
|
## @SCRIPTNAME, @SCRIPTLINE doesn't tell the main file.
|
|
|
|
{
|
|
@local b;
|
|
call_by_ref_2(99, b);
|
|
tap_ensure (b[1], 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
}
|
|
|
|
{
|
|
@local b, r;
|
|
b[1] = 1;
|
|
r = call_by_ref_2(99, b);
|
|
tap_ensure (r, 99, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (b[1], 99, @SCRIPTNAME, @SCRIPTLINE);
|
|
}
|
|
|
|
{
|
|
@local b, r;
|
|
b[1] = 1;
|
|
r = hawk::call("call_by_ref_2", 99, b);
|
|
tap_ensure (r, 99, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (length(b), 2, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (b[1], 99, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (b[2], "perfect", @SCRIPTNAME, @SCRIPTLINE);
|
|
|
|
tap_ensure (hawk::call('f', 1, 2, 3), 6, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (hawk::call("f", 1, 2, 3), 6, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (hawk::call(@b'f', 1, 2, 3), 6, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (hawk::call(@b"f", 1, 2, 3), 6, @SCRIPTNAME, @SCRIPTLINE);
|
|
}
|
|
|
|
|
|
{
|
|
@local a;
|
|
a[1] = hawk::array();
|
|
a[1][2]=20;
|
|
tap_ensure (a[1][2], 20, @SCRIPTNAME, @SCRIPTLINE);
|
|
a[1][2]++;
|
|
tap_ensure (a[1][2], 21, @SCRIPTNAME, @SCRIPTLINE);
|
|
--a[1][2];
|
|
tap_ensure (a[1][2], 20, @SCRIPTNAME, @SCRIPTLINE);
|
|
}
|
|
|
|
{
|
|
@local a, nil;
|
|
a = hawk::array();
|
|
a[10] = "good";
|
|
a[0][40] = "bye"
|
|
a[0][0] = "farewell"
|
|
tap_ensure (hawk::typename(a), "array", @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (hawk::typename(a[0]), "array", @SCRIPTNAME, @SCRIPTLINE);
|
|
call_by_ref_3(a[9]);
|
|
tap_ensure (a[10], "good", @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (a[9], "hello world", @SCRIPTNAME, @SCRIPTLINE);
|
|
call_by_ref_3(a[10]);
|
|
tap_ensure (a[10], "hello world", @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (a[9], "hello world", @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (a[0][40], "bye", @SCRIPTNAME, @SCRIPTLINE);
|
|
call_by_ref_3(a[0][40]);
|
|
tap_ensure (a[0][40], "hello world", @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (length(a[0]), 2, @SCRIPTNAME, @SCRIPTLINE);
|
|
delete a[0][40];
|
|
tap_ensure (length(a[0]), 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (a[0][0], "farewell", @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (a[0][40], nil, @SCRIPTNAME, @SCRIPTLINE);
|
|
#hawk::splice (a[0], 40, 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
#tap_ensure (length(a[0]), 40, @SCRIPTNAME, @SCRIPTLINE);
|
|
}
|
|
|
|
|
|
{
|
|
@local a, i;
|
|
|
|
a = hawk::array();
|
|
tap_ensure (length(a), 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
|
|
for (i = 0; i < 10; i++) a[i*i]=i;
|
|
tap_ensure (length(a), 10, @SCRIPTNAME, @SCRIPTLINE);
|
|
|
|
delete a[0];
|
|
tap_ensure (length(a), 9, @SCRIPTNAME, @SCRIPTLINE);
|
|
|
|
delete a[81];
|
|
tap_ensure (length(a), 8, @SCRIPTNAME, @SCRIPTLINE);
|
|
|
|
delete a[36];
|
|
tap_ensure (length(a), 7, @SCRIPTNAME, @SCRIPTLINE);
|
|
|
|
for (i = 0; i < 10; i++) delete a[i*i];
|
|
tap_ensure (length(a), 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
|
|
delete a;
|
|
tap_ensure (length(a), 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
}
|
|
|
|
{
|
|
@local a, b, c;
|
|
a = hawk::array();
|
|
a[10][20][30] = 20;
|
|
b[12][20][30] = 20;
|
|
tap_ensure ((10 in a) && (20 in a[10]) && (30 in a[10][20]), 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((11 in a) && (20 in a[10]) && (30 in a[10][20]), 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
|
|
b = hawk::map();
|
|
b[10][20][30] = 20;
|
|
b[12][20][30] = 20;
|
|
tap_ensure ((10 in a) && (20 in a[10]) && (30 in a[10][20]), 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((11 in a) && (20 in a[10]) && (30 in a[10][20]), 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
|
|
c = hawk::map();
|
|
c[10,20,30] = "heloo";
|
|
tap_ensure (((10,20,30) in c), 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (((10,30,30) in c), 0, @SCRIPTNAME, @SCRIPTLINE);
|
|
}
|
|
|
|
{
|
|
@local a;
|
|
a = hawk::array(1,2,3);
|
|
tap_ensure (a[1], 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (a[2], 2, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (a[3], 3, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (length(a), 3, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (hawk::typename(a), "array", @SCRIPTNAME, @SCRIPTLINE);
|
|
}
|
|
|
|
|
|
{
|
|
# concatenation operator
|
|
tap_ensure ((@b"hawk" 10) === @b"hawk10", 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (("hawk" 10) === "hawk10", 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
|
|
tap_ensure ((@b"hawk" "hawk") === @b"hawkhawk", 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (("hawk" @b"hawk") === "hawkhawk", 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
|
|
tap_ensure ((@b"hawk" '1') === @b"hawk1", 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (("hawk" '1') === "hawk1", 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
|
|
tap_ensure (('*' @b"hawk" '1') === "*hawk1", 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (('*' "hawk" '1') === "*hawk1", 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
|
|
tap_ensure ((@b"hawk" '⚾') === @b"hawk\xe2\x9a\xbe", 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (("hawk" '⚾') === "hawk⚾", 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
|
|
tap_ensure ((@b"hawk" str::fromcharcode(0x26be)) === @b"hawk\xe2\x9a\xbe", 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (("hawk" str::fromcharcode(0x26be)) === "hawk⚾", 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((@b"hawk" @b'\xFF') === @b"hawk\xFF", 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure ((str::subchar(@b"\xFF\xFE", 1) str::subchar(@b"\xFF\xFE", 2)) === @b"\xFF\xFE", 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
|
|
tap_ensure ((@b"hawk" %% 10) === @b"hawk10", 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (("hawk" %% 10) === "hawk10", 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
|
|
tap_ensure ((@b"hawk" %% "hawk") === @b"hawkhawk", 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (("hawk" %% @b"hawk") === "hawkhawk", 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
|
|
tap_ensure ((@b"hawk" %% '1') === @b"hawk1", 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (("hawk" %% '1') === "hawk1", 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
|
|
tap_ensure (('*' %% @b"hawk" %% '1') === "*hawk1", 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (('*' %% "hawk" %% '1') === "*hawk1", 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
|
|
tap_ensure ((@b"hawk" %% '⚾') === @b"hawk\xe2\x9a\xbe", 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (("hawk" %% '⚾') === "hawk⚾", 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
|
|
tap_ensure ((@b"hawk" %% str::fromcharcode(0x26be)) === @b"hawk\xe2\x9a\xbe", 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
tap_ensure (("hawk" %% str::fromcharcode(0x26be)) === "hawk⚾", 1, @SCRIPTNAME, @SCRIPTLINE);
|
|
}
|
|
|
|
tap_end ();
|
|
}
|