diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/drivers/hint_fixes_test.js | 4 | ||||
| -rw-r--r-- | tests/errors/static_const_typo.zc | 5 | ||||
| -rw-r--r-- | tests/errors/static_typo.zc | 5 | ||||
| -rw-r--r-- | tests/langerrors/struct_const_runtime.zc | 6 | ||||
| -rw-r--r-- | tests/programs/struct_const.zc | 28 | ||||
| -rwxr-xr-x | tests/test.sh | 1 | ||||
| -rw-r--r-- | tests/typeerrors/field_typo.zc | 5 |
7 files changed, 54 insertions, 0 deletions
diff --git a/tests/drivers/hint_fixes_test.js b/tests/drivers/hint_fixes_test.js index 20d3dd1..a388911 100644 --- a/tests/drivers/hint_fixes_test.js +++ b/tests/drivers/hint_fixes_test.js @@ -76,5 +76,9 @@ fixes('a misspelled local function is corrected', 'int count_items() { return 1; 'int count_items() { return 1; }\nfn main() {\n\treturn count_items();\n}\n', 'change to `count_items`'); fixes('a qualified name from a file library adds its include', 'include rt;\nfn main() {\n\treturn actor.vector();\n}\n', 'actor', 0, 'include rt;\ninclude actor;\nfn main() {\n\treturn actor.vector();\n}\n', 'include actor'); +fixes('a misspelled field is corrected', 'include rt;\nstruct point { int length, width; }\nfn main() {\n\tpoint* p = rt.new(point);\n\treturn p.lenght;\n}\n', 'lenght', 0, + 'include rt;\nstruct point { int length, width; }\nfn main() {\n\tpoint* p = rt.new(point);\n\treturn p.length;\n}\n', 'change to `length`'); +fixes('a misspelled static function of a library group is corrected', 'include rt;\ninclude std;\nfn main() {\n\treturn std.Text.itao(5, 0);\n}\n', 'itao', 0, + 'include rt;\ninclude std;\nfn main() {\n\treturn std.Text.itoa(5, 0);\n}\n', 'change to `itoa`'); console.log(ok + ' hint fix checks passed, ' + bad + ' failed'); process.exit(bad ? 1 : 0); diff --git a/tests/errors/static_const_typo.zc b/tests/errors/static_const_typo.zc new file mode 100644 index 0000000..c7f2b7b --- /dev/null +++ b/tests/errors/static_const_typo.zc @@ -0,0 +1,5 @@ +namespace; + +// expect: MAXX: is not a static function of this struct; did you mean 'MAX'? +struct Text { const MAX = 24; int len; }; +fn main() { return Text.MAXX; } diff --git a/tests/errors/static_typo.zc b/tests/errors/static_typo.zc new file mode 100644 index 0000000..97f6513 --- /dev/null +++ b/tests/errors/static_typo.zc @@ -0,0 +1,5 @@ +namespace; + +// expect: itao: is not a static function of this struct; did you mean 'itoa'? +struct Text { int len; static int itoa(int n) { return n; } }; +fn main() { return Text.itao(1); } diff --git a/tests/langerrors/struct_const_runtime.zc b/tests/langerrors/struct_const_runtime.zc new file mode 100644 index 0000000..b55626e --- /dev/null +++ b/tests/langerrors/struct_const_runtime.zc @@ -0,0 +1,6 @@ +namespace; + +// expect: a struct constant must be a constant expression +int f(int x) { return x; } +struct Text { const MAX = f(3); int len; } +fn main() { return 0; } diff --git a/tests/programs/struct_const.zc b/tests/programs/struct_const.zc new file mode 100644 index 0000000..59af8fd --- /dev/null +++ b/tests/programs/struct_const.zc @@ -0,0 +1,28 @@ +namespace; +include rt; + +struct Text { + const MAX = 24, MIN = 1; + const int WIDE = MAX * 2; + int len, tag; + static int top() { return MAX; } + static int span() { return MAX - MIN; } + int room() { return MAX - this.len; } + int total() { int[MIN + 2] a; a[2] = WIDE; return a[2] + this.tag; } +} + +const MAX = 99; + +int main() { + Text t; + t.len = 5; t.tag = 7; + rt.put_n(Text.MAX); rt.put_c(32); + rt.put_n(Text.MIN + Text.WIDE); rt.put_c(32); + rt.put_n(Text.top()); rt.put_c(32); + rt.put_n(Text.span()); rt.put_c(32); + rt.put_n(t.room()); rt.put_c(32); + rt.put_n(t.total()); rt.put_c(32); + rt.put_n(t.len + t.tag); rt.put_c(32); + rt.put_n(MAX); rt.put_c(10); + return 0; +} diff --git a/tests/test.sh b/tests/test.sh index 46625a6..7ae7b9d 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -123,6 +123,7 @@ run(){ # $1 = vm command, $2 = label chk "$($vm < tests/programs/generics.zc | md5sum)" "$(md5sum < tests/programs/generics.expected)" "$l generic functions are compiled per type arguments" chk "$($vm < tests/programs/genmeth.zc | md5sum)" "$(md5sum < tests/programs/genmeth.expected)" "$l methods of generic structs are compiled per type arguments" chk "$($vm < tests/programs/static.zc)" "14 5 9" "$l static functions of a struct are called as Struct.name(args)" + chk "$($vm < tests/programs/struct_const.zc)" "24 49 24 23 19 55 12 99" "$l constants declared in a struct are reached as Struct.NAME, and by bare name in its methods" chk "$($vm < tests/programs/methodown.zc)" "7 9" "$l struct methods and functions return owned objects (.u)" chk "$($vm < tests/programs/typedmethods.zc)" "14 5 13" "$l struct methods declare a return type and typed parameters" chk "$($vm < tests/programs/enumscope.zc)" "0 5 6 blue" "$l enum members are reached as Enum.MEMBER, also in a case" diff --git a/tests/typeerrors/field_typo.zc b/tests/typeerrors/field_typo.zc new file mode 100644 index 0000000..aa64209 --- /dev/null +++ b/tests/typeerrors/field_typo.zc @@ -0,0 +1,5 @@ +namespace; + +// expect: point has no field lenght; did you mean 'length'? +struct point { int length, width; }; +fn main() { point* p; return p.lenght; } |
