mirror of
https://github.com/nunuhara/xsystem4.git
synced 2026-10-01 11:28:01 +03:00
52 lines
1.0 KiB
C
Executable File
52 lines
1.0 KiB
C
Executable File
// -*-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;
|
|
}
|
|
|
|
struct lang_struct_inner {
|
|
int a;
|
|
};
|
|
|
|
struct lang_struct {
|
|
int a;
|
|
lang_struct_inner in;
|
|
};
|
|
|
|
void struct_set_a(lang_struct s, int i)
|
|
{
|
|
s.a = i;
|
|
}
|
|
|
|
void struct_set_inner(lang_struct s, int i)
|
|
{
|
|
s.in.a = i;
|
|
}
|
|
|
|
void test_lang(void)
|
|
{
|
|
int i;
|
|
string s;
|
|
lang_struct ls;
|
|
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("struct pass-by-value", (ls.a = 42, struct_set_a(ls, 2), ls.a), 42);
|
|
test_equal("nested struct pass-by-value", (ls.in.a = 42, struct_set_inner(ls, 2), ls.in.a), 42);
|
|
test_equal("conditional", (i = 1, i ? 42 : 0), 42);
|
|
}
|