From 22fccdbb0d771897568dd6f1603102007a5d2c5b Mon Sep 17 00:00:00 2001 From: Josh Wolfe Date: Thu, 3 Dec 2015 12:19:28 -0700 Subject: [PATCH] tests for bool stuff --- test/run_tests.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/run_tests.cpp b/test/run_tests.cpp index bf5cf6e2f6..77fbb0c5e9 100644 --- a/test/run_tests.cpp +++ b/test/run_tests.cpp @@ -273,6 +273,22 @@ export fn _start() -> unreachable { exit(0); } )SOURCE", "OK\n"); + + add_simple_case("bool literals", R"SOURCE( +#link("c") +extern { + fn puts(s: *const u8) -> i32; + fn exit(code: i32) -> unreachable; +} + +export fn _start() -> unreachable { + if (true) { puts("OK 1"); } + if (false) { puts("BAD 1"); } + if (!true) { puts("BAD 2"); } + if (!false) { puts("OK 2"); } + exit(0); +} + )SOURCE", "OK 1\nOK 2\n"); } static void add_compile_failure_test_cases(void) { @@ -382,6 +398,12 @@ fn f() -> i32 { } )SOURCE", 1, ".tmp_source.zig:2:15: error: type mismatch. expected i32. got *const u8"); + add_compile_fail_case("if condition is bool, not int", R"SOURCE( +fn f() { + if (0) {} +} + )SOURCE", 1, ".tmp_source.zig:3:9: error: type mismatch. expected bool. got i32"); + } static void print_compiler_invokation(TestCase *test_case, Buf *zig_stderr) {