diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-04-29 15:54:04 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-04-29 15:54:04 -0700 |
| commit | 4307436b9945f814ff5731981df1d19febf3ba0a (patch) | |
| tree | efaaec94a41d632d45f255d464d9787eb02c4c9b /test/behavior/bool.zig | |
| parent | 5a02c938dafdf2bb11b2350b6ad3161ef93744f0 (diff) | |
| download | zig-4307436b9945f814ff5731981df1d19febf3ba0a.tar.gz zig-4307436b9945f814ff5731981df1d19febf3ba0a.zip | |
move behavior tests from test/stage1/ to test/
And fix test cases to make them pass. This is in preparation for
starting to pass behavior tests with self-hosted.
Diffstat (limited to 'test/behavior/bool.zig')
| -rw-r--r-- | test/behavior/bool.zig | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/test/behavior/bool.zig b/test/behavior/bool.zig new file mode 100644 index 0000000000..ef9383244e --- /dev/null +++ b/test/behavior/bool.zig @@ -0,0 +1,35 @@ +const expect = @import("std").testing.expect; + +test "bool literals" { + expect(true); + expect(!false); +} + +test "cast bool to int" { + const t = true; + const f = false; + expect(@boolToInt(t) == @as(u32, 1)); + expect(@boolToInt(f) == @as(u32, 0)); + nonConstCastBoolToInt(t, f); +} + +fn nonConstCastBoolToInt(t: bool, f: bool) void { + expect(@boolToInt(t) == @as(u32, 1)); + expect(@boolToInt(f) == @as(u32, 0)); +} + +test "bool cmp" { + expect(testBoolCmp(true, false) == false); +} +fn testBoolCmp(a: bool, b: bool) bool { + return a == b; +} + +const global_f = false; +const global_t = true; +const not_global_f = !global_f; +const not_global_t = !global_t; +test "compile time bool not" { + expect(not_global_f); + expect(!not_global_t); +} |
