authorgravatar for 4678790+dweiller@users.noreply.github.comDominic <4678790+dweiller@users.noreply.github.com> 2023-05-01 15:37:25+10:00
committergravatar for 4678790+dweiller@users.noreply.github.comDominic <4678790+dweiller@users.noreply.github.com> 2023-05-07 15:55:20+10:00
log7c8d60e814b985d3aab43c7c467f424596942ef9
tree87faddca683187829a9a8e07276c9772ba6a7304
parent2c2a0402c65986674d427390292f2fe38474c90f

test: add behavior tests for slice-by-length


1 files changed, 38 insertions(+), 0 deletions(-)

test/behavior/slice.zig+38
...@@ -355,6 +355,10 @@ test "slice syntax resulting in pointer-to-array" {...@@ -355,6 +355,10 @@ test "slice syntax resulting in pointer-to-array" {
355 try testSlice();355 try testSlice();
356 try testSliceOpt();356 try testSliceOpt();
357 try testSliceAlign();357 try testSliceAlign();
358 try testSliceLength();
359 try testSliceLengthZ();
360 try testArrayLength();
361 try testArrayLengthZ();
358 }362 }
359363
360 fn testArray() !void {364 fn testArray() !void {
...@@ -465,6 +469,40 @@ test "slice syntax resulting in pointer-to-array" {...@@ -465,6 +469,40 @@ test "slice syntax resulting in pointer-to-array" {
465 try expectEqualSlices("a"[0..] ++ "b"[0..], "ab");469 try expectEqualSlices("a"[0..] ++ "b"[0..], "ab");
466 try expectEqualSlices("a"[0.. :0] ++ "b"[0.. :0], "ab");470 try expectEqualSlices("a"[0.. :0] ++ "b"[0.. :0], "ab");
467 }471 }
472
473 fn testSliceLength() !void {
474 var array = [5]u8{ 1, 2, 3, 4, 5 };
475 var slice: []u8 = &array;
476 comptime try expect(@TypeOf(slice[1..][0..2]) == *[2]u8);
477 comptime try expect(@TypeOf(slice[1..][0..4]) == *[4]u8);
478 comptime try expect(@TypeOf(slice[1..][0..2 :4]) == *[2:4]u8);
479 }
480
481 fn testSliceLengthZ() !void {
482 var array = [5:0]u8{ 1, 2, 3, 4, 5 };
483 var slice: [:0]u8 = &array;
484 comptime try expect(@TypeOf(slice[1..][0..2]) == *[2]u8);
485 comptime try expect(@TypeOf(slice[1..][0..2 :4]) == *[2:4]u8);
486 comptime try expect(@TypeOf(slice[1.. :0][0..2]) == *[2]u8);
487 comptime try expect(@TypeOf(slice[1.. :0][0..2 :4]) == *[2:4]u8);
488 }
489
490 fn testArrayLength() !void {
491 var array = [5]u8{ 1, 2, 3, 4, 5 };
492 comptime try expect(@TypeOf(array[1..][0..2]) == *[2]u8);
493 comptime try expect(@TypeOf(array[1..][0..4]) == *[4]u8);
494 comptime try expect(@TypeOf(array[1..][0..2 :4]) == *[2:4]u8);
495 }
496
497 fn testArrayLengthZ() !void {
498 var array = [5:0]u8{ 1, 2, 3, 4, 5 };
499 comptime try expect(@TypeOf(array[1..][0..2]) == *[2]u8);
500 comptime try expect(@TypeOf(array[1..][0..4]) == *[4:0]u8);
501 comptime try expect(@TypeOf(array[1..][0..2 :4]) == *[2:4]u8);
502 comptime try expect(@TypeOf(array[1.. :0][0..2]) == *[2]u8);
503 comptime try expect(@TypeOf(array[1.. :0][0..4]) == *[4:0]u8);
504 comptime try expect(@TypeOf(array[1.. :0][0..2 :4]) == *[2:4]u8);
505 }
468 };506 };
469507
470 try S.doTheTest();508 try S.doTheTest();