| 1 | const std = @import("std"); |
| 2 | const expectEqual = std.testing.expectEqual; |
| 3 | |
| 4 | test "0-terminated sentinel array" { |
| 5 | const array = [_:0]u8{ 1, 2, 3, 4 }; |
| 6 | |
| 7 | try expectEqual([4:0]u8, @TypeOf(array)); |
| 8 | try expectEqual(4, array.len); |
| 9 | try expectEqual(0, array[4]); |
| 10 | } |
| 11 | |
| 12 | test "extra 0s in 0-terminated sentinel array" { |
| 13 | // The sentinel value may appear earlier, but does not influence the compile-time 'len'. |
| 14 | const array = [_:0]u8{ 1, 0, 0, 4 }; |
| 15 | |
| 16 | try expectEqual([4:0]u8, @TypeOf(array)); |
| 17 | try expectEqual(4, array.len); |
| 18 | try expectEqual(0, array[4]); |
| 19 | } |
| 20 | |
| 21 | // test |