From d37de6c23ab751f4ea7ee75241504f583d65f2fc Mon Sep 17 00:00:00 2001 From: Nunuhara Cabbage Date: Sat, 19 Oct 2019 22:51:27 -0700 Subject: [PATCH] Add tests for some basic language features --- test/Source/lang.jaf | 29 +++++++++++++++++++++++++++++ test/Source/main.jaf | 7 +++++++ test/Source/test.inc | 1 + 3 files changed, 37 insertions(+) create mode 100755 test/Source/lang.jaf diff --git a/test/Source/lang.jaf b/test/Source/lang.jaf new file mode 100755 index 0000000..83214a2 --- /dev/null +++ b/test/Source/lang.jaf @@ -0,0 +1,29 @@ +// -*-mode: C; coding: sjis; -*- + +int g; + +void assign(ref int i, int v) +{ + i = v; +} + +void string_set_local(string s) +{ + s = "oops"; +} + +void string_assign(ref string dst, string src) +{ + dst = src; +} + +void test_lang(void) +{ + int i; + string s; + test_equal("global assignment", (g = 16, g), 16); + test_equal("ref assignment", (i = 0, assign(i, 32), i), 32); + test_string("string pass-by-value", (s = "test", string_set_local(s), s), "test"); + test_string("string pass-by-ref", (s = "foo", string_assign(s, "bar"), s), "bar"); + test_equal("conditional", (i = 1, i ? 42 : 0), 42); +} diff --git a/test/Source/main.jaf b/test/Source/main.jaf index d7d6db2..124a087 100755 --- a/test/Source/main.jaf +++ b/test/Source/main.jaf @@ -53,15 +53,22 @@ void test_string(string msg, string actual, string expected) int main(void) { + test_start("language features"); + test_lang(); + test_end("language features"); + test_start("arithmetic"); test_arithmetic(); test_end("arithmetic"); + test_start("strings"); test_strings(); test_end("strings"); + test_start("structs"); test_structs(); test_end("structs"); + if (total_failed > 0) { system.Output(string(total_failed) + " tests failed.\n"); } else { diff --git a/test/Source/test.inc b/test/Source/test.inc index 6f1091c..a5058b7 100755 --- a/test/Source/test.inc +++ b/test/Source/test.inc @@ -1,5 +1,6 @@ Source = { "main.jaf", +"lang.jaf", "arithmetic.jaf", "strings.jaf", "structs.jaf"