From 832454f38b3ef635ee03fb54c382d8be02ac7c9e Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 18 Apr 2016 13:06:17 -0700 Subject: [PATCH] move 2 tests to self hosted land --- test/run_tests.cpp | 39 --------------------------------------- test/self_hosted.zig | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 39 deletions(-) diff --git a/test/run_tests.cpp b/test/run_tests.cpp index 7786c8e98..7b5b90e4a 100644 --- a/test/run_tests.cpp +++ b/test/run_tests.cpp @@ -430,33 +430,6 @@ pub fn main(args: [][]u8) -> %void { } )SOURCE", "9\n8\n7\n6\n0\n1\n2\n3\n9\n8\n7\n6\n0\n1\n2\n3\n"); - add_simple_case("pointer to void return type", R"SOURCE( -const io = @import("std").io; -const x = void{}; -fn f() -> &void { - %%io.stdout.printf("OK\n"); - return &x; -} -pub fn main(args: [][]u8) -> %void { - const a = f(); - return *a; -} - )SOURCE", "OK\n"); - - add_simple_case("call result of if else expression", R"SOURCE( -const io = @import("std").io; -fn a() -> []u8 { "a\n" } -fn b() -> []u8 { "b\n" } -fn f(x: bool) { - %%io.stdout.printf((if (x) a else b)()); -} -pub fn main(args: [][]u8) -> %void { - f(true); - f(false); -} - )SOURCE", "a\nb\n"); - - add_simple_case_libc("expose function pointer to C land", R"SOURCE( const c = @c_import(@c_include("stdlib.h")); @@ -502,18 +475,6 @@ export fn main(argc: c_int, argv: &&u8) -> c_int { )SOURCE", "3.25\n3\n3.00\n-0.40\n"); - add_simple_case("const expression eval handling of variables", R"SOURCE( -const io = @import("std").io; -pub fn main(args: [][]u8) -> %void { - var x = true; - while (x) { - x = false; - } - %%io.stdout.printf("OK\n"); -} - )SOURCE", "OK\n"); - - add_simple_case("incomplete struct parameter top level decl", R"SOURCE( const io = @import("std").io; struct A { diff --git a/test/self_hosted.zig b/test/self_hosted.zig index 3f0ea4f8f..1ab673db1 100644 --- a/test/self_hosted.zig +++ b/test/self_hosted.zig @@ -1166,3 +1166,39 @@ fn statically_initialized_array_literal() { assert(y[3] == 4); } const st_init_arr_lit_x = []u8{1,2,3,4}; + + + +#attribute("test") +fn pointer_to_void_return_type() { + %%test_pointer_to_void_return_type(); +} +fn test_pointer_to_void_return_type() -> %void { + const a = test_pointer_to_void_return_type_2(); + return *a; +} +const test_pointer_to_void_return_type_x = void{}; +fn test_pointer_to_void_return_type_2() -> &void { + return &test_pointer_to_void_return_type_x; +} + + +#attribute("test") +fn call_result_of_if_else_expression() { + assert(str_eql(f2(true), "a")); + assert(str_eql(f2(false), "b")); +} +fn f2(x: bool) -> []u8 { + return (if (x) f_a else f_b)(); +} +fn f_a() -> []u8 { "a" } +fn f_b() -> []u8 { "b" } + + +#attribute("test") +fn const_expression_eval_handling_of_variables() { + var x = true; + while (x) { + x = false; + } +}