authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-04-18 13:06:17-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-04-18 13:06:17-07:00
log832454f38b3ef635ee03fb54c382d8be02ac7c9e
tree140e2675e5181e8be4ddfee8c463bce22e4f99d8
parentc899368a90fa821f3a7b8c01c195d375073714d8

move 2 tests to self hosted land


2 files changed, 36 insertions(+), 39 deletions(-)

test/run_tests.cpp-39
...@@ -430,33 +430,6 @@ pub fn main(args: [][]u8) -> %void {...@@ -430,33 +430,6 @@ pub fn main(args: [][]u8) -> %void {
430}430}
431 )SOURCE", "9\n8\n7\n6\n0\n1\n2\n3\n9\n8\n7\n6\n0\n1\n2\n3\n");431 )SOURCE", "9\n8\n7\n6\n0\n1\n2\n3\n9\n8\n7\n6\n0\n1\n2\n3\n");
432432
433 add_simple_case("pointer to void return type", R"SOURCE(
434const io = @import("std").io;
435const x = void{};
436fn f() -> &void {
437 %%io.stdout.printf("OK\n");
438 return &x;
439}
440pub fn main(args: [][]u8) -> %void {
441 const a = f();
442 return *a;
443}
444 )SOURCE", "OK\n");
445
446 add_simple_case("call result of if else expression", R"SOURCE(
447const io = @import("std").io;
448fn a() -> []u8 { "a\n" }
449fn b() -> []u8 { "b\n" }
450fn f(x: bool) {
451 %%io.stdout.printf((if (x) a else b)());
452}
453pub fn main(args: [][]u8) -> %void {
454 f(true);
455 f(false);
456}
457 )SOURCE", "a\nb\n");
458
459
460 add_simple_case_libc("expose function pointer to C land", R"SOURCE(433 add_simple_case_libc("expose function pointer to C land", R"SOURCE(
461const c = @c_import(@c_include("stdlib.h"));434const c = @c_import(@c_include("stdlib.h"));
462435
...@@ -502,18 +475,6 @@ export fn main(argc: c_int, argv: &&u8) -> c_int {...@@ -502,18 +475,6 @@ export fn main(argc: c_int, argv: &&u8) -> c_int {
502 )SOURCE", "3.25\n3\n3.00\n-0.40\n");475 )SOURCE", "3.25\n3\n3.00\n-0.40\n");
503476
504477
505 add_simple_case("const expression eval handling of variables", R"SOURCE(
506const io = @import("std").io;
507pub fn main(args: [][]u8) -> %void {
508 var x = true;
509 while (x) {
510 x = false;
511 }
512 %%io.stdout.printf("OK\n");
513}
514 )SOURCE", "OK\n");
515
516
517 add_simple_case("incomplete struct parameter top level decl", R"SOURCE(478 add_simple_case("incomplete struct parameter top level decl", R"SOURCE(
518const io = @import("std").io;479const io = @import("std").io;
519struct A {480struct A {
test/self_hosted.zig+36
...@@ -1166,3 +1166,39 @@ fn statically_initialized_array_literal() {...@@ -1166,3 +1166,39 @@ fn statically_initialized_array_literal() {
1166 assert(y[3] == 4);1166 assert(y[3] == 4);
1167}1167}
1168const st_init_arr_lit_x = []u8{1,2,3,4};1168const st_init_arr_lit_x = []u8{1,2,3,4};
1169
1170
1171
1172#attribute("test")
1173fn pointer_to_void_return_type() {
1174 %%test_pointer_to_void_return_type();
1175}
1176fn test_pointer_to_void_return_type() -> %void {
1177 const a = test_pointer_to_void_return_type_2();
1178 return *a;
1179}
1180const test_pointer_to_void_return_type_x = void{};
1181fn test_pointer_to_void_return_type_2() -> &void {
1182 return &test_pointer_to_void_return_type_x;
1183}
1184
1185
1186#attribute("test")
1187fn call_result_of_if_else_expression() {
1188 assert(str_eql(f2(true), "a"));
1189 assert(str_eql(f2(false), "b"));
1190}
1191fn f2(x: bool) -> []u8 {
1192 return (if (x) f_a else f_b)();
1193}
1194fn f_a() -> []u8 { "a" }
1195fn f_b() -> []u8 { "b" }
1196
1197
1198#attribute("test")
1199fn const_expression_eval_handling_of_variables() {
1200 var x = true;
1201 while (x) {
1202 x = false;
1203 }
1204}