authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2021-05-04 20:47:26+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2021-05-08 15:15:30+03:00
logfd77f2cfed81f3414c079909e079a812e23071c3
treef9facf463ab13791faa0820c347371067ed27a79
parent59f9253d94331cedd4d0518250c8094a064f6cd2

std: update usage of std.testing


252 files changed, 6200 insertions(+), 6201 deletions(-)

lib/std/SemanticVersion.zig+13-13
...@@ -249,13 +249,13 @@ test "SemanticVersion format" {...@@ -249,13 +249,13 @@ test "SemanticVersion format" {
249 "+justmeta",249 "+justmeta",
250 "9.8.7+meta+meta",250 "9.8.7+meta+meta",
251 "9.8.7-whatever+meta+meta",251 "9.8.7-whatever+meta+meta",
252 }) |invalid| expectError(error.InvalidVersion, parse(invalid));252 }) |invalid| try expectError(error.InvalidVersion, parse(invalid));
253253
254 // Valid version string that may overflow.254 // Valid version string that may overflow.
255 const big_valid = "99999999999999999999999.999999999999999999.99999999999999999";255 const big_valid = "99999999999999999999999.999999999999999999.99999999999999999";
256 if (parse(big_valid)) |ver| {256 if (parse(big_valid)) |ver| {
257 try std.testing.expectFmt(big_valid, "{}", .{ver});257 try std.testing.expectFmt(big_valid, "{}", .{ver});
258 } else |err| expect(err == error.Overflow);258 } else |err| try expect(err == error.Overflow);
259259
260 // Invalid version string that may overflow.260 // Invalid version string that may overflow.
261 const big_invalid = "99999999999999999999999.999999999999999999.99999999999999999----RC-SNAPSHOT.12.09.1--------------------------------..12";261 const big_invalid = "99999999999999999999999.999999999999999999.99999999999999999----RC-SNAPSHOT.12.09.1--------------------------------..12";
...@@ -264,22 +264,22 @@ test "SemanticVersion format" {...@@ -264,22 +264,22 @@ test "SemanticVersion format" {
264264
265test "SemanticVersion precedence" {265test "SemanticVersion precedence" {
266 // SemVer 2 spec 11.2 example: 1.0.0 < 2.0.0 < 2.1.0 < 2.1.1.266 // SemVer 2 spec 11.2 example: 1.0.0 < 2.0.0 < 2.1.0 < 2.1.1.
267 expect(order(try parse("1.0.0"), try parse("2.0.0")) == .lt);267 try expect(order(try parse("1.0.0"), try parse("2.0.0")) == .lt);
268 expect(order(try parse("2.0.0"), try parse("2.1.0")) == .lt);268 try expect(order(try parse("2.0.0"), try parse("2.1.0")) == .lt);
269 expect(order(try parse("2.1.0"), try parse("2.1.1")) == .lt);269 try expect(order(try parse("2.1.0"), try parse("2.1.1")) == .lt);
270270
271 // SemVer 2 spec 11.3 example: 1.0.0-alpha < 1.0.0.271 // SemVer 2 spec 11.3 example: 1.0.0-alpha < 1.0.0.
272 expect(order(try parse("1.0.0-alpha"), try parse("1.0.0")) == .lt);272 try expect(order(try parse("1.0.0-alpha"), try parse("1.0.0")) == .lt);
273273
274 // SemVer 2 spec 11.4 example: 1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta < 1.0.0-beta <274 // SemVer 2 spec 11.4 example: 1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta < 1.0.0-beta <
275 // 1.0.0-beta.2 < 1.0.0-beta.11 < 1.0.0-rc.1 < 1.0.0.275 // 1.0.0-beta.2 < 1.0.0-beta.11 < 1.0.0-rc.1 < 1.0.0.
276 expect(order(try parse("1.0.0-alpha"), try parse("1.0.0-alpha.1")) == .lt);276 try expect(order(try parse("1.0.0-alpha"), try parse("1.0.0-alpha.1")) == .lt);
277 expect(order(try parse("1.0.0-alpha.1"), try parse("1.0.0-alpha.beta")) == .lt);277 try expect(order(try parse("1.0.0-alpha.1"), try parse("1.0.0-alpha.beta")) == .lt);
278 expect(order(try parse("1.0.0-alpha.beta"), try parse("1.0.0-beta")) == .lt);278 try expect(order(try parse("1.0.0-alpha.beta"), try parse("1.0.0-beta")) == .lt);
279 expect(order(try parse("1.0.0-beta"), try parse("1.0.0-beta.2")) == .lt);279 try expect(order(try parse("1.0.0-beta"), try parse("1.0.0-beta.2")) == .lt);
280 expect(order(try parse("1.0.0-beta.2"), try parse("1.0.0-beta.11")) == .lt);280 try expect(order(try parse("1.0.0-beta.2"), try parse("1.0.0-beta.11")) == .lt);
281 expect(order(try parse("1.0.0-beta.11"), try parse("1.0.0-rc.1")) == .lt);281 try expect(order(try parse("1.0.0-beta.11"), try parse("1.0.0-rc.1")) == .lt);
282 expect(order(try parse("1.0.0-rc.1"), try parse("1.0.0")) == .lt);282 try expect(order(try parse("1.0.0-rc.1"), try parse("1.0.0")) == .lt);
283}283}
284284
285test "zig_version" {285test "zig_version" {
lib/std/Thread/AutoResetEvent.zig+8-8
...@@ -176,7 +176,7 @@ test "basic usage" {...@@ -176,7 +176,7 @@ test "basic usage" {
176 // test local code paths176 // test local code paths
177 {177 {
178 var event = AutoResetEvent{};178 var event = AutoResetEvent{};
179 testing.expectError(error.TimedOut, event.timedWait(1));179 try testing.expectError(error.TimedOut, event.timedWait(1));
180 event.set();180 event.set();
181 event.wait();181 event.wait();
182 }182 }
...@@ -192,28 +192,28 @@ test "basic usage" {...@@ -192,28 +192,28 @@ test "basic usage" {
192192
193 const Self = @This();193 const Self = @This();
194194
195 fn sender(self: *Self) void {195 fn sender(self: *Self) !void {
196 testing.expect(self.value == 0);196 try testing.expect(self.value == 0);
197 self.value = 1;197 self.value = 1;
198 self.out.set();198 self.out.set();
199199
200 self.in.wait();200 self.in.wait();
201 testing.expect(self.value == 2);201 try testing.expect(self.value == 2);
202 self.value = 3;202 self.value = 3;
203 self.out.set();203 self.out.set();
204204
205 self.in.wait();205 self.in.wait();
206 testing.expect(self.value == 4);206 try testing.expect(self.value == 4);
207 }207 }
208208
209 fn receiver(self: *Self) void {209 fn receiver(self: *Self) !void {
210 self.out.wait();210 self.out.wait();
211 testing.expect(self.value == 1);211 try testing.expect(self.value == 1);
212 self.value = 2;212 self.value = 2;
213 self.in.set();213 self.in.set();
214214
215 self.out.wait();215 self.out.wait();
216 testing.expect(self.value == 3);216 try testing.expect(self.value == 3);
217 self.value = 4;217 self.value = 4;
218 self.in.set();218 self.in.set();
219 }219 }
lib/std/Thread/Mutex.zig+2-2
...@@ -294,7 +294,7 @@ test "basic usage" {...@@ -294,7 +294,7 @@ test "basic usage" {
294294
295 if (builtin.single_threaded) {295 if (builtin.single_threaded) {
296 worker(&context);296 worker(&context);
297 testing.expect(context.data == TestContext.incr_count);297 try testing.expect(context.data == TestContext.incr_count);
298 } else {298 } else {
299 const thread_count = 10;299 const thread_count = 10;
300 var threads: [thread_count]*std.Thread = undefined;300 var threads: [thread_count]*std.Thread = undefined;
...@@ -304,7 +304,7 @@ test "basic usage" {...@@ -304,7 +304,7 @@ test "basic usage" {
304 for (threads) |t|304 for (threads) |t|
305 t.wait();305 t.wait();
306306
307 testing.expect(context.data == thread_count * TestContext.incr_count);307 try testing.expect(context.data == thread_count * TestContext.incr_count);
308 }308 }
309}309}
310310
lib/std/Thread/ResetEvent.zig+10-10
...@@ -204,7 +204,7 @@ test "basic usage" {...@@ -204,7 +204,7 @@ test "basic usage" {
204 event.reset();204 event.reset();
205205
206 event.set();206 event.set();
207 testing.expectEqual(TimedWaitResult.event_set, event.timedWait(1));207 try testing.expectEqual(TimedWaitResult.event_set, event.timedWait(1));
208208
209 // test cross-thread signaling209 // test cross-thread signaling
210 if (builtin.single_threaded)210 if (builtin.single_threaded)
...@@ -233,25 +233,25 @@ test "basic usage" {...@@ -233,25 +233,25 @@ test "basic usage" {
233 self.* = undefined;233 self.* = undefined;
234 }234 }
235235
236 fn sender(self: *Self) void {236 fn sender(self: *Self) !void {
237 // update value and signal input237 // update value and signal input
238 testing.expect(self.value == 0);238 try testing.expect(self.value == 0);
239 self.value = 1;239 self.value = 1;
240 self.in.set();240 self.in.set();
241241
242 // wait for receiver to update value and signal output242 // wait for receiver to update value and signal output
243 self.out.wait();243 self.out.wait();
244 testing.expect(self.value == 2);244 try testing.expect(self.value == 2);
245245
246 // update value and signal final input246 // update value and signal final input
247 self.value = 3;247 self.value = 3;
248 self.in.set();248 self.in.set();
249 }249 }
250250
251 fn receiver(self: *Self) void {251 fn receiver(self: *Self) !void {
252 // wait for sender to update value and signal input252 // wait for sender to update value and signal input
253 self.in.wait();253 self.in.wait();
254 assert(self.value == 1);254 try testing.expect(self.value == 1);
255255
256 // update value and signal output256 // update value and signal output
257 self.in.reset();257 self.in.reset();
...@@ -260,7 +260,7 @@ test "basic usage" {...@@ -260,7 +260,7 @@ test "basic usage" {
260260
261 // wait for sender to update value and signal final input261 // wait for sender to update value and signal final input
262 self.in.wait();262 self.in.wait();
263 assert(self.value == 3);263 try testing.expect(self.value == 3);
264 }264 }
265265
266 fn sleeper(self: *Self) void {266 fn sleeper(self: *Self) void {
...@@ -272,9 +272,9 @@ test "basic usage" {...@@ -272,9 +272,9 @@ test "basic usage" {
272272
273 fn timedWaiter(self: *Self) !void {273 fn timedWaiter(self: *Self) !void {
274 self.in.wait();274 self.in.wait();
275 testing.expectEqual(TimedWaitResult.timed_out, self.out.timedWait(time.ns_per_us));275 try testing.expectEqual(TimedWaitResult.timed_out, self.out.timedWait(time.ns_per_us));
276 try self.out.timedWait(time.ns_per_ms * 100);276 try self.out.timedWait(time.ns_per_ms * 100);
277 testing.expect(self.value == 5);277 try testing.expect(self.value == 5);
278 }278 }
279 };279 };
280280
...@@ -283,7 +283,7 @@ test "basic usage" {...@@ -283,7 +283,7 @@ test "basic usage" {
283 defer context.deinit();283 defer context.deinit();
284 const receiver = try std.Thread.spawn(Context.receiver, &context);284 const receiver = try std.Thread.spawn(Context.receiver, &context);
285 defer receiver.wait();285 defer receiver.wait();
286 context.sender();286 try context.sender();
287287
288 if (false) {288 if (false) {
289 // I have now observed this fail on macOS, Windows, and Linux.289 // I have now observed this fail on macOS, Windows, and Linux.
lib/std/Thread/StaticResetEvent.zig+10-10
...@@ -320,7 +320,7 @@ test "basic usage" {...@@ -320,7 +320,7 @@ test "basic usage" {
320 event.reset();320 event.reset();
321321
322 event.set();322 event.set();
323 testing.expectEqual(TimedWaitResult.event_set, event.timedWait(1));323 try testing.expectEqual(TimedWaitResult.event_set, event.timedWait(1));
324324
325 // test cross-thread signaling325 // test cross-thread signaling
326 if (std.builtin.single_threaded)326 if (std.builtin.single_threaded)
...@@ -333,25 +333,25 @@ test "basic usage" {...@@ -333,25 +333,25 @@ test "basic usage" {
333 in: StaticResetEvent = .{},333 in: StaticResetEvent = .{},
334 out: StaticResetEvent = .{},334 out: StaticResetEvent = .{},
335335
336 fn sender(self: *Self) void {336 fn sender(self: *Self) !void {
337 // update value and signal input337 // update value and signal input
338 testing.expect(self.value == 0);338 try testing.expect(self.value == 0);
339 self.value = 1;339 self.value = 1;
340 self.in.set();340 self.in.set();
341341
342 // wait for receiver to update value and signal output342 // wait for receiver to update value and signal output
343 self.out.wait();343 self.out.wait();
344 testing.expect(self.value == 2);344 try testing.expect(self.value == 2);
345345
346 // update value and signal final input346 // update value and signal final input
347 self.value = 3;347 self.value = 3;
348 self.in.set();348 self.in.set();
349 }349 }
350350
351 fn receiver(self: *Self) void {351 fn receiver(self: *Self) !void {
352 // wait for sender to update value and signal input352 // wait for sender to update value and signal input
353 self.in.wait();353 self.in.wait();
354 assert(self.value == 1);354 try testing.expect(self.value == 1);
355355
356 // update value and signal output356 // update value and signal output
357 self.in.reset();357 self.in.reset();
...@@ -360,7 +360,7 @@ test "basic usage" {...@@ -360,7 +360,7 @@ test "basic usage" {
360360
361 // wait for sender to update value and signal final input361 // wait for sender to update value and signal final input
362 self.in.wait();362 self.in.wait();
363 assert(self.value == 3);363 try testing.expect(self.value == 3);
364 }364 }
365365
366 fn sleeper(self: *Self) void {366 fn sleeper(self: *Self) void {
...@@ -372,16 +372,16 @@ test "basic usage" {...@@ -372,16 +372,16 @@ test "basic usage" {
372372
373 fn timedWaiter(self: *Self) !void {373 fn timedWaiter(self: *Self) !void {
374 self.in.wait();374 self.in.wait();
375 testing.expectEqual(TimedWaitResult.timed_out, self.out.timedWait(time.ns_per_us));375 try testing.expectEqual(TimedWaitResult.timed_out, self.out.timedWait(time.ns_per_us));
376 try self.out.timedWait(time.ns_per_ms * 100);376 try self.out.timedWait(time.ns_per_ms * 100);
377 testing.expect(self.value == 5);377 try testing.expect(self.value == 5);
378 }378 }
379 };379 };
380380
381 var context = Context{};381 var context = Context{};
382 const receiver = try std.Thread.spawn(Context.receiver, &context);382 const receiver = try std.Thread.spawn(Context.receiver, &context);
383 defer receiver.wait();383 defer receiver.wait();
384 context.sender();384 try context.sender();
385385
386 if (false) {386 if (false) {
387 // I have now observed this fail on macOS, Windows, and Linux.387 // I have now observed this fail on macOS, Windows, and Linux.
lib/std/array_hash_map.zig+68-68
...@@ -1064,63 +1064,63 @@ test "basic hash map usage" {...@@ -1064,63 +1064,63 @@ test "basic hash map usage" {
1064 var map = AutoArrayHashMap(i32, i32).init(std.testing.allocator);1064 var map = AutoArrayHashMap(i32, i32).init(std.testing.allocator);
1065 defer map.deinit();1065 defer map.deinit();
10661066
1067 testing.expect((try map.fetchPut(1, 11)) == null);1067 try testing.expect((try map.fetchPut(1, 11)) == null);
1068 testing.expect((try map.fetchPut(2, 22)) == null);1068 try testing.expect((try map.fetchPut(2, 22)) == null);
1069 testing.expect((try map.fetchPut(3, 33)) == null);1069 try testing.expect((try map.fetchPut(3, 33)) == null);
1070 testing.expect((try map.fetchPut(4, 44)) == null);1070 try testing.expect((try map.fetchPut(4, 44)) == null);
10711071
1072 try map.putNoClobber(5, 55);1072 try map.putNoClobber(5, 55);
1073 testing.expect((try map.fetchPut(5, 66)).?.value == 55);1073 try testing.expect((try map.fetchPut(5, 66)).?.value == 55);
1074 testing.expect((try map.fetchPut(5, 55)).?.value == 66);1074 try testing.expect((try map.fetchPut(5, 55)).?.value == 66);
10751075
1076 const gop1 = try map.getOrPut(5);1076 const gop1 = try map.getOrPut(5);
1077 testing.expect(gop1.found_existing == true);1077 try testing.expect(gop1.found_existing == true);
1078 testing.expect(gop1.entry.value == 55);1078 try testing.expect(gop1.entry.value == 55);
1079 testing.expect(gop1.index == 4);1079 try testing.expect(gop1.index == 4);
1080 gop1.entry.value = 77;1080 gop1.entry.value = 77;
1081 testing.expect(map.getEntry(5).?.value == 77);1081 try testing.expect(map.getEntry(5).?.value == 77);
10821082
1083 const gop2 = try map.getOrPut(99);1083 const gop2 = try map.getOrPut(99);
1084 testing.expect(gop2.found_existing == false);1084 try testing.expect(gop2.found_existing == false);
1085 testing.expect(gop2.index == 5);1085 try testing.expect(gop2.index == 5);
1086 gop2.entry.value = 42;1086 gop2.entry.value = 42;
1087 testing.expect(map.getEntry(99).?.value == 42);1087 try testing.expect(map.getEntry(99).?.value == 42);
10881088
1089 const gop3 = try map.getOrPutValue(5, 5);1089 const gop3 = try map.getOrPutValue(5, 5);
1090 testing.expect(gop3.value == 77);1090 try testing.expect(gop3.value == 77);
10911091
1092 const gop4 = try map.getOrPutValue(100, 41);1092 const gop4 = try map.getOrPutValue(100, 41);
1093 testing.expect(gop4.value == 41);1093 try testing.expect(gop4.value == 41);
10941094
1095 testing.expect(map.contains(2));1095 try testing.expect(map.contains(2));
1096 testing.expect(map.getEntry(2).?.value == 22);1096 try testing.expect(map.getEntry(2).?.value == 22);
1097 testing.expect(map.get(2).? == 22);1097 try testing.expect(map.get(2).? == 22);
10981098
1099 const rmv1 = map.swapRemove(2);1099 const rmv1 = map.swapRemove(2);
1100 testing.expect(rmv1.?.key == 2);1100 try testing.expect(rmv1.?.key == 2);
1101 testing.expect(rmv1.?.value == 22);1101 try testing.expect(rmv1.?.value == 22);
1102 testing.expect(map.swapRemove(2) == null);1102 try testing.expect(map.swapRemove(2) == null);
1103 testing.expect(map.getEntry(2) == null);1103 try testing.expect(map.getEntry(2) == null);
1104 testing.expect(map.get(2) == null);1104 try testing.expect(map.get(2) == null);
11051105
1106 // Since we've used `swapRemove` above, the index of this entry should remain unchanged.1106 // Since we've used `swapRemove` above, the index of this entry should remain unchanged.
1107 testing.expect(map.getIndex(100).? == 1);1107 try testing.expect(map.getIndex(100).? == 1);
1108 const gop5 = try map.getOrPut(5);1108 const gop5 = try map.getOrPut(5);
1109 testing.expect(gop5.found_existing == true);1109 try testing.expect(gop5.found_existing == true);
1110 testing.expect(gop5.entry.value == 77);1110 try testing.expect(gop5.entry.value == 77);
1111 testing.expect(gop5.index == 4);1111 try testing.expect(gop5.index == 4);
11121112
1113 // Whereas, if we do an `orderedRemove`, it should move the index forward one spot.1113 // Whereas, if we do an `orderedRemove`, it should move the index forward one spot.
1114 const rmv2 = map.orderedRemove(100);1114 const rmv2 = map.orderedRemove(100);
1115 testing.expect(rmv2.?.key == 100);1115 try testing.expect(rmv2.?.key == 100);
1116 testing.expect(rmv2.?.value == 41);1116 try testing.expect(rmv2.?.value == 41);
1117 testing.expect(map.orderedRemove(100) == null);1117 try testing.expect(map.orderedRemove(100) == null);
1118 testing.expect(map.getEntry(100) == null);1118 try testing.expect(map.getEntry(100) == null);
1119 testing.expect(map.get(100) == null);1119 try testing.expect(map.get(100) == null);
1120 const gop6 = try map.getOrPut(5);1120 const gop6 = try map.getOrPut(5);
1121 testing.expect(gop6.found_existing == true);1121 try testing.expect(gop6.found_existing == true);
1122 testing.expect(gop6.entry.value == 77);1122 try testing.expect(gop6.entry.value == 77);
1123 testing.expect(gop6.index == 3);1123 try testing.expect(gop6.index == 3);
11241124
1125 map.removeAssertDiscard(3);1125 map.removeAssertDiscard(3);
1126}1126}
...@@ -1156,11 +1156,11 @@ test "iterator hash map" {...@@ -1156,11 +1156,11 @@ test "iterator hash map" {
1156 while (it.next()) |entry| : (count += 1) {1156 while (it.next()) |entry| : (count += 1) {
1157 buffer[@intCast(usize, entry.key)] = entry.value;1157 buffer[@intCast(usize, entry.key)] = entry.value;
1158 }1158 }
1159 testing.expect(count == 3);1159 try testing.expect(count == 3);
1160 testing.expect(it.next() == null);1160 try testing.expect(it.next() == null);
11611161
1162 for (buffer) |v, i| {1162 for (buffer) |v, i| {
1163 testing.expect(buffer[@intCast(usize, keys[i])] == values[i]);1163 try testing.expect(buffer[@intCast(usize, keys[i])] == values[i]);
1164 }1164 }
11651165
1166 it.reset();1166 it.reset();
...@@ -1172,13 +1172,13 @@ test "iterator hash map" {...@@ -1172,13 +1172,13 @@ test "iterator hash map" {
1172 }1172 }
11731173
1174 for (buffer[0..2]) |v, i| {1174 for (buffer[0..2]) |v, i| {
1175 testing.expect(buffer[@intCast(usize, keys[i])] == values[i]);1175 try testing.expect(buffer[@intCast(usize, keys[i])] == values[i]);
1176 }1176 }
11771177
1178 it.reset();1178 it.reset();
1179 var entry = it.next().?;1179 var entry = it.next().?;
1180 testing.expect(entry.key == first_entry.key);1180 try testing.expect(entry.key == first_entry.key);
1181 testing.expect(entry.value == first_entry.value);1181 try testing.expect(entry.value == first_entry.value);
1182}1182}
11831183
1184test "ensure capacity" {1184test "ensure capacity" {
...@@ -1187,13 +1187,13 @@ test "ensure capacity" {...@@ -1187,13 +1187,13 @@ test "ensure capacity" {
11871187
1188 try map.ensureCapacity(20);1188 try map.ensureCapacity(20);
1189 const initial_capacity = map.capacity();1189 const initial_capacity = map.capacity();
1190 testing.expect(initial_capacity >= 20);1190 try testing.expect(initial_capacity >= 20);
1191 var i: i32 = 0;1191 var i: i32 = 0;
1192 while (i < 20) : (i += 1) {1192 while (i < 20) : (i += 1) {
1193 testing.expect(map.fetchPutAssumeCapacity(i, i + 10) == null);1193 try testing.expect(map.fetchPutAssumeCapacity(i, i + 10) == null);
1194 }1194 }
1195 // shouldn't resize from putAssumeCapacity1195 // shouldn't resize from putAssumeCapacity
1196 testing.expect(initial_capacity == map.capacity());1196 try testing.expect(initial_capacity == map.capacity());
1197}1197}
11981198
1199test "clone" {1199test "clone" {
...@@ -1211,7 +1211,7 @@ test "clone" {...@@ -1211,7 +1211,7 @@ test "clone" {
12111211
1212 i = 0;1212 i = 0;
1213 while (i < 10) : (i += 1) {1213 while (i < 10) : (i += 1) {
1214 testing.expect(copy.get(i).? == i * 10);1214 try testing.expect(copy.get(i).? == i * 10);
1215 }1215 }
1216}1216}
12171217
...@@ -1223,35 +1223,35 @@ test "shrink" {...@@ -1223,35 +1223,35 @@ test "shrink" {
1223 const num_entries = 20;1223 const num_entries = 20;
1224 var i: i32 = 0;1224 var i: i32 = 0;
1225 while (i < num_entries) : (i += 1)1225 while (i < num_entries) : (i += 1)
1226 testing.expect((try map.fetchPut(i, i * 10)) == null);1226 try testing.expect((try map.fetchPut(i, i * 10)) == null);
12271227
1228 testing.expect(map.unmanaged.index_header != null);1228 try testing.expect(map.unmanaged.index_header != null);
1229 testing.expect(map.count() == num_entries);1229 try testing.expect(map.count() == num_entries);
12301230
1231 // Test `shrinkRetainingCapacity`.1231 // Test `shrinkRetainingCapacity`.
1232 map.shrinkRetainingCapacity(17);1232 map.shrinkRetainingCapacity(17);
1233 testing.expect(map.count() == 17);1233 try testing.expect(map.count() == 17);
1234 testing.expect(map.capacity() == 20);1234 try testing.expect(map.capacity() == 20);
1235 i = 0;1235 i = 0;
1236 while (i < num_entries) : (i += 1) {1236 while (i < num_entries) : (i += 1) {
1237 const gop = try map.getOrPut(i);1237 const gop = try map.getOrPut(i);
1238 if (i < 17) {1238 if (i < 17) {
1239 testing.expect(gop.found_existing == true);1239 try testing.expect(gop.found_existing == true);
1240 testing.expect(gop.entry.value == i * 10);1240 try testing.expect(gop.entry.value == i * 10);
1241 } else testing.expect(gop.found_existing == false);1241 } else try testing.expect(gop.found_existing == false);
1242 }1242 }
12431243
1244 // Test `shrinkAndFree`.1244 // Test `shrinkAndFree`.
1245 map.shrinkAndFree(15);1245 map.shrinkAndFree(15);
1246 testing.expect(map.count() == 15);1246 try testing.expect(map.count() == 15);
1247 testing.expect(map.capacity() == 15);1247 try testing.expect(map.capacity() == 15);
1248 i = 0;1248 i = 0;
1249 while (i < num_entries) : (i += 1) {1249 while (i < num_entries) : (i += 1) {
1250 const gop = try map.getOrPut(i);1250 const gop = try map.getOrPut(i);
1251 if (i < 15) {1251 if (i < 15) {
1252 testing.expect(gop.found_existing == true);1252 try testing.expect(gop.found_existing == true);
1253 testing.expect(gop.entry.value == i * 10);1253 try testing.expect(gop.entry.value == i * 10);
1254 } else testing.expect(gop.found_existing == false);1254 } else try testing.expect(gop.found_existing == false);
1255 }1255 }
1256}1256}
12571257
...@@ -1264,12 +1264,12 @@ test "pop" {...@@ -1264,12 +1264,12 @@ test "pop" {
12641264
1265 var i: i32 = 0;1265 var i: i32 = 0;
1266 while (i < 9) : (i += 1) {1266 while (i < 9) : (i += 1) {
1267 testing.expect((try map.fetchPut(i, i)) == null);1267 try testing.expect((try map.fetchPut(i, i)) == null);
1268 }1268 }
12691269
1270 while (i > 0) : (i -= 1) {1270 while (i > 0) : (i -= 1) {
1271 const pop = map.pop();1271 const pop = map.pop();
1272 testing.expect(pop.key == i - 1 and pop.value == i - 1);1272 try testing.expect(pop.key == i - 1 and pop.value == i - 1);
1273 }1273 }
1274}1274}
12751275
...@@ -1281,10 +1281,10 @@ test "reIndex" {...@@ -1281,10 +1281,10 @@ test "reIndex" {
1281 const num_indexed_entries = 20;1281 const num_indexed_entries = 20;
1282 var i: i32 = 0;1282 var i: i32 = 0;
1283 while (i < num_indexed_entries) : (i += 1)1283 while (i < num_indexed_entries) : (i += 1)
1284 testing.expect((try map.fetchPut(i, i * 10)) == null);1284 try testing.expect((try map.fetchPut(i, i * 10)) == null);
12851285
1286 // Make sure we allocated an index header.1286 // Make sure we allocated an index header.
1287 testing.expect(map.unmanaged.index_header != null);1287 try testing.expect(map.unmanaged.index_header != null);
12881288
1289 // Now write to the underlying array list directly.1289 // Now write to the underlying array list directly.
1290 const num_unindexed_entries = 20;1290 const num_unindexed_entries = 20;
...@@ -1303,9 +1303,9 @@ test "reIndex" {...@@ -1303,9 +1303,9 @@ test "reIndex" {
1303 i = 0;1303 i = 0;
1304 while (i < num_indexed_entries + num_unindexed_entries) : (i += 1) {1304 while (i < num_indexed_entries + num_unindexed_entries) : (i += 1) {
1305 const gop = try map.getOrPut(i);1305 const gop = try map.getOrPut(i);
1306 testing.expect(gop.found_existing == true);1306 try testing.expect(gop.found_existing == true);
1307 testing.expect(gop.entry.value == i * 10);1307 try testing.expect(gop.entry.value == i * 10);
1308 testing.expect(gop.index == i);1308 try testing.expect(gop.index == i);
1309 }1309 }
1310}1310}
13111311
...@@ -1332,9 +1332,9 @@ test "fromOwnedArrayList" {...@@ -1332,9 +1332,9 @@ test "fromOwnedArrayList" {
1332 i = 0;1332 i = 0;
1333 while (i < num_entries) : (i += 1) {1333 while (i < num_entries) : (i += 1) {
1334 const gop = try map.getOrPut(i);1334 const gop = try map.getOrPut(i);
1335 testing.expect(gop.found_existing == true);1335 try testing.expect(gop.found_existing == true);
1336 testing.expect(gop.entry.value == i * 10);1336 try testing.expect(gop.entry.value == i * 10);
1337 testing.expect(gop.index == i);1337 try testing.expect(gop.index == i);
1338 }1338 }
1339}1339}
13401340
lib/std/array_list.zig+116-116
...@@ -695,15 +695,15 @@ test "std.ArrayList/ArrayListUnmanaged.init" {...@@ -695,15 +695,15 @@ test "std.ArrayList/ArrayListUnmanaged.init" {
695 var list = ArrayList(i32).init(testing.allocator);695 var list = ArrayList(i32).init(testing.allocator);
696 defer list.deinit();696 defer list.deinit();
697697
698 testing.expect(list.items.len == 0);698 try testing.expect(list.items.len == 0);
699 testing.expect(list.capacity == 0);699 try testing.expect(list.capacity == 0);
700 }700 }
701701
702 {702 {
703 var list = ArrayListUnmanaged(i32){};703 var list = ArrayListUnmanaged(i32){};
704704
705 testing.expect(list.items.len == 0);705 try testing.expect(list.items.len == 0);
706 testing.expect(list.capacity == 0);706 try testing.expect(list.capacity == 0);
707 }707 }
708}708}
709709
...@@ -712,14 +712,14 @@ test "std.ArrayList/ArrayListUnmanaged.initCapacity" {...@@ -712,14 +712,14 @@ test "std.ArrayList/ArrayListUnmanaged.initCapacity" {
712 {712 {
713 var list = try ArrayList(i8).initCapacity(a, 200);713 var list = try ArrayList(i8).initCapacity(a, 200);
714 defer list.deinit();714 defer list.deinit();
715 testing.expect(list.items.len == 0);715 try testing.expect(list.items.len == 0);
716 testing.expect(list.capacity >= 200);716 try testing.expect(list.capacity >= 200);
717 }717 }
718 {718 {
719 var list = try ArrayListUnmanaged(i8).initCapacity(a, 200);719 var list = try ArrayListUnmanaged(i8).initCapacity(a, 200);
720 defer list.deinit(a);720 defer list.deinit(a);
721 testing.expect(list.items.len == 0);721 try testing.expect(list.items.len == 0);
722 testing.expect(list.capacity >= 200);722 try testing.expect(list.capacity >= 200);
723 }723 }
724}724}
725725
...@@ -739,33 +739,33 @@ test "std.ArrayList/ArrayListUnmanaged.basic" {...@@ -739,33 +739,33 @@ test "std.ArrayList/ArrayListUnmanaged.basic" {
739 {739 {
740 var i: usize = 0;740 var i: usize = 0;
741 while (i < 10) : (i += 1) {741 while (i < 10) : (i += 1) {
742 testing.expect(list.items[i] == @intCast(i32, i + 1));742 try testing.expect(list.items[i] == @intCast(i32, i + 1));
743 }743 }
744 }744 }
745745
746 for (list.items) |v, i| {746 for (list.items) |v, i| {
747 testing.expect(v == @intCast(i32, i + 1));747 try testing.expect(v == @intCast(i32, i + 1));
748 }748 }
749749
750 testing.expect(list.pop() == 10);750 try testing.expect(list.pop() == 10);
751 testing.expect(list.items.len == 9);751 try testing.expect(list.items.len == 9);
752752
753 list.appendSlice(&[_]i32{ 1, 2, 3 }) catch unreachable;753 list.appendSlice(&[_]i32{ 1, 2, 3 }) catch unreachable;
754 testing.expect(list.items.len == 12);754 try testing.expect(list.items.len == 12);
755 testing.expect(list.pop() == 3);755 try testing.expect(list.pop() == 3);
756 testing.expect(list.pop() == 2);756 try testing.expect(list.pop() == 2);
757 testing.expect(list.pop() == 1);757 try testing.expect(list.pop() == 1);
758 testing.expect(list.items.len == 9);758 try testing.expect(list.items.len == 9);
759759
760 list.appendSlice(&[_]i32{}) catch unreachable;760 list.appendSlice(&[_]i32{}) catch unreachable;
761 testing.expect(list.items.len == 9);761 try testing.expect(list.items.len == 9);
762762
763 // can only set on indices < self.items.len763 // can only set on indices < self.items.len
764 list.items[7] = 33;764 list.items[7] = 33;
765 list.items[8] = 42;765 list.items[8] = 42;
766766
767 testing.expect(list.pop() == 42);767 try testing.expect(list.pop() == 42);
768 testing.expect(list.pop() == 33);768 try testing.expect(list.pop() == 33);
769 }769 }
770 {770 {
771 var list = ArrayListUnmanaged(i32){};771 var list = ArrayListUnmanaged(i32){};
...@@ -781,33 +781,33 @@ test "std.ArrayList/ArrayListUnmanaged.basic" {...@@ -781,33 +781,33 @@ test "std.ArrayList/ArrayListUnmanaged.basic" {
781 {781 {
782 var i: usize = 0;782 var i: usize = 0;
783 while (i < 10) : (i += 1) {783 while (i < 10) : (i += 1) {
784 testing.expect(list.items[i] == @intCast(i32, i + 1));784 try testing.expect(list.items[i] == @intCast(i32, i + 1));
785 }785 }
786 }786 }
787787
788 for (list.items) |v, i| {788 for (list.items) |v, i| {
789 testing.expect(v == @intCast(i32, i + 1));789 try testing.expect(v == @intCast(i32, i + 1));
790 }790 }
791791
792 testing.expect(list.pop() == 10);792 try testing.expect(list.pop() == 10);
793 testing.expect(list.items.len == 9);793 try testing.expect(list.items.len == 9);
794794
795 list.appendSlice(a, &[_]i32{ 1, 2, 3 }) catch unreachable;795 list.appendSlice(a, &[_]i32{ 1, 2, 3 }) catch unreachable;
796 testing.expect(list.items.len == 12);796 try testing.expect(list.items.len == 12);
797 testing.expect(list.pop() == 3);797 try testing.expect(list.pop() == 3);
798 testing.expect(list.pop() == 2);798 try testing.expect(list.pop() == 2);
799 testing.expect(list.pop() == 1);799 try testing.expect(list.pop() == 1);
800 testing.expect(list.items.len == 9);800 try testing.expect(list.items.len == 9);
801801
802 list.appendSlice(a, &[_]i32{}) catch unreachable;802 list.appendSlice(a, &[_]i32{}) catch unreachable;
803 testing.expect(list.items.len == 9);803 try testing.expect(list.items.len == 9);
804804
805 // can only set on indices < self.items.len805 // can only set on indices < self.items.len
806 list.items[7] = 33;806 list.items[7] = 33;
807 list.items[8] = 42;807 list.items[8] = 42;
808808
809 testing.expect(list.pop() == 42);809 try testing.expect(list.pop() == 42);
810 testing.expect(list.pop() == 33);810 try testing.expect(list.pop() == 33);
811 }811 }
812}812}
813813
...@@ -818,9 +818,9 @@ test "std.ArrayList/ArrayListUnmanaged.appendNTimes" {...@@ -818,9 +818,9 @@ test "std.ArrayList/ArrayListUnmanaged.appendNTimes" {
818 defer list.deinit();818 defer list.deinit();
819819
820 try list.appendNTimes(2, 10);820 try list.appendNTimes(2, 10);
821 testing.expectEqual(@as(usize, 10), list.items.len);821 try testing.expectEqual(@as(usize, 10), list.items.len);
822 for (list.items) |element| {822 for (list.items) |element| {
823 testing.expectEqual(@as(i32, 2), element);823 try testing.expectEqual(@as(i32, 2), element);
824 }824 }
825 }825 }
826 {826 {
...@@ -828,9 +828,9 @@ test "std.ArrayList/ArrayListUnmanaged.appendNTimes" {...@@ -828,9 +828,9 @@ test "std.ArrayList/ArrayListUnmanaged.appendNTimes" {
828 defer list.deinit(a);828 defer list.deinit(a);
829829
830 try list.appendNTimes(a, 2, 10);830 try list.appendNTimes(a, 2, 10);
831 testing.expectEqual(@as(usize, 10), list.items.len);831 try testing.expectEqual(@as(usize, 10), list.items.len);
832 for (list.items) |element| {832 for (list.items) |element| {
833 testing.expectEqual(@as(i32, 2), element);833 try testing.expectEqual(@as(i32, 2), element);
834 }834 }
835 }835 }
836}836}
...@@ -840,12 +840,12 @@ test "std.ArrayList/ArrayListUnmanaged.appendNTimes with failing allocator" {...@@ -840,12 +840,12 @@ test "std.ArrayList/ArrayListUnmanaged.appendNTimes with failing allocator" {
840 {840 {
841 var list = ArrayList(i32).init(a);841 var list = ArrayList(i32).init(a);
842 defer list.deinit();842 defer list.deinit();
843 testing.expectError(error.OutOfMemory, list.appendNTimes(2, 10));843 try testing.expectError(error.OutOfMemory, list.appendNTimes(2, 10));
844 }844 }
845 {845 {
846 var list = ArrayListUnmanaged(i32){};846 var list = ArrayListUnmanaged(i32){};
847 defer list.deinit(a);847 defer list.deinit(a);
848 testing.expectError(error.OutOfMemory, list.appendNTimes(a, 2, 10));848 try testing.expectError(error.OutOfMemory, list.appendNTimes(a, 2, 10));
849 }849 }
850}850}
851851
...@@ -864,18 +864,18 @@ test "std.ArrayList/ArrayListUnmanaged.orderedRemove" {...@@ -864,18 +864,18 @@ test "std.ArrayList/ArrayListUnmanaged.orderedRemove" {
864 try list.append(7);864 try list.append(7);
865865
866 //remove from middle866 //remove from middle
867 testing.expectEqual(@as(i32, 4), list.orderedRemove(3));867 try testing.expectEqual(@as(i32, 4), list.orderedRemove(3));
868 testing.expectEqual(@as(i32, 5), list.items[3]);868 try testing.expectEqual(@as(i32, 5), list.items[3]);
869 testing.expectEqual(@as(usize, 6), list.items.len);869 try testing.expectEqual(@as(usize, 6), list.items.len);
870870
871 //remove from end871 //remove from end
872 testing.expectEqual(@as(i32, 7), list.orderedRemove(5));872 try testing.expectEqual(@as(i32, 7), list.orderedRemove(5));
873 testing.expectEqual(@as(usize, 5), list.items.len);873 try testing.expectEqual(@as(usize, 5), list.items.len);
874874
875 //remove from front875 //remove from front
876 testing.expectEqual(@as(i32, 1), list.orderedRemove(0));876 try testing.expectEqual(@as(i32, 1), list.orderedRemove(0));
877 testing.expectEqual(@as(i32, 2), list.items[0]);877 try testing.expectEqual(@as(i32, 2), list.items[0]);
878 testing.expectEqual(@as(usize, 4), list.items.len);878 try testing.expectEqual(@as(usize, 4), list.items.len);
879 }879 }
880 {880 {
881 var list = ArrayListUnmanaged(i32){};881 var list = ArrayListUnmanaged(i32){};
...@@ -890,18 +890,18 @@ test "std.ArrayList/ArrayListUnmanaged.orderedRemove" {...@@ -890,18 +890,18 @@ test "std.ArrayList/ArrayListUnmanaged.orderedRemove" {
890 try list.append(a, 7);890 try list.append(a, 7);
891891
892 //remove from middle892 //remove from middle
893 testing.expectEqual(@as(i32, 4), list.orderedRemove(3));893 try testing.expectEqual(@as(i32, 4), list.orderedRemove(3));
894 testing.expectEqual(@as(i32, 5), list.items[3]);894 try testing.expectEqual(@as(i32, 5), list.items[3]);
895 testing.expectEqual(@as(usize, 6), list.items.len);895 try testing.expectEqual(@as(usize, 6), list.items.len);
896896
897 //remove from end897 //remove from end
898 testing.expectEqual(@as(i32, 7), list.orderedRemove(5));898 try testing.expectEqual(@as(i32, 7), list.orderedRemove(5));
899 testing.expectEqual(@as(usize, 5), list.items.len);899 try testing.expectEqual(@as(usize, 5), list.items.len);
900900
901 //remove from front901 //remove from front
902 testing.expectEqual(@as(i32, 1), list.orderedRemove(0));902 try testing.expectEqual(@as(i32, 1), list.orderedRemove(0));
903 testing.expectEqual(@as(i32, 2), list.items[0]);903 try testing.expectEqual(@as(i32, 2), list.items[0]);
904 testing.expectEqual(@as(usize, 4), list.items.len);904 try testing.expectEqual(@as(usize, 4), list.items.len);
905 }905 }
906}906}
907907
...@@ -920,18 +920,18 @@ test "std.ArrayList/ArrayListUnmanaged.swapRemove" {...@@ -920,18 +920,18 @@ test "std.ArrayList/ArrayListUnmanaged.swapRemove" {
920 try list.append(7);920 try list.append(7);
921921
922 //remove from middle922 //remove from middle
923 testing.expect(list.swapRemove(3) == 4);923 try testing.expect(list.swapRemove(3) == 4);
924 testing.expect(list.items[3] == 7);924 try testing.expect(list.items[3] == 7);
925 testing.expect(list.items.len == 6);925 try testing.expect(list.items.len == 6);
926926
927 //remove from end927 //remove from end
928 testing.expect(list.swapRemove(5) == 6);928 try testing.expect(list.swapRemove(5) == 6);
929 testing.expect(list.items.len == 5);929 try testing.expect(list.items.len == 5);
930930
931 //remove from front931 //remove from front
932 testing.expect(list.swapRemove(0) == 1);932 try testing.expect(list.swapRemove(0) == 1);
933 testing.expect(list.items[0] == 5);933 try testing.expect(list.items[0] == 5);
934 testing.expect(list.items.len == 4);934 try testing.expect(list.items.len == 4);
935 }935 }
936 {936 {
937 var list = ArrayListUnmanaged(i32){};937 var list = ArrayListUnmanaged(i32){};
...@@ -946,18 +946,18 @@ test "std.ArrayList/ArrayListUnmanaged.swapRemove" {...@@ -946,18 +946,18 @@ test "std.ArrayList/ArrayListUnmanaged.swapRemove" {
946 try list.append(a, 7);946 try list.append(a, 7);
947947
948 //remove from middle948 //remove from middle
949 testing.expect(list.swapRemove(3) == 4);949 try testing.expect(list.swapRemove(3) == 4);
950 testing.expect(list.items[3] == 7);950 try testing.expect(list.items[3] == 7);
951 testing.expect(list.items.len == 6);951 try testing.expect(list.items.len == 6);
952952
953 //remove from end953 //remove from end
954 testing.expect(list.swapRemove(5) == 6);954 try testing.expect(list.swapRemove(5) == 6);
955 testing.expect(list.items.len == 5);955 try testing.expect(list.items.len == 5);
956956
957 //remove from front957 //remove from front
958 testing.expect(list.swapRemove(0) == 1);958 try testing.expect(list.swapRemove(0) == 1);
959 testing.expect(list.items[0] == 5);959 try testing.expect(list.items[0] == 5);
960 testing.expect(list.items.len == 4);960 try testing.expect(list.items.len == 4);
961 }961 }
962}962}
963963
...@@ -971,10 +971,10 @@ test "std.ArrayList/ArrayListUnmanaged.insert" {...@@ -971,10 +971,10 @@ test "std.ArrayList/ArrayListUnmanaged.insert" {
971 try list.append(2);971 try list.append(2);
972 try list.append(3);972 try list.append(3);
973 try list.insert(0, 5);973 try list.insert(0, 5);
974 testing.expect(list.items[0] == 5);974 try testing.expect(list.items[0] == 5);
975 testing.expect(list.items[1] == 1);975 try testing.expect(list.items[1] == 1);
976 testing.expect(list.items[2] == 2);976 try testing.expect(list.items[2] == 2);
977 testing.expect(list.items[3] == 3);977 try testing.expect(list.items[3] == 3);
978 }978 }
979 {979 {
980 var list = ArrayListUnmanaged(i32){};980 var list = ArrayListUnmanaged(i32){};
...@@ -984,10 +984,10 @@ test "std.ArrayList/ArrayListUnmanaged.insert" {...@@ -984,10 +984,10 @@ test "std.ArrayList/ArrayListUnmanaged.insert" {
984 try list.append(a, 2);984 try list.append(a, 2);
985 try list.append(a, 3);985 try list.append(a, 3);
986 try list.insert(a, 0, 5);986 try list.insert(a, 0, 5);
987 testing.expect(list.items[0] == 5);987 try testing.expect(list.items[0] == 5);
988 testing.expect(list.items[1] == 1);988 try testing.expect(list.items[1] == 1);
989 testing.expect(list.items[2] == 2);989 try testing.expect(list.items[2] == 2);
990 testing.expect(list.items[3] == 3);990 try testing.expect(list.items[3] == 3);
991 }991 }
992}992}
993993
...@@ -1002,17 +1002,17 @@ test "std.ArrayList/ArrayListUnmanaged.insertSlice" {...@@ -1002,17 +1002,17 @@ test "std.ArrayList/ArrayListUnmanaged.insertSlice" {
1002 try list.append(3);1002 try list.append(3);
1003 try list.append(4);1003 try list.append(4);
1004 try list.insertSlice(1, &[_]i32{ 9, 8 });1004 try list.insertSlice(1, &[_]i32{ 9, 8 });
1005 testing.expect(list.items[0] == 1);1005 try testing.expect(list.items[0] == 1);
1006 testing.expect(list.items[1] == 9);1006 try testing.expect(list.items[1] == 9);
1007 testing.expect(list.items[2] == 8);1007 try testing.expect(list.items[2] == 8);
1008 testing.expect(list.items[3] == 2);1008 try testing.expect(list.items[3] == 2);
1009 testing.expect(list.items[4] == 3);1009 try testing.expect(list.items[4] == 3);
1010 testing.expect(list.items[5] == 4);1010 try testing.expect(list.items[5] == 4);
10111011
1012 const items = [_]i32{1};1012 const items = [_]i32{1};
1013 try list.insertSlice(0, items[0..0]);1013 try list.insertSlice(0, items[0..0]);
1014 testing.expect(list.items.len == 6);1014 try testing.expect(list.items.len == 6);
1015 testing.expect(list.items[0] == 1);1015 try testing.expect(list.items[0] == 1);
1016 }1016 }
1017 {1017 {
1018 var list = ArrayListUnmanaged(i32){};1018 var list = ArrayListUnmanaged(i32){};
...@@ -1023,17 +1023,17 @@ test "std.ArrayList/ArrayListUnmanaged.insertSlice" {...@@ -1023,17 +1023,17 @@ test "std.ArrayList/ArrayListUnmanaged.insertSlice" {
1023 try list.append(a, 3);1023 try list.append(a, 3);
1024 try list.append(a, 4);1024 try list.append(a, 4);
1025 try list.insertSlice(a, 1, &[_]i32{ 9, 8 });1025 try list.insertSlice(a, 1, &[_]i32{ 9, 8 });
1026 testing.expect(list.items[0] == 1);1026 try testing.expect(list.items[0] == 1);
1027 testing.expect(list.items[1] == 9);1027 try testing.expect(list.items[1] == 9);
1028 testing.expect(list.items[2] == 8);1028 try testing.expect(list.items[2] == 8);
1029 testing.expect(list.items[3] == 2);1029 try testing.expect(list.items[3] == 2);
1030 testing.expect(list.items[4] == 3);1030 try testing.expect(list.items[4] == 3);
1031 testing.expect(list.items[5] == 4);1031 try testing.expect(list.items[5] == 4);
10321032
1033 const items = [_]i32{1};1033 const items = [_]i32{1};
1034 try list.insertSlice(a, 0, items[0..0]);1034 try list.insertSlice(a, 0, items[0..0]);
1035 testing.expect(list.items.len == 6);1035 try testing.expect(list.items.len == 6);
1036 testing.expect(list.items[0] == 1);1036 try testing.expect(list.items[0] == 1);
1037 }1037 }
1038}1038}
10391039
...@@ -1066,13 +1066,13 @@ test "std.ArrayList/ArrayListUnmanaged.replaceRange" {...@@ -1066,13 +1066,13 @@ test "std.ArrayList/ArrayListUnmanaged.replaceRange" {
1066 try list_lt.replaceRange(1, 2, &new);1066 try list_lt.replaceRange(1, 2, &new);
10671067
1068 // after_range > new_items.len in function body1068 // after_range > new_items.len in function body
1069 testing.expect(1 + 4 > new.len);1069 try testing.expect(1 + 4 > new.len);
1070 try list_gt.replaceRange(1, 4, &new);1070 try list_gt.replaceRange(1, 4, &new);
10711071
1072 testing.expectEqualSlices(i32, list_zero.items, &result_zero);1072 try testing.expectEqualSlices(i32, list_zero.items, &result_zero);
1073 testing.expectEqualSlices(i32, list_eq.items, &result_eq);1073 try testing.expectEqualSlices(i32, list_eq.items, &result_eq);
1074 testing.expectEqualSlices(i32, list_lt.items, &result_le);1074 try testing.expectEqualSlices(i32, list_lt.items, &result_le);
1075 testing.expectEqualSlices(i32, list_gt.items, &result_gt);1075 try testing.expectEqualSlices(i32, list_gt.items, &result_gt);
1076 }1076 }
1077 {1077 {
1078 var list_zero = ArrayListUnmanaged(i32){};1078 var list_zero = ArrayListUnmanaged(i32){};
...@@ -1090,13 +1090,13 @@ test "std.ArrayList/ArrayListUnmanaged.replaceRange" {...@@ -1090,13 +1090,13 @@ test "std.ArrayList/ArrayListUnmanaged.replaceRange" {
1090 try list_lt.replaceRange(a, 1, 2, &new);1090 try list_lt.replaceRange(a, 1, 2, &new);
10911091
1092 // after_range > new_items.len in function body1092 // after_range > new_items.len in function body
1093 testing.expect(1 + 4 > new.len);1093 try testing.expect(1 + 4 > new.len);
1094 try list_gt.replaceRange(a, 1, 4, &new);1094 try list_gt.replaceRange(a, 1, 4, &new);
10951095
1096 testing.expectEqualSlices(i32, list_zero.items, &result_zero);1096 try testing.expectEqualSlices(i32, list_zero.items, &result_zero);
1097 testing.expectEqualSlices(i32, list_eq.items, &result_eq);1097 try testing.expectEqualSlices(i32, list_eq.items, &result_eq);
1098 testing.expectEqualSlices(i32, list_lt.items, &result_le);1098 try testing.expectEqualSlices(i32, list_lt.items, &result_le);
1099 testing.expectEqualSlices(i32, list_gt.items, &result_gt);1099 try testing.expectEqualSlices(i32, list_gt.items, &result_gt);
1100 }1100 }
1101}1101}
11021102
...@@ -1116,13 +1116,13 @@ test "std.ArrayList/ArrayListUnmanaged: ArrayList(T) of struct T" {...@@ -1116,13 +1116,13 @@ test "std.ArrayList/ArrayListUnmanaged: ArrayList(T) of struct T" {
1116 var root = Item{ .integer = 1, .sub_items = ArrayList(Item).init(a) };1116 var root = Item{ .integer = 1, .sub_items = ArrayList(Item).init(a) };
1117 defer root.sub_items.deinit();1117 defer root.sub_items.deinit();
1118 try root.sub_items.append(Item{ .integer = 42, .sub_items = ArrayList(Item).init(a) });1118 try root.sub_items.append(Item{ .integer = 42, .sub_items = ArrayList(Item).init(a) });
1119 testing.expect(root.sub_items.items[0].integer == 42);1119 try testing.expect(root.sub_items.items[0].integer == 42);
1120 }1120 }
1121 {1121 {
1122 var root = ItemUnmanaged{ .integer = 1, .sub_items = ArrayListUnmanaged(ItemUnmanaged){} };1122 var root = ItemUnmanaged{ .integer = 1, .sub_items = ArrayListUnmanaged(ItemUnmanaged){} };
1123 defer root.sub_items.deinit(a);1123 defer root.sub_items.deinit(a);
1124 try root.sub_items.append(a, ItemUnmanaged{ .integer = 42, .sub_items = ArrayListUnmanaged(ItemUnmanaged){} });1124 try root.sub_items.append(a, ItemUnmanaged{ .integer = 42, .sub_items = ArrayListUnmanaged(ItemUnmanaged){} });
1125 testing.expect(root.sub_items.items[0].integer == 42);1125 try testing.expect(root.sub_items.items[0].integer == 42);
1126 }1126 }
1127}1127}
11281128
...@@ -1137,7 +1137,7 @@ test "std.ArrayList(u8)/ArrayListAligned implements writer" {...@@ -1137,7 +1137,7 @@ test "std.ArrayList(u8)/ArrayListAligned implements writer" {
1137 const y: i32 = 1234;1137 const y: i32 = 1234;
1138 try buffer.writer().print("x: {}\ny: {}\n", .{ x, y });1138 try buffer.writer().print("x: {}\ny: {}\n", .{ x, y });
11391139
1140 testing.expectEqualSlices(u8, "x: 42\ny: 1234\n", buffer.items);1140 try testing.expectEqualSlices(u8, "x: 42\ny: 1234\n", buffer.items);
1141 }1141 }
1142 {1142 {
1143 var list = ArrayListAligned(u8, 2).init(a);1143 var list = ArrayListAligned(u8, 2).init(a);
...@@ -1149,7 +1149,7 @@ test "std.ArrayList(u8)/ArrayListAligned implements writer" {...@@ -1149,7 +1149,7 @@ test "std.ArrayList(u8)/ArrayListAligned implements writer" {
1149 try writer.writeAll("d");1149 try writer.writeAll("d");
1150 try writer.writeAll("efg");1150 try writer.writeAll("efg");
11511151
1152 testing.expectEqualSlices(u8, list.items, "abcdefg");1152 try testing.expectEqualSlices(u8, list.items, "abcdefg");
1153 }1153 }
1154}1154}
11551155
...@@ -1167,7 +1167,7 @@ test "std.ArrayList/ArrayListUnmanaged.shrink still sets length on error.OutOfMe...@@ -1167,7 +1167,7 @@ test "std.ArrayList/ArrayListUnmanaged.shrink still sets length on error.OutOfMe
1167 try list.append(3);1167 try list.append(3);
11681168
1169 list.shrinkAndFree(1);1169 list.shrinkAndFree(1);
1170 testing.expect(list.items.len == 1);1170 try testing.expect(list.items.len == 1);
1171 }1171 }
1172 {1172 {
1173 var list = ArrayListUnmanaged(i32){};1173 var list = ArrayListUnmanaged(i32){};
...@@ -1177,7 +1177,7 @@ test "std.ArrayList/ArrayListUnmanaged.shrink still sets length on error.OutOfMe...@@ -1177,7 +1177,7 @@ test "std.ArrayList/ArrayListUnmanaged.shrink still sets length on error.OutOfMe
1177 try list.append(a, 3);1177 try list.append(a, 3);
11781178
1179 list.shrinkAndFree(a, 1);1179 list.shrinkAndFree(a, 1);
1180 testing.expect(list.items.len == 1);1180 try testing.expect(list.items.len == 1);
1181 }1181 }
1182}1182}
11831183
...@@ -1191,7 +1191,7 @@ test "std.ArrayList/ArrayListUnmanaged.addManyAsArray" {...@@ -1191,7 +1191,7 @@ test "std.ArrayList/ArrayListUnmanaged.addManyAsArray" {
1191 try list.ensureCapacity(8);1191 try list.ensureCapacity(8);
1192 list.addManyAsArrayAssumeCapacity(4).* = "asdf".*;1192 list.addManyAsArrayAssumeCapacity(4).* = "asdf".*;
11931193
1194 testing.expectEqualSlices(u8, list.items, "aoeuasdf");1194 try testing.expectEqualSlices(u8, list.items, "aoeuasdf");
1195 }1195 }
1196 {1196 {
1197 var list = ArrayListUnmanaged(u8){};1197 var list = ArrayListUnmanaged(u8){};
...@@ -1201,7 +1201,7 @@ test "std.ArrayList/ArrayListUnmanaged.addManyAsArray" {...@@ -1201,7 +1201,7 @@ test "std.ArrayList/ArrayListUnmanaged.addManyAsArray" {
1201 try list.ensureCapacity(a, 8);1201 try list.ensureCapacity(a, 8);
1202 list.addManyAsArrayAssumeCapacity(4).* = "asdf".*;1202 list.addManyAsArrayAssumeCapacity(4).* = "asdf".*;
12031203
1204 testing.expectEqualSlices(u8, list.items, "aoeuasdf");1204 try testing.expectEqualSlices(u8, list.items, "aoeuasdf");
1205 }1205 }
1206}1206}
12071207
...@@ -1215,7 +1215,7 @@ test "std.ArrayList/ArrayListUnmanaged.toOwnedSliceSentinel" {...@@ -1215,7 +1215,7 @@ test "std.ArrayList/ArrayListUnmanaged.toOwnedSliceSentinel" {
12151215
1216 const result = try list.toOwnedSliceSentinel(0);1216 const result = try list.toOwnedSliceSentinel(0);
1217 defer a.free(result);1217 defer a.free(result);
1218 testing.expectEqualStrings(result, mem.spanZ(result.ptr));1218 try testing.expectEqualStrings(result, mem.spanZ(result.ptr));
1219 }1219 }
1220 {1220 {
1221 var list = ArrayListUnmanaged(u8){};1221 var list = ArrayListUnmanaged(u8){};
...@@ -1225,7 +1225,7 @@ test "std.ArrayList/ArrayListUnmanaged.toOwnedSliceSentinel" {...@@ -1225,7 +1225,7 @@ test "std.ArrayList/ArrayListUnmanaged.toOwnedSliceSentinel" {
12251225
1226 const result = try list.toOwnedSliceSentinel(a, 0);1226 const result = try list.toOwnedSliceSentinel(a, 0);
1227 defer a.free(result);1227 defer a.free(result);
1228 testing.expectEqualStrings(result, mem.spanZ(result.ptr));1228 try testing.expectEqualStrings(result, mem.spanZ(result.ptr));
1229 }1229 }
1230}1230}
12311231
...@@ -1239,7 +1239,7 @@ test "ArrayListAligned/ArrayListAlignedUnmanaged accepts unaligned slices" {...@@ -1239,7 +1239,7 @@ test "ArrayListAligned/ArrayListAlignedUnmanaged accepts unaligned slices" {
1239 try list.insertSlice(2, &.{ 4, 5, 6, 7 });1239 try list.insertSlice(2, &.{ 4, 5, 6, 7 });
1240 try list.replaceRange(1, 3, &.{ 8, 9 });1240 try list.replaceRange(1, 3, &.{ 8, 9 });
12411241
1242 testing.expectEqualSlices(u8, list.items, &.{ 0, 8, 9, 6, 7, 2, 3 });1242 try testing.expectEqualSlices(u8, list.items, &.{ 0, 8, 9, 6, 7, 2, 3 });
1243 }1243 }
1244 {1244 {
1245 var list = std.ArrayListAlignedUnmanaged(u8, 8){};1245 var list = std.ArrayListAlignedUnmanaged(u8, 8){};
...@@ -1249,6 +1249,6 @@ test "ArrayListAligned/ArrayListAlignedUnmanaged accepts unaligned slices" {...@@ -1249,6 +1249,6 @@ test "ArrayListAligned/ArrayListAlignedUnmanaged accepts unaligned slices" {
1249 try list.insertSlice(a, 2, &.{ 4, 5, 6, 7 });1249 try list.insertSlice(a, 2, &.{ 4, 5, 6, 7 });
1250 try list.replaceRange(a, 1, 3, &.{ 8, 9 });1250 try list.replaceRange(a, 1, 3, &.{ 8, 9 });
12511251
1252 testing.expectEqualSlices(u8, list.items, &.{ 0, 8, 9, 6, 7, 2, 3 });1252 try testing.expectEqualSlices(u8, list.items, &.{ 0, 8, 9, 6, 7, 2, 3 });
1253 }1253 }
1254}1254}
lib/std/ascii.zig+23-23
...@@ -236,11 +236,11 @@ pub const spaces = [_]u8{ ' ', '\t', '\n', '\r', control_code.VT, control_code.F...@@ -236,11 +236,11 @@ pub const spaces = [_]u8{ ' ', '\t', '\n', '\r', control_code.VT, control_code.F
236236
237test "spaces" {237test "spaces" {
238 const testing = std.testing;238 const testing = std.testing;
239 for (spaces) |space| testing.expect(isSpace(space));239 for (spaces) |space| try testing.expect(isSpace(space));
240240
241 var i: u8 = 0;241 var i: u8 = 0;
242 while (isASCII(i)) : (i += 1) {242 while (isASCII(i)) : (i += 1) {
243 if (isSpace(i)) testing.expect(std.mem.indexOfScalar(u8, &spaces, i) != null);243 if (isSpace(i)) try testing.expect(std.mem.indexOfScalar(u8, &spaces, i) != null);
244 }244 }
245}245}
246246
...@@ -279,13 +279,13 @@ pub fn toLower(c: u8) u8 {...@@ -279,13 +279,13 @@ pub fn toLower(c: u8) u8 {
279test "ascii character classes" {279test "ascii character classes" {
280 const testing = std.testing;280 const testing = std.testing;
281281
282 testing.expect('C' == toUpper('c'));282 try testing.expect('C' == toUpper('c'));
283 testing.expect(':' == toUpper(':'));283 try testing.expect(':' == toUpper(':'));
284 testing.expect('\xab' == toUpper('\xab'));284 try testing.expect('\xab' == toUpper('\xab'));
285 testing.expect('c' == toLower('C'));285 try testing.expect('c' == toLower('C'));
286 testing.expect(isAlpha('c'));286 try testing.expect(isAlpha('c'));
287 testing.expect(!isAlpha('5'));287 try testing.expect(!isAlpha('5'));
288 testing.expect(isSpace(' '));288 try testing.expect(isSpace(' '));
289}289}
290290
291/// Allocates a lower case copy of `ascii_string`.291/// Allocates a lower case copy of `ascii_string`.
...@@ -301,7 +301,7 @@ pub fn allocLowerString(allocator: *std.mem.Allocator, ascii_string: []const u8)...@@ -301,7 +301,7 @@ pub fn allocLowerString(allocator: *std.mem.Allocator, ascii_string: []const u8)
301test "allocLowerString" {301test "allocLowerString" {
302 const result = try allocLowerString(std.testing.allocator, "aBcDeFgHiJkLmNOPqrst0234+💩!");302 const result = try allocLowerString(std.testing.allocator, "aBcDeFgHiJkLmNOPqrst0234+💩!");
303 defer std.testing.allocator.free(result);303 defer std.testing.allocator.free(result);
304 std.testing.expect(std.mem.eql(u8, "abcdefghijklmnopqrst0234+💩!", result));304 try std.testing.expect(std.mem.eql(u8, "abcdefghijklmnopqrst0234+💩!", result));
305}305}
306306
307/// Allocates an upper case copy of `ascii_string`.307/// Allocates an upper case copy of `ascii_string`.
...@@ -317,7 +317,7 @@ pub fn allocUpperString(allocator: *std.mem.Allocator, ascii_string: []const u8)...@@ -317,7 +317,7 @@ pub fn allocUpperString(allocator: *std.mem.Allocator, ascii_string: []const u8)
317test "allocUpperString" {317test "allocUpperString" {
318 const result = try allocUpperString(std.testing.allocator, "aBcDeFgHiJkLmNOPqrst0234+💩!");318 const result = try allocUpperString(std.testing.allocator, "aBcDeFgHiJkLmNOPqrst0234+💩!");
319 defer std.testing.allocator.free(result);319 defer std.testing.allocator.free(result);
320 std.testing.expect(std.mem.eql(u8, "ABCDEFGHIJKLMNOPQRST0234+💩!", result));320 try std.testing.expect(std.mem.eql(u8, "ABCDEFGHIJKLMNOPQRST0234+💩!", result));
321}321}
322322
323/// Compares strings `a` and `b` case insensitively and returns whether they are equal.323/// Compares strings `a` and `b` case insensitively and returns whether they are equal.
...@@ -330,9 +330,9 @@ pub fn eqlIgnoreCase(a: []const u8, b: []const u8) bool {...@@ -330,9 +330,9 @@ pub fn eqlIgnoreCase(a: []const u8, b: []const u8) bool {
330}330}
331331
332test "eqlIgnoreCase" {332test "eqlIgnoreCase" {
333 std.testing.expect(eqlIgnoreCase("HEl💩Lo!", "hel💩lo!"));333 try std.testing.expect(eqlIgnoreCase("HEl💩Lo!", "hel💩lo!"));
334 std.testing.expect(!eqlIgnoreCase("hElLo!", "hello! "));334 try std.testing.expect(!eqlIgnoreCase("hElLo!", "hello! "));
335 std.testing.expect(!eqlIgnoreCase("hElLo!", "helro!"));335 try std.testing.expect(!eqlIgnoreCase("hElLo!", "helro!"));
336}336}
337337
338pub fn startsWithIgnoreCase(haystack: []const u8, needle: []const u8) bool {338pub fn startsWithIgnoreCase(haystack: []const u8, needle: []const u8) bool {
...@@ -340,8 +340,8 @@ pub fn startsWithIgnoreCase(haystack: []const u8, needle: []const u8) bool {...@@ -340,8 +340,8 @@ pub fn startsWithIgnoreCase(haystack: []const u8, needle: []const u8) bool {
340}340}
341341
342test "ascii.startsWithIgnoreCase" {342test "ascii.startsWithIgnoreCase" {
343 std.testing.expect(startsWithIgnoreCase("boB", "Bo"));343 try std.testing.expect(startsWithIgnoreCase("boB", "Bo"));
344 std.testing.expect(!startsWithIgnoreCase("Needle in hAyStAcK", "haystack"));344 try std.testing.expect(!startsWithIgnoreCase("Needle in hAyStAcK", "haystack"));
345}345}
346346
347pub fn endsWithIgnoreCase(haystack: []const u8, needle: []const u8) bool {347pub fn endsWithIgnoreCase(haystack: []const u8, needle: []const u8) bool {
...@@ -349,8 +349,8 @@ pub fn endsWithIgnoreCase(haystack: []const u8, needle: []const u8) bool {...@@ -349,8 +349,8 @@ pub fn endsWithIgnoreCase(haystack: []const u8, needle: []const u8) bool {
349}349}
350350
351test "ascii.endsWithIgnoreCase" {351test "ascii.endsWithIgnoreCase" {
352 std.testing.expect(endsWithIgnoreCase("Needle in HaYsTaCk", "haystack"));352 try std.testing.expect(endsWithIgnoreCase("Needle in HaYsTaCk", "haystack"));
353 std.testing.expect(!endsWithIgnoreCase("BoB", "Bo"));353 try std.testing.expect(!endsWithIgnoreCase("BoB", "Bo"));
354}354}
355355
356/// Finds `substr` in `container`, ignoring case, starting at `start_index`.356/// Finds `substr` in `container`, ignoring case, starting at `start_index`.
...@@ -372,12 +372,12 @@ pub fn indexOfIgnoreCase(container: []const u8, substr: []const u8) ?usize {...@@ -372,12 +372,12 @@ pub fn indexOfIgnoreCase(container: []const u8, substr: []const u8) ?usize {
372}372}
373373
374test "indexOfIgnoreCase" {374test "indexOfIgnoreCase" {
375 std.testing.expect(indexOfIgnoreCase("one Two Three Four", "foUr").? == 14);375 try std.testing.expect(indexOfIgnoreCase("one Two Three Four", "foUr").? == 14);
376 std.testing.expect(indexOfIgnoreCase("one two three FouR", "gOur") == null);376 try std.testing.expect(indexOfIgnoreCase("one two three FouR", "gOur") == null);
377 std.testing.expect(indexOfIgnoreCase("foO", "Foo").? == 0);377 try std.testing.expect(indexOfIgnoreCase("foO", "Foo").? == 0);
378 std.testing.expect(indexOfIgnoreCase("foo", "fool") == null);378 try std.testing.expect(indexOfIgnoreCase("foo", "fool") == null);
379379
380 std.testing.expect(indexOfIgnoreCase("FOO foo", "fOo").? == 0);380 try std.testing.expect(indexOfIgnoreCase("FOO foo", "fOo").? == 0);
381}381}
382382
383/// Compares two slices of numbers lexicographically. O(n).383/// Compares two slices of numbers lexicographically. O(n).
lib/std/atomic/bool.zig+4-4
...@@ -47,9 +47,9 @@ pub const Bool = extern struct {...@@ -47,9 +47,9 @@ pub const Bool = extern struct {
4747
48test "std.atomic.Bool" {48test "std.atomic.Bool" {
49 var a = Bool.init(false);49 var a = Bool.init(false);
50 testing.expectEqual(false, a.xchg(false, .SeqCst));50 try testing.expectEqual(false, a.xchg(false, .SeqCst));
51 testing.expectEqual(false, a.load(.SeqCst));51 try testing.expectEqual(false, a.load(.SeqCst));
52 a.store(true, .SeqCst);52 a.store(true, .SeqCst);
53 testing.expectEqual(true, a.xchg(false, .SeqCst));53 try testing.expectEqual(true, a.xchg(false, .SeqCst));
54 testing.expectEqual(false, a.load(.SeqCst));54 try testing.expectEqual(false, a.load(.SeqCst));
55}55}
lib/std/atomic/int.zig+6-6
...@@ -81,12 +81,12 @@ pub fn Int(comptime T: type) type {...@@ -81,12 +81,12 @@ pub fn Int(comptime T: type) type {
8181
82test "std.atomic.Int" {82test "std.atomic.Int" {
83 var a = Int(u8).init(0);83 var a = Int(u8).init(0);
84 testing.expectEqual(@as(u8, 0), a.incr());84 try testing.expectEqual(@as(u8, 0), a.incr());
85 testing.expectEqual(@as(u8, 1), a.load(.SeqCst));85 try testing.expectEqual(@as(u8, 1), a.load(.SeqCst));
86 a.store(42, .SeqCst);86 a.store(42, .SeqCst);
87 testing.expectEqual(@as(u8, 42), a.decr());87 try testing.expectEqual(@as(u8, 42), a.decr());
88 testing.expectEqual(@as(u8, 41), a.xchg(100));88 try testing.expectEqual(@as(u8, 41), a.xchg(100));
89 testing.expectEqual(@as(u8, 100), a.fetchAdd(5));89 try testing.expectEqual(@as(u8, 100), a.fetchAdd(5));
90 testing.expectEqual(@as(u8, 105), a.get());90 try testing.expectEqual(@as(u8, 105), a.get());
91 a.set(200);91 a.set(200);
92}92}
lib/std/atomic/queue.zig+28-28
...@@ -195,24 +195,24 @@ test "std.atomic.Queue" {...@@ -195,24 +195,24 @@ test "std.atomic.Queue" {
195 };195 };
196196
197 if (builtin.single_threaded) {197 if (builtin.single_threaded) {
198 expect(context.queue.isEmpty());198 try expect(context.queue.isEmpty());
199 {199 {
200 var i: usize = 0;200 var i: usize = 0;
201 while (i < put_thread_count) : (i += 1) {201 while (i < put_thread_count) : (i += 1) {
202 expect(startPuts(&context) == 0);202 try expect(startPuts(&context) == 0);
203 }203 }
204 }204 }
205 expect(!context.queue.isEmpty());205 try expect(!context.queue.isEmpty());
206 context.puts_done = true;206 context.puts_done = true;
207 {207 {
208 var i: usize = 0;208 var i: usize = 0;
209 while (i < put_thread_count) : (i += 1) {209 while (i < put_thread_count) : (i += 1) {
210 expect(startGets(&context) == 0);210 try expect(startGets(&context) == 0);
211 }211 }
212 }212 }
213 expect(context.queue.isEmpty());213 try expect(context.queue.isEmpty());
214 } else {214 } else {
215 expect(context.queue.isEmpty());215 try expect(context.queue.isEmpty());
216216
217 var putters: [put_thread_count]*std.Thread = undefined;217 var putters: [put_thread_count]*std.Thread = undefined;
218 for (putters) |*t| {218 for (putters) |*t| {
...@@ -229,7 +229,7 @@ test "std.atomic.Queue" {...@@ -229,7 +229,7 @@ test "std.atomic.Queue" {
229 for (getters) |t|229 for (getters) |t|
230 t.wait();230 t.wait();
231231
232 expect(context.queue.isEmpty());232 try expect(context.queue.isEmpty());
233 }233 }
234234
235 if (context.put_sum != context.get_sum) {235 if (context.put_sum != context.get_sum) {
...@@ -279,7 +279,7 @@ fn startGets(ctx: *Context) u8 {...@@ -279,7 +279,7 @@ fn startGets(ctx: *Context) u8 {
279279
280test "std.atomic.Queue single-threaded" {280test "std.atomic.Queue single-threaded" {
281 var queue = Queue(i32).init();281 var queue = Queue(i32).init();
282 expect(queue.isEmpty());282 try expect(queue.isEmpty());
283283
284 var node_0 = Queue(i32).Node{284 var node_0 = Queue(i32).Node{
285 .data = 0,285 .data = 0,
...@@ -287,7 +287,7 @@ test "std.atomic.Queue single-threaded" {...@@ -287,7 +287,7 @@ test "std.atomic.Queue single-threaded" {
287 .prev = undefined,287 .prev = undefined,
288 };288 };
289 queue.put(&node_0);289 queue.put(&node_0);
290 expect(!queue.isEmpty());290 try expect(!queue.isEmpty());
291291
292 var node_1 = Queue(i32).Node{292 var node_1 = Queue(i32).Node{
293 .data = 1,293 .data = 1,
...@@ -295,10 +295,10 @@ test "std.atomic.Queue single-threaded" {...@@ -295,10 +295,10 @@ test "std.atomic.Queue single-threaded" {
295 .prev = undefined,295 .prev = undefined,
296 };296 };
297 queue.put(&node_1);297 queue.put(&node_1);
298 expect(!queue.isEmpty());298 try expect(!queue.isEmpty());
299299
300 expect(queue.get().?.data == 0);300 try expect(queue.get().?.data == 0);
301 expect(!queue.isEmpty());301 try expect(!queue.isEmpty());
302302
303 var node_2 = Queue(i32).Node{303 var node_2 = Queue(i32).Node{
304 .data = 2,304 .data = 2,
...@@ -306,7 +306,7 @@ test "std.atomic.Queue single-threaded" {...@@ -306,7 +306,7 @@ test "std.atomic.Queue single-threaded" {
306 .prev = undefined,306 .prev = undefined,
307 };307 };
308 queue.put(&node_2);308 queue.put(&node_2);
309 expect(!queue.isEmpty());309 try expect(!queue.isEmpty());
310310
311 var node_3 = Queue(i32).Node{311 var node_3 = Queue(i32).Node{
312 .data = 3,312 .data = 3,
...@@ -314,13 +314,13 @@ test "std.atomic.Queue single-threaded" {...@@ -314,13 +314,13 @@ test "std.atomic.Queue single-threaded" {
314 .prev = undefined,314 .prev = undefined,
315 };315 };
316 queue.put(&node_3);316 queue.put(&node_3);
317 expect(!queue.isEmpty());317 try expect(!queue.isEmpty());
318318
319 expect(queue.get().?.data == 1);319 try expect(queue.get().?.data == 1);
320 expect(!queue.isEmpty());320 try expect(!queue.isEmpty());
321321
322 expect(queue.get().?.data == 2);322 try expect(queue.get().?.data == 2);
323 expect(!queue.isEmpty());323 try expect(!queue.isEmpty());
324324
325 var node_4 = Queue(i32).Node{325 var node_4 = Queue(i32).Node{
326 .data = 4,326 .data = 4,
...@@ -328,17 +328,17 @@ test "std.atomic.Queue single-threaded" {...@@ -328,17 +328,17 @@ test "std.atomic.Queue single-threaded" {
328 .prev = undefined,328 .prev = undefined,
329 };329 };
330 queue.put(&node_4);330 queue.put(&node_4);
331 expect(!queue.isEmpty());331 try expect(!queue.isEmpty());
332332
333 expect(queue.get().?.data == 3);333 try expect(queue.get().?.data == 3);
334 node_3.next = null;334 node_3.next = null;
335 expect(!queue.isEmpty());335 try expect(!queue.isEmpty());
336336
337 expect(queue.get().?.data == 4);337 try expect(queue.get().?.data == 4);
338 expect(queue.isEmpty());338 try expect(queue.isEmpty());
339339
340 expect(queue.get() == null);340 try expect(queue.get() == null);
341 expect(queue.isEmpty());341 try expect(queue.isEmpty());
342}342}
343343
344test "std.atomic.Queue dump" {344test "std.atomic.Queue dump" {
...@@ -352,7 +352,7 @@ test "std.atomic.Queue dump" {...@@ -352,7 +352,7 @@ test "std.atomic.Queue dump" {
352 // Test empty stream352 // Test empty stream
353 fbs.reset();353 fbs.reset();
354 try queue.dumpToStream(fbs.writer());354 try queue.dumpToStream(fbs.writer());
355 expect(mem.eql(u8, buffer[0..fbs.pos],355 try expect(mem.eql(u8, buffer[0..fbs.pos],
356 \\head: (null)356 \\head: (null)
357 \\tail: (null)357 \\tail: (null)
358 \\358 \\
...@@ -376,7 +376,7 @@ test "std.atomic.Queue dump" {...@@ -376,7 +376,7 @@ test "std.atomic.Queue dump" {
376 \\ (null)376 \\ (null)
377 \\377 \\
378 , .{ @ptrToInt(queue.head), @ptrToInt(queue.tail) });378 , .{ @ptrToInt(queue.head), @ptrToInt(queue.tail) });
379 expect(mem.eql(u8, buffer[0..fbs.pos], expected));379 try expect(mem.eql(u8, buffer[0..fbs.pos], expected));
380380
381 // Test a stream with two elements381 // Test a stream with two elements
382 var node_1 = Queue(i32).Node{382 var node_1 = Queue(i32).Node{
...@@ -397,5 +397,5 @@ test "std.atomic.Queue dump" {...@@ -397,5 +397,5 @@ test "std.atomic.Queue dump" {
397 \\ (null)397 \\ (null)
398 \\398 \\
399 , .{ @ptrToInt(queue.head), @ptrToInt(queue.head.?.next), @ptrToInt(queue.tail) });399 , .{ @ptrToInt(queue.head), @ptrToInt(queue.head.?.next), @ptrToInt(queue.tail) });
400 expect(mem.eql(u8, buffer[0..fbs.pos], expected));400 try expect(mem.eql(u8, buffer[0..fbs.pos], expected));
401}401}
lib/std/atomic/stack.zig+2-2
...@@ -110,14 +110,14 @@ test "std.atomic.stack" {...@@ -110,14 +110,14 @@ test "std.atomic.stack" {
110 {110 {
111 var i: usize = 0;111 var i: usize = 0;
112 while (i < put_thread_count) : (i += 1) {112 while (i < put_thread_count) : (i += 1) {
113 expect(startPuts(&context) == 0);113 try expect(startPuts(&context) == 0);
114 }114 }
115 }115 }
116 context.puts_done = true;116 context.puts_done = true;
117 {117 {
118 var i: usize = 0;118 var i: usize = 0;
119 while (i < put_thread_count) : (i += 1) {119 while (i < put_thread_count) : (i += 1) {
120 expect(startGets(&context) == 0);120 try expect(startGets(&context) == 0);
121 }121 }
122 }122 }
123 } else {123 } else {
lib/std/base64.zig+9-9
...@@ -318,14 +318,14 @@ pub const Base64DecoderWithIgnore = struct {...@@ -318,14 +318,14 @@ pub const Base64DecoderWithIgnore = struct {
318318
319test "base64" {319test "base64" {
320 @setEvalBranchQuota(8000);320 @setEvalBranchQuota(8000);
321 testBase64() catch unreachable;321 try testBase64();
322 comptime testAllApis(standard, "comptime", "Y29tcHRpbWU=") catch unreachable;322 comptime try testAllApis(standard, "comptime", "Y29tcHRpbWU=");
323}323}
324324
325test "base64 url_safe_no_pad" {325test "base64 url_safe_no_pad" {
326 @setEvalBranchQuota(8000);326 @setEvalBranchQuota(8000);
327 testBase64UrlSafeNoPad() catch unreachable;327 try testBase64UrlSafeNoPad();
328 comptime testAllApis(url_safe_no_pad, "comptime", "Y29tcHRpbWU") catch unreachable;328 comptime try testAllApis(url_safe_no_pad, "comptime", "Y29tcHRpbWU");
329}329}
330330
331fn testBase64() !void {331fn testBase64() !void {
...@@ -404,7 +404,7 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [...@@ -404,7 +404,7 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [
404 {404 {
405 var buffer: [0x100]u8 = undefined;405 var buffer: [0x100]u8 = undefined;
406 const encoded = codecs.Encoder.encode(&buffer, expected_decoded);406 const encoded = codecs.Encoder.encode(&buffer, expected_decoded);
407 testing.expectEqualSlices(u8, expected_encoded, encoded);407 try testing.expectEqualSlices(u8, expected_encoded, encoded);
408 }408 }
409409
410 // Base64Decoder410 // Base64Decoder
...@@ -412,7 +412,7 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [...@@ -412,7 +412,7 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [
412 var buffer: [0x100]u8 = undefined;412 var buffer: [0x100]u8 = undefined;
413 var decoded = buffer[0..try codecs.Decoder.calcSizeForSlice(expected_encoded)];413 var decoded = buffer[0..try codecs.Decoder.calcSizeForSlice(expected_encoded)];
414 try codecs.Decoder.decode(decoded, expected_encoded);414 try codecs.Decoder.decode(decoded, expected_encoded);
415 testing.expectEqualSlices(u8, expected_decoded, decoded);415 try testing.expectEqualSlices(u8, expected_decoded, decoded);
416 }416 }
417417
418 // Base64DecoderWithIgnore418 // Base64DecoderWithIgnore
...@@ -421,8 +421,8 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [...@@ -421,8 +421,8 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [
421 var buffer: [0x100]u8 = undefined;421 var buffer: [0x100]u8 = undefined;
422 var decoded = buffer[0..try decoder_ignore_nothing.calcSizeUpperBound(expected_encoded.len)];422 var decoded = buffer[0..try decoder_ignore_nothing.calcSizeUpperBound(expected_encoded.len)];
423 var written = try decoder_ignore_nothing.decode(decoded, expected_encoded);423 var written = try decoder_ignore_nothing.decode(decoded, expected_encoded);
424 testing.expect(written <= decoded.len);424 try testing.expect(written <= decoded.len);
425 testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]);425 try testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]);
426 }426 }
427}427}
428428
...@@ -431,7 +431,7 @@ fn testDecodeIgnoreSpace(codecs: Codecs, expected_decoded: []const u8, encoded:...@@ -431,7 +431,7 @@ fn testDecodeIgnoreSpace(codecs: Codecs, expected_decoded: []const u8, encoded:
431 var buffer: [0x100]u8 = undefined;431 var buffer: [0x100]u8 = undefined;
432 var decoded = buffer[0..try decoder_ignore_space.calcSizeUpperBound(encoded.len)];432 var decoded = buffer[0..try decoder_ignore_space.calcSizeUpperBound(encoded.len)];
433 var written = try decoder_ignore_space.decode(decoded, encoded);433 var written = try decoder_ignore_space.decode(decoded, encoded);
434 testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]);434 try testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]);
435}435}
436436
437fn testError(codecs: Codecs, encoded: []const u8, expected_err: anyerror) !void {437fn testError(codecs: Codecs, encoded: []const u8, expected_err: anyerror) !void {
lib/std/bit_set.zig+89-89
...@@ -998,9 +998,9 @@ fn BitSetIterator(comptime MaskInt: type, comptime options: IteratorOptions) typ...@@ -998,9 +998,9 @@ fn BitSetIterator(comptime MaskInt: type, comptime options: IteratorOptions) typ
998998
999const testing = std.testing;999const testing = std.testing;
10001000
1001fn testBitSet(a: anytype, b: anytype, len: usize) void {1001fn testBitSet(a: anytype, b: anytype, len: usize) !void {
1002 testing.expectEqual(len, a.capacity());1002 try testing.expectEqual(len, a.capacity());
1003 testing.expectEqual(len, b.capacity());1003 try testing.expectEqual(len, b.capacity());
10041004
1005 {1005 {
1006 var i: usize = 0;1006 var i: usize = 0;
...@@ -1010,50 +1010,50 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void {...@@ -1010,50 +1010,50 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void {
1010 }1010 }
1011 }1011 }
10121012
1013 testing.expectEqual((len + 1) / 2, a.count());1013 try testing.expectEqual((len + 1) / 2, a.count());
1014 testing.expectEqual((len + 3) / 4 + (len + 2) / 4, b.count());1014 try testing.expectEqual((len + 3) / 4 + (len + 2) / 4, b.count());
10151015
1016 {1016 {
1017 var iter = a.iterator(.{});1017 var iter = a.iterator(.{});
1018 var i: usize = 0;1018 var i: usize = 0;
1019 while (i < len) : (i += 2) {1019 while (i < len) : (i += 2) {
1020 testing.expectEqual(@as(?usize, i), iter.next());1020 try testing.expectEqual(@as(?usize, i), iter.next());
1021 }1021 }
1022 testing.expectEqual(@as(?usize, null), iter.next());1022 try testing.expectEqual(@as(?usize, null), iter.next());
1023 testing.expectEqual(@as(?usize, null), iter.next());1023 try testing.expectEqual(@as(?usize, null), iter.next());
1024 testing.expectEqual(@as(?usize, null), iter.next());1024 try testing.expectEqual(@as(?usize, null), iter.next());
1025 }1025 }
1026 a.toggleAll();1026 a.toggleAll();
1027 {1027 {
1028 var iter = a.iterator(.{});1028 var iter = a.iterator(.{});
1029 var i: usize = 1;1029 var i: usize = 1;
1030 while (i < len) : (i += 2) {1030 while (i < len) : (i += 2) {
1031 testing.expectEqual(@as(?usize, i), iter.next());1031 try testing.expectEqual(@as(?usize, i), iter.next());
1032 }1032 }
1033 testing.expectEqual(@as(?usize, null), iter.next());1033 try testing.expectEqual(@as(?usize, null), iter.next());
1034 testing.expectEqual(@as(?usize, null), iter.next());1034 try testing.expectEqual(@as(?usize, null), iter.next());
1035 testing.expectEqual(@as(?usize, null), iter.next());1035 try testing.expectEqual(@as(?usize, null), iter.next());
1036 }1036 }
10371037
1038 {1038 {
1039 var iter = b.iterator(.{ .kind = .unset });1039 var iter = b.iterator(.{ .kind = .unset });
1040 var i: usize = 2;1040 var i: usize = 2;
1041 while (i < len) : (i += 4) {1041 while (i < len) : (i += 4) {
1042 testing.expectEqual(@as(?usize, i), iter.next());1042 try testing.expectEqual(@as(?usize, i), iter.next());
1043 if (i + 1 < len) {1043 if (i + 1 < len) {
1044 testing.expectEqual(@as(?usize, i + 1), iter.next());1044 try testing.expectEqual(@as(?usize, i + 1), iter.next());
1045 }1045 }
1046 }1046 }
1047 testing.expectEqual(@as(?usize, null), iter.next());1047 try testing.expectEqual(@as(?usize, null), iter.next());
1048 testing.expectEqual(@as(?usize, null), iter.next());1048 try testing.expectEqual(@as(?usize, null), iter.next());
1049 testing.expectEqual(@as(?usize, null), iter.next());1049 try testing.expectEqual(@as(?usize, null), iter.next());
1050 }1050 }
10511051
1052 {1052 {
1053 var i: usize = 0;1053 var i: usize = 0;
1054 while (i < len) : (i += 1) {1054 while (i < len) : (i += 1) {
1055 testing.expectEqual(i & 1 != 0, a.isSet(i));1055 try testing.expectEqual(i & 1 != 0, a.isSet(i));
1056 testing.expectEqual(i & 2 == 0, b.isSet(i));1056 try testing.expectEqual(i & 2 == 0, b.isSet(i));
1057 }1057 }
1058 }1058 }
10591059
...@@ -1061,8 +1061,8 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void {...@@ -1061,8 +1061,8 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void {
1061 {1061 {
1062 var i: usize = 0;1062 var i: usize = 0;
1063 while (i < len) : (i += 1) {1063 while (i < len) : (i += 1) {
1064 testing.expectEqual(i & 1 != 0 or i & 2 == 0, a.isSet(i));1064 try testing.expectEqual(i & 1 != 0 or i & 2 == 0, a.isSet(i));
1065 testing.expectEqual(i & 2 == 0, b.isSet(i));1065 try testing.expectEqual(i & 2 == 0, b.isSet(i));
1066 }1066 }
10671067
1068 i = len;1068 i = len;
...@@ -1071,27 +1071,27 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void {...@@ -1071,27 +1071,27 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void {
1071 while (i > 0) {1071 while (i > 0) {
1072 i -= 1;1072 i -= 1;
1073 if (i & 1 != 0 or i & 2 == 0) {1073 if (i & 1 != 0 or i & 2 == 0) {
1074 testing.expectEqual(@as(?usize, i), set.next());1074 try testing.expectEqual(@as(?usize, i), set.next());
1075 } else {1075 } else {
1076 testing.expectEqual(@as(?usize, i), unset.next());1076 try testing.expectEqual(@as(?usize, i), unset.next());
1077 }1077 }
1078 }1078 }
1079 testing.expectEqual(@as(?usize, null), set.next());1079 try testing.expectEqual(@as(?usize, null), set.next());
1080 testing.expectEqual(@as(?usize, null), set.next());1080 try testing.expectEqual(@as(?usize, null), set.next());
1081 testing.expectEqual(@as(?usize, null), set.next());1081 try testing.expectEqual(@as(?usize, null), set.next());
1082 testing.expectEqual(@as(?usize, null), unset.next());1082 try testing.expectEqual(@as(?usize, null), unset.next());
1083 testing.expectEqual(@as(?usize, null), unset.next());1083 try testing.expectEqual(@as(?usize, null), unset.next());
1084 testing.expectEqual(@as(?usize, null), unset.next());1084 try testing.expectEqual(@as(?usize, null), unset.next());
1085 }1085 }
10861086
1087 a.toggleSet(b.*);1087 a.toggleSet(b.*);
1088 {1088 {
1089 testing.expectEqual(len / 4, a.count());1089 try testing.expectEqual(len / 4, a.count());
10901090
1091 var i: usize = 0;1091 var i: usize = 0;
1092 while (i < len) : (i += 1) {1092 while (i < len) : (i += 1) {
1093 testing.expectEqual(i & 1 != 0 and i & 2 != 0, a.isSet(i));1093 try testing.expectEqual(i & 1 != 0 and i & 2 != 0, a.isSet(i));
1094 testing.expectEqual(i & 2 == 0, b.isSet(i));1094 try testing.expectEqual(i & 2 == 0, b.isSet(i));
1095 if (i & 1 == 0) {1095 if (i & 1 == 0) {
1096 a.set(i);1096 a.set(i);
1097 } else {1097 } else {
...@@ -1102,29 +1102,29 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void {...@@ -1102,29 +1102,29 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void {
11021102
1103 a.setIntersection(b.*);1103 a.setIntersection(b.*);
1104 {1104 {
1105 testing.expectEqual((len + 3) / 4, a.count());1105 try testing.expectEqual((len + 3) / 4, a.count());
11061106
1107 var i: usize = 0;1107 var i: usize = 0;
1108 while (i < len) : (i += 1) {1108 while (i < len) : (i += 1) {
1109 testing.expectEqual(i & 1 == 0 and i & 2 == 0, a.isSet(i));1109 try testing.expectEqual(i & 1 == 0 and i & 2 == 0, a.isSet(i));
1110 testing.expectEqual(i & 2 == 0, b.isSet(i));1110 try testing.expectEqual(i & 2 == 0, b.isSet(i));
1111 }1111 }
1112 }1112 }
11131113
1114 a.toggleSet(a.*);1114 a.toggleSet(a.*);
1115 {1115 {
1116 var iter = a.iterator(.{});1116 var iter = a.iterator(.{});
1117 testing.expectEqual(@as(?usize, null), iter.next());1117 try testing.expectEqual(@as(?usize, null), iter.next());
1118 testing.expectEqual(@as(?usize, null), iter.next());1118 try testing.expectEqual(@as(?usize, null), iter.next());
1119 testing.expectEqual(@as(?usize, null), iter.next());1119 try testing.expectEqual(@as(?usize, null), iter.next());
1120 testing.expectEqual(@as(usize, 0), a.count());1120 try testing.expectEqual(@as(usize, 0), a.count());
1121 }1121 }
1122 {1122 {
1123 var iter = a.iterator(.{ .direction = .reverse });1123 var iter = a.iterator(.{ .direction = .reverse });
1124 testing.expectEqual(@as(?usize, null), iter.next());1124 try testing.expectEqual(@as(?usize, null), iter.next());
1125 testing.expectEqual(@as(?usize, null), iter.next());1125 try testing.expectEqual(@as(?usize, null), iter.next());
1126 testing.expectEqual(@as(?usize, null), iter.next());1126 try testing.expectEqual(@as(?usize, null), iter.next());
1127 testing.expectEqual(@as(usize, 0), a.count());1127 try testing.expectEqual(@as(usize, 0), a.count());
1128 }1128 }
11291129
1130 const test_bits = [_]usize{1130 const test_bits = [_]usize{
...@@ -1139,51 +1139,51 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void {...@@ -1139,51 +1139,51 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void {
11391139
1140 for (test_bits) |i| {1140 for (test_bits) |i| {
1141 if (i < a.capacity()) {1141 if (i < a.capacity()) {
1142 testing.expectEqual(@as(?usize, i), a.findFirstSet());1142 try testing.expectEqual(@as(?usize, i), a.findFirstSet());
1143 testing.expectEqual(@as(?usize, i), a.toggleFirstSet());1143 try testing.expectEqual(@as(?usize, i), a.toggleFirstSet());
1144 }1144 }
1145 }1145 }
1146 testing.expectEqual(@as(?usize, null), a.findFirstSet());1146 try testing.expectEqual(@as(?usize, null), a.findFirstSet());
1147 testing.expectEqual(@as(?usize, null), a.toggleFirstSet());1147 try testing.expectEqual(@as(?usize, null), a.toggleFirstSet());
1148 testing.expectEqual(@as(?usize, null), a.findFirstSet());1148 try testing.expectEqual(@as(?usize, null), a.findFirstSet());
1149 testing.expectEqual(@as(?usize, null), a.toggleFirstSet());1149 try testing.expectEqual(@as(?usize, null), a.toggleFirstSet());
1150 testing.expectEqual(@as(usize, 0), a.count());1150 try testing.expectEqual(@as(usize, 0), a.count());
1151}1151}
11521152
1153fn testStaticBitSet(comptime Set: type) void {1153fn testStaticBitSet(comptime Set: type) !void {
1154 var a = Set.initEmpty();1154 var a = Set.initEmpty();
1155 var b = Set.initFull();1155 var b = Set.initFull();
1156 testing.expectEqual(@as(usize, 0), a.count());1156 try testing.expectEqual(@as(usize, 0), a.count());
1157 testing.expectEqual(@as(usize, Set.bit_length), b.count());1157 try testing.expectEqual(@as(usize, Set.bit_length), b.count());
11581158
1159 testBitSet(&a, &b, Set.bit_length);1159 try testBitSet(&a, &b, Set.bit_length);
1160}1160}
11611161
1162test "IntegerBitSet" {1162test "IntegerBitSet" {
1163 testStaticBitSet(IntegerBitSet(0));1163 try testStaticBitSet(IntegerBitSet(0));
1164 testStaticBitSet(IntegerBitSet(1));1164 try testStaticBitSet(IntegerBitSet(1));
1165 testStaticBitSet(IntegerBitSet(2));1165 try testStaticBitSet(IntegerBitSet(2));
1166 testStaticBitSet(IntegerBitSet(5));1166 try testStaticBitSet(IntegerBitSet(5));
1167 testStaticBitSet(IntegerBitSet(8));1167 try testStaticBitSet(IntegerBitSet(8));
1168 testStaticBitSet(IntegerBitSet(32));1168 try testStaticBitSet(IntegerBitSet(32));
1169 testStaticBitSet(IntegerBitSet(64));1169 try testStaticBitSet(IntegerBitSet(64));
1170 testStaticBitSet(IntegerBitSet(127));1170 try testStaticBitSet(IntegerBitSet(127));
1171}1171}
11721172
1173test "ArrayBitSet" {1173test "ArrayBitSet" {
1174 inline for (.{ 0, 1, 2, 31, 32, 33, 63, 64, 65, 254, 500, 3000 }) |size| {1174 inline for (.{ 0, 1, 2, 31, 32, 33, 63, 64, 65, 254, 500, 3000 }) |size| {
1175 testStaticBitSet(ArrayBitSet(u8, size));1175 try testStaticBitSet(ArrayBitSet(u8, size));
1176 testStaticBitSet(ArrayBitSet(u16, size));1176 try testStaticBitSet(ArrayBitSet(u16, size));
1177 testStaticBitSet(ArrayBitSet(u32, size));1177 try testStaticBitSet(ArrayBitSet(u32, size));
1178 testStaticBitSet(ArrayBitSet(u64, size));1178 try testStaticBitSet(ArrayBitSet(u64, size));
1179 testStaticBitSet(ArrayBitSet(u128, size));1179 try testStaticBitSet(ArrayBitSet(u128, size));
1180 }1180 }
1181}1181}
11821182
1183test "DynamicBitSetUnmanaged" {1183test "DynamicBitSetUnmanaged" {
1184 const allocator = std.testing.allocator;1184 const allocator = std.testing.allocator;
1185 var a = try DynamicBitSetUnmanaged.initEmpty(300, allocator);1185 var a = try DynamicBitSetUnmanaged.initEmpty(300, allocator);
1186 testing.expectEqual(@as(usize, 0), a.count());1186 try testing.expectEqual(@as(usize, 0), a.count());
1187 a.deinit(allocator);1187 a.deinit(allocator);
11881188
1189 a = try DynamicBitSetUnmanaged.initEmpty(0, allocator);1189 a = try DynamicBitSetUnmanaged.initEmpty(0, allocator);
...@@ -1193,10 +1193,10 @@ test "DynamicBitSetUnmanaged" {...@@ -1193,10 +1193,10 @@ test "DynamicBitSetUnmanaged" {
11931193
1194 var tmp = try a.clone(allocator);1194 var tmp = try a.clone(allocator);
1195 defer tmp.deinit(allocator);1195 defer tmp.deinit(allocator);
1196 testing.expectEqual(old_len, tmp.capacity());1196 try testing.expectEqual(old_len, tmp.capacity());
1197 var i: usize = 0;1197 var i: usize = 0;
1198 while (i < old_len) : (i += 1) {1198 while (i < old_len) : (i += 1) {
1199 testing.expectEqual(a.isSet(i), tmp.isSet(i));1199 try testing.expectEqual(a.isSet(i), tmp.isSet(i));
1200 }1200 }
12011201
1202 a.toggleSet(a); // zero a1202 a.toggleSet(a); // zero a
...@@ -1206,24 +1206,24 @@ test "DynamicBitSetUnmanaged" {...@@ -1206,24 +1206,24 @@ test "DynamicBitSetUnmanaged" {
1206 try tmp.resize(size, false, allocator);1206 try tmp.resize(size, false, allocator);
12071207
1208 if (size > old_len) {1208 if (size > old_len) {
1209 testing.expectEqual(size - old_len, a.count());1209 try testing.expectEqual(size - old_len, a.count());
1210 } else {1210 } else {
1211 testing.expectEqual(@as(usize, 0), a.count());1211 try testing.expectEqual(@as(usize, 0), a.count());
1212 }1212 }
1213 testing.expectEqual(@as(usize, 0), tmp.count());1213 try testing.expectEqual(@as(usize, 0), tmp.count());
12141214
1215 var b = try DynamicBitSetUnmanaged.initFull(size, allocator);1215 var b = try DynamicBitSetUnmanaged.initFull(size, allocator);
1216 defer b.deinit(allocator);1216 defer b.deinit(allocator);
1217 testing.expectEqual(@as(usize, size), b.count());1217 try testing.expectEqual(@as(usize, size), b.count());
12181218
1219 testBitSet(&a, &b, size);1219 try testBitSet(&a, &b, size);
1220 }1220 }
1221}1221}
12221222
1223test "DynamicBitSet" {1223test "DynamicBitSet" {
1224 const allocator = std.testing.allocator;1224 const allocator = std.testing.allocator;
1225 var a = try DynamicBitSet.initEmpty(300, allocator);1225 var a = try DynamicBitSet.initEmpty(300, allocator);
1226 testing.expectEqual(@as(usize, 0), a.count());1226 try testing.expectEqual(@as(usize, 0), a.count());
1227 a.deinit();1227 a.deinit();
12281228
1229 a = try DynamicBitSet.initEmpty(0, allocator);1229 a = try DynamicBitSet.initEmpty(0, allocator);
...@@ -1233,10 +1233,10 @@ test "DynamicBitSet" {...@@ -1233,10 +1233,10 @@ test "DynamicBitSet" {
12331233
1234 var tmp = try a.clone(allocator);1234 var tmp = try a.clone(allocator);
1235 defer tmp.deinit();1235 defer tmp.deinit();
1236 testing.expectEqual(old_len, tmp.capacity());1236 try testing.expectEqual(old_len, tmp.capacity());
1237 var i: usize = 0;1237 var i: usize = 0;
1238 while (i < old_len) : (i += 1) {1238 while (i < old_len) : (i += 1) {
1239 testing.expectEqual(a.isSet(i), tmp.isSet(i));1239 try testing.expectEqual(a.isSet(i), tmp.isSet(i));
1240 }1240 }
12411241
1242 a.toggleSet(a); // zero a1242 a.toggleSet(a); // zero a
...@@ -1246,24 +1246,24 @@ test "DynamicBitSet" {...@@ -1246,24 +1246,24 @@ test "DynamicBitSet" {
1246 try tmp.resize(size, false);1246 try tmp.resize(size, false);
12471247
1248 if (size > old_len) {1248 if (size > old_len) {
1249 testing.expectEqual(size - old_len, a.count());1249 try testing.expectEqual(size - old_len, a.count());
1250 } else {1250 } else {
1251 testing.expectEqual(@as(usize, 0), a.count());1251 try testing.expectEqual(@as(usize, 0), a.count());
1252 }1252 }
1253 testing.expectEqual(@as(usize, 0), tmp.count());1253 try testing.expectEqual(@as(usize, 0), tmp.count());
12541254
1255 var b = try DynamicBitSet.initFull(size, allocator);1255 var b = try DynamicBitSet.initFull(size, allocator);
1256 defer b.deinit();1256 defer b.deinit();
1257 testing.expectEqual(@as(usize, size), b.count());1257 try testing.expectEqual(@as(usize, size), b.count());
12581258
1259 testBitSet(&a, &b, size);1259 try testBitSet(&a, &b, size);
1260 }1260 }
1261}1261}
12621262
1263test "StaticBitSet" {1263test "StaticBitSet" {
1264 testing.expectEqual(IntegerBitSet(0), StaticBitSet(0));1264 try testing.expectEqual(IntegerBitSet(0), StaticBitSet(0));
1265 testing.expectEqual(IntegerBitSet(5), StaticBitSet(5));1265 try testing.expectEqual(IntegerBitSet(5), StaticBitSet(5));
1266 testing.expectEqual(IntegerBitSet(@bitSizeOf(usize)), StaticBitSet(@bitSizeOf(usize)));1266 try testing.expectEqual(IntegerBitSet(@bitSizeOf(usize)), StaticBitSet(@bitSizeOf(usize)));
1267 testing.expectEqual(ArrayBitSet(usize, @bitSizeOf(usize) + 1), StaticBitSet(@bitSizeOf(usize) + 1));1267 try testing.expectEqual(ArrayBitSet(usize, @bitSizeOf(usize) + 1), StaticBitSet(@bitSizeOf(usize) + 1));
1268 testing.expectEqual(ArrayBitSet(usize, 500), StaticBitSet(500));1268 try testing.expectEqual(ArrayBitSet(usize, 500), StaticBitSet(500));
1269}1269}
lib/std/buf_map.zig+7-7
...@@ -94,19 +94,19 @@ test "BufMap" {...@@ -94,19 +94,19 @@ test "BufMap" {
94 defer bufmap.deinit();94 defer bufmap.deinit();
9595
96 try bufmap.set("x", "1");96 try bufmap.set("x", "1");
97 testing.expect(mem.eql(u8, bufmap.get("x").?, "1"));97 try testing.expect(mem.eql(u8, bufmap.get("x").?, "1"));
98 testing.expect(1 == bufmap.count());98 try testing.expect(1 == bufmap.count());
9999
100 try bufmap.set("x", "2");100 try bufmap.set("x", "2");
101 testing.expect(mem.eql(u8, bufmap.get("x").?, "2"));101 try testing.expect(mem.eql(u8, bufmap.get("x").?, "2"));
102 testing.expect(1 == bufmap.count());102 try testing.expect(1 == bufmap.count());
103103
104 try bufmap.set("x", "3");104 try bufmap.set("x", "3");
105 testing.expect(mem.eql(u8, bufmap.get("x").?, "3"));105 try testing.expect(mem.eql(u8, bufmap.get("x").?, "3"));
106 testing.expect(1 == bufmap.count());106 try testing.expect(1 == bufmap.count());
107107
108 bufmap.delete("x");108 bufmap.delete("x");
109 testing.expect(0 == bufmap.count());109 try testing.expect(0 == bufmap.count());
110110
111 try bufmap.setMove(try allocator.dupe(u8, "k"), try allocator.dupe(u8, "v1"));111 try bufmap.setMove(try allocator.dupe(u8, "k"), try allocator.dupe(u8, "v1"));
112 try bufmap.setMove(try allocator.dupe(u8, "k"), try allocator.dupe(u8, "v2"));112 try bufmap.setMove(try allocator.dupe(u8, "k"), try allocator.dupe(u8, "v2"));
lib/std/buf_set.zig+2-2
...@@ -73,9 +73,9 @@ test "BufSet" {...@@ -73,9 +73,9 @@ test "BufSet" {
73 defer bufset.deinit();73 defer bufset.deinit();
7474
75 try bufset.put("x");75 try bufset.put("x");
76 testing.expect(bufset.count() == 1);76 try testing.expect(bufset.count() == 1);
77 bufset.delete("x");77 bufset.delete("x");
78 testing.expect(bufset.count() == 0);78 try testing.expect(bufset.count() == 0);
7979
80 try bufset.put("x");80 try bufset.put("x");
81 try bufset.put("y");81 try bufset.put("y");
lib/std/build.zig+11-11
...@@ -3060,19 +3060,19 @@ test "Builder.dupePkg()" {...@@ -3060,19 +3060,19 @@ test "Builder.dupePkg()" {
3060 const dupe_deps = dupe.dependencies.?;3060 const dupe_deps = dupe.dependencies.?;
30613061
3062 // probably the same top level package details3062 // probably the same top level package details
3063 std.testing.expectEqualStrings(pkg_top.name, dupe.name);3063 try std.testing.expectEqualStrings(pkg_top.name, dupe.name);
30643064
3065 // probably the same dependencies3065 // probably the same dependencies
3066 std.testing.expectEqual(original_deps.len, dupe_deps.len);3066 try std.testing.expectEqual(original_deps.len, dupe_deps.len);
3067 std.testing.expectEqual(original_deps[0].name, pkg_dep.name);3067 try std.testing.expectEqual(original_deps[0].name, pkg_dep.name);
30683068
3069 // could segfault otherwise if pointers in duplicated package's fields are3069 // could segfault otherwise if pointers in duplicated package's fields are
3070 // the same as those in stack allocated package's fields3070 // the same as those in stack allocated package's fields
3071 std.testing.expect(dupe_deps.ptr != original_deps.ptr);3071 try std.testing.expect(dupe_deps.ptr != original_deps.ptr);
3072 std.testing.expect(dupe.name.ptr != pkg_top.name.ptr);3072 try std.testing.expect(dupe.name.ptr != pkg_top.name.ptr);
3073 std.testing.expect(dupe.path.ptr != pkg_top.path.ptr);3073 try std.testing.expect(dupe.path.ptr != pkg_top.path.ptr);
3074 std.testing.expect(dupe_deps[0].name.ptr != pkg_dep.name.ptr);3074 try std.testing.expect(dupe_deps[0].name.ptr != pkg_dep.name.ptr);
3075 std.testing.expect(dupe_deps[0].path.ptr != pkg_dep.path.ptr);3075 try std.testing.expect(dupe_deps[0].path.ptr != pkg_dep.path.ptr);
3076}3076}
30773077
3078test "LibExeObjStep.addBuildOption" {3078test "LibExeObjStep.addBuildOption" {
...@@ -3096,7 +3096,7 @@ test "LibExeObjStep.addBuildOption" {...@@ -3096,7 +3096,7 @@ test "LibExeObjStep.addBuildOption" {
3096 exe.addBuildOption(?[]const u8, "optional_string", null);3096 exe.addBuildOption(?[]const u8, "optional_string", null);
3097 exe.addBuildOption(std.SemanticVersion, "semantic_version", try std.SemanticVersion.parse("0.1.2-foo+bar"));3097 exe.addBuildOption(std.SemanticVersion, "semantic_version", try std.SemanticVersion.parse("0.1.2-foo+bar"));
30983098
3099 std.testing.expectEqualStrings(3099 try std.testing.expectEqualStrings(
3100 \\pub const option1: usize = 1;3100 \\pub const option1: usize = 1;
3101 \\pub const option2: ?usize = null;3101 \\pub const option2: ?usize = null;
3102 \\pub const string: []const u8 = "zigisthebest";3102 \\pub const string: []const u8 = "zigisthebest";
...@@ -3140,10 +3140,10 @@ test "LibExeObjStep.addPackage" {...@@ -3140,10 +3140,10 @@ test "LibExeObjStep.addPackage" {
3140 var exe = builder.addExecutable("not_an_executable", "/not/an/executable.zig");3140 var exe = builder.addExecutable("not_an_executable", "/not/an/executable.zig");
3141 exe.addPackage(pkg_top);3141 exe.addPackage(pkg_top);
31423142
3143 std.testing.expectEqual(@as(usize, 1), exe.packages.items.len);3143 try std.testing.expectEqual(@as(usize, 1), exe.packages.items.len);
31443144
3145 const dupe = exe.packages.items[0];3145 const dupe = exe.packages.items[0];
3146 std.testing.expectEqualStrings(pkg_top.name, dupe.name);3146 try std.testing.expectEqualStrings(pkg_top.name, dupe.name);
3147}3147}
31483148
3149test {3149test {
lib/std/builtin.zig+1-1
...@@ -546,7 +546,7 @@ pub fn testVersionParse() !void {...@@ -546,7 +546,7 @@ pub fn testVersionParse() !void {
546 const f = struct {546 const f = struct {
547 fn eql(text: []const u8, v1: u32, v2: u32, v3: u32) !void {547 fn eql(text: []const u8, v1: u32, v2: u32, v3: u32) !void {
548 const v = try Version.parse(text);548 const v = try Version.parse(text);
549 std.testing.expect(v.major == v1 and v.minor == v2 and v.patch == v3);549 try std.testing.expect(v.major == v1 and v.minor == v2 and v.patch == v3);
550 }550 }
551551
552 fn err(text: []const u8, expected_err: anyerror) !void {552 fn err(text: []const u8, expected_err: anyerror) !void {
lib/std/c/tokenizer.zig+8-8
...@@ -1310,7 +1310,7 @@ pub const Tokenizer = struct {...@@ -1310,7 +1310,7 @@ pub const Tokenizer = struct {
1310};1310};
13111311
1312test "operators" {1312test "operators" {
1313 expectTokens(1313 try expectTokens(
1314 \\ ! != | || |= = ==1314 \\ ! != | || |= = ==
1315 \\ ( ) { } [ ] . .. ...1315 \\ ( ) { } [ ] . .. ...
1316 \\ ^ ^= + ++ += - -- -=1316 \\ ^ ^= + ++ += - -- -=
...@@ -1379,7 +1379,7 @@ test "operators" {...@@ -1379,7 +1379,7 @@ test "operators" {
1379}1379}
13801380
1381test "keywords" {1381test "keywords" {
1382 expectTokens(1382 try expectTokens(
1383 \\auto break case char const continue default do 1383 \\auto break case char const continue default do
1384 \\double else enum extern float for goto if int 1384 \\double else enum extern float for goto if int
1385 \\long register return short signed sizeof static 1385 \\long register return short signed sizeof static
...@@ -1442,7 +1442,7 @@ test "keywords" {...@@ -1442,7 +1442,7 @@ test "keywords" {
1442}1442}
14431443
1444test "preprocessor keywords" {1444test "preprocessor keywords" {
1445 expectTokens(1445 try expectTokens(
1446 \\#include <test>1446 \\#include <test>
1447 \\#define #include <11447 \\#define #include <1
1448 \\#ifdef1448 \\#ifdef
...@@ -1478,7 +1478,7 @@ test "preprocessor keywords" {...@@ -1478,7 +1478,7 @@ test "preprocessor keywords" {
1478}1478}
14791479
1480test "line continuation" {1480test "line continuation" {
1481 expectTokens(1481 try expectTokens(
1482 \\#define foo \1482 \\#define foo \
1483 \\ bar1483 \\ bar
1484 \\"foo\1484 \\"foo\
...@@ -1509,7 +1509,7 @@ test "line continuation" {...@@ -1509,7 +1509,7 @@ test "line continuation" {
1509}1509}
15101510
1511test "string prefix" {1511test "string prefix" {
1512 expectTokens(1512 try expectTokens(
1513 \\"foo"1513 \\"foo"
1514 \\u"foo"1514 \\u"foo"
1515 \\u8"foo"1515 \\u8"foo"
...@@ -1543,7 +1543,7 @@ test "string prefix" {...@@ -1543,7 +1543,7 @@ test "string prefix" {
1543}1543}
15441544
1545test "num suffixes" {1545test "num suffixes" {
1546 expectTokens(1546 try expectTokens(
1547 \\ 1.0f 1.0L 1.0 .0 1.1547 \\ 1.0f 1.0L 1.0 .0 1.
1548 \\ 0l 0lu 0ll 0llu 01548 \\ 0l 0lu 0ll 0llu 0
1549 \\ 1u 1ul 1ull 11549 \\ 1u 1ul 1ull 1
...@@ -1573,7 +1573,7 @@ test "num suffixes" {...@@ -1573,7 +1573,7 @@ test "num suffixes" {
1573 });1573 });
1574}1574}
15751575
1576fn expectTokens(source: []const u8, expected_tokens: []const Token.Id) void {1576fn expectTokens(source: []const u8, expected_tokens: []const Token.Id) !void {
1577 var tokenizer = Tokenizer{1577 var tokenizer = Tokenizer{
1578 .buffer = source,1578 .buffer = source,
1579 };1579 };
...@@ -1584,5 +1584,5 @@ fn expectTokens(source: []const u8, expected_tokens: []const Token.Id) void {...@@ -1584,5 +1584,5 @@ fn expectTokens(source: []const u8, expected_tokens: []const Token.Id) void {
1584 }1584 }
1585 }1585 }
1586 const last_token = tokenizer.next();1586 const last_token = tokenizer.next();
1587 std.testing.expect(last_token.id == .Eof);1587 try std.testing.expect(last_token.id == .Eof);
1588}1588}
lib/std/child_process.zig+2-2
...@@ -1005,7 +1005,7 @@ test "createNullDelimitedEnvMap" {...@@ -1005,7 +1005,7 @@ test "createNullDelimitedEnvMap" {
1005 defer arena.deinit();1005 defer arena.deinit();
1006 const environ = try createNullDelimitedEnvMap(&arena.allocator, &envmap);1006 const environ = try createNullDelimitedEnvMap(&arena.allocator, &envmap);
10071007
1008 testing.expectEqual(@as(usize, 5), environ.len);1008 try testing.expectEqual(@as(usize, 5), environ.len);
10091009
1010 inline for (.{1010 inline for (.{
1011 "HOME=/home/ifreund",1011 "HOME=/home/ifreund",
...@@ -1017,7 +1017,7 @@ test "createNullDelimitedEnvMap" {...@@ -1017,7 +1017,7 @@ test "createNullDelimitedEnvMap" {
1017 for (environ) |variable| {1017 for (environ) |variable| {
1018 if (mem.eql(u8, mem.span(variable orelse continue), target)) break;1018 if (mem.eql(u8, mem.span(variable orelse continue), target)) break;
1019 } else {1019 } else {
1020 testing.expect(false); // Environment variable not found1020 try testing.expect(false); // Environment variable not found
1021 }1021 }
1022 }1022 }
1023}1023}
lib/std/compress/deflate.zig+1-1
...@@ -669,5 +669,5 @@ test "lengths overflow" {...@@ -669,5 +669,5 @@ test "lengths overflow" {
669 var inflate = inflateStream(reader, &window);669 var inflate = inflateStream(reader, &window);
670670
671 var buf: [1]u8 = undefined;671 var buf: [1]u8 = undefined;
672 std.testing.expectError(error.InvalidLength, inflate.read(&buf));672 try std.testing.expectError(error.InvalidLength, inflate.read(&buf));
673}673}
lib/std/compress/gzip.zig+9-9
...@@ -172,17 +172,17 @@ fn testReader(data: []const u8, comptime expected: []const u8) !void {...@@ -172,17 +172,17 @@ fn testReader(data: []const u8, comptime expected: []const u8) !void {
172 var hash: [32]u8 = undefined;172 var hash: [32]u8 = undefined;
173 std.crypto.hash.sha2.Sha256.hash(buf, hash[0..], .{});173 std.crypto.hash.sha2.Sha256.hash(buf, hash[0..], .{});
174174
175 assertEqual(expected, &hash);175 try assertEqual(expected, &hash);
176}176}
177177
178// Assert `expected` == `input` where `input` is a bytestring.178// Assert `expected` == `input` where `input` is a bytestring.
179pub fn assertEqual(comptime expected: []const u8, input: []const u8) void {179pub fn assertEqual(comptime expected: []const u8, input: []const u8) !void {
180 var expected_bytes: [expected.len / 2]u8 = undefined;180 var expected_bytes: [expected.len / 2]u8 = undefined;
181 for (expected_bytes) |*r, i| {181 for (expected_bytes) |*r, i| {
182 r.* = std.fmt.parseInt(u8, expected[2 * i .. 2 * i + 2], 16) catch unreachable;182 r.* = std.fmt.parseInt(u8, expected[2 * i .. 2 * i + 2], 16) catch unreachable;
183 }183 }
184184
185 testing.expectEqualSlices(u8, &expected_bytes, input);185 try testing.expectEqualSlices(u8, &expected_bytes, input);
186}186}
187187
188// All the test cases are obtained by compressing the RFC1952 text188// All the test cases are obtained by compressing the RFC1952 text
...@@ -198,12 +198,12 @@ test "compressed data" {...@@ -198,12 +198,12 @@ test "compressed data" {
198198
199test "sanity checks" {199test "sanity checks" {
200 // Truncated header200 // Truncated header
201 testing.expectError(201 try testing.expectError(
202 error.EndOfStream,202 error.EndOfStream,
203 testReader(&[_]u8{ 0x1f, 0x8B }, ""),203 testReader(&[_]u8{ 0x1f, 0x8B }, ""),
204 );204 );
205 // Wrong CM205 // Wrong CM
206 testing.expectError(206 try testing.expectError(
207 error.InvalidCompression,207 error.InvalidCompression,
208 testReader(&[_]u8{208 testReader(&[_]u8{
209 0x1f, 0x8b, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00,209 0x1f, 0x8b, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00,
...@@ -211,7 +211,7 @@ test "sanity checks" {...@@ -211,7 +211,7 @@ test "sanity checks" {
211 }, ""),211 }, ""),
212 );212 );
213 // Wrong checksum213 // Wrong checksum
214 testing.expectError(214 try testing.expectError(
215 error.WrongChecksum,215 error.WrongChecksum,
216 testReader(&[_]u8{216 testReader(&[_]u8{
217 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,217 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
...@@ -220,7 +220,7 @@ test "sanity checks" {...@@ -220,7 +220,7 @@ test "sanity checks" {
220 }, ""),220 }, ""),
221 );221 );
222 // Truncated checksum222 // Truncated checksum
223 testing.expectError(223 try testing.expectError(
224 error.EndOfStream,224 error.EndOfStream,
225 testReader(&[_]u8{225 testReader(&[_]u8{
226 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,226 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
...@@ -228,7 +228,7 @@ test "sanity checks" {...@@ -228,7 +228,7 @@ test "sanity checks" {
228 }, ""),228 }, ""),
229 );229 );
230 // Wrong initial size230 // Wrong initial size
231 testing.expectError(231 try testing.expectError(
232 error.CorruptedData,232 error.CorruptedData,
233 testReader(&[_]u8{233 testReader(&[_]u8{
234 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,234 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
...@@ -237,7 +237,7 @@ test "sanity checks" {...@@ -237,7 +237,7 @@ test "sanity checks" {
237 }, ""),237 }, ""),
238 );238 );
239 // Truncated initial size field239 // Truncated initial size field
240 testing.expectError(240 try testing.expectError(
241 error.EndOfStream,241 error.EndOfStream,
242 testReader(&[_]u8{242 testReader(&[_]u8{
243 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,243 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
lib/std/compress/zlib.zig+9-9
...@@ -109,17 +109,17 @@ fn testReader(data: []const u8, comptime expected: []const u8) !void {...@@ -109,17 +109,17 @@ fn testReader(data: []const u8, comptime expected: []const u8) !void {
109 var hash: [32]u8 = undefined;109 var hash: [32]u8 = undefined;
110 std.crypto.hash.sha2.Sha256.hash(buf, hash[0..], .{});110 std.crypto.hash.sha2.Sha256.hash(buf, hash[0..], .{});
111111
112 assertEqual(expected, &hash);112 try assertEqual(expected, &hash);
113}113}
114114
115// Assert `expected` == `input` where `input` is a bytestring.115// Assert `expected` == `input` where `input` is a bytestring.
116pub fn assertEqual(comptime expected: []const u8, input: []const u8) void {116pub fn assertEqual(comptime expected: []const u8, input: []const u8) !void {
117 var expected_bytes: [expected.len / 2]u8 = undefined;117 var expected_bytes: [expected.len / 2]u8 = undefined;
118 for (expected_bytes) |*r, i| {118 for (expected_bytes) |*r, i| {
119 r.* = std.fmt.parseInt(u8, expected[2 * i .. 2 * i + 2], 16) catch unreachable;119 r.* = std.fmt.parseInt(u8, expected[2 * i .. 2 * i + 2], 16) catch unreachable;
120 }120 }
121121
122 testing.expectEqualSlices(u8, &expected_bytes, input);122 try testing.expectEqualSlices(u8, &expected_bytes, input);
123}123}
124124
125// All the test cases are obtained by compressing the RFC1950 text125// All the test cases are obtained by compressing the RFC1950 text
...@@ -159,32 +159,32 @@ test "don't read past deflate stream's end" {...@@ -159,32 +159,32 @@ test "don't read past deflate stream's end" {
159159
160test "sanity checks" {160test "sanity checks" {
161 // Truncated header161 // Truncated header
162 testing.expectError(162 try testing.expectError(
163 error.EndOfStream,163 error.EndOfStream,
164 testReader(&[_]u8{0x78}, ""),164 testReader(&[_]u8{0x78}, ""),
165 );165 );
166 // Failed FCHECK check166 // Failed FCHECK check
167 testing.expectError(167 try testing.expectError(
168 error.BadHeader,168 error.BadHeader,
169 testReader(&[_]u8{ 0x78, 0x9D }, ""),169 testReader(&[_]u8{ 0x78, 0x9D }, ""),
170 );170 );
171 // Wrong CM171 // Wrong CM
172 testing.expectError(172 try testing.expectError(
173 error.InvalidCompression,173 error.InvalidCompression,
174 testReader(&[_]u8{ 0x79, 0x94 }, ""),174 testReader(&[_]u8{ 0x79, 0x94 }, ""),
175 );175 );
176 // Wrong CINFO176 // Wrong CINFO
177 testing.expectError(177 try testing.expectError(
178 error.InvalidWindowSize,178 error.InvalidWindowSize,
179 testReader(&[_]u8{ 0x88, 0x98 }, ""),179 testReader(&[_]u8{ 0x88, 0x98 }, ""),
180 );180 );
181 // Wrong checksum181 // Wrong checksum
182 testing.expectError(182 try testing.expectError(
183 error.WrongChecksum,183 error.WrongChecksum,
184 testReader(&[_]u8{ 0x78, 0xda, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00 }, ""),184 testReader(&[_]u8{ 0x78, 0xda, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00 }, ""),
185 );185 );
186 // Truncated checksum186 // Truncated checksum
187 testing.expectError(187 try testing.expectError(
188 error.EndOfStream,188 error.EndOfStream,
189 testReader(&[_]u8{ 0x78, 0xda, 0x03, 0x00, 0x00 }, ""),189 testReader(&[_]u8{ 0x78, 0xda, 0x03, 0x00, 0x00 }, ""),
190 );190 );
lib/std/comptime_string_map.zig+21-21
...@@ -95,7 +95,7 @@ test "ComptimeStringMap list literal of list literals" {...@@ -95,7 +95,7 @@ test "ComptimeStringMap list literal of list literals" {
95 .{ "samelen", .E },95 .{ "samelen", .E },
96 });96 });
9797
98 testMap(map);98 try testMap(map);
99}99}
100100
101test "ComptimeStringMap array of structs" {101test "ComptimeStringMap array of structs" {
...@@ -111,7 +111,7 @@ test "ComptimeStringMap array of structs" {...@@ -111,7 +111,7 @@ test "ComptimeStringMap array of structs" {
111 .{ .@"0" = "samelen", .@"1" = .E },111 .{ .@"0" = "samelen", .@"1" = .E },
112 });112 });
113113
114 testMap(map);114 try testMap(map);
115}115}
116116
117test "ComptimeStringMap slice of structs" {117test "ComptimeStringMap slice of structs" {
...@@ -128,18 +128,18 @@ test "ComptimeStringMap slice of structs" {...@@ -128,18 +128,18 @@ test "ComptimeStringMap slice of structs" {
128 };128 };
129 const map = ComptimeStringMap(TestEnum, slice);129 const map = ComptimeStringMap(TestEnum, slice);
130130
131 testMap(map);131 try testMap(map);
132}132}
133133
134fn testMap(comptime map: anytype) void {134fn testMap(comptime map: anytype) !void {
135 std.testing.expectEqual(TestEnum.A, map.get("have").?);135 try std.testing.expectEqual(TestEnum.A, map.get("have").?);
136 std.testing.expectEqual(TestEnum.B, map.get("nothing").?);136 try std.testing.expectEqual(TestEnum.B, map.get("nothing").?);
137 std.testing.expect(null == map.get("missing"));137 try std.testing.expect(null == map.get("missing"));
138 std.testing.expectEqual(TestEnum.D, map.get("these").?);138 try std.testing.expectEqual(TestEnum.D, map.get("these").?);
139 std.testing.expectEqual(TestEnum.E, map.get("samelen").?);139 try std.testing.expectEqual(TestEnum.E, map.get("samelen").?);
140140
141 std.testing.expect(!map.has("missing"));141 try std.testing.expect(!map.has("missing"));
142 std.testing.expect(map.has("these"));142 try std.testing.expect(map.has("these"));
143}143}
144144
145test "ComptimeStringMap void value type, slice of structs" {145test "ComptimeStringMap void value type, slice of structs" {
...@@ -155,7 +155,7 @@ test "ComptimeStringMap void value type, slice of structs" {...@@ -155,7 +155,7 @@ test "ComptimeStringMap void value type, slice of structs" {
155 };155 };
156 const map = ComptimeStringMap(void, slice);156 const map = ComptimeStringMap(void, slice);
157157
158 testSet(map);158 try testSet(map);
159}159}
160160
161test "ComptimeStringMap void value type, list literal of list literals" {161test "ComptimeStringMap void value type, list literal of list literals" {
...@@ -167,16 +167,16 @@ test "ComptimeStringMap void value type, list literal of list literals" {...@@ -167,16 +167,16 @@ test "ComptimeStringMap void value type, list literal of list literals" {
167 .{"samelen"},167 .{"samelen"},
168 });168 });
169169
170 testSet(map);170 try testSet(map);
171}171}
172172
173fn testSet(comptime map: anytype) void {173fn testSet(comptime map: anytype) !void {
174 std.testing.expectEqual({}, map.get("have").?);174 try std.testing.expectEqual({}, map.get("have").?);
175 std.testing.expectEqual({}, map.get("nothing").?);175 try std.testing.expectEqual({}, map.get("nothing").?);
176 std.testing.expect(null == map.get("missing"));176 try std.testing.expect(null == map.get("missing"));
177 std.testing.expectEqual({}, map.get("these").?);177 try std.testing.expectEqual({}, map.get("these").?);
178 std.testing.expectEqual({}, map.get("samelen").?);178 try std.testing.expectEqual({}, map.get("samelen").?);
179179
180 std.testing.expect(!map.has("missing"));180 try std.testing.expect(!map.has("missing"));
181 std.testing.expect(map.has("these"));181 try std.testing.expect(map.has("these"));
182}182}
lib/std/crypto.zig+2-2
...@@ -188,7 +188,7 @@ test "CSPRNG" {...@@ -188,7 +188,7 @@ test "CSPRNG" {
188 const a = random.int(u64);188 const a = random.int(u64);
189 const b = random.int(u64);189 const b = random.int(u64);
190 const c = random.int(u64);190 const c = random.int(u64);
191 std.testing.expect(a ^ b ^ c != 0);191 try std.testing.expect(a ^ b ^ c != 0);
192}192}
193193
194test "issue #4532: no index out of bounds" {194test "issue #4532: no index out of bounds" {
...@@ -226,6 +226,6 @@ test "issue #4532: no index out of bounds" {...@@ -226,6 +226,6 @@ test "issue #4532: no index out of bounds" {
226 h.update(block[1..]);226 h.update(block[1..]);
227 h.final(&out2);227 h.final(&out2);
228228
229 std.testing.expectEqual(out1, out2);229 try std.testing.expectEqual(out1, out2);
230 }230 }
231}231}
lib/std/crypto/25519/curve25519.zig+6-6
...@@ -120,13 +120,13 @@ test "curve25519" {...@@ -120,13 +120,13 @@ test "curve25519" {
120 const p = try Curve25519.basePoint.clampedMul(s);120 const p = try Curve25519.basePoint.clampedMul(s);
121 try p.rejectIdentity();121 try p.rejectIdentity();
122 var buf: [128]u8 = undefined;122 var buf: [128]u8 = undefined;
123 std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&p.toBytes())}), "E6F2A4D1C28EE5C7AD0329268255A468AD407D2672824C0C0EB30EA6EF450145");123 try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&p.toBytes())}), "E6F2A4D1C28EE5C7AD0329268255A468AD407D2672824C0C0EB30EA6EF450145");
124 const q = try p.clampedMul(s);124 const q = try p.clampedMul(s);
125 std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&q.toBytes())}), "3614E119FFE55EC55B87D6B19971A9F4CBC78EFE80BEC55B96392BABCC712537");125 try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&q.toBytes())}), "3614E119FFE55EC55B87D6B19971A9F4CBC78EFE80BEC55B96392BABCC712537");
126126
127 try Curve25519.rejectNonCanonical(s);127 try Curve25519.rejectNonCanonical(s);
128 s[31] |= 0x80;128 s[31] |= 0x80;
129 std.testing.expectError(error.NonCanonical, Curve25519.rejectNonCanonical(s));129 try std.testing.expectError(error.NonCanonical, Curve25519.rejectNonCanonical(s));
130}130}
131131
132test "curve25519 small order check" {132test "curve25519 small order check" {
...@@ -155,13 +155,13 @@ test "curve25519 small order check" {...@@ -155,13 +155,13 @@ test "curve25519 small order check" {
155 },155 },
156 };156 };
157 for (small_order_ss) |small_order_s| {157 for (small_order_ss) |small_order_s| {
158 std.testing.expectError(error.WeakPublicKey, Curve25519.fromBytes(small_order_s).mul(s));158 try std.testing.expectError(error.WeakPublicKey, Curve25519.fromBytes(small_order_s).mul(s));
159 var extra = small_order_s;159 var extra = small_order_s;
160 extra[31] ^= 0x80;160 extra[31] ^= 0x80;
161 std.testing.expectError(error.WeakPublicKey, Curve25519.fromBytes(extra).mul(s));161 try std.testing.expectError(error.WeakPublicKey, Curve25519.fromBytes(extra).mul(s));
162 var valid = small_order_s;162 var valid = small_order_s;
163 valid[31] = 0x40;163 valid[31] = 0x40;
164 s[0] = 0;164 s[0] = 0;
165 std.testing.expectError(error.IdentityElement, Curve25519.fromBytes(valid).mul(s));165 try std.testing.expectError(error.IdentityElement, Curve25519.fromBytes(valid).mul(s));
166 }166 }
167}167}
lib/std/crypto/25519/ed25519.zig+6-6
...@@ -219,8 +219,8 @@ test "ed25519 key pair creation" {...@@ -219,8 +219,8 @@ test "ed25519 key pair creation" {
219 _ = try fmt.hexToBytes(seed[0..], "8052030376d47112be7f73ed7a019293dd12ad910b654455798b4667d73de166");219 _ = try fmt.hexToBytes(seed[0..], "8052030376d47112be7f73ed7a019293dd12ad910b654455798b4667d73de166");
220 const key_pair = try Ed25519.KeyPair.create(seed);220 const key_pair = try Ed25519.KeyPair.create(seed);
221 var buf: [256]u8 = undefined;221 var buf: [256]u8 = undefined;
222 std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&key_pair.secret_key)}), "8052030376D47112BE7F73ED7A019293DD12AD910B654455798B4667D73DE1662D6F7455D97B4A3A10D7293909D1A4F2058CB9A370E43FA8154BB280DB839083");222 try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&key_pair.secret_key)}), "8052030376D47112BE7F73ED7A019293DD12AD910B654455798B4667D73DE1662D6F7455D97B4A3A10D7293909D1A4F2058CB9A370E43FA8154BB280DB839083");
223 std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&key_pair.public_key)}), "2D6F7455D97B4A3A10D7293909D1A4F2058CB9A370E43FA8154BB280DB839083");223 try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&key_pair.public_key)}), "2D6F7455D97B4A3A10D7293909D1A4F2058CB9A370E43FA8154BB280DB839083");
224}224}
225225
226test "ed25519 signature" {226test "ed25519 signature" {
...@@ -230,9 +230,9 @@ test "ed25519 signature" {...@@ -230,9 +230,9 @@ test "ed25519 signature" {
230230
231 const sig = try Ed25519.sign("test", key_pair, null);231 const sig = try Ed25519.sign("test", key_pair, null);
232 var buf: [128]u8 = undefined;232 var buf: [128]u8 = undefined;
233 std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&sig)}), "10A442B4A80CC4225B154F43BEF28D2472CA80221951262EB8E0DF9091575E2687CC486E77263C3418C757522D54F84B0359236ABBBD4ACD20DC297FDCA66808");233 try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&sig)}), "10A442B4A80CC4225B154F43BEF28D2472CA80221951262EB8E0DF9091575E2687CC486E77263C3418C757522D54F84B0359236ABBBD4ACD20DC297FDCA66808");
234 try Ed25519.verify(sig, "test", key_pair.public_key);234 try Ed25519.verify(sig, "test", key_pair.public_key);
235 std.testing.expectError(error.SignatureVerificationFailed, Ed25519.verify(sig, "TEST", key_pair.public_key));235 try std.testing.expectError(error.SignatureVerificationFailed, Ed25519.verify(sig, "TEST", key_pair.public_key));
236}236}
237237
238test "ed25519 batch verification" {238test "ed25519 batch verification" {
...@@ -260,7 +260,7 @@ test "ed25519 batch verification" {...@@ -260,7 +260,7 @@ test "ed25519 batch verification" {
260 try Ed25519.verifyBatch(2, signature_batch);260 try Ed25519.verifyBatch(2, signature_batch);
261261
262 signature_batch[1].sig = sig1;262 signature_batch[1].sig = sig1;
263 std.testing.expectError(error.SignatureVerificationFailed, Ed25519.verifyBatch(signature_batch.len, signature_batch));263 try std.testing.expectError(error.SignatureVerificationFailed, Ed25519.verifyBatch(signature_batch.len, signature_batch));
264 }264 }
265}265}
266266
...@@ -354,7 +354,7 @@ test "ed25519 test vectors" {...@@ -354,7 +354,7 @@ test "ed25519 test vectors" {
354 var sig: [64]u8 = undefined;354 var sig: [64]u8 = undefined;
355 _ = try fmt.hexToBytes(&sig, entry.sig_hex);355 _ = try fmt.hexToBytes(&sig, entry.sig_hex);
356 if (entry.expected) |error_type| {356 if (entry.expected) |error_type| {
357 std.testing.expectError(error_type, Ed25519.verify(sig, &msg, public_key));357 try std.testing.expectError(error_type, Ed25519.verify(sig, &msg, public_key));
358 } else {358 } else {
359 try Ed25519.verify(sig, &msg, public_key);359 try Ed25519.verify(sig, &msg, public_key);
360 }360 }
lib/std/crypto/25519/edwards25519.zig+9-9
...@@ -491,7 +491,7 @@ test "edwards25519 packing/unpacking" {...@@ -491,7 +491,7 @@ test "edwards25519 packing/unpacking" {
491 var b = Edwards25519.basePoint;491 var b = Edwards25519.basePoint;
492 const pk = try b.mul(s);492 const pk = try b.mul(s);
493 var buf: [128]u8 = undefined;493 var buf: [128]u8 = undefined;
494 std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&pk.toBytes())}), "074BC7E0FCBD587FDBC0969444245FADC562809C8F6E97E949AF62484B5B81A6");494 try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&pk.toBytes())}), "074BC7E0FCBD587FDBC0969444245FADC562809C8F6E97E949AF62484B5B81A6");
495495
496 const small_order_ss: [7][32]u8 = .{496 const small_order_ss: [7][32]u8 = .{
497 .{497 .{
...@@ -518,7 +518,7 @@ test "edwards25519 packing/unpacking" {...@@ -518,7 +518,7 @@ test "edwards25519 packing/unpacking" {
518 };518 };
519 for (small_order_ss) |small_order_s| {519 for (small_order_ss) |small_order_s| {
520 const small_p = try Edwards25519.fromBytes(small_order_s);520 const small_p = try Edwards25519.fromBytes(small_order_s);
521 std.testing.expectError(error.WeakPublicKey, small_p.mul(s));521 try std.testing.expectError(error.WeakPublicKey, small_p.mul(s));
522 }522 }
523}523}
524524
...@@ -531,26 +531,26 @@ test "edwards25519 point addition/substraction" {...@@ -531,26 +531,26 @@ test "edwards25519 point addition/substraction" {
531 const q = try Edwards25519.basePoint.clampedMul(s2);531 const q = try Edwards25519.basePoint.clampedMul(s2);
532 const r = p.add(q).add(q).sub(q).sub(q);532 const r = p.add(q).add(q).sub(q).sub(q);
533 try r.rejectIdentity();533 try r.rejectIdentity();
534 std.testing.expectError(error.IdentityElement, r.sub(p).rejectIdentity());534 try std.testing.expectError(error.IdentityElement, r.sub(p).rejectIdentity());
535 std.testing.expectError(error.IdentityElement, p.sub(p).rejectIdentity());535 try std.testing.expectError(error.IdentityElement, p.sub(p).rejectIdentity());
536 std.testing.expectError(error.IdentityElement, p.sub(q).add(q).sub(p).rejectIdentity());536 try std.testing.expectError(error.IdentityElement, p.sub(q).add(q).sub(p).rejectIdentity());
537}537}
538538
539test "edwards25519 uniform-to-point" {539test "edwards25519 uniform-to-point" {
540 var r = [32]u8{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 };540 var r = [32]u8{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 };
541 var p = Edwards25519.fromUniform(r);541 var p = Edwards25519.fromUniform(r);
542 htest.assertEqual("0691eee3cf70a0056df6bfa03120635636581b5c4ea571dfc680f78c7e0b4137", p.toBytes()[0..]);542 try htest.assertEqual("0691eee3cf70a0056df6bfa03120635636581b5c4ea571dfc680f78c7e0b4137", p.toBytes()[0..]);
543543
544 r[31] = 0xff;544 r[31] = 0xff;
545 p = Edwards25519.fromUniform(r);545 p = Edwards25519.fromUniform(r);
546 htest.assertEqual("f70718e68ef42d90ca1d936bb2d7e159be6c01d8095d39bd70487c82fe5c973a", p.toBytes()[0..]);546 try htest.assertEqual("f70718e68ef42d90ca1d936bb2d7e159be6c01d8095d39bd70487c82fe5c973a", p.toBytes()[0..]);
547}547}
548548
549// Test vectors from draft-irtf-cfrg-hash-to-curve-10549// Test vectors from draft-irtf-cfrg-hash-to-curve-10
550test "edwards25519 hash-to-curve operation" {550test "edwards25519 hash-to-curve operation" {
551 var p = Edwards25519.fromString(true, "QUUX-V01-CS02-with-edwards25519_XMD:SHA-512_ELL2_RO_", "abc");551 var p = Edwards25519.fromString(true, "QUUX-V01-CS02-with-edwards25519_XMD:SHA-512_ELL2_RO_", "abc");
552 htest.assertEqual("31558a26887f23fb8218f143e69d5f0af2e7831130bd5b432ef23883b895831a", p.toBytes()[0..]);552 try htest.assertEqual("31558a26887f23fb8218f143e69d5f0af2e7831130bd5b432ef23883b895831a", p.toBytes()[0..]);
553553
554 p = Edwards25519.fromString(false, "QUUX-V01-CS02-with-edwards25519_XMD:SHA-512_ELL2_NU_", "abc");554 p = Edwards25519.fromString(false, "QUUX-V01-CS02-with-edwards25519_XMD:SHA-512_ELL2_NU_", "abc");
555 htest.assertEqual("42fa27c8f5a1ae0aa38bb59d5938e5145622ba5dedd11d11736fa2f9502d73e7", p.toBytes()[0..]);555 try htest.assertEqual("42fa27c8f5a1ae0aa38bb59d5938e5145622ba5dedd11d11736fa2f9502d73e7", p.toBytes()[0..]);
556}556}
lib/std/crypto/25519/ristretto255.zig+5-5
...@@ -175,21 +175,21 @@ pub const Ristretto255 = struct {...@@ -175,21 +175,21 @@ pub const Ristretto255 = struct {
175test "ristretto255" {175test "ristretto255" {
176 const p = Ristretto255.basePoint;176 const p = Ristretto255.basePoint;
177 var buf: [256]u8 = undefined;177 var buf: [256]u8 = undefined;
178 std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&p.toBytes())}), "E2F2AE0A6ABC4E71A884A961C500515F58E30B6AA582DD8DB6A65945E08D2D76");178 try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&p.toBytes())}), "E2F2AE0A6ABC4E71A884A961C500515F58E30B6AA582DD8DB6A65945E08D2D76");
179179
180 var r: [Ristretto255.encoded_length]u8 = undefined;180 var r: [Ristretto255.encoded_length]u8 = undefined;
181 _ = try fmt.hexToBytes(r[0..], "6a493210f7499cd17fecb510ae0cea23a110e8d5b901f8acadd3095c73a3b919");181 _ = try fmt.hexToBytes(r[0..], "6a493210f7499cd17fecb510ae0cea23a110e8d5b901f8acadd3095c73a3b919");
182 var q = try Ristretto255.fromBytes(r);182 var q = try Ristretto255.fromBytes(r);
183 q = q.dbl().add(p);183 q = q.dbl().add(p);
184 std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&q.toBytes())}), "E882B131016B52C1D3337080187CF768423EFCCBB517BB495AB812C4160FF44E");184 try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&q.toBytes())}), "E882B131016B52C1D3337080187CF768423EFCCBB517BB495AB812C4160FF44E");
185185
186 const s = [_]u8{15} ++ [_]u8{0} ** 31;186 const s = [_]u8{15} ++ [_]u8{0} ** 31;
187 const w = try p.mul(s);187 const w = try p.mul(s);
188 std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&w.toBytes())}), "E0C418F7C8D9C4CDD7395B93EA124F3AD99021BB681DFC3302A9D99A2E53E64E");188 try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&w.toBytes())}), "E0C418F7C8D9C4CDD7395B93EA124F3AD99021BB681DFC3302A9D99A2E53E64E");
189189
190 std.testing.expect(p.dbl().dbl().dbl().dbl().equivalent(w.add(p)));190 try std.testing.expect(p.dbl().dbl().dbl().dbl().equivalent(w.add(p)));
191191
192 const h = [_]u8{69} ** 32 ++ [_]u8{42} ** 32;192 const h = [_]u8{69} ** 32 ++ [_]u8{42} ** 32;
193 const ph = Ristretto255.fromUniform(h);193 const ph = Ristretto255.fromUniform(h);
194 std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&ph.toBytes())}), "DCCA54E037A4311EFBEEF413ACD21D35276518970B7A61DC88F8587B493D5E19");194 try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&ph.toBytes())}), "DCCA54E037A4311EFBEEF413ACD21D35276518970B7A61DC88F8587B493D5E19");
195}195}
lib/std/crypto/25519/scalar.zig+4-4
...@@ -773,15 +773,15 @@ test "scalar25519" {...@@ -773,15 +773,15 @@ test "scalar25519" {
773 var y = x.toBytes();773 var y = x.toBytes();
774 try rejectNonCanonical(y);774 try rejectNonCanonical(y);
775 var buf: [128]u8 = undefined;775 var buf: [128]u8 = undefined;
776 std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&y)}), "1E979B917937F3DE71D18077F961F6CEFF01030405060708010203040506070F");776 try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&y)}), "1E979B917937F3DE71D18077F961F6CEFF01030405060708010203040506070F");
777777
778 const reduced = reduce(field_size);778 const reduced = reduce(field_size);
779 std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&reduced)}), "0000000000000000000000000000000000000000000000000000000000000000");779 try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&reduced)}), "0000000000000000000000000000000000000000000000000000000000000000");
780}780}
781781
782test "non-canonical scalar25519" {782test "non-canonical scalar25519" {
783 const too_targe: [32]u8 = .{ 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10 };783 const too_targe: [32]u8 = .{ 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10 };
784 std.testing.expectError(error.NonCanonical, rejectNonCanonical(too_targe));784 try std.testing.expectError(error.NonCanonical, rejectNonCanonical(too_targe));
785}785}
786786
787test "mulAdd overflow check" {787test "mulAdd overflow check" {
...@@ -790,5 +790,5 @@ test "mulAdd overflow check" {...@@ -790,5 +790,5 @@ test "mulAdd overflow check" {
790 const c: [32]u8 = [_]u8{0xff} ** 32;790 const c: [32]u8 = [_]u8{0xff} ** 32;
791 const x = mulAdd(a, b, c);791 const x = mulAdd(a, b, c);
792 var buf: [128]u8 = undefined;792 var buf: [128]u8 = undefined;
793 std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&x)}), "D14DF91389432C25AD60FF9791B9FD1D67BEF517D273ECCE3D9A307C1B419903");793 try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&x)}), "D14DF91389432C25AD60FF9791B9FD1D67BEF517D273ECCE3D9A307C1B419903");
794}794}
lib/std/crypto/25519/x25519.zig+8-8
...@@ -92,7 +92,7 @@ test "x25519 public key calculation from secret key" {...@@ -92,7 +92,7 @@ test "x25519 public key calculation from secret key" {
92 _ = try fmt.hexToBytes(sk[0..], "8052030376d47112be7f73ed7a019293dd12ad910b654455798b4667d73de166");92 _ = try fmt.hexToBytes(sk[0..], "8052030376d47112be7f73ed7a019293dd12ad910b654455798b4667d73de166");
93 _ = try fmt.hexToBytes(pk_expected[0..], "f1814f0e8ff1043d8a44d25babff3cedcae6c22c3edaa48f857ae70de2baae50");93 _ = try fmt.hexToBytes(pk_expected[0..], "f1814f0e8ff1043d8a44d25babff3cedcae6c22c3edaa48f857ae70de2baae50");
94 const pk_calculated = try X25519.recoverPublicKey(sk);94 const pk_calculated = try X25519.recoverPublicKey(sk);
95 std.testing.expectEqual(pk_calculated, pk_expected);95 try std.testing.expectEqual(pk_calculated, pk_expected);
96}96}
9797
98test "x25519 rfc7748 vector1" {98test "x25519 rfc7748 vector1" {
...@@ -102,7 +102,7 @@ test "x25519 rfc7748 vector1" {...@@ -102,7 +102,7 @@ test "x25519 rfc7748 vector1" {
102 const expected_output = [32]u8{ 0xc3, 0xda, 0x55, 0x37, 0x9d, 0xe9, 0xc6, 0x90, 0x8e, 0x94, 0xea, 0x4d, 0xf2, 0x8d, 0x08, 0x4f, 0x32, 0xec, 0xcf, 0x03, 0x49, 0x1c, 0x71, 0xf7, 0x54, 0xb4, 0x07, 0x55, 0x77, 0xa2, 0x85, 0x52 };102 const expected_output = [32]u8{ 0xc3, 0xda, 0x55, 0x37, 0x9d, 0xe9, 0xc6, 0x90, 0x8e, 0x94, 0xea, 0x4d, 0xf2, 0x8d, 0x08, 0x4f, 0x32, 0xec, 0xcf, 0x03, 0x49, 0x1c, 0x71, 0xf7, 0x54, 0xb4, 0x07, 0x55, 0x77, 0xa2, 0x85, 0x52 };
103103
104 const output = try X25519.scalarmult(secret_key, public_key);104 const output = try X25519.scalarmult(secret_key, public_key);
105 std.testing.expectEqual(output, expected_output);105 try std.testing.expectEqual(output, expected_output);
106}106}
107107
108test "x25519 rfc7748 vector2" {108test "x25519 rfc7748 vector2" {
...@@ -112,7 +112,7 @@ test "x25519 rfc7748 vector2" {...@@ -112,7 +112,7 @@ test "x25519 rfc7748 vector2" {
112 const expected_output = [32]u8{ 0x95, 0xcb, 0xde, 0x94, 0x76, 0xe8, 0x90, 0x7d, 0x7a, 0xad, 0xe4, 0x5c, 0xb4, 0xb8, 0x73, 0xf8, 0x8b, 0x59, 0x5a, 0x68, 0x79, 0x9f, 0xa1, 0x52, 0xe6, 0xf8, 0xf7, 0x64, 0x7a, 0xac, 0x79, 0x57 };112 const expected_output = [32]u8{ 0x95, 0xcb, 0xde, 0x94, 0x76, 0xe8, 0x90, 0x7d, 0x7a, 0xad, 0xe4, 0x5c, 0xb4, 0xb8, 0x73, 0xf8, 0x8b, 0x59, 0x5a, 0x68, 0x79, 0x9f, 0xa1, 0x52, 0xe6, 0xf8, 0xf7, 0x64, 0x7a, 0xac, 0x79, 0x57 };
113113
114 const output = try X25519.scalarmult(secret_key, public_key);114 const output = try X25519.scalarmult(secret_key, public_key);
115 std.testing.expectEqual(output, expected_output);115 try std.testing.expectEqual(output, expected_output);
116}116}
117117
118test "x25519 rfc7748 one iteration" {118test "x25519 rfc7748 one iteration" {
...@@ -129,7 +129,7 @@ test "x25519 rfc7748 one iteration" {...@@ -129,7 +129,7 @@ test "x25519 rfc7748 one iteration" {
129 mem.copy(u8, k[0..], output[0..]);129 mem.copy(u8, k[0..], output[0..]);
130 }130 }
131131
132 std.testing.expectEqual(k, expected_output);132 try std.testing.expectEqual(k, expected_output);
133}133}
134134
135test "x25519 rfc7748 1,000 iterations" {135test "x25519 rfc7748 1,000 iterations" {
...@@ -151,7 +151,7 @@ test "x25519 rfc7748 1,000 iterations" {...@@ -151,7 +151,7 @@ test "x25519 rfc7748 1,000 iterations" {
151 mem.copy(u8, k[0..], output[0..]);151 mem.copy(u8, k[0..], output[0..]);
152 }152 }
153153
154 std.testing.expectEqual(k, expected_output);154 try std.testing.expectEqual(k, expected_output);
155}155}
156156
157test "x25519 rfc7748 1,000,000 iterations" {157test "x25519 rfc7748 1,000,000 iterations" {
...@@ -172,12 +172,12 @@ test "x25519 rfc7748 1,000,000 iterations" {...@@ -172,12 +172,12 @@ test "x25519 rfc7748 1,000,000 iterations" {
172 mem.copy(u8, k[0..], output[0..]);172 mem.copy(u8, k[0..], output[0..]);
173 }173 }
174174
175 std.testing.expectEqual(k[0..], expected_output);175 try std.testing.expectEqual(k[0..], expected_output);
176}176}
177177
178test "edwards25519 -> curve25519 map" {178test "edwards25519 -> curve25519 map" {
179 const ed_kp = try crypto.sign.Ed25519.KeyPair.create([_]u8{0x42} ** 32);179 const ed_kp = try crypto.sign.Ed25519.KeyPair.create([_]u8{0x42} ** 32);
180 const mont_kp = try X25519.KeyPair.fromEd25519(ed_kp);180 const mont_kp = try X25519.KeyPair.fromEd25519(ed_kp);
181 htest.assertEqual("90e7595fc89e52fdfddce9c6a43d74dbf6047025ee0462d2d172e8b6a2841d6e", &mont_kp.secret_key);181 try htest.assertEqual("90e7595fc89e52fdfddce9c6a43d74dbf6047025ee0462d2d172e8b6a2841d6e", &mont_kp.secret_key);
182 htest.assertEqual("cc4f2cdb695dd766f34118eb67b98652fed1d8bc49c330b119bbfa8a64989378", &mont_kp.public_key);182 try htest.assertEqual("cc4f2cdb695dd766f34118eb67b98652fed1d8bc49c330b119bbfa8a64989378", &mont_kp.public_key);
183}183}
lib/std/crypto/aegis.zig+20-20
...@@ -352,16 +352,16 @@ test "Aegis128L test vector 1" {...@@ -352,16 +352,16 @@ test "Aegis128L test vector 1" {
352352
353 Aegis128L.encrypt(&c, &tag, &m, &ad, nonce, key);353 Aegis128L.encrypt(&c, &tag, &m, &ad, nonce, key);
354 try Aegis128L.decrypt(&m2, &c, tag, &ad, nonce, key);354 try Aegis128L.decrypt(&m2, &c, tag, &ad, nonce, key);
355 testing.expectEqualSlices(u8, &m, &m2);355 try testing.expectEqualSlices(u8, &m, &m2);
356356
357 htest.assertEqual("79d94593d8c2119d7e8fd9b8fc77845c5c077a05b2528b6ac54b563aed8efe84", &c);357 try htest.assertEqual("79d94593d8c2119d7e8fd9b8fc77845c5c077a05b2528b6ac54b563aed8efe84", &c);
358 htest.assertEqual("cc6f3372f6aa1bb82388d695c3962d9a", &tag);358 try htest.assertEqual("cc6f3372f6aa1bb82388d695c3962d9a", &tag);
359359
360 c[0] +%= 1;360 c[0] +%= 1;
361 testing.expectError(error.AuthenticationFailed, Aegis128L.decrypt(&m2, &c, tag, &ad, nonce, key));361 try testing.expectError(error.AuthenticationFailed, Aegis128L.decrypt(&m2, &c, tag, &ad, nonce, key));
362 c[0] -%= 1;362 c[0] -%= 1;
363 tag[0] +%= 1;363 tag[0] +%= 1;
364 testing.expectError(error.AuthenticationFailed, Aegis128L.decrypt(&m2, &c, tag, &ad, nonce, key));364 try testing.expectError(error.AuthenticationFailed, Aegis128L.decrypt(&m2, &c, tag, &ad, nonce, key));
365}365}
366366
367test "Aegis128L test vector 2" {367test "Aegis128L test vector 2" {
...@@ -375,10 +375,10 @@ test "Aegis128L test vector 2" {...@@ -375,10 +375,10 @@ test "Aegis128L test vector 2" {
375375
376 Aegis128L.encrypt(&c, &tag, &m, &ad, nonce, key);376 Aegis128L.encrypt(&c, &tag, &m, &ad, nonce, key);
377 try Aegis128L.decrypt(&m2, &c, tag, &ad, nonce, key);377 try Aegis128L.decrypt(&m2, &c, tag, &ad, nonce, key);
378 testing.expectEqualSlices(u8, &m, &m2);378 try testing.expectEqualSlices(u8, &m, &m2);
379379
380 htest.assertEqual("41de9000a7b5e40e2d68bb64d99ebb19", &c);380 try htest.assertEqual("41de9000a7b5e40e2d68bb64d99ebb19", &c);
381 htest.assertEqual("f4d997cc9b94227ada4fe4165422b1c8", &tag);381 try htest.assertEqual("f4d997cc9b94227ada4fe4165422b1c8", &tag);
382}382}
383383
384test "Aegis128L test vector 3" {384test "Aegis128L test vector 3" {
...@@ -392,9 +392,9 @@ test "Aegis128L test vector 3" {...@@ -392,9 +392,9 @@ test "Aegis128L test vector 3" {
392392
393 Aegis128L.encrypt(&c, &tag, &m, &ad, nonce, key);393 Aegis128L.encrypt(&c, &tag, &m, &ad, nonce, key);
394 try Aegis128L.decrypt(&m2, &c, tag, &ad, nonce, key);394 try Aegis128L.decrypt(&m2, &c, tag, &ad, nonce, key);
395 testing.expectEqualSlices(u8, &m, &m2);395 try testing.expectEqualSlices(u8, &m, &m2);
396396
397 htest.assertEqual("83cc600dc4e3e7e62d4055826174f149", &tag);397 try htest.assertEqual("83cc600dc4e3e7e62d4055826174f149", &tag);
398}398}
399399
400test "Aegis256 test vector 1" {400test "Aegis256 test vector 1" {
...@@ -408,16 +408,16 @@ test "Aegis256 test vector 1" {...@@ -408,16 +408,16 @@ test "Aegis256 test vector 1" {
408408
409 Aegis256.encrypt(&c, &tag, &m, &ad, nonce, key);409 Aegis256.encrypt(&c, &tag, &m, &ad, nonce, key);
410 try Aegis256.decrypt(&m2, &c, tag, &ad, nonce, key);410 try Aegis256.decrypt(&m2, &c, tag, &ad, nonce, key);
411 testing.expectEqualSlices(u8, &m, &m2);411 try testing.expectEqualSlices(u8, &m, &m2);
412412
413 htest.assertEqual("f373079ed84b2709faee373584585d60accd191db310ef5d8b11833df9dec711", &c);413 try htest.assertEqual("f373079ed84b2709faee373584585d60accd191db310ef5d8b11833df9dec711", &c);
414 htest.assertEqual("8d86f91ee606e9ff26a01b64ccbdd91d", &tag);414 try htest.assertEqual("8d86f91ee606e9ff26a01b64ccbdd91d", &tag);
415415
416 c[0] +%= 1;416 c[0] +%= 1;
417 testing.expectError(error.AuthenticationFailed, Aegis256.decrypt(&m2, &c, tag, &ad, nonce, key));417 try testing.expectError(error.AuthenticationFailed, Aegis256.decrypt(&m2, &c, tag, &ad, nonce, key));
418 c[0] -%= 1;418 c[0] -%= 1;
419 tag[0] +%= 1;419 tag[0] +%= 1;
420 testing.expectError(error.AuthenticationFailed, Aegis256.decrypt(&m2, &c, tag, &ad, nonce, key));420 try testing.expectError(error.AuthenticationFailed, Aegis256.decrypt(&m2, &c, tag, &ad, nonce, key));
421}421}
422422
423test "Aegis256 test vector 2" {423test "Aegis256 test vector 2" {
...@@ -431,10 +431,10 @@ test "Aegis256 test vector 2" {...@@ -431,10 +431,10 @@ test "Aegis256 test vector 2" {
431431
432 Aegis256.encrypt(&c, &tag, &m, &ad, nonce, key);432 Aegis256.encrypt(&c, &tag, &m, &ad, nonce, key);
433 try Aegis256.decrypt(&m2, &c, tag, &ad, nonce, key);433 try Aegis256.decrypt(&m2, &c, tag, &ad, nonce, key);
434 testing.expectEqualSlices(u8, &m, &m2);434 try testing.expectEqualSlices(u8, &m, &m2);
435435
436 htest.assertEqual("b98f03a947807713d75a4fff9fc277a6", &c);436 try htest.assertEqual("b98f03a947807713d75a4fff9fc277a6", &c);
437 htest.assertEqual("478f3b50dc478ef7d5cf2d0f7cc13180", &tag);437 try htest.assertEqual("478f3b50dc478ef7d5cf2d0f7cc13180", &tag);
438}438}
439439
440test "Aegis256 test vector 3" {440test "Aegis256 test vector 3" {
...@@ -448,7 +448,7 @@ test "Aegis256 test vector 3" {...@@ -448,7 +448,7 @@ test "Aegis256 test vector 3" {
448448
449 Aegis256.encrypt(&c, &tag, &m, &ad, nonce, key);449 Aegis256.encrypt(&c, &tag, &m, &ad, nonce, key);
450 try Aegis256.decrypt(&m2, &c, tag, &ad, nonce, key);450 try Aegis256.decrypt(&m2, &c, tag, &ad, nonce, key);
451 testing.expectEqualSlices(u8, &m, &m2);451 try testing.expectEqualSlices(u8, &m, &m2);
452452
453 htest.assertEqual("f7a0878f68bd083e8065354071fc27c3", &tag);453 try htest.assertEqual("f7a0878f68bd083e8065354071fc27c3", &tag);
454}454}
lib/std/crypto/aes.zig+9-9
...@@ -48,7 +48,7 @@ test "ctr" {...@@ -48,7 +48,7 @@ test "ctr" {
48 var out: [exp_out.len]u8 = undefined;48 var out: [exp_out.len]u8 = undefined;
49 var ctx = Aes128.initEnc(key);49 var ctx = Aes128.initEnc(key);
50 ctr(AesEncryptCtx(Aes128), ctx, out[0..], in[0..], iv, builtin.Endian.Big);50 ctr(AesEncryptCtx(Aes128), ctx, out[0..], in[0..], iv, builtin.Endian.Big);
51 testing.expectEqualSlices(u8, exp_out[0..], out[0..]);51 try testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
52}52}
5353
54test "encrypt" {54test "encrypt" {
...@@ -61,7 +61,7 @@ test "encrypt" {...@@ -61,7 +61,7 @@ test "encrypt" {
61 var out: [exp_out.len]u8 = undefined;61 var out: [exp_out.len]u8 = undefined;
62 var ctx = Aes128.initEnc(key);62 var ctx = Aes128.initEnc(key);
63 ctx.encrypt(out[0..], in[0..]);63 ctx.encrypt(out[0..], in[0..]);
64 testing.expectEqualSlices(u8, exp_out[0..], out[0..]);64 try testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
65 }65 }
6666
67 // Appendix C.367 // Appendix C.3
...@@ -76,7 +76,7 @@ test "encrypt" {...@@ -76,7 +76,7 @@ test "encrypt" {
76 var out: [exp_out.len]u8 = undefined;76 var out: [exp_out.len]u8 = undefined;
77 var ctx = Aes256.initEnc(key);77 var ctx = Aes256.initEnc(key);
78 ctx.encrypt(out[0..], in[0..]);78 ctx.encrypt(out[0..], in[0..]);
79 testing.expectEqualSlices(u8, exp_out[0..], out[0..]);79 try testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
80 }80 }
81}81}
8282
...@@ -90,7 +90,7 @@ test "decrypt" {...@@ -90,7 +90,7 @@ test "decrypt" {
90 var out: [exp_out.len]u8 = undefined;90 var out: [exp_out.len]u8 = undefined;
91 var ctx = Aes128.initDec(key);91 var ctx = Aes128.initDec(key);
92 ctx.decrypt(out[0..], in[0..]);92 ctx.decrypt(out[0..], in[0..]);
93 testing.expectEqualSlices(u8, exp_out[0..], out[0..]);93 try testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
94 }94 }
9595
96 // Appendix C.396 // Appendix C.3
...@@ -105,7 +105,7 @@ test "decrypt" {...@@ -105,7 +105,7 @@ test "decrypt" {
105 var out: [exp_out.len]u8 = undefined;105 var out: [exp_out.len]u8 = undefined;
106 var ctx = Aes256.initDec(key);106 var ctx = Aes256.initDec(key);
107 ctx.decrypt(out[0..], in[0..]);107 ctx.decrypt(out[0..], in[0..]);
108 testing.expectEqualSlices(u8, exp_out[0..], out[0..]);108 try testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
109 }109 }
110}110}
111111
...@@ -123,11 +123,11 @@ test "expand 128-bit key" {...@@ -123,11 +123,11 @@ test "expand 128-bit key" {
123123
124 for (enc.key_schedule.round_keys) |round_key, i| {124 for (enc.key_schedule.round_keys) |round_key, i| {
125 _ = try std.fmt.hexToBytes(&exp, exp_enc[i]);125 _ = try std.fmt.hexToBytes(&exp, exp_enc[i]);
126 testing.expectEqualSlices(u8, &exp, &round_key.toBytes());126 try testing.expectEqualSlices(u8, &exp, &round_key.toBytes());
127 }127 }
128 for (enc.key_schedule.round_keys) |round_key, i| {128 for (enc.key_schedule.round_keys) |round_key, i| {
129 _ = try std.fmt.hexToBytes(&exp, exp_dec[i]);129 _ = try std.fmt.hexToBytes(&exp, exp_dec[i]);
130 testing.expectEqualSlices(u8, &exp, &round_key.toBytes());130 try testing.expectEqualSlices(u8, &exp, &round_key.toBytes());
131 }131 }
132}132}
133133
...@@ -145,10 +145,10 @@ test "expand 256-bit key" {...@@ -145,10 +145,10 @@ test "expand 256-bit key" {
145145
146 for (enc.key_schedule.round_keys) |round_key, i| {146 for (enc.key_schedule.round_keys) |round_key, i| {
147 _ = try std.fmt.hexToBytes(&exp, exp_enc[i]);147 _ = try std.fmt.hexToBytes(&exp, exp_enc[i]);
148 testing.expectEqualSlices(u8, &exp, &round_key.toBytes());148 try testing.expectEqualSlices(u8, &exp, &round_key.toBytes());
149 }149 }
150 for (dec.key_schedule.round_keys) |round_key, i| {150 for (dec.key_schedule.round_keys) |round_key, i| {
151 _ = try std.fmt.hexToBytes(&exp, exp_dec[i]);151 _ = try std.fmt.hexToBytes(&exp, exp_dec[i]);
152 testing.expectEqualSlices(u8, &exp, &round_key.toBytes());152 try testing.expectEqualSlices(u8, &exp, &round_key.toBytes());
153 }153 }
154}154}
lib/std/crypto/aes_gcm.zig+8-8
...@@ -118,7 +118,7 @@ test "Aes256Gcm - Empty message and no associated data" {...@@ -118,7 +118,7 @@ test "Aes256Gcm - Empty message and no associated data" {
118 var tag: [Aes256Gcm.tag_length]u8 = undefined;118 var tag: [Aes256Gcm.tag_length]u8 = undefined;
119119
120 Aes256Gcm.encrypt(&c, &tag, m, ad, nonce, key);120 Aes256Gcm.encrypt(&c, &tag, m, ad, nonce, key);
121 htest.assertEqual("6b6ff610a16fa4cd59f1fb7903154e92", &tag);121 try htest.assertEqual("6b6ff610a16fa4cd59f1fb7903154e92", &tag);
122}122}
123123
124test "Aes256Gcm - Associated data only" {124test "Aes256Gcm - Associated data only" {
...@@ -130,7 +130,7 @@ test "Aes256Gcm - Associated data only" {...@@ -130,7 +130,7 @@ test "Aes256Gcm - Associated data only" {
130 var tag: [Aes256Gcm.tag_length]u8 = undefined;130 var tag: [Aes256Gcm.tag_length]u8 = undefined;
131131
132 Aes256Gcm.encrypt(&c, &tag, m, ad, nonce, key);132 Aes256Gcm.encrypt(&c, &tag, m, ad, nonce, key);
133 htest.assertEqual("262ed164c2dfb26e080a9d108dd9dd4c", &tag);133 try htest.assertEqual("262ed164c2dfb26e080a9d108dd9dd4c", &tag);
134}134}
135135
136test "Aes256Gcm - Message only" {136test "Aes256Gcm - Message only" {
...@@ -144,10 +144,10 @@ test "Aes256Gcm - Message only" {...@@ -144,10 +144,10 @@ test "Aes256Gcm - Message only" {
144144
145 Aes256Gcm.encrypt(&c, &tag, m, ad, nonce, key);145 Aes256Gcm.encrypt(&c, &tag, m, ad, nonce, key);
146 try Aes256Gcm.decrypt(&m2, &c, tag, ad, nonce, key);146 try Aes256Gcm.decrypt(&m2, &c, tag, ad, nonce, key);
147 testing.expectEqualSlices(u8, m[0..], m2[0..]);147 try testing.expectEqualSlices(u8, m[0..], m2[0..]);
148148
149 htest.assertEqual("5ca1642d90009fea33d01f78cf6eefaf01d539472f7c", &c);149 try htest.assertEqual("5ca1642d90009fea33d01f78cf6eefaf01d539472f7c", &c);
150 htest.assertEqual("07cd7fc9103e2f9e9bf2dfaa319caff4", &tag);150 try htest.assertEqual("07cd7fc9103e2f9e9bf2dfaa319caff4", &tag);
151}151}
152152
153test "Aes256Gcm - Message and associated data" {153test "Aes256Gcm - Message and associated data" {
...@@ -161,8 +161,8 @@ test "Aes256Gcm - Message and associated data" {...@@ -161,8 +161,8 @@ test "Aes256Gcm - Message and associated data" {
161161
162 Aes256Gcm.encrypt(&c, &tag, m, ad, nonce, key);162 Aes256Gcm.encrypt(&c, &tag, m, ad, nonce, key);
163 try Aes256Gcm.decrypt(&m2, &c, tag, ad, nonce, key);163 try Aes256Gcm.decrypt(&m2, &c, tag, ad, nonce, key);
164 testing.expectEqualSlices(u8, m[0..], m2[0..]);164 try testing.expectEqualSlices(u8, m[0..], m2[0..]);
165165
166 htest.assertEqual("5ca1642d90009fea33d01f78cf6eefaf01", &c);166 try htest.assertEqual("5ca1642d90009fea33d01f78cf6eefaf01", &c);
167 htest.assertEqual("64accec679d444e2373bd9f6796c0d2c", &tag);167 try htest.assertEqual("64accec679d444e2373bd9f6796c0d2c", &tag);
168}168}
lib/std/crypto/bcrypt.zig+2-2
...@@ -281,13 +281,13 @@ test "bcrypt codec" {...@@ -281,13 +281,13 @@ test "bcrypt codec" {
281 Codec.encode(salt_str[0..], salt[0..]);281 Codec.encode(salt_str[0..], salt[0..]);
282 var salt2: [salt_length]u8 = undefined;282 var salt2: [salt_length]u8 = undefined;
283 try Codec.decode(salt2[0..], salt_str[0..]);283 try Codec.decode(salt2[0..], salt_str[0..]);
284 testing.expectEqualSlices(u8, salt[0..], salt2[0..]);284 try testing.expectEqualSlices(u8, salt[0..], salt2[0..]);
285}285}
286286
287test "bcrypt" {287test "bcrypt" {
288 const s = try strHash("password", 5);288 const s = try strHash("password", 5);
289 try strVerify(s, "password");289 try strVerify(s, "password");
290 testing.expectError(error.PasswordVerificationFailed, strVerify(s, "invalid password"));290 try testing.expectError(error.PasswordVerificationFailed, strVerify(s, "invalid password"));
291291
292 const long_s = try strHash("password" ** 100, 5);292 const long_s = try strHash("password" ** 100, 5);
293 try strVerify(long_s, "password" ** 100);293 try strVerify(long_s, "password" ** 100);
lib/std/crypto/blake2.zig+82-82
...@@ -194,16 +194,16 @@ pub fn Blake2s(comptime out_bits: usize) type {...@@ -194,16 +194,16 @@ pub fn Blake2s(comptime out_bits: usize) type {
194194
195test "blake2s160 single" {195test "blake2s160 single" {
196 const h1 = "354c9c33f735962418bdacb9479873429c34916f";196 const h1 = "354c9c33f735962418bdacb9479873429c34916f";
197 htest.assertEqualHash(Blake2s160, h1, "");197 try htest.assertEqualHash(Blake2s160, h1, "");
198198
199 const h2 = "5ae3b99be29b01834c3b508521ede60438f8de17";199 const h2 = "5ae3b99be29b01834c3b508521ede60438f8de17";
200 htest.assertEqualHash(Blake2s160, h2, "abc");200 try htest.assertEqualHash(Blake2s160, h2, "abc");
201201
202 const h3 = "5a604fec9713c369e84b0ed68daed7d7504ef240";202 const h3 = "5a604fec9713c369e84b0ed68daed7d7504ef240";
203 htest.assertEqualHash(Blake2s160, h3, "The quick brown fox jumps over the lazy dog");203 try htest.assertEqualHash(Blake2s160, h3, "The quick brown fox jumps over the lazy dog");
204204
205 const h4 = "b60c4dc60e2681e58fbc24e77f07e02c69e72ed0";205 const h4 = "b60c4dc60e2681e58fbc24e77f07e02c69e72ed0";
206 htest.assertEqualHash(Blake2s160, h4, "a" ** 32 ++ "b" ** 32);206 try htest.assertEqualHash(Blake2s160, h4, "a" ** 32 ++ "b" ** 32);
207}207}
208208
209test "blake2s160 streaming" {209test "blake2s160 streaming" {
...@@ -213,21 +213,21 @@ test "blake2s160 streaming" {...@@ -213,21 +213,21 @@ test "blake2s160 streaming" {
213 const h1 = "354c9c33f735962418bdacb9479873429c34916f";213 const h1 = "354c9c33f735962418bdacb9479873429c34916f";
214214
215 h.final(out[0..]);215 h.final(out[0..]);
216 htest.assertEqual(h1, out[0..]);216 try htest.assertEqual(h1, out[0..]);
217217
218 const h2 = "5ae3b99be29b01834c3b508521ede60438f8de17";218 const h2 = "5ae3b99be29b01834c3b508521ede60438f8de17";
219219
220 h = Blake2s160.init(.{});220 h = Blake2s160.init(.{});
221 h.update("abc");221 h.update("abc");
222 h.final(out[0..]);222 h.final(out[0..]);
223 htest.assertEqual(h2, out[0..]);223 try htest.assertEqual(h2, out[0..]);
224224
225 h = Blake2s160.init(.{});225 h = Blake2s160.init(.{});
226 h.update("a");226 h.update("a");
227 h.update("b");227 h.update("b");
228 h.update("c");228 h.update("c");
229 h.final(out[0..]);229 h.final(out[0..]);
230 htest.assertEqual(h2, out[0..]);230 try htest.assertEqual(h2, out[0..]);
231231
232 const h3 = "b60c4dc60e2681e58fbc24e77f07e02c69e72ed0";232 const h3 = "b60c4dc60e2681e58fbc24e77f07e02c69e72ed0";
233233
...@@ -235,12 +235,12 @@ test "blake2s160 streaming" {...@@ -235,12 +235,12 @@ test "blake2s160 streaming" {
235 h.update("a" ** 32);235 h.update("a" ** 32);
236 h.update("b" ** 32);236 h.update("b" ** 32);
237 h.final(out[0..]);237 h.final(out[0..]);
238 htest.assertEqual(h3, out[0..]);238 try htest.assertEqual(h3, out[0..]);
239239
240 h = Blake2s160.init(.{});240 h = Blake2s160.init(.{});
241 h.update("a" ** 32 ++ "b" ** 32);241 h.update("a" ** 32 ++ "b" ** 32);
242 h.final(out[0..]);242 h.final(out[0..]);
243 htest.assertEqual(h3, out[0..]);243 try htest.assertEqual(h3, out[0..]);
244244
245 const h4 = "4667fd60791a7fe41f939bca646b4529e296bd68";245 const h4 = "4667fd60791a7fe41f939bca646b4529e296bd68";
246246
...@@ -248,12 +248,12 @@ test "blake2s160 streaming" {...@@ -248,12 +248,12 @@ test "blake2s160 streaming" {
248 h.update("a" ** 32);248 h.update("a" ** 32);
249 h.update("b" ** 32);249 h.update("b" ** 32);
250 h.final(out[0..]);250 h.final(out[0..]);
251 htest.assertEqual(h4, out[0..]);251 try htest.assertEqual(h4, out[0..]);
252252
253 h = Blake2s160.init(.{ .context = [_]u8{0x69} ** 8, .salt = [_]u8{0x42} ** 8 });253 h = Blake2s160.init(.{ .context = [_]u8{0x69} ** 8, .salt = [_]u8{0x42} ** 8 });
254 h.update("a" ** 32 ++ "b" ** 32);254 h.update("a" ** 32 ++ "b" ** 32);
255 h.final(out[0..]);255 h.final(out[0..]);
256 htest.assertEqual(h4, out[0..]);256 try htest.assertEqual(h4, out[0..]);
257}257}
258258
259test "comptime blake2s160" {259test "comptime blake2s160" {
...@@ -265,28 +265,28 @@ test "comptime blake2s160" {...@@ -265,28 +265,28 @@ test "comptime blake2s160" {
265265
266 const h1 = "2c56ad9d0b2c8b474aafa93ab307db2f0940105f";266 const h1 = "2c56ad9d0b2c8b474aafa93ab307db2f0940105f";
267267
268 htest.assertEqualHash(Blake2s160, h1, block[0..]);268 try htest.assertEqualHash(Blake2s160, h1, block[0..]);
269269
270 var h = Blake2s160.init(.{});270 var h = Blake2s160.init(.{});
271 h.update(&block);271 h.update(&block);
272 h.final(out[0..]);272 h.final(out[0..]);
273273
274 htest.assertEqual(h1, out[0..]);274 try htest.assertEqual(h1, out[0..]);
275 }275 }
276}276}
277277
278test "blake2s224 single" {278test "blake2s224 single" {
279 const h1 = "1fa1291e65248b37b3433475b2a0dd63d54a11ecc4e3e034e7bc1ef4";279 const h1 = "1fa1291e65248b37b3433475b2a0dd63d54a11ecc4e3e034e7bc1ef4";
280 htest.assertEqualHash(Blake2s224, h1, "");280 try htest.assertEqualHash(Blake2s224, h1, "");
281281
282 const h2 = "0b033fc226df7abde29f67a05d3dc62cf271ef3dfea4d387407fbd55";282 const h2 = "0b033fc226df7abde29f67a05d3dc62cf271ef3dfea4d387407fbd55";
283 htest.assertEqualHash(Blake2s224, h2, "abc");283 try htest.assertEqualHash(Blake2s224, h2, "abc");
284284
285 const h3 = "e4e5cb6c7cae41982b397bf7b7d2d9d1949823ae78435326e8db4912";285 const h3 = "e4e5cb6c7cae41982b397bf7b7d2d9d1949823ae78435326e8db4912";
286 htest.assertEqualHash(Blake2s224, h3, "The quick brown fox jumps over the lazy dog");286 try htest.assertEqualHash(Blake2s224, h3, "The quick brown fox jumps over the lazy dog");
287287
288 const h4 = "557381a78facd2b298640f4e32113e58967d61420af1aa939d0cfe01";288 const h4 = "557381a78facd2b298640f4e32113e58967d61420af1aa939d0cfe01";
289 htest.assertEqualHash(Blake2s224, h4, "a" ** 32 ++ "b" ** 32);289 try htest.assertEqualHash(Blake2s224, h4, "a" ** 32 ++ "b" ** 32);
290}290}
291291
292test "blake2s224 streaming" {292test "blake2s224 streaming" {
...@@ -296,21 +296,21 @@ test "blake2s224 streaming" {...@@ -296,21 +296,21 @@ test "blake2s224 streaming" {
296 const h1 = "1fa1291e65248b37b3433475b2a0dd63d54a11ecc4e3e034e7bc1ef4";296 const h1 = "1fa1291e65248b37b3433475b2a0dd63d54a11ecc4e3e034e7bc1ef4";
297297
298 h.final(out[0..]);298 h.final(out[0..]);
299 htest.assertEqual(h1, out[0..]);299 try htest.assertEqual(h1, out[0..]);
300300
301 const h2 = "0b033fc226df7abde29f67a05d3dc62cf271ef3dfea4d387407fbd55";301 const h2 = "0b033fc226df7abde29f67a05d3dc62cf271ef3dfea4d387407fbd55";
302302
303 h = Blake2s224.init(.{});303 h = Blake2s224.init(.{});
304 h.update("abc");304 h.update("abc");
305 h.final(out[0..]);305 h.final(out[0..]);
306 htest.assertEqual(h2, out[0..]);306 try htest.assertEqual(h2, out[0..]);
307307
308 h = Blake2s224.init(.{});308 h = Blake2s224.init(.{});
309 h.update("a");309 h.update("a");
310 h.update("b");310 h.update("b");
311 h.update("c");311 h.update("c");
312 h.final(out[0..]);312 h.final(out[0..]);
313 htest.assertEqual(h2, out[0..]);313 try htest.assertEqual(h2, out[0..]);
314314
315 const h3 = "557381a78facd2b298640f4e32113e58967d61420af1aa939d0cfe01";315 const h3 = "557381a78facd2b298640f4e32113e58967d61420af1aa939d0cfe01";
316316
...@@ -318,12 +318,12 @@ test "blake2s224 streaming" {...@@ -318,12 +318,12 @@ test "blake2s224 streaming" {
318 h.update("a" ** 32);318 h.update("a" ** 32);
319 h.update("b" ** 32);319 h.update("b" ** 32);
320 h.final(out[0..]);320 h.final(out[0..]);
321 htest.assertEqual(h3, out[0..]);321 try htest.assertEqual(h3, out[0..]);
322322
323 h = Blake2s224.init(.{});323 h = Blake2s224.init(.{});
324 h.update("a" ** 32 ++ "b" ** 32);324 h.update("a" ** 32 ++ "b" ** 32);
325 h.final(out[0..]);325 h.final(out[0..]);
326 htest.assertEqual(h3, out[0..]);326 try htest.assertEqual(h3, out[0..]);
327327
328 const h4 = "a4d6a9d253441b80e5dfd60a04db169ffab77aec56a2855c402828c3";328 const h4 = "a4d6a9d253441b80e5dfd60a04db169ffab77aec56a2855c402828c3";
329329
...@@ -331,12 +331,12 @@ test "blake2s224 streaming" {...@@ -331,12 +331,12 @@ test "blake2s224 streaming" {
331 h.update("a" ** 32);331 h.update("a" ** 32);
332 h.update("b" ** 32);332 h.update("b" ** 32);
333 h.final(out[0..]);333 h.final(out[0..]);
334 htest.assertEqual(h4, out[0..]);334 try htest.assertEqual(h4, out[0..]);
335335
336 h = Blake2s224.init(.{ .context = [_]u8{0x69} ** 8, .salt = [_]u8{0x42} ** 8 });336 h = Blake2s224.init(.{ .context = [_]u8{0x69} ** 8, .salt = [_]u8{0x42} ** 8 });
337 h.update("a" ** 32 ++ "b" ** 32);337 h.update("a" ** 32 ++ "b" ** 32);
338 h.final(out[0..]);338 h.final(out[0..]);
339 htest.assertEqual(h4, out[0..]);339 try htest.assertEqual(h4, out[0..]);
340}340}
341341
342test "comptime blake2s224" {342test "comptime blake2s224" {
...@@ -347,28 +347,28 @@ test "comptime blake2s224" {...@@ -347,28 +347,28 @@ test "comptime blake2s224" {
347347
348 const h1 = "86b7611563293f8c73627df7a6d6ba25ca0548c2a6481f7d116ee576";348 const h1 = "86b7611563293f8c73627df7a6d6ba25ca0548c2a6481f7d116ee576";
349349
350 htest.assertEqualHash(Blake2s224, h1, block[0..]);350 try htest.assertEqualHash(Blake2s224, h1, block[0..]);
351351
352 var h = Blake2s224.init(.{});352 var h = Blake2s224.init(.{});
353 h.update(&block);353 h.update(&block);
354 h.final(out[0..]);354 h.final(out[0..]);
355355
356 htest.assertEqual(h1, out[0..]);356 try htest.assertEqual(h1, out[0..]);
357 }357 }
358}358}
359359
360test "blake2s256 single" {360test "blake2s256 single" {
361 const h1 = "69217a3079908094e11121d042354a7c1f55b6482ca1a51e1b250dfd1ed0eef9";361 const h1 = "69217a3079908094e11121d042354a7c1f55b6482ca1a51e1b250dfd1ed0eef9";
362 htest.assertEqualHash(Blake2s256, h1, "");362 try htest.assertEqualHash(Blake2s256, h1, "");
363363
364 const h2 = "508c5e8c327c14e2e1a72ba34eeb452f37458b209ed63a294d999b4c86675982";364 const h2 = "508c5e8c327c14e2e1a72ba34eeb452f37458b209ed63a294d999b4c86675982";
365 htest.assertEqualHash(Blake2s256, h2, "abc");365 try htest.assertEqualHash(Blake2s256, h2, "abc");
366366
367 const h3 = "606beeec743ccbeff6cbcdf5d5302aa855c256c29b88c8ed331ea1a6bf3c8812";367 const h3 = "606beeec743ccbeff6cbcdf5d5302aa855c256c29b88c8ed331ea1a6bf3c8812";
368 htest.assertEqualHash(Blake2s256, h3, "The quick brown fox jumps over the lazy dog");368 try htest.assertEqualHash(Blake2s256, h3, "The quick brown fox jumps over the lazy dog");
369369
370 const h4 = "8d8711dade07a6b92b9a3ea1f40bee9b2c53ff3edd2a273dec170b0163568977";370 const h4 = "8d8711dade07a6b92b9a3ea1f40bee9b2c53ff3edd2a273dec170b0163568977";
371 htest.assertEqualHash(Blake2s256, h4, "a" ** 32 ++ "b" ** 32);371 try htest.assertEqualHash(Blake2s256, h4, "a" ** 32 ++ "b" ** 32);
372}372}
373373
374test "blake2s256 streaming" {374test "blake2s256 streaming" {
...@@ -378,21 +378,21 @@ test "blake2s256 streaming" {...@@ -378,21 +378,21 @@ test "blake2s256 streaming" {
378 const h1 = "69217a3079908094e11121d042354a7c1f55b6482ca1a51e1b250dfd1ed0eef9";378 const h1 = "69217a3079908094e11121d042354a7c1f55b6482ca1a51e1b250dfd1ed0eef9";
379379
380 h.final(out[0..]);380 h.final(out[0..]);
381 htest.assertEqual(h1, out[0..]);381 try htest.assertEqual(h1, out[0..]);
382382
383 const h2 = "508c5e8c327c14e2e1a72ba34eeb452f37458b209ed63a294d999b4c86675982";383 const h2 = "508c5e8c327c14e2e1a72ba34eeb452f37458b209ed63a294d999b4c86675982";
384384
385 h = Blake2s256.init(.{});385 h = Blake2s256.init(.{});
386 h.update("abc");386 h.update("abc");
387 h.final(out[0..]);387 h.final(out[0..]);
388 htest.assertEqual(h2, out[0..]);388 try htest.assertEqual(h2, out[0..]);
389389
390 h = Blake2s256.init(.{});390 h = Blake2s256.init(.{});
391 h.update("a");391 h.update("a");
392 h.update("b");392 h.update("b");
393 h.update("c");393 h.update("c");
394 h.final(out[0..]);394 h.final(out[0..]);
395 htest.assertEqual(h2, out[0..]);395 try htest.assertEqual(h2, out[0..]);
396396
397 const h3 = "8d8711dade07a6b92b9a3ea1f40bee9b2c53ff3edd2a273dec170b0163568977";397 const h3 = "8d8711dade07a6b92b9a3ea1f40bee9b2c53ff3edd2a273dec170b0163568977";
398398
...@@ -400,12 +400,12 @@ test "blake2s256 streaming" {...@@ -400,12 +400,12 @@ test "blake2s256 streaming" {
400 h.update("a" ** 32);400 h.update("a" ** 32);
401 h.update("b" ** 32);401 h.update("b" ** 32);
402 h.final(out[0..]);402 h.final(out[0..]);
403 htest.assertEqual(h3, out[0..]);403 try htest.assertEqual(h3, out[0..]);
404404
405 h = Blake2s256.init(.{});405 h = Blake2s256.init(.{});
406 h.update("a" ** 32 ++ "b" ** 32);406 h.update("a" ** 32 ++ "b" ** 32);
407 h.final(out[0..]);407 h.final(out[0..]);
408 htest.assertEqual(h3, out[0..]);408 try htest.assertEqual(h3, out[0..]);
409}409}
410410
411test "blake2s256 keyed" {411test "blake2s256 keyed" {
...@@ -415,20 +415,20 @@ test "blake2s256 keyed" {...@@ -415,20 +415,20 @@ test "blake2s256 keyed" {
415 const key = "secret_key";415 const key = "secret_key";
416416
417 Blake2s256.hash("a" ** 64 ++ "b" ** 64, &out, .{ .key = key });417 Blake2s256.hash("a" ** 64 ++ "b" ** 64, &out, .{ .key = key });
418 htest.assertEqual(h1, out[0..]);418 try htest.assertEqual(h1, out[0..]);
419419
420 var h = Blake2s256.init(.{ .key = key });420 var h = Blake2s256.init(.{ .key = key });
421 h.update("a" ** 64 ++ "b" ** 64);421 h.update("a" ** 64 ++ "b" ** 64);
422 h.final(out[0..]);422 h.final(out[0..]);
423423
424 htest.assertEqual(h1, out[0..]);424 try htest.assertEqual(h1, out[0..]);
425425
426 h = Blake2s256.init(.{ .key = key });426 h = Blake2s256.init(.{ .key = key });
427 h.update("a" ** 64);427 h.update("a" ** 64);
428 h.update("b" ** 64);428 h.update("b" ** 64);
429 h.final(out[0..]);429 h.final(out[0..]);
430430
431 htest.assertEqual(h1, out[0..]);431 try htest.assertEqual(h1, out[0..]);
432}432}
433433
434test "comptime blake2s256" {434test "comptime blake2s256" {
...@@ -439,13 +439,13 @@ test "comptime blake2s256" {...@@ -439,13 +439,13 @@ test "comptime blake2s256" {
439439
440 const h1 = "ae09db7cd54f42b490ef09b6bc541af688e4959bb8c53f359a6f56e38ab454a3";440 const h1 = "ae09db7cd54f42b490ef09b6bc541af688e4959bb8c53f359a6f56e38ab454a3";
441441
442 htest.assertEqualHash(Blake2s256, h1, block[0..]);442 try htest.assertEqualHash(Blake2s256, h1, block[0..]);
443443
444 var h = Blake2s256.init(.{});444 var h = Blake2s256.init(.{});
445 h.update(&block);445 h.update(&block);
446 h.final(out[0..]);446 h.final(out[0..]);
447447
448 htest.assertEqual(h1, out[0..]);448 try htest.assertEqual(h1, out[0..]);
449 }449 }
450}450}
451451
...@@ -617,16 +617,16 @@ pub fn Blake2b(comptime out_bits: usize) type {...@@ -617,16 +617,16 @@ pub fn Blake2b(comptime out_bits: usize) type {
617617
618test "blake2b160 single" {618test "blake2b160 single" {
619 const h1 = "3345524abf6bbe1809449224b5972c41790b6cf2";619 const h1 = "3345524abf6bbe1809449224b5972c41790b6cf2";
620 htest.assertEqualHash(Blake2b160, h1, "");620 try htest.assertEqualHash(Blake2b160, h1, "");
621621
622 const h2 = "384264f676f39536840523f284921cdc68b6846b";622 const h2 = "384264f676f39536840523f284921cdc68b6846b";
623 htest.assertEqualHash(Blake2b160, h2, "abc");623 try htest.assertEqualHash(Blake2b160, h2, "abc");
624624
625 const h3 = "3c523ed102ab45a37d54f5610d5a983162fde84f";625 const h3 = "3c523ed102ab45a37d54f5610d5a983162fde84f";
626 htest.assertEqualHash(Blake2b160, h3, "The quick brown fox jumps over the lazy dog");626 try htest.assertEqualHash(Blake2b160, h3, "The quick brown fox jumps over the lazy dog");
627627
628 const h4 = "43758f5de1740f651f1ae39de92260fe8bd5a11f";628 const h4 = "43758f5de1740f651f1ae39de92260fe8bd5a11f";
629 htest.assertEqualHash(Blake2b160, h4, "a" ** 64 ++ "b" ** 64);629 try htest.assertEqualHash(Blake2b160, h4, "a" ** 64 ++ "b" ** 64);
630}630}
631631
632test "blake2b160 streaming" {632test "blake2b160 streaming" {
...@@ -636,40 +636,40 @@ test "blake2b160 streaming" {...@@ -636,40 +636,40 @@ test "blake2b160 streaming" {
636 const h1 = "3345524abf6bbe1809449224b5972c41790b6cf2";636 const h1 = "3345524abf6bbe1809449224b5972c41790b6cf2";
637637
638 h.final(out[0..]);638 h.final(out[0..]);
639 htest.assertEqual(h1, out[0..]);639 try htest.assertEqual(h1, out[0..]);
640640
641 const h2 = "384264f676f39536840523f284921cdc68b6846b";641 const h2 = "384264f676f39536840523f284921cdc68b6846b";
642642
643 h = Blake2b160.init(.{});643 h = Blake2b160.init(.{});
644 h.update("abc");644 h.update("abc");
645 h.final(out[0..]);645 h.final(out[0..]);
646 htest.assertEqual(h2, out[0..]);646 try htest.assertEqual(h2, out[0..]);
647647
648 h = Blake2b160.init(.{});648 h = Blake2b160.init(.{});
649 h.update("a");649 h.update("a");
650 h.update("b");650 h.update("b");
651 h.update("c");651 h.update("c");
652 h.final(out[0..]);652 h.final(out[0..]);
653 htest.assertEqual(h2, out[0..]);653 try htest.assertEqual(h2, out[0..]);
654654
655 const h3 = "43758f5de1740f651f1ae39de92260fe8bd5a11f";655 const h3 = "43758f5de1740f651f1ae39de92260fe8bd5a11f";
656656
657 h = Blake2b160.init(.{});657 h = Blake2b160.init(.{});
658 h.update("a" ** 64 ++ "b" ** 64);658 h.update("a" ** 64 ++ "b" ** 64);
659 h.final(out[0..]);659 h.final(out[0..]);
660 htest.assertEqual(h3, out[0..]);660 try htest.assertEqual(h3, out[0..]);
661661
662 h = Blake2b160.init(.{});662 h = Blake2b160.init(.{});
663 h.update("a" ** 64);663 h.update("a" ** 64);
664 h.update("b" ** 64);664 h.update("b" ** 64);
665 h.final(out[0..]);665 h.final(out[0..]);
666 htest.assertEqual(h3, out[0..]);666 try htest.assertEqual(h3, out[0..]);
667667
668 h = Blake2b160.init(.{});668 h = Blake2b160.init(.{});
669 h.update("a" ** 64);669 h.update("a" ** 64);
670 h.update("b" ** 64);670 h.update("b" ** 64);
671 h.final(out[0..]);671 h.final(out[0..]);
672 htest.assertEqual(h3, out[0..]);672 try htest.assertEqual(h3, out[0..]);
673673
674 const h4 = "72328f8a8200663752fc302d372b5dd9b49dd8dc";674 const h4 = "72328f8a8200663752fc302d372b5dd9b49dd8dc";
675675
...@@ -677,13 +677,13 @@ test "blake2b160 streaming" {...@@ -677,13 +677,13 @@ test "blake2b160 streaming" {
677 h.update("a" ** 64);677 h.update("a" ** 64);
678 h.update("b" ** 64);678 h.update("b" ** 64);
679 h.final(out[0..]);679 h.final(out[0..]);
680 htest.assertEqual(h4, out[0..]);680 try htest.assertEqual(h4, out[0..]);
681681
682 h = Blake2b160.init(.{ .context = [_]u8{0x69} ** 16, .salt = [_]u8{0x42} ** 16 });682 h = Blake2b160.init(.{ .context = [_]u8{0x69} ** 16, .salt = [_]u8{0x42} ** 16 });
683 h.update("a" ** 64);683 h.update("a" ** 64);
684 h.update("b" ** 64);684 h.update("b" ** 64);
685 h.final(out[0..]);685 h.final(out[0..]);
686 htest.assertEqual(h4, out[0..]);686 try htest.assertEqual(h4, out[0..]);
687}687}
688688
689test "comptime blake2b160" {689test "comptime blake2b160" {
...@@ -694,28 +694,28 @@ test "comptime blake2b160" {...@@ -694,28 +694,28 @@ test "comptime blake2b160" {
694694
695 const h1 = "8d26f158f564e3293b42f5e3d34263cb173aa9c9";695 const h1 = "8d26f158f564e3293b42f5e3d34263cb173aa9c9";
696696
697 htest.assertEqualHash(Blake2b160, h1, block[0..]);697 try htest.assertEqualHash(Blake2b160, h1, block[0..]);
698698
699 var h = Blake2b160.init(.{});699 var h = Blake2b160.init(.{});
700 h.update(&block);700 h.update(&block);
701 h.final(out[0..]);701 h.final(out[0..]);
702702
703 htest.assertEqual(h1, out[0..]);703 try htest.assertEqual(h1, out[0..]);
704 }704 }
705}705}
706706
707test "blake2b384 single" {707test "blake2b384 single" {
708 const h1 = "b32811423377f52d7862286ee1a72ee540524380fda1724a6f25d7978c6fd3244a6caf0498812673c5e05ef583825100";708 const h1 = "b32811423377f52d7862286ee1a72ee540524380fda1724a6f25d7978c6fd3244a6caf0498812673c5e05ef583825100";
709 htest.assertEqualHash(Blake2b384, h1, "");709 try htest.assertEqualHash(Blake2b384, h1, "");
710710
711 const h2 = "6f56a82c8e7ef526dfe182eb5212f7db9df1317e57815dbda46083fc30f54ee6c66ba83be64b302d7cba6ce15bb556f4";711 const h2 = "6f56a82c8e7ef526dfe182eb5212f7db9df1317e57815dbda46083fc30f54ee6c66ba83be64b302d7cba6ce15bb556f4";
712 htest.assertEqualHash(Blake2b384, h2, "abc");712 try htest.assertEqualHash(Blake2b384, h2, "abc");
713713
714 const h3 = "b7c81b228b6bd912930e8f0b5387989691c1cee1e65aade4da3b86a3c9f678fc8018f6ed9e2906720c8d2a3aeda9c03d";714 const h3 = "b7c81b228b6bd912930e8f0b5387989691c1cee1e65aade4da3b86a3c9f678fc8018f6ed9e2906720c8d2a3aeda9c03d";
715 htest.assertEqualHash(Blake2b384, h3, "The quick brown fox jumps over the lazy dog");715 try htest.assertEqualHash(Blake2b384, h3, "The quick brown fox jumps over the lazy dog");
716716
717 const h4 = "b7283f0172fecbbd7eca32ce10d8a6c06b453cb3cf675b33eb4246f0da2bb94a6c0bdd6eec0b5fd71ec4fd51be80bf4c";717 const h4 = "b7283f0172fecbbd7eca32ce10d8a6c06b453cb3cf675b33eb4246f0da2bb94a6c0bdd6eec0b5fd71ec4fd51be80bf4c";
718 htest.assertEqualHash(Blake2b384, h4, "a" ** 64 ++ "b" ** 64);718 try htest.assertEqualHash(Blake2b384, h4, "a" ** 64 ++ "b" ** 64);
719}719}
720720
721test "blake2b384 streaming" {721test "blake2b384 streaming" {
...@@ -725,40 +725,40 @@ test "blake2b384 streaming" {...@@ -725,40 +725,40 @@ test "blake2b384 streaming" {
725 const h1 = "b32811423377f52d7862286ee1a72ee540524380fda1724a6f25d7978c6fd3244a6caf0498812673c5e05ef583825100";725 const h1 = "b32811423377f52d7862286ee1a72ee540524380fda1724a6f25d7978c6fd3244a6caf0498812673c5e05ef583825100";
726726
727 h.final(out[0..]);727 h.final(out[0..]);
728 htest.assertEqual(h1, out[0..]);728 try htest.assertEqual(h1, out[0..]);
729729
730 const h2 = "6f56a82c8e7ef526dfe182eb5212f7db9df1317e57815dbda46083fc30f54ee6c66ba83be64b302d7cba6ce15bb556f4";730 const h2 = "6f56a82c8e7ef526dfe182eb5212f7db9df1317e57815dbda46083fc30f54ee6c66ba83be64b302d7cba6ce15bb556f4";
731731
732 h = Blake2b384.init(.{});732 h = Blake2b384.init(.{});
733 h.update("abc");733 h.update("abc");
734 h.final(out[0..]);734 h.final(out[0..]);
735 htest.assertEqual(h2, out[0..]);735 try htest.assertEqual(h2, out[0..]);
736736
737 h = Blake2b384.init(.{});737 h = Blake2b384.init(.{});
738 h.update("a");738 h.update("a");
739 h.update("b");739 h.update("b");
740 h.update("c");740 h.update("c");
741 h.final(out[0..]);741 h.final(out[0..]);
742 htest.assertEqual(h2, out[0..]);742 try htest.assertEqual(h2, out[0..]);
743743
744 const h3 = "b7283f0172fecbbd7eca32ce10d8a6c06b453cb3cf675b33eb4246f0da2bb94a6c0bdd6eec0b5fd71ec4fd51be80bf4c";744 const h3 = "b7283f0172fecbbd7eca32ce10d8a6c06b453cb3cf675b33eb4246f0da2bb94a6c0bdd6eec0b5fd71ec4fd51be80bf4c";
745745
746 h = Blake2b384.init(.{});746 h = Blake2b384.init(.{});
747 h.update("a" ** 64 ++ "b" ** 64);747 h.update("a" ** 64 ++ "b" ** 64);
748 h.final(out[0..]);748 h.final(out[0..]);
749 htest.assertEqual(h3, out[0..]);749 try htest.assertEqual(h3, out[0..]);
750750
751 h = Blake2b384.init(.{});751 h = Blake2b384.init(.{});
752 h.update("a" ** 64);752 h.update("a" ** 64);
753 h.update("b" ** 64);753 h.update("b" ** 64);
754 h.final(out[0..]);754 h.final(out[0..]);
755 htest.assertEqual(h3, out[0..]);755 try htest.assertEqual(h3, out[0..]);
756756
757 h = Blake2b384.init(.{});757 h = Blake2b384.init(.{});
758 h.update("a" ** 64);758 h.update("a" ** 64);
759 h.update("b" ** 64);759 h.update("b" ** 64);
760 h.final(out[0..]);760 h.final(out[0..]);
761 htest.assertEqual(h3, out[0..]);761 try htest.assertEqual(h3, out[0..]);
762762
763 const h4 = "934c48fcb197031c71f583d92f98703510805e72142e0b46f5752d1e971bc86c355d556035613ff7a4154b4de09dac5c";763 const h4 = "934c48fcb197031c71f583d92f98703510805e72142e0b46f5752d1e971bc86c355d556035613ff7a4154b4de09dac5c";
764764
...@@ -766,13 +766,13 @@ test "blake2b384 streaming" {...@@ -766,13 +766,13 @@ test "blake2b384 streaming" {
766 h.update("a" ** 64);766 h.update("a" ** 64);
767 h.update("b" ** 64);767 h.update("b" ** 64);
768 h.final(out[0..]);768 h.final(out[0..]);
769 htest.assertEqual(h4, out[0..]);769 try htest.assertEqual(h4, out[0..]);
770770
771 h = Blake2b384.init(.{ .context = [_]u8{0x69} ** 16, .salt = [_]u8{0x42} ** 16 });771 h = Blake2b384.init(.{ .context = [_]u8{0x69} ** 16, .salt = [_]u8{0x42} ** 16 });
772 h.update("a" ** 64);772 h.update("a" ** 64);
773 h.update("b" ** 64);773 h.update("b" ** 64);
774 h.final(out[0..]);774 h.final(out[0..]);
775 htest.assertEqual(h4, out[0..]);775 try htest.assertEqual(h4, out[0..]);
776}776}
777777
778test "comptime blake2b384" {778test "comptime blake2b384" {
...@@ -783,28 +783,28 @@ test "comptime blake2b384" {...@@ -783,28 +783,28 @@ test "comptime blake2b384" {
783783
784 const h1 = "e8aa1931ea0422e4446fecdd25c16cf35c240b10cb4659dd5c776eddcaa4d922397a589404b46eb2e53d78132d05fd7d";784 const h1 = "e8aa1931ea0422e4446fecdd25c16cf35c240b10cb4659dd5c776eddcaa4d922397a589404b46eb2e53d78132d05fd7d";
785785
786 htest.assertEqualHash(Blake2b384, h1, block[0..]);786 try htest.assertEqualHash(Blake2b384, h1, block[0..]);
787787
788 var h = Blake2b384.init(.{});788 var h = Blake2b384.init(.{});
789 h.update(&block);789 h.update(&block);
790 h.final(out[0..]);790 h.final(out[0..]);
791791
792 htest.assertEqual(h1, out[0..]);792 try htest.assertEqual(h1, out[0..]);
793 }793 }
794}794}
795795
796test "blake2b512 single" {796test "blake2b512 single" {
797 const h1 = "786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce";797 const h1 = "786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce";
798 htest.assertEqualHash(Blake2b512, h1, "");798 try htest.assertEqualHash(Blake2b512, h1, "");
799799
800 const h2 = "ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923";800 const h2 = "ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923";
801 htest.assertEqualHash(Blake2b512, h2, "abc");801 try htest.assertEqualHash(Blake2b512, h2, "abc");
802802
803 const h3 = "a8add4bdddfd93e4877d2746e62817b116364a1fa7bc148d95090bc7333b3673f82401cf7aa2e4cb1ecd90296e3f14cb5413f8ed77be73045b13914cdcd6a918";803 const h3 = "a8add4bdddfd93e4877d2746e62817b116364a1fa7bc148d95090bc7333b3673f82401cf7aa2e4cb1ecd90296e3f14cb5413f8ed77be73045b13914cdcd6a918";
804 htest.assertEqualHash(Blake2b512, h3, "The quick brown fox jumps over the lazy dog");804 try htest.assertEqualHash(Blake2b512, h3, "The quick brown fox jumps over the lazy dog");
805805
806 const h4 = "049980af04d6a2cf16b4b49793c3ed7e40732073788806f2c989ebe9547bda0541d63abe298ec8955d08af48ae731f2e8a0bd6d201655a5473b4aa79d211b920";806 const h4 = "049980af04d6a2cf16b4b49793c3ed7e40732073788806f2c989ebe9547bda0541d63abe298ec8955d08af48ae731f2e8a0bd6d201655a5473b4aa79d211b920";
807 htest.assertEqualHash(Blake2b512, h4, "a" ** 64 ++ "b" ** 64);807 try htest.assertEqualHash(Blake2b512, h4, "a" ** 64 ++ "b" ** 64);
808}808}
809809
810test "blake2b512 streaming" {810test "blake2b512 streaming" {
...@@ -814,34 +814,34 @@ test "blake2b512 streaming" {...@@ -814,34 +814,34 @@ test "blake2b512 streaming" {
814 const h1 = "786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce";814 const h1 = "786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce";
815815
816 h.final(out[0..]);816 h.final(out[0..]);
817 htest.assertEqual(h1, out[0..]);817 try htest.assertEqual(h1, out[0..]);
818818
819 const h2 = "ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923";819 const h2 = "ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923";
820820
821 h = Blake2b512.init(.{});821 h = Blake2b512.init(.{});
822 h.update("abc");822 h.update("abc");
823 h.final(out[0..]);823 h.final(out[0..]);
824 htest.assertEqual(h2, out[0..]);824 try htest.assertEqual(h2, out[0..]);
825825
826 h = Blake2b512.init(.{});826 h = Blake2b512.init(.{});
827 h.update("a");827 h.update("a");
828 h.update("b");828 h.update("b");
829 h.update("c");829 h.update("c");
830 h.final(out[0..]);830 h.final(out[0..]);
831 htest.assertEqual(h2, out[0..]);831 try htest.assertEqual(h2, out[0..]);
832832
833 const h3 = "049980af04d6a2cf16b4b49793c3ed7e40732073788806f2c989ebe9547bda0541d63abe298ec8955d08af48ae731f2e8a0bd6d201655a5473b4aa79d211b920";833 const h3 = "049980af04d6a2cf16b4b49793c3ed7e40732073788806f2c989ebe9547bda0541d63abe298ec8955d08af48ae731f2e8a0bd6d201655a5473b4aa79d211b920";
834834
835 h = Blake2b512.init(.{});835 h = Blake2b512.init(.{});
836 h.update("a" ** 64 ++ "b" ** 64);836 h.update("a" ** 64 ++ "b" ** 64);
837 h.final(out[0..]);837 h.final(out[0..]);
838 htest.assertEqual(h3, out[0..]);838 try htest.assertEqual(h3, out[0..]);
839839
840 h = Blake2b512.init(.{});840 h = Blake2b512.init(.{});
841 h.update("a" ** 64);841 h.update("a" ** 64);
842 h.update("b" ** 64);842 h.update("b" ** 64);
843 h.final(out[0..]);843 h.final(out[0..]);
844 htest.assertEqual(h3, out[0..]);844 try htest.assertEqual(h3, out[0..]);
845}845}
846846
847test "blake2b512 keyed" {847test "blake2b512 keyed" {
...@@ -851,20 +851,20 @@ test "blake2b512 keyed" {...@@ -851,20 +851,20 @@ test "blake2b512 keyed" {
851 const key = "secret_key";851 const key = "secret_key";
852852
853 Blake2b512.hash("a" ** 64 ++ "b" ** 64, &out, .{ .key = key });853 Blake2b512.hash("a" ** 64 ++ "b" ** 64, &out, .{ .key = key });
854 htest.assertEqual(h1, out[0..]);854 try htest.assertEqual(h1, out[0..]);
855855
856 var h = Blake2b512.init(.{ .key = key });856 var h = Blake2b512.init(.{ .key = key });
857 h.update("a" ** 64 ++ "b" ** 64);857 h.update("a" ** 64 ++ "b" ** 64);
858 h.final(out[0..]);858 h.final(out[0..]);
859859
860 htest.assertEqual(h1, out[0..]);860 try htest.assertEqual(h1, out[0..]);
861861
862 h = Blake2b512.init(.{ .key = key });862 h = Blake2b512.init(.{ .key = key });
863 h.update("a" ** 64);863 h.update("a" ** 64);
864 h.update("b" ** 64);864 h.update("b" ** 64);
865 h.final(out[0..]);865 h.final(out[0..]);
866866
867 htest.assertEqual(h1, out[0..]);867 try htest.assertEqual(h1, out[0..]);
868}868}
869869
870test "comptime blake2b512" {870test "comptime blake2b512" {
...@@ -875,12 +875,12 @@ test "comptime blake2b512" {...@@ -875,12 +875,12 @@ test "comptime blake2b512" {
875875
876 const h1 = "865939e120e6805438478841afb739ae4250cf372653078a065cdcfffca4caf798e6d462b65d658fc165782640eded70963449ae1500fb0f24981d7727e22c41";876 const h1 = "865939e120e6805438478841afb739ae4250cf372653078a065cdcfffca4caf798e6d462b65d658fc165782640eded70963449ae1500fb0f24981d7727e22c41";
877877
878 htest.assertEqualHash(Blake2b512, h1, block[0..]);878 try htest.assertEqualHash(Blake2b512, h1, block[0..]);
879879
880 var h = Blake2b512.init(.{});880 var h = Blake2b512.init(.{});
881 h.update(&block);881 h.update(&block);
882 h.final(out[0..]);882 h.final(out[0..]);
883883
884 htest.assertEqual(h1, out[0..]);884 try htest.assertEqual(h1, out[0..]);
885 }885 }
886}886}
lib/std/crypto/blake3.zig+5-5
...@@ -641,7 +641,7 @@ const reference_test = ReferenceTest{...@@ -641,7 +641,7 @@ const reference_test = ReferenceTest{
641 },641 },
642};642};
643643
644fn testBlake3(hasher: *Blake3, input_len: usize, expected_hex: [262]u8) void {644fn testBlake3(hasher: *Blake3, input_len: usize, expected_hex: [262]u8) !void {
645 // Save initial state645 // Save initial state
646 const initial_state = hasher.*;646 const initial_state = hasher.*;
647647
...@@ -664,7 +664,7 @@ fn testBlake3(hasher: *Blake3, input_len: usize, expected_hex: [262]u8) void {...@@ -664,7 +664,7 @@ fn testBlake3(hasher: *Blake3, input_len: usize, expected_hex: [262]u8) void {
664 // Compare to expected value664 // Compare to expected value
665 var expected_bytes: [expected_hex.len / 2]u8 = undefined;665 var expected_bytes: [expected_hex.len / 2]u8 = undefined;
666 _ = fmt.hexToBytes(expected_bytes[0..], expected_hex[0..]) catch unreachable;666 _ = fmt.hexToBytes(expected_bytes[0..], expected_hex[0..]) catch unreachable;
667 testing.expectEqual(actual_bytes, expected_bytes);667 try testing.expectEqual(actual_bytes, expected_bytes);
668668
669 // Restore initial state669 // Restore initial state
670 hasher.* = initial_state;670 hasher.* = initial_state;
...@@ -676,8 +676,8 @@ test "BLAKE3 reference test cases" {...@@ -676,8 +676,8 @@ test "BLAKE3 reference test cases" {
676 var derive_key = &Blake3.initKdf(reference_test.context_string, .{});676 var derive_key = &Blake3.initKdf(reference_test.context_string, .{});
677677
678 for (reference_test.cases) |t| {678 for (reference_test.cases) |t| {
679 testBlake3(hash, t.input_len, t.hash.*);679 try testBlake3(hash, t.input_len, t.hash.*);
680 testBlake3(keyed_hash, t.input_len, t.keyed_hash.*);680 try testBlake3(keyed_hash, t.input_len, t.keyed_hash.*);
681 testBlake3(derive_key, t.input_len, t.derive_key.*);681 try testBlake3(derive_key, t.input_len, t.derive_key.*);
682 }682 }
683}683}
lib/std/crypto/chacha20.zig+21-21
...@@ -604,9 +604,9 @@ test "chacha20 AEAD API" {...@@ -604,9 +604,9 @@ test "chacha20 AEAD API" {
604604
605 aead.encrypt(c[0..], tag[0..], m, ad, nonce, key);605 aead.encrypt(c[0..], tag[0..], m, ad, nonce, key);
606 try aead.decrypt(out[0..], c[0..], tag, ad[0..], nonce, key);606 try aead.decrypt(out[0..], c[0..], tag, ad[0..], nonce, key);
607 testing.expectEqualSlices(u8, out[0..], m);607 try testing.expectEqualSlices(u8, out[0..], m);
608 c[0] += 1;608 c[0] += 1;
609 testing.expectError(error.AuthenticationFailed, aead.decrypt(out[0..], c[0..], tag, ad[0..], nonce, key));609 try testing.expectError(error.AuthenticationFailed, aead.decrypt(out[0..], c[0..], tag, ad[0..], nonce, key));
610 }610 }
611}611}
612612
...@@ -644,11 +644,11 @@ test "crypto.chacha20 test vector sunscreen" {...@@ -644,11 +644,11 @@ test "crypto.chacha20 test vector sunscreen" {
644 };644 };
645645
646 ChaCha20IETF.xor(result[0..], m[0..], 1, key, nonce);646 ChaCha20IETF.xor(result[0..], m[0..], 1, key, nonce);
647 testing.expectEqualSlices(u8, &expected_result, &result);647 try testing.expectEqualSlices(u8, &expected_result, &result);
648648
649 var m2: [114]u8 = undefined;649 var m2: [114]u8 = undefined;
650 ChaCha20IETF.xor(m2[0..], result[0..], 1, key, nonce);650 ChaCha20IETF.xor(m2[0..], result[0..], 1, key, nonce);
651 testing.expect(mem.order(u8, m, &m2) == .eq);651 try testing.expect(mem.order(u8, m, &m2) == .eq);
652}652}
653653
654// https://tools.ietf.org/html/draft-agl-tls-chacha20poly1305-04#section-7654// https://tools.ietf.org/html/draft-agl-tls-chacha20poly1305-04#section-7
...@@ -683,7 +683,7 @@ test "crypto.chacha20 test vector 1" {...@@ -683,7 +683,7 @@ test "crypto.chacha20 test vector 1" {
683 const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0 };683 const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0 };
684684
685 ChaCha20With64BitNonce.xor(result[0..], m[0..], 0, key, nonce);685 ChaCha20With64BitNonce.xor(result[0..], m[0..], 0, key, nonce);
686 testing.expectEqualSlices(u8, &expected_result, &result);686 try testing.expectEqualSlices(u8, &expected_result, &result);
687}687}
688688
689test "crypto.chacha20 test vector 2" {689test "crypto.chacha20 test vector 2" {
...@@ -717,7 +717,7 @@ test "crypto.chacha20 test vector 2" {...@@ -717,7 +717,7 @@ test "crypto.chacha20 test vector 2" {
717 const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0 };717 const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0 };
718718
719 ChaCha20With64BitNonce.xor(result[0..], m[0..], 0, key, nonce);719 ChaCha20With64BitNonce.xor(result[0..], m[0..], 0, key, nonce);
720 testing.expectEqualSlices(u8, &expected_result, &result);720 try testing.expectEqualSlices(u8, &expected_result, &result);
721}721}
722722
723test "crypto.chacha20 test vector 3" {723test "crypto.chacha20 test vector 3" {
...@@ -751,7 +751,7 @@ test "crypto.chacha20 test vector 3" {...@@ -751,7 +751,7 @@ test "crypto.chacha20 test vector 3" {
751 const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 1 };751 const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 1 };
752752
753 ChaCha20With64BitNonce.xor(result[0..], m[0..], 0, key, nonce);753 ChaCha20With64BitNonce.xor(result[0..], m[0..], 0, key, nonce);
754 testing.expectEqualSlices(u8, &expected_result, &result);754 try testing.expectEqualSlices(u8, &expected_result, &result);
755}755}
756756
757test "crypto.chacha20 test vector 4" {757test "crypto.chacha20 test vector 4" {
...@@ -785,7 +785,7 @@ test "crypto.chacha20 test vector 4" {...@@ -785,7 +785,7 @@ test "crypto.chacha20 test vector 4" {
785 const nonce = [_]u8{ 1, 0, 0, 0, 0, 0, 0, 0 };785 const nonce = [_]u8{ 1, 0, 0, 0, 0, 0, 0, 0 };
786786
787 ChaCha20With64BitNonce.xor(result[0..], m[0..], 0, key, nonce);787 ChaCha20With64BitNonce.xor(result[0..], m[0..], 0, key, nonce);
788 testing.expectEqualSlices(u8, &expected_result, &result);788 try testing.expectEqualSlices(u8, &expected_result, &result);
789}789}
790790
791test "crypto.chacha20 test vector 5" {791test "crypto.chacha20 test vector 5" {
...@@ -857,7 +857,7 @@ test "crypto.chacha20 test vector 5" {...@@ -857,7 +857,7 @@ test "crypto.chacha20 test vector 5" {
857 };857 };
858858
859 ChaCha20With64BitNonce.xor(result[0..], m[0..], 0, key, nonce);859 ChaCha20With64BitNonce.xor(result[0..], m[0..], 0, key, nonce);
860 testing.expectEqualSlices(u8, &expected_result, &result);860 try testing.expectEqualSlices(u8, &expected_result, &result);
861}861}
862862
863test "seal" {863test "seal" {
...@@ -873,7 +873,7 @@ test "seal" {...@@ -873,7 +873,7 @@ test "seal" {
873873
874 var out: [exp_out.len]u8 = undefined;874 var out: [exp_out.len]u8 = undefined;
875 ChaCha20Poly1305.encrypt(out[0..m.len], out[m.len..], m, ad, nonce, key);875 ChaCha20Poly1305.encrypt(out[0..m.len], out[m.len..], m, ad, nonce, key);
876 testing.expectEqualSlices(u8, exp_out[0..], out[0..]);876 try testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
877 }877 }
878 {878 {
879 const m = [_]u8{879 const m = [_]u8{
...@@ -906,7 +906,7 @@ test "seal" {...@@ -906,7 +906,7 @@ test "seal" {
906906
907 var out: [exp_out.len]u8 = undefined;907 var out: [exp_out.len]u8 = undefined;
908 ChaCha20Poly1305.encrypt(out[0..m.len], out[m.len..], m[0..], ad[0..], nonce, key);908 ChaCha20Poly1305.encrypt(out[0..m.len], out[m.len..], m[0..], ad[0..], nonce, key);
909 testing.expectEqualSlices(u8, exp_out[0..], out[0..]);909 try testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
910 }910 }
911}911}
912912
...@@ -923,7 +923,7 @@ test "open" {...@@ -923,7 +923,7 @@ test "open" {
923923
924 var out: [exp_out.len]u8 = undefined;924 var out: [exp_out.len]u8 = undefined;
925 try ChaCha20Poly1305.decrypt(out[0..], c[0..exp_out.len], c[exp_out.len..].*, ad[0..], nonce, key);925 try ChaCha20Poly1305.decrypt(out[0..], c[0..exp_out.len], c[exp_out.len..].*, ad[0..], nonce, key);
926 testing.expectEqualSlices(u8, exp_out[0..], out[0..]);926 try testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
927 }927 }
928 {928 {
929 const c = [_]u8{929 const c = [_]u8{
...@@ -956,21 +956,21 @@ test "open" {...@@ -956,21 +956,21 @@ test "open" {
956956
957 var out: [exp_out.len]u8 = undefined;957 var out: [exp_out.len]u8 = undefined;
958 try ChaCha20Poly1305.decrypt(out[0..], c[0..exp_out.len], c[exp_out.len..].*, ad[0..], nonce, key);958 try ChaCha20Poly1305.decrypt(out[0..], c[0..exp_out.len], c[exp_out.len..].*, ad[0..], nonce, key);
959 testing.expectEqualSlices(u8, exp_out[0..], out[0..]);959 try testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
960960
961 // corrupting the ciphertext, data, key, or nonce should cause a failure961 // corrupting the ciphertext, data, key, or nonce should cause a failure
962 var bad_c = c;962 var bad_c = c;
963 bad_c[0] ^= 1;963 bad_c[0] ^= 1;
964 testing.expectError(error.AuthenticationFailed, ChaCha20Poly1305.decrypt(out[0..], bad_c[0..out.len], bad_c[out.len..].*, ad[0..], nonce, key));964 try testing.expectError(error.AuthenticationFailed, ChaCha20Poly1305.decrypt(out[0..], bad_c[0..out.len], bad_c[out.len..].*, ad[0..], nonce, key));
965 var bad_ad = ad;965 var bad_ad = ad;
966 bad_ad[0] ^= 1;966 bad_ad[0] ^= 1;
967 testing.expectError(error.AuthenticationFailed, ChaCha20Poly1305.decrypt(out[0..], c[0..out.len], c[out.len..].*, bad_ad[0..], nonce, key));967 try testing.expectError(error.AuthenticationFailed, ChaCha20Poly1305.decrypt(out[0..], c[0..out.len], c[out.len..].*, bad_ad[0..], nonce, key));
968 var bad_key = key;968 var bad_key = key;
969 bad_key[0] ^= 1;969 bad_key[0] ^= 1;
970 testing.expectError(error.AuthenticationFailed, ChaCha20Poly1305.decrypt(out[0..], c[0..out.len], c[out.len..].*, ad[0..], nonce, bad_key));970 try testing.expectError(error.AuthenticationFailed, ChaCha20Poly1305.decrypt(out[0..], c[0..out.len], c[out.len..].*, ad[0..], nonce, bad_key));
971 var bad_nonce = nonce;971 var bad_nonce = nonce;
972 bad_nonce[0] ^= 1;972 bad_nonce[0] ^= 1;
973 testing.expectError(error.AuthenticationFailed, ChaCha20Poly1305.decrypt(out[0..], c[0..out.len], c[out.len..].*, ad[0..], bad_nonce, key));973 try testing.expectError(error.AuthenticationFailed, ChaCha20Poly1305.decrypt(out[0..], c[0..out.len], c[out.len..].*, ad[0..], bad_nonce, key));
974 }974 }
975}975}
976976
...@@ -982,7 +982,7 @@ test "crypto.xchacha20" {...@@ -982,7 +982,7 @@ test "crypto.xchacha20" {
982 var c: [m.len]u8 = undefined;982 var c: [m.len]u8 = undefined;
983 XChaCha20IETF.xor(c[0..], m[0..], 0, key, nonce);983 XChaCha20IETF.xor(c[0..], m[0..], 0, key, nonce);
984 var buf: [2 * c.len]u8 = undefined;984 var buf: [2 * c.len]u8 = undefined;
985 testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&c)}), "E0A1BCF939654AFDBDC1746EC49832647C19D891F0D1A81FC0C1703B4514BDEA584B512F6908C2C5E9DD18D5CBC1805DE5803FE3B9CA5F193FB8359E91FAB0C3BB40309A292EB1CF49685C65C4A3ADF4F11DB0CD2B6B67FBC174BC2E860E8F769FD3565BBFAD1C845E05A0FED9BE167C240D");985 try testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&c)}), "E0A1BCF939654AFDBDC1746EC49832647C19D891F0D1A81FC0C1703B4514BDEA584B512F6908C2C5E9DD18D5CBC1805DE5803FE3B9CA5F193FB8359E91FAB0C3BB40309A292EB1CF49685C65C4A3ADF4F11DB0CD2B6B67FBC174BC2E860E8F769FD3565BBFAD1C845E05A0FED9BE167C240D");
986 }986 }
987 {987 {
988 const ad = "Additional data";988 const ad = "Additional data";
...@@ -991,9 +991,9 @@ test "crypto.xchacha20" {...@@ -991,9 +991,9 @@ test "crypto.xchacha20" {
991 var out: [m.len]u8 = undefined;991 var out: [m.len]u8 = undefined;
992 try XChaCha20Poly1305.decrypt(out[0..], c[0..m.len], c[m.len..].*, ad, nonce, key);992 try XChaCha20Poly1305.decrypt(out[0..], c[0..m.len], c[m.len..].*, ad, nonce, key);
993 var buf: [2 * c.len]u8 = undefined;993 var buf: [2 * c.len]u8 = undefined;
994 testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&c)}), "994D2DD32333F48E53650C02C7A2ABB8E018B0836D7175AEC779F52E961780768F815C58F1AA52D211498DB89B9216763F569C9433A6BBFCEFB4D4A49387A4C5207FBB3B5A92B5941294DF30588C6740D39DC16FA1F0E634F7246CF7CDCB978E44347D89381B7A74EB7084F754B90BDE9AAF5A94B8F2A85EFD0B50692AE2D425E234");994 try testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&c)}), "994D2DD32333F48E53650C02C7A2ABB8E018B0836D7175AEC779F52E961780768F815C58F1AA52D211498DB89B9216763F569C9433A6BBFCEFB4D4A49387A4C5207FBB3B5A92B5941294DF30588C6740D39DC16FA1F0E634F7246CF7CDCB978E44347D89381B7A74EB7084F754B90BDE9AAF5A94B8F2A85EFD0B50692AE2D425E234");
995 testing.expectEqualSlices(u8, out[0..], m);995 try testing.expectEqualSlices(u8, out[0..], m);
996 c[0] += 1;996 c[0] += 1;
997 testing.expectError(error.AuthenticationFailed, XChaCha20Poly1305.decrypt(out[0..], c[0..m.len], c[m.len..].*, ad, nonce, key));997 try testing.expectError(error.AuthenticationFailed, XChaCha20Poly1305.decrypt(out[0..], c[0..m.len], c[m.len..].*, ad, nonce, key));
998 }998 }
999}999}
lib/std/crypto/ghash.zig+2-2
...@@ -326,11 +326,11 @@ test "ghash" {...@@ -326,11 +326,11 @@ test "ghash" {
326 st.update(&m);326 st.update(&m);
327 var out: [16]u8 = undefined;327 var out: [16]u8 = undefined;
328 st.final(&out);328 st.final(&out);
329 htest.assertEqual("889295fa746e8b174bf4ec80a65dea41", &out);329 try htest.assertEqual("889295fa746e8b174bf4ec80a65dea41", &out);
330330
331 st = Ghash.init(&key);331 st = Ghash.init(&key);
332 st.update(m[0..100]);332 st.update(m[0..100]);
333 st.update(m[100..]);333 st.update(m[100..]);
334 st.final(&out);334 st.final(&out);
335 htest.assertEqual("889295fa746e8b174bf4ec80a65dea41", &out);335 try htest.assertEqual("889295fa746e8b174bf4ec80a65dea41", &out);
336}336}
lib/std/crypto/gimli.zig+19-19
...@@ -205,7 +205,7 @@ test "permute" {...@@ -205,7 +205,7 @@ test "permute" {
205 while (i < 12) : (i += 1) {205 while (i < 12) : (i += 1) {
206 mem.writeIntLittle(u32, expected_output[i * 4 ..][0..4], tv_output[i / 4][i % 4]);206 mem.writeIntLittle(u32, expected_output[i * 4 ..][0..4], tv_output[i / 4][i % 4]);
207 }207 }
208 testing.expectEqualSlices(u8, state.toSliceConst(), expected_output[0..]);208 try testing.expectEqualSlices(u8, state.toSliceConst(), expected_output[0..]);
209}209}
210210
211pub const Hash = struct {211pub const Hash = struct {
...@@ -274,7 +274,7 @@ test "hash" {...@@ -274,7 +274,7 @@ test "hash" {
274 _ = try std.fmt.hexToBytes(&msg, "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C");274 _ = try std.fmt.hexToBytes(&msg, "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C");
275 var md: [32]u8 = undefined;275 var md: [32]u8 = undefined;
276 hash(&md, &msg, .{});276 hash(&md, &msg, .{});
277 htest.assertEqual("1C9A03DC6A5DDC5444CFC6F4B154CFF5CF081633B2CEA4D7D0AE7CCFED5AAA44", &md);277 try htest.assertEqual("1C9A03DC6A5DDC5444CFC6F4B154CFF5CF081633B2CEA4D7D0AE7CCFED5AAA44", &md);
278}278}
279279
280test "hash test vector 17" {280test "hash test vector 17" {
...@@ -282,7 +282,7 @@ test "hash test vector 17" {...@@ -282,7 +282,7 @@ test "hash test vector 17" {
282 _ = try std.fmt.hexToBytes(&msg, "000102030405060708090A0B0C0D0E0F");282 _ = try std.fmt.hexToBytes(&msg, "000102030405060708090A0B0C0D0E0F");
283 var md: [32]u8 = undefined;283 var md: [32]u8 = undefined;
284 hash(&md, &msg, .{});284 hash(&md, &msg, .{});
285 htest.assertEqual("404C130AF1B9023A7908200919F690FFBB756D5176E056FFDE320016A37C7282", &md);285 try htest.assertEqual("404C130AF1B9023A7908200919F690FFBB756D5176E056FFDE320016A37C7282", &md);
286}286}
287287
288test "hash test vector 33" {288test "hash test vector 33" {
...@@ -290,7 +290,7 @@ test "hash test vector 33" {...@@ -290,7 +290,7 @@ test "hash test vector 33" {
290 _ = try std.fmt.hexToBytes(&msg, "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F");290 _ = try std.fmt.hexToBytes(&msg, "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F");
291 var md: [32]u8 = undefined;291 var md: [32]u8 = undefined;
292 hash(&md, &msg, .{});292 hash(&md, &msg, .{});
293 htest.assertEqual("A8F4FA28708BDA7EFB4C1914CA4AFA9E475B82D588D36504F87DBB0ED9AB3C4B", &md);293 try htest.assertEqual("A8F4FA28708BDA7EFB4C1914CA4AFA9E475B82D588D36504F87DBB0ED9AB3C4B", &md);
294}294}
295295
296pub const Aead = struct {296pub const Aead = struct {
...@@ -447,12 +447,12 @@ test "cipher" {...@@ -447,12 +447,12 @@ test "cipher" {
447 var ct: [pt.len]u8 = undefined;447 var ct: [pt.len]u8 = undefined;
448 var tag: [16]u8 = undefined;448 var tag: [16]u8 = undefined;
449 Aead.encrypt(&ct, &tag, &pt, &ad, nonce, key);449 Aead.encrypt(&ct, &tag, &pt, &ad, nonce, key);
450 htest.assertEqual("", &ct);450 try htest.assertEqual("", &ct);
451 htest.assertEqual("14DA9BB7120BF58B985A8E00FDEBA15B", &tag);451 try htest.assertEqual("14DA9BB7120BF58B985A8E00FDEBA15B", &tag);
452452
453 var pt2: [pt.len]u8 = undefined;453 var pt2: [pt.len]u8 = undefined;
454 try Aead.decrypt(&pt2, &ct, tag, &ad, nonce, key);454 try Aead.decrypt(&pt2, &ct, tag, &ad, nonce, key);
455 testing.expectEqualSlices(u8, &pt, &pt2);455 try testing.expectEqualSlices(u8, &pt, &pt2);
456 }456 }
457 { // test vector (34) from NIST KAT submission.457 { // test vector (34) from NIST KAT submission.
458 const ad: [0]u8 = undefined;458 const ad: [0]u8 = undefined;
...@@ -462,12 +462,12 @@ test "cipher" {...@@ -462,12 +462,12 @@ test "cipher" {
462 var ct: [pt.len]u8 = undefined;462 var ct: [pt.len]u8 = undefined;
463 var tag: [16]u8 = undefined;463 var tag: [16]u8 = undefined;
464 Aead.encrypt(&ct, &tag, &pt, &ad, nonce, key);464 Aead.encrypt(&ct, &tag, &pt, &ad, nonce, key);
465 htest.assertEqual("7F", &ct);465 try htest.assertEqual("7F", &ct);
466 htest.assertEqual("80492C317B1CD58A1EDC3A0D3E9876FC", &tag);466 try htest.assertEqual("80492C317B1CD58A1EDC3A0D3E9876FC", &tag);
467467
468 var pt2: [pt.len]u8 = undefined;468 var pt2: [pt.len]u8 = undefined;
469 try Aead.decrypt(&pt2, &ct, tag, &ad, nonce, key);469 try Aead.decrypt(&pt2, &ct, tag, &ad, nonce, key);
470 testing.expectEqualSlices(u8, &pt, &pt2);470 try testing.expectEqualSlices(u8, &pt, &pt2);
471 }471 }
472 { // test vector (106) from NIST KAT submission.472 { // test vector (106) from NIST KAT submission.
473 var ad: [12 / 2]u8 = undefined;473 var ad: [12 / 2]u8 = undefined;
...@@ -478,12 +478,12 @@ test "cipher" {...@@ -478,12 +478,12 @@ test "cipher" {
478 var ct: [pt.len]u8 = undefined;478 var ct: [pt.len]u8 = undefined;
479 var tag: [16]u8 = undefined;479 var tag: [16]u8 = undefined;
480 Aead.encrypt(&ct, &tag, &pt, &ad, nonce, key);480 Aead.encrypt(&ct, &tag, &pt, &ad, nonce, key);
481 htest.assertEqual("484D35", &ct);481 try htest.assertEqual("484D35", &ct);
482 htest.assertEqual("030BBEA23B61C00CED60A923BDCF9147", &tag);482 try htest.assertEqual("030BBEA23B61C00CED60A923BDCF9147", &tag);
483483
484 var pt2: [pt.len]u8 = undefined;484 var pt2: [pt.len]u8 = undefined;
485 try Aead.decrypt(&pt2, &ct, tag, &ad, nonce, key);485 try Aead.decrypt(&pt2, &ct, tag, &ad, nonce, key);
486 testing.expectEqualSlices(u8, &pt, &pt2);486 try testing.expectEqualSlices(u8, &pt, &pt2);
487 }487 }
488 { // test vector (790) from NIST KAT submission.488 { // test vector (790) from NIST KAT submission.
489 var ad: [60 / 2]u8 = undefined;489 var ad: [60 / 2]u8 = undefined;
...@@ -494,12 +494,12 @@ test "cipher" {...@@ -494,12 +494,12 @@ test "cipher" {
494 var ct: [pt.len]u8 = undefined;494 var ct: [pt.len]u8 = undefined;
495 var tag: [16]u8 = undefined;495 var tag: [16]u8 = undefined;
496 Aead.encrypt(&ct, &tag, &pt, &ad, nonce, key);496 Aead.encrypt(&ct, &tag, &pt, &ad, nonce, key);
497 htest.assertEqual("6815B4A0ECDAD01596EAD87D9E690697475D234C6A13D1", &ct);497 try htest.assertEqual("6815B4A0ECDAD01596EAD87D9E690697475D234C6A13D1", &ct);
498 htest.assertEqual("DFE23F1642508290D68245279558B2FB", &tag);498 try htest.assertEqual("DFE23F1642508290D68245279558B2FB", &tag);
499499
500 var pt2: [pt.len]u8 = undefined;500 var pt2: [pt.len]u8 = undefined;
501 try Aead.decrypt(&pt2, &ct, tag, &ad, nonce, key);501 try Aead.decrypt(&pt2, &ct, tag, &ad, nonce, key);
502 testing.expectEqualSlices(u8, &pt, &pt2);502 try testing.expectEqualSlices(u8, &pt, &pt2);
503 }503 }
504 { // test vector (1057) from NIST KAT submission.504 { // test vector (1057) from NIST KAT submission.
505 const ad: [0]u8 = undefined;505 const ad: [0]u8 = undefined;
...@@ -509,11 +509,11 @@ test "cipher" {...@@ -509,11 +509,11 @@ test "cipher" {
509 var ct: [pt.len]u8 = undefined;509 var ct: [pt.len]u8 = undefined;
510 var tag: [16]u8 = undefined;510 var tag: [16]u8 = undefined;
511 Aead.encrypt(&ct, &tag, &pt, &ad, nonce, key);511 Aead.encrypt(&ct, &tag, &pt, &ad, nonce, key);
512 htest.assertEqual("7F8A2CF4F52AA4D6B2E74105C30A2777B9D0C8AEFDD555DE35861BD3011F652F", &ct);512 try htest.assertEqual("7F8A2CF4F52AA4D6B2E74105C30A2777B9D0C8AEFDD555DE35861BD3011F652F", &ct);
513 htest.assertEqual("7256456FA935AC34BBF55AE135F33257", &tag);513 try htest.assertEqual("7256456FA935AC34BBF55AE135F33257", &tag);
514514
515 var pt2: [pt.len]u8 = undefined;515 var pt2: [pt.len]u8 = undefined;
516 try Aead.decrypt(&pt2, &ct, tag, &ad, nonce, key);516 try Aead.decrypt(&pt2, &ct, tag, &ad, nonce, key);
517 testing.expectEqualSlices(u8, &pt, &pt2);517 try testing.expectEqualSlices(u8, &pt, &pt2);
518 }518 }
519}519}
lib/std/crypto/hkdf.zig+2-2
...@@ -65,8 +65,8 @@ test "Hkdf" {...@@ -65,8 +65,8 @@ test "Hkdf" {
65 const context = [_]u8{ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9 };65 const context = [_]u8{ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9 };
66 const kdf = HkdfSha256;66 const kdf = HkdfSha256;
67 const prk = kdf.extract(&salt, &ikm);67 const prk = kdf.extract(&salt, &ikm);
68 htest.assertEqual("077709362c2e32df0ddc3f0dc47bba6390b6c73bb50f9c3122ec844ad7c2b3e5", &prk);68 try htest.assertEqual("077709362c2e32df0ddc3f0dc47bba6390b6c73bb50f9c3122ec844ad7c2b3e5", &prk);
69 var out: [42]u8 = undefined;69 var out: [42]u8 = undefined;
70 kdf.expand(&out, &context, prk);70 kdf.expand(&out, &context, prk);
71 htest.assertEqual("3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865", &out);71 try htest.assertEqual("3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865", &out);
72}72}
lib/std/crypto/hmac.zig+6-6
...@@ -84,26 +84,26 @@ const htest = @import("test.zig");...@@ -84,26 +84,26 @@ const htest = @import("test.zig");
84test "hmac md5" {84test "hmac md5" {
85 var out: [HmacMd5.mac_length]u8 = undefined;85 var out: [HmacMd5.mac_length]u8 = undefined;
86 HmacMd5.create(out[0..], "", "");86 HmacMd5.create(out[0..], "", "");
87 htest.assertEqual("74e6f7298a9c2d168935f58c001bad88", out[0..]);87 try htest.assertEqual("74e6f7298a9c2d168935f58c001bad88", out[0..]);
8888
89 HmacMd5.create(out[0..], "The quick brown fox jumps over the lazy dog", "key");89 HmacMd5.create(out[0..], "The quick brown fox jumps over the lazy dog", "key");
90 htest.assertEqual("80070713463e7749b90c2dc24911e275", out[0..]);90 try htest.assertEqual("80070713463e7749b90c2dc24911e275", out[0..]);
91}91}
9292
93test "hmac sha1" {93test "hmac sha1" {
94 var out: [HmacSha1.mac_length]u8 = undefined;94 var out: [HmacSha1.mac_length]u8 = undefined;
95 HmacSha1.create(out[0..], "", "");95 HmacSha1.create(out[0..], "", "");
96 htest.assertEqual("fbdb1d1b18aa6c08324b7d64b71fb76370690e1d", out[0..]);96 try htest.assertEqual("fbdb1d1b18aa6c08324b7d64b71fb76370690e1d", out[0..]);
9797
98 HmacSha1.create(out[0..], "The quick brown fox jumps over the lazy dog", "key");98 HmacSha1.create(out[0..], "The quick brown fox jumps over the lazy dog", "key");
99 htest.assertEqual("de7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9", out[0..]);99 try htest.assertEqual("de7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9", out[0..]);
100}100}
101101
102test "hmac sha256" {102test "hmac sha256" {
103 var out: [sha2.HmacSha256.mac_length]u8 = undefined;103 var out: [sha2.HmacSha256.mac_length]u8 = undefined;
104 sha2.HmacSha256.create(out[0..], "", "");104 sha2.HmacSha256.create(out[0..], "", "");
105 htest.assertEqual("b613679a0814d9ec772f95d778c35fc5ff1697c493715653c6c712144292c5ad", out[0..]);105 try htest.assertEqual("b613679a0814d9ec772f95d778c35fc5ff1697c493715653c6c712144292c5ad", out[0..]);
106106
107 sha2.HmacSha256.create(out[0..], "The quick brown fox jumps over the lazy dog", "key");107 sha2.HmacSha256.create(out[0..], "The quick brown fox jumps over the lazy dog", "key");
108 htest.assertEqual("f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8", out[0..]);108 try htest.assertEqual("f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8", out[0..]);
109}109}
lib/std/crypto/isap.zig+3-3
...@@ -240,8 +240,8 @@ test "ISAP" {...@@ -240,8 +240,8 @@ test "ISAP" {
240 var msg = "test";240 var msg = "test";
241 var c: [msg.len]u8 = undefined;241 var c: [msg.len]u8 = undefined;
242 IsapA128A.encrypt(c[0..], &tag, msg[0..], ad, n, k);242 IsapA128A.encrypt(c[0..], &tag, msg[0..], ad, n, k);
243 testing.expect(mem.eql(u8, &[_]u8{ 0x8f, 0x68, 0x03, 0x8d }, c[0..]));243 try testing.expect(mem.eql(u8, &[_]u8{ 0x8f, 0x68, 0x03, 0x8d }, c[0..]));
244 testing.expect(mem.eql(u8, &[_]u8{ 0x6c, 0x25, 0xe8, 0xe2, 0xe1, 0x1f, 0x38, 0xe9, 0x80, 0x75, 0xde, 0xd5, 0x2d, 0xb2, 0x31, 0x82 }, tag[0..]));244 try testing.expect(mem.eql(u8, &[_]u8{ 0x6c, 0x25, 0xe8, 0xe2, 0xe1, 0x1f, 0x38, 0xe9, 0x80, 0x75, 0xde, 0xd5, 0x2d, 0xb2, 0x31, 0x82 }, tag[0..]));
245 try IsapA128A.decrypt(c[0..], c[0..], tag, ad, n, k);245 try IsapA128A.decrypt(c[0..], c[0..], tag, ad, n, k);
246 testing.expect(mem.eql(u8, msg, c[0..]));246 try testing.expect(mem.eql(u8, msg, c[0..]));
247}247}
lib/std/crypto/md5.zig+10-10
...@@ -241,13 +241,13 @@ pub const Md5 = struct {...@@ -241,13 +241,13 @@ pub const Md5 = struct {
241const htest = @import("test.zig");241const htest = @import("test.zig");
242242
243test "md5 single" {243test "md5 single" {
244 htest.assertEqualHash(Md5, "d41d8cd98f00b204e9800998ecf8427e", "");244 try htest.assertEqualHash(Md5, "d41d8cd98f00b204e9800998ecf8427e", "");
245 htest.assertEqualHash(Md5, "0cc175b9c0f1b6a831c399e269772661", "a");245 try htest.assertEqualHash(Md5, "0cc175b9c0f1b6a831c399e269772661", "a");
246 htest.assertEqualHash(Md5, "900150983cd24fb0d6963f7d28e17f72", "abc");246 try htest.assertEqualHash(Md5, "900150983cd24fb0d6963f7d28e17f72", "abc");
247 htest.assertEqualHash(Md5, "f96b697d7cb7938d525a2f31aaf161d0", "message digest");247 try htest.assertEqualHash(Md5, "f96b697d7cb7938d525a2f31aaf161d0", "message digest");
248 htest.assertEqualHash(Md5, "c3fcd3d76192e4007dfb496cca67e13b", "abcdefghijklmnopqrstuvwxyz");248 try htest.assertEqualHash(Md5, "c3fcd3d76192e4007dfb496cca67e13b", "abcdefghijklmnopqrstuvwxyz");
249 htest.assertEqualHash(Md5, "d174ab98d277d9f5a5611c2c9f419d9f", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");249 try htest.assertEqualHash(Md5, "d174ab98d277d9f5a5611c2c9f419d9f", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
250 htest.assertEqualHash(Md5, "57edf4a22be3c955ac49da2e2107b67a", "12345678901234567890123456789012345678901234567890123456789012345678901234567890");250 try htest.assertEqualHash(Md5, "57edf4a22be3c955ac49da2e2107b67a", "12345678901234567890123456789012345678901234567890123456789012345678901234567890");
251}251}
252252
253test "md5 streaming" {253test "md5 streaming" {
...@@ -255,12 +255,12 @@ test "md5 streaming" {...@@ -255,12 +255,12 @@ test "md5 streaming" {
255 var out: [16]u8 = undefined;255 var out: [16]u8 = undefined;
256256
257 h.final(out[0..]);257 h.final(out[0..]);
258 htest.assertEqual("d41d8cd98f00b204e9800998ecf8427e", out[0..]);258 try htest.assertEqual("d41d8cd98f00b204e9800998ecf8427e", out[0..]);
259259
260 h = Md5.init(.{});260 h = Md5.init(.{});
261 h.update("abc");261 h.update("abc");
262 h.final(out[0..]);262 h.final(out[0..]);
263 htest.assertEqual("900150983cd24fb0d6963f7d28e17f72", out[0..]);263 try htest.assertEqual("900150983cd24fb0d6963f7d28e17f72", out[0..]);
264264
265 h = Md5.init(.{});265 h = Md5.init(.{});
266 h.update("a");266 h.update("a");
...@@ -268,7 +268,7 @@ test "md5 streaming" {...@@ -268,7 +268,7 @@ test "md5 streaming" {
268 h.update("c");268 h.update("c");
269 h.final(out[0..]);269 h.final(out[0..]);
270270
271 htest.assertEqual("900150983cd24fb0d6963f7d28e17f72", out[0..]);271 try htest.assertEqual("900150983cd24fb0d6963f7d28e17f72", out[0..]);
272}272}
273273
274test "md5 aligned final" {274test "md5 aligned final" {
lib/std/crypto/pbkdf2.zig+6-6
...@@ -168,7 +168,7 @@ test "RFC 6070 one iteration" {...@@ -168,7 +168,7 @@ test "RFC 6070 one iteration" {
168168
169 const expected = "0c60c80f961f0e71f3a9b524af6012062fe037a6";169 const expected = "0c60c80f961f0e71f3a9b524af6012062fe037a6";
170170
171 htest.assertEqual(expected, dk[0..]);171 try htest.assertEqual(expected, dk[0..]);
172}172}
173173
174test "RFC 6070 two iterations" {174test "RFC 6070 two iterations" {
...@@ -183,7 +183,7 @@ test "RFC 6070 two iterations" {...@@ -183,7 +183,7 @@ test "RFC 6070 two iterations" {
183183
184 const expected = "ea6c014dc72d6f8ccd1ed92ace1d41f0d8de8957";184 const expected = "ea6c014dc72d6f8ccd1ed92ace1d41f0d8de8957";
185185
186 htest.assertEqual(expected, dk[0..]);186 try htest.assertEqual(expected, dk[0..]);
187}187}
188188
189test "RFC 6070 4096 iterations" {189test "RFC 6070 4096 iterations" {
...@@ -198,7 +198,7 @@ test "RFC 6070 4096 iterations" {...@@ -198,7 +198,7 @@ test "RFC 6070 4096 iterations" {
198198
199 const expected = "4b007901b765489abead49d926f721d065a429c1";199 const expected = "4b007901b765489abead49d926f721d065a429c1";
200200
201 htest.assertEqual(expected, dk[0..]);201 try htest.assertEqual(expected, dk[0..]);
202}202}
203203
204test "RFC 6070 16,777,216 iterations" {204test "RFC 6070 16,777,216 iterations" {
...@@ -218,7 +218,7 @@ test "RFC 6070 16,777,216 iterations" {...@@ -218,7 +218,7 @@ test "RFC 6070 16,777,216 iterations" {
218218
219 const expected = "eefe3d61cd4da4e4e9945b3d6ba2158c2634e984";219 const expected = "eefe3d61cd4da4e4e9945b3d6ba2158c2634e984";
220220
221 htest.assertEqual(expected, dk[0..]);221 try htest.assertEqual(expected, dk[0..]);
222}222}
223223
224test "RFC 6070 multi-block salt and password" {224test "RFC 6070 multi-block salt and password" {
...@@ -233,7 +233,7 @@ test "RFC 6070 multi-block salt and password" {...@@ -233,7 +233,7 @@ test "RFC 6070 multi-block salt and password" {
233233
234 const expected = "3d2eec4fe41c849b80c8d83662c0e44a8b291a964cf2f07038";234 const expected = "3d2eec4fe41c849b80c8d83662c0e44a8b291a964cf2f07038";
235235
236 htest.assertEqual(expected, dk[0..]);236 try htest.assertEqual(expected, dk[0..]);
237}237}
238238
239test "RFC 6070 embedded NUL" {239test "RFC 6070 embedded NUL" {
...@@ -248,7 +248,7 @@ test "RFC 6070 embedded NUL" {...@@ -248,7 +248,7 @@ test "RFC 6070 embedded NUL" {
248248
249 const expected = "56fa6aa75548099dcc37d7f03425e0c3";249 const expected = "56fa6aa75548099dcc37d7f03425e0c3";
250250
251 htest.assertEqual(expected, dk[0..]);251 try htest.assertEqual(expected, dk[0..]);
252}252}
253253
254test "Very large dk_len" {254test "Very large dk_len" {
lib/std/crypto/pcurves/tests.zig+9-9
...@@ -17,7 +17,7 @@ test "p256 ECDH key exchange" {...@@ -17,7 +17,7 @@ test "p256 ECDH key exchange" {
17 const dhB = try P256.basePoint.mul(dhb, .Little);17 const dhB = try P256.basePoint.mul(dhb, .Little);
18 const shareda = try dhA.mul(dhb, .Little);18 const shareda = try dhA.mul(dhb, .Little);
19 const sharedb = try dhB.mul(dha, .Little);19 const sharedb = try dhB.mul(dha, .Little);
20 testing.expect(shareda.equivalent(sharedb));20 try testing.expect(shareda.equivalent(sharedb));
21}21}
2222
23test "p256 point from affine coordinates" {23test "p256 point from affine coordinates" {
...@@ -28,7 +28,7 @@ test "p256 point from affine coordinates" {...@@ -28,7 +28,7 @@ test "p256 point from affine coordinates" {
28 var ys: [32]u8 = undefined;28 var ys: [32]u8 = undefined;
29 _ = try fmt.hexToBytes(&ys, yh);29 _ = try fmt.hexToBytes(&ys, yh);
30 var p = try P256.fromSerializedAffineCoordinates(xs, ys, .Big);30 var p = try P256.fromSerializedAffineCoordinates(xs, ys, .Big);
31 testing.expect(p.equivalent(P256.basePoint));31 try testing.expect(p.equivalent(P256.basePoint));
32}32}
3333
34test "p256 test vectors" {34test "p256 test vectors" {
...@@ -50,7 +50,7 @@ test "p256 test vectors" {...@@ -50,7 +50,7 @@ test "p256 test vectors" {
50 p = p.add(P256.basePoint);50 p = p.add(P256.basePoint);
51 var xs: [32]u8 = undefined;51 var xs: [32]u8 = undefined;
52 _ = try fmt.hexToBytes(&xs, xh);52 _ = try fmt.hexToBytes(&xs, xh);
53 testing.expectEqualSlices(u8, &x.toBytes(.Big), &xs);53 try testing.expectEqualSlices(u8, &x.toBytes(.Big), &xs);
54 }54 }
55}55}
5656
...@@ -67,7 +67,7 @@ test "p256 test vectors - doubling" {...@@ -67,7 +67,7 @@ test "p256 test vectors - doubling" {
67 p = p.dbl();67 p = p.dbl();
68 var xs: [32]u8 = undefined;68 var xs: [32]u8 = undefined;
69 _ = try fmt.hexToBytes(&xs, xh);69 _ = try fmt.hexToBytes(&xs, xh);
70 testing.expectEqualSlices(u8, &x.toBytes(.Big), &xs);70 try testing.expectEqualSlices(u8, &x.toBytes(.Big), &xs);
71 }71 }
72}72}
7373
...@@ -75,29 +75,29 @@ test "p256 compressed sec1 encoding/decoding" {...@@ -75,29 +75,29 @@ test "p256 compressed sec1 encoding/decoding" {
75 const p = P256.random();75 const p = P256.random();
76 const s = p.toCompressedSec1();76 const s = p.toCompressedSec1();
77 const q = try P256.fromSec1(&s);77 const q = try P256.fromSec1(&s);
78 testing.expect(p.equivalent(q));78 try testing.expect(p.equivalent(q));
79}79}
8080
81test "p256 uncompressed sec1 encoding/decoding" {81test "p256 uncompressed sec1 encoding/decoding" {
82 const p = P256.random();82 const p = P256.random();
83 const s = p.toUncompressedSec1();83 const s = p.toUncompressedSec1();
84 const q = try P256.fromSec1(&s);84 const q = try P256.fromSec1(&s);
85 testing.expect(p.equivalent(q));85 try testing.expect(p.equivalent(q));
86}86}
8787
88test "p256 public key is the neutral element" {88test "p256 public key is the neutral element" {
89 const n = P256.scalar.Scalar.zero.toBytes(.Little);89 const n = P256.scalar.Scalar.zero.toBytes(.Little);
90 const p = P256.random();90 const p = P256.random();
91 testing.expectError(error.IdentityElement, p.mul(n, .Little));91 try testing.expectError(error.IdentityElement, p.mul(n, .Little));
92}92}
9393
94test "p256 public key is the neutral element (public verification)" {94test "p256 public key is the neutral element (public verification)" {
95 const n = P256.scalar.Scalar.zero.toBytes(.Little);95 const n = P256.scalar.Scalar.zero.toBytes(.Little);
96 const p = P256.random();96 const p = P256.random();
97 testing.expectError(error.IdentityElement, p.mulPublic(n, .Little));97 try testing.expectError(error.IdentityElement, p.mulPublic(n, .Little));
98}98}
9999
100test "p256 field element non-canonical encoding" {100test "p256 field element non-canonical encoding" {
101 const s = [_]u8{0xff} ** 32;101 const s = [_]u8{0xff} ** 32;
102 testing.expectError(error.NonCanonical, P256.Fe.fromBytes(s, .Little));102 try testing.expectError(error.NonCanonical, P256.Fe.fromBytes(s, .Little));
103}103}
lib/std/crypto/poly1305.zig+1-1
...@@ -216,5 +216,5 @@ test "poly1305 rfc7439 vector1" {...@@ -216,5 +216,5 @@ test "poly1305 rfc7439 vector1" {
216 var mac: [16]u8 = undefined;216 var mac: [16]u8 = undefined;
217 Poly1305.create(mac[0..], msg, key);217 Poly1305.create(mac[0..], msg, key);
218218
219 std.testing.expectEqualSlices(u8, expected_mac, &mac);219 try std.testing.expectEqualSlices(u8, expected_mac, &mac);
220}220}
lib/std/crypto/salsa20.zig+3-3
...@@ -561,11 +561,11 @@ test "(x)salsa20" {...@@ -561,11 +561,11 @@ test "(x)salsa20" {
561 var c: [msg.len]u8 = undefined;561 var c: [msg.len]u8 = undefined;
562562
563 Salsa20.xor(&c, msg[0..], 0, key, nonce);563 Salsa20.xor(&c, msg[0..], 0, key, nonce);
564 htest.assertEqual("30ff9933aa6534ff5207142593cd1fca4b23bdd8", c[0..]);564 try htest.assertEqual("30ff9933aa6534ff5207142593cd1fca4b23bdd8", c[0..]);
565565
566 const extended_nonce = [_]u8{0x42} ** 24;566 const extended_nonce = [_]u8{0x42} ** 24;
567 XSalsa20.xor(&c, msg[0..], 0, key, extended_nonce);567 XSalsa20.xor(&c, msg[0..], 0, key, extended_nonce);
568 htest.assertEqual("b4ab7d82e750ec07644fa3281bce6cd91d4243f9", c[0..]);568 try htest.assertEqual("b4ab7d82e750ec07644fa3281bce6cd91d4243f9", c[0..]);
569}569}
570570
571test "xsalsa20poly1305" {571test "xsalsa20poly1305" {
...@@ -628,5 +628,5 @@ test "secretbox twoblocks" {...@@ -628,5 +628,5 @@ test "secretbox twoblocks" {
628 const msg = [_]u8{'a'} ** 97;628 const msg = [_]u8{'a'} ** 97;
629 var ciphertext: [msg.len + SecretBox.tag_length]u8 = undefined;629 var ciphertext: [msg.len + SecretBox.tag_length]u8 = undefined;
630 SecretBox.seal(&ciphertext, &msg, nonce, key);630 SecretBox.seal(&ciphertext, &msg, nonce, key);
631 htest.assertEqual("b05760e217288ba079caa2fd57fd3701784974ffcfda20fe523b89211ad8af065a6eb37cdb29d51aca5bd75dafdd21d18b044c54bb7c526cf576c94ee8900f911ceab0147e82b667a28c52d58ceb29554ff45471224d37b03256b01c119b89ff6d36855de8138d103386dbc9d971f52261", &ciphertext);631 try htest.assertEqual("b05760e217288ba079caa2fd57fd3701784974ffcfda20fe523b89211ad8af065a6eb37cdb29d51aca5bd75dafdd21d18b044c54bb7c526cf576c94ee8900f911ceab0147e82b667a28c52d58ceb29554ff45471224d37b03256b01c119b89ff6d36855de8138d103386dbc9d971f52261", &ciphertext);
632}632}
lib/std/crypto/sha1.zig+6-6
...@@ -265,9 +265,9 @@ pub const Sha1 = struct {...@@ -265,9 +265,9 @@ pub const Sha1 = struct {
265const htest = @import("test.zig");265const htest = @import("test.zig");
266266
267test "sha1 single" {267test "sha1 single" {
268 htest.assertEqualHash(Sha1, "da39a3ee5e6b4b0d3255bfef95601890afd80709", "");268 try htest.assertEqualHash(Sha1, "da39a3ee5e6b4b0d3255bfef95601890afd80709", "");
269 htest.assertEqualHash(Sha1, "a9993e364706816aba3e25717850c26c9cd0d89d", "abc");269 try htest.assertEqualHash(Sha1, "a9993e364706816aba3e25717850c26c9cd0d89d", "abc");
270 htest.assertEqualHash(Sha1, "a49b2446a02c645bf419f995b67091253a04a259", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");270 try htest.assertEqualHash(Sha1, "a49b2446a02c645bf419f995b67091253a04a259", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
271}271}
272272
273test "sha1 streaming" {273test "sha1 streaming" {
...@@ -275,19 +275,19 @@ test "sha1 streaming" {...@@ -275,19 +275,19 @@ test "sha1 streaming" {
275 var out: [20]u8 = undefined;275 var out: [20]u8 = undefined;
276276
277 h.final(&out);277 h.final(&out);
278 htest.assertEqual("da39a3ee5e6b4b0d3255bfef95601890afd80709", out[0..]);278 try htest.assertEqual("da39a3ee5e6b4b0d3255bfef95601890afd80709", out[0..]);
279279
280 h = Sha1.init(.{});280 h = Sha1.init(.{});
281 h.update("abc");281 h.update("abc");
282 h.final(&out);282 h.final(&out);
283 htest.assertEqual("a9993e364706816aba3e25717850c26c9cd0d89d", out[0..]);283 try htest.assertEqual("a9993e364706816aba3e25717850c26c9cd0d89d", out[0..]);
284284
285 h = Sha1.init(.{});285 h = Sha1.init(.{});
286 h.update("a");286 h.update("a");
287 h.update("b");287 h.update("b");
288 h.update("c");288 h.update("c");
289 h.final(&out);289 h.final(&out);
290 htest.assertEqual("a9993e364706816aba3e25717850c26c9cd0d89d", out[0..]);290 try htest.assertEqual("a9993e364706816aba3e25717850c26c9cd0d89d", out[0..]);
291}291}
292292
293test "sha1 aligned final" {293test "sha1 aligned final" {
lib/std/crypto/sha2.zig+24-24
...@@ -285,9 +285,9 @@ fn Sha2x32(comptime params: Sha2Params32) type {...@@ -285,9 +285,9 @@ fn Sha2x32(comptime params: Sha2Params32) type {
285}285}
286286
287test "sha224 single" {287test "sha224 single" {
288 htest.assertEqualHash(Sha224, "d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f", "");288 try htest.assertEqualHash(Sha224, "d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f", "");
289 htest.assertEqualHash(Sha224, "23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", "abc");289 try htest.assertEqualHash(Sha224, "23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", "abc");
290 htest.assertEqualHash(Sha224, "c97ca9a559850ce97a04a96def6d99a9e0e0e2ab14e6b8df265fc0b3", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");290 try htest.assertEqualHash(Sha224, "c97ca9a559850ce97a04a96def6d99a9e0e0e2ab14e6b8df265fc0b3", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
291}291}
292292
293test "sha224 streaming" {293test "sha224 streaming" {
...@@ -295,25 +295,25 @@ test "sha224 streaming" {...@@ -295,25 +295,25 @@ test "sha224 streaming" {
295 var out: [28]u8 = undefined;295 var out: [28]u8 = undefined;
296296
297 h.final(out[0..]);297 h.final(out[0..]);
298 htest.assertEqual("d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f", out[0..]);298 try htest.assertEqual("d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f", out[0..]);
299299
300 h = Sha224.init(.{});300 h = Sha224.init(.{});
301 h.update("abc");301 h.update("abc");
302 h.final(out[0..]);302 h.final(out[0..]);
303 htest.assertEqual("23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", out[0..]);303 try htest.assertEqual("23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", out[0..]);
304304
305 h = Sha224.init(.{});305 h = Sha224.init(.{});
306 h.update("a");306 h.update("a");
307 h.update("b");307 h.update("b");
308 h.update("c");308 h.update("c");
309 h.final(out[0..]);309 h.final(out[0..]);
310 htest.assertEqual("23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", out[0..]);310 try htest.assertEqual("23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", out[0..]);
311}311}
312312
313test "sha256 single" {313test "sha256 single" {
314 htest.assertEqualHash(Sha256, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "");314 try htest.assertEqualHash(Sha256, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "");
315 htest.assertEqualHash(Sha256, "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", "abc");315 try htest.assertEqualHash(Sha256, "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", "abc");
316 htest.assertEqualHash(Sha256, "cf5b16a778af8380036ce59e7b0492370b249b11e8f07a51afac45037afee9d1", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");316 try htest.assertEqualHash(Sha256, "cf5b16a778af8380036ce59e7b0492370b249b11e8f07a51afac45037afee9d1", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
317}317}
318318
319test "sha256 streaming" {319test "sha256 streaming" {
...@@ -321,19 +321,19 @@ test "sha256 streaming" {...@@ -321,19 +321,19 @@ test "sha256 streaming" {
321 var out: [32]u8 = undefined;321 var out: [32]u8 = undefined;
322322
323 h.final(out[0..]);323 h.final(out[0..]);
324 htest.assertEqual("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", out[0..]);324 try htest.assertEqual("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", out[0..]);
325325
326 h = Sha256.init(.{});326 h = Sha256.init(.{});
327 h.update("abc");327 h.update("abc");
328 h.final(out[0..]);328 h.final(out[0..]);
329 htest.assertEqual("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", out[0..]);329 try htest.assertEqual("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", out[0..]);
330330
331 h = Sha256.init(.{});331 h = Sha256.init(.{});
332 h.update("a");332 h.update("a");
333 h.update("b");333 h.update("b");
334 h.update("c");334 h.update("c");
335 h.final(out[0..]);335 h.final(out[0..]);
336 htest.assertEqual("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", out[0..]);336 try htest.assertEqual("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", out[0..]);
337}337}
338338
339test "sha256 aligned final" {339test "sha256 aligned final" {
...@@ -675,13 +675,13 @@ fn Sha2x64(comptime params: Sha2Params64) type {...@@ -675,13 +675,13 @@ fn Sha2x64(comptime params: Sha2Params64) type {
675675
676test "sha384 single" {676test "sha384 single" {
677 const h1 = "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b";677 const h1 = "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b";
678 htest.assertEqualHash(Sha384, h1, "");678 try htest.assertEqualHash(Sha384, h1, "");
679679
680 const h2 = "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7";680 const h2 = "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7";
681 htest.assertEqualHash(Sha384, h2, "abc");681 try htest.assertEqualHash(Sha384, h2, "abc");
682682
683 const h3 = "09330c33f71147e83d192fc782cd1b4753111b173b3b05d22fa08086e3b0f712fcc7c71a557e2db966c3e9fa91746039";683 const h3 = "09330c33f71147e83d192fc782cd1b4753111b173b3b05d22fa08086e3b0f712fcc7c71a557e2db966c3e9fa91746039";
684 htest.assertEqualHash(Sha384, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");684 try htest.assertEqualHash(Sha384, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
685}685}
686686
687test "sha384 streaming" {687test "sha384 streaming" {
...@@ -690,32 +690,32 @@ test "sha384 streaming" {...@@ -690,32 +690,32 @@ test "sha384 streaming" {
690690
691 const h1 = "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b";691 const h1 = "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b";
692 h.final(out[0..]);692 h.final(out[0..]);
693 htest.assertEqual(h1, out[0..]);693 try htest.assertEqual(h1, out[0..]);
694694
695 const h2 = "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7";695 const h2 = "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7";
696696
697 h = Sha384.init(.{});697 h = Sha384.init(.{});
698 h.update("abc");698 h.update("abc");
699 h.final(out[0..]);699 h.final(out[0..]);
700 htest.assertEqual(h2, out[0..]);700 try htest.assertEqual(h2, out[0..]);
701701
702 h = Sha384.init(.{});702 h = Sha384.init(.{});
703 h.update("a");703 h.update("a");
704 h.update("b");704 h.update("b");
705 h.update("c");705 h.update("c");
706 h.final(out[0..]);706 h.final(out[0..]);
707 htest.assertEqual(h2, out[0..]);707 try htest.assertEqual(h2, out[0..]);
708}708}
709709
710test "sha512 single" {710test "sha512 single" {
711 const h1 = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e";711 const h1 = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e";
712 htest.assertEqualHash(Sha512, h1, "");712 try htest.assertEqualHash(Sha512, h1, "");
713713
714 const h2 = "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f";714 const h2 = "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f";
715 htest.assertEqualHash(Sha512, h2, "abc");715 try htest.assertEqualHash(Sha512, h2, "abc");
716716
717 const h3 = "8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018501d289e4900f7e4331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909";717 const h3 = "8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018501d289e4900f7e4331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909";
718 htest.assertEqualHash(Sha512, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");718 try htest.assertEqualHash(Sha512, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
719}719}
720720
721test "sha512 streaming" {721test "sha512 streaming" {
...@@ -724,21 +724,21 @@ test "sha512 streaming" {...@@ -724,21 +724,21 @@ test "sha512 streaming" {
724724
725 const h1 = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e";725 const h1 = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e";
726 h.final(out[0..]);726 h.final(out[0..]);
727 htest.assertEqual(h1, out[0..]);727 try htest.assertEqual(h1, out[0..]);
728728
729 const h2 = "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f";729 const h2 = "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f";
730730
731 h = Sha512.init(.{});731 h = Sha512.init(.{});
732 h.update("abc");732 h.update("abc");
733 h.final(out[0..]);733 h.final(out[0..]);
734 htest.assertEqual(h2, out[0..]);734 try htest.assertEqual(h2, out[0..]);
735735
736 h = Sha512.init(.{});736 h = Sha512.init(.{});
737 h.update("a");737 h.update("a");
738 h.update("b");738 h.update("b");
739 h.update("c");739 h.update("c");
740 h.final(out[0..]);740 h.final(out[0..]);
741 htest.assertEqual(h2, out[0..]);741 try htest.assertEqual(h2, out[0..]);
742}742}
743743
744test "sha512 aligned final" {744test "sha512 aligned final" {
lib/std/crypto/sha3.zig+30-30
...@@ -169,9 +169,9 @@ fn keccakF(comptime F: usize, d: *[F / 8]u8) void {...@@ -169,9 +169,9 @@ fn keccakF(comptime F: usize, d: *[F / 8]u8) void {
169}169}
170170
171test "sha3-224 single" {171test "sha3-224 single" {
172 htest.assertEqualHash(Sha3_224, "6b4e03423667dbb73b6e15454f0eb1abd4597f9a1b078e3f5b5a6bc7", "");172 try htest.assertEqualHash(Sha3_224, "6b4e03423667dbb73b6e15454f0eb1abd4597f9a1b078e3f5b5a6bc7", "");
173 htest.assertEqualHash(Sha3_224, "e642824c3f8cf24ad09234ee7d3c766fc9a3a5168d0c94ad73b46fdf", "abc");173 try htest.assertEqualHash(Sha3_224, "e642824c3f8cf24ad09234ee7d3c766fc9a3a5168d0c94ad73b46fdf", "abc");
174 htest.assertEqualHash(Sha3_224, "543e6868e1666c1a643630df77367ae5a62a85070a51c14cbf665cbc", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");174 try htest.assertEqualHash(Sha3_224, "543e6868e1666c1a643630df77367ae5a62a85070a51c14cbf665cbc", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
175}175}
176176
177test "sha3-224 streaming" {177test "sha3-224 streaming" {
...@@ -179,25 +179,25 @@ test "sha3-224 streaming" {...@@ -179,25 +179,25 @@ test "sha3-224 streaming" {
179 var out: [28]u8 = undefined;179 var out: [28]u8 = undefined;
180180
181 h.final(out[0..]);181 h.final(out[0..]);
182 htest.assertEqual("6b4e03423667dbb73b6e15454f0eb1abd4597f9a1b078e3f5b5a6bc7", out[0..]);182 try htest.assertEqual("6b4e03423667dbb73b6e15454f0eb1abd4597f9a1b078e3f5b5a6bc7", out[0..]);
183183
184 h = Sha3_224.init(.{});184 h = Sha3_224.init(.{});
185 h.update("abc");185 h.update("abc");
186 h.final(out[0..]);186 h.final(out[0..]);
187 htest.assertEqual("e642824c3f8cf24ad09234ee7d3c766fc9a3a5168d0c94ad73b46fdf", out[0..]);187 try htest.assertEqual("e642824c3f8cf24ad09234ee7d3c766fc9a3a5168d0c94ad73b46fdf", out[0..]);
188188
189 h = Sha3_224.init(.{});189 h = Sha3_224.init(.{});
190 h.update("a");190 h.update("a");
191 h.update("b");191 h.update("b");
192 h.update("c");192 h.update("c");
193 h.final(out[0..]);193 h.final(out[0..]);
194 htest.assertEqual("e642824c3f8cf24ad09234ee7d3c766fc9a3a5168d0c94ad73b46fdf", out[0..]);194 try htest.assertEqual("e642824c3f8cf24ad09234ee7d3c766fc9a3a5168d0c94ad73b46fdf", out[0..]);
195}195}
196196
197test "sha3-256 single" {197test "sha3-256 single" {
198 htest.assertEqualHash(Sha3_256, "a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a", "");198 try htest.assertEqualHash(Sha3_256, "a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a", "");
199 htest.assertEqualHash(Sha3_256, "3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532", "abc");199 try htest.assertEqualHash(Sha3_256, "3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532", "abc");
200 htest.assertEqualHash(Sha3_256, "916f6061fe879741ca6469b43971dfdb28b1a32dc36cb3254e812be27aad1d18", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");200 try htest.assertEqualHash(Sha3_256, "916f6061fe879741ca6469b43971dfdb28b1a32dc36cb3254e812be27aad1d18", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
201}201}
202202
203test "sha3-256 streaming" {203test "sha3-256 streaming" {
...@@ -205,19 +205,19 @@ test "sha3-256 streaming" {...@@ -205,19 +205,19 @@ test "sha3-256 streaming" {
205 var out: [32]u8 = undefined;205 var out: [32]u8 = undefined;
206206
207 h.final(out[0..]);207 h.final(out[0..]);
208 htest.assertEqual("a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a", out[0..]);208 try htest.assertEqual("a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a", out[0..]);
209209
210 h = Sha3_256.init(.{});210 h = Sha3_256.init(.{});
211 h.update("abc");211 h.update("abc");
212 h.final(out[0..]);212 h.final(out[0..]);
213 htest.assertEqual("3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532", out[0..]);213 try htest.assertEqual("3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532", out[0..]);
214214
215 h = Sha3_256.init(.{});215 h = Sha3_256.init(.{});
216 h.update("a");216 h.update("a");
217 h.update("b");217 h.update("b");
218 h.update("c");218 h.update("c");
219 h.final(out[0..]);219 h.final(out[0..]);
220 htest.assertEqual("3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532", out[0..]);220 try htest.assertEqual("3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532", out[0..]);
221}221}
222222
223test "sha3-256 aligned final" {223test "sha3-256 aligned final" {
...@@ -231,11 +231,11 @@ test "sha3-256 aligned final" {...@@ -231,11 +231,11 @@ test "sha3-256 aligned final" {
231231
232test "sha3-384 single" {232test "sha3-384 single" {
233 const h1 = "0c63a75b845e4f7d01107d852e4c2485c51a50aaaa94fc61995e71bbee983a2ac3713831264adb47fb6bd1e058d5f004";233 const h1 = "0c63a75b845e4f7d01107d852e4c2485c51a50aaaa94fc61995e71bbee983a2ac3713831264adb47fb6bd1e058d5f004";
234 htest.assertEqualHash(Sha3_384, h1, "");234 try htest.assertEqualHash(Sha3_384, h1, "");
235 const h2 = "ec01498288516fc926459f58e2c6ad8df9b473cb0fc08c2596da7cf0e49be4b298d88cea927ac7f539f1edf228376d25";235 const h2 = "ec01498288516fc926459f58e2c6ad8df9b473cb0fc08c2596da7cf0e49be4b298d88cea927ac7f539f1edf228376d25";
236 htest.assertEqualHash(Sha3_384, h2, "abc");236 try htest.assertEqualHash(Sha3_384, h2, "abc");
237 const h3 = "79407d3b5916b59c3e30b09822974791c313fb9ecc849e406f23592d04f625dc8c709b98b43b3852b337216179aa7fc7";237 const h3 = "79407d3b5916b59c3e30b09822974791c313fb9ecc849e406f23592d04f625dc8c709b98b43b3852b337216179aa7fc7";
238 htest.assertEqualHash(Sha3_384, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");238 try htest.assertEqualHash(Sha3_384, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
239}239}
240240
241test "sha3-384 streaming" {241test "sha3-384 streaming" {
...@@ -244,29 +244,29 @@ test "sha3-384 streaming" {...@@ -244,29 +244,29 @@ test "sha3-384 streaming" {
244244
245 const h1 = "0c63a75b845e4f7d01107d852e4c2485c51a50aaaa94fc61995e71bbee983a2ac3713831264adb47fb6bd1e058d5f004";245 const h1 = "0c63a75b845e4f7d01107d852e4c2485c51a50aaaa94fc61995e71bbee983a2ac3713831264adb47fb6bd1e058d5f004";
246 h.final(out[0..]);246 h.final(out[0..]);
247 htest.assertEqual(h1, out[0..]);247 try htest.assertEqual(h1, out[0..]);
248248
249 const h2 = "ec01498288516fc926459f58e2c6ad8df9b473cb0fc08c2596da7cf0e49be4b298d88cea927ac7f539f1edf228376d25";249 const h2 = "ec01498288516fc926459f58e2c6ad8df9b473cb0fc08c2596da7cf0e49be4b298d88cea927ac7f539f1edf228376d25";
250 h = Sha3_384.init(.{});250 h = Sha3_384.init(.{});
251 h.update("abc");251 h.update("abc");
252 h.final(out[0..]);252 h.final(out[0..]);
253 htest.assertEqual(h2, out[0..]);253 try htest.assertEqual(h2, out[0..]);
254254
255 h = Sha3_384.init(.{});255 h = Sha3_384.init(.{});
256 h.update("a");256 h.update("a");
257 h.update("b");257 h.update("b");
258 h.update("c");258 h.update("c");
259 h.final(out[0..]);259 h.final(out[0..]);
260 htest.assertEqual(h2, out[0..]);260 try htest.assertEqual(h2, out[0..]);
261}261}
262262
263test "sha3-512 single" {263test "sha3-512 single" {
264 const h1 = "a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26";264 const h1 = "a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26";
265 htest.assertEqualHash(Sha3_512, h1, "");265 try htest.assertEqualHash(Sha3_512, h1, "");
266 const h2 = "b751850b1a57168a5693cd924b6b096e08f621827444f70d884f5d0240d2712e10e116e9192af3c91a7ec57647e3934057340b4cf408d5a56592f8274eec53f0";266 const h2 = "b751850b1a57168a5693cd924b6b096e08f621827444f70d884f5d0240d2712e10e116e9192af3c91a7ec57647e3934057340b4cf408d5a56592f8274eec53f0";
267 htest.assertEqualHash(Sha3_512, h2, "abc");267 try htest.assertEqualHash(Sha3_512, h2, "abc");
268 const h3 = "afebb2ef542e6579c50cad06d2e578f9f8dd6881d7dc824d26360feebf18a4fa73e3261122948efcfd492e74e82e2189ed0fb440d187f382270cb455f21dd185";268 const h3 = "afebb2ef542e6579c50cad06d2e578f9f8dd6881d7dc824d26360feebf18a4fa73e3261122948efcfd492e74e82e2189ed0fb440d187f382270cb455f21dd185";
269 htest.assertEqualHash(Sha3_512, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");269 try htest.assertEqualHash(Sha3_512, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
270}270}
271271
272test "sha3-512 streaming" {272test "sha3-512 streaming" {
...@@ -275,20 +275,20 @@ test "sha3-512 streaming" {...@@ -275,20 +275,20 @@ test "sha3-512 streaming" {
275275
276 const h1 = "a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26";276 const h1 = "a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26";
277 h.final(out[0..]);277 h.final(out[0..]);
278 htest.assertEqual(h1, out[0..]);278 try htest.assertEqual(h1, out[0..]);
279279
280 const h2 = "b751850b1a57168a5693cd924b6b096e08f621827444f70d884f5d0240d2712e10e116e9192af3c91a7ec57647e3934057340b4cf408d5a56592f8274eec53f0";280 const h2 = "b751850b1a57168a5693cd924b6b096e08f621827444f70d884f5d0240d2712e10e116e9192af3c91a7ec57647e3934057340b4cf408d5a56592f8274eec53f0";
281 h = Sha3_512.init(.{});281 h = Sha3_512.init(.{});
282 h.update("abc");282 h.update("abc");
283 h.final(out[0..]);283 h.final(out[0..]);
284 htest.assertEqual(h2, out[0..]);284 try htest.assertEqual(h2, out[0..]);
285285
286 h = Sha3_512.init(.{});286 h = Sha3_512.init(.{});
287 h.update("a");287 h.update("a");
288 h.update("b");288 h.update("b");
289 h.update("c");289 h.update("c");
290 h.final(out[0..]);290 h.final(out[0..]);
291 htest.assertEqual(h2, out[0..]);291 try htest.assertEqual(h2, out[0..]);
292}292}
293293
294test "sha3-512 aligned final" {294test "sha3-512 aligned final" {
...@@ -301,13 +301,13 @@ test "sha3-512 aligned final" {...@@ -301,13 +301,13 @@ test "sha3-512 aligned final" {
301}301}
302302
303test "keccak-256 single" {303test "keccak-256 single" {
304 htest.assertEqualHash(Keccak_256, "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470", "");304 try htest.assertEqualHash(Keccak_256, "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470", "");
305 htest.assertEqualHash(Keccak_256, "4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45", "abc");305 try htest.assertEqualHash(Keccak_256, "4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45", "abc");
306 htest.assertEqualHash(Keccak_256, "f519747ed599024f3882238e5ab43960132572b7345fbeb9a90769dafd21ad67", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");306 try htest.assertEqualHash(Keccak_256, "f519747ed599024f3882238e5ab43960132572b7345fbeb9a90769dafd21ad67", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
307}307}
308308
309test "keccak-512 single" {309test "keccak-512 single" {
310 htest.assertEqualHash(Keccak_512, "0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e", "");310 try htest.assertEqualHash(Keccak_512, "0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e", "");
311 htest.assertEqualHash(Keccak_512, "18587dc2ea106b9a1563e32b3312421ca164c7f1f07bc922a9c83d77cea3a1e5d0c69910739025372dc14ac9642629379540c17e2a65b19d77aa511a9d00bb96", "abc");311 try htest.assertEqualHash(Keccak_512, "18587dc2ea106b9a1563e32b3312421ca164c7f1f07bc922a9c83d77cea3a1e5d0c69910739025372dc14ac9642629379540c17e2a65b19d77aa511a9d00bb96", "abc");
312 htest.assertEqualHash(Keccak_512, "ac2fb35251825d3aa48468a9948c0a91b8256f6d97d8fa4160faff2dd9dfcc24f3f1db7a983dad13d53439ccac0b37e24037e7b95f80f59f37a2f683c4ba4682", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");312 try htest.assertEqualHash(Keccak_512, "ac2fb35251825d3aa48468a9948c0a91b8256f6d97d8fa4160faff2dd9dfcc24f3f1db7a983dad13d53439ccac0b37e24037e7b95f80f59f37a2f683c4ba4682", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
313}313}
lib/std/crypto/siphash.zig+3-3
...@@ -319,7 +319,7 @@ test "siphash64-2-4 sanity" {...@@ -319,7 +319,7 @@ test "siphash64-2-4 sanity" {
319319
320 var out: [siphash.mac_length]u8 = undefined;320 var out: [siphash.mac_length]u8 = undefined;
321 siphash.create(&out, buffer[0..i], test_key);321 siphash.create(&out, buffer[0..i], test_key);
322 testing.expectEqual(out, vector);322 try testing.expectEqual(out, vector);
323 }323 }
324}324}
325325
...@@ -399,7 +399,7 @@ test "siphash128-2-4 sanity" {...@@ -399,7 +399,7 @@ test "siphash128-2-4 sanity" {
399399
400 var out: [siphash.mac_length]u8 = undefined;400 var out: [siphash.mac_length]u8 = undefined;
401 siphash.create(&out, buffer[0..i], test_key[0..]);401 siphash.create(&out, buffer[0..i], test_key[0..]);
402 testing.expectEqual(out, vector);402 try testing.expectEqual(out, vector);
403 }403 }
404}404}
405405
...@@ -423,6 +423,6 @@ test "iterative non-divisible update" {...@@ -423,6 +423,6 @@ test "iterative non-divisible update" {
423 }423 }
424 const iterative_hash = siphash.finalInt();424 const iterative_hash = siphash.finalInt();
425425
426 std.testing.expectEqual(iterative_hash, non_iterative_hash);426 try std.testing.expectEqual(iterative_hash, non_iterative_hash);
427 }427 }
428}428}
lib/std/crypto/test.zig+4-4
...@@ -8,19 +8,19 @@ const testing = std.testing;...@@ -8,19 +8,19 @@ const testing = std.testing;
8const fmt = std.fmt;8const fmt = std.fmt;
99
10// Hash using the specified hasher `H` asserting `expected == H(input)`.10// Hash using the specified hasher `H` asserting `expected == H(input)`.
11pub fn assertEqualHash(comptime Hasher: anytype, comptime expected_hex: *const [Hasher.digest_length * 2:0]u8, input: []const u8) void {11pub fn assertEqualHash(comptime Hasher: anytype, comptime expected_hex: *const [Hasher.digest_length * 2:0]u8, input: []const u8) !void {
12 var h: [Hasher.digest_length]u8 = undefined;12 var h: [Hasher.digest_length]u8 = undefined;
13 Hasher.hash(input, &h, .{});13 Hasher.hash(input, &h, .{});
1414
15 assertEqual(expected_hex, &h);15 try assertEqual(expected_hex, &h);
16}16}
1717
18// Assert `expected` == hex(`input`) where `input` is a bytestring18// Assert `expected` == hex(`input`) where `input` is a bytestring
19pub fn assertEqual(comptime expected_hex: [:0]const u8, input: []const u8) void {19pub fn assertEqual(comptime expected_hex: [:0]const u8, input: []const u8) !void {
20 var expected_bytes: [expected_hex.len / 2]u8 = undefined;20 var expected_bytes: [expected_hex.len / 2]u8 = undefined;
21 for (expected_bytes) |*r, i| {21 for (expected_bytes) |*r, i| {
22 r.* = fmt.parseInt(u8, expected_hex[2 * i .. 2 * i + 2], 16) catch unreachable;22 r.* = fmt.parseInt(u8, expected_hex[2 * i .. 2 * i + 2], 16) catch unreachable;
23 }23 }
2424
25 testing.expectEqualSlices(u8, &expected_bytes, input);25 try testing.expectEqualSlices(u8, &expected_bytes, input);
26}26}
lib/std/crypto/utils.zig+11-11
...@@ -92,9 +92,9 @@ test "crypto.utils.timingSafeEql" {...@@ -92,9 +92,9 @@ test "crypto.utils.timingSafeEql" {
92 var b: [100]u8 = undefined;92 var b: [100]u8 = undefined;
93 std.crypto.random.bytes(a[0..]);93 std.crypto.random.bytes(a[0..]);
94 std.crypto.random.bytes(b[0..]);94 std.crypto.random.bytes(b[0..]);
95 testing.expect(!timingSafeEql([100]u8, a, b));95 try testing.expect(!timingSafeEql([100]u8, a, b));
96 mem.copy(u8, a[0..], b[0..]);96 mem.copy(u8, a[0..], b[0..]);
97 testing.expect(timingSafeEql([100]u8, a, b));97 try testing.expect(timingSafeEql([100]u8, a, b));
98}98}
9999
100test "crypto.utils.timingSafeEql (vectors)" {100test "crypto.utils.timingSafeEql (vectors)" {
...@@ -104,22 +104,22 @@ test "crypto.utils.timingSafeEql (vectors)" {...@@ -104,22 +104,22 @@ test "crypto.utils.timingSafeEql (vectors)" {
104 std.crypto.random.bytes(b[0..]);104 std.crypto.random.bytes(b[0..]);
105 const v1: std.meta.Vector(100, u8) = a;105 const v1: std.meta.Vector(100, u8) = a;
106 const v2: std.meta.Vector(100, u8) = b;106 const v2: std.meta.Vector(100, u8) = b;
107 testing.expect(!timingSafeEql(std.meta.Vector(100, u8), v1, v2));107 try testing.expect(!timingSafeEql(std.meta.Vector(100, u8), v1, v2));
108 const v3: std.meta.Vector(100, u8) = a;108 const v3: std.meta.Vector(100, u8) = a;
109 testing.expect(timingSafeEql(std.meta.Vector(100, u8), v1, v3));109 try testing.expect(timingSafeEql(std.meta.Vector(100, u8), v1, v3));
110}110}
111111
112test "crypto.utils.timingSafeCompare" {112test "crypto.utils.timingSafeCompare" {
113 var a = [_]u8{10} ** 32;113 var a = [_]u8{10} ** 32;
114 var b = [_]u8{10} ** 32;114 var b = [_]u8{10} ** 32;
115 testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .eq);115 try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .eq);
116 testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .eq);116 try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .eq);
117 a[31] = 1;117 a[31] = 1;
118 testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .lt);118 try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .lt);
119 testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .lt);119 try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .lt);
120 a[0] = 20;120 a[0] = 20;
121 testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .gt);121 try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .gt);
122 testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .lt);122 try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .lt);
123}123}
124124
125test "crypto.utils.secureZero" {125test "crypto.utils.secureZero" {
...@@ -129,5 +129,5 @@ test "crypto.utils.secureZero" {...@@ -129,5 +129,5 @@ test "crypto.utils.secureZero" {
129 mem.set(u8, a[0..], 0);129 mem.set(u8, a[0..], 0);
130 secureZero(u8, b[0..]);130 secureZero(u8, b[0..]);
131131
132 testing.expectEqualSlices(u8, a[0..], b[0..]);132 try testing.expectEqualSlices(u8, a[0..], b[0..]);
133}133}
lib/std/cstr.zig+7-7
...@@ -27,13 +27,13 @@ pub fn cmp(a: [*:0]const u8, b: [*:0]const u8) i8 {...@@ -27,13 +27,13 @@ pub fn cmp(a: [*:0]const u8, b: [*:0]const u8) i8 {
27}27}
2828
29test "cstr fns" {29test "cstr fns" {
30 comptime testCStrFnsImpl();30 comptime try testCStrFnsImpl();
31 testCStrFnsImpl();31 try testCStrFnsImpl();
32}32}
3333
34fn testCStrFnsImpl() void {34fn testCStrFnsImpl() !void {
35 testing.expect(cmp("aoeu", "aoez") == -1);35 try testing.expect(cmp("aoeu", "aoez") == -1);
36 testing.expect(mem.len("123456789") == 9);36 try testing.expect(mem.len("123456789") == 9);
37}37}
3838
39/// Returns a mutable, null-terminated slice with the same length as `slice`.39/// Returns a mutable, null-terminated slice with the same length as `slice`.
...@@ -48,8 +48,8 @@ pub fn addNullByte(allocator: *mem.Allocator, slice: []const u8) ![:0]u8 {...@@ -48,8 +48,8 @@ pub fn addNullByte(allocator: *mem.Allocator, slice: []const u8) ![:0]u8 {
48test "addNullByte" {48test "addNullByte" {
49 const slice = try addNullByte(std.testing.allocator, "hello"[0..4]);49 const slice = try addNullByte(std.testing.allocator, "hello"[0..4]);
50 defer std.testing.allocator.free(slice);50 defer std.testing.allocator.free(slice);
51 testing.expect(slice.len == 4);51 try testing.expect(slice.len == 4);
52 testing.expect(slice[4] == 0);52 try testing.expect(slice[4] == 0);
53}53}
5454
55pub const NullTerminated2DArray = struct {55pub const NullTerminated2DArray = struct {
lib/std/dynamic_library.zig+1-1
...@@ -408,7 +408,7 @@ test "dynamic_library" {...@@ -408,7 +408,7 @@ test "dynamic_library" {
408 };408 };
409409
410 const dynlib = DynLib.open(libname) catch |err| {410 const dynlib = DynLib.open(libname) catch |err| {
411 testing.expect(err == error.FileNotFound);411 try testing.expect(err == error.FileNotFound);
412 return;412 return;
413 };413 };
414}414}
lib/std/elf.zig+1-1
...@@ -565,7 +565,7 @@ test "bswapAllFields" {...@@ -565,7 +565,7 @@ test "bswapAllFields" {
565 .ch_addralign = 0x12124242,565 .ch_addralign = 0x12124242,
566 };566 };
567 bswapAllFields(Elf32_Chdr, &s);567 bswapAllFields(Elf32_Chdr, &s);
568 std.testing.expectEqual(Elf32_Chdr{568 try std.testing.expectEqual(Elf32_Chdr{
569 .ch_type = 0x34123412,569 .ch_type = 0x34123412,
570 .ch_size = 0x78567856,570 .ch_size = 0x78567856,
571 .ch_addralign = 0x42421212,571 .ch_addralign = 0x42421212,
lib/std/enums.zig+275-275
...@@ -56,10 +56,10 @@ test "std.enums.valuesFromFields" {...@@ -56,10 +56,10 @@ test "std.enums.valuesFromFields" {
56 .{ .name = "a", .value = undefined },56 .{ .name = "a", .value = undefined },
57 .{ .name = "d", .value = undefined },57 .{ .name = "d", .value = undefined },
58 });58 });
59 testing.expectEqual(E.b, fields[0]);59 try testing.expectEqual(E.b, fields[0]);
60 testing.expectEqual(E.a, fields[1]);60 try testing.expectEqual(E.a, fields[1]);
61 testing.expectEqual(E.d, fields[2]); // a == d61 try testing.expectEqual(E.d, fields[2]); // a == d
62 testing.expectEqual(E.d, fields[3]);62 try testing.expectEqual(E.d, fields[3]);
63}63}
6464
65/// Returns the set of all named values in the given enum, in65/// Returns the set of all named values in the given enum, in
...@@ -70,7 +70,7 @@ pub fn values(comptime E: type) []const E {...@@ -70,7 +70,7 @@ pub fn values(comptime E: type) []const E {
7070
71test "std.enum.values" {71test "std.enum.values" {
72 const E = extern enum { a, b, c, d = 0 };72 const E = extern enum { a, b, c, d = 0 };
73 testing.expectEqualSlices(E, &.{ .a, .b, .c, .d }, values(E));73 try testing.expectEqualSlices(E, &.{ .a, .b, .c, .d }, values(E));
74}74}
7575
76/// Returns the set of all unique named values in the given enum, in76/// Returns the set of all unique named values in the given enum, in
...@@ -82,10 +82,10 @@ pub fn uniqueValues(comptime E: type) []const E {...@@ -82,10 +82,10 @@ pub fn uniqueValues(comptime E: type) []const E {
8282
83test "std.enum.uniqueValues" {83test "std.enum.uniqueValues" {
84 const E = extern enum { a, b, c, d = 0, e, f = 3 };84 const E = extern enum { a, b, c, d = 0, e, f = 3 };
85 testing.expectEqualSlices(E, &.{ .a, .b, .c, .f }, uniqueValues(E));85 try testing.expectEqualSlices(E, &.{ .a, .b, .c, .f }, uniqueValues(E));
8686
87 const F = enum { a, b, c };87 const F = enum { a, b, c };
88 testing.expectEqualSlices(F, &.{ .a, .b, .c }, uniqueValues(F));88 try testing.expectEqualSlices(F, &.{ .a, .b, .c }, uniqueValues(F));
89}89}
9090
91/// Returns the set of all unique field values in the given enum, in91/// Returns the set of all unique field values in the given enum, in
...@@ -179,10 +179,10 @@ test "std.enums.directEnumArray" {...@@ -179,10 +179,10 @@ test "std.enums.directEnumArray" {
179 .c = true,179 .c = true,
180 });180 });
181181
182 testing.expectEqual([7]bool, @TypeOf(array));182 try testing.expectEqual([7]bool, @TypeOf(array));
183 testing.expectEqual(true, array[4]);183 try testing.expectEqual(true, array[4]);
184 testing.expectEqual(false, array[6]);184 try testing.expectEqual(false, array[6]);
185 testing.expectEqual(true, array[2]);185 try testing.expectEqual(true, array[2]);
186}186}
187187
188/// Initializes an array of Data which can be indexed by188/// Initializes an array of Data which can be indexed by
...@@ -220,10 +220,10 @@ test "std.enums.directEnumArrayDefault" {...@@ -220,10 +220,10 @@ test "std.enums.directEnumArrayDefault" {
220 .b = runtime_false,220 .b = runtime_false,
221 });221 });
222222
223 testing.expectEqual([7]bool, @TypeOf(array));223 try testing.expectEqual([7]bool, @TypeOf(array));
224 testing.expectEqual(true, array[4]);224 try testing.expectEqual(true, array[4]);
225 testing.expectEqual(false, array[6]);225 try testing.expectEqual(false, array[6]);
226 testing.expectEqual(false, array[2]);226 try testing.expectEqual(false, array[2]);
227}227}
228228
229/// Cast an enum literal, value, or string to the enum value of type E229/// Cast an enum literal, value, or string to the enum value of type E
...@@ -250,23 +250,23 @@ pub fn nameCast(comptime E: type, comptime value: anytype) E {...@@ -250,23 +250,23 @@ pub fn nameCast(comptime E: type, comptime value: anytype) E {
250test "std.enums.nameCast" {250test "std.enums.nameCast" {
251 const A = enum { a = 0, b = 1 };251 const A = enum { a = 0, b = 1 };
252 const B = enum { a = 1, b = 0 };252 const B = enum { a = 1, b = 0 };
253 testing.expectEqual(A.a, nameCast(A, .a));253 try testing.expectEqual(A.a, nameCast(A, .a));
254 testing.expectEqual(A.a, nameCast(A, A.a));254 try testing.expectEqual(A.a, nameCast(A, A.a));
255 testing.expectEqual(A.a, nameCast(A, B.a));255 try testing.expectEqual(A.a, nameCast(A, B.a));
256 testing.expectEqual(A.a, nameCast(A, "a"));256 try testing.expectEqual(A.a, nameCast(A, "a"));
257 testing.expectEqual(A.a, nameCast(A, @as(*const [1]u8, "a")));257 try testing.expectEqual(A.a, nameCast(A, @as(*const [1]u8, "a")));
258 testing.expectEqual(A.a, nameCast(A, @as([:0]const u8, "a")));258 try testing.expectEqual(A.a, nameCast(A, @as([:0]const u8, "a")));
259 testing.expectEqual(A.a, nameCast(A, @as([]const u8, "a")));259 try testing.expectEqual(A.a, nameCast(A, @as([]const u8, "a")));
260260
261 testing.expectEqual(B.a, nameCast(B, .a));261 try testing.expectEqual(B.a, nameCast(B, .a));
262 testing.expectEqual(B.a, nameCast(B, A.a));262 try testing.expectEqual(B.a, nameCast(B, A.a));
263 testing.expectEqual(B.a, nameCast(B, B.a));263 try testing.expectEqual(B.a, nameCast(B, B.a));
264 testing.expectEqual(B.a, nameCast(B, "a"));264 try testing.expectEqual(B.a, nameCast(B, "a"));
265265
266 testing.expectEqual(B.b, nameCast(B, .b));266 try testing.expectEqual(B.b, nameCast(B, .b));
267 testing.expectEqual(B.b, nameCast(B, A.b));267 try testing.expectEqual(B.b, nameCast(B, A.b));
268 testing.expectEqual(B.b, nameCast(B, B.b));268 try testing.expectEqual(B.b, nameCast(B, B.b));
269 testing.expectEqual(B.b, nameCast(B, "b"));269 try testing.expectEqual(B.b, nameCast(B, "b"));
270}270}
271271
272/// A set of enum elements, backed by a bitfield. If the enum272/// A set of enum elements, backed by a bitfield. If the enum
...@@ -851,202 +851,202 @@ test "std.enums.EnumIndexer dense zeroed" {...@@ -851,202 +851,202 @@ test "std.enums.EnumIndexer dense zeroed" {
851 const E = enum { b = 1, a = 0, c = 2 };851 const E = enum { b = 1, a = 0, c = 2 };
852 const Indexer = EnumIndexer(E);852 const Indexer = EnumIndexer(E);
853 ensureIndexer(Indexer);853 ensureIndexer(Indexer);
854 testing.expectEqual(E, Indexer.Key);854 try testing.expectEqual(E, Indexer.Key);
855 testing.expectEqual(@as(usize, 3), Indexer.count);855 try testing.expectEqual(@as(usize, 3), Indexer.count);
856856
857 testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));857 try testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
858 testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));858 try testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
859 testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));859 try testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
860860
861 testing.expectEqual(E.a, Indexer.keyForIndex(0));861 try testing.expectEqual(E.a, Indexer.keyForIndex(0));
862 testing.expectEqual(E.b, Indexer.keyForIndex(1));862 try testing.expectEqual(E.b, Indexer.keyForIndex(1));
863 testing.expectEqual(E.c, Indexer.keyForIndex(2));863 try testing.expectEqual(E.c, Indexer.keyForIndex(2));
864}864}
865865
866test "std.enums.EnumIndexer dense positive" {866test "std.enums.EnumIndexer dense positive" {
867 const E = enum(u4) { c = 6, a = 4, b = 5 };867 const E = enum(u4) { c = 6, a = 4, b = 5 };
868 const Indexer = EnumIndexer(E);868 const Indexer = EnumIndexer(E);
869 ensureIndexer(Indexer);869 ensureIndexer(Indexer);
870 testing.expectEqual(E, Indexer.Key);870 try testing.expectEqual(E, Indexer.Key);
871 testing.expectEqual(@as(usize, 3), Indexer.count);871 try testing.expectEqual(@as(usize, 3), Indexer.count);
872872
873 testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));873 try testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
874 testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));874 try testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
875 testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));875 try testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
876876
877 testing.expectEqual(E.a, Indexer.keyForIndex(0));877 try testing.expectEqual(E.a, Indexer.keyForIndex(0));
878 testing.expectEqual(E.b, Indexer.keyForIndex(1));878 try testing.expectEqual(E.b, Indexer.keyForIndex(1));
879 testing.expectEqual(E.c, Indexer.keyForIndex(2));879 try testing.expectEqual(E.c, Indexer.keyForIndex(2));
880}880}
881881
882test "std.enums.EnumIndexer dense negative" {882test "std.enums.EnumIndexer dense negative" {
883 const E = enum(i4) { a = -6, c = -4, b = -5 };883 const E = enum(i4) { a = -6, c = -4, b = -5 };
884 const Indexer = EnumIndexer(E);884 const Indexer = EnumIndexer(E);
885 ensureIndexer(Indexer);885 ensureIndexer(Indexer);
886 testing.expectEqual(E, Indexer.Key);886 try testing.expectEqual(E, Indexer.Key);
887 testing.expectEqual(@as(usize, 3), Indexer.count);887 try testing.expectEqual(@as(usize, 3), Indexer.count);
888888
889 testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));889 try testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
890 testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));890 try testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
891 testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));891 try testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
892892
893 testing.expectEqual(E.a, Indexer.keyForIndex(0));893 try testing.expectEqual(E.a, Indexer.keyForIndex(0));
894 testing.expectEqual(E.b, Indexer.keyForIndex(1));894 try testing.expectEqual(E.b, Indexer.keyForIndex(1));
895 testing.expectEqual(E.c, Indexer.keyForIndex(2));895 try testing.expectEqual(E.c, Indexer.keyForIndex(2));
896}896}
897897
898test "std.enums.EnumIndexer sparse" {898test "std.enums.EnumIndexer sparse" {
899 const E = enum(i4) { a = -2, c = 6, b = 4 };899 const E = enum(i4) { a = -2, c = 6, b = 4 };
900 const Indexer = EnumIndexer(E);900 const Indexer = EnumIndexer(E);
901 ensureIndexer(Indexer);901 ensureIndexer(Indexer);
902 testing.expectEqual(E, Indexer.Key);902 try testing.expectEqual(E, Indexer.Key);
903 testing.expectEqual(@as(usize, 3), Indexer.count);903 try testing.expectEqual(@as(usize, 3), Indexer.count);
904904
905 testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));905 try testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
906 testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));906 try testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
907 testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));907 try testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
908908
909 testing.expectEqual(E.a, Indexer.keyForIndex(0));909 try testing.expectEqual(E.a, Indexer.keyForIndex(0));
910 testing.expectEqual(E.b, Indexer.keyForIndex(1));910 try testing.expectEqual(E.b, Indexer.keyForIndex(1));
911 testing.expectEqual(E.c, Indexer.keyForIndex(2));911 try testing.expectEqual(E.c, Indexer.keyForIndex(2));
912}912}
913913
914test "std.enums.EnumIndexer repeats" {914test "std.enums.EnumIndexer repeats" {
915 const E = extern enum { a = -2, c = 6, b = 4, b2 = 4 };915 const E = extern enum { a = -2, c = 6, b = 4, b2 = 4 };
916 const Indexer = EnumIndexer(E);916 const Indexer = EnumIndexer(E);
917 ensureIndexer(Indexer);917 ensureIndexer(Indexer);
918 testing.expectEqual(E, Indexer.Key);918 try testing.expectEqual(E, Indexer.Key);
919 testing.expectEqual(@as(usize, 3), Indexer.count);919 try testing.expectEqual(@as(usize, 3), Indexer.count);
920920
921 testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));921 try testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
922 testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));922 try testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
923 testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));923 try testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
924924
925 testing.expectEqual(E.a, Indexer.keyForIndex(0));925 try testing.expectEqual(E.a, Indexer.keyForIndex(0));
926 testing.expectEqual(E.b, Indexer.keyForIndex(1));926 try testing.expectEqual(E.b, Indexer.keyForIndex(1));
927 testing.expectEqual(E.c, Indexer.keyForIndex(2));927 try testing.expectEqual(E.c, Indexer.keyForIndex(2));
928}928}
929929
930test "std.enums.EnumSet" {930test "std.enums.EnumSet" {
931 const E = extern enum { a, b, c, d, e = 0 };931 const E = extern enum { a, b, c, d, e = 0 };
932 const Set = EnumSet(E);932 const Set = EnumSet(E);
933 testing.expectEqual(E, Set.Key);933 try testing.expectEqual(E, Set.Key);
934 testing.expectEqual(EnumIndexer(E), Set.Indexer);934 try testing.expectEqual(EnumIndexer(E), Set.Indexer);
935 testing.expectEqual(@as(usize, 4), Set.len);935 try testing.expectEqual(@as(usize, 4), Set.len);
936936
937 // Empty sets937 // Empty sets
938 const empty = Set{};938 const empty = Set{};
939 comptime testing.expect(empty.count() == 0);939 comptime try testing.expect(empty.count() == 0);
940940
941 var empty_b = Set.init(.{});941 var empty_b = Set.init(.{});
942 testing.expect(empty_b.count() == 0);942 try testing.expect(empty_b.count() == 0);
943943
944 const empty_c = comptime Set.init(.{});944 const empty_c = comptime Set.init(.{});
945 comptime testing.expect(empty_c.count() == 0);945 comptime try testing.expect(empty_c.count() == 0);
946946
947 const full = Set.initFull();947 const full = Set.initFull();
948 testing.expect(full.count() == Set.len);948 try testing.expect(full.count() == Set.len);
949949
950 const full_b = comptime Set.initFull();950 const full_b = comptime Set.initFull();
951 comptime testing.expect(full_b.count() == Set.len);951 comptime try testing.expect(full_b.count() == Set.len);
952952
953 testing.expectEqual(false, empty.contains(.a));953 try testing.expectEqual(false, empty.contains(.a));
954 testing.expectEqual(false, empty.contains(.b));954 try testing.expectEqual(false, empty.contains(.b));
955 testing.expectEqual(false, empty.contains(.c));955 try testing.expectEqual(false, empty.contains(.c));
956 testing.expectEqual(false, empty.contains(.d));956 try testing.expectEqual(false, empty.contains(.d));
957 testing.expectEqual(false, empty.contains(.e));957 try testing.expectEqual(false, empty.contains(.e));
958 {958 {
959 var iter = empty_b.iterator();959 var iter = empty_b.iterator();
960 testing.expectEqual(@as(?E, null), iter.next());960 try testing.expectEqual(@as(?E, null), iter.next());
961 }961 }
962962
963 var mut = Set.init(.{963 var mut = Set.init(.{
964 .a = true,964 .a = true,
965 .c = true,965 .c = true,
966 });966 });
967 testing.expectEqual(@as(usize, 2), mut.count());967 try testing.expectEqual(@as(usize, 2), mut.count());
968 testing.expectEqual(true, mut.contains(.a));968 try testing.expectEqual(true, mut.contains(.a));
969 testing.expectEqual(false, mut.contains(.b));969 try testing.expectEqual(false, mut.contains(.b));
970 testing.expectEqual(true, mut.contains(.c));970 try testing.expectEqual(true, mut.contains(.c));
971 testing.expectEqual(false, mut.contains(.d));971 try testing.expectEqual(false, mut.contains(.d));
972 testing.expectEqual(true, mut.contains(.e)); // aliases a972 try testing.expectEqual(true, mut.contains(.e)); // aliases a
973 {973 {
974 var it = mut.iterator();974 var it = mut.iterator();
975 testing.expectEqual(@as(?E, .a), it.next());975 try testing.expectEqual(@as(?E, .a), it.next());
976 testing.expectEqual(@as(?E, .c), it.next());976 try testing.expectEqual(@as(?E, .c), it.next());
977 testing.expectEqual(@as(?E, null), it.next());977 try testing.expectEqual(@as(?E, null), it.next());
978 }978 }
979979
980 mut.toggleAll();980 mut.toggleAll();
981 testing.expectEqual(@as(usize, 2), mut.count());981 try testing.expectEqual(@as(usize, 2), mut.count());
982 testing.expectEqual(false, mut.contains(.a));982 try testing.expectEqual(false, mut.contains(.a));
983 testing.expectEqual(true, mut.contains(.b));983 try testing.expectEqual(true, mut.contains(.b));
984 testing.expectEqual(false, mut.contains(.c));984 try testing.expectEqual(false, mut.contains(.c));
985 testing.expectEqual(true, mut.contains(.d));985 try testing.expectEqual(true, mut.contains(.d));
986 testing.expectEqual(false, mut.contains(.e)); // aliases a986 try testing.expectEqual(false, mut.contains(.e)); // aliases a
987 {987 {
988 var it = mut.iterator();988 var it = mut.iterator();
989 testing.expectEqual(@as(?E, .b), it.next());989 try testing.expectEqual(@as(?E, .b), it.next());
990 testing.expectEqual(@as(?E, .d), it.next());990 try testing.expectEqual(@as(?E, .d), it.next());
991 testing.expectEqual(@as(?E, null), it.next());991 try testing.expectEqual(@as(?E, null), it.next());
992 }992 }
993993
994 mut.toggleSet(Set.init(.{ .a = true, .b = true }));994 mut.toggleSet(Set.init(.{ .a = true, .b = true }));
995 testing.expectEqual(@as(usize, 2), mut.count());995 try testing.expectEqual(@as(usize, 2), mut.count());
996 testing.expectEqual(true, mut.contains(.a));996 try testing.expectEqual(true, mut.contains(.a));
997 testing.expectEqual(false, mut.contains(.b));997 try testing.expectEqual(false, mut.contains(.b));
998 testing.expectEqual(false, mut.contains(.c));998 try testing.expectEqual(false, mut.contains(.c));
999 testing.expectEqual(true, mut.contains(.d));999 try testing.expectEqual(true, mut.contains(.d));
1000 testing.expectEqual(true, mut.contains(.e)); // aliases a1000 try testing.expectEqual(true, mut.contains(.e)); // aliases a
10011001
1002 mut.setUnion(Set.init(.{ .a = true, .b = true }));1002 mut.setUnion(Set.init(.{ .a = true, .b = true }));
1003 testing.expectEqual(@as(usize, 3), mut.count());1003 try testing.expectEqual(@as(usize, 3), mut.count());
1004 testing.expectEqual(true, mut.contains(.a));1004 try testing.expectEqual(true, mut.contains(.a));
1005 testing.expectEqual(true, mut.contains(.b));1005 try testing.expectEqual(true, mut.contains(.b));
1006 testing.expectEqual(false, mut.contains(.c));1006 try testing.expectEqual(false, mut.contains(.c));
1007 testing.expectEqual(true, mut.contains(.d));1007 try testing.expectEqual(true, mut.contains(.d));
10081008
1009 mut.remove(.c);1009 mut.remove(.c);
1010 mut.remove(.b);1010 mut.remove(.b);
1011 testing.expectEqual(@as(usize, 2), mut.count());1011 try testing.expectEqual(@as(usize, 2), mut.count());
1012 testing.expectEqual(true, mut.contains(.a));1012 try testing.expectEqual(true, mut.contains(.a));
1013 testing.expectEqual(false, mut.contains(.b));1013 try testing.expectEqual(false, mut.contains(.b));
1014 testing.expectEqual(false, mut.contains(.c));1014 try testing.expectEqual(false, mut.contains(.c));
1015 testing.expectEqual(true, mut.contains(.d));1015 try testing.expectEqual(true, mut.contains(.d));
10161016
1017 mut.setIntersection(Set.init(.{ .a = true, .b = true }));1017 mut.setIntersection(Set.init(.{ .a = true, .b = true }));
1018 testing.expectEqual(@as(usize, 1), mut.count());1018 try testing.expectEqual(@as(usize, 1), mut.count());
1019 testing.expectEqual(true, mut.contains(.a));1019 try testing.expectEqual(true, mut.contains(.a));
1020 testing.expectEqual(false, mut.contains(.b));1020 try testing.expectEqual(false, mut.contains(.b));
1021 testing.expectEqual(false, mut.contains(.c));1021 try testing.expectEqual(false, mut.contains(.c));
1022 testing.expectEqual(false, mut.contains(.d));1022 try testing.expectEqual(false, mut.contains(.d));
10231023
1024 mut.insert(.a);1024 mut.insert(.a);
1025 mut.insert(.b);1025 mut.insert(.b);
1026 testing.expectEqual(@as(usize, 2), mut.count());1026 try testing.expectEqual(@as(usize, 2), mut.count());
1027 testing.expectEqual(true, mut.contains(.a));1027 try testing.expectEqual(true, mut.contains(.a));
1028 testing.expectEqual(true, mut.contains(.b));1028 try testing.expectEqual(true, mut.contains(.b));
1029 testing.expectEqual(false, mut.contains(.c));1029 try testing.expectEqual(false, mut.contains(.c));
1030 testing.expectEqual(false, mut.contains(.d));1030 try testing.expectEqual(false, mut.contains(.d));
10311031
1032 mut.setPresent(.a, false);1032 mut.setPresent(.a, false);
1033 mut.toggle(.b);1033 mut.toggle(.b);
1034 mut.toggle(.c);1034 mut.toggle(.c);
1035 mut.setPresent(.d, true);1035 mut.setPresent(.d, true);
1036 testing.expectEqual(@as(usize, 2), mut.count());1036 try testing.expectEqual(@as(usize, 2), mut.count());
1037 testing.expectEqual(false, mut.contains(.a));1037 try testing.expectEqual(false, mut.contains(.a));
1038 testing.expectEqual(false, mut.contains(.b));1038 try testing.expectEqual(false, mut.contains(.b));
1039 testing.expectEqual(true, mut.contains(.c));1039 try testing.expectEqual(true, mut.contains(.c));
1040 testing.expectEqual(true, mut.contains(.d));1040 try testing.expectEqual(true, mut.contains(.d));
1041}1041}
10421042
1043test "std.enums.EnumArray void" {1043test "std.enums.EnumArray void" {
1044 const E = extern enum { a, b, c, d, e = 0 };1044 const E = extern enum { a, b, c, d, e = 0 };
1045 const ArrayVoid = EnumArray(E, void);1045 const ArrayVoid = EnumArray(E, void);
1046 testing.expectEqual(E, ArrayVoid.Key);1046 try testing.expectEqual(E, ArrayVoid.Key);
1047 testing.expectEqual(EnumIndexer(E), ArrayVoid.Indexer);1047 try testing.expectEqual(EnumIndexer(E), ArrayVoid.Indexer);
1048 testing.expectEqual(void, ArrayVoid.Value);1048 try testing.expectEqual(void, ArrayVoid.Value);
1049 testing.expectEqual(@as(usize, 4), ArrayVoid.len);1049 try testing.expectEqual(@as(usize, 4), ArrayVoid.len);
10501050
1051 const undef = ArrayVoid.initUndefined();1051 const undef = ArrayVoid.initUndefined();
1052 var inst = ArrayVoid.initFill({});1052 var inst = ArrayVoid.initFill({});
...@@ -1059,113 +1059,113 @@ test "std.enums.EnumArray void" {...@@ -1059,113 +1059,113 @@ test "std.enums.EnumArray void" {
1059 inst.set(.a, {});1059 inst.set(.a, {});
10601060
1061 var it = inst.iterator();1061 var it = inst.iterator();
1062 testing.expectEqual(E.a, it.next().?.key);1062 try testing.expectEqual(E.a, it.next().?.key);
1063 testing.expectEqual(E.b, it.next().?.key);1063 try testing.expectEqual(E.b, it.next().?.key);
1064 testing.expectEqual(E.c, it.next().?.key);1064 try testing.expectEqual(E.c, it.next().?.key);
1065 testing.expectEqual(E.d, it.next().?.key);1065 try testing.expectEqual(E.d, it.next().?.key);
1066 testing.expect(it.next() == null);1066 try testing.expect(it.next() == null);
1067}1067}
10681068
1069test "std.enums.EnumArray sized" {1069test "std.enums.EnumArray sized" {
1070 const E = extern enum { a, b, c, d, e = 0 };1070 const E = extern enum { a, b, c, d, e = 0 };
1071 const Array = EnumArray(E, usize);1071 const Array = EnumArray(E, usize);
1072 testing.expectEqual(E, Array.Key);1072 try testing.expectEqual(E, Array.Key);
1073 testing.expectEqual(EnumIndexer(E), Array.Indexer);1073 try testing.expectEqual(EnumIndexer(E), Array.Indexer);
1074 testing.expectEqual(usize, Array.Value);1074 try testing.expectEqual(usize, Array.Value);
1075 testing.expectEqual(@as(usize, 4), Array.len);1075 try testing.expectEqual(@as(usize, 4), Array.len);
10761076
1077 const undef = Array.initUndefined();1077 const undef = Array.initUndefined();
1078 var inst = Array.initFill(5);1078 var inst = Array.initFill(5);
1079 const inst2 = Array.init(.{ .a = 1, .b = 2, .c = 3, .d = 4 });1079 const inst2 = Array.init(.{ .a = 1, .b = 2, .c = 3, .d = 4 });
1080 const inst3 = Array.initDefault(6, .{ .b = 4, .c = 2 });1080 const inst3 = Array.initDefault(6, .{ .b = 4, .c = 2 });
10811081
1082 testing.expectEqual(@as(usize, 5), inst.get(.a));1082 try testing.expectEqual(@as(usize, 5), inst.get(.a));
1083 testing.expectEqual(@as(usize, 5), inst.get(.b));1083 try testing.expectEqual(@as(usize, 5), inst.get(.b));
1084 testing.expectEqual(@as(usize, 5), inst.get(.c));1084 try testing.expectEqual(@as(usize, 5), inst.get(.c));
1085 testing.expectEqual(@as(usize, 5), inst.get(.d));1085 try testing.expectEqual(@as(usize, 5), inst.get(.d));
10861086
1087 testing.expectEqual(@as(usize, 1), inst2.get(.a));1087 try testing.expectEqual(@as(usize, 1), inst2.get(.a));
1088 testing.expectEqual(@as(usize, 2), inst2.get(.b));1088 try testing.expectEqual(@as(usize, 2), inst2.get(.b));
1089 testing.expectEqual(@as(usize, 3), inst2.get(.c));1089 try testing.expectEqual(@as(usize, 3), inst2.get(.c));
1090 testing.expectEqual(@as(usize, 4), inst2.get(.d));1090 try testing.expectEqual(@as(usize, 4), inst2.get(.d));
10911091
1092 testing.expectEqual(@as(usize, 6), inst3.get(.a));1092 try testing.expectEqual(@as(usize, 6), inst3.get(.a));
1093 testing.expectEqual(@as(usize, 4), inst3.get(.b));1093 try testing.expectEqual(@as(usize, 4), inst3.get(.b));
1094 testing.expectEqual(@as(usize, 2), inst3.get(.c));1094 try testing.expectEqual(@as(usize, 2), inst3.get(.c));
1095 testing.expectEqual(@as(usize, 6), inst3.get(.d));1095 try testing.expectEqual(@as(usize, 6), inst3.get(.d));
10961096
1097 testing.expectEqual(&inst.values[0], inst.getPtr(.a));1097 try testing.expectEqual(&inst.values[0], inst.getPtr(.a));
1098 testing.expectEqual(&inst.values[1], inst.getPtr(.b));1098 try testing.expectEqual(&inst.values[1], inst.getPtr(.b));
1099 testing.expectEqual(&inst.values[2], inst.getPtr(.c));1099 try testing.expectEqual(&inst.values[2], inst.getPtr(.c));
1100 testing.expectEqual(&inst.values[3], inst.getPtr(.d));1100 try testing.expectEqual(&inst.values[3], inst.getPtr(.d));
11011101
1102 testing.expectEqual(@as(*const usize, &inst.values[0]), inst.getPtrConst(.a));1102 try testing.expectEqual(@as(*const usize, &inst.values[0]), inst.getPtrConst(.a));
1103 testing.expectEqual(@as(*const usize, &inst.values[1]), inst.getPtrConst(.b));1103 try testing.expectEqual(@as(*const usize, &inst.values[1]), inst.getPtrConst(.b));
1104 testing.expectEqual(@as(*const usize, &inst.values[2]), inst.getPtrConst(.c));1104 try testing.expectEqual(@as(*const usize, &inst.values[2]), inst.getPtrConst(.c));
1105 testing.expectEqual(@as(*const usize, &inst.values[3]), inst.getPtrConst(.d));1105 try testing.expectEqual(@as(*const usize, &inst.values[3]), inst.getPtrConst(.d));
11061106
1107 inst.set(.c, 8);1107 inst.set(.c, 8);
1108 testing.expectEqual(@as(usize, 5), inst.get(.a));1108 try testing.expectEqual(@as(usize, 5), inst.get(.a));
1109 testing.expectEqual(@as(usize, 5), inst.get(.b));1109 try testing.expectEqual(@as(usize, 5), inst.get(.b));
1110 testing.expectEqual(@as(usize, 8), inst.get(.c));1110 try testing.expectEqual(@as(usize, 8), inst.get(.c));
1111 testing.expectEqual(@as(usize, 5), inst.get(.d));1111 try testing.expectEqual(@as(usize, 5), inst.get(.d));
11121112
1113 var it = inst.iterator();1113 var it = inst.iterator();
1114 const Entry = Array.Entry;1114 const Entry = Array.Entry;
1115 testing.expectEqual(@as(?Entry, Entry{1115 try testing.expectEqual(@as(?Entry, Entry{
1116 .key = .a,1116 .key = .a,
1117 .value = &inst.values[0],1117 .value = &inst.values[0],
1118 }), it.next());1118 }), it.next());
1119 testing.expectEqual(@as(?Entry, Entry{1119 try testing.expectEqual(@as(?Entry, Entry{
1120 .key = .b,1120 .key = .b,
1121 .value = &inst.values[1],1121 .value = &inst.values[1],
1122 }), it.next());1122 }), it.next());
1123 testing.expectEqual(@as(?Entry, Entry{1123 try testing.expectEqual(@as(?Entry, Entry{
1124 .key = .c,1124 .key = .c,
1125 .value = &inst.values[2],1125 .value = &inst.values[2],
1126 }), it.next());1126 }), it.next());
1127 testing.expectEqual(@as(?Entry, Entry{1127 try testing.expectEqual(@as(?Entry, Entry{
1128 .key = .d,1128 .key = .d,
1129 .value = &inst.values[3],1129 .value = &inst.values[3],
1130 }), it.next());1130 }), it.next());
1131 testing.expectEqual(@as(?Entry, null), it.next());1131 try testing.expectEqual(@as(?Entry, null), it.next());
1132}1132}
11331133
1134test "std.enums.EnumMap void" {1134test "std.enums.EnumMap void" {
1135 const E = extern enum { a, b, c, d, e = 0 };1135 const E = extern enum { a, b, c, d, e = 0 };
1136 const Map = EnumMap(E, void);1136 const Map = EnumMap(E, void);
1137 testing.expectEqual(E, Map.Key);1137 try testing.expectEqual(E, Map.Key);
1138 testing.expectEqual(EnumIndexer(E), Map.Indexer);1138 try testing.expectEqual(EnumIndexer(E), Map.Indexer);
1139 testing.expectEqual(void, Map.Value);1139 try testing.expectEqual(void, Map.Value);
1140 testing.expectEqual(@as(usize, 4), Map.len);1140 try testing.expectEqual(@as(usize, 4), Map.len);
11411141
1142 const b = Map.initFull({});1142 const b = Map.initFull({});
1143 testing.expectEqual(@as(usize, 4), b.count());1143 try testing.expectEqual(@as(usize, 4), b.count());
11441144
1145 const c = Map.initFullWith(.{ .a = {}, .b = {}, .c = {}, .d = {} });1145 const c = Map.initFullWith(.{ .a = {}, .b = {}, .c = {}, .d = {} });
1146 testing.expectEqual(@as(usize, 4), c.count());1146 try testing.expectEqual(@as(usize, 4), c.count());
11471147
1148 const d = Map.initFullWithDefault({}, .{ .b = {} });1148 const d = Map.initFullWithDefault({}, .{ .b = {} });
1149 testing.expectEqual(@as(usize, 4), d.count());1149 try testing.expectEqual(@as(usize, 4), d.count());
11501150
1151 var a = Map.init(.{ .b = {}, .d = {} });1151 var a = Map.init(.{ .b = {}, .d = {} });
1152 testing.expectEqual(@as(usize, 2), a.count());1152 try testing.expectEqual(@as(usize, 2), a.count());
1153 testing.expectEqual(false, a.contains(.a));1153 try testing.expectEqual(false, a.contains(.a));
1154 testing.expectEqual(true, a.contains(.b));1154 try testing.expectEqual(true, a.contains(.b));
1155 testing.expectEqual(false, a.contains(.c));1155 try testing.expectEqual(false, a.contains(.c));
1156 testing.expectEqual(true, a.contains(.d));1156 try testing.expectEqual(true, a.contains(.d));
1157 testing.expect(a.get(.a) == null);1157 try testing.expect(a.get(.a) == null);
1158 testing.expect(a.get(.b) != null);1158 try testing.expect(a.get(.b) != null);
1159 testing.expect(a.get(.c) == null);1159 try testing.expect(a.get(.c) == null);
1160 testing.expect(a.get(.d) != null);1160 try testing.expect(a.get(.d) != null);
1161 testing.expect(a.getPtr(.a) == null);1161 try testing.expect(a.getPtr(.a) == null);
1162 testing.expect(a.getPtr(.b) != null);1162 try testing.expect(a.getPtr(.b) != null);
1163 testing.expect(a.getPtr(.c) == null);1163 try testing.expect(a.getPtr(.c) == null);
1164 testing.expect(a.getPtr(.d) != null);1164 try testing.expect(a.getPtr(.d) != null);
1165 testing.expect(a.getPtrConst(.a) == null);1165 try testing.expect(a.getPtrConst(.a) == null);
1166 testing.expect(a.getPtrConst(.b) != null);1166 try testing.expect(a.getPtrConst(.b) != null);
1167 testing.expect(a.getPtrConst(.c) == null);1167 try testing.expect(a.getPtrConst(.c) == null);
1168 testing.expect(a.getPtrConst(.d) != null);1168 try testing.expect(a.getPtrConst(.d) != null);
1169 _ = a.getPtrAssertContains(.b);1169 _ = a.getPtrAssertContains(.b);
1170 _ = a.getAssertContains(.d);1170 _ = a.getAssertContains(.d);
11711171
...@@ -1174,115 +1174,115 @@ test "std.enums.EnumMap void" {...@@ -1174,115 +1174,115 @@ test "std.enums.EnumMap void" {
1174 a.putUninitialized(.c).* = {};1174 a.putUninitialized(.c).* = {};
1175 a.putUninitialized(.c).* = {};1175 a.putUninitialized(.c).* = {};
11761176
1177 testing.expectEqual(@as(usize, 4), a.count());1177 try testing.expectEqual(@as(usize, 4), a.count());
1178 testing.expect(a.get(.a) != null);1178 try testing.expect(a.get(.a) != null);
1179 testing.expect(a.get(.b) != null);1179 try testing.expect(a.get(.b) != null);
1180 testing.expect(a.get(.c) != null);1180 try testing.expect(a.get(.c) != null);
1181 testing.expect(a.get(.d) != null);1181 try testing.expect(a.get(.d) != null);
11821182
1183 a.remove(.a);1183 a.remove(.a);
1184 _ = a.fetchRemove(.c);1184 _ = a.fetchRemove(.c);
11851185
1186 var iter = a.iterator();1186 var iter = a.iterator();
1187 const Entry = Map.Entry;1187 const Entry = Map.Entry;
1188 testing.expectEqual(E.b, iter.next().?.key);1188 try testing.expectEqual(E.b, iter.next().?.key);
1189 testing.expectEqual(E.d, iter.next().?.key);1189 try testing.expectEqual(E.d, iter.next().?.key);
1190 testing.expect(iter.next() == null);1190 try testing.expect(iter.next() == null);
1191}1191}
11921192
1193test "std.enums.EnumMap sized" {1193test "std.enums.EnumMap sized" {
1194 const E = extern enum { a, b, c, d, e = 0 };1194 const E = extern enum { a, b, c, d, e = 0 };
1195 const Map = EnumMap(E, usize);1195 const Map = EnumMap(E, usize);
1196 testing.expectEqual(E, Map.Key);1196 try testing.expectEqual(E, Map.Key);
1197 testing.expectEqual(EnumIndexer(E), Map.Indexer);1197 try testing.expectEqual(EnumIndexer(E), Map.Indexer);
1198 testing.expectEqual(usize, Map.Value);1198 try testing.expectEqual(usize, Map.Value);
1199 testing.expectEqual(@as(usize, 4), Map.len);1199 try testing.expectEqual(@as(usize, 4), Map.len);
12001200
1201 const b = Map.initFull(5);1201 const b = Map.initFull(5);
1202 testing.expectEqual(@as(usize, 4), b.count());1202 try testing.expectEqual(@as(usize, 4), b.count());
1203 testing.expect(b.contains(.a));1203 try testing.expect(b.contains(.a));
1204 testing.expect(b.contains(.b));1204 try testing.expect(b.contains(.b));
1205 testing.expect(b.contains(.c));1205 try testing.expect(b.contains(.c));
1206 testing.expect(b.contains(.d));1206 try testing.expect(b.contains(.d));
1207 testing.expectEqual(@as(?usize, 5), b.get(.a));1207 try testing.expectEqual(@as(?usize, 5), b.get(.a));
1208 testing.expectEqual(@as(?usize, 5), b.get(.b));1208 try testing.expectEqual(@as(?usize, 5), b.get(.b));
1209 testing.expectEqual(@as(?usize, 5), b.get(.c));1209 try testing.expectEqual(@as(?usize, 5), b.get(.c));
1210 testing.expectEqual(@as(?usize, 5), b.get(.d));1210 try testing.expectEqual(@as(?usize, 5), b.get(.d));
12111211
1212 const c = Map.initFullWith(.{ .a = 1, .b = 2, .c = 3, .d = 4 });1212 const c = Map.initFullWith(.{ .a = 1, .b = 2, .c = 3, .d = 4 });
1213 testing.expectEqual(@as(usize, 4), c.count());1213 try testing.expectEqual(@as(usize, 4), c.count());
1214 testing.expect(c.contains(.a));1214 try testing.expect(c.contains(.a));
1215 testing.expect(c.contains(.b));1215 try testing.expect(c.contains(.b));
1216 testing.expect(c.contains(.c));1216 try testing.expect(c.contains(.c));
1217 testing.expect(c.contains(.d));1217 try testing.expect(c.contains(.d));
1218 testing.expectEqual(@as(?usize, 1), c.get(.a));1218 try testing.expectEqual(@as(?usize, 1), c.get(.a));
1219 testing.expectEqual(@as(?usize, 2), c.get(.b));1219 try testing.expectEqual(@as(?usize, 2), c.get(.b));
1220 testing.expectEqual(@as(?usize, 3), c.get(.c));1220 try testing.expectEqual(@as(?usize, 3), c.get(.c));
1221 testing.expectEqual(@as(?usize, 4), c.get(.d));1221 try testing.expectEqual(@as(?usize, 4), c.get(.d));
12221222
1223 const d = Map.initFullWithDefault(6, .{ .b = 2, .c = 4 });1223 const d = Map.initFullWithDefault(6, .{ .b = 2, .c = 4 });
1224 testing.expectEqual(@as(usize, 4), d.count());1224 try testing.expectEqual(@as(usize, 4), d.count());
1225 testing.expect(d.contains(.a));1225 try testing.expect(d.contains(.a));
1226 testing.expect(d.contains(.b));1226 try testing.expect(d.contains(.b));
1227 testing.expect(d.contains(.c));1227 try testing.expect(d.contains(.c));
1228 testing.expect(d.contains(.d));1228 try testing.expect(d.contains(.d));
1229 testing.expectEqual(@as(?usize, 6), d.get(.a));1229 try testing.expectEqual(@as(?usize, 6), d.get(.a));
1230 testing.expectEqual(@as(?usize, 2), d.get(.b));1230 try testing.expectEqual(@as(?usize, 2), d.get(.b));
1231 testing.expectEqual(@as(?usize, 4), d.get(.c));1231 try testing.expectEqual(@as(?usize, 4), d.get(.c));
1232 testing.expectEqual(@as(?usize, 6), d.get(.d));1232 try testing.expectEqual(@as(?usize, 6), d.get(.d));
12331233
1234 var a = Map.init(.{ .b = 2, .d = 4 });1234 var a = Map.init(.{ .b = 2, .d = 4 });
1235 testing.expectEqual(@as(usize, 2), a.count());1235 try testing.expectEqual(@as(usize, 2), a.count());
1236 testing.expectEqual(false, a.contains(.a));1236 try testing.expectEqual(false, a.contains(.a));
1237 testing.expectEqual(true, a.contains(.b));1237 try testing.expectEqual(true, a.contains(.b));
1238 testing.expectEqual(false, a.contains(.c));1238 try testing.expectEqual(false, a.contains(.c));
1239 testing.expectEqual(true, a.contains(.d));1239 try testing.expectEqual(true, a.contains(.d));
12401240
1241 testing.expectEqual(@as(?usize, null), a.get(.a));1241 try testing.expectEqual(@as(?usize, null), a.get(.a));
1242 testing.expectEqual(@as(?usize, 2), a.get(.b));1242 try testing.expectEqual(@as(?usize, 2), a.get(.b));
1243 testing.expectEqual(@as(?usize, null), a.get(.c));1243 try testing.expectEqual(@as(?usize, null), a.get(.c));
1244 testing.expectEqual(@as(?usize, 4), a.get(.d));1244 try testing.expectEqual(@as(?usize, 4), a.get(.d));
12451245
1246 testing.expectEqual(@as(?*usize, null), a.getPtr(.a));1246 try testing.expectEqual(@as(?*usize, null), a.getPtr(.a));
1247 testing.expectEqual(@as(?*usize, &a.values[1]), a.getPtr(.b));1247 try testing.expectEqual(@as(?*usize, &a.values[1]), a.getPtr(.b));
1248 testing.expectEqual(@as(?*usize, null), a.getPtr(.c));1248 try testing.expectEqual(@as(?*usize, null), a.getPtr(.c));
1249 testing.expectEqual(@as(?*usize, &a.values[3]), a.getPtr(.d));1249 try testing.expectEqual(@as(?*usize, &a.values[3]), a.getPtr(.d));
12501250
1251 testing.expectEqual(@as(?*const usize, null), a.getPtrConst(.a));1251 try testing.expectEqual(@as(?*const usize, null), a.getPtrConst(.a));
1252 testing.expectEqual(@as(?*const usize, &a.values[1]), a.getPtrConst(.b));1252 try testing.expectEqual(@as(?*const usize, &a.values[1]), a.getPtrConst(.b));
1253 testing.expectEqual(@as(?*const usize, null), a.getPtrConst(.c));1253 try testing.expectEqual(@as(?*const usize, null), a.getPtrConst(.c));
1254 testing.expectEqual(@as(?*const usize, &a.values[3]), a.getPtrConst(.d));1254 try testing.expectEqual(@as(?*const usize, &a.values[3]), a.getPtrConst(.d));
12551255
1256 testing.expectEqual(@as(*const usize, &a.values[1]), a.getPtrAssertContains(.b));1256 try testing.expectEqual(@as(*const usize, &a.values[1]), a.getPtrAssertContains(.b));
1257 testing.expectEqual(@as(*const usize, &a.values[3]), a.getPtrAssertContains(.d));1257 try testing.expectEqual(@as(*const usize, &a.values[3]), a.getPtrAssertContains(.d));
1258 testing.expectEqual(@as(usize, 2), a.getAssertContains(.b));1258 try testing.expectEqual(@as(usize, 2), a.getAssertContains(.b));
1259 testing.expectEqual(@as(usize, 4), a.getAssertContains(.d));1259 try testing.expectEqual(@as(usize, 4), a.getAssertContains(.d));
12601260
1261 a.put(.a, 3);1261 a.put(.a, 3);
1262 a.put(.a, 5);1262 a.put(.a, 5);
1263 a.putUninitialized(.c).* = 7;1263 a.putUninitialized(.c).* = 7;
1264 a.putUninitialized(.c).* = 9;1264 a.putUninitialized(.c).* = 9;
12651265
1266 testing.expectEqual(@as(usize, 4), a.count());1266 try testing.expectEqual(@as(usize, 4), a.count());
1267 testing.expectEqual(@as(?usize, 5), a.get(.a));1267 try testing.expectEqual(@as(?usize, 5), a.get(.a));
1268 testing.expectEqual(@as(?usize, 2), a.get(.b));1268 try testing.expectEqual(@as(?usize, 2), a.get(.b));
1269 testing.expectEqual(@as(?usize, 9), a.get(.c));1269 try testing.expectEqual(@as(?usize, 9), a.get(.c));
1270 testing.expectEqual(@as(?usize, 4), a.get(.d));1270 try testing.expectEqual(@as(?usize, 4), a.get(.d));
12711271
1272 a.remove(.a);1272 a.remove(.a);
1273 testing.expectEqual(@as(?usize, null), a.fetchRemove(.a));1273 try testing.expectEqual(@as(?usize, null), a.fetchRemove(.a));
1274 testing.expectEqual(@as(?usize, 9), a.fetchRemove(.c));1274 try testing.expectEqual(@as(?usize, 9), a.fetchRemove(.c));
1275 a.remove(.c);1275 a.remove(.c);
12761276
1277 var iter = a.iterator();1277 var iter = a.iterator();
1278 const Entry = Map.Entry;1278 const Entry = Map.Entry;
1279 testing.expectEqual(@as(?Entry, Entry{1279 try testing.expectEqual(@as(?Entry, Entry{
1280 .key = .b,1280 .key = .b,
1281 .value = &a.values[1],1281 .value = &a.values[1],
1282 }), iter.next());1282 }), iter.next());
1283 testing.expectEqual(@as(?Entry, Entry{1283 try testing.expectEqual(@as(?Entry, Entry{
1284 .key = .d,1284 .key = .d,
1285 .value = &a.values[3],1285 .value = &a.values[3],
1286 }), iter.next());1286 }), iter.next());
1287 testing.expectEqual(@as(?Entry, null), iter.next());1287 try testing.expectEqual(@as(?Entry, null), iter.next());
1288}1288}
lib/std/event/batch.zig+2-2
...@@ -119,12 +119,12 @@ test "std.event.Batch" {...@@ -119,12 +119,12 @@ test "std.event.Batch" {
119 batch.add(&async sleepALittle(&count));119 batch.add(&async sleepALittle(&count));
120 batch.add(&async increaseByTen(&count));120 batch.add(&async increaseByTen(&count));
121 batch.wait();121 batch.wait();
122 testing.expect(count == 11);122 try testing.expect(count == 11);
123123
124 var another = Batch(anyerror!void, 2, .auto_async).init();124 var another = Batch(anyerror!void, 2, .auto_async).init();
125 another.add(&async somethingElse());125 another.add(&async somethingElse());
126 another.add(&async doSomethingThatFails());126 another.add(&async doSomethingThatFails());
127 testing.expectError(error.ItBroke, another.wait());127 try testing.expectError(error.ItBroke, another.wait());
128}128}
129129
130fn sleepALittle(count: *usize) void {130fn sleepALittle(count: *usize) void {
lib/std/event/channel.zig+7-7
...@@ -310,25 +310,25 @@ test "std.event.Channel wraparound" {...@@ -310,25 +310,25 @@ test "std.event.Channel wraparound" {
310 // the buffer wraps around, make sure it doesn't crash.310 // the buffer wraps around, make sure it doesn't crash.
311 var result: i32 = undefined;311 var result: i32 = undefined;
312 channel.put(5);312 channel.put(5);
313 testing.expectEqual(@as(i32, 5), channel.get());313 try testing.expectEqual(@as(i32, 5), channel.get());
314 channel.put(6);314 channel.put(6);
315 testing.expectEqual(@as(i32, 6), channel.get());315 try testing.expectEqual(@as(i32, 6), channel.get());
316 channel.put(7);316 channel.put(7);
317 testing.expectEqual(@as(i32, 7), channel.get());317 try testing.expectEqual(@as(i32, 7), channel.get());
318}318}
319fn testChannelGetter(channel: *Channel(i32)) callconv(.Async) void {319fn testChannelGetter(channel: *Channel(i32)) callconv(.Async) void {
320 const value1 = channel.get();320 const value1 = channel.get();
321 testing.expect(value1 == 1234);321 try testing.expect(value1 == 1234);
322322
323 const value2 = channel.get();323 const value2 = channel.get();
324 testing.expect(value2 == 4567);324 try testing.expect(value2 == 4567);
325325
326 const value3 = channel.getOrNull();326 const value3 = channel.getOrNull();
327 testing.expect(value3 == null);327 try testing.expect(value3 == null);
328328
329 var last_put = async testPut(channel, 4444);329 var last_put = async testPut(channel, 4444);
330 const value4 = channel.getOrNull();330 const value4 = channel.getOrNull();
331 testing.expect(value4.? == 4444);331 try testing.expect(value4.? == 4444);
332 await last_put;332 await last_put;
333}333}
334fn testChannelPutter(channel: *Channel(i32)) callconv(.Async) void {334fn testChannelPutter(channel: *Channel(i32)) callconv(.Async) void {
lib/std/event/future.zig+1-1
...@@ -107,7 +107,7 @@ fn testFuture() void {...@@ -107,7 +107,7 @@ fn testFuture() void {
107107
108 const result = (await a) + (await b);108 const result = (await a) + (await b);
109109
110 testing.expect(result == 12);110 try testing.expect(result == 12);
111}111}
112112
113fn waitOnFuture(future: *Future(i32)) i32 {113fn waitOnFuture(future: *Future(i32)) i32 {
lib/std/event/group.zig+2-2
...@@ -140,14 +140,14 @@ fn testGroup(allocator: *Allocator) callconv(.Async) void {...@@ -140,14 +140,14 @@ fn testGroup(allocator: *Allocator) callconv(.Async) void {
140 var increase_by_ten_frame = async increaseByTen(&count);140 var increase_by_ten_frame = async increaseByTen(&count);
141 group.add(&increase_by_ten_frame) catch @panic("memory");141 group.add(&increase_by_ten_frame) catch @panic("memory");
142 group.wait();142 group.wait();
143 testing.expect(count == 11);143 try testing.expect(count == 11);
144144
145 var another = Group(anyerror!void).init(allocator);145 var another = Group(anyerror!void).init(allocator);
146 var something_else_frame = async somethingElse();146 var something_else_frame = async somethingElse();
147 another.add(&something_else_frame) catch @panic("memory");147 another.add(&something_else_frame) catch @panic("memory");
148 var something_that_fails_frame = async doSomethingThatFails();148 var something_that_fails_frame = async doSomethingThatFails();
149 another.add(&something_that_fails_frame) catch @panic("memory");149 another.add(&something_that_fails_frame) catch @panic("memory");
150 testing.expectError(error.ItBroke, another.wait());150 try testing.expectError(error.ItBroke, another.wait());
151}151}
152fn sleepALittle(count: *usize) callconv(.Async) void {152fn sleepALittle(count: *usize) callconv(.Async) void {
153 std.time.sleep(1 * std.time.ns_per_ms);153 std.time.sleep(1 * std.time.ns_per_ms);
lib/std/event/lock.zig+1-1
...@@ -136,7 +136,7 @@ test "std.event.Lock" {...@@ -136,7 +136,7 @@ test "std.event.Lock" {
136 testLock(&lock);136 testLock(&lock);
137137
138 const expected_result = [1]i32{3 * @intCast(i32, shared_test_data.len)} ** shared_test_data.len;138 const expected_result = [1]i32{3 * @intCast(i32, shared_test_data.len)} ** shared_test_data.len;
139 testing.expectEqualSlices(i32, &expected_result, &shared_test_data);139 try testing.expectEqualSlices(i32, &expected_result, &shared_test_data);
140}140}
141fn testLock(lock: *Lock) void {141fn testLock(lock: *Lock) void {
142 var handle1 = async lockRunner(lock);142 var handle1 = async lockRunner(lock);
lib/std/event/loop.zig+3-3
...@@ -1655,7 +1655,7 @@ fn testEventLoop() i32 {...@@ -1655,7 +1655,7 @@ fn testEventLoop() i32 {
16551655
1656fn testEventLoop2(h: anyframe->i32, did_it: *bool) void {1656fn testEventLoop2(h: anyframe->i32, did_it: *bool) void {
1657 const value = await h;1657 const value = await h;
1658 testing.expect(value == 1234);1658 try testing.expect(value == 1234);
1659 did_it.* = true;1659 did_it.* = true;
1660}1660}
16611661
...@@ -1682,7 +1682,7 @@ test "std.event.Loop - runDetached" {...@@ -1682,7 +1682,7 @@ test "std.event.Loop - runDetached" {
1682 // with the previous runDetached.1682 // with the previous runDetached.
1683 loop.run();1683 loop.run();
16841684
1685 testing.expect(testRunDetachedData == 1);1685 try testing.expect(testRunDetachedData == 1);
1686}1686}
16871687
1688fn testRunDetached() void {1688fn testRunDetached() void {
...@@ -1705,7 +1705,7 @@ test "std.event.Loop - sleep" {...@@ -1705,7 +1705,7 @@ test "std.event.Loop - sleep" {
1705 for (frames) |*frame|1705 for (frames) |*frame|
1706 await frame;1706 await frame;
17071707
1708 testing.expect(sleep_count == frames.len);1708 try testing.expect(sleep_count == frames.len);
1709}1709}
17101710
1711fn testSleep(wait_ns: u64, sleep_count: *usize) void {1711fn testSleep(wait_ns: u64, sleep_count: *usize) void {
lib/std/event/rwlock.zig+3-3
...@@ -228,7 +228,7 @@ test "std.event.RwLock" {...@@ -228,7 +228,7 @@ test "std.event.RwLock" {
228 const handle = testLock(std.heap.page_allocator, &lock);228 const handle = testLock(std.heap.page_allocator, &lock);
229229
230 const expected_result = [1]i32{shared_it_count * @intCast(i32, shared_test_data.len)} ** shared_test_data.len;230 const expected_result = [1]i32{shared_it_count * @intCast(i32, shared_test_data.len)} ** shared_test_data.len;
231 testing.expectEqualSlices(i32, expected_result, shared_test_data);231 try testing.expectEqualSlices(i32, expected_result, shared_test_data);
232}232}
233fn testLock(allocator: *Allocator, lock: *RwLock) callconv(.Async) void {233fn testLock(allocator: *Allocator, lock: *RwLock) callconv(.Async) void {
234 var read_nodes: [100]Loop.NextTickNode = undefined;234 var read_nodes: [100]Loop.NextTickNode = undefined;
...@@ -290,7 +290,7 @@ fn readRunner(lock: *RwLock) callconv(.Async) void {...@@ -290,7 +290,7 @@ fn readRunner(lock: *RwLock) callconv(.Async) void {
290 const handle = await lock_promise;290 const handle = await lock_promise;
291 defer handle.release();291 defer handle.release();
292292
293 testing.expect(shared_test_index == 0);293 try testing.expect(shared_test_index == 0);
294 testing.expect(shared_test_data[i] == @intCast(i32, shared_count));294 try testing.expect(shared_test_data[i] == @intCast(i32, shared_count));
295 }295 }
296}296}
lib/std/fifo.zig+38-38
...@@ -402,59 +402,59 @@ test "LinearFifo(u8, .Dynamic)" {...@@ -402,59 +402,59 @@ test "LinearFifo(u8, .Dynamic)" {
402 defer fifo.deinit();402 defer fifo.deinit();
403403
404 try fifo.write("HELLO");404 try fifo.write("HELLO");
405 testing.expectEqual(@as(usize, 5), fifo.readableLength());405 try testing.expectEqual(@as(usize, 5), fifo.readableLength());
406 testing.expectEqualSlices(u8, "HELLO", fifo.readableSlice(0));406 try testing.expectEqualSlices(u8, "HELLO", fifo.readableSlice(0));
407407
408 {408 {
409 var i: usize = 0;409 var i: usize = 0;
410 while (i < 5) : (i += 1) {410 while (i < 5) : (i += 1) {
411 try fifo.write(&[_]u8{fifo.peekItem(i)});411 try fifo.write(&[_]u8{fifo.peekItem(i)});
412 }412 }
413 testing.expectEqual(@as(usize, 10), fifo.readableLength());413 try testing.expectEqual(@as(usize, 10), fifo.readableLength());
414 testing.expectEqualSlices(u8, "HELLOHELLO", fifo.readableSlice(0));414 try testing.expectEqualSlices(u8, "HELLOHELLO", fifo.readableSlice(0));
415 }415 }
416416
417 {417 {
418 testing.expectEqual(@as(u8, 'H'), fifo.readItem().?);418 try testing.expectEqual(@as(u8, 'H'), fifo.readItem().?);
419 testing.expectEqual(@as(u8, 'E'), fifo.readItem().?);419 try testing.expectEqual(@as(u8, 'E'), fifo.readItem().?);
420 testing.expectEqual(@as(u8, 'L'), fifo.readItem().?);420 try testing.expectEqual(@as(u8, 'L'), fifo.readItem().?);
421 testing.expectEqual(@as(u8, 'L'), fifo.readItem().?);421 try testing.expectEqual(@as(u8, 'L'), fifo.readItem().?);
422 testing.expectEqual(@as(u8, 'O'), fifo.readItem().?);422 try testing.expectEqual(@as(u8, 'O'), fifo.readItem().?);
423 }423 }
424 testing.expectEqual(@as(usize, 5), fifo.readableLength());424 try testing.expectEqual(@as(usize, 5), fifo.readableLength());
425425
426 { // Writes that wrap around426 { // Writes that wrap around
427 testing.expectEqual(@as(usize, 11), fifo.writableLength());427 try testing.expectEqual(@as(usize, 11), fifo.writableLength());
428 testing.expectEqual(@as(usize, 6), fifo.writableSlice(0).len);428 try testing.expectEqual(@as(usize, 6), fifo.writableSlice(0).len);
429 fifo.writeAssumeCapacity("6<chars<11");429 fifo.writeAssumeCapacity("6<chars<11");
430 testing.expectEqualSlices(u8, "HELLO6<char", fifo.readableSlice(0));430 try testing.expectEqualSlices(u8, "HELLO6<char", fifo.readableSlice(0));
431 testing.expectEqualSlices(u8, "s<11", fifo.readableSlice(11));431 try testing.expectEqualSlices(u8, "s<11", fifo.readableSlice(11));
432 testing.expectEqualSlices(u8, "11", fifo.readableSlice(13));432 try testing.expectEqualSlices(u8, "11", fifo.readableSlice(13));
433 testing.expectEqualSlices(u8, "", fifo.readableSlice(15));433 try testing.expectEqualSlices(u8, "", fifo.readableSlice(15));
434 fifo.discard(11);434 fifo.discard(11);
435 testing.expectEqualSlices(u8, "s<11", fifo.readableSlice(0));435 try testing.expectEqualSlices(u8, "s<11", fifo.readableSlice(0));
436 fifo.discard(4);436 fifo.discard(4);
437 testing.expectEqual(@as(usize, 0), fifo.readableLength());437 try testing.expectEqual(@as(usize, 0), fifo.readableLength());
438 }438 }
439439
440 {440 {
441 const buf = try fifo.writableWithSize(12);441 const buf = try fifo.writableWithSize(12);
442 testing.expectEqual(@as(usize, 12), buf.len);442 try testing.expectEqual(@as(usize, 12), buf.len);
443 var i: u8 = 0;443 var i: u8 = 0;
444 while (i < 10) : (i += 1) {444 while (i < 10) : (i += 1) {
445 buf[i] = i + 'a';445 buf[i] = i + 'a';
446 }446 }
447 fifo.update(10);447 fifo.update(10);
448 testing.expectEqualSlices(u8, "abcdefghij", fifo.readableSlice(0));448 try testing.expectEqualSlices(u8, "abcdefghij", fifo.readableSlice(0));
449 }449 }
450450
451 {451 {
452 try fifo.unget("prependedstring");452 try fifo.unget("prependedstring");
453 var result: [30]u8 = undefined;453 var result: [30]u8 = undefined;
454 testing.expectEqualSlices(u8, "prependedstringabcdefghij", result[0..fifo.read(&result)]);454 try testing.expectEqualSlices(u8, "prependedstringabcdefghij", result[0..fifo.read(&result)]);
455 try fifo.unget("b");455 try fifo.unget("b");
456 try fifo.unget("a");456 try fifo.unget("a");
457 testing.expectEqualSlices(u8, "ab", result[0..fifo.read(&result)]);457 try testing.expectEqualSlices(u8, "ab", result[0..fifo.read(&result)]);
458 }458 }
459459
460 fifo.shrink(0);460 fifo.shrink(0);
...@@ -462,17 +462,17 @@ test "LinearFifo(u8, .Dynamic)" {...@@ -462,17 +462,17 @@ test "LinearFifo(u8, .Dynamic)" {
462 {462 {
463 try fifo.writer().print("{s}, {s}!", .{ "Hello", "World" });463 try fifo.writer().print("{s}, {s}!", .{ "Hello", "World" });
464 var result: [30]u8 = undefined;464 var result: [30]u8 = undefined;
465 testing.expectEqualSlices(u8, "Hello, World!", result[0..fifo.read(&result)]);465 try testing.expectEqualSlices(u8, "Hello, World!", result[0..fifo.read(&result)]);
466 testing.expectEqual(@as(usize, 0), fifo.readableLength());466 try testing.expectEqual(@as(usize, 0), fifo.readableLength());
467 }467 }
468468
469 {469 {
470 try fifo.writer().writeAll("This is a test");470 try fifo.writer().writeAll("This is a test");
471 var result: [30]u8 = undefined;471 var result: [30]u8 = undefined;
472 testing.expectEqualSlices(u8, "This", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?);472 try testing.expectEqualSlices(u8, "This", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?);
473 testing.expectEqualSlices(u8, "is", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?);473 try testing.expectEqualSlices(u8, "is", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?);
474 testing.expectEqualSlices(u8, "a", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?);474 try testing.expectEqualSlices(u8, "a", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?);
475 testing.expectEqualSlices(u8, "test", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?);475 try testing.expectEqualSlices(u8, "test", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?);
476 }476 }
477477
478 {478 {
...@@ -481,7 +481,7 @@ test "LinearFifo(u8, .Dynamic)" {...@@ -481,7 +481,7 @@ test "LinearFifo(u8, .Dynamic)" {
481 var out_buf: [50]u8 = undefined;481 var out_buf: [50]u8 = undefined;
482 var out_fbs = std.io.fixedBufferStream(&out_buf);482 var out_fbs = std.io.fixedBufferStream(&out_buf);
483 try fifo.pump(in_fbs.reader(), out_fbs.writer());483 try fifo.pump(in_fbs.reader(), out_fbs.writer());
484 testing.expectEqualSlices(u8, in_fbs.buffer, out_fbs.getWritten());484 try testing.expectEqualSlices(u8, in_fbs.buffer, out_fbs.getWritten());
485 }485 }
486}486}
487487
...@@ -498,28 +498,28 @@ test "LinearFifo" {...@@ -498,28 +498,28 @@ test "LinearFifo" {
498 defer fifo.deinit();498 defer fifo.deinit();
499499
500 try fifo.write(&[_]T{ 0, 1, 1, 0, 1 });500 try fifo.write(&[_]T{ 0, 1, 1, 0, 1 });
501 testing.expectEqual(@as(usize, 5), fifo.readableLength());501 try testing.expectEqual(@as(usize, 5), fifo.readableLength());
502502
503 {503 {
504 testing.expectEqual(@as(T, 0), fifo.readItem().?);504 try testing.expectEqual(@as(T, 0), fifo.readItem().?);
505 testing.expectEqual(@as(T, 1), fifo.readItem().?);505 try testing.expectEqual(@as(T, 1), fifo.readItem().?);
506 testing.expectEqual(@as(T, 1), fifo.readItem().?);506 try testing.expectEqual(@as(T, 1), fifo.readItem().?);
507 testing.expectEqual(@as(T, 0), fifo.readItem().?);507 try testing.expectEqual(@as(T, 0), fifo.readItem().?);
508 testing.expectEqual(@as(T, 1), fifo.readItem().?);508 try testing.expectEqual(@as(T, 1), fifo.readItem().?);
509 testing.expectEqual(@as(usize, 0), fifo.readableLength());509 try testing.expectEqual(@as(usize, 0), fifo.readableLength());
510 }510 }
511511
512 {512 {
513 try fifo.writeItem(1);513 try fifo.writeItem(1);
514 try fifo.writeItem(1);514 try fifo.writeItem(1);
515 try fifo.writeItem(1);515 try fifo.writeItem(1);
516 testing.expectEqual(@as(usize, 3), fifo.readableLength());516 try testing.expectEqual(@as(usize, 3), fifo.readableLength());
517 }517 }
518518
519 {519 {
520 var readBuf: [3]T = undefined;520 var readBuf: [3]T = undefined;
521 const n = fifo.read(&readBuf);521 const n = fifo.read(&readBuf);
522 testing.expectEqual(@as(usize, 3), n); // NOTE: It should be the number of items.522 try testing.expectEqual(@as(usize, 3), n); // NOTE: It should be the number of items.
523 }523 }
524 }524 }
525 }525 }
lib/std/fmt.zig+77-77
...@@ -1422,7 +1422,7 @@ test "fmtDuration" {...@@ -1422,7 +1422,7 @@ test "fmtDuration" {
1422 .{ .s = "1y1m999ns", .d = 365 * std.time.ns_per_day + std.time.ns_per_min + 999 },1422 .{ .s = "1y1m999ns", .d = 365 * std.time.ns_per_day + std.time.ns_per_min + 999 },
1423 }) |tc| {1423 }) |tc| {
1424 const slice = try bufPrint(&buf, "{}", .{fmtDuration(tc.d)});1424 const slice = try bufPrint(&buf, "{}", .{fmtDuration(tc.d)});
1425 std.testing.expectEqualStrings(tc.s, slice);1425 try std.testing.expectEqualStrings(tc.s, slice);
1426 }1426 }
1427}1427}
14281428
...@@ -1478,44 +1478,44 @@ pub fn parseInt(comptime T: type, buf: []const u8, radix: u8) ParseIntError!T {...@@ -1478,44 +1478,44 @@ pub fn parseInt(comptime T: type, buf: []const u8, radix: u8) ParseIntError!T {
1478}1478}
14791479
1480test "parseInt" {1480test "parseInt" {
1481 std.testing.expect((try parseInt(i32, "-10", 10)) == -10);1481 try std.testing.expect((try parseInt(i32, "-10", 10)) == -10);
1482 std.testing.expect((try parseInt(i32, "+10", 10)) == 10);1482 try std.testing.expect((try parseInt(i32, "+10", 10)) == 10);
1483 std.testing.expect((try parseInt(u32, "+10", 10)) == 10);1483 try std.testing.expect((try parseInt(u32, "+10", 10)) == 10);
1484 std.testing.expectError(error.Overflow, parseInt(u32, "-10", 10));1484 try std.testing.expectError(error.Overflow, parseInt(u32, "-10", 10));
1485 std.testing.expectError(error.InvalidCharacter, parseInt(u32, " 10", 10));1485 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, " 10", 10));
1486 std.testing.expectError(error.InvalidCharacter, parseInt(u32, "10 ", 10));1486 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "10 ", 10));
1487 std.testing.expect((try parseInt(u8, "255", 10)) == 255);1487 try std.testing.expect((try parseInt(u8, "255", 10)) == 255);
1488 std.testing.expectError(error.Overflow, parseInt(u8, "256", 10));1488 try std.testing.expectError(error.Overflow, parseInt(u8, "256", 10));
14891489
1490 // +0 and -0 should work for unsigned1490 // +0 and -0 should work for unsigned
1491 std.testing.expect((try parseInt(u8, "-0", 10)) == 0);1491 try std.testing.expect((try parseInt(u8, "-0", 10)) == 0);
1492 std.testing.expect((try parseInt(u8, "+0", 10)) == 0);1492 try std.testing.expect((try parseInt(u8, "+0", 10)) == 0);
14931493
1494 // ensure minInt is parsed correctly1494 // ensure minInt is parsed correctly
1495 std.testing.expect((try parseInt(i8, "-128", 10)) == math.minInt(i8));1495 try std.testing.expect((try parseInt(i8, "-128", 10)) == math.minInt(i8));
1496 std.testing.expect((try parseInt(i43, "-4398046511104", 10)) == math.minInt(i43));1496 try std.testing.expect((try parseInt(i43, "-4398046511104", 10)) == math.minInt(i43));
14971497
1498 // empty string or bare +- is invalid1498 // empty string or bare +- is invalid
1499 std.testing.expectError(error.InvalidCharacter, parseInt(u32, "", 10));1499 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "", 10));
1500 std.testing.expectError(error.InvalidCharacter, parseInt(i32, "", 10));1500 try std.testing.expectError(error.InvalidCharacter, parseInt(i32, "", 10));
1501 std.testing.expectError(error.InvalidCharacter, parseInt(u32, "+", 10));1501 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "+", 10));
1502 std.testing.expectError(error.InvalidCharacter, parseInt(i32, "+", 10));1502 try std.testing.expectError(error.InvalidCharacter, parseInt(i32, "+", 10));
1503 std.testing.expectError(error.InvalidCharacter, parseInt(u32, "-", 10));1503 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "-", 10));
1504 std.testing.expectError(error.InvalidCharacter, parseInt(i32, "-", 10));1504 try std.testing.expectError(error.InvalidCharacter, parseInt(i32, "-", 10));
15051505
1506 // autodectect the radix1506 // autodectect the radix
1507 std.testing.expect((try parseInt(i32, "111", 0)) == 111);1507 try std.testing.expect((try parseInt(i32, "111", 0)) == 111);
1508 std.testing.expect((try parseInt(i32, "+0b111", 0)) == 7);1508 try std.testing.expect((try parseInt(i32, "+0b111", 0)) == 7);
1509 std.testing.expect((try parseInt(i32, "+0o111", 0)) == 73);1509 try std.testing.expect((try parseInt(i32, "+0o111", 0)) == 73);
1510 std.testing.expect((try parseInt(i32, "+0x111", 0)) == 273);1510 try std.testing.expect((try parseInt(i32, "+0x111", 0)) == 273);
1511 std.testing.expect((try parseInt(i32, "-0b111", 0)) == -7);1511 try std.testing.expect((try parseInt(i32, "-0b111", 0)) == -7);
1512 std.testing.expect((try parseInt(i32, "-0o111", 0)) == -73);1512 try std.testing.expect((try parseInt(i32, "-0o111", 0)) == -73);
1513 std.testing.expect((try parseInt(i32, "-0x111", 0)) == -273);1513 try std.testing.expect((try parseInt(i32, "-0x111", 0)) == -273);
15141514
1515 // bare binary/octal/decimal prefix is invalid1515 // bare binary/octal/decimal prefix is invalid
1516 std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0b", 0));1516 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0b", 0));
1517 std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0o", 0));1517 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0o", 0));
1518 std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0x", 0));1518 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0x", 0));
1519}1519}
15201520
1521fn parseWithSign(1521fn parseWithSign(
...@@ -1583,37 +1583,37 @@ pub fn parseUnsigned(comptime T: type, buf: []const u8, radix: u8) ParseIntError...@@ -1583,37 +1583,37 @@ pub fn parseUnsigned(comptime T: type, buf: []const u8, radix: u8) ParseIntError
1583}1583}
15841584
1585test "parseUnsigned" {1585test "parseUnsigned" {
1586 std.testing.expect((try parseUnsigned(u16, "050124", 10)) == 50124);1586 try std.testing.expect((try parseUnsigned(u16, "050124", 10)) == 50124);
1587 std.testing.expect((try parseUnsigned(u16, "65535", 10)) == 65535);1587 try std.testing.expect((try parseUnsigned(u16, "65535", 10)) == 65535);
1588 std.testing.expectError(error.Overflow, parseUnsigned(u16, "65536", 10));1588 try std.testing.expectError(error.Overflow, parseUnsigned(u16, "65536", 10));
15891589
1590 std.testing.expect((try parseUnsigned(u64, "0ffffffffffffffff", 16)) == 0xffffffffffffffff);1590 try std.testing.expect((try parseUnsigned(u64, "0ffffffffffffffff", 16)) == 0xffffffffffffffff);
1591 std.testing.expectError(error.Overflow, parseUnsigned(u64, "10000000000000000", 16));1591 try std.testing.expectError(error.Overflow, parseUnsigned(u64, "10000000000000000", 16));
15921592
1593 std.testing.expect((try parseUnsigned(u32, "DeadBeef", 16)) == 0xDEADBEEF);1593 try std.testing.expect((try parseUnsigned(u32, "DeadBeef", 16)) == 0xDEADBEEF);
15941594
1595 std.testing.expect((try parseUnsigned(u7, "1", 10)) == 1);1595 try std.testing.expect((try parseUnsigned(u7, "1", 10)) == 1);
1596 std.testing.expect((try parseUnsigned(u7, "1000", 2)) == 8);1596 try std.testing.expect((try parseUnsigned(u7, "1000", 2)) == 8);
15971597
1598 std.testing.expectError(error.InvalidCharacter, parseUnsigned(u32, "f", 10));1598 try std.testing.expectError(error.InvalidCharacter, parseUnsigned(u32, "f", 10));
1599 std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "109", 8));1599 try std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "109", 8));
16001600
1601 std.testing.expect((try parseUnsigned(u32, "NUMBER", 36)) == 1442151747);1601 try std.testing.expect((try parseUnsigned(u32, "NUMBER", 36)) == 1442151747);
16021602
1603 // these numbers should fit even though the radix itself doesn't fit in the destination type1603 // these numbers should fit even though the radix itself doesn't fit in the destination type
1604 std.testing.expect((try parseUnsigned(u1, "0", 10)) == 0);1604 try std.testing.expect((try parseUnsigned(u1, "0", 10)) == 0);
1605 std.testing.expect((try parseUnsigned(u1, "1", 10)) == 1);1605 try std.testing.expect((try parseUnsigned(u1, "1", 10)) == 1);
1606 std.testing.expectError(error.Overflow, parseUnsigned(u1, "2", 10));1606 try std.testing.expectError(error.Overflow, parseUnsigned(u1, "2", 10));
1607 std.testing.expect((try parseUnsigned(u1, "001", 16)) == 1);1607 try std.testing.expect((try parseUnsigned(u1, "001", 16)) == 1);
1608 std.testing.expect((try parseUnsigned(u2, "3", 16)) == 3);1608 try std.testing.expect((try parseUnsigned(u2, "3", 16)) == 3);
1609 std.testing.expectError(error.Overflow, parseUnsigned(u2, "4", 16));1609 try std.testing.expectError(error.Overflow, parseUnsigned(u2, "4", 16));
16101610
1611 // parseUnsigned does not expect a sign1611 // parseUnsigned does not expect a sign
1612 std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "+0", 10));1612 try std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "+0", 10));
1613 std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "-0", 10));1613 try std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "-0", 10));
16141614
1615 // test empty string error1615 // test empty string error
1616 std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "", 10));1616 try std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "", 10));
1617}1617}
16181618
1619pub const parseFloat = @import("fmt/parse_float.zig").parseFloat;1619pub const parseFloat = @import("fmt/parse_float.zig").parseFloat;
...@@ -1692,21 +1692,21 @@ test "bufPrintInt" {...@@ -1692,21 +1692,21 @@ test "bufPrintInt" {
1692 var buffer: [100]u8 = undefined;1692 var buffer: [100]u8 = undefined;
1693 const buf = buffer[0..];1693 const buf = buffer[0..];
16941694
1695 std.testing.expectEqualSlices(u8, "-1", bufPrintIntToSlice(buf, @as(i1, -1), 10, false, FormatOptions{}));1695 try std.testing.expectEqualSlices(u8, "-1", bufPrintIntToSlice(buf, @as(i1, -1), 10, false, FormatOptions{}));
16961696
1697 std.testing.expectEqualSlices(u8, "-101111000110000101001110", bufPrintIntToSlice(buf, @as(i32, -12345678), 2, false, FormatOptions{}));1697 try std.testing.expectEqualSlices(u8, "-101111000110000101001110", bufPrintIntToSlice(buf, @as(i32, -12345678), 2, false, FormatOptions{}));
1698 std.testing.expectEqualSlices(u8, "-12345678", bufPrintIntToSlice(buf, @as(i32, -12345678), 10, false, FormatOptions{}));1698 try std.testing.expectEqualSlices(u8, "-12345678", bufPrintIntToSlice(buf, @as(i32, -12345678), 10, false, FormatOptions{}));
1699 std.testing.expectEqualSlices(u8, "-bc614e", bufPrintIntToSlice(buf, @as(i32, -12345678), 16, false, FormatOptions{}));1699 try std.testing.expectEqualSlices(u8, "-bc614e", bufPrintIntToSlice(buf, @as(i32, -12345678), 16, false, FormatOptions{}));
1700 std.testing.expectEqualSlices(u8, "-BC614E", bufPrintIntToSlice(buf, @as(i32, -12345678), 16, true, FormatOptions{}));1700 try std.testing.expectEqualSlices(u8, "-BC614E", bufPrintIntToSlice(buf, @as(i32, -12345678), 16, true, FormatOptions{}));
17011701
1702 std.testing.expectEqualSlices(u8, "12345678", bufPrintIntToSlice(buf, @as(u32, 12345678), 10, true, FormatOptions{}));1702 try std.testing.expectEqualSlices(u8, "12345678", bufPrintIntToSlice(buf, @as(u32, 12345678), 10, true, FormatOptions{}));
17031703
1704 std.testing.expectEqualSlices(u8, " 666", bufPrintIntToSlice(buf, @as(u32, 666), 10, false, FormatOptions{ .width = 6 }));1704 try std.testing.expectEqualSlices(u8, " 666", bufPrintIntToSlice(buf, @as(u32, 666), 10, false, FormatOptions{ .width = 6 }));
1705 std.testing.expectEqualSlices(u8, " 1234", bufPrintIntToSlice(buf, @as(u32, 0x1234), 16, false, FormatOptions{ .width = 6 }));1705 try std.testing.expectEqualSlices(u8, " 1234", bufPrintIntToSlice(buf, @as(u32, 0x1234), 16, false, FormatOptions{ .width = 6 }));
1706 std.testing.expectEqualSlices(u8, "1234", bufPrintIntToSlice(buf, @as(u32, 0x1234), 16, false, FormatOptions{ .width = 1 }));1706 try std.testing.expectEqualSlices(u8, "1234", bufPrintIntToSlice(buf, @as(u32, 0x1234), 16, false, FormatOptions{ .width = 1 }));
17071707
1708 std.testing.expectEqualSlices(u8, "+42", bufPrintIntToSlice(buf, @as(i32, 42), 10, false, FormatOptions{ .width = 3 }));1708 try std.testing.expectEqualSlices(u8, "+42", bufPrintIntToSlice(buf, @as(i32, 42), 10, false, FormatOptions{ .width = 3 }));
1709 std.testing.expectEqualSlices(u8, "-42", bufPrintIntToSlice(buf, @as(i32, -42), 10, false, FormatOptions{ .width = 3 }));1709 try std.testing.expectEqualSlices(u8, "-42", bufPrintIntToSlice(buf, @as(i32, -42), 10, false, FormatOptions{ .width = 3 }));
1710}1710}
17111711
1712pub fn bufPrintIntToSlice(buf: []u8, value: anytype, base: u8, uppercase: bool, options: FormatOptions) []u8 {1712pub fn bufPrintIntToSlice(buf: []u8, value: anytype, base: u8, uppercase: bool, options: FormatOptions) []u8 {
...@@ -1724,8 +1724,8 @@ pub fn comptimePrint(comptime fmt: []const u8, args: anytype) *const [count(fmt,...@@ -1724,8 +1724,8 @@ pub fn comptimePrint(comptime fmt: []const u8, args: anytype) *const [count(fmt,
17241724
1725test "comptimePrint" {1725test "comptimePrint" {
1726 @setEvalBranchQuota(2000);1726 @setEvalBranchQuota(2000);
1727 std.testing.expectEqual(*const [3:0]u8, @TypeOf(comptime comptimePrint("{}", .{100})));1727 try std.testing.expectEqual(*const [3:0]u8, @TypeOf(comptime comptimePrint("{}", .{100})));
1728 std.testing.expectEqualSlices(u8, "100", comptime comptimePrint("{}", .{100}));1728 try std.testing.expectEqualSlices(u8, "100", comptime comptimePrint("{}", .{100}));
1729}1729}
17301730
1731test "parse u64 digit too big" {1731test "parse u64 digit too big" {
...@@ -1738,7 +1738,7 @@ test "parse u64 digit too big" {...@@ -1738,7 +1738,7 @@ test "parse u64 digit too big" {
17381738
1739test "parse unsigned comptime" {1739test "parse unsigned comptime" {
1740 comptime {1740 comptime {
1741 std.testing.expect((try parseUnsigned(usize, "2", 10)) == 2);1741 try std.testing.expect((try parseUnsigned(usize, "2", 10)) == 2);
1742 }1742 }
1743}1743}
17441744
...@@ -1835,15 +1835,15 @@ test "buffer" {...@@ -1835,15 +1835,15 @@ test "buffer" {
1835 var buf1: [32]u8 = undefined;1835 var buf1: [32]u8 = undefined;
1836 var fbs = std.io.fixedBufferStream(&buf1);1836 var fbs = std.io.fixedBufferStream(&buf1);
1837 try formatType(1234, "", FormatOptions{}, fbs.writer(), default_max_depth);1837 try formatType(1234, "", FormatOptions{}, fbs.writer(), default_max_depth);
1838 std.testing.expect(mem.eql(u8, fbs.getWritten(), "1234"));1838 try std.testing.expect(mem.eql(u8, fbs.getWritten(), "1234"));
18391839
1840 fbs.reset();1840 fbs.reset();
1841 try formatType('a', "c", FormatOptions{}, fbs.writer(), default_max_depth);1841 try formatType('a', "c", FormatOptions{}, fbs.writer(), default_max_depth);
1842 std.testing.expect(mem.eql(u8, fbs.getWritten(), "a"));1842 try std.testing.expect(mem.eql(u8, fbs.getWritten(), "a"));
18431843
1844 fbs.reset();1844 fbs.reset();
1845 try formatType(0b1100, "b", FormatOptions{}, fbs.writer(), default_max_depth);1845 try formatType(0b1100, "b", FormatOptions{}, fbs.writer(), default_max_depth);
1846 std.testing.expect(mem.eql(u8, fbs.getWritten(), "1100"));1846 try std.testing.expect(mem.eql(u8, fbs.getWritten(), "1100"));
1847 }1847 }
1848}1848}
18491849
...@@ -2170,10 +2170,10 @@ test "union" {...@@ -2170,10 +2170,10 @@ test "union" {
21702170
2171 var buf: [100]u8 = undefined;2171 var buf: [100]u8 = undefined;
2172 const uu_result = try bufPrint(buf[0..], "{}", .{uu_inst});2172 const uu_result = try bufPrint(buf[0..], "{}", .{uu_inst});
2173 std.testing.expect(mem.eql(u8, uu_result[0..3], "UU@"));2173 try std.testing.expect(mem.eql(u8, uu_result[0..3], "UU@"));
21742174
2175 const eu_result = try bufPrint(buf[0..], "{}", .{eu_inst});2175 const eu_result = try bufPrint(buf[0..], "{}", .{eu_inst});
2176 std.testing.expect(mem.eql(u8, uu_result[0..3], "EU@"));2176 try std.testing.expect(mem.eql(u8, uu_result[0..3], "EU@"));
2177}2177}
21782178
2179test "enum" {2179test "enum" {
...@@ -2256,9 +2256,9 @@ test "hexToBytes" {...@@ -2256,9 +2256,9 @@ test "hexToBytes" {
2256 try expectFmt("90" ** 32, "{s}", .{fmtSliceHexUpper(try hexToBytes(&buf, "90" ** 32))});2256 try expectFmt("90" ** 32, "{s}", .{fmtSliceHexUpper(try hexToBytes(&buf, "90" ** 32))});
2257 try expectFmt("ABCD", "{s}", .{fmtSliceHexUpper(try hexToBytes(&buf, "ABCD"))});2257 try expectFmt("ABCD", "{s}", .{fmtSliceHexUpper(try hexToBytes(&buf, "ABCD"))});
2258 try expectFmt("", "{s}", .{fmtSliceHexUpper(try hexToBytes(&buf, ""))});2258 try expectFmt("", "{s}", .{fmtSliceHexUpper(try hexToBytes(&buf, ""))});
2259 std.testing.expectError(error.InvalidCharacter, hexToBytes(&buf, "012Z"));2259 try std.testing.expectError(error.InvalidCharacter, hexToBytes(&buf, "012Z"));
2260 std.testing.expectError(error.InvalidLength, hexToBytes(&buf, "AAA"));2260 try std.testing.expectError(error.InvalidLength, hexToBytes(&buf, "AAA"));
2261 std.testing.expectError(error.NoSpaceLeft, hexToBytes(buf[0..1], "ABAB"));2261 try std.testing.expectError(error.NoSpaceLeft, hexToBytes(buf[0..1], "ABAB"));
2262}2262}
22632263
2264test "formatIntValue with comptime_int" {2264test "formatIntValue with comptime_int" {
...@@ -2267,7 +2267,7 @@ test "formatIntValue with comptime_int" {...@@ -2267,7 +2267,7 @@ test "formatIntValue with comptime_int" {
2267 var buf: [20]u8 = undefined;2267 var buf: [20]u8 = undefined;
2268 var fbs = std.io.fixedBufferStream(&buf);2268 var fbs = std.io.fixedBufferStream(&buf);
2269 try formatIntValue(value, "", FormatOptions{}, fbs.writer());2269 try formatIntValue(value, "", FormatOptions{}, fbs.writer());
2270 std.testing.expect(mem.eql(u8, fbs.getWritten(), "123456789123456789"));2270 try std.testing.expect(mem.eql(u8, fbs.getWritten(), "123456789123456789"));
2271}2271}
22722272
2273test "formatFloatValue with comptime_float" {2273test "formatFloatValue with comptime_float" {
...@@ -2276,7 +2276,7 @@ test "formatFloatValue with comptime_float" {...@@ -2276,7 +2276,7 @@ test "formatFloatValue with comptime_float" {
2276 var buf: [20]u8 = undefined;2276 var buf: [20]u8 = undefined;
2277 var fbs = std.io.fixedBufferStream(&buf);2277 var fbs = std.io.fixedBufferStream(&buf);
2278 try formatFloatValue(value, "", FormatOptions{}, fbs.writer());2278 try formatFloatValue(value, "", FormatOptions{}, fbs.writer());
2279 std.testing.expect(mem.eql(u8, fbs.getWritten(), "1.0e+00"));2279 try std.testing.expect(mem.eql(u8, fbs.getWritten(), "1.0e+00"));
22802280
2281 try expectFmt("1.0e+00", "{}", .{value});2281 try expectFmt("1.0e+00", "{}", .{value});
2282 try expectFmt("1.0e+00", "{}", .{1.0});2282 try expectFmt("1.0e+00", "{}", .{1.0});
...@@ -2332,19 +2332,19 @@ test "formatType max_depth" {...@@ -2332,19 +2332,19 @@ test "formatType max_depth" {
2332 var buf: [1000]u8 = undefined;2332 var buf: [1000]u8 = undefined;
2333 var fbs = std.io.fixedBufferStream(&buf);2333 var fbs = std.io.fixedBufferStream(&buf);
2334 try formatType(inst, "", FormatOptions{}, fbs.writer(), 0);2334 try formatType(inst, "", FormatOptions{}, fbs.writer(), 0);
2335 std.testing.expect(mem.eql(u8, fbs.getWritten(), "S{ ... }"));2335 try std.testing.expect(mem.eql(u8, fbs.getWritten(), "S{ ... }"));
23362336
2337 fbs.reset();2337 fbs.reset();
2338 try formatType(inst, "", FormatOptions{}, fbs.writer(), 1);2338 try formatType(inst, "", FormatOptions{}, fbs.writer(), 1);
2339 std.testing.expect(mem.eql(u8, fbs.getWritten(), "S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }"));2339 try std.testing.expect(mem.eql(u8, fbs.getWritten(), "S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }"));
23402340
2341 fbs.reset();2341 fbs.reset();
2342 try formatType(inst, "", FormatOptions{}, fbs.writer(), 2);2342 try formatType(inst, "", FormatOptions{}, fbs.writer(), 2);
2343 std.testing.expect(mem.eql(u8, fbs.getWritten(), "S{ .a = S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }, .tu = TU{ .ptr = TU{ ... } }, .e = E.Two, .vec = (10.200,2.220) }"));2343 try std.testing.expect(mem.eql(u8, fbs.getWritten(), "S{ .a = S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }, .tu = TU{ .ptr = TU{ ... } }, .e = E.Two, .vec = (10.200,2.220) }"));
23442344
2345 fbs.reset();2345 fbs.reset();
2346 try formatType(inst, "", FormatOptions{}, fbs.writer(), 3);2346 try formatType(inst, "", FormatOptions{}, fbs.writer(), 3);
2347 std.testing.expect(mem.eql(u8, fbs.getWritten(), "S{ .a = S{ .a = S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }, .tu = TU{ .ptr = TU{ ... } }, .e = E.Two, .vec = (10.200,2.220) }, .tu = TU{ .ptr = TU{ .ptr = TU{ ... } } }, .e = E.Two, .vec = (10.200,2.220) }"));2347 try std.testing.expect(mem.eql(u8, fbs.getWritten(), "S{ .a = S{ .a = S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }, .tu = TU{ .ptr = TU{ ... } }, .e = E.Two, .vec = (10.200,2.220) }, .tu = TU{ .ptr = TU{ .ptr = TU{ ... } } }, .e = E.Two, .vec = (10.200,2.220) }"));
2348}2348}
23492349
2350test "positional" {2350test "positional" {
lib/std/fmt/parse_float.zig+29-29
...@@ -376,44 +376,44 @@ test "fmt.parseFloat" {...@@ -376,44 +376,44 @@ test "fmt.parseFloat" {
376 inline for ([_]type{ f16, f32, f64, f128 }) |T| {376 inline for ([_]type{ f16, f32, f64, f128 }) |T| {
377 const Z = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);377 const Z = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);
378378
379 testing.expectError(error.InvalidCharacter, parseFloat(T, ""));379 try testing.expectError(error.InvalidCharacter, parseFloat(T, ""));
380 testing.expectError(error.InvalidCharacter, parseFloat(T, " 1"));380 try testing.expectError(error.InvalidCharacter, parseFloat(T, " 1"));
381 testing.expectError(error.InvalidCharacter, parseFloat(T, "1abc"));381 try testing.expectError(error.InvalidCharacter, parseFloat(T, "1abc"));
382 testing.expectError(error.InvalidCharacter, parseFloat(T, "+"));382 try testing.expectError(error.InvalidCharacter, parseFloat(T, "+"));
383 testing.expectError(error.InvalidCharacter, parseFloat(T, "-"));383 try testing.expectError(error.InvalidCharacter, parseFloat(T, "-"));
384384
385 expectEqual(try parseFloat(T, "0"), 0.0);385 try expectEqual(try parseFloat(T, "0"), 0.0);
386 expectEqual(try parseFloat(T, "0"), 0.0);386 try expectEqual(try parseFloat(T, "0"), 0.0);
387 expectEqual(try parseFloat(T, "+0"), 0.0);387 try expectEqual(try parseFloat(T, "+0"), 0.0);
388 expectEqual(try parseFloat(T, "-0"), 0.0);388 try expectEqual(try parseFloat(T, "-0"), 0.0);
389389
390 expectEqual(try parseFloat(T, "0e0"), 0);390 try expectEqual(try parseFloat(T, "0e0"), 0);
391 expectEqual(try parseFloat(T, "2e3"), 2000.0);391 try expectEqual(try parseFloat(T, "2e3"), 2000.0);
392 expectEqual(try parseFloat(T, "1e0"), 1.0);392 try expectEqual(try parseFloat(T, "1e0"), 1.0);
393 expectEqual(try parseFloat(T, "-2e3"), -2000.0);393 try expectEqual(try parseFloat(T, "-2e3"), -2000.0);
394 expectEqual(try parseFloat(T, "-1e0"), -1.0);394 try expectEqual(try parseFloat(T, "-1e0"), -1.0);
395 expectEqual(try parseFloat(T, "1.234e3"), 1234);395 try expectEqual(try parseFloat(T, "1.234e3"), 1234);
396396
397 expect(approxEqAbs(T, try parseFloat(T, "3.141"), 3.141, epsilon));397 try expect(approxEqAbs(T, try parseFloat(T, "3.141"), 3.141, epsilon));
398 expect(approxEqAbs(T, try parseFloat(T, "-3.141"), -3.141, epsilon));398 try expect(approxEqAbs(T, try parseFloat(T, "-3.141"), -3.141, epsilon));
399399
400 expectEqual(try parseFloat(T, "1e-700"), 0);400 try expectEqual(try parseFloat(T, "1e-700"), 0);
401 expectEqual(try parseFloat(T, "1e+700"), std.math.inf(T));401 try expectEqual(try parseFloat(T, "1e+700"), std.math.inf(T));
402402
403 expectEqual(@bitCast(Z, try parseFloat(T, "nAn")), @bitCast(Z, std.math.nan(T)));403 try expectEqual(@bitCast(Z, try parseFloat(T, "nAn")), @bitCast(Z, std.math.nan(T)));
404 expectEqual(try parseFloat(T, "inF"), std.math.inf(T));404 try expectEqual(try parseFloat(T, "inF"), std.math.inf(T));
405 expectEqual(try parseFloat(T, "-INF"), -std.math.inf(T));405 try expectEqual(try parseFloat(T, "-INF"), -std.math.inf(T));
406406
407 expectEqual(try parseFloat(T, "0.4e0066999999999999999999999999999999999999999999999999999"), std.math.inf(T));407 try expectEqual(try parseFloat(T, "0.4e0066999999999999999999999999999999999999999999999999999"), std.math.inf(T));
408408
409 if (T != f16) {409 if (T != f16) {
410 expect(approxEqAbs(T, try parseFloat(T, "1e-2"), 0.01, epsilon));410 try expect(approxEqAbs(T, try parseFloat(T, "1e-2"), 0.01, epsilon));
411 expect(approxEqAbs(T, try parseFloat(T, "1234e-2"), 12.34, epsilon));411 try expect(approxEqAbs(T, try parseFloat(T, "1234e-2"), 12.34, epsilon));
412412
413 expect(approxEqAbs(T, try parseFloat(T, "123142.1"), 123142.1, epsilon));413 try expect(approxEqAbs(T, try parseFloat(T, "123142.1"), 123142.1, epsilon));
414 expect(approxEqAbs(T, try parseFloat(T, "-123142.1124"), @as(T, -123142.1124), epsilon));414 try expect(approxEqAbs(T, try parseFloat(T, "-123142.1124"), @as(T, -123142.1124), epsilon));
415 expect(approxEqAbs(T, try parseFloat(T, "0.7062146892655368"), @as(T, 0.7062146892655368), epsilon));415 try expect(approxEqAbs(T, try parseFloat(T, "0.7062146892655368"), @as(T, 0.7062146892655368), epsilon));
416 expect(approxEqAbs(T, try parseFloat(T, "2.71828182845904523536"), @as(T, 2.718281828459045), epsilon));416 try expect(approxEqAbs(T, try parseFloat(T, "2.71828182845904523536"), @as(T, 2.718281828459045), epsilon));
417 }417 }
418 }418 }
419}419}
lib/std/fmt/parse_hex_float.zig+13-13
...@@ -247,17 +247,17 @@ pub fn parseHexFloat(comptime T: type, s: []const u8) !T {...@@ -247,17 +247,17 @@ pub fn parseHexFloat(comptime T: type, s: []const u8) !T {
247}247}
248248
249test "special" {249test "special" {
250 testing.expect(math.isNan(try parseHexFloat(f32, "nAn")));250 try testing.expect(math.isNan(try parseHexFloat(f32, "nAn")));
251 testing.expect(math.isPositiveInf(try parseHexFloat(f32, "iNf")));251 try testing.expect(math.isPositiveInf(try parseHexFloat(f32, "iNf")));
252 testing.expect(math.isPositiveInf(try parseHexFloat(f32, "+Inf")));252 try testing.expect(math.isPositiveInf(try parseHexFloat(f32, "+Inf")));
253 testing.expect(math.isNegativeInf(try parseHexFloat(f32, "-iNf")));253 try testing.expect(math.isNegativeInf(try parseHexFloat(f32, "-iNf")));
254}254}
255test "zero" {255test "zero" {
256 testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "0x0"));256 try testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "0x0"));
257 testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "-0x0"));257 try testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "-0x0"));
258 testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "0x0p42"));258 try testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "0x0p42"));
259 testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "-0x0.00000p42"));259 try testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "-0x0.00000p42"));
260 testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "0x0.00000p666"));260 try testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "0x0.00000p666"));
261}261}
262262
263test "f16" {263test "f16" {
...@@ -279,7 +279,7 @@ test "f16" {...@@ -279,7 +279,7 @@ test "f16" {
279 };279 };
280280
281 for (cases) |case| {281 for (cases) |case| {
282 testing.expectEqual(case.v, try parseHexFloat(f16, case.s));282 try testing.expectEqual(case.v, try parseHexFloat(f16, case.s));
283 }283 }
284}284}
285test "f32" {285test "f32" {
...@@ -303,7 +303,7 @@ test "f32" {...@@ -303,7 +303,7 @@ test "f32" {
303 };303 };
304304
305 for (cases) |case| {305 for (cases) |case| {
306 testing.expectEqual(case.v, try parseHexFloat(f32, case.s));306 try testing.expectEqual(case.v, try parseHexFloat(f32, case.s));
307 }307 }
308}308}
309test "f64" {309test "f64" {
...@@ -325,7 +325,7 @@ test "f64" {...@@ -325,7 +325,7 @@ test "f64" {
325 };325 };
326326
327 for (cases) |case| {327 for (cases) |case| {
328 testing.expectEqual(case.v, try parseHexFloat(f64, case.s));328 try testing.expectEqual(case.v, try parseHexFloat(f64, case.s));
329 }329 }
330}330}
331test "f128" {331test "f128" {
...@@ -347,6 +347,6 @@ test "f128" {...@@ -347,6 +347,6 @@ test "f128" {
347 };347 };
348348
349 for (cases) |case| {349 for (cases) |case| {
350 testing.expectEqual(@bitCast(u128, case.v), @bitCast(u128, try parseHexFloat(f128, case.s)));350 try testing.expectEqual(@bitCast(u128, case.v), @bitCast(u128, try parseHexFloat(f128, case.s)));
351 }351 }
352}352}
lib/std/fs/path.zig+205-205
...@@ -96,72 +96,72 @@ pub fn joinZ(allocator: *Allocator, paths: []const []const u8) ![:0]u8 {...@@ -96,72 +96,72 @@ pub fn joinZ(allocator: *Allocator, paths: []const []const u8) ![:0]u8 {
96 return out[0 .. out.len - 1 :0];96 return out[0 .. out.len - 1 :0];
97}97}
9898
99fn testJoinMaybeZWindows(paths: []const []const u8, expected: []const u8, zero: bool) void {99fn testJoinMaybeZWindows(paths: []const []const u8, expected: []const u8, zero: bool) !void {
100 const windowsIsSep = struct {100 const windowsIsSep = struct {
101 fn isSep(byte: u8) bool {101 fn isSep(byte: u8) bool {
102 return byte == '/' or byte == '\\';102 return byte == '/' or byte == '\\';
103 }103 }
104 }.isSep;104 }.isSep;
105 const actual = joinSepMaybeZ(testing.allocator, sep_windows, windowsIsSep, paths, zero) catch @panic("fail");105 const actual = try joinSepMaybeZ(testing.allocator, sep_windows, windowsIsSep, paths, zero);
106 defer testing.allocator.free(actual);106 defer testing.allocator.free(actual);
107 testing.expectEqualSlices(u8, expected, if (zero) actual[0 .. actual.len - 1 :0] else actual);107 try testing.expectEqualSlices(u8, expected, if (zero) actual[0 .. actual.len - 1 :0] else actual);
108}108}
109109
110fn testJoinMaybeZPosix(paths: []const []const u8, expected: []const u8, zero: bool) void {110fn testJoinMaybeZPosix(paths: []const []const u8, expected: []const u8, zero: bool) !void {
111 const posixIsSep = struct {111 const posixIsSep = struct {
112 fn isSep(byte: u8) bool {112 fn isSep(byte: u8) bool {
113 return byte == '/';113 return byte == '/';
114 }114 }
115 }.isSep;115 }.isSep;
116 const actual = joinSepMaybeZ(testing.allocator, sep_posix, posixIsSep, paths, zero) catch @panic("fail");116 const actual = try joinSepMaybeZ(testing.allocator, sep_posix, posixIsSep, paths, zero);
117 defer testing.allocator.free(actual);117 defer testing.allocator.free(actual);
118 testing.expectEqualSlices(u8, expected, if (zero) actual[0 .. actual.len - 1 :0] else actual);118 try testing.expectEqualSlices(u8, expected, if (zero) actual[0 .. actual.len - 1 :0] else actual);
119}119}
120120
121test "join" {121test "join" {
122 {122 {
123 const actual: []u8 = try join(testing.allocator, &[_][]const u8{});123 const actual: []u8 = try join(testing.allocator, &[_][]const u8{});
124 defer testing.allocator.free(actual);124 defer testing.allocator.free(actual);
125 testing.expectEqualSlices(u8, "", actual);125 try testing.expectEqualSlices(u8, "", actual);
126 }126 }
127 {127 {
128 const actual: [:0]u8 = try joinZ(testing.allocator, &[_][]const u8{});128 const actual: [:0]u8 = try joinZ(testing.allocator, &[_][]const u8{});
129 defer testing.allocator.free(actual);129 defer testing.allocator.free(actual);
130 testing.expectEqualSlices(u8, "", actual);130 try testing.expectEqualSlices(u8, "", actual);
131 }131 }
132 for (&[_]bool{ false, true }) |zero| {132 for (&[_]bool{ false, true }) |zero| {
133 testJoinMaybeZWindows(&[_][]const u8{}, "", zero);133 try testJoinMaybeZWindows(&[_][]const u8{}, "", zero);
134 testJoinMaybeZWindows(&[_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c", zero);134 try testJoinMaybeZWindows(&[_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c", zero);
135 testJoinMaybeZWindows(&[_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c", zero);135 try testJoinMaybeZWindows(&[_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c", zero);
136 testJoinMaybeZWindows(&[_][]const u8{ "c:\\a\\b\\", "c" }, "c:\\a\\b\\c", zero);136 try testJoinMaybeZWindows(&[_][]const u8{ "c:\\a\\b\\", "c" }, "c:\\a\\b\\c", zero);
137137
138 testJoinMaybeZWindows(&[_][]const u8{ "c:\\", "a", "b\\", "c" }, "c:\\a\\b\\c", zero);138 try testJoinMaybeZWindows(&[_][]const u8{ "c:\\", "a", "b\\", "c" }, "c:\\a\\b\\c", zero);
139 testJoinMaybeZWindows(&[_][]const u8{ "c:\\a\\", "b\\", "c" }, "c:\\a\\b\\c", zero);139 try testJoinMaybeZWindows(&[_][]const u8{ "c:\\a\\", "b\\", "c" }, "c:\\a\\b\\c", zero);
140140
141 testJoinMaybeZWindows(141 try testJoinMaybeZWindows(
142 &[_][]const u8{ "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std", "io.zig" },142 &[_][]const u8{ "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std", "io.zig" },
143 "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std\\io.zig",143 "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std\\io.zig",
144 zero,144 zero,
145 );145 );
146146
147 testJoinMaybeZWindows(&[_][]const u8{ "c:\\", "a", "b/", "c" }, "c:\\a\\b/c", zero);147 try testJoinMaybeZWindows(&[_][]const u8{ "c:\\", "a", "b/", "c" }, "c:\\a\\b/c", zero);
148 testJoinMaybeZWindows(&[_][]const u8{ "c:\\a/", "b\\", "/c" }, "c:\\a/b\\c", zero);148 try testJoinMaybeZWindows(&[_][]const u8{ "c:\\a/", "b\\", "/c" }, "c:\\a/b\\c", zero);
149149
150 testJoinMaybeZPosix(&[_][]const u8{}, "", zero);150 try testJoinMaybeZPosix(&[_][]const u8{}, "", zero);
151 testJoinMaybeZPosix(&[_][]const u8{ "/a/b", "c" }, "/a/b/c", zero);151 try testJoinMaybeZPosix(&[_][]const u8{ "/a/b", "c" }, "/a/b/c", zero);
152 testJoinMaybeZPosix(&[_][]const u8{ "/a/b/", "c" }, "/a/b/c", zero);152 try testJoinMaybeZPosix(&[_][]const u8{ "/a/b/", "c" }, "/a/b/c", zero);
153153
154 testJoinMaybeZPosix(&[_][]const u8{ "/", "a", "b/", "c" }, "/a/b/c", zero);154 try testJoinMaybeZPosix(&[_][]const u8{ "/", "a", "b/", "c" }, "/a/b/c", zero);
155 testJoinMaybeZPosix(&[_][]const u8{ "/a/", "b/", "c" }, "/a/b/c", zero);155 try testJoinMaybeZPosix(&[_][]const u8{ "/a/", "b/", "c" }, "/a/b/c", zero);
156156
157 testJoinMaybeZPosix(157 try testJoinMaybeZPosix(
158 &[_][]const u8{ "/home/andy/dev/zig/build/lib/zig/std", "io.zig" },158 &[_][]const u8{ "/home/andy/dev/zig/build/lib/zig/std", "io.zig" },
159 "/home/andy/dev/zig/build/lib/zig/std/io.zig",159 "/home/andy/dev/zig/build/lib/zig/std/io.zig",
160 zero,160 zero,
161 );161 );
162162
163 testJoinMaybeZPosix(&[_][]const u8{ "a", "/c" }, "a/c", zero);163 try testJoinMaybeZPosix(&[_][]const u8{ "a", "/c" }, "a/c", zero);
164 testJoinMaybeZPosix(&[_][]const u8{ "a/", "/c" }, "a/c", zero);164 try testJoinMaybeZPosix(&[_][]const u8{ "a/", "/c" }, "a/c", zero);
165 }165 }
166}166}
167167
...@@ -235,42 +235,42 @@ pub fn isAbsolutePosixZ(path_c: [*:0]const u8) bool {...@@ -235,42 +235,42 @@ pub fn isAbsolutePosixZ(path_c: [*:0]const u8) bool {
235}235}
236236
237test "isAbsoluteWindows" {237test "isAbsoluteWindows" {
238 testIsAbsoluteWindows("", false);238 try testIsAbsoluteWindows("", false);
239 testIsAbsoluteWindows("/", true);239 try testIsAbsoluteWindows("/", true);
240 testIsAbsoluteWindows("//", true);240 try testIsAbsoluteWindows("//", true);
241 testIsAbsoluteWindows("//server", true);241 try testIsAbsoluteWindows("//server", true);
242 testIsAbsoluteWindows("//server/file", true);242 try testIsAbsoluteWindows("//server/file", true);
243 testIsAbsoluteWindows("\\\\server\\file", true);243 try testIsAbsoluteWindows("\\\\server\\file", true);
244 testIsAbsoluteWindows("\\\\server", true);244 try testIsAbsoluteWindows("\\\\server", true);
245 testIsAbsoluteWindows("\\\\", true);245 try testIsAbsoluteWindows("\\\\", true);
246 testIsAbsoluteWindows("c", false);246 try testIsAbsoluteWindows("c", false);
247 testIsAbsoluteWindows("c:", false);247 try testIsAbsoluteWindows("c:", false);
248 testIsAbsoluteWindows("c:\\", true);248 try testIsAbsoluteWindows("c:\\", true);
249 testIsAbsoluteWindows("c:/", true);249 try testIsAbsoluteWindows("c:/", true);
250 testIsAbsoluteWindows("c://", true);250 try testIsAbsoluteWindows("c://", true);
251 testIsAbsoluteWindows("C:/Users/", true);251 try testIsAbsoluteWindows("C:/Users/", true);
252 testIsAbsoluteWindows("C:\\Users\\", true);252 try testIsAbsoluteWindows("C:\\Users\\", true);
253 testIsAbsoluteWindows("C:cwd/another", false);253 try testIsAbsoluteWindows("C:cwd/another", false);
254 testIsAbsoluteWindows("C:cwd\\another", false);254 try testIsAbsoluteWindows("C:cwd\\another", false);
255 testIsAbsoluteWindows("directory/directory", false);255 try testIsAbsoluteWindows("directory/directory", false);
256 testIsAbsoluteWindows("directory\\directory", false);256 try testIsAbsoluteWindows("directory\\directory", false);
257 testIsAbsoluteWindows("/usr/local", true);257 try testIsAbsoluteWindows("/usr/local", true);
258}258}
259259
260test "isAbsolutePosix" {260test "isAbsolutePosix" {
261 testIsAbsolutePosix("", false);261 try testIsAbsolutePosix("", false);
262 testIsAbsolutePosix("/home/foo", true);262 try testIsAbsolutePosix("/home/foo", true);
263 testIsAbsolutePosix("/home/foo/..", true);263 try testIsAbsolutePosix("/home/foo/..", true);
264 testIsAbsolutePosix("bar/", false);264 try testIsAbsolutePosix("bar/", false);
265 testIsAbsolutePosix("./baz", false);265 try testIsAbsolutePosix("./baz", false);
266}266}
267267
268fn testIsAbsoluteWindows(path: []const u8, expected_result: bool) void {268fn testIsAbsoluteWindows(path: []const u8, expected_result: bool) !void {
269 testing.expectEqual(expected_result, isAbsoluteWindows(path));269 try testing.expectEqual(expected_result, isAbsoluteWindows(path));
270}270}
271271
272fn testIsAbsolutePosix(path: []const u8, expected_result: bool) void {272fn testIsAbsolutePosix(path: []const u8, expected_result: bool) !void {
273 testing.expectEqual(expected_result, isAbsolutePosix(path));273 try testing.expectEqual(expected_result, isAbsolutePosix(path));
274}274}
275275
276pub const WindowsPath = struct {276pub const WindowsPath = struct {
...@@ -334,33 +334,33 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {...@@ -334,33 +334,33 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {
334test "windowsParsePath" {334test "windowsParsePath" {
335 {335 {
336 const parsed = windowsParsePath("//a/b");336 const parsed = windowsParsePath("//a/b");
337 testing.expect(parsed.is_abs);337 try testing.expect(parsed.is_abs);
338 testing.expect(parsed.kind == WindowsPath.Kind.NetworkShare);338 try testing.expect(parsed.kind == WindowsPath.Kind.NetworkShare);
339 testing.expect(mem.eql(u8, parsed.disk_designator, "//a/b"));339 try testing.expect(mem.eql(u8, parsed.disk_designator, "//a/b"));
340 }340 }
341 {341 {
342 const parsed = windowsParsePath("\\\\a\\b");342 const parsed = windowsParsePath("\\\\a\\b");
343 testing.expect(parsed.is_abs);343 try testing.expect(parsed.is_abs);
344 testing.expect(parsed.kind == WindowsPath.Kind.NetworkShare);344 try testing.expect(parsed.kind == WindowsPath.Kind.NetworkShare);
345 testing.expect(mem.eql(u8, parsed.disk_designator, "\\\\a\\b"));345 try testing.expect(mem.eql(u8, parsed.disk_designator, "\\\\a\\b"));
346 }346 }
347 {347 {
348 const parsed = windowsParsePath("\\\\a\\");348 const parsed = windowsParsePath("\\\\a\\");
349 testing.expect(!parsed.is_abs);349 try testing.expect(!parsed.is_abs);
350 testing.expect(parsed.kind == WindowsPath.Kind.None);350 try testing.expect(parsed.kind == WindowsPath.Kind.None);
351 testing.expect(mem.eql(u8, parsed.disk_designator, ""));351 try testing.expect(mem.eql(u8, parsed.disk_designator, ""));
352 }352 }
353 {353 {
354 const parsed = windowsParsePath("/usr/local");354 const parsed = windowsParsePath("/usr/local");
355 testing.expect(parsed.is_abs);355 try testing.expect(parsed.is_abs);
356 testing.expect(parsed.kind == WindowsPath.Kind.None);356 try testing.expect(parsed.kind == WindowsPath.Kind.None);
357 testing.expect(mem.eql(u8, parsed.disk_designator, ""));357 try testing.expect(mem.eql(u8, parsed.disk_designator, ""));
358 }358 }
359 {359 {
360 const parsed = windowsParsePath("c:../");360 const parsed = windowsParsePath("c:../");
361 testing.expect(!parsed.is_abs);361 try testing.expect(!parsed.is_abs);
362 testing.expect(parsed.kind == WindowsPath.Kind.Drive);362 try testing.expect(parsed.kind == WindowsPath.Kind.Drive);
363 testing.expect(mem.eql(u8, parsed.disk_designator, "c:"));363 try testing.expect(mem.eql(u8, parsed.disk_designator, "c:"));
364 }364 }
365}365}
366366
...@@ -772,13 +772,13 @@ test "resolvePosix" {...@@ -772,13 +772,13 @@ test "resolvePosix" {
772fn testResolveWindows(paths: []const []const u8, expected: []const u8) !void {772fn testResolveWindows(paths: []const []const u8, expected: []const u8) !void {
773 const actual = try resolveWindows(testing.allocator, paths);773 const actual = try resolveWindows(testing.allocator, paths);
774 defer testing.allocator.free(actual);774 defer testing.allocator.free(actual);
775 return testing.expect(mem.eql(u8, actual, expected));775 try testing.expect(mem.eql(u8, actual, expected));
776}776}
777777
778fn testResolvePosix(paths: []const []const u8, expected: []const u8) !void {778fn testResolvePosix(paths: []const []const u8, expected: []const u8) !void {
779 const actual = try resolvePosix(testing.allocator, paths);779 const actual = try resolvePosix(testing.allocator, paths);
780 defer testing.allocator.free(actual);780 defer testing.allocator.free(actual);
781 return testing.expect(mem.eql(u8, actual, expected));781 try testing.expect(mem.eql(u8, actual, expected));
782}782}
783783
784/// Strip the last component from a file path.784/// Strip the last component from a file path.
...@@ -856,68 +856,68 @@ pub fn dirnamePosix(path: []const u8) ?[]const u8 {...@@ -856,68 +856,68 @@ pub fn dirnamePosix(path: []const u8) ?[]const u8 {
856}856}
857857
858test "dirnamePosix" {858test "dirnamePosix" {
859 testDirnamePosix("/a/b/c", "/a/b");859 try testDirnamePosix("/a/b/c", "/a/b");
860 testDirnamePosix("/a/b/c///", "/a/b");860 try testDirnamePosix("/a/b/c///", "/a/b");
861 testDirnamePosix("/a", "/");861 try testDirnamePosix("/a", "/");
862 testDirnamePosix("/", null);862 try testDirnamePosix("/", null);
863 testDirnamePosix("//", null);863 try testDirnamePosix("//", null);
864 testDirnamePosix("///", null);864 try testDirnamePosix("///", null);
865 testDirnamePosix("////", null);865 try testDirnamePosix("////", null);
866 testDirnamePosix("", null);866 try testDirnamePosix("", null);
867 testDirnamePosix("a", null);867 try testDirnamePosix("a", null);
868 testDirnamePosix("a/", null);868 try testDirnamePosix("a/", null);
869 testDirnamePosix("a//", null);869 try testDirnamePosix("a//", null);
870}870}
871871
872test "dirnameWindows" {872test "dirnameWindows" {
873 testDirnameWindows("c:\\", null);873 try testDirnameWindows("c:\\", null);
874 testDirnameWindows("c:\\foo", "c:\\");874 try testDirnameWindows("c:\\foo", "c:\\");
875 testDirnameWindows("c:\\foo\\", "c:\\");875 try testDirnameWindows("c:\\foo\\", "c:\\");
876 testDirnameWindows("c:\\foo\\bar", "c:\\foo");876 try testDirnameWindows("c:\\foo\\bar", "c:\\foo");
877 testDirnameWindows("c:\\foo\\bar\\", "c:\\foo");877 try testDirnameWindows("c:\\foo\\bar\\", "c:\\foo");
878 testDirnameWindows("c:\\foo\\bar\\baz", "c:\\foo\\bar");878 try testDirnameWindows("c:\\foo\\bar\\baz", "c:\\foo\\bar");
879 testDirnameWindows("\\", null);879 try testDirnameWindows("\\", null);
880 testDirnameWindows("\\foo", "\\");880 try testDirnameWindows("\\foo", "\\");
881 testDirnameWindows("\\foo\\", "\\");881 try testDirnameWindows("\\foo\\", "\\");
882 testDirnameWindows("\\foo\\bar", "\\foo");882 try testDirnameWindows("\\foo\\bar", "\\foo");
883 testDirnameWindows("\\foo\\bar\\", "\\foo");883 try testDirnameWindows("\\foo\\bar\\", "\\foo");
884 testDirnameWindows("\\foo\\bar\\baz", "\\foo\\bar");884 try testDirnameWindows("\\foo\\bar\\baz", "\\foo\\bar");
885 testDirnameWindows("c:", null);885 try testDirnameWindows("c:", null);
886 testDirnameWindows("c:foo", null);886 try testDirnameWindows("c:foo", null);
887 testDirnameWindows("c:foo\\", null);887 try testDirnameWindows("c:foo\\", null);
888 testDirnameWindows("c:foo\\bar", "c:foo");888 try testDirnameWindows("c:foo\\bar", "c:foo");
889 testDirnameWindows("c:foo\\bar\\", "c:foo");889 try testDirnameWindows("c:foo\\bar\\", "c:foo");
890 testDirnameWindows("c:foo\\bar\\baz", "c:foo\\bar");890 try testDirnameWindows("c:foo\\bar\\baz", "c:foo\\bar");
891 testDirnameWindows("file:stream", null);891 try testDirnameWindows("file:stream", null);
892 testDirnameWindows("dir\\file:stream", "dir");892 try testDirnameWindows("dir\\file:stream", "dir");
893 testDirnameWindows("\\\\unc\\share", null);893 try testDirnameWindows("\\\\unc\\share", null);
894 testDirnameWindows("\\\\unc\\share\\foo", "\\\\unc\\share\\");894 try testDirnameWindows("\\\\unc\\share\\foo", "\\\\unc\\share\\");
895 testDirnameWindows("\\\\unc\\share\\foo\\", "\\\\unc\\share\\");895 try testDirnameWindows("\\\\unc\\share\\foo\\", "\\\\unc\\share\\");
896 testDirnameWindows("\\\\unc\\share\\foo\\bar", "\\\\unc\\share\\foo");896 try testDirnameWindows("\\\\unc\\share\\foo\\bar", "\\\\unc\\share\\foo");
897 testDirnameWindows("\\\\unc\\share\\foo\\bar\\", "\\\\unc\\share\\foo");897 try testDirnameWindows("\\\\unc\\share\\foo\\bar\\", "\\\\unc\\share\\foo");
898 testDirnameWindows("\\\\unc\\share\\foo\\bar\\baz", "\\\\unc\\share\\foo\\bar");898 try testDirnameWindows("\\\\unc\\share\\foo\\bar\\baz", "\\\\unc\\share\\foo\\bar");
899 testDirnameWindows("/a/b/", "/a");899 try testDirnameWindows("/a/b/", "/a");
900 testDirnameWindows("/a/b", "/a");900 try testDirnameWindows("/a/b", "/a");
901 testDirnameWindows("/a", "/");901 try testDirnameWindows("/a", "/");
902 testDirnameWindows("", null);902 try testDirnameWindows("", null);
903 testDirnameWindows("/", null);903 try testDirnameWindows("/", null);
904 testDirnameWindows("////", null);904 try testDirnameWindows("////", null);
905 testDirnameWindows("foo", null);905 try testDirnameWindows("foo", null);
906}906}
907907
908fn testDirnamePosix(input: []const u8, expected_output: ?[]const u8) void {908fn testDirnamePosix(input: []const u8, expected_output: ?[]const u8) !void {
909 if (dirnamePosix(input)) |output| {909 if (dirnamePosix(input)) |output| {
910 testing.expect(mem.eql(u8, output, expected_output.?));910 try testing.expect(mem.eql(u8, output, expected_output.?));
911 } else {911 } else {
912 testing.expect(expected_output == null);912 try testing.expect(expected_output == null);
913 }913 }
914}914}
915915
916fn testDirnameWindows(input: []const u8, expected_output: ?[]const u8) void {916fn testDirnameWindows(input: []const u8, expected_output: ?[]const u8) !void {
917 if (dirnameWindows(input)) |output| {917 if (dirnameWindows(input)) |output| {
918 testing.expect(mem.eql(u8, output, expected_output.?));918 try testing.expect(mem.eql(u8, output, expected_output.?));
919 } else {919 } else {
920 testing.expect(expected_output == null);920 try testing.expect(expected_output == null);
921 }921 }
922}922}
923923
...@@ -983,54 +983,54 @@ pub fn basenameWindows(path: []const u8) []const u8 {...@@ -983,54 +983,54 @@ pub fn basenameWindows(path: []const u8) []const u8 {
983}983}
984984
985test "basename" {985test "basename" {
986 testBasename("", "");986 try testBasename("", "");
987 testBasename("/", "");987 try testBasename("/", "");
988 testBasename("/dir/basename.ext", "basename.ext");988 try testBasename("/dir/basename.ext", "basename.ext");
989 testBasename("/basename.ext", "basename.ext");989 try testBasename("/basename.ext", "basename.ext");
990 testBasename("basename.ext", "basename.ext");990 try testBasename("basename.ext", "basename.ext");
991 testBasename("basename.ext/", "basename.ext");991 try testBasename("basename.ext/", "basename.ext");
992 testBasename("basename.ext//", "basename.ext");992 try testBasename("basename.ext//", "basename.ext");
993 testBasename("/aaa/bbb", "bbb");993 try testBasename("/aaa/bbb", "bbb");
994 testBasename("/aaa/", "aaa");994 try testBasename("/aaa/", "aaa");
995 testBasename("/aaa/b", "b");995 try testBasename("/aaa/b", "b");
996 testBasename("/a/b", "b");996 try testBasename("/a/b", "b");
997 testBasename("//a", "a");997 try testBasename("//a", "a");
998998
999 testBasenamePosix("\\dir\\basename.ext", "\\dir\\basename.ext");999 try testBasenamePosix("\\dir\\basename.ext", "\\dir\\basename.ext");
1000 testBasenamePosix("\\basename.ext", "\\basename.ext");1000 try testBasenamePosix("\\basename.ext", "\\basename.ext");
1001 testBasenamePosix("basename.ext", "basename.ext");1001 try testBasenamePosix("basename.ext", "basename.ext");
1002 testBasenamePosix("basename.ext\\", "basename.ext\\");1002 try testBasenamePosix("basename.ext\\", "basename.ext\\");
1003 testBasenamePosix("basename.ext\\\\", "basename.ext\\\\");1003 try testBasenamePosix("basename.ext\\\\", "basename.ext\\\\");
1004 testBasenamePosix("foo", "foo");1004 try testBasenamePosix("foo", "foo");
10051005
1006 testBasenameWindows("\\dir\\basename.ext", "basename.ext");1006 try testBasenameWindows("\\dir\\basename.ext", "basename.ext");
1007 testBasenameWindows("\\basename.ext", "basename.ext");1007 try testBasenameWindows("\\basename.ext", "basename.ext");
1008 testBasenameWindows("basename.ext", "basename.ext");1008 try testBasenameWindows("basename.ext", "basename.ext");
1009 testBasenameWindows("basename.ext\\", "basename.ext");1009 try testBasenameWindows("basename.ext\\", "basename.ext");
1010 testBasenameWindows("basename.ext\\\\", "basename.ext");1010 try testBasenameWindows("basename.ext\\\\", "basename.ext");
1011 testBasenameWindows("foo", "foo");1011 try testBasenameWindows("foo", "foo");
1012 testBasenameWindows("C:", "");1012 try testBasenameWindows("C:", "");
1013 testBasenameWindows("C:.", ".");1013 try testBasenameWindows("C:.", ".");
1014 testBasenameWindows("C:\\", "");1014 try testBasenameWindows("C:\\", "");
1015 testBasenameWindows("C:\\dir\\base.ext", "base.ext");1015 try testBasenameWindows("C:\\dir\\base.ext", "base.ext");
1016 testBasenameWindows("C:\\basename.ext", "basename.ext");1016 try testBasenameWindows("C:\\basename.ext", "basename.ext");
1017 testBasenameWindows("C:basename.ext", "basename.ext");1017 try testBasenameWindows("C:basename.ext", "basename.ext");
1018 testBasenameWindows("C:basename.ext\\", "basename.ext");1018 try testBasenameWindows("C:basename.ext\\", "basename.ext");
1019 testBasenameWindows("C:basename.ext\\\\", "basename.ext");1019 try testBasenameWindows("C:basename.ext\\\\", "basename.ext");
1020 testBasenameWindows("C:foo", "foo");1020 try testBasenameWindows("C:foo", "foo");
1021 testBasenameWindows("file:stream", "file:stream");1021 try testBasenameWindows("file:stream", "file:stream");
1022}1022}
10231023
1024fn testBasename(input: []const u8, expected_output: []const u8) void {1024fn testBasename(input: []const u8, expected_output: []const u8) !void {
1025 testing.expectEqualSlices(u8, expected_output, basename(input));1025 try testing.expectEqualSlices(u8, expected_output, basename(input));
1026}1026}
10271027
1028fn testBasenamePosix(input: []const u8, expected_output: []const u8) void {1028fn testBasenamePosix(input: []const u8, expected_output: []const u8) !void {
1029 testing.expectEqualSlices(u8, expected_output, basenamePosix(input));1029 try testing.expectEqualSlices(u8, expected_output, basenamePosix(input));
1030}1030}
10311031
1032fn testBasenameWindows(input: []const u8, expected_output: []const u8) void {1032fn testBasenameWindows(input: []const u8, expected_output: []const u8) !void {
1033 testing.expectEqualSlices(u8, expected_output, basenameWindows(input));1033 try testing.expectEqualSlices(u8, expected_output, basenameWindows(input));
1034}1034}
10351035
1036/// Returns the relative path from `from` to `to`. If `from` and `to` each1036/// Returns the relative path from `from` to `to`. If `from` and `to` each
...@@ -1212,13 +1212,13 @@ test "relative" {...@@ -1212,13 +1212,13 @@ test "relative" {
1212fn testRelativePosix(from: []const u8, to: []const u8, expected_output: []const u8) !void {1212fn testRelativePosix(from: []const u8, to: []const u8, expected_output: []const u8) !void {
1213 const result = try relativePosix(testing.allocator, from, to);1213 const result = try relativePosix(testing.allocator, from, to);
1214 defer testing.allocator.free(result);1214 defer testing.allocator.free(result);
1215 testing.expectEqualSlices(u8, expected_output, result);1215 try testing.expectEqualSlices(u8, expected_output, result);
1216}1216}
12171217
1218fn testRelativeWindows(from: []const u8, to: []const u8, expected_output: []const u8) !void {1218fn testRelativeWindows(from: []const u8, to: []const u8, expected_output: []const u8) !void {
1219 const result = try relativeWindows(testing.allocator, from, to);1219 const result = try relativeWindows(testing.allocator, from, to);
1220 defer testing.allocator.free(result);1220 defer testing.allocator.free(result);
1221 testing.expectEqualSlices(u8, expected_output, result);1221 try testing.expectEqualSlices(u8, expected_output, result);
1222}1222}
12231223
1224/// Returns the extension of the file name (if any).1224/// Returns the extension of the file name (if any).
...@@ -1241,47 +1241,47 @@ pub fn extension(path: []const u8) []const u8 {...@@ -1241,47 +1241,47 @@ pub fn extension(path: []const u8) []const u8 {
1241 return filename[index..];1241 return filename[index..];
1242}1242}
12431243
1244fn testExtension(path: []const u8, expected: []const u8) void {1244fn testExtension(path: []const u8, expected: []const u8) !void {
1245 std.testing.expectEqualStrings(expected, extension(path));1245 try std.testing.expectEqualStrings(expected, extension(path));
1246}1246}
12471247
1248test "extension" {1248test "extension" {
1249 testExtension("", "");1249 try testExtension("", "");
1250 testExtension(".", "");1250 try testExtension(".", "");
1251 testExtension("a.", ".");1251 try testExtension("a.", ".");
1252 testExtension("abc.", ".");1252 try testExtension("abc.", ".");
1253 testExtension(".a", "");1253 try testExtension(".a", "");
1254 testExtension(".file", "");1254 try testExtension(".file", "");
1255 testExtension(".gitignore", "");1255 try testExtension(".gitignore", "");
1256 testExtension("file.ext", ".ext");1256 try testExtension("file.ext", ".ext");
1257 testExtension("file.ext.", ".");1257 try testExtension("file.ext.", ".");
1258 testExtension("very-long-file.bruh", ".bruh");1258 try testExtension("very-long-file.bruh", ".bruh");
1259 testExtension("a.b.c", ".c");1259 try testExtension("a.b.c", ".c");
1260 testExtension("a.b.c/", ".c");1260 try testExtension("a.b.c/", ".c");
12611261
1262 testExtension("/", "");1262 try testExtension("/", "");
1263 testExtension("/.", "");1263 try testExtension("/.", "");
1264 testExtension("/a.", ".");1264 try testExtension("/a.", ".");
1265 testExtension("/abc.", ".");1265 try testExtension("/abc.", ".");
1266 testExtension("/.a", "");1266 try testExtension("/.a", "");
1267 testExtension("/.file", "");1267 try testExtension("/.file", "");
1268 testExtension("/.gitignore", "");1268 try testExtension("/.gitignore", "");
1269 testExtension("/file.ext", ".ext");1269 try testExtension("/file.ext", ".ext");
1270 testExtension("/file.ext.", ".");1270 try testExtension("/file.ext.", ".");
1271 testExtension("/very-long-file.bruh", ".bruh");1271 try testExtension("/very-long-file.bruh", ".bruh");
1272 testExtension("/a.b.c", ".c");1272 try testExtension("/a.b.c", ".c");
1273 testExtension("/a.b.c/", ".c");1273 try testExtension("/a.b.c/", ".c");
12741274
1275 testExtension("/foo/bar/bam/", "");1275 try testExtension("/foo/bar/bam/", "");
1276 testExtension("/foo/bar/bam/.", "");1276 try testExtension("/foo/bar/bam/.", "");
1277 testExtension("/foo/bar/bam/a.", ".");1277 try testExtension("/foo/bar/bam/a.", ".");
1278 testExtension("/foo/bar/bam/abc.", ".");1278 try testExtension("/foo/bar/bam/abc.", ".");
1279 testExtension("/foo/bar/bam/.a", "");1279 try testExtension("/foo/bar/bam/.a", "");
1280 testExtension("/foo/bar/bam/.file", "");1280 try testExtension("/foo/bar/bam/.file", "");
1281 testExtension("/foo/bar/bam/.gitignore", "");1281 try testExtension("/foo/bar/bam/.gitignore", "");
1282 testExtension("/foo/bar/bam/file.ext", ".ext");1282 try testExtension("/foo/bar/bam/file.ext", ".ext");
1283 testExtension("/foo/bar/bam/file.ext.", ".");1283 try testExtension("/foo/bar/bam/file.ext.", ".");
1284 testExtension("/foo/bar/bam/very-long-file.bruh", ".bruh");1284 try testExtension("/foo/bar/bam/very-long-file.bruh", ".bruh");
1285 testExtension("/foo/bar/bam/a.b.c", ".c");1285 try testExtension("/foo/bar/bam/a.b.c", ".c");
1286 testExtension("/foo/bar/bam/a.b.c/", ".c");1286 try testExtension("/foo/bar/bam/a.b.c/", ".c");
1287}1287}
lib/std/fs/test.zig+52-52
...@@ -46,7 +46,7 @@ test "Dir.readLink" {...@@ -46,7 +46,7 @@ test "Dir.readLink" {
46fn testReadLink(dir: Dir, target_path: []const u8, symlink_path: []const u8) !void {46fn testReadLink(dir: Dir, target_path: []const u8, symlink_path: []const u8) !void {
47 var buffer: [fs.MAX_PATH_BYTES]u8 = undefined;47 var buffer: [fs.MAX_PATH_BYTES]u8 = undefined;
48 const given = try dir.readLink(symlink_path, buffer[0..]);48 const given = try dir.readLink(symlink_path, buffer[0..]);
49 testing.expect(mem.eql(u8, target_path, given));49 try testing.expect(mem.eql(u8, target_path, given));
50}50}
5151
52test "accessAbsolute" {52test "accessAbsolute" {
...@@ -132,7 +132,7 @@ test "readLinkAbsolute" {...@@ -132,7 +132,7 @@ test "readLinkAbsolute" {
132fn testReadLinkAbsolute(target_path: []const u8, symlink_path: []const u8) !void {132fn testReadLinkAbsolute(target_path: []const u8, symlink_path: []const u8) !void {
133 var buffer: [fs.MAX_PATH_BYTES]u8 = undefined;133 var buffer: [fs.MAX_PATH_BYTES]u8 = undefined;
134 const given = try fs.readLinkAbsolute(symlink_path, buffer[0..]);134 const given = try fs.readLinkAbsolute(symlink_path, buffer[0..]);
135 testing.expect(mem.eql(u8, target_path, given));135 try testing.expect(mem.eql(u8, target_path, given));
136}136}
137137
138test "Dir.Iterator" {138test "Dir.Iterator" {
...@@ -159,9 +159,9 @@ test "Dir.Iterator" {...@@ -159,9 +159,9 @@ test "Dir.Iterator" {
159 try entries.append(Dir.Entry{ .name = name, .kind = entry.kind });159 try entries.append(Dir.Entry{ .name = name, .kind = entry.kind });
160 }160 }
161161
162 testing.expect(entries.items.len == 2); // note that the Iterator skips '.' and '..'162 try testing.expect(entries.items.len == 2); // note that the Iterator skips '.' and '..'
163 testing.expect(contains(&entries, Dir.Entry{ .name = "some_file", .kind = Dir.Entry.Kind.File }));163 try testing.expect(contains(&entries, Dir.Entry{ .name = "some_file", .kind = Dir.Entry.Kind.File }));
164 testing.expect(contains(&entries, Dir.Entry{ .name = "some_dir", .kind = Dir.Entry.Kind.Directory }));164 try testing.expect(contains(&entries, Dir.Entry{ .name = "some_dir", .kind = Dir.Entry.Kind.Directory }));
165}165}
166166
167fn entryEql(lhs: Dir.Entry, rhs: Dir.Entry) bool {167fn entryEql(lhs: Dir.Entry, rhs: Dir.Entry) bool {
...@@ -203,7 +203,7 @@ test "Dir.realpath smoke test" {...@@ -203,7 +203,7 @@ test "Dir.realpath smoke test" {
203 const file_path = try tmp_dir.dir.realpath("test_file", buf1[0..]);203 const file_path = try tmp_dir.dir.realpath("test_file", buf1[0..]);
204 const expected_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "test_file" });204 const expected_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "test_file" });
205205
206 testing.expect(mem.eql(u8, file_path, expected_path));206 try testing.expect(mem.eql(u8, file_path, expected_path));
207 }207 }
208208
209 // Next, test alloc version209 // Next, test alloc version
...@@ -211,7 +211,7 @@ test "Dir.realpath smoke test" {...@@ -211,7 +211,7 @@ test "Dir.realpath smoke test" {
211 const file_path = try tmp_dir.dir.realpathAlloc(&arena.allocator, "test_file");211 const file_path = try tmp_dir.dir.realpathAlloc(&arena.allocator, "test_file");
212 const expected_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "test_file" });212 const expected_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "test_file" });
213213
214 testing.expect(mem.eql(u8, file_path, expected_path));214 try testing.expect(mem.eql(u8, file_path, expected_path));
215 }215 }
216}216}
217217
...@@ -224,7 +224,7 @@ test "readAllAlloc" {...@@ -224,7 +224,7 @@ test "readAllAlloc" {
224224
225 const buf1 = try file.readToEndAlloc(testing.allocator, 1024);225 const buf1 = try file.readToEndAlloc(testing.allocator, 1024);
226 defer testing.allocator.free(buf1);226 defer testing.allocator.free(buf1);
227 testing.expect(buf1.len == 0);227 try testing.expect(buf1.len == 0);
228228
229 const write_buf: []const u8 = "this is a test.\nthis is a test.\nthis is a test.\nthis is a test.\n";229 const write_buf: []const u8 = "this is a test.\nthis is a test.\nthis is a test.\nthis is a test.\n";
230 try file.writeAll(write_buf);230 try file.writeAll(write_buf);
...@@ -233,19 +233,19 @@ test "readAllAlloc" {...@@ -233,19 +233,19 @@ test "readAllAlloc" {
233 // max_bytes > file_size233 // max_bytes > file_size
234 const buf2 = try file.readToEndAlloc(testing.allocator, 1024);234 const buf2 = try file.readToEndAlloc(testing.allocator, 1024);
235 defer testing.allocator.free(buf2);235 defer testing.allocator.free(buf2);
236 testing.expectEqual(write_buf.len, buf2.len);236 try testing.expectEqual(write_buf.len, buf2.len);
237 testing.expect(std.mem.eql(u8, write_buf, buf2));237 try testing.expect(std.mem.eql(u8, write_buf, buf2));
238 try file.seekTo(0);238 try file.seekTo(0);
239239
240 // max_bytes == file_size240 // max_bytes == file_size
241 const buf3 = try file.readToEndAlloc(testing.allocator, write_buf.len);241 const buf3 = try file.readToEndAlloc(testing.allocator, write_buf.len);
242 defer testing.allocator.free(buf3);242 defer testing.allocator.free(buf3);
243 testing.expectEqual(write_buf.len, buf3.len);243 try testing.expectEqual(write_buf.len, buf3.len);
244 testing.expect(std.mem.eql(u8, write_buf, buf3));244 try testing.expect(std.mem.eql(u8, write_buf, buf3));
245 try file.seekTo(0);245 try file.seekTo(0);
246246
247 // max_bytes < file_size247 // max_bytes < file_size
248 testing.expectError(error.FileTooBig, file.readToEndAlloc(testing.allocator, write_buf.len - 1));248 try testing.expectError(error.FileTooBig, file.readToEndAlloc(testing.allocator, write_buf.len - 1));
249}249}
250250
251test "directory operations on files" {251test "directory operations on files" {
...@@ -257,22 +257,22 @@ test "directory operations on files" {...@@ -257,22 +257,22 @@ test "directory operations on files" {
257 var file = try tmp_dir.dir.createFile(test_file_name, .{ .read = true });257 var file = try tmp_dir.dir.createFile(test_file_name, .{ .read = true });
258 file.close();258 file.close();
259259
260 testing.expectError(error.PathAlreadyExists, tmp_dir.dir.makeDir(test_file_name));260 try testing.expectError(error.PathAlreadyExists, tmp_dir.dir.makeDir(test_file_name));
261 testing.expectError(error.NotDir, tmp_dir.dir.openDir(test_file_name, .{}));261 try testing.expectError(error.NotDir, tmp_dir.dir.openDir(test_file_name, .{}));
262 testing.expectError(error.NotDir, tmp_dir.dir.deleteDir(test_file_name));262 try testing.expectError(error.NotDir, tmp_dir.dir.deleteDir(test_file_name));
263263
264 if (builtin.os.tag != .wasi and builtin.os.tag != .freebsd and builtin.os.tag != .openbsd) {264 if (builtin.os.tag != .wasi and builtin.os.tag != .freebsd and builtin.os.tag != .openbsd) {
265 const absolute_path = try tmp_dir.dir.realpathAlloc(testing.allocator, test_file_name);265 const absolute_path = try tmp_dir.dir.realpathAlloc(testing.allocator, test_file_name);
266 defer testing.allocator.free(absolute_path);266 defer testing.allocator.free(absolute_path);
267267
268 testing.expectError(error.PathAlreadyExists, fs.makeDirAbsolute(absolute_path));268 try testing.expectError(error.PathAlreadyExists, fs.makeDirAbsolute(absolute_path));
269 testing.expectError(error.NotDir, fs.deleteDirAbsolute(absolute_path));269 try testing.expectError(error.NotDir, fs.deleteDirAbsolute(absolute_path));
270 }270 }
271271
272 // ensure the file still exists and is a file as a sanity check272 // ensure the file still exists and is a file as a sanity check
273 file = try tmp_dir.dir.openFile(test_file_name, .{});273 file = try tmp_dir.dir.openFile(test_file_name, .{});
274 const stat = try file.stat();274 const stat = try file.stat();
275 testing.expect(stat.kind == .File);275 try testing.expect(stat.kind == .File);
276 file.close();276 file.close();
277}277}
278278
...@@ -287,23 +287,23 @@ test "file operations on directories" {...@@ -287,23 +287,23 @@ test "file operations on directories" {
287287
288 try tmp_dir.dir.makeDir(test_dir_name);288 try tmp_dir.dir.makeDir(test_dir_name);
289289
290 testing.expectError(error.IsDir, tmp_dir.dir.createFile(test_dir_name, .{}));290 try testing.expectError(error.IsDir, tmp_dir.dir.createFile(test_dir_name, .{}));
291 testing.expectError(error.IsDir, tmp_dir.dir.deleteFile(test_dir_name));291 try testing.expectError(error.IsDir, tmp_dir.dir.deleteFile(test_dir_name));
292 // Currently, WASI will return error.Unexpected (via ENOTCAPABLE) when attempting fd_read on a directory handle.292 // Currently, WASI will return error.Unexpected (via ENOTCAPABLE) when attempting fd_read on a directory handle.
293 // TODO: Re-enable on WASI once https://github.com/bytecodealliance/wasmtime/issues/1935 is resolved.293 // TODO: Re-enable on WASI once https://github.com/bytecodealliance/wasmtime/issues/1935 is resolved.
294 if (builtin.os.tag != .wasi) {294 if (builtin.os.tag != .wasi) {
295 testing.expectError(error.IsDir, tmp_dir.dir.readFileAlloc(testing.allocator, test_dir_name, std.math.maxInt(usize)));295 try testing.expectError(error.IsDir, tmp_dir.dir.readFileAlloc(testing.allocator, test_dir_name, std.math.maxInt(usize)));
296 }296 }
297 // Note: The `.write = true` is necessary to ensure the error occurs on all platforms.297 // Note: The `.write = true` is necessary to ensure the error occurs on all platforms.
298 // TODO: Add a read-only test as well, see https://github.com/ziglang/zig/issues/5732298 // TODO: Add a read-only test as well, see https://github.com/ziglang/zig/issues/5732
299 testing.expectError(error.IsDir, tmp_dir.dir.openFile(test_dir_name, .{ .write = true }));299 try testing.expectError(error.IsDir, tmp_dir.dir.openFile(test_dir_name, .{ .write = true }));
300300
301 if (builtin.os.tag != .wasi and builtin.os.tag != .freebsd and builtin.os.tag != .openbsd) {301 if (builtin.os.tag != .wasi and builtin.os.tag != .freebsd and builtin.os.tag != .openbsd) {
302 const absolute_path = try tmp_dir.dir.realpathAlloc(testing.allocator, test_dir_name);302 const absolute_path = try tmp_dir.dir.realpathAlloc(testing.allocator, test_dir_name);
303 defer testing.allocator.free(absolute_path);303 defer testing.allocator.free(absolute_path);
304304
305 testing.expectError(error.IsDir, fs.createFileAbsolute(absolute_path, .{}));305 try testing.expectError(error.IsDir, fs.createFileAbsolute(absolute_path, .{}));
306 testing.expectError(error.IsDir, fs.deleteFileAbsolute(absolute_path));306 try testing.expectError(error.IsDir, fs.deleteFileAbsolute(absolute_path));
307 }307 }
308308
309 // ensure the directory still exists as a sanity check309 // ensure the directory still exists as a sanity check
...@@ -316,7 +316,7 @@ test "deleteDir" {...@@ -316,7 +316,7 @@ test "deleteDir" {
316 defer tmp_dir.cleanup();316 defer tmp_dir.cleanup();
317317
318 // deleting a non-existent directory318 // deleting a non-existent directory
319 testing.expectError(error.FileNotFound, tmp_dir.dir.deleteDir("test_dir"));319 try testing.expectError(error.FileNotFound, tmp_dir.dir.deleteDir("test_dir"));
320320
321 var dir = try tmp_dir.dir.makeOpenPath("test_dir", .{});321 var dir = try tmp_dir.dir.makeOpenPath("test_dir", .{});
322 var file = try dir.createFile("test_file", .{});322 var file = try dir.createFile("test_file", .{});
...@@ -326,7 +326,7 @@ test "deleteDir" {...@@ -326,7 +326,7 @@ test "deleteDir" {
326 // deleting a non-empty directory326 // deleting a non-empty directory
327 // TODO: Re-enable this check on Windows, see https://github.com/ziglang/zig/issues/5537327 // TODO: Re-enable this check on Windows, see https://github.com/ziglang/zig/issues/5537
328 if (builtin.os.tag != .windows) {328 if (builtin.os.tag != .windows) {
329 testing.expectError(error.DirNotEmpty, tmp_dir.dir.deleteDir("test_dir"));329 try testing.expectError(error.DirNotEmpty, tmp_dir.dir.deleteDir("test_dir"));
330 }330 }
331331
332 dir = try tmp_dir.dir.openDir("test_dir", .{});332 dir = try tmp_dir.dir.openDir("test_dir", .{});
...@@ -341,7 +341,7 @@ test "Dir.rename files" {...@@ -341,7 +341,7 @@ test "Dir.rename files" {
341 var tmp_dir = tmpDir(.{});341 var tmp_dir = tmpDir(.{});
342 defer tmp_dir.cleanup();342 defer tmp_dir.cleanup();
343343
344 testing.expectError(error.FileNotFound, tmp_dir.dir.rename("missing_file_name", "something_else"));344 try testing.expectError(error.FileNotFound, tmp_dir.dir.rename("missing_file_name", "something_else"));
345345
346 // Renaming files346 // Renaming files
347 const test_file_name = "test_file";347 const test_file_name = "test_file";
...@@ -351,7 +351,7 @@ test "Dir.rename files" {...@@ -351,7 +351,7 @@ test "Dir.rename files" {
351 try tmp_dir.dir.rename(test_file_name, renamed_test_file_name);351 try tmp_dir.dir.rename(test_file_name, renamed_test_file_name);
352352
353 // Ensure the file was renamed353 // Ensure the file was renamed
354 testing.expectError(error.FileNotFound, tmp_dir.dir.openFile(test_file_name, .{}));354 try testing.expectError(error.FileNotFound, tmp_dir.dir.openFile(test_file_name, .{}));
355 file = try tmp_dir.dir.openFile(renamed_test_file_name, .{});355 file = try tmp_dir.dir.openFile(renamed_test_file_name, .{});
356 file.close();356 file.close();
357357
...@@ -363,7 +363,7 @@ test "Dir.rename files" {...@@ -363,7 +363,7 @@ test "Dir.rename files" {
363 existing_file.close();363 existing_file.close();
364 try tmp_dir.dir.rename(renamed_test_file_name, "existing_file");364 try tmp_dir.dir.rename(renamed_test_file_name, "existing_file");
365365
366 testing.expectError(error.FileNotFound, tmp_dir.dir.openFile(renamed_test_file_name, .{}));366 try testing.expectError(error.FileNotFound, tmp_dir.dir.openFile(renamed_test_file_name, .{}));
367 file = try tmp_dir.dir.openFile("existing_file", .{});367 file = try tmp_dir.dir.openFile("existing_file", .{});
368 file.close();368 file.close();
369}369}
...@@ -380,7 +380,7 @@ test "Dir.rename directories" {...@@ -380,7 +380,7 @@ test "Dir.rename directories" {
380 try tmp_dir.dir.rename("test_dir", "test_dir_renamed");380 try tmp_dir.dir.rename("test_dir", "test_dir_renamed");
381381
382 // Ensure the directory was renamed382 // Ensure the directory was renamed
383 testing.expectError(error.FileNotFound, tmp_dir.dir.openDir("test_dir", .{}));383 try testing.expectError(error.FileNotFound, tmp_dir.dir.openDir("test_dir", .{}));
384 var dir = try tmp_dir.dir.openDir("test_dir_renamed", .{});384 var dir = try tmp_dir.dir.openDir("test_dir_renamed", .{});
385385
386 // Put a file in the directory386 // Put a file in the directory
...@@ -391,7 +391,7 @@ test "Dir.rename directories" {...@@ -391,7 +391,7 @@ test "Dir.rename directories" {
391 try tmp_dir.dir.rename("test_dir_renamed", "test_dir_renamed_again");391 try tmp_dir.dir.rename("test_dir_renamed", "test_dir_renamed_again");
392392
393 // Ensure the directory was renamed and the file still exists in it393 // Ensure the directory was renamed and the file still exists in it
394 testing.expectError(error.FileNotFound, tmp_dir.dir.openDir("test_dir_renamed", .{}));394 try testing.expectError(error.FileNotFound, tmp_dir.dir.openDir("test_dir_renamed", .{}));
395 dir = try tmp_dir.dir.openDir("test_dir_renamed_again", .{});395 dir = try tmp_dir.dir.openDir("test_dir_renamed_again", .{});
396 file = try dir.openFile("test_file", .{});396 file = try dir.openFile("test_file", .{});
397 file.close();397 file.close();
...@@ -402,7 +402,7 @@ test "Dir.rename directories" {...@@ -402,7 +402,7 @@ test "Dir.rename directories" {
402 file = try target_dir.createFile("filler", .{ .read = true });402 file = try target_dir.createFile("filler", .{ .read = true });
403 file.close();403 file.close();
404404
405 testing.expectError(error.PathAlreadyExists, tmp_dir.dir.rename("test_dir_renamed_again", "non_empty_target_dir"));405 try testing.expectError(error.PathAlreadyExists, tmp_dir.dir.rename("test_dir_renamed_again", "non_empty_target_dir"));
406406
407 // Ensure the directory was not renamed407 // Ensure the directory was not renamed
408 dir = try tmp_dir.dir.openDir("test_dir_renamed_again", .{});408 dir = try tmp_dir.dir.openDir("test_dir_renamed_again", .{});
...@@ -421,8 +421,8 @@ test "Dir.rename file <-> dir" {...@@ -421,8 +421,8 @@ test "Dir.rename file <-> dir" {
421 var file = try tmp_dir.dir.createFile("test_file", .{ .read = true });421 var file = try tmp_dir.dir.createFile("test_file", .{ .read = true });
422 file.close();422 file.close();
423 try tmp_dir.dir.makeDir("test_dir");423 try tmp_dir.dir.makeDir("test_dir");
424 testing.expectError(error.IsDir, tmp_dir.dir.rename("test_file", "test_dir"));424 try testing.expectError(error.IsDir, tmp_dir.dir.rename("test_file", "test_dir"));
425 testing.expectError(error.NotDir, tmp_dir.dir.rename("test_dir", "test_file"));425 try testing.expectError(error.NotDir, tmp_dir.dir.rename("test_dir", "test_file"));
426}426}
427427
428test "rename" {428test "rename" {
...@@ -440,7 +440,7 @@ test "rename" {...@@ -440,7 +440,7 @@ test "rename" {
440 try fs.rename(tmp_dir1.dir, test_file_name, tmp_dir2.dir, renamed_test_file_name);440 try fs.rename(tmp_dir1.dir, test_file_name, tmp_dir2.dir, renamed_test_file_name);
441441
442 // ensure the file was renamed442 // ensure the file was renamed
443 testing.expectError(error.FileNotFound, tmp_dir1.dir.openFile(test_file_name, .{}));443 try testing.expectError(error.FileNotFound, tmp_dir1.dir.openFile(test_file_name, .{}));
444 file = try tmp_dir2.dir.openFile(renamed_test_file_name, .{});444 file = try tmp_dir2.dir.openFile(renamed_test_file_name, .{});
445 file.close();445 file.close();
446}446}
...@@ -461,7 +461,7 @@ test "renameAbsolute" {...@@ -461,7 +461,7 @@ test "renameAbsolute" {
461 break :blk try fs.realpathAlloc(&arena.allocator, relative_path);461 break :blk try fs.realpathAlloc(&arena.allocator, relative_path);
462 };462 };
463463
464 testing.expectError(error.FileNotFound, fs.renameAbsolute(464 try testing.expectError(error.FileNotFound, fs.renameAbsolute(
465 try fs.path.join(allocator, &[_][]const u8{ base_path, "missing_file_name" }),465 try fs.path.join(allocator, &[_][]const u8{ base_path, "missing_file_name" }),
466 try fs.path.join(allocator, &[_][]const u8{ base_path, "something_else" }),466 try fs.path.join(allocator, &[_][]const u8{ base_path, "something_else" }),
467 ));467 ));
...@@ -477,10 +477,10 @@ test "renameAbsolute" {...@@ -477,10 +477,10 @@ test "renameAbsolute" {
477 );477 );
478478
479 // ensure the file was renamed479 // ensure the file was renamed
480 testing.expectError(error.FileNotFound, tmp_dir.dir.openFile(test_file_name, .{}));480 try testing.expectError(error.FileNotFound, tmp_dir.dir.openFile(test_file_name, .{}));
481 file = try tmp_dir.dir.openFile(renamed_test_file_name, .{});481 file = try tmp_dir.dir.openFile(renamed_test_file_name, .{});
482 const stat = try file.stat();482 const stat = try file.stat();
483 testing.expect(stat.kind == .File);483 try testing.expect(stat.kind == .File);
484 file.close();484 file.close();
485485
486 // Renaming directories486 // Renaming directories
...@@ -493,7 +493,7 @@ test "renameAbsolute" {...@@ -493,7 +493,7 @@ test "renameAbsolute" {
493 );493 );
494494
495 // ensure the directory was renamed495 // ensure the directory was renamed
496 testing.expectError(error.FileNotFound, tmp_dir.dir.openDir(test_dir_name, .{}));496 try testing.expectError(error.FileNotFound, tmp_dir.dir.openDir(test_dir_name, .{}));
497 var dir = try tmp_dir.dir.openDir(renamed_test_dir_name, .{});497 var dir = try tmp_dir.dir.openDir(renamed_test_dir_name, .{});
498 dir.close();498 dir.close();
499}499}
...@@ -516,7 +516,7 @@ test "makePath, put some files in it, deleteTree" {...@@ -516,7 +516,7 @@ test "makePath, put some files in it, deleteTree" {
516 if (tmp.dir.openDir("os_test_tmp", .{})) |dir| {516 if (tmp.dir.openDir("os_test_tmp", .{})) |dir| {
517 @panic("expected error");517 @panic("expected error");
518 } else |err| {518 } else |err| {
519 testing.expect(err == error.FileNotFound);519 try testing.expect(err == error.FileNotFound);
520 }520 }
521}521}
522522
...@@ -530,7 +530,7 @@ test "access file" {...@@ -530,7 +530,7 @@ test "access file" {
530 if (tmp.dir.access("os_test_tmp" ++ fs.path.sep_str ++ "file.txt", .{})) |ok| {530 if (tmp.dir.access("os_test_tmp" ++ fs.path.sep_str ++ "file.txt", .{})) |ok| {
531 @panic("expected error");531 @panic("expected error");
532 } else |err| {532 } else |err| {
533 testing.expect(err == error.FileNotFound);533 try testing.expect(err == error.FileNotFound);
534 }534 }
535535
536 try tmp.dir.writeFile("os_test_tmp" ++ fs.path.sep_str ++ "file.txt", "");536 try tmp.dir.writeFile("os_test_tmp" ++ fs.path.sep_str ++ "file.txt", "");
...@@ -600,7 +600,7 @@ test "sendfile" {...@@ -600,7 +600,7 @@ test "sendfile" {
600 .header_count = 2,600 .header_count = 2,
601 });601 });
602 const amt = try dest_file.preadAll(&written_buf, 0);602 const amt = try dest_file.preadAll(&written_buf, 0);
603 testing.expect(mem.eql(u8, written_buf[0..amt], "header1\nsecond header\nine1\nsecontrailer1\nsecond trailer\n"));603 try testing.expect(mem.eql(u8, written_buf[0..amt], "header1\nsecond header\nine1\nsecontrailer1\nsecond trailer\n"));
604}604}
605605
606test "copyRangeAll" {606test "copyRangeAll" {
...@@ -626,7 +626,7 @@ test "copyRangeAll" {...@@ -626,7 +626,7 @@ test "copyRangeAll" {
626 _ = try src_file.copyRangeAll(0, dest_file, 0, data.len);626 _ = try src_file.copyRangeAll(0, dest_file, 0, data.len);
627627
628 const amt = try dest_file.preadAll(&written_buf, 0);628 const amt = try dest_file.preadAll(&written_buf, 0);
629 testing.expect(mem.eql(u8, written_buf[0..amt], data));629 try testing.expect(mem.eql(u8, written_buf[0..amt], data));
630}630}
631631
632test "fs.copyFile" {632test "fs.copyFile" {
...@@ -655,7 +655,7 @@ fn expectFileContents(dir: Dir, file_path: []const u8, data: []const u8) !void {...@@ -655,7 +655,7 @@ fn expectFileContents(dir: Dir, file_path: []const u8, data: []const u8) !void {
655 const contents = try dir.readFileAlloc(testing.allocator, file_path, 1000);655 const contents = try dir.readFileAlloc(testing.allocator, file_path, 1000);
656 defer testing.allocator.free(contents);656 defer testing.allocator.free(contents);
657657
658 testing.expectEqualSlices(u8, data, contents);658 try testing.expectEqualSlices(u8, data, contents);
659}659}
660660
661test "AtomicFile" {661test "AtomicFile" {
...@@ -676,7 +676,7 @@ test "AtomicFile" {...@@ -676,7 +676,7 @@ test "AtomicFile" {
676 }676 }
677 const content = try tmp.dir.readFileAlloc(testing.allocator, test_out_file, 9999);677 const content = try tmp.dir.readFileAlloc(testing.allocator, test_out_file, 9999);
678 defer testing.allocator.free(content);678 defer testing.allocator.free(content);
679 testing.expect(mem.eql(u8, content, test_content));679 try testing.expect(mem.eql(u8, content, test_content));
680680
681 try tmp.dir.deleteFile(test_out_file);681 try tmp.dir.deleteFile(test_out_file);
682}682}
...@@ -685,7 +685,7 @@ test "realpath" {...@@ -685,7 +685,7 @@ test "realpath" {
685 if (builtin.os.tag == .wasi) return error.SkipZigTest;685 if (builtin.os.tag == .wasi) return error.SkipZigTest;
686686
687 var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;687 var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
688 testing.expectError(error.FileNotFound, fs.realpath("definitely_bogus_does_not_exist1234", &buf));688 try testing.expectError(error.FileNotFound, fs.realpath("definitely_bogus_does_not_exist1234", &buf));
689}689}
690690
691test "open file with exclusive nonblocking lock twice" {691test "open file with exclusive nonblocking lock twice" {
...@@ -700,7 +700,7 @@ test "open file with exclusive nonblocking lock twice" {...@@ -700,7 +700,7 @@ test "open file with exclusive nonblocking lock twice" {
700 defer file1.close();700 defer file1.close();
701701
702 const file2 = tmp.dir.createFile(filename, .{ .lock = .Exclusive, .lock_nonblocking = true });702 const file2 = tmp.dir.createFile(filename, .{ .lock = .Exclusive, .lock_nonblocking = true });
703 testing.expectError(error.WouldBlock, file2);703 try testing.expectError(error.WouldBlock, file2);
704}704}
705705
706test "open file with shared and exclusive nonblocking lock" {706test "open file with shared and exclusive nonblocking lock" {
...@@ -715,7 +715,7 @@ test "open file with shared and exclusive nonblocking lock" {...@@ -715,7 +715,7 @@ test "open file with shared and exclusive nonblocking lock" {
715 defer file1.close();715 defer file1.close();
716716
717 const file2 = tmp.dir.createFile(filename, .{ .lock = .Exclusive, .lock_nonblocking = true });717 const file2 = tmp.dir.createFile(filename, .{ .lock = .Exclusive, .lock_nonblocking = true });
718 testing.expectError(error.WouldBlock, file2);718 try testing.expectError(error.WouldBlock, file2);
719}719}
720720
721test "open file with exclusive and shared nonblocking lock" {721test "open file with exclusive and shared nonblocking lock" {
...@@ -730,7 +730,7 @@ test "open file with exclusive and shared nonblocking lock" {...@@ -730,7 +730,7 @@ test "open file with exclusive and shared nonblocking lock" {
730 defer file1.close();730 defer file1.close();
731731
732 const file2 = tmp.dir.createFile(filename, .{ .lock = .Shared, .lock_nonblocking = true });732 const file2 = tmp.dir.createFile(filename, .{ .lock = .Shared, .lock_nonblocking = true });
733 testing.expectError(error.WouldBlock, file2);733 try testing.expectError(error.WouldBlock, file2);
734}734}
735735
736test "open file with exclusive lock twice, make sure it waits" {736test "open file with exclusive lock twice, make sure it waits" {
...@@ -790,7 +790,7 @@ test "open file with exclusive nonblocking lock twice (absolute paths)" {...@@ -790,7 +790,7 @@ test "open file with exclusive nonblocking lock twice (absolute paths)" {
790790
791 const file2 = fs.createFileAbsolute(filename, .{ .lock = .Exclusive, .lock_nonblocking = true });791 const file2 = fs.createFileAbsolute(filename, .{ .lock = .Exclusive, .lock_nonblocking = true });
792 file1.close();792 file1.close();
793 testing.expectError(error.WouldBlock, file2);793 try testing.expectError(error.WouldBlock, file2);
794794
795 try fs.deleteFileAbsolute(filename);795 try fs.deleteFileAbsolute(filename);
796}796}
...@@ -830,6 +830,6 @@ test "walker" {...@@ -830,6 +830,6 @@ test "walker" {
830 try fs.path.join(allocator, &[_][]const u8{ expected_dir_name, name });830 try fs.path.join(allocator, &[_][]const u8{ expected_dir_name, name });
831831
832 var entry = (try walker.next()).?;832 var entry = (try walker.next()).?;
833 testing.expectEqualStrings(expected_dir_name, try fs.path.relative(allocator, tmp_path, entry.path));833 try testing.expectEqualStrings(expected_dir_name, try fs.path.relative(allocator, tmp_path, entry.path));
834 }834 }
835}835}
lib/std/fs/wasi.zig+3-3
...@@ -174,8 +174,8 @@ test "extracting WASI preopens" {...@@ -174,8 +174,8 @@ test "extracting WASI preopens" {
174174
175 try preopens.populate();175 try preopens.populate();
176176
177 std.testing.expectEqual(@as(usize, 1), preopens.asSlice().len);177 try std.testing.expectEqual(@as(usize, 1), preopens.asSlice().len);
178 const preopen = preopens.find(PreopenType{ .Dir = "." }) orelse unreachable;178 const preopen = preopens.find(PreopenType{ .Dir = "." }) orelse unreachable;
179 std.testing.expect(preopen.@"type".eql(PreopenType{ .Dir = "." }));179 try std.testing.expect(preopen.@"type".eql(PreopenType{ .Dir = "." }));
180 std.testing.expectEqual(@as(usize, 3), preopen.fd);180 try std.testing.expectEqual(@as(usize, 3), preopen.fd);
181}181}
lib/std/fs/watch.zig+3-3
...@@ -662,13 +662,13 @@ fn testWriteWatchWriteDelete(allocator: *Allocator) !void {...@@ -662,13 +662,13 @@ fn testWriteWatchWriteDelete(allocator: *Allocator) !void {
662662
663 const read_contents = try std.fs.cwd().readFileAlloc(allocator, file_path, 1024 * 1024);663 const read_contents = try std.fs.cwd().readFileAlloc(allocator, file_path, 1024 * 1024);
664 defer allocator.free(read_contents);664 defer allocator.free(read_contents);
665 testing.expectEqualSlices(u8, contents, read_contents);665 try testing.expectEqualSlices(u8, contents, read_contents);
666666
667 // now watch the file667 // now watch the file
668 var watch = try Watch(void).init(allocator, 0);668 var watch = try Watch(void).init(allocator, 0);
669 defer watch.deinit();669 defer watch.deinit();
670670
671 testing.expect((try watch.addFile(file_path, {})) == null);671 try testing.expect((try watch.addFile(file_path, {})) == null);
672672
673 var ev = async watch.channel.get();673 var ev = async watch.channel.get();
674 var ev_consumed = false;674 var ev_consumed = false;
...@@ -698,7 +698,7 @@ fn testWriteWatchWriteDelete(allocator: *Allocator) !void {...@@ -698,7 +698,7 @@ fn testWriteWatchWriteDelete(allocator: *Allocator) !void {
698 const contents_updated = try std.fs.cwd().readFileAlloc(allocator, file_path, 1024 * 1024);698 const contents_updated = try std.fs.cwd().readFileAlloc(allocator, file_path, 1024 * 1024);
699 defer allocator.free(contents_updated);699 defer allocator.free(contents_updated);
700700
701 testing.expectEqualSlices(u8,701 try testing.expectEqualSlices(u8,
702 \\line 1702 \\line 1
703 \\lorem ipsum703 \\lorem ipsum
704 , contents_updated);704 , contents_updated);
lib/std/hash/adler.zig+6-6
...@@ -99,21 +99,21 @@ pub const Adler32 = struct {...@@ -99,21 +99,21 @@ pub const Adler32 = struct {
99};99};
100100
101test "adler32 sanity" {101test "adler32 sanity" {
102 testing.expectEqual(@as(u32, 0x620062), Adler32.hash("a"));102 try testing.expectEqual(@as(u32, 0x620062), Adler32.hash("a"));
103 testing.expectEqual(@as(u32, 0xbc002ed), Adler32.hash("example"));103 try testing.expectEqual(@as(u32, 0xbc002ed), Adler32.hash("example"));
104}104}
105105
106test "adler32 long" {106test "adler32 long" {
107 const long1 = [_]u8{1} ** 1024;107 const long1 = [_]u8{1} ** 1024;
108 testing.expectEqual(@as(u32, 0x06780401), Adler32.hash(long1[0..]));108 try testing.expectEqual(@as(u32, 0x06780401), Adler32.hash(long1[0..]));
109109
110 const long2 = [_]u8{1} ** 1025;110 const long2 = [_]u8{1} ** 1025;
111 testing.expectEqual(@as(u32, 0x0a7a0402), Adler32.hash(long2[0..]));111 try testing.expectEqual(@as(u32, 0x0a7a0402), Adler32.hash(long2[0..]));
112}112}
113113
114test "adler32 very long" {114test "adler32 very long" {
115 const long = [_]u8{1} ** 5553;115 const long = [_]u8{1} ** 5553;
116 testing.expectEqual(@as(u32, 0x707f15b2), Adler32.hash(long[0..]));116 try testing.expectEqual(@as(u32, 0x707f15b2), Adler32.hash(long[0..]));
117}117}
118118
119test "adler32 very long with variation" {119test "adler32 very long with variation" {
...@@ -129,5 +129,5 @@ test "adler32 very long with variation" {...@@ -129,5 +129,5 @@ test "adler32 very long with variation" {
129 break :blk result;129 break :blk result;
130 };130 };
131131
132 testing.expectEqual(@as(u32, 0x5af38d6e), std.hash.Adler32.hash(long[0..]));132 try testing.expectEqual(@as(u32, 0x5af38d6e), std.hash.Adler32.hash(long[0..]));
133}133}
lib/std/hash/auto_hash.zig+46-46
...@@ -239,18 +239,18 @@ fn testHashDeepRecursive(key: anytype) u64 {...@@ -239,18 +239,18 @@ fn testHashDeepRecursive(key: anytype) u64 {
239239
240test "typeContainsSlice" {240test "typeContainsSlice" {
241 comptime {241 comptime {
242 testing.expect(!typeContainsSlice(meta.Tag(std.builtin.TypeInfo)));242 try testing.expect(!typeContainsSlice(meta.Tag(std.builtin.TypeInfo)));
243243
244 testing.expect(typeContainsSlice([]const u8));244 try testing.expect(typeContainsSlice([]const u8));
245 testing.expect(!typeContainsSlice(u8));245 try testing.expect(!typeContainsSlice(u8));
246 const A = struct { x: []const u8 };246 const A = struct { x: []const u8 };
247 const B = struct { a: A };247 const B = struct { a: A };
248 const C = struct { b: B };248 const C = struct { b: B };
249 const D = struct { x: u8 };249 const D = struct { x: u8 };
250 testing.expect(typeContainsSlice(A));250 try testing.expect(typeContainsSlice(A));
251 testing.expect(typeContainsSlice(B));251 try testing.expect(typeContainsSlice(B));
252 testing.expect(typeContainsSlice(C));252 try testing.expect(typeContainsSlice(C));
253 testing.expect(!typeContainsSlice(D));253 try testing.expect(!typeContainsSlice(D));
254 }254 }
255}255}
256256
...@@ -261,17 +261,17 @@ test "hash pointer" {...@@ -261,17 +261,17 @@ test "hash pointer" {
261 const c = &array[2];261 const c = &array[2];
262 const d = a;262 const d = a;
263263
264 testing.expect(testHashShallow(a) == testHashShallow(d));264 try testing.expect(testHashShallow(a) == testHashShallow(d));
265 testing.expect(testHashShallow(a) != testHashShallow(c));265 try testing.expect(testHashShallow(a) != testHashShallow(c));
266 testing.expect(testHashShallow(a) != testHashShallow(b));266 try testing.expect(testHashShallow(a) != testHashShallow(b));
267267
268 testing.expect(testHashDeep(a) == testHashDeep(a));268 try testing.expect(testHashDeep(a) == testHashDeep(a));
269 testing.expect(testHashDeep(a) == testHashDeep(c));269 try testing.expect(testHashDeep(a) == testHashDeep(c));
270 testing.expect(testHashDeep(a) == testHashDeep(b));270 try testing.expect(testHashDeep(a) == testHashDeep(b));
271271
272 testing.expect(testHashDeepRecursive(a) == testHashDeepRecursive(a));272 try testing.expect(testHashDeepRecursive(a) == testHashDeepRecursive(a));
273 testing.expect(testHashDeepRecursive(a) == testHashDeepRecursive(c));273 try testing.expect(testHashDeepRecursive(a) == testHashDeepRecursive(c));
274 testing.expect(testHashDeepRecursive(a) == testHashDeepRecursive(b));274 try testing.expect(testHashDeepRecursive(a) == testHashDeepRecursive(b));
275}275}
276276
277test "hash slice shallow" {277test "hash slice shallow" {
...@@ -286,10 +286,10 @@ test "hash slice shallow" {...@@ -286,10 +286,10 @@ test "hash slice shallow" {
286 const a = array1[runtime_zero..];286 const a = array1[runtime_zero..];
287 const b = array2[runtime_zero..];287 const b = array2[runtime_zero..];
288 const c = array1[runtime_zero..3];288 const c = array1[runtime_zero..3];
289 testing.expect(testHashShallow(a) == testHashShallow(a));289 try testing.expect(testHashShallow(a) == testHashShallow(a));
290 testing.expect(testHashShallow(a) != testHashShallow(array1));290 try testing.expect(testHashShallow(a) != testHashShallow(array1));
291 testing.expect(testHashShallow(a) != testHashShallow(b));291 try testing.expect(testHashShallow(a) != testHashShallow(b));
292 testing.expect(testHashShallow(a) != testHashShallow(c));292 try testing.expect(testHashShallow(a) != testHashShallow(c));
293}293}
294294
295test "hash slice deep" {295test "hash slice deep" {
...@@ -302,10 +302,10 @@ test "hash slice deep" {...@@ -302,10 +302,10 @@ test "hash slice deep" {
302 const a = array1[0..];302 const a = array1[0..];
303 const b = array2[0..];303 const b = array2[0..];
304 const c = array1[0..3];304 const c = array1[0..3];
305 testing.expect(testHashDeep(a) == testHashDeep(a));305 try testing.expect(testHashDeep(a) == testHashDeep(a));
306 testing.expect(testHashDeep(a) == testHashDeep(array1));306 try testing.expect(testHashDeep(a) == testHashDeep(array1));
307 testing.expect(testHashDeep(a) == testHashDeep(b));307 try testing.expect(testHashDeep(a) == testHashDeep(b));
308 testing.expect(testHashDeep(a) != testHashDeep(c));308 try testing.expect(testHashDeep(a) != testHashDeep(c));
309}309}
310310
311test "hash struct deep" {311test "hash struct deep" {
...@@ -331,28 +331,28 @@ test "hash struct deep" {...@@ -331,28 +331,28 @@ test "hash struct deep" {
331 defer allocator.destroy(bar.c);331 defer allocator.destroy(bar.c);
332 defer allocator.destroy(baz.c);332 defer allocator.destroy(baz.c);
333333
334 testing.expect(testHashDeep(foo) == testHashDeep(bar));334 try testing.expect(testHashDeep(foo) == testHashDeep(bar));
335 testing.expect(testHashDeep(foo) != testHashDeep(baz));335 try testing.expect(testHashDeep(foo) != testHashDeep(baz));
336 testing.expect(testHashDeep(bar) != testHashDeep(baz));336 try testing.expect(testHashDeep(bar) != testHashDeep(baz));
337337
338 var hasher = Wyhash.init(0);338 var hasher = Wyhash.init(0);
339 const h = testHashDeep(foo);339 const h = testHashDeep(foo);
340 autoHash(&hasher, foo.a);340 autoHash(&hasher, foo.a);
341 autoHash(&hasher, foo.b);341 autoHash(&hasher, foo.b);
342 autoHash(&hasher, foo.c.*);342 autoHash(&hasher, foo.c.*);
343 testing.expectEqual(h, hasher.final());343 try testing.expectEqual(h, hasher.final());
344344
345 const h2 = testHashDeepRecursive(&foo);345 const h2 = testHashDeepRecursive(&foo);
346 testing.expect(h2 != testHashDeep(&foo));346 try testing.expect(h2 != testHashDeep(&foo));
347 testing.expect(h2 == testHashDeep(foo));347 try testing.expect(h2 == testHashDeep(foo));
348}348}
349349
350test "testHash optional" {350test "testHash optional" {
351 const a: ?u32 = 123;351 const a: ?u32 = 123;
352 const b: ?u32 = null;352 const b: ?u32 = null;
353 testing.expectEqual(testHash(a), testHash(@as(u32, 123)));353 try testing.expectEqual(testHash(a), testHash(@as(u32, 123)));
354 testing.expect(testHash(a) != testHash(b));354 try testing.expect(testHash(a) != testHash(b));
355 testing.expectEqual(testHash(b), 0);355 try testing.expectEqual(testHash(b), 0);
356}356}
357357
358test "testHash array" {358test "testHash array" {
...@@ -362,7 +362,7 @@ test "testHash array" {...@@ -362,7 +362,7 @@ test "testHash array" {
362 autoHash(&hasher, @as(u32, 1));362 autoHash(&hasher, @as(u32, 1));
363 autoHash(&hasher, @as(u32, 2));363 autoHash(&hasher, @as(u32, 2));
364 autoHash(&hasher, @as(u32, 3));364 autoHash(&hasher, @as(u32, 3));
365 testing.expectEqual(h, hasher.final());365 try testing.expectEqual(h, hasher.final());
366}366}
367367
368test "testHash struct" {368test "testHash struct" {
...@@ -377,7 +377,7 @@ test "testHash struct" {...@@ -377,7 +377,7 @@ test "testHash struct" {
377 autoHash(&hasher, @as(u32, 1));377 autoHash(&hasher, @as(u32, 1));
378 autoHash(&hasher, @as(u32, 2));378 autoHash(&hasher, @as(u32, 2));
379 autoHash(&hasher, @as(u32, 3));379 autoHash(&hasher, @as(u32, 3));
380 testing.expectEqual(h, hasher.final());380 try testing.expectEqual(h, hasher.final());
381}381}
382382
383test "testHash union" {383test "testHash union" {
...@@ -390,12 +390,12 @@ test "testHash union" {...@@ -390,12 +390,12 @@ test "testHash union" {
390 const a = Foo{ .A = 18 };390 const a = Foo{ .A = 18 };
391 var b = Foo{ .B = true };391 var b = Foo{ .B = true };
392 const c = Foo{ .C = 18 };392 const c = Foo{ .C = 18 };
393 testing.expect(testHash(a) == testHash(a));393 try testing.expect(testHash(a) == testHash(a));
394 testing.expect(testHash(a) != testHash(b));394 try testing.expect(testHash(a) != testHash(b));
395 testing.expect(testHash(a) != testHash(c));395 try testing.expect(testHash(a) != testHash(c));
396396
397 b = Foo{ .A = 18 };397 b = Foo{ .A = 18 };
398 testing.expect(testHash(a) == testHash(b));398 try testing.expect(testHash(a) == testHash(b));
399}399}
400400
401test "testHash vector" {401test "testHash vector" {
...@@ -404,13 +404,13 @@ test "testHash vector" {...@@ -404,13 +404,13 @@ test "testHash vector" {
404404
405 const a: meta.Vector(4, u32) = [_]u32{ 1, 2, 3, 4 };405 const a: meta.Vector(4, u32) = [_]u32{ 1, 2, 3, 4 };
406 const b: meta.Vector(4, u32) = [_]u32{ 1, 2, 3, 5 };406 const b: meta.Vector(4, u32) = [_]u32{ 1, 2, 3, 5 };
407 testing.expect(testHash(a) == testHash(a));407 try testing.expect(testHash(a) == testHash(a));
408 testing.expect(testHash(a) != testHash(b));408 try testing.expect(testHash(a) != testHash(b));
409409
410 const c: meta.Vector(4, u31) = [_]u31{ 1, 2, 3, 4 };410 const c: meta.Vector(4, u31) = [_]u31{ 1, 2, 3, 4 };
411 const d: meta.Vector(4, u31) = [_]u31{ 1, 2, 3, 5 };411 const d: meta.Vector(4, u31) = [_]u31{ 1, 2, 3, 5 };
412 testing.expect(testHash(c) == testHash(c));412 try testing.expect(testHash(c) == testHash(c));
413 testing.expect(testHash(c) != testHash(d));413 try testing.expect(testHash(c) != testHash(d));
414}414}
415415
416test "testHash error union" {416test "testHash error union" {
...@@ -422,7 +422,7 @@ test "testHash error union" {...@@ -422,7 +422,7 @@ test "testHash error union" {
422 };422 };
423 const f = Foo{};423 const f = Foo{};
424 const g: Errors!Foo = Errors.Test;424 const g: Errors!Foo = Errors.Test;
425 testing.expect(testHash(f) != testHash(g));425 try testing.expect(testHash(f) != testHash(g));
426 testing.expect(testHash(f) == testHash(Foo{}));426 try testing.expect(testHash(f) == testHash(Foo{}));
427 testing.expect(testHash(g) == testHash(Errors.Test));427 try testing.expect(testHash(g) == testHash(Errors.Test));
428}428}
lib/std/hash/cityhash.zig+7-7
...@@ -381,14 +381,14 @@ fn CityHash32hashIgnoreSeed(str: []const u8, seed: u32) u32 {...@@ -381,14 +381,14 @@ fn CityHash32hashIgnoreSeed(str: []const u8, seed: u32) u32 {
381381
382test "cityhash32" {382test "cityhash32" {
383 const Test = struct {383 const Test = struct {
384 fn doTest() void {384 fn doTest() !void {
385 // Note: SMHasher doesn't provide a 32bit version of the algorithm.385 // Note: SMHasher doesn't provide a 32bit version of the algorithm.
386 // Note: The implementation was verified against the Google Abseil version.386 // Note: The implementation was verified against the Google Abseil version.
387 std.testing.expectEqual(SMHasherTest(CityHash32hashIgnoreSeed), 0x68254F81);387 try std.testing.expectEqual(SMHasherTest(CityHash32hashIgnoreSeed), 0x68254F81);
388 std.testing.expectEqual(SMHasherTest(CityHash32hashIgnoreSeed), 0x68254F81);388 try std.testing.expectEqual(SMHasherTest(CityHash32hashIgnoreSeed), 0x68254F81);
389 }389 }
390 };390 };
391 Test.doTest();391 try Test.doTest();
392 // TODO This is uncommented to prevent OOM on the CI server. Re-enable this test392 // TODO This is uncommented to prevent OOM on the CI server. Re-enable this test
393 // case once we ship stage2.393 // case once we ship stage2.
394 //@setEvalBranchQuota(50000);394 //@setEvalBranchQuota(50000);
...@@ -397,13 +397,13 @@ test "cityhash32" {...@@ -397,13 +397,13 @@ test "cityhash32" {
397397
398test "cityhash64" {398test "cityhash64" {
399 const Test = struct {399 const Test = struct {
400 fn doTest() void {400 fn doTest() !void {
401 // Note: This is not compliant with the SMHasher implementation of CityHash64!401 // Note: This is not compliant with the SMHasher implementation of CityHash64!
402 // Note: The implementation was verified against the Google Abseil version.402 // Note: The implementation was verified against the Google Abseil version.
403 std.testing.expectEqual(SMHasherTest(CityHash64.hashWithSeed), 0x5FABC5C5);403 try std.testing.expectEqual(SMHasherTest(CityHash64.hashWithSeed), 0x5FABC5C5);
404 }404 }
405 };405 };
406 Test.doTest();406 try Test.doTest();
407 // TODO This is uncommented to prevent OOM on the CI server. Re-enable this test407 // TODO This is uncommented to prevent OOM on the CI server. Re-enable this test
408 // case once we ship stage2.408 // case once we ship stage2.
409 //@setEvalBranchQuota(50000);409 //@setEvalBranchQuota(50000);
lib/std/hash/crc.zig+12-12
...@@ -109,9 +109,9 @@ test "crc32 ieee" {...@@ -109,9 +109,9 @@ test "crc32 ieee" {
109109
110 const Crc32Ieee = Crc32WithPoly(.IEEE);110 const Crc32Ieee = Crc32WithPoly(.IEEE);
111111
112 testing.expect(Crc32Ieee.hash("") == 0x00000000);112 try testing.expect(Crc32Ieee.hash("") == 0x00000000);
113 testing.expect(Crc32Ieee.hash("a") == 0xe8b7be43);113 try testing.expect(Crc32Ieee.hash("a") == 0xe8b7be43);
114 testing.expect(Crc32Ieee.hash("abc") == 0x352441c2);114 try testing.expect(Crc32Ieee.hash("abc") == 0x352441c2);
115}115}
116116
117test "crc32 castagnoli" {117test "crc32 castagnoli" {
...@@ -119,9 +119,9 @@ test "crc32 castagnoli" {...@@ -119,9 +119,9 @@ test "crc32 castagnoli" {
119119
120 const Crc32Castagnoli = Crc32WithPoly(.Castagnoli);120 const Crc32Castagnoli = Crc32WithPoly(.Castagnoli);
121121
122 testing.expect(Crc32Castagnoli.hash("") == 0x00000000);122 try testing.expect(Crc32Castagnoli.hash("") == 0x00000000);
123 testing.expect(Crc32Castagnoli.hash("a") == 0xc1d04330);123 try testing.expect(Crc32Castagnoli.hash("a") == 0xc1d04330);
124 testing.expect(Crc32Castagnoli.hash("abc") == 0x364b3fb7);124 try testing.expect(Crc32Castagnoli.hash("abc") == 0x364b3fb7);
125}125}
126126
127// half-byte lookup table implementation.127// half-byte lookup table implementation.
...@@ -177,9 +177,9 @@ test "small crc32 ieee" {...@@ -177,9 +177,9 @@ test "small crc32 ieee" {
177177
178 const Crc32Ieee = Crc32SmallWithPoly(.IEEE);178 const Crc32Ieee = Crc32SmallWithPoly(.IEEE);
179179
180 testing.expect(Crc32Ieee.hash("") == 0x00000000);180 try testing.expect(Crc32Ieee.hash("") == 0x00000000);
181 testing.expect(Crc32Ieee.hash("a") == 0xe8b7be43);181 try testing.expect(Crc32Ieee.hash("a") == 0xe8b7be43);
182 testing.expect(Crc32Ieee.hash("abc") == 0x352441c2);182 try testing.expect(Crc32Ieee.hash("abc") == 0x352441c2);
183}183}
184184
185test "small crc32 castagnoli" {185test "small crc32 castagnoli" {
...@@ -187,7 +187,7 @@ test "small crc32 castagnoli" {...@@ -187,7 +187,7 @@ test "small crc32 castagnoli" {
187187
188 const Crc32Castagnoli = Crc32SmallWithPoly(.Castagnoli);188 const Crc32Castagnoli = Crc32SmallWithPoly(.Castagnoli);
189189
190 testing.expect(Crc32Castagnoli.hash("") == 0x00000000);190 try testing.expect(Crc32Castagnoli.hash("") == 0x00000000);
191 testing.expect(Crc32Castagnoli.hash("a") == 0xc1d04330);191 try testing.expect(Crc32Castagnoli.hash("a") == 0xc1d04330);
192 testing.expect(Crc32Castagnoli.hash("abc") == 0x364b3fb7);192 try testing.expect(Crc32Castagnoli.hash("abc") == 0x364b3fb7);
193}193}
lib/std/hash/fnv.zig+8-8
...@@ -46,18 +46,18 @@ fn Fnv1a(comptime T: type, comptime prime: T, comptime offset: T) type {...@@ -46,18 +46,18 @@ fn Fnv1a(comptime T: type, comptime prime: T, comptime offset: T) type {
46}46}
4747
48test "fnv1a-32" {48test "fnv1a-32" {
49 testing.expect(Fnv1a_32.hash("") == 0x811c9dc5);49 try testing.expect(Fnv1a_32.hash("") == 0x811c9dc5);
50 testing.expect(Fnv1a_32.hash("a") == 0xe40c292c);50 try testing.expect(Fnv1a_32.hash("a") == 0xe40c292c);
51 testing.expect(Fnv1a_32.hash("foobar") == 0xbf9cf968);51 try testing.expect(Fnv1a_32.hash("foobar") == 0xbf9cf968);
52}52}
5353
54test "fnv1a-64" {54test "fnv1a-64" {
55 testing.expect(Fnv1a_64.hash("") == 0xcbf29ce484222325);55 try testing.expect(Fnv1a_64.hash("") == 0xcbf29ce484222325);
56 testing.expect(Fnv1a_64.hash("a") == 0xaf63dc4c8601ec8c);56 try testing.expect(Fnv1a_64.hash("a") == 0xaf63dc4c8601ec8c);
57 testing.expect(Fnv1a_64.hash("foobar") == 0x85944171f73967e8);57 try testing.expect(Fnv1a_64.hash("foobar") == 0x85944171f73967e8);
58}58}
5959
60test "fnv1a-128" {60test "fnv1a-128" {
61 testing.expect(Fnv1a_128.hash("") == 0x6c62272e07bb014262b821756295c58d);61 try testing.expect(Fnv1a_128.hash("") == 0x6c62272e07bb014262b821756295c58d);
62 testing.expect(Fnv1a_128.hash("a") == 0xd228cb696f1a8caf78912b704e4a8964);62 try testing.expect(Fnv1a_128.hash("a") == 0xd228cb696f1a8caf78912b704e4a8964);
63}63}
lib/std/hash/murmur.zig+9-9
...@@ -308,7 +308,7 @@ fn SMHasherTest(comptime hash_fn: anytype, comptime hashbits: u32) u32 {...@@ -308,7 +308,7 @@ fn SMHasherTest(comptime hash_fn: anytype, comptime hashbits: u32) u32 {
308}308}
309309
310test "murmur2_32" {310test "murmur2_32" {
311 testing.expectEqual(SMHasherTest(Murmur2_32.hashWithSeed, 32), 0x27864C1E);311 try testing.expectEqual(SMHasherTest(Murmur2_32.hashWithSeed, 32), 0x27864C1E);
312 var v0: u32 = 0x12345678;312 var v0: u32 = 0x12345678;
313 var v1: u64 = 0x1234567812345678;313 var v1: u64 = 0x1234567812345678;
314 var v0le: u32 = v0;314 var v0le: u32 = v0;
...@@ -317,12 +317,12 @@ test "murmur2_32" {...@@ -317,12 +317,12 @@ test "murmur2_32" {
317 v0le = @byteSwap(u32, v0le);317 v0le = @byteSwap(u32, v0le);
318 v1le = @byteSwap(u64, v1le);318 v1le = @byteSwap(u64, v1le);
319 }319 }
320 testing.expectEqual(Murmur2_32.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur2_32.hashUint32(v0));320 try testing.expectEqual(Murmur2_32.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur2_32.hashUint32(v0));
321 testing.expectEqual(Murmur2_32.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur2_32.hashUint64(v1));321 try testing.expectEqual(Murmur2_32.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur2_32.hashUint64(v1));
322}322}
323323
324test "murmur2_64" {324test "murmur2_64" {
325 std.testing.expectEqual(SMHasherTest(Murmur2_64.hashWithSeed, 64), 0x1F0D3804);325 try std.testing.expectEqual(SMHasherTest(Murmur2_64.hashWithSeed, 64), 0x1F0D3804);
326 var v0: u32 = 0x12345678;326 var v0: u32 = 0x12345678;
327 var v1: u64 = 0x1234567812345678;327 var v1: u64 = 0x1234567812345678;
328 var v0le: u32 = v0;328 var v0le: u32 = v0;
...@@ -331,12 +331,12 @@ test "murmur2_64" {...@@ -331,12 +331,12 @@ test "murmur2_64" {
331 v0le = @byteSwap(u32, v0le);331 v0le = @byteSwap(u32, v0le);
332 v1le = @byteSwap(u64, v1le);332 v1le = @byteSwap(u64, v1le);
333 }333 }
334 testing.expectEqual(Murmur2_64.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur2_64.hashUint32(v0));334 try testing.expectEqual(Murmur2_64.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur2_64.hashUint32(v0));
335 testing.expectEqual(Murmur2_64.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur2_64.hashUint64(v1));335 try testing.expectEqual(Murmur2_64.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur2_64.hashUint64(v1));
336}336}
337337
338test "murmur3_32" {338test "murmur3_32" {
339 std.testing.expectEqual(SMHasherTest(Murmur3_32.hashWithSeed, 32), 0xB0F57EE3);339 try std.testing.expectEqual(SMHasherTest(Murmur3_32.hashWithSeed, 32), 0xB0F57EE3);
340 var v0: u32 = 0x12345678;340 var v0: u32 = 0x12345678;
341 var v1: u64 = 0x1234567812345678;341 var v1: u64 = 0x1234567812345678;
342 var v0le: u32 = v0;342 var v0le: u32 = v0;
...@@ -345,6 +345,6 @@ test "murmur3_32" {...@@ -345,6 +345,6 @@ test "murmur3_32" {
345 v0le = @byteSwap(u32, v0le);345 v0le = @byteSwap(u32, v0le);
346 v1le = @byteSwap(u64, v1le);346 v1le = @byteSwap(u64, v1le);
347 }347 }
348 testing.expectEqual(Murmur3_32.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur3_32.hashUint32(v0));348 try testing.expectEqual(Murmur3_32.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur3_32.hashUint32(v0));
349 testing.expectEqual(Murmur3_32.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur3_32.hashUint64(v1));349 try testing.expectEqual(Murmur3_32.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur3_32.hashUint64(v1));
350}350}
lib/std/hash/wyhash.zig+11-11
...@@ -183,13 +183,13 @@ const expectEqual = std.testing.expectEqual;...@@ -183,13 +183,13 @@ const expectEqual = std.testing.expectEqual;
183test "test vectors" {183test "test vectors" {
184 const hash = Wyhash.hash;184 const hash = Wyhash.hash;
185185
186 expectEqual(hash(0, ""), 0x0);186 try expectEqual(hash(0, ""), 0x0);
187 expectEqual(hash(1, "a"), 0xbed235177f41d328);187 try expectEqual(hash(1, "a"), 0xbed235177f41d328);
188 expectEqual(hash(2, "abc"), 0xbe348debe59b27c3);188 try expectEqual(hash(2, "abc"), 0xbe348debe59b27c3);
189 expectEqual(hash(3, "message digest"), 0x37320f657213a290);189 try expectEqual(hash(3, "message digest"), 0x37320f657213a290);
190 expectEqual(hash(4, "abcdefghijklmnopqrstuvwxyz"), 0xd0b270e1d8a7019c);190 try expectEqual(hash(4, "abcdefghijklmnopqrstuvwxyz"), 0xd0b270e1d8a7019c);
191 expectEqual(hash(5, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"), 0x602a1894d3bbfe7f);191 try expectEqual(hash(5, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"), 0x602a1894d3bbfe7f);
192 expectEqual(hash(6, "12345678901234567890123456789012345678901234567890123456789012345678901234567890"), 0x829e9c148b75970e);192 try expectEqual(hash(6, "12345678901234567890123456789012345678901234567890123456789012345678901234567890"), 0x829e9c148b75970e);
193}193}
194194
195test "test vectors streaming" {195test "test vectors streaming" {
...@@ -197,19 +197,19 @@ test "test vectors streaming" {...@@ -197,19 +197,19 @@ test "test vectors streaming" {
197 for ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") |e| {197 for ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") |e| {
198 wh.update(mem.asBytes(&e));198 wh.update(mem.asBytes(&e));
199 }199 }
200 expectEqual(wh.final(), 0x602a1894d3bbfe7f);200 try expectEqual(wh.final(), 0x602a1894d3bbfe7f);
201201
202 const pattern = "1234567890";202 const pattern = "1234567890";
203 const count = 8;203 const count = 8;
204 const result = 0x829e9c148b75970e;204 const result = 0x829e9c148b75970e;
205 expectEqual(Wyhash.hash(6, pattern ** 8), result);205 try expectEqual(Wyhash.hash(6, pattern ** 8), result);
206206
207 wh = Wyhash.init(6);207 wh = Wyhash.init(6);
208 var i: u32 = 0;208 var i: u32 = 0;
209 while (i < count) : (i += 1) {209 while (i < count) : (i += 1) {
210 wh.update(pattern);210 wh.update(pattern);
211 }211 }
212 expectEqual(wh.final(), result);212 try expectEqual(wh.final(), result);
213}213}
214214
215test "iterative non-divisible update" {215test "iterative non-divisible update" {
...@@ -231,6 +231,6 @@ test "iterative non-divisible update" {...@@ -231,6 +231,6 @@ test "iterative non-divisible update" {
231 }231 }
232 const iterative_hash = wy.final();232 const iterative_hash = wy.final();
233233
234 std.testing.expectEqual(iterative_hash, non_iterative_hash);234 try std.testing.expectEqual(iterative_hash, non_iterative_hash);
235 }235 }
236}236}
lib/std/hash_map.zig+72-72
...@@ -824,15 +824,15 @@ test "std.hash_map basic usage" {...@@ -824,15 +824,15 @@ test "std.hash_map basic usage" {
824 while (it.next()) |kv| {824 while (it.next()) |kv| {
825 sum += kv.key;825 sum += kv.key;
826 }826 }
827 expect(sum == total);827 try expect(sum == total);
828828
829 i = 0;829 i = 0;
830 sum = 0;830 sum = 0;
831 while (i < count) : (i += 1) {831 while (i < count) : (i += 1) {
832 expectEqual(map.get(i).?, i);832 try expectEqual(map.get(i).?, i);
833 sum += map.get(i).?;833 sum += map.get(i).?;
834 }834 }
835 expectEqual(total, sum);835 try expectEqual(total, sum);
836}836}
837837
838test "std.hash_map ensureCapacity" {838test "std.hash_map ensureCapacity" {
...@@ -841,13 +841,13 @@ test "std.hash_map ensureCapacity" {...@@ -841,13 +841,13 @@ test "std.hash_map ensureCapacity" {
841841
842 try map.ensureCapacity(20);842 try map.ensureCapacity(20);
843 const initial_capacity = map.capacity();843 const initial_capacity = map.capacity();
844 testing.expect(initial_capacity >= 20);844 try testing.expect(initial_capacity >= 20);
845 var i: i32 = 0;845 var i: i32 = 0;
846 while (i < 20) : (i += 1) {846 while (i < 20) : (i += 1) {
847 testing.expect(map.fetchPutAssumeCapacity(i, i + 10) == null);847 try testing.expect(map.fetchPutAssumeCapacity(i, i + 10) == null);
848 }848 }
849 // shouldn't resize from putAssumeCapacity849 // shouldn't resize from putAssumeCapacity
850 testing.expect(initial_capacity == map.capacity());850 try testing.expect(initial_capacity == map.capacity());
851}851}
852852
853test "std.hash_map ensureCapacity with tombstones" {853test "std.hash_map ensureCapacity with tombstones" {
...@@ -870,22 +870,22 @@ test "std.hash_map clearRetainingCapacity" {...@@ -870,22 +870,22 @@ test "std.hash_map clearRetainingCapacity" {
870 map.clearRetainingCapacity();870 map.clearRetainingCapacity();
871871
872 try map.put(1, 1);872 try map.put(1, 1);
873 expectEqual(map.get(1).?, 1);873 try expectEqual(map.get(1).?, 1);
874 expectEqual(map.count(), 1);874 try expectEqual(map.count(), 1);
875875
876 map.clearRetainingCapacity();876 map.clearRetainingCapacity();
877 map.putAssumeCapacity(1, 1);877 map.putAssumeCapacity(1, 1);
878 expectEqual(map.get(1).?, 1);878 try expectEqual(map.get(1).?, 1);
879 expectEqual(map.count(), 1);879 try expectEqual(map.count(), 1);
880880
881 const cap = map.capacity();881 const cap = map.capacity();
882 expect(cap > 0);882 try expect(cap > 0);
883883
884 map.clearRetainingCapacity();884 map.clearRetainingCapacity();
885 map.clearRetainingCapacity();885 map.clearRetainingCapacity();
886 expectEqual(map.count(), 0);886 try expectEqual(map.count(), 0);
887 expectEqual(map.capacity(), cap);887 try expectEqual(map.capacity(), cap);
888 expect(!map.contains(1));888 try expect(!map.contains(1));
889}889}
890890
891test "std.hash_map grow" {891test "std.hash_map grow" {
...@@ -898,19 +898,19 @@ test "std.hash_map grow" {...@@ -898,19 +898,19 @@ test "std.hash_map grow" {
898 while (i < growTo) : (i += 1) {898 while (i < growTo) : (i += 1) {
899 try map.put(i, i);899 try map.put(i, i);
900 }900 }
901 expectEqual(map.count(), growTo);901 try expectEqual(map.count(), growTo);
902902
903 i = 0;903 i = 0;
904 var it = map.iterator();904 var it = map.iterator();
905 while (it.next()) |kv| {905 while (it.next()) |kv| {
906 expectEqual(kv.key, kv.value);906 try expectEqual(kv.key, kv.value);
907 i += 1;907 i += 1;
908 }908 }
909 expectEqual(i, growTo);909 try expectEqual(i, growTo);
910910
911 i = 0;911 i = 0;
912 while (i < growTo) : (i += 1) {912 while (i < growTo) : (i += 1) {
913 expectEqual(map.get(i).?, i);913 try expectEqual(map.get(i).?, i);
914 }914 }
915}915}
916916
...@@ -921,7 +921,7 @@ test "std.hash_map clone" {...@@ -921,7 +921,7 @@ test "std.hash_map clone" {
921 var a = try map.clone();921 var a = try map.clone();
922 defer a.deinit();922 defer a.deinit();
923923
924 expectEqual(a.count(), 0);924 try expectEqual(a.count(), 0);
925925
926 try a.put(1, 1);926 try a.put(1, 1);
927 try a.put(2, 2);927 try a.put(2, 2);
...@@ -930,10 +930,10 @@ test "std.hash_map clone" {...@@ -930,10 +930,10 @@ test "std.hash_map clone" {
930 var b = try a.clone();930 var b = try a.clone();
931 defer b.deinit();931 defer b.deinit();
932932
933 expectEqual(b.count(), 3);933 try expectEqual(b.count(), 3);
934 expectEqual(b.get(1), 1);934 try expectEqual(b.get(1), 1);
935 expectEqual(b.get(2), 2);935 try expectEqual(b.get(2), 2);
936 expectEqual(b.get(3), 3);936 try expectEqual(b.get(3), 3);
937}937}
938938
939test "std.hash_map ensureCapacity with existing elements" {939test "std.hash_map ensureCapacity with existing elements" {
...@@ -941,12 +941,12 @@ test "std.hash_map ensureCapacity with existing elements" {...@@ -941,12 +941,12 @@ test "std.hash_map ensureCapacity with existing elements" {
941 defer map.deinit();941 defer map.deinit();
942942
943 try map.put(0, 0);943 try map.put(0, 0);
944 expectEqual(map.count(), 1);944 try expectEqual(map.count(), 1);
945 expectEqual(map.capacity(), @TypeOf(map).Unmanaged.minimal_capacity);945 try expectEqual(map.capacity(), @TypeOf(map).Unmanaged.minimal_capacity);
946946
947 try map.ensureCapacity(65);947 try map.ensureCapacity(65);
948 expectEqual(map.count(), 1);948 try expectEqual(map.count(), 1);
949 expectEqual(map.capacity(), 128);949 try expectEqual(map.capacity(), 128);
950}950}
951951
952test "std.hash_map ensureCapacity satisfies max load factor" {952test "std.hash_map ensureCapacity satisfies max load factor" {
...@@ -954,7 +954,7 @@ test "std.hash_map ensureCapacity satisfies max load factor" {...@@ -954,7 +954,7 @@ test "std.hash_map ensureCapacity satisfies max load factor" {
954 defer map.deinit();954 defer map.deinit();
955955
956 try map.ensureCapacity(127);956 try map.ensureCapacity(127);
957 expectEqual(map.capacity(), 256);957 try expectEqual(map.capacity(), 256);
958}958}
959959
960test "std.hash_map remove" {960test "std.hash_map remove" {
...@@ -972,19 +972,19 @@ test "std.hash_map remove" {...@@ -972,19 +972,19 @@ test "std.hash_map remove" {
972 _ = map.remove(i);972 _ = map.remove(i);
973 }973 }
974 }974 }
975 expectEqual(map.count(), 10);975 try expectEqual(map.count(), 10);
976 var it = map.iterator();976 var it = map.iterator();
977 while (it.next()) |kv| {977 while (it.next()) |kv| {
978 expectEqual(kv.key, kv.value);978 try expectEqual(kv.key, kv.value);
979 expect(kv.key % 3 != 0);979 try expect(kv.key % 3 != 0);
980 }980 }
981981
982 i = 0;982 i = 0;
983 while (i < 16) : (i += 1) {983 while (i < 16) : (i += 1) {
984 if (i % 3 == 0) {984 if (i % 3 == 0) {
985 expect(!map.contains(i));985 try expect(!map.contains(i));
986 } else {986 } else {
987 expectEqual(map.get(i).?, i);987 try expectEqual(map.get(i).?, i);
988 }988 }
989 }989 }
990}990}
...@@ -1001,14 +1001,14 @@ test "std.hash_map reverse removes" {...@@ -1001,14 +1001,14 @@ test "std.hash_map reverse removes" {
1001 i = 16;1001 i = 16;
1002 while (i > 0) : (i -= 1) {1002 while (i > 0) : (i -= 1) {
1003 _ = map.remove(i - 1);1003 _ = map.remove(i - 1);
1004 expect(!map.contains(i - 1));1004 try expect(!map.contains(i - 1));
1005 var j: u32 = 0;1005 var j: u32 = 0;
1006 while (j < i - 1) : (j += 1) {1006 while (j < i - 1) : (j += 1) {
1007 expectEqual(map.get(j).?, j);1007 try expectEqual(map.get(j).?, j);
1008 }1008 }
1009 }1009 }
10101010
1011 expectEqual(map.count(), 0);1011 try expectEqual(map.count(), 0);
1012}1012}
10131013
1014test "std.hash_map multiple removes on same metadata" {1014test "std.hash_map multiple removes on same metadata" {
...@@ -1024,17 +1024,17 @@ test "std.hash_map multiple removes on same metadata" {...@@ -1024,17 +1024,17 @@ test "std.hash_map multiple removes on same metadata" {
1024 _ = map.remove(15);1024 _ = map.remove(15);
1025 _ = map.remove(14);1025 _ = map.remove(14);
1026 _ = map.remove(13);1026 _ = map.remove(13);
1027 expect(!map.contains(7));1027 try expect(!map.contains(7));
1028 expect(!map.contains(15));1028 try expect(!map.contains(15));
1029 expect(!map.contains(14));1029 try expect(!map.contains(14));
1030 expect(!map.contains(13));1030 try expect(!map.contains(13));
10311031
1032 i = 0;1032 i = 0;
1033 while (i < 13) : (i += 1) {1033 while (i < 13) : (i += 1) {
1034 if (i == 7) {1034 if (i == 7) {
1035 expect(!map.contains(i));1035 try expect(!map.contains(i));
1036 } else {1036 } else {
1037 expectEqual(map.get(i).?, i);1037 try expectEqual(map.get(i).?, i);
1038 }1038 }
1039 }1039 }
10401040
...@@ -1044,7 +1044,7 @@ test "std.hash_map multiple removes on same metadata" {...@@ -1044,7 +1044,7 @@ test "std.hash_map multiple removes on same metadata" {
1044 try map.put(7, 7);1044 try map.put(7, 7);
1045 i = 0;1045 i = 0;
1046 while (i < 16) : (i += 1) {1046 while (i < 16) : (i += 1) {
1047 expectEqual(map.get(i).?, i);1047 try expectEqual(map.get(i).?, i);
1048 }1048 }
1049}1049}
10501050
...@@ -1070,12 +1070,12 @@ test "std.hash_map put and remove loop in random order" {...@@ -1070,12 +1070,12 @@ test "std.hash_map put and remove loop in random order" {
1070 for (keys.items) |key| {1070 for (keys.items) |key| {
1071 try map.put(key, key);1071 try map.put(key, key);
1072 }1072 }
1073 expectEqual(map.count(), size);1073 try expectEqual(map.count(), size);
10741074
1075 for (keys.items) |key| {1075 for (keys.items) |key| {
1076 _ = map.remove(key);1076 _ = map.remove(key);
1077 }1077 }
1078 expectEqual(map.count(), 0);1078 try expectEqual(map.count(), 0);
1079 }1079 }
1080}1080}
10811081
...@@ -1119,7 +1119,7 @@ test "std.hash_map put" {...@@ -1119,7 +1119,7 @@ test "std.hash_map put" {
11191119
1120 i = 0;1120 i = 0;
1121 while (i < 16) : (i += 1) {1121 while (i < 16) : (i += 1) {
1122 expectEqual(map.get(i).?, i);1122 try expectEqual(map.get(i).?, i);
1123 }1123 }
11241124
1125 i = 0;1125 i = 0;
...@@ -1129,7 +1129,7 @@ test "std.hash_map put" {...@@ -1129,7 +1129,7 @@ test "std.hash_map put" {
11291129
1130 i = 0;1130 i = 0;
1131 while (i < 16) : (i += 1) {1131 while (i < 16) : (i += 1) {
1132 expectEqual(map.get(i).?, i * 16 + 1);1132 try expectEqual(map.get(i).?, i * 16 + 1);
1133 }1133 }
1134}1134}
11351135
...@@ -1148,7 +1148,7 @@ test "std.hash_map putAssumeCapacity" {...@@ -1148,7 +1148,7 @@ test "std.hash_map putAssumeCapacity" {
1148 while (i < 20) : (i += 1) {1148 while (i < 20) : (i += 1) {
1149 sum += map.get(i).?;1149 sum += map.get(i).?;
1150 }1150 }
1151 expectEqual(sum, 190);1151 try expectEqual(sum, 190);
11521152
1153 i = 0;1153 i = 0;
1154 while (i < 20) : (i += 1) {1154 while (i < 20) : (i += 1) {
...@@ -1160,7 +1160,7 @@ test "std.hash_map putAssumeCapacity" {...@@ -1160,7 +1160,7 @@ test "std.hash_map putAssumeCapacity" {
1160 while (i < 20) : (i += 1) {1160 while (i < 20) : (i += 1) {
1161 sum += map.get(i).?;1161 sum += map.get(i).?;
1162 }1162 }
1163 expectEqual(sum, 20);1163 try expectEqual(sum, 20);
1164}1164}
11651165
1166test "std.hash_map getOrPut" {1166test "std.hash_map getOrPut" {
...@@ -1183,49 +1183,49 @@ test "std.hash_map getOrPut" {...@@ -1183,49 +1183,49 @@ test "std.hash_map getOrPut" {
1183 sum += map.get(i).?;1183 sum += map.get(i).?;
1184 }1184 }
11851185
1186 expectEqual(sum, 30);1186 try expectEqual(sum, 30);
1187}1187}
11881188
1189test "std.hash_map basic hash map usage" {1189test "std.hash_map basic hash map usage" {
1190 var map = AutoHashMap(i32, i32).init(std.testing.allocator);1190 var map = AutoHashMap(i32, i32).init(std.testing.allocator);
1191 defer map.deinit();1191 defer map.deinit();
11921192
1193 testing.expect((try map.fetchPut(1, 11)) == null);1193 try testing.expect((try map.fetchPut(1, 11)) == null);
1194 testing.expect((try map.fetchPut(2, 22)) == null);1194 try testing.expect((try map.fetchPut(2, 22)) == null);
1195 testing.expect((try map.fetchPut(3, 33)) == null);1195 try testing.expect((try map.fetchPut(3, 33)) == null);
1196 testing.expect((try map.fetchPut(4, 44)) == null);1196 try testing.expect((try map.fetchPut(4, 44)) == null);
11971197
1198 try map.putNoClobber(5, 55);1198 try map.putNoClobber(5, 55);
1199 testing.expect((try map.fetchPut(5, 66)).?.value == 55);1199 try testing.expect((try map.fetchPut(5, 66)).?.value == 55);
1200 testing.expect((try map.fetchPut(5, 55)).?.value == 66);1200 try testing.expect((try map.fetchPut(5, 55)).?.value == 66);
12011201
1202 const gop1 = try map.getOrPut(5);1202 const gop1 = try map.getOrPut(5);
1203 testing.expect(gop1.found_existing == true);1203 try testing.expect(gop1.found_existing == true);
1204 testing.expect(gop1.entry.value == 55);1204 try testing.expect(gop1.entry.value == 55);
1205 gop1.entry.value = 77;1205 gop1.entry.value = 77;
1206 testing.expect(map.getEntry(5).?.value == 77);1206 try testing.expect(map.getEntry(5).?.value == 77);
12071207
1208 const gop2 = try map.getOrPut(99);1208 const gop2 = try map.getOrPut(99);
1209 testing.expect(gop2.found_existing == false);1209 try testing.expect(gop2.found_existing == false);
1210 gop2.entry.value = 42;1210 gop2.entry.value = 42;
1211 testing.expect(map.getEntry(99).?.value == 42);1211 try testing.expect(map.getEntry(99).?.value == 42);
12121212
1213 const gop3 = try map.getOrPutValue(5, 5);1213 const gop3 = try map.getOrPutValue(5, 5);
1214 testing.expect(gop3.value == 77);1214 try testing.expect(gop3.value == 77);
12151215
1216 const gop4 = try map.getOrPutValue(100, 41);1216 const gop4 = try map.getOrPutValue(100, 41);
1217 testing.expect(gop4.value == 41);1217 try testing.expect(gop4.value == 41);
12181218
1219 testing.expect(map.contains(2));1219 try testing.expect(map.contains(2));
1220 testing.expect(map.getEntry(2).?.value == 22);1220 try testing.expect(map.getEntry(2).?.value == 22);
1221 testing.expect(map.get(2).? == 22);1221 try testing.expect(map.get(2).? == 22);
12221222
1223 const rmv1 = map.remove(2);1223 const rmv1 = map.remove(2);
1224 testing.expect(rmv1.?.key == 2);1224 try testing.expect(rmv1.?.key == 2);
1225 testing.expect(rmv1.?.value == 22);1225 try testing.expect(rmv1.?.value == 22);
1226 testing.expect(map.remove(2) == null);1226 try testing.expect(map.remove(2) == null);
1227 testing.expect(map.getEntry(2) == null);1227 try testing.expect(map.getEntry(2) == null);
1228 testing.expect(map.get(2) == null);1228 try testing.expect(map.get(2) == null);
12291229
1230 map.removeAssertDiscard(3);1230 map.removeAssertDiscard(3);
1231}1231}
...@@ -1244,6 +1244,6 @@ test "std.hash_map clone" {...@@ -1244,6 +1244,6 @@ test "std.hash_map clone" {
12441244
1245 i = 0;1245 i = 0;
1246 while (i < 10) : (i += 1) {1246 while (i < 10) : (i += 1) {
1247 testing.expect(copy.get(i).? == i * 10);1247 try testing.expect(copy.get(i).? == i * 10);
1248 }1248 }
1249}1249}
lib/std/heap.zig+43-43
...@@ -858,16 +858,16 @@ test "WasmPageAllocator internals" {...@@ -858,16 +858,16 @@ test "WasmPageAllocator internals" {
858 if (comptime std.Target.current.isWasm()) {858 if (comptime std.Target.current.isWasm()) {
859 const conventional_memsize = WasmPageAllocator.conventional.totalPages() * mem.page_size;859 const conventional_memsize = WasmPageAllocator.conventional.totalPages() * mem.page_size;
860 const initial = try page_allocator.alloc(u8, mem.page_size);860 const initial = try page_allocator.alloc(u8, mem.page_size);
861 testing.expect(@ptrToInt(initial.ptr) < conventional_memsize); // If this isn't conventional, the rest of these tests don't make sense. Also we have a serious memory leak in the test suite.861 try testing.expect(@ptrToInt(initial.ptr) < conventional_memsize); // If this isn't conventional, the rest of these tests don't make sense. Also we have a serious memory leak in the test suite.
862862
863 var inplace = try page_allocator.realloc(initial, 1);863 var inplace = try page_allocator.realloc(initial, 1);
864 testing.expectEqual(initial.ptr, inplace.ptr);864 try testing.expectEqual(initial.ptr, inplace.ptr);
865 inplace = try page_allocator.realloc(inplace, 4);865 inplace = try page_allocator.realloc(inplace, 4);
866 testing.expectEqual(initial.ptr, inplace.ptr);866 try testing.expectEqual(initial.ptr, inplace.ptr);
867 page_allocator.free(inplace);867 page_allocator.free(inplace);
868868
869 const reuse = try page_allocator.alloc(u8, 1);869 const reuse = try page_allocator.alloc(u8, 1);
870 testing.expectEqual(initial.ptr, reuse.ptr);870 try testing.expectEqual(initial.ptr, reuse.ptr);
871 page_allocator.free(reuse);871 page_allocator.free(reuse);
872872
873 // This segment may span conventional and extended which has really complex rules so we're just ignoring it for now.873 // This segment may span conventional and extended which has really complex rules so we're just ignoring it for now.
...@@ -875,18 +875,18 @@ test "WasmPageAllocator internals" {...@@ -875,18 +875,18 @@ test "WasmPageAllocator internals" {
875 page_allocator.free(padding);875 page_allocator.free(padding);
876876
877 const extended = try page_allocator.alloc(u8, conventional_memsize);877 const extended = try page_allocator.alloc(u8, conventional_memsize);
878 testing.expect(@ptrToInt(extended.ptr) >= conventional_memsize);878 try testing.expect(@ptrToInt(extended.ptr) >= conventional_memsize);
879879
880 const use_small = try page_allocator.alloc(u8, 1);880 const use_small = try page_allocator.alloc(u8, 1);
881 testing.expectEqual(initial.ptr, use_small.ptr);881 try testing.expectEqual(initial.ptr, use_small.ptr);
882 page_allocator.free(use_small);882 page_allocator.free(use_small);
883883
884 inplace = try page_allocator.realloc(extended, 1);884 inplace = try page_allocator.realloc(extended, 1);
885 testing.expectEqual(extended.ptr, inplace.ptr);885 try testing.expectEqual(extended.ptr, inplace.ptr);
886 page_allocator.free(inplace);886 page_allocator.free(inplace);
887887
888 const reuse_extended = try page_allocator.alloc(u8, conventional_memsize);888 const reuse_extended = try page_allocator.alloc(u8, conventional_memsize);
889 testing.expectEqual(extended.ptr, reuse_extended.ptr);889 try testing.expectEqual(extended.ptr, reuse_extended.ptr);
890 page_allocator.free(reuse_extended);890 page_allocator.free(reuse_extended);
891 }891 }
892}892}
...@@ -959,15 +959,15 @@ test "FixedBufferAllocator.reset" {...@@ -959,15 +959,15 @@ test "FixedBufferAllocator.reset" {
959959
960 var x = try fba.allocator.create(u64);960 var x = try fba.allocator.create(u64);
961 x.* = X;961 x.* = X;
962 testing.expectError(error.OutOfMemory, fba.allocator.create(u64));962 try testing.expectError(error.OutOfMemory, fba.allocator.create(u64));
963963
964 fba.reset();964 fba.reset();
965 var y = try fba.allocator.create(u64);965 var y = try fba.allocator.create(u64);
966 y.* = Y;966 y.* = Y;
967967
968 // we expect Y to have overwritten X.968 // we expect Y to have overwritten X.
969 testing.expect(x.* == y.*);969 try testing.expect(x.* == y.*);
970 testing.expect(y.* == Y);970 try testing.expect(y.* == Y);
971}971}
972972
973test "StackFallbackAllocator" {973test "StackFallbackAllocator" {
...@@ -987,11 +987,11 @@ test "FixedBufferAllocator Reuse memory on realloc" {...@@ -987,11 +987,11 @@ test "FixedBufferAllocator Reuse memory on realloc" {
987 var fixed_buffer_allocator = FixedBufferAllocator.init(small_fixed_buffer[0..]);987 var fixed_buffer_allocator = FixedBufferAllocator.init(small_fixed_buffer[0..]);
988988
989 var slice0 = try fixed_buffer_allocator.allocator.alloc(u8, 5);989 var slice0 = try fixed_buffer_allocator.allocator.alloc(u8, 5);
990 testing.expect(slice0.len == 5);990 try testing.expect(slice0.len == 5);
991 var slice1 = try fixed_buffer_allocator.allocator.realloc(slice0, 10);991 var slice1 = try fixed_buffer_allocator.allocator.realloc(slice0, 10);
992 testing.expect(slice1.ptr == slice0.ptr);992 try testing.expect(slice1.ptr == slice0.ptr);
993 testing.expect(slice1.len == 10);993 try testing.expect(slice1.len == 10);
994 testing.expectError(error.OutOfMemory, fixed_buffer_allocator.allocator.realloc(slice1, 11));994 try testing.expectError(error.OutOfMemory, fixed_buffer_allocator.allocator.realloc(slice1, 11));
995 }995 }
996 // check that we don't re-use the memory if it's not the most recent block996 // check that we don't re-use the memory if it's not the most recent block
997 {997 {
...@@ -1002,10 +1002,10 @@ test "FixedBufferAllocator Reuse memory on realloc" {...@@ -1002,10 +1002,10 @@ test "FixedBufferAllocator Reuse memory on realloc" {
1002 slice0[1] = 2;1002 slice0[1] = 2;
1003 var slice1 = try fixed_buffer_allocator.allocator.alloc(u8, 2);1003 var slice1 = try fixed_buffer_allocator.allocator.alloc(u8, 2);
1004 var slice2 = try fixed_buffer_allocator.allocator.realloc(slice0, 4);1004 var slice2 = try fixed_buffer_allocator.allocator.realloc(slice0, 4);
1005 testing.expect(slice0.ptr != slice2.ptr);1005 try testing.expect(slice0.ptr != slice2.ptr);
1006 testing.expect(slice1.ptr != slice2.ptr);1006 try testing.expect(slice1.ptr != slice2.ptr);
1007 testing.expect(slice2[0] == 1);1007 try testing.expect(slice2[0] == 1);
1008 testing.expect(slice2[1] == 2);1008 try testing.expect(slice2[1] == 2);
1009 }1009 }
1010}1010}
10111011
...@@ -1024,28 +1024,28 @@ pub fn testAllocator(base_allocator: *mem.Allocator) !void {...@@ -1024,28 +1024,28 @@ pub fn testAllocator(base_allocator: *mem.Allocator) !void {
1024 const allocator = &validationAllocator.allocator;1024 const allocator = &validationAllocator.allocator;
10251025
1026 var slice = try allocator.alloc(*i32, 100);1026 var slice = try allocator.alloc(*i32, 100);
1027 testing.expect(slice.len == 100);1027 try testing.expect(slice.len == 100);
1028 for (slice) |*item, i| {1028 for (slice) |*item, i| {
1029 item.* = try allocator.create(i32);1029 item.* = try allocator.create(i32);
1030 item.*.* = @intCast(i32, i);1030 item.*.* = @intCast(i32, i);
1031 }1031 }
10321032
1033 slice = try allocator.realloc(slice, 20000);1033 slice = try allocator.realloc(slice, 20000);
1034 testing.expect(slice.len == 20000);1034 try testing.expect(slice.len == 20000);
10351035
1036 for (slice[0..100]) |item, i| {1036 for (slice[0..100]) |item, i| {
1037 testing.expect(item.* == @intCast(i32, i));1037 try testing.expect(item.* == @intCast(i32, i));
1038 allocator.destroy(item);1038 allocator.destroy(item);
1039 }1039 }
10401040
1041 slice = allocator.shrink(slice, 50);1041 slice = allocator.shrink(slice, 50);
1042 testing.expect(slice.len == 50);1042 try testing.expect(slice.len == 50);
1043 slice = allocator.shrink(slice, 25);1043 slice = allocator.shrink(slice, 25);
1044 testing.expect(slice.len == 25);1044 try testing.expect(slice.len == 25);
1045 slice = allocator.shrink(slice, 0);1045 slice = allocator.shrink(slice, 0);
1046 testing.expect(slice.len == 0);1046 try testing.expect(slice.len == 0);
1047 slice = try allocator.realloc(slice, 10);1047 slice = try allocator.realloc(slice, 10);
1048 testing.expect(slice.len == 10);1048 try testing.expect(slice.len == 10);
10491049
1050 allocator.free(slice);1050 allocator.free(slice);
10511051
...@@ -1058,7 +1058,7 @@ pub fn testAllocator(base_allocator: *mem.Allocator) !void {...@@ -1058,7 +1058,7 @@ pub fn testAllocator(base_allocator: *mem.Allocator) !void {
1058 allocator.destroy(zero_bit_ptr);1058 allocator.destroy(zero_bit_ptr);
10591059
1060 const oversize = try allocator.allocAdvanced(u32, null, 5, .at_least);1060 const oversize = try allocator.allocAdvanced(u32, null, 5, .at_least);
1061 testing.expect(oversize.len >= 5);1061 try testing.expect(oversize.len >= 5);
1062 for (oversize) |*item| {1062 for (oversize) |*item| {
1063 item.* = 0xDEADBEEF;1063 item.* = 0xDEADBEEF;
1064 }1064 }
...@@ -1073,29 +1073,29 @@ pub fn testAllocatorAligned(base_allocator: *mem.Allocator) !void {...@@ -1073,29 +1073,29 @@ pub fn testAllocatorAligned(base_allocator: *mem.Allocator) !void {
1073 inline for ([_]u29{ 1, 2, 4, 8, 16, 32, 64 }) |alignment| {1073 inline for ([_]u29{ 1, 2, 4, 8, 16, 32, 64 }) |alignment| {
1074 // initial1074 // initial
1075 var slice = try allocator.alignedAlloc(u8, alignment, 10);1075 var slice = try allocator.alignedAlloc(u8, alignment, 10);
1076 testing.expect(slice.len == 10);1076 try testing.expect(slice.len == 10);
1077 // grow1077 // grow
1078 slice = try allocator.realloc(slice, 100);1078 slice = try allocator.realloc(slice, 100);
1079 testing.expect(slice.len == 100);1079 try testing.expect(slice.len == 100);
1080 // shrink1080 // shrink
1081 slice = allocator.shrink(slice, 10);1081 slice = allocator.shrink(slice, 10);
1082 testing.expect(slice.len == 10);1082 try testing.expect(slice.len == 10);
1083 // go to zero1083 // go to zero
1084 slice = allocator.shrink(slice, 0);1084 slice = allocator.shrink(slice, 0);
1085 testing.expect(slice.len == 0);1085 try testing.expect(slice.len == 0);
1086 // realloc from zero1086 // realloc from zero
1087 slice = try allocator.realloc(slice, 100);1087 slice = try allocator.realloc(slice, 100);
1088 testing.expect(slice.len == 100);1088 try testing.expect(slice.len == 100);
1089 // shrink with shrink1089 // shrink with shrink
1090 slice = allocator.shrink(slice, 10);1090 slice = allocator.shrink(slice, 10);
1091 testing.expect(slice.len == 10);1091 try testing.expect(slice.len == 10);
1092 // shrink to zero1092 // shrink to zero
1093 slice = allocator.shrink(slice, 0);1093 slice = allocator.shrink(slice, 0);
1094 testing.expect(slice.len == 0);1094 try testing.expect(slice.len == 0);
1095 }1095 }
1096}1096}
10971097
1098pub fn testAllocatorLargeAlignment(base_allocator: *mem.Allocator) mem.Allocator.Error!void {1098pub fn testAllocatorLargeAlignment(base_allocator: *mem.Allocator) !void {
1099 var validationAllocator = mem.validationWrap(base_allocator);1099 var validationAllocator = mem.validationWrap(base_allocator);
1100 const allocator = &validationAllocator.allocator;1100 const allocator = &validationAllocator.allocator;
11011101
...@@ -1110,24 +1110,24 @@ pub fn testAllocatorLargeAlignment(base_allocator: *mem.Allocator) mem.Allocator...@@ -1110,24 +1110,24 @@ pub fn testAllocatorLargeAlignment(base_allocator: *mem.Allocator) mem.Allocator
1110 _ = @shlWithOverflow(usize, ~@as(usize, 0), @as(USizeShift, @ctz(u29, large_align)), &align_mask);1110 _ = @shlWithOverflow(usize, ~@as(usize, 0), @as(USizeShift, @ctz(u29, large_align)), &align_mask);
11111111
1112 var slice = try allocator.alignedAlloc(u8, large_align, 500);1112 var slice = try allocator.alignedAlloc(u8, large_align, 500);
1113 testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));1113 try testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
11141114
1115 slice = allocator.shrink(slice, 100);1115 slice = allocator.shrink(slice, 100);
1116 testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));1116 try testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
11171117
1118 slice = try allocator.realloc(slice, 5000);1118 slice = try allocator.realloc(slice, 5000);
1119 testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));1119 try testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
11201120
1121 slice = allocator.shrink(slice, 10);1121 slice = allocator.shrink(slice, 10);
1122 testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));1122 try testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
11231123
1124 slice = try allocator.realloc(slice, 20000);1124 slice = try allocator.realloc(slice, 20000);
1125 testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));1125 try testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
11261126
1127 allocator.free(slice);1127 allocator.free(slice);
1128}1128}
11291129
1130pub fn testAllocatorAlignedShrink(base_allocator: *mem.Allocator) mem.Allocator.Error!void {1130pub fn testAllocatorAlignedShrink(base_allocator: *mem.Allocator) !void {
1131 var validationAllocator = mem.validationWrap(base_allocator);1131 var validationAllocator = mem.validationWrap(base_allocator);
1132 const allocator = &validationAllocator.allocator;1132 const allocator = &validationAllocator.allocator;
11331133
...@@ -1155,8 +1155,8 @@ pub fn testAllocatorAlignedShrink(base_allocator: *mem.Allocator) mem.Allocator....@@ -1155,8 +1155,8 @@ pub fn testAllocatorAlignedShrink(base_allocator: *mem.Allocator) mem.Allocator.
11551155
1156 // realloc to a smaller size but with a larger alignment1156 // realloc to a smaller size but with a larger alignment
1157 slice = try allocator.reallocAdvanced(slice, mem.page_size * 32, alloc_size / 2, .exact);1157 slice = try allocator.reallocAdvanced(slice, mem.page_size * 32, alloc_size / 2, .exact);
1158 testing.expect(slice[0] == 0x12);1158 try testing.expect(slice[0] == 0x12);
1159 testing.expect(slice[60] == 0x34);1159 try testing.expect(slice[60] == 0x34);
1160}1160}
11611161
1162test "heap" {1162test "heap" {
lib/std/heap/general_purpose_allocator.zig+50-50
...@@ -692,7 +692,7 @@ const test_config = Config{};...@@ -692,7 +692,7 @@ const test_config = Config{};
692692
693test "small allocations - free in same order" {693test "small allocations - free in same order" {
694 var gpa = GeneralPurposeAllocator(test_config){};694 var gpa = GeneralPurposeAllocator(test_config){};
695 defer std.testing.expect(!gpa.deinit());695 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
696 const allocator = &gpa.allocator;696 const allocator = &gpa.allocator;
697697
698 var list = std.ArrayList(*u64).init(std.testing.allocator);698 var list = std.ArrayList(*u64).init(std.testing.allocator);
...@@ -711,7 +711,7 @@ test "small allocations - free in same order" {...@@ -711,7 +711,7 @@ test "small allocations - free in same order" {
711711
712test "small allocations - free in reverse order" {712test "small allocations - free in reverse order" {
713 var gpa = GeneralPurposeAllocator(test_config){};713 var gpa = GeneralPurposeAllocator(test_config){};
714 defer std.testing.expect(!gpa.deinit());714 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
715 const allocator = &gpa.allocator;715 const allocator = &gpa.allocator;
716716
717 var list = std.ArrayList(*u64).init(std.testing.allocator);717 var list = std.ArrayList(*u64).init(std.testing.allocator);
...@@ -730,7 +730,7 @@ test "small allocations - free in reverse order" {...@@ -730,7 +730,7 @@ test "small allocations - free in reverse order" {
730730
731test "large allocations" {731test "large allocations" {
732 var gpa = GeneralPurposeAllocator(test_config){};732 var gpa = GeneralPurposeAllocator(test_config){};
733 defer std.testing.expect(!gpa.deinit());733 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
734 const allocator = &gpa.allocator;734 const allocator = &gpa.allocator;
735735
736 const ptr1 = try allocator.alloc(u64, 42768);736 const ptr1 = try allocator.alloc(u64, 42768);
...@@ -743,7 +743,7 @@ test "large allocations" {...@@ -743,7 +743,7 @@ test "large allocations" {
743743
744test "realloc" {744test "realloc" {
745 var gpa = GeneralPurposeAllocator(test_config){};745 var gpa = GeneralPurposeAllocator(test_config){};
746 defer std.testing.expect(!gpa.deinit());746 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
747 const allocator = &gpa.allocator;747 const allocator = &gpa.allocator;
748748
749 var slice = try allocator.alignedAlloc(u8, @alignOf(u32), 1);749 var slice = try allocator.alignedAlloc(u8, @alignOf(u32), 1);
...@@ -753,19 +753,19 @@ test "realloc" {...@@ -753,19 +753,19 @@ test "realloc" {
753 // This reallocation should keep its pointer address.753 // This reallocation should keep its pointer address.
754 const old_slice = slice;754 const old_slice = slice;
755 slice = try allocator.realloc(slice, 2);755 slice = try allocator.realloc(slice, 2);
756 std.testing.expect(old_slice.ptr == slice.ptr);756 try std.testing.expect(old_slice.ptr == slice.ptr);
757 std.testing.expect(slice[0] == 0x12);757 try std.testing.expect(slice[0] == 0x12);
758 slice[1] = 0x34;758 slice[1] = 0x34;
759759
760 // This requires upgrading to a larger size class760 // This requires upgrading to a larger size class
761 slice = try allocator.realloc(slice, 17);761 slice = try allocator.realloc(slice, 17);
762 std.testing.expect(slice[0] == 0x12);762 try std.testing.expect(slice[0] == 0x12);
763 std.testing.expect(slice[1] == 0x34);763 try std.testing.expect(slice[1] == 0x34);
764}764}
765765
766test "shrink" {766test "shrink" {
767 var gpa = GeneralPurposeAllocator(test_config){};767 var gpa = GeneralPurposeAllocator(test_config){};
768 defer std.testing.expect(!gpa.deinit());768 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
769 const allocator = &gpa.allocator;769 const allocator = &gpa.allocator;
770770
771 var slice = try allocator.alloc(u8, 20);771 var slice = try allocator.alloc(u8, 20);
...@@ -776,19 +776,19 @@ test "shrink" {...@@ -776,19 +776,19 @@ test "shrink" {
776 slice = allocator.shrink(slice, 17);776 slice = allocator.shrink(slice, 17);
777777
778 for (slice) |b| {778 for (slice) |b| {
779 std.testing.expect(b == 0x11);779 try std.testing.expect(b == 0x11);
780 }780 }
781781
782 slice = allocator.shrink(slice, 16);782 slice = allocator.shrink(slice, 16);
783783
784 for (slice) |b| {784 for (slice) |b| {
785 std.testing.expect(b == 0x11);785 try std.testing.expect(b == 0x11);
786 }786 }
787}787}
788788
789test "large object - grow" {789test "large object - grow" {
790 var gpa = GeneralPurposeAllocator(test_config){};790 var gpa = GeneralPurposeAllocator(test_config){};
791 defer std.testing.expect(!gpa.deinit());791 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
792 const allocator = &gpa.allocator;792 const allocator = &gpa.allocator;
793793
794 var slice1 = try allocator.alloc(u8, page_size * 2 - 20);794 var slice1 = try allocator.alloc(u8, page_size * 2 - 20);
...@@ -796,17 +796,17 @@ test "large object - grow" {...@@ -796,17 +796,17 @@ test "large object - grow" {
796796
797 const old = slice1;797 const old = slice1;
798 slice1 = try allocator.realloc(slice1, page_size * 2 - 10);798 slice1 = try allocator.realloc(slice1, page_size * 2 - 10);
799 std.testing.expect(slice1.ptr == old.ptr);799 try std.testing.expect(slice1.ptr == old.ptr);
800800
801 slice1 = try allocator.realloc(slice1, page_size * 2);801 slice1 = try allocator.realloc(slice1, page_size * 2);
802 std.testing.expect(slice1.ptr == old.ptr);802 try std.testing.expect(slice1.ptr == old.ptr);
803803
804 slice1 = try allocator.realloc(slice1, page_size * 2 + 1);804 slice1 = try allocator.realloc(slice1, page_size * 2 + 1);
805}805}
806806
807test "realloc small object to large object" {807test "realloc small object to large object" {
808 var gpa = GeneralPurposeAllocator(test_config){};808 var gpa = GeneralPurposeAllocator(test_config){};
809 defer std.testing.expect(!gpa.deinit());809 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
810 const allocator = &gpa.allocator;810 const allocator = &gpa.allocator;
811811
812 var slice = try allocator.alloc(u8, 70);812 var slice = try allocator.alloc(u8, 70);
...@@ -817,13 +817,13 @@ test "realloc small object to large object" {...@@ -817,13 +817,13 @@ test "realloc small object to large object" {
817 // This requires upgrading to a large object817 // This requires upgrading to a large object
818 const large_object_size = page_size * 2 + 50;818 const large_object_size = page_size * 2 + 50;
819 slice = try allocator.realloc(slice, large_object_size);819 slice = try allocator.realloc(slice, large_object_size);
820 std.testing.expect(slice[0] == 0x12);820 try std.testing.expect(slice[0] == 0x12);
821 std.testing.expect(slice[60] == 0x34);821 try std.testing.expect(slice[60] == 0x34);
822}822}
823823
824test "shrink large object to large object" {824test "shrink large object to large object" {
825 var gpa = GeneralPurposeAllocator(test_config){};825 var gpa = GeneralPurposeAllocator(test_config){};
826 defer std.testing.expect(!gpa.deinit());826 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
827 const allocator = &gpa.allocator;827 const allocator = &gpa.allocator;
828828
829 var slice = try allocator.alloc(u8, page_size * 2 + 50);829 var slice = try allocator.alloc(u8, page_size * 2 + 50);
...@@ -832,21 +832,21 @@ test "shrink large object to large object" {...@@ -832,21 +832,21 @@ test "shrink large object to large object" {
832 slice[60] = 0x34;832 slice[60] = 0x34;
833833
834 slice = try allocator.resize(slice, page_size * 2 + 1);834 slice = try allocator.resize(slice, page_size * 2 + 1);
835 std.testing.expect(slice[0] == 0x12);835 try std.testing.expect(slice[0] == 0x12);
836 std.testing.expect(slice[60] == 0x34);836 try std.testing.expect(slice[60] == 0x34);
837837
838 slice = allocator.shrink(slice, page_size * 2 + 1);838 slice = allocator.shrink(slice, page_size * 2 + 1);
839 std.testing.expect(slice[0] == 0x12);839 try std.testing.expect(slice[0] == 0x12);
840 std.testing.expect(slice[60] == 0x34);840 try std.testing.expect(slice[60] == 0x34);
841841
842 slice = try allocator.realloc(slice, page_size * 2);842 slice = try allocator.realloc(slice, page_size * 2);
843 std.testing.expect(slice[0] == 0x12);843 try std.testing.expect(slice[0] == 0x12);
844 std.testing.expect(slice[60] == 0x34);844 try std.testing.expect(slice[60] == 0x34);
845}845}
846846
847test "shrink large object to large object with larger alignment" {847test "shrink large object to large object with larger alignment" {
848 var gpa = GeneralPurposeAllocator(test_config){};848 var gpa = GeneralPurposeAllocator(test_config){};
849 defer std.testing.expect(!gpa.deinit());849 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
850 const allocator = &gpa.allocator;850 const allocator = &gpa.allocator;
851851
852 var debug_buffer: [1000]u8 = undefined;852 var debug_buffer: [1000]u8 = undefined;
...@@ -875,13 +875,13 @@ test "shrink large object to large object with larger alignment" {...@@ -875,13 +875,13 @@ test "shrink large object to large object with larger alignment" {
875 slice[60] = 0x34;875 slice[60] = 0x34;
876876
877 slice = try allocator.reallocAdvanced(slice, big_alignment, alloc_size / 2, .exact);877 slice = try allocator.reallocAdvanced(slice, big_alignment, alloc_size / 2, .exact);
878 std.testing.expect(slice[0] == 0x12);878 try std.testing.expect(slice[0] == 0x12);
879 std.testing.expect(slice[60] == 0x34);879 try std.testing.expect(slice[60] == 0x34);
880}880}
881881
882test "realloc large object to small object" {882test "realloc large object to small object" {
883 var gpa = GeneralPurposeAllocator(test_config){};883 var gpa = GeneralPurposeAllocator(test_config){};
884 defer std.testing.expect(!gpa.deinit());884 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
885 const allocator = &gpa.allocator;885 const allocator = &gpa.allocator;
886886
887 var slice = try allocator.alloc(u8, page_size * 2 + 50);887 var slice = try allocator.alloc(u8, page_size * 2 + 50);
...@@ -890,8 +890,8 @@ test "realloc large object to small object" {...@@ -890,8 +890,8 @@ test "realloc large object to small object" {
890 slice[16] = 0x34;890 slice[16] = 0x34;
891891
892 slice = try allocator.realloc(slice, 19);892 slice = try allocator.realloc(slice, 19);
893 std.testing.expect(slice[0] == 0x12);893 try std.testing.expect(slice[0] == 0x12);
894 std.testing.expect(slice[16] == 0x34);894 try std.testing.expect(slice[16] == 0x34);
895}895}
896896
897test "overrideable mutexes" {897test "overrideable mutexes" {
...@@ -899,7 +899,7 @@ test "overrideable mutexes" {...@@ -899,7 +899,7 @@ test "overrideable mutexes" {
899 .backing_allocator = std.testing.allocator,899 .backing_allocator = std.testing.allocator,
900 .mutex = std.Thread.Mutex{},900 .mutex = std.Thread.Mutex{},
901 };901 };
902 defer std.testing.expect(!gpa.deinit());902 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
903 const allocator = &gpa.allocator;903 const allocator = &gpa.allocator;
904904
905 const ptr = try allocator.create(i32);905 const ptr = try allocator.create(i32);
...@@ -908,7 +908,7 @@ test "overrideable mutexes" {...@@ -908,7 +908,7 @@ test "overrideable mutexes" {
908908
909test "non-page-allocator backing allocator" {909test "non-page-allocator backing allocator" {
910 var gpa = GeneralPurposeAllocator(.{}){ .backing_allocator = std.testing.allocator };910 var gpa = GeneralPurposeAllocator(.{}){ .backing_allocator = std.testing.allocator };
911 defer std.testing.expect(!gpa.deinit());911 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
912 const allocator = &gpa.allocator;912 const allocator = &gpa.allocator;
913913
914 const ptr = try allocator.create(i32);914 const ptr = try allocator.create(i32);
...@@ -917,7 +917,7 @@ test "non-page-allocator backing allocator" {...@@ -917,7 +917,7 @@ test "non-page-allocator backing allocator" {
917917
918test "realloc large object to larger alignment" {918test "realloc large object to larger alignment" {
919 var gpa = GeneralPurposeAllocator(test_config){};919 var gpa = GeneralPurposeAllocator(test_config){};
920 defer std.testing.expect(!gpa.deinit());920 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
921 const allocator = &gpa.allocator;921 const allocator = &gpa.allocator;
922922
923 var debug_buffer: [1000]u8 = undefined;923 var debug_buffer: [1000]u8 = undefined;
...@@ -943,22 +943,22 @@ test "realloc large object to larger alignment" {...@@ -943,22 +943,22 @@ test "realloc large object to larger alignment" {
943 slice[16] = 0x34;943 slice[16] = 0x34;
944944
945 slice = try allocator.reallocAdvanced(slice, 32, page_size * 2 + 100, .exact);945 slice = try allocator.reallocAdvanced(slice, 32, page_size * 2 + 100, .exact);
946 std.testing.expect(slice[0] == 0x12);946 try std.testing.expect(slice[0] == 0x12);
947 std.testing.expect(slice[16] == 0x34);947 try std.testing.expect(slice[16] == 0x34);
948948
949 slice = try allocator.reallocAdvanced(slice, 32, page_size * 2 + 25, .exact);949 slice = try allocator.reallocAdvanced(slice, 32, page_size * 2 + 25, .exact);
950 std.testing.expect(slice[0] == 0x12);950 try std.testing.expect(slice[0] == 0x12);
951 std.testing.expect(slice[16] == 0x34);951 try std.testing.expect(slice[16] == 0x34);
952952
953 slice = try allocator.reallocAdvanced(slice, big_alignment, page_size * 2 + 100, .exact);953 slice = try allocator.reallocAdvanced(slice, big_alignment, page_size * 2 + 100, .exact);
954 std.testing.expect(slice[0] == 0x12);954 try std.testing.expect(slice[0] == 0x12);
955 std.testing.expect(slice[16] == 0x34);955 try std.testing.expect(slice[16] == 0x34);
956}956}
957957
958test "large object shrinks to small but allocation fails during shrink" {958test "large object shrinks to small but allocation fails during shrink" {
959 var failing_allocator = std.testing.FailingAllocator.init(std.heap.page_allocator, 3);959 var failing_allocator = std.testing.FailingAllocator.init(std.heap.page_allocator, 3);
960 var gpa = GeneralPurposeAllocator(.{}){ .backing_allocator = &failing_allocator.allocator };960 var gpa = GeneralPurposeAllocator(.{}){ .backing_allocator = &failing_allocator.allocator };
961 defer std.testing.expect(!gpa.deinit());961 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
962 const allocator = &gpa.allocator;962 const allocator = &gpa.allocator;
963963
964 var slice = try allocator.alloc(u8, page_size * 2 + 50);964 var slice = try allocator.alloc(u8, page_size * 2 + 50);
...@@ -969,13 +969,13 @@ test "large object shrinks to small but allocation fails during shrink" {...@@ -969,13 +969,13 @@ test "large object shrinks to small but allocation fails during shrink" {
969 // Next allocation will fail in the backing allocator of the GeneralPurposeAllocator969 // Next allocation will fail in the backing allocator of the GeneralPurposeAllocator
970970
971 slice = allocator.shrink(slice, 4);971 slice = allocator.shrink(slice, 4);
972 std.testing.expect(slice[0] == 0x12);972 try std.testing.expect(slice[0] == 0x12);
973 std.testing.expect(slice[3] == 0x34);973 try std.testing.expect(slice[3] == 0x34);
974}974}
975975
976test "objects of size 1024 and 2048" {976test "objects of size 1024 and 2048" {
977 var gpa = GeneralPurposeAllocator(test_config){};977 var gpa = GeneralPurposeAllocator(test_config){};
978 defer std.testing.expect(!gpa.deinit());978 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
979 const allocator = &gpa.allocator;979 const allocator = &gpa.allocator;
980980
981 const slice = try allocator.alloc(u8, 1025);981 const slice = try allocator.alloc(u8, 1025);
...@@ -987,26 +987,26 @@ test "objects of size 1024 and 2048" {...@@ -987,26 +987,26 @@ test "objects of size 1024 and 2048" {
987987
988test "setting a memory cap" {988test "setting a memory cap" {
989 var gpa = GeneralPurposeAllocator(.{ .enable_memory_limit = true }){};989 var gpa = GeneralPurposeAllocator(.{ .enable_memory_limit = true }){};
990 defer std.testing.expect(!gpa.deinit());990 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
991 const allocator = &gpa.allocator;991 const allocator = &gpa.allocator;
992992
993 gpa.setRequestedMemoryLimit(1010);993 gpa.setRequestedMemoryLimit(1010);
994994
995 const small = try allocator.create(i32);995 const small = try allocator.create(i32);
996 std.testing.expect(gpa.total_requested_bytes == 4);996 try std.testing.expect(gpa.total_requested_bytes == 4);
997997
998 const big = try allocator.alloc(u8, 1000);998 const big = try allocator.alloc(u8, 1000);
999 std.testing.expect(gpa.total_requested_bytes == 1004);999 try std.testing.expect(gpa.total_requested_bytes == 1004);
10001000
1001 std.testing.expectError(error.OutOfMemory, allocator.create(u64));1001 try std.testing.expectError(error.OutOfMemory, allocator.create(u64));
10021002
1003 allocator.destroy(small);1003 allocator.destroy(small);
1004 std.testing.expect(gpa.total_requested_bytes == 1000);1004 try std.testing.expect(gpa.total_requested_bytes == 1000);
10051005
1006 allocator.free(big);1006 allocator.free(big);
1007 std.testing.expect(gpa.total_requested_bytes == 0);1007 try std.testing.expect(gpa.total_requested_bytes == 0);
10081008
1009 const exact = try allocator.alloc(u8, 1010);1009 const exact = try allocator.alloc(u8, 1010);
1010 std.testing.expect(gpa.total_requested_bytes == 1010);1010 try std.testing.expect(gpa.total_requested_bytes == 1010);
1011 allocator.free(exact);1011 allocator.free(exact);
1012}1012}
lib/std/heap/logging_allocator.zig+3-3
...@@ -93,11 +93,11 @@ test "LoggingAllocator" {...@@ -93,11 +93,11 @@ test "LoggingAllocator" {
9393
94 var a = try allocator.alloc(u8, 10);94 var a = try allocator.alloc(u8, 10);
95 a = allocator.shrink(a, 5);95 a = allocator.shrink(a, 5);
96 std.testing.expect(a.len == 5);96 try std.testing.expect(a.len == 5);
97 std.testing.expectError(error.OutOfMemory, allocator.resize(a, 20));97 try std.testing.expectError(error.OutOfMemory, allocator.resize(a, 20));
98 allocator.free(a);98 allocator.free(a);
9999
100 std.testing.expectEqualSlices(u8,100 try std.testing.expectEqualSlices(u8,
101 \\alloc : 10 success!101 \\alloc : 10 success!
102 \\shrink: 10 to 5102 \\shrink: 10 to 5
103 \\expand: 5 to 20 failure!103 \\expand: 5 to 20 failure!
lib/std/io/bit_reader.zig+38-38
...@@ -185,64 +185,64 @@ test "api coverage" {...@@ -185,64 +185,64 @@ test "api coverage" {
185 const expect = testing.expect;185 const expect = testing.expect;
186 const expectError = testing.expectError;186 const expectError = testing.expectError;
187187
188 expect(1 == try bit_stream_be.readBits(u2, 1, &out_bits));188 try expect(1 == try bit_stream_be.readBits(u2, 1, &out_bits));
189 expect(out_bits == 1);189 try expect(out_bits == 1);
190 expect(2 == try bit_stream_be.readBits(u5, 2, &out_bits));190 try expect(2 == try bit_stream_be.readBits(u5, 2, &out_bits));
191 expect(out_bits == 2);191 try expect(out_bits == 2);
192 expect(3 == try bit_stream_be.readBits(u128, 3, &out_bits));192 try expect(3 == try bit_stream_be.readBits(u128, 3, &out_bits));
193 expect(out_bits == 3);193 try expect(out_bits == 3);
194 expect(4 == try bit_stream_be.readBits(u8, 4, &out_bits));194 try expect(4 == try bit_stream_be.readBits(u8, 4, &out_bits));
195 expect(out_bits == 4);195 try expect(out_bits == 4);
196 expect(5 == try bit_stream_be.readBits(u9, 5, &out_bits));196 try expect(5 == try bit_stream_be.readBits(u9, 5, &out_bits));
197 expect(out_bits == 5);197 try expect(out_bits == 5);
198 expect(1 == try bit_stream_be.readBits(u1, 1, &out_bits));198 try expect(1 == try bit_stream_be.readBits(u1, 1, &out_bits));
199 expect(out_bits == 1);199 try expect(out_bits == 1);
200200
201 mem_in_be.pos = 0;201 mem_in_be.pos = 0;
202 bit_stream_be.bit_count = 0;202 bit_stream_be.bit_count = 0;
203 expect(0b110011010000101 == try bit_stream_be.readBits(u15, 15, &out_bits));203 try expect(0b110011010000101 == try bit_stream_be.readBits(u15, 15, &out_bits));
204 expect(out_bits == 15);204 try expect(out_bits == 15);
205205
206 mem_in_be.pos = 0;206 mem_in_be.pos = 0;
207 bit_stream_be.bit_count = 0;207 bit_stream_be.bit_count = 0;
208 expect(0b1100110100001011 == try bit_stream_be.readBits(u16, 16, &out_bits));208 try expect(0b1100110100001011 == try bit_stream_be.readBits(u16, 16, &out_bits));
209 expect(out_bits == 16);209 try expect(out_bits == 16);
210210
211 _ = try bit_stream_be.readBits(u0, 0, &out_bits);211 _ = try bit_stream_be.readBits(u0, 0, &out_bits);
212212
213 expect(0 == try bit_stream_be.readBits(u1, 1, &out_bits));213 try expect(0 == try bit_stream_be.readBits(u1, 1, &out_bits));
214 expect(out_bits == 0);214 try expect(out_bits == 0);
215 expectError(error.EndOfStream, bit_stream_be.readBitsNoEof(u1, 1));215 try expectError(error.EndOfStream, bit_stream_be.readBitsNoEof(u1, 1));
216216
217 var mem_in_le = io.fixedBufferStream(&mem_le);217 var mem_in_le = io.fixedBufferStream(&mem_le);
218 var bit_stream_le = bitReader(.Little, mem_in_le.reader());218 var bit_stream_le = bitReader(.Little, mem_in_le.reader());
219219
220 expect(1 == try bit_stream_le.readBits(u2, 1, &out_bits));220 try expect(1 == try bit_stream_le.readBits(u2, 1, &out_bits));
221 expect(out_bits == 1);221 try expect(out_bits == 1);
222 expect(2 == try bit_stream_le.readBits(u5, 2, &out_bits));222 try expect(2 == try bit_stream_le.readBits(u5, 2, &out_bits));
223 expect(out_bits == 2);223 try expect(out_bits == 2);
224 expect(3 == try bit_stream_le.readBits(u128, 3, &out_bits));224 try expect(3 == try bit_stream_le.readBits(u128, 3, &out_bits));
225 expect(out_bits == 3);225 try expect(out_bits == 3);
226 expect(4 == try bit_stream_le.readBits(u8, 4, &out_bits));226 try expect(4 == try bit_stream_le.readBits(u8, 4, &out_bits));
227 expect(out_bits == 4);227 try expect(out_bits == 4);
228 expect(5 == try bit_stream_le.readBits(u9, 5, &out_bits));228 try expect(5 == try bit_stream_le.readBits(u9, 5, &out_bits));
229 expect(out_bits == 5);229 try expect(out_bits == 5);
230 expect(1 == try bit_stream_le.readBits(u1, 1, &out_bits));230 try expect(1 == try bit_stream_le.readBits(u1, 1, &out_bits));
231 expect(out_bits == 1);231 try expect(out_bits == 1);
232232
233 mem_in_le.pos = 0;233 mem_in_le.pos = 0;
234 bit_stream_le.bit_count = 0;234 bit_stream_le.bit_count = 0;
235 expect(0b001010100011101 == try bit_stream_le.readBits(u15, 15, &out_bits));235 try expect(0b001010100011101 == try bit_stream_le.readBits(u15, 15, &out_bits));
236 expect(out_bits == 15);236 try expect(out_bits == 15);
237237
238 mem_in_le.pos = 0;238 mem_in_le.pos = 0;
239 bit_stream_le.bit_count = 0;239 bit_stream_le.bit_count = 0;
240 expect(0b1001010100011101 == try bit_stream_le.readBits(u16, 16, &out_bits));240 try expect(0b1001010100011101 == try bit_stream_le.readBits(u16, 16, &out_bits));
241 expect(out_bits == 16);241 try expect(out_bits == 16);
242242
243 _ = try bit_stream_le.readBits(u0, 0, &out_bits);243 _ = try bit_stream_le.readBits(u0, 0, &out_bits);
244244
245 expect(0 == try bit_stream_le.readBits(u1, 1, &out_bits));245 try expect(0 == try bit_stream_le.readBits(u1, 1, &out_bits));
246 expect(out_bits == 0);246 try expect(out_bits == 0);
247 expectError(error.EndOfStream, bit_stream_le.readBitsNoEof(u1, 1));247 try expectError(error.EndOfStream, bit_stream_le.readBitsNoEof(u1, 1));
248}248}
lib/std/io/bit_writer.zig+6-6
...@@ -163,17 +163,17 @@ test "api coverage" {...@@ -163,17 +163,17 @@ test "api coverage" {
163 try bit_stream_be.writeBits(@as(u9, 5), 5);163 try bit_stream_be.writeBits(@as(u9, 5), 5);
164 try bit_stream_be.writeBits(@as(u1, 1), 1);164 try bit_stream_be.writeBits(@as(u1, 1), 1);
165165
166 testing.expect(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001011);166 try testing.expect(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001011);
167167
168 mem_out_be.pos = 0;168 mem_out_be.pos = 0;
169169
170 try bit_stream_be.writeBits(@as(u15, 0b110011010000101), 15);170 try bit_stream_be.writeBits(@as(u15, 0b110011010000101), 15);
171 try bit_stream_be.flushBits();171 try bit_stream_be.flushBits();
172 testing.expect(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001010);172 try testing.expect(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001010);
173173
174 mem_out_be.pos = 0;174 mem_out_be.pos = 0;
175 try bit_stream_be.writeBits(@as(u32, 0b110011010000101), 16);175 try bit_stream_be.writeBits(@as(u32, 0b110011010000101), 16);
176 testing.expect(mem_be[0] == 0b01100110 and mem_be[1] == 0b10000101);176 try testing.expect(mem_be[0] == 0b01100110 and mem_be[1] == 0b10000101);
177177
178 try bit_stream_be.writeBits(@as(u0, 0), 0);178 try bit_stream_be.writeBits(@as(u0, 0), 0);
179179
...@@ -187,16 +187,16 @@ test "api coverage" {...@@ -187,16 +187,16 @@ test "api coverage" {
187 try bit_stream_le.writeBits(@as(u9, 5), 5);187 try bit_stream_le.writeBits(@as(u9, 5), 5);
188 try bit_stream_le.writeBits(@as(u1, 1), 1);188 try bit_stream_le.writeBits(@as(u1, 1), 1);
189189
190 testing.expect(mem_le[0] == 0b00011101 and mem_le[1] == 0b10010101);190 try testing.expect(mem_le[0] == 0b00011101 and mem_le[1] == 0b10010101);
191191
192 mem_out_le.pos = 0;192 mem_out_le.pos = 0;
193 try bit_stream_le.writeBits(@as(u15, 0b110011010000101), 15);193 try bit_stream_le.writeBits(@as(u15, 0b110011010000101), 15);
194 try bit_stream_le.flushBits();194 try bit_stream_le.flushBits();
195 testing.expect(mem_le[0] == 0b10000101 and mem_le[1] == 0b01100110);195 try testing.expect(mem_le[0] == 0b10000101 and mem_le[1] == 0b01100110);
196196
197 mem_out_le.pos = 0;197 mem_out_le.pos = 0;
198 try bit_stream_le.writeBits(@as(u32, 0b1100110100001011), 16);198 try bit_stream_le.writeBits(@as(u32, 0b1100110100001011), 16);
199 testing.expect(mem_le[0] == 0b00001011 and mem_le[1] == 0b11001101);199 try testing.expect(mem_le[0] == 0b00001011 and mem_le[1] == 0b11001101);
200200
201 try bit_stream_le.writeBits(@as(u0, 0), 0);201 try bit_stream_le.writeBits(@as(u0, 0), 0);
202}202}
lib/std/io/buffered_reader.zig+1-1
...@@ -87,5 +87,5 @@ test "io.BufferedReader" {...@@ -87,5 +87,5 @@ test "io.BufferedReader" {
8787
88 const res = try stream.readAllAlloc(testing.allocator, str.len + 1);88 const res = try stream.readAllAlloc(testing.allocator, str.len + 1);
89 defer testing.allocator.free(res);89 defer testing.allocator.free(res);
90 testing.expectEqualSlices(u8, str, res);90 try testing.expectEqualSlices(u8, str, res);
91}91}
lib/std/io/counting_reader.zig+2-2
...@@ -41,8 +41,8 @@ test "io.CountingReader" {...@@ -41,8 +41,8 @@ test "io.CountingReader" {
4141
42 //read and discard all bytes42 //read and discard all bytes
43 while (stream.readByte()) |_| {} else |err| {43 while (stream.readByte()) |_| {} else |err| {
44 testing.expect(err == error.EndOfStream);44 try testing.expect(err == error.EndOfStream);
45 }45 }
4646
47 testing.expect(counting_stream.bytes_read == bytes.len);47 try testing.expect(counting_stream.bytes_read == bytes.len);
48}48}
lib/std/io/counting_writer.zig+1-1
...@@ -40,5 +40,5 @@ test "io.CountingWriter" {...@@ -40,5 +40,5 @@ test "io.CountingWriter" {
4040
41 const bytes = "yay" ** 100;41 const bytes = "yay" ** 100;
42 stream.writeAll(bytes) catch unreachable;42 stream.writeAll(bytes) catch unreachable;
43 testing.expect(counting_stream.bytes_written == bytes.len);43 try testing.expect(counting_stream.bytes_written == bytes.len);
44}44}
lib/std/io/fixed_buffer_stream.zig+13-13
...@@ -134,7 +134,7 @@ test "FixedBufferStream output" {...@@ -134,7 +134,7 @@ test "FixedBufferStream output" {
134 const stream = fbs.writer();134 const stream = fbs.writer();
135135
136 try stream.print("{s}{s}!", .{ "Hello", "World" });136 try stream.print("{s}{s}!", .{ "Hello", "World" });
137 testing.expectEqualSlices(u8, "HelloWorld!", fbs.getWritten());137 try testing.expectEqualSlices(u8, "HelloWorld!", fbs.getWritten());
138}138}
139139
140test "FixedBufferStream output 2" {140test "FixedBufferStream output 2" {
...@@ -142,19 +142,19 @@ test "FixedBufferStream output 2" {...@@ -142,19 +142,19 @@ test "FixedBufferStream output 2" {
142 var fbs = fixedBufferStream(&buffer);142 var fbs = fixedBufferStream(&buffer);
143143
144 try fbs.writer().writeAll("Hello");144 try fbs.writer().writeAll("Hello");
145 testing.expect(mem.eql(u8, fbs.getWritten(), "Hello"));145 try testing.expect(mem.eql(u8, fbs.getWritten(), "Hello"));
146146
147 try fbs.writer().writeAll("world");147 try fbs.writer().writeAll("world");
148 testing.expect(mem.eql(u8, fbs.getWritten(), "Helloworld"));148 try testing.expect(mem.eql(u8, fbs.getWritten(), "Helloworld"));
149149
150 testing.expectError(error.NoSpaceLeft, fbs.writer().writeAll("!"));150 try testing.expectError(error.NoSpaceLeft, fbs.writer().writeAll("!"));
151 testing.expect(mem.eql(u8, fbs.getWritten(), "Helloworld"));151 try testing.expect(mem.eql(u8, fbs.getWritten(), "Helloworld"));
152152
153 fbs.reset();153 fbs.reset();
154 testing.expect(fbs.getWritten().len == 0);154 try testing.expect(fbs.getWritten().len == 0);
155155
156 testing.expectError(error.NoSpaceLeft, fbs.writer().writeAll("Hello world!"));156 try testing.expectError(error.NoSpaceLeft, fbs.writer().writeAll("Hello world!"));
157 testing.expect(mem.eql(u8, fbs.getWritten(), "Hello worl"));157 try testing.expect(mem.eql(u8, fbs.getWritten(), "Hello worl"));
158}158}
159159
160test "FixedBufferStream input" {160test "FixedBufferStream input" {
...@@ -164,13 +164,13 @@ test "FixedBufferStream input" {...@@ -164,13 +164,13 @@ test "FixedBufferStream input" {
164 var dest: [4]u8 = undefined;164 var dest: [4]u8 = undefined;
165165
166 var read = try fbs.reader().read(dest[0..4]);166 var read = try fbs.reader().read(dest[0..4]);
167 testing.expect(read == 4);167 try testing.expect(read == 4);
168 testing.expect(mem.eql(u8, dest[0..4], bytes[0..4]));168 try testing.expect(mem.eql(u8, dest[0..4], bytes[0..4]));
169169
170 read = try fbs.reader().read(dest[0..4]);170 read = try fbs.reader().read(dest[0..4]);
171 testing.expect(read == 3);171 try testing.expect(read == 3);
172 testing.expect(mem.eql(u8, dest[0..3], bytes[4..7]));172 try testing.expect(mem.eql(u8, dest[0..3], bytes[4..7]));
173173
174 read = try fbs.reader().read(dest[0..4]);174 read = try fbs.reader().read(dest[0..4]);
175 testing.expect(read == 0);175 try testing.expect(read == 0);
176}176}
lib/std/io/limited_reader.zig+4-4
...@@ -43,8 +43,8 @@ test "basic usage" {...@@ -43,8 +43,8 @@ test "basic usage" {
43 var early_stream = limitedReader(fbs.reader(), 3);43 var early_stream = limitedReader(fbs.reader(), 3);
4444
45 var buf: [5]u8 = undefined;45 var buf: [5]u8 = undefined;
46 testing.expectEqual(@as(usize, 3), try early_stream.reader().read(&buf));46 try testing.expectEqual(@as(usize, 3), try early_stream.reader().read(&buf));
47 testing.expectEqualSlices(u8, data[0..3], buf[0..3]);47 try testing.expectEqualSlices(u8, data[0..3], buf[0..3]);
48 testing.expectEqual(@as(usize, 0), try early_stream.reader().read(&buf));48 try testing.expectEqual(@as(usize, 0), try early_stream.reader().read(&buf));
49 testing.expectError(error.EndOfStream, early_stream.reader().skipBytes(10, .{}));49 try testing.expectError(error.EndOfStream, early_stream.reader().skipBytes(10, .{}));
50}50}
lib/std/io/multi_writer.zig+2-2
...@@ -52,6 +52,6 @@ test "MultiWriter" {...@@ -52,6 +52,6 @@ test "MultiWriter" {
52 var fbs2 = io.fixedBufferStream(&buf2);52 var fbs2 = io.fixedBufferStream(&buf2);
53 var stream = multiWriter(.{ fbs1.writer(), fbs2.writer() });53 var stream = multiWriter(.{ fbs1.writer(), fbs2.writer() });
54 try stream.writer().print("HI", .{});54 try stream.writer().print("HI", .{});
55 testing.expectEqualSlices(u8, "HI", fbs1.getWritten());55 try testing.expectEqualSlices(u8, "HI", fbs1.getWritten());
56 testing.expectEqualSlices(u8, "HI", fbs2.getWritten());56 try testing.expectEqualSlices(u8, "HI", fbs2.getWritten());
57}57}
lib/std/io/peek_stream.zig+11-11
...@@ -94,24 +94,24 @@ test "PeekStream" {...@@ -94,24 +94,24 @@ test "PeekStream" {
94 try ps.putBackByte(10);94 try ps.putBackByte(10);
9595
96 var read = try ps.reader().read(dest[0..4]);96 var read = try ps.reader().read(dest[0..4]);
97 testing.expect(read == 4);97 try testing.expect(read == 4);
98 testing.expect(dest[0] == 10);98 try testing.expect(dest[0] == 10);
99 testing.expect(dest[1] == 9);99 try testing.expect(dest[1] == 9);
100 testing.expect(mem.eql(u8, dest[2..4], bytes[0..2]));100 try testing.expect(mem.eql(u8, dest[2..4], bytes[0..2]));
101101
102 read = try ps.reader().read(dest[0..4]);102 read = try ps.reader().read(dest[0..4]);
103 testing.expect(read == 4);103 try testing.expect(read == 4);
104 testing.expect(mem.eql(u8, dest[0..4], bytes[2..6]));104 try testing.expect(mem.eql(u8, dest[0..4], bytes[2..6]));
105105
106 read = try ps.reader().read(dest[0..4]);106 read = try ps.reader().read(dest[0..4]);
107 testing.expect(read == 2);107 try testing.expect(read == 2);
108 testing.expect(mem.eql(u8, dest[0..2], bytes[6..8]));108 try testing.expect(mem.eql(u8, dest[0..2], bytes[6..8]));
109109
110 try ps.putBackByte(11);110 try ps.putBackByte(11);
111 try ps.putBackByte(12);111 try ps.putBackByte(12);
112112
113 read = try ps.reader().read(dest[0..4]);113 read = try ps.reader().read(dest[0..4]);
114 testing.expect(read == 2);114 try testing.expect(read == 2);
115 testing.expect(dest[0] == 12);115 try testing.expect(dest[0] == 12);
116 testing.expect(dest[1] == 11);116 try testing.expect(dest[1] == 11);
117}117}
lib/std/io/reader.zig+7-7
...@@ -329,26 +329,26 @@ pub fn Reader(...@@ -329,26 +329,26 @@ pub fn Reader(
329test "Reader" {329test "Reader" {
330 var buf = "a\x02".*;330 var buf = "a\x02".*;
331 const reader = std.io.fixedBufferStream(&buf).reader();331 const reader = std.io.fixedBufferStream(&buf).reader();
332 testing.expect((try reader.readByte()) == 'a');332 try testing.expect((try reader.readByte()) == 'a');
333 testing.expect((try reader.readEnum(enum(u8) {333 try testing.expect((try reader.readEnum(enum(u8) {
334 a = 0,334 a = 0,
335 b = 99,335 b = 99,
336 c = 2,336 c = 2,
337 d = 3,337 d = 3,
338 }, undefined)) == .c);338 }, undefined)) == .c);
339 testing.expectError(error.EndOfStream, reader.readByte());339 try testing.expectError(error.EndOfStream, reader.readByte());
340}340}
341341
342test "Reader.isBytes" {342test "Reader.isBytes" {
343 const reader = std.io.fixedBufferStream("foobar").reader();343 const reader = std.io.fixedBufferStream("foobar").reader();
344 testing.expectEqual(true, try reader.isBytes("foo"));344 try testing.expectEqual(true, try reader.isBytes("foo"));
345 testing.expectEqual(false, try reader.isBytes("qux"));345 try testing.expectEqual(false, try reader.isBytes("qux"));
346}346}
347347
348test "Reader.skipBytes" {348test "Reader.skipBytes" {
349 const reader = std.io.fixedBufferStream("foobar").reader();349 const reader = std.io.fixedBufferStream("foobar").reader();
350 try reader.skipBytes(3, .{});350 try reader.skipBytes(3, .{});
351 testing.expect(try reader.isBytes("bar"));351 try testing.expect(try reader.isBytes("bar"));
352 try reader.skipBytes(0, .{});352 try reader.skipBytes(0, .{});
353 testing.expectError(error.EndOfStream, reader.skipBytes(1, .{}));353 try testing.expectError(error.EndOfStream, reader.skipBytes(1, .{}));
354}354}
lib/std/io/test.zig+33-33
...@@ -40,7 +40,7 @@ test "write a file, read it, then delete it" {...@@ -40,7 +40,7 @@ test "write a file, read it, then delete it" {
4040
41 {41 {
42 // Make sure the exclusive flag is honored.42 // Make sure the exclusive flag is honored.
43 expectError(File.OpenError.PathAlreadyExists, tmp.dir.createFile(tmp_file_name, .{ .exclusive = true }));43 try expectError(File.OpenError.PathAlreadyExists, tmp.dir.createFile(tmp_file_name, .{ .exclusive = true }));
44 }44 }
4545
46 {46 {
...@@ -49,16 +49,16 @@ test "write a file, read it, then delete it" {...@@ -49,16 +49,16 @@ test "write a file, read it, then delete it" {
4949
50 const file_size = try file.getEndPos();50 const file_size = try file.getEndPos();
51 const expected_file_size: u64 = "begin".len + data.len + "end".len;51 const expected_file_size: u64 = "begin".len + data.len + "end".len;
52 expectEqual(expected_file_size, file_size);52 try expectEqual(expected_file_size, file_size);
5353
54 var buf_stream = io.bufferedReader(file.reader());54 var buf_stream = io.bufferedReader(file.reader());
55 const st = buf_stream.reader();55 const st = buf_stream.reader();
56 const contents = try st.readAllAlloc(std.testing.allocator, 2 * 1024);56 const contents = try st.readAllAlloc(std.testing.allocator, 2 * 1024);
57 defer std.testing.allocator.free(contents);57 defer std.testing.allocator.free(contents);
5858
59 expect(mem.eql(u8, contents[0.."begin".len], "begin"));59 try expect(mem.eql(u8, contents[0.."begin".len], "begin"));
60 expect(mem.eql(u8, contents["begin".len .. contents.len - "end".len], &data));60 try expect(mem.eql(u8, contents["begin".len .. contents.len - "end".len], &data));
61 expect(mem.eql(u8, contents[contents.len - "end".len ..], "end"));61 try expect(mem.eql(u8, contents[contents.len - "end".len ..], "end"));
62 }62 }
63 try tmp.dir.deleteFile(tmp_file_name);63 try tmp.dir.deleteFile(tmp_file_name);
64}64}
...@@ -90,20 +90,20 @@ test "BitStreams with File Stream" {...@@ -90,20 +90,20 @@ test "BitStreams with File Stream" {
9090
91 var out_bits: usize = undefined;91 var out_bits: usize = undefined;
9292
93 expect(1 == try bit_stream.readBits(u2, 1, &out_bits));93 try expect(1 == try bit_stream.readBits(u2, 1, &out_bits));
94 expect(out_bits == 1);94 try expect(out_bits == 1);
95 expect(2 == try bit_stream.readBits(u5, 2, &out_bits));95 try expect(2 == try bit_stream.readBits(u5, 2, &out_bits));
96 expect(out_bits == 2);96 try expect(out_bits == 2);
97 expect(3 == try bit_stream.readBits(u128, 3, &out_bits));97 try expect(3 == try bit_stream.readBits(u128, 3, &out_bits));
98 expect(out_bits == 3);98 try expect(out_bits == 3);
99 expect(4 == try bit_stream.readBits(u8, 4, &out_bits));99 try expect(4 == try bit_stream.readBits(u8, 4, &out_bits));
100 expect(out_bits == 4);100 try expect(out_bits == 4);
101 expect(5 == try bit_stream.readBits(u9, 5, &out_bits));101 try expect(5 == try bit_stream.readBits(u9, 5, &out_bits));
102 expect(out_bits == 5);102 try expect(out_bits == 5);
103 expect(1 == try bit_stream.readBits(u1, 1, &out_bits));103 try expect(1 == try bit_stream.readBits(u1, 1, &out_bits));
104 expect(out_bits == 1);104 try expect(out_bits == 1);
105105
106 expectError(error.EndOfStream, bit_stream.readBitsNoEof(u1, 1));106 try expectError(error.EndOfStream, bit_stream.readBitsNoEof(u1, 1));
107 }107 }
108 try tmp.dir.deleteFile(tmp_file_name);108 try tmp.dir.deleteFile(tmp_file_name);
109}109}
...@@ -123,16 +123,16 @@ test "File seek ops" {...@@ -123,16 +123,16 @@ test "File seek ops" {
123123
124 // Seek to the end124 // Seek to the end
125 try file.seekFromEnd(0);125 try file.seekFromEnd(0);
126 expect((try file.getPos()) == try file.getEndPos());126 try expect((try file.getPos()) == try file.getEndPos());
127 // Negative delta127 // Negative delta
128 try file.seekBy(-4096);128 try file.seekBy(-4096);
129 expect((try file.getPos()) == 4096);129 try expect((try file.getPos()) == 4096);
130 // Positive delta130 // Positive delta
131 try file.seekBy(10);131 try file.seekBy(10);
132 expect((try file.getPos()) == 4106);132 try expect((try file.getPos()) == 4106);
133 // Absolute position133 // Absolute position
134 try file.seekTo(1234);134 try file.seekTo(1234);
135 expect((try file.getPos()) == 1234);135 try expect((try file.getPos()) == 1234);
136}136}
137137
138test "setEndPos" {138test "setEndPos" {
...@@ -147,18 +147,18 @@ test "setEndPos" {...@@ -147,18 +147,18 @@ test "setEndPos" {
147 }147 }
148148
149 // Verify that the file size changes and the file offset is not moved149 // Verify that the file size changes and the file offset is not moved
150 std.testing.expect((try file.getEndPos()) == 0);150 try std.testing.expect((try file.getEndPos()) == 0);
151 std.testing.expect((try file.getPos()) == 0);151 try std.testing.expect((try file.getPos()) == 0);
152 try file.setEndPos(8192);152 try file.setEndPos(8192);
153 std.testing.expect((try file.getEndPos()) == 8192);153 try std.testing.expect((try file.getEndPos()) == 8192);
154 std.testing.expect((try file.getPos()) == 0);154 try std.testing.expect((try file.getPos()) == 0);
155 try file.seekTo(100);155 try file.seekTo(100);
156 try file.setEndPos(4096);156 try file.setEndPos(4096);
157 std.testing.expect((try file.getEndPos()) == 4096);157 try std.testing.expect((try file.getEndPos()) == 4096);
158 std.testing.expect((try file.getPos()) == 100);158 try std.testing.expect((try file.getPos()) == 100);
159 try file.setEndPos(0);159 try file.setEndPos(0);
160 std.testing.expect((try file.getEndPos()) == 0);160 try std.testing.expect((try file.getEndPos()) == 0);
161 std.testing.expect((try file.getPos()) == 100);161 try std.testing.expect((try file.getPos()) == 100);
162}162}
163163
164test "updateTimes" {164test "updateTimes" {
...@@ -178,6 +178,6 @@ test "updateTimes" {...@@ -178,6 +178,6 @@ test "updateTimes" {
178 stat_old.mtime - 5 * std.time.ns_per_s,178 stat_old.mtime - 5 * std.time.ns_per_s,
179 );179 );
180 var stat_new = try file.stat();180 var stat_new = try file.stat();
181 expect(stat_new.atime < stat_old.atime);181 try expect(stat_new.atime < stat_old.atime);
182 expect(stat_new.mtime < stat_old.mtime);182 try expect(stat_new.mtime < stat_old.mtime);
183}183}
lib/std/json.zig+139-139
...@@ -79,18 +79,18 @@ fn encodesTo(decoded: []const u8, encoded: []const u8) bool {...@@ -79,18 +79,18 @@ fn encodesTo(decoded: []const u8, encoded: []const u8) bool {
7979
80test "encodesTo" {80test "encodesTo" {
81 // same81 // same
82 testing.expectEqual(true, encodesTo("false", "false"));82 try testing.expectEqual(true, encodesTo("false", "false"));
83 // totally different83 // totally different
84 testing.expectEqual(false, encodesTo("false", "true"));84 try testing.expectEqual(false, encodesTo("false", "true"));
85 // different lengths85 // different lengths
86 testing.expectEqual(false, encodesTo("false", "other"));86 try testing.expectEqual(false, encodesTo("false", "other"));
87 // with escape87 // with escape
88 testing.expectEqual(true, encodesTo("\\", "\\\\"));88 try testing.expectEqual(true, encodesTo("\\", "\\\\"));
89 testing.expectEqual(true, encodesTo("with\nescape", "with\\nescape"));89 try testing.expectEqual(true, encodesTo("with\nescape", "with\\nescape"));
90 // with unicode90 // with unicode
91 testing.expectEqual(true, encodesTo("ą", "\\u0105"));91 try testing.expectEqual(true, encodesTo("ą", "\\u0105"));
92 testing.expectEqual(true, encodesTo("😂", "\\ud83d\\ude02"));92 try testing.expectEqual(true, encodesTo("😂", "\\ud83d\\ude02"));
93 testing.expectEqual(true, encodesTo("withąunicode😂", "with\\u0105unicode\\ud83d\\ude02"));93 try testing.expectEqual(true, encodesTo("withąunicode😂", "with\\u0105unicode\\ud83d\\ude02"));
94}94}
9595
96/// A single token slice into the parent string.96/// A single token slice into the parent string.
...@@ -1138,9 +1138,9 @@ pub const TokenStream = struct {...@@ -1138,9 +1138,9 @@ pub const TokenStream = struct {
1138 }1138 }
1139};1139};
11401140
1141fn checkNext(p: *TokenStream, id: std.meta.Tag(Token)) void {1141fn checkNext(p: *TokenStream, id: std.meta.Tag(Token)) !void {
1142 const token = (p.next() catch unreachable).?;1142 const token = (p.next() catch unreachable).?;
1143 debug.assert(std.meta.activeTag(token) == id);1143 try testing.expect(std.meta.activeTag(token) == id);
1144}1144}
11451145
1146test "json.token" {1146test "json.token" {
...@@ -1163,46 +1163,46 @@ test "json.token" {...@@ -1163,46 +1163,46 @@ test "json.token" {
11631163
1164 var p = TokenStream.init(s);1164 var p = TokenStream.init(s);
11651165
1166 checkNext(&p, .ObjectBegin);1166 try checkNext(&p, .ObjectBegin);
1167 checkNext(&p, .String); // Image1167 try checkNext(&p, .String); // Image
1168 checkNext(&p, .ObjectBegin);1168 try checkNext(&p, .ObjectBegin);
1169 checkNext(&p, .String); // Width1169 try checkNext(&p, .String); // Width
1170 checkNext(&p, .Number);1170 try checkNext(&p, .Number);
1171 checkNext(&p, .String); // Height1171 try checkNext(&p, .String); // Height
1172 checkNext(&p, .Number);1172 try checkNext(&p, .Number);
1173 checkNext(&p, .String); // Title1173 try checkNext(&p, .String); // Title
1174 checkNext(&p, .String);1174 try checkNext(&p, .String);
1175 checkNext(&p, .String); // Thumbnail1175 try checkNext(&p, .String); // Thumbnail
1176 checkNext(&p, .ObjectBegin);1176 try checkNext(&p, .ObjectBegin);
1177 checkNext(&p, .String); // Url1177 try checkNext(&p, .String); // Url
1178 checkNext(&p, .String);1178 try checkNext(&p, .String);
1179 checkNext(&p, .String); // Height1179 try checkNext(&p, .String); // Height
1180 checkNext(&p, .Number);1180 try checkNext(&p, .Number);
1181 checkNext(&p, .String); // Width1181 try checkNext(&p, .String); // Width
1182 checkNext(&p, .Number);1182 try checkNext(&p, .Number);
1183 checkNext(&p, .ObjectEnd);1183 try checkNext(&p, .ObjectEnd);
1184 checkNext(&p, .String); // Animated1184 try checkNext(&p, .String); // Animated
1185 checkNext(&p, .False);1185 try checkNext(&p, .False);
1186 checkNext(&p, .String); // IDs1186 try checkNext(&p, .String); // IDs
1187 checkNext(&p, .ArrayBegin);1187 try checkNext(&p, .ArrayBegin);
1188 checkNext(&p, .Number);1188 try checkNext(&p, .Number);
1189 checkNext(&p, .Number);1189 try checkNext(&p, .Number);
1190 checkNext(&p, .Number);1190 try checkNext(&p, .Number);
1191 checkNext(&p, .Number);1191 try checkNext(&p, .Number);
1192 checkNext(&p, .ArrayEnd);1192 try checkNext(&p, .ArrayEnd);
1193 checkNext(&p, .ObjectEnd);1193 try checkNext(&p, .ObjectEnd);
1194 checkNext(&p, .ObjectEnd);1194 try checkNext(&p, .ObjectEnd);
11951195
1196 testing.expect((try p.next()) == null);1196 try testing.expect((try p.next()) == null);
1197}1197}
11981198
1199test "json.token mismatched close" {1199test "json.token mismatched close" {
1200 var p = TokenStream.init("[102, 111, 111 }");1200 var p = TokenStream.init("[102, 111, 111 }");
1201 checkNext(&p, .ArrayBegin);1201 try checkNext(&p, .ArrayBegin);
1202 checkNext(&p, .Number);1202 try checkNext(&p, .Number);
1203 checkNext(&p, .Number);1203 try checkNext(&p, .Number);
1204 checkNext(&p, .Number);1204 try checkNext(&p, .Number);
1205 testing.expectError(error.UnexpectedClosingBrace, p.next());1205 try testing.expectError(error.UnexpectedClosingBrace, p.next());
1206}1206}
12071207
1208/// Validate a JSON string. This does not limit number precision so a decoder may not necessarily1208/// Validate a JSON string. This does not limit number precision so a decoder may not necessarily
...@@ -1223,12 +1223,12 @@ pub fn validate(s: []const u8) bool {...@@ -1223,12 +1223,12 @@ pub fn validate(s: []const u8) bool {
1223}1223}
12241224
1225test "json.validate" {1225test "json.validate" {
1226 testing.expectEqual(true, validate("{}"));1226 try testing.expectEqual(true, validate("{}"));
1227 testing.expectEqual(true, validate("[]"));1227 try testing.expectEqual(true, validate("[]"));
1228 testing.expectEqual(true, validate("[{[[[[{}]]]]}]"));1228 try testing.expectEqual(true, validate("[{[[[[{}]]]]}]"));
1229 testing.expectEqual(false, validate("{]"));1229 try testing.expectEqual(false, validate("{]"));
1230 testing.expectEqual(false, validate("[}"));1230 try testing.expectEqual(false, validate("[}"));
1231 testing.expectEqual(false, validate("{{{{[]}}}]"));1231 try testing.expectEqual(false, validate("{{{{[]}}}]"));
1232}1232}
12331233
1234const Allocator = std.mem.Allocator;1234const Allocator = std.mem.Allocator;
...@@ -1326,37 +1326,37 @@ test "Value.jsonStringify" {...@@ -1326,37 +1326,37 @@ test "Value.jsonStringify" {
1326 var buffer: [10]u8 = undefined;1326 var buffer: [10]u8 = undefined;
1327 var fbs = std.io.fixedBufferStream(&buffer);1327 var fbs = std.io.fixedBufferStream(&buffer);
1328 try @as(Value, .Null).jsonStringify(.{}, fbs.writer());1328 try @as(Value, .Null).jsonStringify(.{}, fbs.writer());
1329 testing.expectEqualSlices(u8, fbs.getWritten(), "null");1329 try testing.expectEqualSlices(u8, fbs.getWritten(), "null");
1330 }1330 }
1331 {1331 {
1332 var buffer: [10]u8 = undefined;1332 var buffer: [10]u8 = undefined;
1333 var fbs = std.io.fixedBufferStream(&buffer);1333 var fbs = std.io.fixedBufferStream(&buffer);
1334 try (Value{ .Bool = true }).jsonStringify(.{}, fbs.writer());1334 try (Value{ .Bool = true }).jsonStringify(.{}, fbs.writer());
1335 testing.expectEqualSlices(u8, fbs.getWritten(), "true");1335 try testing.expectEqualSlices(u8, fbs.getWritten(), "true");
1336 }1336 }
1337 {1337 {
1338 var buffer: [10]u8 = undefined;1338 var buffer: [10]u8 = undefined;
1339 var fbs = std.io.fixedBufferStream(&buffer);1339 var fbs = std.io.fixedBufferStream(&buffer);
1340 try (Value{ .Integer = 42 }).jsonStringify(.{}, fbs.writer());1340 try (Value{ .Integer = 42 }).jsonStringify(.{}, fbs.writer());
1341 testing.expectEqualSlices(u8, fbs.getWritten(), "42");1341 try testing.expectEqualSlices(u8, fbs.getWritten(), "42");
1342 }1342 }
1343 {1343 {
1344 var buffer: [10]u8 = undefined;1344 var buffer: [10]u8 = undefined;
1345 var fbs = std.io.fixedBufferStream(&buffer);1345 var fbs = std.io.fixedBufferStream(&buffer);
1346 try (Value{ .NumberString = "43" }).jsonStringify(.{}, fbs.writer());1346 try (Value{ .NumberString = "43" }).jsonStringify(.{}, fbs.writer());
1347 testing.expectEqualSlices(u8, fbs.getWritten(), "43");1347 try testing.expectEqualSlices(u8, fbs.getWritten(), "43");
1348 }1348 }
1349 {1349 {
1350 var buffer: [10]u8 = undefined;1350 var buffer: [10]u8 = undefined;
1351 var fbs = std.io.fixedBufferStream(&buffer);1351 var fbs = std.io.fixedBufferStream(&buffer);
1352 try (Value{ .Float = 42 }).jsonStringify(.{}, fbs.writer());1352 try (Value{ .Float = 42 }).jsonStringify(.{}, fbs.writer());
1353 testing.expectEqualSlices(u8, fbs.getWritten(), "4.2e+01");1353 try testing.expectEqualSlices(u8, fbs.getWritten(), "4.2e+01");
1354 }1354 }
1355 {1355 {
1356 var buffer: [10]u8 = undefined;1356 var buffer: [10]u8 = undefined;
1357 var fbs = std.io.fixedBufferStream(&buffer);1357 var fbs = std.io.fixedBufferStream(&buffer);
1358 try (Value{ .String = "weeee" }).jsonStringify(.{}, fbs.writer());1358 try (Value{ .String = "weeee" }).jsonStringify(.{}, fbs.writer());
1359 testing.expectEqualSlices(u8, fbs.getWritten(), "\"weeee\"");1359 try testing.expectEqualSlices(u8, fbs.getWritten(), "\"weeee\"");
1360 }1360 }
1361 {1361 {
1362 var buffer: [10]u8 = undefined;1362 var buffer: [10]u8 = undefined;
...@@ -1369,7 +1369,7 @@ test "Value.jsonStringify" {...@@ -1369,7 +1369,7 @@ test "Value.jsonStringify" {
1369 try (Value{1369 try (Value{
1370 .Array = Array.fromOwnedSlice(undefined, &vals),1370 .Array = Array.fromOwnedSlice(undefined, &vals),
1371 }).jsonStringify(.{}, fbs.writer());1371 }).jsonStringify(.{}, fbs.writer());
1372 testing.expectEqualSlices(u8, fbs.getWritten(), "[1,2,3]");1372 try testing.expectEqualSlices(u8, fbs.getWritten(), "[1,2,3]");
1373 }1373 }
1374 {1374 {
1375 var buffer: [10]u8 = undefined;1375 var buffer: [10]u8 = undefined;
...@@ -1378,7 +1378,7 @@ test "Value.jsonStringify" {...@@ -1378,7 +1378,7 @@ test "Value.jsonStringify" {
1378 defer obj.deinit();1378 defer obj.deinit();
1379 try obj.putNoClobber("a", .{ .String = "b" });1379 try obj.putNoClobber("a", .{ .String = "b" });
1380 try (Value{ .Object = obj }).jsonStringify(.{}, fbs.writer());1380 try (Value{ .Object = obj }).jsonStringify(.{}, fbs.writer());
1381 testing.expectEqualSlices(u8, fbs.getWritten(), "{\"a\":\"b\"}");1381 try testing.expectEqualSlices(u8, fbs.getWritten(), "{\"a\":\"b\"}");
1382 }1382 }
1383}1383}
13841384
...@@ -1751,17 +1751,17 @@ pub fn parseFree(comptime T: type, value: T, options: ParseOptions) void {...@@ -1751,17 +1751,17 @@ pub fn parseFree(comptime T: type, value: T, options: ParseOptions) void {
1751}1751}
17521752
1753test "parse" {1753test "parse" {
1754 testing.expectEqual(false, try parse(bool, &TokenStream.init("false"), ParseOptions{}));1754 try testing.expectEqual(false, try parse(bool, &TokenStream.init("false"), ParseOptions{}));
1755 testing.expectEqual(true, try parse(bool, &TokenStream.init("true"), ParseOptions{}));1755 try testing.expectEqual(true, try parse(bool, &TokenStream.init("true"), ParseOptions{}));
1756 testing.expectEqual(@as(u1, 1), try parse(u1, &TokenStream.init("1"), ParseOptions{}));1756 try testing.expectEqual(@as(u1, 1), try parse(u1, &TokenStream.init("1"), ParseOptions{}));
1757 testing.expectError(error.Overflow, parse(u1, &TokenStream.init("50"), ParseOptions{}));1757 try testing.expectError(error.Overflow, parse(u1, &TokenStream.init("50"), ParseOptions{}));
1758 testing.expectEqual(@as(u64, 42), try parse(u64, &TokenStream.init("42"), ParseOptions{}));1758 try testing.expectEqual(@as(u64, 42), try parse(u64, &TokenStream.init("42"), ParseOptions{}));
1759 testing.expectEqual(@as(f64, 42), try parse(f64, &TokenStream.init("42.0"), ParseOptions{}));1759 try testing.expectEqual(@as(f64, 42), try parse(f64, &TokenStream.init("42.0"), ParseOptions{}));
1760 testing.expectEqual(@as(?bool, null), try parse(?bool, &TokenStream.init("null"), ParseOptions{}));1760 try testing.expectEqual(@as(?bool, null), try parse(?bool, &TokenStream.init("null"), ParseOptions{}));
1761 testing.expectEqual(@as(?bool, true), try parse(?bool, &TokenStream.init("true"), ParseOptions{}));1761 try testing.expectEqual(@as(?bool, true), try parse(?bool, &TokenStream.init("true"), ParseOptions{}));
17621762
1763 testing.expectEqual(@as([3]u8, "foo".*), try parse([3]u8, &TokenStream.init("\"foo\""), ParseOptions{}));1763 try testing.expectEqual(@as([3]u8, "foo".*), try parse([3]u8, &TokenStream.init("\"foo\""), ParseOptions{}));
1764 testing.expectEqual(@as([3]u8, "foo".*), try parse([3]u8, &TokenStream.init("[102, 111, 111]"), ParseOptions{}));1764 try testing.expectEqual(@as([3]u8, "foo".*), try parse([3]u8, &TokenStream.init("[102, 111, 111]"), ParseOptions{}));
1765}1765}
17661766
1767test "parse into enum" {1767test "parse into enum" {
...@@ -1770,31 +1770,31 @@ test "parse into enum" {...@@ -1770,31 +1770,31 @@ test "parse into enum" {
1770 Bar,1770 Bar,
1771 @"with\\escape",1771 @"with\\escape",
1772 };1772 };
1773 testing.expectEqual(@as(T, .Foo), try parse(T, &TokenStream.init("\"Foo\""), ParseOptions{}));1773 try testing.expectEqual(@as(T, .Foo), try parse(T, &TokenStream.init("\"Foo\""), ParseOptions{}));
1774 testing.expectEqual(@as(T, .Foo), try parse(T, &TokenStream.init("42"), ParseOptions{}));1774 try testing.expectEqual(@as(T, .Foo), try parse(T, &TokenStream.init("42"), ParseOptions{}));
1775 testing.expectEqual(@as(T, .@"with\\escape"), try parse(T, &TokenStream.init("\"with\\\\escape\""), ParseOptions{}));1775 try testing.expectEqual(@as(T, .@"with\\escape"), try parse(T, &TokenStream.init("\"with\\\\escape\""), ParseOptions{}));
1776 testing.expectError(error.InvalidEnumTag, parse(T, &TokenStream.init("5"), ParseOptions{}));1776 try testing.expectError(error.InvalidEnumTag, parse(T, &TokenStream.init("5"), ParseOptions{}));
1777 testing.expectError(error.InvalidEnumTag, parse(T, &TokenStream.init("\"Qux\""), ParseOptions{}));1777 try testing.expectError(error.InvalidEnumTag, parse(T, &TokenStream.init("\"Qux\""), ParseOptions{}));
1778}1778}
17791779
1780test "parse into that allocates a slice" {1780test "parse into that allocates a slice" {
1781 testing.expectError(error.AllocatorRequired, parse([]u8, &TokenStream.init("\"foo\""), ParseOptions{}));1781 try testing.expectError(error.AllocatorRequired, parse([]u8, &TokenStream.init("\"foo\""), ParseOptions{}));
17821782
1783 const options = ParseOptions{ .allocator = testing.allocator };1783 const options = ParseOptions{ .allocator = testing.allocator };
1784 {1784 {
1785 const r = try parse([]u8, &TokenStream.init("\"foo\""), options);1785 const r = try parse([]u8, &TokenStream.init("\"foo\""), options);
1786 defer parseFree([]u8, r, options);1786 defer parseFree([]u8, r, options);
1787 testing.expectEqualSlices(u8, "foo", r);1787 try testing.expectEqualSlices(u8, "foo", r);
1788 }1788 }
1789 {1789 {
1790 const r = try parse([]u8, &TokenStream.init("[102, 111, 111]"), options);1790 const r = try parse([]u8, &TokenStream.init("[102, 111, 111]"), options);
1791 defer parseFree([]u8, r, options);1791 defer parseFree([]u8, r, options);
1792 testing.expectEqualSlices(u8, "foo", r);1792 try testing.expectEqualSlices(u8, "foo", r);
1793 }1793 }
1794 {1794 {
1795 const r = try parse([]u8, &TokenStream.init("\"with\\\\escape\""), options);1795 const r = try parse([]u8, &TokenStream.init("\"with\\\\escape\""), options);
1796 defer parseFree([]u8, r, options);1796 defer parseFree([]u8, r, options);
1797 testing.expectEqualSlices(u8, "with\\escape", r);1797 try testing.expectEqualSlices(u8, "with\\escape", r);
1798 }1798 }
1799}1799}
18001800
...@@ -1805,7 +1805,7 @@ test "parse into tagged union" {...@@ -1805,7 +1805,7 @@ test "parse into tagged union" {
1805 float: f64,1805 float: f64,
1806 string: []const u8,1806 string: []const u8,
1807 };1807 };
1808 testing.expectEqual(T{ .float = 1.5 }, try parse(T, &TokenStream.init("1.5"), ParseOptions{}));1808 try testing.expectEqual(T{ .float = 1.5 }, try parse(T, &TokenStream.init("1.5"), ParseOptions{}));
1809 }1809 }
18101810
1811 { // failing allocations should be bubbled up instantly without trying next member1811 { // failing allocations should be bubbled up instantly without trying next member
...@@ -1816,7 +1816,7 @@ test "parse into tagged union" {...@@ -1816,7 +1816,7 @@ test "parse into tagged union" {
1816 string: []const u8,1816 string: []const u8,
1817 array: [3]u8,1817 array: [3]u8,
1818 };1818 };
1819 testing.expectError(error.OutOfMemory, parse(T, &TokenStream.init("[1,2,3]"), options));1819 try testing.expectError(error.OutOfMemory, parse(T, &TokenStream.init("[1,2,3]"), options));
1820 }1820 }
18211821
1822 {1822 {
...@@ -1825,7 +1825,7 @@ test "parse into tagged union" {...@@ -1825,7 +1825,7 @@ test "parse into tagged union" {
1825 x: u8,1825 x: u8,
1826 y: u8,1826 y: u8,
1827 };1827 };
1828 testing.expectEqual(T{ .x = 42 }, try parse(T, &TokenStream.init("42"), ParseOptions{}));1828 try testing.expectEqual(T{ .x = 42 }, try parse(T, &TokenStream.init("42"), ParseOptions{}));
1829 }1829 }
18301830
1831 { // needs to back out when first union member doesn't match1831 { // needs to back out when first union member doesn't match
...@@ -1833,7 +1833,7 @@ test "parse into tagged union" {...@@ -1833,7 +1833,7 @@ test "parse into tagged union" {
1833 A: struct { x: u32 },1833 A: struct { x: u32 },
1834 B: struct { y: u32 },1834 B: struct { y: u32 },
1835 };1835 };
1836 testing.expectEqual(T{ .B = .{ .y = 42 } }, try parse(T, &TokenStream.init("{\"y\":42}"), ParseOptions{}));1836 try testing.expectEqual(T{ .B = .{ .y = 42 } }, try parse(T, &TokenStream.init("{\"y\":42}"), ParseOptions{}));
1837 }1837 }
1838}1838}
18391839
...@@ -1843,7 +1843,7 @@ test "parse union bubbles up AllocatorRequired" {...@@ -1843,7 +1843,7 @@ test "parse union bubbles up AllocatorRequired" {
1843 string: []const u8,1843 string: []const u8,
1844 int: i32,1844 int: i32,
1845 };1845 };
1846 testing.expectError(error.AllocatorRequired, parse(T, &TokenStream.init("42"), ParseOptions{}));1846 try testing.expectError(error.AllocatorRequired, parse(T, &TokenStream.init("42"), ParseOptions{}));
1847 }1847 }
18481848
1849 { // string member not first in union (and matching)1849 { // string member not first in union (and matching)
...@@ -1852,7 +1852,7 @@ test "parse union bubbles up AllocatorRequired" {...@@ -1852,7 +1852,7 @@ test "parse union bubbles up AllocatorRequired" {
1852 float: f64,1852 float: f64,
1853 string: []const u8,1853 string: []const u8,
1854 };1854 };
1855 testing.expectError(error.AllocatorRequired, parse(T, &TokenStream.init("\"foo\""), ParseOptions{}));1855 try testing.expectError(error.AllocatorRequired, parse(T, &TokenStream.init("\"foo\""), ParseOptions{}));
1856 }1856 }
1857}1857}
18581858
...@@ -1866,11 +1866,11 @@ test "parseFree descends into tagged union" {...@@ -1866,11 +1866,11 @@ test "parseFree descends into tagged union" {
1866 };1866 };
1867 // use a string with unicode escape so we know result can't be a reference to global constant1867 // use a string with unicode escape so we know result can't be a reference to global constant
1868 const r = try parse(T, &TokenStream.init("\"with\\u0105unicode\""), options);1868 const r = try parse(T, &TokenStream.init("\"with\\u0105unicode\""), options);
1869 testing.expectEqual(std.meta.Tag(T).string, @as(std.meta.Tag(T), r));1869 try testing.expectEqual(std.meta.Tag(T).string, @as(std.meta.Tag(T), r));
1870 testing.expectEqualSlices(u8, "withąunicode", r.string);1870 try testing.expectEqualSlices(u8, "withąunicode", r.string);
1871 testing.expectEqual(@as(usize, 0), fail_alloc.deallocations);1871 try testing.expectEqual(@as(usize, 0), fail_alloc.deallocations);
1872 parseFree(T, r, options);1872 parseFree(T, r, options);
1873 testing.expectEqual(@as(usize, 1), fail_alloc.deallocations);1873 try testing.expectEqual(@as(usize, 1), fail_alloc.deallocations);
1874}1874}
18751875
1876test "parse with comptime field" {1876test "parse with comptime field" {
...@@ -1879,7 +1879,7 @@ test "parse with comptime field" {...@@ -1879,7 +1879,7 @@ test "parse with comptime field" {
1879 comptime a: i32 = 0,1879 comptime a: i32 = 0,
1880 b: bool,1880 b: bool,
1881 };1881 };
1882 testing.expectEqual(T{ .a = 0, .b = true }, try parse(T, &TokenStream.init(1882 try testing.expectEqual(T{ .a = 0, .b = true }, try parse(T, &TokenStream.init(
1883 \\{1883 \\{
1884 \\ "a": 0,1884 \\ "a": 0,
1885 \\ "b": true1885 \\ "b": true
...@@ -1912,7 +1912,7 @@ test "parse with comptime field" {...@@ -1912,7 +1912,7 @@ test "parse with comptime field" {
19121912
1913test "parse into struct with no fields" {1913test "parse into struct with no fields" {
1914 const T = struct {};1914 const T = struct {};
1915 testing.expectEqual(T{}, try parse(T, &TokenStream.init("{}"), ParseOptions{}));1915 try testing.expectEqual(T{}, try parse(T, &TokenStream.init("{}"), ParseOptions{}));
1916}1916}
19171917
1918test "parse into struct with misc fields" {1918test "parse into struct with misc fields" {
...@@ -1968,24 +1968,24 @@ test "parse into struct with misc fields" {...@@ -1968,24 +1968,24 @@ test "parse into struct with misc fields" {
1968 \\}1968 \\}
1969 ), options);1969 ), options);
1970 defer parseFree(T, r, options);1970 defer parseFree(T, r, options);
1971 testing.expectEqual(@as(i64, 420), r.int);1971 try testing.expectEqual(@as(i64, 420), r.int);
1972 testing.expectEqual(@as(f64, 3.14), r.float);1972 try testing.expectEqual(@as(f64, 3.14), r.float);
1973 testing.expectEqual(true, r.@"with\\escape");1973 try testing.expectEqual(true, r.@"with\\escape");
1974 testing.expectEqual(false, r.@"withąunicode😂");1974 try testing.expectEqual(false, r.@"withąunicode😂");
1975 testing.expectEqualSlices(u8, "zig", r.language);1975 try testing.expectEqualSlices(u8, "zig", r.language);
1976 testing.expectEqual(@as(?bool, null), r.optional);1976 try testing.expectEqual(@as(?bool, null), r.optional);
1977 testing.expectEqual(@as(i32, 42), r.default_field);1977 try testing.expectEqual(@as(i32, 42), r.default_field);
1978 testing.expectEqual(@as(f64, 66.6), r.static_array[0]);1978 try testing.expectEqual(@as(f64, 66.6), r.static_array[0]);
1979 testing.expectEqual(@as(f64, 420.420), r.static_array[1]);1979 try testing.expectEqual(@as(f64, 420.420), r.static_array[1]);
1980 testing.expectEqual(@as(f64, 69.69), r.static_array[2]);1980 try testing.expectEqual(@as(f64, 69.69), r.static_array[2]);
1981 testing.expectEqual(@as(usize, 3), r.dynamic_array.len);1981 try testing.expectEqual(@as(usize, 3), r.dynamic_array.len);
1982 testing.expectEqual(@as(f64, 66.6), r.dynamic_array[0]);1982 try testing.expectEqual(@as(f64, 66.6), r.dynamic_array[0]);
1983 testing.expectEqual(@as(f64, 420.420), r.dynamic_array[1]);1983 try testing.expectEqual(@as(f64, 420.420), r.dynamic_array[1]);
1984 testing.expectEqual(@as(f64, 69.69), r.dynamic_array[2]);1984 try testing.expectEqual(@as(f64, 69.69), r.dynamic_array[2]);
1985 testing.expectEqualSlices(u8, r.complex.nested, "zig");1985 try testing.expectEqualSlices(u8, r.complex.nested, "zig");
1986 testing.expectEqualSlices(u8, "zig", r.veryComplex[0].foo);1986 try testing.expectEqualSlices(u8, "zig", r.veryComplex[0].foo);
1987 testing.expectEqualSlices(u8, "rocks", r.veryComplex[1].foo);1987 try testing.expectEqualSlices(u8, "rocks", r.veryComplex[1].foo);
1988 testing.expectEqual(T.Union{ .float = 100000 }, r.a_union);1988 try testing.expectEqual(T.Union{ .float = 100000 }, r.a_union);
1989}1989}
19901990
1991/// A non-stream JSON parser which constructs a tree of Value's.1991/// A non-stream JSON parser which constructs a tree of Value's.
...@@ -2320,28 +2320,28 @@ test "json.parser.dynamic" {...@@ -2320,28 +2320,28 @@ test "json.parser.dynamic" {
2320 var image = root.Object.get("Image").?;2320 var image = root.Object.get("Image").?;
23212321
2322 const width = image.Object.get("Width").?;2322 const width = image.Object.get("Width").?;
2323 testing.expect(width.Integer == 800);2323 try testing.expect(width.Integer == 800);
23242324
2325 const height = image.Object.get("Height").?;2325 const height = image.Object.get("Height").?;
2326 testing.expect(height.Integer == 600);2326 try testing.expect(height.Integer == 600);
23272327
2328 const title = image.Object.get("Title").?;2328 const title = image.Object.get("Title").?;
2329 testing.expect(mem.eql(u8, title.String, "View from 15th Floor"));2329 try testing.expect(mem.eql(u8, title.String, "View from 15th Floor"));
23302330
2331 const animated = image.Object.get("Animated").?;2331 const animated = image.Object.get("Animated").?;
2332 testing.expect(animated.Bool == false);2332 try testing.expect(animated.Bool == false);
23332333
2334 const array_of_object = image.Object.get("ArrayOfObject").?;2334 const array_of_object = image.Object.get("ArrayOfObject").?;
2335 testing.expect(array_of_object.Array.items.len == 1);2335 try testing.expect(array_of_object.Array.items.len == 1);
23362336
2337 const obj0 = array_of_object.Array.items[0].Object.get("n").?;2337 const obj0 = array_of_object.Array.items[0].Object.get("n").?;
2338 testing.expect(mem.eql(u8, obj0.String, "m"));2338 try testing.expect(mem.eql(u8, obj0.String, "m"));
23392339
2340 const double = image.Object.get("double").?;2340 const double = image.Object.get("double").?;
2341 testing.expect(double.Float == 1.3412);2341 try testing.expect(double.Float == 1.3412);
23422342
2343 const large_int = image.Object.get("LargeInt").?;2343 const large_int = image.Object.get("LargeInt").?;
2344 testing.expect(mem.eql(u8, large_int.NumberString, "18446744073709551615"));2344 try testing.expect(mem.eql(u8, large_int.NumberString, "18446744073709551615"));
2345}2345}
23462346
2347test "import more json tests" {2347test "import more json tests" {
...@@ -2388,12 +2388,12 @@ test "write json then parse it" {...@@ -2388,12 +2388,12 @@ test "write json then parse it" {
2388 var tree = try parser.parse(fixed_buffer_stream.getWritten());2388 var tree = try parser.parse(fixed_buffer_stream.getWritten());
2389 defer tree.deinit();2389 defer tree.deinit();
23902390
2391 testing.expect(tree.root.Object.get("f").?.Bool == false);2391 try testing.expect(tree.root.Object.get("f").?.Bool == false);
2392 testing.expect(tree.root.Object.get("t").?.Bool == true);2392 try testing.expect(tree.root.Object.get("t").?.Bool == true);
2393 testing.expect(tree.root.Object.get("int").?.Integer == 1234);2393 try testing.expect(tree.root.Object.get("int").?.Integer == 1234);
2394 testing.expect(tree.root.Object.get("array").?.Array.items[0].Null == {});2394 try testing.expect(tree.root.Object.get("array").?.Array.items[0].Null == {});
2395 testing.expect(tree.root.Object.get("array").?.Array.items[1].Float == 12.34);2395 try testing.expect(tree.root.Object.get("array").?.Array.items[1].Float == 12.34);
2396 testing.expect(mem.eql(u8, tree.root.Object.get("str").?.String, "hello"));2396 try testing.expect(mem.eql(u8, tree.root.Object.get("str").?.String, "hello"));
2397}2397}
23982398
2399fn test_parse(arena_allocator: *std.mem.Allocator, json_str: []const u8) !Value {2399fn test_parse(arena_allocator: *std.mem.Allocator, json_str: []const u8) !Value {
...@@ -2404,7 +2404,7 @@ fn test_parse(arena_allocator: *std.mem.Allocator, json_str: []const u8) !Value...@@ -2404,7 +2404,7 @@ fn test_parse(arena_allocator: *std.mem.Allocator, json_str: []const u8) !Value
2404test "parsing empty string gives appropriate error" {2404test "parsing empty string gives appropriate error" {
2405 var arena_allocator = std.heap.ArenaAllocator.init(std.testing.allocator);2405 var arena_allocator = std.heap.ArenaAllocator.init(std.testing.allocator);
2406 defer arena_allocator.deinit();2406 defer arena_allocator.deinit();
2407 testing.expectError(error.UnexpectedEndOfJson, test_parse(&arena_allocator.allocator, ""));2407 try testing.expectError(error.UnexpectedEndOfJson, test_parse(&arena_allocator.allocator, ""));
2408}2408}
24092409
2410test "integer after float has proper type" {2410test "integer after float has proper type" {
...@@ -2416,7 +2416,7 @@ test "integer after float has proper type" {...@@ -2416,7 +2416,7 @@ test "integer after float has proper type" {
2416 \\ "ints": [1, 2, 3]2416 \\ "ints": [1, 2, 3]
2417 \\}2417 \\}
2418 );2418 );
2419 std.testing.expect(json.Object.get("ints").?.Array.items[0] == .Integer);2419 try std.testing.expect(json.Object.get("ints").?.Array.items[0] == .Integer);
2420}2420}
24212421
2422test "escaped characters" {2422test "escaped characters" {
...@@ -2439,16 +2439,16 @@ test "escaped characters" {...@@ -2439,16 +2439,16 @@ test "escaped characters" {
24392439
2440 const obj = (try test_parse(&arena_allocator.allocator, input)).Object;2440 const obj = (try test_parse(&arena_allocator.allocator, input)).Object;
24412441
2442 testing.expectEqualSlices(u8, obj.get("backslash").?.String, "\\");2442 try testing.expectEqualSlices(u8, obj.get("backslash").?.String, "\\");
2443 testing.expectEqualSlices(u8, obj.get("forwardslash").?.String, "/");2443 try testing.expectEqualSlices(u8, obj.get("forwardslash").?.String, "/");
2444 testing.expectEqualSlices(u8, obj.get("newline").?.String, "\n");2444 try testing.expectEqualSlices(u8, obj.get("newline").?.String, "\n");
2445 testing.expectEqualSlices(u8, obj.get("carriagereturn").?.String, "\r");2445 try testing.expectEqualSlices(u8, obj.get("carriagereturn").?.String, "\r");
2446 testing.expectEqualSlices(u8, obj.get("tab").?.String, "\t");2446 try testing.expectEqualSlices(u8, obj.get("tab").?.String, "\t");
2447 testing.expectEqualSlices(u8, obj.get("formfeed").?.String, "\x0C");2447 try testing.expectEqualSlices(u8, obj.get("formfeed").?.String, "\x0C");
2448 testing.expectEqualSlices(u8, obj.get("backspace").?.String, "\x08");2448 try testing.expectEqualSlices(u8, obj.get("backspace").?.String, "\x08");
2449 testing.expectEqualSlices(u8, obj.get("doublequote").?.String, "\"");2449 try testing.expectEqualSlices(u8, obj.get("doublequote").?.String, "\"");
2450 testing.expectEqualSlices(u8, obj.get("unicode").?.String, "ą");2450 try testing.expectEqualSlices(u8, obj.get("unicode").?.String, "ą");
2451 testing.expectEqualSlices(u8, obj.get("surrogatepair").?.String, "😂");2451 try testing.expectEqualSlices(u8, obj.get("surrogatepair").?.String, "😂");
2452}2452}
24532453
2454test "string copy option" {2454test "string copy option" {
...@@ -2471,7 +2471,7 @@ test "string copy option" {...@@ -2471,7 +2471,7 @@ test "string copy option" {
2471 const obj_copy = tree_copy.root.Object;2471 const obj_copy = tree_copy.root.Object;
24722472
2473 for ([_][]const u8{ "noescape", "simple", "unicode", "surrogatepair" }) |field_name| {2473 for ([_][]const u8{ "noescape", "simple", "unicode", "surrogatepair" }) |field_name| {
2474 testing.expectEqualSlices(u8, obj_nocopy.get(field_name).?.String, obj_copy.get(field_name).?.String);2474 try testing.expectEqualSlices(u8, obj_nocopy.get(field_name).?.String, obj_copy.get(field_name).?.String);
2475 }2475 }
24762476
2477 const nocopy_addr = &obj_nocopy.get("noescape").?.String[0];2477 const nocopy_addr = &obj_nocopy.get("noescape").?.String[0];
...@@ -2479,12 +2479,12 @@ test "string copy option" {...@@ -2479,12 +2479,12 @@ test "string copy option" {
24792479
2480 var found_nocopy = false;2480 var found_nocopy = false;
2481 for (input) |_, index| {2481 for (input) |_, index| {
2482 testing.expect(copy_addr != &input[index]);2482 try testing.expect(copy_addr != &input[index]);
2483 if (nocopy_addr == &input[index]) {2483 if (nocopy_addr == &input[index]) {
2484 found_nocopy = true;2484 found_nocopy = true;
2485 }2485 }
2486 }2486 }
2487 testing.expect(found_nocopy);2487 try testing.expect(found_nocopy);
2488}2488}
24892489
2490pub const StringifyOptions = struct {2490pub const StringifyOptions = struct {
lib/std/json/test.zig+275-275
...@@ -21,37 +21,37 @@ fn testNonStreaming(s: []const u8) !void {...@@ -21,37 +21,37 @@ fn testNonStreaming(s: []const u8) !void {
21}21}
2222
23fn ok(s: []const u8) !void {23fn ok(s: []const u8) !void {
24 testing.expect(json.validate(s));24 try testing.expect(json.validate(s));
2525
26 try testNonStreaming(s);26 try testNonStreaming(s);
27}27}
2828
29fn err(s: []const u8) void {29fn err(s: []const u8) !void {
30 testing.expect(!json.validate(s));30 try testing.expect(!json.validate(s));
3131
32 testing.expect(std.meta.isError(testNonStreaming(s)));32 try testing.expect(std.meta.isError(testNonStreaming(s)));
33}33}
3434
35fn utf8Error(s: []const u8) void {35fn utf8Error(s: []const u8) !void {
36 testing.expect(!json.validate(s));36 try testing.expect(!json.validate(s));
3737
38 testing.expectError(error.InvalidUtf8Byte, testNonStreaming(s));38 try testing.expectError(error.InvalidUtf8Byte, testNonStreaming(s));
39}39}
4040
41fn any(s: []const u8) void {41fn any(s: []const u8) !void {
42 _ = json.validate(s);42 _ = json.validate(s);
4343
44 testNonStreaming(s) catch {};44 testNonStreaming(s) catch {};
45}45}
4646
47fn anyStreamingErrNonStreaming(s: []const u8) void {47fn anyStreamingErrNonStreaming(s: []const u8) !void {
48 _ = json.validate(s);48 _ = json.validate(s);
4949
50 testing.expect(std.meta.isError(testNonStreaming(s)));50 try testing.expect(std.meta.isError(testNonStreaming(s)));
51}51}
5252
53fn roundTrip(s: []const u8) !void {53fn roundTrip(s: []const u8) !void {
54 testing.expect(json.validate(s));54 try testing.expect(json.validate(s));
5555
56 var p = json.Parser.init(testing.allocator, false);56 var p = json.Parser.init(testing.allocator, false);
57 defer p.deinit();57 defer p.deinit();
...@@ -63,7 +63,7 @@ fn roundTrip(s: []const u8) !void {...@@ -63,7 +63,7 @@ fn roundTrip(s: []const u8) !void {
63 var fbs = std.io.fixedBufferStream(&buf);63 var fbs = std.io.fixedBufferStream(&buf);
64 try tree.root.jsonStringify(.{}, fbs.writer());64 try tree.root.jsonStringify(.{}, fbs.writer());
6565
66 testing.expectEqualStrings(s, fbs.getWritten());66 try testing.expectEqualStrings(s, fbs.getWritten());
67}67}
6868
69////////////////////////////////////////////////////////////////////////////////////////////////////69////////////////////////////////////////////////////////////////////////////////////////////////////
...@@ -642,109 +642,109 @@ test "y_structure_whitespace_array" {...@@ -642,109 +642,109 @@ test "y_structure_whitespace_array" {
642////////////////////////////////////////////////////////////////////////////////////////////////////642////////////////////////////////////////////////////////////////////////////////////////////////////
643643
644test "n_array_1_true_without_comma" {644test "n_array_1_true_without_comma" {
645 err(645 try err(
646 \\[1 true]646 \\[1 true]
647 );647 );
648}648}
649649
650test "n_array_a_invalid_utf8" {650test "n_array_a_invalid_utf8" {
651 err(651 try err(
652 \\[aå]652 \\[aå]
653 );653 );
654}654}
655655
656test "n_array_colon_instead_of_comma" {656test "n_array_colon_instead_of_comma" {
657 err(657 try err(
658 \\["": 1]658 \\["": 1]
659 );659 );
660}660}
661661
662test "n_array_comma_after_close" {662test "n_array_comma_after_close" {
663 err(663 try err(
664 \\[""],664 \\[""],
665 );665 );
666}666}
667667
668test "n_array_comma_and_number" {668test "n_array_comma_and_number" {
669 err(669 try err(
670 \\[,1]670 \\[,1]
671 );671 );
672}672}
673673
674test "n_array_double_comma" {674test "n_array_double_comma" {
675 err(675 try err(
676 \\[1,,2]676 \\[1,,2]
677 );677 );
678}678}
679679
680test "n_array_double_extra_comma" {680test "n_array_double_extra_comma" {
681 err(681 try err(
682 \\["x",,]682 \\["x",,]
683 );683 );
684}684}
685685
686test "n_array_extra_close" {686test "n_array_extra_close" {
687 err(687 try err(
688 \\["x"]]688 \\["x"]]
689 );689 );
690}690}
691691
692test "n_array_extra_comma" {692test "n_array_extra_comma" {
693 err(693 try err(
694 \\["",]694 \\["",]
695 );695 );
696}696}
697697
698test "n_array_incomplete_invalid_value" {698test "n_array_incomplete_invalid_value" {
699 err(699 try err(
700 \\[x700 \\[x
701 );701 );
702}702}
703703
704test "n_array_incomplete" {704test "n_array_incomplete" {
705 err(705 try err(
706 \\["x"706 \\["x"
707 );707 );
708}708}
709709
710test "n_array_inner_array_no_comma" {710test "n_array_inner_array_no_comma" {
711 err(711 try err(
712 \\[3[4]]712 \\[3[4]]
713 );713 );
714}714}
715715
716test "n_array_invalid_utf8" {716test "n_array_invalid_utf8" {
717 err(717 try err(
718 \\[ÿ]718 \\[ÿ]
719 );719 );
720}720}
721721
722test "n_array_items_separated_by_semicolon" {722test "n_array_items_separated_by_semicolon" {
723 err(723 try err(
724 \\[1:2]724 \\[1:2]
725 );725 );
726}726}
727727
728test "n_array_just_comma" {728test "n_array_just_comma" {
729 err(729 try err(
730 \\[,]730 \\[,]
731 );731 );
732}732}
733733
734test "n_array_just_minus" {734test "n_array_just_minus" {
735 err(735 try err(
736 \\[-]736 \\[-]
737 );737 );
738}738}
739739
740test "n_array_missing_value" {740test "n_array_missing_value" {
741 err(741 try err(
742 \\[ , ""]742 \\[ , ""]
743 );743 );
744}744}
745745
746test "n_array_newlines_unclosed" {746test "n_array_newlines_unclosed" {
747 err(747 try err(
748 \\["a",748 \\["a",
749 \\4749 \\4
750 \\,1,750 \\,1,
...@@ -752,41 +752,41 @@ test "n_array_newlines_unclosed" {...@@ -752,41 +752,41 @@ test "n_array_newlines_unclosed" {
752}752}
753753
754test "n_array_number_and_comma" {754test "n_array_number_and_comma" {
755 err(755 try err(
756 \\[1,]756 \\[1,]
757 );757 );
758}758}
759759
760test "n_array_number_and_several_commas" {760test "n_array_number_and_several_commas" {
761 err(761 try err(
762 \\[1,,]762 \\[1,,]
763 );763 );
764}764}
765765
766test "n_array_spaces_vertical_tab_formfeed" {766test "n_array_spaces_vertical_tab_formfeed" {
767 err("[\"\x0aa\"\\f]");767 try err("[\"\x0aa\"\\f]");
768}768}
769769
770test "n_array_star_inside" {770test "n_array_star_inside" {
771 err(771 try err(
772 \\[*]772 \\[*]
773 );773 );
774}774}
775775
776test "n_array_unclosed" {776test "n_array_unclosed" {
777 err(777 try err(
778 \\[""778 \\[""
779 );779 );
780}780}
781781
782test "n_array_unclosed_trailing_comma" {782test "n_array_unclosed_trailing_comma" {
783 err(783 try err(
784 \\[1,784 \\[1,
785 );785 );
786}786}
787787
788test "n_array_unclosed_with_new_lines" {788test "n_array_unclosed_with_new_lines" {
789 err(789 try err(
790 \\[1,790 \\[1,
791 \\1791 \\1
792 \\,1792 \\,1
...@@ -794,956 +794,956 @@ test "n_array_unclosed_with_new_lines" {...@@ -794,956 +794,956 @@ test "n_array_unclosed_with_new_lines" {
794}794}
795795
796test "n_array_unclosed_with_object_inside" {796test "n_array_unclosed_with_object_inside" {
797 err(797 try err(
798 \\[{}798 \\[{}
799 );799 );
800}800}
801801
802test "n_incomplete_false" {802test "n_incomplete_false" {
803 err(803 try err(
804 \\[fals]804 \\[fals]
805 );805 );
806}806}
807807
808test "n_incomplete_null" {808test "n_incomplete_null" {
809 err(809 try err(
810 \\[nul]810 \\[nul]
811 );811 );
812}812}
813813
814test "n_incomplete_true" {814test "n_incomplete_true" {
815 err(815 try err(
816 \\[tru]816 \\[tru]
817 );817 );
818}818}
819819
820test "n_multidigit_number_then_00" {820test "n_multidigit_number_then_00" {
821 err("123\x00");821 try err("123\x00");
822}822}
823823
824test "n_number_0.1.2" {824test "n_number_0.1.2" {
825 err(825 try err(
826 \\[0.1.2]826 \\[0.1.2]
827 );827 );
828}828}
829829
830test "n_number_-01" {830test "n_number_-01" {
831 err(831 try err(
832 \\[-01]832 \\[-01]
833 );833 );
834}834}
835835
836test "n_number_0.3e" {836test "n_number_0.3e" {
837 err(837 try err(
838 \\[0.3e]838 \\[0.3e]
839 );839 );
840}840}
841841
842test "n_number_0.3e+" {842test "n_number_0.3e+" {
843 err(843 try err(
844 \\[0.3e+]844 \\[0.3e+]
845 );845 );
846}846}
847847
848test "n_number_0_capital_E" {848test "n_number_0_capital_E" {
849 err(849 try err(
850 \\[0E]850 \\[0E]
851 );851 );
852}852}
853853
854test "n_number_0_capital_E+" {854test "n_number_0_capital_E+" {
855 err(855 try err(
856 \\[0E+]856 \\[0E+]
857 );857 );
858}858}
859859
860test "n_number_0.e1" {860test "n_number_0.e1" {
861 err(861 try err(
862 \\[0.e1]862 \\[0.e1]
863 );863 );
864}864}
865865
866test "n_number_0e" {866test "n_number_0e" {
867 err(867 try err(
868 \\[0e]868 \\[0e]
869 );869 );
870}870}
871871
872test "n_number_0e+" {872test "n_number_0e+" {
873 err(873 try err(
874 \\[0e+]874 \\[0e+]
875 );875 );
876}876}
877877
878test "n_number_1_000" {878test "n_number_1_000" {
879 err(879 try err(
880 \\[1 000.0]880 \\[1 000.0]
881 );881 );
882}882}
883883
884test "n_number_1.0e-" {884test "n_number_1.0e-" {
885 err(885 try err(
886 \\[1.0e-]886 \\[1.0e-]
887 );887 );
888}888}
889889
890test "n_number_1.0e" {890test "n_number_1.0e" {
891 err(891 try err(
892 \\[1.0e]892 \\[1.0e]
893 );893 );
894}894}
895895
896test "n_number_1.0e+" {896test "n_number_1.0e+" {
897 err(897 try err(
898 \\[1.0e+]898 \\[1.0e+]
899 );899 );
900}900}
901901
902test "n_number_-1.0." {902test "n_number_-1.0." {
903 err(903 try err(
904 \\[-1.0.]904 \\[-1.0.]
905 );905 );
906}906}
907907
908test "n_number_1eE2" {908test "n_number_1eE2" {
909 err(909 try err(
910 \\[1eE2]910 \\[1eE2]
911 );911 );
912}912}
913913
914test "n_number_.-1" {914test "n_number_.-1" {
915 err(915 try err(
916 \\[.-1]916 \\[.-1]
917 );917 );
918}918}
919919
920test "n_number_+1" {920test "n_number_+1" {
921 err(921 try err(
922 \\[+1]922 \\[+1]
923 );923 );
924}924}
925925
926test "n_number_.2e-3" {926test "n_number_.2e-3" {
927 err(927 try err(
928 \\[.2e-3]928 \\[.2e-3]
929 );929 );
930}930}
931931
932test "n_number_2.e-3" {932test "n_number_2.e-3" {
933 err(933 try err(
934 \\[2.e-3]934 \\[2.e-3]
935 );935 );
936}936}
937937
938test "n_number_2.e+3" {938test "n_number_2.e+3" {
939 err(939 try err(
940 \\[2.e+3]940 \\[2.e+3]
941 );941 );
942}942}
943943
944test "n_number_2.e3" {944test "n_number_2.e3" {
945 err(945 try err(
946 \\[2.e3]946 \\[2.e3]
947 );947 );
948}948}
949949
950test "n_number_-2." {950test "n_number_-2." {
951 err(951 try err(
952 \\[-2.]952 \\[-2.]
953 );953 );
954}954}
955955
956test "n_number_9.e+" {956test "n_number_9.e+" {
957 err(957 try err(
958 \\[9.e+]958 \\[9.e+]
959 );959 );
960}960}
961961
962test "n_number_expression" {962test "n_number_expression" {
963 err(963 try err(
964 \\[1+2]964 \\[1+2]
965 );965 );
966}966}
967967
968test "n_number_hex_1_digit" {968test "n_number_hex_1_digit" {
969 err(969 try err(
970 \\[0x1]970 \\[0x1]
971 );971 );
972}972}
973973
974test "n_number_hex_2_digits" {974test "n_number_hex_2_digits" {
975 err(975 try err(
976 \\[0x42]976 \\[0x42]
977 );977 );
978}978}
979979
980test "n_number_infinity" {980test "n_number_infinity" {
981 err(981 try err(
982 \\[Infinity]982 \\[Infinity]
983 );983 );
984}984}
985985
986test "n_number_+Inf" {986test "n_number_+Inf" {
987 err(987 try err(
988 \\[+Inf]988 \\[+Inf]
989 );989 );
990}990}
991991
992test "n_number_Inf" {992test "n_number_Inf" {
993 err(993 try err(
994 \\[Inf]994 \\[Inf]
995 );995 );
996}996}
997997
998test "n_number_invalid+-" {998test "n_number_invalid+-" {
999 err(999 try err(
1000 \\[0e+-1]1000 \\[0e+-1]
1001 );1001 );
1002}1002}
10031003
1004test "n_number_invalid-negative-real" {1004test "n_number_invalid-negative-real" {
1005 err(1005 try err(
1006 \\[-123.123foo]1006 \\[-123.123foo]
1007 );1007 );
1008}1008}
10091009
1010test "n_number_invalid-utf-8-in-bigger-int" {1010test "n_number_invalid-utf-8-in-bigger-int" {
1011 err(1011 try err(
1012 \\[123å]1012 \\[123å]
1013 );1013 );
1014}1014}
10151015
1016test "n_number_invalid-utf-8-in-exponent" {1016test "n_number_invalid-utf-8-in-exponent" {
1017 err(1017 try err(
1018 \\[1e1å]1018 \\[1e1å]
1019 );1019 );
1020}1020}
10211021
1022test "n_number_invalid-utf-8-in-int" {1022test "n_number_invalid-utf-8-in-int" {
1023 err(1023 try err(
1024 \\[0å]1024 \\[0å]
1025 );1025 );
1026}1026}
10271027
1028test "n_number_++" {1028test "n_number_++" {
1029 err(1029 try err(
1030 \\[++1234]1030 \\[++1234]
1031 );1031 );
1032}1032}
10331033
1034test "n_number_minus_infinity" {1034test "n_number_minus_infinity" {
1035 err(1035 try err(
1036 \\[-Infinity]1036 \\[-Infinity]
1037 );1037 );
1038}1038}
10391039
1040test "n_number_minus_sign_with_trailing_garbage" {1040test "n_number_minus_sign_with_trailing_garbage" {
1041 err(1041 try err(
1042 \\[-foo]1042 \\[-foo]
1043 );1043 );
1044}1044}
10451045
1046test "n_number_minus_space_1" {1046test "n_number_minus_space_1" {
1047 err(1047 try err(
1048 \\[- 1]1048 \\[- 1]
1049 );1049 );
1050}1050}
10511051
1052test "n_number_-NaN" {1052test "n_number_-NaN" {
1053 err(1053 try err(
1054 \\[-NaN]1054 \\[-NaN]
1055 );1055 );
1056}1056}
10571057
1058test "n_number_NaN" {1058test "n_number_NaN" {
1059 err(1059 try err(
1060 \\[NaN]1060 \\[NaN]
1061 );1061 );
1062}1062}
10631063
1064test "n_number_neg_int_starting_with_zero" {1064test "n_number_neg_int_starting_with_zero" {
1065 err(1065 try err(
1066 \\[-012]1066 \\[-012]
1067 );1067 );
1068}1068}
10691069
1070test "n_number_neg_real_without_int_part" {1070test "n_number_neg_real_without_int_part" {
1071 err(1071 try err(
1072 \\[-.123]1072 \\[-.123]
1073 );1073 );
1074}1074}
10751075
1076test "n_number_neg_with_garbage_at_end" {1076test "n_number_neg_with_garbage_at_end" {
1077 err(1077 try err(
1078 \\[-1x]1078 \\[-1x]
1079 );1079 );
1080}1080}
10811081
1082test "n_number_real_garbage_after_e" {1082test "n_number_real_garbage_after_e" {
1083 err(1083 try err(
1084 \\[1ea]1084 \\[1ea]
1085 );1085 );
1086}1086}
10871087
1088test "n_number_real_with_invalid_utf8_after_e" {1088test "n_number_real_with_invalid_utf8_after_e" {
1089 err(1089 try err(
1090 \\[1eå]1090 \\[1eå]
1091 );1091 );
1092}1092}
10931093
1094test "n_number_real_without_fractional_part" {1094test "n_number_real_without_fractional_part" {
1095 err(1095 try err(
1096 \\[1.]1096 \\[1.]
1097 );1097 );
1098}1098}
10991099
1100test "n_number_starting_with_dot" {1100test "n_number_starting_with_dot" {
1101 err(1101 try err(
1102 \\[.123]1102 \\[.123]
1103 );1103 );
1104}1104}
11051105
1106test "n_number_U+FF11_fullwidth_digit_one" {1106test "n_number_U+FF11_fullwidth_digit_one" {
1107 err(1107 try err(
1108 \\[1]1108 \\[1]
1109 );1109 );
1110}1110}
11111111
1112test "n_number_with_alpha_char" {1112test "n_number_with_alpha_char" {
1113 err(1113 try err(
1114 \\[1.8011670033376514H-308]1114 \\[1.8011670033376514H-308]
1115 );1115 );
1116}1116}
11171117
1118test "n_number_with_alpha" {1118test "n_number_with_alpha" {
1119 err(1119 try err(
1120 \\[1.2a-3]1120 \\[1.2a-3]
1121 );1121 );
1122}1122}
11231123
1124test "n_number_with_leading_zero" {1124test "n_number_with_leading_zero" {
1125 err(1125 try err(
1126 \\[012]1126 \\[012]
1127 );1127 );
1128}1128}
11291129
1130test "n_object_bad_value" {1130test "n_object_bad_value" {
1131 err(1131 try err(
1132 \\["x", truth]1132 \\["x", truth]
1133 );1133 );
1134}1134}
11351135
1136test "n_object_bracket_key" {1136test "n_object_bracket_key" {
1137 err(1137 try err(
1138 \\{[: "x"}1138 \\{[: "x"}
1139 );1139 );
1140}1140}
11411141
1142test "n_object_comma_instead_of_colon" {1142test "n_object_comma_instead_of_colon" {
1143 err(1143 try err(
1144 \\{"x", null}1144 \\{"x", null}
1145 );1145 );
1146}1146}
11471147
1148test "n_object_double_colon" {1148test "n_object_double_colon" {
1149 err(1149 try err(
1150 \\{"x"::"b"}1150 \\{"x"::"b"}
1151 );1151 );
1152}1152}
11531153
1154test "n_object_emoji" {1154test "n_object_emoji" {
1155 err(1155 try err(
1156 \\{🇨🇭}1156 \\{🇨🇭}
1157 );1157 );
1158}1158}
11591159
1160test "n_object_garbage_at_end" {1160test "n_object_garbage_at_end" {
1161 err(1161 try err(
1162 \\{"a":"a" 123}1162 \\{"a":"a" 123}
1163 );1163 );
1164}1164}
11651165
1166test "n_object_key_with_single_quotes" {1166test "n_object_key_with_single_quotes" {
1167 err(1167 try err(
1168 \\{key: 'value'}1168 \\{key: 'value'}
1169 );1169 );
1170}1170}
11711171
1172test "n_object_lone_continuation_byte_in_key_and_trailing_comma" {1172test "n_object_lone_continuation_byte_in_key_and_trailing_comma" {
1173 err(1173 try err(
1174 \\{"¹":"0",}1174 \\{"¹":"0",}
1175 );1175 );
1176}1176}
11771177
1178test "n_object_missing_colon" {1178test "n_object_missing_colon" {
1179 err(1179 try err(
1180 \\{"a" b}1180 \\{"a" b}
1181 );1181 );
1182}1182}
11831183
1184test "n_object_missing_key" {1184test "n_object_missing_key" {
1185 err(1185 try err(
1186 \\{:"b"}1186 \\{:"b"}
1187 );1187 );
1188}1188}
11891189
1190test "n_object_missing_semicolon" {1190test "n_object_missing_semicolon" {
1191 err(1191 try err(
1192 \\{"a" "b"}1192 \\{"a" "b"}
1193 );1193 );
1194}1194}
11951195
1196test "n_object_missing_value" {1196test "n_object_missing_value" {
1197 err(1197 try err(
1198 \\{"a":1198 \\{"a":
1199 );1199 );
1200}1200}
12011201
1202test "n_object_no-colon" {1202test "n_object_no-colon" {
1203 err(1203 try err(
1204 \\{"a"1204 \\{"a"
1205 );1205 );
1206}1206}
12071207
1208test "n_object_non_string_key_but_huge_number_instead" {1208test "n_object_non_string_key_but_huge_number_instead" {
1209 err(1209 try err(
1210 \\{9999E9999:1}1210 \\{9999E9999:1}
1211 );1211 );
1212}1212}
12131213
1214test "n_object_non_string_key" {1214test "n_object_non_string_key" {
1215 err(1215 try err(
1216 \\{1:1}1216 \\{1:1}
1217 );1217 );
1218}1218}
12191219
1220test "n_object_repeated_null_null" {1220test "n_object_repeated_null_null" {
1221 err(1221 try err(
1222 \\{null:null,null:null}1222 \\{null:null,null:null}
1223 );1223 );
1224}1224}
12251225
1226test "n_object_several_trailing_commas" {1226test "n_object_several_trailing_commas" {
1227 err(1227 try err(
1228 \\{"id":0,,,,,}1228 \\{"id":0,,,,,}
1229 );1229 );
1230}1230}
12311231
1232test "n_object_single_quote" {1232test "n_object_single_quote" {
1233 err(1233 try err(
1234 \\{'a':0}1234 \\{'a':0}
1235 );1235 );
1236}1236}
12371237
1238test "n_object_trailing_comma" {1238test "n_object_trailing_comma" {
1239 err(1239 try err(
1240 \\{"id":0,}1240 \\{"id":0,}
1241 );1241 );
1242}1242}
12431243
1244test "n_object_trailing_comment" {1244test "n_object_trailing_comment" {
1245 err(1245 try err(
1246 \\{"a":"b"}/**/1246 \\{"a":"b"}/**/
1247 );1247 );
1248}1248}
12491249
1250test "n_object_trailing_comment_open" {1250test "n_object_trailing_comment_open" {
1251 err(1251 try err(
1252 \\{"a":"b"}/**//1252 \\{"a":"b"}/**//
1253 );1253 );
1254}1254}
12551255
1256test "n_object_trailing_comment_slash_open_incomplete" {1256test "n_object_trailing_comment_slash_open_incomplete" {
1257 err(1257 try err(
1258 \\{"a":"b"}/1258 \\{"a":"b"}/
1259 );1259 );
1260}1260}
12611261
1262test "n_object_trailing_comment_slash_open" {1262test "n_object_trailing_comment_slash_open" {
1263 err(1263 try err(
1264 \\{"a":"b"}//1264 \\{"a":"b"}//
1265 );1265 );
1266}1266}
12671267
1268test "n_object_two_commas_in_a_row" {1268test "n_object_two_commas_in_a_row" {
1269 err(1269 try err(
1270 \\{"a":"b",,"c":"d"}1270 \\{"a":"b",,"c":"d"}
1271 );1271 );
1272}1272}
12731273
1274test "n_object_unquoted_key" {1274test "n_object_unquoted_key" {
1275 err(1275 try err(
1276 \\{a: "b"}1276 \\{a: "b"}
1277 );1277 );
1278}1278}
12791279
1280test "n_object_unterminated-value" {1280test "n_object_unterminated-value" {
1281 err(1281 try err(
1282 \\{"a":"a1282 \\{"a":"a
1283 );1283 );
1284}1284}
12851285
1286test "n_object_with_single_string" {1286test "n_object_with_single_string" {
1287 err(1287 try err(
1288 \\{ "foo" : "bar", "a" }1288 \\{ "foo" : "bar", "a" }
1289 );1289 );
1290}1290}
12911291
1292test "n_object_with_trailing_garbage" {1292test "n_object_with_trailing_garbage" {
1293 err(1293 try err(
1294 \\{"a":"b"}#1294 \\{"a":"b"}#
1295 );1295 );
1296}1296}
12971297
1298test "n_single_space" {1298test "n_single_space" {
1299 err(" ");1299 try err(" ");
1300}1300}
13011301
1302test "n_string_1_surrogate_then_escape" {1302test "n_string_1_surrogate_then_escape" {
1303 err(1303 try err(
1304 \\["\uD800\"]1304 \\["\uD800\"]
1305 );1305 );
1306}1306}
13071307
1308test "n_string_1_surrogate_then_escape_u1" {1308test "n_string_1_surrogate_then_escape_u1" {
1309 err(1309 try err(
1310 \\["\uD800\u1"]1310 \\["\uD800\u1"]
1311 );1311 );
1312}1312}
13131313
1314test "n_string_1_surrogate_then_escape_u1x" {1314test "n_string_1_surrogate_then_escape_u1x" {
1315 err(1315 try err(
1316 \\["\uD800\u1x"]1316 \\["\uD800\u1x"]
1317 );1317 );
1318}1318}
13191319
1320test "n_string_1_surrogate_then_escape_u" {1320test "n_string_1_surrogate_then_escape_u" {
1321 err(1321 try err(
1322 \\["\uD800\u"]1322 \\["\uD800\u"]
1323 );1323 );
1324}1324}
13251325
1326test "n_string_accentuated_char_no_quotes" {1326test "n_string_accentuated_char_no_quotes" {
1327 err(1327 try err(
1328 \\[é]1328 \\[é]
1329 );1329 );
1330}1330}
13311331
1332test "n_string_backslash_00" {1332test "n_string_backslash_00" {
1333 err("[\"\x00\"]");1333 try err("[\"\x00\"]");
1334}1334}
13351335
1336test "n_string_escaped_backslash_bad" {1336test "n_string_escaped_backslash_bad" {
1337 err(1337 try err(
1338 \\["\\\"]1338 \\["\\\"]
1339 );1339 );
1340}1340}
13411341
1342test "n_string_escaped_ctrl_char_tab" {1342test "n_string_escaped_ctrl_char_tab" {
1343 err("\x5b\x22\x5c\x09\x22\x5d");1343 try err("\x5b\x22\x5c\x09\x22\x5d");
1344}1344}
13451345
1346test "n_string_escaped_emoji" {1346test "n_string_escaped_emoji" {
1347 err("[\"\x5c\xc3\xb0\xc2\x9f\xc2\x8c\xc2\x80\"]");1347 try err("[\"\x5c\xc3\xb0\xc2\x9f\xc2\x8c\xc2\x80\"]");
1348}1348}
13491349
1350test "n_string_escape_x" {1350test "n_string_escape_x" {
1351 err(1351 try err(
1352 \\["\x00"]1352 \\["\x00"]
1353 );1353 );
1354}1354}
13551355
1356test "n_string_incomplete_escaped_character" {1356test "n_string_incomplete_escaped_character" {
1357 err(1357 try err(
1358 \\["\u00A"]1358 \\["\u00A"]
1359 );1359 );
1360}1360}
13611361
1362test "n_string_incomplete_escape" {1362test "n_string_incomplete_escape" {
1363 err(1363 try err(
1364 \\["\"]1364 \\["\"]
1365 );1365 );
1366}1366}
13671367
1368test "n_string_incomplete_surrogate_escape_invalid" {1368test "n_string_incomplete_surrogate_escape_invalid" {
1369 err(1369 try err(
1370 \\["\uD800\uD800\x"]1370 \\["\uD800\uD800\x"]
1371 );1371 );
1372}1372}
13731373
1374test "n_string_incomplete_surrogate" {1374test "n_string_incomplete_surrogate" {
1375 err(1375 try err(
1376 \\["\uD834\uDd"]1376 \\["\uD834\uDd"]
1377 );1377 );
1378}1378}
13791379
1380test "n_string_invalid_backslash_esc" {1380test "n_string_invalid_backslash_esc" {
1381 err(1381 try err(
1382 \\["\a"]1382 \\["\a"]
1383 );1383 );
1384}1384}
13851385
1386test "n_string_invalid_unicode_escape" {1386test "n_string_invalid_unicode_escape" {
1387 err(1387 try err(
1388 \\["\uqqqq"]1388 \\["\uqqqq"]
1389 );1389 );
1390}1390}
13911391
1392test "n_string_invalid_utf8_after_escape" {1392test "n_string_invalid_utf8_after_escape" {
1393 err("[\"\\\x75\xc3\xa5\"]");1393 try err("[\"\\\x75\xc3\xa5\"]");
1394}1394}
13951395
1396test "n_string_invalid-utf-8-in-escape" {1396test "n_string_invalid-utf-8-in-escape" {
1397 err(1397 try err(
1398 \\["\uå"]1398 \\["\uå"]
1399 );1399 );
1400}1400}
14011401
1402test "n_string_leading_uescaped_thinspace" {1402test "n_string_leading_uescaped_thinspace" {
1403 err(1403 try err(
1404 \\[\u0020"asd"]1404 \\[\u0020"asd"]
1405 );1405 );
1406}1406}
14071407
1408test "n_string_no_quotes_with_bad_escape" {1408test "n_string_no_quotes_with_bad_escape" {
1409 err(1409 try err(
1410 \\[\n]1410 \\[\n]
1411 );1411 );
1412}1412}
14131413
1414test "n_string_single_doublequote" {1414test "n_string_single_doublequote" {
1415 err(1415 try err(
1416 \\"1416 \\"
1417 );1417 );
1418}1418}
14191419
1420test "n_string_single_quote" {1420test "n_string_single_quote" {
1421 err(1421 try err(
1422 \\['single quote']1422 \\['single quote']
1423 );1423 );
1424}1424}
14251425
1426test "n_string_single_string_no_double_quotes" {1426test "n_string_single_string_no_double_quotes" {
1427 err(1427 try err(
1428 \\abc1428 \\abc
1429 );1429 );
1430}1430}
14311431
1432test "n_string_start_escape_unclosed" {1432test "n_string_start_escape_unclosed" {
1433 err(1433 try err(
1434 \\["\1434 \\["\
1435 );1435 );
1436}1436}
14371437
1438test "n_string_unescaped_crtl_char" {1438test "n_string_unescaped_crtl_char" {
1439 err("[\"a\x00a\"]");1439 try err("[\"a\x00a\"]");
1440}1440}
14411441
1442test "n_string_unescaped_newline" {1442test "n_string_unescaped_newline" {
1443 err(1443 try err(
1444 \\["new1444 \\["new
1445 \\line"]1445 \\line"]
1446 );1446 );
1447}1447}
14481448
1449test "n_string_unescaped_tab" {1449test "n_string_unescaped_tab" {
1450 err("[\"\t\"]");1450 try err("[\"\t\"]");
1451}1451}
14521452
1453test "n_string_unicode_CapitalU" {1453test "n_string_unicode_CapitalU" {
1454 err(1454 try err(
1455 \\"\UA66D"1455 \\"\UA66D"
1456 );1456 );
1457}1457}
14581458
1459test "n_string_with_trailing_garbage" {1459test "n_string_with_trailing_garbage" {
1460 err(1460 try err(
1461 \\""x1461 \\""x
1462 );1462 );
1463}1463}
14641464
1465test "n_structure_100000_opening_arrays" {1465test "n_structure_100000_opening_arrays" {
1466 err("[" ** 100000);1466 try err("[" ** 100000);
1467}1467}
14681468
1469test "n_structure_angle_bracket_." {1469test "n_structure_angle_bracket_." {
1470 err(1470 try err(
1471 \\<.>1471 \\<.>
1472 );1472 );
1473}1473}
14741474
1475test "n_structure_angle_bracket_null" {1475test "n_structure_angle_bracket_null" {
1476 err(1476 try err(
1477 \\[<null>]1477 \\[<null>]
1478 );1478 );
1479}1479}
14801480
1481test "n_structure_array_trailing_garbage" {1481test "n_structure_array_trailing_garbage" {
1482 err(1482 try err(
1483 \\[1]x1483 \\[1]x
1484 );1484 );
1485}1485}
14861486
1487test "n_structure_array_with_extra_array_close" {1487test "n_structure_array_with_extra_array_close" {
1488 err(1488 try err(
1489 \\[1]]1489 \\[1]]
1490 );1490 );
1491}1491}
14921492
1493test "n_structure_array_with_unclosed_string" {1493test "n_structure_array_with_unclosed_string" {
1494 err(1494 try err(
1495 \\["asd]1495 \\["asd]
1496 );1496 );
1497}1497}
14981498
1499test "n_structure_ascii-unicode-identifier" {1499test "n_structure_ascii-unicode-identifier" {
1500 err(1500 try err(
1501 \\aå1501 \\aå
1502 );1502 );
1503}1503}
15041504
1505test "n_structure_capitalized_True" {1505test "n_structure_capitalized_True" {
1506 err(1506 try err(
1507 \\[True]1507 \\[True]
1508 );1508 );
1509}1509}
15101510
1511test "n_structure_close_unopened_array" {1511test "n_structure_close_unopened_array" {
1512 err(1512 try err(
1513 \\1]1513 \\1]
1514 );1514 );
1515}1515}
15161516
1517test "n_structure_comma_instead_of_closing_brace" {1517test "n_structure_comma_instead_of_closing_brace" {
1518 err(1518 try err(
1519 \\{"x": true,1519 \\{"x": true,
1520 );1520 );
1521}1521}
15221522
1523test "n_structure_double_array" {1523test "n_structure_double_array" {
1524 err(1524 try err(
1525 \\[][]1525 \\[][]
1526 );1526 );
1527}1527}
15281528
1529test "n_structure_end_array" {1529test "n_structure_end_array" {
1530 err(1530 try err(
1531 \\]1531 \\]
1532 );1532 );
1533}1533}
15341534
1535test "n_structure_incomplete_UTF8_BOM" {1535test "n_structure_incomplete_UTF8_BOM" {
1536 err(1536 try err(
1537 \\ï»{}1537 \\ï»{}
1538 );1538 );
1539}1539}
15401540
1541test "n_structure_lone-invalid-utf-8" {1541test "n_structure_lone-invalid-utf-8" {
1542 err(1542 try err(
1543 \\å1543 \\å
1544 );1544 );
1545}1545}
15461546
1547test "n_structure_lone-open-bracket" {1547test "n_structure_lone-open-bracket" {
1548 err(1548 try err(
1549 \\[1549 \\[
1550 );1550 );
1551}1551}
15521552
1553test "n_structure_no_data" {1553test "n_structure_no_data" {
1554 err(1554 try err(
1555 \\1555 \\
1556 );1556 );
1557}1557}
15581558
1559test "n_structure_null-byte-outside-string" {1559test "n_structure_null-byte-outside-string" {
1560 err("[\x00]");1560 try err("[\x00]");
1561}1561}
15621562
1563test "n_structure_number_with_trailing_garbage" {1563test "n_structure_number_with_trailing_garbage" {
1564 err(1564 try err(
1565 \\2@1565 \\2@
1566 );1566 );
1567}1567}
15681568
1569test "n_structure_object_followed_by_closing_object" {1569test "n_structure_object_followed_by_closing_object" {
1570 err(1570 try err(
1571 \\{}}1571 \\{}}
1572 );1572 );
1573}1573}
15741574
1575test "n_structure_object_unclosed_no_value" {1575test "n_structure_object_unclosed_no_value" {
1576 err(1576 try err(
1577 \\{"":1577 \\{"":
1578 );1578 );
1579}1579}
15801580
1581test "n_structure_object_with_comment" {1581test "n_structure_object_with_comment" {
1582 err(1582 try err(
1583 \\{"a":/*comment*/"b"}1583 \\{"a":/*comment*/"b"}
1584 );1584 );
1585}1585}
15861586
1587test "n_structure_object_with_trailing_garbage" {1587test "n_structure_object_with_trailing_garbage" {
1588 err(1588 try err(
1589 \\{"a": true} "x"1589 \\{"a": true} "x"
1590 );1590 );
1591}1591}
15921592
1593test "n_structure_open_array_apostrophe" {1593test "n_structure_open_array_apostrophe" {
1594 err(1594 try err(
1595 \\['1595 \\['
1596 );1596 );
1597}1597}
15981598
1599test "n_structure_open_array_comma" {1599test "n_structure_open_array_comma" {
1600 err(1600 try err(
1601 \\[,1601 \\[,
1602 );1602 );
1603}1603}
16041604
1605test "n_structure_open_array_object" {1605test "n_structure_open_array_object" {
1606 err("[{\"\":" ** 50000);1606 try err("[{\"\":" ** 50000);
1607}1607}
16081608
1609test "n_structure_open_array_open_object" {1609test "n_structure_open_array_open_object" {
1610 err(1610 try err(
1611 \\[{1611 \\[{
1612 );1612 );
1613}1613}
16141614
1615test "n_structure_open_array_open_string" {1615test "n_structure_open_array_open_string" {
1616 err(1616 try err(
1617 \\["a1617 \\["a
1618 );1618 );
1619}1619}
16201620
1621test "n_structure_open_array_string" {1621test "n_structure_open_array_string" {
1622 err(1622 try err(
1623 \\["a"1623 \\["a"
1624 );1624 );
1625}1625}
16261626
1627test "n_structure_open_object_close_array" {1627test "n_structure_open_object_close_array" {
1628 err(1628 try err(
1629 \\{]1629 \\{]
1630 );1630 );
1631}1631}
16321632
1633test "n_structure_open_object_comma" {1633test "n_structure_open_object_comma" {
1634 err(1634 try err(
1635 \\{,1635 \\{,
1636 );1636 );
1637}1637}
16381638
1639test "n_structure_open_object" {1639test "n_structure_open_object" {
1640 err(1640 try err(
1641 \\{1641 \\{
1642 );1642 );
1643}1643}
16441644
1645test "n_structure_open_object_open_array" {1645test "n_structure_open_object_open_array" {
1646 err(1646 try err(
1647 \\{[1647 \\{[
1648 );1648 );
1649}1649}
16501650
1651test "n_structure_open_object_open_string" {1651test "n_structure_open_object_open_string" {
1652 err(1652 try err(
1653 \\{"a1653 \\{"a
1654 );1654 );
1655}1655}
16561656
1657test "n_structure_open_object_string_with_apostrophes" {1657test "n_structure_open_object_string_with_apostrophes" {
1658 err(1658 try err(
1659 \\{'a'1659 \\{'a'
1660 );1660 );
1661}1661}
16621662
1663test "n_structure_open_open" {1663test "n_structure_open_open" {
1664 err(1664 try err(
1665 \\["\{["\{["\{["\{1665 \\["\{["\{["\{["\{
1666 );1666 );
1667}1667}
16681668
1669test "n_structure_single_eacute" {1669test "n_structure_single_eacute" {
1670 err(1670 try err(
1671 \\é1671 \\é
1672 );1672 );
1673}1673}
16741674
1675test "n_structure_single_star" {1675test "n_structure_single_star" {
1676 err(1676 try err(
1677 \\*1677 \\*
1678 );1678 );
1679}1679}
16801680
1681test "n_structure_trailing_#" {1681test "n_structure_trailing_#" {
1682 err(1682 try err(
1683 \\{"a":"b"}#{}1683 \\{"a":"b"}#{}
1684 );1684 );
1685}1685}
16861686
1687test "n_structure_U+2060_word_joined" {1687test "n_structure_U+2060_word_joined" {
1688 err(1688 try err(
1689 \\[⁠]1689 \\[⁠]
1690 );1690 );
1691}1691}
16921692
1693test "n_structure_uescaped_LF_before_string" {1693test "n_structure_uescaped_LF_before_string" {
1694 err(1694 try err(
1695 \\[\u000A""]1695 \\[\u000A""]
1696 );1696 );
1697}1697}
16981698
1699test "n_structure_unclosed_array" {1699test "n_structure_unclosed_array" {
1700 err(1700 try err(
1701 \\[11701 \\[1
1702 );1702 );
1703}1703}
17041704
1705test "n_structure_unclosed_array_partial_null" {1705test "n_structure_unclosed_array_partial_null" {
1706 err(1706 try err(
1707 \\[ false, nul1707 \\[ false, nul
1708 );1708 );
1709}1709}
17101710
1711test "n_structure_unclosed_array_unfinished_false" {1711test "n_structure_unclosed_array_unfinished_false" {
1712 err(1712 try err(
1713 \\[ true, fals1713 \\[ true, fals
1714 );1714 );
1715}1715}
17161716
1717test "n_structure_unclosed_array_unfinished_true" {1717test "n_structure_unclosed_array_unfinished_true" {
1718 err(1718 try err(
1719 \\[ false, tru1719 \\[ false, tru
1720 );1720 );
1721}1721}
17221722
1723test "n_structure_unclosed_object" {1723test "n_structure_unclosed_object" {
1724 err(1724 try err(
1725 \\{"asd":"asd"1725 \\{"asd":"asd"
1726 );1726 );
1727}1727}
17281728
1729test "n_structure_unicode-identifier" {1729test "n_structure_unicode-identifier" {
1730 err(1730 try err(
1731 \\Ã¥1731 \\Ã¥
1732 );1732 );
1733}1733}
17341734
1735test "n_structure_UTF8_BOM_no_data" {1735test "n_structure_UTF8_BOM_no_data" {
1736 err(1736 try err(
1737 \\1737 \\
1738 );1738 );
1739}1739}
17401740
1741test "n_structure_whitespace_formfeed" {1741test "n_structure_whitespace_formfeed" {
1742 err("[\x0c]");1742 try err("[\x0c]");
1743}1743}
17441744
1745test "n_structure_whitespace_U+2060_word_joiner" {1745test "n_structure_whitespace_U+2060_word_joiner" {
1746 err(1746 try err(
1747 \\[⁠]1747 \\[⁠]
1748 );1748 );
1749}1749}
...@@ -1751,255 +1751,255 @@ test "n_structure_whitespace_U+2060_word_joiner" {...@@ -1751,255 +1751,255 @@ test "n_structure_whitespace_U+2060_word_joiner" {
1751////////////////////////////////////////////////////////////////////////////////////////////////////1751////////////////////////////////////////////////////////////////////////////////////////////////////
17521752
1753test "i_number_double_huge_neg_exp" {1753test "i_number_double_huge_neg_exp" {
1754 any(1754 try any(
1755 \\[123.456e-789]1755 \\[123.456e-789]
1756 );1756 );
1757}1757}
17581758
1759test "i_number_huge_exp" {1759test "i_number_huge_exp" {
1760 any(1760 try any(
1761 \\[0.4e00669999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999969999999006]1761 \\[0.4e00669999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999969999999006]
1762 );1762 );
1763}1763}
17641764
1765test "i_number_neg_int_huge_exp" {1765test "i_number_neg_int_huge_exp" {
1766 any(1766 try any(
1767 \\[-1e+9999]1767 \\[-1e+9999]
1768 );1768 );
1769}1769}
17701770
1771test "i_number_pos_double_huge_exp" {1771test "i_number_pos_double_huge_exp" {
1772 any(1772 try any(
1773 \\[1.5e+9999]1773 \\[1.5e+9999]
1774 );1774 );
1775}1775}
17761776
1777test "i_number_real_neg_overflow" {1777test "i_number_real_neg_overflow" {
1778 any(1778 try any(
1779 \\[-123123e100000]1779 \\[-123123e100000]
1780 );1780 );
1781}1781}
17821782
1783test "i_number_real_pos_overflow" {1783test "i_number_real_pos_overflow" {
1784 any(1784 try any(
1785 \\[123123e100000]1785 \\[123123e100000]
1786 );1786 );
1787}1787}
17881788
1789test "i_number_real_underflow" {1789test "i_number_real_underflow" {
1790 any(1790 try any(
1791 \\[123e-10000000]1791 \\[123e-10000000]
1792 );1792 );
1793}1793}
17941794
1795test "i_number_too_big_neg_int" {1795test "i_number_too_big_neg_int" {
1796 any(1796 try any(
1797 \\[-123123123123123123123123123123]1797 \\[-123123123123123123123123123123]
1798 );1798 );
1799}1799}
18001800
1801test "i_number_too_big_pos_int" {1801test "i_number_too_big_pos_int" {
1802 any(1802 try any(
1803 \\[100000000000000000000]1803 \\[100000000000000000000]
1804 );1804 );
1805}1805}
18061806
1807test "i_number_very_big_negative_int" {1807test "i_number_very_big_negative_int" {
1808 any(1808 try any(
1809 \\[-237462374673276894279832749832423479823246327846]1809 \\[-237462374673276894279832749832423479823246327846]
1810 );1810 );
1811}1811}
18121812
1813test "i_object_key_lone_2nd_surrogate" {1813test "i_object_key_lone_2nd_surrogate" {
1814 anyStreamingErrNonStreaming(1814 try anyStreamingErrNonStreaming(
1815 \\{"\uDFAA":0}1815 \\{"\uDFAA":0}
1816 );1816 );
1817}1817}
18181818
1819test "i_string_1st_surrogate_but_2nd_missing" {1819test "i_string_1st_surrogate_but_2nd_missing" {
1820 anyStreamingErrNonStreaming(1820 try anyStreamingErrNonStreaming(
1821 \\["\uDADA"]1821 \\["\uDADA"]
1822 );1822 );
1823}1823}
18241824
1825test "i_string_1st_valid_surrogate_2nd_invalid" {1825test "i_string_1st_valid_surrogate_2nd_invalid" {
1826 anyStreamingErrNonStreaming(1826 try anyStreamingErrNonStreaming(
1827 \\["\uD888\u1234"]1827 \\["\uD888\u1234"]
1828 );1828 );
1829}1829}
18301830
1831test "i_string_incomplete_surrogate_and_escape_valid" {1831test "i_string_incomplete_surrogate_and_escape_valid" {
1832 anyStreamingErrNonStreaming(1832 try anyStreamingErrNonStreaming(
1833 \\["\uD800\n"]1833 \\["\uD800\n"]
1834 );1834 );
1835}1835}
18361836
1837test "i_string_incomplete_surrogate_pair" {1837test "i_string_incomplete_surrogate_pair" {
1838 anyStreamingErrNonStreaming(1838 try anyStreamingErrNonStreaming(
1839 \\["\uDd1ea"]1839 \\["\uDd1ea"]
1840 );1840 );
1841}1841}
18421842
1843test "i_string_incomplete_surrogates_escape_valid" {1843test "i_string_incomplete_surrogates_escape_valid" {
1844 anyStreamingErrNonStreaming(1844 try anyStreamingErrNonStreaming(
1845 \\["\uD800\uD800\n"]1845 \\["\uD800\uD800\n"]
1846 );1846 );
1847}1847}
18481848
1849test "i_string_invalid_lonely_surrogate" {1849test "i_string_invalid_lonely_surrogate" {
1850 anyStreamingErrNonStreaming(1850 try anyStreamingErrNonStreaming(
1851 \\["\ud800"]1851 \\["\ud800"]
1852 );1852 );
1853}1853}
18541854
1855test "i_string_invalid_surrogate" {1855test "i_string_invalid_surrogate" {
1856 anyStreamingErrNonStreaming(1856 try anyStreamingErrNonStreaming(
1857 \\["\ud800abc"]1857 \\["\ud800abc"]
1858 );1858 );
1859}1859}
18601860
1861test "i_string_invalid_utf-8" {1861test "i_string_invalid_utf-8" {
1862 any(1862 try any(
1863 \\["ÿ"]1863 \\["ÿ"]
1864 );1864 );
1865}1865}
18661866
1867test "i_string_inverted_surrogates_U+1D11E" {1867test "i_string_inverted_surrogates_U+1D11E" {
1868 anyStreamingErrNonStreaming(1868 try anyStreamingErrNonStreaming(
1869 \\["\uDd1e\uD834"]1869 \\["\uDd1e\uD834"]
1870 );1870 );
1871}1871}
18721872
1873test "i_string_iso_latin_1" {1873test "i_string_iso_latin_1" {
1874 any(1874 try any(
1875 \\["é"]1875 \\["é"]
1876 );1876 );
1877}1877}
18781878
1879test "i_string_lone_second_surrogate" {1879test "i_string_lone_second_surrogate" {
1880 anyStreamingErrNonStreaming(1880 try anyStreamingErrNonStreaming(
1881 \\["\uDFAA"]1881 \\["\uDFAA"]
1882 );1882 );
1883}1883}
18841884
1885test "i_string_lone_utf8_continuation_byte" {1885test "i_string_lone_utf8_continuation_byte" {
1886 any(1886 try any(
1887 \\[""]1887 \\[""]
1888 );1888 );
1889}1889}
18901890
1891test "i_string_not_in_unicode_range" {1891test "i_string_not_in_unicode_range" {
1892 any(1892 try any(
1893 \\["ô¿¿¿"]1893 \\["ô¿¿¿"]
1894 );1894 );
1895}1895}
18961896
1897test "i_string_overlong_sequence_2_bytes" {1897test "i_string_overlong_sequence_2_bytes" {
1898 any(1898 try any(
1899 \\["À¯"]1899 \\["À¯"]
1900 );1900 );
1901}1901}
19021902
1903test "i_string_overlong_sequence_6_bytes" {1903test "i_string_overlong_sequence_6_bytes" {
1904 any(1904 try any(
1905 \\["üƒ¿¿¿¿"]1905 \\["üƒ¿¿¿¿"]
1906 );1906 );
1907}1907}
19081908
1909test "i_string_overlong_sequence_6_bytes_null" {1909test "i_string_overlong_sequence_6_bytes_null" {
1910 any(1910 try any(
1911 \\["ü€€€€€"]1911 \\["ü€€€€€"]
1912 );1912 );
1913}1913}
19141914
1915test "i_string_truncated-utf-8" {1915test "i_string_truncated-utf-8" {
1916 any(1916 try any(
1917 \\["àÿ"]1917 \\["àÿ"]
1918 );1918 );
1919}1919}
19201920
1921test "i_string_utf16BE_no_BOM" {1921test "i_string_utf16BE_no_BOM" {
1922 any("\x00\x5b\x00\x22\x00\xc3\xa9\x00\x22\x00\x5d");1922 try any("\x00\x5b\x00\x22\x00\xc3\xa9\x00\x22\x00\x5d");
1923}1923}
19241924
1925test "i_string_utf16LE_no_BOM" {1925test "i_string_utf16LE_no_BOM" {
1926 any("\x5b\x00\x22\x00\xc3\xa9\x00\x22\x00\x5d\x00");1926 try any("\x5b\x00\x22\x00\xc3\xa9\x00\x22\x00\x5d\x00");
1927}1927}
19281928
1929test "i_string_UTF-16LE_with_BOM" {1929test "i_string_UTF-16LE_with_BOM" {
1930 any("\xc3\xbf\xc3\xbe\x5b\x00\x22\x00\xc3\xa9\x00\x22\x00\x5d\x00");1930 try any("\xc3\xbf\xc3\xbe\x5b\x00\x22\x00\xc3\xa9\x00\x22\x00\x5d\x00");
1931}1931}
19321932
1933test "i_string_UTF-8_invalid_sequence" {1933test "i_string_UTF-8_invalid_sequence" {
1934 any(1934 try any(
1935 \\["日шú"]1935 \\["日шú"]
1936 );1936 );
1937}1937}
19381938
1939test "i_string_UTF8_surrogate_U+D800" {1939test "i_string_UTF8_surrogate_U+D800" {
1940 any(1940 try any(
1941 \\["í €"]1941 \\["í €"]
1942 );1942 );
1943}1943}
19441944
1945test "i_structure_500_nested_arrays" {1945test "i_structure_500_nested_arrays" {
1946 any(("[" ** 500) ++ ("]" ** 500));1946 try any(("[" ** 500) ++ ("]" ** 500));
1947}1947}
19481948
1949test "i_structure_UTF-8_BOM_empty_object" {1949test "i_structure_UTF-8_BOM_empty_object" {
1950 any(1950 try any(
1951 \\{}1951 \\{}
1952 );1952 );
1953}1953}
19541954
1955test "truncated UTF-8 sequence" {1955test "truncated UTF-8 sequence" {
1956 utf8Error("\"\xc2\"");1956 try utf8Error("\"\xc2\"");
1957 utf8Error("\"\xdf\"");1957 try utf8Error("\"\xdf\"");
1958 utf8Error("\"\xed\xa0\"");1958 try utf8Error("\"\xed\xa0\"");
1959 utf8Error("\"\xf0\x80\"");1959 try utf8Error("\"\xf0\x80\"");
1960 utf8Error("\"\xf0\x80\x80\"");1960 try utf8Error("\"\xf0\x80\x80\"");
1961}1961}
19621962
1963test "invalid continuation byte" {1963test "invalid continuation byte" {
1964 utf8Error("\"\xc2\x00\"");1964 try utf8Error("\"\xc2\x00\"");
1965 utf8Error("\"\xc2\x7f\"");1965 try utf8Error("\"\xc2\x7f\"");
1966 utf8Error("\"\xc2\xc0\"");1966 try utf8Error("\"\xc2\xc0\"");
1967 utf8Error("\"\xc3\xc1\"");1967 try utf8Error("\"\xc3\xc1\"");
1968 utf8Error("\"\xc4\xf5\"");1968 try utf8Error("\"\xc4\xf5\"");
1969 utf8Error("\"\xc5\xff\"");1969 try utf8Error("\"\xc5\xff\"");
1970 utf8Error("\"\xe4\x80\x00\"");1970 try utf8Error("\"\xe4\x80\x00\"");
1971 utf8Error("\"\xe5\x80\x10\"");1971 try utf8Error("\"\xe5\x80\x10\"");
1972 utf8Error("\"\xe6\x80\xc0\"");1972 try utf8Error("\"\xe6\x80\xc0\"");
1973 utf8Error("\"\xe7\x80\xf5\"");1973 try utf8Error("\"\xe7\x80\xf5\"");
1974 utf8Error("\"\xe8\x00\x80\"");1974 try utf8Error("\"\xe8\x00\x80\"");
1975 utf8Error("\"\xf2\x00\x80\x80\"");1975 try utf8Error("\"\xf2\x00\x80\x80\"");
1976 utf8Error("\"\xf0\x80\x00\x80\"");1976 try utf8Error("\"\xf0\x80\x00\x80\"");
1977 utf8Error("\"\xf1\x80\xc0\x80\"");1977 try utf8Error("\"\xf1\x80\xc0\x80\"");
1978 utf8Error("\"\xf2\x80\x80\x00\"");1978 try utf8Error("\"\xf2\x80\x80\x00\"");
1979 utf8Error("\"\xf3\x80\x80\xc0\"");1979 try utf8Error("\"\xf3\x80\x80\xc0\"");
1980 utf8Error("\"\xf4\x80\x80\xf5\"");1980 try utf8Error("\"\xf4\x80\x80\xf5\"");
1981}1981}
19821982
1983test "disallowed overlong form" {1983test "disallowed overlong form" {
1984 utf8Error("\"\xc0\x80\"");1984 try utf8Error("\"\xc0\x80\"");
1985 utf8Error("\"\xc0\x90\"");1985 try utf8Error("\"\xc0\x90\"");
1986 utf8Error("\"\xc1\x80\"");1986 try utf8Error("\"\xc1\x80\"");
1987 utf8Error("\"\xc1\x90\"");1987 try utf8Error("\"\xc1\x90\"");
1988 utf8Error("\"\xe0\x80\x80\"");1988 try utf8Error("\"\xe0\x80\x80\"");
1989 utf8Error("\"\xf0\x80\x80\x80\"");1989 try utf8Error("\"\xf0\x80\x80\x80\"");
1990}1990}
19911991
1992test "out of UTF-16 range" {1992test "out of UTF-16 range" {
1993 utf8Error("\"\xf4\x90\x80\x80\"");1993 try utf8Error("\"\xf4\x90\x80\x80\"");
1994 utf8Error("\"\xf5\x80\x80\x80\"");1994 try utf8Error("\"\xf5\x80\x80\x80\"");
1995 utf8Error("\"\xf6\x80\x80\x80\"");1995 try utf8Error("\"\xf6\x80\x80\x80\"");
1996 utf8Error("\"\xf7\x80\x80\x80\"");1996 try utf8Error("\"\xf7\x80\x80\x80\"");
1997 utf8Error("\"\xf8\x80\x80\x80\"");1997 try utf8Error("\"\xf8\x80\x80\x80\"");
1998 utf8Error("\"\xf9\x80\x80\x80\"");1998 try utf8Error("\"\xf9\x80\x80\x80\"");
1999 utf8Error("\"\xfa\x80\x80\x80\"");1999 try utf8Error("\"\xfa\x80\x80\x80\"");
2000 utf8Error("\"\xfb\x80\x80\x80\"");2000 try utf8Error("\"\xfb\x80\x80\x80\"");
2001 utf8Error("\"\xfc\x80\x80\x80\"");2001 try utf8Error("\"\xfc\x80\x80\x80\"");
2002 utf8Error("\"\xfd\x80\x80\x80\"");2002 try utf8Error("\"\xfd\x80\x80\x80\"");
2003 utf8Error("\"\xfe\x80\x80\x80\"");2003 try utf8Error("\"\xfe\x80\x80\x80\"");
2004 utf8Error("\"\xff\x80\x80\x80\"");2004 try utf8Error("\"\xff\x80\x80\x80\"");
2005}2005}
lib/std/json/write_stream.zig+1-1
...@@ -288,7 +288,7 @@ test "json write stream" {...@@ -288,7 +288,7 @@ test "json write stream" {
288 \\ "float": 3.5e+00288 \\ "float": 3.5e+00
289 \\}289 \\}
290 ;290 ;
291 std.testing.expect(std.mem.eql(u8, expected, result));291 try std.testing.expect(std.mem.eql(u8, expected, result));
292}292}
293293
294fn getJsonObject(allocator: *std.mem.Allocator) !std.json.Value {294fn getJsonObject(allocator: *std.mem.Allocator) !std.json.Value {
lib/std/leb128.zig+68-68
...@@ -152,22 +152,22 @@ test "writeUnsignedFixed" {...@@ -152,22 +152,22 @@ test "writeUnsignedFixed" {
152 {152 {
153 var buf: [4]u8 = undefined;153 var buf: [4]u8 = undefined;
154 writeUnsignedFixed(4, &buf, 0);154 writeUnsignedFixed(4, &buf, 0);
155 testing.expect((try test_read_uleb128(u64, &buf)) == 0);155 try testing.expect((try test_read_uleb128(u64, &buf)) == 0);
156 }156 }
157 {157 {
158 var buf: [4]u8 = undefined;158 var buf: [4]u8 = undefined;
159 writeUnsignedFixed(4, &buf, 1);159 writeUnsignedFixed(4, &buf, 1);
160 testing.expect((try test_read_uleb128(u64, &buf)) == 1);160 try testing.expect((try test_read_uleb128(u64, &buf)) == 1);
161 }161 }
162 {162 {
163 var buf: [4]u8 = undefined;163 var buf: [4]u8 = undefined;
164 writeUnsignedFixed(4, &buf, 1000);164 writeUnsignedFixed(4, &buf, 1000);
165 testing.expect((try test_read_uleb128(u64, &buf)) == 1000);165 try testing.expect((try test_read_uleb128(u64, &buf)) == 1000);
166 }166 }
167 {167 {
168 var buf: [4]u8 = undefined;168 var buf: [4]u8 = undefined;
169 writeUnsignedFixed(4, &buf, 10000000);169 writeUnsignedFixed(4, &buf, 10000000);
170 testing.expect((try test_read_uleb128(u64, &buf)) == 10000000);170 try testing.expect((try test_read_uleb128(u64, &buf)) == 10000000);
171 }171 }
172}172}
173173
...@@ -212,44 +212,44 @@ fn test_read_uleb128_seq(comptime T: type, comptime N: usize, encoded: []const u...@@ -212,44 +212,44 @@ fn test_read_uleb128_seq(comptime T: type, comptime N: usize, encoded: []const u
212212
213test "deserialize signed LEB128" {213test "deserialize signed LEB128" {
214 // Truncated214 // Truncated
215 testing.expectError(error.EndOfStream, test_read_stream_ileb128(i64, "\x80"));215 try testing.expectError(error.EndOfStream, test_read_stream_ileb128(i64, "\x80"));
216216
217 // Overflow217 // Overflow
218 testing.expectError(error.Overflow, test_read_ileb128(i8, "\x80\x80\x40"));218 try testing.expectError(error.Overflow, test_read_ileb128(i8, "\x80\x80\x40"));
219 testing.expectError(error.Overflow, test_read_ileb128(i16, "\x80\x80\x80\x40"));219 try testing.expectError(error.Overflow, test_read_ileb128(i16, "\x80\x80\x80\x40"));
220 testing.expectError(error.Overflow, test_read_ileb128(i32, "\x80\x80\x80\x80\x40"));220 try testing.expectError(error.Overflow, test_read_ileb128(i32, "\x80\x80\x80\x80\x40"));
221 testing.expectError(error.Overflow, test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x40"));221 try testing.expectError(error.Overflow, test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x40"));
222 testing.expectError(error.Overflow, test_read_ileb128(i8, "\xff\x7e"));222 try testing.expectError(error.Overflow, test_read_ileb128(i8, "\xff\x7e"));
223223
224 // Decode SLEB128224 // Decode SLEB128
225 testing.expect((try test_read_ileb128(i64, "\x00")) == 0);225 try testing.expect((try test_read_ileb128(i64, "\x00")) == 0);
226 testing.expect((try test_read_ileb128(i64, "\x01")) == 1);226 try testing.expect((try test_read_ileb128(i64, "\x01")) == 1);
227 testing.expect((try test_read_ileb128(i64, "\x3f")) == 63);227 try testing.expect((try test_read_ileb128(i64, "\x3f")) == 63);
228 testing.expect((try test_read_ileb128(i64, "\x40")) == -64);228 try testing.expect((try test_read_ileb128(i64, "\x40")) == -64);
229 testing.expect((try test_read_ileb128(i64, "\x41")) == -63);229 try testing.expect((try test_read_ileb128(i64, "\x41")) == -63);
230 testing.expect((try test_read_ileb128(i64, "\x7f")) == -1);230 try testing.expect((try test_read_ileb128(i64, "\x7f")) == -1);
231 testing.expect((try test_read_ileb128(i64, "\x80\x01")) == 128);231 try testing.expect((try test_read_ileb128(i64, "\x80\x01")) == 128);
232 testing.expect((try test_read_ileb128(i64, "\x81\x01")) == 129);232 try testing.expect((try test_read_ileb128(i64, "\x81\x01")) == 129);
233 testing.expect((try test_read_ileb128(i64, "\xff\x7e")) == -129);233 try testing.expect((try test_read_ileb128(i64, "\xff\x7e")) == -129);
234 testing.expect((try test_read_ileb128(i64, "\x80\x7f")) == -128);234 try testing.expect((try test_read_ileb128(i64, "\x80\x7f")) == -128);
235 testing.expect((try test_read_ileb128(i64, "\x81\x7f")) == -127);235 try testing.expect((try test_read_ileb128(i64, "\x81\x7f")) == -127);
236 testing.expect((try test_read_ileb128(i64, "\xc0\x00")) == 64);236 try testing.expect((try test_read_ileb128(i64, "\xc0\x00")) == 64);
237 testing.expect((try test_read_ileb128(i64, "\xc7\x9f\x7f")) == -12345);237 try testing.expect((try test_read_ileb128(i64, "\xc7\x9f\x7f")) == -12345);
238 testing.expect((try test_read_ileb128(i8, "\xff\x7f")) == -1);238 try testing.expect((try test_read_ileb128(i8, "\xff\x7f")) == -1);
239 testing.expect((try test_read_ileb128(i16, "\xff\xff\x7f")) == -1);239 try testing.expect((try test_read_ileb128(i16, "\xff\xff\x7f")) == -1);
240 testing.expect((try test_read_ileb128(i32, "\xff\xff\xff\xff\x7f")) == -1);240 try testing.expect((try test_read_ileb128(i32, "\xff\xff\xff\xff\x7f")) == -1);
241 testing.expect((try test_read_ileb128(i32, "\x80\x80\x80\x80\x08")) == -0x80000000);241 try testing.expect((try test_read_ileb128(i32, "\x80\x80\x80\x80\x08")) == -0x80000000);
242 testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01")) == @bitCast(i64, @intCast(u64, 0x8000000000000000)));242 try testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01")) == @bitCast(i64, @intCast(u64, 0x8000000000000000)));
243 testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x40")) == -0x4000000000000000);243 try testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x40")) == -0x4000000000000000);
244 testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x7f")) == -0x8000000000000000);244 try testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x7f")) == -0x8000000000000000);
245245
246 // Decode unnormalized SLEB128 with extra padding bytes.246 // Decode unnormalized SLEB128 with extra padding bytes.
247 testing.expect((try test_read_ileb128(i64, "\x80\x00")) == 0);247 try testing.expect((try test_read_ileb128(i64, "\x80\x00")) == 0);
248 testing.expect((try test_read_ileb128(i64, "\x80\x80\x00")) == 0);248 try testing.expect((try test_read_ileb128(i64, "\x80\x80\x00")) == 0);
249 testing.expect((try test_read_ileb128(i64, "\xff\x00")) == 0x7f);249 try testing.expect((try test_read_ileb128(i64, "\xff\x00")) == 0x7f);
250 testing.expect((try test_read_ileb128(i64, "\xff\x80\x00")) == 0x7f);250 try testing.expect((try test_read_ileb128(i64, "\xff\x80\x00")) == 0x7f);
251 testing.expect((try test_read_ileb128(i64, "\x80\x81\x00")) == 0x80);251 try testing.expect((try test_read_ileb128(i64, "\x80\x81\x00")) == 0x80);
252 testing.expect((try test_read_ileb128(i64, "\x80\x81\x80\x00")) == 0x80);252 try testing.expect((try test_read_ileb128(i64, "\x80\x81\x80\x00")) == 0x80);
253253
254 // Decode sequence of SLEB128 values254 // Decode sequence of SLEB128 values
255 try test_read_ileb128_seq(i64, 4, "\x81\x01\x3f\x80\x7f\x80\x80\x80\x00");255 try test_read_ileb128_seq(i64, 4, "\x81\x01\x3f\x80\x7f\x80\x80\x80\x00");
...@@ -257,39 +257,39 @@ test "deserialize signed LEB128" {...@@ -257,39 +257,39 @@ test "deserialize signed LEB128" {
257257
258test "deserialize unsigned LEB128" {258test "deserialize unsigned LEB128" {
259 // Truncated259 // Truncated
260 testing.expectError(error.EndOfStream, test_read_stream_uleb128(u64, "\x80"));260 try testing.expectError(error.EndOfStream, test_read_stream_uleb128(u64, "\x80"));
261261
262 // Overflow262 // Overflow
263 testing.expectError(error.Overflow, test_read_uleb128(u8, "\x80\x02"));263 try testing.expectError(error.Overflow, test_read_uleb128(u8, "\x80\x02"));
264 testing.expectError(error.Overflow, test_read_uleb128(u8, "\x80\x80\x40"));264 try testing.expectError(error.Overflow, test_read_uleb128(u8, "\x80\x80\x40"));
265 testing.expectError(error.Overflow, test_read_uleb128(u16, "\x80\x80\x84"));265 try testing.expectError(error.Overflow, test_read_uleb128(u16, "\x80\x80\x84"));
266 testing.expectError(error.Overflow, test_read_uleb128(u16, "\x80\x80\x80\x40"));266 try testing.expectError(error.Overflow, test_read_uleb128(u16, "\x80\x80\x80\x40"));
267 testing.expectError(error.Overflow, test_read_uleb128(u32, "\x80\x80\x80\x80\x90"));267 try testing.expectError(error.Overflow, test_read_uleb128(u32, "\x80\x80\x80\x80\x90"));
268 testing.expectError(error.Overflow, test_read_uleb128(u32, "\x80\x80\x80\x80\x40"));268 try testing.expectError(error.Overflow, test_read_uleb128(u32, "\x80\x80\x80\x80\x40"));
269 testing.expectError(error.Overflow, test_read_uleb128(u64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x40"));269 try testing.expectError(error.Overflow, test_read_uleb128(u64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x40"));
270270
271 // Decode ULEB128271 // Decode ULEB128
272 testing.expect((try test_read_uleb128(u64, "\x00")) == 0);272 try testing.expect((try test_read_uleb128(u64, "\x00")) == 0);
273 testing.expect((try test_read_uleb128(u64, "\x01")) == 1);273 try testing.expect((try test_read_uleb128(u64, "\x01")) == 1);
274 testing.expect((try test_read_uleb128(u64, "\x3f")) == 63);274 try testing.expect((try test_read_uleb128(u64, "\x3f")) == 63);
275 testing.expect((try test_read_uleb128(u64, "\x40")) == 64);275 try testing.expect((try test_read_uleb128(u64, "\x40")) == 64);
276 testing.expect((try test_read_uleb128(u64, "\x7f")) == 0x7f);276 try testing.expect((try test_read_uleb128(u64, "\x7f")) == 0x7f);
277 testing.expect((try test_read_uleb128(u64, "\x80\x01")) == 0x80);277 try testing.expect((try test_read_uleb128(u64, "\x80\x01")) == 0x80);
278 testing.expect((try test_read_uleb128(u64, "\x81\x01")) == 0x81);278 try testing.expect((try test_read_uleb128(u64, "\x81\x01")) == 0x81);
279 testing.expect((try test_read_uleb128(u64, "\x90\x01")) == 0x90);279 try testing.expect((try test_read_uleb128(u64, "\x90\x01")) == 0x90);
280 testing.expect((try test_read_uleb128(u64, "\xff\x01")) == 0xff);280 try testing.expect((try test_read_uleb128(u64, "\xff\x01")) == 0xff);
281 testing.expect((try test_read_uleb128(u64, "\x80\x02")) == 0x100);281 try testing.expect((try test_read_uleb128(u64, "\x80\x02")) == 0x100);
282 testing.expect((try test_read_uleb128(u64, "\x81\x02")) == 0x101);282 try testing.expect((try test_read_uleb128(u64, "\x81\x02")) == 0x101);
283 testing.expect((try test_read_uleb128(u64, "\x80\xc1\x80\x80\x10")) == 4294975616);283 try testing.expect((try test_read_uleb128(u64, "\x80\xc1\x80\x80\x10")) == 4294975616);
284 testing.expect((try test_read_uleb128(u64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01")) == 0x8000000000000000);284 try testing.expect((try test_read_uleb128(u64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01")) == 0x8000000000000000);
285285
286 // Decode ULEB128 with extra padding bytes286 // Decode ULEB128 with extra padding bytes
287 testing.expect((try test_read_uleb128(u64, "\x80\x00")) == 0);287 try testing.expect((try test_read_uleb128(u64, "\x80\x00")) == 0);
288 testing.expect((try test_read_uleb128(u64, "\x80\x80\x00")) == 0);288 try testing.expect((try test_read_uleb128(u64, "\x80\x80\x00")) == 0);
289 testing.expect((try test_read_uleb128(u64, "\xff\x00")) == 0x7f);289 try testing.expect((try test_read_uleb128(u64, "\xff\x00")) == 0x7f);
290 testing.expect((try test_read_uleb128(u64, "\xff\x80\x00")) == 0x7f);290 try testing.expect((try test_read_uleb128(u64, "\xff\x80\x00")) == 0x7f);
291 testing.expect((try test_read_uleb128(u64, "\x80\x81\x00")) == 0x80);291 try testing.expect((try test_read_uleb128(u64, "\x80\x81\x00")) == 0x80);
292 testing.expect((try test_read_uleb128(u64, "\x80\x81\x80\x00")) == 0x80);292 try testing.expect((try test_read_uleb128(u64, "\x80\x81\x80\x00")) == 0x80);
293293
294 // Decode sequence of ULEB128 values294 // Decode sequence of ULEB128 values
295 try test_read_uleb128_seq(u64, 4, "\x81\x01\x3f\x80\x7f\x80\x80\x80\x00");295 try test_read_uleb128_seq(u64, 4, "\x81\x01\x3f\x80\x7f\x80\x80\x80\x00");
...@@ -326,19 +326,19 @@ fn test_write_leb128(value: anytype) !void {...@@ -326,19 +326,19 @@ fn test_write_leb128(value: anytype) !void {
326 // stream write326 // stream write
327 try writeStream(fbs.writer(), value);327 try writeStream(fbs.writer(), value);
328 const w1_pos = fbs.pos;328 const w1_pos = fbs.pos;
329 testing.expect(w1_pos == bytes_needed);329 try testing.expect(w1_pos == bytes_needed);
330330
331 // stream read331 // stream read
332 fbs.pos = 0;332 fbs.pos = 0;
333 const sr = try readStream(T, fbs.reader());333 const sr = try readStream(T, fbs.reader());
334 testing.expect(fbs.pos == w1_pos);334 try testing.expect(fbs.pos == w1_pos);
335 testing.expect(sr == value);335 try testing.expect(sr == value);
336336
337 // bigger type stream read337 // bigger type stream read
338 fbs.pos = 0;338 fbs.pos = 0;
339 const bsr = try readStream(B, fbs.reader());339 const bsr = try readStream(B, fbs.reader());
340 testing.expect(fbs.pos == w1_pos);340 try testing.expect(fbs.pos == w1_pos);
341 testing.expect(bsr == value);341 try testing.expect(bsr == value);
342}342}
343343
344test "serialize unsigned LEB128" {344test "serialize unsigned LEB128" {
lib/std/linked_list.zig+20-20
...@@ -123,7 +123,7 @@ test "basic SinglyLinkedList test" {...@@ -123,7 +123,7 @@ test "basic SinglyLinkedList test" {
123 const L = SinglyLinkedList(u32);123 const L = SinglyLinkedList(u32);
124 var list = L{};124 var list = L{};
125125
126 testing.expect(list.len() == 0);126 try testing.expect(list.len() == 0);
127127
128 var one = L.Node{ .data = 1 };128 var one = L.Node{ .data = 1 };
129 var two = L.Node{ .data = 2 };129 var two = L.Node{ .data = 2 };
...@@ -137,14 +137,14 @@ test "basic SinglyLinkedList test" {...@@ -137,14 +137,14 @@ test "basic SinglyLinkedList test" {
137 two.insertAfter(&three); // {1, 2, 3, 5}137 two.insertAfter(&three); // {1, 2, 3, 5}
138 three.insertAfter(&four); // {1, 2, 3, 4, 5}138 three.insertAfter(&four); // {1, 2, 3, 4, 5}
139139
140 testing.expect(list.len() == 5);140 try testing.expect(list.len() == 5);
141141
142 // Traverse forwards.142 // Traverse forwards.
143 {143 {
144 var it = list.first;144 var it = list.first;
145 var index: u32 = 1;145 var index: u32 = 1;
146 while (it) |node| : (it = node.next) {146 while (it) |node| : (it = node.next) {
147 testing.expect(node.data == index);147 try testing.expect(node.data == index);
148 index += 1;148 index += 1;
149 }149 }
150 }150 }
...@@ -153,9 +153,9 @@ test "basic SinglyLinkedList test" {...@@ -153,9 +153,9 @@ test "basic SinglyLinkedList test" {
153 _ = list.remove(&five); // {2, 3, 4}153 _ = list.remove(&five); // {2, 3, 4}
154 _ = two.removeNext(); // {2, 4}154 _ = two.removeNext(); // {2, 4}
155155
156 testing.expect(list.first.?.data == 2);156 try testing.expect(list.first.?.data == 2);
157 testing.expect(list.first.?.next.?.data == 4);157 try testing.expect(list.first.?.next.?.data == 4);
158 testing.expect(list.first.?.next.?.next == null);158 try testing.expect(list.first.?.next.?.next == null);
159}159}
160160
161/// A tail queue is headed by a pair of pointers, one to the head of the161/// A tail queue is headed by a pair of pointers, one to the head of the
...@@ -344,7 +344,7 @@ test "basic TailQueue test" {...@@ -344,7 +344,7 @@ test "basic TailQueue test" {
344 var it = list.first;344 var it = list.first;
345 var index: u32 = 1;345 var index: u32 = 1;
346 while (it) |node| : (it = node.next) {346 while (it) |node| : (it = node.next) {
347 testing.expect(node.data == index);347 try testing.expect(node.data == index);
348 index += 1;348 index += 1;
349 }349 }
350 }350 }
...@@ -354,7 +354,7 @@ test "basic TailQueue test" {...@@ -354,7 +354,7 @@ test "basic TailQueue test" {
354 var it = list.last;354 var it = list.last;
355 var index: u32 = 1;355 var index: u32 = 1;
356 while (it) |node| : (it = node.prev) {356 while (it) |node| : (it = node.prev) {
357 testing.expect(node.data == (6 - index));357 try testing.expect(node.data == (6 - index));
358 index += 1;358 index += 1;
359 }359 }
360 }360 }
...@@ -363,9 +363,9 @@ test "basic TailQueue test" {...@@ -363,9 +363,9 @@ test "basic TailQueue test" {
363 var last = list.pop(); // {2, 3, 4}363 var last = list.pop(); // {2, 3, 4}
364 list.remove(&three); // {2, 4}364 list.remove(&three); // {2, 4}
365365
366 testing.expect(list.first.?.data == 2);366 try testing.expect(list.first.?.data == 2);
367 testing.expect(list.last.?.data == 4);367 try testing.expect(list.last.?.data == 4);
368 testing.expect(list.len == 2);368 try testing.expect(list.len == 2);
369}369}
370370
371test "TailQueue concatenation" {371test "TailQueue concatenation" {
...@@ -387,18 +387,18 @@ test "TailQueue concatenation" {...@@ -387,18 +387,18 @@ test "TailQueue concatenation" {
387387
388 list1.concatByMoving(&list2);388 list1.concatByMoving(&list2);
389389
390 testing.expect(list1.last == &five);390 try testing.expect(list1.last == &five);
391 testing.expect(list1.len == 5);391 try testing.expect(list1.len == 5);
392 testing.expect(list2.first == null);392 try testing.expect(list2.first == null);
393 testing.expect(list2.last == null);393 try testing.expect(list2.last == null);
394 testing.expect(list2.len == 0);394 try testing.expect(list2.len == 0);
395395
396 // Traverse forwards.396 // Traverse forwards.
397 {397 {
398 var it = list1.first;398 var it = list1.first;
399 var index: u32 = 1;399 var index: u32 = 1;
400 while (it) |node| : (it = node.next) {400 while (it) |node| : (it = node.next) {
401 testing.expect(node.data == index);401 try testing.expect(node.data == index);
402 index += 1;402 index += 1;
403 }403 }
404 }404 }
...@@ -408,7 +408,7 @@ test "TailQueue concatenation" {...@@ -408,7 +408,7 @@ test "TailQueue concatenation" {
408 var it = list1.last;408 var it = list1.last;
409 var index: u32 = 1;409 var index: u32 = 1;
410 while (it) |node| : (it = node.prev) {410 while (it) |node| : (it = node.prev) {
411 testing.expect(node.data == (6 - index));411 try testing.expect(node.data == (6 - index));
412 index += 1;412 index += 1;
413 }413 }
414 }414 }
...@@ -421,7 +421,7 @@ test "TailQueue concatenation" {...@@ -421,7 +421,7 @@ test "TailQueue concatenation" {
421 var it = list2.first;421 var it = list2.first;
422 var index: u32 = 1;422 var index: u32 = 1;
423 while (it) |node| : (it = node.next) {423 while (it) |node| : (it = node.next) {
424 testing.expect(node.data == index);424 try testing.expect(node.data == index);
425 index += 1;425 index += 1;
426 }426 }
427 }427 }
...@@ -431,7 +431,7 @@ test "TailQueue concatenation" {...@@ -431,7 +431,7 @@ test "TailQueue concatenation" {
431 var it = list2.last;431 var it = list2.last;
432 var index: u32 = 1;432 var index: u32 = 1;
433 while (it) |node| : (it = node.prev) {433 while (it) |node| : (it = node.prev) {
434 testing.expect(node.data == (6 - index));434 try testing.expect(node.data == (6 - index));
435 index += 1;435 index += 1;
436 }436 }
437 }437 }
lib/std/math.zig+353-353
...@@ -177,20 +177,20 @@ test "approxEqAbs and approxEqRel" {...@@ -177,20 +177,20 @@ test "approxEqAbs and approxEqRel" {
177 else => unreachable,177 else => unreachable,
178 };178 };
179179
180 testing.expect(approxEqAbs(T, 0.0, 0.0, eps_value));180 try testing.expect(approxEqAbs(T, 0.0, 0.0, eps_value));
181 testing.expect(approxEqAbs(T, -0.0, -0.0, eps_value));181 try testing.expect(approxEqAbs(T, -0.0, -0.0, eps_value));
182 testing.expect(approxEqAbs(T, 0.0, -0.0, eps_value));182 try testing.expect(approxEqAbs(T, 0.0, -0.0, eps_value));
183 testing.expect(approxEqRel(T, 1.0, 1.0, sqrt_eps_value));183 try testing.expect(approxEqRel(T, 1.0, 1.0, sqrt_eps_value));
184 testing.expect(!approxEqRel(T, 1.0, 0.0, sqrt_eps_value));184 try testing.expect(!approxEqRel(T, 1.0, 0.0, sqrt_eps_value));
185 testing.expect(!approxEqAbs(T, 1.0 + 2 * epsilon(T), 1.0, eps_value));185 try testing.expect(!approxEqAbs(T, 1.0 + 2 * epsilon(T), 1.0, eps_value));
186 testing.expect(approxEqAbs(T, 1.0 + 1 * epsilon(T), 1.0, eps_value));186 try testing.expect(approxEqAbs(T, 1.0 + 1 * epsilon(T), 1.0, eps_value));
187 testing.expect(!approxEqRel(T, 1.0, nan_value, sqrt_eps_value));187 try testing.expect(!approxEqRel(T, 1.0, nan_value, sqrt_eps_value));
188 testing.expect(!approxEqRel(T, nan_value, nan_value, sqrt_eps_value));188 try testing.expect(!approxEqRel(T, nan_value, nan_value, sqrt_eps_value));
189 testing.expect(approxEqRel(T, inf_value, inf_value, sqrt_eps_value));189 try testing.expect(approxEqRel(T, inf_value, inf_value, sqrt_eps_value));
190 testing.expect(approxEqRel(T, min_value, min_value, sqrt_eps_value));190 try testing.expect(approxEqRel(T, min_value, min_value, sqrt_eps_value));
191 testing.expect(approxEqRel(T, -min_value, -min_value, sqrt_eps_value));191 try testing.expect(approxEqRel(T, -min_value, -min_value, sqrt_eps_value));
192 testing.expect(approxEqAbs(T, min_value, 0.0, eps_value * 2));192 try testing.expect(approxEqAbs(T, min_value, 0.0, eps_value * 2));
193 testing.expect(approxEqAbs(T, -min_value, 0.0, eps_value * 2));193 try testing.expect(approxEqAbs(T, -min_value, 0.0, eps_value * 2));
194 }194 }
195}195}
196196
...@@ -349,34 +349,34 @@ pub fn min(x: anytype, y: anytype) Min(@TypeOf(x), @TypeOf(y)) {...@@ -349,34 +349,34 @@ pub fn min(x: anytype, y: anytype) Min(@TypeOf(x), @TypeOf(y)) {
349}349}
350350
351test "math.min" {351test "math.min" {
352 testing.expect(min(@as(i32, -1), @as(i32, 2)) == -1);352 try testing.expect(min(@as(i32, -1), @as(i32, 2)) == -1);
353 {353 {
354 var a: u16 = 999;354 var a: u16 = 999;
355 var b: u32 = 10;355 var b: u32 = 10;
356 var result = min(a, b);356 var result = min(a, b);
357 testing.expect(@TypeOf(result) == u16);357 try testing.expect(@TypeOf(result) == u16);
358 testing.expect(result == 10);358 try testing.expect(result == 10);
359 }359 }
360 {360 {
361 var a: f64 = 10.34;361 var a: f64 = 10.34;
362 var b: f32 = 999.12;362 var b: f32 = 999.12;
363 var result = min(a, b);363 var result = min(a, b);
364 testing.expect(@TypeOf(result) == f64);364 try testing.expect(@TypeOf(result) == f64);
365 testing.expect(result == 10.34);365 try testing.expect(result == 10.34);
366 }366 }
367 {367 {
368 var a: i8 = -127;368 var a: i8 = -127;
369 var b: i16 = -200;369 var b: i16 = -200;
370 var result = min(a, b);370 var result = min(a, b);
371 testing.expect(@TypeOf(result) == i16);371 try testing.expect(@TypeOf(result) == i16);
372 testing.expect(result == -200);372 try testing.expect(result == -200);
373 }373 }
374 {374 {
375 const a = 10.34;375 const a = 10.34;
376 var b: f32 = 999.12;376 var b: f32 = 999.12;
377 var result = min(a, b);377 var result = min(a, b);
378 testing.expect(@TypeOf(result) == f32);378 try testing.expect(@TypeOf(result) == f32);
379 testing.expect(result == 10.34);379 try testing.expect(result == 10.34);
380 }380 }
381}381}
382382
...@@ -385,7 +385,7 @@ pub fn max(x: anytype, y: anytype) @TypeOf(x, y) {...@@ -385,7 +385,7 @@ pub fn max(x: anytype, y: anytype) @TypeOf(x, y) {
385}385}
386386
387test "math.max" {387test "math.max" {
388 testing.expect(max(@as(i32, -1), @as(i32, 2)) == 2);388 try testing.expect(max(@as(i32, -1), @as(i32, 2)) == 2);
389}389}
390390
391pub fn clamp(val: anytype, lower: anytype, upper: anytype) @TypeOf(val, lower, upper) {391pub fn clamp(val: anytype, lower: anytype, upper: anytype) @TypeOf(val, lower, upper) {
...@@ -394,19 +394,19 @@ pub fn clamp(val: anytype, lower: anytype, upper: anytype) @TypeOf(val, lower, u...@@ -394,19 +394,19 @@ pub fn clamp(val: anytype, lower: anytype, upper: anytype) @TypeOf(val, lower, u
394}394}
395test "math.clamp" {395test "math.clamp" {
396 // Within range396 // Within range
397 testing.expect(std.math.clamp(@as(i32, -1), @as(i32, -4), @as(i32, 7)) == -1);397 try testing.expect(std.math.clamp(@as(i32, -1), @as(i32, -4), @as(i32, 7)) == -1);
398 // Below398 // Below
399 testing.expect(std.math.clamp(@as(i32, -5), @as(i32, -4), @as(i32, 7)) == -4);399 try testing.expect(std.math.clamp(@as(i32, -5), @as(i32, -4), @as(i32, 7)) == -4);
400 // Above400 // Above
401 testing.expect(std.math.clamp(@as(i32, 8), @as(i32, -4), @as(i32, 7)) == 7);401 try testing.expect(std.math.clamp(@as(i32, 8), @as(i32, -4), @as(i32, 7)) == 7);
402402
403 // Floating point403 // Floating point
404 testing.expect(std.math.clamp(@as(f32, 1.1), @as(f32, 0.0), @as(f32, 1.0)) == 1.0);404 try testing.expect(std.math.clamp(@as(f32, 1.1), @as(f32, 0.0), @as(f32, 1.0)) == 1.0);
405 testing.expect(std.math.clamp(@as(f32, -127.5), @as(f32, -200), @as(f32, -100)) == -127.5);405 try testing.expect(std.math.clamp(@as(f32, -127.5), @as(f32, -200), @as(f32, -100)) == -127.5);
406406
407 // Mix of comptime and non-comptime407 // Mix of comptime and non-comptime
408 var i: i32 = 1;408 var i: i32 = 1;
409 testing.expect(std.math.clamp(i, 0, 1) == 1);409 try testing.expect(std.math.clamp(i, 0, 1) == 1);
410}410}
411411
412pub fn mul(comptime T: type, a: T, b: T) (error{Overflow}!T) {412pub fn mul(comptime T: type, a: T, b: T) (error{Overflow}!T) {
...@@ -461,17 +461,17 @@ pub fn shl(comptime T: type, a: T, shift_amt: anytype) T {...@@ -461,17 +461,17 @@ pub fn shl(comptime T: type, a: T, shift_amt: anytype) T {
461}461}
462462
463test "math.shl" {463test "math.shl" {
464 testing.expect(shl(u8, 0b11111111, @as(usize, 3)) == 0b11111000);464 try testing.expect(shl(u8, 0b11111111, @as(usize, 3)) == 0b11111000);
465 testing.expect(shl(u8, 0b11111111, @as(usize, 8)) == 0);465 try testing.expect(shl(u8, 0b11111111, @as(usize, 8)) == 0);
466 testing.expect(shl(u8, 0b11111111, @as(usize, 9)) == 0);466 try testing.expect(shl(u8, 0b11111111, @as(usize, 9)) == 0);
467 testing.expect(shl(u8, 0b11111111, @as(isize, -2)) == 0b00111111);467 try testing.expect(shl(u8, 0b11111111, @as(isize, -2)) == 0b00111111);
468 testing.expect(shl(u8, 0b11111111, 3) == 0b11111000);468 try testing.expect(shl(u8, 0b11111111, 3) == 0b11111000);
469 testing.expect(shl(u8, 0b11111111, 8) == 0);469 try testing.expect(shl(u8, 0b11111111, 8) == 0);
470 testing.expect(shl(u8, 0b11111111, 9) == 0);470 try testing.expect(shl(u8, 0b11111111, 9) == 0);
471 testing.expect(shl(u8, 0b11111111, -2) == 0b00111111);471 try testing.expect(shl(u8, 0b11111111, -2) == 0b00111111);
472 testing.expect(shl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, @as(usize, 1))[0] == @as(u32, 42) << 1);472 try testing.expect(shl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, @as(usize, 1))[0] == @as(u32, 42) << 1);
473 testing.expect(shl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, @as(isize, -1))[0] == @as(u32, 42) >> 1);473 try testing.expect(shl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, @as(isize, -1))[0] == @as(u32, 42) >> 1);
474 testing.expect(shl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, 33)[0] == 0);474 try testing.expect(shl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, 33)[0] == 0);
475}475}
476476
477/// Shifts right. Overflowed bits are truncated.477/// Shifts right. Overflowed bits are truncated.
...@@ -501,17 +501,17 @@ pub fn shr(comptime T: type, a: T, shift_amt: anytype) T {...@@ -501,17 +501,17 @@ pub fn shr(comptime T: type, a: T, shift_amt: anytype) T {
501}501}
502502
503test "math.shr" {503test "math.shr" {
504 testing.expect(shr(u8, 0b11111111, @as(usize, 3)) == 0b00011111);504 try testing.expect(shr(u8, 0b11111111, @as(usize, 3)) == 0b00011111);
505 testing.expect(shr(u8, 0b11111111, @as(usize, 8)) == 0);505 try testing.expect(shr(u8, 0b11111111, @as(usize, 8)) == 0);
506 testing.expect(shr(u8, 0b11111111, @as(usize, 9)) == 0);506 try testing.expect(shr(u8, 0b11111111, @as(usize, 9)) == 0);
507 testing.expect(shr(u8, 0b11111111, @as(isize, -2)) == 0b11111100);507 try testing.expect(shr(u8, 0b11111111, @as(isize, -2)) == 0b11111100);
508 testing.expect(shr(u8, 0b11111111, 3) == 0b00011111);508 try testing.expect(shr(u8, 0b11111111, 3) == 0b00011111);
509 testing.expect(shr(u8, 0b11111111, 8) == 0);509 try testing.expect(shr(u8, 0b11111111, 8) == 0);
510 testing.expect(shr(u8, 0b11111111, 9) == 0);510 try testing.expect(shr(u8, 0b11111111, 9) == 0);
511 testing.expect(shr(u8, 0b11111111, -2) == 0b11111100);511 try testing.expect(shr(u8, 0b11111111, -2) == 0b11111100);
512 testing.expect(shr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, @as(usize, 1))[0] == @as(u32, 42) >> 1);512 try testing.expect(shr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, @as(usize, 1))[0] == @as(u32, 42) >> 1);
513 testing.expect(shr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, @as(isize, -1))[0] == @as(u32, 42) << 1);513 try testing.expect(shr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, @as(isize, -1))[0] == @as(u32, 42) << 1);
514 testing.expect(shr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, 33)[0] == 0);514 try testing.expect(shr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, 33)[0] == 0);
515}515}
516516
517/// Rotates right. Only unsigned values can be rotated.517/// Rotates right. Only unsigned values can be rotated.
...@@ -533,13 +533,13 @@ pub fn rotr(comptime T: type, x: T, r: anytype) T {...@@ -533,13 +533,13 @@ pub fn rotr(comptime T: type, x: T, r: anytype) T {
533}533}
534534
535test "math.rotr" {535test "math.rotr" {
536 testing.expect(rotr(u8, 0b00000001, @as(usize, 0)) == 0b00000001);536 try testing.expect(rotr(u8, 0b00000001, @as(usize, 0)) == 0b00000001);
537 testing.expect(rotr(u8, 0b00000001, @as(usize, 9)) == 0b10000000);537 try testing.expect(rotr(u8, 0b00000001, @as(usize, 9)) == 0b10000000);
538 testing.expect(rotr(u8, 0b00000001, @as(usize, 8)) == 0b00000001);538 try testing.expect(rotr(u8, 0b00000001, @as(usize, 8)) == 0b00000001);
539 testing.expect(rotr(u8, 0b00000001, @as(usize, 4)) == 0b00010000);539 try testing.expect(rotr(u8, 0b00000001, @as(usize, 4)) == 0b00010000);
540 testing.expect(rotr(u8, 0b00000001, @as(isize, -1)) == 0b00000010);540 try testing.expect(rotr(u8, 0b00000001, @as(isize, -1)) == 0b00000010);
541 testing.expect(rotr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){1}, @as(usize, 1))[0] == @as(u32, 1) << 31);541 try testing.expect(rotr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){1}, @as(usize, 1))[0] == @as(u32, 1) << 31);
542 testing.expect(rotr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){1}, @as(isize, -1))[0] == @as(u32, 1) << 1);542 try testing.expect(rotr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){1}, @as(isize, -1))[0] == @as(u32, 1) << 1);
543}543}
544544
545/// Rotates left. Only unsigned values can be rotated.545/// Rotates left. Only unsigned values can be rotated.
...@@ -561,13 +561,13 @@ pub fn rotl(comptime T: type, x: T, r: anytype) T {...@@ -561,13 +561,13 @@ pub fn rotl(comptime T: type, x: T, r: anytype) T {
561}561}
562562
563test "math.rotl" {563test "math.rotl" {
564 testing.expect(rotl(u8, 0b00000001, @as(usize, 0)) == 0b00000001);564 try testing.expect(rotl(u8, 0b00000001, @as(usize, 0)) == 0b00000001);
565 testing.expect(rotl(u8, 0b00000001, @as(usize, 9)) == 0b00000010);565 try testing.expect(rotl(u8, 0b00000001, @as(usize, 9)) == 0b00000010);
566 testing.expect(rotl(u8, 0b00000001, @as(usize, 8)) == 0b00000001);566 try testing.expect(rotl(u8, 0b00000001, @as(usize, 8)) == 0b00000001);
567 testing.expect(rotl(u8, 0b00000001, @as(usize, 4)) == 0b00010000);567 try testing.expect(rotl(u8, 0b00000001, @as(usize, 4)) == 0b00010000);
568 testing.expect(rotl(u8, 0b00000001, @as(isize, -1)) == 0b10000000);568 try testing.expect(rotl(u8, 0b00000001, @as(isize, -1)) == 0b10000000);
569 testing.expect(rotl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){1 << 31}, @as(usize, 1))[0] == 1);569 try testing.expect(rotl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){1 << 31}, @as(usize, 1))[0] == 1);
570 testing.expect(rotl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){1 << 31}, @as(isize, -1))[0] == @as(u32, 1) << 30);570 try testing.expect(rotl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){1 << 31}, @as(isize, -1))[0] == @as(u32, 1) << 30);
571}571}
572572
573pub fn Log2Int(comptime T: type) type {573pub fn Log2Int(comptime T: type) type {
...@@ -598,62 +598,62 @@ pub fn IntFittingRange(comptime from: comptime_int, comptime to: comptime_int) t...@@ -598,62 +598,62 @@ pub fn IntFittingRange(comptime from: comptime_int, comptime to: comptime_int) t
598}598}
599599
600test "math.IntFittingRange" {600test "math.IntFittingRange" {
601 testing.expect(IntFittingRange(0, 0) == u0);601 try testing.expect(IntFittingRange(0, 0) == u0);
602 testing.expect(IntFittingRange(0, 1) == u1);602 try testing.expect(IntFittingRange(0, 1) == u1);
603 testing.expect(IntFittingRange(0, 2) == u2);603 try testing.expect(IntFittingRange(0, 2) == u2);
604 testing.expect(IntFittingRange(0, 3) == u2);604 try testing.expect(IntFittingRange(0, 3) == u2);
605 testing.expect(IntFittingRange(0, 4) == u3);605 try testing.expect(IntFittingRange(0, 4) == u3);
606 testing.expect(IntFittingRange(0, 7) == u3);606 try testing.expect(IntFittingRange(0, 7) == u3);
607 testing.expect(IntFittingRange(0, 8) == u4);607 try testing.expect(IntFittingRange(0, 8) == u4);
608 testing.expect(IntFittingRange(0, 9) == u4);608 try testing.expect(IntFittingRange(0, 9) == u4);
609 testing.expect(IntFittingRange(0, 15) == u4);609 try testing.expect(IntFittingRange(0, 15) == u4);
610 testing.expect(IntFittingRange(0, 16) == u5);610 try testing.expect(IntFittingRange(0, 16) == u5);
611 testing.expect(IntFittingRange(0, 17) == u5);611 try testing.expect(IntFittingRange(0, 17) == u5);
612 testing.expect(IntFittingRange(0, 4095) == u12);612 try testing.expect(IntFittingRange(0, 4095) == u12);
613 testing.expect(IntFittingRange(2000, 4095) == u12);613 try testing.expect(IntFittingRange(2000, 4095) == u12);
614 testing.expect(IntFittingRange(0, 4096) == u13);614 try testing.expect(IntFittingRange(0, 4096) == u13);
615 testing.expect(IntFittingRange(2000, 4096) == u13);615 try testing.expect(IntFittingRange(2000, 4096) == u13);
616 testing.expect(IntFittingRange(0, 4097) == u13);616 try testing.expect(IntFittingRange(0, 4097) == u13);
617 testing.expect(IntFittingRange(2000, 4097) == u13);617 try testing.expect(IntFittingRange(2000, 4097) == u13);
618 testing.expect(IntFittingRange(0, 123456789123456798123456789) == u87);618 try testing.expect(IntFittingRange(0, 123456789123456798123456789) == u87);
619 testing.expect(IntFittingRange(0, 123456789123456798123456789123456789123456798123456789) == u177);619 try testing.expect(IntFittingRange(0, 123456789123456798123456789123456789123456798123456789) == u177);
620620
621 testing.expect(IntFittingRange(-1, -1) == i1);621 try testing.expect(IntFittingRange(-1, -1) == i1);
622 testing.expect(IntFittingRange(-1, 0) == i1);622 try testing.expect(IntFittingRange(-1, 0) == i1);
623 testing.expect(IntFittingRange(-1, 1) == i2);623 try testing.expect(IntFittingRange(-1, 1) == i2);
624 testing.expect(IntFittingRange(-2, -2) == i2);624 try testing.expect(IntFittingRange(-2, -2) == i2);
625 testing.expect(IntFittingRange(-2, -1) == i2);625 try testing.expect(IntFittingRange(-2, -1) == i2);
626 testing.expect(IntFittingRange(-2, 0) == i2);626 try testing.expect(IntFittingRange(-2, 0) == i2);
627 testing.expect(IntFittingRange(-2, 1) == i2);627 try testing.expect(IntFittingRange(-2, 1) == i2);
628 testing.expect(IntFittingRange(-2, 2) == i3);628 try testing.expect(IntFittingRange(-2, 2) == i3);
629 testing.expect(IntFittingRange(-1, 2) == i3);629 try testing.expect(IntFittingRange(-1, 2) == i3);
630 testing.expect(IntFittingRange(-1, 3) == i3);630 try testing.expect(IntFittingRange(-1, 3) == i3);
631 testing.expect(IntFittingRange(-1, 4) == i4);631 try testing.expect(IntFittingRange(-1, 4) == i4);
632 testing.expect(IntFittingRange(-1, 7) == i4);632 try testing.expect(IntFittingRange(-1, 7) == i4);
633 testing.expect(IntFittingRange(-1, 8) == i5);633 try testing.expect(IntFittingRange(-1, 8) == i5);
634 testing.expect(IntFittingRange(-1, 9) == i5);634 try testing.expect(IntFittingRange(-1, 9) == i5);
635 testing.expect(IntFittingRange(-1, 15) == i5);635 try testing.expect(IntFittingRange(-1, 15) == i5);
636 testing.expect(IntFittingRange(-1, 16) == i6);636 try testing.expect(IntFittingRange(-1, 16) == i6);
637 testing.expect(IntFittingRange(-1, 17) == i6);637 try testing.expect(IntFittingRange(-1, 17) == i6);
638 testing.expect(IntFittingRange(-1, 4095) == i13);638 try testing.expect(IntFittingRange(-1, 4095) == i13);
639 testing.expect(IntFittingRange(-4096, 4095) == i13);639 try testing.expect(IntFittingRange(-4096, 4095) == i13);
640 testing.expect(IntFittingRange(-1, 4096) == i14);640 try testing.expect(IntFittingRange(-1, 4096) == i14);
641 testing.expect(IntFittingRange(-4097, 4095) == i14);641 try testing.expect(IntFittingRange(-4097, 4095) == i14);
642 testing.expect(IntFittingRange(-1, 4097) == i14);642 try testing.expect(IntFittingRange(-1, 4097) == i14);
643 testing.expect(IntFittingRange(-1, 123456789123456798123456789) == i88);643 try testing.expect(IntFittingRange(-1, 123456789123456798123456789) == i88);
644 testing.expect(IntFittingRange(-1, 123456789123456798123456789123456789123456798123456789) == i178);644 try testing.expect(IntFittingRange(-1, 123456789123456798123456789123456789123456798123456789) == i178);
645}645}
646646
647test "math overflow functions" {647test "math overflow functions" {
648 testOverflow();648 try testOverflow();
649 comptime testOverflow();649 comptime try testOverflow();
650}650}
651651
652fn testOverflow() void {652fn testOverflow() !void {
653 testing.expect((mul(i32, 3, 4) catch unreachable) == 12);653 try testing.expect((mul(i32, 3, 4) catch unreachable) == 12);
654 testing.expect((add(i32, 3, 4) catch unreachable) == 7);654 try testing.expect((add(i32, 3, 4) catch unreachable) == 7);
655 testing.expect((sub(i32, 3, 4) catch unreachable) == -1);655 try testing.expect((sub(i32, 3, 4) catch unreachable) == -1);
656 testing.expect((shlExact(i32, 0b11, 4) catch unreachable) == 0b110000);656 try testing.expect((shlExact(i32, 0b11, 4) catch unreachable) == 0b110000);
657}657}
658658
659pub fn absInt(x: anytype) !@TypeOf(x) {659pub fn absInt(x: anytype) !@TypeOf(x) {
...@@ -670,23 +670,23 @@ pub fn absInt(x: anytype) !@TypeOf(x) {...@@ -670,23 +670,23 @@ pub fn absInt(x: anytype) !@TypeOf(x) {
670}670}
671671
672test "math.absInt" {672test "math.absInt" {
673 testAbsInt();673 try testAbsInt();
674 comptime testAbsInt();674 comptime try testAbsInt();
675}675}
676fn testAbsInt() void {676fn testAbsInt() !void {
677 testing.expect((absInt(@as(i32, -10)) catch unreachable) == 10);677 try testing.expect((absInt(@as(i32, -10)) catch unreachable) == 10);
678 testing.expect((absInt(@as(i32, 10)) catch unreachable) == 10);678 try testing.expect((absInt(@as(i32, 10)) catch unreachable) == 10);
679}679}
680680
681pub const absFloat = fabs;681pub const absFloat = fabs;
682682
683test "math.absFloat" {683test "math.absFloat" {
684 testAbsFloat();684 try testAbsFloat();
685 comptime testAbsFloat();685 comptime try testAbsFloat();
686}686}
687fn testAbsFloat() void {687fn testAbsFloat() !void {
688 testing.expect(absFloat(@as(f32, -10.05)) == 10.05);688 try testing.expect(absFloat(@as(f32, -10.05)) == 10.05);
689 testing.expect(absFloat(@as(f32, 10.05)) == 10.05);689 try testing.expect(absFloat(@as(f32, 10.05)) == 10.05);
690}690}
691691
692pub fn divTrunc(comptime T: type, numerator: T, denominator: T) !T {692pub fn divTrunc(comptime T: type, numerator: T, denominator: T) !T {
...@@ -697,17 +697,17 @@ pub fn divTrunc(comptime T: type, numerator: T, denominator: T) !T {...@@ -697,17 +697,17 @@ pub fn divTrunc(comptime T: type, numerator: T, denominator: T) !T {
697}697}
698698
699test "math.divTrunc" {699test "math.divTrunc" {
700 testDivTrunc();700 try testDivTrunc();
701 comptime testDivTrunc();701 comptime try testDivTrunc();
702}702}
703fn testDivTrunc() void {703fn testDivTrunc() !void {
704 testing.expect((divTrunc(i32, 5, 3) catch unreachable) == 1);704 try testing.expect((divTrunc(i32, 5, 3) catch unreachable) == 1);
705 testing.expect((divTrunc(i32, -5, 3) catch unreachable) == -1);705 try testing.expect((divTrunc(i32, -5, 3) catch unreachable) == -1);
706 testing.expectError(error.DivisionByZero, divTrunc(i8, -5, 0));706 try testing.expectError(error.DivisionByZero, divTrunc(i8, -5, 0));
707 testing.expectError(error.Overflow, divTrunc(i8, -128, -1));707 try testing.expectError(error.Overflow, divTrunc(i8, -128, -1));
708708
709 testing.expect((divTrunc(f32, 5.0, 3.0) catch unreachable) == 1.0);709 try testing.expect((divTrunc(f32, 5.0, 3.0) catch unreachable) == 1.0);
710 testing.expect((divTrunc(f32, -5.0, 3.0) catch unreachable) == -1.0);710 try testing.expect((divTrunc(f32, -5.0, 3.0) catch unreachable) == -1.0);
711}711}
712712
713pub fn divFloor(comptime T: type, numerator: T, denominator: T) !T {713pub fn divFloor(comptime T: type, numerator: T, denominator: T) !T {
...@@ -718,17 +718,17 @@ pub fn divFloor(comptime T: type, numerator: T, denominator: T) !T {...@@ -718,17 +718,17 @@ pub fn divFloor(comptime T: type, numerator: T, denominator: T) !T {
718}718}
719719
720test "math.divFloor" {720test "math.divFloor" {
721 testDivFloor();721 try testDivFloor();
722 comptime testDivFloor();722 comptime try testDivFloor();
723}723}
724fn testDivFloor() void {724fn testDivFloor() !void {
725 testing.expect((divFloor(i32, 5, 3) catch unreachable) == 1);725 try testing.expect((divFloor(i32, 5, 3) catch unreachable) == 1);
726 testing.expect((divFloor(i32, -5, 3) catch unreachable) == -2);726 try testing.expect((divFloor(i32, -5, 3) catch unreachable) == -2);
727 testing.expectError(error.DivisionByZero, divFloor(i8, -5, 0));727 try testing.expectError(error.DivisionByZero, divFloor(i8, -5, 0));
728 testing.expectError(error.Overflow, divFloor(i8, -128, -1));728 try testing.expectError(error.Overflow, divFloor(i8, -128, -1));
729729
730 testing.expect((divFloor(f32, 5.0, 3.0) catch unreachable) == 1.0);730 try testing.expect((divFloor(f32, 5.0, 3.0) catch unreachable) == 1.0);
731 testing.expect((divFloor(f32, -5.0, 3.0) catch unreachable) == -2.0);731 try testing.expect((divFloor(f32, -5.0, 3.0) catch unreachable) == -2.0);
732}732}
733733
734pub fn divCeil(comptime T: type, numerator: T, denominator: T) !T {734pub fn divCeil(comptime T: type, numerator: T, denominator: T) !T {
...@@ -752,36 +752,36 @@ pub fn divCeil(comptime T: type, numerator: T, denominator: T) !T {...@@ -752,36 +752,36 @@ pub fn divCeil(comptime T: type, numerator: T, denominator: T) !T {
752}752}
753753
754test "math.divCeil" {754test "math.divCeil" {
755 testDivCeil();755 try testDivCeil();
756 comptime testDivCeil();756 comptime try testDivCeil();
757}757}
758fn testDivCeil() void {758fn testDivCeil() !void {
759 testing.expectEqual(@as(i32, 2), divCeil(i32, 5, 3) catch unreachable);759 try testing.expectEqual(@as(i32, 2), divCeil(i32, 5, 3) catch unreachable);
760 testing.expectEqual(@as(i32, -1), divCeil(i32, -5, 3) catch unreachable);760 try testing.expectEqual(@as(i32, -1), divCeil(i32, -5, 3) catch unreachable);
761 testing.expectEqual(@as(i32, -1), divCeil(i32, 5, -3) catch unreachable);761 try testing.expectEqual(@as(i32, -1), divCeil(i32, 5, -3) catch unreachable);
762 testing.expectEqual(@as(i32, 2), divCeil(i32, -5, -3) catch unreachable);762 try testing.expectEqual(@as(i32, 2), divCeil(i32, -5, -3) catch unreachable);
763 testing.expectEqual(@as(i32, 0), divCeil(i32, 0, 5) catch unreachable);763 try testing.expectEqual(@as(i32, 0), divCeil(i32, 0, 5) catch unreachable);
764 testing.expectEqual(@as(u32, 0), divCeil(u32, 0, 5) catch unreachable);764 try testing.expectEqual(@as(u32, 0), divCeil(u32, 0, 5) catch unreachable);
765 testing.expectError(error.DivisionByZero, divCeil(i8, -5, 0));765 try testing.expectError(error.DivisionByZero, divCeil(i8, -5, 0));
766 testing.expectError(error.Overflow, divCeil(i8, -128, -1));766 try testing.expectError(error.Overflow, divCeil(i8, -128, -1));
767767
768 testing.expectEqual(@as(f32, 0.0), divCeil(f32, 0.0, 5.0) catch unreachable);768 try testing.expectEqual(@as(f32, 0.0), divCeil(f32, 0.0, 5.0) catch unreachable);
769 testing.expectEqual(@as(f32, 2.0), divCeil(f32, 5.0, 3.0) catch unreachable);769 try testing.expectEqual(@as(f32, 2.0), divCeil(f32, 5.0, 3.0) catch unreachable);
770 testing.expectEqual(@as(f32, -1.0), divCeil(f32, -5.0, 3.0) catch unreachable);770 try testing.expectEqual(@as(f32, -1.0), divCeil(f32, -5.0, 3.0) catch unreachable);
771 testing.expectEqual(@as(f32, -1.0), divCeil(f32, 5.0, -3.0) catch unreachable);771 try testing.expectEqual(@as(f32, -1.0), divCeil(f32, 5.0, -3.0) catch unreachable);
772 testing.expectEqual(@as(f32, 2.0), divCeil(f32, -5.0, -3.0) catch unreachable);772 try testing.expectEqual(@as(f32, 2.0), divCeil(f32, -5.0, -3.0) catch unreachable);
773773
774 testing.expectEqual(6, divCeil(comptime_int, 23, 4) catch unreachable);774 try testing.expectEqual(6, divCeil(comptime_int, 23, 4) catch unreachable);
775 testing.expectEqual(-5, divCeil(comptime_int, -23, 4) catch unreachable);775 try testing.expectEqual(-5, divCeil(comptime_int, -23, 4) catch unreachable);
776 testing.expectEqual(-5, divCeil(comptime_int, 23, -4) catch unreachable);776 try testing.expectEqual(-5, divCeil(comptime_int, 23, -4) catch unreachable);
777 testing.expectEqual(6, divCeil(comptime_int, -23, -4) catch unreachable);777 try testing.expectEqual(6, divCeil(comptime_int, -23, -4) catch unreachable);
778 testing.expectError(error.DivisionByZero, divCeil(comptime_int, 23, 0));778 try testing.expectError(error.DivisionByZero, divCeil(comptime_int, 23, 0));
779779
780 testing.expectEqual(6.0, divCeil(comptime_float, 23.0, 4.0) catch unreachable);780 try testing.expectEqual(6.0, divCeil(comptime_float, 23.0, 4.0) catch unreachable);
781 testing.expectEqual(-5.0, divCeil(comptime_float, -23.0, 4.0) catch unreachable);781 try testing.expectEqual(-5.0, divCeil(comptime_float, -23.0, 4.0) catch unreachable);
782 testing.expectEqual(-5.0, divCeil(comptime_float, 23.0, -4.0) catch unreachable);782 try testing.expectEqual(-5.0, divCeil(comptime_float, 23.0, -4.0) catch unreachable);
783 testing.expectEqual(6.0, divCeil(comptime_float, -23.0, -4.0) catch unreachable);783 try testing.expectEqual(6.0, divCeil(comptime_float, -23.0, -4.0) catch unreachable);
784 testing.expectError(error.DivisionByZero, divCeil(comptime_float, 23.0, 0.0));784 try testing.expectError(error.DivisionByZero, divCeil(comptime_float, 23.0, 0.0));
785}785}
786786
787pub fn divExact(comptime T: type, numerator: T, denominator: T) !T {787pub fn divExact(comptime T: type, numerator: T, denominator: T) !T {
...@@ -794,19 +794,19 @@ pub fn divExact(comptime T: type, numerator: T, denominator: T) !T {...@@ -794,19 +794,19 @@ pub fn divExact(comptime T: type, numerator: T, denominator: T) !T {
794}794}
795795
796test "math.divExact" {796test "math.divExact" {
797 testDivExact();797 try testDivExact();
798 comptime testDivExact();798 comptime try testDivExact();
799}799}
800fn testDivExact() void {800fn testDivExact() !void {
801 testing.expect((divExact(i32, 10, 5) catch unreachable) == 2);801 try testing.expect((divExact(i32, 10, 5) catch unreachable) == 2);
802 testing.expect((divExact(i32, -10, 5) catch unreachable) == -2);802 try testing.expect((divExact(i32, -10, 5) catch unreachable) == -2);
803 testing.expectError(error.DivisionByZero, divExact(i8, -5, 0));803 try testing.expectError(error.DivisionByZero, divExact(i8, -5, 0));
804 testing.expectError(error.Overflow, divExact(i8, -128, -1));804 try testing.expectError(error.Overflow, divExact(i8, -128, -1));
805 testing.expectError(error.UnexpectedRemainder, divExact(i32, 5, 2));805 try testing.expectError(error.UnexpectedRemainder, divExact(i32, 5, 2));
806806
807 testing.expect((divExact(f32, 10.0, 5.0) catch unreachable) == 2.0);807 try testing.expect((divExact(f32, 10.0, 5.0) catch unreachable) == 2.0);
808 testing.expect((divExact(f32, -10.0, 5.0) catch unreachable) == -2.0);808 try testing.expect((divExact(f32, -10.0, 5.0) catch unreachable) == -2.0);
809 testing.expectError(error.UnexpectedRemainder, divExact(f32, 5.0, 2.0));809 try testing.expectError(error.UnexpectedRemainder, divExact(f32, 5.0, 2.0));
810}810}
811811
812pub fn mod(comptime T: type, numerator: T, denominator: T) !T {812pub fn mod(comptime T: type, numerator: T, denominator: T) !T {
...@@ -817,19 +817,19 @@ pub fn mod(comptime T: type, numerator: T, denominator: T) !T {...@@ -817,19 +817,19 @@ pub fn mod(comptime T: type, numerator: T, denominator: T) !T {
817}817}
818818
819test "math.mod" {819test "math.mod" {
820 testMod();820 try testMod();
821 comptime testMod();821 comptime try testMod();
822}822}
823fn testMod() void {823fn testMod() !void {
824 testing.expect((mod(i32, -5, 3) catch unreachable) == 1);824 try testing.expect((mod(i32, -5, 3) catch unreachable) == 1);
825 testing.expect((mod(i32, 5, 3) catch unreachable) == 2);825 try testing.expect((mod(i32, 5, 3) catch unreachable) == 2);
826 testing.expectError(error.NegativeDenominator, mod(i32, 10, -1));826 try testing.expectError(error.NegativeDenominator, mod(i32, 10, -1));
827 testing.expectError(error.DivisionByZero, mod(i32, 10, 0));827 try testing.expectError(error.DivisionByZero, mod(i32, 10, 0));
828828
829 testing.expect((mod(f32, -5, 3) catch unreachable) == 1);829 try testing.expect((mod(f32, -5, 3) catch unreachable) == 1);
830 testing.expect((mod(f32, 5, 3) catch unreachable) == 2);830 try testing.expect((mod(f32, 5, 3) catch unreachable) == 2);
831 testing.expectError(error.NegativeDenominator, mod(f32, 10, -1));831 try testing.expectError(error.NegativeDenominator, mod(f32, 10, -1));
832 testing.expectError(error.DivisionByZero, mod(f32, 10, 0));832 try testing.expectError(error.DivisionByZero, mod(f32, 10, 0));
833}833}
834834
835pub fn rem(comptime T: type, numerator: T, denominator: T) !T {835pub fn rem(comptime T: type, numerator: T, denominator: T) !T {
...@@ -840,19 +840,19 @@ pub fn rem(comptime T: type, numerator: T, denominator: T) !T {...@@ -840,19 +840,19 @@ pub fn rem(comptime T: type, numerator: T, denominator: T) !T {
840}840}
841841
842test "math.rem" {842test "math.rem" {
843 testRem();843 try testRem();
844 comptime testRem();844 comptime try testRem();
845}845}
846fn testRem() void {846fn testRem() !void {
847 testing.expect((rem(i32, -5, 3) catch unreachable) == -2);847 try testing.expect((rem(i32, -5, 3) catch unreachable) == -2);
848 testing.expect((rem(i32, 5, 3) catch unreachable) == 2);848 try testing.expect((rem(i32, 5, 3) catch unreachable) == 2);
849 testing.expectError(error.NegativeDenominator, rem(i32, 10, -1));849 try testing.expectError(error.NegativeDenominator, rem(i32, 10, -1));
850 testing.expectError(error.DivisionByZero, rem(i32, 10, 0));850 try testing.expectError(error.DivisionByZero, rem(i32, 10, 0));
851851
852 testing.expect((rem(f32, -5, 3) catch unreachable) == -2);852 try testing.expect((rem(f32, -5, 3) catch unreachable) == -2);
853 testing.expect((rem(f32, 5, 3) catch unreachable) == 2);853 try testing.expect((rem(f32, 5, 3) catch unreachable) == 2);
854 testing.expectError(error.NegativeDenominator, rem(f32, 10, -1));854 try testing.expectError(error.NegativeDenominator, rem(f32, 10, -1));
855 testing.expectError(error.DivisionByZero, rem(f32, 10, 0));855 try testing.expectError(error.DivisionByZero, rem(f32, 10, 0));
856}856}
857857
858/// Returns the absolute value of the integer parameter.858/// Returns the absolute value of the integer parameter.
...@@ -883,11 +883,11 @@ pub fn absCast(x: anytype) switch (@typeInfo(@TypeOf(x))) {...@@ -883,11 +883,11 @@ pub fn absCast(x: anytype) switch (@typeInfo(@TypeOf(x))) {
883}883}
884884
885test "math.absCast" {885test "math.absCast" {
886 testing.expectEqual(@as(u1, 1), absCast(@as(i1, -1)));886 try testing.expectEqual(@as(u1, 1), absCast(@as(i1, -1)));
887 testing.expectEqual(@as(u32, 999), absCast(@as(i32, -999)));887 try testing.expectEqual(@as(u32, 999), absCast(@as(i32, -999)));
888 testing.expectEqual(@as(u32, 999), absCast(@as(i32, 999)));888 try testing.expectEqual(@as(u32, 999), absCast(@as(i32, 999)));
889 testing.expectEqual(@as(u32, -minInt(i32)), absCast(@as(i32, minInt(i32))));889 try testing.expectEqual(@as(u32, -minInt(i32)), absCast(@as(i32, minInt(i32))));
890 testing.expectEqual(999, absCast(-999));890 try testing.expectEqual(999, absCast(-999));
891}891}
892892
893/// Returns the negation of the integer parameter.893/// Returns the negation of the integer parameter.
...@@ -904,13 +904,13 @@ pub fn negateCast(x: anytype) !std.meta.Int(.signed, std.meta.bitCount(@TypeOf(x...@@ -904,13 +904,13 @@ pub fn negateCast(x: anytype) !std.meta.Int(.signed, std.meta.bitCount(@TypeOf(x
904}904}
905905
906test "math.negateCast" {906test "math.negateCast" {
907 testing.expect((negateCast(@as(u32, 999)) catch unreachable) == -999);907 try testing.expect((negateCast(@as(u32, 999)) catch unreachable) == -999);
908 testing.expect(@TypeOf(negateCast(@as(u32, 999)) catch unreachable) == i32);908 try testing.expect(@TypeOf(negateCast(@as(u32, 999)) catch unreachable) == i32);
909909
910 testing.expect((negateCast(@as(u32, -minInt(i32))) catch unreachable) == minInt(i32));910 try testing.expect((negateCast(@as(u32, -minInt(i32))) catch unreachable) == minInt(i32));
911 testing.expect(@TypeOf(negateCast(@as(u32, -minInt(i32))) catch unreachable) == i32);911 try testing.expect(@TypeOf(negateCast(@as(u32, -minInt(i32))) catch unreachable) == i32);
912912
913 testing.expectError(error.Overflow, negateCast(@as(u32, maxInt(i32) + 10)));913 try testing.expectError(error.Overflow, negateCast(@as(u32, maxInt(i32) + 10)));
914}914}
915915
916/// Cast an integer to a different integer type. If the value doesn't fit,916/// Cast an integer to a different integer type. If the value doesn't fit,
...@@ -929,13 +929,13 @@ pub fn cast(comptime T: type, x: anytype) (error{Overflow}!T) {...@@ -929,13 +929,13 @@ pub fn cast(comptime T: type, x: anytype) (error{Overflow}!T) {
929}929}
930930
931test "math.cast" {931test "math.cast" {
932 testing.expectError(error.Overflow, cast(u8, @as(u32, 300)));932 try testing.expectError(error.Overflow, cast(u8, @as(u32, 300)));
933 testing.expectError(error.Overflow, cast(i8, @as(i32, -200)));933 try testing.expectError(error.Overflow, cast(i8, @as(i32, -200)));
934 testing.expectError(error.Overflow, cast(u8, @as(i8, -1)));934 try testing.expectError(error.Overflow, cast(u8, @as(i8, -1)));
935 testing.expectError(error.Overflow, cast(u64, @as(i8, -1)));935 try testing.expectError(error.Overflow, cast(u64, @as(i8, -1)));
936936
937 testing.expect((try cast(u8, @as(u32, 255))) == @as(u8, 255));937 try testing.expect((try cast(u8, @as(u32, 255))) == @as(u8, 255));
938 testing.expect(@TypeOf(try cast(u8, @as(u32, 255))) == u8);938 try testing.expect(@TypeOf(try cast(u8, @as(u32, 255))) == u8);
939}939}
940940
941pub const AlignCastError = error{UnalignedMemory};941pub const AlignCastError = error{UnalignedMemory};
...@@ -966,17 +966,17 @@ pub fn floorPowerOfTwo(comptime T: type, value: T) T {...@@ -966,17 +966,17 @@ pub fn floorPowerOfTwo(comptime T: type, value: T) T {
966}966}
967967
968test "math.floorPowerOfTwo" {968test "math.floorPowerOfTwo" {
969 testFloorPowerOfTwo();969 try testFloorPowerOfTwo();
970 comptime testFloorPowerOfTwo();970 comptime try testFloorPowerOfTwo();
971}971}
972972
973fn testFloorPowerOfTwo() void {973fn testFloorPowerOfTwo() !void {
974 testing.expect(floorPowerOfTwo(u32, 63) == 32);974 try testing.expect(floorPowerOfTwo(u32, 63) == 32);
975 testing.expect(floorPowerOfTwo(u32, 64) == 64);975 try testing.expect(floorPowerOfTwo(u32, 64) == 64);
976 testing.expect(floorPowerOfTwo(u32, 65) == 64);976 try testing.expect(floorPowerOfTwo(u32, 65) == 64);
977 testing.expect(floorPowerOfTwo(u4, 7) == 4);977 try testing.expect(floorPowerOfTwo(u4, 7) == 4);
978 testing.expect(floorPowerOfTwo(u4, 8) == 8);978 try testing.expect(floorPowerOfTwo(u4, 8) == 8);
979 testing.expect(floorPowerOfTwo(u4, 9) == 8);979 try testing.expect(floorPowerOfTwo(u4, 9) == 8);
980}980}
981981
982/// Returns the next power of two (if the value is not already a power of two).982/// Returns the next power of two (if the value is not already a power of two).
...@@ -1012,20 +1012,20 @@ pub fn ceilPowerOfTwoAssert(comptime T: type, value: T) T {...@@ -1012,20 +1012,20 @@ pub fn ceilPowerOfTwoAssert(comptime T: type, value: T) T {
1012}1012}
10131013
1014test "math.ceilPowerOfTwoPromote" {1014test "math.ceilPowerOfTwoPromote" {
1015 testCeilPowerOfTwoPromote();1015 try testCeilPowerOfTwoPromote();
1016 comptime testCeilPowerOfTwoPromote();1016 comptime try testCeilPowerOfTwoPromote();
1017}1017}
10181018
1019fn testCeilPowerOfTwoPromote() void {1019fn testCeilPowerOfTwoPromote() !void {
1020 testing.expectEqual(@as(u33, 1), ceilPowerOfTwoPromote(u32, 1));1020 try testing.expectEqual(@as(u33, 1), ceilPowerOfTwoPromote(u32, 1));
1021 testing.expectEqual(@as(u33, 2), ceilPowerOfTwoPromote(u32, 2));1021 try testing.expectEqual(@as(u33, 2), ceilPowerOfTwoPromote(u32, 2));
1022 testing.expectEqual(@as(u33, 64), ceilPowerOfTwoPromote(u32, 63));1022 try testing.expectEqual(@as(u33, 64), ceilPowerOfTwoPromote(u32, 63));
1023 testing.expectEqual(@as(u33, 64), ceilPowerOfTwoPromote(u32, 64));1023 try testing.expectEqual(@as(u33, 64), ceilPowerOfTwoPromote(u32, 64));
1024 testing.expectEqual(@as(u33, 128), ceilPowerOfTwoPromote(u32, 65));1024 try testing.expectEqual(@as(u33, 128), ceilPowerOfTwoPromote(u32, 65));
1025 testing.expectEqual(@as(u6, 8), ceilPowerOfTwoPromote(u5, 7));1025 try testing.expectEqual(@as(u6, 8), ceilPowerOfTwoPromote(u5, 7));
1026 testing.expectEqual(@as(u6, 8), ceilPowerOfTwoPromote(u5, 8));1026 try testing.expectEqual(@as(u6, 8), ceilPowerOfTwoPromote(u5, 8));
1027 testing.expectEqual(@as(u6, 16), ceilPowerOfTwoPromote(u5, 9));1027 try testing.expectEqual(@as(u6, 16), ceilPowerOfTwoPromote(u5, 9));
1028 testing.expectEqual(@as(u5, 16), ceilPowerOfTwoPromote(u4, 9));1028 try testing.expectEqual(@as(u5, 16), ceilPowerOfTwoPromote(u4, 9));
1029}1029}
10301030
1031test "math.ceilPowerOfTwo" {1031test "math.ceilPowerOfTwo" {
...@@ -1034,15 +1034,15 @@ test "math.ceilPowerOfTwo" {...@@ -1034,15 +1034,15 @@ test "math.ceilPowerOfTwo" {
1034}1034}
10351035
1036fn testCeilPowerOfTwo() !void {1036fn testCeilPowerOfTwo() !void {
1037 testing.expectEqual(@as(u32, 1), try ceilPowerOfTwo(u32, 1));1037 try testing.expectEqual(@as(u32, 1), try ceilPowerOfTwo(u32, 1));
1038 testing.expectEqual(@as(u32, 2), try ceilPowerOfTwo(u32, 2));1038 try testing.expectEqual(@as(u32, 2), try ceilPowerOfTwo(u32, 2));
1039 testing.expectEqual(@as(u32, 64), try ceilPowerOfTwo(u32, 63));1039 try testing.expectEqual(@as(u32, 64), try ceilPowerOfTwo(u32, 63));
1040 testing.expectEqual(@as(u32, 64), try ceilPowerOfTwo(u32, 64));1040 try testing.expectEqual(@as(u32, 64), try ceilPowerOfTwo(u32, 64));
1041 testing.expectEqual(@as(u32, 128), try ceilPowerOfTwo(u32, 65));1041 try testing.expectEqual(@as(u32, 128), try ceilPowerOfTwo(u32, 65));
1042 testing.expectEqual(@as(u5, 8), try ceilPowerOfTwo(u5, 7));1042 try testing.expectEqual(@as(u5, 8), try ceilPowerOfTwo(u5, 7));
1043 testing.expectEqual(@as(u5, 8), try ceilPowerOfTwo(u5, 8));1043 try testing.expectEqual(@as(u5, 8), try ceilPowerOfTwo(u5, 8));
1044 testing.expectEqual(@as(u5, 16), try ceilPowerOfTwo(u5, 9));1044 try testing.expectEqual(@as(u5, 16), try ceilPowerOfTwo(u5, 9));
1045 testing.expectError(error.Overflow, ceilPowerOfTwo(u4, 9));1045 try testing.expectError(error.Overflow, ceilPowerOfTwo(u4, 9));
1046}1046}
10471047
1048pub fn log2_int(comptime T: type, x: T) Log2Int(T) {1048pub fn log2_int(comptime T: type, x: T) Log2Int(T) {
...@@ -1059,16 +1059,16 @@ pub fn log2_int_ceil(comptime T: type, x: T) Log2Int(T) {...@@ -1059,16 +1059,16 @@ pub fn log2_int_ceil(comptime T: type, x: T) Log2Int(T) {
1059}1059}
10601060
1061test "std.math.log2_int_ceil" {1061test "std.math.log2_int_ceil" {
1062 testing.expect(log2_int_ceil(u32, 1) == 0);1062 try testing.expect(log2_int_ceil(u32, 1) == 0);
1063 testing.expect(log2_int_ceil(u32, 2) == 1);1063 try testing.expect(log2_int_ceil(u32, 2) == 1);
1064 testing.expect(log2_int_ceil(u32, 3) == 2);1064 try testing.expect(log2_int_ceil(u32, 3) == 2);
1065 testing.expect(log2_int_ceil(u32, 4) == 2);1065 try testing.expect(log2_int_ceil(u32, 4) == 2);
1066 testing.expect(log2_int_ceil(u32, 5) == 3);1066 try testing.expect(log2_int_ceil(u32, 5) == 3);
1067 testing.expect(log2_int_ceil(u32, 6) == 3);1067 try testing.expect(log2_int_ceil(u32, 6) == 3);
1068 testing.expect(log2_int_ceil(u32, 7) == 3);1068 try testing.expect(log2_int_ceil(u32, 7) == 3);
1069 testing.expect(log2_int_ceil(u32, 8) == 3);1069 try testing.expect(log2_int_ceil(u32, 8) == 3);
1070 testing.expect(log2_int_ceil(u32, 9) == 4);1070 try testing.expect(log2_int_ceil(u32, 9) == 4);
1071 testing.expect(log2_int_ceil(u32, 10) == 4);1071 try testing.expect(log2_int_ceil(u32, 10) == 4);
1072}1072}
10731073
1074///Cast a value to a different type. If the value doesn't fit in, or can't be perfectly represented by,1074///Cast a value to a different type. If the value doesn't fit in, or can't be perfectly represented by,
...@@ -1112,15 +1112,15 @@ pub fn lossyCast(comptime T: type, value: anytype) T {...@@ -1112,15 +1112,15 @@ pub fn lossyCast(comptime T: type, value: anytype) T {
1112}1112}
11131113
1114test "math.lossyCast" {1114test "math.lossyCast" {
1115 testing.expect(lossyCast(i16, 70000.0) == @as(i16, 32767));1115 try testing.expect(lossyCast(i16, 70000.0) == @as(i16, 32767));
1116 testing.expect(lossyCast(u32, @as(i16, -255)) == @as(u32, 0));1116 try testing.expect(lossyCast(u32, @as(i16, -255)) == @as(u32, 0));
1117 testing.expect(lossyCast(i9, @as(u32, 200)) == @as(i9, 200));1117 try testing.expect(lossyCast(i9, @as(u32, 200)) == @as(i9, 200));
1118}1118}
11191119
1120test "math.f64_min" {1120test "math.f64_min" {
1121 const f64_min_u64 = 0x0010000000000000;1121 const f64_min_u64 = 0x0010000000000000;
1122 const fmin: f64 = f64_min;1122 const fmin: f64 = f64_min;
1123 testing.expect(@bitCast(u64, fmin) == f64_min_u64);1123 try testing.expect(@bitCast(u64, fmin) == f64_min_u64);
1124}1124}
11251125
1126pub fn maxInt(comptime T: type) comptime_int {1126pub fn maxInt(comptime T: type) comptime_int {
...@@ -1139,45 +1139,45 @@ pub fn minInt(comptime T: type) comptime_int {...@@ -1139,45 +1139,45 @@ pub fn minInt(comptime T: type) comptime_int {
1139}1139}
11401140
1141test "minInt and maxInt" {1141test "minInt and maxInt" {
1142 testing.expect(maxInt(u0) == 0);1142 try testing.expect(maxInt(u0) == 0);
1143 testing.expect(maxInt(u1) == 1);1143 try testing.expect(maxInt(u1) == 1);
1144 testing.expect(maxInt(u8) == 255);1144 try testing.expect(maxInt(u8) == 255);
1145 testing.expect(maxInt(u16) == 65535);1145 try testing.expect(maxInt(u16) == 65535);
1146 testing.expect(maxInt(u32) == 4294967295);1146 try testing.expect(maxInt(u32) == 4294967295);
1147 testing.expect(maxInt(u64) == 18446744073709551615);1147 try testing.expect(maxInt(u64) == 18446744073709551615);
1148 testing.expect(maxInt(u128) == 340282366920938463463374607431768211455);1148 try testing.expect(maxInt(u128) == 340282366920938463463374607431768211455);
11491149
1150 testing.expect(maxInt(i0) == 0);1150 try testing.expect(maxInt(i0) == 0);
1151 testing.expect(maxInt(i1) == 0);1151 try testing.expect(maxInt(i1) == 0);
1152 testing.expect(maxInt(i8) == 127);1152 try testing.expect(maxInt(i8) == 127);
1153 testing.expect(maxInt(i16) == 32767);1153 try testing.expect(maxInt(i16) == 32767);
1154 testing.expect(maxInt(i32) == 2147483647);1154 try testing.expect(maxInt(i32) == 2147483647);
1155 testing.expect(maxInt(i63) == 4611686018427387903);1155 try testing.expect(maxInt(i63) == 4611686018427387903);
1156 testing.expect(maxInt(i64) == 9223372036854775807);1156 try testing.expect(maxInt(i64) == 9223372036854775807);
1157 testing.expect(maxInt(i128) == 170141183460469231731687303715884105727);1157 try testing.expect(maxInt(i128) == 170141183460469231731687303715884105727);
11581158
1159 testing.expect(minInt(u0) == 0);1159 try testing.expect(minInt(u0) == 0);
1160 testing.expect(minInt(u1) == 0);1160 try testing.expect(minInt(u1) == 0);
1161 testing.expect(minInt(u8) == 0);1161 try testing.expect(minInt(u8) == 0);
1162 testing.expect(minInt(u16) == 0);1162 try testing.expect(minInt(u16) == 0);
1163 testing.expect(minInt(u32) == 0);1163 try testing.expect(minInt(u32) == 0);
1164 testing.expect(minInt(u63) == 0);1164 try testing.expect(minInt(u63) == 0);
1165 testing.expect(minInt(u64) == 0);1165 try testing.expect(minInt(u64) == 0);
1166 testing.expect(minInt(u128) == 0);1166 try testing.expect(minInt(u128) == 0);
11671167
1168 testing.expect(minInt(i0) == 0);1168 try testing.expect(minInt(i0) == 0);
1169 testing.expect(minInt(i1) == -1);1169 try testing.expect(minInt(i1) == -1);
1170 testing.expect(minInt(i8) == -128);1170 try testing.expect(minInt(i8) == -128);
1171 testing.expect(minInt(i16) == -32768);1171 try testing.expect(minInt(i16) == -32768);
1172 testing.expect(minInt(i32) == -2147483648);1172 try testing.expect(minInt(i32) == -2147483648);
1173 testing.expect(minInt(i63) == -4611686018427387904);1173 try testing.expect(minInt(i63) == -4611686018427387904);
1174 testing.expect(minInt(i64) == -9223372036854775808);1174 try testing.expect(minInt(i64) == -9223372036854775808);
1175 testing.expect(minInt(i128) == -170141183460469231731687303715884105728);1175 try testing.expect(minInt(i128) == -170141183460469231731687303715884105728);
1176}1176}
11771177
1178test "max value type" {1178test "max value type" {
1179 const x: u32 = maxInt(i32);1179 const x: u32 = maxInt(i32);
1180 testing.expect(x == 2147483647);1180 try testing.expect(x == 2147483647);
1181}1181}
11821182
1183pub fn mulWide(comptime T: type, a: T, b: T) std.meta.Int(@typeInfo(T).Int.signedness, @typeInfo(T).Int.bits * 2) {1183pub fn mulWide(comptime T: type, a: T, b: T) std.meta.Int(@typeInfo(T).Int.signedness, @typeInfo(T).Int.bits * 2) {
...@@ -1186,9 +1186,9 @@ pub fn mulWide(comptime T: type, a: T, b: T) std.meta.Int(@typeInfo(T).Int.signe...@@ -1186,9 +1186,9 @@ pub fn mulWide(comptime T: type, a: T, b: T) std.meta.Int(@typeInfo(T).Int.signe
1186}1186}
11871187
1188test "math.mulWide" {1188test "math.mulWide" {
1189 testing.expect(mulWide(u8, 5, 5) == 25);1189 try testing.expect(mulWide(u8, 5, 5) == 25);
1190 testing.expect(mulWide(i8, 5, -5) == -25);1190 try testing.expect(mulWide(i8, 5, -5) == -25);
1191 testing.expect(mulWide(u8, 100, 100) == 10000);1191 try testing.expect(mulWide(u8, 100, 100) == 10000);
1192}1192}
11931193
1194/// See also `CompareOperator`.1194/// See also `CompareOperator`.
...@@ -1284,51 +1284,51 @@ pub fn compare(a: anytype, op: CompareOperator, b: anytype) bool {...@@ -1284,51 +1284,51 @@ pub fn compare(a: anytype, op: CompareOperator, b: anytype) bool {
1284}1284}
12851285
1286test "compare between signed and unsigned" {1286test "compare between signed and unsigned" {
1287 testing.expect(compare(@as(i8, -1), .lt, @as(u8, 255)));1287 try testing.expect(compare(@as(i8, -1), .lt, @as(u8, 255)));
1288 testing.expect(compare(@as(i8, 2), .gt, @as(u8, 1)));1288 try testing.expect(compare(@as(i8, 2), .gt, @as(u8, 1)));
1289 testing.expect(!compare(@as(i8, -1), .gte, @as(u8, 255)));1289 try testing.expect(!compare(@as(i8, -1), .gte, @as(u8, 255)));
1290 testing.expect(compare(@as(u8, 255), .gt, @as(i8, -1)));1290 try testing.expect(compare(@as(u8, 255), .gt, @as(i8, -1)));
1291 testing.expect(!compare(@as(u8, 255), .lte, @as(i8, -1)));1291 try testing.expect(!compare(@as(u8, 255), .lte, @as(i8, -1)));
1292 testing.expect(compare(@as(i8, -1), .lt, @as(u9, 255)));1292 try testing.expect(compare(@as(i8, -1), .lt, @as(u9, 255)));
1293 testing.expect(!compare(@as(i8, -1), .gte, @as(u9, 255)));1293 try testing.expect(!compare(@as(i8, -1), .gte, @as(u9, 255)));
1294 testing.expect(compare(@as(u9, 255), .gt, @as(i8, -1)));1294 try testing.expect(compare(@as(u9, 255), .gt, @as(i8, -1)));
1295 testing.expect(!compare(@as(u9, 255), .lte, @as(i8, -1)));1295 try testing.expect(!compare(@as(u9, 255), .lte, @as(i8, -1)));
1296 testing.expect(compare(@as(i9, -1), .lt, @as(u8, 255)));1296 try testing.expect(compare(@as(i9, -1), .lt, @as(u8, 255)));
1297 testing.expect(!compare(@as(i9, -1), .gte, @as(u8, 255)));1297 try testing.expect(!compare(@as(i9, -1), .gte, @as(u8, 255)));
1298 testing.expect(compare(@as(u8, 255), .gt, @as(i9, -1)));1298 try testing.expect(compare(@as(u8, 255), .gt, @as(i9, -1)));
1299 testing.expect(!compare(@as(u8, 255), .lte, @as(i9, -1)));1299 try testing.expect(!compare(@as(u8, 255), .lte, @as(i9, -1)));
1300 testing.expect(compare(@as(u8, 1), .lt, @as(u8, 2)));1300 try testing.expect(compare(@as(u8, 1), .lt, @as(u8, 2)));
1301 testing.expect(@bitCast(u8, @as(i8, -1)) == @as(u8, 255));1301 try testing.expect(@bitCast(u8, @as(i8, -1)) == @as(u8, 255));
1302 testing.expect(!compare(@as(u8, 255), .eq, @as(i8, -1)));1302 try testing.expect(!compare(@as(u8, 255), .eq, @as(i8, -1)));
1303 testing.expect(compare(@as(u8, 1), .eq, @as(u8, 1)));1303 try testing.expect(compare(@as(u8, 1), .eq, @as(u8, 1)));
1304}1304}
13051305
1306test "order" {1306test "order" {
1307 testing.expect(order(0, 0) == .eq);1307 try testing.expect(order(0, 0) == .eq);
1308 testing.expect(order(1, 0) == .gt);1308 try testing.expect(order(1, 0) == .gt);
1309 testing.expect(order(-1, 0) == .lt);1309 try testing.expect(order(-1, 0) == .lt);
1310}1310}
13111311
1312test "order.invert" {1312test "order.invert" {
1313 testing.expect(Order.invert(order(0, 0)) == .eq);1313 try testing.expect(Order.invert(order(0, 0)) == .eq);
1314 testing.expect(Order.invert(order(1, 0)) == .lt);1314 try testing.expect(Order.invert(order(1, 0)) == .lt);
1315 testing.expect(Order.invert(order(-1, 0)) == .gt);1315 try testing.expect(Order.invert(order(-1, 0)) == .gt);
1316}1316}
13171317
1318test "order.compare" {1318test "order.compare" {
1319 testing.expect(order(-1, 0).compare(.lt));1319 try testing.expect(order(-1, 0).compare(.lt));
1320 testing.expect(order(-1, 0).compare(.lte));1320 try testing.expect(order(-1, 0).compare(.lte));
1321 testing.expect(order(0, 0).compare(.lte));1321 try testing.expect(order(0, 0).compare(.lte));
1322 testing.expect(order(0, 0).compare(.eq));1322 try testing.expect(order(0, 0).compare(.eq));
1323 testing.expect(order(0, 0).compare(.gte));1323 try testing.expect(order(0, 0).compare(.gte));
1324 testing.expect(order(1, 0).compare(.gte));1324 try testing.expect(order(1, 0).compare(.gte));
1325 testing.expect(order(1, 0).compare(.gt));1325 try testing.expect(order(1, 0).compare(.gt));
1326 testing.expect(order(1, 0).compare(.neq));1326 try testing.expect(order(1, 0).compare(.neq));
1327}1327}
13281328
1329test "math.comptime" {1329test "math.comptime" {
1330 comptime const v = sin(@as(f32, 1)) + ln(@as(f32, 5));1330 comptime const v = sin(@as(f32, 1)) + ln(@as(f32, 5));
1331 testing.expect(v == sin(@as(f32, 1)) + ln(@as(f32, 5)));1331 try testing.expect(v == sin(@as(f32, 1)) + ln(@as(f32, 5)));
1332}1332}
13331333
1334/// Returns a mask of all ones if value is true,1334/// Returns a mask of all ones if value is true,
...@@ -1354,26 +1354,26 @@ pub fn boolMask(comptime MaskInt: type, value: bool) callconv(.Inline) MaskInt {...@@ -1354,26 +1354,26 @@ pub fn boolMask(comptime MaskInt: type, value: bool) callconv(.Inline) MaskInt {
13541354
1355test "boolMask" {1355test "boolMask" {
1356 const runTest = struct {1356 const runTest = struct {
1357 fn runTest() void {1357 fn runTest() !void {
1358 testing.expectEqual(@as(u1, 0), boolMask(u1, false));1358 try testing.expectEqual(@as(u1, 0), boolMask(u1, false));
1359 testing.expectEqual(@as(u1, 1), boolMask(u1, true));1359 try testing.expectEqual(@as(u1, 1), boolMask(u1, true));
13601360
1361 testing.expectEqual(@as(i1, 0), boolMask(i1, false));1361 try testing.expectEqual(@as(i1, 0), boolMask(i1, false));
1362 testing.expectEqual(@as(i1, -1), boolMask(i1, true));1362 try testing.expectEqual(@as(i1, -1), boolMask(i1, true));
13631363
1364 testing.expectEqual(@as(u13, 0), boolMask(u13, false));1364 try testing.expectEqual(@as(u13, 0), boolMask(u13, false));
1365 testing.expectEqual(@as(u13, 0x1FFF), boolMask(u13, true));1365 try testing.expectEqual(@as(u13, 0x1FFF), boolMask(u13, true));
13661366
1367 testing.expectEqual(@as(i13, 0), boolMask(i13, false));1367 try testing.expectEqual(@as(i13, 0), boolMask(i13, false));
1368 testing.expectEqual(@as(i13, -1), boolMask(i13, true));1368 try testing.expectEqual(@as(i13, -1), boolMask(i13, true));
13691369
1370 testing.expectEqual(@as(u32, 0), boolMask(u32, false));1370 try testing.expectEqual(@as(u32, 0), boolMask(u32, false));
1371 testing.expectEqual(@as(u32, 0xFFFF_FFFF), boolMask(u32, true));1371 try testing.expectEqual(@as(u32, 0xFFFF_FFFF), boolMask(u32, true));
13721372
1373 testing.expectEqual(@as(i32, 0), boolMask(i32, false));1373 try testing.expectEqual(@as(i32, 0), boolMask(i32, false));
1374 testing.expectEqual(@as(i32, -1), boolMask(i32, true));1374 try testing.expectEqual(@as(i32, -1), boolMask(i32, true));
1375 }1375 }
1376 }.runTest;1376 }.runTest;
1377 runTest();1377 try runTest();
1378 comptime runTest();1378 comptime try runTest();
1379}1379}
lib/std/math/acos.zig+18-18
...@@ -154,38 +154,38 @@ fn acos64(x: f64) f64 {...@@ -154,38 +154,38 @@ fn acos64(x: f64) f64 {
154}154}
155155
156test "math.acos" {156test "math.acos" {
157 expect(acos(@as(f32, 0.0)) == acos32(0.0));157 try expect(acos(@as(f32, 0.0)) == acos32(0.0));
158 expect(acos(@as(f64, 0.0)) == acos64(0.0));158 try expect(acos(@as(f64, 0.0)) == acos64(0.0));
159}159}
160160
161test "math.acos32" {161test "math.acos32" {
162 const epsilon = 0.000001;162 const epsilon = 0.000001;
163163
164 expect(math.approxEqAbs(f32, acos32(0.0), 1.570796, epsilon));164 try expect(math.approxEqAbs(f32, acos32(0.0), 1.570796, epsilon));
165 expect(math.approxEqAbs(f32, acos32(0.2), 1.369438, epsilon));165 try expect(math.approxEqAbs(f32, acos32(0.2), 1.369438, epsilon));
166 expect(math.approxEqAbs(f32, acos32(0.3434), 1.220262, epsilon));166 try expect(math.approxEqAbs(f32, acos32(0.3434), 1.220262, epsilon));
167 expect(math.approxEqAbs(f32, acos32(0.5), 1.047198, epsilon));167 try expect(math.approxEqAbs(f32, acos32(0.5), 1.047198, epsilon));
168 expect(math.approxEqAbs(f32, acos32(0.8923), 0.468382, epsilon));168 try expect(math.approxEqAbs(f32, acos32(0.8923), 0.468382, epsilon));
169 expect(math.approxEqAbs(f32, acos32(-0.2), 1.772154, epsilon));169 try expect(math.approxEqAbs(f32, acos32(-0.2), 1.772154, epsilon));
170}170}
171171
172test "math.acos64" {172test "math.acos64" {
173 const epsilon = 0.000001;173 const epsilon = 0.000001;
174174
175 expect(math.approxEqAbs(f64, acos64(0.0), 1.570796, epsilon));175 try expect(math.approxEqAbs(f64, acos64(0.0), 1.570796, epsilon));
176 expect(math.approxEqAbs(f64, acos64(0.2), 1.369438, epsilon));176 try expect(math.approxEqAbs(f64, acos64(0.2), 1.369438, epsilon));
177 expect(math.approxEqAbs(f64, acos64(0.3434), 1.220262, epsilon));177 try expect(math.approxEqAbs(f64, acos64(0.3434), 1.220262, epsilon));
178 expect(math.approxEqAbs(f64, acos64(0.5), 1.047198, epsilon));178 try expect(math.approxEqAbs(f64, acos64(0.5), 1.047198, epsilon));
179 expect(math.approxEqAbs(f64, acos64(0.8923), 0.468382, epsilon));179 try expect(math.approxEqAbs(f64, acos64(0.8923), 0.468382, epsilon));
180 expect(math.approxEqAbs(f64, acos64(-0.2), 1.772154, epsilon));180 try expect(math.approxEqAbs(f64, acos64(-0.2), 1.772154, epsilon));
181}181}
182182
183test "math.acos32.special" {183test "math.acos32.special" {
184 expect(math.isNan(acos32(-2)));184 try expect(math.isNan(acos32(-2)));
185 expect(math.isNan(acos32(1.5)));185 try expect(math.isNan(acos32(1.5)));
186}186}
187187
188test "math.acos64.special" {188test "math.acos64.special" {
189 expect(math.isNan(acos64(-2)));189 try expect(math.isNan(acos64(-2)));
190 expect(math.isNan(acos64(1.5)));190 try expect(math.isNan(acos64(1.5)));
191}191}
lib/std/math/acosh.zig+14-14
...@@ -66,34 +66,34 @@ fn acosh64(x: f64) f64 {...@@ -66,34 +66,34 @@ fn acosh64(x: f64) f64 {
66}66}
6767
68test "math.acosh" {68test "math.acosh" {
69 expect(acosh(@as(f32, 1.5)) == acosh32(1.5));69 try expect(acosh(@as(f32, 1.5)) == acosh32(1.5));
70 expect(acosh(@as(f64, 1.5)) == acosh64(1.5));70 try expect(acosh(@as(f64, 1.5)) == acosh64(1.5));
71}71}
7272
73test "math.acosh32" {73test "math.acosh32" {
74 const epsilon = 0.000001;74 const epsilon = 0.000001;
7575
76 expect(math.approxEqAbs(f32, acosh32(1.5), 0.962424, epsilon));76 try expect(math.approxEqAbs(f32, acosh32(1.5), 0.962424, epsilon));
77 expect(math.approxEqAbs(f32, acosh32(37.45), 4.315976, epsilon));77 try expect(math.approxEqAbs(f32, acosh32(37.45), 4.315976, epsilon));
78 expect(math.approxEqAbs(f32, acosh32(89.123), 5.183133, epsilon));78 try expect(math.approxEqAbs(f32, acosh32(89.123), 5.183133, epsilon));
79 expect(math.approxEqAbs(f32, acosh32(123123.234375), 12.414088, epsilon));79 try expect(math.approxEqAbs(f32, acosh32(123123.234375), 12.414088, epsilon));
80}80}
8181
82test "math.acosh64" {82test "math.acosh64" {
83 const epsilon = 0.000001;83 const epsilon = 0.000001;
8484
85 expect(math.approxEqAbs(f64, acosh64(1.5), 0.962424, epsilon));85 try expect(math.approxEqAbs(f64, acosh64(1.5), 0.962424, epsilon));
86 expect(math.approxEqAbs(f64, acosh64(37.45), 4.315976, epsilon));86 try expect(math.approxEqAbs(f64, acosh64(37.45), 4.315976, epsilon));
87 expect(math.approxEqAbs(f64, acosh64(89.123), 5.183133, epsilon));87 try expect(math.approxEqAbs(f64, acosh64(89.123), 5.183133, epsilon));
88 expect(math.approxEqAbs(f64, acosh64(123123.234375), 12.414088, epsilon));88 try expect(math.approxEqAbs(f64, acosh64(123123.234375), 12.414088, epsilon));
89}89}
9090
91test "math.acosh32.special" {91test "math.acosh32.special" {
92 expect(math.isNan(acosh32(math.nan(f32))));92 try expect(math.isNan(acosh32(math.nan(f32))));
93 expect(math.isSignalNan(acosh32(0.5)));93 try expect(math.isSignalNan(acosh32(0.5)));
94}94}
9595
96test "math.acosh64.special" {96test "math.acosh64.special" {
97 expect(math.isNan(acosh64(math.nan(f64))));97 try expect(math.isNan(acosh64(math.nan(f64))));
98 expect(math.isSignalNan(acosh64(0.5)));98 try expect(math.isSignalNan(acosh64(0.5)));
99}99}
lib/std/math/asin.zig+22-22
...@@ -147,42 +147,42 @@ fn asin64(x: f64) f64 {...@@ -147,42 +147,42 @@ fn asin64(x: f64) f64 {
147}147}
148148
149test "math.asin" {149test "math.asin" {
150 expect(asin(@as(f32, 0.0)) == asin32(0.0));150 try expect(asin(@as(f32, 0.0)) == asin32(0.0));
151 expect(asin(@as(f64, 0.0)) == asin64(0.0));151 try expect(asin(@as(f64, 0.0)) == asin64(0.0));
152}152}
153153
154test "math.asin32" {154test "math.asin32" {
155 const epsilon = 0.000001;155 const epsilon = 0.000001;
156156
157 expect(math.approxEqAbs(f32, asin32(0.0), 0.0, epsilon));157 try expect(math.approxEqAbs(f32, asin32(0.0), 0.0, epsilon));
158 expect(math.approxEqAbs(f32, asin32(0.2), 0.201358, epsilon));158 try expect(math.approxEqAbs(f32, asin32(0.2), 0.201358, epsilon));
159 expect(math.approxEqAbs(f32, asin32(-0.2), -0.201358, epsilon));159 try expect(math.approxEqAbs(f32, asin32(-0.2), -0.201358, epsilon));
160 expect(math.approxEqAbs(f32, asin32(0.3434), 0.350535, epsilon));160 try expect(math.approxEqAbs(f32, asin32(0.3434), 0.350535, epsilon));
161 expect(math.approxEqAbs(f32, asin32(0.5), 0.523599, epsilon));161 try expect(math.approxEqAbs(f32, asin32(0.5), 0.523599, epsilon));
162 expect(math.approxEqAbs(f32, asin32(0.8923), 1.102415, epsilon));162 try expect(math.approxEqAbs(f32, asin32(0.8923), 1.102415, epsilon));
163}163}
164164
165test "math.asin64" {165test "math.asin64" {
166 const epsilon = 0.000001;166 const epsilon = 0.000001;
167167
168 expect(math.approxEqAbs(f64, asin64(0.0), 0.0, epsilon));168 try expect(math.approxEqAbs(f64, asin64(0.0), 0.0, epsilon));
169 expect(math.approxEqAbs(f64, asin64(0.2), 0.201358, epsilon));169 try expect(math.approxEqAbs(f64, asin64(0.2), 0.201358, epsilon));
170 expect(math.approxEqAbs(f64, asin64(-0.2), -0.201358, epsilon));170 try expect(math.approxEqAbs(f64, asin64(-0.2), -0.201358, epsilon));
171 expect(math.approxEqAbs(f64, asin64(0.3434), 0.350535, epsilon));171 try expect(math.approxEqAbs(f64, asin64(0.3434), 0.350535, epsilon));
172 expect(math.approxEqAbs(f64, asin64(0.5), 0.523599, epsilon));172 try expect(math.approxEqAbs(f64, asin64(0.5), 0.523599, epsilon));
173 expect(math.approxEqAbs(f64, asin64(0.8923), 1.102415, epsilon));173 try expect(math.approxEqAbs(f64, asin64(0.8923), 1.102415, epsilon));
174}174}
175175
176test "math.asin32.special" {176test "math.asin32.special" {
177 expect(asin32(0.0) == 0.0);177 try expect(asin32(0.0) == 0.0);
178 expect(asin32(-0.0) == -0.0);178 try expect(asin32(-0.0) == -0.0);
179 expect(math.isNan(asin32(-2)));179 try expect(math.isNan(asin32(-2)));
180 expect(math.isNan(asin32(1.5)));180 try expect(math.isNan(asin32(1.5)));
181}181}
182182
183test "math.asin64.special" {183test "math.asin64.special" {
184 expect(asin64(0.0) == 0.0);184 try expect(asin64(0.0) == 0.0);
185 expect(asin64(-0.0) == -0.0);185 try expect(asin64(-0.0) == -0.0);
186 expect(math.isNan(asin64(-2)));186 try expect(math.isNan(asin64(-2)));
187 expect(math.isNan(asin64(1.5)));187 try expect(math.isNan(asin64(1.5)));
188}188}
lib/std/math/asinh.zig+26-26
...@@ -94,46 +94,46 @@ fn asinh64(x: f64) f64 {...@@ -94,46 +94,46 @@ fn asinh64(x: f64) f64 {
94}94}
9595
96test "math.asinh" {96test "math.asinh" {
97 expect(asinh(@as(f32, 0.0)) == asinh32(0.0));97 try expect(asinh(@as(f32, 0.0)) == asinh32(0.0));
98 expect(asinh(@as(f64, 0.0)) == asinh64(0.0));98 try expect(asinh(@as(f64, 0.0)) == asinh64(0.0));
99}99}
100100
101test "math.asinh32" {101test "math.asinh32" {
102 const epsilon = 0.000001;102 const epsilon = 0.000001;
103103
104 expect(math.approxEqAbs(f32, asinh32(0.0), 0.0, epsilon));104 try expect(math.approxEqAbs(f32, asinh32(0.0), 0.0, epsilon));
105 expect(math.approxEqAbs(f32, asinh32(0.2), 0.198690, epsilon));105 try expect(math.approxEqAbs(f32, asinh32(0.2), 0.198690, epsilon));
106 expect(math.approxEqAbs(f32, asinh32(0.8923), 0.803133, epsilon));106 try expect(math.approxEqAbs(f32, asinh32(0.8923), 0.803133, epsilon));
107 expect(math.approxEqAbs(f32, asinh32(1.5), 1.194763, epsilon));107 try expect(math.approxEqAbs(f32, asinh32(1.5), 1.194763, epsilon));
108 expect(math.approxEqAbs(f32, asinh32(37.45), 4.316332, epsilon));108 try expect(math.approxEqAbs(f32, asinh32(37.45), 4.316332, epsilon));
109 expect(math.approxEqAbs(f32, asinh32(89.123), 5.183196, epsilon));109 try expect(math.approxEqAbs(f32, asinh32(89.123), 5.183196, epsilon));
110 expect(math.approxEqAbs(f32, asinh32(123123.234375), 12.414088, epsilon));110 try expect(math.approxEqAbs(f32, asinh32(123123.234375), 12.414088, epsilon));
111}111}
112112
113test "math.asinh64" {113test "math.asinh64" {
114 const epsilon = 0.000001;114 const epsilon = 0.000001;
115115
116 expect(math.approxEqAbs(f64, asinh64(0.0), 0.0, epsilon));116 try expect(math.approxEqAbs(f64, asinh64(0.0), 0.0, epsilon));
117 expect(math.approxEqAbs(f64, asinh64(0.2), 0.198690, epsilon));117 try expect(math.approxEqAbs(f64, asinh64(0.2), 0.198690, epsilon));
118 expect(math.approxEqAbs(f64, asinh64(0.8923), 0.803133, epsilon));118 try expect(math.approxEqAbs(f64, asinh64(0.8923), 0.803133, epsilon));
119 expect(math.approxEqAbs(f64, asinh64(1.5), 1.194763, epsilon));119 try expect(math.approxEqAbs(f64, asinh64(1.5), 1.194763, epsilon));
120 expect(math.approxEqAbs(f64, asinh64(37.45), 4.316332, epsilon));120 try expect(math.approxEqAbs(f64, asinh64(37.45), 4.316332, epsilon));
121 expect(math.approxEqAbs(f64, asinh64(89.123), 5.183196, epsilon));121 try expect(math.approxEqAbs(f64, asinh64(89.123), 5.183196, epsilon));
122 expect(math.approxEqAbs(f64, asinh64(123123.234375), 12.414088, epsilon));122 try expect(math.approxEqAbs(f64, asinh64(123123.234375), 12.414088, epsilon));
123}123}
124124
125test "math.asinh32.special" {125test "math.asinh32.special" {
126 expect(asinh32(0.0) == 0.0);126 try expect(asinh32(0.0) == 0.0);
127 expect(asinh32(-0.0) == -0.0);127 try expect(asinh32(-0.0) == -0.0);
128 expect(math.isPositiveInf(asinh32(math.inf(f32))));128 try expect(math.isPositiveInf(asinh32(math.inf(f32))));
129 expect(math.isNegativeInf(asinh32(-math.inf(f32))));129 try expect(math.isNegativeInf(asinh32(-math.inf(f32))));
130 expect(math.isNan(asinh32(math.nan(f32))));130 try expect(math.isNan(asinh32(math.nan(f32))));
131}131}
132132
133test "math.asinh64.special" {133test "math.asinh64.special" {
134 expect(asinh64(0.0) == 0.0);134 try expect(asinh64(0.0) == 0.0);
135 expect(asinh64(-0.0) == -0.0);135 try expect(asinh64(-0.0) == -0.0);
136 expect(math.isPositiveInf(asinh64(math.inf(f64))));136 try expect(math.isPositiveInf(asinh64(math.inf(f64))));
137 expect(math.isNegativeInf(asinh64(-math.inf(f64))));137 try expect(math.isNegativeInf(asinh64(-math.inf(f64))));
138 expect(math.isNan(asinh64(math.nan(f64))));138 try expect(math.isNan(asinh64(math.nan(f64))));
139}139}
lib/std/math/atan.zig+20-20
...@@ -217,44 +217,44 @@ fn atan64(x_: f64) f64 {...@@ -217,44 +217,44 @@ fn atan64(x_: f64) f64 {
217}217}
218218
219test "math.atan" {219test "math.atan" {
220 expect(@bitCast(u32, atan(@as(f32, 0.2))) == @bitCast(u32, atan32(0.2)));220 try expect(@bitCast(u32, atan(@as(f32, 0.2))) == @bitCast(u32, atan32(0.2)));
221 expect(atan(@as(f64, 0.2)) == atan64(0.2));221 try expect(atan(@as(f64, 0.2)) == atan64(0.2));
222}222}
223223
224test "math.atan32" {224test "math.atan32" {
225 const epsilon = 0.000001;225 const epsilon = 0.000001;
226226
227 expect(math.approxEqAbs(f32, atan32(0.2), 0.197396, epsilon));227 try expect(math.approxEqAbs(f32, atan32(0.2), 0.197396, epsilon));
228 expect(math.approxEqAbs(f32, atan32(-0.2), -0.197396, epsilon));228 try expect(math.approxEqAbs(f32, atan32(-0.2), -0.197396, epsilon));
229 expect(math.approxEqAbs(f32, atan32(0.3434), 0.330783, epsilon));229 try expect(math.approxEqAbs(f32, atan32(0.3434), 0.330783, epsilon));
230 expect(math.approxEqAbs(f32, atan32(0.8923), 0.728545, epsilon));230 try expect(math.approxEqAbs(f32, atan32(0.8923), 0.728545, epsilon));
231 expect(math.approxEqAbs(f32, atan32(1.5), 0.982794, epsilon));231 try expect(math.approxEqAbs(f32, atan32(1.5), 0.982794, epsilon));
232}232}
233233
234test "math.atan64" {234test "math.atan64" {
235 const epsilon = 0.000001;235 const epsilon = 0.000001;
236236
237 expect(math.approxEqAbs(f64, atan64(0.2), 0.197396, epsilon));237 try expect(math.approxEqAbs(f64, atan64(0.2), 0.197396, epsilon));
238 expect(math.approxEqAbs(f64, atan64(-0.2), -0.197396, epsilon));238 try expect(math.approxEqAbs(f64, atan64(-0.2), -0.197396, epsilon));
239 expect(math.approxEqAbs(f64, atan64(0.3434), 0.330783, epsilon));239 try expect(math.approxEqAbs(f64, atan64(0.3434), 0.330783, epsilon));
240 expect(math.approxEqAbs(f64, atan64(0.8923), 0.728545, epsilon));240 try expect(math.approxEqAbs(f64, atan64(0.8923), 0.728545, epsilon));
241 expect(math.approxEqAbs(f64, atan64(1.5), 0.982794, epsilon));241 try expect(math.approxEqAbs(f64, atan64(1.5), 0.982794, epsilon));
242}242}
243243
244test "math.atan32.special" {244test "math.atan32.special" {
245 const epsilon = 0.000001;245 const epsilon = 0.000001;
246246
247 expect(atan32(0.0) == 0.0);247 try expect(atan32(0.0) == 0.0);
248 expect(atan32(-0.0) == -0.0);248 try expect(atan32(-0.0) == -0.0);
249 expect(math.approxEqAbs(f32, atan32(math.inf(f32)), math.pi / 2.0, epsilon));249 try expect(math.approxEqAbs(f32, atan32(math.inf(f32)), math.pi / 2.0, epsilon));
250 expect(math.approxEqAbs(f32, atan32(-math.inf(f32)), -math.pi / 2.0, epsilon));250 try expect(math.approxEqAbs(f32, atan32(-math.inf(f32)), -math.pi / 2.0, epsilon));
251}251}
252252
253test "math.atan64.special" {253test "math.atan64.special" {
254 const epsilon = 0.000001;254 const epsilon = 0.000001;
255255
256 expect(atan64(0.0) == 0.0);256 try expect(atan64(0.0) == 0.0);
257 expect(atan64(-0.0) == -0.0);257 try expect(atan64(-0.0) == -0.0);
258 expect(math.approxEqAbs(f64, atan64(math.inf(f64)), math.pi / 2.0, epsilon));258 try expect(math.approxEqAbs(f64, atan64(math.inf(f64)), math.pi / 2.0, epsilon));
259 expect(math.approxEqAbs(f64, atan64(-math.inf(f64)), -math.pi / 2.0, epsilon));259 try expect(math.approxEqAbs(f64, atan64(-math.inf(f64)), -math.pi / 2.0, epsilon));
260}260}
lib/std/math/atan2.zig+52-52
...@@ -217,78 +217,78 @@ fn atan2_64(y: f64, x: f64) f64 {...@@ -217,78 +217,78 @@ fn atan2_64(y: f64, x: f64) f64 {
217}217}
218218
219test "math.atan2" {219test "math.atan2" {
220 expect(atan2(f32, 0.2, 0.21) == atan2_32(0.2, 0.21));220 try expect(atan2(f32, 0.2, 0.21) == atan2_32(0.2, 0.21));
221 expect(atan2(f64, 0.2, 0.21) == atan2_64(0.2, 0.21));221 try expect(atan2(f64, 0.2, 0.21) == atan2_64(0.2, 0.21));
222}222}
223223
224test "math.atan2_32" {224test "math.atan2_32" {
225 const epsilon = 0.000001;225 const epsilon = 0.000001;
226226
227 expect(math.approxEqAbs(f32, atan2_32(0.0, 0.0), 0.0, epsilon));227 try expect(math.approxEqAbs(f32, atan2_32(0.0, 0.0), 0.0, epsilon));
228 expect(math.approxEqAbs(f32, atan2_32(0.2, 0.2), 0.785398, epsilon));228 try expect(math.approxEqAbs(f32, atan2_32(0.2, 0.2), 0.785398, epsilon));
229 expect(math.approxEqAbs(f32, atan2_32(-0.2, 0.2), -0.785398, epsilon));229 try expect(math.approxEqAbs(f32, atan2_32(-0.2, 0.2), -0.785398, epsilon));
230 expect(math.approxEqAbs(f32, atan2_32(0.2, -0.2), 2.356194, epsilon));230 try expect(math.approxEqAbs(f32, atan2_32(0.2, -0.2), 2.356194, epsilon));
231 expect(math.approxEqAbs(f32, atan2_32(-0.2, -0.2), -2.356194, epsilon));231 try expect(math.approxEqAbs(f32, atan2_32(-0.2, -0.2), -2.356194, epsilon));
232 expect(math.approxEqAbs(f32, atan2_32(0.34, -0.4), 2.437099, epsilon));232 try expect(math.approxEqAbs(f32, atan2_32(0.34, -0.4), 2.437099, epsilon));
233 expect(math.approxEqAbs(f32, atan2_32(0.34, 1.243), 0.267001, epsilon));233 try expect(math.approxEqAbs(f32, atan2_32(0.34, 1.243), 0.267001, epsilon));
234}234}
235235
236test "math.atan2_64" {236test "math.atan2_64" {
237 const epsilon = 0.000001;237 const epsilon = 0.000001;
238238
239 expect(math.approxEqAbs(f64, atan2_64(0.0, 0.0), 0.0, epsilon));239 try expect(math.approxEqAbs(f64, atan2_64(0.0, 0.0), 0.0, epsilon));
240 expect(math.approxEqAbs(f64, atan2_64(0.2, 0.2), 0.785398, epsilon));240 try expect(math.approxEqAbs(f64, atan2_64(0.2, 0.2), 0.785398, epsilon));
241 expect(math.approxEqAbs(f64, atan2_64(-0.2, 0.2), -0.785398, epsilon));241 try expect(math.approxEqAbs(f64, atan2_64(-0.2, 0.2), -0.785398, epsilon));
242 expect(math.approxEqAbs(f64, atan2_64(0.2, -0.2), 2.356194, epsilon));242 try expect(math.approxEqAbs(f64, atan2_64(0.2, -0.2), 2.356194, epsilon));
243 expect(math.approxEqAbs(f64, atan2_64(-0.2, -0.2), -2.356194, epsilon));243 try expect(math.approxEqAbs(f64, atan2_64(-0.2, -0.2), -2.356194, epsilon));
244 expect(math.approxEqAbs(f64, atan2_64(0.34, -0.4), 2.437099, epsilon));244 try expect(math.approxEqAbs(f64, atan2_64(0.34, -0.4), 2.437099, epsilon));
245 expect(math.approxEqAbs(f64, atan2_64(0.34, 1.243), 0.267001, epsilon));245 try expect(math.approxEqAbs(f64, atan2_64(0.34, 1.243), 0.267001, epsilon));
246}246}
247247
248test "math.atan2_32.special" {248test "math.atan2_32.special" {
249 const epsilon = 0.000001;249 const epsilon = 0.000001;
250250
251 expect(math.isNan(atan2_32(1.0, math.nan(f32))));251 try expect(math.isNan(atan2_32(1.0, math.nan(f32))));
252 expect(math.isNan(atan2_32(math.nan(f32), 1.0)));252 try expect(math.isNan(atan2_32(math.nan(f32), 1.0)));
253 expect(atan2_32(0.0, 5.0) == 0.0);253 try expect(atan2_32(0.0, 5.0) == 0.0);
254 expect(atan2_32(-0.0, 5.0) == -0.0);254 try expect(atan2_32(-0.0, 5.0) == -0.0);
255 expect(math.approxEqAbs(f32, atan2_32(0.0, -5.0), math.pi, epsilon));255 try expect(math.approxEqAbs(f32, atan2_32(0.0, -5.0), math.pi, epsilon));
256 //expect(math.approxEqAbs(f32, atan2_32(-0.0, -5.0), -math.pi, .{.rel=0,.abs=epsilon})); TODO support negative zero?256 //expect(math.approxEqAbs(f32, atan2_32(-0.0, -5.0), -math.pi, .{.rel=0,.abs=epsilon})); TODO support negative zero?
257 expect(math.approxEqAbs(f32, atan2_32(1.0, 0.0), math.pi / 2.0, epsilon));257 try expect(math.approxEqAbs(f32, atan2_32(1.0, 0.0), math.pi / 2.0, epsilon));
258 expect(math.approxEqAbs(f32, atan2_32(1.0, -0.0), math.pi / 2.0, epsilon));258 try expect(math.approxEqAbs(f32, atan2_32(1.0, -0.0), math.pi / 2.0, epsilon));
259 expect(math.approxEqAbs(f32, atan2_32(-1.0, 0.0), -math.pi / 2.0, epsilon));259 try expect(math.approxEqAbs(f32, atan2_32(-1.0, 0.0), -math.pi / 2.0, epsilon));
260 expect(math.approxEqAbs(f32, atan2_32(-1.0, -0.0), -math.pi / 2.0, epsilon));260 try expect(math.approxEqAbs(f32, atan2_32(-1.0, -0.0), -math.pi / 2.0, epsilon));
261 expect(math.approxEqAbs(f32, atan2_32(math.inf(f32), math.inf(f32)), math.pi / 4.0, epsilon));261 try expect(math.approxEqAbs(f32, atan2_32(math.inf(f32), math.inf(f32)), math.pi / 4.0, epsilon));
262 expect(math.approxEqAbs(f32, atan2_32(-math.inf(f32), math.inf(f32)), -math.pi / 4.0, epsilon));262 try expect(math.approxEqAbs(f32, atan2_32(-math.inf(f32), math.inf(f32)), -math.pi / 4.0, epsilon));
263 expect(math.approxEqAbs(f32, atan2_32(math.inf(f32), -math.inf(f32)), 3.0 * math.pi / 4.0, epsilon));263 try expect(math.approxEqAbs(f32, atan2_32(math.inf(f32), -math.inf(f32)), 3.0 * math.pi / 4.0, epsilon));
264 expect(math.approxEqAbs(f32, atan2_32(-math.inf(f32), -math.inf(f32)), -3.0 * math.pi / 4.0, epsilon));264 try expect(math.approxEqAbs(f32, atan2_32(-math.inf(f32), -math.inf(f32)), -3.0 * math.pi / 4.0, epsilon));
265 expect(atan2_32(1.0, math.inf(f32)) == 0.0);265 try expect(atan2_32(1.0, math.inf(f32)) == 0.0);
266 expect(math.approxEqAbs(f32, atan2_32(1.0, -math.inf(f32)), math.pi, epsilon));266 try expect(math.approxEqAbs(f32, atan2_32(1.0, -math.inf(f32)), math.pi, epsilon));
267 expect(math.approxEqAbs(f32, atan2_32(-1.0, -math.inf(f32)), -math.pi, epsilon));267 try expect(math.approxEqAbs(f32, atan2_32(-1.0, -math.inf(f32)), -math.pi, epsilon));
268 expect(math.approxEqAbs(f32, atan2_32(math.inf(f32), 1.0), math.pi / 2.0, epsilon));268 try expect(math.approxEqAbs(f32, atan2_32(math.inf(f32), 1.0), math.pi / 2.0, epsilon));
269 expect(math.approxEqAbs(f32, atan2_32(-math.inf(f32), 1.0), -math.pi / 2.0, epsilon));269 try expect(math.approxEqAbs(f32, atan2_32(-math.inf(f32), 1.0), -math.pi / 2.0, epsilon));
270}270}
271271
272test "math.atan2_64.special" {272test "math.atan2_64.special" {
273 const epsilon = 0.000001;273 const epsilon = 0.000001;
274274
275 expect(math.isNan(atan2_64(1.0, math.nan(f64))));275 try expect(math.isNan(atan2_64(1.0, math.nan(f64))));
276 expect(math.isNan(atan2_64(math.nan(f64), 1.0)));276 try expect(math.isNan(atan2_64(math.nan(f64), 1.0)));
277 expect(atan2_64(0.0, 5.0) == 0.0);277 try expect(atan2_64(0.0, 5.0) == 0.0);
278 expect(atan2_64(-0.0, 5.0) == -0.0);278 try expect(atan2_64(-0.0, 5.0) == -0.0);
279 expect(math.approxEqAbs(f64, atan2_64(0.0, -5.0), math.pi, epsilon));279 try expect(math.approxEqAbs(f64, atan2_64(0.0, -5.0), math.pi, epsilon));
280 //expect(math.approxEqAbs(f64, atan2_64(-0.0, -5.0), -math.pi, .{.rel=0,.abs=epsilon})); TODO support negative zero?280 //expect(math.approxEqAbs(f64, atan2_64(-0.0, -5.0), -math.pi, .{.rel=0,.abs=epsilon})); TODO support negative zero?
281 expect(math.approxEqAbs(f64, atan2_64(1.0, 0.0), math.pi / 2.0, epsilon));281 try expect(math.approxEqAbs(f64, atan2_64(1.0, 0.0), math.pi / 2.0, epsilon));
282 expect(math.approxEqAbs(f64, atan2_64(1.0, -0.0), math.pi / 2.0, epsilon));282 try expect(math.approxEqAbs(f64, atan2_64(1.0, -0.0), math.pi / 2.0, epsilon));
283 expect(math.approxEqAbs(f64, atan2_64(-1.0, 0.0), -math.pi / 2.0, epsilon));283 try expect(math.approxEqAbs(f64, atan2_64(-1.0, 0.0), -math.pi / 2.0, epsilon));
284 expect(math.approxEqAbs(f64, atan2_64(-1.0, -0.0), -math.pi / 2.0, epsilon));284 try expect(math.approxEqAbs(f64, atan2_64(-1.0, -0.0), -math.pi / 2.0, epsilon));
285 expect(math.approxEqAbs(f64, atan2_64(math.inf(f64), math.inf(f64)), math.pi / 4.0, epsilon));285 try expect(math.approxEqAbs(f64, atan2_64(math.inf(f64), math.inf(f64)), math.pi / 4.0, epsilon));
286 expect(math.approxEqAbs(f64, atan2_64(-math.inf(f64), math.inf(f64)), -math.pi / 4.0, epsilon));286 try expect(math.approxEqAbs(f64, atan2_64(-math.inf(f64), math.inf(f64)), -math.pi / 4.0, epsilon));
287 expect(math.approxEqAbs(f64, atan2_64(math.inf(f64), -math.inf(f64)), 3.0 * math.pi / 4.0, epsilon));287 try expect(math.approxEqAbs(f64, atan2_64(math.inf(f64), -math.inf(f64)), 3.0 * math.pi / 4.0, epsilon));
288 expect(math.approxEqAbs(f64, atan2_64(-math.inf(f64), -math.inf(f64)), -3.0 * math.pi / 4.0, epsilon));288 try expect(math.approxEqAbs(f64, atan2_64(-math.inf(f64), -math.inf(f64)), -3.0 * math.pi / 4.0, epsilon));
289 expect(atan2_64(1.0, math.inf(f64)) == 0.0);289 try expect(atan2_64(1.0, math.inf(f64)) == 0.0);
290 expect(math.approxEqAbs(f64, atan2_64(1.0, -math.inf(f64)), math.pi, epsilon));290 try expect(math.approxEqAbs(f64, atan2_64(1.0, -math.inf(f64)), math.pi, epsilon));
291 expect(math.approxEqAbs(f64, atan2_64(-1.0, -math.inf(f64)), -math.pi, epsilon));291 try expect(math.approxEqAbs(f64, atan2_64(-1.0, -math.inf(f64)), -math.pi, epsilon));
292 expect(math.approxEqAbs(f64, atan2_64(math.inf(f64), 1.0), math.pi / 2.0, epsilon));292 try expect(math.approxEqAbs(f64, atan2_64(math.inf(f64), 1.0), math.pi / 2.0, epsilon));
293 expect(math.approxEqAbs(f64, atan2_64(-math.inf(f64), 1.0), -math.pi / 2.0, epsilon));293 try expect(math.approxEqAbs(f64, atan2_64(-math.inf(f64), 1.0), -math.pi / 2.0, epsilon));
294}294}
lib/std/math/atanh.zig+18-18
...@@ -89,38 +89,38 @@ fn atanh_64(x: f64) f64 {...@@ -89,38 +89,38 @@ fn atanh_64(x: f64) f64 {
89}89}
9090
91test "math.atanh" {91test "math.atanh" {
92 expect(atanh(@as(f32, 0.0)) == atanh_32(0.0));92 try expect(atanh(@as(f32, 0.0)) == atanh_32(0.0));
93 expect(atanh(@as(f64, 0.0)) == atanh_64(0.0));93 try expect(atanh(@as(f64, 0.0)) == atanh_64(0.0));
94}94}
9595
96test "math.atanh_32" {96test "math.atanh_32" {
97 const epsilon = 0.000001;97 const epsilon = 0.000001;
9898
99 expect(math.approxEqAbs(f32, atanh_32(0.0), 0.0, epsilon));99 try expect(math.approxEqAbs(f32, atanh_32(0.0), 0.0, epsilon));
100 expect(math.approxEqAbs(f32, atanh_32(0.2), 0.202733, epsilon));100 try expect(math.approxEqAbs(f32, atanh_32(0.2), 0.202733, epsilon));
101 expect(math.approxEqAbs(f32, atanh_32(0.8923), 1.433099, epsilon));101 try expect(math.approxEqAbs(f32, atanh_32(0.8923), 1.433099, epsilon));
102}102}
103103
104test "math.atanh_64" {104test "math.atanh_64" {
105 const epsilon = 0.000001;105 const epsilon = 0.000001;
106106
107 expect(math.approxEqAbs(f64, atanh_64(0.0), 0.0, epsilon));107 try expect(math.approxEqAbs(f64, atanh_64(0.0), 0.0, epsilon));
108 expect(math.approxEqAbs(f64, atanh_64(0.2), 0.202733, epsilon));108 try expect(math.approxEqAbs(f64, atanh_64(0.2), 0.202733, epsilon));
109 expect(math.approxEqAbs(f64, atanh_64(0.8923), 1.433099, epsilon));109 try expect(math.approxEqAbs(f64, atanh_64(0.8923), 1.433099, epsilon));
110}110}
111111
112test "math.atanh32.special" {112test "math.atanh32.special" {
113 expect(math.isPositiveInf(atanh_32(1)));113 try expect(math.isPositiveInf(atanh_32(1)));
114 expect(math.isNegativeInf(atanh_32(-1)));114 try expect(math.isNegativeInf(atanh_32(-1)));
115 expect(math.isSignalNan(atanh_32(1.5)));115 try expect(math.isSignalNan(atanh_32(1.5)));
116 expect(math.isSignalNan(atanh_32(-1.5)));116 try expect(math.isSignalNan(atanh_32(-1.5)));
117 expect(math.isNan(atanh_32(math.nan(f32))));117 try expect(math.isNan(atanh_32(math.nan(f32))));
118}118}
119119
120test "math.atanh64.special" {120test "math.atanh64.special" {
121 expect(math.isPositiveInf(atanh_64(1)));121 try expect(math.isPositiveInf(atanh_64(1)));
122 expect(math.isNegativeInf(atanh_64(-1)));122 try expect(math.isNegativeInf(atanh_64(-1)));
123 expect(math.isSignalNan(atanh_64(1.5)));123 try expect(math.isSignalNan(atanh_64(1.5)));
124 expect(math.isSignalNan(atanh_64(-1.5)));124 try expect(math.isSignalNan(atanh_64(-1.5)));
125 expect(math.isNan(atanh_64(math.nan(f64))));125 try expect(math.isNan(atanh_64(math.nan(f64))));
126}126}
lib/std/math/big/int_test.zig+211-211
...@@ -30,7 +30,7 @@ test "big.int comptime_int set" {...@@ -30,7 +30,7 @@ test "big.int comptime_int set" {
30 const result = @as(Limb, s & maxInt(Limb));30 const result = @as(Limb, s & maxInt(Limb));
31 s >>= @typeInfo(Limb).Int.bits / 2;31 s >>= @typeInfo(Limb).Int.bits / 2;
32 s >>= @typeInfo(Limb).Int.bits / 2;32 s >>= @typeInfo(Limb).Int.bits / 2;
33 testing.expect(a.limbs[i] == result);33 try testing.expect(a.limbs[i] == result);
34 }34 }
35}35}
3636
...@@ -38,37 +38,37 @@ test "big.int comptime_int set negative" {...@@ -38,37 +38,37 @@ test "big.int comptime_int set negative" {
38 var a = try Managed.initSet(testing.allocator, -10);38 var a = try Managed.initSet(testing.allocator, -10);
39 defer a.deinit();39 defer a.deinit();
4040
41 testing.expect(a.limbs[0] == 10);41 try testing.expect(a.limbs[0] == 10);
42 testing.expect(a.isPositive() == false);42 try testing.expect(a.isPositive() == false);
43}43}
4444
45test "big.int int set unaligned small" {45test "big.int int set unaligned small" {
46 var a = try Managed.initSet(testing.allocator, @as(u7, 45));46 var a = try Managed.initSet(testing.allocator, @as(u7, 45));
47 defer a.deinit();47 defer a.deinit();
4848
49 testing.expect(a.limbs[0] == 45);49 try testing.expect(a.limbs[0] == 45);
50 testing.expect(a.isPositive() == true);50 try testing.expect(a.isPositive() == true);
51}51}
5252
53test "big.int comptime_int to" {53test "big.int comptime_int to" {
54 var a = try Managed.initSet(testing.allocator, 0xefffffff00000001eeeeeeefaaaaaaab);54 var a = try Managed.initSet(testing.allocator, 0xefffffff00000001eeeeeeefaaaaaaab);
55 defer a.deinit();55 defer a.deinit();
5656
57 testing.expect((try a.to(u128)) == 0xefffffff00000001eeeeeeefaaaaaaab);57 try testing.expect((try a.to(u128)) == 0xefffffff00000001eeeeeeefaaaaaaab);
58}58}
5959
60test "big.int sub-limb to" {60test "big.int sub-limb to" {
61 var a = try Managed.initSet(testing.allocator, 10);61 var a = try Managed.initSet(testing.allocator, 10);
62 defer a.deinit();62 defer a.deinit();
6363
64 testing.expect((try a.to(u8)) == 10);64 try testing.expect((try a.to(u8)) == 10);
65}65}
6666
67test "big.int to target too small error" {67test "big.int to target too small error" {
68 var a = try Managed.initSet(testing.allocator, 0xffffffff);68 var a = try Managed.initSet(testing.allocator, 0xffffffff);
69 defer a.deinit();69 defer a.deinit();
7070
71 testing.expectError(error.TargetTooSmall, a.to(u8));71 try testing.expectError(error.TargetTooSmall, a.to(u8));
72}72}
7373
74test "big.int normalize" {74test "big.int normalize" {
...@@ -81,22 +81,22 @@ test "big.int normalize" {...@@ -81,22 +81,22 @@ test "big.int normalize" {
81 a.limbs[2] = 3;81 a.limbs[2] = 3;
82 a.limbs[3] = 0;82 a.limbs[3] = 0;
83 a.normalize(4);83 a.normalize(4);
84 testing.expect(a.len() == 3);84 try testing.expect(a.len() == 3);
8585
86 a.limbs[0] = 1;86 a.limbs[0] = 1;
87 a.limbs[1] = 2;87 a.limbs[1] = 2;
88 a.limbs[2] = 3;88 a.limbs[2] = 3;
89 a.normalize(3);89 a.normalize(3);
90 testing.expect(a.len() == 3);90 try testing.expect(a.len() == 3);
9191
92 a.limbs[0] = 0;92 a.limbs[0] = 0;
93 a.limbs[1] = 0;93 a.limbs[1] = 0;
94 a.normalize(2);94 a.normalize(2);
95 testing.expect(a.len() == 1);95 try testing.expect(a.len() == 1);
9696
97 a.limbs[0] = 0;97 a.limbs[0] = 0;
98 a.normalize(1);98 a.normalize(1);
99 testing.expect(a.len() == 1);99 try testing.expect(a.len() == 1);
100}100}
101101
102test "big.int normalize multi" {102test "big.int normalize multi" {
...@@ -109,24 +109,24 @@ test "big.int normalize multi" {...@@ -109,24 +109,24 @@ test "big.int normalize multi" {
109 a.limbs[2] = 0;109 a.limbs[2] = 0;
110 a.limbs[3] = 0;110 a.limbs[3] = 0;
111 a.normalize(4);111 a.normalize(4);
112 testing.expect(a.len() == 2);112 try testing.expect(a.len() == 2);
113113
114 a.limbs[0] = 1;114 a.limbs[0] = 1;
115 a.limbs[1] = 2;115 a.limbs[1] = 2;
116 a.limbs[2] = 3;116 a.limbs[2] = 3;
117 a.normalize(3);117 a.normalize(3);
118 testing.expect(a.len() == 3);118 try testing.expect(a.len() == 3);
119119
120 a.limbs[0] = 0;120 a.limbs[0] = 0;
121 a.limbs[1] = 0;121 a.limbs[1] = 0;
122 a.limbs[2] = 0;122 a.limbs[2] = 0;
123 a.limbs[3] = 0;123 a.limbs[3] = 0;
124 a.normalize(4);124 a.normalize(4);
125 testing.expect(a.len() == 1);125 try testing.expect(a.len() == 1);
126126
127 a.limbs[0] = 0;127 a.limbs[0] = 0;
128 a.normalize(1);128 a.normalize(1);
129 testing.expect(a.len() == 1);129 try testing.expect(a.len() == 1);
130}130}
131131
132test "big.int parity" {132test "big.int parity" {
...@@ -134,12 +134,12 @@ test "big.int parity" {...@@ -134,12 +134,12 @@ test "big.int parity" {
134 defer a.deinit();134 defer a.deinit();
135135
136 try a.set(0);136 try a.set(0);
137 testing.expect(a.isEven());137 try testing.expect(a.isEven());
138 testing.expect(!a.isOdd());138 try testing.expect(!a.isOdd());
139139
140 try a.set(7);140 try a.set(7);
141 testing.expect(!a.isEven());141 try testing.expect(!a.isEven());
142 testing.expect(a.isOdd());142 try testing.expect(a.isOdd());
143}143}
144144
145test "big.int bitcount + sizeInBaseUpperBound" {145test "big.int bitcount + sizeInBaseUpperBound" {
...@@ -147,27 +147,27 @@ test "big.int bitcount + sizeInBaseUpperBound" {...@@ -147,27 +147,27 @@ test "big.int bitcount + sizeInBaseUpperBound" {
147 defer a.deinit();147 defer a.deinit();
148148
149 try a.set(0b100);149 try a.set(0b100);
150 testing.expect(a.bitCountAbs() == 3);150 try testing.expect(a.bitCountAbs() == 3);
151 testing.expect(a.sizeInBaseUpperBound(2) >= 3);151 try testing.expect(a.sizeInBaseUpperBound(2) >= 3);
152 testing.expect(a.sizeInBaseUpperBound(10) >= 1);152 try testing.expect(a.sizeInBaseUpperBound(10) >= 1);
153153
154 a.negate();154 a.negate();
155 testing.expect(a.bitCountAbs() == 3);155 try testing.expect(a.bitCountAbs() == 3);
156 testing.expect(a.sizeInBaseUpperBound(2) >= 4);156 try testing.expect(a.sizeInBaseUpperBound(2) >= 4);
157 testing.expect(a.sizeInBaseUpperBound(10) >= 2);157 try testing.expect(a.sizeInBaseUpperBound(10) >= 2);
158158
159 try a.set(0xffffffff);159 try a.set(0xffffffff);
160 testing.expect(a.bitCountAbs() == 32);160 try testing.expect(a.bitCountAbs() == 32);
161 testing.expect(a.sizeInBaseUpperBound(2) >= 32);161 try testing.expect(a.sizeInBaseUpperBound(2) >= 32);
162 testing.expect(a.sizeInBaseUpperBound(10) >= 10);162 try testing.expect(a.sizeInBaseUpperBound(10) >= 10);
163163
164 try a.shiftLeft(a, 5000);164 try a.shiftLeft(a, 5000);
165 testing.expect(a.bitCountAbs() == 5032);165 try testing.expect(a.bitCountAbs() == 5032);
166 testing.expect(a.sizeInBaseUpperBound(2) >= 5032);166 try testing.expect(a.sizeInBaseUpperBound(2) >= 5032);
167 a.setSign(false);167 a.setSign(false);
168168
169 testing.expect(a.bitCountAbs() == 5032);169 try testing.expect(a.bitCountAbs() == 5032);
170 testing.expect(a.sizeInBaseUpperBound(2) >= 5033);170 try testing.expect(a.sizeInBaseUpperBound(2) >= 5033);
171}171}
172172
173test "big.int bitcount/to" {173test "big.int bitcount/to" {
...@@ -175,30 +175,30 @@ test "big.int bitcount/to" {...@@ -175,30 +175,30 @@ test "big.int bitcount/to" {
175 defer a.deinit();175 defer a.deinit();
176176
177 try a.set(0);177 try a.set(0);
178 testing.expect(a.bitCountTwosComp() == 0);178 try testing.expect(a.bitCountTwosComp() == 0);
179179
180 testing.expect((try a.to(u0)) == 0);180 try testing.expect((try a.to(u0)) == 0);
181 testing.expect((try a.to(i0)) == 0);181 try testing.expect((try a.to(i0)) == 0);
182182
183 try a.set(-1);183 try a.set(-1);
184 testing.expect(a.bitCountTwosComp() == 1);184 try testing.expect(a.bitCountTwosComp() == 1);
185 testing.expect((try a.to(i1)) == -1);185 try testing.expect((try a.to(i1)) == -1);
186186
187 try a.set(-8);187 try a.set(-8);
188 testing.expect(a.bitCountTwosComp() == 4);188 try testing.expect(a.bitCountTwosComp() == 4);
189 testing.expect((try a.to(i4)) == -8);189 try testing.expect((try a.to(i4)) == -8);
190190
191 try a.set(127);191 try a.set(127);
192 testing.expect(a.bitCountTwosComp() == 7);192 try testing.expect(a.bitCountTwosComp() == 7);
193 testing.expect((try a.to(u7)) == 127);193 try testing.expect((try a.to(u7)) == 127);
194194
195 try a.set(-128);195 try a.set(-128);
196 testing.expect(a.bitCountTwosComp() == 8);196 try testing.expect(a.bitCountTwosComp() == 8);
197 testing.expect((try a.to(i8)) == -128);197 try testing.expect((try a.to(i8)) == -128);
198198
199 try a.set(-129);199 try a.set(-129);
200 testing.expect(a.bitCountTwosComp() == 9);200 try testing.expect(a.bitCountTwosComp() == 9);
201 testing.expect((try a.to(i9)) == -129);201 try testing.expect((try a.to(i9)) == -129);
202}202}
203203
204test "big.int fits" {204test "big.int fits" {
...@@ -206,27 +206,27 @@ test "big.int fits" {...@@ -206,27 +206,27 @@ test "big.int fits" {
206 defer a.deinit();206 defer a.deinit();
207207
208 try a.set(0);208 try a.set(0);
209 testing.expect(a.fits(u0));209 try testing.expect(a.fits(u0));
210 testing.expect(a.fits(i0));210 try testing.expect(a.fits(i0));
211211
212 try a.set(255);212 try a.set(255);
213 testing.expect(!a.fits(u0));213 try testing.expect(!a.fits(u0));
214 testing.expect(!a.fits(u1));214 try testing.expect(!a.fits(u1));
215 testing.expect(!a.fits(i8));215 try testing.expect(!a.fits(i8));
216 testing.expect(a.fits(u8));216 try testing.expect(a.fits(u8));
217 testing.expect(a.fits(u9));217 try testing.expect(a.fits(u9));
218 testing.expect(a.fits(i9));218 try testing.expect(a.fits(i9));
219219
220 try a.set(-128);220 try a.set(-128);
221 testing.expect(!a.fits(i7));221 try testing.expect(!a.fits(i7));
222 testing.expect(a.fits(i8));222 try testing.expect(a.fits(i8));
223 testing.expect(a.fits(i9));223 try testing.expect(a.fits(i9));
224 testing.expect(!a.fits(u9));224 try testing.expect(!a.fits(u9));
225225
226 try a.set(0x1ffffffffeeeeeeee);226 try a.set(0x1ffffffffeeeeeeee);
227 testing.expect(!a.fits(u32));227 try testing.expect(!a.fits(u32));
228 testing.expect(!a.fits(u64));228 try testing.expect(!a.fits(u64));
229 testing.expect(a.fits(u65));229 try testing.expect(a.fits(u65));
230}230}
231231
232test "big.int string set" {232test "big.int string set" {
...@@ -234,7 +234,7 @@ test "big.int string set" {...@@ -234,7 +234,7 @@ test "big.int string set" {
234 defer a.deinit();234 defer a.deinit();
235235
236 try a.setString(10, "120317241209124781241290847124");236 try a.setString(10, "120317241209124781241290847124");
237 testing.expect((try a.to(u128)) == 120317241209124781241290847124);237 try testing.expect((try a.to(u128)) == 120317241209124781241290847124);
238}238}
239239
240test "big.int string negative" {240test "big.int string negative" {
...@@ -242,7 +242,7 @@ test "big.int string negative" {...@@ -242,7 +242,7 @@ test "big.int string negative" {
242 defer a.deinit();242 defer a.deinit();
243243
244 try a.setString(10, "-1023");244 try a.setString(10, "-1023");
245 testing.expect((try a.to(i32)) == -1023);245 try testing.expect((try a.to(i32)) == -1023);
246}246}
247247
248test "big.int string set number with underscores" {248test "big.int string set number with underscores" {
...@@ -250,7 +250,7 @@ test "big.int string set number with underscores" {...@@ -250,7 +250,7 @@ test "big.int string set number with underscores" {
250 defer a.deinit();250 defer a.deinit();
251251
252 try a.setString(10, "__1_2_0_3_1_7_2_4_1_2_0_____9_1__2__4_7_8_1_2_4_1_2_9_0_8_4_7_1_2_4___");252 try a.setString(10, "__1_2_0_3_1_7_2_4_1_2_0_____9_1__2__4_7_8_1_2_4_1_2_9_0_8_4_7_1_2_4___");
253 testing.expect((try a.to(u128)) == 120317241209124781241290847124);253 try testing.expect((try a.to(u128)) == 120317241209124781241290847124);
254}254}
255255
256test "big.int string set case insensitive number" {256test "big.int string set case insensitive number" {
...@@ -258,19 +258,19 @@ test "big.int string set case insensitive number" {...@@ -258,19 +258,19 @@ test "big.int string set case insensitive number" {
258 defer a.deinit();258 defer a.deinit();
259259
260 try a.setString(16, "aB_cD_eF");260 try a.setString(16, "aB_cD_eF");
261 testing.expect((try a.to(u32)) == 0xabcdef);261 try testing.expect((try a.to(u32)) == 0xabcdef);
262}262}
263263
264test "big.int string set bad char error" {264test "big.int string set bad char error" {
265 var a = try Managed.init(testing.allocator);265 var a = try Managed.init(testing.allocator);
266 defer a.deinit();266 defer a.deinit();
267 testing.expectError(error.InvalidCharacter, a.setString(10, "x"));267 try testing.expectError(error.InvalidCharacter, a.setString(10, "x"));
268}268}
269269
270test "big.int string set bad base error" {270test "big.int string set bad base error" {
271 var a = try Managed.init(testing.allocator);271 var a = try Managed.init(testing.allocator);
272 defer a.deinit();272 defer a.deinit();
273 testing.expectError(error.InvalidBase, a.setString(45, "10"));273 try testing.expectError(error.InvalidBase, a.setString(45, "10"));
274}274}
275275
276test "big.int string to" {276test "big.int string to" {
...@@ -281,14 +281,14 @@ test "big.int string to" {...@@ -281,14 +281,14 @@ test "big.int string to" {
281 defer testing.allocator.free(as);281 defer testing.allocator.free(as);
282 const es = "120317241209124781241290847124";282 const es = "120317241209124781241290847124";
283283
284 testing.expect(mem.eql(u8, as, es));284 try testing.expect(mem.eql(u8, as, es));
285}285}
286286
287test "big.int string to base base error" {287test "big.int string to base base error" {
288 var a = try Managed.initSet(testing.allocator, 0xffffffff);288 var a = try Managed.initSet(testing.allocator, 0xffffffff);
289 defer a.deinit();289 defer a.deinit();
290290
291 testing.expectError(error.InvalidBase, a.toString(testing.allocator, 45, false));291 try testing.expectError(error.InvalidBase, a.toString(testing.allocator, 45, false));
292}292}
293293
294test "big.int string to base 2" {294test "big.int string to base 2" {
...@@ -299,7 +299,7 @@ test "big.int string to base 2" {...@@ -299,7 +299,7 @@ test "big.int string to base 2" {
299 defer testing.allocator.free(as);299 defer testing.allocator.free(as);
300 const es = "-1011";300 const es = "-1011";
301301
302 testing.expect(mem.eql(u8, as, es));302 try testing.expect(mem.eql(u8, as, es));
303}303}
304304
305test "big.int string to base 16" {305test "big.int string to base 16" {
...@@ -310,7 +310,7 @@ test "big.int string to base 16" {...@@ -310,7 +310,7 @@ test "big.int string to base 16" {
310 defer testing.allocator.free(as);310 defer testing.allocator.free(as);
311 const es = "efffffff00000001eeeeeeefaaaaaaab";311 const es = "efffffff00000001eeeeeeefaaaaaaab";
312312
313 testing.expect(mem.eql(u8, as, es));313 try testing.expect(mem.eql(u8, as, es));
314}314}
315315
316test "big.int neg string to" {316test "big.int neg string to" {
...@@ -321,7 +321,7 @@ test "big.int neg string to" {...@@ -321,7 +321,7 @@ test "big.int neg string to" {
321 defer testing.allocator.free(as);321 defer testing.allocator.free(as);
322 const es = "-123907434";322 const es = "-123907434";
323323
324 testing.expect(mem.eql(u8, as, es));324 try testing.expect(mem.eql(u8, as, es));
325}325}
326326
327test "big.int zero string to" {327test "big.int zero string to" {
...@@ -332,7 +332,7 @@ test "big.int zero string to" {...@@ -332,7 +332,7 @@ test "big.int zero string to" {
332 defer testing.allocator.free(as);332 defer testing.allocator.free(as);
333 const es = "0";333 const es = "0";
334334
335 testing.expect(mem.eql(u8, as, es));335 try testing.expect(mem.eql(u8, as, es));
336}336}
337337
338test "big.int clone" {338test "big.int clone" {
...@@ -341,12 +341,12 @@ test "big.int clone" {...@@ -341,12 +341,12 @@ test "big.int clone" {
341 var b = try a.clone();341 var b = try a.clone();
342 defer b.deinit();342 defer b.deinit();
343343
344 testing.expect((try a.to(u32)) == 1234);344 try testing.expect((try a.to(u32)) == 1234);
345 testing.expect((try b.to(u32)) == 1234);345 try testing.expect((try b.to(u32)) == 1234);
346346
347 try a.set(77);347 try a.set(77);
348 testing.expect((try a.to(u32)) == 77);348 try testing.expect((try a.to(u32)) == 77);
349 testing.expect((try b.to(u32)) == 1234);349 try testing.expect((try b.to(u32)) == 1234);
350}350}
351351
352test "big.int swap" {352test "big.int swap" {
...@@ -355,20 +355,20 @@ test "big.int swap" {...@@ -355,20 +355,20 @@ test "big.int swap" {
355 var b = try Managed.initSet(testing.allocator, 5678);355 var b = try Managed.initSet(testing.allocator, 5678);
356 defer b.deinit();356 defer b.deinit();
357357
358 testing.expect((try a.to(u32)) == 1234);358 try testing.expect((try a.to(u32)) == 1234);
359 testing.expect((try b.to(u32)) == 5678);359 try testing.expect((try b.to(u32)) == 5678);
360360
361 a.swap(&b);361 a.swap(&b);
362362
363 testing.expect((try a.to(u32)) == 5678);363 try testing.expect((try a.to(u32)) == 5678);
364 testing.expect((try b.to(u32)) == 1234);364 try testing.expect((try b.to(u32)) == 1234);
365}365}
366366
367test "big.int to negative" {367test "big.int to negative" {
368 var a = try Managed.initSet(testing.allocator, -10);368 var a = try Managed.initSet(testing.allocator, -10);
369 defer a.deinit();369 defer a.deinit();
370370
371 testing.expect((try a.to(i32)) == -10);371 try testing.expect((try a.to(i32)) == -10);
372}372}
373373
374test "big.int compare" {374test "big.int compare" {
...@@ -377,8 +377,8 @@ test "big.int compare" {...@@ -377,8 +377,8 @@ test "big.int compare" {
377 var b = try Managed.initSet(testing.allocator, 10);377 var b = try Managed.initSet(testing.allocator, 10);
378 defer b.deinit();378 defer b.deinit();
379379
380 testing.expect(a.orderAbs(b) == .gt);380 try testing.expect(a.orderAbs(b) == .gt);
381 testing.expect(a.order(b) == .lt);381 try testing.expect(a.order(b) == .lt);
382}382}
383383
384test "big.int compare similar" {384test "big.int compare similar" {
...@@ -387,8 +387,8 @@ test "big.int compare similar" {...@@ -387,8 +387,8 @@ test "big.int compare similar" {
387 var b = try Managed.initSet(testing.allocator, 0xffffffffeeeeeeeeffffffffeeeeeeef);387 var b = try Managed.initSet(testing.allocator, 0xffffffffeeeeeeeeffffffffeeeeeeef);
388 defer b.deinit();388 defer b.deinit();
389389
390 testing.expect(a.orderAbs(b) == .lt);390 try testing.expect(a.orderAbs(b) == .lt);
391 testing.expect(b.orderAbs(a) == .gt);391 try testing.expect(b.orderAbs(a) == .gt);
392}392}
393393
394test "big.int compare different limb size" {394test "big.int compare different limb size" {
...@@ -397,8 +397,8 @@ test "big.int compare different limb size" {...@@ -397,8 +397,8 @@ test "big.int compare different limb size" {
397 var b = try Managed.initSet(testing.allocator, 1);397 var b = try Managed.initSet(testing.allocator, 1);
398 defer b.deinit();398 defer b.deinit();
399399
400 testing.expect(a.orderAbs(b) == .gt);400 try testing.expect(a.orderAbs(b) == .gt);
401 testing.expect(b.orderAbs(a) == .lt);401 try testing.expect(b.orderAbs(a) == .lt);
402}402}
403403
404test "big.int compare multi-limb" {404test "big.int compare multi-limb" {
...@@ -407,8 +407,8 @@ test "big.int compare multi-limb" {...@@ -407,8 +407,8 @@ test "big.int compare multi-limb" {
407 var b = try Managed.initSet(testing.allocator, 0x7777777799999999ffffeeeeffffeeeeffffeeeee);407 var b = try Managed.initSet(testing.allocator, 0x7777777799999999ffffeeeeffffeeeeffffeeeee);
408 defer b.deinit();408 defer b.deinit();
409409
410 testing.expect(a.orderAbs(b) == .gt);410 try testing.expect(a.orderAbs(b) == .gt);
411 testing.expect(a.order(b) == .lt);411 try testing.expect(a.order(b) == .lt);
412}412}
413413
414test "big.int equality" {414test "big.int equality" {
...@@ -417,8 +417,8 @@ test "big.int equality" {...@@ -417,8 +417,8 @@ test "big.int equality" {
417 var b = try Managed.initSet(testing.allocator, -0xffffffff1);417 var b = try Managed.initSet(testing.allocator, -0xffffffff1);
418 defer b.deinit();418 defer b.deinit();
419419
420 testing.expect(a.eqAbs(b));420 try testing.expect(a.eqAbs(b));
421 testing.expect(!a.eq(b));421 try testing.expect(!a.eq(b));
422}422}
423423
424test "big.int abs" {424test "big.int abs" {
...@@ -426,10 +426,10 @@ test "big.int abs" {...@@ -426,10 +426,10 @@ test "big.int abs" {
426 defer a.deinit();426 defer a.deinit();
427427
428 a.abs();428 a.abs();
429 testing.expect((try a.to(u32)) == 5);429 try testing.expect((try a.to(u32)) == 5);
430430
431 a.abs();431 a.abs();
432 testing.expect((try a.to(u32)) == 5);432 try testing.expect((try a.to(u32)) == 5);
433}433}
434434
435test "big.int negate" {435test "big.int negate" {
...@@ -437,10 +437,10 @@ test "big.int negate" {...@@ -437,10 +437,10 @@ test "big.int negate" {
437 defer a.deinit();437 defer a.deinit();
438438
439 a.negate();439 a.negate();
440 testing.expect((try a.to(i32)) == -5);440 try testing.expect((try a.to(i32)) == -5);
441441
442 a.negate();442 a.negate();
443 testing.expect((try a.to(i32)) == 5);443 try testing.expect((try a.to(i32)) == 5);
444}444}
445445
446test "big.int add single-single" {446test "big.int add single-single" {
...@@ -453,7 +453,7 @@ test "big.int add single-single" {...@@ -453,7 +453,7 @@ test "big.int add single-single" {
453 defer c.deinit();453 defer c.deinit();
454 try c.add(a.toConst(), b.toConst());454 try c.add(a.toConst(), b.toConst());
455455
456 testing.expect((try c.to(u32)) == 55);456 try testing.expect((try c.to(u32)) == 55);
457}457}
458458
459test "big.int add multi-single" {459test "big.int add multi-single" {
...@@ -466,10 +466,10 @@ test "big.int add multi-single" {...@@ -466,10 +466,10 @@ test "big.int add multi-single" {
466 defer c.deinit();466 defer c.deinit();
467467
468 try c.add(a.toConst(), b.toConst());468 try c.add(a.toConst(), b.toConst());
469 testing.expect((try c.to(DoubleLimb)) == maxInt(Limb) + 2);469 try testing.expect((try c.to(DoubleLimb)) == maxInt(Limb) + 2);
470470
471 try c.add(b.toConst(), a.toConst());471 try c.add(b.toConst(), a.toConst());
472 testing.expect((try c.to(DoubleLimb)) == maxInt(Limb) + 2);472 try testing.expect((try c.to(DoubleLimb)) == maxInt(Limb) + 2);
473}473}
474474
475test "big.int add multi-multi" {475test "big.int add multi-multi" {
...@@ -484,7 +484,7 @@ test "big.int add multi-multi" {...@@ -484,7 +484,7 @@ test "big.int add multi-multi" {
484 defer c.deinit();484 defer c.deinit();
485 try c.add(a.toConst(), b.toConst());485 try c.add(a.toConst(), b.toConst());
486486
487 testing.expect((try c.to(u128)) == op1 + op2);487 try testing.expect((try c.to(u128)) == op1 + op2);
488}488}
489489
490test "big.int add zero-zero" {490test "big.int add zero-zero" {
...@@ -497,7 +497,7 @@ test "big.int add zero-zero" {...@@ -497,7 +497,7 @@ test "big.int add zero-zero" {
497 defer c.deinit();497 defer c.deinit();
498 try c.add(a.toConst(), b.toConst());498 try c.add(a.toConst(), b.toConst());
499499
500 testing.expect((try c.to(u32)) == 0);500 try testing.expect((try c.to(u32)) == 0);
501}501}
502502
503test "big.int add alias multi-limb nonzero-zero" {503test "big.int add alias multi-limb nonzero-zero" {
...@@ -509,7 +509,7 @@ test "big.int add alias multi-limb nonzero-zero" {...@@ -509,7 +509,7 @@ test "big.int add alias multi-limb nonzero-zero" {
509509
510 try a.add(a.toConst(), b.toConst());510 try a.add(a.toConst(), b.toConst());
511511
512 testing.expect((try a.to(u128)) == op1);512 try testing.expect((try a.to(u128)) == op1);
513}513}
514514
515test "big.int add sign" {515test "big.int add sign" {
...@@ -526,16 +526,16 @@ test "big.int add sign" {...@@ -526,16 +526,16 @@ test "big.int add sign" {
526 defer neg_two.deinit();526 defer neg_two.deinit();
527527
528 try a.add(one.toConst(), two.toConst());528 try a.add(one.toConst(), two.toConst());
529 testing.expect((try a.to(i32)) == 3);529 try testing.expect((try a.to(i32)) == 3);
530530
531 try a.add(neg_one.toConst(), two.toConst());531 try a.add(neg_one.toConst(), two.toConst());
532 testing.expect((try a.to(i32)) == 1);532 try testing.expect((try a.to(i32)) == 1);
533533
534 try a.add(one.toConst(), neg_two.toConst());534 try a.add(one.toConst(), neg_two.toConst());
535 testing.expect((try a.to(i32)) == -1);535 try testing.expect((try a.to(i32)) == -1);
536536
537 try a.add(neg_one.toConst(), neg_two.toConst());537 try a.add(neg_one.toConst(), neg_two.toConst());
538 testing.expect((try a.to(i32)) == -3);538 try testing.expect((try a.to(i32)) == -3);
539}539}
540540
541test "big.int sub single-single" {541test "big.int sub single-single" {
...@@ -548,7 +548,7 @@ test "big.int sub single-single" {...@@ -548,7 +548,7 @@ test "big.int sub single-single" {
548 defer c.deinit();548 defer c.deinit();
549 try c.sub(a.toConst(), b.toConst());549 try c.sub(a.toConst(), b.toConst());
550550
551 testing.expect((try c.to(u32)) == 45);551 try testing.expect((try c.to(u32)) == 45);
552}552}
553553
554test "big.int sub multi-single" {554test "big.int sub multi-single" {
...@@ -561,7 +561,7 @@ test "big.int sub multi-single" {...@@ -561,7 +561,7 @@ test "big.int sub multi-single" {
561 defer c.deinit();561 defer c.deinit();
562 try c.sub(a.toConst(), b.toConst());562 try c.sub(a.toConst(), b.toConst());
563563
564 testing.expect((try c.to(Limb)) == maxInt(Limb));564 try testing.expect((try c.to(Limb)) == maxInt(Limb));
565}565}
566566
567test "big.int sub multi-multi" {567test "big.int sub multi-multi" {
...@@ -577,7 +577,7 @@ test "big.int sub multi-multi" {...@@ -577,7 +577,7 @@ test "big.int sub multi-multi" {
577 defer c.deinit();577 defer c.deinit();
578 try c.sub(a.toConst(), b.toConst());578 try c.sub(a.toConst(), b.toConst());
579579
580 testing.expect((try c.to(u128)) == op1 - op2);580 try testing.expect((try c.to(u128)) == op1 - op2);
581}581}
582582
583test "big.int sub equal" {583test "big.int sub equal" {
...@@ -590,7 +590,7 @@ test "big.int sub equal" {...@@ -590,7 +590,7 @@ test "big.int sub equal" {
590 defer c.deinit();590 defer c.deinit();
591 try c.sub(a.toConst(), b.toConst());591 try c.sub(a.toConst(), b.toConst());
592592
593 testing.expect((try c.to(u32)) == 0);593 try testing.expect((try c.to(u32)) == 0);
594}594}
595595
596test "big.int sub sign" {596test "big.int sub sign" {
...@@ -607,19 +607,19 @@ test "big.int sub sign" {...@@ -607,19 +607,19 @@ test "big.int sub sign" {
607 defer neg_two.deinit();607 defer neg_two.deinit();
608608
609 try a.sub(one.toConst(), two.toConst());609 try a.sub(one.toConst(), two.toConst());
610 testing.expect((try a.to(i32)) == -1);610 try testing.expect((try a.to(i32)) == -1);
611611
612 try a.sub(neg_one.toConst(), two.toConst());612 try a.sub(neg_one.toConst(), two.toConst());
613 testing.expect((try a.to(i32)) == -3);613 try testing.expect((try a.to(i32)) == -3);
614614
615 try a.sub(one.toConst(), neg_two.toConst());615 try a.sub(one.toConst(), neg_two.toConst());
616 testing.expect((try a.to(i32)) == 3);616 try testing.expect((try a.to(i32)) == 3);
617617
618 try a.sub(neg_one.toConst(), neg_two.toConst());618 try a.sub(neg_one.toConst(), neg_two.toConst());
619 testing.expect((try a.to(i32)) == 1);619 try testing.expect((try a.to(i32)) == 1);
620620
621 try a.sub(neg_two.toConst(), neg_one.toConst());621 try a.sub(neg_two.toConst(), neg_one.toConst());
622 testing.expect((try a.to(i32)) == -1);622 try testing.expect((try a.to(i32)) == -1);
623}623}
624624
625test "big.int mul single-single" {625test "big.int mul single-single" {
...@@ -632,7 +632,7 @@ test "big.int mul single-single" {...@@ -632,7 +632,7 @@ test "big.int mul single-single" {
632 defer c.deinit();632 defer c.deinit();
633 try c.mul(a.toConst(), b.toConst());633 try c.mul(a.toConst(), b.toConst());
634634
635 testing.expect((try c.to(u64)) == 250);635 try testing.expect((try c.to(u64)) == 250);
636}636}
637637
638test "big.int mul multi-single" {638test "big.int mul multi-single" {
...@@ -645,7 +645,7 @@ test "big.int mul multi-single" {...@@ -645,7 +645,7 @@ test "big.int mul multi-single" {
645 defer c.deinit();645 defer c.deinit();
646 try c.mul(a.toConst(), b.toConst());646 try c.mul(a.toConst(), b.toConst());
647647
648 testing.expect((try c.to(DoubleLimb)) == 2 * maxInt(Limb));648 try testing.expect((try c.to(DoubleLimb)) == 2 * maxInt(Limb));
649}649}
650650
651test "big.int mul multi-multi" {651test "big.int mul multi-multi" {
...@@ -660,7 +660,7 @@ test "big.int mul multi-multi" {...@@ -660,7 +660,7 @@ test "big.int mul multi-multi" {
660 defer c.deinit();660 defer c.deinit();
661 try c.mul(a.toConst(), b.toConst());661 try c.mul(a.toConst(), b.toConst());
662662
663 testing.expect((try c.to(u256)) == op1 * op2);663 try testing.expect((try c.to(u256)) == op1 * op2);
664}664}
665665
666test "big.int mul alias r with a" {666test "big.int mul alias r with a" {
...@@ -671,7 +671,7 @@ test "big.int mul alias r with a" {...@@ -671,7 +671,7 @@ test "big.int mul alias r with a" {
671671
672 try a.mul(a.toConst(), b.toConst());672 try a.mul(a.toConst(), b.toConst());
673673
674 testing.expect((try a.to(DoubleLimb)) == 2 * maxInt(Limb));674 try testing.expect((try a.to(DoubleLimb)) == 2 * maxInt(Limb));
675}675}
676676
677test "big.int mul alias r with b" {677test "big.int mul alias r with b" {
...@@ -682,7 +682,7 @@ test "big.int mul alias r with b" {...@@ -682,7 +682,7 @@ test "big.int mul alias r with b" {
682682
683 try a.mul(b.toConst(), a.toConst());683 try a.mul(b.toConst(), a.toConst());
684684
685 testing.expect((try a.to(DoubleLimb)) == 2 * maxInt(Limb));685 try testing.expect((try a.to(DoubleLimb)) == 2 * maxInt(Limb));
686}686}
687687
688test "big.int mul alias r with a and b" {688test "big.int mul alias r with a and b" {
...@@ -691,7 +691,7 @@ test "big.int mul alias r with a and b" {...@@ -691,7 +691,7 @@ test "big.int mul alias r with a and b" {
691691
692 try a.mul(a.toConst(), a.toConst());692 try a.mul(a.toConst(), a.toConst());
693693
694 testing.expect((try a.to(DoubleLimb)) == maxInt(Limb) * maxInt(Limb));694 try testing.expect((try a.to(DoubleLimb)) == maxInt(Limb) * maxInt(Limb));
695}695}
696696
697test "big.int mul a*0" {697test "big.int mul a*0" {
...@@ -704,7 +704,7 @@ test "big.int mul a*0" {...@@ -704,7 +704,7 @@ test "big.int mul a*0" {
704 defer c.deinit();704 defer c.deinit();
705 try c.mul(a.toConst(), b.toConst());705 try c.mul(a.toConst(), b.toConst());
706706
707 testing.expect((try c.to(u32)) == 0);707 try testing.expect((try c.to(u32)) == 0);
708}708}
709709
710test "big.int mul 0*0" {710test "big.int mul 0*0" {
...@@ -717,7 +717,7 @@ test "big.int mul 0*0" {...@@ -717,7 +717,7 @@ test "big.int mul 0*0" {
717 defer c.deinit();717 defer c.deinit();
718 try c.mul(a.toConst(), b.toConst());718 try c.mul(a.toConst(), b.toConst());
719719
720 testing.expect((try c.to(u32)) == 0);720 try testing.expect((try c.to(u32)) == 0);
721}721}
722722
723test "big.int mul large" {723test "big.int mul large" {
...@@ -738,7 +738,7 @@ test "big.int mul large" {...@@ -738,7 +738,7 @@ test "big.int mul large" {
738 try b.mul(a.toConst(), a.toConst());738 try b.mul(a.toConst(), a.toConst());
739 try c.sqr(a.toConst());739 try c.sqr(a.toConst());
740740
741 testing.expect(b.eq(c));741 try testing.expect(b.eq(c));
742}742}
743743
744test "big.int div single-single no rem" {744test "big.int div single-single no rem" {
...@@ -753,8 +753,8 @@ test "big.int div single-single no rem" {...@@ -753,8 +753,8 @@ test "big.int div single-single no rem" {
753 defer r.deinit();753 defer r.deinit();
754 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());754 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
755755
756 testing.expect((try q.to(u32)) == 10);756 try testing.expect((try q.to(u32)) == 10);
757 testing.expect((try r.to(u32)) == 0);757 try testing.expect((try r.to(u32)) == 0);
758}758}
759759
760test "big.int div single-single with rem" {760test "big.int div single-single with rem" {
...@@ -769,8 +769,8 @@ test "big.int div single-single with rem" {...@@ -769,8 +769,8 @@ test "big.int div single-single with rem" {
769 defer r.deinit();769 defer r.deinit();
770 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());770 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
771771
772 testing.expect((try q.to(u32)) == 9);772 try testing.expect((try q.to(u32)) == 9);
773 testing.expect((try r.to(u32)) == 4);773 try testing.expect((try r.to(u32)) == 4);
774}774}
775775
776test "big.int div multi-single no rem" {776test "big.int div multi-single no rem" {
...@@ -788,8 +788,8 @@ test "big.int div multi-single no rem" {...@@ -788,8 +788,8 @@ test "big.int div multi-single no rem" {
788 defer r.deinit();788 defer r.deinit();
789 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());789 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
790790
791 testing.expect((try q.to(u64)) == op1 / op2);791 try testing.expect((try q.to(u64)) == op1 / op2);
792 testing.expect((try r.to(u64)) == 0);792 try testing.expect((try r.to(u64)) == 0);
793}793}
794794
795test "big.int div multi-single with rem" {795test "big.int div multi-single with rem" {
...@@ -807,8 +807,8 @@ test "big.int div multi-single with rem" {...@@ -807,8 +807,8 @@ test "big.int div multi-single with rem" {
807 defer r.deinit();807 defer r.deinit();
808 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());808 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
809809
810 testing.expect((try q.to(u64)) == op1 / op2);810 try testing.expect((try q.to(u64)) == op1 / op2);
811 testing.expect((try r.to(u64)) == 3);811 try testing.expect((try r.to(u64)) == 3);
812}812}
813813
814test "big.int div multi>2-single" {814test "big.int div multi>2-single" {
...@@ -826,8 +826,8 @@ test "big.int div multi>2-single" {...@@ -826,8 +826,8 @@ test "big.int div multi>2-single" {
826 defer r.deinit();826 defer r.deinit();
827 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());827 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
828828
829 testing.expect((try q.to(u128)) == op1 / op2);829 try testing.expect((try q.to(u128)) == op1 / op2);
830 testing.expect((try r.to(u32)) == 0x3e4e);830 try testing.expect((try r.to(u32)) == 0x3e4e);
831}831}
832832
833test "big.int div single-single q < r" {833test "big.int div single-single q < r" {
...@@ -842,8 +842,8 @@ test "big.int div single-single q < r" {...@@ -842,8 +842,8 @@ test "big.int div single-single q < r" {
842 defer r.deinit();842 defer r.deinit();
843 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());843 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
844844
845 testing.expect((try q.to(u64)) == 0);845 try testing.expect((try q.to(u64)) == 0);
846 testing.expect((try r.to(u64)) == 0x0078f432);846 try testing.expect((try r.to(u64)) == 0x0078f432);
847}847}
848848
849test "big.int div single-single q == r" {849test "big.int div single-single q == r" {
...@@ -858,8 +858,8 @@ test "big.int div single-single q == r" {...@@ -858,8 +858,8 @@ test "big.int div single-single q == r" {
858 defer r.deinit();858 defer r.deinit();
859 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());859 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
860860
861 testing.expect((try q.to(u64)) == 1);861 try testing.expect((try q.to(u64)) == 1);
862 testing.expect((try r.to(u64)) == 0);862 try testing.expect((try r.to(u64)) == 0);
863}863}
864864
865test "big.int div q=0 alias" {865test "big.int div q=0 alias" {
...@@ -870,8 +870,8 @@ test "big.int div q=0 alias" {...@@ -870,8 +870,8 @@ test "big.int div q=0 alias" {
870870
871 try Managed.divTrunc(&a, &b, a.toConst(), b.toConst());871 try Managed.divTrunc(&a, &b, a.toConst(), b.toConst());
872872
873 testing.expect((try a.to(u64)) == 0);873 try testing.expect((try a.to(u64)) == 0);
874 testing.expect((try b.to(u64)) == 3);874 try testing.expect((try b.to(u64)) == 3);
875}875}
876876
877test "big.int div multi-multi q < r" {877test "big.int div multi-multi q < r" {
...@@ -888,8 +888,8 @@ test "big.int div multi-multi q < r" {...@@ -888,8 +888,8 @@ test "big.int div multi-multi q < r" {
888 defer r.deinit();888 defer r.deinit();
889 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());889 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
890890
891 testing.expect((try q.to(u128)) == 0);891 try testing.expect((try q.to(u128)) == 0);
892 testing.expect((try r.to(u128)) == op1);892 try testing.expect((try r.to(u128)) == op1);
893}893}
894894
895test "big.int div trunc single-single +/+" {895test "big.int div trunc single-single +/+" {
...@@ -912,8 +912,8 @@ test "big.int div trunc single-single +/+" {...@@ -912,8 +912,8 @@ test "big.int div trunc single-single +/+" {
912 const eq = @divTrunc(u, v);912 const eq = @divTrunc(u, v);
913 const er = @mod(u, v);913 const er = @mod(u, v);
914914
915 testing.expect((try q.to(i32)) == eq);915 try testing.expect((try q.to(i32)) == eq);
916 testing.expect((try r.to(i32)) == er);916 try testing.expect((try r.to(i32)) == er);
917}917}
918918
919test "big.int div trunc single-single -/+" {919test "big.int div trunc single-single -/+" {
...@@ -936,8 +936,8 @@ test "big.int div trunc single-single -/+" {...@@ -936,8 +936,8 @@ test "big.int div trunc single-single -/+" {
936 const eq = -1;936 const eq = -1;
937 const er = -2;937 const er = -2;
938938
939 testing.expect((try q.to(i32)) == eq);939 try testing.expect((try q.to(i32)) == eq);
940 testing.expect((try r.to(i32)) == er);940 try testing.expect((try r.to(i32)) == er);
941}941}
942942
943test "big.int div trunc single-single +/-" {943test "big.int div trunc single-single +/-" {
...@@ -960,8 +960,8 @@ test "big.int div trunc single-single +/-" {...@@ -960,8 +960,8 @@ test "big.int div trunc single-single +/-" {
960 const eq = -1;960 const eq = -1;
961 const er = 2;961 const er = 2;
962962
963 testing.expect((try q.to(i32)) == eq);963 try testing.expect((try q.to(i32)) == eq);
964 testing.expect((try r.to(i32)) == er);964 try testing.expect((try r.to(i32)) == er);
965}965}
966966
967test "big.int div trunc single-single -/-" {967test "big.int div trunc single-single -/-" {
...@@ -984,8 +984,8 @@ test "big.int div trunc single-single -/-" {...@@ -984,8 +984,8 @@ test "big.int div trunc single-single -/-" {
984 const eq = 1;984 const eq = 1;
985 const er = -2;985 const er = -2;
986986
987 testing.expect((try q.to(i32)) == eq);987 try testing.expect((try q.to(i32)) == eq);
988 testing.expect((try r.to(i32)) == er);988 try testing.expect((try r.to(i32)) == er);
989}989}
990990
991test "big.int div floor single-single +/+" {991test "big.int div floor single-single +/+" {
...@@ -1008,8 +1008,8 @@ test "big.int div floor single-single +/+" {...@@ -1008,8 +1008,8 @@ test "big.int div floor single-single +/+" {
1008 const eq = 1;1008 const eq = 1;
1009 const er = 2;1009 const er = 2;
10101010
1011 testing.expect((try q.to(i32)) == eq);1011 try testing.expect((try q.to(i32)) == eq);
1012 testing.expect((try r.to(i32)) == er);1012 try testing.expect((try r.to(i32)) == er);
1013}1013}
10141014
1015test "big.int div floor single-single -/+" {1015test "big.int div floor single-single -/+" {
...@@ -1032,8 +1032,8 @@ test "big.int div floor single-single -/+" {...@@ -1032,8 +1032,8 @@ test "big.int div floor single-single -/+" {
1032 const eq = -2;1032 const eq = -2;
1033 const er = 1;1033 const er = 1;
10341034
1035 testing.expect((try q.to(i32)) == eq);1035 try testing.expect((try q.to(i32)) == eq);
1036 testing.expect((try r.to(i32)) == er);1036 try testing.expect((try r.to(i32)) == er);
1037}1037}
10381038
1039test "big.int div floor single-single +/-" {1039test "big.int div floor single-single +/-" {
...@@ -1056,8 +1056,8 @@ test "big.int div floor single-single +/-" {...@@ -1056,8 +1056,8 @@ test "big.int div floor single-single +/-" {
1056 const eq = -2;1056 const eq = -2;
1057 const er = -1;1057 const er = -1;
10581058
1059 testing.expect((try q.to(i32)) == eq);1059 try testing.expect((try q.to(i32)) == eq);
1060 testing.expect((try r.to(i32)) == er);1060 try testing.expect((try r.to(i32)) == er);
1061}1061}
10621062
1063test "big.int div floor single-single -/-" {1063test "big.int div floor single-single -/-" {
...@@ -1080,8 +1080,8 @@ test "big.int div floor single-single -/-" {...@@ -1080,8 +1080,8 @@ test "big.int div floor single-single -/-" {
1080 const eq = 1;1080 const eq = 1;
1081 const er = -2;1081 const er = -2;
10821082
1083 testing.expect((try q.to(i32)) == eq);1083 try testing.expect((try q.to(i32)) == eq);
1084 testing.expect((try r.to(i32)) == er);1084 try testing.expect((try r.to(i32)) == er);
1085}1085}
10861086
1087test "big.int div multi-multi with rem" {1087test "big.int div multi-multi with rem" {
...@@ -1096,8 +1096,8 @@ test "big.int div multi-multi with rem" {...@@ -1096,8 +1096,8 @@ test "big.int div multi-multi with rem" {
1096 defer r.deinit();1096 defer r.deinit();
1097 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());1097 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
10981098
1099 testing.expect((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b);1099 try testing.expect((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b);
1100 testing.expect((try r.to(u128)) == 0x28de0acacd806823638);1100 try testing.expect((try r.to(u128)) == 0x28de0acacd806823638);
1101}1101}
11021102
1103test "big.int div multi-multi no rem" {1103test "big.int div multi-multi no rem" {
...@@ -1112,8 +1112,8 @@ test "big.int div multi-multi no rem" {...@@ -1112,8 +1112,8 @@ test "big.int div multi-multi no rem" {
1112 defer r.deinit();1112 defer r.deinit();
1113 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());1113 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
11141114
1115 testing.expect((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b);1115 try testing.expect((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b);
1116 testing.expect((try r.to(u128)) == 0);1116 try testing.expect((try r.to(u128)) == 0);
1117}1117}
11181118
1119test "big.int div multi-multi (2 branch)" {1119test "big.int div multi-multi (2 branch)" {
...@@ -1128,8 +1128,8 @@ test "big.int div multi-multi (2 branch)" {...@@ -1128,8 +1128,8 @@ test "big.int div multi-multi (2 branch)" {
1128 defer r.deinit();1128 defer r.deinit();
1129 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());1129 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
11301130
1131 testing.expect((try q.to(u128)) == 0x10000000000000000);1131 try testing.expect((try q.to(u128)) == 0x10000000000000000);
1132 testing.expect((try r.to(u128)) == 0x44444443444444431111111111111111);1132 try testing.expect((try r.to(u128)) == 0x44444443444444431111111111111111);
1133}1133}
11341134
1135test "big.int div multi-multi (3.1/3.3 branch)" {1135test "big.int div multi-multi (3.1/3.3 branch)" {
...@@ -1144,8 +1144,8 @@ test "big.int div multi-multi (3.1/3.3 branch)" {...@@ -1144,8 +1144,8 @@ test "big.int div multi-multi (3.1/3.3 branch)" {
1144 defer r.deinit();1144 defer r.deinit();
1145 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());1145 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
11461146
1147 testing.expect((try q.to(u128)) == 0xfffffffffffffffffff);1147 try testing.expect((try q.to(u128)) == 0xfffffffffffffffffff);
1148 testing.expect((try r.to(u256)) == 0x1111111111111111111110b12222222222222222282);1148 try testing.expect((try r.to(u256)) == 0x1111111111111111111110b12222222222222222282);
1149}1149}
11501150
1151test "big.int div multi-single zero-limb trailing" {1151test "big.int div multi-single zero-limb trailing" {
...@@ -1162,8 +1162,8 @@ test "big.int div multi-single zero-limb trailing" {...@@ -1162,8 +1162,8 @@ test "big.int div multi-single zero-limb trailing" {
11621162
1163 var expected = try Managed.initSet(testing.allocator, 0x6000000000000000000000000000000000000000000000000);1163 var expected = try Managed.initSet(testing.allocator, 0x6000000000000000000000000000000000000000000000000);
1164 defer expected.deinit();1164 defer expected.deinit();
1165 testing.expect(q.eq(expected));1165 try testing.expect(q.eq(expected));
1166 testing.expect(r.eqZero());1166 try testing.expect(r.eqZero());
1167}1167}
11681168
1169test "big.int div multi-multi zero-limb trailing (with rem)" {1169test "big.int div multi-multi zero-limb trailing (with rem)" {
...@@ -1178,11 +1178,11 @@ test "big.int div multi-multi zero-limb trailing (with rem)" {...@@ -1178,11 +1178,11 @@ test "big.int div multi-multi zero-limb trailing (with rem)" {
1178 defer r.deinit();1178 defer r.deinit();
1179 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());1179 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
11801180
1181 testing.expect((try q.to(u128)) == 0x10000000000000000);1181 try testing.expect((try q.to(u128)) == 0x10000000000000000);
11821182
1183 const rs = try r.toString(testing.allocator, 16, false);1183 const rs = try r.toString(testing.allocator, 16, false);
1184 defer testing.allocator.free(rs);1184 defer testing.allocator.free(rs);
1185 testing.expect(std.mem.eql(u8, rs, "4444444344444443111111111111111100000000000000000000000000000000"));1185 try testing.expect(std.mem.eql(u8, rs, "4444444344444443111111111111111100000000000000000000000000000000"));
1186}1186}
11871187
1188test "big.int div multi-multi zero-limb trailing (with rem) and dividend zero-limb count > divisor zero-limb count" {1188test "big.int div multi-multi zero-limb trailing (with rem) and dividend zero-limb count > divisor zero-limb count" {
...@@ -1197,11 +1197,11 @@ test "big.int div multi-multi zero-limb trailing (with rem) and dividend zero-li...@@ -1197,11 +1197,11 @@ test "big.int div multi-multi zero-limb trailing (with rem) and dividend zero-li
1197 defer r.deinit();1197 defer r.deinit();
1198 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());1198 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
11991199
1200 testing.expect((try q.to(u128)) == 0x1);1200 try testing.expect((try q.to(u128)) == 0x1);
12011201
1202 const rs = try r.toString(testing.allocator, 16, false);1202 const rs = try r.toString(testing.allocator, 16, false);
1203 defer testing.allocator.free(rs);1203 defer testing.allocator.free(rs);
1204 testing.expect(std.mem.eql(u8, rs, "444444434444444311111111111111110000000000000000"));1204 try testing.expect(std.mem.eql(u8, rs, "444444434444444311111111111111110000000000000000"));
1205}1205}
12061206
1207test "big.int div multi-multi zero-limb trailing (with rem) and dividend zero-limb count < divisor zero-limb count" {1207test "big.int div multi-multi zero-limb trailing (with rem) and dividend zero-limb count < divisor zero-limb count" {
...@@ -1218,11 +1218,11 @@ test "big.int div multi-multi zero-limb trailing (with rem) and dividend zero-li...@@ -1218,11 +1218,11 @@ test "big.int div multi-multi zero-limb trailing (with rem) and dividend zero-li
12181218
1219 const qs = try q.toString(testing.allocator, 16, false);1219 const qs = try q.toString(testing.allocator, 16, false);
1220 defer testing.allocator.free(qs);1220 defer testing.allocator.free(qs);
1221 testing.expect(std.mem.eql(u8, qs, "10000000000000000820820803105186f"));1221 try testing.expect(std.mem.eql(u8, qs, "10000000000000000820820803105186f"));
12221222
1223 const rs = try r.toString(testing.allocator, 16, false);1223 const rs = try r.toString(testing.allocator, 16, false);
1224 defer testing.allocator.free(rs);1224 defer testing.allocator.free(rs);
1225 testing.expect(std.mem.eql(u8, rs, "4e11f2baa5896a321d463b543d0104e30000000000000000"));1225 try testing.expect(std.mem.eql(u8, rs, "4e11f2baa5896a321d463b543d0104e30000000000000000"));
1226}1226}
12271227
1228test "big.int div multi-multi fuzz case #1" {1228test "big.int div multi-multi fuzz case #1" {
...@@ -1242,11 +1242,11 @@ test "big.int div multi-multi fuzz case #1" {...@@ -1242,11 +1242,11 @@ test "big.int div multi-multi fuzz case #1" {
12421242
1243 const qs = try q.toString(testing.allocator, 16, false);1243 const qs = try q.toString(testing.allocator, 16, false);
1244 defer testing.allocator.free(qs);1244 defer testing.allocator.free(qs);
1245 testing.expect(std.mem.eql(u8, qs, "3ffffffffffffffffffffffffffff0000000000000000000000000000000000001ffffffffffffffffffffffffffff7fffffffe000000000000000000000000000180000000000000000000003fffffbfffffffdfffffffffffffeffff800000100101000000100000000020003fffffdfbfffffe3ffffffffffffeffff7fffc00800a100000017ffe000002000400007efbfff7fe9f00000037ffff3fff7fffa004006100000009ffe00000190038200bf7d2ff7fefe80400060000f7d7f8fbf9401fe38e0403ffc0bdffffa51102c300d7be5ef9df4e5060007b0127ad3fa69f97d0f820b6605ff617ddf7f32ad7a05c0d03f2e7bc78a6000e087a8bbcdc59e07a5a079128a7861f553ddebed7e8e56701756f9ead39b48cd1b0831889ea6ec1fddf643d0565b075ff07e6caea4e2854ec9227fd635ed60a2f5eef2893052ffd54718fa08604acbf6a15e78a467c4a3c53c0278af06c4416573f925491b195e8fd79302cb1aaf7caf4ecfc9aec1254cc969786363ac729f914c6ddcc26738d6b0facd54eba026580aba2eb6482a088b0d224a8852420b91ec1"));1245 try testing.expect(std.mem.eql(u8, qs, "3ffffffffffffffffffffffffffff0000000000000000000000000000000000001ffffffffffffffffffffffffffff7fffffffe000000000000000000000000000180000000000000000000003fffffbfffffffdfffffffffffffeffff800000100101000000100000000020003fffffdfbfffffe3ffffffffffffeffff7fffc00800a100000017ffe000002000400007efbfff7fe9f00000037ffff3fff7fffa004006100000009ffe00000190038200bf7d2ff7fefe80400060000f7d7f8fbf9401fe38e0403ffc0bdffffa51102c300d7be5ef9df4e5060007b0127ad3fa69f97d0f820b6605ff617ddf7f32ad7a05c0d03f2e7bc78a6000e087a8bbcdc59e07a5a079128a7861f553ddebed7e8e56701756f9ead39b48cd1b0831889ea6ec1fddf643d0565b075ff07e6caea4e2854ec9227fd635ed60a2f5eef2893052ffd54718fa08604acbf6a15e78a467c4a3c53c0278af06c4416573f925491b195e8fd79302cb1aaf7caf4ecfc9aec1254cc969786363ac729f914c6ddcc26738d6b0facd54eba026580aba2eb6482a088b0d224a8852420b91ec1"));
12461246
1247 const rs = try r.toString(testing.allocator, 16, false);1247 const rs = try r.toString(testing.allocator, 16, false);
1248 defer testing.allocator.free(rs);1248 defer testing.allocator.free(rs);
1249 testing.expect(std.mem.eql(u8, rs, "310d1d4c414426b4836c2635bad1df3a424e50cbdd167ffccb4dfff57d36b4aae0d6ca0910698220171a0f3373c1060a046c2812f0027e321f72979daa5e7973214170d49e885de0c0ecc167837d44502430674a82522e5df6a0759548052420b91ec1"));1249 try testing.expect(std.mem.eql(u8, rs, "310d1d4c414426b4836c2635bad1df3a424e50cbdd167ffccb4dfff57d36b4aae0d6ca0910698220171a0f3373c1060a046c2812f0027e321f72979daa5e7973214170d49e885de0c0ecc167837d44502430674a82522e5df6a0759548052420b91ec1"));
1250}1250}
12511251
1252test "big.int div multi-multi fuzz case #2" {1252test "big.int div multi-multi fuzz case #2" {
...@@ -1266,11 +1266,11 @@ test "big.int div multi-multi fuzz case #2" {...@@ -1266,11 +1266,11 @@ test "big.int div multi-multi fuzz case #2" {
12661266
1267 const qs = try q.toString(testing.allocator, 16, false);1267 const qs = try q.toString(testing.allocator, 16, false);
1268 defer testing.allocator.free(qs);1268 defer testing.allocator.free(qs);
1269 testing.expect(std.mem.eql(u8, qs, "40100400fe3f8fe3f8fe3f8fe3f8fe3f8fe4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f91e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4992649926499264991e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4792e4b92e4b92e4b92e4b92a4a92a4a92a4"));1269 try testing.expect(std.mem.eql(u8, qs, "40100400fe3f8fe3f8fe3f8fe3f8fe3f8fe4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f91e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4992649926499264991e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4792e4b92e4b92e4b92e4b92a4a92a4a92a4"));
12701270
1271 const rs = try r.toString(testing.allocator, 16, false);1271 const rs = try r.toString(testing.allocator, 16, false);
1272 defer testing.allocator.free(rs);1272 defer testing.allocator.free(rs);
1273 testing.expect(std.mem.eql(u8, rs, "a900000000000000000000000000000000000000000000000000"));1273 try testing.expect(std.mem.eql(u8, rs, "a900000000000000000000000000000000000000000000000000"));
1274}1274}
12751275
1276test "big.int shift-right single" {1276test "big.int shift-right single" {
...@@ -1278,7 +1278,7 @@ test "big.int shift-right single" {...@@ -1278,7 +1278,7 @@ test "big.int shift-right single" {
1278 defer a.deinit();1278 defer a.deinit();
1279 try a.shiftRight(a, 16);1279 try a.shiftRight(a, 16);
12801280
1281 testing.expect((try a.to(u32)) == 0xffff);1281 try testing.expect((try a.to(u32)) == 0xffff);
1282}1282}
12831283
1284test "big.int shift-right multi" {1284test "big.int shift-right multi" {
...@@ -1286,13 +1286,13 @@ test "big.int shift-right multi" {...@@ -1286,13 +1286,13 @@ test "big.int shift-right multi" {
1286 defer a.deinit();1286 defer a.deinit();
1287 try a.shiftRight(a, 67);1287 try a.shiftRight(a, 67);
12881288
1289 testing.expect((try a.to(u64)) == 0x1fffe0001dddc222);1289 try testing.expect((try a.to(u64)) == 0x1fffe0001dddc222);
12901290
1291 try a.set(0xffff0000eeee1111dddd2222cccc3333);1291 try a.set(0xffff0000eeee1111dddd2222cccc3333);
1292 try a.shiftRight(a, 63);1292 try a.shiftRight(a, 63);
1293 try a.shiftRight(a, 63);1293 try a.shiftRight(a, 63);
1294 try a.shiftRight(a, 2);1294 try a.shiftRight(a, 2);
1295 testing.expect(a.eqZero());1295 try testing.expect(a.eqZero());
1296}1296}
12971297
1298test "big.int shift-left single" {1298test "big.int shift-left single" {
...@@ -1300,7 +1300,7 @@ test "big.int shift-left single" {...@@ -1300,7 +1300,7 @@ test "big.int shift-left single" {
1300 defer a.deinit();1300 defer a.deinit();
1301 try a.shiftLeft(a, 16);1301 try a.shiftLeft(a, 16);
13021302
1303 testing.expect((try a.to(u64)) == 0xffff0000);1303 try testing.expect((try a.to(u64)) == 0xffff0000);
1304}1304}
13051305
1306test "big.int shift-left multi" {1306test "big.int shift-left multi" {
...@@ -1308,7 +1308,7 @@ test "big.int shift-left multi" {...@@ -1308,7 +1308,7 @@ test "big.int shift-left multi" {
1308 defer a.deinit();1308 defer a.deinit();
1309 try a.shiftLeft(a, 67);1309 try a.shiftLeft(a, 67);
13101310
1311 testing.expect((try a.to(u128)) == 0xffff0000eeee11100000000000000000);1311 try testing.expect((try a.to(u128)) == 0xffff0000eeee11100000000000000000);
1312}1312}
13131313
1314test "big.int shift-right negative" {1314test "big.int shift-right negative" {
...@@ -1318,12 +1318,12 @@ test "big.int shift-right negative" {...@@ -1318,12 +1318,12 @@ test "big.int shift-right negative" {
1318 var arg = try Managed.initSet(testing.allocator, -20);1318 var arg = try Managed.initSet(testing.allocator, -20);
1319 defer arg.deinit();1319 defer arg.deinit();
1320 try a.shiftRight(arg, 2);1320 try a.shiftRight(arg, 2);
1321 testing.expect((try a.to(i32)) == -20 >> 2);1321 try testing.expect((try a.to(i32)) == -20 >> 2);
13221322
1323 var arg2 = try Managed.initSet(testing.allocator, -5);1323 var arg2 = try Managed.initSet(testing.allocator, -5);
1324 defer arg2.deinit();1324 defer arg2.deinit();
1325 try a.shiftRight(arg2, 10);1325 try a.shiftRight(arg2, 10);
1326 testing.expect((try a.to(i32)) == -5 >> 10);1326 try testing.expect((try a.to(i32)) == -5 >> 10);
1327}1327}
13281328
1329test "big.int shift-left negative" {1329test "big.int shift-left negative" {
...@@ -1333,7 +1333,7 @@ test "big.int shift-left negative" {...@@ -1333,7 +1333,7 @@ test "big.int shift-left negative" {
1333 var arg = try Managed.initSet(testing.allocator, -10);1333 var arg = try Managed.initSet(testing.allocator, -10);
1334 defer arg.deinit();1334 defer arg.deinit();
1335 try a.shiftRight(arg, 1232);1335 try a.shiftRight(arg, 1232);
1336 testing.expect((try a.to(i32)) == -10 >> 1232);1336 try testing.expect((try a.to(i32)) == -10 >> 1232);
1337}1337}
13381338
1339test "big.int bitwise and simple" {1339test "big.int bitwise and simple" {
...@@ -1344,7 +1344,7 @@ test "big.int bitwise and simple" {...@@ -1344,7 +1344,7 @@ test "big.int bitwise and simple" {
13441344
1345 try a.bitAnd(a, b);1345 try a.bitAnd(a, b);
13461346
1347 testing.expect((try a.to(u64)) == 0xeeeeeeee00000000);1347 try testing.expect((try a.to(u64)) == 0xeeeeeeee00000000);
1348}1348}
13491349
1350test "big.int bitwise and multi-limb" {1350test "big.int bitwise and multi-limb" {
...@@ -1355,7 +1355,7 @@ test "big.int bitwise and multi-limb" {...@@ -1355,7 +1355,7 @@ test "big.int bitwise and multi-limb" {
13551355
1356 try a.bitAnd(a, b);1356 try a.bitAnd(a, b);
13571357
1358 testing.expect((try a.to(u128)) == 0);1358 try testing.expect((try a.to(u128)) == 0);
1359}1359}
13601360
1361test "big.int bitwise xor simple" {1361test "big.int bitwise xor simple" {
...@@ -1366,7 +1366,7 @@ test "big.int bitwise xor simple" {...@@ -1366,7 +1366,7 @@ test "big.int bitwise xor simple" {
13661366
1367 try a.bitXor(a, b);1367 try a.bitXor(a, b);
13681368
1369 testing.expect((try a.to(u64)) == 0x1111111133333333);1369 try testing.expect((try a.to(u64)) == 0x1111111133333333);
1370}1370}
13711371
1372test "big.int bitwise xor multi-limb" {1372test "big.int bitwise xor multi-limb" {
...@@ -1377,7 +1377,7 @@ test "big.int bitwise xor multi-limb" {...@@ -1377,7 +1377,7 @@ test "big.int bitwise xor multi-limb" {
13771377
1378 try a.bitXor(a, b);1378 try a.bitXor(a, b);
13791379
1380 testing.expect((try a.to(DoubleLimb)) == (maxInt(Limb) + 1) ^ maxInt(Limb));1380 try testing.expect((try a.to(DoubleLimb)) == (maxInt(Limb) + 1) ^ maxInt(Limb));
1381}1381}
13821382
1383test "big.int bitwise or simple" {1383test "big.int bitwise or simple" {
...@@ -1388,7 +1388,7 @@ test "big.int bitwise or simple" {...@@ -1388,7 +1388,7 @@ test "big.int bitwise or simple" {
13881388
1389 try a.bitOr(a, b);1389 try a.bitOr(a, b);
13901390
1391 testing.expect((try a.to(u64)) == 0xffffffff33333333);1391 try testing.expect((try a.to(u64)) == 0xffffffff33333333);
1392}1392}
13931393
1394test "big.int bitwise or multi-limb" {1394test "big.int bitwise or multi-limb" {
...@@ -1400,7 +1400,7 @@ test "big.int bitwise or multi-limb" {...@@ -1400,7 +1400,7 @@ test "big.int bitwise or multi-limb" {
1400 try a.bitOr(a, b);1400 try a.bitOr(a, b);
14011401
1402 // TODO: big.int.cpp or is wrong on multi-limb.1402 // TODO: big.int.cpp or is wrong on multi-limb.
1403 testing.expect((try a.to(DoubleLimb)) == (maxInt(Limb) + 1) + maxInt(Limb));1403 try testing.expect((try a.to(DoubleLimb)) == (maxInt(Limb) + 1) + maxInt(Limb));
1404}1404}
14051405
1406test "big.int var args" {1406test "big.int var args" {
...@@ -1410,15 +1410,15 @@ test "big.int var args" {...@@ -1410,15 +1410,15 @@ test "big.int var args" {
1410 var b = try Managed.initSet(testing.allocator, 6);1410 var b = try Managed.initSet(testing.allocator, 6);
1411 defer b.deinit();1411 defer b.deinit();
1412 try a.add(a.toConst(), b.toConst());1412 try a.add(a.toConst(), b.toConst());
1413 testing.expect((try a.to(u64)) == 11);1413 try testing.expect((try a.to(u64)) == 11);
14141414
1415 var c = try Managed.initSet(testing.allocator, 11);1415 var c = try Managed.initSet(testing.allocator, 11);
1416 defer c.deinit();1416 defer c.deinit();
1417 testing.expect(a.order(c) == .eq);1417 try testing.expect(a.order(c) == .eq);
14181418
1419 var d = try Managed.initSet(testing.allocator, 14);1419 var d = try Managed.initSet(testing.allocator, 14);
1420 defer d.deinit();1420 defer d.deinit();
1421 testing.expect(a.order(d) != .gt);1421 try testing.expect(a.order(d) != .gt);
1422}1422}
14231423
1424test "big.int gcd non-one small" {1424test "big.int gcd non-one small" {
...@@ -1431,7 +1431,7 @@ test "big.int gcd non-one small" {...@@ -1431,7 +1431,7 @@ test "big.int gcd non-one small" {
14311431
1432 try r.gcd(a, b);1432 try r.gcd(a, b);
14331433
1434 testing.expect((try r.to(u32)) == 1);1434 try testing.expect((try r.to(u32)) == 1);
1435}1435}
14361436
1437test "big.int gcd non-one small" {1437test "big.int gcd non-one small" {
...@@ -1444,7 +1444,7 @@ test "big.int gcd non-one small" {...@@ -1444,7 +1444,7 @@ test "big.int gcd non-one small" {
14441444
1445 try r.gcd(a, b);1445 try r.gcd(a, b);
14461446
1447 testing.expect((try r.to(u32)) == 38);1447 try testing.expect((try r.to(u32)) == 38);
1448}1448}
14491449
1450test "big.int gcd non-one large" {1450test "big.int gcd non-one large" {
...@@ -1457,7 +1457,7 @@ test "big.int gcd non-one large" {...@@ -1457,7 +1457,7 @@ test "big.int gcd non-one large" {
14571457
1458 try r.gcd(a, b);1458 try r.gcd(a, b);
14591459
1460 testing.expect((try r.to(u32)) == 4369);1460 try testing.expect((try r.to(u32)) == 4369);
1461}1461}
14621462
1463test "big.int gcd large multi-limb result" {1463test "big.int gcd large multi-limb result" {
...@@ -1471,7 +1471,7 @@ test "big.int gcd large multi-limb result" {...@@ -1471,7 +1471,7 @@ test "big.int gcd large multi-limb result" {
1471 try r.gcd(a, b);1471 try r.gcd(a, b);
14721472
1473 const answer = (try r.to(u256));1473 const answer = (try r.to(u256));
1474 testing.expect(answer == 0xf000000ff00000fff0000ffff000fffff00ffffff1);1474 try testing.expect(answer == 0xf000000ff00000fff0000ffff000fffff00ffffff1);
1475}1475}
14761476
1477test "big.int gcd one large" {1477test "big.int gcd one large" {
...@@ -1484,7 +1484,7 @@ test "big.int gcd one large" {...@@ -1484,7 +1484,7 @@ test "big.int gcd one large" {
14841484
1485 try r.gcd(a, b);1485 try r.gcd(a, b);
14861486
1487 testing.expect((try r.to(u64)) == 1);1487 try testing.expect((try r.to(u64)) == 1);
1488}1488}
14891489
1490test "big.int mutable to managed" {1490test "big.int mutable to managed" {
...@@ -1495,7 +1495,7 @@ test "big.int mutable to managed" {...@@ -1495,7 +1495,7 @@ test "big.int mutable to managed" {
1495 var a = Mutable.init(limbs_buf, 0xdeadbeef);1495 var a = Mutable.init(limbs_buf, 0xdeadbeef);
1496 var a_managed = a.toManaged(allocator);1496 var a_managed = a.toManaged(allocator);
14971497
1498 testing.expect(a.toConst().eq(a_managed.toConst()));1498 try testing.expect(a.toConst().eq(a_managed.toConst()));
1499}1499}
15001500
1501test "big.int const to managed" {1501test "big.int const to managed" {
...@@ -1505,7 +1505,7 @@ test "big.int const to managed" {...@@ -1505,7 +1505,7 @@ test "big.int const to managed" {
1505 var b = try a.toConst().toManaged(testing.allocator);1505 var b = try a.toConst().toManaged(testing.allocator);
1506 defer b.deinit();1506 defer b.deinit();
15071507
1508 testing.expect(a.toConst().eq(b.toConst()));1508 try testing.expect(a.toConst().eq(b.toConst()));
1509}1509}
15101510
1511test "big.int pow" {1511test "big.int pow" {
...@@ -1514,10 +1514,10 @@ test "big.int pow" {...@@ -1514,10 +1514,10 @@ test "big.int pow" {
1514 defer a.deinit();1514 defer a.deinit();
15151515
1516 try a.pow(a.toConst(), 3);1516 try a.pow(a.toConst(), 3);
1517 testing.expectEqual(@as(i32, -27), try a.to(i32));1517 try testing.expectEqual(@as(i32, -27), try a.to(i32));
15181518
1519 try a.pow(a.toConst(), 4);1519 try a.pow(a.toConst(), 4);
1520 testing.expectEqual(@as(i32, 531441), try a.to(i32));1520 try testing.expectEqual(@as(i32, 531441), try a.to(i32));
1521 }1521 }
1522 {1522 {
1523 var a = try Managed.initSet(testing.allocator, 10);1523 var a = try Managed.initSet(testing.allocator, 10);
...@@ -1531,11 +1531,11 @@ test "big.int pow" {...@@ -1531,11 +1531,11 @@ test "big.int pow" {
1531 // y and a are aliased1531 // y and a are aliased
1532 try a.pow(a.toConst(), 123);1532 try a.pow(a.toConst(), 123);
15331533
1534 testing.expect(a.eq(y));1534 try testing.expect(a.eq(y));
15351535
1536 const ys = try y.toString(testing.allocator, 16, false);1536 const ys = try y.toString(testing.allocator, 16, false);
1537 defer testing.allocator.free(ys);1537 defer testing.allocator.free(ys);
1538 testing.expectEqualSlices(1538 try testing.expectEqualSlices(
1539 u8,1539 u8,
1540 "183425a5f872f126e00a5ad62c839075cd6846c6fb0230887c7ad7a9dc530fcb" ++1540 "183425a5f872f126e00a5ad62c839075cd6846c6fb0230887c7ad7a9dc530fcb" ++
1541 "4933f60e8000000000000000000000000000000",1541 "4933f60e8000000000000000000000000000000",
...@@ -1548,17 +1548,17 @@ test "big.int pow" {...@@ -1548,17 +1548,17 @@ test "big.int pow" {
1548 defer a.deinit();1548 defer a.deinit();
15491549
1550 try a.pow(a.toConst(), 100);1550 try a.pow(a.toConst(), 100);
1551 testing.expectEqual(@as(i32, 0), try a.to(i32));1551 try testing.expectEqual(@as(i32, 0), try a.to(i32));
15521552
1553 try a.set(1);1553 try a.set(1);
1554 try a.pow(a.toConst(), 0);1554 try a.pow(a.toConst(), 0);
1555 testing.expectEqual(@as(i32, 1), try a.to(i32));1555 try testing.expectEqual(@as(i32, 1), try a.to(i32));
1556 try a.pow(a.toConst(), 100);1556 try a.pow(a.toConst(), 100);
1557 testing.expectEqual(@as(i32, 1), try a.to(i32));1557 try testing.expectEqual(@as(i32, 1), try a.to(i32));
1558 try a.set(-1);1558 try a.set(-1);
1559 try a.pow(a.toConst(), 15);1559 try a.pow(a.toConst(), 15);
1560 testing.expectEqual(@as(i32, -1), try a.to(i32));1560 try testing.expectEqual(@as(i32, -1), try a.to(i32));
1561 try a.pow(a.toConst(), 16);1561 try a.pow(a.toConst(), 16);
1562 testing.expectEqual(@as(i32, 1), try a.to(i32));1562 try testing.expectEqual(@as(i32, 1), try a.to(i32));
1563 }1563 }
1564}1564}
lib/std/math/big/rational.zig+67-67
...@@ -473,7 +473,7 @@ pub const Rational = struct {...@@ -473,7 +473,7 @@ pub const Rational = struct {
473};473};
474474
475fn extractLowBits(a: Int, comptime T: type) T {475fn extractLowBits(a: Int, comptime T: type) T {
476 testing.expect(@typeInfo(T) == .Int);476 debug.assert(@typeInfo(T) == .Int);
477477
478 const t_bits = @typeInfo(T).Int.bits;478 const t_bits = @typeInfo(T).Int.bits;
479 const limb_bits = @typeInfo(Limb).Int.bits;479 const limb_bits = @typeInfo(Limb).Int.bits;
...@@ -498,19 +498,19 @@ test "big.rational extractLowBits" {...@@ -498,19 +498,19 @@ test "big.rational extractLowBits" {
498 defer a.deinit();498 defer a.deinit();
499499
500 const a1 = extractLowBits(a, u8);500 const a1 = extractLowBits(a, u8);
501 testing.expect(a1 == 0x21);501 try testing.expect(a1 == 0x21);
502502
503 const a2 = extractLowBits(a, u16);503 const a2 = extractLowBits(a, u16);
504 testing.expect(a2 == 0x4321);504 try testing.expect(a2 == 0x4321);
505505
506 const a3 = extractLowBits(a, u32);506 const a3 = extractLowBits(a, u32);
507 testing.expect(a3 == 0x87654321);507 try testing.expect(a3 == 0x87654321);
508508
509 const a4 = extractLowBits(a, u64);509 const a4 = extractLowBits(a, u64);
510 testing.expect(a4 == 0x1234567887654321);510 try testing.expect(a4 == 0x1234567887654321);
511511
512 const a5 = extractLowBits(a, u128);512 const a5 = extractLowBits(a, u128);
513 testing.expect(a5 == 0x11112222333344441234567887654321);513 try testing.expect(a5 == 0x11112222333344441234567887654321);
514}514}
515515
516test "big.rational set" {516test "big.rational set" {
...@@ -518,28 +518,28 @@ test "big.rational set" {...@@ -518,28 +518,28 @@ test "big.rational set" {
518 defer a.deinit();518 defer a.deinit();
519519
520 try a.setInt(5);520 try a.setInt(5);
521 testing.expect((try a.p.to(u32)) == 5);521 try testing.expect((try a.p.to(u32)) == 5);
522 testing.expect((try a.q.to(u32)) == 1);522 try testing.expect((try a.q.to(u32)) == 1);
523523
524 try a.setRatio(7, 3);524 try a.setRatio(7, 3);
525 testing.expect((try a.p.to(u32)) == 7);525 try testing.expect((try a.p.to(u32)) == 7);
526 testing.expect((try a.q.to(u32)) == 3);526 try testing.expect((try a.q.to(u32)) == 3);
527527
528 try a.setRatio(9, 3);528 try a.setRatio(9, 3);
529 testing.expect((try a.p.to(i32)) == 3);529 try testing.expect((try a.p.to(i32)) == 3);
530 testing.expect((try a.q.to(i32)) == 1);530 try testing.expect((try a.q.to(i32)) == 1);
531531
532 try a.setRatio(-9, 3);532 try a.setRatio(-9, 3);
533 testing.expect((try a.p.to(i32)) == -3);533 try testing.expect((try a.p.to(i32)) == -3);
534 testing.expect((try a.q.to(i32)) == 1);534 try testing.expect((try a.q.to(i32)) == 1);
535535
536 try a.setRatio(9, -3);536 try a.setRatio(9, -3);
537 testing.expect((try a.p.to(i32)) == -3);537 try testing.expect((try a.p.to(i32)) == -3);
538 testing.expect((try a.q.to(i32)) == 1);538 try testing.expect((try a.q.to(i32)) == 1);
539539
540 try a.setRatio(-9, -3);540 try a.setRatio(-9, -3);
541 testing.expect((try a.p.to(i32)) == 3);541 try testing.expect((try a.p.to(i32)) == 3);
542 testing.expect((try a.q.to(i32)) == 1);542 try testing.expect((try a.q.to(i32)) == 1);
543}543}
544544
545test "big.rational setFloat" {545test "big.rational setFloat" {
...@@ -547,24 +547,24 @@ test "big.rational setFloat" {...@@ -547,24 +547,24 @@ test "big.rational setFloat" {
547 defer a.deinit();547 defer a.deinit();
548548
549 try a.setFloat(f64, 2.5);549 try a.setFloat(f64, 2.5);
550 testing.expect((try a.p.to(i32)) == 5);550 try testing.expect((try a.p.to(i32)) == 5);
551 testing.expect((try a.q.to(i32)) == 2);551 try testing.expect((try a.q.to(i32)) == 2);
552552
553 try a.setFloat(f32, -2.5);553 try a.setFloat(f32, -2.5);
554 testing.expect((try a.p.to(i32)) == -5);554 try testing.expect((try a.p.to(i32)) == -5);
555 testing.expect((try a.q.to(i32)) == 2);555 try testing.expect((try a.q.to(i32)) == 2);
556556
557 try a.setFloat(f32, 3.141593);557 try a.setFloat(f32, 3.141593);
558558
559 // = 3.14159297943115234375559 // = 3.14159297943115234375
560 testing.expect((try a.p.to(u32)) == 3294199);560 try testing.expect((try a.p.to(u32)) == 3294199);
561 testing.expect((try a.q.to(u32)) == 1048576);561 try testing.expect((try a.q.to(u32)) == 1048576);
562562
563 try a.setFloat(f64, 72.141593120712409172417410926841290461290467124);563 try a.setFloat(f64, 72.141593120712409172417410926841290461290467124);
564564
565 // = 72.1415931207124145885245525278151035308837890625565 // = 72.1415931207124145885245525278151035308837890625
566 testing.expect((try a.p.to(u128)) == 5076513310880537);566 try testing.expect((try a.p.to(u128)) == 5076513310880537);
567 testing.expect((try a.q.to(u128)) == 70368744177664);567 try testing.expect((try a.q.to(u128)) == 70368744177664);
568}568}
569569
570test "big.rational setFloatString" {570test "big.rational setFloatString" {
...@@ -574,8 +574,8 @@ test "big.rational setFloatString" {...@@ -574,8 +574,8 @@ test "big.rational setFloatString" {
574 try a.setFloatString("72.14159312071241458852455252781510353");574 try a.setFloatString("72.14159312071241458852455252781510353");
575575
576 // = 72.1415931207124145885245525278151035308837890625576 // = 72.1415931207124145885245525278151035308837890625
577 testing.expect((try a.p.to(u128)) == 7214159312071241458852455252781510353);577 try testing.expect((try a.p.to(u128)) == 7214159312071241458852455252781510353);
578 testing.expect((try a.q.to(u128)) == 100000000000000000000000000000000000);578 try testing.expect((try a.q.to(u128)) == 100000000000000000000000000000000000);
579}579}
580580
581test "big.rational toFloat" {581test "big.rational toFloat" {
...@@ -584,11 +584,11 @@ test "big.rational toFloat" {...@@ -584,11 +584,11 @@ test "big.rational toFloat" {
584584
585 // = 3.14159297943115234375585 // = 3.14159297943115234375
586 try a.setRatio(3294199, 1048576);586 try a.setRatio(3294199, 1048576);
587 testing.expect((try a.toFloat(f64)) == 3.14159297943115234375);587 try testing.expect((try a.toFloat(f64)) == 3.14159297943115234375);
588588
589 // = 72.1415931207124145885245525278151035308837890625589 // = 72.1415931207124145885245525278151035308837890625
590 try a.setRatio(5076513310880537, 70368744177664);590 try a.setRatio(5076513310880537, 70368744177664);
591 testing.expect((try a.toFloat(f64)) == 72.141593120712409172417410926841290461290467124);591 try testing.expect((try a.toFloat(f64)) == 72.141593120712409172417410926841290461290467124);
592}592}
593593
594test "big.rational set/to Float round-trip" {594test "big.rational set/to Float round-trip" {
...@@ -599,7 +599,7 @@ test "big.rational set/to Float round-trip" {...@@ -599,7 +599,7 @@ test "big.rational set/to Float round-trip" {
599 while (i < 512) : (i += 1) {599 while (i < 512) : (i += 1) {
600 const r = prng.random.float(f64);600 const r = prng.random.float(f64);
601 try a.setFloat(f64, r);601 try a.setFloat(f64, r);
602 testing.expect((try a.toFloat(f64)) == r);602 try testing.expect((try a.toFloat(f64)) == r);
603 }603 }
604}604}
605605
...@@ -611,8 +611,8 @@ test "big.rational copy" {...@@ -611,8 +611,8 @@ test "big.rational copy" {
611 defer b.deinit();611 defer b.deinit();
612612
613 try a.copyInt(b);613 try a.copyInt(b);
614 testing.expect((try a.p.to(u32)) == 5);614 try testing.expect((try a.p.to(u32)) == 5);
615 testing.expect((try a.q.to(u32)) == 1);615 try testing.expect((try a.q.to(u32)) == 1);
616616
617 var c = try Int.initSet(testing.allocator, 7);617 var c = try Int.initSet(testing.allocator, 7);
618 defer c.deinit();618 defer c.deinit();
...@@ -620,8 +620,8 @@ test "big.rational copy" {...@@ -620,8 +620,8 @@ test "big.rational copy" {
620 defer d.deinit();620 defer d.deinit();
621621
622 try a.copyRatio(c, d);622 try a.copyRatio(c, d);
623 testing.expect((try a.p.to(u32)) == 7);623 try testing.expect((try a.p.to(u32)) == 7);
624 testing.expect((try a.q.to(u32)) == 3);624 try testing.expect((try a.q.to(u32)) == 3);
625625
626 var e = try Int.initSet(testing.allocator, 9);626 var e = try Int.initSet(testing.allocator, 9);
627 defer e.deinit();627 defer e.deinit();
...@@ -629,8 +629,8 @@ test "big.rational copy" {...@@ -629,8 +629,8 @@ test "big.rational copy" {
629 defer f.deinit();629 defer f.deinit();
630630
631 try a.copyRatio(e, f);631 try a.copyRatio(e, f);
632 testing.expect((try a.p.to(u32)) == 3);632 try testing.expect((try a.p.to(u32)) == 3);
633 testing.expect((try a.q.to(u32)) == 1);633 try testing.expect((try a.q.to(u32)) == 1);
634}634}
635635
636test "big.rational negate" {636test "big.rational negate" {
...@@ -638,16 +638,16 @@ test "big.rational negate" {...@@ -638,16 +638,16 @@ test "big.rational negate" {
638 defer a.deinit();638 defer a.deinit();
639639
640 try a.setInt(-50);640 try a.setInt(-50);
641 testing.expect((try a.p.to(i32)) == -50);641 try testing.expect((try a.p.to(i32)) == -50);
642 testing.expect((try a.q.to(i32)) == 1);642 try testing.expect((try a.q.to(i32)) == 1);
643643
644 a.negate();644 a.negate();
645 testing.expect((try a.p.to(i32)) == 50);645 try testing.expect((try a.p.to(i32)) == 50);
646 testing.expect((try a.q.to(i32)) == 1);646 try testing.expect((try a.q.to(i32)) == 1);
647647
648 a.negate();648 a.negate();
649 testing.expect((try a.p.to(i32)) == -50);649 try testing.expect((try a.p.to(i32)) == -50);
650 testing.expect((try a.q.to(i32)) == 1);650 try testing.expect((try a.q.to(i32)) == 1);
651}651}
652652
653test "big.rational abs" {653test "big.rational abs" {
...@@ -655,16 +655,16 @@ test "big.rational abs" {...@@ -655,16 +655,16 @@ test "big.rational abs" {
655 defer a.deinit();655 defer a.deinit();
656656
657 try a.setInt(-50);657 try a.setInt(-50);
658 testing.expect((try a.p.to(i32)) == -50);658 try testing.expect((try a.p.to(i32)) == -50);
659 testing.expect((try a.q.to(i32)) == 1);659 try testing.expect((try a.q.to(i32)) == 1);
660660
661 a.abs();661 a.abs();
662 testing.expect((try a.p.to(i32)) == 50);662 try testing.expect((try a.p.to(i32)) == 50);
663 testing.expect((try a.q.to(i32)) == 1);663 try testing.expect((try a.q.to(i32)) == 1);
664664
665 a.abs();665 a.abs();
666 testing.expect((try a.p.to(i32)) == 50);666 try testing.expect((try a.p.to(i32)) == 50);
667 testing.expect((try a.q.to(i32)) == 1);667 try testing.expect((try a.q.to(i32)) == 1);
668}668}
669669
670test "big.rational swap" {670test "big.rational swap" {
...@@ -676,19 +676,19 @@ test "big.rational swap" {...@@ -676,19 +676,19 @@ test "big.rational swap" {
676 try a.setRatio(50, 23);676 try a.setRatio(50, 23);
677 try b.setRatio(17, 3);677 try b.setRatio(17, 3);
678678
679 testing.expect((try a.p.to(u32)) == 50);679 try testing.expect((try a.p.to(u32)) == 50);
680 testing.expect((try a.q.to(u32)) == 23);680 try testing.expect((try a.q.to(u32)) == 23);
681681
682 testing.expect((try b.p.to(u32)) == 17);682 try testing.expect((try b.p.to(u32)) == 17);
683 testing.expect((try b.q.to(u32)) == 3);683 try testing.expect((try b.q.to(u32)) == 3);
684684
685 a.swap(&b);685 a.swap(&b);
686686
687 testing.expect((try a.p.to(u32)) == 17);687 try testing.expect((try a.p.to(u32)) == 17);
688 testing.expect((try a.q.to(u32)) == 3);688 try testing.expect((try a.q.to(u32)) == 3);
689689
690 testing.expect((try b.p.to(u32)) == 50);690 try testing.expect((try b.p.to(u32)) == 50);
691 testing.expect((try b.q.to(u32)) == 23);691 try testing.expect((try b.q.to(u32)) == 23);
692}692}
693693
694test "big.rational order" {694test "big.rational order" {
...@@ -699,11 +699,11 @@ test "big.rational order" {...@@ -699,11 +699,11 @@ test "big.rational order" {
699699
700 try a.setRatio(500, 231);700 try a.setRatio(500, 231);
701 try b.setRatio(18903, 8584);701 try b.setRatio(18903, 8584);
702 testing.expect((try a.order(b)) == .lt);702 try testing.expect((try a.order(b)) == .lt);
703703
704 try a.setRatio(890, 10);704 try a.setRatio(890, 10);
705 try b.setRatio(89, 1);705 try b.setRatio(89, 1);
706 testing.expect((try a.order(b)) == .eq);706 try testing.expect((try a.order(b)) == .eq);
707}707}
708708
709test "big.rational add single-limb" {709test "big.rational add single-limb" {
...@@ -714,11 +714,11 @@ test "big.rational add single-limb" {...@@ -714,11 +714,11 @@ test "big.rational add single-limb" {
714714
715 try a.setRatio(500, 231);715 try a.setRatio(500, 231);
716 try b.setRatio(18903, 8584);716 try b.setRatio(18903, 8584);
717 testing.expect((try a.order(b)) == .lt);717 try testing.expect((try a.order(b)) == .lt);
718718
719 try a.setRatio(890, 10);719 try a.setRatio(890, 10);
720 try b.setRatio(89, 1);720 try b.setRatio(89, 1);
721 testing.expect((try a.order(b)) == .eq);721 try testing.expect((try a.order(b)) == .eq);
722}722}
723723
724test "big.rational add" {724test "big.rational add" {
...@@ -734,7 +734,7 @@ test "big.rational add" {...@@ -734,7 +734,7 @@ test "big.rational add" {
734 try a.add(a, b);734 try a.add(a, b);
735735
736 try r.setRatio(984786924199, 290395044174);736 try r.setRatio(984786924199, 290395044174);
737 testing.expect((try a.order(r)) == .eq);737 try testing.expect((try a.order(r)) == .eq);
738}738}
739739
740test "big.rational sub" {740test "big.rational sub" {
...@@ -750,7 +750,7 @@ test "big.rational sub" {...@@ -750,7 +750,7 @@ test "big.rational sub" {
750 try a.sub(a, b);750 try a.sub(a, b);
751751
752 try r.setRatio(979040510045, 290395044174);752 try r.setRatio(979040510045, 290395044174);
753 testing.expect((try a.order(r)) == .eq);753 try testing.expect((try a.order(r)) == .eq);
754}754}
755755
756test "big.rational mul" {756test "big.rational mul" {
...@@ -766,7 +766,7 @@ test "big.rational mul" {...@@ -766,7 +766,7 @@ test "big.rational mul" {
766 try a.mul(a, b);766 try a.mul(a, b);
767767
768 try r.setRatio(571481443, 17082061422);768 try r.setRatio(571481443, 17082061422);
769 testing.expect((try a.order(r)) == .eq);769 try testing.expect((try a.order(r)) == .eq);
770}770}
771771
772test "big.rational div" {772test "big.rational div" {
...@@ -782,7 +782,7 @@ test "big.rational div" {...@@ -782,7 +782,7 @@ test "big.rational div" {
782 try a.div(a, b);782 try a.div(a, b);
783783
784 try r.setRatio(75531824394, 221015929);784 try r.setRatio(75531824394, 221015929);
785 testing.expect((try a.order(r)) == .eq);785 try testing.expect((try a.order(r)) == .eq);
786}786}
787787
788test "big.rational div" {788test "big.rational div" {
...@@ -795,11 +795,11 @@ test "big.rational div" {...@@ -795,11 +795,11 @@ test "big.rational div" {
795 a.invert();795 a.invert();
796796
797 try r.setRatio(23341, 78923);797 try r.setRatio(23341, 78923);
798 testing.expect((try a.order(r)) == .eq);798 try testing.expect((try a.order(r)) == .eq);
799799
800 try a.setRatio(-78923, 23341);800 try a.setRatio(-78923, 23341);
801 a.invert();801 a.invert();
802802
803 try r.setRatio(-23341, 78923);803 try r.setRatio(-23341, 78923);
804 testing.expect((try a.order(r)) == .eq);804 try testing.expect((try a.order(r)) == .eq);
805}805}
lib/std/math/cbrt.zig+24-24
...@@ -125,44 +125,44 @@ fn cbrt64(x: f64) f64 {...@@ -125,44 +125,44 @@ fn cbrt64(x: f64) f64 {
125}125}
126126
127test "math.cbrt" {127test "math.cbrt" {
128 expect(cbrt(@as(f32, 0.0)) == cbrt32(0.0));128 try expect(cbrt(@as(f32, 0.0)) == cbrt32(0.0));
129 expect(cbrt(@as(f64, 0.0)) == cbrt64(0.0));129 try expect(cbrt(@as(f64, 0.0)) == cbrt64(0.0));
130}130}
131131
132test "math.cbrt32" {132test "math.cbrt32" {
133 const epsilon = 0.000001;133 const epsilon = 0.000001;
134134
135 expect(cbrt32(0.0) == 0.0);135 try expect(cbrt32(0.0) == 0.0);
136 expect(math.approxEqAbs(f32, cbrt32(0.2), 0.584804, epsilon));136 try expect(math.approxEqAbs(f32, cbrt32(0.2), 0.584804, epsilon));
137 expect(math.approxEqAbs(f32, cbrt32(0.8923), 0.962728, epsilon));137 try expect(math.approxEqAbs(f32, cbrt32(0.8923), 0.962728, epsilon));
138 expect(math.approxEqAbs(f32, cbrt32(1.5), 1.144714, epsilon));138 try expect(math.approxEqAbs(f32, cbrt32(1.5), 1.144714, epsilon));
139 expect(math.approxEqAbs(f32, cbrt32(37.45), 3.345676, epsilon));139 try expect(math.approxEqAbs(f32, cbrt32(37.45), 3.345676, epsilon));
140 expect(math.approxEqAbs(f32, cbrt32(123123.234375), 49.748501, epsilon));140 try expect(math.approxEqAbs(f32, cbrt32(123123.234375), 49.748501, epsilon));
141}141}
142142
143test "math.cbrt64" {143test "math.cbrt64" {
144 const epsilon = 0.000001;144 const epsilon = 0.000001;
145145
146 expect(cbrt64(0.0) == 0.0);146 try expect(cbrt64(0.0) == 0.0);
147 expect(math.approxEqAbs(f64, cbrt64(0.2), 0.584804, epsilon));147 try expect(math.approxEqAbs(f64, cbrt64(0.2), 0.584804, epsilon));
148 expect(math.approxEqAbs(f64, cbrt64(0.8923), 0.962728, epsilon));148 try expect(math.approxEqAbs(f64, cbrt64(0.8923), 0.962728, epsilon));
149 expect(math.approxEqAbs(f64, cbrt64(1.5), 1.144714, epsilon));149 try expect(math.approxEqAbs(f64, cbrt64(1.5), 1.144714, epsilon));
150 expect(math.approxEqAbs(f64, cbrt64(37.45), 3.345676, epsilon));150 try expect(math.approxEqAbs(f64, cbrt64(37.45), 3.345676, epsilon));
151 expect(math.approxEqAbs(f64, cbrt64(123123.234375), 49.748501, epsilon));151 try expect(math.approxEqAbs(f64, cbrt64(123123.234375), 49.748501, epsilon));
152}152}
153153
154test "math.cbrt.special" {154test "math.cbrt.special" {
155 expect(cbrt32(0.0) == 0.0);155 try expect(cbrt32(0.0) == 0.0);
156 expect(cbrt32(-0.0) == -0.0);156 try expect(cbrt32(-0.0) == -0.0);
157 expect(math.isPositiveInf(cbrt32(math.inf(f32))));157 try expect(math.isPositiveInf(cbrt32(math.inf(f32))));
158 expect(math.isNegativeInf(cbrt32(-math.inf(f32))));158 try expect(math.isNegativeInf(cbrt32(-math.inf(f32))));
159 expect(math.isNan(cbrt32(math.nan(f32))));159 try expect(math.isNan(cbrt32(math.nan(f32))));
160}160}
161161
162test "math.cbrt64.special" {162test "math.cbrt64.special" {
163 expect(cbrt64(0.0) == 0.0);163 try expect(cbrt64(0.0) == 0.0);
164 expect(cbrt64(-0.0) == -0.0);164 try expect(cbrt64(-0.0) == -0.0);
165 expect(math.isPositiveInf(cbrt64(math.inf(f64))));165 try expect(math.isPositiveInf(cbrt64(math.inf(f64))));
166 expect(math.isNegativeInf(cbrt64(-math.inf(f64))));166 try expect(math.isNegativeInf(cbrt64(-math.inf(f64))));
167 expect(math.isNan(cbrt64(math.nan(f64))));167 try expect(math.isNan(cbrt64(math.nan(f64))));
168}168}
lib/std/math/ceil.zig+27-27
...@@ -120,49 +120,49 @@ fn ceil128(x: f128) f128 {...@@ -120,49 +120,49 @@ fn ceil128(x: f128) f128 {
120}120}
121121
122test "math.ceil" {122test "math.ceil" {
123 expect(ceil(@as(f32, 0.0)) == ceil32(0.0));123 try expect(ceil(@as(f32, 0.0)) == ceil32(0.0));
124 expect(ceil(@as(f64, 0.0)) == ceil64(0.0));124 try expect(ceil(@as(f64, 0.0)) == ceil64(0.0));
125 expect(ceil(@as(f128, 0.0)) == ceil128(0.0));125 try expect(ceil(@as(f128, 0.0)) == ceil128(0.0));
126}126}
127127
128test "math.ceil32" {128test "math.ceil32" {
129 expect(ceil32(1.3) == 2.0);129 try expect(ceil32(1.3) == 2.0);
130 expect(ceil32(-1.3) == -1.0);130 try expect(ceil32(-1.3) == -1.0);
131 expect(ceil32(0.2) == 1.0);131 try expect(ceil32(0.2) == 1.0);
132}132}
133133
134test "math.ceil64" {134test "math.ceil64" {
135 expect(ceil64(1.3) == 2.0);135 try expect(ceil64(1.3) == 2.0);
136 expect(ceil64(-1.3) == -1.0);136 try expect(ceil64(-1.3) == -1.0);
137 expect(ceil64(0.2) == 1.0);137 try expect(ceil64(0.2) == 1.0);
138}138}
139139
140test "math.ceil128" {140test "math.ceil128" {
141 expect(ceil128(1.3) == 2.0);141 try expect(ceil128(1.3) == 2.0);
142 expect(ceil128(-1.3) == -1.0);142 try expect(ceil128(-1.3) == -1.0);
143 expect(ceil128(0.2) == 1.0);143 try expect(ceil128(0.2) == 1.0);
144}144}
145145
146test "math.ceil32.special" {146test "math.ceil32.special" {
147 expect(ceil32(0.0) == 0.0);147 try expect(ceil32(0.0) == 0.0);
148 expect(ceil32(-0.0) == -0.0);148 try expect(ceil32(-0.0) == -0.0);
149 expect(math.isPositiveInf(ceil32(math.inf(f32))));149 try expect(math.isPositiveInf(ceil32(math.inf(f32))));
150 expect(math.isNegativeInf(ceil32(-math.inf(f32))));150 try expect(math.isNegativeInf(ceil32(-math.inf(f32))));
151 expect(math.isNan(ceil32(math.nan(f32))));151 try expect(math.isNan(ceil32(math.nan(f32))));
152}152}
153153
154test "math.ceil64.special" {154test "math.ceil64.special" {
155 expect(ceil64(0.0) == 0.0);155 try expect(ceil64(0.0) == 0.0);
156 expect(ceil64(-0.0) == -0.0);156 try expect(ceil64(-0.0) == -0.0);
157 expect(math.isPositiveInf(ceil64(math.inf(f64))));157 try expect(math.isPositiveInf(ceil64(math.inf(f64))));
158 expect(math.isNegativeInf(ceil64(-math.inf(f64))));158 try expect(math.isNegativeInf(ceil64(-math.inf(f64))));
159 expect(math.isNan(ceil64(math.nan(f64))));159 try expect(math.isNan(ceil64(math.nan(f64))));
160}160}
161161
162test "math.ceil128.special" {162test "math.ceil128.special" {
163 expect(ceil128(0.0) == 0.0);163 try expect(ceil128(0.0) == 0.0);
164 expect(ceil128(-0.0) == -0.0);164 try expect(ceil128(-0.0) == -0.0);
165 expect(math.isPositiveInf(ceil128(math.inf(f128))));165 try expect(math.isPositiveInf(ceil128(math.inf(f128))));
166 expect(math.isNegativeInf(ceil128(-math.inf(f128))));166 try expect(math.isNegativeInf(ceil128(-math.inf(f128))));
167 expect(math.isNan(ceil128(math.nan(f128))));167 try expect(math.isNan(ceil128(math.nan(f128))));
168}168}
lib/std/math/complex.zig+7-7
...@@ -114,7 +114,7 @@ test "complex.add" {...@@ -114,7 +114,7 @@ test "complex.add" {
114 const b = Complex(f32).new(2, 7);114 const b = Complex(f32).new(2, 7);
115 const c = a.add(b);115 const c = a.add(b);
116116
117 testing.expect(c.re == 7 and c.im == 10);117 try testing.expect(c.re == 7 and c.im == 10);
118}118}
119119
120test "complex.sub" {120test "complex.sub" {
...@@ -122,7 +122,7 @@ test "complex.sub" {...@@ -122,7 +122,7 @@ test "complex.sub" {
122 const b = Complex(f32).new(2, 7);122 const b = Complex(f32).new(2, 7);
123 const c = a.sub(b);123 const c = a.sub(b);
124124
125 testing.expect(c.re == 3 and c.im == -4);125 try testing.expect(c.re == 3 and c.im == -4);
126}126}
127127
128test "complex.mul" {128test "complex.mul" {
...@@ -130,7 +130,7 @@ test "complex.mul" {...@@ -130,7 +130,7 @@ test "complex.mul" {
130 const b = Complex(f32).new(2, 7);130 const b = Complex(f32).new(2, 7);
131 const c = a.mul(b);131 const c = a.mul(b);
132132
133 testing.expect(c.re == -11 and c.im == 41);133 try testing.expect(c.re == -11 and c.im == 41);
134}134}
135135
136test "complex.div" {136test "complex.div" {
...@@ -138,7 +138,7 @@ test "complex.div" {...@@ -138,7 +138,7 @@ test "complex.div" {
138 const b = Complex(f32).new(2, 7);138 const b = Complex(f32).new(2, 7);
139 const c = a.div(b);139 const c = a.div(b);
140140
141 testing.expect(math.approxEqAbs(f32, c.re, @as(f32, 31) / 53, epsilon) and141 try testing.expect(math.approxEqAbs(f32, c.re, @as(f32, 31) / 53, epsilon) and
142 math.approxEqAbs(f32, c.im, @as(f32, -29) / 53, epsilon));142 math.approxEqAbs(f32, c.im, @as(f32, -29) / 53, epsilon));
143}143}
144144
...@@ -146,14 +146,14 @@ test "complex.conjugate" {...@@ -146,14 +146,14 @@ test "complex.conjugate" {
146 const a = Complex(f32).new(5, 3);146 const a = Complex(f32).new(5, 3);
147 const c = a.conjugate();147 const c = a.conjugate();
148148
149 testing.expect(c.re == 5 and c.im == -3);149 try testing.expect(c.re == 5 and c.im == -3);
150}150}
151151
152test "complex.reciprocal" {152test "complex.reciprocal" {
153 const a = Complex(f32).new(5, 3);153 const a = Complex(f32).new(5, 3);
154 const c = a.reciprocal();154 const c = a.reciprocal();
155155
156 testing.expect(math.approxEqAbs(f32, c.re, @as(f32, 5) / 34, epsilon) and156 try testing.expect(math.approxEqAbs(f32, c.re, @as(f32, 5) / 34, epsilon) and
157 math.approxEqAbs(f32, c.im, @as(f32, -3) / 34, epsilon));157 math.approxEqAbs(f32, c.im, @as(f32, -3) / 34, epsilon));
158}158}
159159
...@@ -161,7 +161,7 @@ test "complex.magnitude" {...@@ -161,7 +161,7 @@ test "complex.magnitude" {
161 const a = Complex(f32).new(5, 3);161 const a = Complex(f32).new(5, 3);
162 const c = a.magnitude();162 const c = a.magnitude();
163163
164 testing.expect(math.approxEqAbs(f32, c, 5.83095, epsilon));164 try testing.expect(math.approxEqAbs(f32, c, 5.83095, epsilon));
165}165}
166166
167test "complex.cmath" {167test "complex.cmath" {
lib/std/math/complex/abs.zig+1-1
...@@ -20,5 +20,5 @@ const epsilon = 0.0001;...@@ -20,5 +20,5 @@ const epsilon = 0.0001;
20test "complex.cabs" {20test "complex.cabs" {
21 const a = Complex(f32).new(5, 3);21 const a = Complex(f32).new(5, 3);
22 const c = abs(a);22 const c = abs(a);
23 testing.expect(math.approxEqAbs(f32, c, 5.83095, epsilon));23 try testing.expect(math.approxEqAbs(f32, c, 5.83095, epsilon));
24}24}
lib/std/math/complex/acos.zig+2-2
...@@ -22,6 +22,6 @@ test "complex.cacos" {...@@ -22,6 +22,6 @@ test "complex.cacos" {
22 const a = Complex(f32).new(5, 3);22 const a = Complex(f32).new(5, 3);
23 const c = acos(a);23 const c = acos(a);
2424
25 testing.expect(math.approxEqAbs(f32, c.re, 0.546975, epsilon));25 try testing.expect(math.approxEqAbs(f32, c.re, 0.546975, epsilon));
26 testing.expect(math.approxEqAbs(f32, c.im, -2.452914, epsilon));26 try testing.expect(math.approxEqAbs(f32, c.im, -2.452914, epsilon));
27}27}
lib/std/math/complex/acosh.zig+2-2
...@@ -22,6 +22,6 @@ test "complex.cacosh" {...@@ -22,6 +22,6 @@ test "complex.cacosh" {
22 const a = Complex(f32).new(5, 3);22 const a = Complex(f32).new(5, 3);
23 const c = acosh(a);23 const c = acosh(a);
2424
25 testing.expect(math.approxEqAbs(f32, c.re, 2.452914, epsilon));25 try testing.expect(math.approxEqAbs(f32, c.re, 2.452914, epsilon));
26 testing.expect(math.approxEqAbs(f32, c.im, 0.546975, epsilon));26 try testing.expect(math.approxEqAbs(f32, c.im, 0.546975, epsilon));
27}27}
lib/std/math/complex/arg.zig+1-1
...@@ -20,5 +20,5 @@ const epsilon = 0.0001;...@@ -20,5 +20,5 @@ const epsilon = 0.0001;
20test "complex.carg" {20test "complex.carg" {
21 const a = Complex(f32).new(5, 3);21 const a = Complex(f32).new(5, 3);
22 const c = arg(a);22 const c = arg(a);
23 testing.expect(math.approxEqAbs(f32, c, 0.540420, epsilon));23 try testing.expect(math.approxEqAbs(f32, c, 0.540420, epsilon));
24}24}
lib/std/math/complex/asin.zig+2-2
...@@ -28,6 +28,6 @@ test "complex.casin" {...@@ -28,6 +28,6 @@ test "complex.casin" {
28 const a = Complex(f32).new(5, 3);28 const a = Complex(f32).new(5, 3);
29 const c = asin(a);29 const c = asin(a);
3030
31 testing.expect(math.approxEqAbs(f32, c.re, 1.023822, epsilon));31 try testing.expect(math.approxEqAbs(f32, c.re, 1.023822, epsilon));
32 testing.expect(math.approxEqAbs(f32, c.im, 2.452914, epsilon));32 try testing.expect(math.approxEqAbs(f32, c.im, 2.452914, epsilon));
33}33}
lib/std/math/complex/asinh.zig+2-2
...@@ -23,6 +23,6 @@ test "complex.casinh" {...@@ -23,6 +23,6 @@ test "complex.casinh" {
23 const a = Complex(f32).new(5, 3);23 const a = Complex(f32).new(5, 3);
24 const c = asinh(a);24 const c = asinh(a);
2525
26 testing.expect(math.approxEqAbs(f32, c.re, 2.459831, epsilon));26 try testing.expect(math.approxEqAbs(f32, c.re, 2.459831, epsilon));
27 testing.expect(math.approxEqAbs(f32, c.im, 0.533999, epsilon));27 try testing.expect(math.approxEqAbs(f32, c.im, 0.533999, epsilon));
28}28}
lib/std/math/complex/atan.zig+4-4
...@@ -130,14 +130,14 @@ test "complex.catan32" {...@@ -130,14 +130,14 @@ test "complex.catan32" {
130 const a = Complex(f32).new(5, 3);130 const a = Complex(f32).new(5, 3);
131 const c = atan(a);131 const c = atan(a);
132132
133 testing.expect(math.approxEqAbs(f32, c.re, 1.423679, epsilon));133 try testing.expect(math.approxEqAbs(f32, c.re, 1.423679, epsilon));
134 testing.expect(math.approxEqAbs(f32, c.im, 0.086569, epsilon));134 try testing.expect(math.approxEqAbs(f32, c.im, 0.086569, epsilon));
135}135}
136136
137test "complex.catan64" {137test "complex.catan64" {
138 const a = Complex(f64).new(5, 3);138 const a = Complex(f64).new(5, 3);
139 const c = atan(a);139 const c = atan(a);
140140
141 testing.expect(math.approxEqAbs(f64, c.re, 1.423679, epsilon));141 try testing.expect(math.approxEqAbs(f64, c.re, 1.423679, epsilon));
142 testing.expect(math.approxEqAbs(f64, c.im, 0.086569, epsilon));142 try testing.expect(math.approxEqAbs(f64, c.im, 0.086569, epsilon));
143}143}
lib/std/math/complex/atanh.zig+2-2
...@@ -23,6 +23,6 @@ test "complex.catanh" {...@@ -23,6 +23,6 @@ test "complex.catanh" {
23 const a = Complex(f32).new(5, 3);23 const a = Complex(f32).new(5, 3);
24 const c = atanh(a);24 const c = atanh(a);
2525
26 testing.expect(math.approxEqAbs(f32, c.re, 0.146947, epsilon));26 try testing.expect(math.approxEqAbs(f32, c.re, 0.146947, epsilon));
27 testing.expect(math.approxEqAbs(f32, c.im, 1.480870, epsilon));27 try testing.expect(math.approxEqAbs(f32, c.im, 1.480870, epsilon));
28}28}
lib/std/math/complex/conj.zig+1-1
...@@ -19,5 +19,5 @@ test "complex.conj" {...@@ -19,5 +19,5 @@ test "complex.conj" {
19 const a = Complex(f32).new(5, 3);19 const a = Complex(f32).new(5, 3);
20 const c = a.conjugate();20 const c = a.conjugate();
2121
22 testing.expect(c.re == 5 and c.im == -3);22 try testing.expect(c.re == 5 and c.im == -3);
23}23}
lib/std/math/complex/cos.zig+2-2
...@@ -22,6 +22,6 @@ test "complex.ccos" {...@@ -22,6 +22,6 @@ test "complex.ccos" {
22 const a = Complex(f32).new(5, 3);22 const a = Complex(f32).new(5, 3);
23 const c = cos(a);23 const c = cos(a);
2424
25 testing.expect(math.approxEqAbs(f32, c.re, 2.855815, epsilon));25 try testing.expect(math.approxEqAbs(f32, c.re, 2.855815, epsilon));
26 testing.expect(math.approxEqAbs(f32, c.im, 9.606383, epsilon));26 try testing.expect(math.approxEqAbs(f32, c.im, 9.606383, epsilon));
27}27}
lib/std/math/complex/cosh.zig+4-4
...@@ -165,14 +165,14 @@ test "complex.ccosh32" {...@@ -165,14 +165,14 @@ test "complex.ccosh32" {
165 const a = Complex(f32).new(5, 3);165 const a = Complex(f32).new(5, 3);
166 const c = cosh(a);166 const c = cosh(a);
167167
168 testing.expect(math.approxEqAbs(f32, c.re, -73.467300, epsilon));168 try testing.expect(math.approxEqAbs(f32, c.re, -73.467300, epsilon));
169 testing.expect(math.approxEqAbs(f32, c.im, 10.471557, epsilon));169 try testing.expect(math.approxEqAbs(f32, c.im, 10.471557, epsilon));
170}170}
171171
172test "complex.ccosh64" {172test "complex.ccosh64" {
173 const a = Complex(f64).new(5, 3);173 const a = Complex(f64).new(5, 3);
174 const c = cosh(a);174 const c = cosh(a);
175175
176 testing.expect(math.approxEqAbs(f64, c.re, -73.467300, epsilon));176 try testing.expect(math.approxEqAbs(f64, c.re, -73.467300, epsilon));
177 testing.expect(math.approxEqAbs(f64, c.im, 10.471557, epsilon));177 try testing.expect(math.approxEqAbs(f64, c.im, 10.471557, epsilon));
178}178}
lib/std/math/complex/exp.zig+4-4
...@@ -131,14 +131,14 @@ test "complex.cexp32" {...@@ -131,14 +131,14 @@ test "complex.cexp32" {
131 const a = Complex(f32).new(5, 3);131 const a = Complex(f32).new(5, 3);
132 const c = exp(a);132 const c = exp(a);
133133
134 testing.expect(math.approxEqAbs(f32, c.re, -146.927917, epsilon));134 try testing.expect(math.approxEqAbs(f32, c.re, -146.927917, epsilon));
135 testing.expect(math.approxEqAbs(f32, c.im, 20.944065, epsilon));135 try testing.expect(math.approxEqAbs(f32, c.im, 20.944065, epsilon));
136}136}
137137
138test "complex.cexp64" {138test "complex.cexp64" {
139 const a = Complex(f64).new(5, 3);139 const a = Complex(f64).new(5, 3);
140 const c = exp(a);140 const c = exp(a);
141141
142 testing.expect(math.approxEqAbs(f64, c.re, -146.927917, epsilon));142 try testing.expect(math.approxEqAbs(f64, c.re, -146.927917, epsilon));
143 testing.expect(math.approxEqAbs(f64, c.im, 20.944065, epsilon));143 try testing.expect(math.approxEqAbs(f64, c.im, 20.944065, epsilon));
144}144}
lib/std/math/complex/log.zig+2-2
...@@ -24,6 +24,6 @@ test "complex.clog" {...@@ -24,6 +24,6 @@ test "complex.clog" {
24 const a = Complex(f32).new(5, 3);24 const a = Complex(f32).new(5, 3);
25 const c = log(a);25 const c = log(a);
2626
27 testing.expect(math.approxEqAbs(f32, c.re, 1.763180, epsilon));27 try testing.expect(math.approxEqAbs(f32, c.re, 1.763180, epsilon));
28 testing.expect(math.approxEqAbs(f32, c.im, 0.540419, epsilon));28 try testing.expect(math.approxEqAbs(f32, c.im, 0.540419, epsilon));
29}29}
lib/std/math/complex/pow.zig+2-2
...@@ -23,6 +23,6 @@ test "complex.cpow" {...@@ -23,6 +23,6 @@ test "complex.cpow" {
23 const b = Complex(f32).new(2.3, -1.3);23 const b = Complex(f32).new(2.3, -1.3);
24 const c = pow(Complex(f32), a, b);24 const c = pow(Complex(f32), a, b);
2525
26 testing.expect(math.approxEqAbs(f32, c.re, 58.049110, epsilon));26 try testing.expect(math.approxEqAbs(f32, c.re, 58.049110, epsilon));
27 testing.expect(math.approxEqAbs(f32, c.im, -101.003433, epsilon));27 try testing.expect(math.approxEqAbs(f32, c.im, -101.003433, epsilon));
28}28}
lib/std/math/complex/proj.zig+1-1
...@@ -26,5 +26,5 @@ test "complex.cproj" {...@@ -26,5 +26,5 @@ test "complex.cproj" {
26 const a = Complex(f32).new(5, 3);26 const a = Complex(f32).new(5, 3);
27 const c = proj(a);27 const c = proj(a);
2828
29 testing.expect(c.re == 5 and c.im == 3);29 try testing.expect(c.re == 5 and c.im == 3);
30}30}
lib/std/math/complex/sin.zig+2-2
...@@ -23,6 +23,6 @@ test "complex.csin" {...@@ -23,6 +23,6 @@ test "complex.csin" {
23 const a = Complex(f32).new(5, 3);23 const a = Complex(f32).new(5, 3);
24 const c = sin(a);24 const c = sin(a);
2525
26 testing.expect(math.approxEqAbs(f32, c.re, -9.654126, epsilon));26 try testing.expect(math.approxEqAbs(f32, c.re, -9.654126, epsilon));
27 testing.expect(math.approxEqAbs(f32, c.im, 2.841692, epsilon));27 try testing.expect(math.approxEqAbs(f32, c.im, 2.841692, epsilon));
28}28}
lib/std/math/complex/sinh.zig+4-4
...@@ -164,14 +164,14 @@ test "complex.csinh32" {...@@ -164,14 +164,14 @@ test "complex.csinh32" {
164 const a = Complex(f32).new(5, 3);164 const a = Complex(f32).new(5, 3);
165 const c = sinh(a);165 const c = sinh(a);
166166
167 testing.expect(math.approxEqAbs(f32, c.re, -73.460617, epsilon));167 try testing.expect(math.approxEqAbs(f32, c.re, -73.460617, epsilon));
168 testing.expect(math.approxEqAbs(f32, c.im, 10.472508, epsilon));168 try testing.expect(math.approxEqAbs(f32, c.im, 10.472508, epsilon));
169}169}
170170
171test "complex.csinh64" {171test "complex.csinh64" {
172 const a = Complex(f64).new(5, 3);172 const a = Complex(f64).new(5, 3);
173 const c = sinh(a);173 const c = sinh(a);
174174
175 testing.expect(math.approxEqAbs(f64, c.re, -73.460617, epsilon));175 try testing.expect(math.approxEqAbs(f64, c.re, -73.460617, epsilon));
176 testing.expect(math.approxEqAbs(f64, c.im, 10.472508, epsilon));176 try testing.expect(math.approxEqAbs(f64, c.im, 10.472508, epsilon));
177}177}
lib/std/math/complex/sqrt.zig+4-4
...@@ -138,14 +138,14 @@ test "complex.csqrt32" {...@@ -138,14 +138,14 @@ test "complex.csqrt32" {
138 const a = Complex(f32).new(5, 3);138 const a = Complex(f32).new(5, 3);
139 const c = sqrt(a);139 const c = sqrt(a);
140140
141 testing.expect(math.approxEqAbs(f32, c.re, 2.327117, epsilon));141 try testing.expect(math.approxEqAbs(f32, c.re, 2.327117, epsilon));
142 testing.expect(math.approxEqAbs(f32, c.im, 0.644574, epsilon));142 try testing.expect(math.approxEqAbs(f32, c.im, 0.644574, epsilon));
143}143}
144144
145test "complex.csqrt64" {145test "complex.csqrt64" {
146 const a = Complex(f64).new(5, 3);146 const a = Complex(f64).new(5, 3);
147 const c = sqrt(a);147 const c = sqrt(a);
148148
149 testing.expect(math.approxEqAbs(f64, c.re, 2.3271175190399496, epsilon));149 try testing.expect(math.approxEqAbs(f64, c.re, 2.3271175190399496, epsilon));
150 testing.expect(math.approxEqAbs(f64, c.im, 0.6445742373246469, epsilon));150 try testing.expect(math.approxEqAbs(f64, c.im, 0.6445742373246469, epsilon));
151}151}
lib/std/math/complex/tan.zig+2-2
...@@ -23,6 +23,6 @@ test "complex.ctan" {...@@ -23,6 +23,6 @@ test "complex.ctan" {
23 const a = Complex(f32).new(5, 3);23 const a = Complex(f32).new(5, 3);
24 const c = tan(a);24 const c = tan(a);
2525
26 testing.expect(math.approxEqAbs(f32, c.re, -0.002708233, epsilon));26 try testing.expect(math.approxEqAbs(f32, c.re, -0.002708233, epsilon));
27 testing.expect(math.approxEqAbs(f32, c.im, 1.004165, epsilon));27 try testing.expect(math.approxEqAbs(f32, c.im, 1.004165, epsilon));
28}28}
lib/std/math/complex/tanh.zig+4-4
...@@ -113,14 +113,14 @@ test "complex.ctanh32" {...@@ -113,14 +113,14 @@ test "complex.ctanh32" {
113 const a = Complex(f32).new(5, 3);113 const a = Complex(f32).new(5, 3);
114 const c = tanh(a);114 const c = tanh(a);
115115
116 testing.expect(math.approxEqAbs(f32, c.re, 0.999913, epsilon));116 try testing.expect(math.approxEqAbs(f32, c.re, 0.999913, epsilon));
117 testing.expect(math.approxEqAbs(f32, c.im, -0.000025, epsilon));117 try testing.expect(math.approxEqAbs(f32, c.im, -0.000025, epsilon));
118}118}
119119
120test "complex.ctanh64" {120test "complex.ctanh64" {
121 const a = Complex(f64).new(5, 3);121 const a = Complex(f64).new(5, 3);
122 const c = tanh(a);122 const c = tanh(a);
123123
124 testing.expect(math.approxEqAbs(f64, c.re, 0.999913, epsilon));124 try testing.expect(math.approxEqAbs(f64, c.re, 0.999913, epsilon));
125 testing.expect(math.approxEqAbs(f64, c.im, -0.000025, epsilon));125 try testing.expect(math.approxEqAbs(f64, c.im, -0.000025, epsilon));
126}126}
lib/std/math/copysign.zig+20-20
...@@ -62,36 +62,36 @@ fn copysign128(x: f128, y: f128) f128 {...@@ -62,36 +62,36 @@ fn copysign128(x: f128, y: f128) f128 {
62}62}
6363
64test "math.copysign" {64test "math.copysign" {
65 expect(copysign(f16, 1.0, 1.0) == copysign16(1.0, 1.0));65 try expect(copysign(f16, 1.0, 1.0) == copysign16(1.0, 1.0));
66 expect(copysign(f32, 1.0, 1.0) == copysign32(1.0, 1.0));66 try expect(copysign(f32, 1.0, 1.0) == copysign32(1.0, 1.0));
67 expect(copysign(f64, 1.0, 1.0) == copysign64(1.0, 1.0));67 try expect(copysign(f64, 1.0, 1.0) == copysign64(1.0, 1.0));
68 expect(copysign(f128, 1.0, 1.0) == copysign128(1.0, 1.0));68 try expect(copysign(f128, 1.0, 1.0) == copysign128(1.0, 1.0));
69}69}
7070
71test "math.copysign16" {71test "math.copysign16" {
72 expect(copysign16(5.0, 1.0) == 5.0);72 try expect(copysign16(5.0, 1.0) == 5.0);
73 expect(copysign16(5.0, -1.0) == -5.0);73 try expect(copysign16(5.0, -1.0) == -5.0);
74 expect(copysign16(-5.0, -1.0) == -5.0);74 try expect(copysign16(-5.0, -1.0) == -5.0);
75 expect(copysign16(-5.0, 1.0) == 5.0);75 try expect(copysign16(-5.0, 1.0) == 5.0);
76}76}
7777
78test "math.copysign32" {78test "math.copysign32" {
79 expect(copysign32(5.0, 1.0) == 5.0);79 try expect(copysign32(5.0, 1.0) == 5.0);
80 expect(copysign32(5.0, -1.0) == -5.0);80 try expect(copysign32(5.0, -1.0) == -5.0);
81 expect(copysign32(-5.0, -1.0) == -5.0);81 try expect(copysign32(-5.0, -1.0) == -5.0);
82 expect(copysign32(-5.0, 1.0) == 5.0);82 try expect(copysign32(-5.0, 1.0) == 5.0);
83}83}
8484
85test "math.copysign64" {85test "math.copysign64" {
86 expect(copysign64(5.0, 1.0) == 5.0);86 try expect(copysign64(5.0, 1.0) == 5.0);
87 expect(copysign64(5.0, -1.0) == -5.0);87 try expect(copysign64(5.0, -1.0) == -5.0);
88 expect(copysign64(-5.0, -1.0) == -5.0);88 try expect(copysign64(-5.0, -1.0) == -5.0);
89 expect(copysign64(-5.0, 1.0) == 5.0);89 try expect(copysign64(-5.0, 1.0) == 5.0);
90}90}
9191
92test "math.copysign128" {92test "math.copysign128" {
93 expect(copysign128(5.0, 1.0) == 5.0);93 try expect(copysign128(5.0, 1.0) == 5.0);
94 expect(copysign128(5.0, -1.0) == -5.0);94 try expect(copysign128(5.0, -1.0) == -5.0);
95 expect(copysign128(-5.0, -1.0) == -5.0);95 try expect(copysign128(-5.0, -1.0) == -5.0);
96 expect(copysign128(-5.0, 1.0) == 5.0);96 try expect(copysign128(-5.0, 1.0) == 5.0);
97}97}
lib/std/math/cos.zig+22-22
...@@ -88,42 +88,42 @@ fn cos_(comptime T: type, x_: T) T {...@@ -88,42 +88,42 @@ fn cos_(comptime T: type, x_: T) T {
88}88}
8989
90test "math.cos" {90test "math.cos" {
91 expect(cos(@as(f32, 0.0)) == cos_(f32, 0.0));91 try expect(cos(@as(f32, 0.0)) == cos_(f32, 0.0));
92 expect(cos(@as(f64, 0.0)) == cos_(f64, 0.0));92 try expect(cos(@as(f64, 0.0)) == cos_(f64, 0.0));
93}93}
9494
95test "math.cos32" {95test "math.cos32" {
96 const epsilon = 0.000001;96 const epsilon = 0.000001;
9797
98 expect(math.approxEqAbs(f32, cos_(f32, 0.0), 1.0, epsilon));98 try expect(math.approxEqAbs(f32, cos_(f32, 0.0), 1.0, epsilon));
99 expect(math.approxEqAbs(f32, cos_(f32, 0.2), 0.980067, epsilon));99 try expect(math.approxEqAbs(f32, cos_(f32, 0.2), 0.980067, epsilon));
100 expect(math.approxEqAbs(f32, cos_(f32, 0.8923), 0.627623, epsilon));100 try expect(math.approxEqAbs(f32, cos_(f32, 0.8923), 0.627623, epsilon));
101 expect(math.approxEqAbs(f32, cos_(f32, 1.5), 0.070737, epsilon));101 try expect(math.approxEqAbs(f32, cos_(f32, 1.5), 0.070737, epsilon));
102 expect(math.approxEqAbs(f32, cos_(f32, -1.5), 0.070737, epsilon));102 try expect(math.approxEqAbs(f32, cos_(f32, -1.5), 0.070737, epsilon));
103 expect(math.approxEqAbs(f32, cos_(f32, 37.45), 0.969132, epsilon));103 try expect(math.approxEqAbs(f32, cos_(f32, 37.45), 0.969132, epsilon));
104 expect(math.approxEqAbs(f32, cos_(f32, 89.123), 0.400798, epsilon));104 try expect(math.approxEqAbs(f32, cos_(f32, 89.123), 0.400798, epsilon));
105}105}
106106
107test "math.cos64" {107test "math.cos64" {
108 const epsilon = 0.000001;108 const epsilon = 0.000001;
109109
110 expect(math.approxEqAbs(f64, cos_(f64, 0.0), 1.0, epsilon));110 try expect(math.approxEqAbs(f64, cos_(f64, 0.0), 1.0, epsilon));
111 expect(math.approxEqAbs(f64, cos_(f64, 0.2), 0.980067, epsilon));111 try expect(math.approxEqAbs(f64, cos_(f64, 0.2), 0.980067, epsilon));
112 expect(math.approxEqAbs(f64, cos_(f64, 0.8923), 0.627623, epsilon));112 try expect(math.approxEqAbs(f64, cos_(f64, 0.8923), 0.627623, epsilon));
113 expect(math.approxEqAbs(f64, cos_(f64, 1.5), 0.070737, epsilon));113 try expect(math.approxEqAbs(f64, cos_(f64, 1.5), 0.070737, epsilon));
114 expect(math.approxEqAbs(f64, cos_(f64, -1.5), 0.070737, epsilon));114 try expect(math.approxEqAbs(f64, cos_(f64, -1.5), 0.070737, epsilon));
115 expect(math.approxEqAbs(f64, cos_(f64, 37.45), 0.969132, epsilon));115 try expect(math.approxEqAbs(f64, cos_(f64, 37.45), 0.969132, epsilon));
116 expect(math.approxEqAbs(f64, cos_(f64, 89.123), 0.40080, epsilon));116 try expect(math.approxEqAbs(f64, cos_(f64, 89.123), 0.40080, epsilon));
117}117}
118118
119test "math.cos32.special" {119test "math.cos32.special" {
120 expect(math.isNan(cos_(f32, math.inf(f32))));120 try expect(math.isNan(cos_(f32, math.inf(f32))));
121 expect(math.isNan(cos_(f32, -math.inf(f32))));121 try expect(math.isNan(cos_(f32, -math.inf(f32))));
122 expect(math.isNan(cos_(f32, math.nan(f32))));122 try expect(math.isNan(cos_(f32, math.nan(f32))));
123}123}
124124
125test "math.cos64.special" {125test "math.cos64.special" {
126 expect(math.isNan(cos_(f64, math.inf(f64))));126 try expect(math.isNan(cos_(f64, math.inf(f64))));
127 expect(math.isNan(cos_(f64, -math.inf(f64))));127 try expect(math.isNan(cos_(f64, -math.inf(f64))));
128 expect(math.isNan(cos_(f64, math.nan(f64))));128 try expect(math.isNan(cos_(f64, math.nan(f64))));
129}129}
lib/std/math/cosh.zig+28-28
...@@ -93,48 +93,48 @@ fn cosh64(x: f64) f64 {...@@ -93,48 +93,48 @@ fn cosh64(x: f64) f64 {
93}93}
9494
95test "math.cosh" {95test "math.cosh" {
96 expect(cosh(@as(f32, 1.5)) == cosh32(1.5));96 try expect(cosh(@as(f32, 1.5)) == cosh32(1.5));
97 expect(cosh(@as(f64, 1.5)) == cosh64(1.5));97 try expect(cosh(@as(f64, 1.5)) == cosh64(1.5));
98}98}
9999
100test "math.cosh32" {100test "math.cosh32" {
101 const epsilon = 0.000001;101 const epsilon = 0.000001;
102102
103 expect(math.approxEqAbs(f32, cosh32(0.0), 1.0, epsilon));103 try expect(math.approxEqAbs(f32, cosh32(0.0), 1.0, epsilon));
104 expect(math.approxEqAbs(f32, cosh32(0.2), 1.020067, epsilon));104 try expect(math.approxEqAbs(f32, cosh32(0.2), 1.020067, epsilon));
105 expect(math.approxEqAbs(f32, cosh32(0.8923), 1.425225, epsilon));105 try expect(math.approxEqAbs(f32, cosh32(0.8923), 1.425225, epsilon));
106 expect(math.approxEqAbs(f32, cosh32(1.5), 2.352410, epsilon));106 try expect(math.approxEqAbs(f32, cosh32(1.5), 2.352410, epsilon));
107 expect(math.approxEqAbs(f32, cosh32(-0.0), 1.0, epsilon));107 try expect(math.approxEqAbs(f32, cosh32(-0.0), 1.0, epsilon));
108 expect(math.approxEqAbs(f32, cosh32(-0.2), 1.020067, epsilon));108 try expect(math.approxEqAbs(f32, cosh32(-0.2), 1.020067, epsilon));
109 expect(math.approxEqAbs(f32, cosh32(-0.8923), 1.425225, epsilon));109 try expect(math.approxEqAbs(f32, cosh32(-0.8923), 1.425225, epsilon));
110 expect(math.approxEqAbs(f32, cosh32(-1.5), 2.352410, epsilon));110 try expect(math.approxEqAbs(f32, cosh32(-1.5), 2.352410, epsilon));
111}111}
112112
113test "math.cosh64" {113test "math.cosh64" {
114 const epsilon = 0.000001;114 const epsilon = 0.000001;
115115
116 expect(math.approxEqAbs(f64, cosh64(0.0), 1.0, epsilon));116 try expect(math.approxEqAbs(f64, cosh64(0.0), 1.0, epsilon));
117 expect(math.approxEqAbs(f64, cosh64(0.2), 1.020067, epsilon));117 try expect(math.approxEqAbs(f64, cosh64(0.2), 1.020067, epsilon));
118 expect(math.approxEqAbs(f64, cosh64(0.8923), 1.425225, epsilon));118 try expect(math.approxEqAbs(f64, cosh64(0.8923), 1.425225, epsilon));
119 expect(math.approxEqAbs(f64, cosh64(1.5), 2.352410, epsilon));119 try expect(math.approxEqAbs(f64, cosh64(1.5), 2.352410, epsilon));
120 expect(math.approxEqAbs(f64, cosh64(-0.0), 1.0, epsilon));120 try expect(math.approxEqAbs(f64, cosh64(-0.0), 1.0, epsilon));
121 expect(math.approxEqAbs(f64, cosh64(-0.2), 1.020067, epsilon));121 try expect(math.approxEqAbs(f64, cosh64(-0.2), 1.020067, epsilon));
122 expect(math.approxEqAbs(f64, cosh64(-0.8923), 1.425225, epsilon));122 try expect(math.approxEqAbs(f64, cosh64(-0.8923), 1.425225, epsilon));
123 expect(math.approxEqAbs(f64, cosh64(-1.5), 2.352410, epsilon));123 try expect(math.approxEqAbs(f64, cosh64(-1.5), 2.352410, epsilon));
124}124}
125125
126test "math.cosh32.special" {126test "math.cosh32.special" {
127 expect(cosh32(0.0) == 1.0);127 try expect(cosh32(0.0) == 1.0);
128 expect(cosh32(-0.0) == 1.0);128 try expect(cosh32(-0.0) == 1.0);
129 expect(math.isPositiveInf(cosh32(math.inf(f32))));129 try expect(math.isPositiveInf(cosh32(math.inf(f32))));
130 expect(math.isPositiveInf(cosh32(-math.inf(f32))));130 try expect(math.isPositiveInf(cosh32(-math.inf(f32))));
131 expect(math.isNan(cosh32(math.nan(f32))));131 try expect(math.isNan(cosh32(math.nan(f32))));
132}132}
133133
134test "math.cosh64.special" {134test "math.cosh64.special" {
135 expect(cosh64(0.0) == 1.0);135 try expect(cosh64(0.0) == 1.0);
136 expect(cosh64(-0.0) == 1.0);136 try expect(cosh64(-0.0) == 1.0);
137 expect(math.isPositiveInf(cosh64(math.inf(f64))));137 try expect(math.isPositiveInf(cosh64(math.inf(f64))));
138 expect(math.isPositiveInf(cosh64(-math.inf(f64))));138 try expect(math.isPositiveInf(cosh64(-math.inf(f64))));
139 expect(math.isNan(cosh64(math.nan(f64))));139 try expect(math.isNan(cosh64(math.nan(f64))));
140}140}
lib/std/math/exp.zig+16-16
...@@ -187,36 +187,36 @@ fn exp64(x_: f64) f64 {...@@ -187,36 +187,36 @@ fn exp64(x_: f64) f64 {
187}187}
188188
189test "math.exp" {189test "math.exp" {
190 expect(exp(@as(f32, 0.0)) == exp32(0.0));190 try expect(exp(@as(f32, 0.0)) == exp32(0.0));
191 expect(exp(@as(f64, 0.0)) == exp64(0.0));191 try expect(exp(@as(f64, 0.0)) == exp64(0.0));
192}192}
193193
194test "math.exp32" {194test "math.exp32" {
195 const epsilon = 0.000001;195 const epsilon = 0.000001;
196196
197 expect(exp32(0.0) == 1.0);197 try expect(exp32(0.0) == 1.0);
198 expect(math.approxEqAbs(f32, exp32(0.0), 1.0, epsilon));198 try expect(math.approxEqAbs(f32, exp32(0.0), 1.0, epsilon));
199 expect(math.approxEqAbs(f32, exp32(0.2), 1.221403, epsilon));199 try expect(math.approxEqAbs(f32, exp32(0.2), 1.221403, epsilon));
200 expect(math.approxEqAbs(f32, exp32(0.8923), 2.440737, epsilon));200 try expect(math.approxEqAbs(f32, exp32(0.8923), 2.440737, epsilon));
201 expect(math.approxEqAbs(f32, exp32(1.5), 4.481689, epsilon));201 try expect(math.approxEqAbs(f32, exp32(1.5), 4.481689, epsilon));
202}202}
203203
204test "math.exp64" {204test "math.exp64" {
205 const epsilon = 0.000001;205 const epsilon = 0.000001;
206206
207 expect(exp64(0.0) == 1.0);207 try expect(exp64(0.0) == 1.0);
208 expect(math.approxEqAbs(f64, exp64(0.0), 1.0, epsilon));208 try expect(math.approxEqAbs(f64, exp64(0.0), 1.0, epsilon));
209 expect(math.approxEqAbs(f64, exp64(0.2), 1.221403, epsilon));209 try expect(math.approxEqAbs(f64, exp64(0.2), 1.221403, epsilon));
210 expect(math.approxEqAbs(f64, exp64(0.8923), 2.440737, epsilon));210 try expect(math.approxEqAbs(f64, exp64(0.8923), 2.440737, epsilon));
211 expect(math.approxEqAbs(f64, exp64(1.5), 4.481689, epsilon));211 try expect(math.approxEqAbs(f64, exp64(1.5), 4.481689, epsilon));
212}212}
213213
214test "math.exp32.special" {214test "math.exp32.special" {
215 expect(math.isPositiveInf(exp32(math.inf(f32))));215 try expect(math.isPositiveInf(exp32(math.inf(f32))));
216 expect(math.isNan(exp32(math.nan(f32))));216 try expect(math.isNan(exp32(math.nan(f32))));
217}217}
218218
219test "math.exp64.special" {219test "math.exp64.special" {
220 expect(math.isPositiveInf(exp64(math.inf(f64))));220 try expect(math.isPositiveInf(exp64(math.inf(f64))));
221 expect(math.isNan(exp64(math.nan(f64))));221 try expect(math.isNan(exp64(math.nan(f64))));
222}222}
lib/std/math/exp2.zig+15-15
...@@ -426,35 +426,35 @@ fn exp2_64(x: f64) f64 {...@@ -426,35 +426,35 @@ fn exp2_64(x: f64) f64 {
426}426}
427427
428test "math.exp2" {428test "math.exp2" {
429 expect(exp2(@as(f32, 0.8923)) == exp2_32(0.8923));429 try expect(exp2(@as(f32, 0.8923)) == exp2_32(0.8923));
430 expect(exp2(@as(f64, 0.8923)) == exp2_64(0.8923));430 try expect(exp2(@as(f64, 0.8923)) == exp2_64(0.8923));
431}431}
432432
433test "math.exp2_32" {433test "math.exp2_32" {
434 const epsilon = 0.000001;434 const epsilon = 0.000001;
435435
436 expect(exp2_32(0.0) == 1.0);436 try expect(exp2_32(0.0) == 1.0);
437 expect(math.approxEqAbs(f32, exp2_32(0.2), 1.148698, epsilon));437 try expect(math.approxEqAbs(f32, exp2_32(0.2), 1.148698, epsilon));
438 expect(math.approxEqAbs(f32, exp2_32(0.8923), 1.856133, epsilon));438 try expect(math.approxEqAbs(f32, exp2_32(0.8923), 1.856133, epsilon));
439 expect(math.approxEqAbs(f32, exp2_32(1.5), 2.828427, epsilon));439 try expect(math.approxEqAbs(f32, exp2_32(1.5), 2.828427, epsilon));
440 expect(math.approxEqAbs(f32, exp2_32(37.45), 187747237888, epsilon));440 try expect(math.approxEqAbs(f32, exp2_32(37.45), 187747237888, epsilon));
441}441}
442442
443test "math.exp2_64" {443test "math.exp2_64" {
444 const epsilon = 0.000001;444 const epsilon = 0.000001;
445445
446 expect(exp2_64(0.0) == 1.0);446 try expect(exp2_64(0.0) == 1.0);
447 expect(math.approxEqAbs(f64, exp2_64(0.2), 1.148698, epsilon));447 try expect(math.approxEqAbs(f64, exp2_64(0.2), 1.148698, epsilon));
448 expect(math.approxEqAbs(f64, exp2_64(0.8923), 1.856133, epsilon));448 try expect(math.approxEqAbs(f64, exp2_64(0.8923), 1.856133, epsilon));
449 expect(math.approxEqAbs(f64, exp2_64(1.5), 2.828427, epsilon));449 try expect(math.approxEqAbs(f64, exp2_64(1.5), 2.828427, epsilon));
450}450}
451451
452test "math.exp2_32.special" {452test "math.exp2_32.special" {
453 expect(math.isPositiveInf(exp2_32(math.inf(f32))));453 try expect(math.isPositiveInf(exp2_32(math.inf(f32))));
454 expect(math.isNan(exp2_32(math.nan(f32))));454 try expect(math.isNan(exp2_32(math.nan(f32))));
455}455}
456456
457test "math.exp2_64.special" {457test "math.exp2_64.special" {
458 expect(math.isPositiveInf(exp2_64(math.inf(f64))));458 try expect(math.isPositiveInf(exp2_64(math.inf(f64))));
459 expect(math.isNan(exp2_64(math.nan(f64))));459 try expect(math.isNan(exp2_64(math.nan(f64))));
460}460}
lib/std/math/expm1.zig+18-18
...@@ -292,42 +292,42 @@ fn expm1_64(x_: f64) f64 {...@@ -292,42 +292,42 @@ fn expm1_64(x_: f64) f64 {
292}292}
293293
294test "math.exp1m" {294test "math.exp1m" {
295 expect(expm1(@as(f32, 0.0)) == expm1_32(0.0));295 try expect(expm1(@as(f32, 0.0)) == expm1_32(0.0));
296 expect(expm1(@as(f64, 0.0)) == expm1_64(0.0));296 try expect(expm1(@as(f64, 0.0)) == expm1_64(0.0));
297}297}
298298
299test "math.expm1_32" {299test "math.expm1_32" {
300 const epsilon = 0.000001;300 const epsilon = 0.000001;
301301
302 expect(expm1_32(0.0) == 0.0);302 try expect(expm1_32(0.0) == 0.0);
303 expect(math.approxEqAbs(f32, expm1_32(0.0), 0.0, epsilon));303 try expect(math.approxEqAbs(f32, expm1_32(0.0), 0.0, epsilon));
304 expect(math.approxEqAbs(f32, expm1_32(0.2), 0.221403, epsilon));304 try expect(math.approxEqAbs(f32, expm1_32(0.2), 0.221403, epsilon));
305 expect(math.approxEqAbs(f32, expm1_32(0.8923), 1.440737, epsilon));305 try expect(math.approxEqAbs(f32, expm1_32(0.8923), 1.440737, epsilon));
306 expect(math.approxEqAbs(f32, expm1_32(1.5), 3.481689, epsilon));306 try expect(math.approxEqAbs(f32, expm1_32(1.5), 3.481689, epsilon));
307}307}
308308
309test "math.expm1_64" {309test "math.expm1_64" {
310 const epsilon = 0.000001;310 const epsilon = 0.000001;
311311
312 expect(expm1_64(0.0) == 0.0);312 try expect(expm1_64(0.0) == 0.0);
313 expect(math.approxEqAbs(f64, expm1_64(0.0), 0.0, epsilon));313 try expect(math.approxEqAbs(f64, expm1_64(0.0), 0.0, epsilon));
314 expect(math.approxEqAbs(f64, expm1_64(0.2), 0.221403, epsilon));314 try expect(math.approxEqAbs(f64, expm1_64(0.2), 0.221403, epsilon));
315 expect(math.approxEqAbs(f64, expm1_64(0.8923), 1.440737, epsilon));315 try expect(math.approxEqAbs(f64, expm1_64(0.8923), 1.440737, epsilon));
316 expect(math.approxEqAbs(f64, expm1_64(1.5), 3.481689, epsilon));316 try expect(math.approxEqAbs(f64, expm1_64(1.5), 3.481689, epsilon));
317}317}
318318
319test "math.expm1_32.special" {319test "math.expm1_32.special" {
320 const epsilon = 0.000001;320 const epsilon = 0.000001;
321321
322 expect(math.isPositiveInf(expm1_32(math.inf(f32))));322 try expect(math.isPositiveInf(expm1_32(math.inf(f32))));
323 expect(expm1_32(-math.inf(f32)) == -1.0);323 try expect(expm1_32(-math.inf(f32)) == -1.0);
324 expect(math.isNan(expm1_32(math.nan(f32))));324 try expect(math.isNan(expm1_32(math.nan(f32))));
325}325}
326326
327test "math.expm1_64.special" {327test "math.expm1_64.special" {
328 const epsilon = 0.000001;328 const epsilon = 0.000001;
329329
330 expect(math.isPositiveInf(expm1_64(math.inf(f64))));330 try expect(math.isPositiveInf(expm1_64(math.inf(f64))));
331 expect(expm1_64(-math.inf(f64)) == -1.0);331 try expect(expm1_64(-math.inf(f64)) == -1.0);
332 expect(math.isNan(expm1_64(math.nan(f64))));332 try expect(math.isNan(expm1_64(math.nan(f64))));
333}333}
lib/std/math/fabs.zig+24-24
...@@ -55,52 +55,52 @@ fn fabs128(x: f128) f128 {...@@ -55,52 +55,52 @@ fn fabs128(x: f128) f128 {
55}55}
5656
57test "math.fabs" {57test "math.fabs" {
58 expect(fabs(@as(f16, 1.0)) == fabs16(1.0));58 try expect(fabs(@as(f16, 1.0)) == fabs16(1.0));
59 expect(fabs(@as(f32, 1.0)) == fabs32(1.0));59 try expect(fabs(@as(f32, 1.0)) == fabs32(1.0));
60 expect(fabs(@as(f64, 1.0)) == fabs64(1.0));60 try expect(fabs(@as(f64, 1.0)) == fabs64(1.0));
61 expect(fabs(@as(f128, 1.0)) == fabs128(1.0));61 try expect(fabs(@as(f128, 1.0)) == fabs128(1.0));
62}62}
6363
64test "math.fabs16" {64test "math.fabs16" {
65 expect(fabs16(1.0) == 1.0);65 try expect(fabs16(1.0) == 1.0);
66 expect(fabs16(-1.0) == 1.0);66 try expect(fabs16(-1.0) == 1.0);
67}67}
6868
69test "math.fabs32" {69test "math.fabs32" {
70 expect(fabs32(1.0) == 1.0);70 try expect(fabs32(1.0) == 1.0);
71 expect(fabs32(-1.0) == 1.0);71 try expect(fabs32(-1.0) == 1.0);
72}72}
7373
74test "math.fabs64" {74test "math.fabs64" {
75 expect(fabs64(1.0) == 1.0);75 try expect(fabs64(1.0) == 1.0);
76 expect(fabs64(-1.0) == 1.0);76 try expect(fabs64(-1.0) == 1.0);
77}77}
7878
79test "math.fabs128" {79test "math.fabs128" {
80 expect(fabs128(1.0) == 1.0);80 try expect(fabs128(1.0) == 1.0);
81 expect(fabs128(-1.0) == 1.0);81 try expect(fabs128(-1.0) == 1.0);
82}82}
8383
84test "math.fabs16.special" {84test "math.fabs16.special" {
85 expect(math.isPositiveInf(fabs(math.inf(f16))));85 try expect(math.isPositiveInf(fabs(math.inf(f16))));
86 expect(math.isPositiveInf(fabs(-math.inf(f16))));86 try expect(math.isPositiveInf(fabs(-math.inf(f16))));
87 expect(math.isNan(fabs(math.nan(f16))));87 try expect(math.isNan(fabs(math.nan(f16))));
88}88}
8989
90test "math.fabs32.special" {90test "math.fabs32.special" {
91 expect(math.isPositiveInf(fabs(math.inf(f32))));91 try expect(math.isPositiveInf(fabs(math.inf(f32))));
92 expect(math.isPositiveInf(fabs(-math.inf(f32))));92 try expect(math.isPositiveInf(fabs(-math.inf(f32))));
93 expect(math.isNan(fabs(math.nan(f32))));93 try expect(math.isNan(fabs(math.nan(f32))));
94}94}
9595
96test "math.fabs64.special" {96test "math.fabs64.special" {
97 expect(math.isPositiveInf(fabs(math.inf(f64))));97 try expect(math.isPositiveInf(fabs(math.inf(f64))));
98 expect(math.isPositiveInf(fabs(-math.inf(f64))));98 try expect(math.isPositiveInf(fabs(-math.inf(f64))));
99 expect(math.isNan(fabs(math.nan(f64))));99 try expect(math.isNan(fabs(math.nan(f64))));
100}100}
101101
102test "math.fabs128.special" {102test "math.fabs128.special" {
103 expect(math.isPositiveInf(fabs(math.inf(f128))));103 try expect(math.isPositiveInf(fabs(math.inf(f128))));
104 expect(math.isPositiveInf(fabs(-math.inf(f128))));104 try expect(math.isPositiveInf(fabs(-math.inf(f128))));
105 expect(math.isNan(fabs(math.nan(f128))));105 try expect(math.isNan(fabs(math.nan(f128))));
106}106}
lib/std/math/floor.zig+36-36
...@@ -156,64 +156,64 @@ fn floor128(x: f128) f128 {...@@ -156,64 +156,64 @@ fn floor128(x: f128) f128 {
156}156}
157157
158test "math.floor" {158test "math.floor" {
159 expect(floor(@as(f16, 1.3)) == floor16(1.3));159 try expect(floor(@as(f16, 1.3)) == floor16(1.3));
160 expect(floor(@as(f32, 1.3)) == floor32(1.3));160 try expect(floor(@as(f32, 1.3)) == floor32(1.3));
161 expect(floor(@as(f64, 1.3)) == floor64(1.3));161 try expect(floor(@as(f64, 1.3)) == floor64(1.3));
162 expect(floor(@as(f128, 1.3)) == floor128(1.3));162 try expect(floor(@as(f128, 1.3)) == floor128(1.3));
163}163}
164164
165test "math.floor16" {165test "math.floor16" {
166 expect(floor16(1.3) == 1.0);166 try expect(floor16(1.3) == 1.0);
167 expect(floor16(-1.3) == -2.0);167 try expect(floor16(-1.3) == -2.0);
168 expect(floor16(0.2) == 0.0);168 try expect(floor16(0.2) == 0.0);
169}169}
170170
171test "math.floor32" {171test "math.floor32" {
172 expect(floor32(1.3) == 1.0);172 try expect(floor32(1.3) == 1.0);
173 expect(floor32(-1.3) == -2.0);173 try expect(floor32(-1.3) == -2.0);
174 expect(floor32(0.2) == 0.0);174 try expect(floor32(0.2) == 0.0);
175}175}
176176
177test "math.floor64" {177test "math.floor64" {
178 expect(floor64(1.3) == 1.0);178 try expect(floor64(1.3) == 1.0);
179 expect(floor64(-1.3) == -2.0);179 try expect(floor64(-1.3) == -2.0);
180 expect(floor64(0.2) == 0.0);180 try expect(floor64(0.2) == 0.0);
181}181}
182182
183test "math.floor128" {183test "math.floor128" {
184 expect(floor128(1.3) == 1.0);184 try expect(floor128(1.3) == 1.0);
185 expect(floor128(-1.3) == -2.0);185 try expect(floor128(-1.3) == -2.0);
186 expect(floor128(0.2) == 0.0);186 try expect(floor128(0.2) == 0.0);
187}187}
188188
189test "math.floor16.special" {189test "math.floor16.special" {
190 expect(floor16(0.0) == 0.0);190 try expect(floor16(0.0) == 0.0);
191 expect(floor16(-0.0) == -0.0);191 try expect(floor16(-0.0) == -0.0);
192 expect(math.isPositiveInf(floor16(math.inf(f16))));192 try expect(math.isPositiveInf(floor16(math.inf(f16))));
193 expect(math.isNegativeInf(floor16(-math.inf(f16))));193 try expect(math.isNegativeInf(floor16(-math.inf(f16))));
194 expect(math.isNan(floor16(math.nan(f16))));194 try expect(math.isNan(floor16(math.nan(f16))));
195}195}
196196
197test "math.floor32.special" {197test "math.floor32.special" {
198 expect(floor32(0.0) == 0.0);198 try expect(floor32(0.0) == 0.0);
199 expect(floor32(-0.0) == -0.0);199 try expect(floor32(-0.0) == -0.0);
200 expect(math.isPositiveInf(floor32(math.inf(f32))));200 try expect(math.isPositiveInf(floor32(math.inf(f32))));
201 expect(math.isNegativeInf(floor32(-math.inf(f32))));201 try expect(math.isNegativeInf(floor32(-math.inf(f32))));
202 expect(math.isNan(floor32(math.nan(f32))));202 try expect(math.isNan(floor32(math.nan(f32))));
203}203}
204204
205test "math.floor64.special" {205test "math.floor64.special" {
206 expect(floor64(0.0) == 0.0);206 try expect(floor64(0.0) == 0.0);
207 expect(floor64(-0.0) == -0.0);207 try expect(floor64(-0.0) == -0.0);
208 expect(math.isPositiveInf(floor64(math.inf(f64))));208 try expect(math.isPositiveInf(floor64(math.inf(f64))));
209 expect(math.isNegativeInf(floor64(-math.inf(f64))));209 try expect(math.isNegativeInf(floor64(-math.inf(f64))));
210 expect(math.isNan(floor64(math.nan(f64))));210 try expect(math.isNan(floor64(math.nan(f64))));
211}211}
212212
213test "math.floor128.special" {213test "math.floor128.special" {
214 expect(floor128(0.0) == 0.0);214 try expect(floor128(0.0) == 0.0);
215 expect(floor128(-0.0) == -0.0);215 try expect(floor128(-0.0) == -0.0);
216 expect(math.isPositiveInf(floor128(math.inf(f128))));216 try expect(math.isPositiveInf(floor128(math.inf(f128))));
217 expect(math.isNegativeInf(floor128(-math.inf(f128))));217 try expect(math.isNegativeInf(floor128(-math.inf(f128))));
218 expect(math.isNan(floor128(math.nan(f128))));218 try expect(math.isNan(floor128(math.nan(f128))));
219}219}
lib/std/math/fma.zig+16-16
...@@ -148,30 +148,30 @@ fn add_and_denorm(a: f64, b: f64, scale: i32) f64 {...@@ -148,30 +148,30 @@ fn add_and_denorm(a: f64, b: f64, scale: i32) f64 {
148}148}
149149
150test "math.fma" {150test "math.fma" {
151 expect(fma(f32, 0.0, 1.0, 1.0) == fma32(0.0, 1.0, 1.0));151 try expect(fma(f32, 0.0, 1.0, 1.0) == fma32(0.0, 1.0, 1.0));
152 expect(fma(f64, 0.0, 1.0, 1.0) == fma64(0.0, 1.0, 1.0));152 try expect(fma(f64, 0.0, 1.0, 1.0) == fma64(0.0, 1.0, 1.0));
153}153}
154154
155test "math.fma32" {155test "math.fma32" {
156 const epsilon = 0.000001;156 const epsilon = 0.000001;
157157
158 expect(math.approxEqAbs(f32, fma32(0.0, 5.0, 9.124), 9.124, epsilon));158 try expect(math.approxEqAbs(f32, fma32(0.0, 5.0, 9.124), 9.124, epsilon));
159 expect(math.approxEqAbs(f32, fma32(0.2, 5.0, 9.124), 10.124, epsilon));159 try expect(math.approxEqAbs(f32, fma32(0.2, 5.0, 9.124), 10.124, epsilon));
160 expect(math.approxEqAbs(f32, fma32(0.8923, 5.0, 9.124), 13.5855, epsilon));160 try expect(math.approxEqAbs(f32, fma32(0.8923, 5.0, 9.124), 13.5855, epsilon));
161 expect(math.approxEqAbs(f32, fma32(1.5, 5.0, 9.124), 16.624, epsilon));161 try expect(math.approxEqAbs(f32, fma32(1.5, 5.0, 9.124), 16.624, epsilon));
162 expect(math.approxEqAbs(f32, fma32(37.45, 5.0, 9.124), 196.374004, epsilon));162 try expect(math.approxEqAbs(f32, fma32(37.45, 5.0, 9.124), 196.374004, epsilon));
163 expect(math.approxEqAbs(f32, fma32(89.123, 5.0, 9.124), 454.739005, epsilon));163 try expect(math.approxEqAbs(f32, fma32(89.123, 5.0, 9.124), 454.739005, epsilon));
164 expect(math.approxEqAbs(f32, fma32(123123.234375, 5.0, 9.124), 615625.295875, epsilon));164 try expect(math.approxEqAbs(f32, fma32(123123.234375, 5.0, 9.124), 615625.295875, epsilon));
165}165}
166166
167test "math.fma64" {167test "math.fma64" {
168 const epsilon = 0.000001;168 const epsilon = 0.000001;
169169
170 expect(math.approxEqAbs(f64, fma64(0.0, 5.0, 9.124), 9.124, epsilon));170 try expect(math.approxEqAbs(f64, fma64(0.0, 5.0, 9.124), 9.124, epsilon));
171 expect(math.approxEqAbs(f64, fma64(0.2, 5.0, 9.124), 10.124, epsilon));171 try expect(math.approxEqAbs(f64, fma64(0.2, 5.0, 9.124), 10.124, epsilon));
172 expect(math.approxEqAbs(f64, fma64(0.8923, 5.0, 9.124), 13.5855, epsilon));172 try expect(math.approxEqAbs(f64, fma64(0.8923, 5.0, 9.124), 13.5855, epsilon));
173 expect(math.approxEqAbs(f64, fma64(1.5, 5.0, 9.124), 16.624, epsilon));173 try expect(math.approxEqAbs(f64, fma64(1.5, 5.0, 9.124), 16.624, epsilon));
174 expect(math.approxEqAbs(f64, fma64(37.45, 5.0, 9.124), 196.374, epsilon));174 try expect(math.approxEqAbs(f64, fma64(37.45, 5.0, 9.124), 196.374, epsilon));
175 expect(math.approxEqAbs(f64, fma64(89.123, 5.0, 9.124), 454.739, epsilon));175 try expect(math.approxEqAbs(f64, fma64(89.123, 5.0, 9.124), 454.739, epsilon));
176 expect(math.approxEqAbs(f64, fma64(123123.234375, 5.0, 9.124), 615625.295875, epsilon));176 try expect(math.approxEqAbs(f64, fma64(123123.234375, 5.0, 9.124), 615625.295875, epsilon));
177}177}
lib/std/math/frexp.zig+16-16
...@@ -115,11 +115,11 @@ fn frexp64(x: f64) frexp64_result {...@@ -115,11 +115,11 @@ fn frexp64(x: f64) frexp64_result {
115test "math.frexp" {115test "math.frexp" {
116 const a = frexp(@as(f32, 1.3));116 const a = frexp(@as(f32, 1.3));
117 const b = frexp32(1.3);117 const b = frexp32(1.3);
118 expect(a.significand == b.significand and a.exponent == b.exponent);118 try expect(a.significand == b.significand and a.exponent == b.exponent);
119119
120 const c = frexp(@as(f64, 1.3));120 const c = frexp(@as(f64, 1.3));
121 const d = frexp64(1.3);121 const d = frexp64(1.3);
122 expect(c.significand == d.significand and c.exponent == d.exponent);122 try expect(c.significand == d.significand and c.exponent == d.exponent);
123}123}
124124
125test "math.frexp32" {125test "math.frexp32" {
...@@ -127,10 +127,10 @@ test "math.frexp32" {...@@ -127,10 +127,10 @@ test "math.frexp32" {
127 var r: frexp32_result = undefined;127 var r: frexp32_result = undefined;
128128
129 r = frexp32(1.3);129 r = frexp32(1.3);
130 expect(math.approxEqAbs(f32, r.significand, 0.65, epsilon) and r.exponent == 1);130 try expect(math.approxEqAbs(f32, r.significand, 0.65, epsilon) and r.exponent == 1);
131131
132 r = frexp32(78.0234);132 r = frexp32(78.0234);
133 expect(math.approxEqAbs(f32, r.significand, 0.609558, epsilon) and r.exponent == 7);133 try expect(math.approxEqAbs(f32, r.significand, 0.609558, epsilon) and r.exponent == 7);
134}134}
135135
136test "math.frexp64" {136test "math.frexp64" {
...@@ -138,46 +138,46 @@ test "math.frexp64" {...@@ -138,46 +138,46 @@ test "math.frexp64" {
138 var r: frexp64_result = undefined;138 var r: frexp64_result = undefined;
139139
140 r = frexp64(1.3);140 r = frexp64(1.3);
141 expect(math.approxEqAbs(f64, r.significand, 0.65, epsilon) and r.exponent == 1);141 try expect(math.approxEqAbs(f64, r.significand, 0.65, epsilon) and r.exponent == 1);
142142
143 r = frexp64(78.0234);143 r = frexp64(78.0234);
144 expect(math.approxEqAbs(f64, r.significand, 0.609558, epsilon) and r.exponent == 7);144 try expect(math.approxEqAbs(f64, r.significand, 0.609558, epsilon) and r.exponent == 7);
145}145}
146146
147test "math.frexp32.special" {147test "math.frexp32.special" {
148 var r: frexp32_result = undefined;148 var r: frexp32_result = undefined;
149149
150 r = frexp32(0.0);150 r = frexp32(0.0);
151 expect(r.significand == 0.0 and r.exponent == 0);151 try expect(r.significand == 0.0 and r.exponent == 0);
152152
153 r = frexp32(-0.0);153 r = frexp32(-0.0);
154 expect(r.significand == -0.0 and r.exponent == 0);154 try expect(r.significand == -0.0 and r.exponent == 0);
155155
156 r = frexp32(math.inf(f32));156 r = frexp32(math.inf(f32));
157 expect(math.isPositiveInf(r.significand) and r.exponent == 0);157 try expect(math.isPositiveInf(r.significand) and r.exponent == 0);
158158
159 r = frexp32(-math.inf(f32));159 r = frexp32(-math.inf(f32));
160 expect(math.isNegativeInf(r.significand) and r.exponent == 0);160 try expect(math.isNegativeInf(r.significand) and r.exponent == 0);
161161
162 r = frexp32(math.nan(f32));162 r = frexp32(math.nan(f32));
163 expect(math.isNan(r.significand));163 try expect(math.isNan(r.significand));
164}164}
165165
166test "math.frexp64.special" {166test "math.frexp64.special" {
167 var r: frexp64_result = undefined;167 var r: frexp64_result = undefined;
168168
169 r = frexp64(0.0);169 r = frexp64(0.0);
170 expect(r.significand == 0.0 and r.exponent == 0);170 try expect(r.significand == 0.0 and r.exponent == 0);
171171
172 r = frexp64(-0.0);172 r = frexp64(-0.0);
173 expect(r.significand == -0.0 and r.exponent == 0);173 try expect(r.significand == -0.0 and r.exponent == 0);
174174
175 r = frexp64(math.inf(f64));175 r = frexp64(math.inf(f64));
176 expect(math.isPositiveInf(r.significand) and r.exponent == 0);176 try expect(math.isPositiveInf(r.significand) and r.exponent == 0);
177177
178 r = frexp64(-math.inf(f64));178 r = frexp64(-math.inf(f64));
179 expect(math.isNegativeInf(r.significand) and r.exponent == 0);179 try expect(math.isNegativeInf(r.significand) and r.exponent == 0);
180180
181 r = frexp64(math.nan(f64));181 r = frexp64(math.nan(f64));
182 expect(math.isNan(r.significand));182 try expect(math.isNan(r.significand));
183}183}
lib/std/math/hypot.zig+28-28
...@@ -126,48 +126,48 @@ fn hypot64(x: f64, y: f64) f64 {...@@ -126,48 +126,48 @@ fn hypot64(x: f64, y: f64) f64 {
126}126}
127127
128test "math.hypot" {128test "math.hypot" {
129 expect(hypot(f32, 0.0, -1.2) == hypot32(0.0, -1.2));129 try expect(hypot(f32, 0.0, -1.2) == hypot32(0.0, -1.2));
130 expect(hypot(f64, 0.0, -1.2) == hypot64(0.0, -1.2));130 try expect(hypot(f64, 0.0, -1.2) == hypot64(0.0, -1.2));
131}131}
132132
133test "math.hypot32" {133test "math.hypot32" {
134 const epsilon = 0.000001;134 const epsilon = 0.000001;
135135
136 expect(math.approxEqAbs(f32, hypot32(0.0, -1.2), 1.2, epsilon));136 try expect(math.approxEqAbs(f32, hypot32(0.0, -1.2), 1.2, epsilon));
137 expect(math.approxEqAbs(f32, hypot32(0.2, -0.34), 0.394462, epsilon));137 try expect(math.approxEqAbs(f32, hypot32(0.2, -0.34), 0.394462, epsilon));
138 expect(math.approxEqAbs(f32, hypot32(0.8923, 2.636890), 2.783772, epsilon));138 try expect(math.approxEqAbs(f32, hypot32(0.8923, 2.636890), 2.783772, epsilon));
139 expect(math.approxEqAbs(f32, hypot32(1.5, 5.25), 5.460083, epsilon));139 try expect(math.approxEqAbs(f32, hypot32(1.5, 5.25), 5.460083, epsilon));
140 expect(math.approxEqAbs(f32, hypot32(37.45, 159.835), 164.163742, epsilon));140 try expect(math.approxEqAbs(f32, hypot32(37.45, 159.835), 164.163742, epsilon));
141 expect(math.approxEqAbs(f32, hypot32(89.123, 382.028905), 392.286865, epsilon));141 try expect(math.approxEqAbs(f32, hypot32(89.123, 382.028905), 392.286865, epsilon));
142 expect(math.approxEqAbs(f32, hypot32(123123.234375, 529428.707813), 543556.875, epsilon));142 try expect(math.approxEqAbs(f32, hypot32(123123.234375, 529428.707813), 543556.875, epsilon));
143}143}
144144
145test "math.hypot64" {145test "math.hypot64" {
146 const epsilon = 0.000001;146 const epsilon = 0.000001;
147147
148 expect(math.approxEqAbs(f64, hypot64(0.0, -1.2), 1.2, epsilon));148 try expect(math.approxEqAbs(f64, hypot64(0.0, -1.2), 1.2, epsilon));
149 expect(math.approxEqAbs(f64, hypot64(0.2, -0.34), 0.394462, epsilon));149 try expect(math.approxEqAbs(f64, hypot64(0.2, -0.34), 0.394462, epsilon));
150 expect(math.approxEqAbs(f64, hypot64(0.8923, 2.636890), 2.783772, epsilon));150 try expect(math.approxEqAbs(f64, hypot64(0.8923, 2.636890), 2.783772, epsilon));
151 expect(math.approxEqAbs(f64, hypot64(1.5, 5.25), 5.460082, epsilon));151 try expect(math.approxEqAbs(f64, hypot64(1.5, 5.25), 5.460082, epsilon));
152 expect(math.approxEqAbs(f64, hypot64(37.45, 159.835), 164.163728, epsilon));152 try expect(math.approxEqAbs(f64, hypot64(37.45, 159.835), 164.163728, epsilon));
153 expect(math.approxEqAbs(f64, hypot64(89.123, 382.028905), 392.286876, epsilon));153 try expect(math.approxEqAbs(f64, hypot64(89.123, 382.028905), 392.286876, epsilon));
154 expect(math.approxEqAbs(f64, hypot64(123123.234375, 529428.707813), 543556.885247, epsilon));154 try expect(math.approxEqAbs(f64, hypot64(123123.234375, 529428.707813), 543556.885247, epsilon));
155}155}
156156
157test "math.hypot32.special" {157test "math.hypot32.special" {
158 expect(math.isPositiveInf(hypot32(math.inf(f32), 0.0)));158 try expect(math.isPositiveInf(hypot32(math.inf(f32), 0.0)));
159 expect(math.isPositiveInf(hypot32(-math.inf(f32), 0.0)));159 try expect(math.isPositiveInf(hypot32(-math.inf(f32), 0.0)));
160 expect(math.isPositiveInf(hypot32(0.0, math.inf(f32))));160 try expect(math.isPositiveInf(hypot32(0.0, math.inf(f32))));
161 expect(math.isPositiveInf(hypot32(0.0, -math.inf(f32))));161 try expect(math.isPositiveInf(hypot32(0.0, -math.inf(f32))));
162 expect(math.isNan(hypot32(math.nan(f32), 0.0)));162 try expect(math.isNan(hypot32(math.nan(f32), 0.0)));
163 expect(math.isNan(hypot32(0.0, math.nan(f32))));163 try expect(math.isNan(hypot32(0.0, math.nan(f32))));
164}164}
165165
166test "math.hypot64.special" {166test "math.hypot64.special" {
167 expect(math.isPositiveInf(hypot64(math.inf(f64), 0.0)));167 try expect(math.isPositiveInf(hypot64(math.inf(f64), 0.0)));
168 expect(math.isPositiveInf(hypot64(-math.inf(f64), 0.0)));168 try expect(math.isPositiveInf(hypot64(-math.inf(f64), 0.0)));
169 expect(math.isPositiveInf(hypot64(0.0, math.inf(f64))));169 try expect(math.isPositiveInf(hypot64(0.0, math.inf(f64))));
170 expect(math.isPositiveInf(hypot64(0.0, -math.inf(f64))));170 try expect(math.isPositiveInf(hypot64(0.0, -math.inf(f64))));
171 expect(math.isNan(hypot64(math.nan(f64), 0.0)));171 try expect(math.isNan(hypot64(math.nan(f64), 0.0)));
172 expect(math.isNan(hypot64(0.0, math.nan(f64))));172 try expect(math.isNan(hypot64(0.0, math.nan(f64))));
173}173}
lib/std/math/ilogb.zig+22-22
...@@ -106,38 +106,38 @@ fn ilogb64(x: f64) i32 {...@@ -106,38 +106,38 @@ fn ilogb64(x: f64) i32 {
106}106}
107107
108test "math.ilogb" {108test "math.ilogb" {
109 expect(ilogb(@as(f32, 0.2)) == ilogb32(0.2));109 try expect(ilogb(@as(f32, 0.2)) == ilogb32(0.2));
110 expect(ilogb(@as(f64, 0.2)) == ilogb64(0.2));110 try expect(ilogb(@as(f64, 0.2)) == ilogb64(0.2));
111}111}
112112
113test "math.ilogb32" {113test "math.ilogb32" {
114 expect(ilogb32(0.0) == fp_ilogb0);114 try expect(ilogb32(0.0) == fp_ilogb0);
115 expect(ilogb32(0.5) == -1);115 try expect(ilogb32(0.5) == -1);
116 expect(ilogb32(0.8923) == -1);116 try expect(ilogb32(0.8923) == -1);
117 expect(ilogb32(10.0) == 3);117 try expect(ilogb32(10.0) == 3);
118 expect(ilogb32(-123984) == 16);118 try expect(ilogb32(-123984) == 16);
119 expect(ilogb32(2398.23) == 11);119 try expect(ilogb32(2398.23) == 11);
120}120}
121121
122test "math.ilogb64" {122test "math.ilogb64" {
123 expect(ilogb64(0.0) == fp_ilogb0);123 try expect(ilogb64(0.0) == fp_ilogb0);
124 expect(ilogb64(0.5) == -1);124 try expect(ilogb64(0.5) == -1);
125 expect(ilogb64(0.8923) == -1);125 try expect(ilogb64(0.8923) == -1);
126 expect(ilogb64(10.0) == 3);126 try expect(ilogb64(10.0) == 3);
127 expect(ilogb64(-123984) == 16);127 try expect(ilogb64(-123984) == 16);
128 expect(ilogb64(2398.23) == 11);128 try expect(ilogb64(2398.23) == 11);
129}129}
130130
131test "math.ilogb32.special" {131test "math.ilogb32.special" {
132 expect(ilogb32(math.inf(f32)) == maxInt(i32));132 try expect(ilogb32(math.inf(f32)) == maxInt(i32));
133 expect(ilogb32(-math.inf(f32)) == maxInt(i32));133 try expect(ilogb32(-math.inf(f32)) == maxInt(i32));
134 expect(ilogb32(0.0) == minInt(i32));134 try expect(ilogb32(0.0) == minInt(i32));
135 expect(ilogb32(math.nan(f32)) == maxInt(i32));135 try expect(ilogb32(math.nan(f32)) == maxInt(i32));
136}136}
137137
138test "math.ilogb64.special" {138test "math.ilogb64.special" {
139 expect(ilogb64(math.inf(f64)) == maxInt(i32));139 try expect(ilogb64(math.inf(f64)) == maxInt(i32));
140 expect(ilogb64(-math.inf(f64)) == maxInt(i32));140 try expect(ilogb64(-math.inf(f64)) == maxInt(i32));
141 expect(ilogb64(0.0) == minInt(i32));141 try expect(ilogb64(0.0) == minInt(i32));
142 expect(ilogb64(math.nan(f64)) == maxInt(i32));142 try expect(ilogb64(math.nan(f64)) == maxInt(i32));
143}143}
lib/std/math/isfinite.zig+24-24
...@@ -35,30 +35,30 @@ pub fn isFinite(x: anytype) bool {...@@ -35,30 +35,30 @@ pub fn isFinite(x: anytype) bool {
35}35}
3636
37test "math.isFinite" {37test "math.isFinite" {
38 expect(isFinite(@as(f16, 0.0)));38 try expect(isFinite(@as(f16, 0.0)));
39 expect(isFinite(@as(f16, -0.0)));39 try expect(isFinite(@as(f16, -0.0)));
40 expect(isFinite(@as(f32, 0.0)));40 try expect(isFinite(@as(f32, 0.0)));
41 expect(isFinite(@as(f32, -0.0)));41 try expect(isFinite(@as(f32, -0.0)));
42 expect(isFinite(@as(f64, 0.0)));42 try expect(isFinite(@as(f64, 0.0)));
43 expect(isFinite(@as(f64, -0.0)));43 try expect(isFinite(@as(f64, -0.0)));
44 expect(isFinite(@as(f128, 0.0)));44 try expect(isFinite(@as(f128, 0.0)));
45 expect(isFinite(@as(f128, -0.0)));45 try expect(isFinite(@as(f128, -0.0)));
4646
47 expect(!isFinite(math.inf(f16)));47 try expect(!isFinite(math.inf(f16)));
48 expect(!isFinite(-math.inf(f16)));48 try expect(!isFinite(-math.inf(f16)));
49 expect(!isFinite(math.inf(f32)));49 try expect(!isFinite(math.inf(f32)));
50 expect(!isFinite(-math.inf(f32)));50 try expect(!isFinite(-math.inf(f32)));
51 expect(!isFinite(math.inf(f64)));51 try expect(!isFinite(math.inf(f64)));
52 expect(!isFinite(-math.inf(f64)));52 try expect(!isFinite(-math.inf(f64)));
53 expect(!isFinite(math.inf(f128)));53 try expect(!isFinite(math.inf(f128)));
54 expect(!isFinite(-math.inf(f128)));54 try expect(!isFinite(-math.inf(f128)));
5555
56 expect(!isFinite(math.nan(f16)));56 try expect(!isFinite(math.nan(f16)));
57 expect(!isFinite(-math.nan(f16)));57 try expect(!isFinite(-math.nan(f16)));
58 expect(!isFinite(math.nan(f32)));58 try expect(!isFinite(math.nan(f32)));
59 expect(!isFinite(-math.nan(f32)));59 try expect(!isFinite(-math.nan(f32)));
60 expect(!isFinite(math.nan(f64)));60 try expect(!isFinite(math.nan(f64)));
61 expect(!isFinite(-math.nan(f64)));61 try expect(!isFinite(-math.nan(f64)));
62 expect(!isFinite(math.nan(f128)));62 try expect(!isFinite(math.nan(f128)));
63 expect(!isFinite(-math.nan(f128)));63 try expect(!isFinite(-math.nan(f128)));
64}64}
lib/std/math/isinf.zig+48-48
...@@ -79,58 +79,58 @@ pub fn isNegativeInf(x: anytype) bool {...@@ -79,58 +79,58 @@ pub fn isNegativeInf(x: anytype) bool {
79}79}
8080
81test "math.isInf" {81test "math.isInf" {
82 expect(!isInf(@as(f16, 0.0)));82 try expect(!isInf(@as(f16, 0.0)));
83 expect(!isInf(@as(f16, -0.0)));83 try expect(!isInf(@as(f16, -0.0)));
84 expect(!isInf(@as(f32, 0.0)));84 try expect(!isInf(@as(f32, 0.0)));
85 expect(!isInf(@as(f32, -0.0)));85 try expect(!isInf(@as(f32, -0.0)));
86 expect(!isInf(@as(f64, 0.0)));86 try expect(!isInf(@as(f64, 0.0)));
87 expect(!isInf(@as(f64, -0.0)));87 try expect(!isInf(@as(f64, -0.0)));
88 expect(!isInf(@as(f128, 0.0)));88 try expect(!isInf(@as(f128, 0.0)));
89 expect(!isInf(@as(f128, -0.0)));89 try expect(!isInf(@as(f128, -0.0)));
90 expect(isInf(math.inf(f16)));90 try expect(isInf(math.inf(f16)));
91 expect(isInf(-math.inf(f16)));91 try expect(isInf(-math.inf(f16)));
92 expect(isInf(math.inf(f32)));92 try expect(isInf(math.inf(f32)));
93 expect(isInf(-math.inf(f32)));93 try expect(isInf(-math.inf(f32)));
94 expect(isInf(math.inf(f64)));94 try expect(isInf(math.inf(f64)));
95 expect(isInf(-math.inf(f64)));95 try expect(isInf(-math.inf(f64)));
96 expect(isInf(math.inf(f128)));96 try expect(isInf(math.inf(f128)));
97 expect(isInf(-math.inf(f128)));97 try expect(isInf(-math.inf(f128)));
98}98}
9999
100test "math.isPositiveInf" {100test "math.isPositiveInf" {
101 expect(!isPositiveInf(@as(f16, 0.0)));101 try expect(!isPositiveInf(@as(f16, 0.0)));
102 expect(!isPositiveInf(@as(f16, -0.0)));102 try expect(!isPositiveInf(@as(f16, -0.0)));
103 expect(!isPositiveInf(@as(f32, 0.0)));103 try expect(!isPositiveInf(@as(f32, 0.0)));
104 expect(!isPositiveInf(@as(f32, -0.0)));104 try expect(!isPositiveInf(@as(f32, -0.0)));
105 expect(!isPositiveInf(@as(f64, 0.0)));105 try expect(!isPositiveInf(@as(f64, 0.0)));
106 expect(!isPositiveInf(@as(f64, -0.0)));106 try expect(!isPositiveInf(@as(f64, -0.0)));
107 expect(!isPositiveInf(@as(f128, 0.0)));107 try expect(!isPositiveInf(@as(f128, 0.0)));
108 expect(!isPositiveInf(@as(f128, -0.0)));108 try expect(!isPositiveInf(@as(f128, -0.0)));
109 expect(isPositiveInf(math.inf(f16)));109 try expect(isPositiveInf(math.inf(f16)));
110 expect(!isPositiveInf(-math.inf(f16)));110 try expect(!isPositiveInf(-math.inf(f16)));
111 expect(isPositiveInf(math.inf(f32)));111 try expect(isPositiveInf(math.inf(f32)));
112 expect(!isPositiveInf(-math.inf(f32)));112 try expect(!isPositiveInf(-math.inf(f32)));
113 expect(isPositiveInf(math.inf(f64)));113 try expect(isPositiveInf(math.inf(f64)));
114 expect(!isPositiveInf(-math.inf(f64)));114 try expect(!isPositiveInf(-math.inf(f64)));
115 expect(isPositiveInf(math.inf(f128)));115 try expect(isPositiveInf(math.inf(f128)));
116 expect(!isPositiveInf(-math.inf(f128)));116 try expect(!isPositiveInf(-math.inf(f128)));
117}117}
118118
119test "math.isNegativeInf" {119test "math.isNegativeInf" {
120 expect(!isNegativeInf(@as(f16, 0.0)));120 try expect(!isNegativeInf(@as(f16, 0.0)));
121 expect(!isNegativeInf(@as(f16, -0.0)));121 try expect(!isNegativeInf(@as(f16, -0.0)));
122 expect(!isNegativeInf(@as(f32, 0.0)));122 try expect(!isNegativeInf(@as(f32, 0.0)));
123 expect(!isNegativeInf(@as(f32, -0.0)));123 try expect(!isNegativeInf(@as(f32, -0.0)));
124 expect(!isNegativeInf(@as(f64, 0.0)));124 try expect(!isNegativeInf(@as(f64, 0.0)));
125 expect(!isNegativeInf(@as(f64, -0.0)));125 try expect(!isNegativeInf(@as(f64, -0.0)));
126 expect(!isNegativeInf(@as(f128, 0.0)));126 try expect(!isNegativeInf(@as(f128, 0.0)));
127 expect(!isNegativeInf(@as(f128, -0.0)));127 try expect(!isNegativeInf(@as(f128, -0.0)));
128 expect(!isNegativeInf(math.inf(f16)));128 try expect(!isNegativeInf(math.inf(f16)));
129 expect(isNegativeInf(-math.inf(f16)));129 try expect(isNegativeInf(-math.inf(f16)));
130 expect(!isNegativeInf(math.inf(f32)));130 try expect(!isNegativeInf(math.inf(f32)));
131 expect(isNegativeInf(-math.inf(f32)));131 try expect(isNegativeInf(-math.inf(f32)));
132 expect(!isNegativeInf(math.inf(f64)));132 try expect(!isNegativeInf(math.inf(f64)));
133 expect(isNegativeInf(-math.inf(f64)));133 try expect(isNegativeInf(-math.inf(f64)));
134 expect(!isNegativeInf(math.inf(f128)));134 try expect(!isNegativeInf(math.inf(f128)));
135 expect(isNegativeInf(-math.inf(f128)));135 try expect(isNegativeInf(-math.inf(f128)));
136}136}
lib/std/math/isnan.zig+8-8
...@@ -21,12 +21,12 @@ pub fn isSignalNan(x: anytype) bool {...@@ -21,12 +21,12 @@ pub fn isSignalNan(x: anytype) bool {
21}21}
2222
23test "math.isNan" {23test "math.isNan" {
24 expect(isNan(math.nan(f16)));24 try expect(isNan(math.nan(f16)));
25 expect(isNan(math.nan(f32)));25 try expect(isNan(math.nan(f32)));
26 expect(isNan(math.nan(f64)));26 try expect(isNan(math.nan(f64)));
27 expect(isNan(math.nan(f128)));27 try expect(isNan(math.nan(f128)));
28 expect(!isNan(@as(f16, 1.0)));28 try expect(!isNan(@as(f16, 1.0)));
29 expect(!isNan(@as(f32, 1.0)));29 try expect(!isNan(@as(f32, 1.0)));
30 expect(!isNan(@as(f64, 1.0)));30 try expect(!isNan(@as(f64, 1.0)));
31 expect(!isNan(@as(f128, 1.0)));31 try expect(!isNan(@as(f128, 1.0)));
32}32}
lib/std/math/isnormal.zig+9-9
...@@ -31,13 +31,13 @@ pub fn isNormal(x: anytype) bool {...@@ -31,13 +31,13 @@ pub fn isNormal(x: anytype) bool {
31}31}
3232
33test "math.isNormal" {33test "math.isNormal" {
34 expect(!isNormal(math.nan(f16)));34 try expect(!isNormal(math.nan(f16)));
35 expect(!isNormal(math.nan(f32)));35 try expect(!isNormal(math.nan(f32)));
36 expect(!isNormal(math.nan(f64)));36 try expect(!isNormal(math.nan(f64)));
37 expect(!isNormal(@as(f16, 0)));37 try expect(!isNormal(@as(f16, 0)));
38 expect(!isNormal(@as(f32, 0)));38 try expect(!isNormal(@as(f32, 0)));
39 expect(!isNormal(@as(f64, 0)));39 try expect(!isNormal(@as(f64, 0)));
40 expect(isNormal(@as(f16, 1.0)));40 try expect(isNormal(@as(f16, 1.0)));
41 expect(isNormal(@as(f32, 1.0)));41 try expect(isNormal(@as(f32, 1.0)));
42 expect(isNormal(@as(f64, 1.0)));42 try expect(isNormal(@as(f64, 1.0)));
43}43}
lib/std/math/ln.zig+22-22
...@@ -153,42 +153,42 @@ pub fn ln_64(x_: f64) f64 {...@@ -153,42 +153,42 @@ pub fn ln_64(x_: f64) f64 {
153}153}
154154
155test "math.ln" {155test "math.ln" {
156 expect(ln(@as(f32, 0.2)) == ln_32(0.2));156 try expect(ln(@as(f32, 0.2)) == ln_32(0.2));
157 expect(ln(@as(f64, 0.2)) == ln_64(0.2));157 try expect(ln(@as(f64, 0.2)) == ln_64(0.2));
158}158}
159159
160test "math.ln32" {160test "math.ln32" {
161 const epsilon = 0.000001;161 const epsilon = 0.000001;
162162
163 expect(math.approxEqAbs(f32, ln_32(0.2), -1.609438, epsilon));163 try expect(math.approxEqAbs(f32, ln_32(0.2), -1.609438, epsilon));
164 expect(math.approxEqAbs(f32, ln_32(0.8923), -0.113953, epsilon));164 try expect(math.approxEqAbs(f32, ln_32(0.8923), -0.113953, epsilon));
165 expect(math.approxEqAbs(f32, ln_32(1.5), 0.405465, epsilon));165 try expect(math.approxEqAbs(f32, ln_32(1.5), 0.405465, epsilon));
166 expect(math.approxEqAbs(f32, ln_32(37.45), 3.623007, epsilon));166 try expect(math.approxEqAbs(f32, ln_32(37.45), 3.623007, epsilon));
167 expect(math.approxEqAbs(f32, ln_32(89.123), 4.490017, epsilon));167 try expect(math.approxEqAbs(f32, ln_32(89.123), 4.490017, epsilon));
168 expect(math.approxEqAbs(f32, ln_32(123123.234375), 11.720941, epsilon));168 try expect(math.approxEqAbs(f32, ln_32(123123.234375), 11.720941, epsilon));
169}169}
170170
171test "math.ln64" {171test "math.ln64" {
172 const epsilon = 0.000001;172 const epsilon = 0.000001;
173173
174 expect(math.approxEqAbs(f64, ln_64(0.2), -1.609438, epsilon));174 try expect(math.approxEqAbs(f64, ln_64(0.2), -1.609438, epsilon));
175 expect(math.approxEqAbs(f64, ln_64(0.8923), -0.113953, epsilon));175 try expect(math.approxEqAbs(f64, ln_64(0.8923), -0.113953, epsilon));
176 expect(math.approxEqAbs(f64, ln_64(1.5), 0.405465, epsilon));176 try expect(math.approxEqAbs(f64, ln_64(1.5), 0.405465, epsilon));
177 expect(math.approxEqAbs(f64, ln_64(37.45), 3.623007, epsilon));177 try expect(math.approxEqAbs(f64, ln_64(37.45), 3.623007, epsilon));
178 expect(math.approxEqAbs(f64, ln_64(89.123), 4.490017, epsilon));178 try expect(math.approxEqAbs(f64, ln_64(89.123), 4.490017, epsilon));
179 expect(math.approxEqAbs(f64, ln_64(123123.234375), 11.720941, epsilon));179 try expect(math.approxEqAbs(f64, ln_64(123123.234375), 11.720941, epsilon));
180}180}
181181
182test "math.ln32.special" {182test "math.ln32.special" {
183 expect(math.isPositiveInf(ln_32(math.inf(f32))));183 try expect(math.isPositiveInf(ln_32(math.inf(f32))));
184 expect(math.isNegativeInf(ln_32(0.0)));184 try expect(math.isNegativeInf(ln_32(0.0)));
185 expect(math.isNan(ln_32(-1.0)));185 try expect(math.isNan(ln_32(-1.0)));
186 expect(math.isNan(ln_32(math.nan(f32))));186 try expect(math.isNan(ln_32(math.nan(f32))));
187}187}
188188
189test "math.ln64.special" {189test "math.ln64.special" {
190 expect(math.isPositiveInf(ln_64(math.inf(f64))));190 try expect(math.isPositiveInf(ln_64(math.inf(f64))));
191 expect(math.isNegativeInf(ln_64(0.0)));191 try expect(math.isNegativeInf(ln_64(0.0)));
192 expect(math.isNan(ln_64(-1.0)));192 try expect(math.isNan(ln_64(-1.0)));
193 expect(math.isNan(ln_64(math.nan(f64))));193 try expect(math.isNan(ln_64(math.nan(f64))));
194}194}
lib/std/math/log.zig+12-12
...@@ -53,25 +53,25 @@ pub fn log(comptime T: type, base: T, x: T) T {...@@ -53,25 +53,25 @@ pub fn log(comptime T: type, base: T, x: T) T {
53}53}
5454
55test "math.log integer" {55test "math.log integer" {
56 expect(log(u8, 2, 0x1) == 0);56 try expect(log(u8, 2, 0x1) == 0);
57 expect(log(u8, 2, 0x2) == 1);57 try expect(log(u8, 2, 0x2) == 1);
58 expect(log(u16, 2, 0x72) == 6);58 try expect(log(u16, 2, 0x72) == 6);
59 expect(log(u32, 2, 0xFFFFFF) == 23);59 try expect(log(u32, 2, 0xFFFFFF) == 23);
60 expect(log(u64, 2, 0x7FF0123456789ABC) == 62);60 try expect(log(u64, 2, 0x7FF0123456789ABC) == 62);
61}61}
6262
63test "math.log float" {63test "math.log float" {
64 const epsilon = 0.000001;64 const epsilon = 0.000001;
6565
66 expect(math.approxEqAbs(f32, log(f32, 6, 0.23947), -0.797723, epsilon));66 try expect(math.approxEqAbs(f32, log(f32, 6, 0.23947), -0.797723, epsilon));
67 expect(math.approxEqAbs(f32, log(f32, 89, 0.23947), -0.318432, epsilon));67 try expect(math.approxEqAbs(f32, log(f32, 89, 0.23947), -0.318432, epsilon));
68 expect(math.approxEqAbs(f64, log(f64, 123897, 12389216414), 1.981724596, epsilon));68 try expect(math.approxEqAbs(f64, log(f64, 123897, 12389216414), 1.981724596, epsilon));
69}69}
7070
71test "math.log float_special" {71test "math.log float_special" {
72 expect(log(f32, 2, 0.2301974) == math.log2(@as(f32, 0.2301974)));72 try expect(log(f32, 2, 0.2301974) == math.log2(@as(f32, 0.2301974)));
73 expect(log(f32, 10, 0.2301974) == math.log10(@as(f32, 0.2301974)));73 try expect(log(f32, 10, 0.2301974) == math.log10(@as(f32, 0.2301974)));
7474
75 expect(log(f64, 2, 213.23019799993) == math.log2(@as(f64, 213.23019799993)));75 try expect(log(f64, 2, 213.23019799993) == math.log2(@as(f64, 213.23019799993)));
76 expect(log(f64, 10, 213.23019799993) == math.log10(@as(f64, 213.23019799993)));76 try expect(log(f64, 10, 213.23019799993) == math.log10(@as(f64, 213.23019799993)));
77}77}
lib/std/math/log10.zig+22-22
...@@ -181,42 +181,42 @@ pub fn log10_64(x_: f64) f64 {...@@ -181,42 +181,42 @@ pub fn log10_64(x_: f64) f64 {
181}181}
182182
183test "math.log10" {183test "math.log10" {
184 testing.expect(log10(@as(f32, 0.2)) == log10_32(0.2));184 try testing.expect(log10(@as(f32, 0.2)) == log10_32(0.2));
185 testing.expect(log10(@as(f64, 0.2)) == log10_64(0.2));185 try testing.expect(log10(@as(f64, 0.2)) == log10_64(0.2));
186}186}
187187
188test "math.log10_32" {188test "math.log10_32" {
189 const epsilon = 0.000001;189 const epsilon = 0.000001;
190190
191 testing.expect(math.approxEqAbs(f32, log10_32(0.2), -0.698970, epsilon));191 try testing.expect(math.approxEqAbs(f32, log10_32(0.2), -0.698970, epsilon));
192 testing.expect(math.approxEqAbs(f32, log10_32(0.8923), -0.049489, epsilon));192 try testing.expect(math.approxEqAbs(f32, log10_32(0.8923), -0.049489, epsilon));
193 testing.expect(math.approxEqAbs(f32, log10_32(1.5), 0.176091, epsilon));193 try testing.expect(math.approxEqAbs(f32, log10_32(1.5), 0.176091, epsilon));
194 testing.expect(math.approxEqAbs(f32, log10_32(37.45), 1.573452, epsilon));194 try testing.expect(math.approxEqAbs(f32, log10_32(37.45), 1.573452, epsilon));
195 testing.expect(math.approxEqAbs(f32, log10_32(89.123), 1.94999, epsilon));195 try testing.expect(math.approxEqAbs(f32, log10_32(89.123), 1.94999, epsilon));
196 testing.expect(math.approxEqAbs(f32, log10_32(123123.234375), 5.09034, epsilon));196 try testing.expect(math.approxEqAbs(f32, log10_32(123123.234375), 5.09034, epsilon));
197}197}
198198
199test "math.log10_64" {199test "math.log10_64" {
200 const epsilon = 0.000001;200 const epsilon = 0.000001;
201201
202 testing.expect(math.approxEqAbs(f64, log10_64(0.2), -0.698970, epsilon));202 try testing.expect(math.approxEqAbs(f64, log10_64(0.2), -0.698970, epsilon));
203 testing.expect(math.approxEqAbs(f64, log10_64(0.8923), -0.049489, epsilon));203 try testing.expect(math.approxEqAbs(f64, log10_64(0.8923), -0.049489, epsilon));
204 testing.expect(math.approxEqAbs(f64, log10_64(1.5), 0.176091, epsilon));204 try testing.expect(math.approxEqAbs(f64, log10_64(1.5), 0.176091, epsilon));
205 testing.expect(math.approxEqAbs(f64, log10_64(37.45), 1.573452, epsilon));205 try testing.expect(math.approxEqAbs(f64, log10_64(37.45), 1.573452, epsilon));
206 testing.expect(math.approxEqAbs(f64, log10_64(89.123), 1.94999, epsilon));206 try testing.expect(math.approxEqAbs(f64, log10_64(89.123), 1.94999, epsilon));
207 testing.expect(math.approxEqAbs(f64, log10_64(123123.234375), 5.09034, epsilon));207 try testing.expect(math.approxEqAbs(f64, log10_64(123123.234375), 5.09034, epsilon));
208}208}
209209
210test "math.log10_32.special" {210test "math.log10_32.special" {
211 testing.expect(math.isPositiveInf(log10_32(math.inf(f32))));211 try testing.expect(math.isPositiveInf(log10_32(math.inf(f32))));
212 testing.expect(math.isNegativeInf(log10_32(0.0)));212 try testing.expect(math.isNegativeInf(log10_32(0.0)));
213 testing.expect(math.isNan(log10_32(-1.0)));213 try testing.expect(math.isNan(log10_32(-1.0)));
214 testing.expect(math.isNan(log10_32(math.nan(f32))));214 try testing.expect(math.isNan(log10_32(math.nan(f32))));
215}215}
216216
217test "math.log10_64.special" {217test "math.log10_64.special" {
218 testing.expect(math.isPositiveInf(log10_64(math.inf(f64))));218 try testing.expect(math.isPositiveInf(log10_64(math.inf(f64))));
219 testing.expect(math.isNegativeInf(log10_64(0.0)));219 try testing.expect(math.isNegativeInf(log10_64(0.0)));
220 testing.expect(math.isNan(log10_64(-1.0)));220 try testing.expect(math.isNan(log10_64(-1.0)));
221 testing.expect(math.isNan(log10_64(math.nan(f64))));221 try testing.expect(math.isNan(log10_64(math.nan(f64))));
222}222}
lib/std/math/log1p.zig+28-28
...@@ -188,48 +188,48 @@ fn log1p_64(x: f64) f64 {...@@ -188,48 +188,48 @@ fn log1p_64(x: f64) f64 {
188}188}
189189
190test "math.log1p" {190test "math.log1p" {
191 expect(log1p(@as(f32, 0.0)) == log1p_32(0.0));191 try expect(log1p(@as(f32, 0.0)) == log1p_32(0.0));
192 expect(log1p(@as(f64, 0.0)) == log1p_64(0.0));192 try expect(log1p(@as(f64, 0.0)) == log1p_64(0.0));
193}193}
194194
195test "math.log1p_32" {195test "math.log1p_32" {
196 const epsilon = 0.000001;196 const epsilon = 0.000001;
197197
198 expect(math.approxEqAbs(f32, log1p_32(0.0), 0.0, epsilon));198 try expect(math.approxEqAbs(f32, log1p_32(0.0), 0.0, epsilon));
199 expect(math.approxEqAbs(f32, log1p_32(0.2), 0.182322, epsilon));199 try expect(math.approxEqAbs(f32, log1p_32(0.2), 0.182322, epsilon));
200 expect(math.approxEqAbs(f32, log1p_32(0.8923), 0.637793, epsilon));200 try expect(math.approxEqAbs(f32, log1p_32(0.8923), 0.637793, epsilon));
201 expect(math.approxEqAbs(f32, log1p_32(1.5), 0.916291, epsilon));201 try expect(math.approxEqAbs(f32, log1p_32(1.5), 0.916291, epsilon));
202 expect(math.approxEqAbs(f32, log1p_32(37.45), 3.649359, epsilon));202 try expect(math.approxEqAbs(f32, log1p_32(37.45), 3.649359, epsilon));
203 expect(math.approxEqAbs(f32, log1p_32(89.123), 4.501175, epsilon));203 try expect(math.approxEqAbs(f32, log1p_32(89.123), 4.501175, epsilon));
204 expect(math.approxEqAbs(f32, log1p_32(123123.234375), 11.720949, epsilon));204 try expect(math.approxEqAbs(f32, log1p_32(123123.234375), 11.720949, epsilon));
205}205}
206206
207test "math.log1p_64" {207test "math.log1p_64" {
208 const epsilon = 0.000001;208 const epsilon = 0.000001;
209209
210 expect(math.approxEqAbs(f64, log1p_64(0.0), 0.0, epsilon));210 try expect(math.approxEqAbs(f64, log1p_64(0.0), 0.0, epsilon));
211 expect(math.approxEqAbs(f64, log1p_64(0.2), 0.182322, epsilon));211 try expect(math.approxEqAbs(f64, log1p_64(0.2), 0.182322, epsilon));
212 expect(math.approxEqAbs(f64, log1p_64(0.8923), 0.637793, epsilon));212 try expect(math.approxEqAbs(f64, log1p_64(0.8923), 0.637793, epsilon));
213 expect(math.approxEqAbs(f64, log1p_64(1.5), 0.916291, epsilon));213 try expect(math.approxEqAbs(f64, log1p_64(1.5), 0.916291, epsilon));
214 expect(math.approxEqAbs(f64, log1p_64(37.45), 3.649359, epsilon));214 try expect(math.approxEqAbs(f64, log1p_64(37.45), 3.649359, epsilon));
215 expect(math.approxEqAbs(f64, log1p_64(89.123), 4.501175, epsilon));215 try expect(math.approxEqAbs(f64, log1p_64(89.123), 4.501175, epsilon));
216 expect(math.approxEqAbs(f64, log1p_64(123123.234375), 11.720949, epsilon));216 try expect(math.approxEqAbs(f64, log1p_64(123123.234375), 11.720949, epsilon));
217}217}
218218
219test "math.log1p_32.special" {219test "math.log1p_32.special" {
220 expect(math.isPositiveInf(log1p_32(math.inf(f32))));220 try expect(math.isPositiveInf(log1p_32(math.inf(f32))));
221 expect(log1p_32(0.0) == 0.0);221 try expect(log1p_32(0.0) == 0.0);
222 expect(log1p_32(-0.0) == -0.0);222 try expect(log1p_32(-0.0) == -0.0);
223 expect(math.isNegativeInf(log1p_32(-1.0)));223 try expect(math.isNegativeInf(log1p_32(-1.0)));
224 expect(math.isNan(log1p_32(-2.0)));224 try expect(math.isNan(log1p_32(-2.0)));
225 expect(math.isNan(log1p_32(math.nan(f32))));225 try expect(math.isNan(log1p_32(math.nan(f32))));
226}226}
227227
228test "math.log1p_64.special" {228test "math.log1p_64.special" {
229 expect(math.isPositiveInf(log1p_64(math.inf(f64))));229 try expect(math.isPositiveInf(log1p_64(math.inf(f64))));
230 expect(log1p_64(0.0) == 0.0);230 try expect(log1p_64(0.0) == 0.0);
231 expect(log1p_64(-0.0) == -0.0);231 try expect(log1p_64(-0.0) == -0.0);
232 expect(math.isNegativeInf(log1p_64(-1.0)));232 try expect(math.isNegativeInf(log1p_64(-1.0)));
233 expect(math.isNan(log1p_64(-2.0)));233 try expect(math.isNan(log1p_64(-2.0)));
234 expect(math.isNan(log1p_64(math.nan(f64))));234 try expect(math.isNan(log1p_64(math.nan(f64))));
235}235}
lib/std/math/log2.zig+20-20
...@@ -179,40 +179,40 @@ pub fn log2_64(x_: f64) f64 {...@@ -179,40 +179,40 @@ pub fn log2_64(x_: f64) f64 {
179}179}
180180
181test "math.log2" {181test "math.log2" {
182 expect(log2(@as(f32, 0.2)) == log2_32(0.2));182 try expect(log2(@as(f32, 0.2)) == log2_32(0.2));
183 expect(log2(@as(f64, 0.2)) == log2_64(0.2));183 try expect(log2(@as(f64, 0.2)) == log2_64(0.2));
184}184}
185185
186test "math.log2_32" {186test "math.log2_32" {
187 const epsilon = 0.000001;187 const epsilon = 0.000001;
188188
189 expect(math.approxEqAbs(f32, log2_32(0.2), -2.321928, epsilon));189 try expect(math.approxEqAbs(f32, log2_32(0.2), -2.321928, epsilon));
190 expect(math.approxEqAbs(f32, log2_32(0.8923), -0.164399, epsilon));190 try expect(math.approxEqAbs(f32, log2_32(0.8923), -0.164399, epsilon));
191 expect(math.approxEqAbs(f32, log2_32(1.5), 0.584962, epsilon));191 try expect(math.approxEqAbs(f32, log2_32(1.5), 0.584962, epsilon));
192 expect(math.approxEqAbs(f32, log2_32(37.45), 5.226894, epsilon));192 try expect(math.approxEqAbs(f32, log2_32(37.45), 5.226894, epsilon));
193 expect(math.approxEqAbs(f32, log2_32(123123.234375), 16.909744, epsilon));193 try expect(math.approxEqAbs(f32, log2_32(123123.234375), 16.909744, epsilon));
194}194}
195195
196test "math.log2_64" {196test "math.log2_64" {
197 const epsilon = 0.000001;197 const epsilon = 0.000001;
198198
199 expect(math.approxEqAbs(f64, log2_64(0.2), -2.321928, epsilon));199 try expect(math.approxEqAbs(f64, log2_64(0.2), -2.321928, epsilon));
200 expect(math.approxEqAbs(f64, log2_64(0.8923), -0.164399, epsilon));200 try expect(math.approxEqAbs(f64, log2_64(0.8923), -0.164399, epsilon));
201 expect(math.approxEqAbs(f64, log2_64(1.5), 0.584962, epsilon));201 try expect(math.approxEqAbs(f64, log2_64(1.5), 0.584962, epsilon));
202 expect(math.approxEqAbs(f64, log2_64(37.45), 5.226894, epsilon));202 try expect(math.approxEqAbs(f64, log2_64(37.45), 5.226894, epsilon));
203 expect(math.approxEqAbs(f64, log2_64(123123.234375), 16.909744, epsilon));203 try expect(math.approxEqAbs(f64, log2_64(123123.234375), 16.909744, epsilon));
204}204}
205205
206test "math.log2_32.special" {206test "math.log2_32.special" {
207 expect(math.isPositiveInf(log2_32(math.inf(f32))));207 try expect(math.isPositiveInf(log2_32(math.inf(f32))));
208 expect(math.isNegativeInf(log2_32(0.0)));208 try expect(math.isNegativeInf(log2_32(0.0)));
209 expect(math.isNan(log2_32(-1.0)));209 try expect(math.isNan(log2_32(-1.0)));
210 expect(math.isNan(log2_32(math.nan(f32))));210 try expect(math.isNan(log2_32(math.nan(f32))));
211}211}
212212
213test "math.log2_64.special" {213test "math.log2_64.special" {
214 expect(math.isPositiveInf(log2_64(math.inf(f64))));214 try expect(math.isPositiveInf(log2_64(math.inf(f64))));
215 expect(math.isNegativeInf(log2_64(0.0)));215 try expect(math.isNegativeInf(log2_64(0.0)));
216 expect(math.isNan(log2_64(-1.0)));216 try expect(math.isNan(log2_64(-1.0)));
217 expect(math.isNan(log2_64(math.nan(f64))));217 try expect(math.isNan(log2_64(math.nan(f64))));
218}218}
lib/std/math/modf.zig+28-28
...@@ -131,11 +131,11 @@ test "math.modf" {...@@ -131,11 +131,11 @@ test "math.modf" {
131 const a = modf(@as(f32, 1.0));131 const a = modf(@as(f32, 1.0));
132 const b = modf32(1.0);132 const b = modf32(1.0);
133 // NOTE: No struct comparison on generic return type function? non-named, makes sense, but still.133 // NOTE: No struct comparison on generic return type function? non-named, makes sense, but still.
134 expect(a.ipart == b.ipart and a.fpart == b.fpart);134 try expect(a.ipart == b.ipart and a.fpart == b.fpart);
135135
136 const c = modf(@as(f64, 1.0));136 const c = modf(@as(f64, 1.0));
137 const d = modf64(1.0);137 const d = modf64(1.0);
138 expect(a.ipart == b.ipart and a.fpart == b.fpart);138 try expect(a.ipart == b.ipart and a.fpart == b.fpart);
139}139}
140140
141test "math.modf32" {141test "math.modf32" {
...@@ -143,24 +143,24 @@ test "math.modf32" {...@@ -143,24 +143,24 @@ test "math.modf32" {
143 var r: modf32_result = undefined;143 var r: modf32_result = undefined;
144144
145 r = modf32(1.0);145 r = modf32(1.0);
146 expect(math.approxEqAbs(f32, r.ipart, 1.0, epsilon));146 try expect(math.approxEqAbs(f32, r.ipart, 1.0, epsilon));
147 expect(math.approxEqAbs(f32, r.fpart, 0.0, epsilon));147 try expect(math.approxEqAbs(f32, r.fpart, 0.0, epsilon));
148148
149 r = modf32(2.545);149 r = modf32(2.545);
150 expect(math.approxEqAbs(f32, r.ipart, 2.0, epsilon));150 try expect(math.approxEqAbs(f32, r.ipart, 2.0, epsilon));
151 expect(math.approxEqAbs(f32, r.fpart, 0.545, epsilon));151 try expect(math.approxEqAbs(f32, r.fpart, 0.545, epsilon));
152152
153 r = modf32(3.978123);153 r = modf32(3.978123);
154 expect(math.approxEqAbs(f32, r.ipart, 3.0, epsilon));154 try expect(math.approxEqAbs(f32, r.ipart, 3.0, epsilon));
155 expect(math.approxEqAbs(f32, r.fpart, 0.978123, epsilon));155 try expect(math.approxEqAbs(f32, r.fpart, 0.978123, epsilon));
156156
157 r = modf32(43874.3);157 r = modf32(43874.3);
158 expect(math.approxEqAbs(f32, r.ipart, 43874, epsilon));158 try expect(math.approxEqAbs(f32, r.ipart, 43874, epsilon));
159 expect(math.approxEqAbs(f32, r.fpart, 0.300781, epsilon));159 try expect(math.approxEqAbs(f32, r.fpart, 0.300781, epsilon));
160160
161 r = modf32(1234.340780);161 r = modf32(1234.340780);
162 expect(math.approxEqAbs(f32, r.ipart, 1234, epsilon));162 try expect(math.approxEqAbs(f32, r.ipart, 1234, epsilon));
163 expect(math.approxEqAbs(f32, r.fpart, 0.340820, epsilon));163 try expect(math.approxEqAbs(f32, r.fpart, 0.340820, epsilon));
164}164}
165165
166test "math.modf64" {166test "math.modf64" {
...@@ -168,48 +168,48 @@ test "math.modf64" {...@@ -168,48 +168,48 @@ test "math.modf64" {
168 var r: modf64_result = undefined;168 var r: modf64_result = undefined;
169169
170 r = modf64(1.0);170 r = modf64(1.0);
171 expect(math.approxEqAbs(f64, r.ipart, 1.0, epsilon));171 try expect(math.approxEqAbs(f64, r.ipart, 1.0, epsilon));
172 expect(math.approxEqAbs(f64, r.fpart, 0.0, epsilon));172 try expect(math.approxEqAbs(f64, r.fpart, 0.0, epsilon));
173173
174 r = modf64(2.545);174 r = modf64(2.545);
175 expect(math.approxEqAbs(f64, r.ipart, 2.0, epsilon));175 try expect(math.approxEqAbs(f64, r.ipart, 2.0, epsilon));
176 expect(math.approxEqAbs(f64, r.fpart, 0.545, epsilon));176 try expect(math.approxEqAbs(f64, r.fpart, 0.545, epsilon));
177177
178 r = modf64(3.978123);178 r = modf64(3.978123);
179 expect(math.approxEqAbs(f64, r.ipart, 3.0, epsilon));179 try expect(math.approxEqAbs(f64, r.ipart, 3.0, epsilon));
180 expect(math.approxEqAbs(f64, r.fpart, 0.978123, epsilon));180 try expect(math.approxEqAbs(f64, r.fpart, 0.978123, epsilon));
181181
182 r = modf64(43874.3);182 r = modf64(43874.3);
183 expect(math.approxEqAbs(f64, r.ipart, 43874, epsilon));183 try expect(math.approxEqAbs(f64, r.ipart, 43874, epsilon));
184 expect(math.approxEqAbs(f64, r.fpart, 0.3, epsilon));184 try expect(math.approxEqAbs(f64, r.fpart, 0.3, epsilon));
185185
186 r = modf64(1234.340780);186 r = modf64(1234.340780);
187 expect(math.approxEqAbs(f64, r.ipart, 1234, epsilon));187 try expect(math.approxEqAbs(f64, r.ipart, 1234, epsilon));
188 expect(math.approxEqAbs(f64, r.fpart, 0.340780, epsilon));188 try expect(math.approxEqAbs(f64, r.fpart, 0.340780, epsilon));
189}189}
190190
191test "math.modf32.special" {191test "math.modf32.special" {
192 var r: modf32_result = undefined;192 var r: modf32_result = undefined;
193193
194 r = modf32(math.inf(f32));194 r = modf32(math.inf(f32));
195 expect(math.isPositiveInf(r.ipart) and math.isNan(r.fpart));195 try expect(math.isPositiveInf(r.ipart) and math.isNan(r.fpart));
196196
197 r = modf32(-math.inf(f32));197 r = modf32(-math.inf(f32));
198 expect(math.isNegativeInf(r.ipart) and math.isNan(r.fpart));198 try expect(math.isNegativeInf(r.ipart) and math.isNan(r.fpart));
199199
200 r = modf32(math.nan(f32));200 r = modf32(math.nan(f32));
201 expect(math.isNan(r.ipart) and math.isNan(r.fpart));201 try expect(math.isNan(r.ipart) and math.isNan(r.fpart));
202}202}
203203
204test "math.modf64.special" {204test "math.modf64.special" {
205 var r: modf64_result = undefined;205 var r: modf64_result = undefined;
206206
207 r = modf64(math.inf(f64));207 r = modf64(math.inf(f64));
208 expect(math.isPositiveInf(r.ipart) and math.isNan(r.fpart));208 try expect(math.isPositiveInf(r.ipart) and math.isNan(r.fpart));
209209
210 r = modf64(-math.inf(f64));210 r = modf64(-math.inf(f64));
211 expect(math.isNegativeInf(r.ipart) and math.isNan(r.fpart));211 try expect(math.isNegativeInf(r.ipart) and math.isNan(r.fpart));
212212
213 r = modf64(math.nan(f64));213 r = modf64(math.nan(f64));
214 expect(math.isNan(r.ipart) and math.isNan(r.fpart));214 try expect(math.isNan(r.ipart) and math.isNan(r.fpart));
215}215}
lib/std/math/pow.zig+52-52
...@@ -191,67 +191,67 @@ fn isOddInteger(x: f64) bool {...@@ -191,67 +191,67 @@ fn isOddInteger(x: f64) bool {
191test "math.pow" {191test "math.pow" {
192 const epsilon = 0.000001;192 const epsilon = 0.000001;
193193
194 expect(math.approxEqAbs(f32, pow(f32, 0.0, 3.3), 0.0, epsilon));194 try expect(math.approxEqAbs(f32, pow(f32, 0.0, 3.3), 0.0, epsilon));
195 expect(math.approxEqAbs(f32, pow(f32, 0.8923, 3.3), 0.686572, epsilon));195 try expect(math.approxEqAbs(f32, pow(f32, 0.8923, 3.3), 0.686572, epsilon));
196 expect(math.approxEqAbs(f32, pow(f32, 0.2, 3.3), 0.004936, epsilon));196 try expect(math.approxEqAbs(f32, pow(f32, 0.2, 3.3), 0.004936, epsilon));
197 expect(math.approxEqAbs(f32, pow(f32, 1.5, 3.3), 3.811546, epsilon));197 try expect(math.approxEqAbs(f32, pow(f32, 1.5, 3.3), 3.811546, epsilon));
198 expect(math.approxEqAbs(f32, pow(f32, 37.45, 3.3), 155736.703125, epsilon));198 try expect(math.approxEqAbs(f32, pow(f32, 37.45, 3.3), 155736.703125, epsilon));
199 expect(math.approxEqAbs(f32, pow(f32, 89.123, 3.3), 2722489.5, epsilon));199 try expect(math.approxEqAbs(f32, pow(f32, 89.123, 3.3), 2722489.5, epsilon));
200200
201 expect(math.approxEqAbs(f64, pow(f64, 0.0, 3.3), 0.0, epsilon));201 try expect(math.approxEqAbs(f64, pow(f64, 0.0, 3.3), 0.0, epsilon));
202 expect(math.approxEqAbs(f64, pow(f64, 0.8923, 3.3), 0.686572, epsilon));202 try expect(math.approxEqAbs(f64, pow(f64, 0.8923, 3.3), 0.686572, epsilon));
203 expect(math.approxEqAbs(f64, pow(f64, 0.2, 3.3), 0.004936, epsilon));203 try expect(math.approxEqAbs(f64, pow(f64, 0.2, 3.3), 0.004936, epsilon));
204 expect(math.approxEqAbs(f64, pow(f64, 1.5, 3.3), 3.811546, epsilon));204 try expect(math.approxEqAbs(f64, pow(f64, 1.5, 3.3), 3.811546, epsilon));
205 expect(math.approxEqAbs(f64, pow(f64, 37.45, 3.3), 155736.7160616, epsilon));205 try expect(math.approxEqAbs(f64, pow(f64, 37.45, 3.3), 155736.7160616, epsilon));
206 expect(math.approxEqAbs(f64, pow(f64, 89.123, 3.3), 2722490.231436, epsilon));206 try expect(math.approxEqAbs(f64, pow(f64, 89.123, 3.3), 2722490.231436, epsilon));
207}207}
208208
209test "math.pow.special" {209test "math.pow.special" {
210 const epsilon = 0.000001;210 const epsilon = 0.000001;
211211
212 expect(pow(f32, 4, 0.0) == 1.0);212 try expect(pow(f32, 4, 0.0) == 1.0);
213 expect(pow(f32, 7, -0.0) == 1.0);213 try expect(pow(f32, 7, -0.0) == 1.0);
214 expect(pow(f32, 45, 1.0) == 45);214 try expect(pow(f32, 45, 1.0) == 45);
215 expect(pow(f32, -45, 1.0) == -45);215 try expect(pow(f32, -45, 1.0) == -45);
216 expect(math.isNan(pow(f32, math.nan(f32), 5.0)));216 try expect(math.isNan(pow(f32, math.nan(f32), 5.0)));
217 expect(math.isPositiveInf(pow(f32, -math.inf(f32), 0.5)));217 try expect(math.isPositiveInf(pow(f32, -math.inf(f32), 0.5)));
218 expect(math.isPositiveInf(pow(f32, -0, -0.5)));218 try expect(math.isPositiveInf(pow(f32, -0, -0.5)));
219 expect(pow(f32, -0, 0.5) == 0);219 try expect(pow(f32, -0, 0.5) == 0);
220 expect(math.isNan(pow(f32, 5.0, math.nan(f32))));220 try expect(math.isNan(pow(f32, 5.0, math.nan(f32))));
221 expect(math.isPositiveInf(pow(f32, 0.0, -1.0)));221 try expect(math.isPositiveInf(pow(f32, 0.0, -1.0)));
222 //expect(math.isNegativeInf(pow(f32, -0.0, -3.0))); TODO is this required?222 //expect(math.isNegativeInf(pow(f32, -0.0, -3.0))); TODO is this required?
223 expect(math.isPositiveInf(pow(f32, 0.0, -math.inf(f32))));223 try expect(math.isPositiveInf(pow(f32, 0.0, -math.inf(f32))));
224 expect(math.isPositiveInf(pow(f32, -0.0, -math.inf(f32))));224 try expect(math.isPositiveInf(pow(f32, -0.0, -math.inf(f32))));
225 expect(pow(f32, 0.0, math.inf(f32)) == 0.0);225 try expect(pow(f32, 0.0, math.inf(f32)) == 0.0);
226 expect(pow(f32, -0.0, math.inf(f32)) == 0.0);226 try expect(pow(f32, -0.0, math.inf(f32)) == 0.0);
227 expect(math.isPositiveInf(pow(f32, 0.0, -2.0)));227 try expect(math.isPositiveInf(pow(f32, 0.0, -2.0)));
228 expect(math.isPositiveInf(pow(f32, -0.0, -2.0)));228 try expect(math.isPositiveInf(pow(f32, -0.0, -2.0)));
229 expect(pow(f32, 0.0, 1.0) == 0.0);229 try expect(pow(f32, 0.0, 1.0) == 0.0);
230 expect(pow(f32, -0.0, 1.0) == -0.0);230 try expect(pow(f32, -0.0, 1.0) == -0.0);
231 expect(pow(f32, 0.0, 2.0) == 0.0);231 try expect(pow(f32, 0.0, 2.0) == 0.0);
232 expect(pow(f32, -0.0, 2.0) == 0.0);232 try expect(pow(f32, -0.0, 2.0) == 0.0);
233 expect(math.approxEqAbs(f32, pow(f32, -1.0, math.inf(f32)), 1.0, epsilon));233 try expect(math.approxEqAbs(f32, pow(f32, -1.0, math.inf(f32)), 1.0, epsilon));
234 expect(math.approxEqAbs(f32, pow(f32, -1.0, -math.inf(f32)), 1.0, epsilon));234 try expect(math.approxEqAbs(f32, pow(f32, -1.0, -math.inf(f32)), 1.0, epsilon));
235 expect(math.isPositiveInf(pow(f32, 1.2, math.inf(f32))));235 try expect(math.isPositiveInf(pow(f32, 1.2, math.inf(f32))));
236 expect(math.isPositiveInf(pow(f32, -1.2, math.inf(f32))));236 try expect(math.isPositiveInf(pow(f32, -1.2, math.inf(f32))));
237 expect(pow(f32, 1.2, -math.inf(f32)) == 0.0);237 try expect(pow(f32, 1.2, -math.inf(f32)) == 0.0);
238 expect(pow(f32, -1.2, -math.inf(f32)) == 0.0);238 try expect(pow(f32, -1.2, -math.inf(f32)) == 0.0);
239 expect(pow(f32, 0.2, math.inf(f32)) == 0.0);239 try expect(pow(f32, 0.2, math.inf(f32)) == 0.0);
240 expect(pow(f32, -0.2, math.inf(f32)) == 0.0);240 try expect(pow(f32, -0.2, math.inf(f32)) == 0.0);
241 expect(math.isPositiveInf(pow(f32, 0.2, -math.inf(f32))));241 try expect(math.isPositiveInf(pow(f32, 0.2, -math.inf(f32))));
242 expect(math.isPositiveInf(pow(f32, -0.2, -math.inf(f32))));242 try expect(math.isPositiveInf(pow(f32, -0.2, -math.inf(f32))));
243 expect(math.isPositiveInf(pow(f32, math.inf(f32), 1.0)));243 try expect(math.isPositiveInf(pow(f32, math.inf(f32), 1.0)));
244 expect(pow(f32, math.inf(f32), -1.0) == 0.0);244 try expect(pow(f32, math.inf(f32), -1.0) == 0.0);
245 //expect(pow(f32, -math.inf(f32), 5.0) == pow(f32, -0.0, -5.0)); TODO support negative 0?245 //expect(pow(f32, -math.inf(f32), 5.0) == pow(f32, -0.0, -5.0)); TODO support negative 0?
246 expect(pow(f32, -math.inf(f32), -5.2) == pow(f32, -0.0, 5.2));246 try expect(pow(f32, -math.inf(f32), -5.2) == pow(f32, -0.0, 5.2));
247 expect(math.isNan(pow(f32, -1.0, 1.2)));247 try expect(math.isNan(pow(f32, -1.0, 1.2)));
248 expect(math.isNan(pow(f32, -12.4, 78.5)));248 try expect(math.isNan(pow(f32, -12.4, 78.5)));
249}249}
250250
251test "math.pow.overflow" {251test "math.pow.overflow" {
252 expect(math.isPositiveInf(pow(f64, 2, 1 << 32)));252 try expect(math.isPositiveInf(pow(f64, 2, 1 << 32)));
253 expect(pow(f64, 2, -(1 << 32)) == 0);253 try expect(pow(f64, 2, -(1 << 32)) == 0);
254 expect(math.isNegativeInf(pow(f64, -2, (1 << 32) + 1)));254 try expect(math.isNegativeInf(pow(f64, -2, (1 << 32) + 1)));
255 expect(pow(f64, 0.5, 1 << 45) == 0);255 try expect(pow(f64, 0.5, 1 << 45) == 0);
256 expect(math.isPositiveInf(pow(f64, 0.5, -(1 << 45))));256 try expect(math.isPositiveInf(pow(f64, 0.5, -(1 << 45))));
257}257}
lib/std/math/powi.zig+75-75
...@@ -112,82 +112,82 @@ pub fn powi(comptime T: type, x: T, y: T) (error{...@@ -112,82 +112,82 @@ pub fn powi(comptime T: type, x: T, y: T) (error{
112}112}
113113
114test "math.powi" {114test "math.powi" {
115 testing.expectError(error.Underflow, powi(i8, -66, 6));115 try testing.expectError(error.Underflow, powi(i8, -66, 6));
116 testing.expectError(error.Underflow, powi(i16, -13, 13));116 try testing.expectError(error.Underflow, powi(i16, -13, 13));
117 testing.expectError(error.Underflow, powi(i32, -32, 21));117 try testing.expectError(error.Underflow, powi(i32, -32, 21));
118 testing.expectError(error.Underflow, powi(i64, -24, 61));118 try testing.expectError(error.Underflow, powi(i64, -24, 61));
119 testing.expectError(error.Underflow, powi(i17, -15, 15));119 try testing.expectError(error.Underflow, powi(i17, -15, 15));
120 testing.expectError(error.Underflow, powi(i42, -6, 40));120 try testing.expectError(error.Underflow, powi(i42, -6, 40));
121121
122 testing.expect((try powi(i8, -5, 3)) == -125);122 try testing.expect((try powi(i8, -5, 3)) == -125);
123 testing.expect((try powi(i16, -16, 3)) == -4096);123 try testing.expect((try powi(i16, -16, 3)) == -4096);
124 testing.expect((try powi(i32, -91, 3)) == -753571);124 try testing.expect((try powi(i32, -91, 3)) == -753571);
125 testing.expect((try powi(i64, -36, 6)) == 2176782336);125 try testing.expect((try powi(i64, -36, 6)) == 2176782336);
126 testing.expect((try powi(i17, -2, 15)) == -32768);126 try testing.expect((try powi(i17, -2, 15)) == -32768);
127 testing.expect((try powi(i42, -5, 7)) == -78125);127 try testing.expect((try powi(i42, -5, 7)) == -78125);
128128
129 testing.expect((try powi(u8, 6, 2)) == 36);129 try testing.expect((try powi(u8, 6, 2)) == 36);
130 testing.expect((try powi(u16, 5, 4)) == 625);130 try testing.expect((try powi(u16, 5, 4)) == 625);
131 testing.expect((try powi(u32, 12, 6)) == 2985984);131 try testing.expect((try powi(u32, 12, 6)) == 2985984);
132 testing.expect((try powi(u64, 34, 2)) == 1156);132 try testing.expect((try powi(u64, 34, 2)) == 1156);
133 testing.expect((try powi(u17, 16, 3)) == 4096);133 try testing.expect((try powi(u17, 16, 3)) == 4096);
134 testing.expect((try powi(u42, 34, 6)) == 1544804416);134 try testing.expect((try powi(u42, 34, 6)) == 1544804416);
135135
136 testing.expectError(error.Overflow, powi(i8, 120, 7));136 try testing.expectError(error.Overflow, powi(i8, 120, 7));
137 testing.expectError(error.Overflow, powi(i16, 73, 15));137 try testing.expectError(error.Overflow, powi(i16, 73, 15));
138 testing.expectError(error.Overflow, powi(i32, 23, 31));138 try testing.expectError(error.Overflow, powi(i32, 23, 31));
139 testing.expectError(error.Overflow, powi(i64, 68, 61));139 try testing.expectError(error.Overflow, powi(i64, 68, 61));
140 testing.expectError(error.Overflow, powi(i17, 15, 15));140 try testing.expectError(error.Overflow, powi(i17, 15, 15));
141 testing.expectError(error.Overflow, powi(i42, 121312, 41));141 try testing.expectError(error.Overflow, powi(i42, 121312, 41));
142142
143 testing.expectError(error.Overflow, powi(u8, 123, 7));143 try testing.expectError(error.Overflow, powi(u8, 123, 7));
144 testing.expectError(error.Overflow, powi(u16, 2313, 15));144 try testing.expectError(error.Overflow, powi(u16, 2313, 15));
145 testing.expectError(error.Overflow, powi(u32, 8968, 31));145 try testing.expectError(error.Overflow, powi(u32, 8968, 31));
146 testing.expectError(error.Overflow, powi(u64, 2342, 63));146 try testing.expectError(error.Overflow, powi(u64, 2342, 63));
147 testing.expectError(error.Overflow, powi(u17, 2723, 16));147 try testing.expectError(error.Overflow, powi(u17, 2723, 16));
148 testing.expectError(error.Overflow, powi(u42, 8234, 41));148 try testing.expectError(error.Overflow, powi(u42, 8234, 41));
149}149}
150150
151test "math.powi.special" {151test "math.powi.special" {
152 testing.expectError(error.Underflow, powi(i8, -2, 8));152 try testing.expectError(error.Underflow, powi(i8, -2, 8));
153 testing.expectError(error.Underflow, powi(i16, -2, 16));153 try testing.expectError(error.Underflow, powi(i16, -2, 16));
154 testing.expectError(error.Underflow, powi(i32, -2, 32));154 try testing.expectError(error.Underflow, powi(i32, -2, 32));
155 testing.expectError(error.Underflow, powi(i64, -2, 64));155 try testing.expectError(error.Underflow, powi(i64, -2, 64));
156 testing.expectError(error.Underflow, powi(i17, -2, 17));156 try testing.expectError(error.Underflow, powi(i17, -2, 17));
157 testing.expectError(error.Underflow, powi(i42, -2, 42));157 try testing.expectError(error.Underflow, powi(i42, -2, 42));
158158
159 testing.expect((try powi(i8, -1, 3)) == -1);159 try testing.expect((try powi(i8, -1, 3)) == -1);
160 testing.expect((try powi(i16, -1, 2)) == 1);160 try testing.expect((try powi(i16, -1, 2)) == 1);
161 testing.expect((try powi(i32, -1, 16)) == 1);161 try testing.expect((try powi(i32, -1, 16)) == 1);
162 testing.expect((try powi(i64, -1, 6)) == 1);162 try testing.expect((try powi(i64, -1, 6)) == 1);
163 testing.expect((try powi(i17, -1, 15)) == -1);163 try testing.expect((try powi(i17, -1, 15)) == -1);
164 testing.expect((try powi(i42, -1, 7)) == -1);164 try testing.expect((try powi(i42, -1, 7)) == -1);
165165
166 testing.expect((try powi(u8, 1, 2)) == 1);166 try testing.expect((try powi(u8, 1, 2)) == 1);
167 testing.expect((try powi(u16, 1, 4)) == 1);167 try testing.expect((try powi(u16, 1, 4)) == 1);
168 testing.expect((try powi(u32, 1, 6)) == 1);168 try testing.expect((try powi(u32, 1, 6)) == 1);
169 testing.expect((try powi(u64, 1, 2)) == 1);169 try testing.expect((try powi(u64, 1, 2)) == 1);
170 testing.expect((try powi(u17, 1, 3)) == 1);170 try testing.expect((try powi(u17, 1, 3)) == 1);
171 testing.expect((try powi(u42, 1, 6)) == 1);171 try testing.expect((try powi(u42, 1, 6)) == 1);
172172
173 testing.expectError(error.Overflow, powi(i8, 2, 7));173 try testing.expectError(error.Overflow, powi(i8, 2, 7));
174 testing.expectError(error.Overflow, powi(i16, 2, 15));174 try testing.expectError(error.Overflow, powi(i16, 2, 15));
175 testing.expectError(error.Overflow, powi(i32, 2, 31));175 try testing.expectError(error.Overflow, powi(i32, 2, 31));
176 testing.expectError(error.Overflow, powi(i64, 2, 63));176 try testing.expectError(error.Overflow, powi(i64, 2, 63));
177 testing.expectError(error.Overflow, powi(i17, 2, 16));177 try testing.expectError(error.Overflow, powi(i17, 2, 16));
178 testing.expectError(error.Overflow, powi(i42, 2, 41));178 try testing.expectError(error.Overflow, powi(i42, 2, 41));
179179
180 testing.expectError(error.Overflow, powi(u8, 2, 8));180 try testing.expectError(error.Overflow, powi(u8, 2, 8));
181 testing.expectError(error.Overflow, powi(u16, 2, 16));181 try testing.expectError(error.Overflow, powi(u16, 2, 16));
182 testing.expectError(error.Overflow, powi(u32, 2, 32));182 try testing.expectError(error.Overflow, powi(u32, 2, 32));
183 testing.expectError(error.Overflow, powi(u64, 2, 64));183 try testing.expectError(error.Overflow, powi(u64, 2, 64));
184 testing.expectError(error.Overflow, powi(u17, 2, 17));184 try testing.expectError(error.Overflow, powi(u17, 2, 17));
185 testing.expectError(error.Overflow, powi(u42, 2, 42));185 try testing.expectError(error.Overflow, powi(u42, 2, 42));
186186
187 testing.expect((try powi(u8, 6, 0)) == 1);187 try testing.expect((try powi(u8, 6, 0)) == 1);
188 testing.expect((try powi(u16, 5, 0)) == 1);188 try testing.expect((try powi(u16, 5, 0)) == 1);
189 testing.expect((try powi(u32, 12, 0)) == 1);189 try testing.expect((try powi(u32, 12, 0)) == 1);
190 testing.expect((try powi(u64, 34, 0)) == 1);190 try testing.expect((try powi(u64, 34, 0)) == 1);
191 testing.expect((try powi(u17, 16, 0)) == 1);191 try testing.expect((try powi(u17, 16, 0)) == 1);
192 testing.expect((try powi(u42, 34, 0)) == 1);192 try testing.expect((try powi(u42, 34, 0)) == 1);
193}193}
lib/std/math/round.zig+30-30
...@@ -130,52 +130,52 @@ fn round128(x_: f128) f128 {...@@ -130,52 +130,52 @@ fn round128(x_: f128) f128 {
130}130}
131131
132test "math.round" {132test "math.round" {
133 expect(round(@as(f32, 1.3)) == round32(1.3));133 try expect(round(@as(f32, 1.3)) == round32(1.3));
134 expect(round(@as(f64, 1.3)) == round64(1.3));134 try expect(round(@as(f64, 1.3)) == round64(1.3));
135 expect(round(@as(f128, 1.3)) == round128(1.3));135 try expect(round(@as(f128, 1.3)) == round128(1.3));
136}136}
137137
138test "math.round32" {138test "math.round32" {
139 expect(round32(1.3) == 1.0);139 try expect(round32(1.3) == 1.0);
140 expect(round32(-1.3) == -1.0);140 try expect(round32(-1.3) == -1.0);
141 expect(round32(0.2) == 0.0);141 try expect(round32(0.2) == 0.0);
142 expect(round32(1.8) == 2.0);142 try expect(round32(1.8) == 2.0);
143}143}
144144
145test "math.round64" {145test "math.round64" {
146 expect(round64(1.3) == 1.0);146 try expect(round64(1.3) == 1.0);
147 expect(round64(-1.3) == -1.0);147 try expect(round64(-1.3) == -1.0);
148 expect(round64(0.2) == 0.0);148 try expect(round64(0.2) == 0.0);
149 expect(round64(1.8) == 2.0);149 try expect(round64(1.8) == 2.0);
150}150}
151151
152test "math.round128" {152test "math.round128" {
153 expect(round128(1.3) == 1.0);153 try expect(round128(1.3) == 1.0);
154 expect(round128(-1.3) == -1.0);154 try expect(round128(-1.3) == -1.0);
155 expect(round128(0.2) == 0.0);155 try expect(round128(0.2) == 0.0);
156 expect(round128(1.8) == 2.0);156 try expect(round128(1.8) == 2.0);
157}157}
158158
159test "math.round32.special" {159test "math.round32.special" {
160 expect(round32(0.0) == 0.0);160 try expect(round32(0.0) == 0.0);
161 expect(round32(-0.0) == -0.0);161 try expect(round32(-0.0) == -0.0);
162 expect(math.isPositiveInf(round32(math.inf(f32))));162 try expect(math.isPositiveInf(round32(math.inf(f32))));
163 expect(math.isNegativeInf(round32(-math.inf(f32))));163 try expect(math.isNegativeInf(round32(-math.inf(f32))));
164 expect(math.isNan(round32(math.nan(f32))));164 try expect(math.isNan(round32(math.nan(f32))));
165}165}
166166
167test "math.round64.special" {167test "math.round64.special" {
168 expect(round64(0.0) == 0.0);168 try expect(round64(0.0) == 0.0);
169 expect(round64(-0.0) == -0.0);169 try expect(round64(-0.0) == -0.0);
170 expect(math.isPositiveInf(round64(math.inf(f64))));170 try expect(math.isPositiveInf(round64(math.inf(f64))));
171 expect(math.isNegativeInf(round64(-math.inf(f64))));171 try expect(math.isNegativeInf(round64(-math.inf(f64))));
172 expect(math.isNan(round64(math.nan(f64))));172 try expect(math.isNan(round64(math.nan(f64))));
173}173}
174174
175test "math.round128.special" {175test "math.round128.special" {
176 expect(round128(0.0) == 0.0);176 try expect(round128(0.0) == 0.0);
177 expect(round128(-0.0) == -0.0);177 try expect(round128(-0.0) == -0.0);
178 expect(math.isPositiveInf(round128(math.inf(f128))));178 try expect(math.isPositiveInf(round128(math.inf(f128))));
179 expect(math.isNegativeInf(round128(-math.inf(f128))));179 try expect(math.isNegativeInf(round128(-math.inf(f128))));
180 expect(math.isNan(round128(math.nan(f128))));180 try expect(math.isNan(round128(math.nan(f128))));
181}181}
lib/std/math/scalbn.zig+4-4
...@@ -84,14 +84,14 @@ fn scalbn64(x: f64, n_: i32) f64 {...@@ -84,14 +84,14 @@ fn scalbn64(x: f64, n_: i32) f64 {
84}84}
8585
86test "math.scalbn" {86test "math.scalbn" {
87 expect(scalbn(@as(f32, 1.5), 4) == scalbn32(1.5, 4));87 try expect(scalbn(@as(f32, 1.5), 4) == scalbn32(1.5, 4));
88 expect(scalbn(@as(f64, 1.5), 4) == scalbn64(1.5, 4));88 try expect(scalbn(@as(f64, 1.5), 4) == scalbn64(1.5, 4));
89}89}
9090
91test "math.scalbn32" {91test "math.scalbn32" {
92 expect(scalbn32(1.5, 4) == 24.0);92 try expect(scalbn32(1.5, 4) == 24.0);
93}93}
9494
95test "math.scalbn64" {95test "math.scalbn64" {
96 expect(scalbn64(1.5, 4) == 24.0);96 try expect(scalbn64(1.5, 4) == 24.0);
97}97}
lib/std/math/signbit.zig+12-12
...@@ -40,28 +40,28 @@ fn signbit128(x: f128) bool {...@@ -40,28 +40,28 @@ fn signbit128(x: f128) bool {
40}40}
4141
42test "math.signbit" {42test "math.signbit" {
43 expect(signbit(@as(f16, 4.0)) == signbit16(4.0));43 try expect(signbit(@as(f16, 4.0)) == signbit16(4.0));
44 expect(signbit(@as(f32, 4.0)) == signbit32(4.0));44 try expect(signbit(@as(f32, 4.0)) == signbit32(4.0));
45 expect(signbit(@as(f64, 4.0)) == signbit64(4.0));45 try expect(signbit(@as(f64, 4.0)) == signbit64(4.0));
46 expect(signbit(@as(f128, 4.0)) == signbit128(4.0));46 try expect(signbit(@as(f128, 4.0)) == signbit128(4.0));
47}47}
4848
49test "math.signbit16" {49test "math.signbit16" {
50 expect(!signbit16(4.0));50 try expect(!signbit16(4.0));
51 expect(signbit16(-3.0));51 try expect(signbit16(-3.0));
52}52}
5353
54test "math.signbit32" {54test "math.signbit32" {
55 expect(!signbit32(4.0));55 try expect(!signbit32(4.0));
56 expect(signbit32(-3.0));56 try expect(signbit32(-3.0));
57}57}
5858
59test "math.signbit64" {59test "math.signbit64" {
60 expect(!signbit64(4.0));60 try expect(!signbit64(4.0));
61 expect(signbit64(-3.0));61 try expect(signbit64(-3.0));
62}62}
6363
64test "math.signbit128" {64test "math.signbit128" {
65 expect(!signbit128(4.0));65 try expect(!signbit128(4.0));
66 expect(signbit128(-3.0));66 try expect(signbit128(-3.0));
67}67}
lib/std/math/sin.zig+27-27
...@@ -89,47 +89,47 @@ fn sin_(comptime T: type, x_: T) T {...@@ -89,47 +89,47 @@ fn sin_(comptime T: type, x_: T) T {
89}89}
9090
91test "math.sin" {91test "math.sin" {
92 expect(sin(@as(f32, 0.0)) == sin_(f32, 0.0));92 try expect(sin(@as(f32, 0.0)) == sin_(f32, 0.0));
93 expect(sin(@as(f64, 0.0)) == sin_(f64, 0.0));93 try expect(sin(@as(f64, 0.0)) == sin_(f64, 0.0));
94 expect(comptime (math.sin(@as(f64, 2))) == math.sin(@as(f64, 2)));94 try expect(comptime (math.sin(@as(f64, 2))) == math.sin(@as(f64, 2)));
95}95}
9696
97test "math.sin32" {97test "math.sin32" {
98 const epsilon = 0.000001;98 const epsilon = 0.000001;
9999
100 expect(math.approxEqAbs(f32, sin_(f32, 0.0), 0.0, epsilon));100 try expect(math.approxEqAbs(f32, sin_(f32, 0.0), 0.0, epsilon));
101 expect(math.approxEqAbs(f32, sin_(f32, 0.2), 0.198669, epsilon));101 try expect(math.approxEqAbs(f32, sin_(f32, 0.2), 0.198669, epsilon));
102 expect(math.approxEqAbs(f32, sin_(f32, 0.8923), 0.778517, epsilon));102 try expect(math.approxEqAbs(f32, sin_(f32, 0.8923), 0.778517, epsilon));
103 expect(math.approxEqAbs(f32, sin_(f32, 1.5), 0.997495, epsilon));103 try expect(math.approxEqAbs(f32, sin_(f32, 1.5), 0.997495, epsilon));
104 expect(math.approxEqAbs(f32, sin_(f32, -1.5), -0.997495, epsilon));104 try expect(math.approxEqAbs(f32, sin_(f32, -1.5), -0.997495, epsilon));
105 expect(math.approxEqAbs(f32, sin_(f32, 37.45), -0.246544, epsilon));105 try expect(math.approxEqAbs(f32, sin_(f32, 37.45), -0.246544, epsilon));
106 expect(math.approxEqAbs(f32, sin_(f32, 89.123), 0.916166, epsilon));106 try expect(math.approxEqAbs(f32, sin_(f32, 89.123), 0.916166, epsilon));
107}107}
108108
109test "math.sin64" {109test "math.sin64" {
110 const epsilon = 0.000001;110 const epsilon = 0.000001;
111111
112 expect(math.approxEqAbs(f64, sin_(f64, 0.0), 0.0, epsilon));112 try expect(math.approxEqAbs(f64, sin_(f64, 0.0), 0.0, epsilon));
113 expect(math.approxEqAbs(f64, sin_(f64, 0.2), 0.198669, epsilon));113 try expect(math.approxEqAbs(f64, sin_(f64, 0.2), 0.198669, epsilon));
114 expect(math.approxEqAbs(f64, sin_(f64, 0.8923), 0.778517, epsilon));114 try expect(math.approxEqAbs(f64, sin_(f64, 0.8923), 0.778517, epsilon));
115 expect(math.approxEqAbs(f64, sin_(f64, 1.5), 0.997495, epsilon));115 try expect(math.approxEqAbs(f64, sin_(f64, 1.5), 0.997495, epsilon));
116 expect(math.approxEqAbs(f64, sin_(f64, -1.5), -0.997495, epsilon));116 try expect(math.approxEqAbs(f64, sin_(f64, -1.5), -0.997495, epsilon));
117 expect(math.approxEqAbs(f64, sin_(f64, 37.45), -0.246543, epsilon));117 try expect(math.approxEqAbs(f64, sin_(f64, 37.45), -0.246543, epsilon));
118 expect(math.approxEqAbs(f64, sin_(f64, 89.123), 0.916166, epsilon));118 try expect(math.approxEqAbs(f64, sin_(f64, 89.123), 0.916166, epsilon));
119}119}
120120
121test "math.sin32.special" {121test "math.sin32.special" {
122 expect(sin_(f32, 0.0) == 0.0);122 try expect(sin_(f32, 0.0) == 0.0);
123 expect(sin_(f32, -0.0) == -0.0);123 try expect(sin_(f32, -0.0) == -0.0);
124 expect(math.isNan(sin_(f32, math.inf(f32))));124 try expect(math.isNan(sin_(f32, math.inf(f32))));
125 expect(math.isNan(sin_(f32, -math.inf(f32))));125 try expect(math.isNan(sin_(f32, -math.inf(f32))));
126 expect(math.isNan(sin_(f32, math.nan(f32))));126 try expect(math.isNan(sin_(f32, math.nan(f32))));
127}127}
128128
129test "math.sin64.special" {129test "math.sin64.special" {
130 expect(sin_(f64, 0.0) == 0.0);130 try expect(sin_(f64, 0.0) == 0.0);
131 expect(sin_(f64, -0.0) == -0.0);131 try expect(sin_(f64, -0.0) == -0.0);
132 expect(math.isNan(sin_(f64, math.inf(f64))));132 try expect(math.isNan(sin_(f64, math.inf(f64))));
133 expect(math.isNan(sin_(f64, -math.inf(f64))));133 try expect(math.isNan(sin_(f64, -math.inf(f64))));
134 expect(math.isNan(sin_(f64, math.nan(f64))));134 try expect(math.isNan(sin_(f64, math.nan(f64))));
135}135}
lib/std/math/sinh.zig+28-28
...@@ -98,48 +98,48 @@ fn sinh64(x: f64) f64 {...@@ -98,48 +98,48 @@ fn sinh64(x: f64) f64 {
98}98}
9999
100test "math.sinh" {100test "math.sinh" {
101 expect(sinh(@as(f32, 1.5)) == sinh32(1.5));101 try expect(sinh(@as(f32, 1.5)) == sinh32(1.5));
102 expect(sinh(@as(f64, 1.5)) == sinh64(1.5));102 try expect(sinh(@as(f64, 1.5)) == sinh64(1.5));
103}103}
104104
105test "math.sinh32" {105test "math.sinh32" {
106 const epsilon = 0.000001;106 const epsilon = 0.000001;
107107
108 expect(math.approxEqAbs(f32, sinh32(0.0), 0.0, epsilon));108 try expect(math.approxEqAbs(f32, sinh32(0.0), 0.0, epsilon));
109 expect(math.approxEqAbs(f32, sinh32(0.2), 0.201336, epsilon));109 try expect(math.approxEqAbs(f32, sinh32(0.2), 0.201336, epsilon));
110 expect(math.approxEqAbs(f32, sinh32(0.8923), 1.015512, epsilon));110 try expect(math.approxEqAbs(f32, sinh32(0.8923), 1.015512, epsilon));
111 expect(math.approxEqAbs(f32, sinh32(1.5), 2.129279, epsilon));111 try expect(math.approxEqAbs(f32, sinh32(1.5), 2.129279, epsilon));
112 expect(math.approxEqAbs(f32, sinh32(-0.0), -0.0, epsilon));112 try expect(math.approxEqAbs(f32, sinh32(-0.0), -0.0, epsilon));
113 expect(math.approxEqAbs(f32, sinh32(-0.2), -0.201336, epsilon));113 try expect(math.approxEqAbs(f32, sinh32(-0.2), -0.201336, epsilon));
114 expect(math.approxEqAbs(f32, sinh32(-0.8923), -1.015512, epsilon));114 try expect(math.approxEqAbs(f32, sinh32(-0.8923), -1.015512, epsilon));
115 expect(math.approxEqAbs(f32, sinh32(-1.5), -2.129279, epsilon));115 try expect(math.approxEqAbs(f32, sinh32(-1.5), -2.129279, epsilon));
116}116}
117117
118test "math.sinh64" {118test "math.sinh64" {
119 const epsilon = 0.000001;119 const epsilon = 0.000001;
120120
121 expect(math.approxEqAbs(f64, sinh64(0.0), 0.0, epsilon));121 try expect(math.approxEqAbs(f64, sinh64(0.0), 0.0, epsilon));
122 expect(math.approxEqAbs(f64, sinh64(0.2), 0.201336, epsilon));122 try expect(math.approxEqAbs(f64, sinh64(0.2), 0.201336, epsilon));
123 expect(math.approxEqAbs(f64, sinh64(0.8923), 1.015512, epsilon));123 try expect(math.approxEqAbs(f64, sinh64(0.8923), 1.015512, epsilon));
124 expect(math.approxEqAbs(f64, sinh64(1.5), 2.129279, epsilon));124 try expect(math.approxEqAbs(f64, sinh64(1.5), 2.129279, epsilon));
125 expect(math.approxEqAbs(f64, sinh64(-0.0), -0.0, epsilon));125 try expect(math.approxEqAbs(f64, sinh64(-0.0), -0.0, epsilon));
126 expect(math.approxEqAbs(f64, sinh64(-0.2), -0.201336, epsilon));126 try expect(math.approxEqAbs(f64, sinh64(-0.2), -0.201336, epsilon));
127 expect(math.approxEqAbs(f64, sinh64(-0.8923), -1.015512, epsilon));127 try expect(math.approxEqAbs(f64, sinh64(-0.8923), -1.015512, epsilon));
128 expect(math.approxEqAbs(f64, sinh64(-1.5), -2.129279, epsilon));128 try expect(math.approxEqAbs(f64, sinh64(-1.5), -2.129279, epsilon));
129}129}
130130
131test "math.sinh32.special" {131test "math.sinh32.special" {
132 expect(sinh32(0.0) == 0.0);132 try expect(sinh32(0.0) == 0.0);
133 expect(sinh32(-0.0) == -0.0);133 try expect(sinh32(-0.0) == -0.0);
134 expect(math.isPositiveInf(sinh32(math.inf(f32))));134 try expect(math.isPositiveInf(sinh32(math.inf(f32))));
135 expect(math.isNegativeInf(sinh32(-math.inf(f32))));135 try expect(math.isNegativeInf(sinh32(-math.inf(f32))));
136 expect(math.isNan(sinh32(math.nan(f32))));136 try expect(math.isNan(sinh32(math.nan(f32))));
137}137}
138138
139test "math.sinh64.special" {139test "math.sinh64.special" {
140 expect(sinh64(0.0) == 0.0);140 try expect(sinh64(0.0) == 0.0);
141 expect(sinh64(-0.0) == -0.0);141 try expect(sinh64(-0.0) == -0.0);
142 expect(math.isPositiveInf(sinh64(math.inf(f64))));142 try expect(math.isPositiveInf(sinh64(math.inf(f64))));
143 expect(math.isNegativeInf(sinh64(-math.inf(f64))));143 try expect(math.isNegativeInf(sinh64(-math.inf(f64))));
144 expect(math.isNan(sinh64(math.nan(f64))));144 try expect(math.isNan(sinh64(math.nan(f64))));
145}145}
lib/std/math/sqrt.zig+8-8
...@@ -69,14 +69,14 @@ fn sqrt_int(comptime T: type, value: T) Sqrt(T) {...@@ -69,14 +69,14 @@ fn sqrt_int(comptime T: type, value: T) Sqrt(T) {
69}69}
7070
71test "math.sqrt_int" {71test "math.sqrt_int" {
72 expect(sqrt_int(u0, 0) == 0);72 try expect(sqrt_int(u0, 0) == 0);
73 expect(sqrt_int(u1, 1) == 1);73 try expect(sqrt_int(u1, 1) == 1);
74 expect(sqrt_int(u32, 3) == 1);74 try expect(sqrt_int(u32, 3) == 1);
75 expect(sqrt_int(u32, 4) == 2);75 try expect(sqrt_int(u32, 4) == 2);
76 expect(sqrt_int(u32, 5) == 2);76 try expect(sqrt_int(u32, 5) == 2);
77 expect(sqrt_int(u32, 8) == 2);77 try expect(sqrt_int(u32, 8) == 2);
78 expect(sqrt_int(u32, 9) == 3);78 try expect(sqrt_int(u32, 9) == 3);
79 expect(sqrt_int(u32, 10) == 3);79 try expect(sqrt_int(u32, 10) == 3);
80}80}
8181
82/// Returns the return type `sqrt` will return given an operand of type `T`.82/// Returns the return type `sqrt` will return given an operand of type `T`.
lib/std/math/tan.zig+24-24
...@@ -80,44 +80,44 @@ fn tan_(comptime T: type, x_: T) T {...@@ -80,44 +80,44 @@ fn tan_(comptime T: type, x_: T) T {
80}80}
8181
82test "math.tan" {82test "math.tan" {
83 expect(tan(@as(f32, 0.0)) == tan_(f32, 0.0));83 try expect(tan(@as(f32, 0.0)) == tan_(f32, 0.0));
84 expect(tan(@as(f64, 0.0)) == tan_(f64, 0.0));84 try expect(tan(@as(f64, 0.0)) == tan_(f64, 0.0));
85}85}
8686
87test "math.tan32" {87test "math.tan32" {
88 const epsilon = 0.000001;88 const epsilon = 0.000001;
8989
90 expect(math.approxEqAbs(f32, tan_(f32, 0.0), 0.0, epsilon));90 try expect(math.approxEqAbs(f32, tan_(f32, 0.0), 0.0, epsilon));
91 expect(math.approxEqAbs(f32, tan_(f32, 0.2), 0.202710, epsilon));91 try expect(math.approxEqAbs(f32, tan_(f32, 0.2), 0.202710, epsilon));
92 expect(math.approxEqAbs(f32, tan_(f32, 0.8923), 1.240422, epsilon));92 try expect(math.approxEqAbs(f32, tan_(f32, 0.8923), 1.240422, epsilon));
93 expect(math.approxEqAbs(f32, tan_(f32, 1.5), 14.101420, epsilon));93 try expect(math.approxEqAbs(f32, tan_(f32, 1.5), 14.101420, epsilon));
94 expect(math.approxEqAbs(f32, tan_(f32, 37.45), -0.254397, epsilon));94 try expect(math.approxEqAbs(f32, tan_(f32, 37.45), -0.254397, epsilon));
95 expect(math.approxEqAbs(f32, tan_(f32, 89.123), 2.285852, epsilon));95 try expect(math.approxEqAbs(f32, tan_(f32, 89.123), 2.285852, epsilon));
96}96}
9797
98test "math.tan64" {98test "math.tan64" {
99 const epsilon = 0.000001;99 const epsilon = 0.000001;
100100
101 expect(math.approxEqAbs(f64, tan_(f64, 0.0), 0.0, epsilon));101 try expect(math.approxEqAbs(f64, tan_(f64, 0.0), 0.0, epsilon));
102 expect(math.approxEqAbs(f64, tan_(f64, 0.2), 0.202710, epsilon));102 try expect(math.approxEqAbs(f64, tan_(f64, 0.2), 0.202710, epsilon));
103 expect(math.approxEqAbs(f64, tan_(f64, 0.8923), 1.240422, epsilon));103 try expect(math.approxEqAbs(f64, tan_(f64, 0.8923), 1.240422, epsilon));
104 expect(math.approxEqAbs(f64, tan_(f64, 1.5), 14.101420, epsilon));104 try expect(math.approxEqAbs(f64, tan_(f64, 1.5), 14.101420, epsilon));
105 expect(math.approxEqAbs(f64, tan_(f64, 37.45), -0.254397, epsilon));105 try expect(math.approxEqAbs(f64, tan_(f64, 37.45), -0.254397, epsilon));
106 expect(math.approxEqAbs(f64, tan_(f64, 89.123), 2.2858376, epsilon));106 try expect(math.approxEqAbs(f64, tan_(f64, 89.123), 2.2858376, epsilon));
107}107}
108108
109test "math.tan32.special" {109test "math.tan32.special" {
110 expect(tan_(f32, 0.0) == 0.0);110 try expect(tan_(f32, 0.0) == 0.0);
111 expect(tan_(f32, -0.0) == -0.0);111 try expect(tan_(f32, -0.0) == -0.0);
112 expect(math.isNan(tan_(f32, math.inf(f32))));112 try expect(math.isNan(tan_(f32, math.inf(f32))));
113 expect(math.isNan(tan_(f32, -math.inf(f32))));113 try expect(math.isNan(tan_(f32, -math.inf(f32))));
114 expect(math.isNan(tan_(f32, math.nan(f32))));114 try expect(math.isNan(tan_(f32, math.nan(f32))));
115}115}
116116
117test "math.tan64.special" {117test "math.tan64.special" {
118 expect(tan_(f64, 0.0) == 0.0);118 try expect(tan_(f64, 0.0) == 0.0);
119 expect(tan_(f64, -0.0) == -0.0);119 try expect(tan_(f64, -0.0) == -0.0);
120 expect(math.isNan(tan_(f64, math.inf(f64))));120 try expect(math.isNan(tan_(f64, math.inf(f64))));
121 expect(math.isNan(tan_(f64, -math.inf(f64))));121 try expect(math.isNan(tan_(f64, -math.inf(f64))));
122 expect(math.isNan(tan_(f64, math.nan(f64))));122 try expect(math.isNan(tan_(f64, math.nan(f64))));
123}123}
lib/std/math/tanh.zig+22-22
...@@ -124,42 +124,42 @@ fn tanh64(x: f64) f64 {...@@ -124,42 +124,42 @@ fn tanh64(x: f64) f64 {
124}124}
125125
126test "math.tanh" {126test "math.tanh" {
127 expect(tanh(@as(f32, 1.5)) == tanh32(1.5));127 try expect(tanh(@as(f32, 1.5)) == tanh32(1.5));
128 expect(tanh(@as(f64, 1.5)) == tanh64(1.5));128 try expect(tanh(@as(f64, 1.5)) == tanh64(1.5));
129}129}
130130
131test "math.tanh32" {131test "math.tanh32" {
132 const epsilon = 0.000001;132 const epsilon = 0.000001;
133133
134 expect(math.approxEqAbs(f32, tanh32(0.0), 0.0, epsilon));134 try expect(math.approxEqAbs(f32, tanh32(0.0), 0.0, epsilon));
135 expect(math.approxEqAbs(f32, tanh32(0.2), 0.197375, epsilon));135 try expect(math.approxEqAbs(f32, tanh32(0.2), 0.197375, epsilon));
136 expect(math.approxEqAbs(f32, tanh32(0.8923), 0.712528, epsilon));136 try expect(math.approxEqAbs(f32, tanh32(0.8923), 0.712528, epsilon));
137 expect(math.approxEqAbs(f32, tanh32(1.5), 0.905148, epsilon));137 try expect(math.approxEqAbs(f32, tanh32(1.5), 0.905148, epsilon));
138 expect(math.approxEqAbs(f32, tanh32(37.45), 1.0, epsilon));138 try expect(math.approxEqAbs(f32, tanh32(37.45), 1.0, epsilon));
139}139}
140140
141test "math.tanh64" {141test "math.tanh64" {
142 const epsilon = 0.000001;142 const epsilon = 0.000001;
143143
144 expect(math.approxEqAbs(f64, tanh64(0.0), 0.0, epsilon));144 try expect(math.approxEqAbs(f64, tanh64(0.0), 0.0, epsilon));
145 expect(math.approxEqAbs(f64, tanh64(0.2), 0.197375, epsilon));145 try expect(math.approxEqAbs(f64, tanh64(0.2), 0.197375, epsilon));
146 expect(math.approxEqAbs(f64, tanh64(0.8923), 0.712528, epsilon));146 try expect(math.approxEqAbs(f64, tanh64(0.8923), 0.712528, epsilon));
147 expect(math.approxEqAbs(f64, tanh64(1.5), 0.905148, epsilon));147 try expect(math.approxEqAbs(f64, tanh64(1.5), 0.905148, epsilon));
148 expect(math.approxEqAbs(f64, tanh64(37.45), 1.0, epsilon));148 try expect(math.approxEqAbs(f64, tanh64(37.45), 1.0, epsilon));
149}149}
150150
151test "math.tanh32.special" {151test "math.tanh32.special" {
152 expect(tanh32(0.0) == 0.0);152 try expect(tanh32(0.0) == 0.0);
153 expect(tanh32(-0.0) == -0.0);153 try expect(tanh32(-0.0) == -0.0);
154 expect(tanh32(math.inf(f32)) == 1.0);154 try expect(tanh32(math.inf(f32)) == 1.0);
155 expect(tanh32(-math.inf(f32)) == -1.0);155 try expect(tanh32(-math.inf(f32)) == -1.0);
156 expect(math.isNan(tanh32(math.nan(f32))));156 try expect(math.isNan(tanh32(math.nan(f32))));
157}157}
158158
159test "math.tanh64.special" {159test "math.tanh64.special" {
160 expect(tanh64(0.0) == 0.0);160 try expect(tanh64(0.0) == 0.0);
161 expect(tanh64(-0.0) == -0.0);161 try expect(tanh64(-0.0) == -0.0);
162 expect(tanh64(math.inf(f64)) == 1.0);162 try expect(tanh64(math.inf(f64)) == 1.0);
163 expect(tanh64(-math.inf(f64)) == -1.0);163 try expect(tanh64(-math.inf(f64)) == -1.0);
164 expect(math.isNan(tanh64(math.nan(f64))));164 try expect(math.isNan(tanh64(math.nan(f64))));
165}165}
lib/std/math/trunc.zig+27-27
...@@ -94,49 +94,49 @@ fn trunc128(x: f128) f128 {...@@ -94,49 +94,49 @@ fn trunc128(x: f128) f128 {
94}94}
9595
96test "math.trunc" {96test "math.trunc" {
97 expect(trunc(@as(f32, 1.3)) == trunc32(1.3));97 try expect(trunc(@as(f32, 1.3)) == trunc32(1.3));
98 expect(trunc(@as(f64, 1.3)) == trunc64(1.3));98 try expect(trunc(@as(f64, 1.3)) == trunc64(1.3));
99 expect(trunc(@as(f128, 1.3)) == trunc128(1.3));99 try expect(trunc(@as(f128, 1.3)) == trunc128(1.3));
100}100}
101101
102test "math.trunc32" {102test "math.trunc32" {
103 expect(trunc32(1.3) == 1.0);103 try expect(trunc32(1.3) == 1.0);
104 expect(trunc32(-1.3) == -1.0);104 try expect(trunc32(-1.3) == -1.0);
105 expect(trunc32(0.2) == 0.0);105 try expect(trunc32(0.2) == 0.0);
106}106}
107107
108test "math.trunc64" {108test "math.trunc64" {
109 expect(trunc64(1.3) == 1.0);109 try expect(trunc64(1.3) == 1.0);
110 expect(trunc64(-1.3) == -1.0);110 try expect(trunc64(-1.3) == -1.0);
111 expect(trunc64(0.2) == 0.0);111 try expect(trunc64(0.2) == 0.0);
112}112}
113113
114test "math.trunc128" {114test "math.trunc128" {
115 expect(trunc128(1.3) == 1.0);115 try expect(trunc128(1.3) == 1.0);
116 expect(trunc128(-1.3) == -1.0);116 try expect(trunc128(-1.3) == -1.0);
117 expect(trunc128(0.2) == 0.0);117 try expect(trunc128(0.2) == 0.0);
118}118}
119119
120test "math.trunc32.special" {120test "math.trunc32.special" {
121 expect(trunc32(0.0) == 0.0); // 0x3F800000121 try expect(trunc32(0.0) == 0.0); // 0x3F800000
122 expect(trunc32(-0.0) == -0.0);122 try expect(trunc32(-0.0) == -0.0);
123 expect(math.isPositiveInf(trunc32(math.inf(f32))));123 try expect(math.isPositiveInf(trunc32(math.inf(f32))));
124 expect(math.isNegativeInf(trunc32(-math.inf(f32))));124 try expect(math.isNegativeInf(trunc32(-math.inf(f32))));
125 expect(math.isNan(trunc32(math.nan(f32))));125 try expect(math.isNan(trunc32(math.nan(f32))));
126}126}
127127
128test "math.trunc64.special" {128test "math.trunc64.special" {
129 expect(trunc64(0.0) == 0.0);129 try expect(trunc64(0.0) == 0.0);
130 expect(trunc64(-0.0) == -0.0);130 try expect(trunc64(-0.0) == -0.0);
131 expect(math.isPositiveInf(trunc64(math.inf(f64))));131 try expect(math.isPositiveInf(trunc64(math.inf(f64))));
132 expect(math.isNegativeInf(trunc64(-math.inf(f64))));132 try expect(math.isNegativeInf(trunc64(-math.inf(f64))));
133 expect(math.isNan(trunc64(math.nan(f64))));133 try expect(math.isNan(trunc64(math.nan(f64))));
134}134}
135135
136test "math.trunc128.special" {136test "math.trunc128.special" {
137 expect(trunc128(0.0) == 0.0);137 try expect(trunc128(0.0) == 0.0);
138 expect(trunc128(-0.0) == -0.0);138 try expect(trunc128(-0.0) == -0.0);
139 expect(math.isPositiveInf(trunc128(math.inf(f128))));139 try expect(math.isPositiveInf(trunc128(math.inf(f128))));
140 expect(math.isNegativeInf(trunc128(-math.inf(f128))));140 try expect(math.isNegativeInf(trunc128(-math.inf(f128))));
141 expect(math.isNan(trunc128(math.nan(f128))));141 try expect(math.isNan(trunc128(math.nan(f128))));
142}142}
lib/std/mem.zig+359-359
...@@ -142,8 +142,8 @@ fn failAllocatorAlloc(self: *Allocator, n: usize, alignment: u29, len_align: u29...@@ -142,8 +142,8 @@ fn failAllocatorAlloc(self: *Allocator, n: usize, alignment: u29, len_align: u29
142}142}
143143
144test "mem.Allocator basics" {144test "mem.Allocator basics" {
145 testing.expectError(error.OutOfMemory, failAllocator.alloc(u8, 1));145 try testing.expectError(error.OutOfMemory, failAllocator.alloc(u8, 1));
146 testing.expectError(error.OutOfMemory, failAllocator.allocSentinel(u8, 1, 0));146 try testing.expectError(error.OutOfMemory, failAllocator.allocSentinel(u8, 1, 0));
147}147}
148148
149/// Copy all of source into dest at position 0.149/// Copy all of source into dest at position 0.
...@@ -276,8 +276,8 @@ test "mem.zeroes" {...@@ -276,8 +276,8 @@ test "mem.zeroes" {
276 var a = zeroes(C_struct);276 var a = zeroes(C_struct);
277 a.y += 10;277 a.y += 10;
278278
279 testing.expect(a.x == 0);279 try testing.expect(a.x == 0);
280 testing.expect(a.y == 10);280 try testing.expect(a.y == 10);
281281
282 const ZigStruct = struct {282 const ZigStruct = struct {
283 integral_types: struct {283 integral_types: struct {
...@@ -314,32 +314,32 @@ test "mem.zeroes" {...@@ -314,32 +314,32 @@ test "mem.zeroes" {
314 };314 };
315315
316 const b = zeroes(ZigStruct);316 const b = zeroes(ZigStruct);
317 testing.expectEqual(@as(i8, 0), b.integral_types.integer_0);317 try testing.expectEqual(@as(i8, 0), b.integral_types.integer_0);
318 testing.expectEqual(@as(i8, 0), b.integral_types.integer_8);318 try testing.expectEqual(@as(i8, 0), b.integral_types.integer_8);
319 testing.expectEqual(@as(i16, 0), b.integral_types.integer_16);319 try testing.expectEqual(@as(i16, 0), b.integral_types.integer_16);
320 testing.expectEqual(@as(i32, 0), b.integral_types.integer_32);320 try testing.expectEqual(@as(i32, 0), b.integral_types.integer_32);
321 testing.expectEqual(@as(i64, 0), b.integral_types.integer_64);321 try testing.expectEqual(@as(i64, 0), b.integral_types.integer_64);
322 testing.expectEqual(@as(i128, 0), b.integral_types.integer_128);322 try testing.expectEqual(@as(i128, 0), b.integral_types.integer_128);
323 testing.expectEqual(@as(u8, 0), b.integral_types.unsigned_0);323 try testing.expectEqual(@as(u8, 0), b.integral_types.unsigned_0);
324 testing.expectEqual(@as(u8, 0), b.integral_types.unsigned_8);324 try testing.expectEqual(@as(u8, 0), b.integral_types.unsigned_8);
325 testing.expectEqual(@as(u16, 0), b.integral_types.unsigned_16);325 try testing.expectEqual(@as(u16, 0), b.integral_types.unsigned_16);
326 testing.expectEqual(@as(u32, 0), b.integral_types.unsigned_32);326 try testing.expectEqual(@as(u32, 0), b.integral_types.unsigned_32);
327 testing.expectEqual(@as(u64, 0), b.integral_types.unsigned_64);327 try testing.expectEqual(@as(u64, 0), b.integral_types.unsigned_64);
328 testing.expectEqual(@as(u128, 0), b.integral_types.unsigned_128);328 try testing.expectEqual(@as(u128, 0), b.integral_types.unsigned_128);
329 testing.expectEqual(@as(f32, 0), b.integral_types.float_32);329 try testing.expectEqual(@as(f32, 0), b.integral_types.float_32);
330 testing.expectEqual(@as(f64, 0), b.integral_types.float_64);330 try testing.expectEqual(@as(f64, 0), b.integral_types.float_64);
331 testing.expectEqual(@as(?*u8, null), b.pointers.optional);331 try testing.expectEqual(@as(?*u8, null), b.pointers.optional);
332 testing.expectEqual(@as([*c]u8, null), b.pointers.c_pointer);332 try testing.expectEqual(@as([*c]u8, null), b.pointers.c_pointer);
333 testing.expectEqual(@as([]u8, &[_]u8{}), b.pointers.slice);333 try testing.expectEqual(@as([]u8, &[_]u8{}), b.pointers.slice);
334 for (b.array) |e| {334 for (b.array) |e| {
335 testing.expectEqual(@as(u32, 0), e);335 try testing.expectEqual(@as(u32, 0), e);
336 }336 }
337 testing.expectEqual(@splat(2, @as(u32, 0)), b.vector_u32);337 try testing.expectEqual(@splat(2, @as(u32, 0)), b.vector_u32);
338 testing.expectEqual(@splat(2, @as(f32, 0.0)), b.vector_f32);338 try testing.expectEqual(@splat(2, @as(f32, 0.0)), b.vector_f32);
339 testing.expectEqual(@splat(2, @as(bool, false)), b.vector_bool);339 try testing.expectEqual(@splat(2, @as(bool, false)), b.vector_bool);
340 testing.expectEqual(@as(?u8, null), b.optional_int);340 try testing.expectEqual(@as(?u8, null), b.optional_int);
341 for (b.sentinel) |e| {341 for (b.sentinel) |e| {
342 testing.expectEqual(@as(u8, 0), e);342 try testing.expectEqual(@as(u8, 0), e);
343 }343 }
344344
345 const C_union = extern union {345 const C_union = extern union {
...@@ -348,7 +348,7 @@ test "mem.zeroes" {...@@ -348,7 +348,7 @@ test "mem.zeroes" {
348 };348 };
349349
350 var c = zeroes(C_union);350 var c = zeroes(C_union);
351 testing.expectEqual(@as(u8, 0), c.a);351 try testing.expectEqual(@as(u8, 0), c.a);
352}352}
353353
354/// Initializes all fields of the struct with their default value, or zero values if no default value is present.354/// Initializes all fields of the struct with their default value, or zero values if no default value is present.
...@@ -421,7 +421,7 @@ test "zeroInit" {...@@ -421,7 +421,7 @@ test "zeroInit" {
421 .a = 42,421 .a = 42,
422 });422 });
423423
424 testing.expectEqual(S{424 try testing.expectEqual(S{
425 .a = 42,425 .a = 42,
426 .b = null,426 .b = null,
427 .c = .{427 .c = .{
...@@ -439,7 +439,7 @@ test "zeroInit" {...@@ -439,7 +439,7 @@ test "zeroInit" {
439 };439 };
440440
441 const c = zeroInit(Color, .{ 255, 255 });441 const c = zeroInit(Color, .{ 255, 255 });
442 testing.expectEqual(Color{442 try testing.expectEqual(Color{
443 .r = 255,443 .r = 255,
444 .g = 255,444 .g = 255,
445 .b = 0,445 .b = 0,
...@@ -462,11 +462,11 @@ pub fn order(comptime T: type, lhs: []const T, rhs: []const T) math.Order {...@@ -462,11 +462,11 @@ pub fn order(comptime T: type, lhs: []const T, rhs: []const T) math.Order {
462}462}
463463
464test "order" {464test "order" {
465 testing.expect(order(u8, "abcd", "bee") == .lt);465 try testing.expect(order(u8, "abcd", "bee") == .lt);
466 testing.expect(order(u8, "abc", "abc") == .eq);466 try testing.expect(order(u8, "abc", "abc") == .eq);
467 testing.expect(order(u8, "abc", "abc0") == .lt);467 try testing.expect(order(u8, "abc", "abc0") == .lt);
468 testing.expect(order(u8, "", "") == .eq);468 try testing.expect(order(u8, "", "") == .eq);
469 testing.expect(order(u8, "", "a") == .lt);469 try testing.expect(order(u8, "", "a") == .lt);
470}470}
471471
472/// Returns true if lhs < rhs, false otherwise472/// Returns true if lhs < rhs, false otherwise
...@@ -475,11 +475,11 @@ pub fn lessThan(comptime T: type, lhs: []const T, rhs: []const T) bool {...@@ -475,11 +475,11 @@ pub fn lessThan(comptime T: type, lhs: []const T, rhs: []const T) bool {
475}475}
476476
477test "mem.lessThan" {477test "mem.lessThan" {
478 testing.expect(lessThan(u8, "abcd", "bee"));478 try testing.expect(lessThan(u8, "abcd", "bee"));
479 testing.expect(!lessThan(u8, "abc", "abc"));479 try testing.expect(!lessThan(u8, "abc", "abc"));
480 testing.expect(lessThan(u8, "abc", "abc0"));480 try testing.expect(lessThan(u8, "abc", "abc0"));
481 testing.expect(!lessThan(u8, "", ""));481 try testing.expect(!lessThan(u8, "", ""));
482 testing.expect(lessThan(u8, "", "a"));482 try testing.expect(lessThan(u8, "", "a"));
483}483}
484484
485/// Compares two slices and returns whether they are equal.485/// Compares two slices and returns whether they are equal.
...@@ -504,11 +504,11 @@ pub fn indexOfDiff(comptime T: type, a: []const T, b: []const T) ?usize {...@@ -504,11 +504,11 @@ pub fn indexOfDiff(comptime T: type, a: []const T, b: []const T) ?usize {
504}504}
505505
506test "indexOfDiff" {506test "indexOfDiff" {
507 testing.expectEqual(indexOfDiff(u8, "one", "one"), null);507 try testing.expectEqual(indexOfDiff(u8, "one", "one"), null);
508 testing.expectEqual(indexOfDiff(u8, "one two", "one"), 3);508 try testing.expectEqual(indexOfDiff(u8, "one two", "one"), 3);
509 testing.expectEqual(indexOfDiff(u8, "one", "one two"), 3);509 try testing.expectEqual(indexOfDiff(u8, "one", "one two"), 3);
510 testing.expectEqual(indexOfDiff(u8, "one twx", "one two"), 6);510 try testing.expectEqual(indexOfDiff(u8, "one twx", "one two"), 6);
511 testing.expectEqual(indexOfDiff(u8, "xne", "one"), 0);511 try testing.expectEqual(indexOfDiff(u8, "xne", "one"), 0);
512}512}
513513
514pub const toSliceConst = @compileError("deprecated; use std.mem.spanZ");514pub const toSliceConst = @compileError("deprecated; use std.mem.spanZ");
...@@ -548,26 +548,26 @@ pub fn Span(comptime T: type) type {...@@ -548,26 +548,26 @@ pub fn Span(comptime T: type) type {
548}548}
549549
550test "Span" {550test "Span" {
551 testing.expect(Span(*[5]u16) == []u16);551 try testing.expect(Span(*[5]u16) == []u16);
552 testing.expect(Span(?*[5]u16) == ?[]u16);552 try testing.expect(Span(?*[5]u16) == ?[]u16);
553 testing.expect(Span(*const [5]u16) == []const u16);553 try testing.expect(Span(*const [5]u16) == []const u16);
554 testing.expect(Span(?*const [5]u16) == ?[]const u16);554 try testing.expect(Span(?*const [5]u16) == ?[]const u16);
555 testing.expect(Span([]u16) == []u16);555 try testing.expect(Span([]u16) == []u16);
556 testing.expect(Span(?[]u16) == ?[]u16);556 try testing.expect(Span(?[]u16) == ?[]u16);
557 testing.expect(Span([]const u8) == []const u8);557 try testing.expect(Span([]const u8) == []const u8);
558 testing.expect(Span(?[]const u8) == ?[]const u8);558 try testing.expect(Span(?[]const u8) == ?[]const u8);
559 testing.expect(Span([:1]u16) == [:1]u16);559 try testing.expect(Span([:1]u16) == [:1]u16);
560 testing.expect(Span(?[:1]u16) == ?[:1]u16);560 try testing.expect(Span(?[:1]u16) == ?[:1]u16);
561 testing.expect(Span([:1]const u8) == [:1]const u8);561 try testing.expect(Span([:1]const u8) == [:1]const u8);
562 testing.expect(Span(?[:1]const u8) == ?[:1]const u8);562 try testing.expect(Span(?[:1]const u8) == ?[:1]const u8);
563 testing.expect(Span([*:1]u16) == [:1]u16);563 try testing.expect(Span([*:1]u16) == [:1]u16);
564 testing.expect(Span(?[*:1]u16) == ?[:1]u16);564 try testing.expect(Span(?[*:1]u16) == ?[:1]u16);
565 testing.expect(Span([*:1]const u8) == [:1]const u8);565 try testing.expect(Span([*:1]const u8) == [:1]const u8);
566 testing.expect(Span(?[*:1]const u8) == ?[:1]const u8);566 try testing.expect(Span(?[*:1]const u8) == ?[:1]const u8);
567 testing.expect(Span([*c]u16) == [:0]u16);567 try testing.expect(Span([*c]u16) == [:0]u16);
568 testing.expect(Span(?[*c]u16) == ?[:0]u16);568 try testing.expect(Span(?[*c]u16) == ?[:0]u16);
569 testing.expect(Span([*c]const u8) == [:0]const u8);569 try testing.expect(Span([*c]const u8) == [:0]const u8);
570 testing.expect(Span(?[*c]const u8) == ?[:0]const u8);570 try testing.expect(Span(?[*c]const u8) == ?[:0]const u8);
571}571}
572572
573/// Takes a pointer to an array, a sentinel-terminated pointer, or a slice, and573/// Takes a pointer to an array, a sentinel-terminated pointer, or a slice, and
...@@ -597,9 +597,9 @@ pub fn span(ptr: anytype) Span(@TypeOf(ptr)) {...@@ -597,9 +597,9 @@ pub fn span(ptr: anytype) Span(@TypeOf(ptr)) {
597test "span" {597test "span" {
598 var array: [5]u16 = [_]u16{ 1, 2, 3, 4, 5 };598 var array: [5]u16 = [_]u16{ 1, 2, 3, 4, 5 };
599 const ptr = @as([*:3]u16, array[0..2 :3]);599 const ptr = @as([*:3]u16, array[0..2 :3]);
600 testing.expect(eql(u16, span(ptr), &[_]u16{ 1, 2 }));600 try testing.expect(eql(u16, span(ptr), &[_]u16{ 1, 2 }));
601 testing.expect(eql(u16, span(&array), &[_]u16{ 1, 2, 3, 4, 5 }));601 try testing.expect(eql(u16, span(&array), &[_]u16{ 1, 2, 3, 4, 5 }));
602 testing.expectEqual(@as(?[:0]u16, null), span(@as(?[*:0]u16, null)));602 try testing.expectEqual(@as(?[:0]u16, null), span(@as(?[*:0]u16, null)));
603}603}
604604
605/// Same as `span`, except when there is both a sentinel and an array605/// Same as `span`, except when there is both a sentinel and an array
...@@ -625,9 +625,9 @@ pub fn spanZ(ptr: anytype) Span(@TypeOf(ptr)) {...@@ -625,9 +625,9 @@ pub fn spanZ(ptr: anytype) Span(@TypeOf(ptr)) {
625test "spanZ" {625test "spanZ" {
626 var array: [5]u16 = [_]u16{ 1, 2, 3, 4, 5 };626 var array: [5]u16 = [_]u16{ 1, 2, 3, 4, 5 };
627 const ptr = @as([*:3]u16, array[0..2 :3]);627 const ptr = @as([*:3]u16, array[0..2 :3]);
628 testing.expect(eql(u16, spanZ(ptr), &[_]u16{ 1, 2 }));628 try testing.expect(eql(u16, spanZ(ptr), &[_]u16{ 1, 2 }));
629 testing.expect(eql(u16, spanZ(&array), &[_]u16{ 1, 2, 3, 4, 5 }));629 try testing.expect(eql(u16, spanZ(&array), &[_]u16{ 1, 2, 3, 4, 5 }));
630 testing.expectEqual(@as(?[:0]u16, null), spanZ(@as(?[*:0]u16, null)));630 try testing.expectEqual(@as(?[:0]u16, null), spanZ(@as(?[*:0]u16, null)));
631}631}
632632
633/// Takes a pointer to an array, an array, a vector, a sentinel-terminated pointer,633/// Takes a pointer to an array, an array, a vector, a sentinel-terminated pointer,
...@@ -661,30 +661,30 @@ pub fn len(value: anytype) usize {...@@ -661,30 +661,30 @@ pub fn len(value: anytype) usize {
661}661}
662662
663test "len" {663test "len" {
664 testing.expect(len("aoeu") == 4);664 try testing.expect(len("aoeu") == 4);
665665
666 {666 {
667 var array: [5]u16 = [_]u16{ 1, 2, 3, 4, 5 };667 var array: [5]u16 = [_]u16{ 1, 2, 3, 4, 5 };
668 testing.expect(len(&array) == 5);668 try testing.expect(len(&array) == 5);
669 testing.expect(len(array[0..3]) == 3);669 try testing.expect(len(array[0..3]) == 3);
670 array[2] = 0;670 array[2] = 0;
671 const ptr = @as([*:0]u16, array[0..2 :0]);671 const ptr = @as([*:0]u16, array[0..2 :0]);
672 testing.expect(len(ptr) == 2);672 try testing.expect(len(ptr) == 2);
673 }673 }
674 {674 {
675 var array: [5:0]u16 = [_:0]u16{ 1, 2, 3, 4, 5 };675 var array: [5:0]u16 = [_:0]u16{ 1, 2, 3, 4, 5 };
676 testing.expect(len(&array) == 5);676 try testing.expect(len(&array) == 5);
677 array[2] = 0;677 array[2] = 0;
678 testing.expect(len(&array) == 5);678 try testing.expect(len(&array) == 5);
679 }679 }
680 {680 {
681 const vector: meta.Vector(2, u32) = [2]u32{ 1, 2 };681 const vector: meta.Vector(2, u32) = [2]u32{ 1, 2 };
682 testing.expect(len(vector) == 2);682 try testing.expect(len(vector) == 2);
683 }683 }
684 {684 {
685 const tuple = .{ 1, 2 };685 const tuple = .{ 1, 2 };
686 testing.expect(len(tuple) == 2);686 try testing.expect(len(tuple) == 2);
687 testing.expect(tuple[0] == 1);687 try testing.expect(tuple[0] == 1);
688 }688 }
689}689}
690690
...@@ -725,21 +725,21 @@ pub fn lenZ(ptr: anytype) usize {...@@ -725,21 +725,21 @@ pub fn lenZ(ptr: anytype) usize {
725}725}
726726
727test "lenZ" {727test "lenZ" {
728 testing.expect(lenZ("aoeu") == 4);728 try testing.expect(lenZ("aoeu") == 4);
729729
730 {730 {
731 var array: [5]u16 = [_]u16{ 1, 2, 3, 4, 5 };731 var array: [5]u16 = [_]u16{ 1, 2, 3, 4, 5 };
732 testing.expect(lenZ(&array) == 5);732 try testing.expect(lenZ(&array) == 5);
733 testing.expect(lenZ(array[0..3]) == 3);733 try testing.expect(lenZ(array[0..3]) == 3);
734 array[2] = 0;734 array[2] = 0;
735 const ptr = @as([*:0]u16, array[0..2 :0]);735 const ptr = @as([*:0]u16, array[0..2 :0]);
736 testing.expect(lenZ(ptr) == 2);736 try testing.expect(lenZ(ptr) == 2);
737 }737 }
738 {738 {
739 var array: [5:0]u16 = [_:0]u16{ 1, 2, 3, 4, 5 };739 var array: [5:0]u16 = [_:0]u16{ 1, 2, 3, 4, 5 };
740 testing.expect(lenZ(&array) == 5);740 try testing.expect(lenZ(&array) == 5);
741 array[2] = 0;741 array[2] = 0;
742 testing.expect(lenZ(&array) == 2);742 try testing.expect(lenZ(&array) == 2);
743 }743 }
744}744}
745745
...@@ -793,10 +793,10 @@ pub fn trim(comptime T: type, slice: []const T, values_to_strip: []const T) []co...@@ -793,10 +793,10 @@ pub fn trim(comptime T: type, slice: []const T, values_to_strip: []const T) []co
793}793}
794794
795test "mem.trim" {795test "mem.trim" {
796 testing.expectEqualSlices(u8, "foo\n ", trimLeft(u8, " foo\n ", " \n"));796 try testing.expectEqualSlices(u8, "foo\n ", trimLeft(u8, " foo\n ", " \n"));
797 testing.expectEqualSlices(u8, " foo", trimRight(u8, " foo\n ", " \n"));797 try testing.expectEqualSlices(u8, " foo", trimRight(u8, " foo\n ", " \n"));
798 testing.expectEqualSlices(u8, "foo", trim(u8, " foo\n ", " \n"));798 try testing.expectEqualSlices(u8, "foo", trim(u8, " foo\n ", " \n"));
799 testing.expectEqualSlices(u8, "foo", trim(u8, "foo", " \n"));799 try testing.expectEqualSlices(u8, "foo", trim(u8, "foo", " \n"));
800}800}
801801
802/// Linear search for the index of a scalar value inside a slice.802/// Linear search for the index of a scalar value inside a slice.
...@@ -951,28 +951,28 @@ pub fn indexOfPos(comptime T: type, haystack: []const T, start_index: usize, nee...@@ -951,28 +951,28 @@ pub fn indexOfPos(comptime T: type, haystack: []const T, start_index: usize, nee
951}951}
952952
953test "mem.indexOf" {953test "mem.indexOf" {
954 testing.expect(indexOf(u8, "one two three four five six seven eight nine ten eleven", "three four").? == 8);954 try testing.expect(indexOf(u8, "one two three four five six seven eight nine ten eleven", "three four").? == 8);
955 testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten eleven", "three four").? == 8);955 try testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten eleven", "three four").? == 8);
956 testing.expect(indexOf(u8, "one two three four five six seven eight nine ten eleven", "two two") == null);956 try testing.expect(indexOf(u8, "one two three four five six seven eight nine ten eleven", "two two") == null);
957 testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten eleven", "two two") == null);957 try testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten eleven", "two two") == null);
958958
959 testing.expect(indexOf(u8, "one two three four five six seven eight nine ten", "").? == 0);959 try testing.expect(indexOf(u8, "one two three four five six seven eight nine ten", "").? == 0);
960 testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten", "").? == 48);960 try testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten", "").? == 48);
961961
962 testing.expect(indexOf(u8, "one two three four", "four").? == 14);962 try testing.expect(indexOf(u8, "one two three four", "four").? == 14);
963 testing.expect(lastIndexOf(u8, "one two three two four", "two").? == 14);963 try testing.expect(lastIndexOf(u8, "one two three two four", "two").? == 14);
964 testing.expect(indexOf(u8, "one two three four", "gour") == null);964 try testing.expect(indexOf(u8, "one two three four", "gour") == null);
965 testing.expect(lastIndexOf(u8, "one two three four", "gour") == null);965 try testing.expect(lastIndexOf(u8, "one two three four", "gour") == null);
966 testing.expect(indexOf(u8, "foo", "foo").? == 0);966 try testing.expect(indexOf(u8, "foo", "foo").? == 0);
967 testing.expect(lastIndexOf(u8, "foo", "foo").? == 0);967 try testing.expect(lastIndexOf(u8, "foo", "foo").? == 0);
968 testing.expect(indexOf(u8, "foo", "fool") == null);968 try testing.expect(indexOf(u8, "foo", "fool") == null);
969 testing.expect(lastIndexOf(u8, "foo", "lfoo") == null);969 try testing.expect(lastIndexOf(u8, "foo", "lfoo") == null);
970 testing.expect(lastIndexOf(u8, "foo", "fool") == null);970 try testing.expect(lastIndexOf(u8, "foo", "fool") == null);
971971
972 testing.expect(indexOf(u8, "foo foo", "foo").? == 0);972 try testing.expect(indexOf(u8, "foo foo", "foo").? == 0);
973 testing.expect(lastIndexOf(u8, "foo foo", "foo").? == 4);973 try testing.expect(lastIndexOf(u8, "foo foo", "foo").? == 4);
974 testing.expect(lastIndexOfAny(u8, "boo, cat", "abo").? == 6);974 try testing.expect(lastIndexOfAny(u8, "boo, cat", "abo").? == 6);
975 testing.expect(lastIndexOfScalar(u8, "boo", 'o').? == 2);975 try testing.expect(lastIndexOfScalar(u8, "boo", 'o').? == 2);
976}976}
977977
978/// Returns the number of needles inside the haystack978/// Returns the number of needles inside the haystack
...@@ -992,17 +992,17 @@ pub fn count(comptime T: type, haystack: []const T, needle: []const T) usize {...@@ -992,17 +992,17 @@ pub fn count(comptime T: type, haystack: []const T, needle: []const T) usize {
992}992}
993993
994test "mem.count" {994test "mem.count" {
995 testing.expect(count(u8, "", "h") == 0);995 try testing.expect(count(u8, "", "h") == 0);
996 testing.expect(count(u8, "h", "h") == 1);996 try testing.expect(count(u8, "h", "h") == 1);
997 testing.expect(count(u8, "hh", "h") == 2);997 try testing.expect(count(u8, "hh", "h") == 2);
998 testing.expect(count(u8, "world!", "hello") == 0);998 try testing.expect(count(u8, "world!", "hello") == 0);
999 testing.expect(count(u8, "hello world!", "hello") == 1);999 try testing.expect(count(u8, "hello world!", "hello") == 1);
1000 testing.expect(count(u8, " abcabc abc", "abc") == 3);1000 try testing.expect(count(u8, " abcabc abc", "abc") == 3);
1001 testing.expect(count(u8, "udexdcbvbruhasdrw", "bruh") == 1);1001 try testing.expect(count(u8, "udexdcbvbruhasdrw", "bruh") == 1);
1002 testing.expect(count(u8, "foo bar", "o bar") == 1);1002 try testing.expect(count(u8, "foo bar", "o bar") == 1);
1003 testing.expect(count(u8, "foofoofoo", "foo") == 3);1003 try testing.expect(count(u8, "foofoofoo", "foo") == 3);
1004 testing.expect(count(u8, "fffffff", "ff") == 3);1004 try testing.expect(count(u8, "fffffff", "ff") == 3);
1005 testing.expect(count(u8, "owowowu", "owowu") == 1);1005 try testing.expect(count(u8, "owowowu", "owowu") == 1);
1006}1006}
10071007
1008/// Returns true if the haystack contains expected_count or more needles1008/// Returns true if the haystack contains expected_count or more needles
...@@ -1024,19 +1024,19 @@ pub fn containsAtLeast(comptime T: type, haystack: []const T, expected_count: us...@@ -1024,19 +1024,19 @@ pub fn containsAtLeast(comptime T: type, haystack: []const T, expected_count: us
1024}1024}
10251025
1026test "mem.containsAtLeast" {1026test "mem.containsAtLeast" {
1027 testing.expect(containsAtLeast(u8, "aa", 0, "a"));1027 try testing.expect(containsAtLeast(u8, "aa", 0, "a"));
1028 testing.expect(containsAtLeast(u8, "aa", 1, "a"));1028 try testing.expect(containsAtLeast(u8, "aa", 1, "a"));
1029 testing.expect(containsAtLeast(u8, "aa", 2, "a"));1029 try testing.expect(containsAtLeast(u8, "aa", 2, "a"));
1030 testing.expect(!containsAtLeast(u8, "aa", 3, "a"));1030 try testing.expect(!containsAtLeast(u8, "aa", 3, "a"));
10311031
1032 testing.expect(containsAtLeast(u8, "radaradar", 1, "radar"));1032 try testing.expect(containsAtLeast(u8, "radaradar", 1, "radar"));
1033 testing.expect(!containsAtLeast(u8, "radaradar", 2, "radar"));1033 try testing.expect(!containsAtLeast(u8, "radaradar", 2, "radar"));
10341034
1035 testing.expect(containsAtLeast(u8, "radarradaradarradar", 3, "radar"));1035 try testing.expect(containsAtLeast(u8, "radarradaradarradar", 3, "radar"));
1036 testing.expect(!containsAtLeast(u8, "radarradaradarradar", 4, "radar"));1036 try testing.expect(!containsAtLeast(u8, "radarradaradarradar", 4, "radar"));
10371037
1038 testing.expect(containsAtLeast(u8, " radar radar ", 2, "radar"));1038 try testing.expect(containsAtLeast(u8, " radar radar ", 2, "radar"));
1039 testing.expect(!containsAtLeast(u8, " radar radar ", 3, "radar"));1039 try testing.expect(!containsAtLeast(u8, " radar radar ", 3, "radar"));
1040}1040}
10411041
1042/// Reads an integer from memory with size equal to bytes.len.1042/// Reads an integer from memory with size equal to bytes.len.
...@@ -1141,34 +1141,34 @@ test "comptime read/write int" {...@@ -1141,34 +1141,34 @@ test "comptime read/write int" {
1141 var bytes: [2]u8 = undefined;1141 var bytes: [2]u8 = undefined;
1142 writeIntLittle(u16, &bytes, 0x1234);1142 writeIntLittle(u16, &bytes, 0x1234);
1143 const result = readIntBig(u16, &bytes);1143 const result = readIntBig(u16, &bytes);
1144 testing.expect(result == 0x3412);1144 try testing.expect(result == 0x3412);
1145 }1145 }
1146 comptime {1146 comptime {
1147 var bytes: [2]u8 = undefined;1147 var bytes: [2]u8 = undefined;
1148 writeIntBig(u16, &bytes, 0x1234);1148 writeIntBig(u16, &bytes, 0x1234);
1149 const result = readIntLittle(u16, &bytes);1149 const result = readIntLittle(u16, &bytes);
1150 testing.expect(result == 0x3412);1150 try testing.expect(result == 0x3412);
1151 }1151 }
1152}1152}
11531153
1154test "readIntBig and readIntLittle" {1154test "readIntBig and readIntLittle" {
1155 testing.expect(readIntSliceBig(u0, &[_]u8{}) == 0x0);1155 try testing.expect(readIntSliceBig(u0, &[_]u8{}) == 0x0);
1156 testing.expect(readIntSliceLittle(u0, &[_]u8{}) == 0x0);1156 try testing.expect(readIntSliceLittle(u0, &[_]u8{}) == 0x0);
11571157
1158 testing.expect(readIntSliceBig(u8, &[_]u8{0x32}) == 0x32);1158 try testing.expect(readIntSliceBig(u8, &[_]u8{0x32}) == 0x32);
1159 testing.expect(readIntSliceLittle(u8, &[_]u8{0x12}) == 0x12);1159 try testing.expect(readIntSliceLittle(u8, &[_]u8{0x12}) == 0x12);
11601160
1161 testing.expect(readIntSliceBig(u16, &[_]u8{ 0x12, 0x34 }) == 0x1234);1161 try testing.expect(readIntSliceBig(u16, &[_]u8{ 0x12, 0x34 }) == 0x1234);
1162 testing.expect(readIntSliceLittle(u16, &[_]u8{ 0x12, 0x34 }) == 0x3412);1162 try testing.expect(readIntSliceLittle(u16, &[_]u8{ 0x12, 0x34 }) == 0x3412);
11631163
1164 testing.expect(readIntSliceBig(u72, &[_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }) == 0x123456789abcdef024);1164 try testing.expect(readIntSliceBig(u72, &[_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }) == 0x123456789abcdef024);
1165 testing.expect(readIntSliceLittle(u72, &[_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }) == 0xfedcba9876543210ec);1165 try testing.expect(readIntSliceLittle(u72, &[_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }) == 0xfedcba9876543210ec);
11661166
1167 testing.expect(readIntSliceBig(i8, &[_]u8{0xff}) == -1);1167 try testing.expect(readIntSliceBig(i8, &[_]u8{0xff}) == -1);
1168 testing.expect(readIntSliceLittle(i8, &[_]u8{0xfe}) == -2);1168 try testing.expect(readIntSliceLittle(i8, &[_]u8{0xfe}) == -2);
11691169
1170 testing.expect(readIntSliceBig(i16, &[_]u8{ 0xff, 0xfd }) == -3);1170 try testing.expect(readIntSliceBig(i16, &[_]u8{ 0xff, 0xfd }) == -3);
1171 testing.expect(readIntSliceLittle(i16, &[_]u8{ 0xfc, 0xff }) == -4);1171 try testing.expect(readIntSliceLittle(i16, &[_]u8{ 0xfc, 0xff }) == -4);
1172}1172}
11731173
1174/// Writes an integer to memory, storing it in twos-complement.1174/// Writes an integer to memory, storing it in twos-complement.
...@@ -1283,34 +1283,34 @@ test "writeIntBig and writeIntLittle" {...@@ -1283,34 +1283,34 @@ test "writeIntBig and writeIntLittle" {
1283 var buf9: [9]u8 = undefined;1283 var buf9: [9]u8 = undefined;
12841284
1285 writeIntBig(u0, &buf0, 0x0);1285 writeIntBig(u0, &buf0, 0x0);
1286 testing.expect(eql(u8, buf0[0..], &[_]u8{}));1286 try testing.expect(eql(u8, buf0[0..], &[_]u8{}));
1287 writeIntLittle(u0, &buf0, 0x0);1287 writeIntLittle(u0, &buf0, 0x0);
1288 testing.expect(eql(u8, buf0[0..], &[_]u8{}));1288 try testing.expect(eql(u8, buf0[0..], &[_]u8{}));
12891289
1290 writeIntBig(u8, &buf1, 0x12);1290 writeIntBig(u8, &buf1, 0x12);
1291 testing.expect(eql(u8, buf1[0..], &[_]u8{0x12}));1291 try testing.expect(eql(u8, buf1[0..], &[_]u8{0x12}));
1292 writeIntLittle(u8, &buf1, 0x34);1292 writeIntLittle(u8, &buf1, 0x34);
1293 testing.expect(eql(u8, buf1[0..], &[_]u8{0x34}));1293 try testing.expect(eql(u8, buf1[0..], &[_]u8{0x34}));
12941294
1295 writeIntBig(u16, &buf2, 0x1234);1295 writeIntBig(u16, &buf2, 0x1234);
1296 testing.expect(eql(u8, buf2[0..], &[_]u8{ 0x12, 0x34 }));1296 try testing.expect(eql(u8, buf2[0..], &[_]u8{ 0x12, 0x34 }));
1297 writeIntLittle(u16, &buf2, 0x5678);1297 writeIntLittle(u16, &buf2, 0x5678);
1298 testing.expect(eql(u8, buf2[0..], &[_]u8{ 0x78, 0x56 }));1298 try testing.expect(eql(u8, buf2[0..], &[_]u8{ 0x78, 0x56 }));
12991299
1300 writeIntBig(u72, &buf9, 0x123456789abcdef024);1300 writeIntBig(u72, &buf9, 0x123456789abcdef024);
1301 testing.expect(eql(u8, buf9[0..], &[_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }));1301 try testing.expect(eql(u8, buf9[0..], &[_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }));
1302 writeIntLittle(u72, &buf9, 0xfedcba9876543210ec);1302 writeIntLittle(u72, &buf9, 0xfedcba9876543210ec);
1303 testing.expect(eql(u8, buf9[0..], &[_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }));1303 try testing.expect(eql(u8, buf9[0..], &[_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }));
13041304
1305 writeIntBig(i8, &buf1, -1);1305 writeIntBig(i8, &buf1, -1);
1306 testing.expect(eql(u8, buf1[0..], &[_]u8{0xff}));1306 try testing.expect(eql(u8, buf1[0..], &[_]u8{0xff}));
1307 writeIntLittle(i8, &buf1, -2);1307 writeIntLittle(i8, &buf1, -2);
1308 testing.expect(eql(u8, buf1[0..], &[_]u8{0xfe}));1308 try testing.expect(eql(u8, buf1[0..], &[_]u8{0xfe}));
13091309
1310 writeIntBig(i16, &buf2, -3);1310 writeIntBig(i16, &buf2, -3);
1311 testing.expect(eql(u8, buf2[0..], &[_]u8{ 0xff, 0xfd }));1311 try testing.expect(eql(u8, buf2[0..], &[_]u8{ 0xff, 0xfd }));
1312 writeIntLittle(i16, &buf2, -4);1312 writeIntLittle(i16, &buf2, -4);
1313 testing.expect(eql(u8, buf2[0..], &[_]u8{ 0xfc, 0xff }));1313 try testing.expect(eql(u8, buf2[0..], &[_]u8{ 0xfc, 0xff }));
1314}1314}
13151315
1316/// Returns an iterator that iterates over the slices of `buffer` that are not1316/// Returns an iterator that iterates over the slices of `buffer` that are not
...@@ -1331,60 +1331,60 @@ pub fn tokenize(buffer: []const u8, delimiter_bytes: []const u8) TokenIterator {...@@ -1331,60 +1331,60 @@ pub fn tokenize(buffer: []const u8, delimiter_bytes: []const u8) TokenIterator {
13311331
1332test "mem.tokenize" {1332test "mem.tokenize" {
1333 var it = tokenize(" abc def ghi ", " ");1333 var it = tokenize(" abc def ghi ", " ");
1334 testing.expect(eql(u8, it.next().?, "abc"));1334 try testing.expect(eql(u8, it.next().?, "abc"));
1335 testing.expect(eql(u8, it.next().?, "def"));1335 try testing.expect(eql(u8, it.next().?, "def"));
1336 testing.expect(eql(u8, it.next().?, "ghi"));1336 try testing.expect(eql(u8, it.next().?, "ghi"));
1337 testing.expect(it.next() == null);1337 try testing.expect(it.next() == null);
13381338
1339 it = tokenize("..\\bob", "\\");1339 it = tokenize("..\\bob", "\\");
1340 testing.expect(eql(u8, it.next().?, ".."));1340 try testing.expect(eql(u8, it.next().?, ".."));
1341 testing.expect(eql(u8, "..", "..\\bob"[0..it.index]));1341 try testing.expect(eql(u8, "..", "..\\bob"[0..it.index]));
1342 testing.expect(eql(u8, it.next().?, "bob"));1342 try testing.expect(eql(u8, it.next().?, "bob"));
1343 testing.expect(it.next() == null);1343 try testing.expect(it.next() == null);
13441344
1345 it = tokenize("//a/b", "/");1345 it = tokenize("//a/b", "/");
1346 testing.expect(eql(u8, it.next().?, "a"));1346 try testing.expect(eql(u8, it.next().?, "a"));
1347 testing.expect(eql(u8, it.next().?, "b"));1347 try testing.expect(eql(u8, it.next().?, "b"));
1348 testing.expect(eql(u8, "//a/b", "//a/b"[0..it.index]));1348 try testing.expect(eql(u8, "//a/b", "//a/b"[0..it.index]));
1349 testing.expect(it.next() == null);1349 try testing.expect(it.next() == null);
13501350
1351 it = tokenize("|", "|");1351 it = tokenize("|", "|");
1352 testing.expect(it.next() == null);1352 try testing.expect(it.next() == null);
13531353
1354 it = tokenize("", "|");1354 it = tokenize("", "|");
1355 testing.expect(it.next() == null);1355 try testing.expect(it.next() == null);
13561356
1357 it = tokenize("hello", "");1357 it = tokenize("hello", "");
1358 testing.expect(eql(u8, it.next().?, "hello"));1358 try testing.expect(eql(u8, it.next().?, "hello"));
1359 testing.expect(it.next() == null);1359 try testing.expect(it.next() == null);
13601360
1361 it = tokenize("hello", " ");1361 it = tokenize("hello", " ");
1362 testing.expect(eql(u8, it.next().?, "hello"));1362 try testing.expect(eql(u8, it.next().?, "hello"));
1363 testing.expect(it.next() == null);1363 try testing.expect(it.next() == null);
1364}1364}
13651365
1366test "mem.tokenize (multibyte)" {1366test "mem.tokenize (multibyte)" {
1367 var it = tokenize("a|b,c/d e", " /,|");1367 var it = tokenize("a|b,c/d e", " /,|");
1368 testing.expect(eql(u8, it.next().?, "a"));1368 try testing.expect(eql(u8, it.next().?, "a"));
1369 testing.expect(eql(u8, it.next().?, "b"));1369 try testing.expect(eql(u8, it.next().?, "b"));
1370 testing.expect(eql(u8, it.next().?, "c"));1370 try testing.expect(eql(u8, it.next().?, "c"));
1371 testing.expect(eql(u8, it.next().?, "d"));1371 try testing.expect(eql(u8, it.next().?, "d"));
1372 testing.expect(eql(u8, it.next().?, "e"));1372 try testing.expect(eql(u8, it.next().?, "e"));
1373 testing.expect(it.next() == null);1373 try testing.expect(it.next() == null);
1374}1374}
13751375
1376test "mem.tokenize (reset)" {1376test "mem.tokenize (reset)" {
1377 var it = tokenize(" abc def ghi ", " ");1377 var it = tokenize(" abc def ghi ", " ");
1378 testing.expect(eql(u8, it.next().?, "abc"));1378 try testing.expect(eql(u8, it.next().?, "abc"));
1379 testing.expect(eql(u8, it.next().?, "def"));1379 try testing.expect(eql(u8, it.next().?, "def"));
1380 testing.expect(eql(u8, it.next().?, "ghi"));1380 try testing.expect(eql(u8, it.next().?, "ghi"));
13811381
1382 it.reset();1382 it.reset();
13831383
1384 testing.expect(eql(u8, it.next().?, "abc"));1384 try testing.expect(eql(u8, it.next().?, "abc"));
1385 testing.expect(eql(u8, it.next().?, "def"));1385 try testing.expect(eql(u8, it.next().?, "def"));
1386 testing.expect(eql(u8, it.next().?, "ghi"));1386 try testing.expect(eql(u8, it.next().?, "ghi"));
1387 testing.expect(it.next() == null);1387 try testing.expect(it.next() == null);
1388}1388}
13891389
1390/// Returns an iterator that iterates over the slices of `buffer` that1390/// Returns an iterator that iterates over the slices of `buffer` that
...@@ -1408,34 +1408,34 @@ pub const separate = @compileError("deprecated: renamed to split (behavior remai...@@ -1408,34 +1408,34 @@ pub const separate = @compileError("deprecated: renamed to split (behavior remai
14081408
1409test "mem.split" {1409test "mem.split" {
1410 var it = split("abc|def||ghi", "|");1410 var it = split("abc|def||ghi", "|");
1411 testing.expect(eql(u8, it.next().?, "abc"));1411 try testing.expect(eql(u8, it.next().?, "abc"));
1412 testing.expect(eql(u8, it.next().?, "def"));1412 try testing.expect(eql(u8, it.next().?, "def"));
1413 testing.expect(eql(u8, it.next().?, ""));1413 try testing.expect(eql(u8, it.next().?, ""));
1414 testing.expect(eql(u8, it.next().?, "ghi"));1414 try testing.expect(eql(u8, it.next().?, "ghi"));
1415 testing.expect(it.next() == null);1415 try testing.expect(it.next() == null);
14161416
1417 it = split("", "|");1417 it = split("", "|");
1418 testing.expect(eql(u8, it.next().?, ""));1418 try testing.expect(eql(u8, it.next().?, ""));
1419 testing.expect(it.next() == null);1419 try testing.expect(it.next() == null);
14201420
1421 it = split("|", "|");1421 it = split("|", "|");
1422 testing.expect(eql(u8, it.next().?, ""));1422 try testing.expect(eql(u8, it.next().?, ""));
1423 testing.expect(eql(u8, it.next().?, ""));1423 try testing.expect(eql(u8, it.next().?, ""));
1424 testing.expect(it.next() == null);1424 try testing.expect(it.next() == null);
14251425
1426 it = split("hello", " ");1426 it = split("hello", " ");
1427 testing.expect(eql(u8, it.next().?, "hello"));1427 try testing.expect(eql(u8, it.next().?, "hello"));
1428 testing.expect(it.next() == null);1428 try testing.expect(it.next() == null);
1429}1429}
14301430
1431test "mem.split (multibyte)" {1431test "mem.split (multibyte)" {
1432 var it = split("a, b ,, c, d, e", ", ");1432 var it = split("a, b ,, c, d, e", ", ");
1433 testing.expect(eql(u8, it.next().?, "a"));1433 try testing.expect(eql(u8, it.next().?, "a"));
1434 testing.expect(eql(u8, it.next().?, "b ,"));1434 try testing.expect(eql(u8, it.next().?, "b ,"));
1435 testing.expect(eql(u8, it.next().?, "c"));1435 try testing.expect(eql(u8, it.next().?, "c"));
1436 testing.expect(eql(u8, it.next().?, "d"));1436 try testing.expect(eql(u8, it.next().?, "d"));
1437 testing.expect(eql(u8, it.next().?, "e"));1437 try testing.expect(eql(u8, it.next().?, "e"));
1438 testing.expect(it.next() == null);1438 try testing.expect(it.next() == null);
1439}1439}
14401440
1441pub fn startsWith(comptime T: type, haystack: []const T, needle: []const T) bool {1441pub fn startsWith(comptime T: type, haystack: []const T, needle: []const T) bool {
...@@ -1443,8 +1443,8 @@ pub fn startsWith(comptime T: type, haystack: []const T, needle: []const T) bool...@@ -1443,8 +1443,8 @@ pub fn startsWith(comptime T: type, haystack: []const T, needle: []const T) bool
1443}1443}
14441444
1445test "mem.startsWith" {1445test "mem.startsWith" {
1446 testing.expect(startsWith(u8, "Bob", "Bo"));1446 try testing.expect(startsWith(u8, "Bob", "Bo"));
1447 testing.expect(!startsWith(u8, "Needle in haystack", "haystack"));1447 try testing.expect(!startsWith(u8, "Needle in haystack", "haystack"));
1448}1448}
14491449
1450pub fn endsWith(comptime T: type, haystack: []const T, needle: []const T) bool {1450pub fn endsWith(comptime T: type, haystack: []const T, needle: []const T) bool {
...@@ -1452,8 +1452,8 @@ pub fn endsWith(comptime T: type, haystack: []const T, needle: []const T) bool {...@@ -1452,8 +1452,8 @@ pub fn endsWith(comptime T: type, haystack: []const T, needle: []const T) bool {
1452}1452}
14531453
1454test "mem.endsWith" {1454test "mem.endsWith" {
1455 testing.expect(endsWith(u8, "Needle in haystack", "haystack"));1455 try testing.expect(endsWith(u8, "Needle in haystack", "haystack"));
1456 testing.expect(!endsWith(u8, "Bob", "Bo"));1456 try testing.expect(!endsWith(u8, "Bob", "Bo"));
1457}1457}
14581458
1459pub const TokenIterator = struct {1459pub const TokenIterator = struct {
...@@ -1571,22 +1571,22 @@ test "mem.join" {...@@ -1571,22 +1571,22 @@ test "mem.join" {
1571 {1571 {
1572 const str = try join(testing.allocator, ",", &[_][]const u8{});1572 const str = try join(testing.allocator, ",", &[_][]const u8{});
1573 defer testing.allocator.free(str);1573 defer testing.allocator.free(str);
1574 testing.expect(eql(u8, str, ""));1574 try testing.expect(eql(u8, str, ""));
1575 }1575 }
1576 {1576 {
1577 const str = try join(testing.allocator, ",", &[_][]const u8{ "a", "b", "c" });1577 const str = try join(testing.allocator, ",", &[_][]const u8{ "a", "b", "c" });
1578 defer testing.allocator.free(str);1578 defer testing.allocator.free(str);
1579 testing.expect(eql(u8, str, "a,b,c"));1579 try testing.expect(eql(u8, str, "a,b,c"));
1580 }1580 }
1581 {1581 {
1582 const str = try join(testing.allocator, ",", &[_][]const u8{"a"});1582 const str = try join(testing.allocator, ",", &[_][]const u8{"a"});
1583 defer testing.allocator.free(str);1583 defer testing.allocator.free(str);
1584 testing.expect(eql(u8, str, "a"));1584 try testing.expect(eql(u8, str, "a"));
1585 }1585 }
1586 {1586 {
1587 const str = try join(testing.allocator, ",", &[_][]const u8{ "a", "", "b", "", "c" });1587 const str = try join(testing.allocator, ",", &[_][]const u8{ "a", "", "b", "", "c" });
1588 defer testing.allocator.free(str);1588 defer testing.allocator.free(str);
1589 testing.expect(eql(u8, str, "a,,b,,c"));1589 try testing.expect(eql(u8, str, "a,,b,,c"));
1590 }1590 }
1591}1591}
15921592
...@@ -1594,26 +1594,26 @@ test "mem.joinZ" {...@@ -1594,26 +1594,26 @@ test "mem.joinZ" {
1594 {1594 {
1595 const str = try joinZ(testing.allocator, ",", &[_][]const u8{});1595 const str = try joinZ(testing.allocator, ",", &[_][]const u8{});
1596 defer testing.allocator.free(str);1596 defer testing.allocator.free(str);
1597 testing.expect(eql(u8, str, ""));1597 try testing.expect(eql(u8, str, ""));
1598 testing.expectEqual(str[str.len], 0);1598 try testing.expectEqual(str[str.len], 0);
1599 }1599 }
1600 {1600 {
1601 const str = try joinZ(testing.allocator, ",", &[_][]const u8{ "a", "b", "c" });1601 const str = try joinZ(testing.allocator, ",", &[_][]const u8{ "a", "b", "c" });
1602 defer testing.allocator.free(str);1602 defer testing.allocator.free(str);
1603 testing.expect(eql(u8, str, "a,b,c"));1603 try testing.expect(eql(u8, str, "a,b,c"));
1604 testing.expectEqual(str[str.len], 0);1604 try testing.expectEqual(str[str.len], 0);
1605 }1605 }
1606 {1606 {
1607 const str = try joinZ(testing.allocator, ",", &[_][]const u8{"a"});1607 const str = try joinZ(testing.allocator, ",", &[_][]const u8{"a"});
1608 defer testing.allocator.free(str);1608 defer testing.allocator.free(str);
1609 testing.expect(eql(u8, str, "a"));1609 try testing.expect(eql(u8, str, "a"));
1610 testing.expectEqual(str[str.len], 0);1610 try testing.expectEqual(str[str.len], 0);
1611 }1611 }
1612 {1612 {
1613 const str = try joinZ(testing.allocator, ",", &[_][]const u8{ "a", "", "b", "", "c" });1613 const str = try joinZ(testing.allocator, ",", &[_][]const u8{ "a", "", "b", "", "c" });
1614 defer testing.allocator.free(str);1614 defer testing.allocator.free(str);
1615 testing.expect(eql(u8, str, "a,,b,,c"));1615 try testing.expect(eql(u8, str, "a,,b,,c"));
1616 testing.expectEqual(str[str.len], 0);1616 try testing.expectEqual(str[str.len], 0);
1617 }1617 }
1618}1618}
16191619
...@@ -1646,7 +1646,7 @@ test "concat" {...@@ -1646,7 +1646,7 @@ test "concat" {
1646 {1646 {
1647 const str = try concat(testing.allocator, u8, &[_][]const u8{ "abc", "def", "ghi" });1647 const str = try concat(testing.allocator, u8, &[_][]const u8{ "abc", "def", "ghi" });
1648 defer testing.allocator.free(str);1648 defer testing.allocator.free(str);
1649 testing.expect(eql(u8, str, "abcdefghi"));1649 try testing.expect(eql(u8, str, "abcdefghi"));
1650 }1650 }
1651 {1651 {
1652 const str = try concat(testing.allocator, u32, &[_][]const u32{1652 const str = try concat(testing.allocator, u32, &[_][]const u32{
...@@ -1656,21 +1656,21 @@ test "concat" {...@@ -1656,21 +1656,21 @@ test "concat" {
1656 &[_]u32{5},1656 &[_]u32{5},
1657 });1657 });
1658 defer testing.allocator.free(str);1658 defer testing.allocator.free(str);
1659 testing.expect(eql(u32, str, &[_]u32{ 0, 1, 2, 3, 4, 5 }));1659 try testing.expect(eql(u32, str, &[_]u32{ 0, 1, 2, 3, 4, 5 }));
1660 }1660 }
1661}1661}
16621662
1663test "testStringEquality" {1663test "testStringEquality" {
1664 testing.expect(eql(u8, "abcd", "abcd"));1664 try testing.expect(eql(u8, "abcd", "abcd"));
1665 testing.expect(!eql(u8, "abcdef", "abZdef"));1665 try testing.expect(!eql(u8, "abcdef", "abZdef"));
1666 testing.expect(!eql(u8, "abcdefg", "abcdef"));1666 try testing.expect(!eql(u8, "abcdefg", "abcdef"));
1667}1667}
16681668
1669test "testReadInt" {1669test "testReadInt" {
1670 testReadIntImpl();1670 try testReadIntImpl();
1671 comptime testReadIntImpl();1671 comptime try testReadIntImpl();
1672}1672}
1673fn testReadIntImpl() void {1673fn testReadIntImpl() !void {
1674 {1674 {
1675 const bytes = [_]u8{1675 const bytes = [_]u8{
1676 0x12,1676 0x12,
...@@ -1678,12 +1678,12 @@ fn testReadIntImpl() void {...@@ -1678,12 +1678,12 @@ fn testReadIntImpl() void {
1678 0x56,1678 0x56,
1679 0x78,1679 0x78,
1680 };1680 };
1681 testing.expect(readInt(u32, &bytes, builtin.Endian.Big) == 0x12345678);1681 try testing.expect(readInt(u32, &bytes, builtin.Endian.Big) == 0x12345678);
1682 testing.expect(readIntBig(u32, &bytes) == 0x12345678);1682 try testing.expect(readIntBig(u32, &bytes) == 0x12345678);
1683 testing.expect(readIntBig(i32, &bytes) == 0x12345678);1683 try testing.expect(readIntBig(i32, &bytes) == 0x12345678);
1684 testing.expect(readInt(u32, &bytes, builtin.Endian.Little) == 0x78563412);1684 try testing.expect(readInt(u32, &bytes, builtin.Endian.Little) == 0x78563412);
1685 testing.expect(readIntLittle(u32, &bytes) == 0x78563412);1685 try testing.expect(readIntLittle(u32, &bytes) == 0x78563412);
1686 testing.expect(readIntLittle(i32, &bytes) == 0x78563412);1686 try testing.expect(readIntLittle(i32, &bytes) == 0x78563412);
1687 }1687 }
1688 {1688 {
1689 const buf = [_]u8{1689 const buf = [_]u8{
...@@ -1693,7 +1693,7 @@ fn testReadIntImpl() void {...@@ -1693,7 +1693,7 @@ fn testReadIntImpl() void {
1693 0x34,1693 0x34,
1694 };1694 };
1695 const answer = readInt(u32, &buf, builtin.Endian.Big);1695 const answer = readInt(u32, &buf, builtin.Endian.Big);
1696 testing.expect(answer == 0x00001234);1696 try testing.expect(answer == 0x00001234);
1697 }1697 }
1698 {1698 {
1699 const buf = [_]u8{1699 const buf = [_]u8{
...@@ -1703,41 +1703,41 @@ fn testReadIntImpl() void {...@@ -1703,41 +1703,41 @@ fn testReadIntImpl() void {
1703 0x00,1703 0x00,
1704 };1704 };
1705 const answer = readInt(u32, &buf, builtin.Endian.Little);1705 const answer = readInt(u32, &buf, builtin.Endian.Little);
1706 testing.expect(answer == 0x00003412);1706 try testing.expect(answer == 0x00003412);
1707 }1707 }
1708 {1708 {
1709 const bytes = [_]u8{1709 const bytes = [_]u8{
1710 0xff,1710 0xff,
1711 0xfe,1711 0xfe,
1712 };1712 };
1713 testing.expect(readIntBig(u16, &bytes) == 0xfffe);1713 try testing.expect(readIntBig(u16, &bytes) == 0xfffe);
1714 testing.expect(readIntBig(i16, &bytes) == -0x0002);1714 try testing.expect(readIntBig(i16, &bytes) == -0x0002);
1715 testing.expect(readIntLittle(u16, &bytes) == 0xfeff);1715 try testing.expect(readIntLittle(u16, &bytes) == 0xfeff);
1716 testing.expect(readIntLittle(i16, &bytes) == -0x0101);1716 try testing.expect(readIntLittle(i16, &bytes) == -0x0101);
1717 }1717 }
1718}1718}
17191719
1720test "writeIntSlice" {1720test "writeIntSlice" {
1721 testWriteIntImpl();1721 try testWriteIntImpl();
1722 comptime testWriteIntImpl();1722 comptime try testWriteIntImpl();
1723}1723}
1724fn testWriteIntImpl() void {1724fn testWriteIntImpl() !void {
1725 var bytes: [8]u8 = undefined;1725 var bytes: [8]u8 = undefined;
17261726
1727 writeIntSlice(u0, bytes[0..], 0, builtin.Endian.Big);1727 writeIntSlice(u0, bytes[0..], 0, builtin.Endian.Big);
1728 testing.expect(eql(u8, &bytes, &[_]u8{1728 try testing.expect(eql(u8, &bytes, &[_]u8{
1729 0x00, 0x00, 0x00, 0x00,1729 0x00, 0x00, 0x00, 0x00,
1730 0x00, 0x00, 0x00, 0x00,1730 0x00, 0x00, 0x00, 0x00,
1731 }));1731 }));
17321732
1733 writeIntSlice(u0, bytes[0..], 0, builtin.Endian.Little);1733 writeIntSlice(u0, bytes[0..], 0, builtin.Endian.Little);
1734 testing.expect(eql(u8, &bytes, &[_]u8{1734 try testing.expect(eql(u8, &bytes, &[_]u8{
1735 0x00, 0x00, 0x00, 0x00,1735 0x00, 0x00, 0x00, 0x00,
1736 0x00, 0x00, 0x00, 0x00,1736 0x00, 0x00, 0x00, 0x00,
1737 }));1737 }));
17381738
1739 writeIntSlice(u64, bytes[0..], 0x12345678CAFEBABE, builtin.Endian.Big);1739 writeIntSlice(u64, bytes[0..], 0x12345678CAFEBABE, builtin.Endian.Big);
1740 testing.expect(eql(u8, &bytes, &[_]u8{1740 try testing.expect(eql(u8, &bytes, &[_]u8{
1741 0x12,1741 0x12,
1742 0x34,1742 0x34,
1743 0x56,1743 0x56,
...@@ -1749,7 +1749,7 @@ fn testWriteIntImpl() void {...@@ -1749,7 +1749,7 @@ fn testWriteIntImpl() void {
1749 }));1749 }));
17501750
1751 writeIntSlice(u64, bytes[0..], 0xBEBAFECA78563412, builtin.Endian.Little);1751 writeIntSlice(u64, bytes[0..], 0xBEBAFECA78563412, builtin.Endian.Little);
1752 testing.expect(eql(u8, &bytes, &[_]u8{1752 try testing.expect(eql(u8, &bytes, &[_]u8{
1753 0x12,1753 0x12,
1754 0x34,1754 0x34,
1755 0x56,1755 0x56,
...@@ -1761,7 +1761,7 @@ fn testWriteIntImpl() void {...@@ -1761,7 +1761,7 @@ fn testWriteIntImpl() void {
1761 }));1761 }));
17621762
1763 writeIntSlice(u32, bytes[0..], 0x12345678, builtin.Endian.Big);1763 writeIntSlice(u32, bytes[0..], 0x12345678, builtin.Endian.Big);
1764 testing.expect(eql(u8, &bytes, &[_]u8{1764 try testing.expect(eql(u8, &bytes, &[_]u8{
1765 0x00,1765 0x00,
1766 0x00,1766 0x00,
1767 0x00,1767 0x00,
...@@ -1773,7 +1773,7 @@ fn testWriteIntImpl() void {...@@ -1773,7 +1773,7 @@ fn testWriteIntImpl() void {
1773 }));1773 }));
17741774
1775 writeIntSlice(u32, bytes[0..], 0x78563412, builtin.Endian.Little);1775 writeIntSlice(u32, bytes[0..], 0x78563412, builtin.Endian.Little);
1776 testing.expect(eql(u8, &bytes, &[_]u8{1776 try testing.expect(eql(u8, &bytes, &[_]u8{
1777 0x12,1777 0x12,
1778 0x34,1778 0x34,
1779 0x56,1779 0x56,
...@@ -1785,7 +1785,7 @@ fn testWriteIntImpl() void {...@@ -1785,7 +1785,7 @@ fn testWriteIntImpl() void {
1785 }));1785 }));
17861786
1787 writeIntSlice(u16, bytes[0..], 0x1234, builtin.Endian.Big);1787 writeIntSlice(u16, bytes[0..], 0x1234, builtin.Endian.Big);
1788 testing.expect(eql(u8, &bytes, &[_]u8{1788 try testing.expect(eql(u8, &bytes, &[_]u8{
1789 0x00,1789 0x00,
1790 0x00,1790 0x00,
1791 0x00,1791 0x00,
...@@ -1797,7 +1797,7 @@ fn testWriteIntImpl() void {...@@ -1797,7 +1797,7 @@ fn testWriteIntImpl() void {
1797 }));1797 }));
17981798
1799 writeIntSlice(u16, bytes[0..], 0x1234, builtin.Endian.Little);1799 writeIntSlice(u16, bytes[0..], 0x1234, builtin.Endian.Little);
1800 testing.expect(eql(u8, &bytes, &[_]u8{1800 try testing.expect(eql(u8, &bytes, &[_]u8{
1801 0x34,1801 0x34,
1802 0x12,1802 0x12,
1803 0x00,1803 0x00,
...@@ -1820,7 +1820,7 @@ pub fn min(comptime T: type, slice: []const T) T {...@@ -1820,7 +1820,7 @@ pub fn min(comptime T: type, slice: []const T) T {
1820}1820}
18211821
1822test "mem.min" {1822test "mem.min" {
1823 testing.expect(min(u8, "abcdefg") == 'a');1823 try testing.expect(min(u8, "abcdefg") == 'a');
1824}1824}
18251825
1826/// Returns the largest number in a slice. O(n).1826/// Returns the largest number in a slice. O(n).
...@@ -1834,7 +1834,7 @@ pub fn max(comptime T: type, slice: []const T) T {...@@ -1834,7 +1834,7 @@ pub fn max(comptime T: type, slice: []const T) T {
1834}1834}
18351835
1836test "mem.max" {1836test "mem.max" {
1837 testing.expect(max(u8, "abcdefg") == 'g');1837 try testing.expect(max(u8, "abcdefg") == 'g');
1838}1838}
18391839
1840pub fn swap(comptime T: type, a: *T, b: *T) void {1840pub fn swap(comptime T: type, a: *T, b: *T) void {
...@@ -1856,7 +1856,7 @@ test "reverse" {...@@ -1856,7 +1856,7 @@ test "reverse" {
1856 var arr = [_]i32{ 5, 3, 1, 2, 4 };1856 var arr = [_]i32{ 5, 3, 1, 2, 4 };
1857 reverse(i32, arr[0..]);1857 reverse(i32, arr[0..]);
18581858
1859 testing.expect(eql(i32, &arr, &[_]i32{ 4, 2, 1, 3, 5 }));1859 try testing.expect(eql(i32, &arr, &[_]i32{ 4, 2, 1, 3, 5 }));
1860}1860}
18611861
1862/// In-place rotation of the values in an array ([0 1 2 3] becomes [1 2 3 0] if we rotate by 1)1862/// In-place rotation of the values in an array ([0 1 2 3] becomes [1 2 3 0] if we rotate by 1)
...@@ -1871,7 +1871,7 @@ test "rotate" {...@@ -1871,7 +1871,7 @@ test "rotate" {
1871 var arr = [_]i32{ 5, 3, 1, 2, 4 };1871 var arr = [_]i32{ 5, 3, 1, 2, 4 };
1872 rotate(i32, arr[0..], 2);1872 rotate(i32, arr[0..], 2);
18731873
1874 testing.expect(eql(i32, &arr, &[_]i32{ 1, 2, 4, 5, 3 }));1874 try testing.expect(eql(i32, &arr, &[_]i32{ 1, 2, 4, 5, 3 }));
1875}1875}
18761876
1877/// Replace needle with replacement as many times as possible, writing to an output buffer which is assumed to be of1877/// Replace needle with replacement as many times as possible, writing to an output buffer which is assumed to be of
...@@ -1904,31 +1904,31 @@ test "replace" {...@@ -1904,31 +1904,31 @@ test "replace" {
1904 var output: [29]u8 = undefined;1904 var output: [29]u8 = undefined;
1905 var replacements = replace(u8, "All your base are belong to us", "base", "Zig", output[0..]);1905 var replacements = replace(u8, "All your base are belong to us", "base", "Zig", output[0..]);
1906 var expected: []const u8 = "All your Zig are belong to us";1906 var expected: []const u8 = "All your Zig are belong to us";
1907 testing.expect(replacements == 1);1907 try testing.expect(replacements == 1);
1908 testing.expectEqualStrings(expected, output[0..expected.len]);1908 try testing.expectEqualStrings(expected, output[0..expected.len]);
19091909
1910 replacements = replace(u8, "Favor reading code over writing code.", "code", "", output[0..]);1910 replacements = replace(u8, "Favor reading code over writing code.", "code", "", output[0..]);
1911 expected = "Favor reading over writing .";1911 expected = "Favor reading over writing .";
1912 testing.expect(replacements == 2);1912 try testing.expect(replacements == 2);
1913 testing.expectEqualStrings(expected, output[0..expected.len]);1913 try testing.expectEqualStrings(expected, output[0..expected.len]);
19141914
1915 // Empty needle is not allowed but input may be empty.1915 // Empty needle is not allowed but input may be empty.
1916 replacements = replace(u8, "", "x", "y", output[0..0]);1916 replacements = replace(u8, "", "x", "y", output[0..0]);
1917 expected = "";1917 expected = "";
1918 testing.expect(replacements == 0);1918 try testing.expect(replacements == 0);
1919 testing.expectEqualStrings(expected, output[0..expected.len]);1919 try testing.expectEqualStrings(expected, output[0..expected.len]);
19201920
1921 // Adjacent replacements.1921 // Adjacent replacements.
19221922
1923 replacements = replace(u8, "\\n\\n", "\\n", "\n", output[0..]);1923 replacements = replace(u8, "\\n\\n", "\\n", "\n", output[0..]);
1924 expected = "\n\n";1924 expected = "\n\n";
1925 testing.expect(replacements == 2);1925 try testing.expect(replacements == 2);
1926 testing.expectEqualStrings(expected, output[0..expected.len]);1926 try testing.expectEqualStrings(expected, output[0..expected.len]);
19271927
1928 replacements = replace(u8, "abbba", "b", "cd", output[0..]);1928 replacements = replace(u8, "abbba", "b", "cd", output[0..]);
1929 expected = "acdcdcda";1929 expected = "acdcdcda";
1930 testing.expect(replacements == 3);1930 try testing.expect(replacements == 3);
1931 testing.expectEqualStrings(expected, output[0..expected.len]);1931 try testing.expectEqualStrings(expected, output[0..expected.len]);
1932}1932}
19331933
1934/// Calculate the size needed in an output buffer to perform a replacement.1934/// Calculate the size needed in an output buffer to perform a replacement.
...@@ -1952,16 +1952,16 @@ pub fn replacementSize(comptime T: type, input: []const T, needle: []const T, re...@@ -1952,16 +1952,16 @@ pub fn replacementSize(comptime T: type, input: []const T, needle: []const T, re
1952}1952}
19531953
1954test "replacementSize" {1954test "replacementSize" {
1955 testing.expect(replacementSize(u8, "All your base are belong to us", "base", "Zig") == 29);1955 try testing.expect(replacementSize(u8, "All your base are belong to us", "base", "Zig") == 29);
1956 testing.expect(replacementSize(u8, "Favor reading code over writing code.", "code", "") == 29);1956 try testing.expect(replacementSize(u8, "Favor reading code over writing code.", "code", "") == 29);
1957 testing.expect(replacementSize(u8, "Only one obvious way to do things.", "things.", "things in Zig.") == 41);1957 try testing.expect(replacementSize(u8, "Only one obvious way to do things.", "things.", "things in Zig.") == 41);
19581958
1959 // Empty needle is not allowed but input may be empty.1959 // Empty needle is not allowed but input may be empty.
1960 testing.expect(replacementSize(u8, "", "x", "y") == 0);1960 try testing.expect(replacementSize(u8, "", "x", "y") == 0);
19611961
1962 // Adjacent replacements.1962 // Adjacent replacements.
1963 testing.expect(replacementSize(u8, "\\n\\n", "\\n", "\n") == 2);1963 try testing.expect(replacementSize(u8, "\\n\\n", "\\n", "\n") == 2);
1964 testing.expect(replacementSize(u8, "abbba", "b", "cd") == 8);1964 try testing.expect(replacementSize(u8, "abbba", "b", "cd") == 8);
1965}1965}
19661966
1967/// Perform a replacement on an allocated buffer of pre-determined size. Caller must free returned memory.1967/// Perform a replacement on an allocated buffer of pre-determined size. Caller must free returned memory.
...@@ -1976,11 +1976,11 @@ test "replaceOwned" {...@@ -1976,11 +1976,11 @@ test "replaceOwned" {
19761976
1977 const base_replace = replaceOwned(u8, allocator, "All your base are belong to us", "base", "Zig") catch unreachable;1977 const base_replace = replaceOwned(u8, allocator, "All your base are belong to us", "base", "Zig") catch unreachable;
1978 defer allocator.free(base_replace);1978 defer allocator.free(base_replace);
1979 testing.expect(eql(u8, base_replace, "All your Zig are belong to us"));1979 try testing.expect(eql(u8, base_replace, "All your Zig are belong to us"));
19801980
1981 const zen_replace = replaceOwned(u8, allocator, "Favor reading code over writing code.", " code", "") catch unreachable;1981 const zen_replace = replaceOwned(u8, allocator, "Favor reading code over writing code.", " code", "") catch unreachable;
1982 defer allocator.free(zen_replace);1982 defer allocator.free(zen_replace);
1983 testing.expect(eql(u8, zen_replace, "Favor reading over writing."));1983 try testing.expect(eql(u8, zen_replace, "Favor reading over writing."));
1984}1984}
19851985
1986/// Converts a little-endian integer to host endianness.1986/// Converts a little-endian integer to host endianness.
...@@ -2068,12 +2068,12 @@ test "asBytes" {...@@ -2068,12 +2068,12 @@ test "asBytes" {
2068 .Little => "\xEF\xBE\xAD\xDE",2068 .Little => "\xEF\xBE\xAD\xDE",
2069 };2069 };
20702070
2071 testing.expect(eql(u8, asBytes(&deadbeef), deadbeef_bytes));2071 try testing.expect(eql(u8, asBytes(&deadbeef), deadbeef_bytes));
20722072
2073 var codeface = @as(u32, 0xC0DEFACE);2073 var codeface = @as(u32, 0xC0DEFACE);
2074 for (asBytes(&codeface).*) |*b|2074 for (asBytes(&codeface).*) |*b|
2075 b.* = 0;2075 b.* = 0;
2076 testing.expect(codeface == 0);2076 try testing.expect(codeface == 0);
20772077
2078 const S = packed struct {2078 const S = packed struct {
2079 a: u8,2079 a: u8,
...@@ -2088,11 +2088,11 @@ test "asBytes" {...@@ -2088,11 +2088,11 @@ test "asBytes" {
2088 .c = 0xDE,2088 .c = 0xDE,
2089 .d = 0xA1,2089 .d = 0xA1,
2090 };2090 };
2091 testing.expect(eql(u8, asBytes(&inst), "\xBE\xEF\xDE\xA1"));2091 try testing.expect(eql(u8, asBytes(&inst), "\xBE\xEF\xDE\xA1"));
20922092
2093 const ZST = struct {};2093 const ZST = struct {};
2094 const zero = ZST{};2094 const zero = ZST{};
2095 testing.expect(eql(u8, asBytes(&zero), ""));2095 try testing.expect(eql(u8, asBytes(&zero), ""));
2096}2096}
20972097
2098test "asBytes preserves pointer attributes" {2098test "asBytes preserves pointer attributes" {
...@@ -2103,10 +2103,10 @@ test "asBytes preserves pointer attributes" {...@@ -2103,10 +2103,10 @@ test "asBytes preserves pointer attributes" {
2103 const in = @typeInfo(@TypeOf(inPtr)).Pointer;2103 const in = @typeInfo(@TypeOf(inPtr)).Pointer;
2104 const out = @typeInfo(@TypeOf(outSlice)).Pointer;2104 const out = @typeInfo(@TypeOf(outSlice)).Pointer;
21052105
2106 testing.expectEqual(in.is_const, out.is_const);2106 try testing.expectEqual(in.is_const, out.is_const);
2107 testing.expectEqual(in.is_volatile, out.is_volatile);2107 try testing.expectEqual(in.is_volatile, out.is_volatile);
2108 testing.expectEqual(in.is_allowzero, out.is_allowzero);2108 try testing.expectEqual(in.is_allowzero, out.is_allowzero);
2109 testing.expectEqual(in.alignment, out.alignment);2109 try testing.expectEqual(in.alignment, out.alignment);
2110}2110}
21112111
2112/// Given any value, returns a copy of its bytes in an array.2112/// Given any value, returns a copy of its bytes in an array.
...@@ -2117,14 +2117,14 @@ pub fn toBytes(value: anytype) [@sizeOf(@TypeOf(value))]u8 {...@@ -2117,14 +2117,14 @@ pub fn toBytes(value: anytype) [@sizeOf(@TypeOf(value))]u8 {
2117test "toBytes" {2117test "toBytes" {
2118 var my_bytes = toBytes(@as(u32, 0x12345678));2118 var my_bytes = toBytes(@as(u32, 0x12345678));
2119 switch (builtin.endian) {2119 switch (builtin.endian) {
2120 .Big => testing.expect(eql(u8, &my_bytes, "\x12\x34\x56\x78")),2120 .Big => try testing.expect(eql(u8, &my_bytes, "\x12\x34\x56\x78")),
2121 .Little => testing.expect(eql(u8, &my_bytes, "\x78\x56\x34\x12")),2121 .Little => try testing.expect(eql(u8, &my_bytes, "\x78\x56\x34\x12")),
2122 }2122 }
21232123
2124 my_bytes[0] = '\x99';2124 my_bytes[0] = '\x99';
2125 switch (builtin.endian) {2125 switch (builtin.endian) {
2126 .Big => testing.expect(eql(u8, &my_bytes, "\x99\x34\x56\x78")),2126 .Big => try testing.expect(eql(u8, &my_bytes, "\x99\x34\x56\x78")),
2127 .Little => testing.expect(eql(u8, &my_bytes, "\x99\x56\x34\x12")),2127 .Little => try testing.expect(eql(u8, &my_bytes, "\x99\x56\x34\x12")),
2128 }2128 }
2129}2129}
21302130
...@@ -2154,17 +2154,17 @@ test "bytesAsValue" {...@@ -2154,17 +2154,17 @@ test "bytesAsValue" {
2154 .Little => "\xEF\xBE\xAD\xDE",2154 .Little => "\xEF\xBE\xAD\xDE",
2155 };2155 };
21562156
2157 testing.expect(deadbeef == bytesAsValue(u32, deadbeef_bytes).*);2157 try testing.expect(deadbeef == bytesAsValue(u32, deadbeef_bytes).*);
21582158
2159 var codeface_bytes: [4]u8 = switch (builtin.endian) {2159 var codeface_bytes: [4]u8 = switch (builtin.endian) {
2160 .Big => "\xC0\xDE\xFA\xCE",2160 .Big => "\xC0\xDE\xFA\xCE",
2161 .Little => "\xCE\xFA\xDE\xC0",2161 .Little => "\xCE\xFA\xDE\xC0",
2162 }.*;2162 }.*;
2163 var codeface = bytesAsValue(u32, &codeface_bytes);2163 var codeface = bytesAsValue(u32, &codeface_bytes);
2164 testing.expect(codeface.* == 0xC0DEFACE);2164 try testing.expect(codeface.* == 0xC0DEFACE);
2165 codeface.* = 0;2165 codeface.* = 0;
2166 for (codeface_bytes) |b|2166 for (codeface_bytes) |b|
2167 testing.expect(b == 0);2167 try testing.expect(b == 0);
21682168
2169 const S = packed struct {2169 const S = packed struct {
2170 a: u8,2170 a: u8,
...@@ -2181,7 +2181,7 @@ test "bytesAsValue" {...@@ -2181,7 +2181,7 @@ test "bytesAsValue" {
2181 };2181 };
2182 const inst_bytes = "\xBE\xEF\xDE\xA1";2182 const inst_bytes = "\xBE\xEF\xDE\xA1";
2183 const inst2 = bytesAsValue(S, inst_bytes);2183 const inst2 = bytesAsValue(S, inst_bytes);
2184 testing.expect(meta.eql(inst, inst2.*));2184 try testing.expect(meta.eql(inst, inst2.*));
2185}2185}
21862186
2187test "bytesAsValue preserves pointer attributes" {2187test "bytesAsValue preserves pointer attributes" {
...@@ -2192,10 +2192,10 @@ test "bytesAsValue preserves pointer attributes" {...@@ -2192,10 +2192,10 @@ test "bytesAsValue preserves pointer attributes" {
2192 const in = @typeInfo(@TypeOf(inSlice)).Pointer;2192 const in = @typeInfo(@TypeOf(inSlice)).Pointer;
2193 const out = @typeInfo(@TypeOf(outPtr)).Pointer;2193 const out = @typeInfo(@TypeOf(outPtr)).Pointer;
21942194
2195 testing.expectEqual(in.is_const, out.is_const);2195 try testing.expectEqual(in.is_const, out.is_const);
2196 testing.expectEqual(in.is_volatile, out.is_volatile);2196 try testing.expectEqual(in.is_volatile, out.is_volatile);
2197 testing.expectEqual(in.is_allowzero, out.is_allowzero);2197 try testing.expectEqual(in.is_allowzero, out.is_allowzero);
2198 testing.expectEqual(in.alignment, out.alignment);2198 try testing.expectEqual(in.alignment, out.alignment);
2199}2199}
22002200
2201/// Given a pointer to an array of bytes, returns a value of the specified type backed by a2201/// Given a pointer to an array of bytes, returns a value of the specified type backed by a
...@@ -2210,7 +2210,7 @@ test "bytesToValue" {...@@ -2210,7 +2210,7 @@ test "bytesToValue" {
2210 };2210 };
22112211
2212 const deadbeef = bytesToValue(u32, deadbeef_bytes);2212 const deadbeef = bytesToValue(u32, deadbeef_bytes);
2213 testing.expect(deadbeef == @as(u32, 0xDEADBEEF));2213 try testing.expect(deadbeef == @as(u32, 0xDEADBEEF));
2214}2214}
22152215
2216fn BytesAsSliceReturnType(comptime T: type, comptime bytesType: type) type {2216fn BytesAsSliceReturnType(comptime T: type, comptime bytesType: type) type {
...@@ -2243,17 +2243,17 @@ test "bytesAsSlice" {...@@ -2243,17 +2243,17 @@ test "bytesAsSlice" {
2243 {2243 {
2244 const bytes = [_]u8{ 0xDE, 0xAD, 0xBE, 0xEF };2244 const bytes = [_]u8{ 0xDE, 0xAD, 0xBE, 0xEF };
2245 const slice = bytesAsSlice(u16, bytes[0..]);2245 const slice = bytesAsSlice(u16, bytes[0..]);
2246 testing.expect(slice.len == 2);2246 try testing.expect(slice.len == 2);
2247 testing.expect(bigToNative(u16, slice[0]) == 0xDEAD);2247 try testing.expect(bigToNative(u16, slice[0]) == 0xDEAD);
2248 testing.expect(bigToNative(u16, slice[1]) == 0xBEEF);2248 try testing.expect(bigToNative(u16, slice[1]) == 0xBEEF);
2249 }2249 }
2250 {2250 {
2251 const bytes = [_]u8{ 0xDE, 0xAD, 0xBE, 0xEF };2251 const bytes = [_]u8{ 0xDE, 0xAD, 0xBE, 0xEF };
2252 var runtime_zero: usize = 0;2252 var runtime_zero: usize = 0;
2253 const slice = bytesAsSlice(u16, bytes[runtime_zero..]);2253 const slice = bytesAsSlice(u16, bytes[runtime_zero..]);
2254 testing.expect(slice.len == 2);2254 try testing.expect(slice.len == 2);
2255 testing.expect(bigToNative(u16, slice[0]) == 0xDEAD);2255 try testing.expect(bigToNative(u16, slice[0]) == 0xDEAD);
2256 testing.expect(bigToNative(u16, slice[1]) == 0xBEEF);2256 try testing.expect(bigToNative(u16, slice[1]) == 0xBEEF);
2257 }2257 }
2258}2258}
22592259
...@@ -2261,13 +2261,13 @@ test "bytesAsSlice keeps pointer alignment" {...@@ -2261,13 +2261,13 @@ test "bytesAsSlice keeps pointer alignment" {
2261 {2261 {
2262 var bytes = [_]u8{ 0x01, 0x02, 0x03, 0x04 };2262 var bytes = [_]u8{ 0x01, 0x02, 0x03, 0x04 };
2263 const numbers = bytesAsSlice(u32, bytes[0..]);2263 const numbers = bytesAsSlice(u32, bytes[0..]);
2264 comptime testing.expect(@TypeOf(numbers) == []align(@alignOf(@TypeOf(bytes))) u32);2264 comptime try testing.expect(@TypeOf(numbers) == []align(@alignOf(@TypeOf(bytes))) u32);
2265 }2265 }
2266 {2266 {
2267 var bytes = [_]u8{ 0x01, 0x02, 0x03, 0x04 };2267 var bytes = [_]u8{ 0x01, 0x02, 0x03, 0x04 };
2268 var runtime_zero: usize = 0;2268 var runtime_zero: usize = 0;
2269 const numbers = bytesAsSlice(u32, bytes[runtime_zero..]);2269 const numbers = bytesAsSlice(u32, bytes[runtime_zero..]);
2270 comptime testing.expect(@TypeOf(numbers) == []align(@alignOf(@TypeOf(bytes))) u32);2270 comptime try testing.expect(@TypeOf(numbers) == []align(@alignOf(@TypeOf(bytes))) u32);
2271 }2271 }
2272}2272}
22732273
...@@ -2278,7 +2278,7 @@ test "bytesAsSlice on a packed struct" {...@@ -2278,7 +2278,7 @@ test "bytesAsSlice on a packed struct" {
22782278
2279 var b = [1]u8{9};2279 var b = [1]u8{9};
2280 var f = bytesAsSlice(F, &b);2280 var f = bytesAsSlice(F, &b);
2281 testing.expect(f[0].a == 9);2281 try testing.expect(f[0].a == 9);
2282}2282}
22832283
2284test "bytesAsSlice with specified alignment" {2284test "bytesAsSlice with specified alignment" {
...@@ -2289,7 +2289,7 @@ test "bytesAsSlice with specified alignment" {...@@ -2289,7 +2289,7 @@ test "bytesAsSlice with specified alignment" {
2289 0x33,2289 0x33,
2290 };2290 };
2291 const slice: []u32 = std.mem.bytesAsSlice(u32, bytes[0..]);2291 const slice: []u32 = std.mem.bytesAsSlice(u32, bytes[0..]);
2292 testing.expect(slice[0] == 0x33333333);2292 try testing.expect(slice[0] == 0x33333333);
2293}2293}
22942294
2295test "bytesAsSlice preserves pointer attributes" {2295test "bytesAsSlice preserves pointer attributes" {
...@@ -2300,10 +2300,10 @@ test "bytesAsSlice preserves pointer attributes" {...@@ -2300,10 +2300,10 @@ test "bytesAsSlice preserves pointer attributes" {
2300 const in = @typeInfo(@TypeOf(inSlice)).Pointer;2300 const in = @typeInfo(@TypeOf(inSlice)).Pointer;
2301 const out = @typeInfo(@TypeOf(outSlice)).Pointer;2301 const out = @typeInfo(@TypeOf(outSlice)).Pointer;
23022302
2303 testing.expectEqual(in.is_const, out.is_const);2303 try testing.expectEqual(in.is_const, out.is_const);
2304 testing.expectEqual(in.is_volatile, out.is_volatile);2304 try testing.expectEqual(in.is_volatile, out.is_volatile);
2305 testing.expectEqual(in.is_allowzero, out.is_allowzero);2305 try testing.expectEqual(in.is_allowzero, out.is_allowzero);
2306 testing.expectEqual(in.alignment, out.alignment);2306 try testing.expectEqual(in.alignment, out.alignment);
2307}2307}
23082308
2309fn SliceAsBytesReturnType(comptime sliceType: type) type {2309fn SliceAsBytesReturnType(comptime sliceType: type) type {
...@@ -2332,8 +2332,8 @@ pub fn sliceAsBytes(slice: anytype) SliceAsBytesReturnType(@TypeOf(slice)) {...@@ -2332,8 +2332,8 @@ pub fn sliceAsBytes(slice: anytype) SliceAsBytesReturnType(@TypeOf(slice)) {
2332test "sliceAsBytes" {2332test "sliceAsBytes" {
2333 const bytes = [_]u16{ 0xDEAD, 0xBEEF };2333 const bytes = [_]u16{ 0xDEAD, 0xBEEF };
2334 const slice = sliceAsBytes(bytes[0..]);2334 const slice = sliceAsBytes(bytes[0..]);
2335 testing.expect(slice.len == 4);2335 try testing.expect(slice.len == 4);
2336 testing.expect(eql(u8, slice, switch (builtin.endian) {2336 try testing.expect(eql(u8, slice, switch (builtin.endian) {
2337 .Big => "\xDE\xAD\xBE\xEF",2337 .Big => "\xDE\xAD\xBE\xEF",
2338 .Little => "\xAD\xDE\xEF\xBE",2338 .Little => "\xAD\xDE\xEF\xBE",
2339 }));2339 }));
...@@ -2342,7 +2342,7 @@ test "sliceAsBytes" {...@@ -2342,7 +2342,7 @@ test "sliceAsBytes" {
2342test "sliceAsBytes with sentinel slice" {2342test "sliceAsBytes with sentinel slice" {
2343 const empty_string: [:0]const u8 = "";2343 const empty_string: [:0]const u8 = "";
2344 const bytes = sliceAsBytes(empty_string);2344 const bytes = sliceAsBytes(empty_string);
2345 testing.expect(bytes.len == 0);2345 try testing.expect(bytes.len == 0);
2346}2346}
23472347
2348test "sliceAsBytes packed struct at runtime and comptime" {2348test "sliceAsBytes packed struct at runtime and comptime" {
...@@ -2351,49 +2351,49 @@ test "sliceAsBytes packed struct at runtime and comptime" {...@@ -2351,49 +2351,49 @@ test "sliceAsBytes packed struct at runtime and comptime" {
2351 b: u4,2351 b: u4,
2352 };2352 };
2353 const S = struct {2353 const S = struct {
2354 fn doTheTest() void {2354 fn doTheTest() !void {
2355 var foo: Foo = undefined;2355 var foo: Foo = undefined;
2356 var slice = sliceAsBytes(@as(*[1]Foo, &foo)[0..1]);2356 var slice = sliceAsBytes(@as(*[1]Foo, &foo)[0..1]);
2357 slice[0] = 0x13;2357 slice[0] = 0x13;
2358 switch (builtin.endian) {2358 switch (builtin.endian) {
2359 .Big => {2359 .Big => {
2360 testing.expect(foo.a == 0x1);2360 try testing.expect(foo.a == 0x1);
2361 testing.expect(foo.b == 0x3);2361 try testing.expect(foo.b == 0x3);
2362 },2362 },
2363 .Little => {2363 .Little => {
2364 testing.expect(foo.a == 0x3);2364 try testing.expect(foo.a == 0x3);
2365 testing.expect(foo.b == 0x1);2365 try testing.expect(foo.b == 0x1);
2366 },2366 },
2367 }2367 }
2368 }2368 }
2369 };2369 };
2370 S.doTheTest();2370 try S.doTheTest();
2371 comptime S.doTheTest();2371 comptime try S.doTheTest();
2372}2372}
23732373
2374test "sliceAsBytes and bytesAsSlice back" {2374test "sliceAsBytes and bytesAsSlice back" {
2375 testing.expect(@sizeOf(i32) == 4);2375 try testing.expect(@sizeOf(i32) == 4);
23762376
2377 var big_thing_array = [_]i32{ 1, 2, 3, 4 };2377 var big_thing_array = [_]i32{ 1, 2, 3, 4 };
2378 const big_thing_slice: []i32 = big_thing_array[0..];2378 const big_thing_slice: []i32 = big_thing_array[0..];
23792379
2380 const bytes = sliceAsBytes(big_thing_slice);2380 const bytes = sliceAsBytes(big_thing_slice);
2381 testing.expect(bytes.len == 4 * 4);2381 try testing.expect(bytes.len == 4 * 4);
23822382
2383 bytes[4] = 0;2383 bytes[4] = 0;
2384 bytes[5] = 0;2384 bytes[5] = 0;
2385 bytes[6] = 0;2385 bytes[6] = 0;
2386 bytes[7] = 0;2386 bytes[7] = 0;
2387 testing.expect(big_thing_slice[1] == 0);2387 try testing.expect(big_thing_slice[1] == 0);
23882388
2389 const big_thing_again = bytesAsSlice(i32, bytes);2389 const big_thing_again = bytesAsSlice(i32, bytes);
2390 testing.expect(big_thing_again[2] == 3);2390 try testing.expect(big_thing_again[2] == 3);
23912391
2392 big_thing_again[2] = -1;2392 big_thing_again[2] = -1;
2393 testing.expect(bytes[8] == math.maxInt(u8));2393 try testing.expect(bytes[8] == math.maxInt(u8));
2394 testing.expect(bytes[9] == math.maxInt(u8));2394 try testing.expect(bytes[9] == math.maxInt(u8));
2395 testing.expect(bytes[10] == math.maxInt(u8));2395 try testing.expect(bytes[10] == math.maxInt(u8));
2396 testing.expect(bytes[11] == math.maxInt(u8));2396 try testing.expect(bytes[11] == math.maxInt(u8));
2397}2397}
23982398
2399test "sliceAsBytes preserves pointer attributes" {2399test "sliceAsBytes preserves pointer attributes" {
...@@ -2404,10 +2404,10 @@ test "sliceAsBytes preserves pointer attributes" {...@@ -2404,10 +2404,10 @@ test "sliceAsBytes preserves pointer attributes" {
2404 const in = @typeInfo(@TypeOf(inSlice)).Pointer;2404 const in = @typeInfo(@TypeOf(inSlice)).Pointer;
2405 const out = @typeInfo(@TypeOf(outSlice)).Pointer;2405 const out = @typeInfo(@TypeOf(outSlice)).Pointer;
24062406
2407 testing.expectEqual(in.is_const, out.is_const);2407 try testing.expectEqual(in.is_const, out.is_const);
2408 testing.expectEqual(in.is_volatile, out.is_volatile);2408 try testing.expectEqual(in.is_volatile, out.is_volatile);
2409 testing.expectEqual(in.is_allowzero, out.is_allowzero);2409 try testing.expectEqual(in.is_allowzero, out.is_allowzero);
2410 testing.expectEqual(in.alignment, out.alignment);2410 try testing.expectEqual(in.alignment, out.alignment);
2411}2411}
24122412
2413/// Round an address up to the nearest aligned address2413/// Round an address up to the nearest aligned address
...@@ -2434,18 +2434,18 @@ pub fn doNotOptimizeAway(val: anytype) void {...@@ -2434,18 +2434,18 @@ pub fn doNotOptimizeAway(val: anytype) void {
2434}2434}
24352435
2436test "alignForward" {2436test "alignForward" {
2437 testing.expect(alignForward(1, 1) == 1);2437 try testing.expect(alignForward(1, 1) == 1);
2438 testing.expect(alignForward(2, 1) == 2);2438 try testing.expect(alignForward(2, 1) == 2);
2439 testing.expect(alignForward(1, 2) == 2);2439 try testing.expect(alignForward(1, 2) == 2);
2440 testing.expect(alignForward(2, 2) == 2);2440 try testing.expect(alignForward(2, 2) == 2);
2441 testing.expect(alignForward(3, 2) == 4);2441 try testing.expect(alignForward(3, 2) == 4);
2442 testing.expect(alignForward(4, 2) == 4);2442 try testing.expect(alignForward(4, 2) == 4);
2443 testing.expect(alignForward(7, 8) == 8);2443 try testing.expect(alignForward(7, 8) == 8);
2444 testing.expect(alignForward(8, 8) == 8);2444 try testing.expect(alignForward(8, 8) == 8);
2445 testing.expect(alignForward(9, 8) == 16);2445 try testing.expect(alignForward(9, 8) == 16);
2446 testing.expect(alignForward(15, 8) == 16);2446 try testing.expect(alignForward(15, 8) == 16);
2447 testing.expect(alignForward(16, 8) == 16);2447 try testing.expect(alignForward(16, 8) == 16);
2448 testing.expect(alignForward(17, 8) == 24);2448 try testing.expect(alignForward(17, 8) == 24);
2449}2449}
24502450
2451/// Round an address up to the previous aligned address2451/// Round an address up to the previous aligned address
...@@ -2497,19 +2497,19 @@ pub fn isAlignedGeneric(comptime T: type, addr: T, alignment: T) bool {...@@ -2497,19 +2497,19 @@ pub fn isAlignedGeneric(comptime T: type, addr: T, alignment: T) bool {
2497}2497}
24982498
2499test "isAligned" {2499test "isAligned" {
2500 testing.expect(isAligned(0, 4));2500 try testing.expect(isAligned(0, 4));
2501 testing.expect(isAligned(1, 1));2501 try testing.expect(isAligned(1, 1));
2502 testing.expect(isAligned(2, 1));2502 try testing.expect(isAligned(2, 1));
2503 testing.expect(isAligned(2, 2));2503 try testing.expect(isAligned(2, 2));
2504 testing.expect(!isAligned(2, 4));2504 try testing.expect(!isAligned(2, 4));
2505 testing.expect(isAligned(3, 1));2505 try testing.expect(isAligned(3, 1));
2506 testing.expect(!isAligned(3, 2));2506 try testing.expect(!isAligned(3, 2));
2507 testing.expect(!isAligned(3, 4));2507 try testing.expect(!isAligned(3, 4));
2508 testing.expect(isAligned(4, 4));2508 try testing.expect(isAligned(4, 4));
2509 testing.expect(isAligned(4, 2));2509 try testing.expect(isAligned(4, 2));
2510 testing.expect(isAligned(4, 1));2510 try testing.expect(isAligned(4, 1));
2511 testing.expect(!isAligned(4, 8));2511 try testing.expect(!isAligned(4, 8));
2512 testing.expect(!isAligned(4, 16));2512 try testing.expect(!isAligned(4, 16));
2513}2513}
25142514
2515test "freeing empty string with null-terminated sentinel" {2515test "freeing empty string with null-terminated sentinel" {
lib/std/meta.zig+190-190
...@@ -47,16 +47,16 @@ test "std.meta.tagName" {...@@ -47,16 +47,16 @@ test "std.meta.tagName" {
47 var u2a = U2{ .C = 0 };47 var u2a = U2{ .C = 0 };
48 var u2b = U2{ .D = 0 };48 var u2b = U2{ .D = 0 };
4949
50 testing.expect(mem.eql(u8, tagName(E1.A), "A"));50 try testing.expect(mem.eql(u8, tagName(E1.A), "A"));
51 testing.expect(mem.eql(u8, tagName(E1.B), "B"));51 try testing.expect(mem.eql(u8, tagName(E1.B), "B"));
52 testing.expect(mem.eql(u8, tagName(E2.C), "C"));52 try testing.expect(mem.eql(u8, tagName(E2.C), "C"));
53 testing.expect(mem.eql(u8, tagName(E2.D), "D"));53 try testing.expect(mem.eql(u8, tagName(E2.D), "D"));
54 testing.expect(mem.eql(u8, tagName(error.E), "E"));54 try testing.expect(mem.eql(u8, tagName(error.E), "E"));
55 testing.expect(mem.eql(u8, tagName(error.F), "F"));55 try testing.expect(mem.eql(u8, tagName(error.F), "F"));
56 testing.expect(mem.eql(u8, tagName(u1g), "G"));56 try testing.expect(mem.eql(u8, tagName(u1g), "G"));
57 testing.expect(mem.eql(u8, tagName(u1h), "H"));57 try testing.expect(mem.eql(u8, tagName(u1h), "H"));
58 testing.expect(mem.eql(u8, tagName(u2a), "C"));58 try testing.expect(mem.eql(u8, tagName(u2a), "C"));
59 testing.expect(mem.eql(u8, tagName(u2b), "D"));59 try testing.expect(mem.eql(u8, tagName(u2b), "D"));
60}60}
6161
62pub fn stringToEnum(comptime T: type, str: []const u8) ?T {62pub fn stringToEnum(comptime T: type, str: []const u8) ?T {
...@@ -98,9 +98,9 @@ test "std.meta.stringToEnum" {...@@ -98,9 +98,9 @@ test "std.meta.stringToEnum" {
98 A,98 A,
99 B,99 B,
100 };100 };
101 testing.expect(E1.A == stringToEnum(E1, "A").?);101 try testing.expect(E1.A == stringToEnum(E1, "A").?);
102 testing.expect(E1.B == stringToEnum(E1, "B").?);102 try testing.expect(E1.B == stringToEnum(E1, "B").?);
103 testing.expect(null == stringToEnum(E1, "C"));103 try testing.expect(null == stringToEnum(E1, "C"));
104}104}
105105
106pub fn bitCount(comptime T: type) comptime_int {106pub fn bitCount(comptime T: type) comptime_int {
...@@ -113,8 +113,8 @@ pub fn bitCount(comptime T: type) comptime_int {...@@ -113,8 +113,8 @@ pub fn bitCount(comptime T: type) comptime_int {
113}113}
114114
115test "std.meta.bitCount" {115test "std.meta.bitCount" {
116 testing.expect(bitCount(u8) == 8);116 try testing.expect(bitCount(u8) == 8);
117 testing.expect(bitCount(f32) == 32);117 try testing.expect(bitCount(f32) == 32);
118}118}
119119
120/// Returns the alignment of type T.120/// Returns the alignment of type T.
...@@ -135,13 +135,13 @@ pub fn alignment(comptime T: type) comptime_int {...@@ -135,13 +135,13 @@ pub fn alignment(comptime T: type) comptime_int {
135}135}
136136
137test "std.meta.alignment" {137test "std.meta.alignment" {
138 testing.expect(alignment(u8) == 1);138 try testing.expect(alignment(u8) == 1);
139 testing.expect(alignment(*align(1) u8) == 1);139 try testing.expect(alignment(*align(1) u8) == 1);
140 testing.expect(alignment(*align(2) u8) == 2);140 try testing.expect(alignment(*align(2) u8) == 2);
141 testing.expect(alignment([]align(1) u8) == 1);141 try testing.expect(alignment([]align(1) u8) == 1);
142 testing.expect(alignment([]align(2) u8) == 2);142 try testing.expect(alignment([]align(2) u8) == 2);
143 testing.expect(alignment(fn () void) > 0);143 try testing.expect(alignment(fn () void) > 0);
144 testing.expect(alignment(fn () align(128) void) == 128);144 try testing.expect(alignment(fn () align(128) void) == 128);
145}145}
146146
147pub fn Child(comptime T: type) type {147pub fn Child(comptime T: type) type {
...@@ -155,11 +155,11 @@ pub fn Child(comptime T: type) type {...@@ -155,11 +155,11 @@ pub fn Child(comptime T: type) type {
155}155}
156156
157test "std.meta.Child" {157test "std.meta.Child" {
158 testing.expect(Child([1]u8) == u8);158 try testing.expect(Child([1]u8) == u8);
159 testing.expect(Child(*u8) == u8);159 try testing.expect(Child(*u8) == u8);
160 testing.expect(Child([]u8) == u8);160 try testing.expect(Child([]u8) == u8);
161 testing.expect(Child(?u8) == u8);161 try testing.expect(Child(?u8) == u8);
162 testing.expect(Child(Vector(2, u8)) == u8);162 try testing.expect(Child(Vector(2, u8)) == u8);
163}163}
164164
165/// Given a "memory span" type, returns the "element type".165/// Given a "memory span" type, returns the "element type".
...@@ -188,13 +188,13 @@ pub fn Elem(comptime T: type) type {...@@ -188,13 +188,13 @@ pub fn Elem(comptime T: type) type {
188}188}
189189
190test "std.meta.Elem" {190test "std.meta.Elem" {
191 testing.expect(Elem([1]u8) == u8);191 try testing.expect(Elem([1]u8) == u8);
192 testing.expect(Elem([*]u8) == u8);192 try testing.expect(Elem([*]u8) == u8);
193 testing.expect(Elem([]u8) == u8);193 try testing.expect(Elem([]u8) == u8);
194 testing.expect(Elem(*[10]u8) == u8);194 try testing.expect(Elem(*[10]u8) == u8);
195 testing.expect(Elem(Vector(2, u8)) == u8);195 try testing.expect(Elem(Vector(2, u8)) == u8);
196 testing.expect(Elem(*Vector(2, u8)) == u8);196 try testing.expect(Elem(*Vector(2, u8)) == u8);
197 testing.expect(Elem(?[*]u8) == u8);197 try testing.expect(Elem(?[*]u8) == u8);
198}198}
199199
200/// Given a type which can have a sentinel e.g. `[:0]u8`, returns the sentinel value,200/// Given a type which can have a sentinel e.g. `[:0]u8`, returns the sentinel value,
...@@ -219,20 +219,20 @@ pub fn sentinel(comptime T: type) ?Elem(T) {...@@ -219,20 +219,20 @@ pub fn sentinel(comptime T: type) ?Elem(T) {
219}219}
220220
221test "std.meta.sentinel" {221test "std.meta.sentinel" {
222 testSentinel();222 try testSentinel();
223 comptime testSentinel();223 comptime try testSentinel();
224}224}
225225
226fn testSentinel() void {226fn testSentinel() !void {
227 testing.expectEqual(@as(u8, 0), sentinel([:0]u8).?);227 try testing.expectEqual(@as(u8, 0), sentinel([:0]u8).?);
228 testing.expectEqual(@as(u8, 0), sentinel([*:0]u8).?);228 try testing.expectEqual(@as(u8, 0), sentinel([*:0]u8).?);
229 testing.expectEqual(@as(u8, 0), sentinel([5:0]u8).?);229 try testing.expectEqual(@as(u8, 0), sentinel([5:0]u8).?);
230 testing.expectEqual(@as(u8, 0), sentinel(*const [5:0]u8).?);230 try testing.expectEqual(@as(u8, 0), sentinel(*const [5:0]u8).?);
231231
232 testing.expect(sentinel([]u8) == null);232 try testing.expect(sentinel([]u8) == null);
233 testing.expect(sentinel([*]u8) == null);233 try testing.expect(sentinel([*]u8) == null);
234 testing.expect(sentinel([5]u8) == null);234 try testing.expect(sentinel([5]u8) == null);
235 testing.expect(sentinel(*const [5]u8) == null);235 try testing.expect(sentinel(*const [5]u8) == null);
236}236}
237237
238/// Given a "memory span" type, returns the same type except with the given sentinel value.238/// Given a "memory span" type, returns the same type except with the given sentinel value.
...@@ -322,17 +322,17 @@ pub fn assumeSentinel(p: anytype, comptime sentinel_val: Elem(@TypeOf(p))) Senti...@@ -322,17 +322,17 @@ pub fn assumeSentinel(p: anytype, comptime sentinel_val: Elem(@TypeOf(p))) Senti
322}322}
323323
324test "std.meta.assumeSentinel" {324test "std.meta.assumeSentinel" {
325 testing.expect([*:0]u8 == @TypeOf(assumeSentinel(@as([*]u8, undefined), 0)));325 try testing.expect([*:0]u8 == @TypeOf(assumeSentinel(@as([*]u8, undefined), 0)));
326 testing.expect([:0]u8 == @TypeOf(assumeSentinel(@as([]u8, undefined), 0)));326 try testing.expect([:0]u8 == @TypeOf(assumeSentinel(@as([]u8, undefined), 0)));
327 testing.expect([*:0]const u8 == @TypeOf(assumeSentinel(@as([*]const u8, undefined), 0)));327 try testing.expect([*:0]const u8 == @TypeOf(assumeSentinel(@as([*]const u8, undefined), 0)));
328 testing.expect([:0]const u8 == @TypeOf(assumeSentinel(@as([]const u8, undefined), 0)));328 try testing.expect([:0]const u8 == @TypeOf(assumeSentinel(@as([]const u8, undefined), 0)));
329 testing.expect([*:0]u16 == @TypeOf(assumeSentinel(@as([*]u16, undefined), 0)));329 try testing.expect([*:0]u16 == @TypeOf(assumeSentinel(@as([*]u16, undefined), 0)));
330 testing.expect([:0]const u16 == @TypeOf(assumeSentinel(@as([]const u16, undefined), 0)));330 try testing.expect([:0]const u16 == @TypeOf(assumeSentinel(@as([]const u16, undefined), 0)));
331 testing.expect([*:3]u8 == @TypeOf(assumeSentinel(@as([*:1]u8, undefined), 3)));331 try testing.expect([*:3]u8 == @TypeOf(assumeSentinel(@as([*:1]u8, undefined), 3)));
332 testing.expect([:null]?[*]u8 == @TypeOf(assumeSentinel(@as([]?[*]u8, undefined), null)));332 try testing.expect([:null]?[*]u8 == @TypeOf(assumeSentinel(@as([]?[*]u8, undefined), null)));
333 testing.expect([*:null]?[*]u8 == @TypeOf(assumeSentinel(@as([*]?[*]u8, undefined), null)));333 try testing.expect([*:null]?[*]u8 == @TypeOf(assumeSentinel(@as([*]?[*]u8, undefined), null)));
334 testing.expect(*[10:0]u8 == @TypeOf(assumeSentinel(@as(*[10]u8, undefined), 0)));334 try testing.expect(*[10:0]u8 == @TypeOf(assumeSentinel(@as(*[10]u8, undefined), 0)));
335 testing.expect(?[*:0]u8 == @TypeOf(assumeSentinel(@as(?[*]u8, undefined), 0)));335 try testing.expect(?[*:0]u8 == @TypeOf(assumeSentinel(@as(?[*]u8, undefined), 0)));
336}336}
337337
338pub fn containerLayout(comptime T: type) TypeInfo.ContainerLayout {338pub fn containerLayout(comptime T: type) TypeInfo.ContainerLayout {
...@@ -367,15 +367,15 @@ test "std.meta.containerLayout" {...@@ -367,15 +367,15 @@ test "std.meta.containerLayout" {
367 a: u8,367 a: u8,
368 };368 };
369369
370 testing.expect(containerLayout(E1) == .Auto);370 try testing.expect(containerLayout(E1) == .Auto);
371 testing.expect(containerLayout(E2) == .Packed);371 try testing.expect(containerLayout(E2) == .Packed);
372 testing.expect(containerLayout(E3) == .Extern);372 try testing.expect(containerLayout(E3) == .Extern);
373 testing.expect(containerLayout(S1) == .Auto);373 try testing.expect(containerLayout(S1) == .Auto);
374 testing.expect(containerLayout(S2) == .Packed);374 try testing.expect(containerLayout(S2) == .Packed);
375 testing.expect(containerLayout(S3) == .Extern);375 try testing.expect(containerLayout(S3) == .Extern);
376 testing.expect(containerLayout(U1) == .Auto);376 try testing.expect(containerLayout(U1) == .Auto);
377 testing.expect(containerLayout(U2) == .Packed);377 try testing.expect(containerLayout(U2) == .Packed);
378 testing.expect(containerLayout(U3) == .Extern);378 try testing.expect(containerLayout(U3) == .Extern);
379}379}
380380
381pub fn declarations(comptime T: type) []const TypeInfo.Declaration {381pub fn declarations(comptime T: type) []const TypeInfo.Declaration {
...@@ -414,8 +414,8 @@ test "std.meta.declarations" {...@@ -414,8 +414,8 @@ test "std.meta.declarations" {
414 };414 };
415415
416 inline for (decls) |decl| {416 inline for (decls) |decl| {
417 testing.expect(decl.len == 1);417 try testing.expect(decl.len == 1);
418 testing.expect(comptime mem.eql(u8, decl[0].name, "a"));418 try testing.expect(comptime mem.eql(u8, decl[0].name, "a"));
419 }419 }
420}420}
421421
...@@ -450,8 +450,8 @@ test "std.meta.declarationInfo" {...@@ -450,8 +450,8 @@ test "std.meta.declarationInfo" {
450 };450 };
451451
452 inline for (infos) |info| {452 inline for (infos) |info| {
453 testing.expect(comptime mem.eql(u8, info.name, "a"));453 try testing.expect(comptime mem.eql(u8, info.name, "a"));
454 testing.expect(!info.is_pub);454 try testing.expect(!info.is_pub);
455 }455 }
456}456}
457457
...@@ -488,16 +488,16 @@ test "std.meta.fields" {...@@ -488,16 +488,16 @@ test "std.meta.fields" {
488 const sf = comptime fields(S1);488 const sf = comptime fields(S1);
489 const uf = comptime fields(U1);489 const uf = comptime fields(U1);
490490
491 testing.expect(e1f.len == 1);491 try testing.expect(e1f.len == 1);
492 testing.expect(e2f.len == 1);492 try testing.expect(e2f.len == 1);
493 testing.expect(sf.len == 1);493 try testing.expect(sf.len == 1);
494 testing.expect(uf.len == 1);494 try testing.expect(uf.len == 1);
495 testing.expect(mem.eql(u8, e1f[0].name, "A"));495 try testing.expect(mem.eql(u8, e1f[0].name, "A"));
496 testing.expect(mem.eql(u8, e2f[0].name, "A"));496 try testing.expect(mem.eql(u8, e2f[0].name, "A"));
497 testing.expect(mem.eql(u8, sf[0].name, "a"));497 try testing.expect(mem.eql(u8, sf[0].name, "a"));
498 testing.expect(mem.eql(u8, uf[0].name, "a"));498 try testing.expect(mem.eql(u8, uf[0].name, "a"));
499 testing.expect(comptime sf[0].field_type == u8);499 try testing.expect(comptime sf[0].field_type == u8);
500 testing.expect(comptime uf[0].field_type == u8);500 try testing.expect(comptime uf[0].field_type == u8);
501}501}
502502
503pub fn fieldInfo(comptime T: type, comptime field: FieldEnum(T)) switch (@typeInfo(T)) {503pub fn fieldInfo(comptime T: type, comptime field: FieldEnum(T)) switch (@typeInfo(T)) {
...@@ -527,12 +527,12 @@ test "std.meta.fieldInfo" {...@@ -527,12 +527,12 @@ test "std.meta.fieldInfo" {
527 const sf = fieldInfo(S1, .a);527 const sf = fieldInfo(S1, .a);
528 const uf = fieldInfo(U1, .a);528 const uf = fieldInfo(U1, .a);
529529
530 testing.expect(mem.eql(u8, e1f.name, "A"));530 try testing.expect(mem.eql(u8, e1f.name, "A"));
531 testing.expect(mem.eql(u8, e2f.name, "A"));531 try testing.expect(mem.eql(u8, e2f.name, "A"));
532 testing.expect(mem.eql(u8, sf.name, "a"));532 try testing.expect(mem.eql(u8, sf.name, "a"));
533 testing.expect(mem.eql(u8, uf.name, "a"));533 try testing.expect(mem.eql(u8, uf.name, "a"));
534 testing.expect(comptime sf.field_type == u8);534 try testing.expect(comptime sf.field_type == u8);
535 testing.expect(comptime uf.field_type == u8);535 try testing.expect(comptime uf.field_type == u8);
536}536}
537537
538pub fn fieldNames(comptime T: type) *const [fields(T).len][]const u8 {538pub fn fieldNames(comptime T: type) *const [fields(T).len][]const u8 {
...@@ -562,16 +562,16 @@ test "std.meta.fieldNames" {...@@ -562,16 +562,16 @@ test "std.meta.fieldNames" {
562 const s1names = fieldNames(S1);562 const s1names = fieldNames(S1);
563 const u1names = fieldNames(U1);563 const u1names = fieldNames(U1);
564564
565 testing.expect(e1names.len == 2);565 try testing.expect(e1names.len == 2);
566 testing.expectEqualSlices(u8, e1names[0], "A");566 try testing.expectEqualSlices(u8, e1names[0], "A");
567 testing.expectEqualSlices(u8, e1names[1], "B");567 try testing.expectEqualSlices(u8, e1names[1], "B");
568 testing.expect(e2names.len == 1);568 try testing.expect(e2names.len == 1);
569 testing.expectEqualSlices(u8, e2names[0], "A");569 try testing.expectEqualSlices(u8, e2names[0], "A");
570 testing.expect(s1names.len == 1);570 try testing.expect(s1names.len == 1);
571 testing.expectEqualSlices(u8, s1names[0], "a");571 try testing.expectEqualSlices(u8, s1names[0], "a");
572 testing.expect(u1names.len == 2);572 try testing.expect(u1names.len == 2);
573 testing.expectEqualSlices(u8, u1names[0], "a");573 try testing.expectEqualSlices(u8, u1names[0], "a");
574 testing.expectEqualSlices(u8, u1names[1], "b");574 try testing.expectEqualSlices(u8, u1names[1], "b");
575}575}
576576
577pub fn FieldEnum(comptime T: type) type {577pub fn FieldEnum(comptime T: type) type {
...@@ -595,20 +595,20 @@ pub fn FieldEnum(comptime T: type) type {...@@ -595,20 +595,20 @@ pub fn FieldEnum(comptime T: type) type {
595 });595 });
596}596}
597597
598fn expectEqualEnum(expected: anytype, actual: @TypeOf(expected)) void {598fn expectEqualEnum(expected: anytype, actual: @TypeOf(expected)) !void {
599 // TODO: https://github.com/ziglang/zig/issues/7419599 // TODO: https://github.com/ziglang/zig/issues/7419
600 // testing.expectEqual(@typeInfo(expected).Enum, @typeInfo(actual).Enum);600 // testing.expectEqual(@typeInfo(expected).Enum, @typeInfo(actual).Enum);
601 testing.expectEqual(@typeInfo(expected).Enum.layout, @typeInfo(actual).Enum.layout);601 try testing.expectEqual(@typeInfo(expected).Enum.layout, @typeInfo(actual).Enum.layout);
602 testing.expectEqual(@typeInfo(expected).Enum.tag_type, @typeInfo(actual).Enum.tag_type);602 try testing.expectEqual(@typeInfo(expected).Enum.tag_type, @typeInfo(actual).Enum.tag_type);
603 comptime testing.expectEqualSlices(std.builtin.TypeInfo.EnumField, @typeInfo(expected).Enum.fields, @typeInfo(actual).Enum.fields);603 comptime try testing.expectEqualSlices(std.builtin.TypeInfo.EnumField, @typeInfo(expected).Enum.fields, @typeInfo(actual).Enum.fields);
604 comptime testing.expectEqualSlices(std.builtin.TypeInfo.Declaration, @typeInfo(expected).Enum.decls, @typeInfo(actual).Enum.decls);604 comptime try testing.expectEqualSlices(std.builtin.TypeInfo.Declaration, @typeInfo(expected).Enum.decls, @typeInfo(actual).Enum.decls);
605 testing.expectEqual(@typeInfo(expected).Enum.is_exhaustive, @typeInfo(actual).Enum.is_exhaustive);605 try testing.expectEqual(@typeInfo(expected).Enum.is_exhaustive, @typeInfo(actual).Enum.is_exhaustive);
606}606}
607607
608test "std.meta.FieldEnum" {608test "std.meta.FieldEnum" {
609 expectEqualEnum(enum { a }, FieldEnum(struct { a: u8 }));609 try expectEqualEnum(enum { a }, FieldEnum(struct { a: u8 }));
610 expectEqualEnum(enum { a, b, c }, FieldEnum(struct { a: u8, b: void, c: f32 }));610 try expectEqualEnum(enum { a, b, c }, FieldEnum(struct { a: u8, b: void, c: f32 }));
611 expectEqualEnum(enum { a, b, c }, FieldEnum(union { a: u8, b: void, c: f32 }));611 try expectEqualEnum(enum { a, b, c }, FieldEnum(union { a: u8, b: void, c: f32 }));
612}612}
613613
614// Deprecated: use Tag614// Deprecated: use Tag
...@@ -632,8 +632,8 @@ test "std.meta.Tag" {...@@ -632,8 +632,8 @@ test "std.meta.Tag" {
632 D: u16,632 D: u16,
633 };633 };
634634
635 testing.expect(Tag(E) == u8);635 try testing.expect(Tag(E) == u8);
636 testing.expect(Tag(U) == E);636 try testing.expect(Tag(U) == E);
637}637}
638638
639///Returns the active tag of a tagged union639///Returns the active tag of a tagged union
...@@ -654,10 +654,10 @@ test "std.meta.activeTag" {...@@ -654,10 +654,10 @@ test "std.meta.activeTag" {
654 };654 };
655655
656 var u = U{ .Int = 32 };656 var u = U{ .Int = 32 };
657 testing.expect(activeTag(u) == UE.Int);657 try testing.expect(activeTag(u) == UE.Int);
658658
659 u = U{ .Float = 112.9876 };659 u = U{ .Float = 112.9876 };
660 testing.expect(activeTag(u) == UE.Float);660 try testing.expect(activeTag(u) == UE.Float);
661}661}
662662
663const TagPayloadType = TagPayload;663const TagPayloadType = TagPayload;
...@@ -665,7 +665,7 @@ const TagPayloadType = TagPayload;...@@ -665,7 +665,7 @@ const TagPayloadType = TagPayload;
665///Given a tagged union type, and an enum, return the type of the union665///Given a tagged union type, and an enum, return the type of the union
666/// field corresponding to the enum tag.666/// field corresponding to the enum tag.
667pub fn TagPayload(comptime U: type, tag: Tag(U)) type {667pub fn TagPayload(comptime U: type, tag: Tag(U)) type {
668 testing.expect(trait.is(.Union)(U));668 try testing.expect(trait.is(.Union)(U));
669669
670 const info = @typeInfo(U).Union;670 const info = @typeInfo(U).Union;
671 const tag_info = @typeInfo(Tag(U)).Enum;671 const tag_info = @typeInfo(Tag(U)).Enum;
...@@ -687,7 +687,7 @@ test "std.meta.TagPayload" {...@@ -687,7 +687,7 @@ test "std.meta.TagPayload" {
687 };687 };
688 const MovedEvent = TagPayload(Event, Event.Moved);688 const MovedEvent = TagPayload(Event, Event.Moved);
689 var e: Event = undefined;689 var e: Event = undefined;
690 testing.expect(MovedEvent == @TypeOf(e.Moved));690 try testing.expect(MovedEvent == @TypeOf(e.Moved));
691}691}
692692
693/// Compares two of any type for equality. Containers are compared on a field-by-field basis,693/// Compares two of any type for equality. Containers are compared on a field-by-field basis,
...@@ -787,19 +787,19 @@ test "std.meta.eql" {...@@ -787,19 +787,19 @@ test "std.meta.eql" {
787 const u_2 = U{ .s = s_1 };787 const u_2 = U{ .s = s_1 };
788 const u_3 = U{ .f = 24 };788 const u_3 = U{ .f = 24 };
789789
790 testing.expect(eql(s_1, s_3));790 try testing.expect(eql(s_1, s_3));
791 testing.expect(eql(&s_1, &s_1));791 try testing.expect(eql(&s_1, &s_1));
792 testing.expect(!eql(&s_1, &s_3));792 try testing.expect(!eql(&s_1, &s_3));
793 testing.expect(eql(u_1, u_3));793 try testing.expect(eql(u_1, u_3));
794 testing.expect(!eql(u_1, u_2));794 try testing.expect(!eql(u_1, u_2));
795795
796 var a1 = "abcdef".*;796 var a1 = "abcdef".*;
797 var a2 = "abcdef".*;797 var a2 = "abcdef".*;
798 var a3 = "ghijkl".*;798 var a3 = "ghijkl".*;
799799
800 testing.expect(eql(a1, a2));800 try testing.expect(eql(a1, a2));
801 testing.expect(!eql(a1, a3));801 try testing.expect(!eql(a1, a3));
802 testing.expect(!eql(a1[0..], a2[0..]));802 try testing.expect(!eql(a1[0..], a2[0..]));
803803
804 const EU = struct {804 const EU = struct {
805 fn tst(err: bool) !u8 {805 fn tst(err: bool) !u8 {
...@@ -808,16 +808,16 @@ test "std.meta.eql" {...@@ -808,16 +808,16 @@ test "std.meta.eql" {
808 }808 }
809 };809 };
810810
811 testing.expect(eql(EU.tst(true), EU.tst(true)));811 try testing.expect(eql(EU.tst(true), EU.tst(true)));
812 testing.expect(eql(EU.tst(false), EU.tst(false)));812 try testing.expect(eql(EU.tst(false), EU.tst(false)));
813 testing.expect(!eql(EU.tst(false), EU.tst(true)));813 try testing.expect(!eql(EU.tst(false), EU.tst(true)));
814814
815 var v1 = @splat(4, @as(u32, 1));815 var v1 = @splat(4, @as(u32, 1));
816 var v2 = @splat(4, @as(u32, 1));816 var v2 = @splat(4, @as(u32, 1));
817 var v3 = @splat(4, @as(u32, 2));817 var v3 = @splat(4, @as(u32, 2));
818818
819 testing.expect(eql(v1, v2));819 try testing.expect(eql(v1, v2));
820 testing.expect(!eql(v1, v3));820 try testing.expect(!eql(v1, v3));
821}821}
822822
823test "intToEnum with error return" {823test "intToEnum with error return" {
...@@ -831,9 +831,9 @@ test "intToEnum with error return" {...@@ -831,9 +831,9 @@ test "intToEnum with error return" {
831831
832 var zero: u8 = 0;832 var zero: u8 = 0;
833 var one: u16 = 1;833 var one: u16 = 1;
834 testing.expect(intToEnum(E1, zero) catch unreachable == E1.A);834 try testing.expect(intToEnum(E1, zero) catch unreachable == E1.A);
835 testing.expect(intToEnum(E2, one) catch unreachable == E2.B);835 try testing.expect(intToEnum(E2, one) catch unreachable == E2.B);
836 testing.expectError(error.InvalidEnumTag, intToEnum(E1, one));836 try testing.expectError(error.InvalidEnumTag, intToEnum(E1, one));
837}837}
838838
839pub const IntToEnumError = error{InvalidEnumTag};839pub const IntToEnumError = error{InvalidEnumTag};
...@@ -1008,27 +1008,27 @@ test "std.meta.cast" {...@@ -1008,27 +1008,27 @@ test "std.meta.cast" {
10081008
1009 var i = @as(i64, 10);1009 var i = @as(i64, 10);
10101010
1011 testing.expect(cast(*u8, 16) == @intToPtr(*u8, 16));1011 try testing.expect(cast(*u8, 16) == @intToPtr(*u8, 16));
1012 testing.expect(cast(*u64, &i).* == @as(u64, 10));1012 try testing.expect(cast(*u64, &i).* == @as(u64, 10));
1013 testing.expect(cast(*i64, @as(?*align(1) i64, &i)) == &i);1013 try testing.expect(cast(*i64, @as(?*align(1) i64, &i)) == &i);
10141014
1015 testing.expect(cast(?*u8, 2) == @intToPtr(*u8, 2));1015 try testing.expect(cast(?*u8, 2) == @intToPtr(*u8, 2));
1016 testing.expect(cast(?*i64, @as(*align(1) i64, &i)) == &i);1016 try testing.expect(cast(?*i64, @as(*align(1) i64, &i)) == &i);
1017 testing.expect(cast(?*i64, @as(?*align(1) i64, &i)) == &i);1017 try testing.expect(cast(?*i64, @as(?*align(1) i64, &i)) == &i);
10181018
1019 testing.expect(cast(E, 1) == .One);1019 try testing.expect(cast(E, 1) == .One);
10201020
1021 testing.expectEqual(@as(u32, 4), cast(u32, @intToPtr(*u32, 4)));1021 try testing.expectEqual(@as(u32, 4), cast(u32, @intToPtr(*u32, 4)));
1022 testing.expectEqual(@as(u32, 4), cast(u32, @intToPtr(?*u32, 4)));1022 try testing.expectEqual(@as(u32, 4), cast(u32, @intToPtr(?*u32, 4)));
1023 testing.expectEqual(@as(u32, 10), cast(u32, @as(u64, 10)));1023 try testing.expectEqual(@as(u32, 10), cast(u32, @as(u64, 10)));
1024 testing.expectEqual(@as(u8, 2), cast(u8, E.Two));1024 try testing.expectEqual(@as(u8, 2), cast(u8, E.Two));
10251025
1026 testing.expectEqual(@bitCast(i32, @as(u32, 0x8000_0000)), cast(i32, @as(u32, 0x8000_0000)));1026 try testing.expectEqual(@bitCast(i32, @as(u32, 0x8000_0000)), cast(i32, @as(u32, 0x8000_0000)));
10271027
1028 testing.expectEqual(@intToPtr(*u8, 2), cast(*u8, @intToPtr(*const u8, 2)));1028 try testing.expectEqual(@intToPtr(*u8, 2), cast(*u8, @intToPtr(*const u8, 2)));
1029 testing.expectEqual(@intToPtr(*u8, 2), cast(*u8, @intToPtr(*volatile u8, 2)));1029 try testing.expectEqual(@intToPtr(*u8, 2), cast(*u8, @intToPtr(*volatile u8, 2)));
10301030
1031 testing.expectEqual(@intToPtr(?*c_void, 2), cast(?*c_void, @intToPtr(*u8, 2)));1031 try testing.expectEqual(@intToPtr(?*c_void, 2), cast(?*c_void, @intToPtr(*u8, 2)));
10321032
1033 const C_ENUM = extern enum(c_int) {1033 const C_ENUM = extern enum(c_int) {
1034 A = 0,1034 A = 0,
...@@ -1036,10 +1036,10 @@ test "std.meta.cast" {...@@ -1036,10 +1036,10 @@ test "std.meta.cast" {
1036 C,1036 C,
1037 _,1037 _,
1038 };1038 };
1039 testing.expectEqual(cast(C_ENUM, @as(i64, -1)), @intToEnum(C_ENUM, -1));1039 try testing.expectEqual(cast(C_ENUM, @as(i64, -1)), @intToEnum(C_ENUM, -1));
1040 testing.expectEqual(cast(C_ENUM, @as(i8, 1)), .B);1040 try testing.expectEqual(cast(C_ENUM, @as(i8, 1)), .B);
1041 testing.expectEqual(cast(C_ENUM, @as(u64, 1)), .B);1041 try testing.expectEqual(cast(C_ENUM, @as(u64, 1)), .B);
1042 testing.expectEqual(cast(C_ENUM, @as(u64, 42)), @intToEnum(C_ENUM, 42));1042 try testing.expectEqual(cast(C_ENUM, @as(u64, 42)), @intToEnum(C_ENUM, 42));
1043}1043}
10441044
1045/// Given a value returns its size as C's sizeof operator would.1045/// Given a value returns its size as C's sizeof operator would.
...@@ -1118,43 +1118,43 @@ test "sizeof" {...@@ -1118,43 +1118,43 @@ test "sizeof" {
11181118
1119 const ptr_size = @sizeOf(*c_void);1119 const ptr_size = @sizeOf(*c_void);
11201120
1121 testing.expect(sizeof(u32) == 4);1121 try testing.expect(sizeof(u32) == 4);
1122 testing.expect(sizeof(@as(u32, 2)) == 4);1122 try testing.expect(sizeof(@as(u32, 2)) == 4);
1123 testing.expect(sizeof(2) == @sizeOf(c_int));1123 try testing.expect(sizeof(2) == @sizeOf(c_int));
11241124
1125 testing.expect(sizeof(2.0) == @sizeOf(f64));1125 try testing.expect(sizeof(2.0) == @sizeOf(f64));
11261126
1127 testing.expect(sizeof(E) == @sizeOf(c_int));1127 try testing.expect(sizeof(E) == @sizeOf(c_int));
1128 testing.expect(sizeof(E.One) == @sizeOf(c_int));1128 try testing.expect(sizeof(E.One) == @sizeOf(c_int));
11291129
1130 testing.expect(sizeof(S) == 4);1130 try testing.expect(sizeof(S) == 4);
11311131
1132 testing.expect(sizeof([_]u32{ 4, 5, 6 }) == 12);1132 try testing.expect(sizeof([_]u32{ 4, 5, 6 }) == 12);
1133 testing.expect(sizeof([3]u32) == 12);1133 try testing.expect(sizeof([3]u32) == 12);
1134 testing.expect(sizeof([3:0]u32) == 16);1134 try testing.expect(sizeof([3:0]u32) == 16);
1135 testing.expect(sizeof(&[_]u32{ 4, 5, 6 }) == ptr_size);1135 try testing.expect(sizeof(&[_]u32{ 4, 5, 6 }) == ptr_size);
11361136
1137 testing.expect(sizeof(*u32) == ptr_size);1137 try testing.expect(sizeof(*u32) == ptr_size);
1138 testing.expect(sizeof([*]u32) == ptr_size);1138 try testing.expect(sizeof([*]u32) == ptr_size);
1139 testing.expect(sizeof([*c]u32) == ptr_size);1139 try testing.expect(sizeof([*c]u32) == ptr_size);
1140 testing.expect(sizeof(?*u32) == ptr_size);1140 try testing.expect(sizeof(?*u32) == ptr_size);
1141 testing.expect(sizeof(?[*]u32) == ptr_size);1141 try testing.expect(sizeof(?[*]u32) == ptr_size);
1142 testing.expect(sizeof(*c_void) == ptr_size);1142 try testing.expect(sizeof(*c_void) == ptr_size);
1143 testing.expect(sizeof(*void) == ptr_size);1143 try testing.expect(sizeof(*void) == ptr_size);
1144 testing.expect(sizeof(null) == ptr_size);1144 try testing.expect(sizeof(null) == ptr_size);
11451145
1146 testing.expect(sizeof("foobar") == 7);1146 try testing.expect(sizeof("foobar") == 7);
1147 testing.expect(sizeof(&[_:0]u16{ 'f', 'o', 'o', 'b', 'a', 'r' }) == 14);1147 try testing.expect(sizeof(&[_:0]u16{ 'f', 'o', 'o', 'b', 'a', 'r' }) == 14);
1148 testing.expect(sizeof(*const [4:0]u8) == 5);1148 try testing.expect(sizeof(*const [4:0]u8) == 5);
1149 testing.expect(sizeof(*[4:0]u8) == ptr_size);1149 try testing.expect(sizeof(*[4:0]u8) == ptr_size);
1150 testing.expect(sizeof([*]const [4:0]u8) == ptr_size);1150 try testing.expect(sizeof([*]const [4:0]u8) == ptr_size);
1151 testing.expect(sizeof(*const *const [4:0]u8) == ptr_size);1151 try testing.expect(sizeof(*const *const [4:0]u8) == ptr_size);
1152 testing.expect(sizeof(*const [4]u8) == ptr_size);1152 try testing.expect(sizeof(*const [4]u8) == ptr_size);
11531153
1154 testing.expect(sizeof(sizeof) == @sizeOf(@TypeOf(sizeof)));1154 try testing.expect(sizeof(sizeof) == @sizeOf(@TypeOf(sizeof)));
11551155
1156 testing.expect(sizeof(void) == 1);1156 try testing.expect(sizeof(void) == 1);
1157 testing.expect(sizeof(c_void) == 1);1157 try testing.expect(sizeof(c_void) == 1);
1158}1158}
11591159
1160pub const CIntLiteralRadix = enum { decimal, octal, hexadecimal };1160pub const CIntLiteralRadix = enum { decimal, octal, hexadecimal };
...@@ -1193,7 +1193,7 @@ pub fn promoteIntLiteral(...@@ -1193,7 +1193,7 @@ pub fn promoteIntLiteral(
11931193
1194test "promoteIntLiteral" {1194test "promoteIntLiteral" {
1195 const signed_hex = promoteIntLiteral(c_int, math.maxInt(c_int) + 1, .hexadecimal);1195 const signed_hex = promoteIntLiteral(c_int, math.maxInt(c_int) + 1, .hexadecimal);
1196 testing.expectEqual(c_uint, @TypeOf(signed_hex));1196 try testing.expectEqual(c_uint, @TypeOf(signed_hex));
11971197
1198 if (math.maxInt(c_longlong) == math.maxInt(c_int)) return;1198 if (math.maxInt(c_longlong) == math.maxInt(c_int)) return;
11991199
...@@ -1201,11 +1201,11 @@ test "promoteIntLiteral" {...@@ -1201,11 +1201,11 @@ test "promoteIntLiteral" {
1201 const unsigned = promoteIntLiteral(c_uint, math.maxInt(c_uint) + 1, .hexadecimal);1201 const unsigned = promoteIntLiteral(c_uint, math.maxInt(c_uint) + 1, .hexadecimal);
12021202
1203 if (math.maxInt(c_long) > math.maxInt(c_int)) {1203 if (math.maxInt(c_long) > math.maxInt(c_int)) {
1204 testing.expectEqual(c_long, @TypeOf(signed_decimal));1204 try testing.expectEqual(c_long, @TypeOf(signed_decimal));
1205 testing.expectEqual(c_ulong, @TypeOf(unsigned));1205 try testing.expectEqual(c_ulong, @TypeOf(unsigned));
1206 } else {1206 } else {
1207 testing.expectEqual(c_longlong, @TypeOf(signed_decimal));1207 try testing.expectEqual(c_longlong, @TypeOf(signed_decimal));
1208 testing.expectEqual(c_ulonglong, @TypeOf(unsigned));1208 try testing.expectEqual(c_ulonglong, @TypeOf(unsigned));
1209 }1209 }
1210}1210}
12111211
...@@ -1347,17 +1347,17 @@ pub fn shuffleVectorIndex(comptime this_index: c_int, comptime source_vector_len...@@ -1347,17 +1347,17 @@ pub fn shuffleVectorIndex(comptime this_index: c_int, comptime source_vector_len
1347test "shuffleVectorIndex" {1347test "shuffleVectorIndex" {
1348 const vector_len: usize = 4;1348 const vector_len: usize = 4;
13491349
1350 testing.expect(shuffleVectorIndex(-1, vector_len) == 0);1350 try testing.expect(shuffleVectorIndex(-1, vector_len) == 0);
13511351
1352 testing.expect(shuffleVectorIndex(0, vector_len) == 0);1352 try testing.expect(shuffleVectorIndex(0, vector_len) == 0);
1353 testing.expect(shuffleVectorIndex(1, vector_len) == 1);1353 try testing.expect(shuffleVectorIndex(1, vector_len) == 1);
1354 testing.expect(shuffleVectorIndex(2, vector_len) == 2);1354 try testing.expect(shuffleVectorIndex(2, vector_len) == 2);
1355 testing.expect(shuffleVectorIndex(3, vector_len) == 3);1355 try testing.expect(shuffleVectorIndex(3, vector_len) == 3);
13561356
1357 testing.expect(shuffleVectorIndex(4, vector_len) == -1);1357 try testing.expect(shuffleVectorIndex(4, vector_len) == -1);
1358 testing.expect(shuffleVectorIndex(5, vector_len) == -2);1358 try testing.expect(shuffleVectorIndex(5, vector_len) == -2);
1359 testing.expect(shuffleVectorIndex(6, vector_len) == -3);1359 try testing.expect(shuffleVectorIndex(6, vector_len) == -3);
1360 testing.expect(shuffleVectorIndex(7, vector_len) == -4);1360 try testing.expect(shuffleVectorIndex(7, vector_len) == -4);
1361}1361}
13621362
1363/// Returns whether `error_union` contains an error.1363/// Returns whether `error_union` contains an error.
...@@ -1366,6 +1366,6 @@ pub fn isError(error_union: anytype) bool {...@@ -1366,6 +1366,6 @@ pub fn isError(error_union: anytype) bool {
1366}1366}
13671367
1368test "isError" {1368test "isError" {
1369 std.testing.expect(isError(math.absInt(@as(i8, -128))));1369 try std.testing.expect(isError(math.absInt(@as(i8, -128))));
1370 std.testing.expect(!isError(math.absInt(@as(i8, -127))));1370 try std.testing.expect(!isError(math.absInt(@as(i8, -127))));
1371}1371}
lib/std/meta/trailer_flags.zig+7-7
...@@ -146,7 +146,7 @@ test "TrailerFlags" {...@@ -146,7 +146,7 @@ test "TrailerFlags" {
146 b: bool,146 b: bool,
147 c: u64,147 c: u64,
148 });148 });
149 testing.expectEqual(u2, meta.Tag(Flags.FieldEnum));149 try testing.expectEqual(u2, meta.Tag(Flags.FieldEnum));
150150
151 var flags = Flags.init(.{151 var flags = Flags.init(.{
152 .b = true,152 .b = true,
...@@ -158,16 +158,16 @@ test "TrailerFlags" {...@@ -158,16 +158,16 @@ test "TrailerFlags" {
158 flags.set(slice.ptr, .b, false);158 flags.set(slice.ptr, .b, false);
159 flags.set(slice.ptr, .c, 12345678);159 flags.set(slice.ptr, .c, 12345678);
160160
161 testing.expect(flags.get(slice.ptr, .a) == null);161 try testing.expect(flags.get(slice.ptr, .a) == null);
162 testing.expect(!flags.get(slice.ptr, .b).?);162 try testing.expect(!flags.get(slice.ptr, .b).?);
163 testing.expect(flags.get(slice.ptr, .c).? == 12345678);163 try testing.expect(flags.get(slice.ptr, .c).? == 12345678);
164164
165 flags.setMany(slice.ptr, .{165 flags.setMany(slice.ptr, .{
166 .b = true,166 .b = true,
167 .c = 5678,167 .c = 5678,
168 });168 });
169169
170 testing.expect(flags.get(slice.ptr, .a) == null);170 try testing.expect(flags.get(slice.ptr, .a) == null);
171 testing.expect(flags.get(slice.ptr, .b).?);171 try testing.expect(flags.get(slice.ptr, .b).?);
172 testing.expect(flags.get(slice.ptr, .c).? == 5678);172 try testing.expect(flags.get(slice.ptr, .c).? == 5678);
173}173}
lib/std/meta/trait.zig+142-142
...@@ -45,8 +45,8 @@ test "std.meta.trait.multiTrait" {...@@ -45,8 +45,8 @@ test "std.meta.trait.multiTrait" {
45 hasField("x"),45 hasField("x"),
46 hasField("y"),46 hasField("y"),
47 });47 });
48 testing.expect(isVector(Vector2));48 try testing.expect(isVector(Vector2));
49 testing.expect(!isVector(u8));49 try testing.expect(!isVector(u8));
50}50}
5151
52pub fn hasFn(comptime name: []const u8) TraitFn {52pub fn hasFn(comptime name: []const u8) TraitFn {
...@@ -66,9 +66,9 @@ test "std.meta.trait.hasFn" {...@@ -66,9 +66,9 @@ test "std.meta.trait.hasFn" {
66 pub fn useless() void {}66 pub fn useless() void {}
67 };67 };
6868
69 testing.expect(hasFn("useless")(TestStruct));69 try testing.expect(hasFn("useless")(TestStruct));
70 testing.expect(!hasFn("append")(TestStruct));70 try testing.expect(!hasFn("append")(TestStruct));
71 testing.expect(!hasFn("useless")(u8));71 try testing.expect(!hasFn("useless")(u8));
72}72}
7373
74pub fn hasField(comptime name: []const u8) TraitFn {74pub fn hasField(comptime name: []const u8) TraitFn {
...@@ -96,11 +96,11 @@ test "std.meta.trait.hasField" {...@@ -96,11 +96,11 @@ test "std.meta.trait.hasField" {
96 value: u32,96 value: u32,
97 };97 };
9898
99 testing.expect(hasField("value")(TestStruct));99 try testing.expect(hasField("value")(TestStruct));
100 testing.expect(!hasField("value")(*TestStruct));100 try testing.expect(!hasField("value")(*TestStruct));
101 testing.expect(!hasField("x")(TestStruct));101 try testing.expect(!hasField("x")(TestStruct));
102 testing.expect(!hasField("x")(**TestStruct));102 try testing.expect(!hasField("x")(**TestStruct));
103 testing.expect(!hasField("value")(u8));103 try testing.expect(!hasField("value")(u8));
104}104}
105105
106pub fn is(comptime id: builtin.TypeId) TraitFn {106pub fn is(comptime id: builtin.TypeId) TraitFn {
...@@ -113,11 +113,11 @@ pub fn is(comptime id: builtin.TypeId) TraitFn {...@@ -113,11 +113,11 @@ pub fn is(comptime id: builtin.TypeId) TraitFn {
113}113}
114114
115test "std.meta.trait.is" {115test "std.meta.trait.is" {
116 testing.expect(is(.Int)(u8));116 try testing.expect(is(.Int)(u8));
117 testing.expect(!is(.Int)(f32));117 try testing.expect(!is(.Int)(f32));
118 testing.expect(is(.Pointer)(*u8));118 try testing.expect(is(.Pointer)(*u8));
119 testing.expect(is(.Void)(void));119 try testing.expect(is(.Void)(void));
120 testing.expect(!is(.Optional)(anyerror));120 try testing.expect(!is(.Optional)(anyerror));
121}121}
122122
123pub fn isPtrTo(comptime id: builtin.TypeId) TraitFn {123pub fn isPtrTo(comptime id: builtin.TypeId) TraitFn {
...@@ -131,9 +131,9 @@ pub fn isPtrTo(comptime id: builtin.TypeId) TraitFn {...@@ -131,9 +131,9 @@ pub fn isPtrTo(comptime id: builtin.TypeId) TraitFn {
131}131}
132132
133test "std.meta.trait.isPtrTo" {133test "std.meta.trait.isPtrTo" {
134 testing.expect(!isPtrTo(.Struct)(struct {}));134 try testing.expect(!isPtrTo(.Struct)(struct {}));
135 testing.expect(isPtrTo(.Struct)(*struct {}));135 try testing.expect(isPtrTo(.Struct)(*struct {}));
136 testing.expect(!isPtrTo(.Struct)(**struct {}));136 try testing.expect(!isPtrTo(.Struct)(**struct {}));
137}137}
138138
139pub fn isSliceOf(comptime id: builtin.TypeId) TraitFn {139pub fn isSliceOf(comptime id: builtin.TypeId) TraitFn {
...@@ -147,9 +147,9 @@ pub fn isSliceOf(comptime id: builtin.TypeId) TraitFn {...@@ -147,9 +147,9 @@ pub fn isSliceOf(comptime id: builtin.TypeId) TraitFn {
147}147}
148148
149test "std.meta.trait.isSliceOf" {149test "std.meta.trait.isSliceOf" {
150 testing.expect(!isSliceOf(.Struct)(struct {}));150 try testing.expect(!isSliceOf(.Struct)(struct {}));
151 testing.expect(isSliceOf(.Struct)([]struct {}));151 try testing.expect(isSliceOf(.Struct)([]struct {}));
152 testing.expect(!isSliceOf(.Struct)([][]struct {}));152 try testing.expect(!isSliceOf(.Struct)([][]struct {}));
153}153}
154154
155///////////Strait trait Fns155///////////Strait trait Fns
...@@ -170,9 +170,9 @@ test "std.meta.trait.isExtern" {...@@ -170,9 +170,9 @@ test "std.meta.trait.isExtern" {
170 const TestExStruct = extern struct {};170 const TestExStruct = extern struct {};
171 const TestStruct = struct {};171 const TestStruct = struct {};
172172
173 testing.expect(isExtern(TestExStruct));173 try testing.expect(isExtern(TestExStruct));
174 testing.expect(!isExtern(TestStruct));174 try testing.expect(!isExtern(TestStruct));
175 testing.expect(!isExtern(u8));175 try testing.expect(!isExtern(u8));
176}176}
177177
178pub fn isPacked(comptime T: type) bool {178pub fn isPacked(comptime T: type) bool {
...@@ -188,9 +188,9 @@ test "std.meta.trait.isPacked" {...@@ -188,9 +188,9 @@ test "std.meta.trait.isPacked" {
188 const TestPStruct = packed struct {};188 const TestPStruct = packed struct {};
189 const TestStruct = struct {};189 const TestStruct = struct {};
190190
191 testing.expect(isPacked(TestPStruct));191 try testing.expect(isPacked(TestPStruct));
192 testing.expect(!isPacked(TestStruct));192 try testing.expect(!isPacked(TestStruct));
193 testing.expect(!isPacked(u8));193 try testing.expect(!isPacked(u8));
194}194}
195195
196pub fn isUnsignedInt(comptime T: type) bool {196pub fn isUnsignedInt(comptime T: type) bool {
...@@ -201,10 +201,10 @@ pub fn isUnsignedInt(comptime T: type) bool {...@@ -201,10 +201,10 @@ pub fn isUnsignedInt(comptime T: type) bool {
201}201}
202202
203test "isUnsignedInt" {203test "isUnsignedInt" {
204 testing.expect(isUnsignedInt(u32) == true);204 try testing.expect(isUnsignedInt(u32) == true);
205 testing.expect(isUnsignedInt(comptime_int) == false);205 try testing.expect(isUnsignedInt(comptime_int) == false);
206 testing.expect(isUnsignedInt(i64) == false);206 try testing.expect(isUnsignedInt(i64) == false);
207 testing.expect(isUnsignedInt(f64) == false);207 try testing.expect(isUnsignedInt(f64) == false);
208}208}
209209
210pub fn isSignedInt(comptime T: type) bool {210pub fn isSignedInt(comptime T: type) bool {
...@@ -216,10 +216,10 @@ pub fn isSignedInt(comptime T: type) bool {...@@ -216,10 +216,10 @@ pub fn isSignedInt(comptime T: type) bool {
216}216}
217217
218test "isSignedInt" {218test "isSignedInt" {
219 testing.expect(isSignedInt(u32) == false);219 try testing.expect(isSignedInt(u32) == false);
220 testing.expect(isSignedInt(comptime_int) == true);220 try testing.expect(isSignedInt(comptime_int) == true);
221 testing.expect(isSignedInt(i64) == true);221 try testing.expect(isSignedInt(i64) == true);
222 testing.expect(isSignedInt(f64) == false);222 try testing.expect(isSignedInt(f64) == false);
223}223}
224224
225pub fn isSingleItemPtr(comptime T: type) bool {225pub fn isSingleItemPtr(comptime T: type) bool {
...@@ -231,10 +231,10 @@ pub fn isSingleItemPtr(comptime T: type) bool {...@@ -231,10 +231,10 @@ pub fn isSingleItemPtr(comptime T: type) bool {
231231
232test "std.meta.trait.isSingleItemPtr" {232test "std.meta.trait.isSingleItemPtr" {
233 const array = [_]u8{0} ** 10;233 const array = [_]u8{0} ** 10;
234 comptime testing.expect(isSingleItemPtr(@TypeOf(&array[0])));234 comptime try testing.expect(isSingleItemPtr(@TypeOf(&array[0])));
235 comptime testing.expect(!isSingleItemPtr(@TypeOf(array)));235 comptime try testing.expect(!isSingleItemPtr(@TypeOf(array)));
236 var runtime_zero: usize = 0;236 var runtime_zero: usize = 0;
237 testing.expect(!isSingleItemPtr(@TypeOf(array[runtime_zero..1])));237 try testing.expect(!isSingleItemPtr(@TypeOf(array[runtime_zero..1])));
238}238}
239239
240pub fn isManyItemPtr(comptime T: type) bool {240pub fn isManyItemPtr(comptime T: type) bool {
...@@ -247,9 +247,9 @@ pub fn isManyItemPtr(comptime T: type) bool {...@@ -247,9 +247,9 @@ pub fn isManyItemPtr(comptime T: type) bool {
247test "std.meta.trait.isManyItemPtr" {247test "std.meta.trait.isManyItemPtr" {
248 const array = [_]u8{0} ** 10;248 const array = [_]u8{0} ** 10;
249 const mip = @ptrCast([*]const u8, &array[0]);249 const mip = @ptrCast([*]const u8, &array[0]);
250 testing.expect(isManyItemPtr(@TypeOf(mip)));250 try testing.expect(isManyItemPtr(@TypeOf(mip)));
251 testing.expect(!isManyItemPtr(@TypeOf(array)));251 try testing.expect(!isManyItemPtr(@TypeOf(array)));
252 testing.expect(!isManyItemPtr(@TypeOf(array[0..1])));252 try testing.expect(!isManyItemPtr(@TypeOf(array[0..1])));
253}253}
254254
255pub fn isSlice(comptime T: type) bool {255pub fn isSlice(comptime T: type) bool {
...@@ -262,9 +262,9 @@ pub fn isSlice(comptime T: type) bool {...@@ -262,9 +262,9 @@ pub fn isSlice(comptime T: type) bool {
262test "std.meta.trait.isSlice" {262test "std.meta.trait.isSlice" {
263 const array = [_]u8{0} ** 10;263 const array = [_]u8{0} ** 10;
264 var runtime_zero: usize = 0;264 var runtime_zero: usize = 0;
265 testing.expect(isSlice(@TypeOf(array[runtime_zero..])));265 try testing.expect(isSlice(@TypeOf(array[runtime_zero..])));
266 testing.expect(!isSlice(@TypeOf(array)));266 try testing.expect(!isSlice(@TypeOf(array)));
267 testing.expect(!isSlice(@TypeOf(&array[0])));267 try testing.expect(!isSlice(@TypeOf(&array[0])));
268}268}
269269
270pub fn isIndexable(comptime T: type) bool {270pub fn isIndexable(comptime T: type) bool {
...@@ -283,12 +283,12 @@ test "std.meta.trait.isIndexable" {...@@ -283,12 +283,12 @@ test "std.meta.trait.isIndexable" {
283 const vector: meta.Vector(2, u32) = [_]u32{0} ** 2;283 const vector: meta.Vector(2, u32) = [_]u32{0} ** 2;
284 const tuple = .{ 1, 2, 3 };284 const tuple = .{ 1, 2, 3 };
285285
286 testing.expect(isIndexable(@TypeOf(array)));286 try testing.expect(isIndexable(@TypeOf(array)));
287 testing.expect(isIndexable(@TypeOf(&array)));287 try testing.expect(isIndexable(@TypeOf(&array)));
288 testing.expect(isIndexable(@TypeOf(slice)));288 try testing.expect(isIndexable(@TypeOf(slice)));
289 testing.expect(!isIndexable(meta.Child(@TypeOf(slice))));289 try testing.expect(!isIndexable(meta.Child(@TypeOf(slice))));
290 testing.expect(isIndexable(@TypeOf(vector)));290 try testing.expect(isIndexable(@TypeOf(vector)));
291 testing.expect(isIndexable(@TypeOf(tuple)));291 try testing.expect(isIndexable(@TypeOf(tuple)));
292}292}
293293
294pub fn isNumber(comptime T: type) bool {294pub fn isNumber(comptime T: type) bool {
...@@ -317,13 +317,13 @@ test "std.meta.trait.isNumber" {...@@ -317,13 +317,13 @@ test "std.meta.trait.isNumber" {
317 number: u8,317 number: u8,
318 };318 };
319319
320 testing.expect(isNumber(u32));320 try testing.expect(isNumber(u32));
321 testing.expect(isNumber(f32));321 try testing.expect(isNumber(f32));
322 testing.expect(isNumber(u64));322 try testing.expect(isNumber(u64));
323 testing.expect(isNumber(@TypeOf(102)));323 try testing.expect(isNumber(@TypeOf(102)));
324 testing.expect(isNumber(@TypeOf(102.123)));324 try testing.expect(isNumber(@TypeOf(102.123)));
325 testing.expect(!isNumber([]u8));325 try testing.expect(!isNumber([]u8));
326 testing.expect(!isNumber(NotANumber));326 try testing.expect(!isNumber(NotANumber));
327}327}
328328
329pub fn isIntegral(comptime T: type) bool {329pub fn isIntegral(comptime T: type) bool {
...@@ -334,12 +334,12 @@ pub fn isIntegral(comptime T: type) bool {...@@ -334,12 +334,12 @@ pub fn isIntegral(comptime T: type) bool {
334}334}
335335
336test "isIntegral" {336test "isIntegral" {
337 testing.expect(isIntegral(u32));337 try testing.expect(isIntegral(u32));
338 testing.expect(!isIntegral(f32));338 try testing.expect(!isIntegral(f32));
339 testing.expect(isIntegral(@TypeOf(102)));339 try testing.expect(isIntegral(@TypeOf(102)));
340 testing.expect(!isIntegral(@TypeOf(102.123)));340 try testing.expect(!isIntegral(@TypeOf(102.123)));
341 testing.expect(!isIntegral(*u8));341 try testing.expect(!isIntegral(*u8));
342 testing.expect(!isIntegral([]u8));342 try testing.expect(!isIntegral([]u8));
343}343}
344344
345pub fn isFloat(comptime T: type) bool {345pub fn isFloat(comptime T: type) bool {
...@@ -350,12 +350,12 @@ pub fn isFloat(comptime T: type) bool {...@@ -350,12 +350,12 @@ pub fn isFloat(comptime T: type) bool {
350}350}
351351
352test "isFloat" {352test "isFloat" {
353 testing.expect(!isFloat(u32));353 try testing.expect(!isFloat(u32));
354 testing.expect(isFloat(f32));354 try testing.expect(isFloat(f32));
355 testing.expect(!isFloat(@TypeOf(102)));355 try testing.expect(!isFloat(@TypeOf(102)));
356 testing.expect(isFloat(@TypeOf(102.123)));356 try testing.expect(isFloat(@TypeOf(102.123)));
357 testing.expect(!isFloat(*f64));357 try testing.expect(!isFloat(*f64));
358 testing.expect(!isFloat([]f32));358 try testing.expect(!isFloat([]f32));
359}359}
360360
361pub fn isConstPtr(comptime T: type) bool {361pub fn isConstPtr(comptime T: type) bool {
...@@ -366,10 +366,10 @@ pub fn isConstPtr(comptime T: type) bool {...@@ -366,10 +366,10 @@ pub fn isConstPtr(comptime T: type) bool {
366test "std.meta.trait.isConstPtr" {366test "std.meta.trait.isConstPtr" {
367 var t = @as(u8, 0);367 var t = @as(u8, 0);
368 const c = @as(u8, 0);368 const c = @as(u8, 0);
369 testing.expect(isConstPtr(*const @TypeOf(t)));369 try testing.expect(isConstPtr(*const @TypeOf(t)));
370 testing.expect(isConstPtr(@TypeOf(&c)));370 try testing.expect(isConstPtr(@TypeOf(&c)));
371 testing.expect(!isConstPtr(*@TypeOf(t)));371 try testing.expect(!isConstPtr(*@TypeOf(t)));
372 testing.expect(!isConstPtr(@TypeOf(6)));372 try testing.expect(!isConstPtr(@TypeOf(6)));
373}373}
374374
375pub fn isContainer(comptime T: type) bool {375pub fn isContainer(comptime T: type) bool {
...@@ -389,10 +389,10 @@ test "std.meta.trait.isContainer" {...@@ -389,10 +389,10 @@ test "std.meta.trait.isContainer" {
389 B,389 B,
390 };390 };
391391
392 testing.expect(isContainer(TestStruct));392 try testing.expect(isContainer(TestStruct));
393 testing.expect(isContainer(TestUnion));393 try testing.expect(isContainer(TestUnion));
394 testing.expect(isContainer(TestEnum));394 try testing.expect(isContainer(TestEnum));
395 testing.expect(!isContainer(u8));395 try testing.expect(!isContainer(u8));
396}396}
397397
398pub fn isTuple(comptime T: type) bool {398pub fn isTuple(comptime T: type) bool {
...@@ -403,9 +403,9 @@ test "std.meta.trait.isTuple" {...@@ -403,9 +403,9 @@ test "std.meta.trait.isTuple" {
403 const t1 = struct {};403 const t1 = struct {};
404 const t2 = .{ .a = 0 };404 const t2 = .{ .a = 0 };
405 const t3 = .{ 1, 2, 3 };405 const t3 = .{ 1, 2, 3 };
406 testing.expect(!isTuple(t1));406 try testing.expect(!isTuple(t1));
407 testing.expect(!isTuple(@TypeOf(t2)));407 try testing.expect(!isTuple(@TypeOf(t2)));
408 testing.expect(isTuple(@TypeOf(t3)));408 try testing.expect(isTuple(@TypeOf(t3)));
409}409}
410410
411/// Returns true if the passed type will coerce to []const u8.411/// Returns true if the passed type will coerce to []const u8.
...@@ -449,41 +449,41 @@ pub fn isZigString(comptime T: type) bool {...@@ -449,41 +449,41 @@ pub fn isZigString(comptime T: type) bool {
449}449}
450450
451test "std.meta.trait.isZigString" {451test "std.meta.trait.isZigString" {
452 testing.expect(isZigString([]const u8));452 try testing.expect(isZigString([]const u8));
453 testing.expect(isZigString([]u8));453 try testing.expect(isZigString([]u8));
454 testing.expect(isZigString([:0]const u8));454 try testing.expect(isZigString([:0]const u8));
455 testing.expect(isZigString([:0]u8));455 try testing.expect(isZigString([:0]u8));
456 testing.expect(isZigString([:5]const u8));456 try testing.expect(isZigString([:5]const u8));
457 testing.expect(isZigString([:5]u8));457 try testing.expect(isZigString([:5]u8));
458 testing.expect(isZigString(*const [0]u8));458 try testing.expect(isZigString(*const [0]u8));
459 testing.expect(isZigString(*[0]u8));459 try testing.expect(isZigString(*[0]u8));
460 testing.expect(isZigString(*const [0:0]u8));460 try testing.expect(isZigString(*const [0:0]u8));
461 testing.expect(isZigString(*[0:0]u8));461 try testing.expect(isZigString(*[0:0]u8));
462 testing.expect(isZigString(*const [0:5]u8));462 try testing.expect(isZigString(*const [0:5]u8));
463 testing.expect(isZigString(*[0:5]u8));463 try testing.expect(isZigString(*[0:5]u8));
464 testing.expect(isZigString(*const [10]u8));464 try testing.expect(isZigString(*const [10]u8));
465 testing.expect(isZigString(*[10]u8));465 try testing.expect(isZigString(*[10]u8));
466 testing.expect(isZigString(*const [10:0]u8));466 try testing.expect(isZigString(*const [10:0]u8));
467 testing.expect(isZigString(*[10:0]u8));467 try testing.expect(isZigString(*[10:0]u8));
468 testing.expect(isZigString(*const [10:5]u8));468 try testing.expect(isZigString(*const [10:5]u8));
469 testing.expect(isZigString(*[10:5]u8));469 try testing.expect(isZigString(*[10:5]u8));
470470
471 testing.expect(!isZigString(u8));471 try testing.expect(!isZigString(u8));
472 testing.expect(!isZigString([4]u8));472 try testing.expect(!isZigString([4]u8));
473 testing.expect(!isZigString([4:0]u8));473 try testing.expect(!isZigString([4:0]u8));
474 testing.expect(!isZigString([*]const u8));474 try testing.expect(!isZigString([*]const u8));
475 testing.expect(!isZigString([*]const [4]u8));475 try testing.expect(!isZigString([*]const [4]u8));
476 testing.expect(!isZigString([*c]const u8));476 try testing.expect(!isZigString([*c]const u8));
477 testing.expect(!isZigString([*c]const [4]u8));477 try testing.expect(!isZigString([*c]const [4]u8));
478 testing.expect(!isZigString([*:0]const u8));478 try testing.expect(!isZigString([*:0]const u8));
479 testing.expect(!isZigString([*:0]const u8));479 try testing.expect(!isZigString([*:0]const u8));
480 testing.expect(!isZigString(*[]const u8));480 try testing.expect(!isZigString(*[]const u8));
481 testing.expect(!isZigString(?[]const u8));481 try testing.expect(!isZigString(?[]const u8));
482 testing.expect(!isZigString(?*const [4]u8));482 try testing.expect(!isZigString(?*const [4]u8));
483 testing.expect(!isZigString([]allowzero u8));483 try testing.expect(!isZigString([]allowzero u8));
484 testing.expect(!isZigString([]volatile u8));484 try testing.expect(!isZigString([]volatile u8));
485 testing.expect(!isZigString(*allowzero [4]u8));485 try testing.expect(!isZigString(*allowzero [4]u8));
486 testing.expect(!isZigString(*volatile [4]u8));486 try testing.expect(!isZigString(*volatile [4]u8));
487}487}
488488
489pub fn hasDecls(comptime T: type, comptime names: anytype) bool {489pub fn hasDecls(comptime T: type, comptime names: anytype) bool {
...@@ -505,11 +505,11 @@ test "std.meta.trait.hasDecls" {...@@ -505,11 +505,11 @@ test "std.meta.trait.hasDecls" {
505505
506 const tuple = .{ "a", "b", "c" };506 const tuple = .{ "a", "b", "c" };
507507
508 testing.expect(!hasDecls(TestStruct1, .{"a"}));508 try testing.expect(!hasDecls(TestStruct1, .{"a"}));
509 testing.expect(hasDecls(TestStruct2, .{ "a", "b" }));509 try testing.expect(hasDecls(TestStruct2, .{ "a", "b" }));
510 testing.expect(hasDecls(TestStruct2, .{ "a", "b", "useless" }));510 try testing.expect(hasDecls(TestStruct2, .{ "a", "b", "useless" }));
511 testing.expect(!hasDecls(TestStruct2, .{ "a", "b", "c" }));511 try testing.expect(!hasDecls(TestStruct2, .{ "a", "b", "c" }));
512 testing.expect(!hasDecls(TestStruct2, tuple));512 try testing.expect(!hasDecls(TestStruct2, tuple));
513}513}
514514
515pub fn hasFields(comptime T: type, comptime names: anytype) bool {515pub fn hasFields(comptime T: type, comptime names: anytype) bool {
...@@ -531,11 +531,11 @@ test "std.meta.trait.hasFields" {...@@ -531,11 +531,11 @@ test "std.meta.trait.hasFields" {
531531
532 const tuple = .{ "a", "b", "c" };532 const tuple = .{ "a", "b", "c" };
533533
534 testing.expect(!hasFields(TestStruct1, .{"a"}));534 try testing.expect(!hasFields(TestStruct1, .{"a"}));
535 testing.expect(hasFields(TestStruct2, .{ "a", "b" }));535 try testing.expect(hasFields(TestStruct2, .{ "a", "b" }));
536 testing.expect(hasFields(TestStruct2, .{ "a", "b", "c" }));536 try testing.expect(hasFields(TestStruct2, .{ "a", "b", "c" }));
537 testing.expect(hasFields(TestStruct2, tuple));537 try testing.expect(hasFields(TestStruct2, tuple));
538 testing.expect(!hasFields(TestStruct2, .{ "a", "b", "useless" }));538 try testing.expect(!hasFields(TestStruct2, .{ "a", "b", "useless" }));
539}539}
540540
541pub fn hasFunctions(comptime T: type, comptime names: anytype) bool {541pub fn hasFunctions(comptime T: type, comptime names: anytype) bool {
...@@ -555,10 +555,10 @@ test "std.meta.trait.hasFunctions" {...@@ -555,10 +555,10 @@ test "std.meta.trait.hasFunctions" {
555555
556 const tuple = .{ "a", "b", "c" };556 const tuple = .{ "a", "b", "c" };
557557
558 testing.expect(!hasFunctions(TestStruct1, .{"a"}));558 try testing.expect(!hasFunctions(TestStruct1, .{"a"}));
559 testing.expect(hasFunctions(TestStruct2, .{ "a", "b" }));559 try testing.expect(hasFunctions(TestStruct2, .{ "a", "b" }));
560 testing.expect(!hasFunctions(TestStruct2, .{ "a", "b", "c" }));560 try testing.expect(!hasFunctions(TestStruct2, .{ "a", "b", "c" }));
561 testing.expect(!hasFunctions(TestStruct2, tuple));561 try testing.expect(!hasFunctions(TestStruct2, tuple));
562}562}
563563
564/// True if every value of the type `T` has a unique bit pattern representing it.564/// True if every value of the type `T` has a unique bit pattern representing it.
...@@ -606,65 +606,65 @@ test "std.meta.trait.hasUniqueRepresentation" {...@@ -606,65 +606,65 @@ test "std.meta.trait.hasUniqueRepresentation" {
606 b: u32,606 b: u32,
607 };607 };
608608
609 testing.expect(hasUniqueRepresentation(TestStruct1));609 try testing.expect(hasUniqueRepresentation(TestStruct1));
610610
611 const TestStruct2 = struct {611 const TestStruct2 = struct {
612 a: u32,612 a: u32,
613 b: u16,613 b: u16,
614 };614 };
615615
616 testing.expect(!hasUniqueRepresentation(TestStruct2));616 try testing.expect(!hasUniqueRepresentation(TestStruct2));
617617
618 const TestStruct3 = struct {618 const TestStruct3 = struct {
619 a: u32,619 a: u32,
620 b: u32,620 b: u32,
621 };621 };
622622
623 testing.expect(hasUniqueRepresentation(TestStruct3));623 try testing.expect(hasUniqueRepresentation(TestStruct3));
624624
625 const TestStruct4 = struct { a: []const u8 };625 const TestStruct4 = struct { a: []const u8 };
626626
627 testing.expect(!hasUniqueRepresentation(TestStruct4));627 try testing.expect(!hasUniqueRepresentation(TestStruct4));
628628
629 const TestStruct5 = struct { a: TestStruct4 };629 const TestStruct5 = struct { a: TestStruct4 };
630630
631 testing.expect(!hasUniqueRepresentation(TestStruct5));631 try testing.expect(!hasUniqueRepresentation(TestStruct5));
632632
633 const TestUnion1 = packed union {633 const TestUnion1 = packed union {
634 a: u32,634 a: u32,
635 b: u16,635 b: u16,
636 };636 };
637637
638 testing.expect(!hasUniqueRepresentation(TestUnion1));638 try testing.expect(!hasUniqueRepresentation(TestUnion1));
639639
640 const TestUnion2 = extern union {640 const TestUnion2 = extern union {
641 a: u32,641 a: u32,
642 b: u16,642 b: u16,
643 };643 };
644644
645 testing.expect(!hasUniqueRepresentation(TestUnion2));645 try testing.expect(!hasUniqueRepresentation(TestUnion2));
646646
647 const TestUnion3 = union {647 const TestUnion3 = union {
648 a: u32,648 a: u32,
649 b: u16,649 b: u16,
650 };650 };
651651
652 testing.expect(!hasUniqueRepresentation(TestUnion3));652 try testing.expect(!hasUniqueRepresentation(TestUnion3));
653653
654 const TestUnion4 = union(enum) {654 const TestUnion4 = union(enum) {
655 a: u32,655 a: u32,
656 b: u16,656 b: u16,
657 };657 };
658658
659 testing.expect(!hasUniqueRepresentation(TestUnion4));659 try testing.expect(!hasUniqueRepresentation(TestUnion4));
660660
661 inline for ([_]type{ i0, u8, i16, u32, i64 }) |T| {661 inline for ([_]type{ i0, u8, i16, u32, i64 }) |T| {
662 testing.expect(hasUniqueRepresentation(T));662 try testing.expect(hasUniqueRepresentation(T));
663 }663 }
664 inline for ([_]type{ i1, u9, i17, u33, i24 }) |T| {664 inline for ([_]type{ i1, u9, i17, u33, i24 }) |T| {
665 testing.expect(!hasUniqueRepresentation(T));665 try testing.expect(!hasUniqueRepresentation(T));
666 }666 }
667667
668 testing.expect(!hasUniqueRepresentation([]u8));668 try testing.expect(!hasUniqueRepresentation([]u8));
669 testing.expect(!hasUniqueRepresentation([]const u8));669 try testing.expect(!hasUniqueRepresentation([]const u8));
670}670}
lib/std/multi_array_list.zig+57-57
...@@ -303,7 +303,7 @@ test "basic usage" {...@@ -303,7 +303,7 @@ test "basic usage" {
303 var list = MultiArrayList(Foo){};303 var list = MultiArrayList(Foo){};
304 defer list.deinit(ally);304 defer list.deinit(ally);
305305
306 testing.expectEqual(@as(usize, 0), list.items(.a).len);306 try testing.expectEqual(@as(usize, 0), list.items(.a).len);
307307
308 try list.ensureCapacity(ally, 2);308 try list.ensureCapacity(ally, 2);
309309
...@@ -319,12 +319,12 @@ test "basic usage" {...@@ -319,12 +319,12 @@ test "basic usage" {
319 .c = 'b',319 .c = 'b',
320 });320 });
321321
322 testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 1, 2 });322 try testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 1, 2 });
323 testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'a', 'b' });323 try testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'a', 'b' });
324324
325 testing.expectEqual(@as(usize, 2), list.items(.b).len);325 try testing.expectEqual(@as(usize, 2), list.items(.b).len);
326 testing.expectEqualStrings("foobar", list.items(.b)[0]);326 try testing.expectEqualStrings("foobar", list.items(.b)[0]);
327 testing.expectEqualStrings("zigzag", list.items(.b)[1]);327 try testing.expectEqualStrings("zigzag", list.items(.b)[1]);
328328
329 try list.append(ally, .{329 try list.append(ally, .{
330 .a = 3,330 .a = 3,
...@@ -332,13 +332,13 @@ test "basic usage" {...@@ -332,13 +332,13 @@ test "basic usage" {
332 .c = 'c',332 .c = 'c',
333 });333 });
334334
335 testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 1, 2, 3 });335 try testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 1, 2, 3 });
336 testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'a', 'b', 'c' });336 try testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'a', 'b', 'c' });
337337
338 testing.expectEqual(@as(usize, 3), list.items(.b).len);338 try testing.expectEqual(@as(usize, 3), list.items(.b).len);
339 testing.expectEqualStrings("foobar", list.items(.b)[0]);339 try testing.expectEqualStrings("foobar", list.items(.b)[0]);
340 testing.expectEqualStrings("zigzag", list.items(.b)[1]);340 try testing.expectEqualStrings("zigzag", list.items(.b)[1]);
341 testing.expectEqualStrings("fizzbuzz", list.items(.b)[2]);341 try testing.expectEqualStrings("fizzbuzz", list.items(.b)[2]);
342342
343 // Add 6 more things to force a capacity increase.343 // Add 6 more things to force a capacity increase.
344 var i: usize = 0;344 var i: usize = 0;
...@@ -350,12 +350,12 @@ test "basic usage" {...@@ -350,12 +350,12 @@ test "basic usage" {
350 });350 });
351 }351 }
352352
353 testing.expectEqualSlices(353 try testing.expectEqualSlices(
354 u32,354 u32,
355 &[_]u32{ 1, 2, 3, 4, 5, 6, 7, 8, 9 },355 &[_]u32{ 1, 2, 3, 4, 5, 6, 7, 8, 9 },
356 list.items(.a),356 list.items(.a),
357 );357 );
358 testing.expectEqualSlices(358 try testing.expectEqualSlices(
359 u8,359 u8,
360 &[_]u8{ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i' },360 &[_]u8{ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i' },
361 list.items(.c),361 list.items(.c),
...@@ -363,13 +363,13 @@ test "basic usage" {...@@ -363,13 +363,13 @@ test "basic usage" {
363363
364 list.shrinkAndFree(ally, 3);364 list.shrinkAndFree(ally, 3);
365365
366 testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 1, 2, 3 });366 try testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 1, 2, 3 });
367 testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'a', 'b', 'c' });367 try testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'a', 'b', 'c' });
368368
369 testing.expectEqual(@as(usize, 3), list.items(.b).len);369 try testing.expectEqual(@as(usize, 3), list.items(.b).len);
370 testing.expectEqualStrings("foobar", list.items(.b)[0]);370 try testing.expectEqualStrings("foobar", list.items(.b)[0]);
371 testing.expectEqualStrings("zigzag", list.items(.b)[1]);371 try testing.expectEqualStrings("zigzag", list.items(.b)[1]);
372 testing.expectEqualStrings("fizzbuzz", list.items(.b)[2]);372 try testing.expectEqualStrings("fizzbuzz", list.items(.b)[2]);
373}373}
374374
375// This was observed to fail on aarch64 with LLVM 11, when the capacityInBytes375// This was observed to fail on aarch64 with LLVM 11, when the capacityInBytes
...@@ -418,37 +418,37 @@ test "regression test for @reduce bug" {...@@ -418,37 +418,37 @@ test "regression test for @reduce bug" {
418 try list.append(ally, .{ .tag = .eof, .start = 123 });418 try list.append(ally, .{ .tag = .eof, .start = 123 });
419419
420 const tags = list.items(.tag);420 const tags = list.items(.tag);
421 testing.expectEqual(tags[1], .identifier);421 try testing.expectEqual(tags[1], .identifier);
422 testing.expectEqual(tags[2], .equal);422 try testing.expectEqual(tags[2], .equal);
423 testing.expectEqual(tags[3], .builtin);423 try testing.expectEqual(tags[3], .builtin);
424 testing.expectEqual(tags[4], .l_paren);424 try testing.expectEqual(tags[4], .l_paren);
425 testing.expectEqual(tags[5], .string_literal);425 try testing.expectEqual(tags[5], .string_literal);
426 testing.expectEqual(tags[6], .r_paren);426 try testing.expectEqual(tags[6], .r_paren);
427 testing.expectEqual(tags[7], .semicolon);427 try testing.expectEqual(tags[7], .semicolon);
428 testing.expectEqual(tags[8], .keyword_pub);428 try testing.expectEqual(tags[8], .keyword_pub);
429 testing.expectEqual(tags[9], .keyword_fn);429 try testing.expectEqual(tags[9], .keyword_fn);
430 testing.expectEqual(tags[10], .identifier);430 try testing.expectEqual(tags[10], .identifier);
431 testing.expectEqual(tags[11], .l_paren);431 try testing.expectEqual(tags[11], .l_paren);
432 testing.expectEqual(tags[12], .r_paren);432 try testing.expectEqual(tags[12], .r_paren);
433 testing.expectEqual(tags[13], .identifier);433 try testing.expectEqual(tags[13], .identifier);
434 testing.expectEqual(tags[14], .bang);434 try testing.expectEqual(tags[14], .bang);
435 testing.expectEqual(tags[15], .identifier);435 try testing.expectEqual(tags[15], .identifier);
436 testing.expectEqual(tags[16], .l_brace);436 try testing.expectEqual(tags[16], .l_brace);
437 testing.expectEqual(tags[17], .identifier);437 try testing.expectEqual(tags[17], .identifier);
438 testing.expectEqual(tags[18], .period);438 try testing.expectEqual(tags[18], .period);
439 testing.expectEqual(tags[19], .identifier);439 try testing.expectEqual(tags[19], .identifier);
440 testing.expectEqual(tags[20], .period);440 try testing.expectEqual(tags[20], .period);
441 testing.expectEqual(tags[21], .identifier);441 try testing.expectEqual(tags[21], .identifier);
442 testing.expectEqual(tags[22], .l_paren);442 try testing.expectEqual(tags[22], .l_paren);
443 testing.expectEqual(tags[23], .string_literal);443 try testing.expectEqual(tags[23], .string_literal);
444 testing.expectEqual(tags[24], .comma);444 try testing.expectEqual(tags[24], .comma);
445 testing.expectEqual(tags[25], .period);445 try testing.expectEqual(tags[25], .period);
446 testing.expectEqual(tags[26], .l_brace);446 try testing.expectEqual(tags[26], .l_brace);
447 testing.expectEqual(tags[27], .r_brace);447 try testing.expectEqual(tags[27], .r_brace);
448 testing.expectEqual(tags[28], .r_paren);448 try testing.expectEqual(tags[28], .r_paren);
449 testing.expectEqual(tags[29], .semicolon);449 try testing.expectEqual(tags[29], .semicolon);
450 testing.expectEqual(tags[30], .r_brace);450 try testing.expectEqual(tags[30], .r_brace);
451 testing.expectEqual(tags[31], .eof);451 try testing.expectEqual(tags[31], .eof);
452}452}
453453
454test "ensure capacity on empty list" {454test "ensure capacity on empty list" {
...@@ -466,15 +466,15 @@ test "ensure capacity on empty list" {...@@ -466,15 +466,15 @@ test "ensure capacity on empty list" {
466 list.appendAssumeCapacity(.{ .a = 1, .b = 2 });466 list.appendAssumeCapacity(.{ .a = 1, .b = 2 });
467 list.appendAssumeCapacity(.{ .a = 3, .b = 4 });467 list.appendAssumeCapacity(.{ .a = 3, .b = 4 });
468468
469 testing.expectEqualSlices(u32, &[_]u32{ 1, 3 }, list.items(.a));469 try testing.expectEqualSlices(u32, &[_]u32{ 1, 3 }, list.items(.a));
470 testing.expectEqualSlices(u8, &[_]u8{ 2, 4 }, list.items(.b));470 try testing.expectEqualSlices(u8, &[_]u8{ 2, 4 }, list.items(.b));
471471
472 list.len = 0;472 list.len = 0;
473 list.appendAssumeCapacity(.{ .a = 5, .b = 6 });473 list.appendAssumeCapacity(.{ .a = 5, .b = 6 });
474 list.appendAssumeCapacity(.{ .a = 7, .b = 8 });474 list.appendAssumeCapacity(.{ .a = 7, .b = 8 });
475475
476 testing.expectEqualSlices(u32, &[_]u32{ 5, 7 }, list.items(.a));476 try testing.expectEqualSlices(u32, &[_]u32{ 5, 7 }, list.items(.a));
477 testing.expectEqualSlices(u8, &[_]u8{ 6, 8 }, list.items(.b));477 try testing.expectEqualSlices(u8, &[_]u8{ 6, 8 }, list.items(.b));
478478
479 list.len = 0;479 list.len = 0;
480 try list.ensureCapacity(ally, 16);480 try list.ensureCapacity(ally, 16);
...@@ -482,6 +482,6 @@ test "ensure capacity on empty list" {...@@ -482,6 +482,6 @@ test "ensure capacity on empty list" {
482 list.appendAssumeCapacity(.{ .a = 9, .b = 10 });482 list.appendAssumeCapacity(.{ .a = 9, .b = 10 });
483 list.appendAssumeCapacity(.{ .a = 11, .b = 12 });483 list.appendAssumeCapacity(.{ .a = 11, .b = 12 });
484484
485 testing.expectEqualSlices(u32, &[_]u32{ 9, 11 }, list.items(.a));485 try testing.expectEqualSlices(u32, &[_]u32{ 9, 11 }, list.items(.a));
486 testing.expectEqualSlices(u8, &[_]u8{ 10, 12 }, list.items(.b));486 try testing.expectEqualSlices(u8, &[_]u8{ 10, 12 }, list.items(.b));
487}487}
lib/std/net/test.zig+24-24
...@@ -38,26 +38,26 @@ test "parse and render IPv6 addresses" {...@@ -38,26 +38,26 @@ test "parse and render IPv6 addresses" {
38 for (ips) |ip, i| {38 for (ips) |ip, i| {
39 var addr = net.Address.parseIp6(ip, 0) catch unreachable;39 var addr = net.Address.parseIp6(ip, 0) catch unreachable;
40 var newIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr}) catch unreachable;40 var newIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr}) catch unreachable;
41 std.testing.expect(std.mem.eql(u8, printed[i], newIp[1 .. newIp.len - 3]));41 try std.testing.expect(std.mem.eql(u8, printed[i], newIp[1 .. newIp.len - 3]));
4242
43 if (std.builtin.os.tag == .linux) {43 if (std.builtin.os.tag == .linux) {
44 var addr_via_resolve = net.Address.resolveIp6(ip, 0) catch unreachable;44 var addr_via_resolve = net.Address.resolveIp6(ip, 0) catch unreachable;
45 var newResolvedIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr_via_resolve}) catch unreachable;45 var newResolvedIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr_via_resolve}) catch unreachable;
46 std.testing.expect(std.mem.eql(u8, printed[i], newResolvedIp[1 .. newResolvedIp.len - 3]));46 try std.testing.expect(std.mem.eql(u8, printed[i], newResolvedIp[1 .. newResolvedIp.len - 3]));
47 }47 }
48 }48 }
4949
50 testing.expectError(error.InvalidCharacter, net.Address.parseIp6(":::", 0));50 try testing.expectError(error.InvalidCharacter, net.Address.parseIp6(":::", 0));
51 testing.expectError(error.Overflow, net.Address.parseIp6("FF001::FB", 0));51 try testing.expectError(error.Overflow, net.Address.parseIp6("FF001::FB", 0));
52 testing.expectError(error.InvalidCharacter, net.Address.parseIp6("FF01::Fb:zig", 0));52 try testing.expectError(error.InvalidCharacter, net.Address.parseIp6("FF01::Fb:zig", 0));
53 testing.expectError(error.InvalidEnd, net.Address.parseIp6("FF01:0:0:0:0:0:0:FB:", 0));53 try testing.expectError(error.InvalidEnd, net.Address.parseIp6("FF01:0:0:0:0:0:0:FB:", 0));
54 testing.expectError(error.Incomplete, net.Address.parseIp6("FF01:", 0));54 try testing.expectError(error.Incomplete, net.Address.parseIp6("FF01:", 0));
55 testing.expectError(error.InvalidIpv4Mapping, net.Address.parseIp6("::123.123.123.123", 0));55 try testing.expectError(error.InvalidIpv4Mapping, net.Address.parseIp6("::123.123.123.123", 0));
56 // TODO Make this test pass on other operating systems.56 // TODO Make this test pass on other operating systems.
57 if (std.builtin.os.tag == .linux) {57 if (std.builtin.os.tag == .linux) {
58 testing.expectError(error.Incomplete, net.Address.resolveIp6("ff01::fb%", 0));58 try testing.expectError(error.Incomplete, net.Address.resolveIp6("ff01::fb%", 0));
59 testing.expectError(error.Overflow, net.Address.resolveIp6("ff01::fb%wlp3s0s0s0s0s0s0s0s0", 0));59 try testing.expectError(error.Overflow, net.Address.resolveIp6("ff01::fb%wlp3s0s0s0s0s0s0s0s0", 0));
60 testing.expectError(error.Overflow, net.Address.resolveIp6("ff01::fb%12345678901234", 0));60 try testing.expectError(error.Overflow, net.Address.resolveIp6("ff01::fb%12345678901234", 0));
61 }61 }
62}62}
6363
...@@ -68,7 +68,7 @@ test "invalid but parseable IPv6 scope ids" {...@@ -68,7 +68,7 @@ test "invalid but parseable IPv6 scope ids" {
68 return error.SkipZigTest;68 return error.SkipZigTest;
69 }69 }
7070
71 testing.expectError(error.InterfaceNotFound, net.Address.resolveIp6("ff01::fb%123s45678901234", 0));71 try testing.expectError(error.InterfaceNotFound, net.Address.resolveIp6("ff01::fb%123s45678901234", 0));
72}72}
7373
74test "parse and render IPv4 addresses" {74test "parse and render IPv4 addresses" {
...@@ -84,14 +84,14 @@ test "parse and render IPv4 addresses" {...@@ -84,14 +84,14 @@ test "parse and render IPv4 addresses" {
84 }) |ip| {84 }) |ip| {
85 var addr = net.Address.parseIp4(ip, 0) catch unreachable;85 var addr = net.Address.parseIp4(ip, 0) catch unreachable;
86 var newIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr}) catch unreachable;86 var newIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr}) catch unreachable;
87 std.testing.expect(std.mem.eql(u8, ip, newIp[0 .. newIp.len - 2]));87 try std.testing.expect(std.mem.eql(u8, ip, newIp[0 .. newIp.len - 2]));
88 }88 }
8989
90 testing.expectError(error.Overflow, net.Address.parseIp4("256.0.0.1", 0));90 try testing.expectError(error.Overflow, net.Address.parseIp4("256.0.0.1", 0));
91 testing.expectError(error.InvalidCharacter, net.Address.parseIp4("x.0.0.1", 0));91 try testing.expectError(error.InvalidCharacter, net.Address.parseIp4("x.0.0.1", 0));
92 testing.expectError(error.InvalidEnd, net.Address.parseIp4("127.0.0.1.1", 0));92 try testing.expectError(error.InvalidEnd, net.Address.parseIp4("127.0.0.1.1", 0));
93 testing.expectError(error.Incomplete, net.Address.parseIp4("127.0.0.", 0));93 try testing.expectError(error.Incomplete, net.Address.parseIp4("127.0.0.", 0));
94 testing.expectError(error.InvalidCharacter, net.Address.parseIp4("100..0.1", 0));94 try testing.expectError(error.InvalidCharacter, net.Address.parseIp4("100..0.1", 0));
95}95}
9696
97test "resolve DNS" {97test "resolve DNS" {
...@@ -169,8 +169,8 @@ test "listen on a port, send bytes, receive bytes" {...@@ -169,8 +169,8 @@ test "listen on a port, send bytes, receive bytes" {
169 var buf: [16]u8 = undefined;169 var buf: [16]u8 = undefined;
170 const n = try client.stream.reader().read(&buf);170 const n = try client.stream.reader().read(&buf);
171171
172 testing.expectEqual(@as(usize, 12), n);172 try testing.expectEqual(@as(usize, 12), n);
173 testing.expectEqualSlices(u8, "Hello world!", buf[0..n]);173 try testing.expectEqualSlices(u8, "Hello world!", buf[0..n]);
174}174}
175175
176test "listen on a port, send bytes, receive bytes" {176test "listen on a port, send bytes, receive bytes" {
...@@ -230,7 +230,7 @@ fn testClientToHost(allocator: *mem.Allocator, name: []const u8, port: u16) anye...@@ -230,7 +230,7 @@ fn testClientToHost(allocator: *mem.Allocator, name: []const u8, port: u16) anye
230 var buf: [100]u8 = undefined;230 var buf: [100]u8 = undefined;
231 const len = try connection.read(&buf);231 const len = try connection.read(&buf);
232 const msg = buf[0..len];232 const msg = buf[0..len];
233 testing.expect(mem.eql(u8, msg, "hello from server\n"));233 try testing.expect(mem.eql(u8, msg, "hello from server\n"));
234}234}
235235
236fn testClient(addr: net.Address) anyerror!void {236fn testClient(addr: net.Address) anyerror!void {
...@@ -242,7 +242,7 @@ fn testClient(addr: net.Address) anyerror!void {...@@ -242,7 +242,7 @@ fn testClient(addr: net.Address) anyerror!void {
242 var buf: [100]u8 = undefined;242 var buf: [100]u8 = undefined;
243 const len = try socket_file.read(&buf);243 const len = try socket_file.read(&buf);
244 const msg = buf[0..len];244 const msg = buf[0..len];
245 testing.expect(mem.eql(u8, msg, "hello from server\n"));245 try testing.expect(mem.eql(u8, msg, "hello from server\n"));
246}246}
247247
248fn testServer(server: *net.StreamServer) anyerror!void {248fn testServer(server: *net.StreamServer) anyerror!void {
...@@ -293,6 +293,6 @@ test "listen on a unix socket, send bytes, receive bytes" {...@@ -293,6 +293,6 @@ test "listen on a unix socket, send bytes, receive bytes" {
293 var buf: [16]u8 = undefined;293 var buf: [16]u8 = undefined;
294 const n = try client.stream.reader().read(&buf);294 const n = try client.stream.reader().read(&buf);
295295
296 testing.expectEqual(@as(usize, 12), n);296 try testing.expectEqual(@as(usize, 12), n);
297 testing.expectEqualSlices(u8, "Hello world!", buf[0..n]);297 try testing.expectEqualSlices(u8, "Hello world!", buf[0..n]);
298}298}
lib/std/once.zig+1-1
...@@ -67,5 +67,5 @@ test "Once executes its function just once" {...@@ -67,5 +67,5 @@ test "Once executes its function just once" {
67 }67 }
68 }68 }
6969
70 testing.expectEqual(@as(i32, 1), global_number);70 try testing.expectEqual(@as(i32, 1), global_number);
71}71}
lib/std/os/linux/bpf.zig+100-100
...@@ -737,11 +737,11 @@ pub const Insn = packed struct {...@@ -737,11 +737,11 @@ pub const Insn = packed struct {
737};737};
738738
739test "insn bitsize" {739test "insn bitsize" {
740 expectEqual(@bitSizeOf(Insn), 64);740 try expectEqual(@bitSizeOf(Insn), 64);
741}741}
742742
743fn expect_opcode(code: u8, insn: Insn) void {743fn expect_opcode(code: u8, insn: Insn) !void {
744 expectEqual(code, insn.code);744 try expectEqual(code, insn.code);
745}745}
746746
747// The opcodes were grabbed from https://github.com/iovisor/bpf-docs/blob/master/eBPF.md747// The opcodes were grabbed from https://github.com/iovisor/bpf-docs/blob/master/eBPF.md
...@@ -750,108 +750,108 @@ test "opcodes" {...@@ -750,108 +750,108 @@ test "opcodes" {
750 // loading 64-bit immediates (imm is only 32 bits wide)750 // loading 64-bit immediates (imm is only 32 bits wide)
751751
752 // alu instructions752 // alu instructions
753 expect_opcode(0x07, Insn.add(.r1, 0));753 try expect_opcode(0x07, Insn.add(.r1, 0));
754 expect_opcode(0x0f, Insn.add(.r1, .r2));754 try expect_opcode(0x0f, Insn.add(.r1, .r2));
755 expect_opcode(0x17, Insn.sub(.r1, 0));755 try expect_opcode(0x17, Insn.sub(.r1, 0));
756 expect_opcode(0x1f, Insn.sub(.r1, .r2));756 try expect_opcode(0x1f, Insn.sub(.r1, .r2));
757 expect_opcode(0x27, Insn.mul(.r1, 0));757 try expect_opcode(0x27, Insn.mul(.r1, 0));
758 expect_opcode(0x2f, Insn.mul(.r1, .r2));758 try expect_opcode(0x2f, Insn.mul(.r1, .r2));
759 expect_opcode(0x37, Insn.div(.r1, 0));759 try expect_opcode(0x37, Insn.div(.r1, 0));
760 expect_opcode(0x3f, Insn.div(.r1, .r2));760 try expect_opcode(0x3f, Insn.div(.r1, .r2));
761 expect_opcode(0x47, Insn.alu_or(.r1, 0));761 try expect_opcode(0x47, Insn.alu_or(.r1, 0));
762 expect_opcode(0x4f, Insn.alu_or(.r1, .r2));762 try expect_opcode(0x4f, Insn.alu_or(.r1, .r2));
763 expect_opcode(0x57, Insn.alu_and(.r1, 0));763 try expect_opcode(0x57, Insn.alu_and(.r1, 0));
764 expect_opcode(0x5f, Insn.alu_and(.r1, .r2));764 try expect_opcode(0x5f, Insn.alu_and(.r1, .r2));
765 expect_opcode(0x67, Insn.lsh(.r1, 0));765 try expect_opcode(0x67, Insn.lsh(.r1, 0));
766 expect_opcode(0x6f, Insn.lsh(.r1, .r2));766 try expect_opcode(0x6f, Insn.lsh(.r1, .r2));
767 expect_opcode(0x77, Insn.rsh(.r1, 0));767 try expect_opcode(0x77, Insn.rsh(.r1, 0));
768 expect_opcode(0x7f, Insn.rsh(.r1, .r2));768 try expect_opcode(0x7f, Insn.rsh(.r1, .r2));
769 expect_opcode(0x87, Insn.neg(.r1));769 try expect_opcode(0x87, Insn.neg(.r1));
770 expect_opcode(0x97, Insn.mod(.r1, 0));770 try expect_opcode(0x97, Insn.mod(.r1, 0));
771 expect_opcode(0x9f, Insn.mod(.r1, .r2));771 try expect_opcode(0x9f, Insn.mod(.r1, .r2));
772 expect_opcode(0xa7, Insn.xor(.r1, 0));772 try expect_opcode(0xa7, Insn.xor(.r1, 0));
773 expect_opcode(0xaf, Insn.xor(.r1, .r2));773 try expect_opcode(0xaf, Insn.xor(.r1, .r2));
774 expect_opcode(0xb7, Insn.mov(.r1, 0));774 try expect_opcode(0xb7, Insn.mov(.r1, 0));
775 expect_opcode(0xbf, Insn.mov(.r1, .r2));775 try expect_opcode(0xbf, Insn.mov(.r1, .r2));
776 expect_opcode(0xc7, Insn.arsh(.r1, 0));776 try expect_opcode(0xc7, Insn.arsh(.r1, 0));
777 expect_opcode(0xcf, Insn.arsh(.r1, .r2));777 try expect_opcode(0xcf, Insn.arsh(.r1, .r2));
778778
779 // atomic instructions: might be more of these not documented in the wild779 // atomic instructions: might be more of these not documented in the wild
780 expect_opcode(0xdb, Insn.xadd(.r1, .r2));780 try expect_opcode(0xdb, Insn.xadd(.r1, .r2));
781781
782 // TODO: byteswap instructions782 // TODO: byteswap instructions
783 expect_opcode(0xd4, Insn.le(.half_word, .r1));783 try expect_opcode(0xd4, Insn.le(.half_word, .r1));
784 expectEqual(@intCast(i32, 16), Insn.le(.half_word, .r1).imm);784 try expectEqual(@intCast(i32, 16), Insn.le(.half_word, .r1).imm);
785 expect_opcode(0xd4, Insn.le(.word, .r1));785 try expect_opcode(0xd4, Insn.le(.word, .r1));
786 expectEqual(@intCast(i32, 32), Insn.le(.word, .r1).imm);786 try expectEqual(@intCast(i32, 32), Insn.le(.word, .r1).imm);
787 expect_opcode(0xd4, Insn.le(.double_word, .r1));787 try expect_opcode(0xd4, Insn.le(.double_word, .r1));
788 expectEqual(@intCast(i32, 64), Insn.le(.double_word, .r1).imm);788 try expectEqual(@intCast(i32, 64), Insn.le(.double_word, .r1).imm);
789 expect_opcode(0xdc, Insn.be(.half_word, .r1));789 try expect_opcode(0xdc, Insn.be(.half_word, .r1));
790 expectEqual(@intCast(i32, 16), Insn.be(.half_word, .r1).imm);790 try expectEqual(@intCast(i32, 16), Insn.be(.half_word, .r1).imm);
791 expect_opcode(0xdc, Insn.be(.word, .r1));791 try expect_opcode(0xdc, Insn.be(.word, .r1));
792 expectEqual(@intCast(i32, 32), Insn.be(.word, .r1).imm);792 try expectEqual(@intCast(i32, 32), Insn.be(.word, .r1).imm);
793 expect_opcode(0xdc, Insn.be(.double_word, .r1));793 try expect_opcode(0xdc, Insn.be(.double_word, .r1));
794 expectEqual(@intCast(i32, 64), Insn.be(.double_word, .r1).imm);794 try expectEqual(@intCast(i32, 64), Insn.be(.double_word, .r1).imm);
795795
796 // memory instructions796 // memory instructions
797 expect_opcode(0x18, Insn.ld_dw1(.r1, 0));797 try expect_opcode(0x18, Insn.ld_dw1(.r1, 0));
798 expect_opcode(0x00, Insn.ld_dw2(0));798 try expect_opcode(0x00, Insn.ld_dw2(0));
799799
800 // loading a map fd800 // loading a map fd
801 expect_opcode(0x18, Insn.ld_map_fd1(.r1, 0));801 try expect_opcode(0x18, Insn.ld_map_fd1(.r1, 0));
802 expectEqual(@intCast(u4, PSEUDO_MAP_FD), Insn.ld_map_fd1(.r1, 0).src);802 try expectEqual(@intCast(u4, PSEUDO_MAP_FD), Insn.ld_map_fd1(.r1, 0).src);
803 expect_opcode(0x00, Insn.ld_map_fd2(0));803 try expect_opcode(0x00, Insn.ld_map_fd2(0));
804804
805 expect_opcode(0x38, Insn.ld_abs(.double_word, .r1, .r2, 0));805 try expect_opcode(0x38, Insn.ld_abs(.double_word, .r1, .r2, 0));
806 expect_opcode(0x20, Insn.ld_abs(.word, .r1, .r2, 0));806 try expect_opcode(0x20, Insn.ld_abs(.word, .r1, .r2, 0));
807 expect_opcode(0x28, Insn.ld_abs(.half_word, .r1, .r2, 0));807 try expect_opcode(0x28, Insn.ld_abs(.half_word, .r1, .r2, 0));
808 expect_opcode(0x30, Insn.ld_abs(.byte, .r1, .r2, 0));808 try expect_opcode(0x30, Insn.ld_abs(.byte, .r1, .r2, 0));
809809
810 expect_opcode(0x58, Insn.ld_ind(.double_word, .r1, .r2, 0));810 try expect_opcode(0x58, Insn.ld_ind(.double_word, .r1, .r2, 0));
811 expect_opcode(0x40, Insn.ld_ind(.word, .r1, .r2, 0));811 try expect_opcode(0x40, Insn.ld_ind(.word, .r1, .r2, 0));
812 expect_opcode(0x48, Insn.ld_ind(.half_word, .r1, .r2, 0));812 try expect_opcode(0x48, Insn.ld_ind(.half_word, .r1, .r2, 0));
813 expect_opcode(0x50, Insn.ld_ind(.byte, .r1, .r2, 0));813 try expect_opcode(0x50, Insn.ld_ind(.byte, .r1, .r2, 0));
814814
815 expect_opcode(0x79, Insn.ldx(.double_word, .r1, .r2, 0));815 try expect_opcode(0x79, Insn.ldx(.double_word, .r1, .r2, 0));
816 expect_opcode(0x61, Insn.ldx(.word, .r1, .r2, 0));816 try expect_opcode(0x61, Insn.ldx(.word, .r1, .r2, 0));
817 expect_opcode(0x69, Insn.ldx(.half_word, .r1, .r2, 0));817 try expect_opcode(0x69, Insn.ldx(.half_word, .r1, .r2, 0));
818 expect_opcode(0x71, Insn.ldx(.byte, .r1, .r2, 0));818 try expect_opcode(0x71, Insn.ldx(.byte, .r1, .r2, 0));
819819
820 expect_opcode(0x62, Insn.st(.word, .r1, 0, 0));820 try expect_opcode(0x62, Insn.st(.word, .r1, 0, 0));
821 expect_opcode(0x6a, Insn.st(.half_word, .r1, 0, 0));821 try expect_opcode(0x6a, Insn.st(.half_word, .r1, 0, 0));
822 expect_opcode(0x72, Insn.st(.byte, .r1, 0, 0));822 try expect_opcode(0x72, Insn.st(.byte, .r1, 0, 0));
823823
824 expect_opcode(0x63, Insn.stx(.word, .r1, 0, .r2));824 try expect_opcode(0x63, Insn.stx(.word, .r1, 0, .r2));
825 expect_opcode(0x6b, Insn.stx(.half_word, .r1, 0, .r2));825 try expect_opcode(0x6b, Insn.stx(.half_word, .r1, 0, .r2));
826 expect_opcode(0x73, Insn.stx(.byte, .r1, 0, .r2));826 try expect_opcode(0x73, Insn.stx(.byte, .r1, 0, .r2));
827 expect_opcode(0x7b, Insn.stx(.double_word, .r1, 0, .r2));827 try expect_opcode(0x7b, Insn.stx(.double_word, .r1, 0, .r2));
828828
829 // branch instructions829 // branch instructions
830 expect_opcode(0x05, Insn.ja(0));830 try expect_opcode(0x05, Insn.ja(0));
831 expect_opcode(0x15, Insn.jeq(.r1, 0, 0));831 try expect_opcode(0x15, Insn.jeq(.r1, 0, 0));
832 expect_opcode(0x1d, Insn.jeq(.r1, .r2, 0));832 try expect_opcode(0x1d, Insn.jeq(.r1, .r2, 0));
833 expect_opcode(0x25, Insn.jgt(.r1, 0, 0));833 try expect_opcode(0x25, Insn.jgt(.r1, 0, 0));
834 expect_opcode(0x2d, Insn.jgt(.r1, .r2, 0));834 try expect_opcode(0x2d, Insn.jgt(.r1, .r2, 0));
835 expect_opcode(0x35, Insn.jge(.r1, 0, 0));835 try expect_opcode(0x35, Insn.jge(.r1, 0, 0));
836 expect_opcode(0x3d, Insn.jge(.r1, .r2, 0));836 try expect_opcode(0x3d, Insn.jge(.r1, .r2, 0));
837 expect_opcode(0xa5, Insn.jlt(.r1, 0, 0));837 try expect_opcode(0xa5, Insn.jlt(.r1, 0, 0));
838 expect_opcode(0xad, Insn.jlt(.r1, .r2, 0));838 try expect_opcode(0xad, Insn.jlt(.r1, .r2, 0));
839 expect_opcode(0xb5, Insn.jle(.r1, 0, 0));839 try expect_opcode(0xb5, Insn.jle(.r1, 0, 0));
840 expect_opcode(0xbd, Insn.jle(.r1, .r2, 0));840 try expect_opcode(0xbd, Insn.jle(.r1, .r2, 0));
841 expect_opcode(0x45, Insn.jset(.r1, 0, 0));841 try expect_opcode(0x45, Insn.jset(.r1, 0, 0));
842 expect_opcode(0x4d, Insn.jset(.r1, .r2, 0));842 try expect_opcode(0x4d, Insn.jset(.r1, .r2, 0));
843 expect_opcode(0x55, Insn.jne(.r1, 0, 0));843 try expect_opcode(0x55, Insn.jne(.r1, 0, 0));
844 expect_opcode(0x5d, Insn.jne(.r1, .r2, 0));844 try expect_opcode(0x5d, Insn.jne(.r1, .r2, 0));
845 expect_opcode(0x65, Insn.jsgt(.r1, 0, 0));845 try expect_opcode(0x65, Insn.jsgt(.r1, 0, 0));
846 expect_opcode(0x6d, Insn.jsgt(.r1, .r2, 0));846 try expect_opcode(0x6d, Insn.jsgt(.r1, .r2, 0));
847 expect_opcode(0x75, Insn.jsge(.r1, 0, 0));847 try expect_opcode(0x75, Insn.jsge(.r1, 0, 0));
848 expect_opcode(0x7d, Insn.jsge(.r1, .r2, 0));848 try expect_opcode(0x7d, Insn.jsge(.r1, .r2, 0));
849 expect_opcode(0xc5, Insn.jslt(.r1, 0, 0));849 try expect_opcode(0xc5, Insn.jslt(.r1, 0, 0));
850 expect_opcode(0xcd, Insn.jslt(.r1, .r2, 0));850 try expect_opcode(0xcd, Insn.jslt(.r1, .r2, 0));
851 expect_opcode(0xd5, Insn.jsle(.r1, 0, 0));851 try expect_opcode(0xd5, Insn.jsle(.r1, 0, 0));
852 expect_opcode(0xdd, Insn.jsle(.r1, .r2, 0));852 try expect_opcode(0xdd, Insn.jsle(.r1, .r2, 0));
853 expect_opcode(0x85, Insn.call(.unspec));853 try expect_opcode(0x85, Insn.call(.unspec));
854 expect_opcode(0x95, Insn.exit());854 try expect_opcode(0x95, Insn.exit());
855}855}
856856
857pub const Cmd = extern enum(usize) {857pub const Cmd = extern enum(usize) {
...@@ -1596,7 +1596,7 @@ test "map lookup, update, and delete" {...@@ -1596,7 +1596,7 @@ test "map lookup, update, and delete" {
1596 var value = std.mem.zeroes([value_size]u8);1596 var value = std.mem.zeroes([value_size]u8);
15971597
1598 // fails looking up value that doesn't exist1598 // fails looking up value that doesn't exist
1599 expectError(error.NotFound, map_lookup_elem(map, &key, &value));1599 try expectError(error.NotFound, map_lookup_elem(map, &key, &value));
16001600
1601 // succeed at updating and looking up element1601 // succeed at updating and looking up element
1602 try map_update_elem(map, &key, &value, 0);1602 try map_update_elem(map, &key, &value, 0);
...@@ -1604,14 +1604,14 @@ test "map lookup, update, and delete" {...@@ -1604,14 +1604,14 @@ test "map lookup, update, and delete" {
16041604
1605 // fails inserting more than max entries1605 // fails inserting more than max entries
1606 const second_key = [key_size]u8{ 0, 0, 0, 1 };1606 const second_key = [key_size]u8{ 0, 0, 0, 1 };
1607 expectError(error.ReachedMaxEntries, map_update_elem(map, &second_key, &value, 0));1607 try expectError(error.ReachedMaxEntries, map_update_elem(map, &second_key, &value, 0));
16081608
1609 // succeed at deleting an existing elem1609 // succeed at deleting an existing elem
1610 try map_delete_elem(map, &key);1610 try map_delete_elem(map, &key);
1611 expectError(error.NotFound, map_lookup_elem(map, &key, &value));1611 try expectError(error.NotFound, map_lookup_elem(map, &key, &value));
16121612
1613 // fail at deleting a non-existing elem1613 // fail at deleting a non-existing elem
1614 expectError(error.NotFound, map_delete_elem(map, &key));1614 try expectError(error.NotFound, map_delete_elem(map, &key));
1615}1615}
16161616
1617pub fn prog_load(1617pub fn prog_load(
...@@ -1662,5 +1662,5 @@ test "prog_load" {...@@ -1662,5 +1662,5 @@ test "prog_load" {
1662 const prog = try prog_load(.socket_filter, &good_prog, null, "MIT", 0);1662 const prog = try prog_load(.socket_filter, &good_prog, null, "MIT", 0);
1663 defer std.os.close(prog);1663 defer std.os.close(prog);
16641664
1665 expectError(error.UnsafeProgram, prog_load(.socket_filter, &bad_prog, null, "MIT", 0));1665 try expectError(error.UnsafeProgram, prog_load(.socket_filter, &bad_prog, null, "MIT", 0));
1666}1666}
lib/std/os/linux/bpf/btf.zig+1-1
...@@ -92,7 +92,7 @@ pub const IntInfo = packed struct {...@@ -92,7 +92,7 @@ pub const IntInfo = packed struct {
92};92};
9393
94test "IntInfo is 32 bits" {94test "IntInfo is 32 bits" {
95 std.testing.expectEqual(@bitSizeOf(IntInfo), 32);95 try std.testing.expectEqual(@bitSizeOf(IntInfo), 32);
96}96}
9797
98/// Enum kind is followed by this struct98/// Enum kind is followed by this struct
lib/std/os/linux/io_uring.zig+104-104
...@@ -937,16 +937,16 @@ pub fn io_uring_prep_fallocate(...@@ -937,16 +937,16 @@ pub fn io_uring_prep_fallocate(
937test "structs/offsets/entries" {937test "structs/offsets/entries" {
938 if (builtin.os.tag != .linux) return error.SkipZigTest;938 if (builtin.os.tag != .linux) return error.SkipZigTest;
939939
940 testing.expectEqual(@as(usize, 120), @sizeOf(io_uring_params));940 try testing.expectEqual(@as(usize, 120), @sizeOf(io_uring_params));
941 testing.expectEqual(@as(usize, 64), @sizeOf(io_uring_sqe));941 try testing.expectEqual(@as(usize, 64), @sizeOf(io_uring_sqe));
942 testing.expectEqual(@as(usize, 16), @sizeOf(io_uring_cqe));942 try testing.expectEqual(@as(usize, 16), @sizeOf(io_uring_cqe));
943943
944 testing.expectEqual(0, linux.IORING_OFF_SQ_RING);944 try testing.expectEqual(0, linux.IORING_OFF_SQ_RING);
945 testing.expectEqual(0x8000000, linux.IORING_OFF_CQ_RING);945 try testing.expectEqual(0x8000000, linux.IORING_OFF_CQ_RING);
946 testing.expectEqual(0x10000000, linux.IORING_OFF_SQES);946 try testing.expectEqual(0x10000000, linux.IORING_OFF_SQES);
947947
948 testing.expectError(error.EntriesZero, IO_Uring.init(0, 0));948 try testing.expectError(error.EntriesZero, IO_Uring.init(0, 0));
949 testing.expectError(error.EntriesNotPowerOfTwo, IO_Uring.init(3, 0));949 try testing.expectError(error.EntriesNotPowerOfTwo, IO_Uring.init(3, 0));
950}950}
951951
952test "nop" {952test "nop" {
...@@ -959,11 +959,11 @@ test "nop" {...@@ -959,11 +959,11 @@ test "nop" {
959 };959 };
960 defer {960 defer {
961 ring.deinit();961 ring.deinit();
962 testing.expectEqual(@as(os.fd_t, -1), ring.fd);962 testing.expectEqual(@as(os.fd_t, -1), ring.fd) catch @panic("test failed");
963 }963 }
964964
965 const sqe = try ring.nop(0xaaaaaaaa);965 const sqe = try ring.nop(0xaaaaaaaa);
966 testing.expectEqual(io_uring_sqe{966 try testing.expectEqual(io_uring_sqe{
967 .opcode = .NOP,967 .opcode = .NOP,
968 .flags = 0,968 .flags = 0,
969 .ioprio = 0,969 .ioprio = 0,
...@@ -979,40 +979,40 @@ test "nop" {...@@ -979,40 +979,40 @@ test "nop" {
979 .__pad2 = [2]u64{ 0, 0 },979 .__pad2 = [2]u64{ 0, 0 },
980 }, sqe.*);980 }, sqe.*);
981981
982 testing.expectEqual(@as(u32, 0), ring.sq.sqe_head);982 try testing.expectEqual(@as(u32, 0), ring.sq.sqe_head);
983 testing.expectEqual(@as(u32, 1), ring.sq.sqe_tail);983 try testing.expectEqual(@as(u32, 1), ring.sq.sqe_tail);
984 testing.expectEqual(@as(u32, 0), ring.sq.tail.*);984 try testing.expectEqual(@as(u32, 0), ring.sq.tail.*);
985 testing.expectEqual(@as(u32, 0), ring.cq.head.*);985 try testing.expectEqual(@as(u32, 0), ring.cq.head.*);
986 testing.expectEqual(@as(u32, 1), ring.sq_ready());986 try testing.expectEqual(@as(u32, 1), ring.sq_ready());
987 testing.expectEqual(@as(u32, 0), ring.cq_ready());987 try testing.expectEqual(@as(u32, 0), ring.cq_ready());
988988
989 testing.expectEqual(@as(u32, 1), try ring.submit());989 try testing.expectEqual(@as(u32, 1), try ring.submit());
990 testing.expectEqual(@as(u32, 1), ring.sq.sqe_head);990 try testing.expectEqual(@as(u32, 1), ring.sq.sqe_head);
991 testing.expectEqual(@as(u32, 1), ring.sq.sqe_tail);991 try testing.expectEqual(@as(u32, 1), ring.sq.sqe_tail);
992 testing.expectEqual(@as(u32, 1), ring.sq.tail.*);992 try testing.expectEqual(@as(u32, 1), ring.sq.tail.*);
993 testing.expectEqual(@as(u32, 0), ring.cq.head.*);993 try testing.expectEqual(@as(u32, 0), ring.cq.head.*);
994 testing.expectEqual(@as(u32, 0), ring.sq_ready());994 try testing.expectEqual(@as(u32, 0), ring.sq_ready());
995995
996 testing.expectEqual(io_uring_cqe{996 try testing.expectEqual(io_uring_cqe{
997 .user_data = 0xaaaaaaaa,997 .user_data = 0xaaaaaaaa,
998 .res = 0,998 .res = 0,
999 .flags = 0,999 .flags = 0,
1000 }, try ring.copy_cqe());1000 }, try ring.copy_cqe());
1001 testing.expectEqual(@as(u32, 1), ring.cq.head.*);1001 try testing.expectEqual(@as(u32, 1), ring.cq.head.*);
1002 testing.expectEqual(@as(u32, 0), ring.cq_ready());1002 try testing.expectEqual(@as(u32, 0), ring.cq_ready());
10031003
1004 const sqe_barrier = try ring.nop(0xbbbbbbbb);1004 const sqe_barrier = try ring.nop(0xbbbbbbbb);
1005 sqe_barrier.flags |= linux.IOSQE_IO_DRAIN;1005 sqe_barrier.flags |= linux.IOSQE_IO_DRAIN;
1006 testing.expectEqual(@as(u32, 1), try ring.submit());1006 try testing.expectEqual(@as(u32, 1), try ring.submit());
1007 testing.expectEqual(io_uring_cqe{1007 try testing.expectEqual(io_uring_cqe{
1008 .user_data = 0xbbbbbbbb,1008 .user_data = 0xbbbbbbbb,
1009 .res = 0,1009 .res = 0,
1010 .flags = 0,1010 .flags = 0,
1011 }, try ring.copy_cqe());1011 }, try ring.copy_cqe());
1012 testing.expectEqual(@as(u32, 2), ring.sq.sqe_head);1012 try testing.expectEqual(@as(u32, 2), ring.sq.sqe_head);
1013 testing.expectEqual(@as(u32, 2), ring.sq.sqe_tail);1013 try testing.expectEqual(@as(u32, 2), ring.sq.sqe_tail);
1014 testing.expectEqual(@as(u32, 2), ring.sq.tail.*);1014 try testing.expectEqual(@as(u32, 2), ring.sq.tail.*);
1015 testing.expectEqual(@as(u32, 2), ring.cq.head.*);1015 try testing.expectEqual(@as(u32, 2), ring.cq.head.*);
1016}1016}
10171017
1018test "readv" {1018test "readv" {
...@@ -1042,17 +1042,17 @@ test "readv" {...@@ -1042,17 +1042,17 @@ test "readv" {
1042 var buffer = [_]u8{42} ** 128;1042 var buffer = [_]u8{42} ** 128;
1043 var iovecs = [_]os.iovec{os.iovec{ .iov_base = &buffer, .iov_len = buffer.len }};1043 var iovecs = [_]os.iovec{os.iovec{ .iov_base = &buffer, .iov_len = buffer.len }};
1044 const sqe = try ring.readv(0xcccccccc, fd_index, iovecs[0..], 0);1044 const sqe = try ring.readv(0xcccccccc, fd_index, iovecs[0..], 0);
1045 testing.expectEqual(linux.IORING_OP.READV, sqe.opcode);1045 try testing.expectEqual(linux.IORING_OP.READV, sqe.opcode);
1046 sqe.flags |= linux.IOSQE_FIXED_FILE;1046 sqe.flags |= linux.IOSQE_FIXED_FILE;
10471047
1048 testing.expectError(error.SubmissionQueueFull, ring.nop(0));1048 try testing.expectError(error.SubmissionQueueFull, ring.nop(0));
1049 testing.expectEqual(@as(u32, 1), try ring.submit());1049 try testing.expectEqual(@as(u32, 1), try ring.submit());
1050 testing.expectEqual(linux.io_uring_cqe{1050 try testing.expectEqual(linux.io_uring_cqe{
1051 .user_data = 0xcccccccc,1051 .user_data = 0xcccccccc,
1052 .res = buffer.len,1052 .res = buffer.len,
1053 .flags = 0,1053 .flags = 0,
1054 }, try ring.copy_cqe());1054 }, try ring.copy_cqe());
1055 testing.expectEqualSlices(u8, &([_]u8{0} ** buffer.len), buffer[0..]);1055 try testing.expectEqualSlices(u8, &([_]u8{0} ** buffer.len), buffer[0..]);
10561056
1057 try ring.unregister_files();1057 try ring.unregister_files();
1058}1058}
...@@ -1083,46 +1083,46 @@ test "writev/fsync/readv" {...@@ -1083,46 +1083,46 @@ test "writev/fsync/readv" {
1083 };1083 };
10841084
1085 const sqe_writev = try ring.writev(0xdddddddd, fd, iovecs_write[0..], 17);1085 const sqe_writev = try ring.writev(0xdddddddd, fd, iovecs_write[0..], 17);
1086 testing.expectEqual(linux.IORING_OP.WRITEV, sqe_writev.opcode);1086 try testing.expectEqual(linux.IORING_OP.WRITEV, sqe_writev.opcode);
1087 testing.expectEqual(@as(u64, 17), sqe_writev.off);1087 try testing.expectEqual(@as(u64, 17), sqe_writev.off);
1088 sqe_writev.flags |= linux.IOSQE_IO_LINK;1088 sqe_writev.flags |= linux.IOSQE_IO_LINK;
10891089
1090 const sqe_fsync = try ring.fsync(0xeeeeeeee, fd, 0);1090 const sqe_fsync = try ring.fsync(0xeeeeeeee, fd, 0);
1091 testing.expectEqual(linux.IORING_OP.FSYNC, sqe_fsync.opcode);1091 try testing.expectEqual(linux.IORING_OP.FSYNC, sqe_fsync.opcode);
1092 testing.expectEqual(fd, sqe_fsync.fd);1092 try testing.expectEqual(fd, sqe_fsync.fd);
1093 sqe_fsync.flags |= linux.IOSQE_IO_LINK;1093 sqe_fsync.flags |= linux.IOSQE_IO_LINK;
10941094
1095 const sqe_readv = try ring.readv(0xffffffff, fd, iovecs_read[0..], 17);1095 const sqe_readv = try ring.readv(0xffffffff, fd, iovecs_read[0..], 17);
1096 testing.expectEqual(linux.IORING_OP.READV, sqe_readv.opcode);1096 try testing.expectEqual(linux.IORING_OP.READV, sqe_readv.opcode);
1097 testing.expectEqual(@as(u64, 17), sqe_readv.off);1097 try testing.expectEqual(@as(u64, 17), sqe_readv.off);
10981098
1099 testing.expectEqual(@as(u32, 3), ring.sq_ready());1099 try testing.expectEqual(@as(u32, 3), ring.sq_ready());
1100 testing.expectEqual(@as(u32, 3), try ring.submit_and_wait(3));1100 try testing.expectEqual(@as(u32, 3), try ring.submit_and_wait(3));
1101 testing.expectEqual(@as(u32, 0), ring.sq_ready());1101 try testing.expectEqual(@as(u32, 0), ring.sq_ready());
1102 testing.expectEqual(@as(u32, 3), ring.cq_ready());1102 try testing.expectEqual(@as(u32, 3), ring.cq_ready());
11031103
1104 testing.expectEqual(linux.io_uring_cqe{1104 try testing.expectEqual(linux.io_uring_cqe{
1105 .user_data = 0xdddddddd,1105 .user_data = 0xdddddddd,
1106 .res = buffer_write.len,1106 .res = buffer_write.len,
1107 .flags = 0,1107 .flags = 0,
1108 }, try ring.copy_cqe());1108 }, try ring.copy_cqe());
1109 testing.expectEqual(@as(u32, 2), ring.cq_ready());1109 try testing.expectEqual(@as(u32, 2), ring.cq_ready());
11101110
1111 testing.expectEqual(linux.io_uring_cqe{1111 try testing.expectEqual(linux.io_uring_cqe{
1112 .user_data = 0xeeeeeeee,1112 .user_data = 0xeeeeeeee,
1113 .res = 0,1113 .res = 0,
1114 .flags = 0,1114 .flags = 0,
1115 }, try ring.copy_cqe());1115 }, try ring.copy_cqe());
1116 testing.expectEqual(@as(u32, 1), ring.cq_ready());1116 try testing.expectEqual(@as(u32, 1), ring.cq_ready());
11171117
1118 testing.expectEqual(linux.io_uring_cqe{1118 try testing.expectEqual(linux.io_uring_cqe{
1119 .user_data = 0xffffffff,1119 .user_data = 0xffffffff,
1120 .res = buffer_read.len,1120 .res = buffer_read.len,
1121 .flags = 0,1121 .flags = 0,
1122 }, try ring.copy_cqe());1122 }, try ring.copy_cqe());
1123 testing.expectEqual(@as(u32, 0), ring.cq_ready());1123 try testing.expectEqual(@as(u32, 0), ring.cq_ready());
11241124
1125 testing.expectEqualSlices(u8, buffer_write[0..], buffer_read[0..]);1125 try testing.expectEqualSlices(u8, buffer_write[0..], buffer_read[0..]);
1126}1126}
11271127
1128test "write/read" {1128test "write/read" {
...@@ -1144,13 +1144,13 @@ test "write/read" {...@@ -1144,13 +1144,13 @@ test "write/read" {
1144 const buffer_write = [_]u8{97} ** 20;1144 const buffer_write = [_]u8{97} ** 20;
1145 var buffer_read = [_]u8{98} ** 20;1145 var buffer_read = [_]u8{98} ** 20;
1146 const sqe_write = try ring.write(0x11111111, fd, buffer_write[0..], 10);1146 const sqe_write = try ring.write(0x11111111, fd, buffer_write[0..], 10);
1147 testing.expectEqual(linux.IORING_OP.WRITE, sqe_write.opcode);1147 try testing.expectEqual(linux.IORING_OP.WRITE, sqe_write.opcode);
1148 testing.expectEqual(@as(u64, 10), sqe_write.off);1148 try testing.expectEqual(@as(u64, 10), sqe_write.off);
1149 sqe_write.flags |= linux.IOSQE_IO_LINK;1149 sqe_write.flags |= linux.IOSQE_IO_LINK;
1150 const sqe_read = try ring.read(0x22222222, fd, buffer_read[0..], 10);1150 const sqe_read = try ring.read(0x22222222, fd, buffer_read[0..], 10);
1151 testing.expectEqual(linux.IORING_OP.READ, sqe_read.opcode);1151 try testing.expectEqual(linux.IORING_OP.READ, sqe_read.opcode);
1152 testing.expectEqual(@as(u64, 10), sqe_read.off);1152 try testing.expectEqual(@as(u64, 10), sqe_read.off);
1153 testing.expectEqual(@as(u32, 2), try ring.submit());1153 try testing.expectEqual(@as(u32, 2), try ring.submit());
11541154
1155 const cqe_write = try ring.copy_cqe();1155 const cqe_write = try ring.copy_cqe();
1156 const cqe_read = try ring.copy_cqe();1156 const cqe_read = try ring.copy_cqe();
...@@ -1158,17 +1158,17 @@ test "write/read" {...@@ -1158,17 +1158,17 @@ test "write/read" {
1158 // https://lwn.net/Articles/809820/1158 // https://lwn.net/Articles/809820/
1159 if (cqe_write.res == -linux.EINVAL) return error.SkipZigTest;1159 if (cqe_write.res == -linux.EINVAL) return error.SkipZigTest;
1160 if (cqe_read.res == -linux.EINVAL) return error.SkipZigTest;1160 if (cqe_read.res == -linux.EINVAL) return error.SkipZigTest;
1161 testing.expectEqual(linux.io_uring_cqe{1161 try testing.expectEqual(linux.io_uring_cqe{
1162 .user_data = 0x11111111,1162 .user_data = 0x11111111,
1163 .res = buffer_write.len,1163 .res = buffer_write.len,
1164 .flags = 0,1164 .flags = 0,
1165 }, cqe_write);1165 }, cqe_write);
1166 testing.expectEqual(linux.io_uring_cqe{1166 try testing.expectEqual(linux.io_uring_cqe{
1167 .user_data = 0x22222222,1167 .user_data = 0x22222222,
1168 .res = buffer_read.len,1168 .res = buffer_read.len,
1169 .flags = 0,1169 .flags = 0,
1170 }, cqe_read);1170 }, cqe_read);
1171 testing.expectEqualSlices(u8, buffer_write[0..], buffer_read[0..]);1171 try testing.expectEqualSlices(u8, buffer_write[0..], buffer_read[0..]);
1172}1172}
11731173
1174test "openat" {1174test "openat" {
...@@ -1187,7 +1187,7 @@ test "openat" {...@@ -1187,7 +1187,7 @@ test "openat" {
1187 const flags: u32 = os.O_CLOEXEC | os.O_RDWR | os.O_CREAT;1187 const flags: u32 = os.O_CLOEXEC | os.O_RDWR | os.O_CREAT;
1188 const mode: os.mode_t = 0o666;1188 const mode: os.mode_t = 0o666;
1189 const sqe_openat = try ring.openat(0x33333333, linux.AT_FDCWD, path, flags, mode);1189 const sqe_openat = try ring.openat(0x33333333, linux.AT_FDCWD, path, flags, mode);
1190 testing.expectEqual(io_uring_sqe{1190 try testing.expectEqual(io_uring_sqe{
1191 .opcode = .OPENAT,1191 .opcode = .OPENAT,
1192 .flags = 0,1192 .flags = 0,
1193 .ioprio = 0,1193 .ioprio = 0,
...@@ -1202,10 +1202,10 @@ test "openat" {...@@ -1202,10 +1202,10 @@ test "openat" {
1202 .splice_fd_in = 0,1202 .splice_fd_in = 0,
1203 .__pad2 = [2]u64{ 0, 0 },1203 .__pad2 = [2]u64{ 0, 0 },
1204 }, sqe_openat.*);1204 }, sqe_openat.*);
1205 testing.expectEqual(@as(u32, 1), try ring.submit());1205 try testing.expectEqual(@as(u32, 1), try ring.submit());
12061206
1207 const cqe_openat = try ring.copy_cqe();1207 const cqe_openat = try ring.copy_cqe();
1208 testing.expectEqual(@as(u64, 0x33333333), cqe_openat.user_data);1208 try testing.expectEqual(@as(u64, 0x33333333), cqe_openat.user_data);
1209 if (cqe_openat.res == -linux.EINVAL) return error.SkipZigTest;1209 if (cqe_openat.res == -linux.EINVAL) return error.SkipZigTest;
1210 // AT_FDCWD is not fully supported before kernel 5.6:1210 // AT_FDCWD is not fully supported before kernel 5.6:
1211 // See https://lore.kernel.org/io-uring/20200207155039.12819-1-axboe@kernel.dk/T/1211 // See https://lore.kernel.org/io-uring/20200207155039.12819-1-axboe@kernel.dk/T/
...@@ -1214,8 +1214,8 @@ test "openat" {...@@ -1214,8 +1214,8 @@ test "openat" {
1214 return error.SkipZigTest;1214 return error.SkipZigTest;
1215 }1215 }
1216 if (cqe_openat.res <= 0) std.debug.print("\ncqe_openat.res={}\n", .{cqe_openat.res});1216 if (cqe_openat.res <= 0) std.debug.print("\ncqe_openat.res={}\n", .{cqe_openat.res});
1217 testing.expect(cqe_openat.res > 0);1217 try testing.expect(cqe_openat.res > 0);
1218 testing.expectEqual(@as(u32, 0), cqe_openat.flags);1218 try testing.expectEqual(@as(u32, 0), cqe_openat.flags);
12191219
1220 os.close(cqe_openat.res);1220 os.close(cqe_openat.res);
1221}1221}
...@@ -1236,13 +1236,13 @@ test "close" {...@@ -1236,13 +1236,13 @@ test "close" {
1236 defer std.fs.cwd().deleteFile(path) catch {};1236 defer std.fs.cwd().deleteFile(path) catch {};
12371237
1238 const sqe_close = try ring.close(0x44444444, file.handle);1238 const sqe_close = try ring.close(0x44444444, file.handle);
1239 testing.expectEqual(linux.IORING_OP.CLOSE, sqe_close.opcode);1239 try testing.expectEqual(linux.IORING_OP.CLOSE, sqe_close.opcode);
1240 testing.expectEqual(file.handle, sqe_close.fd);1240 try testing.expectEqual(file.handle, sqe_close.fd);
1241 testing.expectEqual(@as(u32, 1), try ring.submit());1241 try testing.expectEqual(@as(u32, 1), try ring.submit());
12421242
1243 const cqe_close = try ring.copy_cqe();1243 const cqe_close = try ring.copy_cqe();
1244 if (cqe_close.res == -linux.EINVAL) return error.SkipZigTest;1244 if (cqe_close.res == -linux.EINVAL) return error.SkipZigTest;
1245 testing.expectEqual(linux.io_uring_cqe{1245 try testing.expectEqual(linux.io_uring_cqe{
1246 .user_data = 0x44444444,1246 .user_data = 0x44444444,
1247 .res = 0,1247 .res = 0,
1248 .flags = 0,1248 .flags = 0,
...@@ -1273,12 +1273,12 @@ test "accept/connect/send/recv" {...@@ -1273,12 +1273,12 @@ test "accept/connect/send/recv" {
1273 var accept_addr: os.sockaddr = undefined;1273 var accept_addr: os.sockaddr = undefined;
1274 var accept_addr_len: os.socklen_t = @sizeOf(@TypeOf(accept_addr));1274 var accept_addr_len: os.socklen_t = @sizeOf(@TypeOf(accept_addr));
1275 const accept = try ring.accept(0xaaaaaaaa, server, &accept_addr, &accept_addr_len, 0);1275 const accept = try ring.accept(0xaaaaaaaa, server, &accept_addr, &accept_addr_len, 0);
1276 testing.expectEqual(@as(u32, 1), try ring.submit());1276 try testing.expectEqual(@as(u32, 1), try ring.submit());
12771277
1278 const client = try os.socket(address.any.family, os.SOCK_STREAM | os.SOCK_CLOEXEC, 0);1278 const client = try os.socket(address.any.family, os.SOCK_STREAM | os.SOCK_CLOEXEC, 0);
1279 defer os.close(client);1279 defer os.close(client);
1280 const connect = try ring.connect(0xcccccccc, client, &address.any, address.getOsSockLen());1280 const connect = try ring.connect(0xcccccccc, client, &address.any, address.getOsSockLen());
1281 testing.expectEqual(@as(u32, 1), try ring.submit());1281 try testing.expectEqual(@as(u32, 1), try ring.submit());
12821282
1283 var cqe_accept = try ring.copy_cqe();1283 var cqe_accept = try ring.copy_cqe();
1284 if (cqe_accept.res == -linux.EINVAL) return error.SkipZigTest;1284 if (cqe_accept.res == -linux.EINVAL) return error.SkipZigTest;
...@@ -1293,11 +1293,11 @@ test "accept/connect/send/recv" {...@@ -1293,11 +1293,11 @@ test "accept/connect/send/recv" {
1293 cqe_connect = a;1293 cqe_connect = a;
1294 }1294 }
12951295
1296 testing.expectEqual(@as(u64, 0xaaaaaaaa), cqe_accept.user_data);1296 try testing.expectEqual(@as(u64, 0xaaaaaaaa), cqe_accept.user_data);
1297 if (cqe_accept.res <= 0) std.debug.print("\ncqe_accept.res={}\n", .{cqe_accept.res});1297 if (cqe_accept.res <= 0) std.debug.print("\ncqe_accept.res={}\n", .{cqe_accept.res});
1298 testing.expect(cqe_accept.res > 0);1298 try testing.expect(cqe_accept.res > 0);
1299 testing.expectEqual(@as(u32, 0), cqe_accept.flags);1299 try testing.expectEqual(@as(u32, 0), cqe_accept.flags);
1300 testing.expectEqual(linux.io_uring_cqe{1300 try testing.expectEqual(linux.io_uring_cqe{
1301 .user_data = 0xcccccccc,1301 .user_data = 0xcccccccc,
1302 .res = 0,1302 .res = 0,
1303 .flags = 0,1303 .flags = 0,
...@@ -1306,11 +1306,11 @@ test "accept/connect/send/recv" {...@@ -1306,11 +1306,11 @@ test "accept/connect/send/recv" {
1306 const send = try ring.send(0xeeeeeeee, client, buffer_send[0..], 0);1306 const send = try ring.send(0xeeeeeeee, client, buffer_send[0..], 0);
1307 send.flags |= linux.IOSQE_IO_LINK;1307 send.flags |= linux.IOSQE_IO_LINK;
1308 const recv = try ring.recv(0xffffffff, cqe_accept.res, buffer_recv[0..], 0);1308 const recv = try ring.recv(0xffffffff, cqe_accept.res, buffer_recv[0..], 0);
1309 testing.expectEqual(@as(u32, 2), try ring.submit());1309 try testing.expectEqual(@as(u32, 2), try ring.submit());
13101310
1311 const cqe_send = try ring.copy_cqe();1311 const cqe_send = try ring.copy_cqe();
1312 if (cqe_send.res == -linux.EINVAL) return error.SkipZigTest;1312 if (cqe_send.res == -linux.EINVAL) return error.SkipZigTest;
1313 testing.expectEqual(linux.io_uring_cqe{1313 try testing.expectEqual(linux.io_uring_cqe{
1314 .user_data = 0xeeeeeeee,1314 .user_data = 0xeeeeeeee,
1315 .res = buffer_send.len,1315 .res = buffer_send.len,
1316 .flags = 0,1316 .flags = 0,
...@@ -1318,13 +1318,13 @@ test "accept/connect/send/recv" {...@@ -1318,13 +1318,13 @@ test "accept/connect/send/recv" {
13181318
1319 const cqe_recv = try ring.copy_cqe();1319 const cqe_recv = try ring.copy_cqe();
1320 if (cqe_recv.res == -linux.EINVAL) return error.SkipZigTest;1320 if (cqe_recv.res == -linux.EINVAL) return error.SkipZigTest;
1321 testing.expectEqual(linux.io_uring_cqe{1321 try testing.expectEqual(linux.io_uring_cqe{
1322 .user_data = 0xffffffff,1322 .user_data = 0xffffffff,
1323 .res = buffer_recv.len,1323 .res = buffer_recv.len,
1324 .flags = 0,1324 .flags = 0,
1325 }, cqe_recv);1325 }, cqe_recv);
13261326
1327 testing.expectEqualSlices(u8, buffer_send[0..buffer_recv.len], buffer_recv[0..]);1327 try testing.expectEqualSlices(u8, buffer_send[0..buffer_recv.len], buffer_recv[0..]);
1328}1328}
13291329
1330test "timeout (after a relative time)" {1330test "timeout (after a relative time)" {
...@@ -1343,12 +1343,12 @@ test "timeout (after a relative time)" {...@@ -1343,12 +1343,12 @@ test "timeout (after a relative time)" {
13431343
1344 const started = std.time.milliTimestamp();1344 const started = std.time.milliTimestamp();
1345 const sqe = try ring.timeout(0x55555555, &ts, 0, 0);1345 const sqe = try ring.timeout(0x55555555, &ts, 0, 0);
1346 testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe.opcode);1346 try testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe.opcode);
1347 testing.expectEqual(@as(u32, 1), try ring.submit());1347 try testing.expectEqual(@as(u32, 1), try ring.submit());
1348 const cqe = try ring.copy_cqe();1348 const cqe = try ring.copy_cqe();
1349 const stopped = std.time.milliTimestamp();1349 const stopped = std.time.milliTimestamp();
13501350
1351 testing.expectEqual(linux.io_uring_cqe{1351 try testing.expectEqual(linux.io_uring_cqe{
1352 .user_data = 0x55555555,1352 .user_data = 0x55555555,
1353 .res = -linux.ETIME,1353 .res = -linux.ETIME,
1354 .flags = 0,1354 .flags = 0,
...@@ -1371,20 +1371,20 @@ test "timeout (after a number of completions)" {...@@ -1371,20 +1371,20 @@ test "timeout (after a number of completions)" {
1371 const ts = os.__kernel_timespec{ .tv_sec = 3, .tv_nsec = 0 };1371 const ts = os.__kernel_timespec{ .tv_sec = 3, .tv_nsec = 0 };
1372 const count_completions: u64 = 1;1372 const count_completions: u64 = 1;
1373 const sqe_timeout = try ring.timeout(0x66666666, &ts, count_completions, 0);1373 const sqe_timeout = try ring.timeout(0x66666666, &ts, count_completions, 0);
1374 testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe_timeout.opcode);1374 try testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe_timeout.opcode);
1375 testing.expectEqual(count_completions, sqe_timeout.off);1375 try testing.expectEqual(count_completions, sqe_timeout.off);
1376 _ = try ring.nop(0x77777777);1376 _ = try ring.nop(0x77777777);
1377 testing.expectEqual(@as(u32, 2), try ring.submit());1377 try testing.expectEqual(@as(u32, 2), try ring.submit());
13781378
1379 const cqe_nop = try ring.copy_cqe();1379 const cqe_nop = try ring.copy_cqe();
1380 testing.expectEqual(linux.io_uring_cqe{1380 try testing.expectEqual(linux.io_uring_cqe{
1381 .user_data = 0x77777777,1381 .user_data = 0x77777777,
1382 .res = 0,1382 .res = 0,
1383 .flags = 0,1383 .flags = 0,
1384 }, cqe_nop);1384 }, cqe_nop);
13851385
1386 const cqe_timeout = try ring.copy_cqe();1386 const cqe_timeout = try ring.copy_cqe();
1387 testing.expectEqual(linux.io_uring_cqe{1387 try testing.expectEqual(linux.io_uring_cqe{
1388 .user_data = 0x66666666,1388 .user_data = 0x66666666,
1389 .res = 0,1389 .res = 0,
1390 .flags = 0,1390 .flags = 0,
...@@ -1403,15 +1403,15 @@ test "timeout_remove" {...@@ -1403,15 +1403,15 @@ test "timeout_remove" {
14031403
1404 const ts = os.__kernel_timespec{ .tv_sec = 3, .tv_nsec = 0 };1404 const ts = os.__kernel_timespec{ .tv_sec = 3, .tv_nsec = 0 };
1405 const sqe_timeout = try ring.timeout(0x88888888, &ts, 0, 0);1405 const sqe_timeout = try ring.timeout(0x88888888, &ts, 0, 0);
1406 testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe_timeout.opcode);1406 try testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe_timeout.opcode);
1407 testing.expectEqual(@as(u64, 0x88888888), sqe_timeout.user_data);1407 try testing.expectEqual(@as(u64, 0x88888888), sqe_timeout.user_data);
14081408
1409 const sqe_timeout_remove = try ring.timeout_remove(0x99999999, 0x88888888, 0);1409 const sqe_timeout_remove = try ring.timeout_remove(0x99999999, 0x88888888, 0);
1410 testing.expectEqual(linux.IORING_OP.TIMEOUT_REMOVE, sqe_timeout_remove.opcode);1410 try testing.expectEqual(linux.IORING_OP.TIMEOUT_REMOVE, sqe_timeout_remove.opcode);
1411 testing.expectEqual(@as(u64, 0x88888888), sqe_timeout_remove.addr);1411 try testing.expectEqual(@as(u64, 0x88888888), sqe_timeout_remove.addr);
1412 testing.expectEqual(@as(u64, 0x99999999), sqe_timeout_remove.user_data);1412 try testing.expectEqual(@as(u64, 0x99999999), sqe_timeout_remove.user_data);
14131413
1414 testing.expectEqual(@as(u32, 2), try ring.submit());1414 try testing.expectEqual(@as(u32, 2), try ring.submit());
14151415
1416 const cqe_timeout = try ring.copy_cqe();1416 const cqe_timeout = try ring.copy_cqe();
1417 // IORING_OP_TIMEOUT_REMOVE is not supported by this kernel version:1417 // IORING_OP_TIMEOUT_REMOVE is not supported by this kernel version:
...@@ -1424,14 +1424,14 @@ test "timeout_remove" {...@@ -1424,14 +1424,14 @@ test "timeout_remove" {
1424 {1424 {
1425 return error.SkipZigTest;1425 return error.SkipZigTest;
1426 }1426 }
1427 testing.expectEqual(linux.io_uring_cqe{1427 try testing.expectEqual(linux.io_uring_cqe{
1428 .user_data = 0x88888888,1428 .user_data = 0x88888888,
1429 .res = -linux.ECANCELED,1429 .res = -linux.ECANCELED,
1430 .flags = 0,1430 .flags = 0,
1431 }, cqe_timeout);1431 }, cqe_timeout);
14321432
1433 const cqe_timeout_remove = try ring.copy_cqe();1433 const cqe_timeout_remove = try ring.copy_cqe();
1434 testing.expectEqual(linux.io_uring_cqe{1434 try testing.expectEqual(linux.io_uring_cqe{
1435 .user_data = 0x99999999,1435 .user_data = 0x99999999,
1436 .res = 0,1436 .res = 0,
1437 .flags = 0,1437 .flags = 0,
...@@ -1453,13 +1453,13 @@ test "fallocate" {...@@ -1453,13 +1453,13 @@ test "fallocate" {
1453 defer file.close();1453 defer file.close();
1454 defer std.fs.cwd().deleteFile(path) catch {};1454 defer std.fs.cwd().deleteFile(path) catch {};
14551455
1456 testing.expectEqual(@as(u64, 0), (try file.stat()).size);1456 try testing.expectEqual(@as(u64, 0), (try file.stat()).size);
14571457
1458 const len: u64 = 65536;1458 const len: u64 = 65536;
1459 const sqe = try ring.fallocate(0xaaaaaaaa, file.handle, 0, 0, len);1459 const sqe = try ring.fallocate(0xaaaaaaaa, file.handle, 0, 0, len);
1460 testing.expectEqual(linux.IORING_OP.FALLOCATE, sqe.opcode);1460 try testing.expectEqual(linux.IORING_OP.FALLOCATE, sqe.opcode);
1461 testing.expectEqual(file.handle, sqe.fd);1461 try testing.expectEqual(file.handle, sqe.fd);
1462 testing.expectEqual(@as(u32, 1), try ring.submit());1462 try testing.expectEqual(@as(u32, 1), try ring.submit());
14631463
1464 const cqe = try ring.copy_cqe();1464 const cqe = try ring.copy_cqe();
1465 switch (-cqe.res) {1465 switch (-cqe.res) {
...@@ -1473,11 +1473,11 @@ test "fallocate" {...@@ -1473,11 +1473,11 @@ test "fallocate" {
1473 linux.EOPNOTSUPP => return error.SkipZigTest,1473 linux.EOPNOTSUPP => return error.SkipZigTest,
1474 else => |errno| std.debug.panic("unhandled errno: {}", .{errno}),1474 else => |errno| std.debug.panic("unhandled errno: {}", .{errno}),
1475 }1475 }
1476 testing.expectEqual(linux.io_uring_cqe{1476 try testing.expectEqual(linux.io_uring_cqe{
1477 .user_data = 0xaaaaaaaa,1477 .user_data = 0xaaaaaaaa,
1478 .res = 0,1478 .res = 0,
1479 .flags = 0,1479 .flags = 0,
1480 }, cqe);1480 }, cqe);
14811481
1482 testing.expectEqual(len, (try file.stat()).size);1482 try testing.expectEqual(len, (try file.stat()).size);
1483}1483}
lib/std/os/linux/test.zig+17-17
...@@ -18,7 +18,7 @@ test "fallocate" {...@@ -18,7 +18,7 @@ test "fallocate" {
18 defer file.close();18 defer file.close();
19 defer fs.cwd().deleteFile(path) catch {};19 defer fs.cwd().deleteFile(path) catch {};
2020
21 expect((try file.stat()).size == 0);21 try expect((try file.stat()).size == 0);
2222
23 const len: u64 = 65536;23 const len: u64 = 65536;
24 switch (linux.getErrno(linux.fallocate(file.handle, 0, 0, len))) {24 switch (linux.getErrno(linux.fallocate(file.handle, 0, 0, len))) {
...@@ -28,20 +28,20 @@ test "fallocate" {...@@ -28,20 +28,20 @@ test "fallocate" {
28 else => |errno| std.debug.panic("unhandled errno: {}", .{errno}),28 else => |errno| std.debug.panic("unhandled errno: {}", .{errno}),
29 }29 }
3030
31 expect((try file.stat()).size == len);31 try expect((try file.stat()).size == len);
32}32}
3333
34test "getpid" {34test "getpid" {
35 expect(linux.getpid() != 0);35 try expect(linux.getpid() != 0);
36}36}
3737
38test "timer" {38test "timer" {
39 const epoll_fd = linux.epoll_create();39 const epoll_fd = linux.epoll_create();
40 var err: usize = linux.getErrno(epoll_fd);40 var err: usize = linux.getErrno(epoll_fd);
41 expect(err == 0);41 try expect(err == 0);
4242
43 const timer_fd = linux.timerfd_create(linux.CLOCK_MONOTONIC, 0);43 const timer_fd = linux.timerfd_create(linux.CLOCK_MONOTONIC, 0);
44 expect(linux.getErrno(timer_fd) == 0);44 try expect(linux.getErrno(timer_fd) == 0);
4545
46 const time_interval = linux.timespec{46 const time_interval = linux.timespec{
47 .tv_sec = 0,47 .tv_sec = 0,
...@@ -54,7 +54,7 @@ test "timer" {...@@ -54,7 +54,7 @@ test "timer" {
54 };54 };
5555
56 err = linux.timerfd_settime(@intCast(i32, timer_fd), 0, &new_time, null);56 err = linux.timerfd_settime(@intCast(i32, timer_fd), 0, &new_time, null);
57 expect(err == 0);57 try expect(err == 0);
5858
59 var event = linux.epoll_event{59 var event = linux.epoll_event{
60 .events = linux.EPOLLIN | linux.EPOLLOUT | linux.EPOLLET,60 .events = linux.EPOLLIN | linux.EPOLLOUT | linux.EPOLLET,
...@@ -62,7 +62,7 @@ test "timer" {...@@ -62,7 +62,7 @@ test "timer" {
62 };62 };
6363
64 err = linux.epoll_ctl(@intCast(i32, epoll_fd), linux.EPOLL_CTL_ADD, @intCast(i32, timer_fd), &event);64 err = linux.epoll_ctl(@intCast(i32, epoll_fd), linux.EPOLL_CTL_ADD, @intCast(i32, timer_fd), &event);
65 expect(err == 0);65 try expect(err == 0);
6666
67 const events_one: linux.epoll_event = undefined;67 const events_one: linux.epoll_event = undefined;
68 var events = [_]linux.epoll_event{events_one} ** 8;68 var events = [_]linux.epoll_event{events_one} ** 8;
...@@ -93,18 +93,18 @@ test "statx" {...@@ -93,18 +93,18 @@ test "statx" {
93 else => unreachable,93 else => unreachable,
94 }94 }
9595
96 expect(stat_buf.mode == statx_buf.mode);96 try expect(stat_buf.mode == statx_buf.mode);
97 expect(@bitCast(u32, stat_buf.uid) == statx_buf.uid);97 try expect(@bitCast(u32, stat_buf.uid) == statx_buf.uid);
98 expect(@bitCast(u32, stat_buf.gid) == statx_buf.gid);98 try expect(@bitCast(u32, stat_buf.gid) == statx_buf.gid);
99 expect(@bitCast(u64, @as(i64, stat_buf.size)) == statx_buf.size);99 try expect(@bitCast(u64, @as(i64, stat_buf.size)) == statx_buf.size);
100 expect(@bitCast(u64, @as(i64, stat_buf.blksize)) == statx_buf.blksize);100 try expect(@bitCast(u64, @as(i64, stat_buf.blksize)) == statx_buf.blksize);
101 expect(@bitCast(u64, @as(i64, stat_buf.blocks)) == statx_buf.blocks);101 try expect(@bitCast(u64, @as(i64, stat_buf.blocks)) == statx_buf.blocks);
102}102}
103103
104test "user and group ids" {104test "user and group ids" {
105 if (builtin.link_libc) return error.SkipZigTest;105 if (builtin.link_libc) return error.SkipZigTest;
106 expectEqual(linux.getauxval(elf.AT_UID), linux.getuid());106 try expectEqual(linux.getauxval(elf.AT_UID), linux.getuid());
107 expectEqual(linux.getauxval(elf.AT_GID), linux.getgid());107 try expectEqual(linux.getauxval(elf.AT_GID), linux.getgid());
108 expectEqual(linux.getauxval(elf.AT_EUID), linux.geteuid());108 try expectEqual(linux.getauxval(elf.AT_EUID), linux.geteuid());
109 expectEqual(linux.getauxval(elf.AT_EGID), linux.getegid());109 try expectEqual(linux.getauxval(elf.AT_EGID), linux.getegid());
110}110}
lib/std/os/test.zig+51-51
...@@ -37,7 +37,7 @@ test "chdir smoke test" {...@@ -37,7 +37,7 @@ test "chdir smoke test" {
37 try os.chdir(old_cwd);37 try os.chdir(old_cwd);
38 var new_cwd_buf: [fs.MAX_PATH_BYTES]u8 = undefined;38 var new_cwd_buf: [fs.MAX_PATH_BYTES]u8 = undefined;
39 const new_cwd = try os.getcwd(new_cwd_buf[0..]);39 const new_cwd = try os.getcwd(new_cwd_buf[0..]);
40 expect(mem.eql(u8, old_cwd, new_cwd));40 try expect(mem.eql(u8, old_cwd, new_cwd));
41 }41 }
42 {42 {
43 // Next, change current working directory to one level above43 // Next, change current working directory to one level above
...@@ -45,7 +45,7 @@ test "chdir smoke test" {...@@ -45,7 +45,7 @@ test "chdir smoke test" {
45 try os.chdir(parent);45 try os.chdir(parent);
46 var new_cwd_buf: [fs.MAX_PATH_BYTES]u8 = undefined;46 var new_cwd_buf: [fs.MAX_PATH_BYTES]u8 = undefined;
47 const new_cwd = try os.getcwd(new_cwd_buf[0..]);47 const new_cwd = try os.getcwd(new_cwd_buf[0..]);
48 expect(mem.eql(u8, parent, new_cwd));48 try expect(mem.eql(u8, parent, new_cwd));
49 }49 }
50}50}
5151
...@@ -77,7 +77,7 @@ test "open smoke test" {...@@ -77,7 +77,7 @@ test "open smoke test" {
7777
78 // Try this again with the same flags. This op should fail with error.PathAlreadyExists.78 // Try this again with the same flags. This op should fail with error.PathAlreadyExists.
79 file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_file" });79 file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_file" });
80 expectError(error.PathAlreadyExists, os.open(file_path, os.O_RDWR | os.O_CREAT | os.O_EXCL, mode));80 try expectError(error.PathAlreadyExists, os.open(file_path, os.O_RDWR | os.O_CREAT | os.O_EXCL, mode));
8181
82 // Try opening without `O_EXCL` flag.82 // Try opening without `O_EXCL` flag.
83 file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_file" });83 file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_file" });
...@@ -86,7 +86,7 @@ test "open smoke test" {...@@ -86,7 +86,7 @@ test "open smoke test" {
8686
87 // Try opening as a directory which should fail.87 // Try opening as a directory which should fail.
88 file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_file" });88 file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_file" });
89 expectError(error.NotDir, os.open(file_path, os.O_RDWR | os.O_DIRECTORY, mode));89 try expectError(error.NotDir, os.open(file_path, os.O_RDWR | os.O_DIRECTORY, mode));
9090
91 // Create some directory91 // Create some directory
92 file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_dir" });92 file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_dir" });
...@@ -99,7 +99,7 @@ test "open smoke test" {...@@ -99,7 +99,7 @@ test "open smoke test" {
9999
100 // Try opening as file which should fail.100 // Try opening as file which should fail.
101 file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_dir" });101 file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_dir" });
102 expectError(error.IsDir, os.open(file_path, os.O_RDWR, mode));102 try expectError(error.IsDir, os.open(file_path, os.O_RDWR, mode));
103}103}
104104
105test "openat smoke test" {105test "openat smoke test" {
...@@ -118,14 +118,14 @@ test "openat smoke test" {...@@ -118,14 +118,14 @@ test "openat smoke test" {
118 os.close(fd);118 os.close(fd);
119119
120 // Try this again with the same flags. This op should fail with error.PathAlreadyExists.120 // Try this again with the same flags. This op should fail with error.PathAlreadyExists.
121 expectError(error.PathAlreadyExists, os.openat(tmp.dir.fd, "some_file", os.O_RDWR | os.O_CREAT | os.O_EXCL, mode));121 try expectError(error.PathAlreadyExists, os.openat(tmp.dir.fd, "some_file", os.O_RDWR | os.O_CREAT | os.O_EXCL, mode));
122122
123 // Try opening without `O_EXCL` flag.123 // Try opening without `O_EXCL` flag.
124 fd = try os.openat(tmp.dir.fd, "some_file", os.O_RDWR | os.O_CREAT, mode);124 fd = try os.openat(tmp.dir.fd, "some_file", os.O_RDWR | os.O_CREAT, mode);
125 os.close(fd);125 os.close(fd);
126126
127 // Try opening as a directory which should fail.127 // Try opening as a directory which should fail.
128 expectError(error.NotDir, os.openat(tmp.dir.fd, "some_file", os.O_RDWR | os.O_DIRECTORY, mode));128 try expectError(error.NotDir, os.openat(tmp.dir.fd, "some_file", os.O_RDWR | os.O_DIRECTORY, mode));
129129
130 // Create some directory130 // Create some directory
131 try os.mkdirat(tmp.dir.fd, "some_dir", mode);131 try os.mkdirat(tmp.dir.fd, "some_dir", mode);
...@@ -135,7 +135,7 @@ test "openat smoke test" {...@@ -135,7 +135,7 @@ test "openat smoke test" {
135 os.close(fd);135 os.close(fd);
136136
137 // Try opening as file which should fail.137 // Try opening as file which should fail.
138 expectError(error.IsDir, os.openat(tmp.dir.fd, "some_dir", os.O_RDWR, mode));138 try expectError(error.IsDir, os.openat(tmp.dir.fd, "some_dir", os.O_RDWR, mode));
139}139}
140140
141test "symlink with relative paths" {141test "symlink with relative paths" {
...@@ -169,7 +169,7 @@ test "symlink with relative paths" {...@@ -169,7 +169,7 @@ test "symlink with relative paths" {
169169
170 var buffer: [fs.MAX_PATH_BYTES]u8 = undefined;170 var buffer: [fs.MAX_PATH_BYTES]u8 = undefined;
171 const given = try os.readlink("symlinked", buffer[0..]);171 const given = try os.readlink("symlinked", buffer[0..]);
172 expect(mem.eql(u8, "file.txt", given));172 try expect(mem.eql(u8, "file.txt", given));
173173
174 try cwd.deleteFile("file.txt");174 try cwd.deleteFile("file.txt");
175 try cwd.deleteFile("symlinked");175 try cwd.deleteFile("symlinked");
...@@ -186,7 +186,7 @@ test "readlink on Windows" {...@@ -186,7 +186,7 @@ test "readlink on Windows" {
186fn testReadlink(target_path: []const u8, symlink_path: []const u8) !void {186fn testReadlink(target_path: []const u8, symlink_path: []const u8) !void {
187 var buffer: [fs.MAX_PATH_BYTES]u8 = undefined;187 var buffer: [fs.MAX_PATH_BYTES]u8 = undefined;
188 const given = try os.readlink(symlink_path, buffer[0..]);188 const given = try os.readlink(symlink_path, buffer[0..]);
189 expect(mem.eql(u8, target_path, given));189 try expect(mem.eql(u8, target_path, given));
190}190}
191191
192test "link with relative paths" {192test "link with relative paths" {
...@@ -209,15 +209,15 @@ test "link with relative paths" {...@@ -209,15 +209,15 @@ test "link with relative paths" {
209 const estat = try os.fstat(efd.handle);209 const estat = try os.fstat(efd.handle);
210 const nstat = try os.fstat(nfd.handle);210 const nstat = try os.fstat(nfd.handle);
211211
212 testing.expectEqual(estat.ino, nstat.ino);212 try testing.expectEqual(estat.ino, nstat.ino);
213 testing.expectEqual(@as(usize, 2), nstat.nlink);213 try testing.expectEqual(@as(usize, 2), nstat.nlink);
214 }214 }
215215
216 try os.unlink("new.txt");216 try os.unlink("new.txt");
217217
218 {218 {
219 const estat = try os.fstat(efd.handle);219 const estat = try os.fstat(efd.handle);
220 testing.expectEqual(@as(usize, 1), estat.nlink);220 try testing.expectEqual(@as(usize, 1), estat.nlink);
221 }221 }
222222
223 try cwd.deleteFile("example.txt");223 try cwd.deleteFile("example.txt");
...@@ -244,15 +244,15 @@ test "linkat with different directories" {...@@ -244,15 +244,15 @@ test "linkat with different directories" {
244 const estat = try os.fstat(efd.handle);244 const estat = try os.fstat(efd.handle);
245 const nstat = try os.fstat(nfd.handle);245 const nstat = try os.fstat(nfd.handle);
246246
247 testing.expectEqual(estat.ino, nstat.ino);247 try testing.expectEqual(estat.ino, nstat.ino);
248 testing.expectEqual(@as(usize, 2), nstat.nlink);248 try testing.expectEqual(@as(usize, 2), nstat.nlink);
249 }249 }
250250
251 try os.unlinkat(tmp.dir.fd, "new.txt", 0);251 try os.unlinkat(tmp.dir.fd, "new.txt", 0);
252252
253 {253 {
254 const estat = try os.fstat(efd.handle);254 const estat = try os.fstat(efd.handle);
255 testing.expectEqual(@as(usize, 1), estat.nlink);255 try testing.expectEqual(@as(usize, 1), estat.nlink);
256 }256 }
257257
258 try cwd.deleteFile("example.txt");258 try cwd.deleteFile("example.txt");
...@@ -281,7 +281,7 @@ test "fstatat" {...@@ -281,7 +281,7 @@ test "fstatat" {
281 // now repeat but using `fstatat` instead281 // now repeat but using `fstatat` instead
282 const flags = if (builtin.os.tag == .wasi) 0x0 else os.AT_SYMLINK_NOFOLLOW;282 const flags = if (builtin.os.tag == .wasi) 0x0 else os.AT_SYMLINK_NOFOLLOW;
283 const statat = try os.fstatat(tmp.dir.fd, "file.txt", flags);283 const statat = try os.fstatat(tmp.dir.fd, "file.txt", flags);
284 expectEqual(stat, statat);284 try expectEqual(stat, statat);
285}285}
286286
287test "readlinkat" {287test "readlinkat" {
...@@ -310,7 +310,7 @@ test "readlinkat" {...@@ -310,7 +310,7 @@ test "readlinkat" {
310 // read the link310 // read the link
311 var buffer: [fs.MAX_PATH_BYTES]u8 = undefined;311 var buffer: [fs.MAX_PATH_BYTES]u8 = undefined;
312 const read_link = try os.readlinkat(tmp.dir.fd, "link", buffer[0..]);312 const read_link = try os.readlinkat(tmp.dir.fd, "link", buffer[0..]);
313 expect(mem.eql(u8, "file.txt", read_link));313 try expect(mem.eql(u8, "file.txt", read_link));
314}314}
315315
316fn testThreadIdFn(thread_id: *Thread.Id) void {316fn testThreadIdFn(thread_id: *Thread.Id) void {
...@@ -325,13 +325,13 @@ test "std.Thread.getCurrentId" {...@@ -325,13 +325,13 @@ test "std.Thread.getCurrentId" {
325 const thread_id = thread.handle();325 const thread_id = thread.handle();
326 thread.wait();326 thread.wait();
327 if (Thread.use_pthreads) {327 if (Thread.use_pthreads) {
328 expect(thread_current_id == thread_id);328 try expect(thread_current_id == thread_id);
329 } else if (builtin.os.tag == .windows) {329 } else if (builtin.os.tag == .windows) {
330 expect(Thread.getCurrentId() != thread_current_id);330 try expect(Thread.getCurrentId() != thread_current_id);
331 } else {331 } else {
332 // If the thread completes very quickly, then thread_id can be 0. See the332 // If the thread completes very quickly, then thread_id can be 0. See the
333 // documentation comments for `std.Thread.handle`.333 // documentation comments for `std.Thread.handle`.
334 expect(thread_id == 0 or thread_current_id == thread_id);334 try expect(thread_id == 0 or thread_current_id == thread_id);
335 }335 }
336}336}
337337
...@@ -350,7 +350,7 @@ test "spawn threads" {...@@ -350,7 +350,7 @@ test "spawn threads" {
350 thread3.wait();350 thread3.wait();
351 thread4.wait();351 thread4.wait();
352352
353 expect(shared_ctx == 4);353 try expect(shared_ctx == 4);
354}354}
355355
356fn start1(ctx: void) u8 {356fn start1(ctx: void) u8 {
...@@ -366,23 +366,23 @@ test "cpu count" {...@@ -366,23 +366,23 @@ test "cpu count" {
366 if (builtin.os.tag == .wasi) return error.SkipZigTest;366 if (builtin.os.tag == .wasi) return error.SkipZigTest;
367367
368 const cpu_count = try Thread.cpuCount();368 const cpu_count = try Thread.cpuCount();
369 expect(cpu_count >= 1);369 try expect(cpu_count >= 1);
370}370}
371371
372test "thread local storage" {372test "thread local storage" {
373 if (builtin.single_threaded) return error.SkipZigTest;373 if (builtin.single_threaded) return error.SkipZigTest;
374 const thread1 = try Thread.spawn(testTls, {});374 const thread1 = try Thread.spawn(testTls, {});
375 const thread2 = try Thread.spawn(testTls, {});375 const thread2 = try Thread.spawn(testTls, {});
376 testTls({});376 try testTls({});
377 thread1.wait();377 thread1.wait();
378 thread2.wait();378 thread2.wait();
379}379}
380380
381threadlocal var x: i32 = 1234;381threadlocal var x: i32 = 1234;
382fn testTls(context: void) void {382fn testTls(context: void) !void {
383 if (x != 1234) @panic("bad start value");383 if (x != 1234) return error.TlsBadStartValue;
384 x += 1;384 x += 1;
385 if (x != 1235) @panic("bad end value");385 if (x != 1235) return error.TlsBadEndValue;
386}386}
387387
388test "getrandom" {388test "getrandom" {
...@@ -392,7 +392,7 @@ test "getrandom" {...@@ -392,7 +392,7 @@ test "getrandom" {
392 try os.getrandom(&buf_b);392 try os.getrandom(&buf_b);
393 // If this test fails the chance is significantly higher that there is a bug than393 // If this test fails the chance is significantly higher that there is a bug than
394 // that two sets of 50 bytes were equal.394 // that two sets of 50 bytes were equal.
395 expect(!mem.eql(u8, &buf_a, &buf_b));395 try expect(!mem.eql(u8, &buf_a, &buf_b));
396}396}
397397
398test "getcwd" {398test "getcwd" {
...@@ -411,7 +411,7 @@ test "sigaltstack" {...@@ -411,7 +411,7 @@ test "sigaltstack" {
411 // Setting a stack size less than MINSIGSTKSZ returns ENOMEM411 // Setting a stack size less than MINSIGSTKSZ returns ENOMEM
412 st.ss_flags = 0;412 st.ss_flags = 0;
413 st.ss_size = 1;413 st.ss_size = 1;
414 testing.expectError(error.SizeTooSmall, os.sigaltstack(&st, null));414 try testing.expectError(error.SizeTooSmall, os.sigaltstack(&st, null));
415}415}
416416
417// If the type is not available use void to avoid erroring out when `iter_fn` is417// If the type is not available use void to avoid erroring out when `iter_fn` is
...@@ -462,7 +462,7 @@ test "dl_iterate_phdr" {...@@ -462,7 +462,7 @@ test "dl_iterate_phdr" {
462462
463 var counter: usize = 0;463 var counter: usize = 0;
464 try os.dl_iterate_phdr(&counter, IterFnError, iter_fn);464 try os.dl_iterate_phdr(&counter, IterFnError, iter_fn);
465 expect(counter != 0);465 try expect(counter != 0);
466}466}
467467
468test "gethostname" {468test "gethostname" {
...@@ -471,7 +471,7 @@ test "gethostname" {...@@ -471,7 +471,7 @@ test "gethostname" {
471471
472 var buf: [os.HOST_NAME_MAX]u8 = undefined;472 var buf: [os.HOST_NAME_MAX]u8 = undefined;
473 const hostname = try os.gethostname(&buf);473 const hostname = try os.gethostname(&buf);
474 expect(hostname.len != 0);474 try expect(hostname.len != 0);
475}475}
476476
477test "pipe" {477test "pipe" {
...@@ -479,10 +479,10 @@ test "pipe" {...@@ -479,10 +479,10 @@ test "pipe" {
479 return error.SkipZigTest;479 return error.SkipZigTest;
480480
481 var fds = try os.pipe();481 var fds = try os.pipe();
482 expect((try os.write(fds[1], "hello")) == 5);482 try expect((try os.write(fds[1], "hello")) == 5);
483 var buf: [16]u8 = undefined;483 var buf: [16]u8 = undefined;
484 expect((try os.read(fds[0], buf[0..])) == 5);484 try expect((try os.read(fds[0], buf[0..])) == 5);
485 testing.expectEqualSlices(u8, buf[0..5], "hello");485 try testing.expectEqualSlices(u8, buf[0..5], "hello");
486 os.close(fds[1]);486 os.close(fds[1]);
487 os.close(fds[0]);487 os.close(fds[0]);
488}488}
...@@ -501,13 +501,13 @@ test "memfd_create" {...@@ -501,13 +501,13 @@ test "memfd_create" {
501 else => |e| return e,501 else => |e| return e,
502 };502 };
503 defer std.os.close(fd);503 defer std.os.close(fd);
504 expect((try std.os.write(fd, "test")) == 4);504 try expect((try std.os.write(fd, "test")) == 4);
505 try std.os.lseek_SET(fd, 0);505 try std.os.lseek_SET(fd, 0);
506506
507 var buf: [10]u8 = undefined;507 var buf: [10]u8 = undefined;
508 const bytes_read = try std.os.read(fd, &buf);508 const bytes_read = try std.os.read(fd, &buf);
509 expect(bytes_read == 4);509 try expect(bytes_read == 4);
510 expect(mem.eql(u8, buf[0..4], "test"));510 try expect(mem.eql(u8, buf[0..4], "test"));
511}511}
512512
513test "mmap" {513test "mmap" {
...@@ -529,14 +529,14 @@ test "mmap" {...@@ -529,14 +529,14 @@ test "mmap" {
529 );529 );
530 defer os.munmap(data);530 defer os.munmap(data);
531531
532 testing.expectEqual(@as(usize, 1234), data.len);532 try testing.expectEqual(@as(usize, 1234), data.len);
533533
534 // By definition the data returned by mmap is zero-filled534 // By definition the data returned by mmap is zero-filled
535 testing.expect(mem.eql(u8, data, &[_]u8{0x00} ** 1234));535 try testing.expect(mem.eql(u8, data, &[_]u8{0x00} ** 1234));
536536
537 // Make sure the memory is writeable as requested537 // Make sure the memory is writeable as requested
538 std.mem.set(u8, data, 0x55);538 std.mem.set(u8, data, 0x55);
539 testing.expect(mem.eql(u8, data, &[_]u8{0x55} ** 1234));539 try testing.expect(mem.eql(u8, data, &[_]u8{0x55} ** 1234));
540 }540 }
541541
542 const test_out_file = "os_tmp_test";542 const test_out_file = "os_tmp_test";
...@@ -576,7 +576,7 @@ test "mmap" {...@@ -576,7 +576,7 @@ test "mmap" {
576576
577 var i: u32 = 0;577 var i: u32 = 0;
578 while (i < alloc_size / @sizeOf(u32)) : (i += 1) {578 while (i < alloc_size / @sizeOf(u32)) : (i += 1) {
579 testing.expectEqual(i, try stream.readIntNative(u32));579 try testing.expectEqual(i, try stream.readIntNative(u32));
580 }580 }
581 }581 }
582582
...@@ -600,7 +600,7 @@ test "mmap" {...@@ -600,7 +600,7 @@ test "mmap" {
600600
601 var i: u32 = alloc_size / 2 / @sizeOf(u32);601 var i: u32 = alloc_size / 2 / @sizeOf(u32);
602 while (i < alloc_size / @sizeOf(u32)) : (i += 1) {602 while (i < alloc_size / @sizeOf(u32)) : (i += 1) {
603 testing.expectEqual(i, try stream.readIntNative(u32));603 try testing.expectEqual(i, try stream.readIntNative(u32));
604 }604 }
605 }605 }
606606
...@@ -609,9 +609,9 @@ test "mmap" {...@@ -609,9 +609,9 @@ test "mmap" {
609609
610test "getenv" {610test "getenv" {
611 if (builtin.os.tag == .windows) {611 if (builtin.os.tag == .windows) {
612 expect(os.getenvW(&[_:0]u16{ 'B', 'O', 'G', 'U', 'S', 0x11, 0x22, 0x33, 0x44, 0x55 }) == null);612 try expect(os.getenvW(&[_:0]u16{ 'B', 'O', 'G', 'U', 'S', 0x11, 0x22, 0x33, 0x44, 0x55 }) == null);
613 } else {613 } else {
614 expect(os.getenvZ("BOGUSDOESNOTEXISTENVVAR") == null);614 try expect(os.getenvZ("BOGUSDOESNOTEXISTENVVAR") == null);
615 }615 }
616}616}
617617
...@@ -633,17 +633,17 @@ test "fcntl" {...@@ -633,17 +633,17 @@ test "fcntl" {
633 // Note: The test assumes createFile opens the file with O_CLOEXEC633 // Note: The test assumes createFile opens the file with O_CLOEXEC
634 {634 {
635 const flags = try os.fcntl(file.handle, os.F_GETFD, 0);635 const flags = try os.fcntl(file.handle, os.F_GETFD, 0);
636 expect((flags & os.FD_CLOEXEC) != 0);636 try expect((flags & os.FD_CLOEXEC) != 0);
637 }637 }
638 {638 {
639 _ = try os.fcntl(file.handle, os.F_SETFD, 0);639 _ = try os.fcntl(file.handle, os.F_SETFD, 0);
640 const flags = try os.fcntl(file.handle, os.F_GETFD, 0);640 const flags = try os.fcntl(file.handle, os.F_GETFD, 0);
641 expect((flags & os.FD_CLOEXEC) == 0);641 try expect((flags & os.FD_CLOEXEC) == 0);
642 }642 }
643 {643 {
644 _ = try os.fcntl(file.handle, os.F_SETFD, os.FD_CLOEXEC);644 _ = try os.fcntl(file.handle, os.F_SETFD, os.FD_CLOEXEC);
645 const flags = try os.fcntl(file.handle, os.F_GETFD, 0);645 const flags = try os.fcntl(file.handle, os.F_GETFD, 0);
646 expect((flags & os.FD_CLOEXEC) != 0);646 try expect((flags & os.FD_CLOEXEC) != 0);
647 }647 }
648}648}
649649
...@@ -748,12 +748,12 @@ test "sigaction" {...@@ -748,12 +748,12 @@ test "sigaction" {
748 os.sigaction(os.SIGUSR1, &sa, null);748 os.sigaction(os.SIGUSR1, &sa, null);
749 // Check that we can read it back correctly.749 // Check that we can read it back correctly.
750 os.sigaction(os.SIGUSR1, null, &old_sa);750 os.sigaction(os.SIGUSR1, null, &old_sa);
751 testing.expectEqual(S.handler, old_sa.handler.sigaction.?);751 try testing.expectEqual(S.handler, old_sa.handler.sigaction.?);
752 testing.expect((old_sa.flags & os.SA_SIGINFO) != 0);752 try testing.expect((old_sa.flags & os.SA_SIGINFO) != 0);
753 // Invoke the handler.753 // Invoke the handler.
754 try os.raise(os.SIGUSR1);754 try os.raise(os.SIGUSR1);
755 testing.expect(signal_test_failed == false);755 try testing.expect(signal_test_failed == false);
756 // Check if the handler has been correctly reset to SIG_DFL756 // Check if the handler has been correctly reset to SIG_DFL
757 os.sigaction(os.SIGUSR1, null, &old_sa);757 os.sigaction(os.SIGUSR1, null, &old_sa);
758 testing.expectEqual(os.SIG_DFL, old_sa.handler.sigaction);758 try testing.expectEqual(os.SIG_DFL, old_sa.handler.sigaction);
759}759}
lib/std/os/windows.zig+3-3
...@@ -997,7 +997,7 @@ test "QueryObjectName" {...@@ -997,7 +997,7 @@ test "QueryObjectName" {
997 var result_path = try QueryObjectName(handle, &out_buffer);997 var result_path = try QueryObjectName(handle, &out_buffer);
998 const required_len_in_u16 = result_path.len + @divExact(@ptrToInt(result_path.ptr) - @ptrToInt(&out_buffer), 2) + 1;998 const required_len_in_u16 = result_path.len + @divExact(@ptrToInt(result_path.ptr) - @ptrToInt(&out_buffer), 2) + 1;
999 //insufficient size999 //insufficient size
1000 std.testing.expectError(error.NameTooLong, QueryObjectName(handle, out_buffer[0 .. required_len_in_u16 - 1]));1000 try std.testing.expectError(error.NameTooLong, QueryObjectName(handle, out_buffer[0 .. required_len_in_u16 - 1]));
1001 //exactly-sufficient size1001 //exactly-sufficient size
1002 _ = try QueryObjectName(handle, out_buffer[0..required_len_in_u16]);1002 _ = try QueryObjectName(handle, out_buffer[0..required_len_in_u16]);
1003}1003}
...@@ -1155,8 +1155,8 @@ test "GetFinalPathNameByHandle" {...@@ -1155,8 +1155,8 @@ test "GetFinalPathNameByHandle" {
11551155
1156 const required_len_in_u16 = nt_path.len + @divExact(@ptrToInt(nt_path.ptr) - @ptrToInt(&buffer), 2) + 1;1156 const required_len_in_u16 = nt_path.len + @divExact(@ptrToInt(nt_path.ptr) - @ptrToInt(&buffer), 2) + 1;
1157 //check with insufficient size1157 //check with insufficient size
1158 std.testing.expectError(error.NameTooLong, GetFinalPathNameByHandle(handle, .{ .volume_name = .Nt }, buffer[0 .. required_len_in_u16 - 1]));1158 try std.testing.expectError(error.NameTooLong, GetFinalPathNameByHandle(handle, .{ .volume_name = .Nt }, buffer[0 .. required_len_in_u16 - 1]));
1159 std.testing.expectError(error.NameTooLong, GetFinalPathNameByHandle(handle, .{ .volume_name = .Dos }, buffer[0 .. required_len_in_u16 - 1]));1159 try std.testing.expectError(error.NameTooLong, GetFinalPathNameByHandle(handle, .{ .volume_name = .Dos }, buffer[0 .. required_len_in_u16 - 1]));
11601160
1161 //check with exactly-sufficient size1161 //check with exactly-sufficient size
1162 _ = try GetFinalPathNameByHandle(handle, .{ .volume_name = .Nt }, buffer[0..required_len_in_u16]);1162 _ = try GetFinalPathNameByHandle(handle, .{ .volume_name = .Nt }, buffer[0..required_len_in_u16]);
lib/std/packed_int_array.zig+49-49
...@@ -353,7 +353,7 @@ test "PackedIntArray" {...@@ -353,7 +353,7 @@ test "PackedIntArray" {
353353
354 const PackedArray = PackedIntArray(I, int_count);354 const PackedArray = PackedIntArray(I, int_count);
355 const expected_bytes = ((bits * int_count) + 7) / 8;355 const expected_bytes = ((bits * int_count) + 7) / 8;
356 testing.expect(@sizeOf(PackedArray) == expected_bytes);356 try testing.expect(@sizeOf(PackedArray) == expected_bytes);
357357
358 var data = @as(PackedArray, undefined);358 var data = @as(PackedArray, undefined);
359359
...@@ -370,7 +370,7 @@ test "PackedIntArray" {...@@ -370,7 +370,7 @@ test "PackedIntArray" {
370 count = 0;370 count = 0;
371 while (i < data.len()) : (i += 1) {371 while (i < data.len()) : (i += 1) {
372 const val = data.get(i);372 const val = data.get(i);
373 testing.expect(val == count);373 try testing.expect(val == count);
374 if (bits > 0) count +%= 1;374 if (bits > 0) count +%= 1;
375 }375 }
376 }376 }
...@@ -427,7 +427,7 @@ test "PackedIntSlice" {...@@ -427,7 +427,7 @@ test "PackedIntSlice" {
427 count = 0;427 count = 0;
428 while (i < data.len()) : (i += 1) {428 while (i < data.len()) : (i += 1) {
429 const val = data.get(i);429 const val = data.get(i);
430 testing.expect(val == count);430 try testing.expect(val == count);
431 if (bits > 0) count +%= 1;431 if (bits > 0) count +%= 1;
432 }432 }
433 }433 }
...@@ -454,48 +454,48 @@ test "PackedIntSlice of PackedInt(Array/Slice)" {...@@ -454,48 +454,48 @@ test "PackedIntSlice of PackedInt(Array/Slice)" {
454454
455 //slice of array455 //slice of array
456 var packed_slice = packed_array.slice(2, 5);456 var packed_slice = packed_array.slice(2, 5);
457 testing.expect(packed_slice.len() == 3);457 try testing.expect(packed_slice.len() == 3);
458 const ps_bit_count = (bits * packed_slice.len()) + packed_slice.bit_offset;458 const ps_bit_count = (bits * packed_slice.len()) + packed_slice.bit_offset;
459 const ps_expected_bytes = (ps_bit_count + 7) / 8;459 const ps_expected_bytes = (ps_bit_count + 7) / 8;
460 testing.expect(packed_slice.bytes.len == ps_expected_bytes);460 try testing.expect(packed_slice.bytes.len == ps_expected_bytes);
461 testing.expect(packed_slice.get(0) == 2 % limit);461 try testing.expect(packed_slice.get(0) == 2 % limit);
462 testing.expect(packed_slice.get(1) == 3 % limit);462 try testing.expect(packed_slice.get(1) == 3 % limit);
463 testing.expect(packed_slice.get(2) == 4 % limit);463 try testing.expect(packed_slice.get(2) == 4 % limit);
464 packed_slice.set(1, 7 % limit);464 packed_slice.set(1, 7 % limit);
465 testing.expect(packed_slice.get(1) == 7 % limit);465 try testing.expect(packed_slice.get(1) == 7 % limit);
466466
467 //write through slice467 //write through slice
468 testing.expect(packed_array.get(3) == 7 % limit);468 try testing.expect(packed_array.get(3) == 7 % limit);
469469
470 //slice of a slice470 //slice of a slice
471 const packed_slice_two = packed_slice.slice(0, 3);471 const packed_slice_two = packed_slice.slice(0, 3);
472 testing.expect(packed_slice_two.len() == 3);472 try testing.expect(packed_slice_two.len() == 3);
473 const ps2_bit_count = (bits * packed_slice_two.len()) + packed_slice_two.bit_offset;473 const ps2_bit_count = (bits * packed_slice_two.len()) + packed_slice_two.bit_offset;
474 const ps2_expected_bytes = (ps2_bit_count + 7) / 8;474 const ps2_expected_bytes = (ps2_bit_count + 7) / 8;
475 testing.expect(packed_slice_two.bytes.len == ps2_expected_bytes);475 try testing.expect(packed_slice_two.bytes.len == ps2_expected_bytes);
476 testing.expect(packed_slice_two.get(1) == 7 % limit);476 try testing.expect(packed_slice_two.get(1) == 7 % limit);
477 testing.expect(packed_slice_two.get(2) == 4 % limit);477 try testing.expect(packed_slice_two.get(2) == 4 % limit);
478478
479 //size one case479 //size one case
480 const packed_slice_three = packed_slice_two.slice(1, 2);480 const packed_slice_three = packed_slice_two.slice(1, 2);
481 testing.expect(packed_slice_three.len() == 1);481 try testing.expect(packed_slice_three.len() == 1);
482 const ps3_bit_count = (bits * packed_slice_three.len()) + packed_slice_three.bit_offset;482 const ps3_bit_count = (bits * packed_slice_three.len()) + packed_slice_three.bit_offset;
483 const ps3_expected_bytes = (ps3_bit_count + 7) / 8;483 const ps3_expected_bytes = (ps3_bit_count + 7) / 8;
484 testing.expect(packed_slice_three.bytes.len == ps3_expected_bytes);484 try testing.expect(packed_slice_three.bytes.len == ps3_expected_bytes);
485 testing.expect(packed_slice_three.get(0) == 7 % limit);485 try testing.expect(packed_slice_three.get(0) == 7 % limit);
486486
487 //empty slice case487 //empty slice case
488 const packed_slice_empty = packed_slice.slice(0, 0);488 const packed_slice_empty = packed_slice.slice(0, 0);
489 testing.expect(packed_slice_empty.len() == 0);489 try testing.expect(packed_slice_empty.len() == 0);
490 testing.expect(packed_slice_empty.bytes.len == 0);490 try testing.expect(packed_slice_empty.bytes.len == 0);
491491
492 //slicing at byte boundaries492 //slicing at byte boundaries
493 const packed_slice_edge = packed_array.slice(8, 16);493 const packed_slice_edge = packed_array.slice(8, 16);
494 testing.expect(packed_slice_edge.len() == 8);494 try testing.expect(packed_slice_edge.len() == 8);
495 const pse_bit_count = (bits * packed_slice_edge.len()) + packed_slice_edge.bit_offset;495 const pse_bit_count = (bits * packed_slice_edge.len()) + packed_slice_edge.bit_offset;
496 const pse_expected_bytes = (pse_bit_count + 7) / 8;496 const pse_expected_bytes = (pse_bit_count + 7) / 8;
497 testing.expect(packed_slice_edge.bytes.len == pse_expected_bytes);497 try testing.expect(packed_slice_edge.bytes.len == pse_expected_bytes);
498 testing.expect(packed_slice_edge.bit_offset == 0);498 try testing.expect(packed_slice_edge.bit_offset == 0);
499 }499 }
500}500}
501501
...@@ -543,7 +543,7 @@ test "PackedInt(Array/Slice) sliceCast" {...@@ -543,7 +543,7 @@ test "PackedInt(Array/Slice) sliceCast" {
543 .Big => 0b01,543 .Big => 0b01,
544 .Little => 0b10,544 .Little => 0b10,
545 };545 };
546 testing.expect(packed_slice_cast_2.get(i) == val);546 try testing.expect(packed_slice_cast_2.get(i) == val);
547 }547 }
548 i = 0;548 i = 0;
549 while (i < packed_slice_cast_4.len()) : (i += 1) {549 while (i < packed_slice_cast_4.len()) : (i += 1) {
...@@ -551,12 +551,12 @@ test "PackedInt(Array/Slice) sliceCast" {...@@ -551,12 +551,12 @@ test "PackedInt(Array/Slice) sliceCast" {
551 .Big => 0b0101,551 .Big => 0b0101,
552 .Little => 0b1010,552 .Little => 0b1010,
553 };553 };
554 testing.expect(packed_slice_cast_4.get(i) == val);554 try testing.expect(packed_slice_cast_4.get(i) == val);
555 }555 }
556 i = 0;556 i = 0;
557 while (i < packed_slice_cast_9.len()) : (i += 1) {557 while (i < packed_slice_cast_9.len()) : (i += 1) {
558 const val = 0b010101010;558 const val = 0b010101010;
559 testing.expect(packed_slice_cast_9.get(i) == val);559 try testing.expect(packed_slice_cast_9.get(i) == val);
560 packed_slice_cast_9.set(i, 0b111000111);560 packed_slice_cast_9.set(i, 0b111000111);
561 }561 }
562 i = 0;562 i = 0;
...@@ -565,7 +565,7 @@ test "PackedInt(Array/Slice) sliceCast" {...@@ -565,7 +565,7 @@ test "PackedInt(Array/Slice) sliceCast" {
565 .Big => if (i % 2 == 0) @as(u3, 0b111) else @as(u3, 0b000),565 .Big => if (i % 2 == 0) @as(u3, 0b111) else @as(u3, 0b000),
566 .Little => if (i % 2 == 0) @as(u3, 0b111) else @as(u3, 0b000),566 .Little => if (i % 2 == 0) @as(u3, 0b111) else @as(u3, 0b000),
567 };567 };
568 testing.expect(packed_slice_cast_3.get(i) == val);568 try testing.expect(packed_slice_cast_3.get(i) == val);
569 }569 }
570}570}
571571
...@@ -575,58 +575,58 @@ test "PackedInt(Array/Slice)Endian" {...@@ -575,58 +575,58 @@ test "PackedInt(Array/Slice)Endian" {
575 {575 {
576 const PackedArrayBe = PackedIntArrayEndian(u4, .Big, 8);576 const PackedArrayBe = PackedIntArrayEndian(u4, .Big, 8);
577 var packed_array_be = PackedArrayBe.init([_]u4{ 0, 1, 2, 3, 4, 5, 6, 7 });577 var packed_array_be = PackedArrayBe.init([_]u4{ 0, 1, 2, 3, 4, 5, 6, 7 });
578 testing.expect(packed_array_be.bytes[0] == 0b00000001);578 try testing.expect(packed_array_be.bytes[0] == 0b00000001);
579 testing.expect(packed_array_be.bytes[1] == 0b00100011);579 try testing.expect(packed_array_be.bytes[1] == 0b00100011);
580580
581 var i = @as(usize, 0);581 var i = @as(usize, 0);
582 while (i < packed_array_be.len()) : (i += 1) {582 while (i < packed_array_be.len()) : (i += 1) {
583 testing.expect(packed_array_be.get(i) == i);583 try testing.expect(packed_array_be.get(i) == i);
584 }584 }
585585
586 var packed_slice_le = packed_array_be.sliceCastEndian(u4, .Little);586 var packed_slice_le = packed_array_be.sliceCastEndian(u4, .Little);
587 i = 0;587 i = 0;
588 while (i < packed_slice_le.len()) : (i += 1) {588 while (i < packed_slice_le.len()) : (i += 1) {
589 const val = if (i % 2 == 0) i + 1 else i - 1;589 const val = if (i % 2 == 0) i + 1 else i - 1;
590 testing.expect(packed_slice_le.get(i) == val);590 try testing.expect(packed_slice_le.get(i) == val);
591 }591 }
592592
593 var packed_slice_le_shift = packed_array_be.slice(1, 5).sliceCastEndian(u4, .Little);593 var packed_slice_le_shift = packed_array_be.slice(1, 5).sliceCastEndian(u4, .Little);
594 i = 0;594 i = 0;
595 while (i < packed_slice_le_shift.len()) : (i += 1) {595 while (i < packed_slice_le_shift.len()) : (i += 1) {
596 const val = if (i % 2 == 0) i else i + 2;596 const val = if (i % 2 == 0) i else i + 2;
597 testing.expect(packed_slice_le_shift.get(i) == val);597 try testing.expect(packed_slice_le_shift.get(i) == val);
598 }598 }
599 }599 }
600600
601 {601 {
602 const PackedArrayBe = PackedIntArrayEndian(u11, .Big, 8);602 const PackedArrayBe = PackedIntArrayEndian(u11, .Big, 8);
603 var packed_array_be = PackedArrayBe.init([_]u11{ 0, 1, 2, 3, 4, 5, 6, 7 });603 var packed_array_be = PackedArrayBe.init([_]u11{ 0, 1, 2, 3, 4, 5, 6, 7 });
604 testing.expect(packed_array_be.bytes[0] == 0b00000000);604 try testing.expect(packed_array_be.bytes[0] == 0b00000000);
605 testing.expect(packed_array_be.bytes[1] == 0b00000000);605 try testing.expect(packed_array_be.bytes[1] == 0b00000000);
606 testing.expect(packed_array_be.bytes[2] == 0b00000100);606 try testing.expect(packed_array_be.bytes[2] == 0b00000100);
607 testing.expect(packed_array_be.bytes[3] == 0b00000001);607 try testing.expect(packed_array_be.bytes[3] == 0b00000001);
608 testing.expect(packed_array_be.bytes[4] == 0b00000000);608 try testing.expect(packed_array_be.bytes[4] == 0b00000000);
609609
610 var i = @as(usize, 0);610 var i = @as(usize, 0);
611 while (i < packed_array_be.len()) : (i += 1) {611 while (i < packed_array_be.len()) : (i += 1) {
612 testing.expect(packed_array_be.get(i) == i);612 try testing.expect(packed_array_be.get(i) == i);
613 }613 }
614614
615 var packed_slice_le = packed_array_be.sliceCastEndian(u11, .Little);615 var packed_slice_le = packed_array_be.sliceCastEndian(u11, .Little);
616 testing.expect(packed_slice_le.get(0) == 0b00000000000);616 try testing.expect(packed_slice_le.get(0) == 0b00000000000);
617 testing.expect(packed_slice_le.get(1) == 0b00010000000);617 try testing.expect(packed_slice_le.get(1) == 0b00010000000);
618 testing.expect(packed_slice_le.get(2) == 0b00000000100);618 try testing.expect(packed_slice_le.get(2) == 0b00000000100);
619 testing.expect(packed_slice_le.get(3) == 0b00000000000);619 try testing.expect(packed_slice_le.get(3) == 0b00000000000);
620 testing.expect(packed_slice_le.get(4) == 0b00010000011);620 try testing.expect(packed_slice_le.get(4) == 0b00010000011);
621 testing.expect(packed_slice_le.get(5) == 0b00000000010);621 try testing.expect(packed_slice_le.get(5) == 0b00000000010);
622 testing.expect(packed_slice_le.get(6) == 0b10000010000);622 try testing.expect(packed_slice_le.get(6) == 0b10000010000);
623 testing.expect(packed_slice_le.get(7) == 0b00000111001);623 try testing.expect(packed_slice_le.get(7) == 0b00000111001);
624624
625 var packed_slice_le_shift = packed_array_be.slice(1, 5).sliceCastEndian(u11, .Little);625 var packed_slice_le_shift = packed_array_be.slice(1, 5).sliceCastEndian(u11, .Little);
626 testing.expect(packed_slice_le_shift.get(0) == 0b00010000000);626 try testing.expect(packed_slice_le_shift.get(0) == 0b00010000000);
627 testing.expect(packed_slice_le_shift.get(1) == 0b00000000100);627 try testing.expect(packed_slice_le_shift.get(1) == 0b00000000100);
628 testing.expect(packed_slice_le_shift.get(2) == 0b00000000000);628 try testing.expect(packed_slice_le_shift.get(2) == 0b00000000000);
629 testing.expect(packed_slice_le_shift.get(3) == 0b00010000011);629 try testing.expect(packed_slice_le_shift.get(3) == 0b00010000011);
630 }630 }
631}631}
632632
lib/std/priority_dequeue.zig+89-89
...@@ -482,12 +482,12 @@ test "std.PriorityDequeue: add and remove min" {...@@ -482,12 +482,12 @@ test "std.PriorityDequeue: add and remove min" {
482 try queue.add(25);482 try queue.add(25);
483 try queue.add(13);483 try queue.add(13);
484484
485 expectEqual(@as(u32, 7), queue.removeMin());485 try expectEqual(@as(u32, 7), queue.removeMin());
486 expectEqual(@as(u32, 12), queue.removeMin());486 try expectEqual(@as(u32, 12), queue.removeMin());
487 expectEqual(@as(u32, 13), queue.removeMin());487 try expectEqual(@as(u32, 13), queue.removeMin());
488 expectEqual(@as(u32, 23), queue.removeMin());488 try expectEqual(@as(u32, 23), queue.removeMin());
489 expectEqual(@as(u32, 25), queue.removeMin());489 try expectEqual(@as(u32, 25), queue.removeMin());
490 expectEqual(@as(u32, 54), queue.removeMin());490 try expectEqual(@as(u32, 54), queue.removeMin());
491}491}
492492
493test "std.PriorityDequeue: add and remove min structs" {493test "std.PriorityDequeue: add and remove min structs" {
...@@ -508,12 +508,12 @@ test "std.PriorityDequeue: add and remove min structs" {...@@ -508,12 +508,12 @@ test "std.PriorityDequeue: add and remove min structs" {
508 try queue.add(.{ .size = 25 });508 try queue.add(.{ .size = 25 });
509 try queue.add(.{ .size = 13 });509 try queue.add(.{ .size = 13 });
510510
511 expectEqual(@as(u32, 7), queue.removeMin().size);511 try expectEqual(@as(u32, 7), queue.removeMin().size);
512 expectEqual(@as(u32, 12), queue.removeMin().size);512 try expectEqual(@as(u32, 12), queue.removeMin().size);
513 expectEqual(@as(u32, 13), queue.removeMin().size);513 try expectEqual(@as(u32, 13), queue.removeMin().size);
514 expectEqual(@as(u32, 23), queue.removeMin().size);514 try expectEqual(@as(u32, 23), queue.removeMin().size);
515 expectEqual(@as(u32, 25), queue.removeMin().size);515 try expectEqual(@as(u32, 25), queue.removeMin().size);
516 expectEqual(@as(u32, 54), queue.removeMin().size);516 try expectEqual(@as(u32, 54), queue.removeMin().size);
517}517}
518518
519test "std.PriorityDequeue: add and remove max" {519test "std.PriorityDequeue: add and remove max" {
...@@ -527,12 +527,12 @@ test "std.PriorityDequeue: add and remove max" {...@@ -527,12 +527,12 @@ test "std.PriorityDequeue: add and remove max" {
527 try queue.add(25);527 try queue.add(25);
528 try queue.add(13);528 try queue.add(13);
529529
530 expectEqual(@as(u32, 54), queue.removeMax());530 try expectEqual(@as(u32, 54), queue.removeMax());
531 expectEqual(@as(u32, 25), queue.removeMax());531 try expectEqual(@as(u32, 25), queue.removeMax());
532 expectEqual(@as(u32, 23), queue.removeMax());532 try expectEqual(@as(u32, 23), queue.removeMax());
533 expectEqual(@as(u32, 13), queue.removeMax());533 try expectEqual(@as(u32, 13), queue.removeMax());
534 expectEqual(@as(u32, 12), queue.removeMax());534 try expectEqual(@as(u32, 12), queue.removeMax());
535 expectEqual(@as(u32, 7), queue.removeMax());535 try expectEqual(@as(u32, 7), queue.removeMax());
536}536}
537537
538test "std.PriorityDequeue: add and remove same min" {538test "std.PriorityDequeue: add and remove same min" {
...@@ -546,12 +546,12 @@ test "std.PriorityDequeue: add and remove same min" {...@@ -546,12 +546,12 @@ test "std.PriorityDequeue: add and remove same min" {
546 try queue.add(1);546 try queue.add(1);
547 try queue.add(1);547 try queue.add(1);
548548
549 expectEqual(@as(u32, 1), queue.removeMin());549 try expectEqual(@as(u32, 1), queue.removeMin());
550 expectEqual(@as(u32, 1), queue.removeMin());550 try expectEqual(@as(u32, 1), queue.removeMin());
551 expectEqual(@as(u32, 1), queue.removeMin());551 try expectEqual(@as(u32, 1), queue.removeMin());
552 expectEqual(@as(u32, 1), queue.removeMin());552 try expectEqual(@as(u32, 1), queue.removeMin());
553 expectEqual(@as(u32, 2), queue.removeMin());553 try expectEqual(@as(u32, 2), queue.removeMin());
554 expectEqual(@as(u32, 2), queue.removeMin());554 try expectEqual(@as(u32, 2), queue.removeMin());
555}555}
556556
557test "std.PriorityDequeue: add and remove same max" {557test "std.PriorityDequeue: add and remove same max" {
...@@ -565,20 +565,20 @@ test "std.PriorityDequeue: add and remove same max" {...@@ -565,20 +565,20 @@ test "std.PriorityDequeue: add and remove same max" {
565 try queue.add(1);565 try queue.add(1);
566 try queue.add(1);566 try queue.add(1);
567567
568 expectEqual(@as(u32, 2), queue.removeMax());568 try expectEqual(@as(u32, 2), queue.removeMax());
569 expectEqual(@as(u32, 2), queue.removeMax());569 try expectEqual(@as(u32, 2), queue.removeMax());
570 expectEqual(@as(u32, 1), queue.removeMax());570 try expectEqual(@as(u32, 1), queue.removeMax());
571 expectEqual(@as(u32, 1), queue.removeMax());571 try expectEqual(@as(u32, 1), queue.removeMax());
572 expectEqual(@as(u32, 1), queue.removeMax());572 try expectEqual(@as(u32, 1), queue.removeMax());
573 expectEqual(@as(u32, 1), queue.removeMax());573 try expectEqual(@as(u32, 1), queue.removeMax());
574}574}
575575
576test "std.PriorityDequeue: removeOrNull empty" {576test "std.PriorityDequeue: removeOrNull empty" {
577 var queue = PDQ.init(testing.allocator, lessThanComparison);577 var queue = PDQ.init(testing.allocator, lessThanComparison);
578 defer queue.deinit();578 defer queue.deinit();
579579
580 expect(queue.removeMinOrNull() == null);580 try expect(queue.removeMinOrNull() == null);
581 expect(queue.removeMaxOrNull() == null);581 try expect(queue.removeMaxOrNull() == null);
582}582}
583583
584test "std.PriorityDequeue: edge case 3 elements" {584test "std.PriorityDequeue: edge case 3 elements" {
...@@ -589,9 +589,9 @@ test "std.PriorityDequeue: edge case 3 elements" {...@@ -589,9 +589,9 @@ test "std.PriorityDequeue: edge case 3 elements" {
589 try queue.add(3);589 try queue.add(3);
590 try queue.add(2);590 try queue.add(2);
591591
592 expectEqual(@as(u32, 2), queue.removeMin());592 try expectEqual(@as(u32, 2), queue.removeMin());
593 expectEqual(@as(u32, 3), queue.removeMin());593 try expectEqual(@as(u32, 3), queue.removeMin());
594 expectEqual(@as(u32, 9), queue.removeMin());594 try expectEqual(@as(u32, 9), queue.removeMin());
595}595}
596596
597test "std.PriorityDequeue: edge case 3 elements max" {597test "std.PriorityDequeue: edge case 3 elements max" {
...@@ -602,37 +602,37 @@ test "std.PriorityDequeue: edge case 3 elements max" {...@@ -602,37 +602,37 @@ test "std.PriorityDequeue: edge case 3 elements max" {
602 try queue.add(3);602 try queue.add(3);
603 try queue.add(2);603 try queue.add(2);
604604
605 expectEqual(@as(u32, 9), queue.removeMax());605 try expectEqual(@as(u32, 9), queue.removeMax());
606 expectEqual(@as(u32, 3), queue.removeMax());606 try expectEqual(@as(u32, 3), queue.removeMax());
607 expectEqual(@as(u32, 2), queue.removeMax());607 try expectEqual(@as(u32, 2), queue.removeMax());
608}608}
609609
610test "std.PriorityDequeue: peekMin" {610test "std.PriorityDequeue: peekMin" {
611 var queue = PDQ.init(testing.allocator, lessThanComparison);611 var queue = PDQ.init(testing.allocator, lessThanComparison);
612 defer queue.deinit();612 defer queue.deinit();
613613
614 expect(queue.peekMin() == null);614 try expect(queue.peekMin() == null);
615615
616 try queue.add(9);616 try queue.add(9);
617 try queue.add(3);617 try queue.add(3);
618 try queue.add(2);618 try queue.add(2);
619619
620 expect(queue.peekMin().? == 2);620 try expect(queue.peekMin().? == 2);
621 expect(queue.peekMin().? == 2);621 try expect(queue.peekMin().? == 2);
622}622}
623623
624test "std.PriorityDequeue: peekMax" {624test "std.PriorityDequeue: peekMax" {
625 var queue = PDQ.init(testing.allocator, lessThanComparison);625 var queue = PDQ.init(testing.allocator, lessThanComparison);
626 defer queue.deinit();626 defer queue.deinit();
627627
628 expect(queue.peekMin() == null);628 try expect(queue.peekMin() == null);
629629
630 try queue.add(9);630 try queue.add(9);
631 try queue.add(3);631 try queue.add(3);
632 try queue.add(2);632 try queue.add(2);
633633
634 expect(queue.peekMax().? == 9);634 try expect(queue.peekMax().? == 9);
635 expect(queue.peekMax().? == 9);635 try expect(queue.peekMax().? == 9);
636}636}
637637
638test "std.PriorityDequeue: sift up with odd indices" {638test "std.PriorityDequeue: sift up with odd indices" {
...@@ -645,7 +645,7 @@ test "std.PriorityDequeue: sift up with odd indices" {...@@ -645,7 +645,7 @@ test "std.PriorityDequeue: sift up with odd indices" {
645645
646 const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };646 const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
647 for (sorted_items) |e| {647 for (sorted_items) |e| {
648 expectEqual(e, queue.removeMin());648 try expectEqual(e, queue.removeMin());
649 }649 }
650}650}
651651
...@@ -659,7 +659,7 @@ test "std.PriorityDequeue: sift up with odd indices" {...@@ -659,7 +659,7 @@ test "std.PriorityDequeue: sift up with odd indices" {
659659
660 const sorted_items = [_]u32{ 25, 24, 24, 22, 21, 16, 15, 15, 14, 13, 12, 11, 7, 7, 6, 5, 2, 1 };660 const sorted_items = [_]u32{ 25, 24, 24, 22, 21, 16, 15, 15, 14, 13, 12, 11, 7, 7, 6, 5, 2, 1 };
661 for (sorted_items) |e| {661 for (sorted_items) |e| {
662 expectEqual(e, queue.removeMax());662 try expectEqual(e, queue.removeMax());
663 }663 }
664}664}
665665
...@@ -671,7 +671,7 @@ test "std.PriorityDequeue: addSlice min" {...@@ -671,7 +671,7 @@ test "std.PriorityDequeue: addSlice min" {
671671
672 const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };672 const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
673 for (sorted_items) |e| {673 for (sorted_items) |e| {
674 expectEqual(e, queue.removeMin());674 try expectEqual(e, queue.removeMin());
675 }675 }
676}676}
677677
...@@ -683,7 +683,7 @@ test "std.PriorityDequeue: addSlice max" {...@@ -683,7 +683,7 @@ test "std.PriorityDequeue: addSlice max" {
683683
684 const sorted_items = [_]u32{ 25, 24, 24, 22, 21, 16, 15, 15, 14, 13, 12, 11, 7, 7, 6, 5, 2, 1 };684 const sorted_items = [_]u32{ 25, 24, 24, 22, 21, 16, 15, 15, 14, 13, 12, 11, 7, 7, 6, 5, 2, 1 };
685 for (sorted_items) |e| {685 for (sorted_items) |e| {
686 expectEqual(e, queue.removeMax());686 try expectEqual(e, queue.removeMax());
687 }687 }
688}688}
689689
...@@ -692,8 +692,8 @@ test "std.PriorityDequeue: fromOwnedSlice trivial case 0" {...@@ -692,8 +692,8 @@ test "std.PriorityDequeue: fromOwnedSlice trivial case 0" {
692 const queue_items = try testing.allocator.dupe(u32, &items);692 const queue_items = try testing.allocator.dupe(u32, &items);
693 var queue = PDQ.fromOwnedSlice(testing.allocator, lessThanComparison, queue_items[0..]);693 var queue = PDQ.fromOwnedSlice(testing.allocator, lessThanComparison, queue_items[0..]);
694 defer queue.deinit();694 defer queue.deinit();
695 expectEqual(@as(usize, 0), queue.len);695 try expectEqual(@as(usize, 0), queue.len);
696 expect(queue.removeMinOrNull() == null);696 try expect(queue.removeMinOrNull() == null);
697}697}
698698
699test "std.PriorityDequeue: fromOwnedSlice trivial case 1" {699test "std.PriorityDequeue: fromOwnedSlice trivial case 1" {
...@@ -702,9 +702,9 @@ test "std.PriorityDequeue: fromOwnedSlice trivial case 1" {...@@ -702,9 +702,9 @@ test "std.PriorityDequeue: fromOwnedSlice trivial case 1" {
702 var queue = PDQ.fromOwnedSlice(testing.allocator, lessThanComparison, queue_items[0..]);702 var queue = PDQ.fromOwnedSlice(testing.allocator, lessThanComparison, queue_items[0..]);
703 defer queue.deinit();703 defer queue.deinit();
704704
705 expectEqual(@as(usize, 1), queue.len);705 try expectEqual(@as(usize, 1), queue.len);
706 expectEqual(items[0], queue.removeMin());706 try expectEqual(items[0], queue.removeMin());
707 expect(queue.removeMinOrNull() == null);707 try expect(queue.removeMinOrNull() == null);
708}708}
709709
710test "std.PriorityDequeue: fromOwnedSlice" {710test "std.PriorityDequeue: fromOwnedSlice" {
...@@ -715,7 +715,7 @@ test "std.PriorityDequeue: fromOwnedSlice" {...@@ -715,7 +715,7 @@ test "std.PriorityDequeue: fromOwnedSlice" {
715715
716 const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };716 const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
717 for (sorted_items) |e| {717 for (sorted_items) |e| {
718 expectEqual(e, queue.removeMin());718 try expectEqual(e, queue.removeMin());
719 }719 }
720}720}
721721
...@@ -729,9 +729,9 @@ test "std.PriorityDequeue: update min queue" {...@@ -729,9 +729,9 @@ test "std.PriorityDequeue: update min queue" {
729 try queue.update(55, 5);729 try queue.update(55, 5);
730 try queue.update(44, 4);730 try queue.update(44, 4);
731 try queue.update(11, 1);731 try queue.update(11, 1);
732 expectEqual(@as(u32, 1), queue.removeMin());732 try expectEqual(@as(u32, 1), queue.removeMin());
733 expectEqual(@as(u32, 4), queue.removeMin());733 try expectEqual(@as(u32, 4), queue.removeMin());
734 expectEqual(@as(u32, 5), queue.removeMin());734 try expectEqual(@as(u32, 5), queue.removeMin());
735}735}
736736
737test "std.PriorityDequeue: update same min queue" {737test "std.PriorityDequeue: update same min queue" {
...@@ -744,10 +744,10 @@ test "std.PriorityDequeue: update same min queue" {...@@ -744,10 +744,10 @@ test "std.PriorityDequeue: update same min queue" {
744 try queue.add(2);744 try queue.add(2);
745 try queue.update(1, 5);745 try queue.update(1, 5);
746 try queue.update(2, 4);746 try queue.update(2, 4);
747 expectEqual(@as(u32, 1), queue.removeMin());747 try expectEqual(@as(u32, 1), queue.removeMin());
748 expectEqual(@as(u32, 2), queue.removeMin());748 try expectEqual(@as(u32, 2), queue.removeMin());
749 expectEqual(@as(u32, 4), queue.removeMin());749 try expectEqual(@as(u32, 4), queue.removeMin());
750 expectEqual(@as(u32, 5), queue.removeMin());750 try expectEqual(@as(u32, 5), queue.removeMin());
751}751}
752752
753test "std.PriorityDequeue: update max queue" {753test "std.PriorityDequeue: update max queue" {
...@@ -761,9 +761,9 @@ test "std.PriorityDequeue: update max queue" {...@@ -761,9 +761,9 @@ test "std.PriorityDequeue: update max queue" {
761 try queue.update(44, 1);761 try queue.update(44, 1);
762 try queue.update(11, 4);762 try queue.update(11, 4);
763763
764 expectEqual(@as(u32, 5), queue.removeMax());764 try expectEqual(@as(u32, 5), queue.removeMax());
765 expectEqual(@as(u32, 4), queue.removeMax());765 try expectEqual(@as(u32, 4), queue.removeMax());
766 expectEqual(@as(u32, 1), queue.removeMax());766 try expectEqual(@as(u32, 1), queue.removeMax());
767}767}
768768
769test "std.PriorityDequeue: update same max queue" {769test "std.PriorityDequeue: update same max queue" {
...@@ -776,10 +776,10 @@ test "std.PriorityDequeue: update same max queue" {...@@ -776,10 +776,10 @@ test "std.PriorityDequeue: update same max queue" {
776 try queue.add(2);776 try queue.add(2);
777 try queue.update(1, 5);777 try queue.update(1, 5);
778 try queue.update(2, 4);778 try queue.update(2, 4);
779 expectEqual(@as(u32, 5), queue.removeMax());779 try expectEqual(@as(u32, 5), queue.removeMax());
780 expectEqual(@as(u32, 4), queue.removeMax());780 try expectEqual(@as(u32, 4), queue.removeMax());
781 expectEqual(@as(u32, 2), queue.removeMax());781 try expectEqual(@as(u32, 2), queue.removeMax());
782 expectEqual(@as(u32, 1), queue.removeMax());782 try expectEqual(@as(u32, 1), queue.removeMax());
783}783}
784784
785test "std.PriorityDequeue: iterator" {785test "std.PriorityDequeue: iterator" {
...@@ -801,7 +801,7 @@ test "std.PriorityDequeue: iterator" {...@@ -801,7 +801,7 @@ test "std.PriorityDequeue: iterator" {
801 _ = map.remove(e);801 _ = map.remove(e);
802 }802 }
803803
804 expectEqual(@as(usize, 0), map.count());804 try expectEqual(@as(usize, 0), map.count());
805}805}
806806
807test "std.PriorityDequeue: remove at index" {807test "std.PriorityDequeue: remove at index" {
...@@ -821,10 +821,10 @@ test "std.PriorityDequeue: remove at index" {...@@ -821,10 +821,10 @@ test "std.PriorityDequeue: remove at index" {
821 idx += 1;821 idx += 1;
822 } else unreachable;822 } else unreachable;
823823
824 expectEqual(queue.removeIndex(two_idx), 2);824 try expectEqual(queue.removeIndex(two_idx), 2);
825 expectEqual(queue.removeMin(), 1);825 try expectEqual(queue.removeMin(), 1);
826 expectEqual(queue.removeMin(), 3);826 try expectEqual(queue.removeMin(), 3);
827 expectEqual(queue.removeMinOrNull(), null);827 try expectEqual(queue.removeMinOrNull(), null);
828}828}
829829
830test "std.PriorityDequeue: iterator while empty" {830test "std.PriorityDequeue: iterator while empty" {
...@@ -833,7 +833,7 @@ test "std.PriorityDequeue: iterator while empty" {...@@ -833,7 +833,7 @@ test "std.PriorityDequeue: iterator while empty" {
833833
834 var it = queue.iterator();834 var it = queue.iterator();
835835
836 expectEqual(it.next(), null);836 try expectEqual(it.next(), null);
837}837}
838838
839test "std.PriorityDequeue: shrinkRetainingCapacity and shrinkAndFree" {839test "std.PriorityDequeue: shrinkRetainingCapacity and shrinkAndFree" {
...@@ -841,26 +841,26 @@ test "std.PriorityDequeue: shrinkRetainingCapacity and shrinkAndFree" {...@@ -841,26 +841,26 @@ test "std.PriorityDequeue: shrinkRetainingCapacity and shrinkAndFree" {
841 defer queue.deinit();841 defer queue.deinit();
842842
843 try queue.ensureCapacity(4);843 try queue.ensureCapacity(4);
844 expect(queue.capacity() >= 4);844 try expect(queue.capacity() >= 4);
845845
846 try queue.add(1);846 try queue.add(1);
847 try queue.add(2);847 try queue.add(2);
848 try queue.add(3);848 try queue.add(3);
849 expect(queue.capacity() >= 4);849 try expect(queue.capacity() >= 4);
850 expectEqual(@as(usize, 3), queue.len);850 try expectEqual(@as(usize, 3), queue.len);
851851
852 queue.shrinkRetainingCapacity(3);852 queue.shrinkRetainingCapacity(3);
853 expect(queue.capacity() >= 4);853 try expect(queue.capacity() >= 4);
854 expectEqual(@as(usize, 3), queue.len);854 try expectEqual(@as(usize, 3), queue.len);
855855
856 queue.shrinkAndFree(3);856 queue.shrinkAndFree(3);
857 expectEqual(@as(usize, 3), queue.capacity());857 try expectEqual(@as(usize, 3), queue.capacity());
858 expectEqual(@as(usize, 3), queue.len);858 try expectEqual(@as(usize, 3), queue.len);
859859
860 expectEqual(@as(u32, 3), queue.removeMax());860 try expectEqual(@as(u32, 3), queue.removeMax());
861 expectEqual(@as(u32, 2), queue.removeMax());861 try expectEqual(@as(u32, 2), queue.removeMax());
862 expectEqual(@as(u32, 1), queue.removeMax());862 try expectEqual(@as(u32, 1), queue.removeMax());
863 expect(queue.removeMaxOrNull() == null);863 try expect(queue.removeMaxOrNull() == null);
864}864}
865865
866test "std.PriorityDequeue: fuzz testing min" {866test "std.PriorityDequeue: fuzz testing min" {
...@@ -885,7 +885,7 @@ fn fuzzTestMin(rng: *std.rand.Random, comptime queue_size: usize) !void {...@@ -885,7 +885,7 @@ fn fuzzTestMin(rng: *std.rand.Random, comptime queue_size: usize) !void {
885 var last_removed: ?u32 = null;885 var last_removed: ?u32 = null;
886 while (queue.removeMinOrNull()) |next| {886 while (queue.removeMinOrNull()) |next| {
887 if (last_removed) |last| {887 if (last_removed) |last| {
888 expect(last <= next);888 try expect(last <= next);
889 }889 }
890 last_removed = next;890 last_removed = next;
891 }891 }
...@@ -913,7 +913,7 @@ fn fuzzTestMax(rng: *std.rand.Random, queue_size: usize) !void {...@@ -913,7 +913,7 @@ fn fuzzTestMax(rng: *std.rand.Random, queue_size: usize) !void {
913 var last_removed: ?u32 = null;913 var last_removed: ?u32 = null;
914 while (queue.removeMaxOrNull()) |next| {914 while (queue.removeMaxOrNull()) |next| {
915 if (last_removed) |last| {915 if (last_removed) |last| {
916 expect(last >= next);916 try expect(last >= next);
917 }917 }
918 last_removed = next;918 last_removed = next;
919 }919 }
...@@ -945,13 +945,13 @@ fn fuzzTestMinMax(rng: *std.rand.Random, queue_size: usize) !void {...@@ -945,13 +945,13 @@ fn fuzzTestMinMax(rng: *std.rand.Random, queue_size: usize) !void {
945 if (i % 2 == 0) {945 if (i % 2 == 0) {
946 const next = queue.removeMin();946 const next = queue.removeMin();
947 if (last_min) |last| {947 if (last_min) |last| {
948 expect(last <= next);948 try expect(last <= next);
949 }949 }
950 last_min = next;950 last_min = next;
951 } else {951 } else {
952 const next = queue.removeMax();952 const next = queue.removeMax();
953 if (last_max) |last| {953 if (last_max) |last| {
954 expect(last >= next);954 try expect(last >= next);
955 }955 }
956 last_max = next;956 last_max = next;
957 }957 }
lib/std/priority_queue.zig+70-70
...@@ -290,12 +290,12 @@ test "std.PriorityQueue: add and remove min heap" {...@@ -290,12 +290,12 @@ test "std.PriorityQueue: add and remove min heap" {
290 try queue.add(23);290 try queue.add(23);
291 try queue.add(25);291 try queue.add(25);
292 try queue.add(13);292 try queue.add(13);
293 expectEqual(@as(u32, 7), queue.remove());293 try expectEqual(@as(u32, 7), queue.remove());
294 expectEqual(@as(u32, 12), queue.remove());294 try expectEqual(@as(u32, 12), queue.remove());
295 expectEqual(@as(u32, 13), queue.remove());295 try expectEqual(@as(u32, 13), queue.remove());
296 expectEqual(@as(u32, 23), queue.remove());296 try expectEqual(@as(u32, 23), queue.remove());
297 expectEqual(@as(u32, 25), queue.remove());297 try expectEqual(@as(u32, 25), queue.remove());
298 expectEqual(@as(u32, 54), queue.remove());298 try expectEqual(@as(u32, 54), queue.remove());
299}299}
300300
301test "std.PriorityQueue: add and remove same min heap" {301test "std.PriorityQueue: add and remove same min heap" {
...@@ -308,19 +308,19 @@ test "std.PriorityQueue: add and remove same min heap" {...@@ -308,19 +308,19 @@ test "std.PriorityQueue: add and remove same min heap" {
308 try queue.add(2);308 try queue.add(2);
309 try queue.add(1);309 try queue.add(1);
310 try queue.add(1);310 try queue.add(1);
311 expectEqual(@as(u32, 1), queue.remove());311 try expectEqual(@as(u32, 1), queue.remove());
312 expectEqual(@as(u32, 1), queue.remove());312 try expectEqual(@as(u32, 1), queue.remove());
313 expectEqual(@as(u32, 1), queue.remove());313 try expectEqual(@as(u32, 1), queue.remove());
314 expectEqual(@as(u32, 1), queue.remove());314 try expectEqual(@as(u32, 1), queue.remove());
315 expectEqual(@as(u32, 2), queue.remove());315 try expectEqual(@as(u32, 2), queue.remove());
316 expectEqual(@as(u32, 2), queue.remove());316 try expectEqual(@as(u32, 2), queue.remove());
317}317}
318318
319test "std.PriorityQueue: removeOrNull on empty" {319test "std.PriorityQueue: removeOrNull on empty" {
320 var queue = PQ.init(testing.allocator, lessThan);320 var queue = PQ.init(testing.allocator, lessThan);
321 defer queue.deinit();321 defer queue.deinit();
322322
323 expect(queue.removeOrNull() == null);323 try expect(queue.removeOrNull() == null);
324}324}
325325
326test "std.PriorityQueue: edge case 3 elements" {326test "std.PriorityQueue: edge case 3 elements" {
...@@ -330,21 +330,21 @@ test "std.PriorityQueue: edge case 3 elements" {...@@ -330,21 +330,21 @@ test "std.PriorityQueue: edge case 3 elements" {
330 try queue.add(9);330 try queue.add(9);
331 try queue.add(3);331 try queue.add(3);
332 try queue.add(2);332 try queue.add(2);
333 expectEqual(@as(u32, 2), queue.remove());333 try expectEqual(@as(u32, 2), queue.remove());
334 expectEqual(@as(u32, 3), queue.remove());334 try expectEqual(@as(u32, 3), queue.remove());
335 expectEqual(@as(u32, 9), queue.remove());335 try expectEqual(@as(u32, 9), queue.remove());
336}336}
337337
338test "std.PriorityQueue: peek" {338test "std.PriorityQueue: peek" {
339 var queue = PQ.init(testing.allocator, lessThan);339 var queue = PQ.init(testing.allocator, lessThan);
340 defer queue.deinit();340 defer queue.deinit();
341341
342 expect(queue.peek() == null);342 try expect(queue.peek() == null);
343 try queue.add(9);343 try queue.add(9);
344 try queue.add(3);344 try queue.add(3);
345 try queue.add(2);345 try queue.add(2);
346 expectEqual(@as(u32, 2), queue.peek().?);346 try expectEqual(@as(u32, 2), queue.peek().?);
347 expectEqual(@as(u32, 2), queue.peek().?);347 try expectEqual(@as(u32, 2), queue.peek().?);
348}348}
349349
350test "std.PriorityQueue: sift up with odd indices" {350test "std.PriorityQueue: sift up with odd indices" {
...@@ -357,7 +357,7 @@ test "std.PriorityQueue: sift up with odd indices" {...@@ -357,7 +357,7 @@ test "std.PriorityQueue: sift up with odd indices" {
357357
358 const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };358 const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
359 for (sorted_items) |e| {359 for (sorted_items) |e| {
360 expectEqual(e, queue.remove());360 try expectEqual(e, queue.remove());
361 }361 }
362}362}
363363
...@@ -369,7 +369,7 @@ test "std.PriorityQueue: addSlice" {...@@ -369,7 +369,7 @@ test "std.PriorityQueue: addSlice" {
369369
370 const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };370 const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
371 for (sorted_items) |e| {371 for (sorted_items) |e| {
372 expectEqual(e, queue.remove());372 try expectEqual(e, queue.remove());
373 }373 }
374}374}
375375
...@@ -378,8 +378,8 @@ test "std.PriorityQueue: fromOwnedSlice trivial case 0" {...@@ -378,8 +378,8 @@ test "std.PriorityQueue: fromOwnedSlice trivial case 0" {
378 const queue_items = try testing.allocator.dupe(u32, &items);378 const queue_items = try testing.allocator.dupe(u32, &items);
379 var queue = PQ.fromOwnedSlice(testing.allocator, lessThan, queue_items[0..]);379 var queue = PQ.fromOwnedSlice(testing.allocator, lessThan, queue_items[0..]);
380 defer queue.deinit();380 defer queue.deinit();
381 expectEqual(@as(usize, 0), queue.len);381 try expectEqual(@as(usize, 0), queue.len);
382 expect(queue.removeOrNull() == null);382 try expect(queue.removeOrNull() == null);
383}383}
384384
385test "std.PriorityQueue: fromOwnedSlice trivial case 1" {385test "std.PriorityQueue: fromOwnedSlice trivial case 1" {
...@@ -388,9 +388,9 @@ test "std.PriorityQueue: fromOwnedSlice trivial case 1" {...@@ -388,9 +388,9 @@ test "std.PriorityQueue: fromOwnedSlice trivial case 1" {
388 var queue = PQ.fromOwnedSlice(testing.allocator, lessThan, queue_items[0..]);388 var queue = PQ.fromOwnedSlice(testing.allocator, lessThan, queue_items[0..]);
389 defer queue.deinit();389 defer queue.deinit();
390390
391 expectEqual(@as(usize, 1), queue.len);391 try expectEqual(@as(usize, 1), queue.len);
392 expectEqual(items[0], queue.remove());392 try expectEqual(items[0], queue.remove());
393 expect(queue.removeOrNull() == null);393 try expect(queue.removeOrNull() == null);
394}394}
395395
396test "std.PriorityQueue: fromOwnedSlice" {396test "std.PriorityQueue: fromOwnedSlice" {
...@@ -401,7 +401,7 @@ test "std.PriorityQueue: fromOwnedSlice" {...@@ -401,7 +401,7 @@ test "std.PriorityQueue: fromOwnedSlice" {
401401
402 const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };402 const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
403 for (sorted_items) |e| {403 for (sorted_items) |e| {
404 expectEqual(e, queue.remove());404 try expectEqual(e, queue.remove());
405 }405 }
406}406}
407407
...@@ -415,12 +415,12 @@ test "std.PriorityQueue: add and remove max heap" {...@@ -415,12 +415,12 @@ test "std.PriorityQueue: add and remove max heap" {
415 try queue.add(23);415 try queue.add(23);
416 try queue.add(25);416 try queue.add(25);
417 try queue.add(13);417 try queue.add(13);
418 expectEqual(@as(u32, 54), queue.remove());418 try expectEqual(@as(u32, 54), queue.remove());
419 expectEqual(@as(u32, 25), queue.remove());419 try expectEqual(@as(u32, 25), queue.remove());
420 expectEqual(@as(u32, 23), queue.remove());420 try expectEqual(@as(u32, 23), queue.remove());
421 expectEqual(@as(u32, 13), queue.remove());421 try expectEqual(@as(u32, 13), queue.remove());
422 expectEqual(@as(u32, 12), queue.remove());422 try expectEqual(@as(u32, 12), queue.remove());
423 expectEqual(@as(u32, 7), queue.remove());423 try expectEqual(@as(u32, 7), queue.remove());
424}424}
425425
426test "std.PriorityQueue: add and remove same max heap" {426test "std.PriorityQueue: add and remove same max heap" {
...@@ -433,12 +433,12 @@ test "std.PriorityQueue: add and remove same max heap" {...@@ -433,12 +433,12 @@ test "std.PriorityQueue: add and remove same max heap" {
433 try queue.add(2);433 try queue.add(2);
434 try queue.add(1);434 try queue.add(1);
435 try queue.add(1);435 try queue.add(1);
436 expectEqual(@as(u32, 2), queue.remove());436 try expectEqual(@as(u32, 2), queue.remove());
437 expectEqual(@as(u32, 2), queue.remove());437 try expectEqual(@as(u32, 2), queue.remove());
438 expectEqual(@as(u32, 1), queue.remove());438 try expectEqual(@as(u32, 1), queue.remove());
439 expectEqual(@as(u32, 1), queue.remove());439 try expectEqual(@as(u32, 1), queue.remove());
440 expectEqual(@as(u32, 1), queue.remove());440 try expectEqual(@as(u32, 1), queue.remove());
441 expectEqual(@as(u32, 1), queue.remove());441 try expectEqual(@as(u32, 1), queue.remove());
442}442}
443443
444test "std.PriorityQueue: iterator" {444test "std.PriorityQueue: iterator" {
...@@ -460,7 +460,7 @@ test "std.PriorityQueue: iterator" {...@@ -460,7 +460,7 @@ test "std.PriorityQueue: iterator" {
460 _ = map.remove(e);460 _ = map.remove(e);
461 }461 }
462462
463 expectEqual(@as(usize, 0), map.count());463 try expectEqual(@as(usize, 0), map.count());
464}464}
465465
466test "std.PriorityQueue: remove at index" {466test "std.PriorityQueue: remove at index" {
...@@ -480,10 +480,10 @@ test "std.PriorityQueue: remove at index" {...@@ -480,10 +480,10 @@ test "std.PriorityQueue: remove at index" {
480 idx += 1;480 idx += 1;
481 } else unreachable;481 } else unreachable;
482482
483 expectEqual(queue.removeIndex(two_idx), 2);483 try expectEqual(queue.removeIndex(two_idx), 2);
484 expectEqual(queue.remove(), 1);484 try expectEqual(queue.remove(), 1);
485 expectEqual(queue.remove(), 3);485 try expectEqual(queue.remove(), 3);
486 expectEqual(queue.removeOrNull(), null);486 try expectEqual(queue.removeOrNull(), null);
487}487}
488488
489test "std.PriorityQueue: iterator while empty" {489test "std.PriorityQueue: iterator while empty" {
...@@ -492,7 +492,7 @@ test "std.PriorityQueue: iterator while empty" {...@@ -492,7 +492,7 @@ test "std.PriorityQueue: iterator while empty" {
492492
493 var it = queue.iterator();493 var it = queue.iterator();
494494
495 expectEqual(it.next(), null);495 try expectEqual(it.next(), null);
496}496}
497497
498test "std.PriorityQueue: shrinkRetainingCapacity and shrinkAndFree" {498test "std.PriorityQueue: shrinkRetainingCapacity and shrinkAndFree" {
...@@ -500,26 +500,26 @@ test "std.PriorityQueue: shrinkRetainingCapacity and shrinkAndFree" {...@@ -500,26 +500,26 @@ test "std.PriorityQueue: shrinkRetainingCapacity and shrinkAndFree" {
500 defer queue.deinit();500 defer queue.deinit();
501501
502 try queue.ensureCapacity(4);502 try queue.ensureCapacity(4);
503 expect(queue.capacity() >= 4);503 try expect(queue.capacity() >= 4);
504504
505 try queue.add(1);505 try queue.add(1);
506 try queue.add(2);506 try queue.add(2);
507 try queue.add(3);507 try queue.add(3);
508 expect(queue.capacity() >= 4);508 try expect(queue.capacity() >= 4);
509 expectEqual(@as(usize, 3), queue.len);509 try expectEqual(@as(usize, 3), queue.len);
510510
511 queue.shrinkRetainingCapacity(3);511 queue.shrinkRetainingCapacity(3);
512 expect(queue.capacity() >= 4);512 try expect(queue.capacity() >= 4);
513 expectEqual(@as(usize, 3), queue.len);513 try expectEqual(@as(usize, 3), queue.len);
514514
515 queue.shrinkAndFree(3);515 queue.shrinkAndFree(3);
516 expectEqual(@as(usize, 3), queue.capacity());516 try expectEqual(@as(usize, 3), queue.capacity());
517 expectEqual(@as(usize, 3), queue.len);517 try expectEqual(@as(usize, 3), queue.len);
518518
519 expectEqual(@as(u32, 1), queue.remove());519 try expectEqual(@as(u32, 1), queue.remove());
520 expectEqual(@as(u32, 2), queue.remove());520 try expectEqual(@as(u32, 2), queue.remove());
521 expectEqual(@as(u32, 3), queue.remove());521 try expectEqual(@as(u32, 3), queue.remove());
522 expect(queue.removeOrNull() == null);522 try expect(queue.removeOrNull() == null);
523}523}
524524
525test "std.PriorityQueue: update min heap" {525test "std.PriorityQueue: update min heap" {
...@@ -532,9 +532,9 @@ test "std.PriorityQueue: update min heap" {...@@ -532,9 +532,9 @@ test "std.PriorityQueue: update min heap" {
532 try queue.update(55, 5);532 try queue.update(55, 5);
533 try queue.update(44, 4);533 try queue.update(44, 4);
534 try queue.update(11, 1);534 try queue.update(11, 1);
535 expectEqual(@as(u32, 1), queue.remove());535 try expectEqual(@as(u32, 1), queue.remove());
536 expectEqual(@as(u32, 4), queue.remove());536 try expectEqual(@as(u32, 4), queue.remove());
537 expectEqual(@as(u32, 5), queue.remove());537 try expectEqual(@as(u32, 5), queue.remove());
538}538}
539539
540test "std.PriorityQueue: update same min heap" {540test "std.PriorityQueue: update same min heap" {
...@@ -547,10 +547,10 @@ test "std.PriorityQueue: update same min heap" {...@@ -547,10 +547,10 @@ test "std.PriorityQueue: update same min heap" {
547 try queue.add(2);547 try queue.add(2);
548 try queue.update(1, 5);548 try queue.update(1, 5);
549 try queue.update(2, 4);549 try queue.update(2, 4);
550 expectEqual(@as(u32, 1), queue.remove());550 try expectEqual(@as(u32, 1), queue.remove());
551 expectEqual(@as(u32, 2), queue.remove());551 try expectEqual(@as(u32, 2), queue.remove());
552 expectEqual(@as(u32, 4), queue.remove());552 try expectEqual(@as(u32, 4), queue.remove());
553 expectEqual(@as(u32, 5), queue.remove());553 try expectEqual(@as(u32, 5), queue.remove());
554}554}
555555
556test "std.PriorityQueue: update max heap" {556test "std.PriorityQueue: update max heap" {
...@@ -563,9 +563,9 @@ test "std.PriorityQueue: update max heap" {...@@ -563,9 +563,9 @@ test "std.PriorityQueue: update max heap" {
563 try queue.update(55, 5);563 try queue.update(55, 5);
564 try queue.update(44, 1);564 try queue.update(44, 1);
565 try queue.update(11, 4);565 try queue.update(11, 4);
566 expectEqual(@as(u32, 5), queue.remove());566 try expectEqual(@as(u32, 5), queue.remove());
567 expectEqual(@as(u32, 4), queue.remove());567 try expectEqual(@as(u32, 4), queue.remove());
568 expectEqual(@as(u32, 1), queue.remove());568 try expectEqual(@as(u32, 1), queue.remove());
569}569}
570570
571test "std.PriorityQueue: update same max heap" {571test "std.PriorityQueue: update same max heap" {
...@@ -578,8 +578,8 @@ test "std.PriorityQueue: update same max heap" {...@@ -578,8 +578,8 @@ test "std.PriorityQueue: update same max heap" {
578 try queue.add(2);578 try queue.add(2);
579 try queue.update(1, 5);579 try queue.update(1, 5);
580 try queue.update(2, 4);580 try queue.update(2, 4);
581 expectEqual(@as(u32, 5), queue.remove());581 try expectEqual(@as(u32, 5), queue.remove());
582 expectEqual(@as(u32, 4), queue.remove());582 try expectEqual(@as(u32, 4), queue.remove());
583 expectEqual(@as(u32, 2), queue.remove());583 try expectEqual(@as(u32, 2), queue.remove());
584 expectEqual(@as(u32, 1), queue.remove());584 try expectEqual(@as(u32, 1), queue.remove());
585}585}
lib/std/process.zig+16-16
...@@ -181,7 +181,7 @@ pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) GetEnvVarOwned...@@ -181,7 +181,7 @@ pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) GetEnvVarOwned
181181
182test "os.getEnvVarOwned" {182test "os.getEnvVarOwned" {
183 var ga = std.testing.allocator;183 var ga = std.testing.allocator;
184 testing.expectError(error.EnvironmentVariableNotFound, getEnvVarOwned(ga, "BADENV"));184 try testing.expectError(error.EnvironmentVariableNotFound, getEnvVarOwned(ga, "BADENV"));
185}185}
186186
187pub const ArgIteratorPosix = struct {187pub const ArgIteratorPosix = struct {
...@@ -516,10 +516,10 @@ test "args iterator" {...@@ -516,10 +516,10 @@ test "args iterator" {
516 };516 };
517 const given_suffix = std.fs.path.basename(prog_name);517 const given_suffix = std.fs.path.basename(prog_name);
518518
519 testing.expect(mem.eql(u8, expected_suffix, given_suffix));519 try testing.expect(mem.eql(u8, expected_suffix, given_suffix));
520 testing.expect(it.skip()); // Skip over zig_exe_path, passed to the test runner520 try testing.expect(it.skip()); // Skip over zig_exe_path, passed to the test runner
521 testing.expect(it.next(ga) == null);521 try testing.expect(it.next(ga) == null);
522 testing.expect(!it.skip());522 try testing.expect(!it.skip());
523}523}
524524
525/// Caller must call argsFree on result.525/// Caller must call argsFree on result.
...@@ -575,14 +575,14 @@ pub fn argsFree(allocator: *mem.Allocator, args_alloc: []const [:0]u8) void {...@@ -575,14 +575,14 @@ pub fn argsFree(allocator: *mem.Allocator, args_alloc: []const [:0]u8) void {
575575
576test "windows arg parsing" {576test "windows arg parsing" {
577 const utf16Literal = std.unicode.utf8ToUtf16LeStringLiteral;577 const utf16Literal = std.unicode.utf8ToUtf16LeStringLiteral;
578 testWindowsCmdLine(utf16Literal("a b\tc d"), &[_][]const u8{ "a", "b", "c", "d" });578 try testWindowsCmdLine(utf16Literal("a b\tc d"), &[_][]const u8{ "a", "b", "c", "d" });
579 testWindowsCmdLine(utf16Literal("\"abc\" d e"), &[_][]const u8{ "abc", "d", "e" });579 try testWindowsCmdLine(utf16Literal("\"abc\" d e"), &[_][]const u8{ "abc", "d", "e" });
580 testWindowsCmdLine(utf16Literal("a\\\\\\b d\"e f\"g h"), &[_][]const u8{ "a\\\\\\b", "de fg", "h" });580 try testWindowsCmdLine(utf16Literal("a\\\\\\b d\"e f\"g h"), &[_][]const u8{ "a\\\\\\b", "de fg", "h" });
581 testWindowsCmdLine(utf16Literal("a\\\\\\\"b c d"), &[_][]const u8{ "a\\\"b", "c", "d" });581 try testWindowsCmdLine(utf16Literal("a\\\\\\\"b c d"), &[_][]const u8{ "a\\\"b", "c", "d" });
582 testWindowsCmdLine(utf16Literal("a\\\\\\\\\"b c\" d e"), &[_][]const u8{ "a\\\\b c", "d", "e" });582 try testWindowsCmdLine(utf16Literal("a\\\\\\\\\"b c\" d e"), &[_][]const u8{ "a\\\\b c", "d", "e" });
583 testWindowsCmdLine(utf16Literal("a b\tc \"d f"), &[_][]const u8{ "a", "b", "c", "d f" });583 try testWindowsCmdLine(utf16Literal("a b\tc \"d f"), &[_][]const u8{ "a", "b", "c", "d f" });
584584
585 testWindowsCmdLine(utf16Literal("\".\\..\\zig-cache\\build\" \"bin\\zig.exe\" \".\\..\" \".\\..\\zig-cache\" \"--help\""), &[_][]const u8{585 try testWindowsCmdLine(utf16Literal("\".\\..\\zig-cache\\build\" \"bin\\zig.exe\" \".\\..\" \".\\..\\zig-cache\" \"--help\""), &[_][]const u8{
586 ".\\..\\zig-cache\\build",586 ".\\..\\zig-cache\\build",
587 "bin\\zig.exe",587 "bin\\zig.exe",
588 ".\\..",588 ".\\..",
...@@ -591,14 +591,14 @@ test "windows arg parsing" {...@@ -591,14 +591,14 @@ test "windows arg parsing" {
591 });591 });
592}592}
593593
594fn testWindowsCmdLine(input_cmd_line: [*]const u16, expected_args: []const []const u8) void {594fn testWindowsCmdLine(input_cmd_line: [*]const u16, expected_args: []const []const u8) !void {
595 var it = ArgIteratorWindows.initWithCmdLine(input_cmd_line);595 var it = ArgIteratorWindows.initWithCmdLine(input_cmd_line);
596 for (expected_args) |expected_arg| {596 for (expected_args) |expected_arg| {
597 const arg = it.next(std.testing.allocator).? catch unreachable;597 const arg = it.next(std.testing.allocator).? catch unreachable;
598 defer std.testing.allocator.free(arg);598 defer std.testing.allocator.free(arg);
599 testing.expectEqualStrings(expected_arg, arg);599 try testing.expectEqualStrings(expected_arg, arg);
600 }600 }
601 testing.expect(it.next(std.testing.allocator) == null);601 try testing.expect(it.next(std.testing.allocator) == null);
602}602}
603603
604pub const UserInfo = struct {604pub const UserInfo = struct {
lib/std/rand.zig+96-96
...@@ -319,139 +319,139 @@ const SequentialPrng = struct {...@@ -319,139 +319,139 @@ const SequentialPrng = struct {
319};319};
320320
321test "Random int" {321test "Random int" {
322 testRandomInt();322 try testRandomInt();
323 comptime testRandomInt();323 comptime try testRandomInt();
324}324}
325fn testRandomInt() void {325fn testRandomInt() !void {
326 var r = SequentialPrng.init();326 var r = SequentialPrng.init();
327327
328 expect(r.random.int(u0) == 0);328 try expect(r.random.int(u0) == 0);
329329
330 r.next_value = 0;330 r.next_value = 0;
331 expect(r.random.int(u1) == 0);331 try expect(r.random.int(u1) == 0);
332 expect(r.random.int(u1) == 1);332 try expect(r.random.int(u1) == 1);
333 expect(r.random.int(u2) == 2);333 try expect(r.random.int(u2) == 2);
334 expect(r.random.int(u2) == 3);334 try expect(r.random.int(u2) == 3);
335 expect(r.random.int(u2) == 0);335 try expect(r.random.int(u2) == 0);
336336
337 r.next_value = 0xff;337 r.next_value = 0xff;
338 expect(r.random.int(u8) == 0xff);338 try expect(r.random.int(u8) == 0xff);
339 r.next_value = 0x11;339 r.next_value = 0x11;
340 expect(r.random.int(u8) == 0x11);340 try expect(r.random.int(u8) == 0x11);
341341
342 r.next_value = 0xff;342 r.next_value = 0xff;
343 expect(r.random.int(u32) == 0xffffffff);343 try expect(r.random.int(u32) == 0xffffffff);
344 r.next_value = 0x11;344 r.next_value = 0x11;
345 expect(r.random.int(u32) == 0x11111111);345 try expect(r.random.int(u32) == 0x11111111);
346346
347 r.next_value = 0xff;347 r.next_value = 0xff;
348 expect(r.random.int(i32) == -1);348 try expect(r.random.int(i32) == -1);
349 r.next_value = 0x11;349 r.next_value = 0x11;
350 expect(r.random.int(i32) == 0x11111111);350 try expect(r.random.int(i32) == 0x11111111);
351351
352 r.next_value = 0xff;352 r.next_value = 0xff;
353 expect(r.random.int(i8) == -1);353 try expect(r.random.int(i8) == -1);
354 r.next_value = 0x11;354 r.next_value = 0x11;
355 expect(r.random.int(i8) == 0x11);355 try expect(r.random.int(i8) == 0x11);
356356
357 r.next_value = 0xff;357 r.next_value = 0xff;
358 expect(r.random.int(u33) == 0x1ffffffff);358 try expect(r.random.int(u33) == 0x1ffffffff);
359 r.next_value = 0xff;359 r.next_value = 0xff;
360 expect(r.random.int(i1) == -1);360 try expect(r.random.int(i1) == -1);
361 r.next_value = 0xff;361 r.next_value = 0xff;
362 expect(r.random.int(i2) == -1);362 try expect(r.random.int(i2) == -1);
363 r.next_value = 0xff;363 r.next_value = 0xff;
364 expect(r.random.int(i33) == -1);364 try expect(r.random.int(i33) == -1);
365}365}
366366
367test "Random boolean" {367test "Random boolean" {
368 testRandomBoolean();368 try testRandomBoolean();
369 comptime testRandomBoolean();369 comptime try testRandomBoolean();
370}370}
371fn testRandomBoolean() void {371fn testRandomBoolean() !void {
372 var r = SequentialPrng.init();372 var r = SequentialPrng.init();
373 expect(r.random.boolean() == false);373 try expect(r.random.boolean() == false);
374 expect(r.random.boolean() == true);374 try expect(r.random.boolean() == true);
375 expect(r.random.boolean() == false);375 try expect(r.random.boolean() == false);
376 expect(r.random.boolean() == true);376 try expect(r.random.boolean() == true);
377}377}
378378
379test "Random intLessThan" {379test "Random intLessThan" {
380 @setEvalBranchQuota(10000);380 @setEvalBranchQuota(10000);
381 testRandomIntLessThan();381 try testRandomIntLessThan();
382 comptime testRandomIntLessThan();382 comptime try testRandomIntLessThan();
383}383}
384fn testRandomIntLessThan() void {384fn testRandomIntLessThan() !void {
385 var r = SequentialPrng.init();385 var r = SequentialPrng.init();
386 r.next_value = 0xff;386 r.next_value = 0xff;
387 expect(r.random.uintLessThan(u8, 4) == 3);387 try expect(r.random.uintLessThan(u8, 4) == 3);
388 expect(r.next_value == 0);388 try expect(r.next_value == 0);
389 expect(r.random.uintLessThan(u8, 4) == 0);389 try expect(r.random.uintLessThan(u8, 4) == 0);
390 expect(r.next_value == 1);390 try expect(r.next_value == 1);
391391
392 r.next_value = 0;392 r.next_value = 0;
393 expect(r.random.uintLessThan(u64, 32) == 0);393 try expect(r.random.uintLessThan(u64, 32) == 0);
394394
395 // trigger the bias rejection code path395 // trigger the bias rejection code path
396 r.next_value = 0;396 r.next_value = 0;
397 expect(r.random.uintLessThan(u8, 3) == 0);397 try expect(r.random.uintLessThan(u8, 3) == 0);
398 // verify we incremented twice398 // verify we incremented twice
399 expect(r.next_value == 2);399 try expect(r.next_value == 2);
400400
401 r.next_value = 0xff;401 r.next_value = 0xff;
402 expect(r.random.intRangeLessThan(u8, 0, 0x80) == 0x7f);402 try expect(r.random.intRangeLessThan(u8, 0, 0x80) == 0x7f);
403 r.next_value = 0xff;403 r.next_value = 0xff;
404 expect(r.random.intRangeLessThan(u8, 0x7f, 0xff) == 0xfe);404 try expect(r.random.intRangeLessThan(u8, 0x7f, 0xff) == 0xfe);
405405
406 r.next_value = 0xff;406 r.next_value = 0xff;
407 expect(r.random.intRangeLessThan(i8, 0, 0x40) == 0x3f);407 try expect(r.random.intRangeLessThan(i8, 0, 0x40) == 0x3f);
408 r.next_value = 0xff;408 r.next_value = 0xff;
409 expect(r.random.intRangeLessThan(i8, -0x40, 0x40) == 0x3f);409 try expect(r.random.intRangeLessThan(i8, -0x40, 0x40) == 0x3f);
410 r.next_value = 0xff;410 r.next_value = 0xff;
411 expect(r.random.intRangeLessThan(i8, -0x80, 0) == -1);411 try expect(r.random.intRangeLessThan(i8, -0x80, 0) == -1);
412412
413 r.next_value = 0xff;413 r.next_value = 0xff;
414 expect(r.random.intRangeLessThan(i3, -4, 0) == -1);414 try expect(r.random.intRangeLessThan(i3, -4, 0) == -1);
415 r.next_value = 0xff;415 r.next_value = 0xff;
416 expect(r.random.intRangeLessThan(i3, -2, 2) == 1);416 try expect(r.random.intRangeLessThan(i3, -2, 2) == 1);
417}417}
418418
419test "Random intAtMost" {419test "Random intAtMost" {
420 @setEvalBranchQuota(10000);420 @setEvalBranchQuota(10000);
421 testRandomIntAtMost();421 try testRandomIntAtMost();
422 comptime testRandomIntAtMost();422 comptime try testRandomIntAtMost();
423}423}
424fn testRandomIntAtMost() void {424fn testRandomIntAtMost() !void {
425 var r = SequentialPrng.init();425 var r = SequentialPrng.init();
426 r.next_value = 0xff;426 r.next_value = 0xff;
427 expect(r.random.uintAtMost(u8, 3) == 3);427 try expect(r.random.uintAtMost(u8, 3) == 3);
428 expect(r.next_value == 0);428 try expect(r.next_value == 0);
429 expect(r.random.uintAtMost(u8, 3) == 0);429 try expect(r.random.uintAtMost(u8, 3) == 0);
430430
431 // trigger the bias rejection code path431 // trigger the bias rejection code path
432 r.next_value = 0;432 r.next_value = 0;
433 expect(r.random.uintAtMost(u8, 2) == 0);433 try expect(r.random.uintAtMost(u8, 2) == 0);
434 // verify we incremented twice434 // verify we incremented twice
435 expect(r.next_value == 2);435 try expect(r.next_value == 2);
436436
437 r.next_value = 0xff;437 r.next_value = 0xff;
438 expect(r.random.intRangeAtMost(u8, 0, 0x7f) == 0x7f);438 try expect(r.random.intRangeAtMost(u8, 0, 0x7f) == 0x7f);
439 r.next_value = 0xff;439 r.next_value = 0xff;
440 expect(r.random.intRangeAtMost(u8, 0x7f, 0xfe) == 0xfe);440 try expect(r.random.intRangeAtMost(u8, 0x7f, 0xfe) == 0xfe);
441441
442 r.next_value = 0xff;442 r.next_value = 0xff;
443 expect(r.random.intRangeAtMost(i8, 0, 0x3f) == 0x3f);443 try expect(r.random.intRangeAtMost(i8, 0, 0x3f) == 0x3f);
444 r.next_value = 0xff;444 r.next_value = 0xff;
445 expect(r.random.intRangeAtMost(i8, -0x40, 0x3f) == 0x3f);445 try expect(r.random.intRangeAtMost(i8, -0x40, 0x3f) == 0x3f);
446 r.next_value = 0xff;446 r.next_value = 0xff;
447 expect(r.random.intRangeAtMost(i8, -0x80, -1) == -1);447 try expect(r.random.intRangeAtMost(i8, -0x80, -1) == -1);
448448
449 r.next_value = 0xff;449 r.next_value = 0xff;
450 expect(r.random.intRangeAtMost(i3, -4, -1) == -1);450 try expect(r.random.intRangeAtMost(i3, -4, -1) == -1);
451 r.next_value = 0xff;451 r.next_value = 0xff;
452 expect(r.random.intRangeAtMost(i3, -2, 1) == 1);452 try expect(r.random.intRangeAtMost(i3, -2, 1) == 1);
453453
454 expect(r.random.uintAtMost(u0, 0) == 0);454 try expect(r.random.uintAtMost(u0, 0) == 0);
455}455}
456456
457test "Random Biased" {457test "Random Biased" {
...@@ -459,30 +459,30 @@ test "Random Biased" {...@@ -459,30 +459,30 @@ test "Random Biased" {
459 // Not thoroughly checking the logic here.459 // Not thoroughly checking the logic here.
460 // Just want to execute all the paths with different types.460 // Just want to execute all the paths with different types.
461461
462 expect(r.random.uintLessThanBiased(u1, 1) == 0);462 try expect(r.random.uintLessThanBiased(u1, 1) == 0);
463 expect(r.random.uintLessThanBiased(u32, 10) < 10);463 try expect(r.random.uintLessThanBiased(u32, 10) < 10);
464 expect(r.random.uintLessThanBiased(u64, 20) < 20);464 try expect(r.random.uintLessThanBiased(u64, 20) < 20);
465465
466 expect(r.random.uintAtMostBiased(u0, 0) == 0);466 try expect(r.random.uintAtMostBiased(u0, 0) == 0);
467 expect(r.random.uintAtMostBiased(u1, 0) <= 0);467 try expect(r.random.uintAtMostBiased(u1, 0) <= 0);
468 expect(r.random.uintAtMostBiased(u32, 10) <= 10);468 try expect(r.random.uintAtMostBiased(u32, 10) <= 10);
469 expect(r.random.uintAtMostBiased(u64, 20) <= 20);469 try expect(r.random.uintAtMostBiased(u64, 20) <= 20);
470470
471 expect(r.random.intRangeLessThanBiased(u1, 0, 1) == 0);471 try expect(r.random.intRangeLessThanBiased(u1, 0, 1) == 0);
472 expect(r.random.intRangeLessThanBiased(i1, -1, 0) == -1);472 try expect(r.random.intRangeLessThanBiased(i1, -1, 0) == -1);
473 expect(r.random.intRangeLessThanBiased(u32, 10, 20) >= 10);473 try expect(r.random.intRangeLessThanBiased(u32, 10, 20) >= 10);
474 expect(r.random.intRangeLessThanBiased(i32, 10, 20) >= 10);474 try expect(r.random.intRangeLessThanBiased(i32, 10, 20) >= 10);
475 expect(r.random.intRangeLessThanBiased(u64, 20, 40) >= 20);475 try expect(r.random.intRangeLessThanBiased(u64, 20, 40) >= 20);
476 expect(r.random.intRangeLessThanBiased(i64, 20, 40) >= 20);476 try expect(r.random.intRangeLessThanBiased(i64, 20, 40) >= 20);
477477
478 // uncomment for broken module error:478 // uncomment for broken module error:
479 //expect(r.random.intRangeAtMostBiased(u0, 0, 0) == 0);479 //expect(r.random.intRangeAtMostBiased(u0, 0, 0) == 0);
480 expect(r.random.intRangeAtMostBiased(u1, 0, 1) >= 0);480 try expect(r.random.intRangeAtMostBiased(u1, 0, 1) >= 0);
481 expect(r.random.intRangeAtMostBiased(i1, -1, 0) >= -1);481 try expect(r.random.intRangeAtMostBiased(i1, -1, 0) >= -1);
482 expect(r.random.intRangeAtMostBiased(u32, 10, 20) >= 10);482 try expect(r.random.intRangeAtMostBiased(u32, 10, 20) >= 10);
483 expect(r.random.intRangeAtMostBiased(i32, 10, 20) >= 10);483 try expect(r.random.intRangeAtMostBiased(i32, 10, 20) >= 10);
484 expect(r.random.intRangeAtMostBiased(u64, 20, 40) >= 20);484 try expect(r.random.intRangeAtMostBiased(u64, 20, 40) >= 20);
485 expect(r.random.intRangeAtMostBiased(i64, 20, 40) >= 20);485 try expect(r.random.intRangeAtMostBiased(i64, 20, 40) >= 20);
486}486}
487487
488// Generator to extend 64-bit seed values into longer sequences.488// Generator to extend 64-bit seed values into longer sequences.
...@@ -519,7 +519,7 @@ test "splitmix64 sequence" {...@@ -519,7 +519,7 @@ test "splitmix64 sequence" {
519 };519 };
520520
521 for (seq) |s| {521 for (seq) |s| {
522 expect(s == r.next());522 try expect(s == r.next());
523 }523 }
524}524}
525525
...@@ -530,12 +530,12 @@ test "Random float" {...@@ -530,12 +530,12 @@ test "Random float" {
530 var i: usize = 0;530 var i: usize = 0;
531 while (i < 1000) : (i += 1) {531 while (i < 1000) : (i += 1) {
532 const val1 = prng.random.float(f32);532 const val1 = prng.random.float(f32);
533 expect(val1 >= 0.0);533 try expect(val1 >= 0.0);
534 expect(val1 < 1.0);534 try expect(val1 < 1.0);
535535
536 const val2 = prng.random.float(f64);536 const val2 = prng.random.float(f64);
537 expect(val2 >= 0.0);537 try expect(val2 >= 0.0);
538 expect(val2 < 1.0);538 try expect(val2 < 1.0);
539 }539 }
540}540}
541541
...@@ -549,12 +549,12 @@ test "Random shuffle" {...@@ -549,12 +549,12 @@ test "Random shuffle" {
549 while (i < 1000) : (i += 1) {549 while (i < 1000) : (i += 1) {
550 prng.random.shuffle(u8, seq[0..]);550 prng.random.shuffle(u8, seq[0..]);
551 seen[seq[0]] = true;551 seen[seq[0]] = true;
552 expect(sumArray(seq[0..]) == 10);552 try expect(sumArray(seq[0..]) == 10);
553 }553 }
554554
555 // we should see every entry at the head at least once555 // we should see every entry at the head at least once
556 for (seen) |e| {556 for (seen) |e| {
557 expect(e == true);557 try expect(e == true);
558 }558 }
559}559}
560560
...@@ -567,17 +567,17 @@ fn sumArray(s: []const u8) u32 {...@@ -567,17 +567,17 @@ fn sumArray(s: []const u8) u32 {
567567
568test "Random range" {568test "Random range" {
569 var prng = DefaultPrng.init(0);569 var prng = DefaultPrng.init(0);
570 testRange(&prng.random, -4, 3);570 try testRange(&prng.random, -4, 3);
571 testRange(&prng.random, -4, -1);571 try testRange(&prng.random, -4, -1);
572 testRange(&prng.random, 10, 14);572 try testRange(&prng.random, 10, 14);
573 testRange(&prng.random, -0x80, 0x7f);573 try testRange(&prng.random, -0x80, 0x7f);
574}574}
575575
576fn testRange(r: *Random, start: i8, end: i8) void {576fn testRange(r: *Random, start: i8, end: i8) !void {
577 testRangeBias(r, start, end, true);577 try testRangeBias(r, start, end, true);
578 testRangeBias(r, start, end, false);578 try testRangeBias(r, start, end, false);
579}579}
580fn testRangeBias(r: *Random, start: i8, end: i8, biased: bool) void {580fn testRangeBias(r: *Random, start: i8, end: i8, biased: bool) !void {
581 const count = @intCast(usize, @as(i32, end) - @as(i32, start));581 const count = @intCast(usize, @as(i32, end) - @as(i32, start));
582 var values_buffer = [_]bool{false} ** 0x100;582 var values_buffer = [_]bool{false} ** 0x100;
583 const values = values_buffer[0..count];583 const values = values_buffer[0..count];
...@@ -599,7 +599,7 @@ test "CSPRNG" {...@@ -599,7 +599,7 @@ test "CSPRNG" {
599 const a = csprng.random.int(u64);599 const a = csprng.random.int(u64);
600 const b = csprng.random.int(u64);600 const b = csprng.random.int(u64);
601 const c = csprng.random.int(u64);601 const c = csprng.random.int(u64);
602 expect(a ^ b ^ c != 0);602 try expect(a ^ b ^ c != 0);
603}603}
604604
605test {605test {
lib/std/rand/Isaac64.zig+2-2
...@@ -205,7 +205,7 @@ test "isaac64 sequence" {...@@ -205,7 +205,7 @@ test "isaac64 sequence" {
205 };205 };
206206
207 for (seq) |s| {207 for (seq) |s| {
208 std.testing.expect(s == r.next());208 try std.testing.expect(s == r.next());
209 }209 }
210}210}
211211
...@@ -237,6 +237,6 @@ test "isaac64 fill" {...@@ -237,6 +237,6 @@ test "isaac64 fill" {
237 var buf1: [7]u8 = undefined;237 var buf1: [7]u8 = undefined;
238 std.mem.writeIntLittle(u64, &buf0, s);238 std.mem.writeIntLittle(u64, &buf0, s);
239 Isaac64.fill(&r.random, &buf1);239 Isaac64.fill(&r.random, &buf1);
240 std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..]));240 try std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..]));
241 }241 }
242}242}
lib/std/rand/Pcg.zig+2-2
...@@ -96,7 +96,7 @@ test "pcg sequence" {...@@ -96,7 +96,7 @@ test "pcg sequence" {
96 };96 };
9797
98 for (seq) |s| {98 for (seq) |s| {
99 std.testing.expect(s == r.next());99 try std.testing.expect(s == r.next());
100 }100 }
101}101}
102102
...@@ -120,6 +120,6 @@ test "pcg fill" {...@@ -120,6 +120,6 @@ test "pcg fill" {
120 var buf1: [3]u8 = undefined;120 var buf1: [3]u8 = undefined;
121 std.mem.writeIntLittle(u32, &buf0, s);121 std.mem.writeIntLittle(u32, &buf0, s);
122 Pcg.fill(&r.random, &buf1);122 Pcg.fill(&r.random, &buf1);
123 std.testing.expect(std.mem.eql(u8, buf0[0..3], buf1[0..]));123 try std.testing.expect(std.mem.eql(u8, buf0[0..3], buf1[0..]));
124 }124 }
125}125}
lib/std/rand/Sfc64.zig+2-2
...@@ -103,7 +103,7 @@ test "Sfc64 sequence" {...@@ -103,7 +103,7 @@ test "Sfc64 sequence" {
103 };103 };
104104
105 for (seq) |s| {105 for (seq) |s| {
106 std.testing.expectEqual(s, r.next());106 try std.testing.expectEqual(s, r.next());
107 }107 }
108}108}
109109
...@@ -135,6 +135,6 @@ test "Sfc64 fill" {...@@ -135,6 +135,6 @@ test "Sfc64 fill" {
135 var buf1: [7]u8 = undefined;135 var buf1: [7]u8 = undefined;
136 std.mem.writeIntLittle(u64, &buf0, s);136 std.mem.writeIntLittle(u64, &buf0, s);
137 Sfc64.fill(&r.random, &buf1);137 Sfc64.fill(&r.random, &buf1);
138 std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..]));138 try std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..]));
139 }139 }
140}140}
lib/std/rand/Xoroshiro128.zig+3-3
...@@ -113,7 +113,7 @@ test "xoroshiro sequence" {...@@ -113,7 +113,7 @@ test "xoroshiro sequence" {
113 };113 };
114114
115 for (seq1) |s| {115 for (seq1) |s| {
116 std.testing.expect(s == r.next());116 try std.testing.expect(s == r.next());
117 }117 }
118118
119 r.jump();119 r.jump();
...@@ -128,7 +128,7 @@ test "xoroshiro sequence" {...@@ -128,7 +128,7 @@ test "xoroshiro sequence" {
128 };128 };
129129
130 for (seq2) |s| {130 for (seq2) |s| {
131 std.testing.expect(s == r.next());131 try std.testing.expect(s == r.next());
132 }132 }
133}133}
134134
...@@ -151,6 +151,6 @@ test "xoroshiro fill" {...@@ -151,6 +151,6 @@ test "xoroshiro fill" {
151 var buf1: [7]u8 = undefined;151 var buf1: [7]u8 = undefined;
152 std.mem.writeIntLittle(u64, &buf0, s);152 std.mem.writeIntLittle(u64, &buf0, s);
153 Xoroshiro128.fill(&r.random, &buf1);153 Xoroshiro128.fill(&r.random, &buf1);
154 std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..]));154 try std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..]));
155 }155 }
156}156}
lib/std/sort.zig+65-65
...@@ -43,35 +43,35 @@ test "binarySearch" {...@@ -43,35 +43,35 @@ test "binarySearch" {
43 return math.order(lhs, rhs);43 return math.order(lhs, rhs);
44 }44 }
45 };45 };
46 testing.expectEqual(46 try testing.expectEqual(
47 @as(?usize, null),47 @as(?usize, null),
48 binarySearch(u32, 1, &[_]u32{}, {}, S.order_u32),48 binarySearch(u32, 1, &[_]u32{}, {}, S.order_u32),
49 );49 );
50 testing.expectEqual(50 try testing.expectEqual(
51 @as(?usize, 0),51 @as(?usize, 0),
52 binarySearch(u32, 1, &[_]u32{1}, {}, S.order_u32),52 binarySearch(u32, 1, &[_]u32{1}, {}, S.order_u32),
53 );53 );
54 testing.expectEqual(54 try testing.expectEqual(
55 @as(?usize, null),55 @as(?usize, null),
56 binarySearch(u32, 1, &[_]u32{0}, {}, S.order_u32),56 binarySearch(u32, 1, &[_]u32{0}, {}, S.order_u32),
57 );57 );
58 testing.expectEqual(58 try testing.expectEqual(
59 @as(?usize, null),59 @as(?usize, null),
60 binarySearch(u32, 0, &[_]u32{1}, {}, S.order_u32),60 binarySearch(u32, 0, &[_]u32{1}, {}, S.order_u32),
61 );61 );
62 testing.expectEqual(62 try testing.expectEqual(
63 @as(?usize, 4),63 @as(?usize, 4),
64 binarySearch(u32, 5, &[_]u32{ 1, 2, 3, 4, 5 }, {}, S.order_u32),64 binarySearch(u32, 5, &[_]u32{ 1, 2, 3, 4, 5 }, {}, S.order_u32),
65 );65 );
66 testing.expectEqual(66 try testing.expectEqual(
67 @as(?usize, 0),67 @as(?usize, 0),
68 binarySearch(u32, 2, &[_]u32{ 2, 4, 8, 16, 32, 64 }, {}, S.order_u32),68 binarySearch(u32, 2, &[_]u32{ 2, 4, 8, 16, 32, 64 }, {}, S.order_u32),
69 );69 );
70 testing.expectEqual(70 try testing.expectEqual(
71 @as(?usize, 1),71 @as(?usize, 1),
72 binarySearch(i32, -4, &[_]i32{ -7, -4, 0, 9, 10 }, {}, S.order_i32),72 binarySearch(i32, -4, &[_]i32{ -7, -4, 0, 9, 10 }, {}, S.order_i32),
73 );73 );
74 testing.expectEqual(74 try testing.expectEqual(
75 @as(?usize, 3),75 @as(?usize, 3),
76 binarySearch(i32, 98, &[_]i32{ -100, -25, 2, 98, 99, 100 }, {}, S.order_i32),76 binarySearch(i32, 98, &[_]i32{ -100, -25, 2, 98, 99, 100 }, {}, S.order_i32),
77 );77 );
...@@ -1152,10 +1152,10 @@ pub fn desc(comptime T: type) fn (void, T, T) bool {...@@ -1152,10 +1152,10 @@ pub fn desc(comptime T: type) fn (void, T, T) bool {
1152}1152}
11531153
1154test "stable sort" {1154test "stable sort" {
1155 testStableSort();1155 try testStableSort();
1156 comptime testStableSort();1156 comptime try testStableSort();
1157}1157}
1158fn testStableSort() void {1158fn testStableSort() !void {
1159 var expected = [_]IdAndValue{1159 var expected = [_]IdAndValue{
1160 IdAndValue{ .id = 0, .value = 0 },1160 IdAndValue{ .id = 0, .value = 0 },
1161 IdAndValue{ .id = 1, .value = 0 },1161 IdAndValue{ .id = 1, .value = 0 },
...@@ -1194,8 +1194,8 @@ fn testStableSort() void {...@@ -1194,8 +1194,8 @@ fn testStableSort() void {
1194 for (cases) |*case| {1194 for (cases) |*case| {
1195 insertionSort(IdAndValue, (case.*)[0..], {}, cmpByValue);1195 insertionSort(IdAndValue, (case.*)[0..], {}, cmpByValue);
1196 for (case.*) |item, i| {1196 for (case.*) |item, i| {
1197 testing.expect(item.id == expected[i].id);1197 try testing.expect(item.id == expected[i].id);
1198 testing.expect(item.value == expected[i].value);1198 try testing.expect(item.value == expected[i].value);
1199 }1199 }
1200 }1200 }
1201}1201}
...@@ -1245,7 +1245,7 @@ test "sort" {...@@ -1245,7 +1245,7 @@ test "sort" {
1245 const slice = buf[0..case[0].len];1245 const slice = buf[0..case[0].len];
1246 mem.copy(u8, slice, case[0]);1246 mem.copy(u8, slice, case[0]);
1247 sort(u8, slice, {}, asc_u8);1247 sort(u8, slice, {}, asc_u8);
1248 testing.expect(mem.eql(u8, slice, case[1]));1248 try testing.expect(mem.eql(u8, slice, case[1]));
1249 }1249 }
12501250
1251 const i32cases = [_][]const []const i32{1251 const i32cases = [_][]const []const i32{
...@@ -1280,7 +1280,7 @@ test "sort" {...@@ -1280,7 +1280,7 @@ test "sort" {
1280 const slice = buf[0..case[0].len];1280 const slice = buf[0..case[0].len];
1281 mem.copy(i32, slice, case[0]);1281 mem.copy(i32, slice, case[0]);
1282 sort(i32, slice, {}, asc_i32);1282 sort(i32, slice, {}, asc_i32);
1283 testing.expect(mem.eql(i32, slice, case[1]));1283 try testing.expect(mem.eql(i32, slice, case[1]));
1284 }1284 }
1285}1285}
12861286
...@@ -1317,7 +1317,7 @@ test "sort descending" {...@@ -1317,7 +1317,7 @@ test "sort descending" {
1317 const slice = buf[0..case[0].len];1317 const slice = buf[0..case[0].len];
1318 mem.copy(i32, slice, case[0]);1318 mem.copy(i32, slice, case[0]);
1319 sort(i32, slice, {}, desc_i32);1319 sort(i32, slice, {}, desc_i32);
1320 testing.expect(mem.eql(i32, slice, case[1]));1320 try testing.expect(mem.eql(i32, slice, case[1]));
1321 }1321 }
1322}1322}
13231323
...@@ -1325,7 +1325,7 @@ test "another sort case" {...@@ -1325,7 +1325,7 @@ test "another sort case" {
1325 var arr = [_]i32{ 5, 3, 1, 2, 4 };1325 var arr = [_]i32{ 5, 3, 1, 2, 4 };
1326 sort(i32, arr[0..], {}, asc_i32);1326 sort(i32, arr[0..], {}, asc_i32);
13271327
1328 testing.expect(mem.eql(i32, &arr, &[_]i32{ 1, 2, 3, 4, 5 }));1328 try testing.expect(mem.eql(i32, &arr, &[_]i32{ 1, 2, 3, 4, 5 }));
1329}1329}
13301330
1331test "sort fuzz testing" {1331test "sort fuzz testing" {
...@@ -1353,9 +1353,9 @@ fn fuzzTest(rng: *std.rand.Random) !void {...@@ -1353,9 +1353,9 @@ fn fuzzTest(rng: *std.rand.Random) !void {
1353 var index: usize = 1;1353 var index: usize = 1;
1354 while (index < array.len) : (index += 1) {1354 while (index < array.len) : (index += 1) {
1355 if (array[index].value == array[index - 1].value) {1355 if (array[index].value == array[index - 1].value) {
1356 testing.expect(array[index].id > array[index - 1].id);1356 try testing.expect(array[index].id > array[index - 1].id);
1357 } else {1357 } else {
1358 testing.expect(array[index].value > array[index - 1].value);1358 try testing.expect(array[index].value > array[index - 1].value);
1359 }1359 }
1360 }1360 }
1361}1361}
...@@ -1383,13 +1383,13 @@ pub fn argMin(...@@ -1383,13 +1383,13 @@ pub fn argMin(
1383}1383}
13841384
1385test "argMin" {1385test "argMin" {
1386 testing.expectEqual(@as(?usize, null), argMin(i32, &[_]i32{}, {}, asc_i32));1386 try testing.expectEqual(@as(?usize, null), argMin(i32, &[_]i32{}, {}, asc_i32));
1387 testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{1}, {}, asc_i32));1387 try testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{1}, {}, asc_i32));
1388 testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));1388 try testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));
1389 testing.expectEqual(@as(?usize, 3), argMin(i32, &[_]i32{ 9, 3, 8, 2, 5 }, {}, asc_i32));1389 try testing.expectEqual(@as(?usize, 3), argMin(i32, &[_]i32{ 9, 3, 8, 2, 5 }, {}, asc_i32));
1390 testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32));1390 try testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32));
1391 testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{ -10, 1, 10 }, {}, asc_i32));1391 try testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{ -10, 1, 10 }, {}, asc_i32));
1392 testing.expectEqual(@as(?usize, 3), argMin(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32));1392 try testing.expectEqual(@as(?usize, 3), argMin(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32));
1393}1393}
13941394
1395pub fn min(1395pub fn min(
...@@ -1403,13 +1403,13 @@ pub fn min(...@@ -1403,13 +1403,13 @@ pub fn min(
1403}1403}
14041404
1405test "min" {1405test "min" {
1406 testing.expectEqual(@as(?i32, null), min(i32, &[_]i32{}, {}, asc_i32));1406 try testing.expectEqual(@as(?i32, null), min(i32, &[_]i32{}, {}, asc_i32));
1407 testing.expectEqual(@as(?i32, 1), min(i32, &[_]i32{1}, {}, asc_i32));1407 try testing.expectEqual(@as(?i32, 1), min(i32, &[_]i32{1}, {}, asc_i32));
1408 testing.expectEqual(@as(?i32, 1), min(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));1408 try testing.expectEqual(@as(?i32, 1), min(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));
1409 testing.expectEqual(@as(?i32, 2), min(i32, &[_]i32{ 9, 3, 8, 2, 5 }, {}, asc_i32));1409 try testing.expectEqual(@as(?i32, 2), min(i32, &[_]i32{ 9, 3, 8, 2, 5 }, {}, asc_i32));
1410 testing.expectEqual(@as(?i32, 1), min(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32));1410 try testing.expectEqual(@as(?i32, 1), min(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32));
1411 testing.expectEqual(@as(?i32, -10), min(i32, &[_]i32{ -10, 1, 10 }, {}, asc_i32));1411 try testing.expectEqual(@as(?i32, -10), min(i32, &[_]i32{ -10, 1, 10 }, {}, asc_i32));
1412 testing.expectEqual(@as(?i32, 7), min(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32));1412 try testing.expectEqual(@as(?i32, 7), min(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32));
1413}1413}
14141414
1415pub fn argMax(1415pub fn argMax(
...@@ -1435,13 +1435,13 @@ pub fn argMax(...@@ -1435,13 +1435,13 @@ pub fn argMax(
1435}1435}
14361436
1437test "argMax" {1437test "argMax" {
1438 testing.expectEqual(@as(?usize, null), argMax(i32, &[_]i32{}, {}, asc_i32));1438 try testing.expectEqual(@as(?usize, null), argMax(i32, &[_]i32{}, {}, asc_i32));
1439 testing.expectEqual(@as(?usize, 0), argMax(i32, &[_]i32{1}, {}, asc_i32));1439 try testing.expectEqual(@as(?usize, 0), argMax(i32, &[_]i32{1}, {}, asc_i32));
1440 testing.expectEqual(@as(?usize, 4), argMax(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));1440 try testing.expectEqual(@as(?usize, 4), argMax(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));
1441 testing.expectEqual(@as(?usize, 0), argMax(i32, &[_]i32{ 9, 3, 8, 2, 5 }, {}, asc_i32));1441 try testing.expectEqual(@as(?usize, 0), argMax(i32, &[_]i32{ 9, 3, 8, 2, 5 }, {}, asc_i32));
1442 testing.expectEqual(@as(?usize, 0), argMax(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32));1442 try testing.expectEqual(@as(?usize, 0), argMax(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32));
1443 testing.expectEqual(@as(?usize, 2), argMax(i32, &[_]i32{ -10, 1, 10 }, {}, asc_i32));1443 try testing.expectEqual(@as(?usize, 2), argMax(i32, &[_]i32{ -10, 1, 10 }, {}, asc_i32));
1444 testing.expectEqual(@as(?usize, 1), argMax(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32));1444 try testing.expectEqual(@as(?usize, 1), argMax(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32));
1445}1445}
14461446
1447pub fn max(1447pub fn max(
...@@ -1455,13 +1455,13 @@ pub fn max(...@@ -1455,13 +1455,13 @@ pub fn max(
1455}1455}
14561456
1457test "max" {1457test "max" {
1458 testing.expectEqual(@as(?i32, null), max(i32, &[_]i32{}, {}, asc_i32));1458 try testing.expectEqual(@as(?i32, null), max(i32, &[_]i32{}, {}, asc_i32));
1459 testing.expectEqual(@as(?i32, 1), max(i32, &[_]i32{1}, {}, asc_i32));1459 try testing.expectEqual(@as(?i32, 1), max(i32, &[_]i32{1}, {}, asc_i32));
1460 testing.expectEqual(@as(?i32, 5), max(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));1460 try testing.expectEqual(@as(?i32, 5), max(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));
1461 testing.expectEqual(@as(?i32, 9), max(i32, &[_]i32{ 9, 3, 8, 2, 5 }, {}, asc_i32));1461 try testing.expectEqual(@as(?i32, 9), max(i32, &[_]i32{ 9, 3, 8, 2, 5 }, {}, asc_i32));
1462 testing.expectEqual(@as(?i32, 1), max(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32));1462 try testing.expectEqual(@as(?i32, 1), max(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32));
1463 testing.expectEqual(@as(?i32, 10), max(i32, &[_]i32{ -10, 1, 10 }, {}, asc_i32));1463 try testing.expectEqual(@as(?i32, 10), max(i32, &[_]i32{ -10, 1, 10 }, {}, asc_i32));
1464 testing.expectEqual(@as(?i32, 3), max(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32));1464 try testing.expectEqual(@as(?i32, 3), max(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32));
1465}1465}
14661466
1467pub fn isSorted(1467pub fn isSorted(
...@@ -1481,28 +1481,28 @@ pub fn isSorted(...@@ -1481,28 +1481,28 @@ pub fn isSorted(
1481}1481}
14821482
1483test "isSorted" {1483test "isSorted" {
1484 testing.expect(isSorted(i32, &[_]i32{}, {}, asc_i32));1484 try testing.expect(isSorted(i32, &[_]i32{}, {}, asc_i32));
1485 testing.expect(isSorted(i32, &[_]i32{10}, {}, asc_i32));1485 try testing.expect(isSorted(i32, &[_]i32{10}, {}, asc_i32));
1486 testing.expect(isSorted(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));1486 try testing.expect(isSorted(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));
1487 testing.expect(isSorted(i32, &[_]i32{ -10, 1, 1, 1, 10 }, {}, asc_i32));1487 try testing.expect(isSorted(i32, &[_]i32{ -10, 1, 1, 1, 10 }, {}, asc_i32));
14881488
1489 testing.expect(isSorted(i32, &[_]i32{}, {}, desc_i32));1489 try testing.expect(isSorted(i32, &[_]i32{}, {}, desc_i32));
1490 testing.expect(isSorted(i32, &[_]i32{-20}, {}, desc_i32));1490 try testing.expect(isSorted(i32, &[_]i32{-20}, {}, desc_i32));
1491 testing.expect(isSorted(i32, &[_]i32{ 3, 2, 1, 0, -1 }, {}, desc_i32));1491 try testing.expect(isSorted(i32, &[_]i32{ 3, 2, 1, 0, -1 }, {}, desc_i32));
1492 testing.expect(isSorted(i32, &[_]i32{ 10, -10 }, {}, desc_i32));1492 try testing.expect(isSorted(i32, &[_]i32{ 10, -10 }, {}, desc_i32));
14931493
1494 testing.expect(isSorted(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32));1494 try testing.expect(isSorted(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32));
1495 testing.expect(isSorted(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, desc_i32));1495 try testing.expect(isSorted(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, desc_i32));
14961496
1497 testing.expectEqual(false, isSorted(i32, &[_]i32{ 5, 4, 3, 2, 1 }, {}, asc_i32));1497 try testing.expectEqual(false, isSorted(i32, &[_]i32{ 5, 4, 3, 2, 1 }, {}, asc_i32));
1498 testing.expectEqual(false, isSorted(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, desc_i32));1498 try testing.expectEqual(false, isSorted(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, desc_i32));
14991499
1500 testing.expect(isSorted(u8, "abcd", {}, asc_u8));1500 try testing.expect(isSorted(u8, "abcd", {}, asc_u8));
1501 testing.expect(isSorted(u8, "zyxw", {}, desc_u8));1501 try testing.expect(isSorted(u8, "zyxw", {}, desc_u8));
15021502
1503 testing.expectEqual(false, isSorted(u8, "abcd", {}, desc_u8));1503 try testing.expectEqual(false, isSorted(u8, "abcd", {}, desc_u8));
1504 testing.expectEqual(false, isSorted(u8, "zyxw", {}, asc_u8));1504 try testing.expectEqual(false, isSorted(u8, "zyxw", {}, asc_u8));
15051505
1506 testing.expect(isSorted(u8, "ffff", {}, asc_u8));1506 try testing.expect(isSorted(u8, "ffff", {}, asc_u8));
1507 testing.expect(isSorted(u8, "ffff", {}, desc_u8));1507 try testing.expect(isSorted(u8, "ffff", {}, desc_u8));
1508}1508}
lib/std/special/c.zig+27-27
...@@ -161,10 +161,10 @@ fn strerror(errnum: c_int) callconv(.C) [*:0]const u8 {...@@ -161,10 +161,10 @@ fn strerror(errnum: c_int) callconv(.C) [*:0]const u8 {
161}161}
162162
163test "strncmp" {163test "strncmp" {
164 std.testing.expect(strncmp("a", "b", 1) == -1);164 try std.testing.expect(strncmp("a", "b", 1) == -1);
165 std.testing.expect(strncmp("a", "c", 1) == -2);165 try std.testing.expect(strncmp("a", "c", 1) == -2);
166 std.testing.expect(strncmp("b", "a", 1) == 1);166 try std.testing.expect(strncmp("b", "a", 1) == 1);
167 std.testing.expect(strncmp("\xff", "\x02", 1) == 253);167 try std.testing.expect(strncmp("\xff", "\x02", 1) == 253);
168}168}
169169
170// Avoid dragging in the runtime safety mechanisms into this .o file,170// Avoid dragging in the runtime safety mechanisms into this .o file,
...@@ -245,9 +245,9 @@ test "memcmp" {...@@ -245,9 +245,9 @@ test "memcmp" {
245 const arr2 = &[_]u8{ 1, 0, 1 };245 const arr2 = &[_]u8{ 1, 0, 1 };
246 const arr3 = &[_]u8{ 1, 2, 1 };246 const arr3 = &[_]u8{ 1, 2, 1 };
247247
248 std.testing.expect(memcmp(base_arr[0..], arr1[0..], base_arr.len) == 0);248 try std.testing.expect(memcmp(base_arr[0..], arr1[0..], base_arr.len) == 0);
249 std.testing.expect(memcmp(base_arr[0..], arr2[0..], base_arr.len) > 0);249 try std.testing.expect(memcmp(base_arr[0..], arr2[0..], base_arr.len) > 0);
250 std.testing.expect(memcmp(base_arr[0..], arr3[0..], base_arr.len) < 0);250 try std.testing.expect(memcmp(base_arr[0..], arr3[0..], base_arr.len) < 0);
251}251}
252252
253export fn bcmp(vl: [*]allowzero const u8, vr: [*]allowzero const u8, n: usize) callconv(.C) isize {253export fn bcmp(vl: [*]allowzero const u8, vr: [*]allowzero const u8, n: usize) callconv(.C) isize {
...@@ -269,9 +269,9 @@ test "bcmp" {...@@ -269,9 +269,9 @@ test "bcmp" {
269 const arr2 = &[_]u8{ 1, 0, 1 };269 const arr2 = &[_]u8{ 1, 0, 1 };
270 const arr3 = &[_]u8{ 1, 2, 1 };270 const arr3 = &[_]u8{ 1, 2, 1 };
271271
272 std.testing.expect(bcmp(base_arr[0..], arr1[0..], base_arr.len) == 0);272 try std.testing.expect(bcmp(base_arr[0..], arr1[0..], base_arr.len) == 0);
273 std.testing.expect(bcmp(base_arr[0..], arr2[0..], base_arr.len) != 0);273 try std.testing.expect(bcmp(base_arr[0..], arr2[0..], base_arr.len) != 0);
274 std.testing.expect(bcmp(base_arr[0..], arr3[0..], base_arr.len) != 0);274 try std.testing.expect(bcmp(base_arr[0..], arr3[0..], base_arr.len) != 0);
275}275}
276276
277comptime {277comptime {
...@@ -865,11 +865,11 @@ test "fmod, fmodf" {...@@ -865,11 +865,11 @@ test "fmod, fmodf" {
865 const nan_val = math.nan(T);865 const nan_val = math.nan(T);
866 const inf_val = math.inf(T);866 const inf_val = math.inf(T);
867867
868 std.testing.expect(isNan(generic_fmod(T, nan_val, 1.0)));868 try std.testing.expect(isNan(generic_fmod(T, nan_val, 1.0)));
869 std.testing.expect(isNan(generic_fmod(T, 1.0, nan_val)));869 try std.testing.expect(isNan(generic_fmod(T, 1.0, nan_val)));
870 std.testing.expect(isNan(generic_fmod(T, inf_val, 1.0)));870 try std.testing.expect(isNan(generic_fmod(T, inf_val, 1.0)));
871 std.testing.expect(isNan(generic_fmod(T, 0.0, 0.0)));871 try std.testing.expect(isNan(generic_fmod(T, 0.0, 0.0)));
872 std.testing.expect(isNan(generic_fmod(T, 1.0, 0.0)));872 try std.testing.expect(isNan(generic_fmod(T, 1.0, 0.0)));
873873
874 std.testing.expectEqual(@as(T, 0.0), generic_fmod(T, 0.0, 2.0));874 std.testing.expectEqual(@as(T, 0.0), generic_fmod(T, 0.0, 2.0));
875 std.testing.expectEqual(@as(T, -0.0), generic_fmod(T, -0.0, 2.0));875 std.testing.expectEqual(@as(T, -0.0), generic_fmod(T, -0.0, 2.0));
...@@ -901,7 +901,7 @@ test "fmin, fminf" {...@@ -901,7 +901,7 @@ test "fmin, fminf" {
901 inline for ([_]type{ f32, f64 }) |T| {901 inline for ([_]type{ f32, f64 }) |T| {
902 const nan_val = math.nan(T);902 const nan_val = math.nan(T);
903903
904 std.testing.expect(isNan(generic_fmin(T, nan_val, nan_val)));904 try std.testing.expect(isNan(generic_fmin(T, nan_val, nan_val)));
905 std.testing.expectEqual(@as(T, 1.0), generic_fmin(T, nan_val, 1.0));905 std.testing.expectEqual(@as(T, 1.0), generic_fmin(T, nan_val, 1.0));
906 std.testing.expectEqual(@as(T, 1.0), generic_fmin(T, 1.0, nan_val));906 std.testing.expectEqual(@as(T, 1.0), generic_fmin(T, 1.0, nan_val));
907907
...@@ -930,7 +930,7 @@ test "fmax, fmaxf" {...@@ -930,7 +930,7 @@ test "fmax, fmaxf" {
930 inline for ([_]type{ f32, f64 }) |T| {930 inline for ([_]type{ f32, f64 }) |T| {
931 const nan_val = math.nan(T);931 const nan_val = math.nan(T);
932932
933 std.testing.expect(isNan(generic_fmax(T, nan_val, nan_val)));933 try std.testing.expect(isNan(generic_fmax(T, nan_val, nan_val)));
934 std.testing.expectEqual(@as(T, 1.0), generic_fmax(T, nan_val, 1.0));934 std.testing.expectEqual(@as(T, 1.0), generic_fmax(T, nan_val, 1.0));
935 std.testing.expectEqual(@as(T, 1.0), generic_fmax(T, 1.0, nan_val));935 std.testing.expectEqual(@as(T, 1.0), generic_fmax(T, 1.0, nan_val));
936936
...@@ -1094,11 +1094,11 @@ test "sqrt" {...@@ -1094,11 +1094,11 @@ test "sqrt" {
1094}1094}
10951095
1096test "sqrt special" {1096test "sqrt special" {
1097 std.testing.expect(std.math.isPositiveInf(sqrt(std.math.inf(f64))));1097 try std.testing.expect(std.math.isPositiveInf(sqrt(std.math.inf(f64))));
1098 std.testing.expect(sqrt(0.0) == 0.0);1098 try std.testing.expect(sqrt(0.0) == 0.0);
1099 std.testing.expect(sqrt(-0.0) == -0.0);1099 try std.testing.expect(sqrt(-0.0) == -0.0);
1100 std.testing.expect(isNan(sqrt(-1.0)));1100 try std.testing.expect(isNan(sqrt(-1.0)));
1101 std.testing.expect(isNan(sqrt(std.math.nan(f64))));1101 try std.testing.expect(isNan(sqrt(std.math.nan(f64))));
1102}1102}
11031103
1104export fn sqrtf(x: f32) f32 {1104export fn sqrtf(x: f32) f32 {
...@@ -1199,9 +1199,9 @@ test "sqrtf" {...@@ -1199,9 +1199,9 @@ test "sqrtf" {
1199}1199}
12001200
1201test "sqrtf special" {1201test "sqrtf special" {
1202 std.testing.expect(std.math.isPositiveInf(sqrtf(std.math.inf(f32))));1202 try std.testing.expect(std.math.isPositiveInf(sqrtf(std.math.inf(f32))));
1203 std.testing.expect(sqrtf(0.0) == 0.0);1203 try std.testing.expect(sqrtf(0.0) == 0.0);
1204 std.testing.expect(sqrtf(-0.0) == -0.0);1204 try std.testing.expect(sqrtf(-0.0) == -0.0);
1205 std.testing.expect(isNan(sqrtf(-1.0)));1205 try std.testing.expect(isNan(sqrtf(-1.0)));
1206 std.testing.expect(isNan(sqrtf(std.math.nan(f32))));1206 try std.testing.expect(isNan(sqrtf(std.math.nan(f32))));
1207}1207}
lib/std/special/compiler_rt/comparedf2_test.zig+1-1
...@@ -101,6 +101,6 @@ const test_vectors = init: {...@@ -101,6 +101,6 @@ const test_vectors = init: {
101101
102test "compare f64" {102test "compare f64" {
103 for (test_vectors) |vector, i| {103 for (test_vectors) |vector, i| {
104 std.testing.expect(test__cmpdf2(vector));104 try std.testing.expect(test__cmpdf2(vector));
105 }105 }
106}106}
lib/std/special/compiler_rt/comparesf2_test.zig+1-1
...@@ -101,6 +101,6 @@ const test_vectors = init: {...@@ -101,6 +101,6 @@ const test_vectors = init: {
101101
102test "compare f32" {102test "compare f32" {
103 for (test_vectors) |vector, i| {103 for (test_vectors) |vector, i| {
104 std.testing.expect(test__cmpsf2(vector));104 try std.testing.expect(test__cmpsf2(vector));
105 }105 }
106}106}
lib/std/special/compiler_rt/divdf3_test.zig+1-1
...@@ -30,7 +30,7 @@ fn compareResultD(result: f64, expected: u64) bool {...@@ -30,7 +30,7 @@ fn compareResultD(result: f64, expected: u64) bool {
30fn test__divdf3(a: f64, b: f64, expected: u64) void {30fn test__divdf3(a: f64, b: f64, expected: u64) void {
31 const x = __divdf3(a, b);31 const x = __divdf3(a, b);
32 const ret = compareResultD(x, expected);32 const ret = compareResultD(x, expected);
33 testing.expect(ret == true);33 try testing.expect(ret == true);
34}34}
3535
36test "divdf3" {36test "divdf3" {
lib/std/special/compiler_rt/divsf3_test.zig+1-1
...@@ -30,7 +30,7 @@ fn compareResultF(result: f32, expected: u32) bool {...@@ -30,7 +30,7 @@ fn compareResultF(result: f32, expected: u32) bool {
30fn test__divsf3(a: f32, b: f32, expected: u32) void {30fn test__divsf3(a: f32, b: f32, expected: u32) void {
31 const x = __divsf3(a, b);31 const x = __divsf3(a, b);
32 const ret = compareResultF(x, expected);32 const ret = compareResultF(x, expected);
33 testing.expect(ret == true);33 try testing.expect(ret == true);
34}34}
3535
36test "divsf3" {36test "divsf3" {
lib/std/special/compiler_rt/divtf3_test.zig+1-1
...@@ -31,7 +31,7 @@ fn compareResultLD(result: f128, expectedHi: u64, expectedLo: u64) bool {...@@ -31,7 +31,7 @@ fn compareResultLD(result: f128, expectedHi: u64, expectedLo: u64) bool {
31fn test__divtf3(a: f128, b: f128, expectedHi: u64, expectedLo: u64) void {31fn test__divtf3(a: f128, b: f128, expectedHi: u64, expectedLo: u64) void {
32 const x = __divtf3(a, b);32 const x = __divtf3(a, b);
33 const ret = compareResultLD(x, expectedHi, expectedLo);33 const ret = compareResultLD(x, expectedHi, expectedLo);
34 testing.expect(ret == true);34 try testing.expect(ret == true);
35}35}
3636
37test "divtf3" {37test "divtf3" {
lib/std/special/compiler_rt/divti3_test.zig+1-1
...@@ -8,7 +8,7 @@ const testing = @import("std").testing;...@@ -8,7 +8,7 @@ const testing = @import("std").testing;
88
9fn test__divti3(a: i128, b: i128, expected: i128) void {9fn test__divti3(a: i128, b: i128, expected: i128) void {
10 const x = __divti3(a, b);10 const x = __divti3(a, b);
11 testing.expect(x == expected);11 try testing.expect(x == expected);
12}12}
1313
14test "divti3" {14test "divti3" {
lib/std/special/compiler_rt/emutls.zig+11-11
...@@ -339,12 +339,12 @@ test "simple_allocator" {...@@ -339,12 +339,12 @@ test "simple_allocator" {
339339
340test "__emutls_get_address zeroed" {340test "__emutls_get_address zeroed" {
341 var ctl = emutls_control.init(usize, null);341 var ctl = emutls_control.init(usize, null);
342 expect(ctl.object.index == 0);342 try expect(ctl.object.index == 0);
343343
344 // retrieve a variable from ctl344 // retrieve a variable from ctl
345 var x = @ptrCast(*usize, @alignCast(@alignOf(usize), __emutls_get_address(&ctl)));345 var x = @ptrCast(*usize, @alignCast(@alignOf(usize), __emutls_get_address(&ctl)));
346 expect(ctl.object.index != 0); // index has been allocated for this ctl346 try expect(ctl.object.index != 0); // index has been allocated for this ctl
347 expect(x.* == 0); // storage has been zeroed347 try expect(x.* == 0); // storage has been zeroed
348348
349 // modify the storage349 // modify the storage
350 x.* = 1234;350 x.* = 1234;
...@@ -352,26 +352,26 @@ test "__emutls_get_address zeroed" {...@@ -352,26 +352,26 @@ test "__emutls_get_address zeroed" {
352 // retrieve a variable from ctl (same ctl)352 // retrieve a variable from ctl (same ctl)
353 var y = @ptrCast(*usize, @alignCast(@alignOf(usize), __emutls_get_address(&ctl)));353 var y = @ptrCast(*usize, @alignCast(@alignOf(usize), __emutls_get_address(&ctl)));
354354
355 expect(y.* == 1234); // same content that x.*355 try expect(y.* == 1234); // same content that x.*
356 expect(x == y); // same pointer356 try expect(x == y); // same pointer
357}357}
358358
359test "__emutls_get_address with default_value" {359test "__emutls_get_address with default_value" {
360 var value: usize = 5678; // default value360 var value: usize = 5678; // default value
361 var ctl = emutls_control.init(usize, &value);361 var ctl = emutls_control.init(usize, &value);
362 expect(ctl.object.index == 0);362 try expect(ctl.object.index == 0);
363363
364 var x: *usize = @ptrCast(*usize, @alignCast(@alignOf(usize), __emutls_get_address(&ctl)));364 var x: *usize = @ptrCast(*usize, @alignCast(@alignOf(usize), __emutls_get_address(&ctl)));
365 expect(ctl.object.index != 0);365 try expect(ctl.object.index != 0);
366 expect(x.* == 5678); // storage initialized with default value366 try expect(x.* == 5678); // storage initialized with default value
367367
368 // modify the storage368 // modify the storage
369 x.* = 9012;369 x.* = 9012;
370370
371 expect(value == 5678); // the default value didn't change371 try expect(value == 5678); // the default value didn't change
372372
373 var y = @ptrCast(*usize, @alignCast(@alignOf(usize), __emutls_get_address(&ctl)));373 var y = @ptrCast(*usize, @alignCast(@alignOf(usize), __emutls_get_address(&ctl)));
374 expect(y.* == 9012); // the modified storage persists374 try expect(y.* == 9012); // the modified storage persists
375}375}
376376
377test "test default_value with differents sizes" {377test "test default_value with differents sizes" {
...@@ -380,7 +380,7 @@ test "test default_value with differents sizes" {...@@ -380,7 +380,7 @@ test "test default_value with differents sizes" {
380 var def: T = value;380 var def: T = value;
381 var ctl = emutls_control.init(T, &def);381 var ctl = emutls_control.init(T, &def);
382 var x = ctl.get_typed_pointer(T);382 var x = ctl.get_typed_pointer(T);
383 expect(x.* == value);383 try expect(x.* == value);
384 }384 }
385 }._testType;385 }._testType;
386386
lib/std/special/compiler_rt/fixdfdi_test.zig+1-1
...@@ -12,7 +12,7 @@ const warn = std.debug.warn;...@@ -12,7 +12,7 @@ const warn = std.debug.warn;
12fn test__fixdfdi(a: f64, expected: i64) void {12fn test__fixdfdi(a: f64, expected: i64) void {
13 const x = __fixdfdi(a);13 const x = __fixdfdi(a);
14 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", .{a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u64, expected)});14 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", .{a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u64, expected)});
15 testing.expect(x == expected);15 try testing.expect(x == expected);
16}16}
1717
18test "fixdfdi" {18test "fixdfdi" {
lib/std/special/compiler_rt/fixdfsi_test.zig+1-1
...@@ -12,7 +12,7 @@ const warn = std.debug.warn;...@@ -12,7 +12,7 @@ const warn = std.debug.warn;
12fn test__fixdfsi(a: f64, expected: i32) void {12fn test__fixdfsi(a: f64, expected: i32) void {
13 const x = __fixdfsi(a);13 const x = __fixdfsi(a);
14 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", .{a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u32, expected)});14 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", .{a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u32, expected)});
15 testing.expect(x == expected);15 try testing.expect(x == expected);
16}16}
1717
18test "fixdfsi" {18test "fixdfsi" {
lib/std/special/compiler_rt/fixdfti_test.zig+1-1
...@@ -12,7 +12,7 @@ const warn = std.debug.warn;...@@ -12,7 +12,7 @@ const warn = std.debug.warn;
12fn test__fixdfti(a: f64, expected: i128) void {12fn test__fixdfti(a: f64, expected: i128) void {
13 const x = __fixdfti(a);13 const x = __fixdfti(a);
14 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", .{a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u128, expected)});14 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", .{a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u128, expected)});
15 testing.expect(x == expected);15 try testing.expect(x == expected);
16}16}
1717
18test "fixdfti" {18test "fixdfti" {
lib/std/special/compiler_rt/fixint_test.zig+1-1
...@@ -14,7 +14,7 @@ const fixint = @import("fixint.zig").fixint;...@@ -14,7 +14,7 @@ const fixint = @import("fixint.zig").fixint;
14fn test__fixint(comptime fp_t: type, comptime fixint_t: type, a: fp_t, expected: fixint_t) void {14fn test__fixint(comptime fp_t: type, comptime fixint_t: type, a: fp_t, expected: fixint_t) void {
15 const x = fixint(fp_t, fixint_t, a);15 const x = fixint(fp_t, fixint_t, a);
16 //warn("a={} x={}:{x} expected={}:{x})\n", .{a, x, x, expected, expected});16 //warn("a={} x={}:{x} expected={}:{x})\n", .{a, x, x, expected, expected});
17 testing.expect(x == expected);17 try testing.expect(x == expected);
18}18}
1919
20test "fixint.i1" {20test "fixint.i1" {
lib/std/special/compiler_rt/fixsfdi_test.zig+1-1
...@@ -12,7 +12,7 @@ const warn = std.debug.warn;...@@ -12,7 +12,7 @@ const warn = std.debug.warn;
12fn test__fixsfdi(a: f32, expected: i64) void {12fn test__fixsfdi(a: f32, expected: i64) void {
13 const x = __fixsfdi(a);13 const x = __fixsfdi(a);
14 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u32, {x})\n", .{a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u64, expected)});14 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u32, {x})\n", .{a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u64, expected)});
15 testing.expect(x == expected);15 try testing.expect(x == expected);
16}16}
1717
18test "fixsfdi" {18test "fixsfdi" {
lib/std/special/compiler_rt/fixsfsi_test.zig+1-1
...@@ -12,7 +12,7 @@ const warn = std.debug.warn;...@@ -12,7 +12,7 @@ const warn = std.debug.warn;
12fn test__fixsfsi(a: f32, expected: i32) void {12fn test__fixsfsi(a: f32, expected: i32) void {
13 const x = __fixsfsi(a);13 const x = __fixsfsi(a);
14 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u32, {x})\n", .{a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u32, expected)});14 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u32, {x})\n", .{a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u32, expected)});
15 testing.expect(x == expected);15 try testing.expect(x == expected);
16}16}
1717
18test "fixsfsi" {18test "fixsfsi" {
lib/std/special/compiler_rt/fixsfti_test.zig+1-1
...@@ -12,7 +12,7 @@ const warn = std.debug.warn;...@@ -12,7 +12,7 @@ const warn = std.debug.warn;
12fn test__fixsfti(a: f32, expected: i128) void {12fn test__fixsfti(a: f32, expected: i128) void {
13 const x = __fixsfti(a);13 const x = __fixsfti(a);
14 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u128, {x})\n", .{a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u128, expected)});14 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u128, {x})\n", .{a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u128, expected)});
15 testing.expect(x == expected);15 try testing.expect(x == expected);
16}16}
1717
18test "fixsfti" {18test "fixsfti" {
lib/std/special/compiler_rt/fixtfdi_test.zig+1-1
...@@ -12,7 +12,7 @@ const warn = std.debug.warn;...@@ -12,7 +12,7 @@ const warn = std.debug.warn;
12fn test__fixtfdi(a: f128, expected: i64) void {12fn test__fixtfdi(a: f128, expected: i64) void {
13 const x = __fixtfdi(a);13 const x = __fixtfdi(a);
14 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", .{a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u64, expected)});14 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", .{a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u64, expected)});
15 testing.expect(x == expected);15 try testing.expect(x == expected);
16}16}
1717
18test "fixtfdi" {18test "fixtfdi" {
lib/std/special/compiler_rt/fixtfsi_test.zig+1-1
...@@ -12,7 +12,7 @@ const warn = std.debug.warn;...@@ -12,7 +12,7 @@ const warn = std.debug.warn;
12fn test__fixtfsi(a: f128, expected: i32) void {12fn test__fixtfsi(a: f128, expected: i32) void {
13 const x = __fixtfsi(a);13 const x = __fixtfsi(a);
14 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u32, {x})\n", .{a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u32, expected)});14 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u32, {x})\n", .{a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u32, expected)});
15 testing.expect(x == expected);15 try testing.expect(x == expected);
16}16}
1717
18test "fixtfsi" {18test "fixtfsi" {
lib/std/special/compiler_rt/fixtfti_test.zig+1-1
...@@ -12,7 +12,7 @@ const warn = std.debug.warn;...@@ -12,7 +12,7 @@ const warn = std.debug.warn;
12fn test__fixtfti(a: f128, expected: i128) void {12fn test__fixtfti(a: f128, expected: i128) void {
13 const x = __fixtfti(a);13 const x = __fixtfti(a);
14 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u128, {x})\n", .{a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u128, expected)});14 //warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u128, {x})\n", .{a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u128, expected)});
15 testing.expect(x == expected);15 try testing.expect(x == expected);
16}16}
1717
18test "fixtfti" {18test "fixtfti" {
lib/std/special/compiler_rt/fixunsdfdi_test.zig+1-1
...@@ -8,7 +8,7 @@ const testing = @import("std").testing;...@@ -8,7 +8,7 @@ const testing = @import("std").testing;
88
9fn test__fixunsdfdi(a: f64, expected: u64) void {9fn test__fixunsdfdi(a: f64, expected: u64) void {
10 const x = __fixunsdfdi(a);10 const x = __fixunsdfdi(a);
11 testing.expect(x == expected);11 try testing.expect(x == expected);
12}12}
1313
14test "fixunsdfdi" {14test "fixunsdfdi" {
lib/std/special/compiler_rt/fixunsdfsi_test.zig+1-1
...@@ -8,7 +8,7 @@ const testing = @import("std").testing;...@@ -8,7 +8,7 @@ const testing = @import("std").testing;
88
9fn test__fixunsdfsi(a: f64, expected: u32) void {9fn test__fixunsdfsi(a: f64, expected: u32) void {
10 const x = __fixunsdfsi(a);10 const x = __fixunsdfsi(a);
11 testing.expect(x == expected);11 try testing.expect(x == expected);
12}12}
1313
14test "fixunsdfsi" {14test "fixunsdfsi" {
lib/std/special/compiler_rt/fixunsdfti_test.zig+1-1
...@@ -8,7 +8,7 @@ const testing = @import("std").testing;...@@ -8,7 +8,7 @@ const testing = @import("std").testing;
88
9fn test__fixunsdfti(a: f64, expected: u128) void {9fn test__fixunsdfti(a: f64, expected: u128) void {
10 const x = __fixunsdfti(a);10 const x = __fixunsdfti(a);
11 testing.expect(x == expected);11 try testing.expect(x == expected);
12}12}
1313
14test "fixunsdfti" {14test "fixunsdfti" {
lib/std/special/compiler_rt/fixunssfdi_test.zig+1-1
...@@ -8,7 +8,7 @@ const testing = @import("std").testing;...@@ -8,7 +8,7 @@ const testing = @import("std").testing;
88
9fn test__fixunssfdi(a: f32, expected: u64) void {9fn test__fixunssfdi(a: f32, expected: u64) void {
10 const x = __fixunssfdi(a);10 const x = __fixunssfdi(a);
11 testing.expect(x == expected);11 try testing.expect(x == expected);
12}12}
1313
14test "fixunssfdi" {14test "fixunssfdi" {
lib/std/special/compiler_rt/fixunssfsi_test.zig+1-1
...@@ -8,7 +8,7 @@ const testing = @import("std").testing;...@@ -8,7 +8,7 @@ const testing = @import("std").testing;
88
9fn test__fixunssfsi(a: f32, expected: u32) void {9fn test__fixunssfsi(a: f32, expected: u32) void {
10 const x = __fixunssfsi(a);10 const x = __fixunssfsi(a);
11 testing.expect(x == expected);11 try testing.expect(x == expected);
12}12}
1313
14test "fixunssfsi" {14test "fixunssfsi" {
lib/std/special/compiler_rt/fixunssfti_test.zig+1-1
...@@ -8,7 +8,7 @@ const testing = @import("std").testing;...@@ -8,7 +8,7 @@ const testing = @import("std").testing;
88
9fn test__fixunssfti(a: f32, expected: u128) void {9fn test__fixunssfti(a: f32, expected: u128) void {
10 const x = __fixunssfti(a);10 const x = __fixunssfti(a);
11 testing.expect(x == expected);11 try testing.expect(x == expected);
12}12}
1313
14test "fixunssfti" {14test "fixunssfti" {
lib/std/special/compiler_rt/fixunstfdi_test.zig+1-1
...@@ -8,7 +8,7 @@ const testing = @import("std").testing;...@@ -8,7 +8,7 @@ const testing = @import("std").testing;
88
9fn test__fixunstfdi(a: f128, expected: u64) void {9fn test__fixunstfdi(a: f128, expected: u64) void {
10 const x = __fixunstfdi(a);10 const x = __fixunstfdi(a);
11 testing.expect(x == expected);11 try testing.expect(x == expected);
12}12}
1313
14test "fixunstfdi" {14test "fixunstfdi" {
lib/std/special/compiler_rt/fixunstfsi_test.zig+1-1
...@@ -8,7 +8,7 @@ const testing = @import("std").testing;...@@ -8,7 +8,7 @@ const testing = @import("std").testing;
88
9fn test__fixunstfsi(a: f128, expected: u32) void {9fn test__fixunstfsi(a: f128, expected: u32) void {
10 const x = __fixunstfsi(a);10 const x = __fixunstfsi(a);
11 testing.expect(x == expected);11 try testing.expect(x == expected);
12}12}
1313
14const inf128 = @bitCast(f128, @as(u128, 0x7fff0000000000000000000000000000));14const inf128 = @bitCast(f128, @as(u128, 0x7fff0000000000000000000000000000));
lib/std/special/compiler_rt/fixunstfti_test.zig+1-1
...@@ -8,7 +8,7 @@ const testing = @import("std").testing;...@@ -8,7 +8,7 @@ const testing = @import("std").testing;
88
9fn test__fixunstfti(a: f128, expected: u128) void {9fn test__fixunstfti(a: f128, expected: u128) void {
10 const x = __fixunstfti(a);10 const x = __fixunstfti(a);
11 testing.expect(x == expected);11 try testing.expect(x == expected);
12}12}
1313
14const inf128 = @bitCast(f128, @as(u128, 0x7fff0000000000000000000000000000));14const inf128 = @bitCast(f128, @as(u128, 0x7fff0000000000000000000000000000));
lib/std/special/compiler_rt/floatdidf_test.zig+1-1
...@@ -8,7 +8,7 @@ const testing = @import("std").testing;...@@ -8,7 +8,7 @@ const testing = @import("std").testing;
88
9fn test__floatdidf(a: i64, expected: f64) void {9fn test__floatdidf(a: i64, expected: f64) void {
10 const r = __floatdidf(a);10 const r = __floatdidf(a);
11 testing.expect(r == expected);11 try testing.expect(r == expected);
12}12}
1313
14test "floatdidf" {14test "floatdidf" {
lib/std/special/compiler_rt/floatdisf_test.zig+1-1
...@@ -8,7 +8,7 @@ const testing = @import("std").testing;...@@ -8,7 +8,7 @@ const testing = @import("std").testing;
88
9fn test__floatdisf(a: i64, expected: f32) void {9fn test__floatdisf(a: i64, expected: f32) void {
10 const x = __floatdisf(a);10 const x = __floatdisf(a);
11 testing.expect(x == expected);11 try testing.expect(x == expected);
12}12}
1313
14test "floatdisf" {14test "floatdisf" {
lib/std/special/compiler_rt/floatditf_test.zig+1-1
...@@ -8,7 +8,7 @@ const testing = @import("std").testing;...@@ -8,7 +8,7 @@ const testing = @import("std").testing;
88
9fn test__floatditf(a: i64, expected: f128) void {9fn test__floatditf(a: i64, expected: f128) void {
10 const x = __floatditf(a);10 const x = __floatditf(a);
11 testing.expect(x == expected);11 try testing.expect(x == expected);
12}12}
1313
14test "floatditf" {14test "floatditf" {
lib/std/special/compiler_rt/floatsiXf.zig+3-3
...@@ -86,17 +86,17 @@ pub fn __aeabi_i2f(arg: i32) callconv(.AAPCS) f32 {...@@ -86,17 +86,17 @@ pub fn __aeabi_i2f(arg: i32) callconv(.AAPCS) f32 {
8686
87fn test_one_floatsitf(a: i32, expected: u128) void {87fn test_one_floatsitf(a: i32, expected: u128) void {
88 const r = __floatsitf(a);88 const r = __floatsitf(a);
89 std.testing.expect(@bitCast(u128, r) == expected);89 try std.testing.expect(@bitCast(u128, r) == expected);
90}90}
9191
92fn test_one_floatsidf(a: i32, expected: u64) void {92fn test_one_floatsidf(a: i32, expected: u64) void {
93 const r = __floatsidf(a);93 const r = __floatsidf(a);
94 std.testing.expect(@bitCast(u64, r) == expected);94 try std.testing.expect(@bitCast(u64, r) == expected);
95}95}
9696
97fn test_one_floatsisf(a: i32, expected: u32) void {97fn test_one_floatsisf(a: i32, expected: u32) void {
98 const r = __floatsisf(a);98 const r = __floatsisf(a);
99 std.testing.expect(@bitCast(u32, r) == expected);99 try std.testing.expect(@bitCast(u32, r) == expected);
100}100}
101101
102test "floatsidf" {102test "floatsidf" {
lib/std/special/compiler_rt/floattidf_test.zig+1-1
...@@ -8,7 +8,7 @@ const testing = @import("std").testing;...@@ -8,7 +8,7 @@ const testing = @import("std").testing;
88
9fn test__floattidf(a: i128, expected: f64) void {9fn test__floattidf(a: i128, expected: f64) void {
10 const x = __floattidf(a);10 const x = __floattidf(a);
11 testing.expect(x == expected);11 try testing.expect(x == expected);
12}12}
1313
14test "floattidf" {14test "floattidf" {
lib/std/special/compiler_rt/floattisf_test.zig+1-1
...@@ -8,7 +8,7 @@ const testing = @import("std").testing;...@@ -8,7 +8,7 @@ const testing = @import("std").testing;
88
9fn test__floattisf(a: i128, expected: f32) void {9fn test__floattisf(a: i128, expected: f32) void {
10 const x = __floattisf(a);10 const x = __floattisf(a);
11 testing.expect(x == expected);11 try testing.expect(x == expected);
12}12}
1313
14test "floattisf" {14test "floattisf" {
lib/std/special/compiler_rt/floattitf_test.zig+1-1
...@@ -8,7 +8,7 @@ const testing = @import("std").testing;...@@ -8,7 +8,7 @@ const testing = @import("std").testing;
88
9fn test__floattitf(a: i128, expected: f128) void {9fn test__floattitf(a: i128, expected: f128) void {
10 const x = __floattitf(a);10 const x = __floattitf(a);
11 testing.expect(x == expected);11 try testing.expect(x == expected);
12}12}
1313
14test "floattitf" {14test "floattitf" {
lib/std/special/compiler_rt/floatundidf_test.zig+1-1
...@@ -8,7 +8,7 @@ const testing = @import("std").testing;...@@ -8,7 +8,7 @@ const testing = @import("std").testing;
88
9fn test__floatundidf(a: u64, expected: f64) void {9fn test__floatundidf(a: u64, expected: f64) void {
10 const r = __floatundidf(a);10 const r = __floatundidf(a);
11 testing.expect(r == expected);11 try testing.expect(r == expected);
12}12}
1313
14test "floatundidf" {14test "floatundidf" {
lib/std/special/compiler_rt/floatunsidf.zig+1-1
...@@ -30,7 +30,7 @@ pub fn __aeabi_ui2d(arg: u32) callconv(.AAPCS) f64 {...@@ -30,7 +30,7 @@ pub fn __aeabi_ui2d(arg: u32) callconv(.AAPCS) f64 {
3030
31fn test_one_floatunsidf(a: u32, expected: u64) void {31fn test_one_floatunsidf(a: u32, expected: u64) void {
32 const r = __floatunsidf(a);32 const r = __floatunsidf(a);
33 std.testing.expect(@bitCast(u64, r) == expected);33 try std.testing.expect(@bitCast(u64, r) == expected);
34}34}
3535
36test "floatsidf" {36test "floatsidf" {
lib/std/special/compiler_rt/floatunsisf.zig+1-1
...@@ -50,7 +50,7 @@ pub fn __aeabi_ui2f(arg: u32) callconv(.AAPCS) f32 {...@@ -50,7 +50,7 @@ pub fn __aeabi_ui2f(arg: u32) callconv(.AAPCS) f32 {
5050
51fn test_one_floatunsisf(a: u32, expected: u32) void {51fn test_one_floatunsisf(a: u32, expected: u32) void {
52 const r = __floatunsisf(a);52 const r = __floatunsisf(a);
53 std.testing.expect(@bitCast(u32, r) == expected);53 try std.testing.expect(@bitCast(u32, r) == expected);
54}54}
5555
56test "floatunsisf" {56test "floatunsisf" {
lib/std/special/compiler_rt/floatuntidf_test.zig+1-1
...@@ -8,7 +8,7 @@ const testing = @import("std").testing;...@@ -8,7 +8,7 @@ const testing = @import("std").testing;
88
9fn test__floatuntidf(a: u128, expected: f64) void {9fn test__floatuntidf(a: u128, expected: f64) void {
10 const x = __floatuntidf(a);10 const x = __floatuntidf(a);
11 testing.expect(x == expected);11 try testing.expect(x == expected);
12}12}
1313
14test "floatuntidf" {14test "floatuntidf" {
lib/std/special/compiler_rt/floatuntisf_test.zig+1-1
...@@ -8,7 +8,7 @@ const testing = @import("std").testing;...@@ -8,7 +8,7 @@ const testing = @import("std").testing;
88
9fn test__floatuntisf(a: u128, expected: f32) void {9fn test__floatuntisf(a: u128, expected: f32) void {
10 const x = __floatuntisf(a);10 const x = __floatuntisf(a);
11 testing.expect(x == expected);11 try testing.expect(x == expected);
12}12}
1313
14test "floatuntisf" {14test "floatuntisf" {
lib/std/special/compiler_rt/floatuntitf_test.zig+1-1
...@@ -8,7 +8,7 @@ const testing = @import("std").testing;...@@ -8,7 +8,7 @@ const testing = @import("std").testing;
88
9fn test__floatuntitf(a: u128, expected: f128) void {9fn test__floatuntitf(a: u128, expected: f128) void {
10 const x = __floatuntitf(a);10 const x = __floatuntitf(a);
11 testing.expect(x == expected);11 try testing.expect(x == expected);
12}12}
1313
14test "floatuntitf" {14test "floatuntitf" {
lib/std/special/compiler_rt/int.zig+8-8
...@@ -64,7 +64,7 @@ test "test_divdi3" {...@@ -64,7 +64,7 @@ test "test_divdi3" {
6464
65fn test_one_divdi3(a: i64, b: i64, expected_q: i64) void {65fn test_one_divdi3(a: i64, b: i64, expected_q: i64) void {
66 const q: i64 = __divdi3(a, b);66 const q: i64 = __divdi3(a, b);
67 testing.expect(q == expected_q);67 try testing.expect(q == expected_q);
68}68}
6969
70pub fn __moddi3(a: i64, b: i64) callconv(.C) i64 {70pub fn __moddi3(a: i64, b: i64) callconv(.C) i64 {
...@@ -104,7 +104,7 @@ test "test_moddi3" {...@@ -104,7 +104,7 @@ test "test_moddi3" {
104104
105fn test_one_moddi3(a: i64, b: i64, expected_r: i64) void {105fn test_one_moddi3(a: i64, b: i64, expected_r: i64) void {
106 const r: i64 = __moddi3(a, b);106 const r: i64 = __moddi3(a, b);
107 testing.expect(r == expected_r);107 try testing.expect(r == expected_r);
108}108}
109109
110pub fn __udivdi3(a: u64, b: u64) callconv(.C) u64 {110pub fn __udivdi3(a: u64, b: u64) callconv(.C) u64 {
...@@ -130,7 +130,7 @@ test "test_umoddi3" {...@@ -130,7 +130,7 @@ test "test_umoddi3" {
130130
131fn test_one_umoddi3(a: u64, b: u64, expected_r: u64) void {131fn test_one_umoddi3(a: u64, b: u64, expected_r: u64) void {
132 const r = __umoddi3(a, b);132 const r = __umoddi3(a, b);
133 testing.expect(r == expected_r);133 try testing.expect(r == expected_r);
134}134}
135135
136pub fn __divmodsi4(a: i32, b: i32, rem: *i32) callconv(.C) i32 {136pub fn __divmodsi4(a: i32, b: i32, rem: *i32) callconv(.C) i32 {
...@@ -166,7 +166,7 @@ test "test_divmodsi4" {...@@ -166,7 +166,7 @@ test "test_divmodsi4" {
166fn test_one_divmodsi4(a: i32, b: i32, expected_q: i32, expected_r: i32) void {166fn test_one_divmodsi4(a: i32, b: i32, expected_q: i32, expected_r: i32) void {
167 var r: i32 = undefined;167 var r: i32 = undefined;
168 const q: i32 = __divmodsi4(a, b, &r);168 const q: i32 = __divmodsi4(a, b, &r);
169 testing.expect(q == expected_q and r == expected_r);169 try testing.expect(q == expected_q and r == expected_r);
170}170}
171171
172pub fn __udivmodsi4(a: u32, b: u32, rem: *u32) callconv(.C) u32 {172pub fn __udivmodsi4(a: u32, b: u32, rem: *u32) callconv(.C) u32 {
...@@ -213,7 +213,7 @@ test "test_divsi3" {...@@ -213,7 +213,7 @@ test "test_divsi3" {
213213
214fn test_one_divsi3(a: i32, b: i32, expected_q: i32) void {214fn test_one_divsi3(a: i32, b: i32, expected_q: i32) void {
215 const q: i32 = __divsi3(a, b);215 const q: i32 = __divsi3(a, b);
216 testing.expect(q == expected_q);216 try testing.expect(q == expected_q);
217}217}
218218
219pub fn __udivsi3(n: u32, d: u32) callconv(.C) u32 {219pub fn __udivsi3(n: u32, d: u32) callconv(.C) u32 {
...@@ -400,7 +400,7 @@ test "test_udivsi3" {...@@ -400,7 +400,7 @@ test "test_udivsi3" {
400400
401fn test_one_udivsi3(a: u32, b: u32, expected_q: u32) void {401fn test_one_udivsi3(a: u32, b: u32, expected_q: u32) void {
402 const q: u32 = __udivsi3(a, b);402 const q: u32 = __udivsi3(a, b);
403 testing.expect(q == expected_q);403 try testing.expect(q == expected_q);
404}404}
405405
406pub fn __modsi3(n: i32, d: i32) callconv(.C) i32 {406pub fn __modsi3(n: i32, d: i32) callconv(.C) i32 {
...@@ -431,7 +431,7 @@ test "test_modsi3" {...@@ -431,7 +431,7 @@ test "test_modsi3" {
431431
432fn test_one_modsi3(a: i32, b: i32, expected_r: i32) void {432fn test_one_modsi3(a: i32, b: i32, expected_r: i32) void {
433 const r: i32 = __modsi3(a, b);433 const r: i32 = __modsi3(a, b);
434 testing.expect(r == expected_r);434 try testing.expect(r == expected_r);
435}435}
436436
437pub fn __umodsi3(n: u32, d: u32) callconv(.C) u32 {437pub fn __umodsi3(n: u32, d: u32) callconv(.C) u32 {
...@@ -583,7 +583,7 @@ test "test_umodsi3" {...@@ -583,7 +583,7 @@ test "test_umodsi3" {
583583
584fn test_one_umodsi3(a: u32, b: u32, expected_r: u32) void {584fn test_one_umodsi3(a: u32, b: u32, expected_r: u32) void {
585 const r: u32 = __umodsi3(a, b);585 const r: u32 = __umodsi3(a, b);
586 testing.expect(r == expected_r);586 try testing.expect(r == expected_r);
587}587}
588588
589pub fn __mulsi3(a: i32, b: i32) callconv(.C) i32 {589pub fn __mulsi3(a: i32, b: i32) callconv(.C) i32 {
lib/std/special/compiler_rt/modti3_test.zig+1-1
...@@ -8,7 +8,7 @@ const testing = @import("std").testing;...@@ -8,7 +8,7 @@ const testing = @import("std").testing;
88
9fn test__modti3(a: i128, b: i128, expected: i128) void {9fn test__modti3(a: i128, b: i128, expected: i128) void {
10 const x = __modti3(a, b);10 const x = __modti3(a, b);
11 testing.expect(x == expected);11 try testing.expect(x == expected);
12}12}
1313
14test "modti3" {14test "modti3" {
lib/std/special/compiler_rt/muldi3_test.zig+1-1
...@@ -8,7 +8,7 @@ const testing = @import("std").testing;...@@ -8,7 +8,7 @@ const testing = @import("std").testing;
88
9fn test__muldi3(a: i64, b: i64, expected: i64) void {9fn test__muldi3(a: i64, b: i64, expected: i64) void {
10 const x = __muldi3(a, b);10 const x = __muldi3(a, b);
11 testing.expect(x == expected);11 try testing.expect(x == expected);
12}12}
1313
14test "muldi3" {14test "muldi3" {
lib/std/special/compiler_rt/mulodi4_test.zig+1-1
...@@ -9,7 +9,7 @@ const testing = @import("std").testing;...@@ -9,7 +9,7 @@ const testing = @import("std").testing;
9fn test__mulodi4(a: i64, b: i64, expected: i64, expected_overflow: c_int) void {9fn test__mulodi4(a: i64, b: i64, expected: i64, expected_overflow: c_int) void {
10 var overflow: c_int = undefined;10 var overflow: c_int = undefined;
11 const x = __mulodi4(a, b, &overflow);11 const x = __mulodi4(a, b, &overflow);
12 testing.expect(overflow == expected_overflow and (expected_overflow != 0 or x == expected));12 try testing.expect(overflow == expected_overflow and (expected_overflow != 0 or x == expected));
13}13}
1414
15test "mulodi4" {15test "mulodi4" {
lib/std/special/compiler_rt/muloti4_test.zig+1-1
...@@ -9,7 +9,7 @@ const testing = @import("std").testing;...@@ -9,7 +9,7 @@ const testing = @import("std").testing;
9fn test__muloti4(a: i128, b: i128, expected: i128, expected_overflow: c_int) void {9fn test__muloti4(a: i128, b: i128, expected: i128, expected_overflow: c_int) void {
10 var overflow: c_int = undefined;10 var overflow: c_int = undefined;
11 const x = __muloti4(a, b, &overflow);11 const x = __muloti4(a, b, &overflow);
12 testing.expect(overflow == expected_overflow and (expected_overflow != 0 or x == expected));12 try testing.expect(overflow == expected_overflow and (expected_overflow != 0 or x == expected));
13}13}
1414
15test "muloti4" {15test "muloti4" {
lib/std/special/compiler_rt/multi3_test.zig+1-1
...@@ -8,7 +8,7 @@ const testing = @import("std").testing;...@@ -8,7 +8,7 @@ const testing = @import("std").testing;
88
9fn test__multi3(a: i128, b: i128, expected: i128) void {9fn test__multi3(a: i128, b: i128, expected: i128) void {
10 const x = __multi3(a, b);10 const x = __multi3(a, b);
11 testing.expect(x == expected);11 try testing.expect(x == expected);
12}12}
1313
14test "multi3" {14test "multi3" {
lib/std/special/compiler_rt/popcountdi2_test.zig+1-1
...@@ -18,7 +18,7 @@ fn naive_popcount(a_param: i64) i32 {...@@ -18,7 +18,7 @@ fn naive_popcount(a_param: i64) i32 {
18fn test__popcountdi2(a: i64) void {18fn test__popcountdi2(a: i64) void {
19 const x = __popcountdi2(a);19 const x = __popcountdi2(a);
20 const expected = naive_popcount(a);20 const expected = naive_popcount(a);
21 testing.expect(expected == x);21 try testing.expect(expected == x);
22}22}
2323
24test "popcountdi2" {24test "popcountdi2" {
lib/std/special/compiler_rt/udivmoddi4_test.zig+2-2
...@@ -11,8 +11,8 @@ const testing = @import("std").testing;...@@ -11,8 +11,8 @@ const testing = @import("std").testing;
11fn test__udivmoddi4(a: u64, b: u64, expected_q: u64, expected_r: u64) void {11fn test__udivmoddi4(a: u64, b: u64, expected_q: u64, expected_r: u64) void {
12 var r: u64 = undefined;12 var r: u64 = undefined;
13 const q = __udivmoddi4(a, b, &r);13 const q = __udivmoddi4(a, b, &r);
14 testing.expect(q == expected_q);14 try testing.expect(q == expected_q);
15 testing.expect(r == expected_r);15 try testing.expect(r == expected_r);
16}16}
1717
18test "udivmoddi4" {18test "udivmoddi4" {
lib/std/special/compiler_rt/udivmodti4_test.zig+2-2
...@@ -11,8 +11,8 @@ const testing = @import("std").testing;...@@ -11,8 +11,8 @@ const testing = @import("std").testing;
11fn test__udivmodti4(a: u128, b: u128, expected_q: u128, expected_r: u128) void {11fn test__udivmodti4(a: u128, b: u128, expected_q: u128, expected_r: u128) void {
12 var r: u128 = undefined;12 var r: u128 = undefined;
13 const q = __udivmodti4(a, b, &r);13 const q = __udivmodti4(a, b, &r);
14 testing.expect(q == expected_q);14 try testing.expect(q == expected_q);
15 testing.expect(r == expected_r);15 try testing.expect(r == expected_r);
16}16}
1717
18test "udivmodti4" {18test "udivmodti4" {
lib/std/special/init-lib/src/main.zig+1-1
...@@ -6,5 +6,5 @@ export fn add(a: i32, b: i32) i32 {...@@ -6,5 +6,5 @@ export fn add(a: i32, b: i32) i32 {
6}6}
77
8test "basic add functionality" {8test "basic add functionality" {
9 testing.expect(add(3, 7) == 10);9 try testing.expect(add(3, 7) == 10);
10}10}
lib/std/time.zig+4-4
...@@ -271,7 +271,7 @@ test "timestamp" {...@@ -271,7 +271,7 @@ test "timestamp" {
271 sleep(ns_per_ms);271 sleep(ns_per_ms);
272 const time_1 = milliTimestamp();272 const time_1 = milliTimestamp();
273 const interval = time_1 - time_0;273 const interval = time_1 - time_0;
274 testing.expect(interval > 0);274 try testing.expect(interval > 0);
275 // Tests should not depend on timings: skip test if outside margin.275 // Tests should not depend on timings: skip test if outside margin.
276 if (!(interval < margin)) return error.SkipZigTest;276 if (!(interval < margin)) return error.SkipZigTest;
277}277}
...@@ -282,13 +282,13 @@ test "Timer" {...@@ -282,13 +282,13 @@ test "Timer" {
282 var timer = try Timer.start();282 var timer = try Timer.start();
283 sleep(10 * ns_per_ms);283 sleep(10 * ns_per_ms);
284 const time_0 = timer.read();284 const time_0 = timer.read();
285 testing.expect(time_0 > 0);285 try testing.expect(time_0 > 0);
286 // Tests should not depend on timings: skip test if outside margin.286 // Tests should not depend on timings: skip test if outside margin.
287 if (!(time_0 < margin)) return error.SkipZigTest;287 if (!(time_0 < margin)) return error.SkipZigTest;
288288
289 const time_1 = timer.lap();289 const time_1 = timer.lap();
290 testing.expect(time_1 >= time_0);290 try testing.expect(time_1 >= time_0);
291291
292 timer.reset();292 timer.reset();
293 testing.expect(timer.read() < time_1);293 try testing.expect(timer.read() < time_1);
294}294}
lib/std/unicode.zig+172-172
...@@ -336,224 +336,224 @@ pub const Utf16LeIterator = struct {...@@ -336,224 +336,224 @@ pub const Utf16LeIterator = struct {
336};336};
337337
338test "utf8 encode" {338test "utf8 encode" {
339 comptime testUtf8Encode() catch unreachable;339 comptime try testUtf8Encode();
340 try testUtf8Encode();340 try testUtf8Encode();
341}341}
342fn testUtf8Encode() !void {342fn testUtf8Encode() !void {
343 // A few taken from wikipedia a few taken elsewhere343 // A few taken from wikipedia a few taken elsewhere
344 var array: [4]u8 = undefined;344 var array: [4]u8 = undefined;
345 testing.expect((try utf8Encode(try utf8Decode("€"), array[0..])) == 3);345 try testing.expect((try utf8Encode(try utf8Decode("€"), array[0..])) == 3);
346 testing.expect(array[0] == 0b11100010);346 try testing.expect(array[0] == 0b11100010);
347 testing.expect(array[1] == 0b10000010);347 try testing.expect(array[1] == 0b10000010);
348 testing.expect(array[2] == 0b10101100);348 try testing.expect(array[2] == 0b10101100);
349349
350 testing.expect((try utf8Encode(try utf8Decode("$"), array[0..])) == 1);350 try testing.expect((try utf8Encode(try utf8Decode("$"), array[0..])) == 1);
351 testing.expect(array[0] == 0b00100100);351 try testing.expect(array[0] == 0b00100100);
352352
353 testing.expect((try utf8Encode(try utf8Decode("¢"), array[0..])) == 2);353 try testing.expect((try utf8Encode(try utf8Decode("¢"), array[0..])) == 2);
354 testing.expect(array[0] == 0b11000010);354 try testing.expect(array[0] == 0b11000010);
355 testing.expect(array[1] == 0b10100010);355 try testing.expect(array[1] == 0b10100010);
356356
357 testing.expect((try utf8Encode(try utf8Decode("𐍈"), array[0..])) == 4);357 try testing.expect((try utf8Encode(try utf8Decode("𐍈"), array[0..])) == 4);
358 testing.expect(array[0] == 0b11110000);358 try testing.expect(array[0] == 0b11110000);
359 testing.expect(array[1] == 0b10010000);359 try testing.expect(array[1] == 0b10010000);
360 testing.expect(array[2] == 0b10001101);360 try testing.expect(array[2] == 0b10001101);
361 testing.expect(array[3] == 0b10001000);361 try testing.expect(array[3] == 0b10001000);
362}362}
363363
364test "utf8 encode error" {364test "utf8 encode error" {
365 comptime testUtf8EncodeError();365 comptime try testUtf8EncodeError();
366 testUtf8EncodeError();366 try testUtf8EncodeError();
367}367}
368fn testUtf8EncodeError() void {368fn testUtf8EncodeError() !void {
369 var array: [4]u8 = undefined;369 var array: [4]u8 = undefined;
370 testErrorEncode(0xd800, array[0..], error.Utf8CannotEncodeSurrogateHalf);370 try testErrorEncode(0xd800, array[0..], error.Utf8CannotEncodeSurrogateHalf);
371 testErrorEncode(0xdfff, array[0..], error.Utf8CannotEncodeSurrogateHalf);371 try testErrorEncode(0xdfff, array[0..], error.Utf8CannotEncodeSurrogateHalf);
372 testErrorEncode(0x110000, array[0..], error.CodepointTooLarge);372 try testErrorEncode(0x110000, array[0..], error.CodepointTooLarge);
373 testErrorEncode(0x1fffff, array[0..], error.CodepointTooLarge);373 try testErrorEncode(0x1fffff, array[0..], error.CodepointTooLarge);
374}374}
375375
376fn testErrorEncode(codePoint: u21, array: []u8, expectedErr: anyerror) void {376fn testErrorEncode(codePoint: u21, array: []u8, expectedErr: anyerror) !void {
377 testing.expectError(expectedErr, utf8Encode(codePoint, array));377 try testing.expectError(expectedErr, utf8Encode(codePoint, array));
378}378}
379379
380test "utf8 iterator on ascii" {380test "utf8 iterator on ascii" {
381 comptime testUtf8IteratorOnAscii();381 comptime try testUtf8IteratorOnAscii();
382 testUtf8IteratorOnAscii();382 try testUtf8IteratorOnAscii();
383}383}
384fn testUtf8IteratorOnAscii() void {384fn testUtf8IteratorOnAscii() !void {
385 const s = Utf8View.initComptime("abc");385 const s = Utf8View.initComptime("abc");
386386
387 var it1 = s.iterator();387 var it1 = s.iterator();
388 testing.expect(std.mem.eql(u8, "a", it1.nextCodepointSlice().?));388 try testing.expect(std.mem.eql(u8, "a", it1.nextCodepointSlice().?));
389 testing.expect(std.mem.eql(u8, "b", it1.nextCodepointSlice().?));389 try testing.expect(std.mem.eql(u8, "b", it1.nextCodepointSlice().?));
390 testing.expect(std.mem.eql(u8, "c", it1.nextCodepointSlice().?));390 try testing.expect(std.mem.eql(u8, "c", it1.nextCodepointSlice().?));
391 testing.expect(it1.nextCodepointSlice() == null);391 try testing.expect(it1.nextCodepointSlice() == null);
392392
393 var it2 = s.iterator();393 var it2 = s.iterator();
394 testing.expect(it2.nextCodepoint().? == 'a');394 try testing.expect(it2.nextCodepoint().? == 'a');
395 testing.expect(it2.nextCodepoint().? == 'b');395 try testing.expect(it2.nextCodepoint().? == 'b');
396 testing.expect(it2.nextCodepoint().? == 'c');396 try testing.expect(it2.nextCodepoint().? == 'c');
397 testing.expect(it2.nextCodepoint() == null);397 try testing.expect(it2.nextCodepoint() == null);
398}398}
399399
400test "utf8 view bad" {400test "utf8 view bad" {
401 comptime testUtf8ViewBad();401 comptime try testUtf8ViewBad();
402 testUtf8ViewBad();402 try testUtf8ViewBad();
403}403}
404fn testUtf8ViewBad() void {404fn testUtf8ViewBad() !void {
405 // Compile-time error.405 // Compile-time error.
406 // const s3 = Utf8View.initComptime("\xfe\xf2");406 // const s3 = Utf8View.initComptime("\xfe\xf2");
407 testing.expectError(error.InvalidUtf8, Utf8View.init("hel\xadlo"));407 try testing.expectError(error.InvalidUtf8, Utf8View.init("hel\xadlo"));
408}408}
409409
410test "utf8 view ok" {410test "utf8 view ok" {
411 comptime testUtf8ViewOk();411 comptime try testUtf8ViewOk();
412 testUtf8ViewOk();412 try testUtf8ViewOk();
413}413}
414fn testUtf8ViewOk() void {414fn testUtf8ViewOk() !void {
415 const s = Utf8View.initComptime("東京市");415 const s = Utf8View.initComptime("東京市");
416416
417 var it1 = s.iterator();417 var it1 = s.iterator();
418 testing.expect(std.mem.eql(u8, "東", it1.nextCodepointSlice().?));418 try testing.expect(std.mem.eql(u8, "東", it1.nextCodepointSlice().?));
419 testing.expect(std.mem.eql(u8, "京", it1.nextCodepointSlice().?));419 try testing.expect(std.mem.eql(u8, "京", it1.nextCodepointSlice().?));
420 testing.expect(std.mem.eql(u8, "市", it1.nextCodepointSlice().?));420 try testing.expect(std.mem.eql(u8, "市", it1.nextCodepointSlice().?));
421 testing.expect(it1.nextCodepointSlice() == null);421 try testing.expect(it1.nextCodepointSlice() == null);
422422
423 var it2 = s.iterator();423 var it2 = s.iterator();
424 testing.expect(it2.nextCodepoint().? == 0x6771);424 try testing.expect(it2.nextCodepoint().? == 0x6771);
425 testing.expect(it2.nextCodepoint().? == 0x4eac);425 try testing.expect(it2.nextCodepoint().? == 0x4eac);
426 testing.expect(it2.nextCodepoint().? == 0x5e02);426 try testing.expect(it2.nextCodepoint().? == 0x5e02);
427 testing.expect(it2.nextCodepoint() == null);427 try testing.expect(it2.nextCodepoint() == null);
428}428}
429429
430test "bad utf8 slice" {430test "bad utf8 slice" {
431 comptime testBadUtf8Slice();431 comptime try testBadUtf8Slice();
432 testBadUtf8Slice();432 try testBadUtf8Slice();
433}433}
434fn testBadUtf8Slice() void {434fn testBadUtf8Slice() !void {
435 testing.expect(utf8ValidateSlice("abc"));435 try testing.expect(utf8ValidateSlice("abc"));
436 testing.expect(!utf8ValidateSlice("abc\xc0"));436 try testing.expect(!utf8ValidateSlice("abc\xc0"));
437 testing.expect(!utf8ValidateSlice("abc\xc0abc"));437 try testing.expect(!utf8ValidateSlice("abc\xc0abc"));
438 testing.expect(utf8ValidateSlice("abc\xdf\xbf"));438 try testing.expect(utf8ValidateSlice("abc\xdf\xbf"));
439}439}
440440
441test "valid utf8" {441test "valid utf8" {
442 comptime testValidUtf8();442 comptime try testValidUtf8();
443 testValidUtf8();443 try testValidUtf8();
444}444}
445fn testValidUtf8() void {445fn testValidUtf8() !void {
446 testValid("\x00", 0x0);446 try testValid("\x00", 0x0);
447 testValid("\x20", 0x20);447 try testValid("\x20", 0x20);
448 testValid("\x7f", 0x7f);448 try testValid("\x7f", 0x7f);
449 testValid("\xc2\x80", 0x80);449 try testValid("\xc2\x80", 0x80);
450 testValid("\xdf\xbf", 0x7ff);450 try testValid("\xdf\xbf", 0x7ff);
451 testValid("\xe0\xa0\x80", 0x800);451 try testValid("\xe0\xa0\x80", 0x800);
452 testValid("\xe1\x80\x80", 0x1000);452 try testValid("\xe1\x80\x80", 0x1000);
453 testValid("\xef\xbf\xbf", 0xffff);453 try testValid("\xef\xbf\xbf", 0xffff);
454 testValid("\xf0\x90\x80\x80", 0x10000);454 try testValid("\xf0\x90\x80\x80", 0x10000);
455 testValid("\xf1\x80\x80\x80", 0x40000);455 try testValid("\xf1\x80\x80\x80", 0x40000);
456 testValid("\xf3\xbf\xbf\xbf", 0xfffff);456 try testValid("\xf3\xbf\xbf\xbf", 0xfffff);
457 testValid("\xf4\x8f\xbf\xbf", 0x10ffff);457 try testValid("\xf4\x8f\xbf\xbf", 0x10ffff);
458}458}
459459
460test "invalid utf8 continuation bytes" {460test "invalid utf8 continuation bytes" {
461 comptime testInvalidUtf8ContinuationBytes();461 comptime try testInvalidUtf8ContinuationBytes();
462 testInvalidUtf8ContinuationBytes();462 try testInvalidUtf8ContinuationBytes();
463}463}
464fn testInvalidUtf8ContinuationBytes() void {464fn testInvalidUtf8ContinuationBytes() !void {
465 // unexpected continuation465 // unexpected continuation
466 testError("\x80", error.Utf8InvalidStartByte);466 try testError("\x80", error.Utf8InvalidStartByte);
467 testError("\xbf", error.Utf8InvalidStartByte);467 try testError("\xbf", error.Utf8InvalidStartByte);
468 // too many leading 1's468 // too many leading 1's
469 testError("\xf8", error.Utf8InvalidStartByte);469 try testError("\xf8", error.Utf8InvalidStartByte);
470 testError("\xff", error.Utf8InvalidStartByte);470 try testError("\xff", error.Utf8InvalidStartByte);
471 // expected continuation for 2 byte sequences471 // expected continuation for 2 byte sequences
472 testError("\xc2", error.UnexpectedEof);472 try testError("\xc2", error.UnexpectedEof);
473 testError("\xc2\x00", error.Utf8ExpectedContinuation);473 try testError("\xc2\x00", error.Utf8ExpectedContinuation);
474 testError("\xc2\xc0", error.Utf8ExpectedContinuation);474 try testError("\xc2\xc0", error.Utf8ExpectedContinuation);
475 // expected continuation for 3 byte sequences475 // expected continuation for 3 byte sequences
476 testError("\xe0", error.UnexpectedEof);476 try testError("\xe0", error.UnexpectedEof);
477 testError("\xe0\x00", error.UnexpectedEof);477 try testError("\xe0\x00", error.UnexpectedEof);
478 testError("\xe0\xc0", error.UnexpectedEof);478 try testError("\xe0\xc0", error.UnexpectedEof);
479 testError("\xe0\xa0", error.UnexpectedEof);479 try testError("\xe0\xa0", error.UnexpectedEof);
480 testError("\xe0\xa0\x00", error.Utf8ExpectedContinuation);480 try testError("\xe0\xa0\x00", error.Utf8ExpectedContinuation);
481 testError("\xe0\xa0\xc0", error.Utf8ExpectedContinuation);481 try testError("\xe0\xa0\xc0", error.Utf8ExpectedContinuation);
482 // expected continuation for 4 byte sequences482 // expected continuation for 4 byte sequences
483 testError("\xf0", error.UnexpectedEof);483 try testError("\xf0", error.UnexpectedEof);
484 testError("\xf0\x00", error.UnexpectedEof);484 try testError("\xf0\x00", error.UnexpectedEof);
485 testError("\xf0\xc0", error.UnexpectedEof);485 try testError("\xf0\xc0", error.UnexpectedEof);
486 testError("\xf0\x90\x00", error.UnexpectedEof);486 try testError("\xf0\x90\x00", error.UnexpectedEof);
487 testError("\xf0\x90\xc0", error.UnexpectedEof);487 try testError("\xf0\x90\xc0", error.UnexpectedEof);
488 testError("\xf0\x90\x80\x00", error.Utf8ExpectedContinuation);488 try testError("\xf0\x90\x80\x00", error.Utf8ExpectedContinuation);
489 testError("\xf0\x90\x80\xc0", error.Utf8ExpectedContinuation);489 try testError("\xf0\x90\x80\xc0", error.Utf8ExpectedContinuation);
490}490}
491491
492test "overlong utf8 codepoint" {492test "overlong utf8 codepoint" {
493 comptime testOverlongUtf8Codepoint();493 comptime try testOverlongUtf8Codepoint();
494 testOverlongUtf8Codepoint();494 try testOverlongUtf8Codepoint();
495}495}
496fn testOverlongUtf8Codepoint() void {496fn testOverlongUtf8Codepoint() !void {
497 testError("\xc0\x80", error.Utf8OverlongEncoding);497 try testError("\xc0\x80", error.Utf8OverlongEncoding);
498 testError("\xc1\xbf", error.Utf8OverlongEncoding);498 try testError("\xc1\xbf", error.Utf8OverlongEncoding);
499 testError("\xe0\x80\x80", error.Utf8OverlongEncoding);499 try testError("\xe0\x80\x80", error.Utf8OverlongEncoding);
500 testError("\xe0\x9f\xbf", error.Utf8OverlongEncoding);500 try testError("\xe0\x9f\xbf", error.Utf8OverlongEncoding);
501 testError("\xf0\x80\x80\x80", error.Utf8OverlongEncoding);501 try testError("\xf0\x80\x80\x80", error.Utf8OverlongEncoding);
502 testError("\xf0\x8f\xbf\xbf", error.Utf8OverlongEncoding);502 try testError("\xf0\x8f\xbf\xbf", error.Utf8OverlongEncoding);
503}503}
504504
505test "misc invalid utf8" {505test "misc invalid utf8" {
506 comptime testMiscInvalidUtf8();506 comptime try testMiscInvalidUtf8();
507 testMiscInvalidUtf8();507 try testMiscInvalidUtf8();
508}508}
509fn testMiscInvalidUtf8() void {509fn testMiscInvalidUtf8() !void {
510 // codepoint out of bounds510 // codepoint out of bounds
511 testError("\xf4\x90\x80\x80", error.Utf8CodepointTooLarge);511 try testError("\xf4\x90\x80\x80", error.Utf8CodepointTooLarge);
512 testError("\xf7\xbf\xbf\xbf", error.Utf8CodepointTooLarge);512 try testError("\xf7\xbf\xbf\xbf", error.Utf8CodepointTooLarge);
513 // surrogate halves513 // surrogate halves
514 testValid("\xed\x9f\xbf", 0xd7ff);514 try testValid("\xed\x9f\xbf", 0xd7ff);
515 testError("\xed\xa0\x80", error.Utf8EncodesSurrogateHalf);515 try testError("\xed\xa0\x80", error.Utf8EncodesSurrogateHalf);
516 testError("\xed\xbf\xbf", error.Utf8EncodesSurrogateHalf);516 try testError("\xed\xbf\xbf", error.Utf8EncodesSurrogateHalf);
517 testValid("\xee\x80\x80", 0xe000);517 try testValid("\xee\x80\x80", 0xe000);
518}518}
519519
520test "utf8 iterator peeking" {520test "utf8 iterator peeking" {
521 comptime testUtf8Peeking();521 comptime try testUtf8Peeking();
522 testUtf8Peeking();522 try testUtf8Peeking();
523}523}
524524
525fn testUtf8Peeking() void {525fn testUtf8Peeking() !void {
526 const s = Utf8View.initComptime("noël");526 const s = Utf8View.initComptime("noël");
527 var it = s.iterator();527 var it = s.iterator();
528528
529 testing.expect(std.mem.eql(u8, "n", it.nextCodepointSlice().?));529 try testing.expect(std.mem.eql(u8, "n", it.nextCodepointSlice().?));
530530
531 testing.expect(std.mem.eql(u8, "o", it.peek(1)));531 try testing.expect(std.mem.eql(u8, "o", it.peek(1)));
532 testing.expect(std.mem.eql(u8, "oë", it.peek(2)));532 try testing.expect(std.mem.eql(u8, "oë", it.peek(2)));
533 testing.expect(std.mem.eql(u8, "oël", it.peek(3)));533 try testing.expect(std.mem.eql(u8, "oël", it.peek(3)));
534 testing.expect(std.mem.eql(u8, "oël", it.peek(4)));534 try testing.expect(std.mem.eql(u8, "oël", it.peek(4)));
535 testing.expect(std.mem.eql(u8, "oël", it.peek(10)));535 try testing.expect(std.mem.eql(u8, "oël", it.peek(10)));
536536
537 testing.expect(std.mem.eql(u8, "o", it.nextCodepointSlice().?));537 try testing.expect(std.mem.eql(u8, "o", it.nextCodepointSlice().?));
538 testing.expect(std.mem.eql(u8, "ë", it.nextCodepointSlice().?));538 try testing.expect(std.mem.eql(u8, "ë", it.nextCodepointSlice().?));
539 testing.expect(std.mem.eql(u8, "l", it.nextCodepointSlice().?));539 try testing.expect(std.mem.eql(u8, "l", it.nextCodepointSlice().?));
540 testing.expect(it.nextCodepointSlice() == null);540 try testing.expect(it.nextCodepointSlice() == null);
541541
542 testing.expect(std.mem.eql(u8, &[_]u8{}, it.peek(1)));542 try testing.expect(std.mem.eql(u8, &[_]u8{}, it.peek(1)));
543}543}
544544
545fn testError(bytes: []const u8, expected_err: anyerror) void {545fn testError(bytes: []const u8, expected_err: anyerror) !void {
546 testing.expectError(expected_err, testDecode(bytes));546 try testing.expectError(expected_err, testDecode(bytes));
547}547}
548548
549fn testValid(bytes: []const u8, expected_codepoint: u21) void {549fn testValid(bytes: []const u8, expected_codepoint: u21) !void {
550 testing.expect((testDecode(bytes) catch unreachable) == expected_codepoint);550 try testing.expect((testDecode(bytes) catch unreachable) == expected_codepoint);
551}551}
552552
553fn testDecode(bytes: []const u8) !u21 {553fn testDecode(bytes: []const u8) !u21 {
554 const length = try utf8ByteSequenceLength(bytes[0]);554 const length = try utf8ByteSequenceLength(bytes[0]);
555 if (bytes.len < length) return error.UnexpectedEof;555 if (bytes.len < length) return error.UnexpectedEof;
556 testing.expect(bytes.len == length);556 try testing.expect(bytes.len == length);
557 return utf8Decode(bytes);557 return utf8Decode(bytes);
558}558}
559559
...@@ -615,7 +615,7 @@ test "utf16leToUtf8" {...@@ -615,7 +615,7 @@ test "utf16leToUtf8" {
615 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 'a');615 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 'a');
616 const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);616 const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);
617 defer std.testing.allocator.free(utf8);617 defer std.testing.allocator.free(utf8);
618 testing.expect(mem.eql(u8, utf8, "Aa"));618 try testing.expect(mem.eql(u8, utf8, "Aa"));
619 }619 }
620620
621 {621 {
...@@ -623,7 +623,7 @@ test "utf16leToUtf8" {...@@ -623,7 +623,7 @@ test "utf16leToUtf8" {
623 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xffff);623 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xffff);
624 const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);624 const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);
625 defer std.testing.allocator.free(utf8);625 defer std.testing.allocator.free(utf8);
626 testing.expect(mem.eql(u8, utf8, "\xc2\x80" ++ "\xef\xbf\xbf"));626 try testing.expect(mem.eql(u8, utf8, "\xc2\x80" ++ "\xef\xbf\xbf"));
627 }627 }
628628
629 {629 {
...@@ -632,7 +632,7 @@ test "utf16leToUtf8" {...@@ -632,7 +632,7 @@ test "utf16leToUtf8" {
632 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xe000);632 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xe000);
633 const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);633 const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);
634 defer std.testing.allocator.free(utf8);634 defer std.testing.allocator.free(utf8);
635 testing.expect(mem.eql(u8, utf8, "\xed\x9f\xbf" ++ "\xee\x80\x80"));635 try testing.expect(mem.eql(u8, utf8, "\xed\x9f\xbf" ++ "\xee\x80\x80"));
636 }636 }
637637
638 {638 {
...@@ -641,7 +641,7 @@ test "utf16leToUtf8" {...@@ -641,7 +641,7 @@ test "utf16leToUtf8" {
641 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdc00);641 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdc00);
642 const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);642 const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);
643 defer std.testing.allocator.free(utf8);643 defer std.testing.allocator.free(utf8);
644 testing.expect(mem.eql(u8, utf8, "\xf0\x90\x80\x80"));644 try testing.expect(mem.eql(u8, utf8, "\xf0\x90\x80\x80"));
645 }645 }
646646
647 {647 {
...@@ -650,7 +650,7 @@ test "utf16leToUtf8" {...@@ -650,7 +650,7 @@ test "utf16leToUtf8" {
650 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdfff);650 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdfff);
651 const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);651 const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);
652 defer std.testing.allocator.free(utf8);652 defer std.testing.allocator.free(utf8);
653 testing.expect(mem.eql(u8, utf8, "\xf4\x8f\xbf\xbf"));653 try testing.expect(mem.eql(u8, utf8, "\xf4\x8f\xbf\xbf"));
654 }654 }
655655
656 {656 {
...@@ -658,7 +658,7 @@ test "utf16leToUtf8" {...@@ -658,7 +658,7 @@ test "utf16leToUtf8" {
658 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdc00);658 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdc00);
659 const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);659 const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);
660 defer std.testing.allocator.free(utf8);660 defer std.testing.allocator.free(utf8);
661 testing.expect(mem.eql(u8, utf8, "\xf4\x8f\xb0\x80"));661 try testing.expect(mem.eql(u8, utf8, "\xf4\x8f\xb0\x80"));
662 }662 }
663}663}
664664
...@@ -717,13 +717,13 @@ test "utf8ToUtf16Le" {...@@ -717,13 +717,13 @@ test "utf8ToUtf16Le" {
717 var utf16le: [2]u16 = [_]u16{0} ** 2;717 var utf16le: [2]u16 = [_]u16{0} ** 2;
718 {718 {
719 const length = try utf8ToUtf16Le(utf16le[0..], "𐐷");719 const length = try utf8ToUtf16Le(utf16le[0..], "𐐷");
720 testing.expectEqual(@as(usize, 2), length);720 try testing.expectEqual(@as(usize, 2), length);
721 testing.expectEqualSlices(u8, "\x01\xd8\x37\xdc", mem.sliceAsBytes(utf16le[0..]));721 try testing.expectEqualSlices(u8, "\x01\xd8\x37\xdc", mem.sliceAsBytes(utf16le[0..]));
722 }722 }
723 {723 {
724 const length = try utf8ToUtf16Le(utf16le[0..], "\u{10FFFF}");724 const length = try utf8ToUtf16Le(utf16le[0..], "\u{10FFFF}");
725 testing.expectEqual(@as(usize, 2), length);725 try testing.expectEqual(@as(usize, 2), length);
726 testing.expectEqualSlices(u8, "\xff\xdb\xff\xdf", mem.sliceAsBytes(utf16le[0..]));726 try testing.expectEqualSlices(u8, "\xff\xdb\xff\xdf", mem.sliceAsBytes(utf16le[0..]));
727 }727 }
728}728}
729729
...@@ -731,14 +731,14 @@ test "utf8ToUtf16LeWithNull" {...@@ -731,14 +731,14 @@ test "utf8ToUtf16LeWithNull" {
731 {731 {
732 const utf16 = try utf8ToUtf16LeWithNull(testing.allocator, "𐐷");732 const utf16 = try utf8ToUtf16LeWithNull(testing.allocator, "𐐷");
733 defer testing.allocator.free(utf16);733 defer testing.allocator.free(utf16);
734 testing.expectEqualSlices(u8, "\x01\xd8\x37\xdc", mem.sliceAsBytes(utf16[0..]));734 try testing.expectEqualSlices(u8, "\x01\xd8\x37\xdc", mem.sliceAsBytes(utf16[0..]));
735 testing.expect(utf16[2] == 0);735 try testing.expect(utf16[2] == 0);
736 }736 }
737 {737 {
738 const utf16 = try utf8ToUtf16LeWithNull(testing.allocator, "\u{10FFFF}");738 const utf16 = try utf8ToUtf16LeWithNull(testing.allocator, "\u{10FFFF}");
739 defer testing.allocator.free(utf16);739 defer testing.allocator.free(utf16);
740 testing.expectEqualSlices(u8, "\xff\xdb\xff\xdf", mem.sliceAsBytes(utf16[0..]));740 try testing.expectEqualSlices(u8, "\xff\xdb\xff\xdf", mem.sliceAsBytes(utf16[0..]));
741 testing.expect(utf16[2] == 0);741 try testing.expect(utf16[2] == 0);
742 }742 }
743}743}
744744
...@@ -776,8 +776,8 @@ test "utf8ToUtf16LeStringLiteral" {...@@ -776,8 +776,8 @@ test "utf8ToUtf16LeStringLiteral" {
776 mem.nativeToLittle(u16, 0x41),776 mem.nativeToLittle(u16, 0x41),
777 };777 };
778 const utf16 = utf8ToUtf16LeStringLiteral("A");778 const utf16 = utf8ToUtf16LeStringLiteral("A");
779 testing.expectEqualSlices(u16, &bytes, utf16);779 try testing.expectEqualSlices(u16, &bytes, utf16);
780 testing.expect(utf16[1] == 0);780 try testing.expect(utf16[1] == 0);
781 }781 }
782 {782 {
783 const bytes = [_:0]u16{783 const bytes = [_:0]u16{
...@@ -785,32 +785,32 @@ test "utf8ToUtf16LeStringLiteral" {...@@ -785,32 +785,32 @@ test "utf8ToUtf16LeStringLiteral" {
785 mem.nativeToLittle(u16, 0xDC37),785 mem.nativeToLittle(u16, 0xDC37),
786 };786 };
787 const utf16 = utf8ToUtf16LeStringLiteral("𐐷");787 const utf16 = utf8ToUtf16LeStringLiteral("𐐷");
788 testing.expectEqualSlices(u16, &bytes, utf16);788 try testing.expectEqualSlices(u16, &bytes, utf16);
789 testing.expect(utf16[2] == 0);789 try testing.expect(utf16[2] == 0);
790 }790 }
791 {791 {
792 const bytes = [_:0]u16{792 const bytes = [_:0]u16{
793 mem.nativeToLittle(u16, 0x02FF),793 mem.nativeToLittle(u16, 0x02FF),
794 };794 };
795 const utf16 = utf8ToUtf16LeStringLiteral("\u{02FF}");795 const utf16 = utf8ToUtf16LeStringLiteral("\u{02FF}");
796 testing.expectEqualSlices(u16, &bytes, utf16);796 try testing.expectEqualSlices(u16, &bytes, utf16);
797 testing.expect(utf16[1] == 0);797 try testing.expect(utf16[1] == 0);
798 }798 }
799 {799 {
800 const bytes = [_:0]u16{800 const bytes = [_:0]u16{
801 mem.nativeToLittle(u16, 0x7FF),801 mem.nativeToLittle(u16, 0x7FF),
802 };802 };
803 const utf16 = utf8ToUtf16LeStringLiteral("\u{7FF}");803 const utf16 = utf8ToUtf16LeStringLiteral("\u{7FF}");
804 testing.expectEqualSlices(u16, &bytes, utf16);804 try testing.expectEqualSlices(u16, &bytes, utf16);
805 testing.expect(utf16[1] == 0);805 try testing.expect(utf16[1] == 0);
806 }806 }
807 {807 {
808 const bytes = [_:0]u16{808 const bytes = [_:0]u16{
809 mem.nativeToLittle(u16, 0x801),809 mem.nativeToLittle(u16, 0x801),
810 };810 };
811 const utf16 = utf8ToUtf16LeStringLiteral("\u{801}");811 const utf16 = utf8ToUtf16LeStringLiteral("\u{801}");
812 testing.expectEqualSlices(u16, &bytes, utf16);812 try testing.expectEqualSlices(u16, &bytes, utf16);
813 testing.expect(utf16[1] == 0);813 try testing.expect(utf16[1] == 0);
814 }814 }
815 {815 {
816 const bytes = [_:0]u16{816 const bytes = [_:0]u16{
...@@ -818,35 +818,35 @@ test "utf8ToUtf16LeStringLiteral" {...@@ -818,35 +818,35 @@ test "utf8ToUtf16LeStringLiteral" {
818 mem.nativeToLittle(u16, 0xDFFF),818 mem.nativeToLittle(u16, 0xDFFF),
819 };819 };
820 const utf16 = utf8ToUtf16LeStringLiteral("\u{10FFFF}");820 const utf16 = utf8ToUtf16LeStringLiteral("\u{10FFFF}");
821 testing.expectEqualSlices(u16, &bytes, utf16);821 try testing.expectEqualSlices(u16, &bytes, utf16);
822 testing.expect(utf16[2] == 0);822 try testing.expect(utf16[2] == 0);
823 }823 }
824}824}
825825
826fn testUtf8CountCodepoints() !void {826fn testUtf8CountCodepoints() !void {
827 testing.expectEqual(@as(usize, 10), try utf8CountCodepoints("abcdefghij"));827 try testing.expectEqual(@as(usize, 10), try utf8CountCodepoints("abcdefghij"));
828 testing.expectEqual(@as(usize, 10), try utf8CountCodepoints("äåéëþüúíóö"));828 try testing.expectEqual(@as(usize, 10), try utf8CountCodepoints("äåéëþüúíóö"));
829 testing.expectEqual(@as(usize, 5), try utf8CountCodepoints("こんにちは"));829 try testing.expectEqual(@as(usize, 5), try utf8CountCodepoints("こんにちは"));
830 // testing.expectError(error.Utf8EncodesSurrogateHalf, utf8CountCodepoints("\xED\xA0\x80"));830 // testing.expectError(error.Utf8EncodesSurrogateHalf, utf8CountCodepoints("\xED\xA0\x80"));
831}831}
832832
833test "utf8 count codepoints" {833test "utf8 count codepoints" {
834 try testUtf8CountCodepoints();834 try testUtf8CountCodepoints();
835 comptime testUtf8CountCodepoints() catch unreachable;835 comptime try testUtf8CountCodepoints();
836}836}
837837
838fn testUtf8ValidCodepoint() !void {838fn testUtf8ValidCodepoint() !void {
839 testing.expect(utf8ValidCodepoint('e'));839 try testing.expect(utf8ValidCodepoint('e'));
840 testing.expect(utf8ValidCodepoint('ë'));840 try testing.expect(utf8ValidCodepoint('ë'));
841 testing.expect(utf8ValidCodepoint('は'));841 try testing.expect(utf8ValidCodepoint('は'));
842 testing.expect(utf8ValidCodepoint(0xe000));842 try testing.expect(utf8ValidCodepoint(0xe000));
843 testing.expect(utf8ValidCodepoint(0x10ffff));843 try testing.expect(utf8ValidCodepoint(0x10ffff));
844 testing.expect(!utf8ValidCodepoint(0xd800));844 try testing.expect(!utf8ValidCodepoint(0xd800));
845 testing.expect(!utf8ValidCodepoint(0xdfff));845 try testing.expect(!utf8ValidCodepoint(0xdfff));
846 testing.expect(!utf8ValidCodepoint(0x110000));846 try testing.expect(!utf8ValidCodepoint(0x110000));
847}847}
848848
849test "utf8 valid codepoint" {849test "utf8 valid codepoint" {
850 try testUtf8ValidCodepoint();850 try testUtf8ValidCodepoint();
851 comptime testUtf8ValidCodepoint() catch unreachable;851 comptime try testUtf8ValidCodepoint();
852}852}
lib/std/valgrind/memcheck.zig+2-2
...@@ -149,7 +149,7 @@ pub fn countLeaks() CountResult {...@@ -149,7 +149,7 @@ pub fn countLeaks() CountResult {
149}149}
150150
151test "countLeaks" {151test "countLeaks" {
152 testing.expectEqual(152 try testing.expectEqual(
153 @as(CountResult, .{153 @as(CountResult, .{
154 .leaked = 0,154 .leaked = 0,
155 .dubious = 0,155 .dubious = 0,
...@@ -179,7 +179,7 @@ pub fn countLeakBlocks() CountResult {...@@ -179,7 +179,7 @@ pub fn countLeakBlocks() CountResult {
179}179}
180180
181test "countLeakBlocks" {181test "countLeakBlocks" {
182 testing.expectEqual(182 try testing.expectEqual(
183 @as(CountResult, .{183 @as(CountResult, .{
184 .leaked = 0,184 .leaked = 0,
185 .dubious = 0,185 .dubious = 0,
lib/std/wasm.zig+9-9
...@@ -200,11 +200,11 @@ test "Wasm - opcodes" {...@@ -200,11 +200,11 @@ test "Wasm - opcodes" {
200 const local_get = opcode(.local_get);200 const local_get = opcode(.local_get);
201 const i64_extend32_s = opcode(.i64_extend32_s);201 const i64_extend32_s = opcode(.i64_extend32_s);
202202
203 testing.expectEqual(@as(u16, 0x41), i32_const);203 try testing.expectEqual(@as(u16, 0x41), i32_const);
204 testing.expectEqual(@as(u16, 0x0B), end);204 try testing.expectEqual(@as(u16, 0x0B), end);
205 testing.expectEqual(@as(u16, 0x1A), drop);205 try testing.expectEqual(@as(u16, 0x1A), drop);
206 testing.expectEqual(@as(u16, 0x20), local_get);206 try testing.expectEqual(@as(u16, 0x20), local_get);
207 testing.expectEqual(@as(u16, 0xC4), i64_extend32_s);207 try testing.expectEqual(@as(u16, 0xC4), i64_extend32_s);
208}208}
209209
210/// Enum representing all Wasm value types as per spec:210/// Enum representing all Wasm value types as per spec:
...@@ -227,10 +227,10 @@ test "Wasm - valtypes" {...@@ -227,10 +227,10 @@ test "Wasm - valtypes" {
227 const _f32 = valtype(.f32);227 const _f32 = valtype(.f32);
228 const _f64 = valtype(.f64);228 const _f64 = valtype(.f64);
229229
230 testing.expectEqual(@as(u8, 0x7F), _i32);230 try testing.expectEqual(@as(u8, 0x7F), _i32);
231 testing.expectEqual(@as(u8, 0x7E), _i64);231 try testing.expectEqual(@as(u8, 0x7E), _i64);
232 testing.expectEqual(@as(u8, 0x7D), _f32);232 try testing.expectEqual(@as(u8, 0x7D), _f32);
233 testing.expectEqual(@as(u8, 0x7C), _f64);233 try testing.expectEqual(@as(u8, 0x7C), _f64);
234}234}
235235
236/// Wasm module sections as per spec:236/// Wasm module sections as per spec:
lib/std/x/net/tcp.zig+3-3
...@@ -322,7 +322,7 @@ test "tcp/client: set read timeout of 1 millisecond on blocking client" {...@@ -322,7 +322,7 @@ test "tcp/client: set read timeout of 1 millisecond on blocking client" {
322 defer conn.deinit();322 defer conn.deinit();
323323
324 var buf: [1]u8 = undefined;324 var buf: [1]u8 = undefined;
325 testing.expectError(error.WouldBlock, client.read(&buf));325 try testing.expectError(error.WouldBlock, client.read(&buf));
326}326}
327327
328test "tcp/listener: bind to unspecified ipv4 address" {328test "tcp/listener: bind to unspecified ipv4 address" {
...@@ -335,7 +335,7 @@ test "tcp/listener: bind to unspecified ipv4 address" {...@@ -335,7 +335,7 @@ test "tcp/listener: bind to unspecified ipv4 address" {
335 try listener.listen(128);335 try listener.listen(128);
336336
337 const address = try listener.getLocalAddress();337 const address = try listener.getLocalAddress();
338 testing.expect(address == .ipv4);338 try testing.expect(address == .ipv4);
339}339}
340340
341test "tcp/listener: bind to unspecified ipv6 address" {341test "tcp/listener: bind to unspecified ipv6 address" {
...@@ -348,5 +348,5 @@ test "tcp/listener: bind to unspecified ipv6 address" {...@@ -348,5 +348,5 @@ test "tcp/listener: bind to unspecified ipv6 address" {
348 try listener.listen(128);348 try listener.listen(128);
349349
350 const address = try listener.getLocalAddress();350 const address = try listener.getLocalAddress();
351 testing.expect(address == .ipv6);351 try testing.expect(address == .ipv6);
352}352}
lib/std/x/os/net.zig+3-3
...@@ -499,12 +499,12 @@ test {...@@ -499,12 +499,12 @@ test {
499499
500test "ip: convert to and from ipv6" {500test "ip: convert to and from ipv6" {
501 try testing.expectFmt("::7f00:1", "{}", .{IPv4.localhost.toIPv6()});501 try testing.expectFmt("::7f00:1", "{}", .{IPv4.localhost.toIPv6()});
502 testing.expect(!IPv4.localhost.toIPv6().mapsToIPv4());502 try testing.expect(!IPv4.localhost.toIPv6().mapsToIPv4());
503503
504 try testing.expectFmt("::ffff:127.0.0.1", "{}", .{IPv4.localhost.mapToIPv6()});504 try testing.expectFmt("::ffff:127.0.0.1", "{}", .{IPv4.localhost.mapToIPv6()});
505 testing.expect(IPv4.localhost.mapToIPv6().mapsToIPv4());505 try testing.expect(IPv4.localhost.mapToIPv6().mapsToIPv4());
506506
507 testing.expect(IPv4.localhost.toIPv6().toIPv4() == null);507 try testing.expect(IPv4.localhost.toIPv6().toIPv4() == null);
508 try testing.expectFmt("127.0.0.1", "{}", .{IPv4.localhost.mapToIPv6().toIPv4()});508 try testing.expectFmt("127.0.0.1", "{}", .{IPv4.localhost.mapToIPv6().toIPv4()});
509}509}
510510
lib/std/zig.zig+19-19
...@@ -253,26 +253,26 @@ pub fn parseCharLiteral(...@@ -253,26 +253,26 @@ pub fn parseCharLiteral(
253253
254test "parseCharLiteral" {254test "parseCharLiteral" {
255 var bad_index: usize = undefined;255 var bad_index: usize = undefined;
256 std.testing.expectEqual(try parseCharLiteral("'a'", &bad_index), 'a');256 try std.testing.expectEqual(try parseCharLiteral("'a'", &bad_index), 'a');
257 std.testing.expectEqual(try parseCharLiteral("'ä'", &bad_index), 'ä');257 try std.testing.expectEqual(try parseCharLiteral("'ä'", &bad_index), 'ä');
258 std.testing.expectEqual(try parseCharLiteral("'\\x00'", &bad_index), 0);258 try std.testing.expectEqual(try parseCharLiteral("'\\x00'", &bad_index), 0);
259 std.testing.expectEqual(try parseCharLiteral("'\\x4f'", &bad_index), 0x4f);259 try std.testing.expectEqual(try parseCharLiteral("'\\x4f'", &bad_index), 0x4f);
260 std.testing.expectEqual(try parseCharLiteral("'\\x4F'", &bad_index), 0x4f);260 try std.testing.expectEqual(try parseCharLiteral("'\\x4F'", &bad_index), 0x4f);
261 std.testing.expectEqual(try parseCharLiteral("'ぁ'", &bad_index), 0x3041);261 try std.testing.expectEqual(try parseCharLiteral("'ぁ'", &bad_index), 0x3041);
262 std.testing.expectEqual(try parseCharLiteral("'\\u{0}'", &bad_index), 0);262 try std.testing.expectEqual(try parseCharLiteral("'\\u{0}'", &bad_index), 0);
263 std.testing.expectEqual(try parseCharLiteral("'\\u{3041}'", &bad_index), 0x3041);263 try std.testing.expectEqual(try parseCharLiteral("'\\u{3041}'", &bad_index), 0x3041);
264 std.testing.expectEqual(try parseCharLiteral("'\\u{7f}'", &bad_index), 0x7f);264 try std.testing.expectEqual(try parseCharLiteral("'\\u{7f}'", &bad_index), 0x7f);
265 std.testing.expectEqual(try parseCharLiteral("'\\u{7FFF}'", &bad_index), 0x7FFF);265 try std.testing.expectEqual(try parseCharLiteral("'\\u{7FFF}'", &bad_index), 0x7FFF);
266266
267 std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\x0'", &bad_index));267 try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\x0'", &bad_index));
268 std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\x000'", &bad_index));268 try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\x000'", &bad_index));
269 std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\y'", &bad_index));269 try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\y'", &bad_index));
270 std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u'", &bad_index));270 try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u'", &bad_index));
271 std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\uFFFF'", &bad_index));271 try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\uFFFF'", &bad_index));
272 std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{}'", &bad_index));272 try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{}'", &bad_index));
273 std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{FFFFFF}'", &bad_index));273 try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{FFFFFF}'", &bad_index));
274 std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{FFFF'", &bad_index));274 try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{FFFF'", &bad_index));
275 std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{FFFF}x'", &bad_index));275 try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{FFFF}x'", &bad_index));
276}276}
277277
278test {278test {
lib/std/zig/cross_target.zig+38-38
...@@ -800,7 +800,7 @@ test "CrossTarget.parse" {...@@ -800,7 +800,7 @@ test "CrossTarget.parse" {
800 .{@tagName(std.Target.current.abi)},800 .{@tagName(std.Target.current.abi)},
801 ) catch unreachable;801 ) catch unreachable;
802802
803 std.testing.expectEqualSlices(u8, triple, text);803 try std.testing.expectEqualSlices(u8, triple, text);
804 }804 }
805 {805 {
806 const cross_target = try CrossTarget.parse(.{806 const cross_target = try CrossTarget.parse(.{
...@@ -808,18 +808,18 @@ test "CrossTarget.parse" {...@@ -808,18 +808,18 @@ test "CrossTarget.parse" {
808 .cpu_features = "native",808 .cpu_features = "native",
809 });809 });
810810
811 std.testing.expect(cross_target.cpu_arch.? == .aarch64);811 try std.testing.expect(cross_target.cpu_arch.? == .aarch64);
812 std.testing.expect(cross_target.cpu_model == .native);812 try std.testing.expect(cross_target.cpu_model == .native);
813 }813 }
814 {814 {
815 const cross_target = try CrossTarget.parse(.{ .arch_os_abi = "native" });815 const cross_target = try CrossTarget.parse(.{ .arch_os_abi = "native" });
816816
817 std.testing.expect(cross_target.cpu_arch == null);817 try std.testing.expect(cross_target.cpu_arch == null);
818 std.testing.expect(cross_target.isNative());818 try std.testing.expect(cross_target.isNative());
819819
820 const text = try cross_target.zigTriple(std.testing.allocator);820 const text = try cross_target.zigTriple(std.testing.allocator);
821 defer std.testing.allocator.free(text);821 defer std.testing.allocator.free(text);
822 std.testing.expectEqualSlices(u8, "native", text);822 try std.testing.expectEqualSlices(u8, "native", text);
823 }823 }
824 {824 {
825 const cross_target = try CrossTarget.parse(.{825 const cross_target = try CrossTarget.parse(.{
...@@ -828,23 +828,23 @@ test "CrossTarget.parse" {...@@ -828,23 +828,23 @@ test "CrossTarget.parse" {
828 });828 });
829 const target = cross_target.toTarget();829 const target = cross_target.toTarget();
830830
831 std.testing.expect(target.os.tag == .linux);831 try std.testing.expect(target.os.tag == .linux);
832 std.testing.expect(target.abi == .gnu);832 try std.testing.expect(target.abi == .gnu);
833 std.testing.expect(target.cpu.arch == .x86_64);833 try std.testing.expect(target.cpu.arch == .x86_64);
834 std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .sse));834 try std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .sse));
835 std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .avx));835 try std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .avx));
836 std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .cx8));836 try std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .cx8));
837 std.testing.expect(Target.x86.featureSetHas(target.cpu.features, .cmov));837 try std.testing.expect(Target.x86.featureSetHas(target.cpu.features, .cmov));
838 std.testing.expect(Target.x86.featureSetHas(target.cpu.features, .fxsr));838 try std.testing.expect(Target.x86.featureSetHas(target.cpu.features, .fxsr));
839839
840 std.testing.expect(Target.x86.featureSetHasAny(target.cpu.features, .{ .sse, .avx, .cmov }));840 try std.testing.expect(Target.x86.featureSetHasAny(target.cpu.features, .{ .sse, .avx, .cmov }));
841 std.testing.expect(!Target.x86.featureSetHasAny(target.cpu.features, .{ .sse, .avx }));841 try std.testing.expect(!Target.x86.featureSetHasAny(target.cpu.features, .{ .sse, .avx }));
842 std.testing.expect(Target.x86.featureSetHasAll(target.cpu.features, .{ .mmx, .x87 }));842 try std.testing.expect(Target.x86.featureSetHasAll(target.cpu.features, .{ .mmx, .x87 }));
843 std.testing.expect(!Target.x86.featureSetHasAll(target.cpu.features, .{ .mmx, .x87, .sse }));843 try std.testing.expect(!Target.x86.featureSetHasAll(target.cpu.features, .{ .mmx, .x87, .sse }));
844844
845 const text = try cross_target.zigTriple(std.testing.allocator);845 const text = try cross_target.zigTriple(std.testing.allocator);
846 defer std.testing.allocator.free(text);846 defer std.testing.allocator.free(text);
847 std.testing.expectEqualSlices(u8, "x86_64-linux-gnu", text);847 try std.testing.expectEqualSlices(u8, "x86_64-linux-gnu", text);
848 }848 }
849 {849 {
850 const cross_target = try CrossTarget.parse(.{850 const cross_target = try CrossTarget.parse(.{
...@@ -853,15 +853,15 @@ test "CrossTarget.parse" {...@@ -853,15 +853,15 @@ test "CrossTarget.parse" {
853 });853 });
854 const target = cross_target.toTarget();854 const target = cross_target.toTarget();
855855
856 std.testing.expect(target.os.tag == .linux);856 try std.testing.expect(target.os.tag == .linux);
857 std.testing.expect(target.abi == .musleabihf);857 try std.testing.expect(target.abi == .musleabihf);
858 std.testing.expect(target.cpu.arch == .arm);858 try std.testing.expect(target.cpu.arch == .arm);
859 std.testing.expect(target.cpu.model == &Target.arm.cpu.generic);859 try std.testing.expect(target.cpu.model == &Target.arm.cpu.generic);
860 std.testing.expect(Target.arm.featureSetHas(target.cpu.features, .v8a));860 try std.testing.expect(Target.arm.featureSetHas(target.cpu.features, .v8a));
861861
862 const text = try cross_target.zigTriple(std.testing.allocator);862 const text = try cross_target.zigTriple(std.testing.allocator);
863 defer std.testing.allocator.free(text);863 defer std.testing.allocator.free(text);
864 std.testing.expectEqualSlices(u8, "arm-linux-musleabihf", text);864 try std.testing.expectEqualSlices(u8, "arm-linux-musleabihf", text);
865 }865 }
866 {866 {
867 const cross_target = try CrossTarget.parse(.{867 const cross_target = try CrossTarget.parse(.{
...@@ -870,21 +870,21 @@ test "CrossTarget.parse" {...@@ -870,21 +870,21 @@ test "CrossTarget.parse" {
870 });870 });
871 const target = cross_target.toTarget();871 const target = cross_target.toTarget();
872872
873 std.testing.expect(target.cpu.arch == .aarch64);873 try std.testing.expect(target.cpu.arch == .aarch64);
874 std.testing.expect(target.os.tag == .linux);874 try std.testing.expect(target.os.tag == .linux);
875 std.testing.expect(target.os.version_range.linux.range.min.major == 3);875 try std.testing.expect(target.os.version_range.linux.range.min.major == 3);
876 std.testing.expect(target.os.version_range.linux.range.min.minor == 10);876 try std.testing.expect(target.os.version_range.linux.range.min.minor == 10);
877 std.testing.expect(target.os.version_range.linux.range.min.patch == 0);877 try std.testing.expect(target.os.version_range.linux.range.min.patch == 0);
878 std.testing.expect(target.os.version_range.linux.range.max.major == 4);878 try std.testing.expect(target.os.version_range.linux.range.max.major == 4);
879 std.testing.expect(target.os.version_range.linux.range.max.minor == 4);879 try std.testing.expect(target.os.version_range.linux.range.max.minor == 4);
880 std.testing.expect(target.os.version_range.linux.range.max.patch == 1);880 try std.testing.expect(target.os.version_range.linux.range.max.patch == 1);
881 std.testing.expect(target.os.version_range.linux.glibc.major == 2);881 try std.testing.expect(target.os.version_range.linux.glibc.major == 2);
882 std.testing.expect(target.os.version_range.linux.glibc.minor == 27);882 try std.testing.expect(target.os.version_range.linux.glibc.minor == 27);
883 std.testing.expect(target.os.version_range.linux.glibc.patch == 0);883 try std.testing.expect(target.os.version_range.linux.glibc.patch == 0);
884 std.testing.expect(target.abi == .gnu);884 try std.testing.expect(target.abi == .gnu);
885885
886 const text = try cross_target.zigTriple(std.testing.allocator);886 const text = try cross_target.zigTriple(std.testing.allocator);
887 defer std.testing.allocator.free(text);887 defer std.testing.allocator.free(text);
888 std.testing.expectEqualSlices(u8, "aarch64-linux.3.10...4.4.1-gnu.2.27", text);888 try std.testing.expectEqualSlices(u8, "aarch64-linux.3.10...4.4.1-gnu.2.27", text);
889 }889 }
890}890}
lib/std/zig/parser_test.zig+9-10
...@@ -988,7 +988,7 @@ test "zig fmt: while else err prong with no block" {...@@ -988,7 +988,7 @@ test "zig fmt: while else err prong with no block" {
988 \\ const result = while (returnError()) |value| {988 \\ const result = while (returnError()) |value| {
989 \\ break value;989 \\ break value;
990 \\ } else |err| @as(i32, 2);990 \\ } else |err| @as(i32, 2);
991 \\ expect(result == 2);991 \\ try expect(result == 2);
992 \\}992 \\}
993 \\993 \\
994 );994 );
...@@ -5135,7 +5135,7 @@ test "recovery: missing while rbrace" {...@@ -5135,7 +5135,7 @@ test "recovery: missing while rbrace" {
51355135
5136const std = @import("std");5136const std = @import("std");
5137const mem = std.mem;5137const mem = std.mem;
5138const warn = std.debug.warn;5138const print = std.debug.print;
5139const io = std.io;5139const io = std.io;
5140const maxInt = std.math.maxInt;5140const maxInt = std.math.maxInt;
51415141
...@@ -5177,13 +5177,13 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {...@@ -5177,13 +5177,13 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {
5177 var failing_allocator = std.testing.FailingAllocator.init(&fixed_allocator.allocator, maxInt(usize));5177 var failing_allocator = std.testing.FailingAllocator.init(&fixed_allocator.allocator, maxInt(usize));
5178 var anything_changed: bool = undefined;5178 var anything_changed: bool = undefined;
5179 const result_source = try testParse(source, &failing_allocator.allocator, &anything_changed);5179 const result_source = try testParse(source, &failing_allocator.allocator, &anything_changed);
5180 std.testing.expectEqualStrings(expected_source, result_source);5180 try std.testing.expectEqualStrings(expected_source, result_source);
5181 const changes_expected = source.ptr != expected_source.ptr;5181 const changes_expected = source.ptr != expected_source.ptr;
5182 if (anything_changed != changes_expected) {5182 if (anything_changed != changes_expected) {
5183 warn("std.zig.render returned {} instead of {}\n", .{ anything_changed, changes_expected });5183 print("std.zig.render returned {} instead of {}\n", .{ anything_changed, changes_expected });
5184 return error.TestFailed;5184 return error.TestFailed;
5185 }5185 }
5186 std.testing.expect(anything_changed == changes_expected);5186 try std.testing.expect(anything_changed == changes_expected);
5187 failing_allocator.allocator.free(result_source);5187 failing_allocator.allocator.free(result_source);
5188 break :x failing_allocator.index;5188 break :x failing_allocator.index;
5189 };5189 };
...@@ -5198,7 +5198,7 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {...@@ -5198,7 +5198,7 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {
5198 } else |err| switch (err) {5198 } else |err| switch (err) {
5199 error.OutOfMemory => {5199 error.OutOfMemory => {
5200 if (failing_allocator.allocated_bytes != failing_allocator.freed_bytes) {5200 if (failing_allocator.allocated_bytes != failing_allocator.freed_bytes) {
5201 warn(5201 print(
5202 "\nfail_index: {d}/{d}\nallocated bytes: {d}\nfreed bytes: {d}\nallocations: {d}\ndeallocations: {d}\n",5202 "\nfail_index: {d}/{d}\nallocated bytes: {d}\nfreed bytes: {d}\nallocations: {d}\ndeallocations: {d}\n",
5203 .{5203 .{
5204 fail_index,5204 fail_index,
...@@ -5212,8 +5212,7 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {...@@ -5212,8 +5212,7 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {
5212 return error.MemoryLeakDetected;5212 return error.MemoryLeakDetected;
5213 }5213 }
5214 },5214 },
5215 error.ParseError => @panic("test failed"),5215 else => return err,
5216 else => @panic("test failed"),
5217 }5216 }
5218 }5217 }
5219}5218}
...@@ -5227,8 +5226,8 @@ fn testError(source: []const u8, expected_errors: []const Error) !void {...@@ -5227,8 +5226,8 @@ fn testError(source: []const u8, expected_errors: []const Error) !void {
5227 var tree = try std.zig.parse(std.testing.allocator, source);5226 var tree = try std.zig.parse(std.testing.allocator, source);
5228 defer tree.deinit(std.testing.allocator);5227 defer tree.deinit(std.testing.allocator);
52295228
5230 std.testing.expectEqual(expected_errors.len, tree.errors.len);5229 try std.testing.expectEqual(expected_errors.len, tree.errors.len);
5231 for (expected_errors) |expected, i| {5230 for (expected_errors) |expected, i| {
5232 std.testing.expectEqual(expected, tree.errors[i].tag);5231 try std.testing.expectEqual(expected, tree.errors[i].tag);
5233 }5232 }
5234}5233}
lib/std/zig/string_literal.zig+3-3
...@@ -153,7 +153,7 @@ test "parse" {...@@ -153,7 +153,7 @@ test "parse" {
153 var fixed_buf_alloc = std.heap.FixedBufferAllocator.init(fixed_buf_mem[0..]);153 var fixed_buf_alloc = std.heap.FixedBufferAllocator.init(fixed_buf_mem[0..]);
154 var alloc = &fixed_buf_alloc.allocator;154 var alloc = &fixed_buf_alloc.allocator;
155155
156 expect(eql(u8, "foo", try parseAlloc(alloc, "\"foo\"")));156 try expect(eql(u8, "foo", try parseAlloc(alloc, "\"foo\"")));
157 expect(eql(u8, "foo", try parseAlloc(alloc, "\"f\x6f\x6f\"")));157 try expect(eql(u8, "foo", try parseAlloc(alloc, "\"f\x6f\x6f\"")));
158 expect(eql(u8, "f💯", try parseAlloc(alloc, "\"f\u{1f4af}\"")));158 try expect(eql(u8, "f💯", try parseAlloc(alloc, "\"f\u{1f4af}\"")));
159}159}
lib/std/zig/system/linux.zig+2-2
...@@ -414,8 +414,8 @@ fn testParser(...@@ -414,8 +414,8 @@ fn testParser(
414) !void {414) !void {
415 var fbs = io.fixedBufferStream(input);415 var fbs = io.fixedBufferStream(input);
416 const result = try parser.parse(arch, fbs.reader());416 const result = try parser.parse(arch, fbs.reader());
417 testing.expectEqual(expected_model, result.?.model);417 try testing.expectEqual(expected_model, result.?.model);
418 testing.expect(expected_model.features.eql(result.?.features));418 try testing.expect(expected_model.features.eql(result.?.features));
419}419}
420420
421// The generic implementation of a /proc/cpuinfo parser.421// The generic implementation of a /proc/cpuinfo parser.
lib/std/zig/system/macos.zig+1-1
...@@ -402,7 +402,7 @@ fn testVersionEquality(expected: std.builtin.Version, got: std.builtin.Version)...@@ -402,7 +402,7 @@ fn testVersionEquality(expected: std.builtin.Version, got: std.builtin.Version)
402 var b_got: [64]u8 = undefined;402 var b_got: [64]u8 = undefined;
403 const s_got: []const u8 = try std.fmt.bufPrint(b_got[0..], "{}", .{got});403 const s_got: []const u8 = try std.fmt.bufPrint(b_got[0..], "{}", .{got});
404404
405 testing.expectEqualStrings(s_expected, s_got);405 try testing.expectEqualStrings(s_expected, s_got);
406}406}
407407
408/// Detect SDK path on Darwin.408/// Detect SDK path on Darwin.
lib/std/zig/tokenizer.zig+294-294
...@@ -1503,11 +1503,11 @@ pub const Tokenizer = struct {...@@ -1503,11 +1503,11 @@ pub const Tokenizer = struct {
1503};1503};
15041504
1505test "tokenizer" {1505test "tokenizer" {
1506 testTokenize("test", &.{.keyword_test});1506 try testTokenize("test", &.{.keyword_test});
1507}1507}
15081508
1509test "line comment followed by top-level comptime" {1509test "line comment followed by top-level comptime" {
1510 testTokenize(1510 try testTokenize(
1511 \\// line comment1511 \\// line comment
1512 \\comptime {}1512 \\comptime {}
1513 \\1513 \\
...@@ -1519,7 +1519,7 @@ test "line comment followed by top-level comptime" {...@@ -1519,7 +1519,7 @@ test "line comment followed by top-level comptime" {
1519}1519}
15201520
1521test "tokenizer - unknown length pointer and then c pointer" {1521test "tokenizer - unknown length pointer and then c pointer" {
1522 testTokenize(1522 try testTokenize(
1523 \\[*]u81523 \\[*]u8
1524 \\[*c]u81524 \\[*c]u8
1525 , &.{1525 , &.{
...@@ -1536,72 +1536,72 @@ test "tokenizer - unknown length pointer and then c pointer" {...@@ -1536,72 +1536,72 @@ test "tokenizer - unknown length pointer and then c pointer" {
1536}1536}
15371537
1538test "tokenizer - code point literal with hex escape" {1538test "tokenizer - code point literal with hex escape" {
1539 testTokenize(1539 try testTokenize(
1540 \\'\x1b'1540 \\'\x1b'
1541 , &.{.char_literal});1541 , &.{.char_literal});
1542 testTokenize(1542 try testTokenize(
1543 \\'\x1'1543 \\'\x1'
1544 , &.{ .invalid, .invalid });1544 , &.{ .invalid, .invalid });
1545}1545}
15461546
1547test "tokenizer - code point literal with unicode escapes" {1547test "tokenizer - code point literal with unicode escapes" {
1548 // Valid unicode escapes1548 // Valid unicode escapes
1549 testTokenize(1549 try testTokenize(
1550 \\'\u{3}'1550 \\'\u{3}'
1551 , &.{.char_literal});1551 , &.{.char_literal});
1552 testTokenize(1552 try testTokenize(
1553 \\'\u{01}'1553 \\'\u{01}'
1554 , &.{.char_literal});1554 , &.{.char_literal});
1555 testTokenize(1555 try testTokenize(
1556 \\'\u{2a}'1556 \\'\u{2a}'
1557 , &.{.char_literal});1557 , &.{.char_literal});
1558 testTokenize(1558 try testTokenize(
1559 \\'\u{3f9}'1559 \\'\u{3f9}'
1560 , &.{.char_literal});1560 , &.{.char_literal});
1561 testTokenize(1561 try testTokenize(
1562 \\'\u{6E09aBc1523}'1562 \\'\u{6E09aBc1523}'
1563 , &.{.char_literal});1563 , &.{.char_literal});
1564 testTokenize(1564 try testTokenize(
1565 \\"\u{440}"1565 \\"\u{440}"
1566 , &.{.string_literal});1566 , &.{.string_literal});
15671567
1568 // Invalid unicode escapes1568 // Invalid unicode escapes
1569 testTokenize(1569 try testTokenize(
1570 \\'\u'1570 \\'\u'
1571 , &.{.invalid});1571 , &.{.invalid});
1572 testTokenize(1572 try testTokenize(
1573 \\'\u{{'1573 \\'\u{{'
1574 , &.{ .invalid, .invalid });1574 , &.{ .invalid, .invalid });
1575 testTokenize(1575 try testTokenize(
1576 \\'\u{}'1576 \\'\u{}'
1577 , &.{ .invalid, .invalid });1577 , &.{ .invalid, .invalid });
1578 testTokenize(1578 try testTokenize(
1579 \\'\u{s}'1579 \\'\u{s}'
1580 , &.{ .invalid, .invalid });1580 , &.{ .invalid, .invalid });
1581 testTokenize(1581 try testTokenize(
1582 \\'\u{2z}'1582 \\'\u{2z}'
1583 , &.{ .invalid, .invalid });1583 , &.{ .invalid, .invalid });
1584 testTokenize(1584 try testTokenize(
1585 \\'\u{4a'1585 \\'\u{4a'
1586 , &.{.invalid});1586 , &.{.invalid});
15871587
1588 // Test old-style unicode literals1588 // Test old-style unicode literals
1589 testTokenize(1589 try testTokenize(
1590 \\'\u0333'1590 \\'\u0333'
1591 , &.{ .invalid, .invalid });1591 , &.{ .invalid, .invalid });
1592 testTokenize(1592 try testTokenize(
1593 \\'\U0333'1593 \\'\U0333'
1594 , &.{ .invalid, .integer_literal, .invalid });1594 , &.{ .invalid, .integer_literal, .invalid });
1595}1595}
15961596
1597test "tokenizer - code point literal with unicode code point" {1597test "tokenizer - code point literal with unicode code point" {
1598 testTokenize(1598 try testTokenize(
1599 \\'💩'1599 \\'💩'
1600 , &.{.char_literal});1600 , &.{.char_literal});
1601}1601}
16021602
1603test "tokenizer - float literal e exponent" {1603test "tokenizer - float literal e exponent" {
1604 testTokenize("a = 4.94065645841246544177e-324;\n", &.{1604 try testTokenize("a = 4.94065645841246544177e-324;\n", &.{
1605 .identifier,1605 .identifier,
1606 .equal,1606 .equal,
1607 .float_literal,1607 .float_literal,
...@@ -1610,7 +1610,7 @@ test "tokenizer - float literal e exponent" {...@@ -1610,7 +1610,7 @@ test "tokenizer - float literal e exponent" {
1610}1610}
16111611
1612test "tokenizer - float literal p exponent" {1612test "tokenizer - float literal p exponent" {
1613 testTokenize("a = 0x1.a827999fcef32p+1022;\n", &.{1613 try testTokenize("a = 0x1.a827999fcef32p+1022;\n", &.{
1614 .identifier,1614 .identifier,
1615 .equal,1615 .equal,
1616 .float_literal,1616 .float_literal,
...@@ -1619,84 +1619,84 @@ test "tokenizer - float literal p exponent" {...@@ -1619,84 +1619,84 @@ test "tokenizer - float literal p exponent" {
1619}1619}
16201620
1621test "tokenizer - chars" {1621test "tokenizer - chars" {
1622 testTokenize("'c'", &.{.char_literal});1622 try testTokenize("'c'", &.{.char_literal});
1623}1623}
16241624
1625test "tokenizer - invalid token characters" {1625test "tokenizer - invalid token characters" {
1626 testTokenize("#", &.{.invalid});1626 try testTokenize("#", &.{.invalid});
1627 testTokenize("`", &.{.invalid});1627 try testTokenize("`", &.{.invalid});
1628 testTokenize("'c", &.{.invalid});1628 try testTokenize("'c", &.{.invalid});
1629 testTokenize("'", &.{.invalid});1629 try testTokenize("'", &.{.invalid});
1630 testTokenize("''", &.{ .invalid, .invalid });1630 try testTokenize("''", &.{ .invalid, .invalid });
1631}1631}
16321632
1633test "tokenizer - invalid literal/comment characters" {1633test "tokenizer - invalid literal/comment characters" {
1634 testTokenize("\"\x00\"", &.{1634 try testTokenize("\"\x00\"", &.{
1635 .string_literal,1635 .string_literal,
1636 .invalid,1636 .invalid,
1637 });1637 });
1638 testTokenize("//\x00", &.{1638 try testTokenize("//\x00", &.{
1639 .invalid,1639 .invalid,
1640 });1640 });
1641 testTokenize("//\x1f", &.{1641 try testTokenize("//\x1f", &.{
1642 .invalid,1642 .invalid,
1643 });1643 });
1644 testTokenize("//\x7f", &.{1644 try testTokenize("//\x7f", &.{
1645 .invalid,1645 .invalid,
1646 });1646 });
1647}1647}
16481648
1649test "tokenizer - utf8" {1649test "tokenizer - utf8" {
1650 testTokenize("//\xc2\x80", &.{});1650 try testTokenize("//\xc2\x80", &.{});
1651 testTokenize("//\xf4\x8f\xbf\xbf", &.{});1651 try testTokenize("//\xf4\x8f\xbf\xbf", &.{});
1652}1652}
16531653
1654test "tokenizer - invalid utf8" {1654test "tokenizer - invalid utf8" {
1655 testTokenize("//\x80", &.{1655 try testTokenize("//\x80", &.{
1656 .invalid,1656 .invalid,
1657 });1657 });
1658 testTokenize("//\xbf", &.{1658 try testTokenize("//\xbf", &.{
1659 .invalid,1659 .invalid,
1660 });1660 });
1661 testTokenize("//\xf8", &.{1661 try testTokenize("//\xf8", &.{
1662 .invalid,1662 .invalid,
1663 });1663 });
1664 testTokenize("//\xff", &.{1664 try testTokenize("//\xff", &.{
1665 .invalid,1665 .invalid,
1666 });1666 });
1667 testTokenize("//\xc2\xc0", &.{1667 try testTokenize("//\xc2\xc0", &.{
1668 .invalid,1668 .invalid,
1669 });1669 });
1670 testTokenize("//\xe0", &.{1670 try testTokenize("//\xe0", &.{
1671 .invalid,1671 .invalid,
1672 });1672 });
1673 testTokenize("//\xf0", &.{1673 try testTokenize("//\xf0", &.{
1674 .invalid,1674 .invalid,
1675 });1675 });
1676 testTokenize("//\xf0\x90\x80\xc0", &.{1676 try testTokenize("//\xf0\x90\x80\xc0", &.{
1677 .invalid,1677 .invalid,
1678 });1678 });
1679}1679}
16801680
1681test "tokenizer - illegal unicode codepoints" {1681test "tokenizer - illegal unicode codepoints" {
1682 // unicode newline characters.U+0085, U+2028, U+20291682 // unicode newline characters.U+0085, U+2028, U+2029
1683 testTokenize("//\xc2\x84", &.{});1683 try testTokenize("//\xc2\x84", &.{});
1684 testTokenize("//\xc2\x85", &.{1684 try testTokenize("//\xc2\x85", &.{
1685 .invalid,1685 .invalid,
1686 });1686 });
1687 testTokenize("//\xc2\x86", &.{});1687 try testTokenize("//\xc2\x86", &.{});
1688 testTokenize("//\xe2\x80\xa7", &.{});1688 try testTokenize("//\xe2\x80\xa7", &.{});
1689 testTokenize("//\xe2\x80\xa8", &.{1689 try testTokenize("//\xe2\x80\xa8", &.{
1690 .invalid,1690 .invalid,
1691 });1691 });
1692 testTokenize("//\xe2\x80\xa9", &.{1692 try testTokenize("//\xe2\x80\xa9", &.{
1693 .invalid,1693 .invalid,
1694 });1694 });
1695 testTokenize("//\xe2\x80\xaa", &.{});1695 try testTokenize("//\xe2\x80\xaa", &.{});
1696}1696}
16971697
1698test "tokenizer - string identifier and builtin fns" {1698test "tokenizer - string identifier and builtin fns" {
1699 testTokenize(1699 try testTokenize(
1700 \\const @"if" = @import("std");1700 \\const @"if" = @import("std");
1701 , &.{1701 , &.{
1702 .keyword_const,1702 .keyword_const,
...@@ -1711,7 +1711,7 @@ test "tokenizer - string identifier and builtin fns" {...@@ -1711,7 +1711,7 @@ test "tokenizer - string identifier and builtin fns" {
1711}1711}
17121712
1713test "tokenizer - multiline string literal with literal tab" {1713test "tokenizer - multiline string literal with literal tab" {
1714 testTokenize(1714 try testTokenize(
1715 \\\\foo bar1715 \\\\foo bar
1716 , &.{1716 , &.{
1717 .multiline_string_literal_line,1717 .multiline_string_literal_line,
...@@ -1719,7 +1719,7 @@ test "tokenizer - multiline string literal with literal tab" {...@@ -1719,7 +1719,7 @@ test "tokenizer - multiline string literal with literal tab" {
1719}1719}
17201720
1721test "tokenizer - comments with literal tab" {1721test "tokenizer - comments with literal tab" {
1722 testTokenize(1722 try testTokenize(
1723 \\//foo bar1723 \\//foo bar
1724 \\//!foo bar1724 \\//!foo bar
1725 \\///foo bar1725 \\///foo bar
...@@ -1735,25 +1735,25 @@ test "tokenizer - comments with literal tab" {...@@ -1735,25 +1735,25 @@ test "tokenizer - comments with literal tab" {
1735}1735}
17361736
1737test "tokenizer - pipe and then invalid" {1737test "tokenizer - pipe and then invalid" {
1738 testTokenize("||=", &.{1738 try testTokenize("||=", &.{
1739 .pipe_pipe,1739 .pipe_pipe,
1740 .equal,1740 .equal,
1741 });1741 });
1742}1742}
17431743
1744test "tokenizer - line comment and doc comment" {1744test "tokenizer - line comment and doc comment" {
1745 testTokenize("//", &.{});1745 try testTokenize("//", &.{});
1746 testTokenize("// a / b", &.{});1746 try testTokenize("// a / b", &.{});
1747 testTokenize("// /", &.{});1747 try testTokenize("// /", &.{});
1748 testTokenize("/// a", &.{.doc_comment});1748 try testTokenize("/// a", &.{.doc_comment});
1749 testTokenize("///", &.{.doc_comment});1749 try testTokenize("///", &.{.doc_comment});
1750 testTokenize("////", &.{});1750 try testTokenize("////", &.{});
1751 testTokenize("//!", &.{.container_doc_comment});1751 try testTokenize("//!", &.{.container_doc_comment});
1752 testTokenize("//!!", &.{.container_doc_comment});1752 try testTokenize("//!!", &.{.container_doc_comment});
1753}1753}
17541754
1755test "tokenizer - line comment followed by identifier" {1755test "tokenizer - line comment followed by identifier" {
1756 testTokenize(1756 try testTokenize(
1757 \\ Unexpected,1757 \\ Unexpected,
1758 \\ // another1758 \\ // another
1759 \\ Another,1759 \\ Another,
...@@ -1766,14 +1766,14 @@ test "tokenizer - line comment followed by identifier" {...@@ -1766,14 +1766,14 @@ test "tokenizer - line comment followed by identifier" {
1766}1766}
17671767
1768test "tokenizer - UTF-8 BOM is recognized and skipped" {1768test "tokenizer - UTF-8 BOM is recognized and skipped" {
1769 testTokenize("\xEF\xBB\xBFa;\n", &.{1769 try testTokenize("\xEF\xBB\xBFa;\n", &.{
1770 .identifier,1770 .identifier,
1771 .semicolon,1771 .semicolon,
1772 });1772 });
1773}1773}
17741774
1775test "correctly parse pointer assignment" {1775test "correctly parse pointer assignment" {
1776 testTokenize("b.*=3;\n", &.{1776 try testTokenize("b.*=3;\n", &.{
1777 .identifier,1777 .identifier,
1778 .period_asterisk,1778 .period_asterisk,
1779 .equal,1779 .equal,
...@@ -1783,14 +1783,14 @@ test "correctly parse pointer assignment" {...@@ -1783,14 +1783,14 @@ test "correctly parse pointer assignment" {
1783}1783}
17841784
1785test "correctly parse pointer dereference followed by asterisk" {1785test "correctly parse pointer dereference followed by asterisk" {
1786 testTokenize("\"b\".* ** 10", &.{1786 try testTokenize("\"b\".* ** 10", &.{
1787 .string_literal,1787 .string_literal,
1788 .period_asterisk,1788 .period_asterisk,
1789 .asterisk_asterisk,1789 .asterisk_asterisk,
1790 .integer_literal,1790 .integer_literal,
1791 });1791 });
17921792
1793 testTokenize("(\"b\".*)** 10", &.{1793 try testTokenize("(\"b\".*)** 10", &.{
1794 .l_paren,1794 .l_paren,
1795 .string_literal,1795 .string_literal,
1796 .period_asterisk,1796 .period_asterisk,
...@@ -1799,7 +1799,7 @@ test "correctly parse pointer dereference followed by asterisk" {...@@ -1799,7 +1799,7 @@ test "correctly parse pointer dereference followed by asterisk" {
1799 .integer_literal,1799 .integer_literal,
1800 });1800 });
18011801
1802 testTokenize("\"b\".*** 10", &.{1802 try testTokenize("\"b\".*** 10", &.{
1803 .string_literal,1803 .string_literal,
1804 .invalid_periodasterisks,1804 .invalid_periodasterisks,
1805 .asterisk_asterisk,1805 .asterisk_asterisk,
...@@ -1808,245 +1808,245 @@ test "correctly parse pointer dereference followed by asterisk" {...@@ -1808,245 +1808,245 @@ test "correctly parse pointer dereference followed by asterisk" {
1808}1808}
18091809
1810test "tokenizer - range literals" {1810test "tokenizer - range literals" {
1811 testTokenize("0...9", &.{ .integer_literal, .ellipsis3, .integer_literal });1811 try testTokenize("0...9", &.{ .integer_literal, .ellipsis3, .integer_literal });
1812 testTokenize("'0'...'9'", &.{ .char_literal, .ellipsis3, .char_literal });1812 try testTokenize("'0'...'9'", &.{ .char_literal, .ellipsis3, .char_literal });
1813 testTokenize("0x00...0x09", &.{ .integer_literal, .ellipsis3, .integer_literal });1813 try testTokenize("0x00...0x09", &.{ .integer_literal, .ellipsis3, .integer_literal });
1814 testTokenize("0b00...0b11", &.{ .integer_literal, .ellipsis3, .integer_literal });1814 try testTokenize("0b00...0b11", &.{ .integer_literal, .ellipsis3, .integer_literal });
1815 testTokenize("0o00...0o11", &.{ .integer_literal, .ellipsis3, .integer_literal });1815 try testTokenize("0o00...0o11", &.{ .integer_literal, .ellipsis3, .integer_literal });
1816}1816}
18171817
1818test "tokenizer - number literals decimal" {1818test "tokenizer - number literals decimal" {
1819 testTokenize("0", &.{.integer_literal});1819 try testTokenize("0", &.{.integer_literal});
1820 testTokenize("1", &.{.integer_literal});1820 try testTokenize("1", &.{.integer_literal});
1821 testTokenize("2", &.{.integer_literal});1821 try testTokenize("2", &.{.integer_literal});
1822 testTokenize("3", &.{.integer_literal});1822 try testTokenize("3", &.{.integer_literal});
1823 testTokenize("4", &.{.integer_literal});1823 try testTokenize("4", &.{.integer_literal});
1824 testTokenize("5", &.{.integer_literal});1824 try testTokenize("5", &.{.integer_literal});
1825 testTokenize("6", &.{.integer_literal});1825 try testTokenize("6", &.{.integer_literal});
1826 testTokenize("7", &.{.integer_literal});1826 try testTokenize("7", &.{.integer_literal});
1827 testTokenize("8", &.{.integer_literal});1827 try testTokenize("8", &.{.integer_literal});
1828 testTokenize("9", &.{.integer_literal});1828 try testTokenize("9", &.{.integer_literal});
1829 testTokenize("1..", &.{ .integer_literal, .ellipsis2 });1829 try testTokenize("1..", &.{ .integer_literal, .ellipsis2 });
1830 testTokenize("0a", &.{ .invalid, .identifier });1830 try testTokenize("0a", &.{ .invalid, .identifier });
1831 testTokenize("9b", &.{ .invalid, .identifier });1831 try testTokenize("9b", &.{ .invalid, .identifier });
1832 testTokenize("1z", &.{ .invalid, .identifier });1832 try testTokenize("1z", &.{ .invalid, .identifier });
1833 testTokenize("1z_1", &.{ .invalid, .identifier });1833 try testTokenize("1z_1", &.{ .invalid, .identifier });
1834 testTokenize("9z3", &.{ .invalid, .identifier });1834 try testTokenize("9z3", &.{ .invalid, .identifier });
18351835
1836 testTokenize("0_0", &.{.integer_literal});1836 try testTokenize("0_0", &.{.integer_literal});
1837 testTokenize("0001", &.{.integer_literal});1837 try testTokenize("0001", &.{.integer_literal});
1838 testTokenize("01234567890", &.{.integer_literal});1838 try testTokenize("01234567890", &.{.integer_literal});
1839 testTokenize("012_345_6789_0", &.{.integer_literal});1839 try testTokenize("012_345_6789_0", &.{.integer_literal});
1840 testTokenize("0_1_2_3_4_5_6_7_8_9_0", &.{.integer_literal});1840 try testTokenize("0_1_2_3_4_5_6_7_8_9_0", &.{.integer_literal});
18411841
1842 testTokenize("00_", &.{.invalid});1842 try testTokenize("00_", &.{.invalid});
1843 testTokenize("0_0_", &.{.invalid});1843 try testTokenize("0_0_", &.{.invalid});
1844 testTokenize("0__0", &.{ .invalid, .identifier });1844 try testTokenize("0__0", &.{ .invalid, .identifier });
1845 testTokenize("0_0f", &.{ .invalid, .identifier });1845 try testTokenize("0_0f", &.{ .invalid, .identifier });
1846 testTokenize("0_0_f", &.{ .invalid, .identifier });1846 try testTokenize("0_0_f", &.{ .invalid, .identifier });
1847 testTokenize("0_0_f_00", &.{ .invalid, .identifier });1847 try testTokenize("0_0_f_00", &.{ .invalid, .identifier });
1848 testTokenize("1_,", &.{ .invalid, .comma });1848 try testTokenize("1_,", &.{ .invalid, .comma });
18491849
1850 testTokenize("1.", &.{.float_literal});1850 try testTokenize("1.", &.{.float_literal});
1851 testTokenize("0.0", &.{.float_literal});1851 try testTokenize("0.0", &.{.float_literal});
1852 testTokenize("1.0", &.{.float_literal});1852 try testTokenize("1.0", &.{.float_literal});
1853 testTokenize("10.0", &.{.float_literal});1853 try testTokenize("10.0", &.{.float_literal});
1854 testTokenize("0e0", &.{.float_literal});1854 try testTokenize("0e0", &.{.float_literal});
1855 testTokenize("1e0", &.{.float_literal});1855 try testTokenize("1e0", &.{.float_literal});
1856 testTokenize("1e100", &.{.float_literal});1856 try testTokenize("1e100", &.{.float_literal});
1857 testTokenize("1.e100", &.{.float_literal});1857 try testTokenize("1.e100", &.{.float_literal});
1858 testTokenize("1.0e100", &.{.float_literal});1858 try testTokenize("1.0e100", &.{.float_literal});
1859 testTokenize("1.0e+100", &.{.float_literal});1859 try testTokenize("1.0e+100", &.{.float_literal});
1860 testTokenize("1.0e-100", &.{.float_literal});1860 try testTokenize("1.0e-100", &.{.float_literal});
1861 testTokenize("1_0_0_0.0_0_0_0_0_1e1_0_0_0", &.{.float_literal});1861 try testTokenize("1_0_0_0.0_0_0_0_0_1e1_0_0_0", &.{.float_literal});
1862 testTokenize("1.+", &.{ .float_literal, .plus });1862 try testTokenize("1.+", &.{ .float_literal, .plus });
18631863
1864 testTokenize("1e", &.{.invalid});1864 try testTokenize("1e", &.{.invalid});
1865 testTokenize("1.0e1f0", &.{ .invalid, .identifier });1865 try testTokenize("1.0e1f0", &.{ .invalid, .identifier });
1866 testTokenize("1.0p100", &.{ .invalid, .identifier });1866 try testTokenize("1.0p100", &.{ .invalid, .identifier });
1867 testTokenize("1.0p-100", &.{ .invalid, .identifier, .minus, .integer_literal });1867 try testTokenize("1.0p-100", &.{ .invalid, .identifier, .minus, .integer_literal });
1868 testTokenize("1.0p1f0", &.{ .invalid, .identifier });1868 try testTokenize("1.0p1f0", &.{ .invalid, .identifier });
1869 testTokenize("1.0_,", &.{ .invalid, .comma });1869 try testTokenize("1.0_,", &.{ .invalid, .comma });
1870 testTokenize("1_.0", &.{ .invalid, .period, .integer_literal });1870 try testTokenize("1_.0", &.{ .invalid, .period, .integer_literal });
1871 testTokenize("1._", &.{ .invalid, .identifier });1871 try testTokenize("1._", &.{ .invalid, .identifier });
1872 testTokenize("1.a", &.{ .invalid, .identifier });1872 try testTokenize("1.a", &.{ .invalid, .identifier });
1873 testTokenize("1.z", &.{ .invalid, .identifier });1873 try testTokenize("1.z", &.{ .invalid, .identifier });
1874 testTokenize("1._0", &.{ .invalid, .identifier });1874 try testTokenize("1._0", &.{ .invalid, .identifier });
1875 testTokenize("1._+", &.{ .invalid, .identifier, .plus });1875 try testTokenize("1._+", &.{ .invalid, .identifier, .plus });
1876 testTokenize("1._e", &.{ .invalid, .identifier });1876 try testTokenize("1._e", &.{ .invalid, .identifier });
1877 testTokenize("1.0e", &.{.invalid});1877 try testTokenize("1.0e", &.{.invalid});
1878 testTokenize("1.0e,", &.{ .invalid, .comma });1878 try testTokenize("1.0e,", &.{ .invalid, .comma });
1879 testTokenize("1.0e_", &.{ .invalid, .identifier });1879 try testTokenize("1.0e_", &.{ .invalid, .identifier });
1880 testTokenize("1.0e+_", &.{ .invalid, .identifier });1880 try testTokenize("1.0e+_", &.{ .invalid, .identifier });
1881 testTokenize("1.0e-_", &.{ .invalid, .identifier });1881 try testTokenize("1.0e-_", &.{ .invalid, .identifier });
1882 testTokenize("1.0e0_+", &.{ .invalid, .plus });1882 try testTokenize("1.0e0_+", &.{ .invalid, .plus });
1883}1883}
18841884
1885test "tokenizer - number literals binary" {1885test "tokenizer - number literals binary" {
1886 testTokenize("0b0", &.{.integer_literal});1886 try testTokenize("0b0", &.{.integer_literal});
1887 testTokenize("0b1", &.{.integer_literal});1887 try testTokenize("0b1", &.{.integer_literal});
1888 testTokenize("0b2", &.{ .invalid, .integer_literal });1888 try testTokenize("0b2", &.{ .invalid, .integer_literal });
1889 testTokenize("0b3", &.{ .invalid, .integer_literal });1889 try testTokenize("0b3", &.{ .invalid, .integer_literal });
1890 testTokenize("0b4", &.{ .invalid, .integer_literal });1890 try testTokenize("0b4", &.{ .invalid, .integer_literal });
1891 testTokenize("0b5", &.{ .invalid, .integer_literal });1891 try testTokenize("0b5", &.{ .invalid, .integer_literal });
1892 testTokenize("0b6", &.{ .invalid, .integer_literal });1892 try testTokenize("0b6", &.{ .invalid, .integer_literal });
1893 testTokenize("0b7", &.{ .invalid, .integer_literal });1893 try testTokenize("0b7", &.{ .invalid, .integer_literal });
1894 testTokenize("0b8", &.{ .invalid, .integer_literal });1894 try testTokenize("0b8", &.{ .invalid, .integer_literal });
1895 testTokenize("0b9", &.{ .invalid, .integer_literal });1895 try testTokenize("0b9", &.{ .invalid, .integer_literal });
1896 testTokenize("0ba", &.{ .invalid, .identifier });1896 try testTokenize("0ba", &.{ .invalid, .identifier });
1897 testTokenize("0bb", &.{ .invalid, .identifier });1897 try testTokenize("0bb", &.{ .invalid, .identifier });
1898 testTokenize("0bc", &.{ .invalid, .identifier });1898 try testTokenize("0bc", &.{ .invalid, .identifier });
1899 testTokenize("0bd", &.{ .invalid, .identifier });1899 try testTokenize("0bd", &.{ .invalid, .identifier });
1900 testTokenize("0be", &.{ .invalid, .identifier });1900 try testTokenize("0be", &.{ .invalid, .identifier });
1901 testTokenize("0bf", &.{ .invalid, .identifier });1901 try testTokenize("0bf", &.{ .invalid, .identifier });
1902 testTokenize("0bz", &.{ .invalid, .identifier });1902 try testTokenize("0bz", &.{ .invalid, .identifier });
19031903
1904 testTokenize("0b0000_0000", &.{.integer_literal});1904 try testTokenize("0b0000_0000", &.{.integer_literal});
1905 testTokenize("0b1111_1111", &.{.integer_literal});1905 try testTokenize("0b1111_1111", &.{.integer_literal});
1906 testTokenize("0b10_10_10_10", &.{.integer_literal});1906 try testTokenize("0b10_10_10_10", &.{.integer_literal});
1907 testTokenize("0b0_1_0_1_0_1_0_1", &.{.integer_literal});1907 try testTokenize("0b0_1_0_1_0_1_0_1", &.{.integer_literal});
1908 testTokenize("0b1.", &.{ .integer_literal, .period });1908 try testTokenize("0b1.", &.{ .integer_literal, .period });
1909 testTokenize("0b1.0", &.{ .integer_literal, .period, .integer_literal });1909 try testTokenize("0b1.0", &.{ .integer_literal, .period, .integer_literal });
19101910
1911 testTokenize("0B0", &.{ .invalid, .identifier });1911 try testTokenize("0B0", &.{ .invalid, .identifier });
1912 testTokenize("0b_", &.{ .invalid, .identifier });1912 try testTokenize("0b_", &.{ .invalid, .identifier });
1913 testTokenize("0b_0", &.{ .invalid, .identifier });1913 try testTokenize("0b_0", &.{ .invalid, .identifier });
1914 testTokenize("0b1_", &.{.invalid});1914 try testTokenize("0b1_", &.{.invalid});
1915 testTokenize("0b0__1", &.{ .invalid, .identifier });1915 try testTokenize("0b0__1", &.{ .invalid, .identifier });
1916 testTokenize("0b0_1_", &.{.invalid});1916 try testTokenize("0b0_1_", &.{.invalid});
1917 testTokenize("0b1e", &.{ .invalid, .identifier });1917 try testTokenize("0b1e", &.{ .invalid, .identifier });
1918 testTokenize("0b1p", &.{ .invalid, .identifier });1918 try testTokenize("0b1p", &.{ .invalid, .identifier });
1919 testTokenize("0b1e0", &.{ .invalid, .identifier });1919 try testTokenize("0b1e0", &.{ .invalid, .identifier });
1920 testTokenize("0b1p0", &.{ .invalid, .identifier });1920 try testTokenize("0b1p0", &.{ .invalid, .identifier });
1921 testTokenize("0b1_,", &.{ .invalid, .comma });1921 try testTokenize("0b1_,", &.{ .invalid, .comma });
1922}1922}
19231923
1924test "tokenizer - number literals octal" {1924test "tokenizer - number literals octal" {
1925 testTokenize("0o0", &.{.integer_literal});1925 try testTokenize("0o0", &.{.integer_literal});
1926 testTokenize("0o1", &.{.integer_literal});1926 try testTokenize("0o1", &.{.integer_literal});
1927 testTokenize("0o2", &.{.integer_literal});1927 try testTokenize("0o2", &.{.integer_literal});
1928 testTokenize("0o3", &.{.integer_literal});1928 try testTokenize("0o3", &.{.integer_literal});
1929 testTokenize("0o4", &.{.integer_literal});1929 try testTokenize("0o4", &.{.integer_literal});
1930 testTokenize("0o5", &.{.integer_literal});1930 try testTokenize("0o5", &.{.integer_literal});
1931 testTokenize("0o6", &.{.integer_literal});1931 try testTokenize("0o6", &.{.integer_literal});
1932 testTokenize("0o7", &.{.integer_literal});1932 try testTokenize("0o7", &.{.integer_literal});
1933 testTokenize("0o8", &.{ .invalid, .integer_literal });1933 try testTokenize("0o8", &.{ .invalid, .integer_literal });
1934 testTokenize("0o9", &.{ .invalid, .integer_literal });1934 try testTokenize("0o9", &.{ .invalid, .integer_literal });
1935 testTokenize("0oa", &.{ .invalid, .identifier });1935 try testTokenize("0oa", &.{ .invalid, .identifier });
1936 testTokenize("0ob", &.{ .invalid, .identifier });1936 try testTokenize("0ob", &.{ .invalid, .identifier });
1937 testTokenize("0oc", &.{ .invalid, .identifier });1937 try testTokenize("0oc", &.{ .invalid, .identifier });
1938 testTokenize("0od", &.{ .invalid, .identifier });1938 try testTokenize("0od", &.{ .invalid, .identifier });
1939 testTokenize("0oe", &.{ .invalid, .identifier });1939 try testTokenize("0oe", &.{ .invalid, .identifier });
1940 testTokenize("0of", &.{ .invalid, .identifier });1940 try testTokenize("0of", &.{ .invalid, .identifier });
1941 testTokenize("0oz", &.{ .invalid, .identifier });1941 try testTokenize("0oz", &.{ .invalid, .identifier });
19421942
1943 testTokenize("0o01234567", &.{.integer_literal});1943 try testTokenize("0o01234567", &.{.integer_literal});
1944 testTokenize("0o0123_4567", &.{.integer_literal});1944 try testTokenize("0o0123_4567", &.{.integer_literal});
1945 testTokenize("0o01_23_45_67", &.{.integer_literal});1945 try testTokenize("0o01_23_45_67", &.{.integer_literal});
1946 testTokenize("0o0_1_2_3_4_5_6_7", &.{.integer_literal});1946 try testTokenize("0o0_1_2_3_4_5_6_7", &.{.integer_literal});
1947 testTokenize("0o7.", &.{ .integer_literal, .period });1947 try testTokenize("0o7.", &.{ .integer_literal, .period });
1948 testTokenize("0o7.0", &.{ .integer_literal, .period, .integer_literal });1948 try testTokenize("0o7.0", &.{ .integer_literal, .period, .integer_literal });
19491949
1950 testTokenize("0O0", &.{ .invalid, .identifier });1950 try testTokenize("0O0", &.{ .invalid, .identifier });
1951 testTokenize("0o_", &.{ .invalid, .identifier });1951 try testTokenize("0o_", &.{ .invalid, .identifier });
1952 testTokenize("0o_0", &.{ .invalid, .identifier });1952 try testTokenize("0o_0", &.{ .invalid, .identifier });
1953 testTokenize("0o1_", &.{.invalid});1953 try testTokenize("0o1_", &.{.invalid});
1954 testTokenize("0o0__1", &.{ .invalid, .identifier });1954 try testTokenize("0o0__1", &.{ .invalid, .identifier });
1955 testTokenize("0o0_1_", &.{.invalid});1955 try testTokenize("0o0_1_", &.{.invalid});
1956 testTokenize("0o1e", &.{ .invalid, .identifier });1956 try testTokenize("0o1e", &.{ .invalid, .identifier });
1957 testTokenize("0o1p", &.{ .invalid, .identifier });1957 try testTokenize("0o1p", &.{ .invalid, .identifier });
1958 testTokenize("0o1e0", &.{ .invalid, .identifier });1958 try testTokenize("0o1e0", &.{ .invalid, .identifier });
1959 testTokenize("0o1p0", &.{ .invalid, .identifier });1959 try testTokenize("0o1p0", &.{ .invalid, .identifier });
1960 testTokenize("0o_,", &.{ .invalid, .identifier, .comma });1960 try testTokenize("0o_,", &.{ .invalid, .identifier, .comma });
1961}1961}
19621962
1963test "tokenizer - number literals hexadeciaml" {1963test "tokenizer - number literals hexadeciaml" {
1964 testTokenize("0x0", &.{.integer_literal});1964 try testTokenize("0x0", &.{.integer_literal});
1965 testTokenize("0x1", &.{.integer_literal});1965 try testTokenize("0x1", &.{.integer_literal});
1966 testTokenize("0x2", &.{.integer_literal});1966 try testTokenize("0x2", &.{.integer_literal});
1967 testTokenize("0x3", &.{.integer_literal});1967 try testTokenize("0x3", &.{.integer_literal});
1968 testTokenize("0x4", &.{.integer_literal});1968 try testTokenize("0x4", &.{.integer_literal});
1969 testTokenize("0x5", &.{.integer_literal});1969 try testTokenize("0x5", &.{.integer_literal});
1970 testTokenize("0x6", &.{.integer_literal});1970 try testTokenize("0x6", &.{.integer_literal});
1971 testTokenize("0x7", &.{.integer_literal});1971 try testTokenize("0x7", &.{.integer_literal});
1972 testTokenize("0x8", &.{.integer_literal});1972 try testTokenize("0x8", &.{.integer_literal});
1973 testTokenize("0x9", &.{.integer_literal});1973 try testTokenize("0x9", &.{.integer_literal});
1974 testTokenize("0xa", &.{.integer_literal});1974 try testTokenize("0xa", &.{.integer_literal});
1975 testTokenize("0xb", &.{.integer_literal});1975 try testTokenize("0xb", &.{.integer_literal});
1976 testTokenize("0xc", &.{.integer_literal});1976 try testTokenize("0xc", &.{.integer_literal});
1977 testTokenize("0xd", &.{.integer_literal});1977 try testTokenize("0xd", &.{.integer_literal});
1978 testTokenize("0xe", &.{.integer_literal});1978 try testTokenize("0xe", &.{.integer_literal});
1979 testTokenize("0xf", &.{.integer_literal});1979 try testTokenize("0xf", &.{.integer_literal});
1980 testTokenize("0xA", &.{.integer_literal});1980 try testTokenize("0xA", &.{.integer_literal});
1981 testTokenize("0xB", &.{.integer_literal});1981 try testTokenize("0xB", &.{.integer_literal});
1982 testTokenize("0xC", &.{.integer_literal});1982 try testTokenize("0xC", &.{.integer_literal});
1983 testTokenize("0xD", &.{.integer_literal});1983 try testTokenize("0xD", &.{.integer_literal});
1984 testTokenize("0xE", &.{.integer_literal});1984 try testTokenize("0xE", &.{.integer_literal});
1985 testTokenize("0xF", &.{.integer_literal});1985 try testTokenize("0xF", &.{.integer_literal});
1986 testTokenize("0x0z", &.{ .invalid, .identifier });1986 try testTokenize("0x0z", &.{ .invalid, .identifier });
1987 testTokenize("0xz", &.{ .invalid, .identifier });1987 try testTokenize("0xz", &.{ .invalid, .identifier });
19881988
1989 testTokenize("0x0123456789ABCDEF", &.{.integer_literal});1989 try testTokenize("0x0123456789ABCDEF", &.{.integer_literal});
1990 testTokenize("0x0123_4567_89AB_CDEF", &.{.integer_literal});1990 try testTokenize("0x0123_4567_89AB_CDEF", &.{.integer_literal});
1991 testTokenize("0x01_23_45_67_89AB_CDE_F", &.{.integer_literal});1991 try testTokenize("0x01_23_45_67_89AB_CDE_F", &.{.integer_literal});
1992 testTokenize("0x0_1_2_3_4_5_6_7_8_9_A_B_C_D_E_F", &.{.integer_literal});1992 try testTokenize("0x0_1_2_3_4_5_6_7_8_9_A_B_C_D_E_F", &.{.integer_literal});
19931993
1994 testTokenize("0X0", &.{ .invalid, .identifier });1994 try testTokenize("0X0", &.{ .invalid, .identifier });
1995 testTokenize("0x_", &.{ .invalid, .identifier });1995 try testTokenize("0x_", &.{ .invalid, .identifier });
1996 testTokenize("0x_1", &.{ .invalid, .identifier });1996 try testTokenize("0x_1", &.{ .invalid, .identifier });
1997 testTokenize("0x1_", &.{.invalid});1997 try testTokenize("0x1_", &.{.invalid});
1998 testTokenize("0x0__1", &.{ .invalid, .identifier });1998 try testTokenize("0x0__1", &.{ .invalid, .identifier });
1999 testTokenize("0x0_1_", &.{.invalid});1999 try testTokenize("0x0_1_", &.{.invalid});
2000 testTokenize("0x_,", &.{ .invalid, .identifier, .comma });2000 try testTokenize("0x_,", &.{ .invalid, .identifier, .comma });
20012001
2002 testTokenize("0x1.", &.{.float_literal});2002 try testTokenize("0x1.", &.{.float_literal});
2003 testTokenize("0x1.0", &.{.float_literal});2003 try testTokenize("0x1.0", &.{.float_literal});
2004 testTokenize("0xF.", &.{.float_literal});2004 try testTokenize("0xF.", &.{.float_literal});
2005 testTokenize("0xF.0", &.{.float_literal});2005 try testTokenize("0xF.0", &.{.float_literal});
2006 testTokenize("0xF.F", &.{.float_literal});2006 try testTokenize("0xF.F", &.{.float_literal});
2007 testTokenize("0xF.Fp0", &.{.float_literal});2007 try testTokenize("0xF.Fp0", &.{.float_literal});
2008 testTokenize("0xF.FP0", &.{.float_literal});2008 try testTokenize("0xF.FP0", &.{.float_literal});
2009 testTokenize("0x1p0", &.{.float_literal});2009 try testTokenize("0x1p0", &.{.float_literal});
2010 testTokenize("0xfp0", &.{.float_literal});2010 try testTokenize("0xfp0", &.{.float_literal});
2011 testTokenize("0x1.+0xF.", &.{ .float_literal, .plus, .float_literal });2011 try testTokenize("0x1.+0xF.", &.{ .float_literal, .plus, .float_literal });
20122012
2013 testTokenize("0x0123456.789ABCDEF", &.{.float_literal});2013 try testTokenize("0x0123456.789ABCDEF", &.{.float_literal});
2014 testTokenize("0x0_123_456.789_ABC_DEF", &.{.float_literal});2014 try testTokenize("0x0_123_456.789_ABC_DEF", &.{.float_literal});
2015 testTokenize("0x0_1_2_3_4_5_6.7_8_9_A_B_C_D_E_F", &.{.float_literal});2015 try testTokenize("0x0_1_2_3_4_5_6.7_8_9_A_B_C_D_E_F", &.{.float_literal});
2016 testTokenize("0x0p0", &.{.float_literal});2016 try testTokenize("0x0p0", &.{.float_literal});
2017 testTokenize("0x0.0p0", &.{.float_literal});2017 try testTokenize("0x0.0p0", &.{.float_literal});
2018 testTokenize("0xff.ffp10", &.{.float_literal});2018 try testTokenize("0xff.ffp10", &.{.float_literal});
2019 testTokenize("0xff.ffP10", &.{.float_literal});2019 try testTokenize("0xff.ffP10", &.{.float_literal});
2020 testTokenize("0xff.p10", &.{.float_literal});2020 try testTokenize("0xff.p10", &.{.float_literal});
2021 testTokenize("0xffp10", &.{.float_literal});2021 try testTokenize("0xffp10", &.{.float_literal});
2022 testTokenize("0xff_ff.ff_ffp1_0_0_0", &.{.float_literal});2022 try testTokenize("0xff_ff.ff_ffp1_0_0_0", &.{.float_literal});
2023 testTokenize("0xf_f_f_f.f_f_f_fp+1_000", &.{.float_literal});2023 try testTokenize("0xf_f_f_f.f_f_f_fp+1_000", &.{.float_literal});
2024 testTokenize("0xf_f_f_f.f_f_f_fp-1_00_0", &.{.float_literal});2024 try testTokenize("0xf_f_f_f.f_f_f_fp-1_00_0", &.{.float_literal});
20252025
2026 testTokenize("0x1e", &.{.integer_literal});2026 try testTokenize("0x1e", &.{.integer_literal});
2027 testTokenize("0x1e0", &.{.integer_literal});2027 try testTokenize("0x1e0", &.{.integer_literal});
2028 testTokenize("0x1p", &.{.invalid});2028 try testTokenize("0x1p", &.{.invalid});
2029 testTokenize("0xfp0z1", &.{ .invalid, .identifier });2029 try testTokenize("0xfp0z1", &.{ .invalid, .identifier });
2030 testTokenize("0xff.ffpff", &.{ .invalid, .identifier });2030 try testTokenize("0xff.ffpff", &.{ .invalid, .identifier });
2031 testTokenize("0x0.p", &.{.invalid});2031 try testTokenize("0x0.p", &.{.invalid});
2032 testTokenize("0x0.z", &.{ .invalid, .identifier });2032 try testTokenize("0x0.z", &.{ .invalid, .identifier });
2033 testTokenize("0x0._", &.{ .invalid, .identifier });2033 try testTokenize("0x0._", &.{ .invalid, .identifier });
2034 testTokenize("0x0_.0", &.{ .invalid, .period, .integer_literal });2034 try testTokenize("0x0_.0", &.{ .invalid, .period, .integer_literal });
2035 testTokenize("0x0_.0.0", &.{ .invalid, .period, .float_literal });2035 try testTokenize("0x0_.0.0", &.{ .invalid, .period, .float_literal });
2036 testTokenize("0x0._0", &.{ .invalid, .identifier });2036 try testTokenize("0x0._0", &.{ .invalid, .identifier });
2037 testTokenize("0x0.0_", &.{.invalid});2037 try testTokenize("0x0.0_", &.{.invalid});
2038 testTokenize("0x0_p0", &.{ .invalid, .identifier });2038 try testTokenize("0x0_p0", &.{ .invalid, .identifier });
2039 testTokenize("0x0_.p0", &.{ .invalid, .period, .identifier });2039 try testTokenize("0x0_.p0", &.{ .invalid, .period, .identifier });
2040 testTokenize("0x0._p0", &.{ .invalid, .identifier });2040 try testTokenize("0x0._p0", &.{ .invalid, .identifier });
2041 testTokenize("0x0.0_p0", &.{ .invalid, .identifier });2041 try testTokenize("0x0.0_p0", &.{ .invalid, .identifier });
2042 testTokenize("0x0._0p0", &.{ .invalid, .identifier });2042 try testTokenize("0x0._0p0", &.{ .invalid, .identifier });
2043 testTokenize("0x0.0p_0", &.{ .invalid, .identifier });2043 try testTokenize("0x0.0p_0", &.{ .invalid, .identifier });
2044 testTokenize("0x0.0p+_0", &.{ .invalid, .identifier });2044 try testTokenize("0x0.0p+_0", &.{ .invalid, .identifier });
2045 testTokenize("0x0.0p-_0", &.{ .invalid, .identifier });2045 try testTokenize("0x0.0p-_0", &.{ .invalid, .identifier });
2046 testTokenize("0x0.0p0_", &.{ .invalid, .eof });2046 try testTokenize("0x0.0p0_", &.{ .invalid, .eof });
2047}2047}
20482048
2049fn testTokenize(source: []const u8, expected_tokens: []const Token.Tag) void {2049fn testTokenize(source: []const u8, expected_tokens: []const Token.Tag) !void {
2050 var tokenizer = Tokenizer.init(source);2050 var tokenizer = Tokenizer.init(source);
2051 for (expected_tokens) |expected_token_id| {2051 for (expected_tokens) |expected_token_id| {
2052 const token = tokenizer.next();2052 const token = tokenizer.next();
...@@ -2055,6 +2055,6 @@ fn testTokenize(source: []const u8, expected_tokens: []const Token.Tag) void {...@@ -2055,6 +2055,6 @@ fn testTokenize(source: []const u8, expected_tokens: []const Token.Tag) void {
2055 }2055 }
2056 }2056 }
2057 const last_token = tokenizer.next();2057 const last_token = tokenizer.next();
2058 std.testing.expect(last_token.tag == .eof);2058 try std.testing.expect(last_token.tag == .eof);
2059 std.testing.expect(last_token.loc.start == source.len);2059 try std.testing.expect(last_token.loc.start == source.len);
2060}2060}