diff options
| author | Techatrix <techatrix@mailbox.org> | 2024-12-29 06:47:15 +0100 |
|---|---|---|
| committer | Techatrix <techatrix@mailbox.org> | 2024-12-29 07:00:39 +0100 |
| commit | 5b6326ec6540d1b7af8de1176f657672be72a1e4 (patch) | |
| tree | 60d3a3c3ad1f5c68d12c33ae7b4181af9331fc1c /test/behavior/slice.zig | |
| parent | 5d51d4474a0c61f08c264c03ecbdf651d91afe82 (diff) | |
| download | zig-5b6326ec6540d1b7af8de1176f657672be72a1e4.tar.gz zig-5b6326ec6540d1b7af8de1176f657672be72a1e4.zip | |
fix slice of slice with sentinel on the lhs slice
example:
```zig
test {
var foo: [2:0]u8 = .{ 1, 2 };
_ = foo[0.. :1][0..2];
}
```
A `.slice_open` ast node will not have a end index nor sentinel.
Diffstat (limited to 'test/behavior/slice.zig')
| -rw-r--r-- | test/behavior/slice.zig | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/test/behavior/slice.zig b/test/behavior/slice.zig index 7c03bb8a20..52680b87f3 100644 --- a/test/behavior/slice.zig +++ b/test/behavior/slice.zig @@ -115,6 +115,23 @@ test "open slice of open slice with sentinel" { try expect(slice[1..][0.. :0][4] == 0); } +test "open slice with sentinel of slice with end index" { + if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO + + var slice: [:0]const u8 = "hello"; + _ = &slice; + + comptime assert(@TypeOf(slice[0.. :0][0..5]) == *const [5]u8); + try expect(slice[0.. :0][0..5].len == 5); + try expect(slice[0.. :0][0..5][0] == 'h'); + try expect(slice[0.. :0][0..5][4] == 'o'); + + comptime assert(@TypeOf(slice[0.. :0][0..5 :0]) == *const [5:0]u8); + try expect(slice[0.. :0][0..5 :0].len == 5); + try expect(slice[0.. :0][0..5 :0][0] == 'h'); + try expect(slice[0.. :0][0..5 :0][5] == 0); +} + test "slice of type" { comptime { var types_array = [_]type{ i32, f64, type }; |
