| author | |
| committer | |
| log | 3b5e26b7f7e4b37cf9357d058f32c0ad08ed7338 |
| tree | 3e62f38dbdee624eb7ac8780e8f2735b3945484d |
| parent | ee09eb7f5461aa9e2374a6adbfbf130bfc0ebf21 |
30 files changed, 100 insertions(+), 364 deletions(-)
test/cases/array.zig+8-27| ... | ... | @@ -1,3 +1,6 @@ |
| 1 | const assert = @import("std").debug.assert; | |
| 2 | const str = @import("std").str; | |
| 3 | ||
| 1 | 4 | fn arrays() { |
| 2 | 5 | @setFnTest(this); |
| 3 | 6 | |
| ... | ... | @@ -60,32 +63,10 @@ fn nestedArrays() { |
| 60 | 63 | |
| 61 | 64 | const array_of_strings = [][]u8 {"hello", "this", "is", "my", "thing"}; |
| 62 | 65 | for (array_of_strings) |s, i| { |
| 63 | if (i == 0) assert(memeql(s, "hello")); | |
| 64 | if (i == 1) assert(memeql(s, "this")); | |
| 65 | if (i == 2) assert(memeql(s, "is")); | |
| 66 | if (i == 3) assert(memeql(s, "my")); | |
| 67 | if (i == 4) assert(memeql(s, "thing")); | |
| 68 | } | |
| 69 | } | |
| 70 | ||
| 71 | ||
| 72 | ||
| 73 | // TODO const assert = @import("std").debug.assert; | |
| 74 | fn assert(ok: bool) { | |
| 75 | if (!ok) | |
| 76 | @unreachable(); | |
| 77 | } | |
| 78 | ||
| 79 | // TODO import from std.str | |
| 80 | pub fn memeql(a: []const u8, b: []const u8) -> bool { | |
| 81 | sliceEql(u8, a, b) | |
| 82 | } | |
| 83 | ||
| 84 | // TODO import from std.str | |
| 85 | pub fn sliceEql(inline T: type, a: []const T, b: []const T) -> bool { | |
| 86 | if (a.len != b.len) return false; | |
| 87 | for (a) |item, index| { | |
| 88 | if (b[index] != item) return false; | |
| 66 | if (i == 0) assert(str.eql(s, "hello")); | |
| 67 | if (i == 1) assert(str.eql(s, "this")); | |
| 68 | if (i == 2) assert(str.eql(s, "is")); | |
| 69 | if (i == 3) assert(str.eql(s, "my")); | |
| 70 | if (i == 4) assert(str.eql(s, "thing")); | |
| 89 | 71 | } |
| 90 | return true; | |
| 91 | 72 | } |
test/cases/atomics.zig+2-6| ... | ... | @@ -1,3 +1,5 @@ |
| 1 | const assert = @import("std").debug.assert; | |
| 2 | ||
| 1 | 3 | fn cmpxchg() { |
| 2 | 4 | @setFnTest(this); |
| 3 | 5 | |
| ... | ... | @@ -13,9 +15,3 @@ fn fence() { |
| 13 | 15 | @fence(AtomicOrder.SeqCst); |
| 14 | 16 | x = 5678; |
| 15 | 17 | } |
| 16 | ||
| 17 | // TODO const assert = @import("std").debug.assert; | |
| 18 | fn assert(ok: bool) { | |
| 19 | if (!ok) | |
| 20 | @unreachable(); | |
| 21 | } |
test/cases/bool.zig+2-6| ... | ... | @@ -1,3 +1,5 @@ |
| 1 | const assert = @import("std").debug.assert; | |
| 2 | ||
| 1 | 3 | fn boolLiterals() { |
| 2 | 4 | @setFnTest(this); |
| 3 | 5 | |
| ... | ... | @@ -28,9 +30,3 @@ fn boolCmp() { |
| 28 | 30 | fn testBoolCmp(a: bool, b: bool) -> bool { |
| 29 | 31 | a == b |
| 30 | 32 | } |
| 31 | ||
| 32 | // TODO const assert = @import("std").debug.assert; | |
| 33 | fn assert(ok: bool) { | |
| 34 | if (!ok) | |
| 35 | @unreachable(); | |
| 36 | } |
test/cases/cast.zig+8-12| ... | ... | @@ -1,14 +1,10 @@ |
| 1 | //fn intToPtrCast() { | |
| 2 | // @setFnTest(this); | |
| 3 | // | |
| 4 | // const x = isize(13); | |
| 5 | // const y = (&u8)(x); | |
| 6 | // const z = usize(y); | |
| 7 | // assert(z == 13); | |
| 8 | //} | |
| 1 | const assert = @import("std").debug.assert; | |
| 9 | 2 | |
| 10 | // TODO const assert = @import("std").debug.assert; | |
| 11 | fn assert(ok: bool) { | |
| 12 | if (!ok) | |
| 13 | @unreachable(); | |
| 3 | fn intToPtrCast() { | |
| 4 | @setFnTest(this); | |
| 5 | ||
| 6 | const x = isize(13); | |
| 7 | const y = (&u8)(x); | |
| 8 | const z = usize(y); | |
| 9 | assert(z == 13); | |
| 14 | 10 | } |
test/cases/const_slice_child.zig+2-6| ... | ... | @@ -1,3 +1,5 @@ |
| 1 | const assert = @import("std").debug.assert; | |
| 2 | ||
| 1 | 3 | var argv: &&const u8 = undefined; |
| 2 | 4 | |
| 3 | 5 | fn constSliceChild() { |
| ... | ... | @@ -41,9 +43,3 @@ fn streql(a: []const u8, b: []const u8) -> bool { |
| 41 | 43 | } |
| 42 | 44 | return true; |
| 43 | 45 | } |
| 44 | ||
| 45 | // TODO const assert = @import("std").debug.assert; | |
| 46 | fn assert(ok: bool) { | |
| 47 | if (!ok) | |
| 48 | @unreachable(); | |
| 49 | } |
test/cases/defer.zig+2-6| ... | ... | @@ -1,3 +1,5 @@ |
| 1 | const assert = @import("std").debug.assert; | |
| 2 | ||
| 1 | 3 | var result: [3]u8 = undefined; |
| 2 | 4 | var index: usize = undefined; |
| 3 | 5 | |
| ... | ... | @@ -49,9 +51,3 @@ fn mixingNormalAndMaybeDefers() { |
| 49 | 51 | assert(result[1] == 'b'); |
| 50 | 52 | assert(result[2] == 'a'); |
| 51 | 53 | } |
| 52 | ||
| 53 | // TODO const assert = @import("std").debug.assert; | |
| 54 | fn assert(ok: bool) { | |
| 55 | if (!ok) | |
| 56 | @unreachable(); | |
| 57 | } |
test/cases/enum.zig+2-10| ... | ... | @@ -1,3 +1,5 @@ |
| 1 | const assert = @import("std").debug.assert; | |
| 2 | ||
| 1 | 3 | fn enumType() { |
| 2 | 4 | @setFnTest(this); |
| 3 | 5 | |
| ... | ... | @@ -111,13 +113,3 @@ const IntToEnumNumber = enum { |
| 111 | 113 | Three, |
| 112 | 114 | Four, |
| 113 | 115 | }; |
| 114 | ||
| 115 | ||
| 116 | // TODO import from std | |
| 117 | fn assert(ok: bool) { | |
| 118 | if (!ok) | |
| 119 | @unreachable(); | |
| 120 | } | |
| 121 | ||
| 122 | ||
| 123 |
test/cases/enum_with_members.zig+8-62| ... | ... | @@ -1,11 +1,15 @@ |
| 1 | const assert = @import("std").debug.assert; | |
| 2 | const str = @import("std").str; | |
| 3 | const io = @import("std").io; | |
| 4 | ||
| 1 | 5 | const ET = enum { |
| 2 | 6 | SINT: i32, |
| 3 | 7 | UINT: u32, |
| 4 | 8 | |
| 5 | 9 | pub fn print(a: &ET, buf: []u8) -> %usize { |
| 6 | 10 | return switch (*a) { |
| 7 | ET.SINT => |x| { bufPrintInt(i32, buf, x) }, | |
| 8 | ET.UINT => |x| { bufPrintInt(u32, buf, x) }, | |
| 11 | ET.SINT => |x| { io.bufPrintInt(i32, buf, x) }, | |
| 12 | ET.UINT => |x| { io.bufPrintInt(u32, buf, x) }, | |
| 9 | 13 | } |
| 10 | 14 | } |
| 11 | 15 | }; |
| ... | ... | @@ -18,66 +22,8 @@ fn enumWithMembers() { |
| 18 | 22 | var buf: [20]u8 = undefined; |
| 19 | 23 | |
| 20 | 24 | assert(%%a.print(buf) == 3); |
| 21 | assert(memeql(buf[0...3], "-42")); | |
| 25 | assert(str.eql(buf[0...3], "-42")); | |
| 22 | 26 | |
| 23 | 27 | assert(%%b.print(buf) == 2); |
| 24 | assert(memeql(buf[0...2], "42")); | |
| 25 | } | |
| 26 | ||
| 27 | // TODO all the below should be imported from std | |
| 28 | ||
| 29 | const max_u64_base10_digits = 20; | |
| 30 | pub fn bufPrintInt(inline T: type, out_buf: []u8, x: T) -> usize { | |
| 31 | if (T.is_signed) bufPrintSigned(T, out_buf, x) else bufPrintUnsigned(T, out_buf, x) | |
| 32 | } | |
| 33 | ||
| 34 | fn bufPrintSigned(inline T: type, out_buf: []u8, x: T) -> usize { | |
| 35 | const uint = @intType(false, T.bit_count); | |
| 36 | if (x < 0) { | |
| 37 | out_buf[0] = '-'; | |
| 38 | return 1 + bufPrintUnsigned(uint, out_buf[1...], uint(-(x + 1)) + 1); | |
| 39 | } else { | |
| 40 | return bufPrintUnsigned(uint, out_buf, uint(x)); | |
| 41 | } | |
| 42 | } | |
| 43 | ||
| 44 | fn bufPrintUnsigned(inline T: type, out_buf: []u8, x: T) -> usize { | |
| 45 | var buf: [max_u64_base10_digits]u8 = undefined; | |
| 46 | var a = x; | |
| 47 | var index: usize = buf.len; | |
| 48 | ||
| 49 | while (true) { | |
| 50 | const digit = a % 10; | |
| 51 | index -= 1; | |
| 52 | buf[index] = '0' + u8(digit); | |
| 53 | a /= 10; | |
| 54 | if (a == 0) | |
| 55 | break; | |
| 56 | } | |
| 57 | ||
| 58 | const len = buf.len - index; | |
| 59 | ||
| 60 | @memcpy(&out_buf[0], &buf[index], len); | |
| 61 | ||
| 62 | return len; | |
| 63 | } | |
| 64 | ||
| 65 | // TODO const assert = @import("std").debug.assert; | |
| 66 | fn assert(ok: bool) { | |
| 67 | if (!ok) | |
| 68 | @unreachable(); | |
| 69 | } | |
| 70 | ||
| 71 | // TODO import from std.str | |
| 72 | pub fn memeql(a: []const u8, b: []const u8) -> bool { | |
| 73 | sliceEql(u8, a, b) | |
| 74 | } | |
| 75 | ||
| 76 | // TODO import from std.str | |
| 77 | pub fn sliceEql(inline T: type, a: []const T, b: []const T) -> bool { | |
| 78 | if (a.len != b.len) return false; | |
| 79 | for (a) |item, index| { | |
| 80 | if (b[index] != item) return false; | |
| 81 | } | |
| 82 | return true; | |
| 28 | assert(str.eql(buf[0...2], "42")); | |
| 83 | 29 | } |
test/cases/error.zig+5-25| ... | ... | @@ -1,3 +1,6 @@ |
| 1 | const assert = @import("std").debug.assert; | |
| 2 | const str = @import("std").str; | |
| 3 | ||
| 1 | 4 | pub fn foo() -> %i32 { |
| 2 | 5 | const x = %return bar(); |
| 3 | 6 | return x + 1 |
| ... | ... | @@ -25,8 +28,8 @@ fn gimmeItBroke() -> []const u8 { |
| 25 | 28 | |
| 26 | 29 | fn errorName() { |
| 27 | 30 | @setFnTest(this); |
| 28 | assert(memeql(@errorName(error.AnError), "AnError")); | |
| 29 | assert(memeql(@errorName(error.ALongerErrorName), "ALongerErrorName")); | |
| 31 | assert(str.eql(@errorName(error.AnError), "AnError")); | |
| 32 | assert(str.eql(@errorName(error.ALongerErrorName), "ALongerErrorName")); | |
| 30 | 33 | } |
| 31 | 34 | error AnError; |
| 32 | 35 | error ALongerErrorName; |
| ... | ... | @@ -97,26 +100,3 @@ fn doErrReturnInAssignment() -> %void { |
| 97 | 100 | fn makeANonErr() -> %i32 { |
| 98 | 101 | return 1; |
| 99 | 102 | } |
| 100 | ||
| 101 | ||
| 102 | ||
| 103 | // TODO const assert = @import("std").debug.assert; | |
| 104 | fn assert(ok: bool) { | |
| 105 | if (!ok) | |
| 106 | @unreachable(); | |
| 107 | } | |
| 108 | ||
| 109 | // TODO import from std.str | |
| 110 | pub fn memeql(a: []const u8, b: []const u8) -> bool { | |
| 111 | sliceEql(u8, a, b) | |
| 112 | } | |
| 113 | ||
| 114 | // TODO import from std.str | |
| 115 | pub fn sliceEql(inline T: type, a: []const T, b: []const T) -> bool { | |
| 116 | if (a.len != b.len) return false; | |
| 117 | for (a) |item, index| { | |
| 118 | if (b[index] != item) return false; | |
| 119 | } | |
| 120 | return true; | |
| 121 | } | |
| 122 |
test/cases/eval.zig+2-8| ... | ... | @@ -1,3 +1,5 @@ |
| 1 | const assert = @import("std").debug.assert; | |
| 2 | ||
| 1 | 3 | fn compileTimeRecursion() { |
| 2 | 4 | @setFnTest(this); |
| 3 | 5 | |
| ... | ... | @@ -159,11 +161,3 @@ fn staticallyInitializedArrayLiteral() { |
| 159 | 161 | assert(y[3] == 4); |
| 160 | 162 | } |
| 161 | 163 | const st_init_arr_lit_x = []u8{1,2,3,4}; |
| 162 | ||
| 163 | ||
| 164 | // TODO const assert = @import("std").debug.assert; | |
| 165 | fn assert(ok: bool) { | |
| 166 | if (!ok) | |
| 167 | @unreachable(); | |
| 168 | } | |
| 169 |
test/cases/fn.zig+2-8| ... | ... | @@ -1,3 +1,5 @@ |
| 1 | const assert = @import("std").debug.assert; | |
| 2 | ||
| 1 | 3 | fn params() { |
| 2 | 4 | @setFnTest(this); |
| 3 | 5 | |
| ... | ... | @@ -98,11 +100,3 @@ fn fn1() -> u32 {5} |
| 98 | 100 | fn fn2() -> u32 {6} |
| 99 | 101 | fn fn3() -> u32 {7} |
| 100 | 102 | fn fn4() -> u32 {8} |
| 101 | ||
| 102 | ||
| 103 | ||
| 104 | // TODO const assert = @import("std").debug.assert; | |
| 105 | fn assert(ok: bool) { | |
| 106 | if (!ok) | |
| 107 | @unreachable(); | |
| 108 | } |
test/cases/for.zig+5-22| ... | ... | @@ -1,3 +1,7 @@ |
| 1 | const std = @import("std"); | |
| 2 | const assert = std.debug.assert; | |
| 3 | const str = std.str; | |
| 4 | ||
| 1 | 5 | fn continueInForLoop() { |
| 2 | 6 | @setFnTest(this); |
| 3 | 7 | |
| ... | ... | @@ -20,31 +24,10 @@ fn forLoopWithPointerElemVar() { |
| 20 | 24 | var target: [source.len]u8 = undefined; |
| 21 | 25 | @memcpy(&target[0], &source[0], source.len); |
| 22 | 26 | mangleString(target); |
| 23 | assert(memeql(target, "bcdefgh")); | |
| 27 | assert(str.eql(target, "bcdefgh")); | |
| 24 | 28 | } |
| 25 | 29 | fn mangleString(s: []u8) { |
| 26 | 30 | for (s) |*c| { |
| 27 | 31 | *c += 1; |
| 28 | 32 | } |
| 29 | 33 | } |
| 30 | ||
| 31 | ||
| 32 | // TODO import from std.str | |
| 33 | pub fn memeql(a: []const u8, b: []const u8) -> bool { | |
| 34 | sliceEql(u8, a, b) | |
| 35 | } | |
| 36 | ||
| 37 | // TODO import from std.str | |
| 38 | pub fn sliceEql(inline T: type, a: []const T, b: []const T) -> bool { | |
| 39 | if (a.len != b.len) return false; | |
| 40 | for (a) |item, index| { | |
| 41 | if (b[index] != item) return false; | |
| 42 | } | |
| 43 | return true; | |
| 44 | } | |
| 45 | ||
| 46 | // TODO const assert = @import("std").debug.assert; | |
| 47 | fn assert(ok: bool) { | |
| 48 | if (!ok) | |
| 49 | @unreachable(); | |
| 50 | } |
test/cases/generics.zig+2-7| ... | ... | @@ -1,3 +1,5 @@ |
| 1 | const assert = @import("std").debug.assert; | |
| 2 | ||
| 1 | 3 | fn simpleGenericFn() { |
| 2 | 4 | @setFnTest(this); |
| 3 | 5 | |
| ... | ... | @@ -138,10 +140,3 @@ fn getByte(ptr: ?&u8) -> u8 {*??ptr} |
| 138 | 140 | fn getFirstByte(inline T: type, mem: []T) -> u8 { |
| 139 | 141 | getByte((&u8)(&mem[0])) |
| 140 | 142 | } |
| 141 | ||
| 142 | // TODO const assert = @import("std").debug.assert; | |
| 143 | fn assert(ok: bool) { | |
| 144 | if (!ok) | |
| 145 | @unreachable(); | |
| 146 | } | |
| 147 |
test/cases/goto.zig+2-6| ... | ... | @@ -1,3 +1,5 @@ |
| 1 | const assert = @import("std").debug.assert; | |
| 2 | ||
| 1 | 3 | fn gotoAndLabels() { |
| 2 | 4 | @setFnTest(this); |
| 3 | 5 | |
| ... | ... | @@ -37,9 +39,3 @@ entry: |
| 37 | 39 | defer it_worked = true; |
| 38 | 40 | if (b) goto exit; |
| 39 | 41 | } |
| 40 | ||
| 41 | // TODO const assert = @import("std").debug.assert; | |
| 42 | fn assert(ok: bool) { | |
| 43 | if (!ok) | |
| 44 | @unreachable(); | |
| 45 | } |
test/cases/if.zig+2-6| ... | ... | @@ -1,3 +1,5 @@ |
| 1 | const assert = @import("std").debug.assert; | |
| 2 | ||
| 1 | 3 | fn ifStatements() { |
| 2 | 4 | @setFnTest(this); |
| 3 | 5 | |
| ... | ... | @@ -38,9 +40,3 @@ fn elseIfExpressionF(c: u8) -> u8 { |
| 38 | 40 | u8(2) |
| 39 | 41 | } |
| 40 | 42 | } |
| 41 | ||
| 42 | // TODO const assert = @import("std").debug.assert; | |
| 43 | fn assert(ok: bool) { | |
| 44 | if (!ok) | |
| 45 | @unreachable(); | |
| 46 | } |
test/cases/import.zig+1-6| ... | ... | @@ -1,3 +1,4 @@ |
| 1 | const assert = @import("std").debug.assert; | |
| 1 | 2 | const a_namespace = @import("cases/import/a_namespace.zig"); |
| 2 | 3 | |
| 3 | 4 | fn callFnViaNamespaceLookup() { |
| ... | ... | @@ -5,9 +6,3 @@ fn callFnViaNamespaceLookup() { |
| 5 | 6 | |
| 6 | 7 | assert(a_namespace.foo() == 1234); |
| 7 | 8 | } |
| 8 | ||
| 9 | // TODO const assert = @import("std").debug.assert; | |
| 10 | fn assert(ok: bool) { | |
| 11 | if (!ok) | |
| 12 | @unreachable(); | |
| 13 | } |
test/cases/ir_block_deps.zig+2-6| ... | ... | @@ -1,3 +1,5 @@ |
| 1 | const assert = @import("std").debug.assert; | |
| 2 | ||
| 1 | 3 | fn foo(id: u64) -> %i32 { |
| 2 | 4 | return switch (id) { |
| 3 | 5 | 1 => getErrInt(), |
| ... | ... | @@ -19,9 +21,3 @@ fn irBlockDeps() { |
| 19 | 21 | assert(%%foo(1) == 0); |
| 20 | 22 | assert(%%foo(2) == 0); |
| 21 | 23 | } |
| 22 | ||
| 23 | // TODO const assert = @import("std").debug.assert; | |
| 24 | fn assert(ok: bool) { | |
| 25 | if (!ok) | |
| 26 | @unreachable(); | |
| 27 | } |
test/cases/math.zig+2-7| ... | ... | @@ -1,3 +1,5 @@ |
| 1 | const assert = @import("std").debug.assert; | |
| 2 | ||
| 1 | 3 | fn exactDivision() { |
| 2 | 4 | @setFnTest(this); |
| 3 | 5 | |
| ... | ... | @@ -175,10 +177,3 @@ fn binaryNot() { |
| 175 | 177 | fn testBinaryNot(x: u16) { |
| 176 | 178 | assert(~x == 0b0101010101010101); |
| 177 | 179 | } |
| 178 | ||
| 179 | // TODO const assert = @import("std").debug.assert; | |
| 180 | fn assert(ok: bool) { | |
| 181 | if (!ok) | |
| 182 | @unreachable(); | |
| 183 | } | |
| 184 |
test/cases/misc.zig+20-56| ... | ... | @@ -1,3 +1,7 @@ |
| 1 | const assert = @import("std").debug.assert; | |
| 2 | const str = @import("std").str; | |
| 3 | const cstr = @import("std").cstr; | |
| 4 | ||
| 1 | 5 | // normal comment |
| 2 | 6 | /// this is a documentation comment |
| 3 | 7 | /// doc comment line 2 |
| ... | ... | @@ -137,7 +141,7 @@ fn first4KeysOfHomeRow() -> []const u8 { |
| 137 | 141 | fn ReturnStringFromFunction() { |
| 138 | 142 | @setFnTest(this); |
| 139 | 143 | |
| 140 | assert(memeql(first4KeysOfHomeRow(), "aoeu")); | |
| 144 | assert(str.eql(first4KeysOfHomeRow(), "aoeu")); | |
| 141 | 145 | } |
| 142 | 146 | |
| 143 | 147 | const g1 : i32 = 1233 + 1; |
| ... | ... | @@ -203,31 +207,31 @@ fn emptyFn() {} |
| 203 | 207 | fn hexEscape() { |
| 204 | 208 | @setFnTest(this); |
| 205 | 209 | |
| 206 | assert(memeql("\x68\x65\x6c\x6c\x6f", "hello")); | |
| 210 | assert(str.eql("\x68\x65\x6c\x6c\x6f", "hello")); | |
| 207 | 211 | } |
| 208 | 212 | |
| 209 | 213 | fn stringConcatenation() { |
| 210 | 214 | @setFnTest(this); |
| 211 | 215 | |
| 212 | assert(memeql("OK" ++ " IT " ++ "WORKED", "OK IT WORKED")); | |
| 216 | assert(str.eql("OK" ++ " IT " ++ "WORKED", "OK IT WORKED")); | |
| 213 | 217 | } |
| 214 | 218 | |
| 215 | 219 | fn arrayMultOperator() { |
| 216 | 220 | @setFnTest(this); |
| 217 | 221 | |
| 218 | assert(memeql("ab" ** 5, "ababababab")); | |
| 222 | assert(str.eql("ab" ** 5, "ababababab")); | |
| 219 | 223 | } |
| 220 | 224 | |
| 221 | 225 | fn stringEscapes() { |
| 222 | 226 | @setFnTest(this); |
| 223 | 227 | |
| 224 | assert(memeql("\"", "\x22")); | |
| 225 | assert(memeql("\'", "\x27")); | |
| 226 | assert(memeql("\n", "\x0a")); | |
| 227 | assert(memeql("\r", "\x0d")); | |
| 228 | assert(memeql("\t", "\x09")); | |
| 229 | assert(memeql("\\", "\x5c")); | |
| 230 | assert(memeql("\u1234\u0069", "\xe1\x88\xb4\x69")); | |
| 228 | assert(str.eql("\"", "\x22")); | |
| 229 | assert(str.eql("\'", "\x27")); | |
| 230 | assert(str.eql("\n", "\x0a")); | |
| 231 | assert(str.eql("\r", "\x0d")); | |
| 232 | assert(str.eql("\t", "\x09")); | |
| 233 | assert(str.eql("\\", "\x5c")); | |
| 234 | assert(str.eql("\u1234\u0069", "\xe1\x88\xb4\x69")); | |
| 231 | 235 | } |
| 232 | 236 | |
| 233 | 237 | fn multilineString() { |
| ... | ... | @@ -239,7 +243,7 @@ fn multilineString() { |
| 239 | 243 | \\three |
| 240 | 244 | ; |
| 241 | 245 | const s2 = "one\ntwo)\nthree"; |
| 242 | assert(memeql(s1, s2)); | |
| 246 | assert(str.eql(s1, s2)); | |
| 243 | 247 | } |
| 244 | 248 | |
| 245 | 249 | fn multilineCString() { |
| ... | ... | @@ -251,7 +255,7 @@ fn multilineCString() { |
| 251 | 255 | c\\three |
| 252 | 256 | ; |
| 253 | 257 | const s2 = c"one\ntwo)\nthree"; |
| 254 | assert(cstrcmp(s1, s2) == 0); | |
| 258 | assert(cstr.cmp(s1, s2) == 0); | |
| 255 | 259 | } |
| 256 | 260 | |
| 257 | 261 | |
| ... | ... | @@ -337,8 +341,8 @@ fn pointerDereferencing() { |
| 337 | 341 | fn callResultOfIfElseExpression() { |
| 338 | 342 | @setFnTest(this); |
| 339 | 343 | |
| 340 | assert(memeql(f2(true), "a")); | |
| 341 | assert(memeql(f2(false), "b")); | |
| 344 | assert(str.eql(f2(true), "a")); | |
| 345 | assert(str.eql(f2(false), "b")); | |
| 342 | 346 | } |
| 343 | 347 | fn f2(x: bool) -> []u8 { |
| 344 | 348 | return (if (x) fA else fB)(); |
| ... | ... | @@ -442,7 +446,7 @@ fn cStringConcatenation() { |
| 442 | 446 | const a = c"OK" ++ c" IT " ++ c"WORKED"; |
| 443 | 447 | const b = c"OK IT WORKED"; |
| 444 | 448 | |
| 445 | const len = cstrlen(b); | |
| 449 | const len = cstr.len(b); | |
| 446 | 450 | const len_with_null = len + 1; |
| 447 | 451 | {var i: u32 = 0; while (i < len_with_null; i += 1) { |
| 448 | 452 | assert(a[i] == b[i]); |
| ... | ... | @@ -486,43 +490,3 @@ const test_pointer_to_void_return_type_x = void{}; |
| 486 | 490 | fn testPointerToVoidReturnType2() -> &const void { |
| 487 | 491 | return &test_pointer_to_void_return_type_x; |
| 488 | 492 | } |
| 489 | ||
| 490 | // TODO import from std.cstr | |
| 491 | pub fn cstrlen(ptr: &const u8) -> usize { | |
| 492 | var count: usize = 0; | |
| 493 | while (ptr[count] != 0; count += 1) {} | |
| 494 | return count; | |
| 495 | } | |
| 496 | ||
| 497 | // TODO import from std.str | |
| 498 | pub fn memeql(a: []const u8, b: []const u8) -> bool { | |
| 499 | sliceEql(u8, a, b) | |
| 500 | } | |
| 501 | ||
| 502 | // TODO import from std.str | |
| 503 | pub fn sliceEql(inline T: type, a: []const T, b: []const T) -> bool { | |
| 504 | if (a.len != b.len) return false; | |
| 505 | for (a) |item, index| { | |
| 506 | if (b[index] != item) return false; | |
| 507 | } | |
| 508 | return true; | |
| 509 | } | |
| 510 | ||
| 511 | // TODO import from std.cstr | |
| 512 | pub fn cstrcmp(a: &const u8, b: &const u8) -> i8 { | |
| 513 | var index: usize = 0; | |
| 514 | while (a[index] == b[index] && a[index] != 0; index += 1) {} | |
| 515 | return if (a[index] > b[index]) { | |
| 516 | 1 | |
| 517 | } else if (a[index] < b[index]) { | |
| 518 | -1 | |
| 519 | } else { | |
| 520 | i8(0) | |
| 521 | }; | |
| 522 | } | |
| 523 | ||
| 524 | // TODO const assert = @import("std").debug.assert; | |
| 525 | fn assert(ok: bool) { | |
| 526 | if (!ok) | |
| 527 | @unreachable(); | |
| 528 | } |
test/cases/namespace_depends_on_compile_var/index.zig+2-6| ... | ... | @@ -1,3 +1,5 @@ |
| 1 | const assert = @import("std").debug.assert; | |
| 2 | ||
| 1 | 3 | fn namespaceDependsOnCompileVar() { |
| 2 | 4 | @setFnTest(this); |
| 3 | 5 | |
| ... | ... | @@ -11,9 +13,3 @@ const some_namespace = switch(@compileVar("os")) { |
| 11 | 13 | Os.linux => @import("cases/namespace_depends_on_compile_var/a.zig"), |
| 12 | 14 | else => @import("cases/namespace_depends_on_compile_var/b.zig"), |
| 13 | 15 | }; |
| 14 | ||
| 15 | // TODO const assert = @import("std").debug.assert; | |
| 16 | fn assert(ok: bool) { | |
| 17 | if (!ok) | |
| 18 | @unreachable(); | |
| 19 | } |
test/cases/null.zig+2-7| ... | ... | @@ -1,3 +1,5 @@ |
| 1 | const assert = @import("std").debug.assert; | |
| 2 | ||
| 1 | 3 | fn nullableType() { |
| 2 | 4 | @setFnTest(this); |
| 3 | 5 | |
| ... | ... | @@ -97,10 +99,3 @@ fn foo(x: ?i32) -> ?bool { |
| 97 | 99 | const value = ?return x; |
| 98 | 100 | return value > 1234; |
| 99 | 101 | } |
| 100 | ||
| 101 | // TODO const assert = @import("std").debug.assert; | |
| 102 | fn assert(ok: bool) { | |
| 103 | if (!ok) | |
| 104 | @unreachable(); | |
| 105 | } | |
| 106 |
test/cases/pub_enum/index.zig+1-7| ... | ... | @@ -1,4 +1,5 @@ |
| 1 | 1 | const other = @import("cases/pub_enum/other.zig"); |
| 2 | const assert = @import("std").debug.assert; | |
| 2 | 3 | |
| 3 | 4 | fn pubEnum() { |
| 4 | 5 | @setFnTest(this); |
| ... | ... | @@ -14,10 +15,3 @@ fn castWithImportedSymbol() { |
| 14 | 15 | |
| 15 | 16 | assert(other.size_t(42) == 42); |
| 16 | 17 | } |
| 17 | ||
| 18 | ||
| 19 | // TODO const assert = @import("std").debug.assert; | |
| 20 | fn assert(ok: bool) { | |
| 21 | if (!ok) | |
| 22 | @unreachable(); | |
| 23 | } |
test/cases/sizeof_and_typeof.zig+2-6| ... | ... | @@ -1,3 +1,5 @@ |
| 1 | const assert = @import("std").debug.assert; | |
| 2 | ||
| 1 | 3 | fn sizeofAndTypeOf() { |
| 2 | 4 | @setFnTest(this); |
| 3 | 5 | |
| ... | ... | @@ -6,9 +8,3 @@ fn sizeofAndTypeOf() { |
| 6 | 8 | } |
| 7 | 9 | const x: u16 = 13; |
| 8 | 10 | const z: @typeOf(x) = 19; |
| 9 | ||
| 10 | // TODO const assert = @import("std").debug.assert; | |
| 11 | fn assert(ok: bool) { | |
| 12 | if (!ok) | |
| 13 | @unreachable(); | |
| 14 | } |
test/cases/struct.zig+2-7| ... | ... | @@ -1,3 +1,5 @@ |
| 1 | const assert = @import("std").debug.assert; | |
| 2 | ||
| 1 | 3 | const StructWithNoFields = struct { |
| 2 | 4 | fn add(a: i32, b: i32) -> i32 { a + b } |
| 3 | 5 | }; |
| ... | ... | @@ -206,10 +208,3 @@ fn passSliceOfEmptyStructToFn() { |
| 206 | 208 | fn testPassSliceOfEmptyStructToFn(slice: []EmptyStruct2) -> usize { |
| 207 | 209 | slice.len |
| 208 | 210 | } |
| 209 | ||
| 210 | ||
| 211 | // TODO const assert = @import("std").debug.assert; | |
| 212 | fn assert(ok: bool) { | |
| 213 | if (!ok) | |
| 214 | @unreachable(); | |
| 215 | } |
test/cases/struct_contains_slice_of_itself.zig+2-6| ... | ... | @@ -1,3 +1,5 @@ |
| 1 | const assert = @import("std").debug.assert; | |
| 2 | ||
| 1 | 3 | const Node = struct { |
| 2 | 4 | payload: i32, |
| 3 | 5 | children: []Node, |
| ... | ... | @@ -40,9 +42,3 @@ fn structContainsSliceOfItself() { |
| 40 | 42 | assert(root.children[2].children[0].payload == 31); |
| 41 | 43 | assert(root.children[2].children[1].payload == 32); |
| 42 | 44 | } |
| 43 | ||
| 44 | // TODO const assert = @import("std").debug.assert; | |
| 45 | fn assert(ok: bool) { | |
| 46 | if (!ok) | |
| 47 | @unreachable(); | |
| 48 | } |
test/cases/switch.zig+2-7| ... | ... | @@ -1,3 +1,5 @@ |
| 1 | const assert = @import("std").debug.assert; | |
| 2 | ||
| 1 | 3 | fn switchWithNumbers() { |
| 2 | 4 | @setFnTest(this); |
| 3 | 5 | |
| ... | ... | @@ -127,10 +129,3 @@ fn switchWithMultipleExpressions() { |
| 127 | 129 | fn returnsFive() -> i32 { |
| 128 | 130 | 5 |
| 129 | 131 | } |
| 130 | ||
| 131 | ||
| 132 | // TODO const assert = @import("std").debug.assert; | |
| 133 | fn assert(ok: bool) { | |
| 134 | if (!ok) | |
| 135 | @unreachable(); | |
| 136 | } |
test/cases/switch_prong_err_enum.zig+2-6| ... | ... | @@ -1,3 +1,5 @@ |
| 1 | const assert = @import("std").debug.assert; | |
| 2 | ||
| 1 | 3 | var read_count: u64 = 0; |
| 2 | 4 | |
| 3 | 5 | fn readOnce() -> %u64 { |
| ... | ... | @@ -25,9 +27,3 @@ fn switchProngReturnsErrorEnum() { |
| 25 | 27 | %%doThing(17); |
| 26 | 28 | assert(read_count == 1); |
| 27 | 29 | } |
| 28 | ||
| 29 | // TODO const assert = @import("std").debug.assert; | |
| 30 | fn assert(ok: bool) { | |
| 31 | if (!ok) | |
| 32 | @unreachable(); | |
| 33 | } |
test/cases/switch_prong_implicit_cast.zig+2-6| ... | ... | @@ -1,3 +1,5 @@ |
| 1 | const assert = @import("std").debug.assert; | |
| 2 | ||
| 1 | 3 | const FormValue = enum { |
| 2 | 4 | One, |
| 3 | 5 | Two: bool, |
| ... | ... | @@ -22,9 +24,3 @@ fn switchProngImplicitCast() { |
| 22 | 24 | }; |
| 23 | 25 | assert(result); |
| 24 | 26 | } |
| 25 | ||
| 26 | // TODO const assert = @import("std").debug.assert; | |
| 27 | fn assert(ok: bool) { | |
| 28 | if (!ok) | |
| 29 | @unreachable(); | |
| 30 | } |
test/cases/this.zig+2-6| ... | ... | @@ -1,3 +1,5 @@ |
| 1 | const assert = @import("std").debug.assert; | |
| 2 | ||
| 1 | 3 | const module = this; |
| 2 | 4 | |
| 3 | 5 | fn Point(inline T: type) -> type { |
| ... | ... | @@ -49,9 +51,3 @@ fn thisReferToFn() { |
| 49 | 51 | |
| 50 | 52 | assert(factorial(5) == 120); |
| 51 | 53 | } |
| 52 | ||
| 53 | // TODO const assert = @import("std").debug.assert; | |
| 54 | fn assert(ok: bool) { | |
| 55 | if (!ok) | |
| 56 | @unreachable(); | |
| 57 | } |
test/cases/while.zig+2-8| ... | ... | @@ -1,3 +1,5 @@ |
| 1 | const assert = @import("std").debug.assert; | |
| 2 | ||
| 1 | 3 | fn whileLoop() { |
| 2 | 4 | @setFnTest(this); |
| 3 | 5 | |
| ... | ... | @@ -72,11 +74,3 @@ fn whileWithContinueExpr() { |
| 72 | 74 | }} |
| 73 | 75 | assert(sum == 40); |
| 74 | 76 | } |
| 75 | ||
| 76 | ||
| 77 | ||
| 78 | // TODO const assert = @import("std").debug.assert; | |
| 79 | fn assert(ok: bool) { | |
| 80 | if (!ok) | |
| 81 | @unreachable(); | |
| 82 | } |