diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-01-29 21:47:26 -0500 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-01-29 22:30:30 -0500 |
| commit | 581edd643fb18a66c472f77e2f8cd3f4cea524a2 (patch) | |
| tree | a03f6a3ade952729456b94584f21d4beb51a4802 /test/cases/slice.zig | |
| parent | 9c328b42916d463465b134457c7f13b5c65da406 (diff) | |
| download | zig-581edd643fb18a66c472f77e2f8cd3f4cea524a2.tar.gz zig-581edd643fb18a66c472f77e2f8cd3f4cea524a2.zip | |
backport copy elision changes
This commit contains everything from the copy-elision-2
branch that does not have to do with copy elision directly,
but is generally useful for master branch.
* All const values know their parents, when applicable, not
just structs and unions.
* Null pointers in const values are represented explicitly,
rather than as a HardCodedAddr value of 0.
* Rename "maybe" to "optional" in various code locations.
* Separate DeclVarSrc and DeclVarGen
* Separate PtrCastSrc and PtrCastGen
* Separate CmpxchgSrc and CmpxchgGen
* Represent optional error set as an integer, using the 0 value.
In a const value, it uses nullptr.
* Introduce type_has_one_possible_value and use it where applicable.
* Fix debug builds not setting memory to 0xaa when storing
undefined.
* Separate the type of a variable from the const value of a variable.
* Use copy_const_val where appropriate.
* Rearrange structs to pack data more efficiently.
* Move test/cases/* to test/behavior/*
* Use `std.debug.assertOrPanic` in behavior tests instead of
`std.debug.assert`.
* Fix outdated slice syntax in docs.
Diffstat (limited to 'test/cases/slice.zig')
| -rw-r--r-- | test/cases/slice.zig | 40 |
1 files changed, 0 insertions, 40 deletions
diff --git a/test/cases/slice.zig b/test/cases/slice.zig deleted file mode 100644 index b4b43bdd19..0000000000 --- a/test/cases/slice.zig +++ /dev/null @@ -1,40 +0,0 @@ -const assert = @import("std").debug.assert; -const mem = @import("std").mem; - -const x = @intToPtr([*]i32, 0x1000)[0..0x500]; -const y = x[0x100..]; -test "compile time slice of pointer to hard coded address" { - assert(@ptrToInt(x.ptr) == 0x1000); - assert(x.len == 0x500); - - assert(@ptrToInt(y.ptr) == 0x1100); - assert(y.len == 0x400); -} - -test "slice child property" { - var array: [5]i32 = undefined; - var slice = array[0..]; - assert(@typeOf(slice).Child == i32); -} - -test "runtime 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]; -} - -test "implicitly cast array of size 0 to slice" { - var msg = []u8{}; - assertLenIsZero(msg); -} - -fn assertLenIsZero(msg: []const u8) void { - assert(msg.len == 0); -} |
