diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2016-04-10 13:58:04 -0700 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2016-04-10 13:58:04 -0700 |
| commit | 4a3bce4b638cf94482afe010af9bae722249f548 (patch) | |
| tree | e7c278c03d811df926cf715f90ecdbd1a1cb8c8a /test/run_tests.cpp | |
| parent | b117b5907c50f495c53770bfc351e0431e6474b3 (diff) | |
| download | zig-4a3bce4b638cf94482afe010af9bae722249f548.tar.gz zig-4a3bce4b638cf94482afe010af9bae722249f548.zip | |
move some tests into self hosted
Diffstat (limited to 'test/run_tests.cpp')
| -rw-r--r-- | test/run_tests.cpp | 222 |
1 files changed, 0 insertions, 222 deletions
diff --git a/test/run_tests.cpp b/test/run_tests.cpp index 3316c792cb..4143fa000e 100644 --- a/test/run_tests.cpp +++ b/test/run_tests.cpp @@ -252,82 +252,6 @@ pub const b_text = a_text; )SOURCE"); } - add_simple_case("params", R"SOURCE( -const io = @import("std").io; - -fn add(a: i32, b: i32) -> i32 { - a + b -} - -pub fn main(args: [][]u8) -> %void { - if (add(22, 11) == 33) { - %%io.stdout.printf("pass\n"); - } -} - )SOURCE", "pass\n"); - - add_simple_case("void parameters", R"SOURCE( -const io = @import("std").io; - -pub fn main(args: [][]u8) -> %void { - void_fun(1, void{}, 2); -} - -fn void_fun(a : i32, b : void, c : i32) { - const v = b; - const vv : void = if (a == 1) {v} else {}; - if (a + c == 3) { %%io.stdout.printf("OK\n"); } - return vv; -} - )SOURCE", "OK\n"); - - add_simple_case("mutable local variables", R"SOURCE( -const io = @import("std").io; - -pub fn main(args: [][]u8) -> %void { - var zero : i32 = 0; - if (zero == 0) { %%io.stdout.printf("zero\n"); } - - var i = i32(0); - while (i != 3) { - %%io.stdout.printf("loop\n"); - i += 1; - } -} - )SOURCE", "zero\nloop\nloop\nloop\n"); - - add_simple_case("arrays", R"SOURCE( -const io = @import("std").io; - -pub fn main(args: [][]u8) -> %void { - var array : [5]i32 = undefined; - - var i : i32 = 0; - while (i < 5) { - array[i] = i + 1; - i = array[i]; - } - - i = 0; - var accumulator = i32(0); - while (i < 5) { - accumulator += array[i]; - - i += 1; - } - - if (accumulator == 15) { - %%io.stdout.printf("OK\n"); - } - - if (get_array_len(array) != 5) { - %%io.stdout.printf("BAD\n"); - } -} -fn get_array_len(a: []i32) -> isize { - a.len -} - )SOURCE", "OK\n"); add_simple_case("hello world without libc", R"SOURCE( @@ -339,49 +263,6 @@ pub fn main(args: [][]u8) -> %void { )SOURCE", "Hello, world!\n"); - add_simple_case("short circuit", R"SOURCE( -const io = @import("std").io; - -pub fn main(args: [][]u8) -> %void { - if (true || { %%io.stdout.printf("BAD 1\n"); false }) { - %%io.stdout.printf("OK 1\n"); - } - if (false || { %%io.stdout.printf("OK 2\n"); false }) { - %%io.stdout.printf("BAD 2\n"); - } - - if (true && { %%io.stdout.printf("OK 3\n"); false }) { - %%io.stdout.printf("BAD 3\n"); - } - if (false && { %%io.stdout.printf("BAD 4\n"); false }) { - } else { - %%io.stdout.printf("OK 4\n"); - } -} - )SOURCE", "OK 1\nOK 2\nOK 3\nOK 4\n"); - - add_simple_case("modify operators", R"SOURCE( -const io = @import("std").io; - -pub fn main(args: [][]u8) -> %void { - var i : i32 = 0; - i += 5; if (i != 5) { %%io.stdout.printf("BAD +=\n"); } - i -= 2; if (i != 3) { %%io.stdout.printf("BAD -=\n"); } - i *= 20; if (i != 60) { %%io.stdout.printf("BAD *=\n"); } - i /= 3; if (i != 20) { %%io.stdout.printf("BAD /=\n"); } - i %= 11; if (i != 9) { %%io.stdout.printf("BAD %=\n"); } - i <<= 1; if (i != 18) { %%io.stdout.printf("BAD <<=\n"); } - i >>= 2; if (i != 4) { %%io.stdout.printf("BAD >>=\n"); } - i = 6; - i &= 5; if (i != 4) { %%io.stdout.printf("BAD &=\n"); } - i ^= 6; if (i != 2) { %%io.stdout.printf("BAD ^=\n"); } - i = 6; - i |= 3; if (i != 7) { %%io.stdout.printf("BAD |=\n"); } - - %%io.stdout.printf("OK\n"); -} - )SOURCE", "OK\n"); - add_simple_case_libc("number literals", R"SOURCE( const c = @c_import(@c_include("stdio.h")); @@ -508,110 +389,7 @@ export fn main(argc: c_int, argv: &&u8) -> c_int { 0o10700.00010e0: 0x1.1c0001p+12 )OUTPUT"); - add_simple_case("structs", R"SOURCE( -const io = @import("std").io; - -pub fn main(args: [][]u8) -> %void { - var foo : Foo = undefined; - @memset(&foo, 0, @sizeof(Foo)); - foo.a += 1; - foo.b = foo.a == 1; - test_foo(foo); - test_mutation(&foo); - if (foo.c != 100) { - %%io.stdout.printf("BAD\n"); - } - test_point_to_self(); - test_byval_assign(); - test_initializer(); - %%io.stdout.printf("OK\n"); -} -struct Foo { - a : i32, - b : bool, - c : f32, -} -fn test_foo(foo : Foo) { - if (!foo.b) { - %%io.stdout.printf("BAD\n"); - } -} -fn test_mutation(foo : &Foo) { - foo.c = 100; -} -struct Node { - val: Val, - next: &Node, -} - -struct Val { - x: i32, -} -fn test_point_to_self() { - var root : Node = undefined; - root.val.x = 1; - - var node : Node = undefined; - node.next = &root; - node.val.x = 2; - - root.next = &node; - - if (node.next.next.next.val.x != 1) { - %%io.stdout.printf("BAD\n"); - } -} -fn test_byval_assign() { - var foo1 : Foo = undefined; - var foo2 : Foo = undefined; - foo1.a = 1234; - - if (foo2.a != 0) { %%io.stdout.printf("BAD\n"); } - - foo2 = foo1; - - if (foo2.a != 1234) { %%io.stdout.printf("BAD - byval assignment failed\n"); } -} -fn test_initializer() { - const val = Val { .x = 42 }; - if (val.x != 42) { %%io.stdout.printf("BAD\n"); } -} - )SOURCE", "OK\n"); - - add_simple_case("global variables", R"SOURCE( -const io = @import("std").io; - -const g1 : i32 = 1233 + 1; -var g2 : i32 = 0; - -pub fn main(args: [][]u8) -> %void { - if (g2 != 0) { %%io.stdout.printf("BAD\n"); } - g2 = g1; - if (g2 != 1234) { %%io.stdout.printf("BAD\n"); } - %%io.stdout.printf("OK\n"); -} - )SOURCE", "OK\n"); - - add_simple_case("while loop", R"SOURCE( -const io = @import("std").io; -pub fn main(args: [][]u8) -> %void { - var i : i32 = 0; - while (i < 4) { - %%io.stdout.printf("loop\n"); - i += 1; - } - g(); -} -fn g() -> i32 { - return f(); -} -fn f() -> i32 { - while (true) { - return 0; - } -} - )SOURCE", "loop\nloop\nloop\nloop\n"); add_simple_case("continue and break", R"SOURCE( const io = @import("std").io; |
