diff options
| author | Veikka Tuominen <git@vexu.eu> | 2024-01-02 17:33:41 +0200 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2024-01-06 16:49:41 -0800 |
| commit | 804cee3b93cb7084c16ee61d3bcb57f7d3c9f0bc (patch) | |
| tree | 3d8c534b1adc352b248255ef2906ef2bdf11dffc /test/behavior/string_literals.zig | |
| parent | 282ff8d3bd4a0d870a98f145aa87039e0409b745 (diff) | |
| download | zig-804cee3b93cb7084c16ee61d3bcb57f7d3c9f0bc.tar.gz zig-804cee3b93cb7084c16ee61d3bcb57f7d3c9f0bc.zip | |
categorize `behavior/bugs/<issueno>.zig` tests
Diffstat (limited to 'test/behavior/string_literals.zig')
| -rw-r--r-- | test/behavior/string_literals.zig | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/test/behavior/string_literals.zig b/test/behavior/string_literals.zig index 04ec145e3f..01f285bf0c 100644 --- a/test/behavior/string_literals.zig +++ b/test/behavior/string_literals.zig @@ -80,3 +80,19 @@ test "string literal pointer sentinel" { try std.testing.expect(@TypeOf(string_literal.ptr) == [*:0]const u8); } + +test "sentinel slice of string literal" { + const string = "Hello!\x00World!"; + try std.testing.expect(@TypeOf(string) == *const [13:0]u8); + + const slice_without_sentinel: []const u8 = string[0..6]; + try std.testing.expect(@TypeOf(slice_without_sentinel) == []const u8); + + const slice_with_sentinel: [:0]const u8 = string[0..6 :0]; + try std.testing.expect(@TypeOf(slice_with_sentinel) == [:0]const u8); +} + +test "Peer type resolution with string literals and unknown length u8 pointers" { + try std.testing.expect(@TypeOf("", "a", @as([*:0]const u8, "")) == [*:0]const u8); + try std.testing.expect(@TypeOf(@as([*:0]const u8, "baz"), "foo", "bar") == [*:0]const u8); +} |
