diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-08-05 23:32:42 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-08-05 23:32:42 -0700 |
| commit | ea7bdeb67d474526732b117992971603e4065f98 (patch) | |
| tree | 5dcd7d8c1cdd311cb40505d986c8fbceab52dfc9 /test/behavior/basic.zig | |
| parent | 9fd3aeb8088cd9a3b0744d5f508ca256a2bbf19f (diff) | |
| parent | 7e9b23e6dce4d87615acd635f3731731a8601d39 (diff) | |
| download | zig-ea7bdeb67d474526732b117992971603e4065f98.tar.gz zig-ea7bdeb67d474526732b117992971603e4065f98.zip | |
Merge pull request #9517 from ziglang/generic-functions
stage2 generic functions
Diffstat (limited to 'test/behavior/basic.zig')
| -rw-r--r-- | test/behavior/basic.zig | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/test/behavior/basic.zig b/test/behavior/basic.zig index c5c2972ffc..1372dfaeeb 100644 --- a/test/behavior/basic.zig +++ b/test/behavior/basic.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const mem = std.mem; const expect = std.testing.expect; // normal comment @@ -83,3 +84,81 @@ test "unicode escape in character literal" { test "unicode character in character literal" { try expect('💩' == 128169); } + +fn first4KeysOfHomeRow() []const u8 { + return "aoeu"; +} + +test "return string from function" { + try expect(mem.eql(u8, first4KeysOfHomeRow(), "aoeu")); +} + +test "hex escape" { + try expect(mem.eql(u8, "\x68\x65\x6c\x6c\x6f", "hello")); +} + +test "multiline string" { + const s1 = + \\one + \\two) + \\three + ; + const s2 = "one\ntwo)\nthree"; + try expect(mem.eql(u8, s1, s2)); +} + +test "multiline string comments at start" { + const s1 = + //\\one + \\two) + \\three + ; + const s2 = "two)\nthree"; + try expect(mem.eql(u8, s1, s2)); +} + +test "multiline string comments at end" { + const s1 = + \\one + \\two) + //\\three + ; + const s2 = "one\ntwo)"; + try expect(mem.eql(u8, s1, s2)); +} + +test "multiline string comments in middle" { + const s1 = + \\one + //\\two) + \\three + ; + const s2 = "one\nthree"; + try expect(mem.eql(u8, s1, s2)); +} + +test "multiline string comments at multiple places" { + const s1 = + \\one + //\\two + \\three + //\\four + \\five + ; + const s2 = "one\nthree\nfive"; + try expect(mem.eql(u8, s1, s2)); +} + +test "call result of if else expression" { + try expect(mem.eql(u8, f2(true), "a")); + try expect(mem.eql(u8, f2(false), "b")); +} +fn f2(x: bool) []const u8 { + return (if (x) fA else fB)(); +} +fn fA() []const u8 { + return "a"; +} +fn fB() []const u8 { + return "b"; +} |
