authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-01-05 03:57:48-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-01-05 03:57:48-05:00
log3b5e26b7f7e4b37cf9357d058f32c0ad08ed7338
tree3e62f38dbdee624eb7ac8780e8f2735b3945484d
parentee09eb7f5461aa9e2374a6adbfbf130bfc0ebf21

self hosted tests import std library


30 files changed, 100 insertions(+), 364 deletions(-)

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