Add tests for some basic language features

This commit is contained in:
Nunuhara Cabbage
2019-10-19 22:53:05 -07:00
parent 49586506d0
commit d37de6c23a
3 changed files with 37 additions and 0 deletions
+29
View File
@@ -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);
}
+7
View File
@@ -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 {
+1
View File
@@ -1,5 +1,6 @@
Source = {
"main.jaf",
"lang.jaf",
"arithmetic.jaf",
"strings.jaf",
"structs.jaf"