Skip to content

Commit

Permalink
behavior: add test coverage for slice and array-related issues
Browse files Browse the repository at this point in the history
  • Loading branch information
wooster0 committed Dec 7, 2022
1 parent 78864b7 commit ae4e67e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
3 changes: 3 additions & 0 deletions test/behavior.zig
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,17 @@ test {
_ = @import("behavior/bugs/6456.zig");
_ = @import("behavior/bugs/6781.zig");
_ = @import("behavior/bugs/6850.zig");
_ = @import("behavior/bugs/6905.zig");
_ = @import("behavior/bugs/7003.zig");
_ = @import("behavior/bugs/7047.zig");
_ = @import("behavior/bugs/7187.zig");
_ = @import("behavior/bugs/7325.zig");
_ = @import("behavior/bugs/8646.zig");
_ = @import("behavior/bugs/9584.zig");
_ = @import("behavior/bugs/10138.zig");
_ = @import("behavior/bugs/10147.zig");
_ = @import("behavior/bugs/10970.zig");
_ = @import("behavior/bugs/10684.zig");
_ = @import("behavior/bugs/11046.zig");
_ = @import("behavior/bugs/11100.zig");
_ = @import("behavior/bugs/11139.zig");
Expand Down
12 changes: 12 additions & 0 deletions test/behavior/bugs/10684.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const std = @import("std");
const expectEqualStrings = std.testing.expectEqualStrings;

test "slicing slices" {
const foo = "1234";
const bar = foo[0..4];
try expectEqualStrings("1234", bar);
try expectEqualStrings("2", bar[1..2]);
try expectEqualStrings("3", bar[2..3]);
try expectEqualStrings("4", bar[3..4]);
try expectEqualStrings("34", bar[2..4]);
}
16 changes: 16 additions & 0 deletions test/behavior/bugs/6905.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const expect = @import("std").testing.expect;

test "sentinel-terminated 0-length slices" {
var u32s: [4]u32 = [_]u32{0, 1, 2, 3};

var index: u8 = 2;
var slice = u32s[index..index:2];
var array_ptr = u32s[2..2:2];
const comptime_known_array_value = u32s[2..2:2].*;
var runtime_array_value = u32s[2..2:2].*;

try expect(slice[0] == 2);
try expect(array_ptr[0] == 2);
try expect(comptime_known_array_value[0] == 2);
try expect(runtime_array_value[0] == 2);
}
11 changes: 11 additions & 0 deletions test/behavior/bugs/8646.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const std = @import("std");

const array = [_][]const []const u8{
&.{ "hello" },
&.{ "world", "hello" },
};

test {
try std.testing.expect(array[0].len == 1);
try std.testing.expectEqualStrings("hello", array[0][0]);
}

0 comments on commit ae4e67e

Please sign in to comment.