aboutsummaryrefslogtreecommitdiff
path: root/test/behavior
diff options
context:
space:
mode:
authorRyan Liptak <squeek502@hotmail.com>2024-07-03 21:41:11 -0700
committerVeikka Tuominen <git@vexu.eu>2024-07-04 16:02:27 +0300
commitb67caf72e31eefe08fe2dc8b17b4bca16e0e3cc6 (patch)
tree7a5f346f9f03566afc1021321ce7992640cc1d9e /test/behavior
parent768b17755e7735b328b92212de2dd7018f78fb4b (diff)
downloadzig-b67caf72e31eefe08fe2dc8b17b4bca16e0e3cc6.tar.gz
zig-b67caf72e31eefe08fe2dc8b17b4bca16e0e3cc6.zip
Add behavior test: including the sentinel when dereferencing a string literal
This test would have failed in the past, but this has been fixed sometime in the last year. Closes #15944
Diffstat (limited to 'test/behavior')
-rw-r--r--test/behavior/string_literals.zig11
1 files changed, 11 insertions, 0 deletions
diff --git a/test/behavior/string_literals.zig b/test/behavior/string_literals.zig
index 898de2167c..a45403af97 100644
--- a/test/behavior/string_literals.zig
+++ b/test/behavior/string_literals.zig
@@ -101,3 +101,14 @@ 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);
}
+
+test "including the sentinel when dereferencing a string literal" {
+ var var_str = "abc";
+ const var_derefed = var_str[0 .. var_str.len + 1].*;
+
+ const const_str = "abc";
+ const const_derefed = const_str[0 .. const_str.len + 1].*;
+
+ try std.testing.expectEqualSlices(u8, &var_derefed, &const_derefed);
+ try std.testing.expectEqual(0, const_derefed[3]);
+}