test_sentinel_mismatch.zig (547B) - Raw
1 const std = @import("std"); 2 const expect = std.testing.expect; 3 4 test "sentinel mismatch" { 5 var array = [_]u8{ 3, 2, 1, 0 }; 6 7 // Creating a sentinel-terminated slice from the array with a length of 2 8 // will result in the value `1` occupying the sentinel element position. 9 // This does not match the indicated sentinel value of `0` and will lead 10 // to a runtime panic. 11 var runtime_length: usize = 2; 12 _ = &runtime_length; 13 const slice = array[0..runtime_length :0]; 14 15 _ = slice; 16 } 17 18 // test_safety=sentinel mismatch