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
This commit is contained in:
Ryan Liptak
2024-07-03 21:41:11 -07:00
committed by Veikka Tuominen
parent 768b17755e
commit b67caf72e3

View File

@@ -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]);
}