Skip to content

Commit

Permalink
add test for allowing slice[slice.len..slice.len]
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewrk committed Dec 13, 2017
1 parent d295279 commit 84619ab
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions test/cases/slice.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const assert = @import("std").debug.assert;
const mem = @import("std").mem;

const x = @intToPtr(&i32, 0x1000)[0..0x500];
const y = x[0x100..];
Expand All @@ -15,3 +16,12 @@ test "slice child property" {
var slice = array[0..];
assert(@typeOf(slice).Child == i32);
}

test "debug safety lets us slice from len..len" {
var an_array = []u8{1, 2, 3};
assert(mem.eql(u8, sliceFromLenToLen(an_array[0..], 3, 3), ""));
}

fn sliceFromLenToLen(a_slice: []u8, start: usize, end: usize) -> []u8 {
return a_slice[start..end];
}

0 comments on commit 84619ab

Please sign in to comment.