mirror of
https://github.com/nunuhara/xsystem4.git
synced 2026-09-30 02:48:14 +03:00
Add tests for some basic language features
This commit is contained in:
Executable
+29
@@ -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);
|
||||
}
|
||||
@@ -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,5 +1,6 @@
|
||||
Source = {
|
||||
"main.jaf",
|
||||
"lang.jaf",
|
||||
"arithmetic.jaf",
|
||||
"strings.jaf",
|
||||
"structs.jaf"
|
||||
|
||||
Reference in New Issue
Block a user