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" {
249249 "+justmeta",
250250 "9.8.7+meta+meta",
251251 "9.8.7-whatever+meta+meta",
252 }) |invalid| expectError(error.InvalidVersion, parse(invalid));
252 }) |invalid| try expectError(error.InvalidVersion, parse(invalid));
253253
254254 // Valid version string that may overflow.
255255 const big_valid = "99999999999999999999999.999999999999999999.99999999999999999";
256256 if (parse(big_valid)) |ver| {
257257 try std.testing.expectFmt(big_valid, "{}", .{ver});
258 } else |err| expect(err == error.Overflow);
258 } else |err| try expect(err == error.Overflow);
259259
260260 // Invalid version string that may overflow.
261261 const big_invalid = "99999999999999999999999.999999999999999999.99999999999999999----RC-SNAPSHOT.12.09.1--------------------------------..12";
......@@ -264,22 +264,22 @@ test "SemanticVersion format" {
264264
265265test "SemanticVersion precedence" {
266266 // 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);
268 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);
267 try expect(order(try parse("1.0.0"), try parse("2.0.0")) == .lt);
268 try expect(order(try parse("2.0.0"), try parse("2.1.0")) == .lt);
269 try expect(order(try parse("2.1.0"), try parse("2.1.1")) == .lt);
270270
271271 // 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
274274 // SemVer 2 spec 11.4 example: 1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta < 1.0.0-beta <
275275 // 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);
277 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);
279 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);
281 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);
276 try expect(order(try parse("1.0.0-alpha"), try parse("1.0.0-alpha.1")) == .lt);
277 try expect(order(try parse("1.0.0-alpha.1"), try parse("1.0.0-alpha.beta")) == .lt);
278 try expect(order(try parse("1.0.0-alpha.beta"), try parse("1.0.0-beta")) == .lt);
279 try expect(order(try parse("1.0.0-beta"), try parse("1.0.0-beta.2")) == .lt);
280 try expect(order(try parse("1.0.0-beta.2"), try parse("1.0.0-beta.11")) == .lt);
281 try expect(order(try parse("1.0.0-beta.11"), try parse("1.0.0-rc.1")) == .lt);
282 try expect(order(try parse("1.0.0-rc.1"), try parse("1.0.0")) == .lt);
283283}
284284
285285test "zig_version" {
lib/std/Thread/AutoResetEvent.zig+8-8
......@@ -176,7 +176,7 @@ test "basic usage" {
176176 // test local code paths
177177 {
178178 var event = AutoResetEvent{};
179 testing.expectError(error.TimedOut, event.timedWait(1));
179 try testing.expectError(error.TimedOut, event.timedWait(1));
180180 event.set();
181181 event.wait();
182182 }
......@@ -192,28 +192,28 @@ test "basic usage" {
192192
193193 const Self = @This();
194194
195 fn sender(self: *Self) void {
196 testing.expect(self.value == 0);
195 fn sender(self: *Self) !void {
196 try testing.expect(self.value == 0);
197197 self.value = 1;
198198 self.out.set();
199199
200200 self.in.wait();
201 testing.expect(self.value == 2);
201 try testing.expect(self.value == 2);
202202 self.value = 3;
203203 self.out.set();
204204
205205 self.in.wait();
206 testing.expect(self.value == 4);
206 try testing.expect(self.value == 4);
207207 }
208208
209 fn receiver(self: *Self) void {
209 fn receiver(self: *Self) !void {
210210 self.out.wait();
211 testing.expect(self.value == 1);
211 try testing.expect(self.value == 1);
212212 self.value = 2;
213213 self.in.set();
214214
215215 self.out.wait();
216 testing.expect(self.value == 3);
216 try testing.expect(self.value == 3);
217217 self.value = 4;
218218 self.in.set();
219219 }
lib/std/Thread/Mutex.zig+2-2
......@@ -294,7 +294,7 @@ test "basic usage" {
294294
295295 if (builtin.single_threaded) {
296296 worker(&context);
297 testing.expect(context.data == TestContext.incr_count);
297 try testing.expect(context.data == TestContext.incr_count);
298298 } else {
299299 const thread_count = 10;
300300 var threads: [thread_count]*std.Thread = undefined;
......@@ -304,7 +304,7 @@ test "basic usage" {
304304 for (threads) |t|
305305 t.wait();
306306
307 testing.expect(context.data == thread_count * TestContext.incr_count);
307 try testing.expect(context.data == thread_count * TestContext.incr_count);
308308 }
309309}
310310
lib/std/Thread/ResetEvent.zig+10-10
......@@ -204,7 +204,7 @@ test "basic usage" {
204204 event.reset();
205205
206206 event.set();
207 testing.expectEqual(TimedWaitResult.event_set, event.timedWait(1));
207 try testing.expectEqual(TimedWaitResult.event_set, event.timedWait(1));
208208
209209 // test cross-thread signaling
210210 if (builtin.single_threaded)
......@@ -233,25 +233,25 @@ test "basic usage" {
233233 self.* = undefined;
234234 }
235235
236 fn sender(self: *Self) void {
236 fn sender(self: *Self) !void {
237237 // update value and signal input
238 testing.expect(self.value == 0);
238 try testing.expect(self.value == 0);
239239 self.value = 1;
240240 self.in.set();
241241
242242 // wait for receiver to update value and signal output
243243 self.out.wait();
244 testing.expect(self.value == 2);
244 try testing.expect(self.value == 2);
245245
246246 // update value and signal final input
247247 self.value = 3;
248248 self.in.set();
249249 }
250250
251 fn receiver(self: *Self) void {
251 fn receiver(self: *Self) !void {
252252 // wait for sender to update value and signal input
253253 self.in.wait();
254 assert(self.value == 1);
254 try testing.expect(self.value == 1);
255255
256256 // update value and signal output
257257 self.in.reset();
......@@ -260,7 +260,7 @@ test "basic usage" {
260260
261261 // wait for sender to update value and signal final input
262262 self.in.wait();
263 assert(self.value == 3);
263 try testing.expect(self.value == 3);
264264 }
265265
266266 fn sleeper(self: *Self) void {
......@@ -272,9 +272,9 @@ test "basic usage" {
272272
273273 fn timedWaiter(self: *Self) !void {
274274 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));
276276 try self.out.timedWait(time.ns_per_ms * 100);
277 testing.expect(self.value == 5);
277 try testing.expect(self.value == 5);
278278 }
279279 };
280280
......@@ -283,7 +283,7 @@ test "basic usage" {
283283 defer context.deinit();
284284 const receiver = try std.Thread.spawn(Context.receiver, &context);
285285 defer receiver.wait();
286 context.sender();
286 try context.sender();
287287
288288 if (false) {
289289 // 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" {
320320 event.reset();
321321
322322 event.set();
323 testing.expectEqual(TimedWaitResult.event_set, event.timedWait(1));
323 try testing.expectEqual(TimedWaitResult.event_set, event.timedWait(1));
324324
325325 // test cross-thread signaling
326326 if (std.builtin.single_threaded)
......@@ -333,25 +333,25 @@ test "basic usage" {
333333 in: StaticResetEvent = .{},
334334 out: StaticResetEvent = .{},
335335
336 fn sender(self: *Self) void {
336 fn sender(self: *Self) !void {
337337 // update value and signal input
338 testing.expect(self.value == 0);
338 try testing.expect(self.value == 0);
339339 self.value = 1;
340340 self.in.set();
341341
342342 // wait for receiver to update value and signal output
343343 self.out.wait();
344 testing.expect(self.value == 2);
344 try testing.expect(self.value == 2);
345345
346346 // update value and signal final input
347347 self.value = 3;
348348 self.in.set();
349349 }
350350
351 fn receiver(self: *Self) void {
351 fn receiver(self: *Self) !void {
352352 // wait for sender to update value and signal input
353353 self.in.wait();
354 assert(self.value == 1);
354 try testing.expect(self.value == 1);
355355
356356 // update value and signal output
357357 self.in.reset();
......@@ -360,7 +360,7 @@ test "basic usage" {
360360
361361 // wait for sender to update value and signal final input
362362 self.in.wait();
363 assert(self.value == 3);
363 try testing.expect(self.value == 3);
364364 }
365365
366366 fn sleeper(self: *Self) void {
......@@ -372,16 +372,16 @@ test "basic usage" {
372372
373373 fn timedWaiter(self: *Self) !void {
374374 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));
376376 try self.out.timedWait(time.ns_per_ms * 100);
377 testing.expect(self.value == 5);
377 try testing.expect(self.value == 5);
378378 }
379379 };
380380
381381 var context = Context{};
382382 const receiver = try std.Thread.spawn(Context.receiver, &context);
383383 defer receiver.wait();
384 context.sender();
384 try context.sender();
385385
386386 if (false) {
387387 // 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" {
10641064 var map = AutoArrayHashMap(i32, i32).init(std.testing.allocator);
10651065 defer map.deinit();
10661066
1067 testing.expect((try map.fetchPut(1, 11)) == null);
1068 testing.expect((try map.fetchPut(2, 22)) == null);
1069 testing.expect((try map.fetchPut(3, 33)) == null);
1070 testing.expect((try map.fetchPut(4, 44)) == null);
1067 try testing.expect((try map.fetchPut(1, 11)) == null);
1068 try testing.expect((try map.fetchPut(2, 22)) == null);
1069 try testing.expect((try map.fetchPut(3, 33)) == null);
1070 try testing.expect((try map.fetchPut(4, 44)) == null);
10711071
10721072 try map.putNoClobber(5, 55);
1073 testing.expect((try map.fetchPut(5, 66)).?.value == 55);
1074 testing.expect((try map.fetchPut(5, 55)).?.value == 66);
1073 try testing.expect((try map.fetchPut(5, 66)).?.value == 55);
1074 try testing.expect((try map.fetchPut(5, 55)).?.value == 66);
10751075
10761076 const gop1 = try map.getOrPut(5);
1077 testing.expect(gop1.found_existing == true);
1078 testing.expect(gop1.entry.value == 55);
1079 testing.expect(gop1.index == 4);
1077 try testing.expect(gop1.found_existing == true);
1078 try testing.expect(gop1.entry.value == 55);
1079 try testing.expect(gop1.index == 4);
10801080 gop1.entry.value = 77;
1081 testing.expect(map.getEntry(5).?.value == 77);
1081 try testing.expect(map.getEntry(5).?.value == 77);
10821082
10831083 const gop2 = try map.getOrPut(99);
1084 testing.expect(gop2.found_existing == false);
1085 testing.expect(gop2.index == 5);
1084 try testing.expect(gop2.found_existing == false);
1085 try testing.expect(gop2.index == 5);
10861086 gop2.entry.value = 42;
1087 testing.expect(map.getEntry(99).?.value == 42);
1087 try testing.expect(map.getEntry(99).?.value == 42);
10881088
10891089 const gop3 = try map.getOrPutValue(5, 5);
1090 testing.expect(gop3.value == 77);
1090 try testing.expect(gop3.value == 77);
10911091
10921092 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));
1096 testing.expect(map.getEntry(2).?.value == 22);
1097 testing.expect(map.get(2).? == 22);
1095 try testing.expect(map.contains(2));
1096 try testing.expect(map.getEntry(2).?.value == 22);
1097 try testing.expect(map.get(2).? == 22);
10981098
10991099 const rmv1 = map.swapRemove(2);
1100 testing.expect(rmv1.?.key == 2);
1101 testing.expect(rmv1.?.value == 22);
1102 testing.expect(map.swapRemove(2) == null);
1103 testing.expect(map.getEntry(2) == null);
1104 testing.expect(map.get(2) == null);
1100 try testing.expect(rmv1.?.key == 2);
1101 try testing.expect(rmv1.?.value == 22);
1102 try testing.expect(map.swapRemove(2) == null);
1103 try testing.expect(map.getEntry(2) == null);
1104 try testing.expect(map.get(2) == null);
11051105
11061106 // 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);
11081108 const gop5 = try map.getOrPut(5);
1109 testing.expect(gop5.found_existing == true);
1110 testing.expect(gop5.entry.value == 77);
1111 testing.expect(gop5.index == 4);
1109 try testing.expect(gop5.found_existing == true);
1110 try testing.expect(gop5.entry.value == 77);
1111 try testing.expect(gop5.index == 4);
11121112
11131113 // Whereas, if we do an `orderedRemove`, it should move the index forward one spot.
11141114 const rmv2 = map.orderedRemove(100);
1115 testing.expect(rmv2.?.key == 100);
1116 testing.expect(rmv2.?.value == 41);
1117 testing.expect(map.orderedRemove(100) == null);
1118 testing.expect(map.getEntry(100) == null);
1119 testing.expect(map.get(100) == null);
1115 try testing.expect(rmv2.?.key == 100);
1116 try testing.expect(rmv2.?.value == 41);
1117 try testing.expect(map.orderedRemove(100) == null);
1118 try testing.expect(map.getEntry(100) == null);
1119 try testing.expect(map.get(100) == null);
11201120 const gop6 = try map.getOrPut(5);
1121 testing.expect(gop6.found_existing == true);
1122 testing.expect(gop6.entry.value == 77);
1123 testing.expect(gop6.index == 3);
1121 try testing.expect(gop6.found_existing == true);
1122 try testing.expect(gop6.entry.value == 77);
1123 try testing.expect(gop6.index == 3);
11241124
11251125 map.removeAssertDiscard(3);
11261126}
......@@ -1156,11 +1156,11 @@ test "iterator hash map" {
11561156 while (it.next()) |entry| : (count += 1) {
11571157 buffer[@intCast(usize, entry.key)] = entry.value;
11581158 }
1159 testing.expect(count == 3);
1160 testing.expect(it.next() == null);
1159 try testing.expect(count == 3);
1160 try testing.expect(it.next() == null);
11611161
11621162 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]);
11641164 }
11651165
11661166 it.reset();
......@@ -1172,13 +1172,13 @@ test "iterator hash map" {
11721172 }
11731173
11741174 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]);
11761176 }
11771177
11781178 it.reset();
11791179 var entry = it.next().?;
1180 testing.expect(entry.key == first_entry.key);
1181 testing.expect(entry.value == first_entry.value);
1180 try testing.expect(entry.key == first_entry.key);
1181 try testing.expect(entry.value == first_entry.value);
11821182}
11831183
11841184test "ensure capacity" {
......@@ -1187,13 +1187,13 @@ test "ensure capacity" {
11871187
11881188 try map.ensureCapacity(20);
11891189 const initial_capacity = map.capacity();
1190 testing.expect(initial_capacity >= 20);
1190 try testing.expect(initial_capacity >= 20);
11911191 var i: i32 = 0;
11921192 while (i < 20) : (i += 1) {
1193 testing.expect(map.fetchPutAssumeCapacity(i, i + 10) == null);
1193 try testing.expect(map.fetchPutAssumeCapacity(i, i + 10) == null);
11941194 }
11951195 // shouldn't resize from putAssumeCapacity
1196 testing.expect(initial_capacity == map.capacity());
1196 try testing.expect(initial_capacity == map.capacity());
11971197}
11981198
11991199test "clone" {
......@@ -1211,7 +1211,7 @@ test "clone" {
12111211
12121212 i = 0;
12131213 while (i < 10) : (i += 1) {
1214 testing.expect(copy.get(i).? == i * 10);
1214 try testing.expect(copy.get(i).? == i * 10);
12151215 }
12161216}
12171217
......@@ -1223,35 +1223,35 @@ test "shrink" {
12231223 const num_entries = 20;
12241224 var i: i32 = 0;
12251225 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);
1229 testing.expect(map.count() == num_entries);
1228 try testing.expect(map.unmanaged.index_header != null);
1229 try testing.expect(map.count() == num_entries);
12301230
12311231 // Test `shrinkRetainingCapacity`.
12321232 map.shrinkRetainingCapacity(17);
1233 testing.expect(map.count() == 17);
1234 testing.expect(map.capacity() == 20);
1233 try testing.expect(map.count() == 17);
1234 try testing.expect(map.capacity() == 20);
12351235 i = 0;
12361236 while (i < num_entries) : (i += 1) {
12371237 const gop = try map.getOrPut(i);
12381238 if (i < 17) {
1239 testing.expect(gop.found_existing == true);
1240 testing.expect(gop.entry.value == i * 10);
1241 } else testing.expect(gop.found_existing == false);
1239 try testing.expect(gop.found_existing == true);
1240 try testing.expect(gop.entry.value == i * 10);
1241 } else try testing.expect(gop.found_existing == false);
12421242 }
12431243
12441244 // Test `shrinkAndFree`.
12451245 map.shrinkAndFree(15);
1246 testing.expect(map.count() == 15);
1247 testing.expect(map.capacity() == 15);
1246 try testing.expect(map.count() == 15);
1247 try testing.expect(map.capacity() == 15);
12481248 i = 0;
12491249 while (i < num_entries) : (i += 1) {
12501250 const gop = try map.getOrPut(i);
12511251 if (i < 15) {
1252 testing.expect(gop.found_existing == true);
1253 testing.expect(gop.entry.value == i * 10);
1254 } else testing.expect(gop.found_existing == false);
1252 try testing.expect(gop.found_existing == true);
1253 try testing.expect(gop.entry.value == i * 10);
1254 } else try testing.expect(gop.found_existing == false);
12551255 }
12561256}
12571257
......@@ -1264,12 +1264,12 @@ test "pop" {
12641264
12651265 var i: i32 = 0;
12661266 while (i < 9) : (i += 1) {
1267 testing.expect((try map.fetchPut(i, i)) == null);
1267 try testing.expect((try map.fetchPut(i, i)) == null);
12681268 }
12691269
12701270 while (i > 0) : (i -= 1) {
12711271 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);
12731273 }
12741274}
12751275
......@@ -1281,10 +1281,10 @@ test "reIndex" {
12811281 const num_indexed_entries = 20;
12821282 var i: i32 = 0;
12831283 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
12861286 // 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
12891289 // Now write to the underlying array list directly.
12901290 const num_unindexed_entries = 20;
......@@ -1303,9 +1303,9 @@ test "reIndex" {
13031303 i = 0;
13041304 while (i < num_indexed_entries + num_unindexed_entries) : (i += 1) {
13051305 const gop = try map.getOrPut(i);
1306 testing.expect(gop.found_existing == true);
1307 testing.expect(gop.entry.value == i * 10);
1308 testing.expect(gop.index == i);
1306 try testing.expect(gop.found_existing == true);
1307 try testing.expect(gop.entry.value == i * 10);
1308 try testing.expect(gop.index == i);
13091309 }
13101310}
13111311
......@@ -1332,9 +1332,9 @@ test "fromOwnedArrayList" {
13321332 i = 0;
13331333 while (i < num_entries) : (i += 1) {
13341334 const gop = try map.getOrPut(i);
1335 testing.expect(gop.found_existing == true);
1336 testing.expect(gop.entry.value == i * 10);
1337 testing.expect(gop.index == i);
1335 try testing.expect(gop.found_existing == true);
1336 try testing.expect(gop.entry.value == i * 10);
1337 try testing.expect(gop.index == i);
13381338 }
13391339}
13401340
lib/std/array_list.zig+116-116
......@@ -695,15 +695,15 @@ test "std.ArrayList/ArrayListUnmanaged.init" {
695695 var list = ArrayList(i32).init(testing.allocator);
696696 defer list.deinit();
697697
698 testing.expect(list.items.len == 0);
699 testing.expect(list.capacity == 0);
698 try testing.expect(list.items.len == 0);
699 try testing.expect(list.capacity == 0);
700700 }
701701
702702 {
703703 var list = ArrayListUnmanaged(i32){};
704704
705 testing.expect(list.items.len == 0);
706 testing.expect(list.capacity == 0);
705 try testing.expect(list.items.len == 0);
706 try testing.expect(list.capacity == 0);
707707 }
708708}
709709
......@@ -712,14 +712,14 @@ test "std.ArrayList/ArrayListUnmanaged.initCapacity" {
712712 {
713713 var list = try ArrayList(i8).initCapacity(a, 200);
714714 defer list.deinit();
715 testing.expect(list.items.len == 0);
716 testing.expect(list.capacity >= 200);
715 try testing.expect(list.items.len == 0);
716 try testing.expect(list.capacity >= 200);
717717 }
718718 {
719719 var list = try ArrayListUnmanaged(i8).initCapacity(a, 200);
720720 defer list.deinit(a);
721 testing.expect(list.items.len == 0);
722 testing.expect(list.capacity >= 200);
721 try testing.expect(list.items.len == 0);
722 try testing.expect(list.capacity >= 200);
723723 }
724724}
725725
......@@ -739,33 +739,33 @@ test "std.ArrayList/ArrayListUnmanaged.basic" {
739739 {
740740 var i: usize = 0;
741741 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));
743743 }
744744 }
745745
746746 for (list.items) |v, i| {
747 testing.expect(v == @intCast(i32, i + 1));
747 try testing.expect(v == @intCast(i32, i + 1));
748748 }
749749
750 testing.expect(list.pop() == 10);
751 testing.expect(list.items.len == 9);
750 try testing.expect(list.pop() == 10);
751 try testing.expect(list.items.len == 9);
752752
753753 list.appendSlice(&[_]i32{ 1, 2, 3 }) catch unreachable;
754 testing.expect(list.items.len == 12);
755 testing.expect(list.pop() == 3);
756 testing.expect(list.pop() == 2);
757 testing.expect(list.pop() == 1);
758 testing.expect(list.items.len == 9);
754 try testing.expect(list.items.len == 12);
755 try testing.expect(list.pop() == 3);
756 try testing.expect(list.pop() == 2);
757 try testing.expect(list.pop() == 1);
758 try testing.expect(list.items.len == 9);
759759
760760 list.appendSlice(&[_]i32{}) catch unreachable;
761 testing.expect(list.items.len == 9);
761 try testing.expect(list.items.len == 9);
762762
763763 // can only set on indices < self.items.len
764764 list.items[7] = 33;
765765 list.items[8] = 42;
766766
767 testing.expect(list.pop() == 42);
768 testing.expect(list.pop() == 33);
767 try testing.expect(list.pop() == 42);
768 try testing.expect(list.pop() == 33);
769769 }
770770 {
771771 var list = ArrayListUnmanaged(i32){};
......@@ -781,33 +781,33 @@ test "std.ArrayList/ArrayListUnmanaged.basic" {
781781 {
782782 var i: usize = 0;
783783 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));
785785 }
786786 }
787787
788788 for (list.items) |v, i| {
789 testing.expect(v == @intCast(i32, i + 1));
789 try testing.expect(v == @intCast(i32, i + 1));
790790 }
791791
792 testing.expect(list.pop() == 10);
793 testing.expect(list.items.len == 9);
792 try testing.expect(list.pop() == 10);
793 try testing.expect(list.items.len == 9);
794794
795795 list.appendSlice(a, &[_]i32{ 1, 2, 3 }) catch unreachable;
796 testing.expect(list.items.len == 12);
797 testing.expect(list.pop() == 3);
798 testing.expect(list.pop() == 2);
799 testing.expect(list.pop() == 1);
800 testing.expect(list.items.len == 9);
796 try testing.expect(list.items.len == 12);
797 try testing.expect(list.pop() == 3);
798 try testing.expect(list.pop() == 2);
799 try testing.expect(list.pop() == 1);
800 try testing.expect(list.items.len == 9);
801801
802802 list.appendSlice(a, &[_]i32{}) catch unreachable;
803 testing.expect(list.items.len == 9);
803 try testing.expect(list.items.len == 9);
804804
805805 // can only set on indices < self.items.len
806806 list.items[7] = 33;
807807 list.items[8] = 42;
808808
809 testing.expect(list.pop() == 42);
810 testing.expect(list.pop() == 33);
809 try testing.expect(list.pop() == 42);
810 try testing.expect(list.pop() == 33);
811811 }
812812}
813813
......@@ -818,9 +818,9 @@ test "std.ArrayList/ArrayListUnmanaged.appendNTimes" {
818818 defer list.deinit();
819819
820820 try list.appendNTimes(2, 10);
821 testing.expectEqual(@as(usize, 10), list.items.len);
821 try testing.expectEqual(@as(usize, 10), list.items.len);
822822 for (list.items) |element| {
823 testing.expectEqual(@as(i32, 2), element);
823 try testing.expectEqual(@as(i32, 2), element);
824824 }
825825 }
826826 {
......@@ -828,9 +828,9 @@ test "std.ArrayList/ArrayListUnmanaged.appendNTimes" {
828828 defer list.deinit(a);
829829
830830 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);
832832 for (list.items) |element| {
833 testing.expectEqual(@as(i32, 2), element);
833 try testing.expectEqual(@as(i32, 2), element);
834834 }
835835 }
836836}
......@@ -840,12 +840,12 @@ test "std.ArrayList/ArrayListUnmanaged.appendNTimes with failing allocator" {
840840 {
841841 var list = ArrayList(i32).init(a);
842842 defer list.deinit();
843 testing.expectError(error.OutOfMemory, list.appendNTimes(2, 10));
843 try testing.expectError(error.OutOfMemory, list.appendNTimes(2, 10));
844844 }
845845 {
846846 var list = ArrayListUnmanaged(i32){};
847847 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));
849849 }
850850}
851851
......@@ -864,18 +864,18 @@ test "std.ArrayList/ArrayListUnmanaged.orderedRemove" {
864864 try list.append(7);
865865
866866 //remove from middle
867 testing.expectEqual(@as(i32, 4), list.orderedRemove(3));
868 testing.expectEqual(@as(i32, 5), list.items[3]);
869 testing.expectEqual(@as(usize, 6), list.items.len);
867 try testing.expectEqual(@as(i32, 4), list.orderedRemove(3));
868 try testing.expectEqual(@as(i32, 5), list.items[3]);
869 try testing.expectEqual(@as(usize, 6), list.items.len);
870870
871871 //remove from end
872 testing.expectEqual(@as(i32, 7), list.orderedRemove(5));
873 testing.expectEqual(@as(usize, 5), list.items.len);
872 try testing.expectEqual(@as(i32, 7), list.orderedRemove(5));
873 try testing.expectEqual(@as(usize, 5), list.items.len);
874874
875875 //remove from front
876 testing.expectEqual(@as(i32, 1), list.orderedRemove(0));
877 testing.expectEqual(@as(i32, 2), list.items[0]);
878 testing.expectEqual(@as(usize, 4), list.items.len);
876 try testing.expectEqual(@as(i32, 1), list.orderedRemove(0));
877 try testing.expectEqual(@as(i32, 2), list.items[0]);
878 try testing.expectEqual(@as(usize, 4), list.items.len);
879879 }
880880 {
881881 var list = ArrayListUnmanaged(i32){};
......@@ -890,18 +890,18 @@ test "std.ArrayList/ArrayListUnmanaged.orderedRemove" {
890890 try list.append(a, 7);
891891
892892 //remove from middle
893 testing.expectEqual(@as(i32, 4), list.orderedRemove(3));
894 testing.expectEqual(@as(i32, 5), list.items[3]);
895 testing.expectEqual(@as(usize, 6), list.items.len);
893 try testing.expectEqual(@as(i32, 4), list.orderedRemove(3));
894 try testing.expectEqual(@as(i32, 5), list.items[3]);
895 try testing.expectEqual(@as(usize, 6), list.items.len);
896896
897897 //remove from end
898 testing.expectEqual(@as(i32, 7), list.orderedRemove(5));
899 testing.expectEqual(@as(usize, 5), list.items.len);
898 try testing.expectEqual(@as(i32, 7), list.orderedRemove(5));
899 try testing.expectEqual(@as(usize, 5), list.items.len);
900900
901901 //remove from front
902 testing.expectEqual(@as(i32, 1), list.orderedRemove(0));
903 testing.expectEqual(@as(i32, 2), list.items[0]);
904 testing.expectEqual(@as(usize, 4), list.items.len);
902 try testing.expectEqual(@as(i32, 1), list.orderedRemove(0));
903 try testing.expectEqual(@as(i32, 2), list.items[0]);
904 try testing.expectEqual(@as(usize, 4), list.items.len);
905905 }
906906}
907907
......@@ -920,18 +920,18 @@ test "std.ArrayList/ArrayListUnmanaged.swapRemove" {
920920 try list.append(7);
921921
922922 //remove from middle
923 testing.expect(list.swapRemove(3) == 4);
924 testing.expect(list.items[3] == 7);
925 testing.expect(list.items.len == 6);
923 try testing.expect(list.swapRemove(3) == 4);
924 try testing.expect(list.items[3] == 7);
925 try testing.expect(list.items.len == 6);
926926
927927 //remove from end
928 testing.expect(list.swapRemove(5) == 6);
929 testing.expect(list.items.len == 5);
928 try testing.expect(list.swapRemove(5) == 6);
929 try testing.expect(list.items.len == 5);
930930
931931 //remove from front
932 testing.expect(list.swapRemove(0) == 1);
933 testing.expect(list.items[0] == 5);
934 testing.expect(list.items.len == 4);
932 try testing.expect(list.swapRemove(0) == 1);
933 try testing.expect(list.items[0] == 5);
934 try testing.expect(list.items.len == 4);
935935 }
936936 {
937937 var list = ArrayListUnmanaged(i32){};
......@@ -946,18 +946,18 @@ test "std.ArrayList/ArrayListUnmanaged.swapRemove" {
946946 try list.append(a, 7);
947947
948948 //remove from middle
949 testing.expect(list.swapRemove(3) == 4);
950 testing.expect(list.items[3] == 7);
951 testing.expect(list.items.len == 6);
949 try testing.expect(list.swapRemove(3) == 4);
950 try testing.expect(list.items[3] == 7);
951 try testing.expect(list.items.len == 6);
952952
953953 //remove from end
954 testing.expect(list.swapRemove(5) == 6);
955 testing.expect(list.items.len == 5);
954 try testing.expect(list.swapRemove(5) == 6);
955 try testing.expect(list.items.len == 5);
956956
957957 //remove from front
958 testing.expect(list.swapRemove(0) == 1);
959 testing.expect(list.items[0] == 5);
960 testing.expect(list.items.len == 4);
958 try testing.expect(list.swapRemove(0) == 1);
959 try testing.expect(list.items[0] == 5);
960 try testing.expect(list.items.len == 4);
961961 }
962962}
963963
......@@ -971,10 +971,10 @@ test "std.ArrayList/ArrayListUnmanaged.insert" {
971971 try list.append(2);
972972 try list.append(3);
973973 try list.insert(0, 5);
974 testing.expect(list.items[0] == 5);
975 testing.expect(list.items[1] == 1);
976 testing.expect(list.items[2] == 2);
977 testing.expect(list.items[3] == 3);
974 try testing.expect(list.items[0] == 5);
975 try testing.expect(list.items[1] == 1);
976 try testing.expect(list.items[2] == 2);
977 try testing.expect(list.items[3] == 3);
978978 }
979979 {
980980 var list = ArrayListUnmanaged(i32){};
......@@ -984,10 +984,10 @@ test "std.ArrayList/ArrayListUnmanaged.insert" {
984984 try list.append(a, 2);
985985 try list.append(a, 3);
986986 try list.insert(a, 0, 5);
987 testing.expect(list.items[0] == 5);
988 testing.expect(list.items[1] == 1);
989 testing.expect(list.items[2] == 2);
990 testing.expect(list.items[3] == 3);
987 try testing.expect(list.items[0] == 5);
988 try testing.expect(list.items[1] == 1);
989 try testing.expect(list.items[2] == 2);
990 try testing.expect(list.items[3] == 3);
991991 }
992992}
993993
......@@ -1002,17 +1002,17 @@ test "std.ArrayList/ArrayListUnmanaged.insertSlice" {
10021002 try list.append(3);
10031003 try list.append(4);
10041004 try list.insertSlice(1, &[_]i32{ 9, 8 });
1005 testing.expect(list.items[0] == 1);
1006 testing.expect(list.items[1] == 9);
1007 testing.expect(list.items[2] == 8);
1008 testing.expect(list.items[3] == 2);
1009 testing.expect(list.items[4] == 3);
1010 testing.expect(list.items[5] == 4);
1005 try testing.expect(list.items[0] == 1);
1006 try testing.expect(list.items[1] == 9);
1007 try testing.expect(list.items[2] == 8);
1008 try testing.expect(list.items[3] == 2);
1009 try testing.expect(list.items[4] == 3);
1010 try testing.expect(list.items[5] == 4);
10111011
10121012 const items = [_]i32{1};
10131013 try list.insertSlice(0, items[0..0]);
1014 testing.expect(list.items.len == 6);
1015 testing.expect(list.items[0] == 1);
1014 try testing.expect(list.items.len == 6);
1015 try testing.expect(list.items[0] == 1);
10161016 }
10171017 {
10181018 var list = ArrayListUnmanaged(i32){};
......@@ -1023,17 +1023,17 @@ test "std.ArrayList/ArrayListUnmanaged.insertSlice" {
10231023 try list.append(a, 3);
10241024 try list.append(a, 4);
10251025 try list.insertSlice(a, 1, &[_]i32{ 9, 8 });
1026 testing.expect(list.items[0] == 1);
1027 testing.expect(list.items[1] == 9);
1028 testing.expect(list.items[2] == 8);
1029 testing.expect(list.items[3] == 2);
1030 testing.expect(list.items[4] == 3);
1031 testing.expect(list.items[5] == 4);
1026 try testing.expect(list.items[0] == 1);
1027 try testing.expect(list.items[1] == 9);
1028 try testing.expect(list.items[2] == 8);
1029 try testing.expect(list.items[3] == 2);
1030 try testing.expect(list.items[4] == 3);
1031 try testing.expect(list.items[5] == 4);
10321032
10331033 const items = [_]i32{1};
10341034 try list.insertSlice(a, 0, items[0..0]);
1035 testing.expect(list.items.len == 6);
1036 testing.expect(list.items[0] == 1);
1035 try testing.expect(list.items.len == 6);
1036 try testing.expect(list.items[0] == 1);
10371037 }
10381038}
10391039
......@@ -1066,13 +1066,13 @@ test "std.ArrayList/ArrayListUnmanaged.replaceRange" {
10661066 try list_lt.replaceRange(1, 2, &new);
10671067
10681068 // after_range > new_items.len in function body
1069 testing.expect(1 + 4 > new.len);
1069 try testing.expect(1 + 4 > new.len);
10701070 try list_gt.replaceRange(1, 4, &new);
10711071
1072 testing.expectEqualSlices(i32, list_zero.items, &result_zero);
1073 testing.expectEqualSlices(i32, list_eq.items, &result_eq);
1074 testing.expectEqualSlices(i32, list_lt.items, &result_le);
1075 testing.expectEqualSlices(i32, list_gt.items, &result_gt);
1072 try testing.expectEqualSlices(i32, list_zero.items, &result_zero);
1073 try testing.expectEqualSlices(i32, list_eq.items, &result_eq);
1074 try testing.expectEqualSlices(i32, list_lt.items, &result_le);
1075 try testing.expectEqualSlices(i32, list_gt.items, &result_gt);
10761076 }
10771077 {
10781078 var list_zero = ArrayListUnmanaged(i32){};
......@@ -1090,13 +1090,13 @@ test "std.ArrayList/ArrayListUnmanaged.replaceRange" {
10901090 try list_lt.replaceRange(a, 1, 2, &new);
10911091
10921092 // after_range > new_items.len in function body
1093 testing.expect(1 + 4 > new.len);
1093 try testing.expect(1 + 4 > new.len);
10941094 try list_gt.replaceRange(a, 1, 4, &new);
10951095
1096 testing.expectEqualSlices(i32, list_zero.items, &result_zero);
1097 testing.expectEqualSlices(i32, list_eq.items, &result_eq);
1098 testing.expectEqualSlices(i32, list_lt.items, &result_le);
1099 testing.expectEqualSlices(i32, list_gt.items, &result_gt);
1096 try testing.expectEqualSlices(i32, list_zero.items, &result_zero);
1097 try testing.expectEqualSlices(i32, list_eq.items, &result_eq);
1098 try testing.expectEqualSlices(i32, list_lt.items, &result_le);
1099 try testing.expectEqualSlices(i32, list_gt.items, &result_gt);
11001100 }
11011101}
11021102
......@@ -1116,13 +1116,13 @@ test "std.ArrayList/ArrayListUnmanaged: ArrayList(T) of struct T" {
11161116 var root = Item{ .integer = 1, .sub_items = ArrayList(Item).init(a) };
11171117 defer root.sub_items.deinit();
11181118 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);
11201120 }
11211121 {
11221122 var root = ItemUnmanaged{ .integer = 1, .sub_items = ArrayListUnmanaged(ItemUnmanaged){} };
11231123 defer root.sub_items.deinit(a);
11241124 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);
11261126 }
11271127}
11281128
......@@ -1137,7 +1137,7 @@ test "std.ArrayList(u8)/ArrayListAligned implements writer" {
11371137 const y: i32 = 1234;
11381138 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);
11411141 }
11421142 {
11431143 var list = ArrayListAligned(u8, 2).init(a);
......@@ -1149,7 +1149,7 @@ test "std.ArrayList(u8)/ArrayListAligned implements writer" {
11491149 try writer.writeAll("d");
11501150 try writer.writeAll("efg");
11511151
1152 testing.expectEqualSlices(u8, list.items, "abcdefg");
1152 try testing.expectEqualSlices(u8, list.items, "abcdefg");
11531153 }
11541154}
11551155
......@@ -1167,7 +1167,7 @@ test "std.ArrayList/ArrayListUnmanaged.shrink still sets length on error.OutOfMe
11671167 try list.append(3);
11681168
11691169 list.shrinkAndFree(1);
1170 testing.expect(list.items.len == 1);
1170 try testing.expect(list.items.len == 1);
11711171 }
11721172 {
11731173 var list = ArrayListUnmanaged(i32){};
......@@ -1177,7 +1177,7 @@ test "std.ArrayList/ArrayListUnmanaged.shrink still sets length on error.OutOfMe
11771177 try list.append(a, 3);
11781178
11791179 list.shrinkAndFree(a, 1);
1180 testing.expect(list.items.len == 1);
1180 try testing.expect(list.items.len == 1);
11811181 }
11821182}
11831183
......@@ -1191,7 +1191,7 @@ test "std.ArrayList/ArrayListUnmanaged.addManyAsArray" {
11911191 try list.ensureCapacity(8);
11921192 list.addManyAsArrayAssumeCapacity(4).* = "asdf".*;
11931193
1194 testing.expectEqualSlices(u8, list.items, "aoeuasdf");
1194 try testing.expectEqualSlices(u8, list.items, "aoeuasdf");
11951195 }
11961196 {
11971197 var list = ArrayListUnmanaged(u8){};
......@@ -1201,7 +1201,7 @@ test "std.ArrayList/ArrayListUnmanaged.addManyAsArray" {
12011201 try list.ensureCapacity(a, 8);
12021202 list.addManyAsArrayAssumeCapacity(4).* = "asdf".*;
12031203
1204 testing.expectEqualSlices(u8, list.items, "aoeuasdf");
1204 try testing.expectEqualSlices(u8, list.items, "aoeuasdf");
12051205 }
12061206}
12071207
......@@ -1215,7 +1215,7 @@ test "std.ArrayList/ArrayListUnmanaged.toOwnedSliceSentinel" {
12151215
12161216 const result = try list.toOwnedSliceSentinel(0);
12171217 defer a.free(result);
1218 testing.expectEqualStrings(result, mem.spanZ(result.ptr));
1218 try testing.expectEqualStrings(result, mem.spanZ(result.ptr));
12191219 }
12201220 {
12211221 var list = ArrayListUnmanaged(u8){};
......@@ -1225,7 +1225,7 @@ test "std.ArrayList/ArrayListUnmanaged.toOwnedSliceSentinel" {
12251225
12261226 const result = try list.toOwnedSliceSentinel(a, 0);
12271227 defer a.free(result);
1228 testing.expectEqualStrings(result, mem.spanZ(result.ptr));
1228 try testing.expectEqualStrings(result, mem.spanZ(result.ptr));
12291229 }
12301230}
12311231
......@@ -1239,7 +1239,7 @@ test "ArrayListAligned/ArrayListAlignedUnmanaged accepts unaligned slices" {
12391239 try list.insertSlice(2, &.{ 4, 5, 6, 7 });
12401240 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 });
12431243 }
12441244 {
12451245 var list = std.ArrayListAlignedUnmanaged(u8, 8){};
......@@ -1249,6 +1249,6 @@ test "ArrayListAligned/ArrayListAlignedUnmanaged accepts unaligned slices" {
12491249 try list.insertSlice(a, 2, &.{ 4, 5, 6, 7 });
12501250 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 });
12531253 }
12541254}
lib/std/ascii.zig+23-23
......@@ -236,11 +236,11 @@ pub const spaces = [_]u8{ ' ', '\t', '\n', '\r', control_code.VT, control_code.F
236236
237237test "spaces" {
238238 const testing = std.testing;
239 for (spaces) |space| testing.expect(isSpace(space));
239 for (spaces) |space| try testing.expect(isSpace(space));
240240
241241 var i: u8 = 0;
242242 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);
244244 }
245245}
246246
......@@ -279,13 +279,13 @@ pub fn toLower(c: u8) u8 {
279279test "ascii character classes" {
280280 const testing = std.testing;
281281
282 testing.expect('C' == toUpper('c'));
283 testing.expect(':' == toUpper(':'));
284 testing.expect('\xab' == toUpper('\xab'));
285 testing.expect('c' == toLower('C'));
286 testing.expect(isAlpha('c'));
287 testing.expect(!isAlpha('5'));
288 testing.expect(isSpace(' '));
282 try testing.expect('C' == toUpper('c'));
283 try testing.expect(':' == toUpper(':'));
284 try testing.expect('\xab' == toUpper('\xab'));
285 try testing.expect('c' == toLower('C'));
286 try testing.expect(isAlpha('c'));
287 try testing.expect(!isAlpha('5'));
288 try testing.expect(isSpace(' '));
289289}
290290
291291/// Allocates a lower case copy of `ascii_string`.
......@@ -301,7 +301,7 @@ pub fn allocLowerString(allocator: *std.mem.Allocator, ascii_string: []const u8)
301301test "allocLowerString" {
302302 const result = try allocLowerString(std.testing.allocator, "aBcDeFgHiJkLmNOPqrst0234+💩!");
303303 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));
305305}
306306
307307/// Allocates an upper case copy of `ascii_string`.
......@@ -317,7 +317,7 @@ pub fn allocUpperString(allocator: *std.mem.Allocator, ascii_string: []const u8)
317317test "allocUpperString" {
318318 const result = try allocUpperString(std.testing.allocator, "aBcDeFgHiJkLmNOPqrst0234+💩!");
319319 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));
321321}
322322
323323/// 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 {
330330}
331331
332332test "eqlIgnoreCase" {
333 std.testing.expect(eqlIgnoreCase("HEl💩Lo!", "hel💩lo!"));
334 std.testing.expect(!eqlIgnoreCase("hElLo!", "hello! "));
335 std.testing.expect(!eqlIgnoreCase("hElLo!", "helro!"));
333 try std.testing.expect(eqlIgnoreCase("HEl💩Lo!", "hel💩lo!"));
334 try std.testing.expect(!eqlIgnoreCase("hElLo!", "hello! "));
335 try std.testing.expect(!eqlIgnoreCase("hElLo!", "helro!"));
336336}
337337
338338pub fn startsWithIgnoreCase(haystack: []const u8, needle: []const u8) bool {
......@@ -340,8 +340,8 @@ pub fn startsWithIgnoreCase(haystack: []const u8, needle: []const u8) bool {
340340}
341341
342342test "ascii.startsWithIgnoreCase" {
343 std.testing.expect(startsWithIgnoreCase("boB", "Bo"));
344 std.testing.expect(!startsWithIgnoreCase("Needle in hAyStAcK", "haystack"));
343 try std.testing.expect(startsWithIgnoreCase("boB", "Bo"));
344 try std.testing.expect(!startsWithIgnoreCase("Needle in hAyStAcK", "haystack"));
345345}
346346
347347pub fn endsWithIgnoreCase(haystack: []const u8, needle: []const u8) bool {
......@@ -349,8 +349,8 @@ pub fn endsWithIgnoreCase(haystack: []const u8, needle: []const u8) bool {
349349}
350350
351351test "ascii.endsWithIgnoreCase" {
352 std.testing.expect(endsWithIgnoreCase("Needle in HaYsTaCk", "haystack"));
353 std.testing.expect(!endsWithIgnoreCase("BoB", "Bo"));
352 try std.testing.expect(endsWithIgnoreCase("Needle in HaYsTaCk", "haystack"));
353 try std.testing.expect(!endsWithIgnoreCase("BoB", "Bo"));
354354}
355355
356356/// Finds `substr` in `container`, ignoring case, starting at `start_index`.
......@@ -372,12 +372,12 @@ pub fn indexOfIgnoreCase(container: []const u8, substr: []const u8) ?usize {
372372}
373373
374374test "indexOfIgnoreCase" {
375 std.testing.expect(indexOfIgnoreCase("one Two Three Four", "foUr").? == 14);
376 std.testing.expect(indexOfIgnoreCase("one two three FouR", "gOur") == null);
377 std.testing.expect(indexOfIgnoreCase("foO", "Foo").? == 0);
378 std.testing.expect(indexOfIgnoreCase("foo", "fool") == null);
375 try std.testing.expect(indexOfIgnoreCase("one Two Three Four", "foUr").? == 14);
376 try std.testing.expect(indexOfIgnoreCase("one two three FouR", "gOur") == null);
377 try std.testing.expect(indexOfIgnoreCase("foO", "Foo").? == 0);
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);
381381}
382382
383383/// Compares two slices of numbers lexicographically. O(n).
lib/std/atomic/bool.zig+4-4
......@@ -47,9 +47,9 @@ pub const Bool = extern struct {
4747
4848test "std.atomic.Bool" {
4949 var a = Bool.init(false);
50 testing.expectEqual(false, a.xchg(false, .SeqCst));
51 testing.expectEqual(false, a.load(.SeqCst));
50 try testing.expectEqual(false, a.xchg(false, .SeqCst));
51 try testing.expectEqual(false, a.load(.SeqCst));
5252 a.store(true, .SeqCst);
53 testing.expectEqual(true, a.xchg(false, .SeqCst));
54 testing.expectEqual(false, a.load(.SeqCst));
53 try testing.expectEqual(true, a.xchg(false, .SeqCst));
54 try testing.expectEqual(false, a.load(.SeqCst));
5555}
lib/std/atomic/int.zig+6-6
......@@ -81,12 +81,12 @@ pub fn Int(comptime T: type) type {
8181
8282test "std.atomic.Int" {
8383 var a = Int(u8).init(0);
84 testing.expectEqual(@as(u8, 0), a.incr());
85 testing.expectEqual(@as(u8, 1), a.load(.SeqCst));
84 try testing.expectEqual(@as(u8, 0), a.incr());
85 try testing.expectEqual(@as(u8, 1), a.load(.SeqCst));
8686 a.store(42, .SeqCst);
87 testing.expectEqual(@as(u8, 42), a.decr());
88 testing.expectEqual(@as(u8, 41), a.xchg(100));
89 testing.expectEqual(@as(u8, 100), a.fetchAdd(5));
90 testing.expectEqual(@as(u8, 105), a.get());
87 try testing.expectEqual(@as(u8, 42), a.decr());
88 try testing.expectEqual(@as(u8, 41), a.xchg(100));
89 try testing.expectEqual(@as(u8, 100), a.fetchAdd(5));
90 try testing.expectEqual(@as(u8, 105), a.get());
9191 a.set(200);
9292}
lib/std/atomic/queue.zig+28-28
......@@ -195,24 +195,24 @@ test "std.atomic.Queue" {
195195 };
196196
197197 if (builtin.single_threaded) {
198 expect(context.queue.isEmpty());
198 try expect(context.queue.isEmpty());
199199 {
200200 var i: usize = 0;
201201 while (i < put_thread_count) : (i += 1) {
202 expect(startPuts(&context) == 0);
202 try expect(startPuts(&context) == 0);
203203 }
204204 }
205 expect(!context.queue.isEmpty());
205 try expect(!context.queue.isEmpty());
206206 context.puts_done = true;
207207 {
208208 var i: usize = 0;
209209 while (i < put_thread_count) : (i += 1) {
210 expect(startGets(&context) == 0);
210 try expect(startGets(&context) == 0);
211211 }
212212 }
213 expect(context.queue.isEmpty());
213 try expect(context.queue.isEmpty());
214214 } else {
215 expect(context.queue.isEmpty());
215 try expect(context.queue.isEmpty());
216216
217217 var putters: [put_thread_count]*std.Thread = undefined;
218218 for (putters) |*t| {
......@@ -229,7 +229,7 @@ test "std.atomic.Queue" {
229229 for (getters) |t|
230230 t.wait();
231231
232 expect(context.queue.isEmpty());
232 try expect(context.queue.isEmpty());
233233 }
234234
235235 if (context.put_sum != context.get_sum) {
......@@ -279,7 +279,7 @@ fn startGets(ctx: *Context) u8 {
279279
280280test "std.atomic.Queue single-threaded" {
281281 var queue = Queue(i32).init();
282 expect(queue.isEmpty());
282 try expect(queue.isEmpty());
283283
284284 var node_0 = Queue(i32).Node{
285285 .data = 0,
......@@ -287,7 +287,7 @@ test "std.atomic.Queue single-threaded" {
287287 .prev = undefined,
288288 };
289289 queue.put(&node_0);
290 expect(!queue.isEmpty());
290 try expect(!queue.isEmpty());
291291
292292 var node_1 = Queue(i32).Node{
293293 .data = 1,
......@@ -295,10 +295,10 @@ test "std.atomic.Queue single-threaded" {
295295 .prev = undefined,
296296 };
297297 queue.put(&node_1);
298 expect(!queue.isEmpty());
298 try expect(!queue.isEmpty());
299299
300 expect(queue.get().?.data == 0);
301 expect(!queue.isEmpty());
300 try expect(queue.get().?.data == 0);
301 try expect(!queue.isEmpty());
302302
303303 var node_2 = Queue(i32).Node{
304304 .data = 2,
......@@ -306,7 +306,7 @@ test "std.atomic.Queue single-threaded" {
306306 .prev = undefined,
307307 };
308308 queue.put(&node_2);
309 expect(!queue.isEmpty());
309 try expect(!queue.isEmpty());
310310
311311 var node_3 = Queue(i32).Node{
312312 .data = 3,
......@@ -314,13 +314,13 @@ test "std.atomic.Queue single-threaded" {
314314 .prev = undefined,
315315 };
316316 queue.put(&node_3);
317 expect(!queue.isEmpty());
317 try expect(!queue.isEmpty());
318318
319 expect(queue.get().?.data == 1);
320 expect(!queue.isEmpty());
319 try expect(queue.get().?.data == 1);
320 try expect(!queue.isEmpty());
321321
322 expect(queue.get().?.data == 2);
323 expect(!queue.isEmpty());
322 try expect(queue.get().?.data == 2);
323 try expect(!queue.isEmpty());
324324
325325 var node_4 = Queue(i32).Node{
326326 .data = 4,
......@@ -328,17 +328,17 @@ test "std.atomic.Queue single-threaded" {
328328 .prev = undefined,
329329 };
330330 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);
334334 node_3.next = null;
335 expect(!queue.isEmpty());
335 try expect(!queue.isEmpty());
336336
337 expect(queue.get().?.data == 4);
338 expect(queue.isEmpty());
337 try expect(queue.get().?.data == 4);
338 try expect(queue.isEmpty());
339339
340 expect(queue.get() == null);
341 expect(queue.isEmpty());
340 try expect(queue.get() == null);
341 try expect(queue.isEmpty());
342342}
343343
344344test "std.atomic.Queue dump" {
......@@ -352,7 +352,7 @@ test "std.atomic.Queue dump" {
352352 // Test empty stream
353353 fbs.reset();
354354 try queue.dumpToStream(fbs.writer());
355 expect(mem.eql(u8, buffer[0..fbs.pos],
355 try expect(mem.eql(u8, buffer[0..fbs.pos],
356356 \\head: (null)
357357 \\tail: (null)
358358 \\
......@@ -376,7 +376,7 @@ test "std.atomic.Queue dump" {
376376 \\ (null)
377377 \\
378378 , .{ @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
381381 // Test a stream with two elements
382382 var node_1 = Queue(i32).Node{
......@@ -397,5 +397,5 @@ test "std.atomic.Queue dump" {
397397 \\ (null)
398398 \\
399399 , .{ @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));
401401}
lib/std/atomic/stack.zig+2-2
......@@ -110,14 +110,14 @@ test "std.atomic.stack" {
110110 {
111111 var i: usize = 0;
112112 while (i < put_thread_count) : (i += 1) {
113 expect(startPuts(&context) == 0);
113 try expect(startPuts(&context) == 0);
114114 }
115115 }
116116 context.puts_done = true;
117117 {
118118 var i: usize = 0;
119119 while (i < put_thread_count) : (i += 1) {
120 expect(startGets(&context) == 0);
120 try expect(startGets(&context) == 0);
121121 }
122122 }
123123 } else {
lib/std/base64.zig+9-9
......@@ -318,14 +318,14 @@ pub const Base64DecoderWithIgnore = struct {
318318
319319test "base64" {
320320 @setEvalBranchQuota(8000);
321 testBase64() catch unreachable;
322 comptime testAllApis(standard, "comptime", "Y29tcHRpbWU=") catch unreachable;
321 try testBase64();
322 comptime try testAllApis(standard, "comptime", "Y29tcHRpbWU=");
323323}
324324
325325test "base64 url_safe_no_pad" {
326326 @setEvalBranchQuota(8000);
327 testBase64UrlSafeNoPad() catch unreachable;
328 comptime testAllApis(url_safe_no_pad, "comptime", "Y29tcHRpbWU") catch unreachable;
327 try testBase64UrlSafeNoPad();
328 comptime try testAllApis(url_safe_no_pad, "comptime", "Y29tcHRpbWU");
329329}
330330
331331fn testBase64() !void {
......@@ -404,7 +404,7 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [
404404 {
405405 var buffer: [0x100]u8 = undefined;
406406 const encoded = codecs.Encoder.encode(&buffer, expected_decoded);
407 testing.expectEqualSlices(u8, expected_encoded, encoded);
407 try testing.expectEqualSlices(u8, expected_encoded, encoded);
408408 }
409409
410410 // Base64Decoder
......@@ -412,7 +412,7 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [
412412 var buffer: [0x100]u8 = undefined;
413413 var decoded = buffer[0..try codecs.Decoder.calcSizeForSlice(expected_encoded)];
414414 try codecs.Decoder.decode(decoded, expected_encoded);
415 testing.expectEqualSlices(u8, expected_decoded, decoded);
415 try testing.expectEqualSlices(u8, expected_decoded, decoded);
416416 }
417417
418418 // Base64DecoderWithIgnore
......@@ -421,8 +421,8 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [
421421 var buffer: [0x100]u8 = undefined;
422422 var decoded = buffer[0..try decoder_ignore_nothing.calcSizeUpperBound(expected_encoded.len)];
423423 var written = try decoder_ignore_nothing.decode(decoded, expected_encoded);
424 testing.expect(written <= decoded.len);
425 testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]);
424 try testing.expect(written <= decoded.len);
425 try testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]);
426426 }
427427}
428428
......@@ -431,7 +431,7 @@ fn testDecodeIgnoreSpace(codecs: Codecs, expected_decoded: []const u8, encoded:
431431 var buffer: [0x100]u8 = undefined;
432432 var decoded = buffer[0..try decoder_ignore_space.calcSizeUpperBound(encoded.len)];
433433 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]);
435435}
436436
437437fn 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
998998
999999const testing = std.testing;
10001000
1001fn testBitSet(a: anytype, b: anytype, len: usize) void {
1002 testing.expectEqual(len, a.capacity());
1003 testing.expectEqual(len, b.capacity());
1001fn testBitSet(a: anytype, b: anytype, len: usize) !void {
1002 try testing.expectEqual(len, a.capacity());
1003 try testing.expectEqual(len, b.capacity());
10041004
10051005 {
10061006 var i: usize = 0;
......@@ -1010,50 +1010,50 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void {
10101010 }
10111011 }
10121012
1013 testing.expectEqual((len + 1) / 2, a.count());
1014 testing.expectEqual((len + 3) / 4 + (len + 2) / 4, b.count());
1013 try testing.expectEqual((len + 1) / 2, a.count());
1014 try testing.expectEqual((len + 3) / 4 + (len + 2) / 4, b.count());
10151015
10161016 {
10171017 var iter = a.iterator(.{});
10181018 var i: usize = 0;
10191019 while (i < len) : (i += 2) {
1020 testing.expectEqual(@as(?usize, i), iter.next());
1020 try testing.expectEqual(@as(?usize, i), iter.next());
10211021 }
1022 testing.expectEqual(@as(?usize, null), iter.next());
1023 testing.expectEqual(@as(?usize, null), iter.next());
1024 testing.expectEqual(@as(?usize, null), iter.next());
1022 try testing.expectEqual(@as(?usize, null), iter.next());
1023 try testing.expectEqual(@as(?usize, null), iter.next());
1024 try testing.expectEqual(@as(?usize, null), iter.next());
10251025 }
10261026 a.toggleAll();
10271027 {
10281028 var iter = a.iterator(.{});
10291029 var i: usize = 1;
10301030 while (i < len) : (i += 2) {
1031 testing.expectEqual(@as(?usize, i), iter.next());
1031 try testing.expectEqual(@as(?usize, i), iter.next());
10321032 }
1033 testing.expectEqual(@as(?usize, null), iter.next());
1034 testing.expectEqual(@as(?usize, null), iter.next());
1035 testing.expectEqual(@as(?usize, null), iter.next());
1033 try testing.expectEqual(@as(?usize, null), iter.next());
1034 try testing.expectEqual(@as(?usize, null), iter.next());
1035 try testing.expectEqual(@as(?usize, null), iter.next());
10361036 }
10371037
10381038 {
10391039 var iter = b.iterator(.{ .kind = .unset });
10401040 var i: usize = 2;
10411041 while (i < len) : (i += 4) {
1042 testing.expectEqual(@as(?usize, i), iter.next());
1042 try testing.expectEqual(@as(?usize, i), iter.next());
10431043 if (i + 1 < len) {
1044 testing.expectEqual(@as(?usize, i + 1), iter.next());
1044 try testing.expectEqual(@as(?usize, i + 1), iter.next());
10451045 }
10461046 }
1047 testing.expectEqual(@as(?usize, null), iter.next());
1048 testing.expectEqual(@as(?usize, null), iter.next());
1049 testing.expectEqual(@as(?usize, null), iter.next());
1047 try testing.expectEqual(@as(?usize, null), iter.next());
1048 try testing.expectEqual(@as(?usize, null), iter.next());
1049 try testing.expectEqual(@as(?usize, null), iter.next());
10501050 }
10511051
10521052 {
10531053 var i: usize = 0;
10541054 while (i < len) : (i += 1) {
1055 testing.expectEqual(i & 1 != 0, a.isSet(i));
1056 testing.expectEqual(i & 2 == 0, b.isSet(i));
1055 try testing.expectEqual(i & 1 != 0, a.isSet(i));
1056 try testing.expectEqual(i & 2 == 0, b.isSet(i));
10571057 }
10581058 }
10591059
......@@ -1061,8 +1061,8 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void {
10611061 {
10621062 var i: usize = 0;
10631063 while (i < len) : (i += 1) {
1064 testing.expectEqual(i & 1 != 0 or i & 2 == 0, a.isSet(i));
1065 testing.expectEqual(i & 2 == 0, b.isSet(i));
1064 try testing.expectEqual(i & 1 != 0 or i & 2 == 0, a.isSet(i));
1065 try testing.expectEqual(i & 2 == 0, b.isSet(i));
10661066 }
10671067
10681068 i = len;
......@@ -1071,27 +1071,27 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void {
10711071 while (i > 0) {
10721072 i -= 1;
10731073 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());
10751075 } else {
1076 testing.expectEqual(@as(?usize, i), unset.next());
1076 try testing.expectEqual(@as(?usize, i), unset.next());
10771077 }
10781078 }
1079 testing.expectEqual(@as(?usize, null), set.next());
1080 testing.expectEqual(@as(?usize, null), set.next());
1081 testing.expectEqual(@as(?usize, null), set.next());
1082 testing.expectEqual(@as(?usize, null), unset.next());
1083 testing.expectEqual(@as(?usize, null), unset.next());
1084 testing.expectEqual(@as(?usize, null), unset.next());
1079 try testing.expectEqual(@as(?usize, null), set.next());
1080 try testing.expectEqual(@as(?usize, null), set.next());
1081 try testing.expectEqual(@as(?usize, null), set.next());
1082 try testing.expectEqual(@as(?usize, null), unset.next());
1083 try testing.expectEqual(@as(?usize, null), unset.next());
1084 try testing.expectEqual(@as(?usize, null), unset.next());
10851085 }
10861086
10871087 a.toggleSet(b.*);
10881088 {
1089 testing.expectEqual(len / 4, a.count());
1089 try testing.expectEqual(len / 4, a.count());
10901090
10911091 var i: usize = 0;
10921092 while (i < len) : (i += 1) {
1093 testing.expectEqual(i & 1 != 0 and i & 2 != 0, a.isSet(i));
1094 testing.expectEqual(i & 2 == 0, b.isSet(i));
1093 try testing.expectEqual(i & 1 != 0 and i & 2 != 0, a.isSet(i));
1094 try testing.expectEqual(i & 2 == 0, b.isSet(i));
10951095 if (i & 1 == 0) {
10961096 a.set(i);
10971097 } else {
......@@ -1102,29 +1102,29 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void {
11021102
11031103 a.setIntersection(b.*);
11041104 {
1105 testing.expectEqual((len + 3) / 4, a.count());
1105 try testing.expectEqual((len + 3) / 4, a.count());
11061106
11071107 var i: usize = 0;
11081108 while (i < len) : (i += 1) {
1109 testing.expectEqual(i & 1 == 0 and i & 2 == 0, a.isSet(i));
1110 testing.expectEqual(i & 2 == 0, b.isSet(i));
1109 try testing.expectEqual(i & 1 == 0 and i & 2 == 0, a.isSet(i));
1110 try testing.expectEqual(i & 2 == 0, b.isSet(i));
11111111 }
11121112 }
11131113
11141114 a.toggleSet(a.*);
11151115 {
11161116 var iter = a.iterator(.{});
1117 testing.expectEqual(@as(?usize, null), iter.next());
1118 testing.expectEqual(@as(?usize, null), iter.next());
1119 testing.expectEqual(@as(?usize, null), iter.next());
1120 testing.expectEqual(@as(usize, 0), a.count());
1117 try testing.expectEqual(@as(?usize, null), iter.next());
1118 try testing.expectEqual(@as(?usize, null), iter.next());
1119 try testing.expectEqual(@as(?usize, null), iter.next());
1120 try testing.expectEqual(@as(usize, 0), a.count());
11211121 }
11221122 {
11231123 var iter = a.iterator(.{ .direction = .reverse });
1124 testing.expectEqual(@as(?usize, null), iter.next());
1125 testing.expectEqual(@as(?usize, null), iter.next());
1126 testing.expectEqual(@as(?usize, null), iter.next());
1127 testing.expectEqual(@as(usize, 0), a.count());
1124 try testing.expectEqual(@as(?usize, null), iter.next());
1125 try testing.expectEqual(@as(?usize, null), iter.next());
1126 try testing.expectEqual(@as(?usize, null), iter.next());
1127 try testing.expectEqual(@as(usize, 0), a.count());
11281128 }
11291129
11301130 const test_bits = [_]usize{
......@@ -1139,51 +1139,51 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void {
11391139
11401140 for (test_bits) |i| {
11411141 if (i < a.capacity()) {
1142 testing.expectEqual(@as(?usize, i), a.findFirstSet());
1143 testing.expectEqual(@as(?usize, i), a.toggleFirstSet());
1142 try testing.expectEqual(@as(?usize, i), a.findFirstSet());
1143 try testing.expectEqual(@as(?usize, i), a.toggleFirstSet());
11441144 }
11451145 }
1146 testing.expectEqual(@as(?usize, null), a.findFirstSet());
1147 testing.expectEqual(@as(?usize, null), a.toggleFirstSet());
1148 testing.expectEqual(@as(?usize, null), a.findFirstSet());
1149 testing.expectEqual(@as(?usize, null), a.toggleFirstSet());
1150 testing.expectEqual(@as(usize, 0), a.count());
1146 try testing.expectEqual(@as(?usize, null), a.findFirstSet());
1147 try testing.expectEqual(@as(?usize, null), a.toggleFirstSet());
1148 try testing.expectEqual(@as(?usize, null), a.findFirstSet());
1149 try testing.expectEqual(@as(?usize, null), a.toggleFirstSet());
1150 try testing.expectEqual(@as(usize, 0), a.count());
11511151}
11521152
1153fn testStaticBitSet(comptime Set: type) void {
1153fn testStaticBitSet(comptime Set: type) !void {
11541154 var a = Set.initEmpty();
11551155 var b = Set.initFull();
1156 testing.expectEqual(@as(usize, 0), a.count());
1157 testing.expectEqual(@as(usize, Set.bit_length), b.count());
1156 try testing.expectEqual(@as(usize, 0), a.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);
11601160}
11611161
11621162test "IntegerBitSet" {
1163 testStaticBitSet(IntegerBitSet(0));
1164 testStaticBitSet(IntegerBitSet(1));
1165 testStaticBitSet(IntegerBitSet(2));
1166 testStaticBitSet(IntegerBitSet(5));
1167 testStaticBitSet(IntegerBitSet(8));
1168 testStaticBitSet(IntegerBitSet(32));
1169 testStaticBitSet(IntegerBitSet(64));
1170 testStaticBitSet(IntegerBitSet(127));
1163 try testStaticBitSet(IntegerBitSet(0));
1164 try testStaticBitSet(IntegerBitSet(1));
1165 try testStaticBitSet(IntegerBitSet(2));
1166 try testStaticBitSet(IntegerBitSet(5));
1167 try testStaticBitSet(IntegerBitSet(8));
1168 try testStaticBitSet(IntegerBitSet(32));
1169 try testStaticBitSet(IntegerBitSet(64));
1170 try testStaticBitSet(IntegerBitSet(127));
11711171}
11721172
11731173test "ArrayBitSet" {
11741174 inline for (.{ 0, 1, 2, 31, 32, 33, 63, 64, 65, 254, 500, 3000 }) |size| {
1175 testStaticBitSet(ArrayBitSet(u8, size));
1176 testStaticBitSet(ArrayBitSet(u16, size));
1177 testStaticBitSet(ArrayBitSet(u32, size));
1178 testStaticBitSet(ArrayBitSet(u64, size));
1179 testStaticBitSet(ArrayBitSet(u128, size));
1175 try testStaticBitSet(ArrayBitSet(u8, size));
1176 try testStaticBitSet(ArrayBitSet(u16, size));
1177 try testStaticBitSet(ArrayBitSet(u32, size));
1178 try testStaticBitSet(ArrayBitSet(u64, size));
1179 try testStaticBitSet(ArrayBitSet(u128, size));
11801180 }
11811181}
11821182
11831183test "DynamicBitSetUnmanaged" {
11841184 const allocator = std.testing.allocator;
11851185 var a = try DynamicBitSetUnmanaged.initEmpty(300, allocator);
1186 testing.expectEqual(@as(usize, 0), a.count());
1186 try testing.expectEqual(@as(usize, 0), a.count());
11871187 a.deinit(allocator);
11881188
11891189 a = try DynamicBitSetUnmanaged.initEmpty(0, allocator);
......@@ -1193,10 +1193,10 @@ test "DynamicBitSetUnmanaged" {
11931193
11941194 var tmp = try a.clone(allocator);
11951195 defer tmp.deinit(allocator);
1196 testing.expectEqual(old_len, tmp.capacity());
1196 try testing.expectEqual(old_len, tmp.capacity());
11971197 var i: usize = 0;
11981198 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));
12001200 }
12011201
12021202 a.toggleSet(a); // zero a
......@@ -1206,24 +1206,24 @@ test "DynamicBitSetUnmanaged" {
12061206 try tmp.resize(size, false, allocator);
12071207
12081208 if (size > old_len) {
1209 testing.expectEqual(size - old_len, a.count());
1209 try testing.expectEqual(size - old_len, a.count());
12101210 } else {
1211 testing.expectEqual(@as(usize, 0), a.count());
1211 try testing.expectEqual(@as(usize, 0), a.count());
12121212 }
1213 testing.expectEqual(@as(usize, 0), tmp.count());
1213 try testing.expectEqual(@as(usize, 0), tmp.count());
12141214
12151215 var b = try DynamicBitSetUnmanaged.initFull(size, allocator);
12161216 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);
12201220 }
12211221}
12221222
12231223test "DynamicBitSet" {
12241224 const allocator = std.testing.allocator;
12251225 var a = try DynamicBitSet.initEmpty(300, allocator);
1226 testing.expectEqual(@as(usize, 0), a.count());
1226 try testing.expectEqual(@as(usize, 0), a.count());
12271227 a.deinit();
12281228
12291229 a = try DynamicBitSet.initEmpty(0, allocator);
......@@ -1233,10 +1233,10 @@ test "DynamicBitSet" {
12331233
12341234 var tmp = try a.clone(allocator);
12351235 defer tmp.deinit();
1236 testing.expectEqual(old_len, tmp.capacity());
1236 try testing.expectEqual(old_len, tmp.capacity());
12371237 var i: usize = 0;
12381238 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));
12401240 }
12411241
12421242 a.toggleSet(a); // zero a
......@@ -1246,24 +1246,24 @@ test "DynamicBitSet" {
12461246 try tmp.resize(size, false);
12471247
12481248 if (size > old_len) {
1249 testing.expectEqual(size - old_len, a.count());
1249 try testing.expectEqual(size - old_len, a.count());
12501250 } else {
1251 testing.expectEqual(@as(usize, 0), a.count());
1251 try testing.expectEqual(@as(usize, 0), a.count());
12521252 }
1253 testing.expectEqual(@as(usize, 0), tmp.count());
1253 try testing.expectEqual(@as(usize, 0), tmp.count());
12541254
12551255 var b = try DynamicBitSet.initFull(size, allocator);
12561256 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);
12601260 }
12611261}
12621262
12631263test "StaticBitSet" {
1264 testing.expectEqual(IntegerBitSet(0), StaticBitSet(0));
1265 testing.expectEqual(IntegerBitSet(5), StaticBitSet(5));
1266 testing.expectEqual(IntegerBitSet(@bitSizeOf(usize)), StaticBitSet(@bitSizeOf(usize)));
1267 testing.expectEqual(ArrayBitSet(usize, @bitSizeOf(usize) + 1), StaticBitSet(@bitSizeOf(usize) + 1));
1268 testing.expectEqual(ArrayBitSet(usize, 500), StaticBitSet(500));
1264 try testing.expectEqual(IntegerBitSet(0), StaticBitSet(0));
1265 try testing.expectEqual(IntegerBitSet(5), StaticBitSet(5));
1266 try testing.expectEqual(IntegerBitSet(@bitSizeOf(usize)), StaticBitSet(@bitSizeOf(usize)));
1267 try testing.expectEqual(ArrayBitSet(usize, @bitSizeOf(usize) + 1), StaticBitSet(@bitSizeOf(usize) + 1));
1268 try testing.expectEqual(ArrayBitSet(usize, 500), StaticBitSet(500));
12691269}
lib/std/buf_map.zig+7-7
......@@ -94,19 +94,19 @@ test "BufMap" {
9494 defer bufmap.deinit();
9595
9696 try bufmap.set("x", "1");
97 testing.expect(mem.eql(u8, bufmap.get("x").?, "1"));
98 testing.expect(1 == bufmap.count());
97 try testing.expect(mem.eql(u8, bufmap.get("x").?, "1"));
98 try testing.expect(1 == bufmap.count());
9999
100100 try bufmap.set("x", "2");
101 testing.expect(mem.eql(u8, bufmap.get("x").?, "2"));
102 testing.expect(1 == bufmap.count());
101 try testing.expect(mem.eql(u8, bufmap.get("x").?, "2"));
102 try testing.expect(1 == bufmap.count());
103103
104104 try bufmap.set("x", "3");
105 testing.expect(mem.eql(u8, bufmap.get("x").?, "3"));
106 testing.expect(1 == bufmap.count());
105 try testing.expect(mem.eql(u8, bufmap.get("x").?, "3"));
106 try testing.expect(1 == bufmap.count());
107107
108108 bufmap.delete("x");
109 testing.expect(0 == bufmap.count());
109 try testing.expect(0 == bufmap.count());
110110
111111 try bufmap.setMove(try allocator.dupe(u8, "k"), try allocator.dupe(u8, "v1"));
112112 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" {
7373 defer bufset.deinit();
7474
7575 try bufset.put("x");
76 testing.expect(bufset.count() == 1);
76 try testing.expect(bufset.count() == 1);
7777 bufset.delete("x");
78 testing.expect(bufset.count() == 0);
78 try testing.expect(bufset.count() == 0);
7979
8080 try bufset.put("x");
8181 try bufset.put("y");
lib/std/build.zig+11-11
......@@ -3060,19 +3060,19 @@ test "Builder.dupePkg()" {
30603060 const dupe_deps = dupe.dependencies.?;
30613061
30623062 // 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
30653065 // probably the same dependencies
3066 std.testing.expectEqual(original_deps.len, dupe_deps.len);
3067 std.testing.expectEqual(original_deps[0].name, pkg_dep.name);
3066 try std.testing.expectEqual(original_deps.len, dupe_deps.len);
3067 try std.testing.expectEqual(original_deps[0].name, pkg_dep.name);
30683068
30693069 // could segfault otherwise if pointers in duplicated package's fields are
30703070 // the same as those in stack allocated package's fields
3071 std.testing.expect(dupe_deps.ptr != original_deps.ptr);
3072 std.testing.expect(dupe.name.ptr != pkg_top.name.ptr);
3073 std.testing.expect(dupe.path.ptr != pkg_top.path.ptr);
3074 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);
3071 try std.testing.expect(dupe_deps.ptr != original_deps.ptr);
3072 try std.testing.expect(dupe.name.ptr != pkg_top.name.ptr);
3073 try std.testing.expect(dupe.path.ptr != pkg_top.path.ptr);
3074 try std.testing.expect(dupe_deps[0].name.ptr != pkg_dep.name.ptr);
3075 try std.testing.expect(dupe_deps[0].path.ptr != pkg_dep.path.ptr);
30763076}
30773077
30783078test "LibExeObjStep.addBuildOption" {
......@@ -3096,7 +3096,7 @@ test "LibExeObjStep.addBuildOption" {
30963096 exe.addBuildOption(?[]const u8, "optional_string", null);
30973097 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(
31003100 \\pub const option1: usize = 1;
31013101 \\pub const option2: ?usize = null;
31023102 \\pub const string: []const u8 = "zigisthebest";
......@@ -3140,10 +3140,10 @@ test "LibExeObjStep.addPackage" {
31403140 var exe = builder.addExecutable("not_an_executable", "/not/an/executable.zig");
31413141 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
31453145 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);
31473147}
31483148
31493149test {
lib/std/builtin.zig+1-1
......@@ -546,7 +546,7 @@ pub fn testVersionParse() !void {
546546 const f = struct {
547547 fn eql(text: []const u8, v1: u32, v2: u32, v3: u32) !void {
548548 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);
550550 }
551551
552552 fn err(text: []const u8, expected_err: anyerror) !void {
lib/std/c/tokenizer.zig+8-8
......@@ -1310,7 +1310,7 @@ pub const Tokenizer = struct {
13101310};
13111311
13121312test "operators" {
1313 expectTokens(
1313 try expectTokens(
13141314 \\ ! != | || |= = ==
13151315 \\ ( ) { } [ ] . .. ...
13161316 \\ ^ ^= + ++ += - -- -=
......@@ -1379,7 +1379,7 @@ test "operators" {
13791379}
13801380
13811381test "keywords" {
1382 expectTokens(
1382 try expectTokens(
13831383 \\auto break case char const continue default do
13841384 \\double else enum extern float for goto if int
13851385 \\long register return short signed sizeof static
......@@ -1442,7 +1442,7 @@ test "keywords" {
14421442}
14431443
14441444test "preprocessor keywords" {
1445 expectTokens(
1445 try expectTokens(
14461446 \\#include <test>
14471447 \\#define #include <1
14481448 \\#ifdef
......@@ -1478,7 +1478,7 @@ test "preprocessor keywords" {
14781478}
14791479
14801480test "line continuation" {
1481 expectTokens(
1481 try expectTokens(
14821482 \\#define foo \
14831483 \\ bar
14841484 \\"foo\
......@@ -1509,7 +1509,7 @@ test "line continuation" {
15091509}
15101510
15111511test "string prefix" {
1512 expectTokens(
1512 try expectTokens(
15131513 \\"foo"
15141514 \\u"foo"
15151515 \\u8"foo"
......@@ -1543,7 +1543,7 @@ test "string prefix" {
15431543}
15441544
15451545test "num suffixes" {
1546 expectTokens(
1546 try expectTokens(
15471547 \\ 1.0f 1.0L 1.0 .0 1.
15481548 \\ 0l 0lu 0ll 0llu 0
15491549 \\ 1u 1ul 1ull 1
......@@ -1573,7 +1573,7 @@ test "num suffixes" {
15731573 });
15741574}
15751575
1576fn expectTokens(source: []const u8, expected_tokens: []const Token.Id) void {
1576fn expectTokens(source: []const u8, expected_tokens: []const Token.Id) !void {
15771577 var tokenizer = Tokenizer{
15781578 .buffer = source,
15791579 };
......@@ -1584,5 +1584,5 @@ fn expectTokens(source: []const u8, expected_tokens: []const Token.Id) void {
15841584 }
15851585 }
15861586 const last_token = tokenizer.next();
1587 std.testing.expect(last_token.id == .Eof);
1587 try std.testing.expect(last_token.id == .Eof);
15881588}
lib/std/child_process.zig+2-2
......@@ -1005,7 +1005,7 @@ test "createNullDelimitedEnvMap" {
10051005 defer arena.deinit();
10061006 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
10101010 inline for (.{
10111011 "HOME=/home/ifreund",
......@@ -1017,7 +1017,7 @@ test "createNullDelimitedEnvMap" {
10171017 for (environ) |variable| {
10181018 if (mem.eql(u8, mem.span(variable orelse continue), target)) break;
10191019 } else {
1020 testing.expect(false); // Environment variable not found
1020 try testing.expect(false); // Environment variable not found
10211021 }
10221022 }
10231023}
lib/std/compress/deflate.zig+1-1
......@@ -669,5 +669,5 @@ test "lengths overflow" {
669669 var inflate = inflateStream(reader, &window);
670670
671671 var buf: [1]u8 = undefined;
672 std.testing.expectError(error.InvalidLength, inflate.read(&buf));
672 try std.testing.expectError(error.InvalidLength, inflate.read(&buf));
673673}
lib/std/compress/gzip.zig+9-9
......@@ -172,17 +172,17 @@ fn testReader(data: []const u8, comptime expected: []const u8) !void {
172172 var hash: [32]u8 = undefined;
173173 std.crypto.hash.sha2.Sha256.hash(buf, hash[0..], .{});
174174
175 assertEqual(expected, &hash);
175 try assertEqual(expected, &hash);
176176}
177177
178178// 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 {
180180 var expected_bytes: [expected.len / 2]u8 = undefined;
181181 for (expected_bytes) |*r, i| {
182182 r.* = std.fmt.parseInt(u8, expected[2 * i .. 2 * i + 2], 16) catch unreachable;
183183 }
184184
185 testing.expectEqualSlices(u8, &expected_bytes, input);
185 try testing.expectEqualSlices(u8, &expected_bytes, input);
186186}
187187
188188// All the test cases are obtained by compressing the RFC1952 text
......@@ -198,12 +198,12 @@ test "compressed data" {
198198
199199test "sanity checks" {
200200 // Truncated header
201 testing.expectError(
201 try testing.expectError(
202202 error.EndOfStream,
203203 testReader(&[_]u8{ 0x1f, 0x8B }, ""),
204204 );
205205 // Wrong CM
206 testing.expectError(
206 try testing.expectError(
207207 error.InvalidCompression,
208208 testReader(&[_]u8{
209209 0x1f, 0x8b, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00,
......@@ -211,7 +211,7 @@ test "sanity checks" {
211211 }, ""),
212212 );
213213 // Wrong checksum
214 testing.expectError(
214 try testing.expectError(
215215 error.WrongChecksum,
216216 testReader(&[_]u8{
217217 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
......@@ -220,7 +220,7 @@ test "sanity checks" {
220220 }, ""),
221221 );
222222 // Truncated checksum
223 testing.expectError(
223 try testing.expectError(
224224 error.EndOfStream,
225225 testReader(&[_]u8{
226226 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
......@@ -228,7 +228,7 @@ test "sanity checks" {
228228 }, ""),
229229 );
230230 // Wrong initial size
231 testing.expectError(
231 try testing.expectError(
232232 error.CorruptedData,
233233 testReader(&[_]u8{
234234 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
......@@ -237,7 +237,7 @@ test "sanity checks" {
237237 }, ""),
238238 );
239239 // Truncated initial size field
240 testing.expectError(
240 try testing.expectError(
241241 error.EndOfStream,
242242 testReader(&[_]u8{
243243 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 {
109109 var hash: [32]u8 = undefined;
110110 std.crypto.hash.sha2.Sha256.hash(buf, hash[0..], .{});
111111
112 assertEqual(expected, &hash);
112 try assertEqual(expected, &hash);
113113}
114114
115115// 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 {
117117 var expected_bytes: [expected.len / 2]u8 = undefined;
118118 for (expected_bytes) |*r, i| {
119119 r.* = std.fmt.parseInt(u8, expected[2 * i .. 2 * i + 2], 16) catch unreachable;
120120 }
121121
122 testing.expectEqualSlices(u8, &expected_bytes, input);
122 try testing.expectEqualSlices(u8, &expected_bytes, input);
123123}
124124
125125// All the test cases are obtained by compressing the RFC1950 text
......@@ -159,32 +159,32 @@ test "don't read past deflate stream's end" {
159159
160160test "sanity checks" {
161161 // Truncated header
162 testing.expectError(
162 try testing.expectError(
163163 error.EndOfStream,
164164 testReader(&[_]u8{0x78}, ""),
165165 );
166166 // Failed FCHECK check
167 testing.expectError(
167 try testing.expectError(
168168 error.BadHeader,
169169 testReader(&[_]u8{ 0x78, 0x9D }, ""),
170170 );
171171 // Wrong CM
172 testing.expectError(
172 try testing.expectError(
173173 error.InvalidCompression,
174174 testReader(&[_]u8{ 0x79, 0x94 }, ""),
175175 );
176176 // Wrong CINFO
177 testing.expectError(
177 try testing.expectError(
178178 error.InvalidWindowSize,
179179 testReader(&[_]u8{ 0x88, 0x98 }, ""),
180180 );
181181 // Wrong checksum
182 testing.expectError(
182 try testing.expectError(
183183 error.WrongChecksum,
184184 testReader(&[_]u8{ 0x78, 0xda, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00 }, ""),
185185 );
186186 // Truncated checksum
187 testing.expectError(
187 try testing.expectError(
188188 error.EndOfStream,
189189 testReader(&[_]u8{ 0x78, 0xda, 0x03, 0x00, 0x00 }, ""),
190190 );
lib/std/comptime_string_map.zig+21-21
......@@ -95,7 +95,7 @@ test "ComptimeStringMap list literal of list literals" {
9595 .{ "samelen", .E },
9696 });
9797
98 testMap(map);
98 try testMap(map);
9999}
100100
101101test "ComptimeStringMap array of structs" {
......@@ -111,7 +111,7 @@ test "ComptimeStringMap array of structs" {
111111 .{ .@"0" = "samelen", .@"1" = .E },
112112 });
113113
114 testMap(map);
114 try testMap(map);
115115}
116116
117117test "ComptimeStringMap slice of structs" {
......@@ -128,18 +128,18 @@ test "ComptimeStringMap slice of structs" {
128128 };
129129 const map = ComptimeStringMap(TestEnum, slice);
130130
131 testMap(map);
131 try testMap(map);
132132}
133133
134fn testMap(comptime map: anytype) void {
135 std.testing.expectEqual(TestEnum.A, map.get("have").?);
136 std.testing.expectEqual(TestEnum.B, map.get("nothing").?);
137 std.testing.expect(null == map.get("missing"));
138 std.testing.expectEqual(TestEnum.D, map.get("these").?);
139 std.testing.expectEqual(TestEnum.E, map.get("samelen").?);
134fn testMap(comptime map: anytype) !void {
135 try std.testing.expectEqual(TestEnum.A, map.get("have").?);
136 try std.testing.expectEqual(TestEnum.B, map.get("nothing").?);
137 try std.testing.expect(null == map.get("missing"));
138 try std.testing.expectEqual(TestEnum.D, map.get("these").?);
139 try std.testing.expectEqual(TestEnum.E, map.get("samelen").?);
140140
141 std.testing.expect(!map.has("missing"));
142 std.testing.expect(map.has("these"));
141 try std.testing.expect(!map.has("missing"));
142 try std.testing.expect(map.has("these"));
143143}
144144
145145test "ComptimeStringMap void value type, slice of structs" {
......@@ -155,7 +155,7 @@ test "ComptimeStringMap void value type, slice of structs" {
155155 };
156156 const map = ComptimeStringMap(void, slice);
157157
158 testSet(map);
158 try testSet(map);
159159}
160160
161161test "ComptimeStringMap void value type, list literal of list literals" {
......@@ -167,16 +167,16 @@ test "ComptimeStringMap void value type, list literal of list literals" {
167167 .{"samelen"},
168168 });
169169
170 testSet(map);
170 try testSet(map);
171171}
172172
173fn testSet(comptime map: anytype) void {
174 std.testing.expectEqual({}, map.get("have").?);
175 std.testing.expectEqual({}, map.get("nothing").?);
176 std.testing.expect(null == map.get("missing"));
177 std.testing.expectEqual({}, map.get("these").?);
178 std.testing.expectEqual({}, map.get("samelen").?);
173fn testSet(comptime map: anytype) !void {
174 try std.testing.expectEqual({}, map.get("have").?);
175 try std.testing.expectEqual({}, map.get("nothing").?);
176 try std.testing.expect(null == map.get("missing"));
177 try std.testing.expectEqual({}, map.get("these").?);
178 try std.testing.expectEqual({}, map.get("samelen").?);
179179
180 std.testing.expect(!map.has("missing"));
181 std.testing.expect(map.has("these"));
180 try std.testing.expect(!map.has("missing"));
181 try std.testing.expect(map.has("these"));
182182}
lib/std/crypto.zig+2-2
......@@ -188,7 +188,7 @@ test "CSPRNG" {
188188 const a = random.int(u64);
189189 const b = random.int(u64);
190190 const c = random.int(u64);
191 std.testing.expect(a ^ b ^ c != 0);
191 try std.testing.expect(a ^ b ^ c != 0);
192192}
193193
194194test "issue #4532: no index out of bounds" {
......@@ -226,6 +226,6 @@ test "issue #4532: no index out of bounds" {
226226 h.update(block[1..]);
227227 h.final(&out2);
228228
229 std.testing.expectEqual(out1, out2);
229 try std.testing.expectEqual(out1, out2);
230230 }
231231}
lib/std/crypto/25519/curve25519.zig+6-6
......@@ -120,13 +120,13 @@ test "curve25519" {
120120 const p = try Curve25519.basePoint.clampedMul(s);
121121 try p.rejectIdentity();
122122 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");
124124 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
127127 try Curve25519.rejectNonCanonical(s);
128128 s[31] |= 0x80;
129 std.testing.expectError(error.NonCanonical, Curve25519.rejectNonCanonical(s));
129 try std.testing.expectError(error.NonCanonical, Curve25519.rejectNonCanonical(s));
130130}
131131
132132test "curve25519 small order check" {
......@@ -155,13 +155,13 @@ test "curve25519 small order check" {
155155 },
156156 };
157157 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));
159159 var extra = small_order_s;
160160 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));
162162 var valid = small_order_s;
163163 valid[31] = 0x40;
164164 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));
166166 }
167167}
lib/std/crypto/25519/ed25519.zig+6-6
......@@ -219,8 +219,8 @@ test "ed25519 key pair creation" {
219219 _ = try fmt.hexToBytes(seed[0..], "8052030376d47112be7f73ed7a019293dd12ad910b654455798b4667d73de166");
220220 const key_pair = try Ed25519.KeyPair.create(seed);
221221 var buf: [256]u8 = undefined;
222 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");
222 try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&key_pair.secret_key)}), "8052030376D47112BE7F73ED7A019293DD12AD910B654455798B4667D73DE1662D6F7455D97B4A3A10D7293909D1A4F2058CB9A370E43FA8154BB280DB839083");
223 try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&key_pair.public_key)}), "2D6F7455D97B4A3A10D7293909D1A4F2058CB9A370E43FA8154BB280DB839083");
224224}
225225
226226test "ed25519 signature" {
......@@ -230,9 +230,9 @@ test "ed25519 signature" {
230230
231231 const sig = try Ed25519.sign("test", key_pair, null);
232232 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");
234234 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));
236236}
237237
238238test "ed25519 batch verification" {
......@@ -260,7 +260,7 @@ test "ed25519 batch verification" {
260260 try Ed25519.verifyBatch(2, signature_batch);
261261
262262 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));
264264 }
265265}
266266
......@@ -354,7 +354,7 @@ test "ed25519 test vectors" {
354354 var sig: [64]u8 = undefined;
355355 _ = try fmt.hexToBytes(&sig, entry.sig_hex);
356356 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));
358358 } else {
359359 try Ed25519.verify(sig, &msg, public_key);
360360 }
lib/std/crypto/25519/edwards25519.zig+9-9
......@@ -491,7 +491,7 @@ test "edwards25519 packing/unpacking" {
491491 var b = Edwards25519.basePoint;
492492 const pk = try b.mul(s);
493493 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
496496 const small_order_ss: [7][32]u8 = .{
497497 .{
......@@ -518,7 +518,7 @@ test "edwards25519 packing/unpacking" {
518518 };
519519 for (small_order_ss) |small_order_s| {
520520 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));
522522 }
523523}
524524
......@@ -531,26 +531,26 @@ test "edwards25519 point addition/substraction" {
531531 const q = try Edwards25519.basePoint.clampedMul(s2);
532532 const r = p.add(q).add(q).sub(q).sub(q);
533533 try r.rejectIdentity();
534 std.testing.expectError(error.IdentityElement, r.sub(p).rejectIdentity());
535 std.testing.expectError(error.IdentityElement, p.sub(p).rejectIdentity());
536 std.testing.expectError(error.IdentityElement, p.sub(q).add(q).sub(p).rejectIdentity());
534 try std.testing.expectError(error.IdentityElement, r.sub(p).rejectIdentity());
535 try std.testing.expectError(error.IdentityElement, p.sub(p).rejectIdentity());
536 try std.testing.expectError(error.IdentityElement, p.sub(q).add(q).sub(p).rejectIdentity());
537537}
538538
539539test "edwards25519 uniform-to-point" {
540540 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 };
541541 var p = Edwards25519.fromUniform(r);
542 htest.assertEqual("0691eee3cf70a0056df6bfa03120635636581b5c4ea571dfc680f78c7e0b4137", p.toBytes()[0..]);
542 try htest.assertEqual("0691eee3cf70a0056df6bfa03120635636581b5c4ea571dfc680f78c7e0b4137", p.toBytes()[0..]);
543543
544544 r[31] = 0xff;
545545 p = Edwards25519.fromUniform(r);
546 htest.assertEqual("f70718e68ef42d90ca1d936bb2d7e159be6c01d8095d39bd70487c82fe5c973a", p.toBytes()[0..]);
546 try htest.assertEqual("f70718e68ef42d90ca1d936bb2d7e159be6c01d8095d39bd70487c82fe5c973a", p.toBytes()[0..]);
547547}
548548
549549// Test vectors from draft-irtf-cfrg-hash-to-curve-10
550550test "edwards25519 hash-to-curve operation" {
551551 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
554554 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..]);
556556}
lib/std/crypto/25519/ristretto255.zig+5-5
......@@ -175,21 +175,21 @@ pub const Ristretto255 = struct {
175175test "ristretto255" {
176176 const p = Ristretto255.basePoint;
177177 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
180180 var r: [Ristretto255.encoded_length]u8 = undefined;
181181 _ = try fmt.hexToBytes(r[0..], "6a493210f7499cd17fecb510ae0cea23a110e8d5b901f8acadd3095c73a3b919");
182182 var q = try Ristretto255.fromBytes(r);
183183 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
186186 const s = [_]u8{15} ++ [_]u8{0} ** 31;
187187 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
192192 const h = [_]u8{69} ** 32 ++ [_]u8{42} ** 32;
193193 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");
195195}
lib/std/crypto/25519/scalar.zig+4-4
......@@ -773,15 +773,15 @@ test "scalar25519" {
773773 var y = x.toBytes();
774774 try rejectNonCanonical(y);
775775 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
778778 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");
780780}
781781
782782test "non-canonical scalar25519" {
783783 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));
785785}
786786
787787test "mulAdd overflow check" {
......@@ -790,5 +790,5 @@ test "mulAdd overflow check" {
790790 const c: [32]u8 = [_]u8{0xff} ** 32;
791791 const x = mulAdd(a, b, c);
792792 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");
794794}
lib/std/crypto/25519/x25519.zig+8-8
......@@ -92,7 +92,7 @@ test "x25519 public key calculation from secret key" {
9292 _ = try fmt.hexToBytes(sk[0..], "8052030376d47112be7f73ed7a019293dd12ad910b654455798b4667d73de166");
9393 _ = try fmt.hexToBytes(pk_expected[0..], "f1814f0e8ff1043d8a44d25babff3cedcae6c22c3edaa48f857ae70de2baae50");
9494 const pk_calculated = try X25519.recoverPublicKey(sk);
95 std.testing.expectEqual(pk_calculated, pk_expected);
95 try std.testing.expectEqual(pk_calculated, pk_expected);
9696}
9797
9898test "x25519 rfc7748 vector1" {
......@@ -102,7 +102,7 @@ test "x25519 rfc7748 vector1" {
102102 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
104104 const output = try X25519.scalarmult(secret_key, public_key);
105 std.testing.expectEqual(output, expected_output);
105 try std.testing.expectEqual(output, expected_output);
106106}
107107
108108test "x25519 rfc7748 vector2" {
......@@ -112,7 +112,7 @@ test "x25519 rfc7748 vector2" {
112112 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
114114 const output = try X25519.scalarmult(secret_key, public_key);
115 std.testing.expectEqual(output, expected_output);
115 try std.testing.expectEqual(output, expected_output);
116116}
117117
118118test "x25519 rfc7748 one iteration" {
......@@ -129,7 +129,7 @@ test "x25519 rfc7748 one iteration" {
129129 mem.copy(u8, k[0..], output[0..]);
130130 }
131131
132 std.testing.expectEqual(k, expected_output);
132 try std.testing.expectEqual(k, expected_output);
133133}
134134
135135test "x25519 rfc7748 1,000 iterations" {
......@@ -151,7 +151,7 @@ test "x25519 rfc7748 1,000 iterations" {
151151 mem.copy(u8, k[0..], output[0..]);
152152 }
153153
154 std.testing.expectEqual(k, expected_output);
154 try std.testing.expectEqual(k, expected_output);
155155}
156156
157157test "x25519 rfc7748 1,000,000 iterations" {
......@@ -172,12 +172,12 @@ test "x25519 rfc7748 1,000,000 iterations" {
172172 mem.copy(u8, k[0..], output[0..]);
173173 }
174174
175 std.testing.expectEqual(k[0..], expected_output);
175 try std.testing.expectEqual(k[0..], expected_output);
176176}
177177
178178test "edwards25519 -> curve25519 map" {
179179 const ed_kp = try crypto.sign.Ed25519.KeyPair.create([_]u8{0x42} ** 32);
180180 const mont_kp = try X25519.KeyPair.fromEd25519(ed_kp);
181 htest.assertEqual("90e7595fc89e52fdfddce9c6a43d74dbf6047025ee0462d2d172e8b6a2841d6e", &mont_kp.secret_key);
182 htest.assertEqual("cc4f2cdb695dd766f34118eb67b98652fed1d8bc49c330b119bbfa8a64989378", &mont_kp.public_key);
181 try htest.assertEqual("90e7595fc89e52fdfddce9c6a43d74dbf6047025ee0462d2d172e8b6a2841d6e", &mont_kp.secret_key);
182 try htest.assertEqual("cc4f2cdb695dd766f34118eb67b98652fed1d8bc49c330b119bbfa8a64989378", &mont_kp.public_key);
183183}
lib/std/crypto/aegis.zig+20-20
......@@ -352,16 +352,16 @@ test "Aegis128L test vector 1" {
352352
353353 Aegis128L.encrypt(&c, &tag, &m, &ad, nonce, key);
354354 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);
358 htest.assertEqual("cc6f3372f6aa1bb82388d695c3962d9a", &tag);
357 try htest.assertEqual("79d94593d8c2119d7e8fd9b8fc77845c5c077a05b2528b6ac54b563aed8efe84", &c);
358 try htest.assertEqual("cc6f3372f6aa1bb82388d695c3962d9a", &tag);
359359
360360 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));
362362 c[0] -%= 1;
363363 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));
365365}
366366
367367test "Aegis128L test vector 2" {
......@@ -375,10 +375,10 @@ test "Aegis128L test vector 2" {
375375
376376 Aegis128L.encrypt(&c, &tag, &m, &ad, nonce, key);
377377 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);
381 htest.assertEqual("f4d997cc9b94227ada4fe4165422b1c8", &tag);
380 try htest.assertEqual("41de9000a7b5e40e2d68bb64d99ebb19", &c);
381 try htest.assertEqual("f4d997cc9b94227ada4fe4165422b1c8", &tag);
382382}
383383
384384test "Aegis128L test vector 3" {
......@@ -392,9 +392,9 @@ test "Aegis128L test vector 3" {
392392
393393 Aegis128L.encrypt(&c, &tag, &m, &ad, nonce, key);
394394 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);
398398}
399399
400400test "Aegis256 test vector 1" {
......@@ -408,16 +408,16 @@ test "Aegis256 test vector 1" {
408408
409409 Aegis256.encrypt(&c, &tag, &m, &ad, nonce, key);
410410 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);
414 htest.assertEqual("8d86f91ee606e9ff26a01b64ccbdd91d", &tag);
413 try htest.assertEqual("f373079ed84b2709faee373584585d60accd191db310ef5d8b11833df9dec711", &c);
414 try htest.assertEqual("8d86f91ee606e9ff26a01b64ccbdd91d", &tag);
415415
416416 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));
418418 c[0] -%= 1;
419419 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));
421421}
422422
423423test "Aegis256 test vector 2" {
......@@ -431,10 +431,10 @@ test "Aegis256 test vector 2" {
431431
432432 Aegis256.encrypt(&c, &tag, &m, &ad, nonce, key);
433433 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);
437 htest.assertEqual("478f3b50dc478ef7d5cf2d0f7cc13180", &tag);
436 try htest.assertEqual("b98f03a947807713d75a4fff9fc277a6", &c);
437 try htest.assertEqual("478f3b50dc478ef7d5cf2d0f7cc13180", &tag);
438438}
439439
440440test "Aegis256 test vector 3" {
......@@ -448,7 +448,7 @@ test "Aegis256 test vector 3" {
448448
449449 Aegis256.encrypt(&c, &tag, &m, &ad, nonce, key);
450450 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);
454454}
lib/std/crypto/aes.zig+9-9
......@@ -48,7 +48,7 @@ test "ctr" {
4848 var out: [exp_out.len]u8 = undefined;
4949 var ctx = Aes128.initEnc(key);
5050 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..]);
5252}
5353
5454test "encrypt" {
......@@ -61,7 +61,7 @@ test "encrypt" {
6161 var out: [exp_out.len]u8 = undefined;
6262 var ctx = Aes128.initEnc(key);
6363 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..]);
6565 }
6666
6767 // Appendix C.3
......@@ -76,7 +76,7 @@ test "encrypt" {
7676 var out: [exp_out.len]u8 = undefined;
7777 var ctx = Aes256.initEnc(key);
7878 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..]);
8080 }
8181}
8282
......@@ -90,7 +90,7 @@ test "decrypt" {
9090 var out: [exp_out.len]u8 = undefined;
9191 var ctx = Aes128.initDec(key);
9292 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..]);
9494 }
9595
9696 // Appendix C.3
......@@ -105,7 +105,7 @@ test "decrypt" {
105105 var out: [exp_out.len]u8 = undefined;
106106 var ctx = Aes256.initDec(key);
107107 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..]);
109109 }
110110}
111111
......@@ -123,11 +123,11 @@ test "expand 128-bit key" {
123123
124124 for (enc.key_schedule.round_keys) |round_key, i| {
125125 _ = 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());
127127 }
128128 for (enc.key_schedule.round_keys) |round_key, i| {
129129 _ = 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());
131131 }
132132}
133133
......@@ -145,10 +145,10 @@ test "expand 256-bit key" {
145145
146146 for (enc.key_schedule.round_keys) |round_key, i| {
147147 _ = 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());
149149 }
150150 for (dec.key_schedule.round_keys) |round_key, i| {
151151 _ = 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());
153153 }
154154}
lib/std/crypto/aes_gcm.zig+8-8
......@@ -118,7 +118,7 @@ test "Aes256Gcm - Empty message and no associated data" {
118118 var tag: [Aes256Gcm.tag_length]u8 = undefined;
119119
120120 Aes256Gcm.encrypt(&c, &tag, m, ad, nonce, key);
121 htest.assertEqual("6b6ff610a16fa4cd59f1fb7903154e92", &tag);
121 try htest.assertEqual("6b6ff610a16fa4cd59f1fb7903154e92", &tag);
122122}
123123
124124test "Aes256Gcm - Associated data only" {
......@@ -130,7 +130,7 @@ test "Aes256Gcm - Associated data only" {
130130 var tag: [Aes256Gcm.tag_length]u8 = undefined;
131131
132132 Aes256Gcm.encrypt(&c, &tag, m, ad, nonce, key);
133 htest.assertEqual("262ed164c2dfb26e080a9d108dd9dd4c", &tag);
133 try htest.assertEqual("262ed164c2dfb26e080a9d108dd9dd4c", &tag);
134134}
135135
136136test "Aes256Gcm - Message only" {
......@@ -144,10 +144,10 @@ test "Aes256Gcm - Message only" {
144144
145145 Aes256Gcm.encrypt(&c, &tag, m, ad, nonce, key);
146146 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);
150 htest.assertEqual("07cd7fc9103e2f9e9bf2dfaa319caff4", &tag);
149 try htest.assertEqual("5ca1642d90009fea33d01f78cf6eefaf01d539472f7c", &c);
150 try htest.assertEqual("07cd7fc9103e2f9e9bf2dfaa319caff4", &tag);
151151}
152152
153153test "Aes256Gcm - Message and associated data" {
......@@ -161,8 +161,8 @@ test "Aes256Gcm - Message and associated data" {
161161
162162 Aes256Gcm.encrypt(&c, &tag, m, ad, nonce, key);
163163 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);
167 htest.assertEqual("64accec679d444e2373bd9f6796c0d2c", &tag);
166 try htest.assertEqual("5ca1642d90009fea33d01f78cf6eefaf01", &c);
167 try htest.assertEqual("64accec679d444e2373bd9f6796c0d2c", &tag);
168168}
lib/std/crypto/bcrypt.zig+2-2
......@@ -281,13 +281,13 @@ test "bcrypt codec" {
281281 Codec.encode(salt_str[0..], salt[0..]);
282282 var salt2: [salt_length]u8 = undefined;
283283 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..]);
285285}
286286
287287test "bcrypt" {
288288 const s = try strHash("password", 5);
289289 try strVerify(s, "password");
290 testing.expectError(error.PasswordVerificationFailed, strVerify(s, "invalid password"));
290 try testing.expectError(error.PasswordVerificationFailed, strVerify(s, "invalid password"));
291291
292292 const long_s = try strHash("password" ** 100, 5);
293293 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 {
194194
195195test "blake2s160 single" {
196196 const h1 = "354c9c33f735962418bdacb9479873429c34916f";
197 htest.assertEqualHash(Blake2s160, h1, "");
197 try htest.assertEqualHash(Blake2s160, h1, "");
198198
199199 const h2 = "5ae3b99be29b01834c3b508521ede60438f8de17";
200 htest.assertEqualHash(Blake2s160, h2, "abc");
200 try htest.assertEqualHash(Blake2s160, h2, "abc");
201201
202202 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
205205 const h4 = "b60c4dc60e2681e58fbc24e77f07e02c69e72ed0";
206 htest.assertEqualHash(Blake2s160, h4, "a" ** 32 ++ "b" ** 32);
206 try htest.assertEqualHash(Blake2s160, h4, "a" ** 32 ++ "b" ** 32);
207207}
208208
209209test "blake2s160 streaming" {
......@@ -213,21 +213,21 @@ test "blake2s160 streaming" {
213213 const h1 = "354c9c33f735962418bdacb9479873429c34916f";
214214
215215 h.final(out[0..]);
216 htest.assertEqual(h1, out[0..]);
216 try htest.assertEqual(h1, out[0..]);
217217
218218 const h2 = "5ae3b99be29b01834c3b508521ede60438f8de17";
219219
220220 h = Blake2s160.init(.{});
221221 h.update("abc");
222222 h.final(out[0..]);
223 htest.assertEqual(h2, out[0..]);
223 try htest.assertEqual(h2, out[0..]);
224224
225225 h = Blake2s160.init(.{});
226226 h.update("a");
227227 h.update("b");
228228 h.update("c");
229229 h.final(out[0..]);
230 htest.assertEqual(h2, out[0..]);
230 try htest.assertEqual(h2, out[0..]);
231231
232232 const h3 = "b60c4dc60e2681e58fbc24e77f07e02c69e72ed0";
233233
......@@ -235,12 +235,12 @@ test "blake2s160 streaming" {
235235 h.update("a" ** 32);
236236 h.update("b" ** 32);
237237 h.final(out[0..]);
238 htest.assertEqual(h3, out[0..]);
238 try htest.assertEqual(h3, out[0..]);
239239
240240 h = Blake2s160.init(.{});
241241 h.update("a" ** 32 ++ "b" ** 32);
242242 h.final(out[0..]);
243 htest.assertEqual(h3, out[0..]);
243 try htest.assertEqual(h3, out[0..]);
244244
245245 const h4 = "4667fd60791a7fe41f939bca646b4529e296bd68";
246246
......@@ -248,12 +248,12 @@ test "blake2s160 streaming" {
248248 h.update("a" ** 32);
249249 h.update("b" ** 32);
250250 h.final(out[0..]);
251 htest.assertEqual(h4, out[0..]);
251 try htest.assertEqual(h4, out[0..]);
252252
253253 h = Blake2s160.init(.{ .context = [_]u8{0x69} ** 8, .salt = [_]u8{0x42} ** 8 });
254254 h.update("a" ** 32 ++ "b" ** 32);
255255 h.final(out[0..]);
256 htest.assertEqual(h4, out[0..]);
256 try htest.assertEqual(h4, out[0..]);
257257}
258258
259259test "comptime blake2s160" {
......@@ -265,28 +265,28 @@ test "comptime blake2s160" {
265265
266266 const h1 = "2c56ad9d0b2c8b474aafa93ab307db2f0940105f";
267267
268 htest.assertEqualHash(Blake2s160, h1, block[0..]);
268 try htest.assertEqualHash(Blake2s160, h1, block[0..]);
269269
270270 var h = Blake2s160.init(.{});
271271 h.update(&block);
272272 h.final(out[0..]);
273273
274 htest.assertEqual(h1, out[0..]);
274 try htest.assertEqual(h1, out[0..]);
275275 }
276276}
277277
278278test "blake2s224 single" {
279279 const h1 = "1fa1291e65248b37b3433475b2a0dd63d54a11ecc4e3e034e7bc1ef4";
280 htest.assertEqualHash(Blake2s224, h1, "");
280 try htest.assertEqualHash(Blake2s224, h1, "");
281281
282282 const h2 = "0b033fc226df7abde29f67a05d3dc62cf271ef3dfea4d387407fbd55";
283 htest.assertEqualHash(Blake2s224, h2, "abc");
283 try htest.assertEqualHash(Blake2s224, h2, "abc");
284284
285285 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
288288 const h4 = "557381a78facd2b298640f4e32113e58967d61420af1aa939d0cfe01";
289 htest.assertEqualHash(Blake2s224, h4, "a" ** 32 ++ "b" ** 32);
289 try htest.assertEqualHash(Blake2s224, h4, "a" ** 32 ++ "b" ** 32);
290290}
291291
292292test "blake2s224 streaming" {
......@@ -296,21 +296,21 @@ test "blake2s224 streaming" {
296296 const h1 = "1fa1291e65248b37b3433475b2a0dd63d54a11ecc4e3e034e7bc1ef4";
297297
298298 h.final(out[0..]);
299 htest.assertEqual(h1, out[0..]);
299 try htest.assertEqual(h1, out[0..]);
300300
301301 const h2 = "0b033fc226df7abde29f67a05d3dc62cf271ef3dfea4d387407fbd55";
302302
303303 h = Blake2s224.init(.{});
304304 h.update("abc");
305305 h.final(out[0..]);
306 htest.assertEqual(h2, out[0..]);
306 try htest.assertEqual(h2, out[0..]);
307307
308308 h = Blake2s224.init(.{});
309309 h.update("a");
310310 h.update("b");
311311 h.update("c");
312312 h.final(out[0..]);
313 htest.assertEqual(h2, out[0..]);
313 try htest.assertEqual(h2, out[0..]);
314314
315315 const h3 = "557381a78facd2b298640f4e32113e58967d61420af1aa939d0cfe01";
316316
......@@ -318,12 +318,12 @@ test "blake2s224 streaming" {
318318 h.update("a" ** 32);
319319 h.update("b" ** 32);
320320 h.final(out[0..]);
321 htest.assertEqual(h3, out[0..]);
321 try htest.assertEqual(h3, out[0..]);
322322
323323 h = Blake2s224.init(.{});
324324 h.update("a" ** 32 ++ "b" ** 32);
325325 h.final(out[0..]);
326 htest.assertEqual(h3, out[0..]);
326 try htest.assertEqual(h3, out[0..]);
327327
328328 const h4 = "a4d6a9d253441b80e5dfd60a04db169ffab77aec56a2855c402828c3";
329329
......@@ -331,12 +331,12 @@ test "blake2s224 streaming" {
331331 h.update("a" ** 32);
332332 h.update("b" ** 32);
333333 h.final(out[0..]);
334 htest.assertEqual(h4, out[0..]);
334 try htest.assertEqual(h4, out[0..]);
335335
336336 h = Blake2s224.init(.{ .context = [_]u8{0x69} ** 8, .salt = [_]u8{0x42} ** 8 });
337337 h.update("a" ** 32 ++ "b" ** 32);
338338 h.final(out[0..]);
339 htest.assertEqual(h4, out[0..]);
339 try htest.assertEqual(h4, out[0..]);
340340}
341341
342342test "comptime blake2s224" {
......@@ -347,28 +347,28 @@ test "comptime blake2s224" {
347347
348348 const h1 = "86b7611563293f8c73627df7a6d6ba25ca0548c2a6481f7d116ee576";
349349
350 htest.assertEqualHash(Blake2s224, h1, block[0..]);
350 try htest.assertEqualHash(Blake2s224, h1, block[0..]);
351351
352352 var h = Blake2s224.init(.{});
353353 h.update(&block);
354354 h.final(out[0..]);
355355
356 htest.assertEqual(h1, out[0..]);
356 try htest.assertEqual(h1, out[0..]);
357357 }
358358}
359359
360360test "blake2s256 single" {
361361 const h1 = "69217a3079908094e11121d042354a7c1f55b6482ca1a51e1b250dfd1ed0eef9";
362 htest.assertEqualHash(Blake2s256, h1, "");
362 try htest.assertEqualHash(Blake2s256, h1, "");
363363
364364 const h2 = "508c5e8c327c14e2e1a72ba34eeb452f37458b209ed63a294d999b4c86675982";
365 htest.assertEqualHash(Blake2s256, h2, "abc");
365 try htest.assertEqualHash(Blake2s256, h2, "abc");
366366
367367 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
370370 const h4 = "8d8711dade07a6b92b9a3ea1f40bee9b2c53ff3edd2a273dec170b0163568977";
371 htest.assertEqualHash(Blake2s256, h4, "a" ** 32 ++ "b" ** 32);
371 try htest.assertEqualHash(Blake2s256, h4, "a" ** 32 ++ "b" ** 32);
372372}
373373
374374test "blake2s256 streaming" {
......@@ -378,21 +378,21 @@ test "blake2s256 streaming" {
378378 const h1 = "69217a3079908094e11121d042354a7c1f55b6482ca1a51e1b250dfd1ed0eef9";
379379
380380 h.final(out[0..]);
381 htest.assertEqual(h1, out[0..]);
381 try htest.assertEqual(h1, out[0..]);
382382
383383 const h2 = "508c5e8c327c14e2e1a72ba34eeb452f37458b209ed63a294d999b4c86675982";
384384
385385 h = Blake2s256.init(.{});
386386 h.update("abc");
387387 h.final(out[0..]);
388 htest.assertEqual(h2, out[0..]);
388 try htest.assertEqual(h2, out[0..]);
389389
390390 h = Blake2s256.init(.{});
391391 h.update("a");
392392 h.update("b");
393393 h.update("c");
394394 h.final(out[0..]);
395 htest.assertEqual(h2, out[0..]);
395 try htest.assertEqual(h2, out[0..]);
396396
397397 const h3 = "8d8711dade07a6b92b9a3ea1f40bee9b2c53ff3edd2a273dec170b0163568977";
398398
......@@ -400,12 +400,12 @@ test "blake2s256 streaming" {
400400 h.update("a" ** 32);
401401 h.update("b" ** 32);
402402 h.final(out[0..]);
403 htest.assertEqual(h3, out[0..]);
403 try htest.assertEqual(h3, out[0..]);
404404
405405 h = Blake2s256.init(.{});
406406 h.update("a" ** 32 ++ "b" ** 32);
407407 h.final(out[0..]);
408 htest.assertEqual(h3, out[0..]);
408 try htest.assertEqual(h3, out[0..]);
409409}
410410
411411test "blake2s256 keyed" {
......@@ -415,20 +415,20 @@ test "blake2s256 keyed" {
415415 const key = "secret_key";
416416
417417 Blake2s256.hash("a" ** 64 ++ "b" ** 64, &out, .{ .key = key });
418 htest.assertEqual(h1, out[0..]);
418 try htest.assertEqual(h1, out[0..]);
419419
420420 var h = Blake2s256.init(.{ .key = key });
421421 h.update("a" ** 64 ++ "b" ** 64);
422422 h.final(out[0..]);
423423
424 htest.assertEqual(h1, out[0..]);
424 try htest.assertEqual(h1, out[0..]);
425425
426426 h = Blake2s256.init(.{ .key = key });
427427 h.update("a" ** 64);
428428 h.update("b" ** 64);
429429 h.final(out[0..]);
430430
431 htest.assertEqual(h1, out[0..]);
431 try htest.assertEqual(h1, out[0..]);
432432}
433433
434434test "comptime blake2s256" {
......@@ -439,13 +439,13 @@ test "comptime blake2s256" {
439439
440440 const h1 = "ae09db7cd54f42b490ef09b6bc541af688e4959bb8c53f359a6f56e38ab454a3";
441441
442 htest.assertEqualHash(Blake2s256, h1, block[0..]);
442 try htest.assertEqualHash(Blake2s256, h1, block[0..]);
443443
444444 var h = Blake2s256.init(.{});
445445 h.update(&block);
446446 h.final(out[0..]);
447447
448 htest.assertEqual(h1, out[0..]);
448 try htest.assertEqual(h1, out[0..]);
449449 }
450450}
451451
......@@ -617,16 +617,16 @@ pub fn Blake2b(comptime out_bits: usize) type {
617617
618618test "blake2b160 single" {
619619 const h1 = "3345524abf6bbe1809449224b5972c41790b6cf2";
620 htest.assertEqualHash(Blake2b160, h1, "");
620 try htest.assertEqualHash(Blake2b160, h1, "");
621621
622622 const h2 = "384264f676f39536840523f284921cdc68b6846b";
623 htest.assertEqualHash(Blake2b160, h2, "abc");
623 try htest.assertEqualHash(Blake2b160, h2, "abc");
624624
625625 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
628628 const h4 = "43758f5de1740f651f1ae39de92260fe8bd5a11f";
629 htest.assertEqualHash(Blake2b160, h4, "a" ** 64 ++ "b" ** 64);
629 try htest.assertEqualHash(Blake2b160, h4, "a" ** 64 ++ "b" ** 64);
630630}
631631
632632test "blake2b160 streaming" {
......@@ -636,40 +636,40 @@ test "blake2b160 streaming" {
636636 const h1 = "3345524abf6bbe1809449224b5972c41790b6cf2";
637637
638638 h.final(out[0..]);
639 htest.assertEqual(h1, out[0..]);
639 try htest.assertEqual(h1, out[0..]);
640640
641641 const h2 = "384264f676f39536840523f284921cdc68b6846b";
642642
643643 h = Blake2b160.init(.{});
644644 h.update("abc");
645645 h.final(out[0..]);
646 htest.assertEqual(h2, out[0..]);
646 try htest.assertEqual(h2, out[0..]);
647647
648648 h = Blake2b160.init(.{});
649649 h.update("a");
650650 h.update("b");
651651 h.update("c");
652652 h.final(out[0..]);
653 htest.assertEqual(h2, out[0..]);
653 try htest.assertEqual(h2, out[0..]);
654654
655655 const h3 = "43758f5de1740f651f1ae39de92260fe8bd5a11f";
656656
657657 h = Blake2b160.init(.{});
658658 h.update("a" ** 64 ++ "b" ** 64);
659659 h.final(out[0..]);
660 htest.assertEqual(h3, out[0..]);
660 try htest.assertEqual(h3, out[0..]);
661661
662662 h = Blake2b160.init(.{});
663663 h.update("a" ** 64);
664664 h.update("b" ** 64);
665665 h.final(out[0..]);
666 htest.assertEqual(h3, out[0..]);
666 try htest.assertEqual(h3, out[0..]);
667667
668668 h = Blake2b160.init(.{});
669669 h.update("a" ** 64);
670670 h.update("b" ** 64);
671671 h.final(out[0..]);
672 htest.assertEqual(h3, out[0..]);
672 try htest.assertEqual(h3, out[0..]);
673673
674674 const h4 = "72328f8a8200663752fc302d372b5dd9b49dd8dc";
675675
......@@ -677,13 +677,13 @@ test "blake2b160 streaming" {
677677 h.update("a" ** 64);
678678 h.update("b" ** 64);
679679 h.final(out[0..]);
680 htest.assertEqual(h4, out[0..]);
680 try htest.assertEqual(h4, out[0..]);
681681
682682 h = Blake2b160.init(.{ .context = [_]u8{0x69} ** 16, .salt = [_]u8{0x42} ** 16 });
683683 h.update("a" ** 64);
684684 h.update("b" ** 64);
685685 h.final(out[0..]);
686 htest.assertEqual(h4, out[0..]);
686 try htest.assertEqual(h4, out[0..]);
687687}
688688
689689test "comptime blake2b160" {
......@@ -694,28 +694,28 @@ test "comptime blake2b160" {
694694
695695 const h1 = "8d26f158f564e3293b42f5e3d34263cb173aa9c9";
696696
697 htest.assertEqualHash(Blake2b160, h1, block[0..]);
697 try htest.assertEqualHash(Blake2b160, h1, block[0..]);
698698
699699 var h = Blake2b160.init(.{});
700700 h.update(&block);
701701 h.final(out[0..]);
702702
703 htest.assertEqual(h1, out[0..]);
703 try htest.assertEqual(h1, out[0..]);
704704 }
705705}
706706
707707test "blake2b384 single" {
708708 const h1 = "b32811423377f52d7862286ee1a72ee540524380fda1724a6f25d7978c6fd3244a6caf0498812673c5e05ef583825100";
709 htest.assertEqualHash(Blake2b384, h1, "");
709 try htest.assertEqualHash(Blake2b384, h1, "");
710710
711711 const h2 = "6f56a82c8e7ef526dfe182eb5212f7db9df1317e57815dbda46083fc30f54ee6c66ba83be64b302d7cba6ce15bb556f4";
712 htest.assertEqualHash(Blake2b384, h2, "abc");
712 try htest.assertEqualHash(Blake2b384, h2, "abc");
713713
714714 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
717717 const h4 = "b7283f0172fecbbd7eca32ce10d8a6c06b453cb3cf675b33eb4246f0da2bb94a6c0bdd6eec0b5fd71ec4fd51be80bf4c";
718 htest.assertEqualHash(Blake2b384, h4, "a" ** 64 ++ "b" ** 64);
718 try htest.assertEqualHash(Blake2b384, h4, "a" ** 64 ++ "b" ** 64);
719719}
720720
721721test "blake2b384 streaming" {
......@@ -725,40 +725,40 @@ test "blake2b384 streaming" {
725725 const h1 = "b32811423377f52d7862286ee1a72ee540524380fda1724a6f25d7978c6fd3244a6caf0498812673c5e05ef583825100";
726726
727727 h.final(out[0..]);
728 htest.assertEqual(h1, out[0..]);
728 try htest.assertEqual(h1, out[0..]);
729729
730730 const h2 = "6f56a82c8e7ef526dfe182eb5212f7db9df1317e57815dbda46083fc30f54ee6c66ba83be64b302d7cba6ce15bb556f4";
731731
732732 h = Blake2b384.init(.{});
733733 h.update("abc");
734734 h.final(out[0..]);
735 htest.assertEqual(h2, out[0..]);
735 try htest.assertEqual(h2, out[0..]);
736736
737737 h = Blake2b384.init(.{});
738738 h.update("a");
739739 h.update("b");
740740 h.update("c");
741741 h.final(out[0..]);
742 htest.assertEqual(h2, out[0..]);
742 try htest.assertEqual(h2, out[0..]);
743743
744744 const h3 = "b7283f0172fecbbd7eca32ce10d8a6c06b453cb3cf675b33eb4246f0da2bb94a6c0bdd6eec0b5fd71ec4fd51be80bf4c";
745745
746746 h = Blake2b384.init(.{});
747747 h.update("a" ** 64 ++ "b" ** 64);
748748 h.final(out[0..]);
749 htest.assertEqual(h3, out[0..]);
749 try htest.assertEqual(h3, out[0..]);
750750
751751 h = Blake2b384.init(.{});
752752 h.update("a" ** 64);
753753 h.update("b" ** 64);
754754 h.final(out[0..]);
755 htest.assertEqual(h3, out[0..]);
755 try htest.assertEqual(h3, out[0..]);
756756
757757 h = Blake2b384.init(.{});
758758 h.update("a" ** 64);
759759 h.update("b" ** 64);
760760 h.final(out[0..]);
761 htest.assertEqual(h3, out[0..]);
761 try htest.assertEqual(h3, out[0..]);
762762
763763 const h4 = "934c48fcb197031c71f583d92f98703510805e72142e0b46f5752d1e971bc86c355d556035613ff7a4154b4de09dac5c";
764764
......@@ -766,13 +766,13 @@ test "blake2b384 streaming" {
766766 h.update("a" ** 64);
767767 h.update("b" ** 64);
768768 h.final(out[0..]);
769 htest.assertEqual(h4, out[0..]);
769 try htest.assertEqual(h4, out[0..]);
770770
771771 h = Blake2b384.init(.{ .context = [_]u8{0x69} ** 16, .salt = [_]u8{0x42} ** 16 });
772772 h.update("a" ** 64);
773773 h.update("b" ** 64);
774774 h.final(out[0..]);
775 htest.assertEqual(h4, out[0..]);
775 try htest.assertEqual(h4, out[0..]);
776776}
777777
778778test "comptime blake2b384" {
......@@ -783,28 +783,28 @@ test "comptime blake2b384" {
783783
784784 const h1 = "e8aa1931ea0422e4446fecdd25c16cf35c240b10cb4659dd5c776eddcaa4d922397a589404b46eb2e53d78132d05fd7d";
785785
786 htest.assertEqualHash(Blake2b384, h1, block[0..]);
786 try htest.assertEqualHash(Blake2b384, h1, block[0..]);
787787
788788 var h = Blake2b384.init(.{});
789789 h.update(&block);
790790 h.final(out[0..]);
791791
792 htest.assertEqual(h1, out[0..]);
792 try htest.assertEqual(h1, out[0..]);
793793 }
794794}
795795
796796test "blake2b512 single" {
797797 const h1 = "786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce";
798 htest.assertEqualHash(Blake2b512, h1, "");
798 try htest.assertEqualHash(Blake2b512, h1, "");
799799
800800 const h2 = "ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923";
801 htest.assertEqualHash(Blake2b512, h2, "abc");
801 try htest.assertEqualHash(Blake2b512, h2, "abc");
802802
803803 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
806806 const h4 = "049980af04d6a2cf16b4b49793c3ed7e40732073788806f2c989ebe9547bda0541d63abe298ec8955d08af48ae731f2e8a0bd6d201655a5473b4aa79d211b920";
807 htest.assertEqualHash(Blake2b512, h4, "a" ** 64 ++ "b" ** 64);
807 try htest.assertEqualHash(Blake2b512, h4, "a" ** 64 ++ "b" ** 64);
808808}
809809
810810test "blake2b512 streaming" {
......@@ -814,34 +814,34 @@ test "blake2b512 streaming" {
814814 const h1 = "786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce";
815815
816816 h.final(out[0..]);
817 htest.assertEqual(h1, out[0..]);
817 try htest.assertEqual(h1, out[0..]);
818818
819819 const h2 = "ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923";
820820
821821 h = Blake2b512.init(.{});
822822 h.update("abc");
823823 h.final(out[0..]);
824 htest.assertEqual(h2, out[0..]);
824 try htest.assertEqual(h2, out[0..]);
825825
826826 h = Blake2b512.init(.{});
827827 h.update("a");
828828 h.update("b");
829829 h.update("c");
830830 h.final(out[0..]);
831 htest.assertEqual(h2, out[0..]);
831 try htest.assertEqual(h2, out[0..]);
832832
833833 const h3 = "049980af04d6a2cf16b4b49793c3ed7e40732073788806f2c989ebe9547bda0541d63abe298ec8955d08af48ae731f2e8a0bd6d201655a5473b4aa79d211b920";
834834
835835 h = Blake2b512.init(.{});
836836 h.update("a" ** 64 ++ "b" ** 64);
837837 h.final(out[0..]);
838 htest.assertEqual(h3, out[0..]);
838 try htest.assertEqual(h3, out[0..]);
839839
840840 h = Blake2b512.init(.{});
841841 h.update("a" ** 64);
842842 h.update("b" ** 64);
843843 h.final(out[0..]);
844 htest.assertEqual(h3, out[0..]);
844 try htest.assertEqual(h3, out[0..]);
845845}
846846
847847test "blake2b512 keyed" {
......@@ -851,20 +851,20 @@ test "blake2b512 keyed" {
851851 const key = "secret_key";
852852
853853 Blake2b512.hash("a" ** 64 ++ "b" ** 64, &out, .{ .key = key });
854 htest.assertEqual(h1, out[0..]);
854 try htest.assertEqual(h1, out[0..]);
855855
856856 var h = Blake2b512.init(.{ .key = key });
857857 h.update("a" ** 64 ++ "b" ** 64);
858858 h.final(out[0..]);
859859
860 htest.assertEqual(h1, out[0..]);
860 try htest.assertEqual(h1, out[0..]);
861861
862862 h = Blake2b512.init(.{ .key = key });
863863 h.update("a" ** 64);
864864 h.update("b" ** 64);
865865 h.final(out[0..]);
866866
867 htest.assertEqual(h1, out[0..]);
867 try htest.assertEqual(h1, out[0..]);
868868}
869869
870870test "comptime blake2b512" {
......@@ -875,12 +875,12 @@ test "comptime blake2b512" {
875875
876876 const h1 = "865939e120e6805438478841afb739ae4250cf372653078a065cdcfffca4caf798e6d462b65d658fc165782640eded70963449ae1500fb0f24981d7727e22c41";
877877
878 htest.assertEqualHash(Blake2b512, h1, block[0..]);
878 try htest.assertEqualHash(Blake2b512, h1, block[0..]);
879879
880880 var h = Blake2b512.init(.{});
881881 h.update(&block);
882882 h.final(out[0..]);
883883
884 htest.assertEqual(h1, out[0..]);
884 try htest.assertEqual(h1, out[0..]);
885885 }
886886}
lib/std/crypto/blake3.zig+5-5
......@@ -641,7 +641,7 @@ const reference_test = ReferenceTest{
641641 },
642642};
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 {
645645 // Save initial state
646646 const initial_state = hasher.*;
647647
......@@ -664,7 +664,7 @@ fn testBlake3(hasher: *Blake3, input_len: usize, expected_hex: [262]u8) void {
664664 // Compare to expected value
665665 var expected_bytes: [expected_hex.len / 2]u8 = undefined;
666666 _ = 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
669669 // Restore initial state
670670 hasher.* = initial_state;
......@@ -676,8 +676,8 @@ test "BLAKE3 reference test cases" {
676676 var derive_key = &Blake3.initKdf(reference_test.context_string, .{});
677677
678678 for (reference_test.cases) |t| {
679 testBlake3(hash, t.input_len, t.hash.*);
680 testBlake3(keyed_hash, t.input_len, t.keyed_hash.*);
681 testBlake3(derive_key, t.input_len, t.derive_key.*);
679 try testBlake3(hash, t.input_len, t.hash.*);
680 try testBlake3(keyed_hash, t.input_len, t.keyed_hash.*);
681 try testBlake3(derive_key, t.input_len, t.derive_key.*);
682682 }
683683}
lib/std/crypto/chacha20.zig+21-21
......@@ -604,9 +604,9 @@ test "chacha20 AEAD API" {
604604
605605 aead.encrypt(c[0..], tag[0..], m, ad, nonce, key);
606606 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);
608608 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));
610610 }
611611}
612612
......@@ -644,11 +644,11 @@ test "crypto.chacha20 test vector sunscreen" {
644644 };
645645
646646 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
649649 var m2: [114]u8 = undefined;
650650 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);
652652}
653653
654654// https://tools.ietf.org/html/draft-agl-tls-chacha20poly1305-04#section-7
......@@ -683,7 +683,7 @@ test "crypto.chacha20 test vector 1" {
683683 const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0 };
684684
685685 ChaCha20With64BitNonce.xor(result[0..], m[0..], 0, key, nonce);
686 testing.expectEqualSlices(u8, &expected_result, &result);
686 try testing.expectEqualSlices(u8, &expected_result, &result);
687687}
688688
689689test "crypto.chacha20 test vector 2" {
......@@ -717,7 +717,7 @@ test "crypto.chacha20 test vector 2" {
717717 const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0 };
718718
719719 ChaCha20With64BitNonce.xor(result[0..], m[0..], 0, key, nonce);
720 testing.expectEqualSlices(u8, &expected_result, &result);
720 try testing.expectEqualSlices(u8, &expected_result, &result);
721721}
722722
723723test "crypto.chacha20 test vector 3" {
......@@ -751,7 +751,7 @@ test "crypto.chacha20 test vector 3" {
751751 const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 1 };
752752
753753 ChaCha20With64BitNonce.xor(result[0..], m[0..], 0, key, nonce);
754 testing.expectEqualSlices(u8, &expected_result, &result);
754 try testing.expectEqualSlices(u8, &expected_result, &result);
755755}
756756
757757test "crypto.chacha20 test vector 4" {
......@@ -785,7 +785,7 @@ test "crypto.chacha20 test vector 4" {
785785 const nonce = [_]u8{ 1, 0, 0, 0, 0, 0, 0, 0 };
786786
787787 ChaCha20With64BitNonce.xor(result[0..], m[0..], 0, key, nonce);
788 testing.expectEqualSlices(u8, &expected_result, &result);
788 try testing.expectEqualSlices(u8, &expected_result, &result);
789789}
790790
791791test "crypto.chacha20 test vector 5" {
......@@ -857,7 +857,7 @@ test "crypto.chacha20 test vector 5" {
857857 };
858858
859859 ChaCha20With64BitNonce.xor(result[0..], m[0..], 0, key, nonce);
860 testing.expectEqualSlices(u8, &expected_result, &result);
860 try testing.expectEqualSlices(u8, &expected_result, &result);
861861}
862862
863863test "seal" {
......@@ -873,7 +873,7 @@ test "seal" {
873873
874874 var out: [exp_out.len]u8 = undefined;
875875 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..]);
877877 }
878878 {
879879 const m = [_]u8{
......@@ -906,7 +906,7 @@ test "seal" {
906906
907907 var out: [exp_out.len]u8 = undefined;
908908 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..]);
910910 }
911911}
912912
......@@ -923,7 +923,7 @@ test "open" {
923923
924924 var out: [exp_out.len]u8 = undefined;
925925 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..]);
927927 }
928928 {
929929 const c = [_]u8{
......@@ -956,21 +956,21 @@ test "open" {
956956
957957 var out: [exp_out.len]u8 = undefined;
958958 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
961961 // corrupting the ciphertext, data, key, or nonce should cause a failure
962962 var bad_c = c;
963963 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));
965965 var bad_ad = ad;
966966 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));
968968 var bad_key = key;
969969 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));
971971 var bad_nonce = nonce;
972972 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));
974974 }
975975}
976976
......@@ -982,7 +982,7 @@ test "crypto.xchacha20" {
982982 var c: [m.len]u8 = undefined;
983983 XChaCha20IETF.xor(c[0..], m[0..], 0, key, nonce);
984984 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");
986986 }
987987 {
988988 const ad = "Additional data";
......@@ -991,9 +991,9 @@ test "crypto.xchacha20" {
991991 var out: [m.len]u8 = undefined;
992992 try XChaCha20Poly1305.decrypt(out[0..], c[0..m.len], c[m.len..].*, ad, nonce, key);
993993 var buf: [2 * c.len]u8 = undefined;
994 testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&c)}), "994D2DD32333F48E53650C02C7A2ABB8E018B0836D7175AEC779F52E961780768F815C58F1AA52D211498DB89B9216763F569C9433A6BBFCEFB4D4A49387A4C5207FBB3B5A92B5941294DF30588C6740D39DC16FA1F0E634F7246CF7CDCB978E44347D89381B7A74EB7084F754B90BDE9AAF5A94B8F2A85EFD0B50692AE2D425E234");
995 testing.expectEqualSlices(u8, out[0..], m);
994 try testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&c)}), "994D2DD32333F48E53650C02C7A2ABB8E018B0836D7175AEC779F52E961780768F815C58F1AA52D211498DB89B9216763F569C9433A6BBFCEFB4D4A49387A4C5207FBB3B5A92B5941294DF30588C6740D39DC16FA1F0E634F7246CF7CDCB978E44347D89381B7A74EB7084F754B90BDE9AAF5A94B8F2A85EFD0B50692AE2D425E234");
995 try testing.expectEqualSlices(u8, out[0..], m);
996996 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));
998998 }
999999}
lib/std/crypto/ghash.zig+2-2
......@@ -326,11 +326,11 @@ test "ghash" {
326326 st.update(&m);
327327 var out: [16]u8 = undefined;
328328 st.final(&out);
329 htest.assertEqual("889295fa746e8b174bf4ec80a65dea41", &out);
329 try htest.assertEqual("889295fa746e8b174bf4ec80a65dea41", &out);
330330
331331 st = Ghash.init(&key);
332332 st.update(m[0..100]);
333333 st.update(m[100..]);
334334 st.final(&out);
335 htest.assertEqual("889295fa746e8b174bf4ec80a65dea41", &out);
335 try htest.assertEqual("889295fa746e8b174bf4ec80a65dea41", &out);
336336}
lib/std/crypto/gimli.zig+19-19
......@@ -205,7 +205,7 @@ test "permute" {
205205 while (i < 12) : (i += 1) {
206206 mem.writeIntLittle(u32, expected_output[i * 4 ..][0..4], tv_output[i / 4][i % 4]);
207207 }
208 testing.expectEqualSlices(u8, state.toSliceConst(), expected_output[0..]);
208 try testing.expectEqualSlices(u8, state.toSliceConst(), expected_output[0..]);
209209}
210210
211211pub const Hash = struct {
......@@ -274,7 +274,7 @@ test "hash" {
274274 _ = try std.fmt.hexToBytes(&msg, "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C");
275275 var md: [32]u8 = undefined;
276276 hash(&md, &msg, .{});
277 htest.assertEqual("1C9A03DC6A5DDC5444CFC6F4B154CFF5CF081633B2CEA4D7D0AE7CCFED5AAA44", &md);
277 try htest.assertEqual("1C9A03DC6A5DDC5444CFC6F4B154CFF5CF081633B2CEA4D7D0AE7CCFED5AAA44", &md);
278278}
279279
280280test "hash test vector 17" {
......@@ -282,7 +282,7 @@ test "hash test vector 17" {
282282 _ = try std.fmt.hexToBytes(&msg, "000102030405060708090A0B0C0D0E0F");
283283 var md: [32]u8 = undefined;
284284 hash(&md, &msg, .{});
285 htest.assertEqual("404C130AF1B9023A7908200919F690FFBB756D5176E056FFDE320016A37C7282", &md);
285 try htest.assertEqual("404C130AF1B9023A7908200919F690FFBB756D5176E056FFDE320016A37C7282", &md);
286286}
287287
288288test "hash test vector 33" {
......@@ -290,7 +290,7 @@ test "hash test vector 33" {
290290 _ = try std.fmt.hexToBytes(&msg, "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F");
291291 var md: [32]u8 = undefined;
292292 hash(&md, &msg, .{});
293 htest.assertEqual("A8F4FA28708BDA7EFB4C1914CA4AFA9E475B82D588D36504F87DBB0ED9AB3C4B", &md);
293 try htest.assertEqual("A8F4FA28708BDA7EFB4C1914CA4AFA9E475B82D588D36504F87DBB0ED9AB3C4B", &md);
294294}
295295
296296pub const Aead = struct {
......@@ -447,12 +447,12 @@ test "cipher" {
447447 var ct: [pt.len]u8 = undefined;
448448 var tag: [16]u8 = undefined;
449449 Aead.encrypt(&ct, &tag, &pt, &ad, nonce, key);
450 htest.assertEqual("", &ct);
451 htest.assertEqual("14DA9BB7120BF58B985A8E00FDEBA15B", &tag);
450 try htest.assertEqual("", &ct);
451 try htest.assertEqual("14DA9BB7120BF58B985A8E00FDEBA15B", &tag);
452452
453453 var pt2: [pt.len]u8 = undefined;
454454 try Aead.decrypt(&pt2, &ct, tag, &ad, nonce, key);
455 testing.expectEqualSlices(u8, &pt, &pt2);
455 try testing.expectEqualSlices(u8, &pt, &pt2);
456456 }
457457 { // test vector (34) from NIST KAT submission.
458458 const ad: [0]u8 = undefined;
......@@ -462,12 +462,12 @@ test "cipher" {
462462 var ct: [pt.len]u8 = undefined;
463463 var tag: [16]u8 = undefined;
464464 Aead.encrypt(&ct, &tag, &pt, &ad, nonce, key);
465 htest.assertEqual("7F", &ct);
466 htest.assertEqual("80492C317B1CD58A1EDC3A0D3E9876FC", &tag);
465 try htest.assertEqual("7F", &ct);
466 try htest.assertEqual("80492C317B1CD58A1EDC3A0D3E9876FC", &tag);
467467
468468 var pt2: [pt.len]u8 = undefined;
469469 try Aead.decrypt(&pt2, &ct, tag, &ad, nonce, key);
470 testing.expectEqualSlices(u8, &pt, &pt2);
470 try testing.expectEqualSlices(u8, &pt, &pt2);
471471 }
472472 { // test vector (106) from NIST KAT submission.
473473 var ad: [12 / 2]u8 = undefined;
......@@ -478,12 +478,12 @@ test "cipher" {
478478 var ct: [pt.len]u8 = undefined;
479479 var tag: [16]u8 = undefined;
480480 Aead.encrypt(&ct, &tag, &pt, &ad, nonce, key);
481 htest.assertEqual("484D35", &ct);
482 htest.assertEqual("030BBEA23B61C00CED60A923BDCF9147", &tag);
481 try htest.assertEqual("484D35", &ct);
482 try htest.assertEqual("030BBEA23B61C00CED60A923BDCF9147", &tag);
483483
484484 var pt2: [pt.len]u8 = undefined;
485485 try Aead.decrypt(&pt2, &ct, tag, &ad, nonce, key);
486 testing.expectEqualSlices(u8, &pt, &pt2);
486 try testing.expectEqualSlices(u8, &pt, &pt2);
487487 }
488488 { // test vector (790) from NIST KAT submission.
489489 var ad: [60 / 2]u8 = undefined;
......@@ -494,12 +494,12 @@ test "cipher" {
494494 var ct: [pt.len]u8 = undefined;
495495 var tag: [16]u8 = undefined;
496496 Aead.encrypt(&ct, &tag, &pt, &ad, nonce, key);
497 htest.assertEqual("6815B4A0ECDAD01596EAD87D9E690697475D234C6A13D1", &ct);
498 htest.assertEqual("DFE23F1642508290D68245279558B2FB", &tag);
497 try htest.assertEqual("6815B4A0ECDAD01596EAD87D9E690697475D234C6A13D1", &ct);
498 try htest.assertEqual("DFE23F1642508290D68245279558B2FB", &tag);
499499
500500 var pt2: [pt.len]u8 = undefined;
501501 try Aead.decrypt(&pt2, &ct, tag, &ad, nonce, key);
502 testing.expectEqualSlices(u8, &pt, &pt2);
502 try testing.expectEqualSlices(u8, &pt, &pt2);
503503 }
504504 { // test vector (1057) from NIST KAT submission.
505505 const ad: [0]u8 = undefined;
......@@ -509,11 +509,11 @@ test "cipher" {
509509 var ct: [pt.len]u8 = undefined;
510510 var tag: [16]u8 = undefined;
511511 Aead.encrypt(&ct, &tag, &pt, &ad, nonce, key);
512 htest.assertEqual("7F8A2CF4F52AA4D6B2E74105C30A2777B9D0C8AEFDD555DE35861BD3011F652F", &ct);
513 htest.assertEqual("7256456FA935AC34BBF55AE135F33257", &tag);
512 try htest.assertEqual("7F8A2CF4F52AA4D6B2E74105C30A2777B9D0C8AEFDD555DE35861BD3011F652F", &ct);
513 try htest.assertEqual("7256456FA935AC34BBF55AE135F33257", &tag);
514514
515515 var pt2: [pt.len]u8 = undefined;
516516 try Aead.decrypt(&pt2, &ct, tag, &ad, nonce, key);
517 testing.expectEqualSlices(u8, &pt, &pt2);
517 try testing.expectEqualSlices(u8, &pt, &pt2);
518518 }
519519}
lib/std/crypto/hkdf.zig+2-2
......@@ -65,8 +65,8 @@ test "Hkdf" {
6565 const context = [_]u8{ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9 };
6666 const kdf = HkdfSha256;
6767 const prk = kdf.extract(&salt, &ikm);
68 htest.assertEqual("077709362c2e32df0ddc3f0dc47bba6390b6c73bb50f9c3122ec844ad7c2b3e5", &prk);
68 try htest.assertEqual("077709362c2e32df0ddc3f0dc47bba6390b6c73bb50f9c3122ec844ad7c2b3e5", &prk);
6969 var out: [42]u8 = undefined;
7070 kdf.expand(&out, &context, prk);
71 htest.assertEqual("3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865", &out);
71 try htest.assertEqual("3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865", &out);
7272}
lib/std/crypto/hmac.zig+6-6
......@@ -84,26 +84,26 @@ const htest = @import("test.zig");
8484test "hmac md5" {
8585 var out: [HmacMd5.mac_length]u8 = undefined;
8686 HmacMd5.create(out[0..], "", "");
87 htest.assertEqual("74e6f7298a9c2d168935f58c001bad88", out[0..]);
87 try htest.assertEqual("74e6f7298a9c2d168935f58c001bad88", out[0..]);
8888
8989 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..]);
9191}
9292
9393test "hmac sha1" {
9494 var out: [HmacSha1.mac_length]u8 = undefined;
9595 HmacSha1.create(out[0..], "", "");
96 htest.assertEqual("fbdb1d1b18aa6c08324b7d64b71fb76370690e1d", out[0..]);
96 try htest.assertEqual("fbdb1d1b18aa6c08324b7d64b71fb76370690e1d", out[0..]);
9797
9898 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..]);
100100}
101101
102102test "hmac sha256" {
103103 var out: [sha2.HmacSha256.mac_length]u8 = undefined;
104104 sha2.HmacSha256.create(out[0..], "", "");
105 htest.assertEqual("b613679a0814d9ec772f95d778c35fc5ff1697c493715653c6c712144292c5ad", out[0..]);
105 try htest.assertEqual("b613679a0814d9ec772f95d778c35fc5ff1697c493715653c6c712144292c5ad", out[0..]);
106106
107107 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..]);
109109}
lib/std/crypto/isap.zig+3-3
......@@ -240,8 +240,8 @@ test "ISAP" {
240240 var msg = "test";
241241 var c: [msg.len]u8 = undefined;
242242 IsapA128A.encrypt(c[0..], &tag, msg[0..], ad, n, k);
243 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..]));
243 try testing.expect(mem.eql(u8, &[_]u8{ 0x8f, 0x68, 0x03, 0x8d }, c[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..]));
245245 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..]));
247247}
lib/std/crypto/md5.zig+10-10
......@@ -241,13 +241,13 @@ pub const Md5 = struct {
241241const htest = @import("test.zig");
242242
243243test "md5 single" {
244 htest.assertEqualHash(Md5, "d41d8cd98f00b204e9800998ecf8427e", "");
245 htest.assertEqualHash(Md5, "0cc175b9c0f1b6a831c399e269772661", "a");
246 htest.assertEqualHash(Md5, "900150983cd24fb0d6963f7d28e17f72", "abc");
247 htest.assertEqualHash(Md5, "f96b697d7cb7938d525a2f31aaf161d0", "message digest");
248 htest.assertEqualHash(Md5, "c3fcd3d76192e4007dfb496cca67e13b", "abcdefghijklmnopqrstuvwxyz");
249 htest.assertEqualHash(Md5, "d174ab98d277d9f5a5611c2c9f419d9f", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
250 htest.assertEqualHash(Md5, "57edf4a22be3c955ac49da2e2107b67a", "12345678901234567890123456789012345678901234567890123456789012345678901234567890");
244 try htest.assertEqualHash(Md5, "d41d8cd98f00b204e9800998ecf8427e", "");
245 try htest.assertEqualHash(Md5, "0cc175b9c0f1b6a831c399e269772661", "a");
246 try htest.assertEqualHash(Md5, "900150983cd24fb0d6963f7d28e17f72", "abc");
247 try htest.assertEqualHash(Md5, "f96b697d7cb7938d525a2f31aaf161d0", "message digest");
248 try htest.assertEqualHash(Md5, "c3fcd3d76192e4007dfb496cca67e13b", "abcdefghijklmnopqrstuvwxyz");
249 try htest.assertEqualHash(Md5, "d174ab98d277d9f5a5611c2c9f419d9f", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
250 try htest.assertEqualHash(Md5, "57edf4a22be3c955ac49da2e2107b67a", "12345678901234567890123456789012345678901234567890123456789012345678901234567890");
251251}
252252
253253test "md5 streaming" {
......@@ -255,12 +255,12 @@ test "md5 streaming" {
255255 var out: [16]u8 = undefined;
256256
257257 h.final(out[0..]);
258 htest.assertEqual("d41d8cd98f00b204e9800998ecf8427e", out[0..]);
258 try htest.assertEqual("d41d8cd98f00b204e9800998ecf8427e", out[0..]);
259259
260260 h = Md5.init(.{});
261261 h.update("abc");
262262 h.final(out[0..]);
263 htest.assertEqual("900150983cd24fb0d6963f7d28e17f72", out[0..]);
263 try htest.assertEqual("900150983cd24fb0d6963f7d28e17f72", out[0..]);
264264
265265 h = Md5.init(.{});
266266 h.update("a");
......@@ -268,7 +268,7 @@ test "md5 streaming" {
268268 h.update("c");
269269 h.final(out[0..]);
270270
271 htest.assertEqual("900150983cd24fb0d6963f7d28e17f72", out[0..]);
271 try htest.assertEqual("900150983cd24fb0d6963f7d28e17f72", out[0..]);
272272}
273273
274274test "md5 aligned final" {
lib/std/crypto/pbkdf2.zig+6-6
......@@ -168,7 +168,7 @@ test "RFC 6070 one iteration" {
168168
169169 const expected = "0c60c80f961f0e71f3a9b524af6012062fe037a6";
170170
171 htest.assertEqual(expected, dk[0..]);
171 try htest.assertEqual(expected, dk[0..]);
172172}
173173
174174test "RFC 6070 two iterations" {
......@@ -183,7 +183,7 @@ test "RFC 6070 two iterations" {
183183
184184 const expected = "ea6c014dc72d6f8ccd1ed92ace1d41f0d8de8957";
185185
186 htest.assertEqual(expected, dk[0..]);
186 try htest.assertEqual(expected, dk[0..]);
187187}
188188
189189test "RFC 6070 4096 iterations" {
......@@ -198,7 +198,7 @@ test "RFC 6070 4096 iterations" {
198198
199199 const expected = "4b007901b765489abead49d926f721d065a429c1";
200200
201 htest.assertEqual(expected, dk[0..]);
201 try htest.assertEqual(expected, dk[0..]);
202202}
203203
204204test "RFC 6070 16,777,216 iterations" {
......@@ -218,7 +218,7 @@ test "RFC 6070 16,777,216 iterations" {
218218
219219 const expected = "eefe3d61cd4da4e4e9945b3d6ba2158c2634e984";
220220
221 htest.assertEqual(expected, dk[0..]);
221 try htest.assertEqual(expected, dk[0..]);
222222}
223223
224224test "RFC 6070 multi-block salt and password" {
......@@ -233,7 +233,7 @@ test "RFC 6070 multi-block salt and password" {
233233
234234 const expected = "3d2eec4fe41c849b80c8d83662c0e44a8b291a964cf2f07038";
235235
236 htest.assertEqual(expected, dk[0..]);
236 try htest.assertEqual(expected, dk[0..]);
237237}
238238
239239test "RFC 6070 embedded NUL" {
......@@ -248,7 +248,7 @@ test "RFC 6070 embedded NUL" {
248248
249249 const expected = "56fa6aa75548099dcc37d7f03425e0c3";
250250
251 htest.assertEqual(expected, dk[0..]);
251 try htest.assertEqual(expected, dk[0..]);
252252}
253253
254254test "Very large dk_len" {
lib/std/crypto/pcurves/tests.zig+9-9
......@@ -17,7 +17,7 @@ test "p256 ECDH key exchange" {
1717 const dhB = try P256.basePoint.mul(dhb, .Little);
1818 const shareda = try dhA.mul(dhb, .Little);
1919 const sharedb = try dhB.mul(dha, .Little);
20 testing.expect(shareda.equivalent(sharedb));
20 try testing.expect(shareda.equivalent(sharedb));
2121}
2222
2323test "p256 point from affine coordinates" {
......@@ -28,7 +28,7 @@ test "p256 point from affine coordinates" {
2828 var ys: [32]u8 = undefined;
2929 _ = try fmt.hexToBytes(&ys, yh);
3030 var p = try P256.fromSerializedAffineCoordinates(xs, ys, .Big);
31 testing.expect(p.equivalent(P256.basePoint));
31 try testing.expect(p.equivalent(P256.basePoint));
3232}
3333
3434test "p256 test vectors" {
......@@ -50,7 +50,7 @@ test "p256 test vectors" {
5050 p = p.add(P256.basePoint);
5151 var xs: [32]u8 = undefined;
5252 _ = try fmt.hexToBytes(&xs, xh);
53 testing.expectEqualSlices(u8, &x.toBytes(.Big), &xs);
53 try testing.expectEqualSlices(u8, &x.toBytes(.Big), &xs);
5454 }
5555}
5656
......@@ -67,7 +67,7 @@ test "p256 test vectors - doubling" {
6767 p = p.dbl();
6868 var xs: [32]u8 = undefined;
6969 _ = try fmt.hexToBytes(&xs, xh);
70 testing.expectEqualSlices(u8, &x.toBytes(.Big), &xs);
70 try testing.expectEqualSlices(u8, &x.toBytes(.Big), &xs);
7171 }
7272}
7373
......@@ -75,29 +75,29 @@ test "p256 compressed sec1 encoding/decoding" {
7575 const p = P256.random();
7676 const s = p.toCompressedSec1();
7777 const q = try P256.fromSec1(&s);
78 testing.expect(p.equivalent(q));
78 try testing.expect(p.equivalent(q));
7979}
8080
8181test "p256 uncompressed sec1 encoding/decoding" {
8282 const p = P256.random();
8383 const s = p.toUncompressedSec1();
8484 const q = try P256.fromSec1(&s);
85 testing.expect(p.equivalent(q));
85 try testing.expect(p.equivalent(q));
8686}
8787
8888test "p256 public key is the neutral element" {
8989 const n = P256.scalar.Scalar.zero.toBytes(.Little);
9090 const p = P256.random();
91 testing.expectError(error.IdentityElement, p.mul(n, .Little));
91 try testing.expectError(error.IdentityElement, p.mul(n, .Little));
9292}
9393
9494test "p256 public key is the neutral element (public verification)" {
9595 const n = P256.scalar.Scalar.zero.toBytes(.Little);
9696 const p = P256.random();
97 testing.expectError(error.IdentityElement, p.mulPublic(n, .Little));
97 try testing.expectError(error.IdentityElement, p.mulPublic(n, .Little));
9898}
9999
100100test "p256 field element non-canonical encoding" {
101101 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));
103103}
lib/std/crypto/poly1305.zig+1-1
......@@ -216,5 +216,5 @@ test "poly1305 rfc7439 vector1" {
216216 var mac: [16]u8 = undefined;
217217 Poly1305.create(mac[0..], msg, key);
218218
219 std.testing.expectEqualSlices(u8, expected_mac, &mac);
219 try std.testing.expectEqualSlices(u8, expected_mac, &mac);
220220}
lib/std/crypto/salsa20.zig+3-3
......@@ -561,11 +561,11 @@ test "(x)salsa20" {
561561 var c: [msg.len]u8 = undefined;
562562
563563 Salsa20.xor(&c, msg[0..], 0, key, nonce);
564 htest.assertEqual("30ff9933aa6534ff5207142593cd1fca4b23bdd8", c[0..]);
564 try htest.assertEqual("30ff9933aa6534ff5207142593cd1fca4b23bdd8", c[0..]);
565565
566566 const extended_nonce = [_]u8{0x42} ** 24;
567567 XSalsa20.xor(&c, msg[0..], 0, key, extended_nonce);
568 htest.assertEqual("b4ab7d82e750ec07644fa3281bce6cd91d4243f9", c[0..]);
568 try htest.assertEqual("b4ab7d82e750ec07644fa3281bce6cd91d4243f9", c[0..]);
569569}
570570
571571test "xsalsa20poly1305" {
......@@ -628,5 +628,5 @@ test "secretbox twoblocks" {
628628 const msg = [_]u8{'a'} ** 97;
629629 var ciphertext: [msg.len + SecretBox.tag_length]u8 = undefined;
630630 SecretBox.seal(&ciphertext, &msg, nonce, key);
631 htest.assertEqual("b05760e217288ba079caa2fd57fd3701784974ffcfda20fe523b89211ad8af065a6eb37cdb29d51aca5bd75dafdd21d18b044c54bb7c526cf576c94ee8900f911ceab0147e82b667a28c52d58ceb29554ff45471224d37b03256b01c119b89ff6d36855de8138d103386dbc9d971f52261", &ciphertext);
631 try htest.assertEqual("b05760e217288ba079caa2fd57fd3701784974ffcfda20fe523b89211ad8af065a6eb37cdb29d51aca5bd75dafdd21d18b044c54bb7c526cf576c94ee8900f911ceab0147e82b667a28c52d58ceb29554ff45471224d37b03256b01c119b89ff6d36855de8138d103386dbc9d971f52261", &ciphertext);
632632}
lib/std/crypto/sha1.zig+6-6
......@@ -265,9 +265,9 @@ pub const Sha1 = struct {
265265const htest = @import("test.zig");
266266
267267test "sha1 single" {
268 htest.assertEqualHash(Sha1, "da39a3ee5e6b4b0d3255bfef95601890afd80709", "");
269 htest.assertEqualHash(Sha1, "a9993e364706816aba3e25717850c26c9cd0d89d", "abc");
270 htest.assertEqualHash(Sha1, "a49b2446a02c645bf419f995b67091253a04a259", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
268 try htest.assertEqualHash(Sha1, "da39a3ee5e6b4b0d3255bfef95601890afd80709", "");
269 try htest.assertEqualHash(Sha1, "a9993e364706816aba3e25717850c26c9cd0d89d", "abc");
270 try htest.assertEqualHash(Sha1, "a49b2446a02c645bf419f995b67091253a04a259", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
271271}
272272
273273test "sha1 streaming" {
......@@ -275,19 +275,19 @@ test "sha1 streaming" {
275275 var out: [20]u8 = undefined;
276276
277277 h.final(&out);
278 htest.assertEqual("da39a3ee5e6b4b0d3255bfef95601890afd80709", out[0..]);
278 try htest.assertEqual("da39a3ee5e6b4b0d3255bfef95601890afd80709", out[0..]);
279279
280280 h = Sha1.init(.{});
281281 h.update("abc");
282282 h.final(&out);
283 htest.assertEqual("a9993e364706816aba3e25717850c26c9cd0d89d", out[0..]);
283 try htest.assertEqual("a9993e364706816aba3e25717850c26c9cd0d89d", out[0..]);
284284
285285 h = Sha1.init(.{});
286286 h.update("a");
287287 h.update("b");
288288 h.update("c");
289289 h.final(&out);
290 htest.assertEqual("a9993e364706816aba3e25717850c26c9cd0d89d", out[0..]);
290 try htest.assertEqual("a9993e364706816aba3e25717850c26c9cd0d89d", out[0..]);
291291}
292292
293293test "sha1 aligned final" {
lib/std/crypto/sha2.zig+24-24
......@@ -285,9 +285,9 @@ fn Sha2x32(comptime params: Sha2Params32) type {
285285}
286286
287287test "sha224 single" {
288 htest.assertEqualHash(Sha224, "d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f", "");
289 htest.assertEqualHash(Sha224, "23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", "abc");
290 htest.assertEqualHash(Sha224, "c97ca9a559850ce97a04a96def6d99a9e0e0e2ab14e6b8df265fc0b3", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
288 try htest.assertEqualHash(Sha224, "d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f", "");
289 try htest.assertEqualHash(Sha224, "23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", "abc");
290 try htest.assertEqualHash(Sha224, "c97ca9a559850ce97a04a96def6d99a9e0e0e2ab14e6b8df265fc0b3", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
291291}
292292
293293test "sha224 streaming" {
......@@ -295,25 +295,25 @@ test "sha224 streaming" {
295295 var out: [28]u8 = undefined;
296296
297297 h.final(out[0..]);
298 htest.assertEqual("d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f", out[0..]);
298 try htest.assertEqual("d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f", out[0..]);
299299
300300 h = Sha224.init(.{});
301301 h.update("abc");
302302 h.final(out[0..]);
303 htest.assertEqual("23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", out[0..]);
303 try htest.assertEqual("23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", out[0..]);
304304
305305 h = Sha224.init(.{});
306306 h.update("a");
307307 h.update("b");
308308 h.update("c");
309309 h.final(out[0..]);
310 htest.assertEqual("23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", out[0..]);
310 try htest.assertEqual("23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", out[0..]);
311311}
312312
313313test "sha256 single" {
314 htest.assertEqualHash(Sha256, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "");
315 htest.assertEqualHash(Sha256, "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", "abc");
316 htest.assertEqualHash(Sha256, "cf5b16a778af8380036ce59e7b0492370b249b11e8f07a51afac45037afee9d1", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
314 try htest.assertEqualHash(Sha256, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "");
315 try htest.assertEqualHash(Sha256, "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", "abc");
316 try htest.assertEqualHash(Sha256, "cf5b16a778af8380036ce59e7b0492370b249b11e8f07a51afac45037afee9d1", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
317317}
318318
319319test "sha256 streaming" {
......@@ -321,19 +321,19 @@ test "sha256 streaming" {
321321 var out: [32]u8 = undefined;
322322
323323 h.final(out[0..]);
324 htest.assertEqual("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", out[0..]);
324 try htest.assertEqual("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", out[0..]);
325325
326326 h = Sha256.init(.{});
327327 h.update("abc");
328328 h.final(out[0..]);
329 htest.assertEqual("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", out[0..]);
329 try htest.assertEqual("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", out[0..]);
330330
331331 h = Sha256.init(.{});
332332 h.update("a");
333333 h.update("b");
334334 h.update("c");
335335 h.final(out[0..]);
336 htest.assertEqual("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", out[0..]);
336 try htest.assertEqual("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", out[0..]);
337337}
338338
339339test "sha256 aligned final" {
......@@ -675,13 +675,13 @@ fn Sha2x64(comptime params: Sha2Params64) type {
675675
676676test "sha384 single" {
677677 const h1 = "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b";
678 htest.assertEqualHash(Sha384, h1, "");
678 try htest.assertEqualHash(Sha384, h1, "");
679679
680680 const h2 = "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7";
681 htest.assertEqualHash(Sha384, h2, "abc");
681 try htest.assertEqualHash(Sha384, h2, "abc");
682682
683683 const h3 = "09330c33f71147e83d192fc782cd1b4753111b173b3b05d22fa08086e3b0f712fcc7c71a557e2db966c3e9fa91746039";
684 htest.assertEqualHash(Sha384, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
684 try htest.assertEqualHash(Sha384, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
685685}
686686
687687test "sha384 streaming" {
......@@ -690,32 +690,32 @@ test "sha384 streaming" {
690690
691691 const h1 = "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b";
692692 h.final(out[0..]);
693 htest.assertEqual(h1, out[0..]);
693 try htest.assertEqual(h1, out[0..]);
694694
695695 const h2 = "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7";
696696
697697 h = Sha384.init(.{});
698698 h.update("abc");
699699 h.final(out[0..]);
700 htest.assertEqual(h2, out[0..]);
700 try htest.assertEqual(h2, out[0..]);
701701
702702 h = Sha384.init(.{});
703703 h.update("a");
704704 h.update("b");
705705 h.update("c");
706706 h.final(out[0..]);
707 htest.assertEqual(h2, out[0..]);
707 try htest.assertEqual(h2, out[0..]);
708708}
709709
710710test "sha512 single" {
711711 const h1 = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e";
712 htest.assertEqualHash(Sha512, h1, "");
712 try htest.assertEqualHash(Sha512, h1, "");
713713
714714 const h2 = "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f";
715 htest.assertEqualHash(Sha512, h2, "abc");
715 try htest.assertEqualHash(Sha512, h2, "abc");
716716
717717 const h3 = "8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018501d289e4900f7e4331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909";
718 htest.assertEqualHash(Sha512, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
718 try htest.assertEqualHash(Sha512, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
719719}
720720
721721test "sha512 streaming" {
......@@ -724,21 +724,21 @@ test "sha512 streaming" {
724724
725725 const h1 = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e";
726726 h.final(out[0..]);
727 htest.assertEqual(h1, out[0..]);
727 try htest.assertEqual(h1, out[0..]);
728728
729729 const h2 = "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f";
730730
731731 h = Sha512.init(.{});
732732 h.update("abc");
733733 h.final(out[0..]);
734 htest.assertEqual(h2, out[0..]);
734 try htest.assertEqual(h2, out[0..]);
735735
736736 h = Sha512.init(.{});
737737 h.update("a");
738738 h.update("b");
739739 h.update("c");
740740 h.final(out[0..]);
741 htest.assertEqual(h2, out[0..]);
741 try htest.assertEqual(h2, out[0..]);
742742}
743743
744744test "sha512 aligned final" {
lib/std/crypto/sha3.zig+30-30
......@@ -169,9 +169,9 @@ fn keccakF(comptime F: usize, d: *[F / 8]u8) void {
169169}
170170
171171test "sha3-224 single" {
172 htest.assertEqualHash(Sha3_224, "6b4e03423667dbb73b6e15454f0eb1abd4597f9a1b078e3f5b5a6bc7", "");
173 htest.assertEqualHash(Sha3_224, "e642824c3f8cf24ad09234ee7d3c766fc9a3a5168d0c94ad73b46fdf", "abc");
174 htest.assertEqualHash(Sha3_224, "543e6868e1666c1a643630df77367ae5a62a85070a51c14cbf665cbc", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
172 try htest.assertEqualHash(Sha3_224, "6b4e03423667dbb73b6e15454f0eb1abd4597f9a1b078e3f5b5a6bc7", "");
173 try htest.assertEqualHash(Sha3_224, "e642824c3f8cf24ad09234ee7d3c766fc9a3a5168d0c94ad73b46fdf", "abc");
174 try htest.assertEqualHash(Sha3_224, "543e6868e1666c1a643630df77367ae5a62a85070a51c14cbf665cbc", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
175175}
176176
177177test "sha3-224 streaming" {
......@@ -179,25 +179,25 @@ test "sha3-224 streaming" {
179179 var out: [28]u8 = undefined;
180180
181181 h.final(out[0..]);
182 htest.assertEqual("6b4e03423667dbb73b6e15454f0eb1abd4597f9a1b078e3f5b5a6bc7", out[0..]);
182 try htest.assertEqual("6b4e03423667dbb73b6e15454f0eb1abd4597f9a1b078e3f5b5a6bc7", out[0..]);
183183
184184 h = Sha3_224.init(.{});
185185 h.update("abc");
186186 h.final(out[0..]);
187 htest.assertEqual("e642824c3f8cf24ad09234ee7d3c766fc9a3a5168d0c94ad73b46fdf", out[0..]);
187 try htest.assertEqual("e642824c3f8cf24ad09234ee7d3c766fc9a3a5168d0c94ad73b46fdf", out[0..]);
188188
189189 h = Sha3_224.init(.{});
190190 h.update("a");
191191 h.update("b");
192192 h.update("c");
193193 h.final(out[0..]);
194 htest.assertEqual("e642824c3f8cf24ad09234ee7d3c766fc9a3a5168d0c94ad73b46fdf", out[0..]);
194 try htest.assertEqual("e642824c3f8cf24ad09234ee7d3c766fc9a3a5168d0c94ad73b46fdf", out[0..]);
195195}
196196
197197test "sha3-256 single" {
198 htest.assertEqualHash(Sha3_256, "a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a", "");
199 htest.assertEqualHash(Sha3_256, "3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532", "abc");
200 htest.assertEqualHash(Sha3_256, "916f6061fe879741ca6469b43971dfdb28b1a32dc36cb3254e812be27aad1d18", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
198 try htest.assertEqualHash(Sha3_256, "a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a", "");
199 try htest.assertEqualHash(Sha3_256, "3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532", "abc");
200 try htest.assertEqualHash(Sha3_256, "916f6061fe879741ca6469b43971dfdb28b1a32dc36cb3254e812be27aad1d18", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
201201}
202202
203203test "sha3-256 streaming" {
......@@ -205,19 +205,19 @@ test "sha3-256 streaming" {
205205 var out: [32]u8 = undefined;
206206
207207 h.final(out[0..]);
208 htest.assertEqual("a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a", out[0..]);
208 try htest.assertEqual("a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a", out[0..]);
209209
210210 h = Sha3_256.init(.{});
211211 h.update("abc");
212212 h.final(out[0..]);
213 htest.assertEqual("3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532", out[0..]);
213 try htest.assertEqual("3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532", out[0..]);
214214
215215 h = Sha3_256.init(.{});
216216 h.update("a");
217217 h.update("b");
218218 h.update("c");
219219 h.final(out[0..]);
220 htest.assertEqual("3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532", out[0..]);
220 try htest.assertEqual("3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532", out[0..]);
221221}
222222
223223test "sha3-256 aligned final" {
......@@ -231,11 +231,11 @@ test "sha3-256 aligned final" {
231231
232232test "sha3-384 single" {
233233 const h1 = "0c63a75b845e4f7d01107d852e4c2485c51a50aaaa94fc61995e71bbee983a2ac3713831264adb47fb6bd1e058d5f004";
234 htest.assertEqualHash(Sha3_384, h1, "");
234 try htest.assertEqualHash(Sha3_384, h1, "");
235235 const h2 = "ec01498288516fc926459f58e2c6ad8df9b473cb0fc08c2596da7cf0e49be4b298d88cea927ac7f539f1edf228376d25";
236 htest.assertEqualHash(Sha3_384, h2, "abc");
236 try htest.assertEqualHash(Sha3_384, h2, "abc");
237237 const h3 = "79407d3b5916b59c3e30b09822974791c313fb9ecc849e406f23592d04f625dc8c709b98b43b3852b337216179aa7fc7";
238 htest.assertEqualHash(Sha3_384, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
238 try htest.assertEqualHash(Sha3_384, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
239239}
240240
241241test "sha3-384 streaming" {
......@@ -244,29 +244,29 @@ test "sha3-384 streaming" {
244244
245245 const h1 = "0c63a75b845e4f7d01107d852e4c2485c51a50aaaa94fc61995e71bbee983a2ac3713831264adb47fb6bd1e058d5f004";
246246 h.final(out[0..]);
247 htest.assertEqual(h1, out[0..]);
247 try htest.assertEqual(h1, out[0..]);
248248
249249 const h2 = "ec01498288516fc926459f58e2c6ad8df9b473cb0fc08c2596da7cf0e49be4b298d88cea927ac7f539f1edf228376d25";
250250 h = Sha3_384.init(.{});
251251 h.update("abc");
252252 h.final(out[0..]);
253 htest.assertEqual(h2, out[0..]);
253 try htest.assertEqual(h2, out[0..]);
254254
255255 h = Sha3_384.init(.{});
256256 h.update("a");
257257 h.update("b");
258258 h.update("c");
259259 h.final(out[0..]);
260 htest.assertEqual(h2, out[0..]);
260 try htest.assertEqual(h2, out[0..]);
261261}
262262
263263test "sha3-512 single" {
264264 const h1 = "a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26";
265 htest.assertEqualHash(Sha3_512, h1, "");
265 try htest.assertEqualHash(Sha3_512, h1, "");
266266 const h2 = "b751850b1a57168a5693cd924b6b096e08f621827444f70d884f5d0240d2712e10e116e9192af3c91a7ec57647e3934057340b4cf408d5a56592f8274eec53f0";
267 htest.assertEqualHash(Sha3_512, h2, "abc");
267 try htest.assertEqualHash(Sha3_512, h2, "abc");
268268 const h3 = "afebb2ef542e6579c50cad06d2e578f9f8dd6881d7dc824d26360feebf18a4fa73e3261122948efcfd492e74e82e2189ed0fb440d187f382270cb455f21dd185";
269 htest.assertEqualHash(Sha3_512, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
269 try htest.assertEqualHash(Sha3_512, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
270270}
271271
272272test "sha3-512 streaming" {
......@@ -275,20 +275,20 @@ test "sha3-512 streaming" {
275275
276276 const h1 = "a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26";
277277 h.final(out[0..]);
278 htest.assertEqual(h1, out[0..]);
278 try htest.assertEqual(h1, out[0..]);
279279
280280 const h2 = "b751850b1a57168a5693cd924b6b096e08f621827444f70d884f5d0240d2712e10e116e9192af3c91a7ec57647e3934057340b4cf408d5a56592f8274eec53f0";
281281 h = Sha3_512.init(.{});
282282 h.update("abc");
283283 h.final(out[0..]);
284 htest.assertEqual(h2, out[0..]);
284 try htest.assertEqual(h2, out[0..]);
285285
286286 h = Sha3_512.init(.{});
287287 h.update("a");
288288 h.update("b");
289289 h.update("c");
290290 h.final(out[0..]);
291 htest.assertEqual(h2, out[0..]);
291 try htest.assertEqual(h2, out[0..]);
292292}
293293
294294test "sha3-512 aligned final" {
......@@ -301,13 +301,13 @@ test "sha3-512 aligned final" {
301301}
302302
303303test "keccak-256 single" {
304 htest.assertEqualHash(Keccak_256, "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470", "");
305 htest.assertEqualHash(Keccak_256, "4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45", "abc");
306 htest.assertEqualHash(Keccak_256, "f519747ed599024f3882238e5ab43960132572b7345fbeb9a90769dafd21ad67", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
304 try htest.assertEqualHash(Keccak_256, "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470", "");
305 try htest.assertEqualHash(Keccak_256, "4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45", "abc");
306 try htest.assertEqualHash(Keccak_256, "f519747ed599024f3882238e5ab43960132572b7345fbeb9a90769dafd21ad67", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
307307}
308308
309309test "keccak-512 single" {
310 htest.assertEqualHash(Keccak_512, "0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e", "");
311 htest.assertEqualHash(Keccak_512, "18587dc2ea106b9a1563e32b3312421ca164c7f1f07bc922a9c83d77cea3a1e5d0c69910739025372dc14ac9642629379540c17e2a65b19d77aa511a9d00bb96", "abc");
312 htest.assertEqualHash(Keccak_512, "ac2fb35251825d3aa48468a9948c0a91b8256f6d97d8fa4160faff2dd9dfcc24f3f1db7a983dad13d53439ccac0b37e24037e7b95f80f59f37a2f683c4ba4682", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
310 try htest.assertEqualHash(Keccak_512, "0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e", "");
311 try htest.assertEqualHash(Keccak_512, "18587dc2ea106b9a1563e32b3312421ca164c7f1f07bc922a9c83d77cea3a1e5d0c69910739025372dc14ac9642629379540c17e2a65b19d77aa511a9d00bb96", "abc");
312 try htest.assertEqualHash(Keccak_512, "ac2fb35251825d3aa48468a9948c0a91b8256f6d97d8fa4160faff2dd9dfcc24f3f1db7a983dad13d53439ccac0b37e24037e7b95f80f59f37a2f683c4ba4682", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
313313}
lib/std/crypto/siphash.zig+3-3
......@@ -319,7 +319,7 @@ test "siphash64-2-4 sanity" {
319319
320320 var out: [siphash.mac_length]u8 = undefined;
321321 siphash.create(&out, buffer[0..i], test_key);
322 testing.expectEqual(out, vector);
322 try testing.expectEqual(out, vector);
323323 }
324324}
325325
......@@ -399,7 +399,7 @@ test "siphash128-2-4 sanity" {
399399
400400 var out: [siphash.mac_length]u8 = undefined;
401401 siphash.create(&out, buffer[0..i], test_key[0..]);
402 testing.expectEqual(out, vector);
402 try testing.expectEqual(out, vector);
403403 }
404404}
405405
......@@ -423,6 +423,6 @@ test "iterative non-divisible update" {
423423 }
424424 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);
427427 }
428428}
lib/std/crypto/test.zig+4-4
......@@ -8,19 +8,19 @@ const testing = std.testing;
88const fmt = std.fmt;
99
1010// 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 {
1212 var h: [Hasher.digest_length]u8 = undefined;
1313 Hasher.hash(input, &h, .{});
1414
15 assertEqual(expected_hex, &h);
15 try assertEqual(expected_hex, &h);
1616}
1717
1818// 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 {
2020 var expected_bytes: [expected_hex.len / 2]u8 = undefined;
2121 for (expected_bytes) |*r, i| {
2222 r.* = fmt.parseInt(u8, expected_hex[2 * i .. 2 * i + 2], 16) catch unreachable;
2323 }
2424
25 testing.expectEqualSlices(u8, &expected_bytes, input);
25 try testing.expectEqualSlices(u8, &expected_bytes, input);
2626}
lib/std/crypto/utils.zig+11-11
......@@ -92,9 +92,9 @@ test "crypto.utils.timingSafeEql" {
9292 var b: [100]u8 = undefined;
9393 std.crypto.random.bytes(a[0..]);
9494 std.crypto.random.bytes(b[0..]);
95 testing.expect(!timingSafeEql([100]u8, a, b));
95 try testing.expect(!timingSafeEql([100]u8, a, b));
9696 mem.copy(u8, a[0..], b[0..]);
97 testing.expect(timingSafeEql([100]u8, a, b));
97 try testing.expect(timingSafeEql([100]u8, a, b));
9898}
9999
100100test "crypto.utils.timingSafeEql (vectors)" {
......@@ -104,22 +104,22 @@ test "crypto.utils.timingSafeEql (vectors)" {
104104 std.crypto.random.bytes(b[0..]);
105105 const v1: std.meta.Vector(100, u8) = a;
106106 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));
108108 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));
110110}
111111
112112test "crypto.utils.timingSafeCompare" {
113113 var a = [_]u8{10} ** 32;
114114 var b = [_]u8{10} ** 32;
115 testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .eq);
116 testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .eq);
115 try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .eq);
116 try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .eq);
117117 a[31] = 1;
118 testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .lt);
119 testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .lt);
118 try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .lt);
119 try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .lt);
120120 a[0] = 20;
121 testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .gt);
122 testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .lt);
121 try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .gt);
122 try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .lt);
123123}
124124
125125test "crypto.utils.secureZero" {
......@@ -129,5 +129,5 @@ test "crypto.utils.secureZero" {
129129 mem.set(u8, a[0..], 0);
130130 secureZero(u8, b[0..]);
131131
132 testing.expectEqualSlices(u8, a[0..], b[0..]);
132 try testing.expectEqualSlices(u8, a[0..], b[0..]);
133133}
lib/std/cstr.zig+7-7
......@@ -27,13 +27,13 @@ pub fn cmp(a: [*:0]const u8, b: [*:0]const u8) i8 {
2727}
2828
2929test "cstr fns" {
30 comptime testCStrFnsImpl();
31 testCStrFnsImpl();
30 comptime try testCStrFnsImpl();
31 try testCStrFnsImpl();
3232}
3333
34fn testCStrFnsImpl() void {
35 testing.expect(cmp("aoeu", "aoez") == -1);
36 testing.expect(mem.len("123456789") == 9);
34fn testCStrFnsImpl() !void {
35 try testing.expect(cmp("aoeu", "aoez") == -1);
36 try testing.expect(mem.len("123456789") == 9);
3737}
3838
3939/// 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 {
4848test "addNullByte" {
4949 const slice = try addNullByte(std.testing.allocator, "hello"[0..4]);
5050 defer std.testing.allocator.free(slice);
51 testing.expect(slice.len == 4);
52 testing.expect(slice[4] == 0);
51 try testing.expect(slice.len == 4);
52 try testing.expect(slice[4] == 0);
5353}
5454
5555pub const NullTerminated2DArray = struct {
lib/std/dynamic_library.zig+1-1
......@@ -408,7 +408,7 @@ test "dynamic_library" {
408408 };
409409
410410 const dynlib = DynLib.open(libname) catch |err| {
411 testing.expect(err == error.FileNotFound);
411 try testing.expect(err == error.FileNotFound);
412412 return;
413413 };
414414}
lib/std/elf.zig+1-1
......@@ -565,7 +565,7 @@ test "bswapAllFields" {
565565 .ch_addralign = 0x12124242,
566566 };
567567 bswapAllFields(Elf32_Chdr, &s);
568 std.testing.expectEqual(Elf32_Chdr{
568 try std.testing.expectEqual(Elf32_Chdr{
569569 .ch_type = 0x34123412,
570570 .ch_size = 0x78567856,
571571 .ch_addralign = 0x42421212,
lib/std/enums.zig+275-275
......@@ -56,10 +56,10 @@ test "std.enums.valuesFromFields" {
5656 .{ .name = "a", .value = undefined },
5757 .{ .name = "d", .value = undefined },
5858 });
59 testing.expectEqual(E.b, fields[0]);
60 testing.expectEqual(E.a, fields[1]);
61 testing.expectEqual(E.d, fields[2]); // a == d
62 testing.expectEqual(E.d, fields[3]);
59 try testing.expectEqual(E.b, fields[0]);
60 try testing.expectEqual(E.a, fields[1]);
61 try testing.expectEqual(E.d, fields[2]); // a == d
62 try testing.expectEqual(E.d, fields[3]);
6363}
6464
6565/// Returns the set of all named values in the given enum, in
......@@ -70,7 +70,7 @@ pub fn values(comptime E: type) []const E {
7070
7171test "std.enum.values" {
7272 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));
7474}
7575
7676/// 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 {
8282
8383test "std.enum.uniqueValues" {
8484 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
8787 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));
8989}
9090
9191/// Returns the set of all unique field values in the given enum, in
......@@ -179,10 +179,10 @@ test "std.enums.directEnumArray" {
179179 .c = true,
180180 });
181181
182 testing.expectEqual([7]bool, @TypeOf(array));
183 testing.expectEqual(true, array[4]);
184 testing.expectEqual(false, array[6]);
185 testing.expectEqual(true, array[2]);
182 try testing.expectEqual([7]bool, @TypeOf(array));
183 try testing.expectEqual(true, array[4]);
184 try testing.expectEqual(false, array[6]);
185 try testing.expectEqual(true, array[2]);
186186}
187187
188188/// Initializes an array of Data which can be indexed by
......@@ -220,10 +220,10 @@ test "std.enums.directEnumArrayDefault" {
220220 .b = runtime_false,
221221 });
222222
223 testing.expectEqual([7]bool, @TypeOf(array));
224 testing.expectEqual(true, array[4]);
225 testing.expectEqual(false, array[6]);
226 testing.expectEqual(false, array[2]);
223 try testing.expectEqual([7]bool, @TypeOf(array));
224 try testing.expectEqual(true, array[4]);
225 try testing.expectEqual(false, array[6]);
226 try testing.expectEqual(false, array[2]);
227227}
228228
229229/// 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 {
250250test "std.enums.nameCast" {
251251 const A = enum { a = 0, b = 1 };
252252 const B = enum { a = 1, b = 0 };
253 testing.expectEqual(A.a, nameCast(A, .a));
254 testing.expectEqual(A.a, nameCast(A, A.a));
255 testing.expectEqual(A.a, nameCast(A, B.a));
256 testing.expectEqual(A.a, nameCast(A, "a"));
257 testing.expectEqual(A.a, nameCast(A, @as(*const [1]u8, "a")));
258 testing.expectEqual(A.a, nameCast(A, @as([:0]const u8, "a")));
259 testing.expectEqual(A.a, nameCast(A, @as([]const u8, "a")));
260
261 testing.expectEqual(B.a, nameCast(B, .a));
262 testing.expectEqual(B.a, nameCast(B, A.a));
263 testing.expectEqual(B.a, nameCast(B, B.a));
264 testing.expectEqual(B.a, nameCast(B, "a"));
265
266 testing.expectEqual(B.b, nameCast(B, .b));
267 testing.expectEqual(B.b, nameCast(B, A.b));
268 testing.expectEqual(B.b, nameCast(B, B.b));
269 testing.expectEqual(B.b, nameCast(B, "b"));
253 try testing.expectEqual(A.a, nameCast(A, .a));
254 try testing.expectEqual(A.a, nameCast(A, A.a));
255 try testing.expectEqual(A.a, nameCast(A, B.a));
256 try testing.expectEqual(A.a, nameCast(A, "a"));
257 try testing.expectEqual(A.a, nameCast(A, @as(*const [1]u8, "a")));
258 try testing.expectEqual(A.a, nameCast(A, @as([:0]const u8, "a")));
259 try testing.expectEqual(A.a, nameCast(A, @as([]const u8, "a")));
260
261 try testing.expectEqual(B.a, nameCast(B, .a));
262 try testing.expectEqual(B.a, nameCast(B, A.a));
263 try testing.expectEqual(B.a, nameCast(B, B.a));
264 try testing.expectEqual(B.a, nameCast(B, "a"));
265
266 try testing.expectEqual(B.b, nameCast(B, .b));
267 try testing.expectEqual(B.b, nameCast(B, A.b));
268 try testing.expectEqual(B.b, nameCast(B, B.b));
269 try testing.expectEqual(B.b, nameCast(B, "b"));
270270}
271271
272272/// A set of enum elements, backed by a bitfield. If the enum
......@@ -851,202 +851,202 @@ test "std.enums.EnumIndexer dense zeroed" {
851851 const E = enum { b = 1, a = 0, c = 2 };
852852 const Indexer = EnumIndexer(E);
853853 ensureIndexer(Indexer);
854 testing.expectEqual(E, Indexer.Key);
855 testing.expectEqual(@as(usize, 3), Indexer.count);
854 try testing.expectEqual(E, Indexer.Key);
855 try testing.expectEqual(@as(usize, 3), Indexer.count);
856856
857 testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
858 testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
859 testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
857 try testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
858 try testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
859 try testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
860860
861 testing.expectEqual(E.a, Indexer.keyForIndex(0));
862 testing.expectEqual(E.b, Indexer.keyForIndex(1));
863 testing.expectEqual(E.c, Indexer.keyForIndex(2));
861 try testing.expectEqual(E.a, Indexer.keyForIndex(0));
862 try testing.expectEqual(E.b, Indexer.keyForIndex(1));
863 try testing.expectEqual(E.c, Indexer.keyForIndex(2));
864864}
865865
866866test "std.enums.EnumIndexer dense positive" {
867867 const E = enum(u4) { c = 6, a = 4, b = 5 };
868868 const Indexer = EnumIndexer(E);
869869 ensureIndexer(Indexer);
870 testing.expectEqual(E, Indexer.Key);
871 testing.expectEqual(@as(usize, 3), Indexer.count);
870 try testing.expectEqual(E, Indexer.Key);
871 try testing.expectEqual(@as(usize, 3), Indexer.count);
872872
873 testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
874 testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
875 testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
873 try testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
874 try testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
875 try testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
876876
877 testing.expectEqual(E.a, Indexer.keyForIndex(0));
878 testing.expectEqual(E.b, Indexer.keyForIndex(1));
879 testing.expectEqual(E.c, Indexer.keyForIndex(2));
877 try testing.expectEqual(E.a, Indexer.keyForIndex(0));
878 try testing.expectEqual(E.b, Indexer.keyForIndex(1));
879 try testing.expectEqual(E.c, Indexer.keyForIndex(2));
880880}
881881
882882test "std.enums.EnumIndexer dense negative" {
883883 const E = enum(i4) { a = -6, c = -4, b = -5 };
884884 const Indexer = EnumIndexer(E);
885885 ensureIndexer(Indexer);
886 testing.expectEqual(E, Indexer.Key);
887 testing.expectEqual(@as(usize, 3), Indexer.count);
886 try testing.expectEqual(E, Indexer.Key);
887 try testing.expectEqual(@as(usize, 3), Indexer.count);
888888
889 testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
890 testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
891 testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
889 try testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
890 try testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
891 try testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
892892
893 testing.expectEqual(E.a, Indexer.keyForIndex(0));
894 testing.expectEqual(E.b, Indexer.keyForIndex(1));
895 testing.expectEqual(E.c, Indexer.keyForIndex(2));
893 try testing.expectEqual(E.a, Indexer.keyForIndex(0));
894 try testing.expectEqual(E.b, Indexer.keyForIndex(1));
895 try testing.expectEqual(E.c, Indexer.keyForIndex(2));
896896}
897897
898898test "std.enums.EnumIndexer sparse" {
899899 const E = enum(i4) { a = -2, c = 6, b = 4 };
900900 const Indexer = EnumIndexer(E);
901901 ensureIndexer(Indexer);
902 testing.expectEqual(E, Indexer.Key);
903 testing.expectEqual(@as(usize, 3), Indexer.count);
902 try testing.expectEqual(E, Indexer.Key);
903 try testing.expectEqual(@as(usize, 3), Indexer.count);
904904
905 testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
906 testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
907 testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
905 try testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
906 try testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
907 try testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
908908
909 testing.expectEqual(E.a, Indexer.keyForIndex(0));
910 testing.expectEqual(E.b, Indexer.keyForIndex(1));
911 testing.expectEqual(E.c, Indexer.keyForIndex(2));
909 try testing.expectEqual(E.a, Indexer.keyForIndex(0));
910 try testing.expectEqual(E.b, Indexer.keyForIndex(1));
911 try testing.expectEqual(E.c, Indexer.keyForIndex(2));
912912}
913913
914914test "std.enums.EnumIndexer repeats" {
915915 const E = extern enum { a = -2, c = 6, b = 4, b2 = 4 };
916916 const Indexer = EnumIndexer(E);
917917 ensureIndexer(Indexer);
918 testing.expectEqual(E, Indexer.Key);
919 testing.expectEqual(@as(usize, 3), Indexer.count);
918 try testing.expectEqual(E, Indexer.Key);
919 try testing.expectEqual(@as(usize, 3), Indexer.count);
920920
921 testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
922 testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
923 testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
921 try testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
922 try testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
923 try testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
924924
925 testing.expectEqual(E.a, Indexer.keyForIndex(0));
926 testing.expectEqual(E.b, Indexer.keyForIndex(1));
927 testing.expectEqual(E.c, Indexer.keyForIndex(2));
925 try testing.expectEqual(E.a, Indexer.keyForIndex(0));
926 try testing.expectEqual(E.b, Indexer.keyForIndex(1));
927 try testing.expectEqual(E.c, Indexer.keyForIndex(2));
928928}
929929
930930test "std.enums.EnumSet" {
931931 const E = extern enum { a, b, c, d, e = 0 };
932932 const Set = EnumSet(E);
933 testing.expectEqual(E, Set.Key);
934 testing.expectEqual(EnumIndexer(E), Set.Indexer);
935 testing.expectEqual(@as(usize, 4), Set.len);
933 try testing.expectEqual(E, Set.Key);
934 try testing.expectEqual(EnumIndexer(E), Set.Indexer);
935 try testing.expectEqual(@as(usize, 4), Set.len);
936936
937937 // Empty sets
938938 const empty = Set{};
939 comptime testing.expect(empty.count() == 0);
939 comptime try testing.expect(empty.count() == 0);
940940
941941 var empty_b = Set.init(.{});
942 testing.expect(empty_b.count() == 0);
942 try testing.expect(empty_b.count() == 0);
943943
944944 const empty_c = comptime Set.init(.{});
945 comptime testing.expect(empty_c.count() == 0);
945 comptime try testing.expect(empty_c.count() == 0);
946946
947947 const full = Set.initFull();
948 testing.expect(full.count() == Set.len);
948 try testing.expect(full.count() == Set.len);
949949
950950 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));
954 testing.expectEqual(false, empty.contains(.b));
955 testing.expectEqual(false, empty.contains(.c));
956 testing.expectEqual(false, empty.contains(.d));
957 testing.expectEqual(false, empty.contains(.e));
953 try testing.expectEqual(false, empty.contains(.a));
954 try testing.expectEqual(false, empty.contains(.b));
955 try testing.expectEqual(false, empty.contains(.c));
956 try testing.expectEqual(false, empty.contains(.d));
957 try testing.expectEqual(false, empty.contains(.e));
958958 {
959959 var iter = empty_b.iterator();
960 testing.expectEqual(@as(?E, null), iter.next());
960 try testing.expectEqual(@as(?E, null), iter.next());
961961 }
962962
963963 var mut = Set.init(.{
964964 .a = true,
965965 .c = true,
966966 });
967 testing.expectEqual(@as(usize, 2), mut.count());
968 testing.expectEqual(true, mut.contains(.a));
969 testing.expectEqual(false, mut.contains(.b));
970 testing.expectEqual(true, mut.contains(.c));
971 testing.expectEqual(false, mut.contains(.d));
972 testing.expectEqual(true, mut.contains(.e)); // aliases a
967 try testing.expectEqual(@as(usize, 2), mut.count());
968 try testing.expectEqual(true, mut.contains(.a));
969 try testing.expectEqual(false, mut.contains(.b));
970 try testing.expectEqual(true, mut.contains(.c));
971 try testing.expectEqual(false, mut.contains(.d));
972 try testing.expectEqual(true, mut.contains(.e)); // aliases a
973973 {
974974 var it = mut.iterator();
975 testing.expectEqual(@as(?E, .a), it.next());
976 testing.expectEqual(@as(?E, .c), it.next());
977 testing.expectEqual(@as(?E, null), it.next());
975 try testing.expectEqual(@as(?E, .a), it.next());
976 try testing.expectEqual(@as(?E, .c), it.next());
977 try testing.expectEqual(@as(?E, null), it.next());
978978 }
979979
980980 mut.toggleAll();
981 testing.expectEqual(@as(usize, 2), mut.count());
982 testing.expectEqual(false, mut.contains(.a));
983 testing.expectEqual(true, mut.contains(.b));
984 testing.expectEqual(false, mut.contains(.c));
985 testing.expectEqual(true, mut.contains(.d));
986 testing.expectEqual(false, mut.contains(.e)); // aliases a
981 try testing.expectEqual(@as(usize, 2), mut.count());
982 try testing.expectEqual(false, mut.contains(.a));
983 try testing.expectEqual(true, mut.contains(.b));
984 try testing.expectEqual(false, mut.contains(.c));
985 try testing.expectEqual(true, mut.contains(.d));
986 try testing.expectEqual(false, mut.contains(.e)); // aliases a
987987 {
988988 var it = mut.iterator();
989 testing.expectEqual(@as(?E, .b), it.next());
990 testing.expectEqual(@as(?E, .d), it.next());
991 testing.expectEqual(@as(?E, null), it.next());
989 try testing.expectEqual(@as(?E, .b), it.next());
990 try testing.expectEqual(@as(?E, .d), it.next());
991 try testing.expectEqual(@as(?E, null), it.next());
992992 }
993993
994994 mut.toggleSet(Set.init(.{ .a = true, .b = true }));
995 testing.expectEqual(@as(usize, 2), mut.count());
996 testing.expectEqual(true, mut.contains(.a));
997 testing.expectEqual(false, mut.contains(.b));
998 testing.expectEqual(false, mut.contains(.c));
999 testing.expectEqual(true, mut.contains(.d));
1000 testing.expectEqual(true, mut.contains(.e)); // aliases a
995 try testing.expectEqual(@as(usize, 2), mut.count());
996 try testing.expectEqual(true, mut.contains(.a));
997 try testing.expectEqual(false, mut.contains(.b));
998 try testing.expectEqual(false, mut.contains(.c));
999 try testing.expectEqual(true, mut.contains(.d));
1000 try testing.expectEqual(true, mut.contains(.e)); // aliases a
10011001
10021002 mut.setUnion(Set.init(.{ .a = true, .b = true }));
1003 testing.expectEqual(@as(usize, 3), mut.count());
1004 testing.expectEqual(true, mut.contains(.a));
1005 testing.expectEqual(true, mut.contains(.b));
1006 testing.expectEqual(false, mut.contains(.c));
1007 testing.expectEqual(true, mut.contains(.d));
1003 try testing.expectEqual(@as(usize, 3), mut.count());
1004 try testing.expectEqual(true, mut.contains(.a));
1005 try testing.expectEqual(true, mut.contains(.b));
1006 try testing.expectEqual(false, mut.contains(.c));
1007 try testing.expectEqual(true, mut.contains(.d));
10081008
10091009 mut.remove(.c);
10101010 mut.remove(.b);
1011 testing.expectEqual(@as(usize, 2), mut.count());
1012 testing.expectEqual(true, mut.contains(.a));
1013 testing.expectEqual(false, mut.contains(.b));
1014 testing.expectEqual(false, mut.contains(.c));
1015 testing.expectEqual(true, mut.contains(.d));
1011 try testing.expectEqual(@as(usize, 2), mut.count());
1012 try testing.expectEqual(true, mut.contains(.a));
1013 try testing.expectEqual(false, mut.contains(.b));
1014 try testing.expectEqual(false, mut.contains(.c));
1015 try testing.expectEqual(true, mut.contains(.d));
10161016
10171017 mut.setIntersection(Set.init(.{ .a = true, .b = true }));
1018 testing.expectEqual(@as(usize, 1), mut.count());
1019 testing.expectEqual(true, mut.contains(.a));
1020 testing.expectEqual(false, mut.contains(.b));
1021 testing.expectEqual(false, mut.contains(.c));
1022 testing.expectEqual(false, mut.contains(.d));
1018 try testing.expectEqual(@as(usize, 1), mut.count());
1019 try testing.expectEqual(true, mut.contains(.a));
1020 try testing.expectEqual(false, mut.contains(.b));
1021 try testing.expectEqual(false, mut.contains(.c));
1022 try testing.expectEqual(false, mut.contains(.d));
10231023
10241024 mut.insert(.a);
10251025 mut.insert(.b);
1026 testing.expectEqual(@as(usize, 2), mut.count());
1027 testing.expectEqual(true, mut.contains(.a));
1028 testing.expectEqual(true, mut.contains(.b));
1029 testing.expectEqual(false, mut.contains(.c));
1030 testing.expectEqual(false, mut.contains(.d));
1026 try testing.expectEqual(@as(usize, 2), mut.count());
1027 try testing.expectEqual(true, mut.contains(.a));
1028 try testing.expectEqual(true, mut.contains(.b));
1029 try testing.expectEqual(false, mut.contains(.c));
1030 try testing.expectEqual(false, mut.contains(.d));
10311031
10321032 mut.setPresent(.a, false);
10331033 mut.toggle(.b);
10341034 mut.toggle(.c);
10351035 mut.setPresent(.d, true);
1036 testing.expectEqual(@as(usize, 2), mut.count());
1037 testing.expectEqual(false, mut.contains(.a));
1038 testing.expectEqual(false, mut.contains(.b));
1039 testing.expectEqual(true, mut.contains(.c));
1040 testing.expectEqual(true, mut.contains(.d));
1036 try testing.expectEqual(@as(usize, 2), mut.count());
1037 try testing.expectEqual(false, mut.contains(.a));
1038 try testing.expectEqual(false, mut.contains(.b));
1039 try testing.expectEqual(true, mut.contains(.c));
1040 try testing.expectEqual(true, mut.contains(.d));
10411041}
10421042
10431043test "std.enums.EnumArray void" {
10441044 const E = extern enum { a, b, c, d, e = 0 };
10451045 const ArrayVoid = EnumArray(E, void);
1046 testing.expectEqual(E, ArrayVoid.Key);
1047 testing.expectEqual(EnumIndexer(E), ArrayVoid.Indexer);
1048 testing.expectEqual(void, ArrayVoid.Value);
1049 testing.expectEqual(@as(usize, 4), ArrayVoid.len);
1046 try testing.expectEqual(E, ArrayVoid.Key);
1047 try testing.expectEqual(EnumIndexer(E), ArrayVoid.Indexer);
1048 try testing.expectEqual(void, ArrayVoid.Value);
1049 try testing.expectEqual(@as(usize, 4), ArrayVoid.len);
10501050
10511051 const undef = ArrayVoid.initUndefined();
10521052 var inst = ArrayVoid.initFill({});
......@@ -1059,113 +1059,113 @@ test "std.enums.EnumArray void" {
10591059 inst.set(.a, {});
10601060
10611061 var it = inst.iterator();
1062 testing.expectEqual(E.a, it.next().?.key);
1063 testing.expectEqual(E.b, it.next().?.key);
1064 testing.expectEqual(E.c, it.next().?.key);
1065 testing.expectEqual(E.d, it.next().?.key);
1066 testing.expect(it.next() == null);
1062 try testing.expectEqual(E.a, it.next().?.key);
1063 try testing.expectEqual(E.b, it.next().?.key);
1064 try testing.expectEqual(E.c, it.next().?.key);
1065 try testing.expectEqual(E.d, it.next().?.key);
1066 try testing.expect(it.next() == null);
10671067}
10681068
10691069test "std.enums.EnumArray sized" {
10701070 const E = extern enum { a, b, c, d, e = 0 };
10711071 const Array = EnumArray(E, usize);
1072 testing.expectEqual(E, Array.Key);
1073 testing.expectEqual(EnumIndexer(E), Array.Indexer);
1074 testing.expectEqual(usize, Array.Value);
1075 testing.expectEqual(@as(usize, 4), Array.len);
1072 try testing.expectEqual(E, Array.Key);
1073 try testing.expectEqual(EnumIndexer(E), Array.Indexer);
1074 try testing.expectEqual(usize, Array.Value);
1075 try testing.expectEqual(@as(usize, 4), Array.len);
10761076
10771077 const undef = Array.initUndefined();
10781078 var inst = Array.initFill(5);
10791079 const inst2 = Array.init(.{ .a = 1, .b = 2, .c = 3, .d = 4 });
10801080 const inst3 = Array.initDefault(6, .{ .b = 4, .c = 2 });
10811081
1082 testing.expectEqual(@as(usize, 5), inst.get(.a));
1083 testing.expectEqual(@as(usize, 5), inst.get(.b));
1084 testing.expectEqual(@as(usize, 5), inst.get(.c));
1085 testing.expectEqual(@as(usize, 5), inst.get(.d));
1082 try testing.expectEqual(@as(usize, 5), inst.get(.a));
1083 try testing.expectEqual(@as(usize, 5), inst.get(.b));
1084 try testing.expectEqual(@as(usize, 5), inst.get(.c));
1085 try testing.expectEqual(@as(usize, 5), inst.get(.d));
10861086
1087 testing.expectEqual(@as(usize, 1), inst2.get(.a));
1088 testing.expectEqual(@as(usize, 2), inst2.get(.b));
1089 testing.expectEqual(@as(usize, 3), inst2.get(.c));
1090 testing.expectEqual(@as(usize, 4), inst2.get(.d));
1087 try testing.expectEqual(@as(usize, 1), inst2.get(.a));
1088 try testing.expectEqual(@as(usize, 2), inst2.get(.b));
1089 try testing.expectEqual(@as(usize, 3), inst2.get(.c));
1090 try testing.expectEqual(@as(usize, 4), inst2.get(.d));
10911091
1092 testing.expectEqual(@as(usize, 6), inst3.get(.a));
1093 testing.expectEqual(@as(usize, 4), inst3.get(.b));
1094 testing.expectEqual(@as(usize, 2), inst3.get(.c));
1095 testing.expectEqual(@as(usize, 6), inst3.get(.d));
1092 try testing.expectEqual(@as(usize, 6), inst3.get(.a));
1093 try testing.expectEqual(@as(usize, 4), inst3.get(.b));
1094 try testing.expectEqual(@as(usize, 2), inst3.get(.c));
1095 try testing.expectEqual(@as(usize, 6), inst3.get(.d));
10961096
1097 testing.expectEqual(&inst.values[0], inst.getPtr(.a));
1098 testing.expectEqual(&inst.values[1], inst.getPtr(.b));
1099 testing.expectEqual(&inst.values[2], inst.getPtr(.c));
1100 testing.expectEqual(&inst.values[3], inst.getPtr(.d));
1097 try testing.expectEqual(&inst.values[0], inst.getPtr(.a));
1098 try testing.expectEqual(&inst.values[1], inst.getPtr(.b));
1099 try testing.expectEqual(&inst.values[2], inst.getPtr(.c));
1100 try testing.expectEqual(&inst.values[3], inst.getPtr(.d));
11011101
1102 testing.expectEqual(@as(*const usize, &inst.values[0]), inst.getPtrConst(.a));
1103 testing.expectEqual(@as(*const usize, &inst.values[1]), inst.getPtrConst(.b));
1104 testing.expectEqual(@as(*const usize, &inst.values[2]), inst.getPtrConst(.c));
1105 testing.expectEqual(@as(*const usize, &inst.values[3]), inst.getPtrConst(.d));
1102 try testing.expectEqual(@as(*const usize, &inst.values[0]), inst.getPtrConst(.a));
1103 try testing.expectEqual(@as(*const usize, &inst.values[1]), inst.getPtrConst(.b));
1104 try testing.expectEqual(@as(*const usize, &inst.values[2]), inst.getPtrConst(.c));
1105 try testing.expectEqual(@as(*const usize, &inst.values[3]), inst.getPtrConst(.d));
11061106
11071107 inst.set(.c, 8);
1108 testing.expectEqual(@as(usize, 5), inst.get(.a));
1109 testing.expectEqual(@as(usize, 5), inst.get(.b));
1110 testing.expectEqual(@as(usize, 8), inst.get(.c));
1111 testing.expectEqual(@as(usize, 5), inst.get(.d));
1108 try testing.expectEqual(@as(usize, 5), inst.get(.a));
1109 try testing.expectEqual(@as(usize, 5), inst.get(.b));
1110 try testing.expectEqual(@as(usize, 8), inst.get(.c));
1111 try testing.expectEqual(@as(usize, 5), inst.get(.d));
11121112
11131113 var it = inst.iterator();
11141114 const Entry = Array.Entry;
1115 testing.expectEqual(@as(?Entry, Entry{
1115 try testing.expectEqual(@as(?Entry, Entry{
11161116 .key = .a,
11171117 .value = &inst.values[0],
11181118 }), it.next());
1119 testing.expectEqual(@as(?Entry, Entry{
1119 try testing.expectEqual(@as(?Entry, Entry{
11201120 .key = .b,
11211121 .value = &inst.values[1],
11221122 }), it.next());
1123 testing.expectEqual(@as(?Entry, Entry{
1123 try testing.expectEqual(@as(?Entry, Entry{
11241124 .key = .c,
11251125 .value = &inst.values[2],
11261126 }), it.next());
1127 testing.expectEqual(@as(?Entry, Entry{
1127 try testing.expectEqual(@as(?Entry, Entry{
11281128 .key = .d,
11291129 .value = &inst.values[3],
11301130 }), it.next());
1131 testing.expectEqual(@as(?Entry, null), it.next());
1131 try testing.expectEqual(@as(?Entry, null), it.next());
11321132}
11331133
11341134test "std.enums.EnumMap void" {
11351135 const E = extern enum { a, b, c, d, e = 0 };
11361136 const Map = EnumMap(E, void);
1137 testing.expectEqual(E, Map.Key);
1138 testing.expectEqual(EnumIndexer(E), Map.Indexer);
1139 testing.expectEqual(void, Map.Value);
1140 testing.expectEqual(@as(usize, 4), Map.len);
1137 try testing.expectEqual(E, Map.Key);
1138 try testing.expectEqual(EnumIndexer(E), Map.Indexer);
1139 try testing.expectEqual(void, Map.Value);
1140 try testing.expectEqual(@as(usize, 4), Map.len);
11411141
11421142 const b = Map.initFull({});
1143 testing.expectEqual(@as(usize, 4), b.count());
1143 try testing.expectEqual(@as(usize, 4), b.count());
11441144
11451145 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
11481148 const d = Map.initFullWithDefault({}, .{ .b = {} });
1149 testing.expectEqual(@as(usize, 4), d.count());
1149 try testing.expectEqual(@as(usize, 4), d.count());
11501150
11511151 var a = Map.init(.{ .b = {}, .d = {} });
1152 testing.expectEqual(@as(usize, 2), a.count());
1153 testing.expectEqual(false, a.contains(.a));
1154 testing.expectEqual(true, a.contains(.b));
1155 testing.expectEqual(false, a.contains(.c));
1156 testing.expectEqual(true, a.contains(.d));
1157 testing.expect(a.get(.a) == null);
1158 testing.expect(a.get(.b) != null);
1159 testing.expect(a.get(.c) == null);
1160 testing.expect(a.get(.d) != null);
1161 testing.expect(a.getPtr(.a) == null);
1162 testing.expect(a.getPtr(.b) != null);
1163 testing.expect(a.getPtr(.c) == null);
1164 testing.expect(a.getPtr(.d) != null);
1165 testing.expect(a.getPtrConst(.a) == null);
1166 testing.expect(a.getPtrConst(.b) != null);
1167 testing.expect(a.getPtrConst(.c) == null);
1168 testing.expect(a.getPtrConst(.d) != null);
1152 try testing.expectEqual(@as(usize, 2), a.count());
1153 try testing.expectEqual(false, a.contains(.a));
1154 try testing.expectEqual(true, a.contains(.b));
1155 try testing.expectEqual(false, a.contains(.c));
1156 try testing.expectEqual(true, a.contains(.d));
1157 try testing.expect(a.get(.a) == null);
1158 try testing.expect(a.get(.b) != null);
1159 try testing.expect(a.get(.c) == null);
1160 try testing.expect(a.get(.d) != null);
1161 try testing.expect(a.getPtr(.a) == null);
1162 try testing.expect(a.getPtr(.b) != null);
1163 try testing.expect(a.getPtr(.c) == null);
1164 try testing.expect(a.getPtr(.d) != null);
1165 try testing.expect(a.getPtrConst(.a) == null);
1166 try testing.expect(a.getPtrConst(.b) != null);
1167 try testing.expect(a.getPtrConst(.c) == null);
1168 try testing.expect(a.getPtrConst(.d) != null);
11691169 _ = a.getPtrAssertContains(.b);
11701170 _ = a.getAssertContains(.d);
11711171
......@@ -1174,115 +1174,115 @@ test "std.enums.EnumMap void" {
11741174 a.putUninitialized(.c).* = {};
11751175 a.putUninitialized(.c).* = {};
11761176
1177 testing.expectEqual(@as(usize, 4), a.count());
1178 testing.expect(a.get(.a) != null);
1179 testing.expect(a.get(.b) != null);
1180 testing.expect(a.get(.c) != null);
1181 testing.expect(a.get(.d) != null);
1177 try testing.expectEqual(@as(usize, 4), a.count());
1178 try testing.expect(a.get(.a) != null);
1179 try testing.expect(a.get(.b) != null);
1180 try testing.expect(a.get(.c) != null);
1181 try testing.expect(a.get(.d) != null);
11821182
11831183 a.remove(.a);
11841184 _ = a.fetchRemove(.c);
11851185
11861186 var iter = a.iterator();
11871187 const Entry = Map.Entry;
1188 testing.expectEqual(E.b, iter.next().?.key);
1189 testing.expectEqual(E.d, iter.next().?.key);
1190 testing.expect(iter.next() == null);
1188 try testing.expectEqual(E.b, iter.next().?.key);
1189 try testing.expectEqual(E.d, iter.next().?.key);
1190 try testing.expect(iter.next() == null);
11911191}
11921192
11931193test "std.enums.EnumMap sized" {
11941194 const E = extern enum { a, b, c, d, e = 0 };
11951195 const Map = EnumMap(E, usize);
1196 testing.expectEqual(E, Map.Key);
1197 testing.expectEqual(EnumIndexer(E), Map.Indexer);
1198 testing.expectEqual(usize, Map.Value);
1199 testing.expectEqual(@as(usize, 4), Map.len);
1196 try testing.expectEqual(E, Map.Key);
1197 try testing.expectEqual(EnumIndexer(E), Map.Indexer);
1198 try testing.expectEqual(usize, Map.Value);
1199 try testing.expectEqual(@as(usize, 4), Map.len);
12001200
12011201 const b = Map.initFull(5);
1202 testing.expectEqual(@as(usize, 4), b.count());
1203 testing.expect(b.contains(.a));
1204 testing.expect(b.contains(.b));
1205 testing.expect(b.contains(.c));
1206 testing.expect(b.contains(.d));
1207 testing.expectEqual(@as(?usize, 5), b.get(.a));
1208 testing.expectEqual(@as(?usize, 5), b.get(.b));
1209 testing.expectEqual(@as(?usize, 5), b.get(.c));
1210 testing.expectEqual(@as(?usize, 5), b.get(.d));
1202 try testing.expectEqual(@as(usize, 4), b.count());
1203 try testing.expect(b.contains(.a));
1204 try testing.expect(b.contains(.b));
1205 try testing.expect(b.contains(.c));
1206 try testing.expect(b.contains(.d));
1207 try testing.expectEqual(@as(?usize, 5), b.get(.a));
1208 try testing.expectEqual(@as(?usize, 5), b.get(.b));
1209 try testing.expectEqual(@as(?usize, 5), b.get(.c));
1210 try testing.expectEqual(@as(?usize, 5), b.get(.d));
12111211
12121212 const c = Map.initFullWith(.{ .a = 1, .b = 2, .c = 3, .d = 4 });
1213 testing.expectEqual(@as(usize, 4), c.count());
1214 testing.expect(c.contains(.a));
1215 testing.expect(c.contains(.b));
1216 testing.expect(c.contains(.c));
1217 testing.expect(c.contains(.d));
1218 testing.expectEqual(@as(?usize, 1), c.get(.a));
1219 testing.expectEqual(@as(?usize, 2), c.get(.b));
1220 testing.expectEqual(@as(?usize, 3), c.get(.c));
1221 testing.expectEqual(@as(?usize, 4), c.get(.d));
1213 try testing.expectEqual(@as(usize, 4), c.count());
1214 try testing.expect(c.contains(.a));
1215 try testing.expect(c.contains(.b));
1216 try testing.expect(c.contains(.c));
1217 try testing.expect(c.contains(.d));
1218 try testing.expectEqual(@as(?usize, 1), c.get(.a));
1219 try testing.expectEqual(@as(?usize, 2), c.get(.b));
1220 try testing.expectEqual(@as(?usize, 3), c.get(.c));
1221 try testing.expectEqual(@as(?usize, 4), c.get(.d));
12221222
12231223 const d = Map.initFullWithDefault(6, .{ .b = 2, .c = 4 });
1224 testing.expectEqual(@as(usize, 4), d.count());
1225 testing.expect(d.contains(.a));
1226 testing.expect(d.contains(.b));
1227 testing.expect(d.contains(.c));
1228 testing.expect(d.contains(.d));
1229 testing.expectEqual(@as(?usize, 6), d.get(.a));
1230 testing.expectEqual(@as(?usize, 2), d.get(.b));
1231 testing.expectEqual(@as(?usize, 4), d.get(.c));
1232 testing.expectEqual(@as(?usize, 6), d.get(.d));
1224 try testing.expectEqual(@as(usize, 4), d.count());
1225 try testing.expect(d.contains(.a));
1226 try testing.expect(d.contains(.b));
1227 try testing.expect(d.contains(.c));
1228 try testing.expect(d.contains(.d));
1229 try testing.expectEqual(@as(?usize, 6), d.get(.a));
1230 try testing.expectEqual(@as(?usize, 2), d.get(.b));
1231 try testing.expectEqual(@as(?usize, 4), d.get(.c));
1232 try testing.expectEqual(@as(?usize, 6), d.get(.d));
12331233
12341234 var a = Map.init(.{ .b = 2, .d = 4 });
1235 testing.expectEqual(@as(usize, 2), a.count());
1236 testing.expectEqual(false, a.contains(.a));
1237 testing.expectEqual(true, a.contains(.b));
1238 testing.expectEqual(false, a.contains(.c));
1239 testing.expectEqual(true, a.contains(.d));
1240
1241 testing.expectEqual(@as(?usize, null), a.get(.a));
1242 testing.expectEqual(@as(?usize, 2), a.get(.b));
1243 testing.expectEqual(@as(?usize, null), a.get(.c));
1244 testing.expectEqual(@as(?usize, 4), a.get(.d));
1245
1246 testing.expectEqual(@as(?*usize, null), a.getPtr(.a));
1247 testing.expectEqual(@as(?*usize, &a.values[1]), a.getPtr(.b));
1248 testing.expectEqual(@as(?*usize, null), a.getPtr(.c));
1249 testing.expectEqual(@as(?*usize, &a.values[3]), a.getPtr(.d));
1250
1251 testing.expectEqual(@as(?*const usize, null), a.getPtrConst(.a));
1252 testing.expectEqual(@as(?*const usize, &a.values[1]), a.getPtrConst(.b));
1253 testing.expectEqual(@as(?*const usize, null), a.getPtrConst(.c));
1254 testing.expectEqual(@as(?*const usize, &a.values[3]), a.getPtrConst(.d));
1255
1256 testing.expectEqual(@as(*const usize, &a.values[1]), a.getPtrAssertContains(.b));
1257 testing.expectEqual(@as(*const usize, &a.values[3]), a.getPtrAssertContains(.d));
1258 testing.expectEqual(@as(usize, 2), a.getAssertContains(.b));
1259 testing.expectEqual(@as(usize, 4), a.getAssertContains(.d));
1235 try testing.expectEqual(@as(usize, 2), a.count());
1236 try testing.expectEqual(false, a.contains(.a));
1237 try testing.expectEqual(true, a.contains(.b));
1238 try testing.expectEqual(false, a.contains(.c));
1239 try testing.expectEqual(true, a.contains(.d));
1240
1241 try testing.expectEqual(@as(?usize, null), a.get(.a));
1242 try testing.expectEqual(@as(?usize, 2), a.get(.b));
1243 try testing.expectEqual(@as(?usize, null), a.get(.c));
1244 try testing.expectEqual(@as(?usize, 4), a.get(.d));
1245
1246 try testing.expectEqual(@as(?*usize, null), a.getPtr(.a));
1247 try testing.expectEqual(@as(?*usize, &a.values[1]), a.getPtr(.b));
1248 try testing.expectEqual(@as(?*usize, null), a.getPtr(.c));
1249 try testing.expectEqual(@as(?*usize, &a.values[3]), a.getPtr(.d));
1250
1251 try testing.expectEqual(@as(?*const usize, null), a.getPtrConst(.a));
1252 try testing.expectEqual(@as(?*const usize, &a.values[1]), a.getPtrConst(.b));
1253 try testing.expectEqual(@as(?*const usize, null), a.getPtrConst(.c));
1254 try testing.expectEqual(@as(?*const usize, &a.values[3]), a.getPtrConst(.d));
1255
1256 try testing.expectEqual(@as(*const usize, &a.values[1]), a.getPtrAssertContains(.b));
1257 try testing.expectEqual(@as(*const usize, &a.values[3]), a.getPtrAssertContains(.d));
1258 try testing.expectEqual(@as(usize, 2), a.getAssertContains(.b));
1259 try testing.expectEqual(@as(usize, 4), a.getAssertContains(.d));
12601260
12611261 a.put(.a, 3);
12621262 a.put(.a, 5);
12631263 a.putUninitialized(.c).* = 7;
12641264 a.putUninitialized(.c).* = 9;
12651265
1266 testing.expectEqual(@as(usize, 4), a.count());
1267 testing.expectEqual(@as(?usize, 5), a.get(.a));
1268 testing.expectEqual(@as(?usize, 2), a.get(.b));
1269 testing.expectEqual(@as(?usize, 9), a.get(.c));
1270 testing.expectEqual(@as(?usize, 4), a.get(.d));
1266 try testing.expectEqual(@as(usize, 4), a.count());
1267 try testing.expectEqual(@as(?usize, 5), a.get(.a));
1268 try testing.expectEqual(@as(?usize, 2), a.get(.b));
1269 try testing.expectEqual(@as(?usize, 9), a.get(.c));
1270 try testing.expectEqual(@as(?usize, 4), a.get(.d));
12711271
12721272 a.remove(.a);
1273 testing.expectEqual(@as(?usize, null), a.fetchRemove(.a));
1274 testing.expectEqual(@as(?usize, 9), a.fetchRemove(.c));
1273 try testing.expectEqual(@as(?usize, null), a.fetchRemove(.a));
1274 try testing.expectEqual(@as(?usize, 9), a.fetchRemove(.c));
12751275 a.remove(.c);
12761276
12771277 var iter = a.iterator();
12781278 const Entry = Map.Entry;
1279 testing.expectEqual(@as(?Entry, Entry{
1279 try testing.expectEqual(@as(?Entry, Entry{
12801280 .key = .b,
12811281 .value = &a.values[1],
12821282 }), iter.next());
1283 testing.expectEqual(@as(?Entry, Entry{
1283 try testing.expectEqual(@as(?Entry, Entry{
12841284 .key = .d,
12851285 .value = &a.values[3],
12861286 }), iter.next());
1287 testing.expectEqual(@as(?Entry, null), iter.next());
1287 try testing.expectEqual(@as(?Entry, null), iter.next());
12881288}
lib/std/event/batch.zig+2-2
......@@ -119,12 +119,12 @@ test "std.event.Batch" {
119119 batch.add(&async sleepALittle(&count));
120120 batch.add(&async increaseByTen(&count));
121121 batch.wait();
122 testing.expect(count == 11);
122 try testing.expect(count == 11);
123123
124124 var another = Batch(anyerror!void, 2, .auto_async).init();
125125 another.add(&async somethingElse());
126126 another.add(&async doSomethingThatFails());
127 testing.expectError(error.ItBroke, another.wait());
127 try testing.expectError(error.ItBroke, another.wait());
128128}
129129
130130fn sleepALittle(count: *usize) void {
lib/std/event/channel.zig+7-7
......@@ -310,25 +310,25 @@ test "std.event.Channel wraparound" {
310310 // the buffer wraps around, make sure it doesn't crash.
311311 var result: i32 = undefined;
312312 channel.put(5);
313 testing.expectEqual(@as(i32, 5), channel.get());
313 try testing.expectEqual(@as(i32, 5), channel.get());
314314 channel.put(6);
315 testing.expectEqual(@as(i32, 6), channel.get());
315 try testing.expectEqual(@as(i32, 6), channel.get());
316316 channel.put(7);
317 testing.expectEqual(@as(i32, 7), channel.get());
317 try testing.expectEqual(@as(i32, 7), channel.get());
318318}
319319fn testChannelGetter(channel: *Channel(i32)) callconv(.Async) void {
320320 const value1 = channel.get();
321 testing.expect(value1 == 1234);
321 try testing.expect(value1 == 1234);
322322
323323 const value2 = channel.get();
324 testing.expect(value2 == 4567);
324 try testing.expect(value2 == 4567);
325325
326326 const value3 = channel.getOrNull();
327 testing.expect(value3 == null);
327 try testing.expect(value3 == null);
328328
329329 var last_put = async testPut(channel, 4444);
330330 const value4 = channel.getOrNull();
331 testing.expect(value4.? == 4444);
331 try testing.expect(value4.? == 4444);
332332 await last_put;
333333}
334334fn testChannelPutter(channel: *Channel(i32)) callconv(.Async) void {
lib/std/event/future.zig+1-1
......@@ -107,7 +107,7 @@ fn testFuture() void {
107107
108108 const result = (await a) + (await b);
109109
110 testing.expect(result == 12);
110 try testing.expect(result == 12);
111111}
112112
113113fn waitOnFuture(future: *Future(i32)) i32 {
lib/std/event/group.zig+2-2
......@@ -140,14 +140,14 @@ fn testGroup(allocator: *Allocator) callconv(.Async) void {
140140 var increase_by_ten_frame = async increaseByTen(&count);
141141 group.add(&increase_by_ten_frame) catch @panic("memory");
142142 group.wait();
143 testing.expect(count == 11);
143 try testing.expect(count == 11);
144144
145145 var another = Group(anyerror!void).init(allocator);
146146 var something_else_frame = async somethingElse();
147147 another.add(&something_else_frame) catch @panic("memory");
148148 var something_that_fails_frame = async doSomethingThatFails();
149149 another.add(&something_that_fails_frame) catch @panic("memory");
150 testing.expectError(error.ItBroke, another.wait());
150 try testing.expectError(error.ItBroke, another.wait());
151151}
152152fn sleepALittle(count: *usize) callconv(.Async) void {
153153 std.time.sleep(1 * std.time.ns_per_ms);
lib/std/event/lock.zig+1-1
......@@ -136,7 +136,7 @@ test "std.event.Lock" {
136136 testLock(&lock);
137137
138138 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);
140140}
141141fn testLock(lock: *Lock) void {
142142 var handle1 = async lockRunner(lock);
lib/std/event/loop.zig+3-3
......@@ -1655,7 +1655,7 @@ fn testEventLoop() i32 {
16551655
16561656fn testEventLoop2(h: anyframe->i32, did_it: *bool) void {
16571657 const value = await h;
1658 testing.expect(value == 1234);
1658 try testing.expect(value == 1234);
16591659 did_it.* = true;
16601660}
16611661
......@@ -1682,7 +1682,7 @@ test "std.event.Loop - runDetached" {
16821682 // with the previous runDetached.
16831683 loop.run();
16841684
1685 testing.expect(testRunDetachedData == 1);
1685 try testing.expect(testRunDetachedData == 1);
16861686}
16871687
16881688fn testRunDetached() void {
......@@ -1705,7 +1705,7 @@ test "std.event.Loop - sleep" {
17051705 for (frames) |*frame|
17061706 await frame;
17071707
1708 testing.expect(sleep_count == frames.len);
1708 try testing.expect(sleep_count == frames.len);
17091709}
17101710
17111711fn testSleep(wait_ns: u64, sleep_count: *usize) void {
lib/std/event/rwlock.zig+3-3
......@@ -228,7 +228,7 @@ test "std.event.RwLock" {
228228 const handle = testLock(std.heap.page_allocator, &lock);
229229
230230 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);
232232}
233233fn testLock(allocator: *Allocator, lock: *RwLock) callconv(.Async) void {
234234 var read_nodes: [100]Loop.NextTickNode = undefined;
......@@ -290,7 +290,7 @@ fn readRunner(lock: *RwLock) callconv(.Async) void {
290290 const handle = await lock_promise;
291291 defer handle.release();
292292
293 testing.expect(shared_test_index == 0);
294 testing.expect(shared_test_data[i] == @intCast(i32, shared_count));
293 try testing.expect(shared_test_index == 0);
294 try testing.expect(shared_test_data[i] == @intCast(i32, shared_count));
295295 }
296296}
lib/std/fifo.zig+38-38
......@@ -402,59 +402,59 @@ test "LinearFifo(u8, .Dynamic)" {
402402 defer fifo.deinit();
403403
404404 try fifo.write("HELLO");
405 testing.expectEqual(@as(usize, 5), fifo.readableLength());
406 testing.expectEqualSlices(u8, "HELLO", fifo.readableSlice(0));
405 try testing.expectEqual(@as(usize, 5), fifo.readableLength());
406 try testing.expectEqualSlices(u8, "HELLO", fifo.readableSlice(0));
407407
408408 {
409409 var i: usize = 0;
410410 while (i < 5) : (i += 1) {
411411 try fifo.write(&[_]u8{fifo.peekItem(i)});
412412 }
413 testing.expectEqual(@as(usize, 10), fifo.readableLength());
414 testing.expectEqualSlices(u8, "HELLOHELLO", fifo.readableSlice(0));
413 try testing.expectEqual(@as(usize, 10), fifo.readableLength());
414 try testing.expectEqualSlices(u8, "HELLOHELLO", fifo.readableSlice(0));
415415 }
416416
417417 {
418 testing.expectEqual(@as(u8, 'H'), fifo.readItem().?);
419 testing.expectEqual(@as(u8, 'E'), fifo.readItem().?);
420 testing.expectEqual(@as(u8, 'L'), fifo.readItem().?);
421 testing.expectEqual(@as(u8, 'L'), fifo.readItem().?);
422 testing.expectEqual(@as(u8, 'O'), fifo.readItem().?);
418 try testing.expectEqual(@as(u8, 'H'), fifo.readItem().?);
419 try testing.expectEqual(@as(u8, 'E'), fifo.readItem().?);
420 try testing.expectEqual(@as(u8, 'L'), fifo.readItem().?);
421 try testing.expectEqual(@as(u8, 'L'), fifo.readItem().?);
422 try testing.expectEqual(@as(u8, 'O'), fifo.readItem().?);
423423 }
424 testing.expectEqual(@as(usize, 5), fifo.readableLength());
424 try testing.expectEqual(@as(usize, 5), fifo.readableLength());
425425
426426 { // Writes that wrap around
427 testing.expectEqual(@as(usize, 11), fifo.writableLength());
428 testing.expectEqual(@as(usize, 6), fifo.writableSlice(0).len);
427 try testing.expectEqual(@as(usize, 11), fifo.writableLength());
428 try testing.expectEqual(@as(usize, 6), fifo.writableSlice(0).len);
429429 fifo.writeAssumeCapacity("6<chars<11");
430 testing.expectEqualSlices(u8, "HELLO6<char", fifo.readableSlice(0));
431 testing.expectEqualSlices(u8, "s<11", fifo.readableSlice(11));
432 testing.expectEqualSlices(u8, "11", fifo.readableSlice(13));
433 testing.expectEqualSlices(u8, "", fifo.readableSlice(15));
430 try testing.expectEqualSlices(u8, "HELLO6<char", fifo.readableSlice(0));
431 try testing.expectEqualSlices(u8, "s<11", fifo.readableSlice(11));
432 try testing.expectEqualSlices(u8, "11", fifo.readableSlice(13));
433 try testing.expectEqualSlices(u8, "", fifo.readableSlice(15));
434434 fifo.discard(11);
435 testing.expectEqualSlices(u8, "s<11", fifo.readableSlice(0));
435 try testing.expectEqualSlices(u8, "s<11", fifo.readableSlice(0));
436436 fifo.discard(4);
437 testing.expectEqual(@as(usize, 0), fifo.readableLength());
437 try testing.expectEqual(@as(usize, 0), fifo.readableLength());
438438 }
439439
440440 {
441441 const buf = try fifo.writableWithSize(12);
442 testing.expectEqual(@as(usize, 12), buf.len);
442 try testing.expectEqual(@as(usize, 12), buf.len);
443443 var i: u8 = 0;
444444 while (i < 10) : (i += 1) {
445445 buf[i] = i + 'a';
446446 }
447447 fifo.update(10);
448 testing.expectEqualSlices(u8, "abcdefghij", fifo.readableSlice(0));
448 try testing.expectEqualSlices(u8, "abcdefghij", fifo.readableSlice(0));
449449 }
450450
451451 {
452452 try fifo.unget("prependedstring");
453453 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)]);
455455 try fifo.unget("b");
456456 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)]);
458458 }
459459
460460 fifo.shrink(0);
......@@ -462,17 +462,17 @@ test "LinearFifo(u8, .Dynamic)" {
462462 {
463463 try fifo.writer().print("{s}, {s}!", .{ "Hello", "World" });
464464 var result: [30]u8 = undefined;
465 testing.expectEqualSlices(u8, "Hello, World!", result[0..fifo.read(&result)]);
466 testing.expectEqual(@as(usize, 0), fifo.readableLength());
465 try testing.expectEqualSlices(u8, "Hello, World!", result[0..fifo.read(&result)]);
466 try testing.expectEqual(@as(usize, 0), fifo.readableLength());
467467 }
468468
469469 {
470470 try fifo.writer().writeAll("This is a test");
471471 var result: [30]u8 = undefined;
472 testing.expectEqualSlices(u8, "This", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?);
473 testing.expectEqualSlices(u8, "is", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?);
474 testing.expectEqualSlices(u8, "a", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?);
475 testing.expectEqualSlices(u8, "test", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?);
472 try testing.expectEqualSlices(u8, "This", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?);
473 try testing.expectEqualSlices(u8, "is", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?);
474 try testing.expectEqualSlices(u8, "a", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?);
475 try testing.expectEqualSlices(u8, "test", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?);
476476 }
477477
478478 {
......@@ -481,7 +481,7 @@ test "LinearFifo(u8, .Dynamic)" {
481481 var out_buf: [50]u8 = undefined;
482482 var out_fbs = std.io.fixedBufferStream(&out_buf);
483483 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());
485485 }
486486}
487487
......@@ -498,28 +498,28 @@ test "LinearFifo" {
498498 defer fifo.deinit();
499499
500500 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
503503 {
504 testing.expectEqual(@as(T, 0), fifo.readItem().?);
505 testing.expectEqual(@as(T, 1), fifo.readItem().?);
506 testing.expectEqual(@as(T, 1), fifo.readItem().?);
507 testing.expectEqual(@as(T, 0), fifo.readItem().?);
508 testing.expectEqual(@as(T, 1), fifo.readItem().?);
509 testing.expectEqual(@as(usize, 0), fifo.readableLength());
504 try testing.expectEqual(@as(T, 0), fifo.readItem().?);
505 try testing.expectEqual(@as(T, 1), fifo.readItem().?);
506 try testing.expectEqual(@as(T, 1), fifo.readItem().?);
507 try testing.expectEqual(@as(T, 0), fifo.readItem().?);
508 try testing.expectEqual(@as(T, 1), fifo.readItem().?);
509 try testing.expectEqual(@as(usize, 0), fifo.readableLength());
510510 }
511511
512512 {
513513 try fifo.writeItem(1);
514514 try fifo.writeItem(1);
515515 try fifo.writeItem(1);
516 testing.expectEqual(@as(usize, 3), fifo.readableLength());
516 try testing.expectEqual(@as(usize, 3), fifo.readableLength());
517517 }
518518
519519 {
520520 var readBuf: [3]T = undefined;
521521 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.
523523 }
524524 }
525525 }
lib/std/fmt.zig+77-77
......@@ -1422,7 +1422,7 @@ test "fmtDuration" {
14221422 .{ .s = "1y1m999ns", .d = 365 * std.time.ns_per_day + std.time.ns_per_min + 999 },
14231423 }) |tc| {
14241424 const slice = try bufPrint(&buf, "{}", .{fmtDuration(tc.d)});
1425 std.testing.expectEqualStrings(tc.s, slice);
1425 try std.testing.expectEqualStrings(tc.s, slice);
14261426 }
14271427}
14281428
......@@ -1478,44 +1478,44 @@ pub fn parseInt(comptime T: type, buf: []const u8, radix: u8) ParseIntError!T {
14781478}
14791479
14801480test "parseInt" {
1481 std.testing.expect((try parseInt(i32, "-10", 10)) == -10);
1482 std.testing.expect((try parseInt(i32, "+10", 10)) == 10);
1483 std.testing.expect((try parseInt(u32, "+10", 10)) == 10);
1484 std.testing.expectError(error.Overflow, parseInt(u32, "-10", 10));
1485 std.testing.expectError(error.InvalidCharacter, parseInt(u32, " 10", 10));
1486 std.testing.expectError(error.InvalidCharacter, parseInt(u32, "10 ", 10));
1487 std.testing.expect((try parseInt(u8, "255", 10)) == 255);
1488 std.testing.expectError(error.Overflow, parseInt(u8, "256", 10));
1481 try std.testing.expect((try parseInt(i32, "-10", 10)) == -10);
1482 try std.testing.expect((try parseInt(i32, "+10", 10)) == 10);
1483 try std.testing.expect((try parseInt(u32, "+10", 10)) == 10);
1484 try std.testing.expectError(error.Overflow, parseInt(u32, "-10", 10));
1485 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, " 10", 10));
1486 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "10 ", 10));
1487 try std.testing.expect((try parseInt(u8, "255", 10)) == 255);
1488 try std.testing.expectError(error.Overflow, parseInt(u8, "256", 10));
14891489
14901490 // +0 and -0 should work for unsigned
1491 std.testing.expect((try parseInt(u8, "-0", 10)) == 0);
1492 std.testing.expect((try parseInt(u8, "+0", 10)) == 0);
1491 try std.testing.expect((try parseInt(u8, "-0", 10)) == 0);
1492 try std.testing.expect((try parseInt(u8, "+0", 10)) == 0);
14931493
14941494 // ensure minInt is parsed correctly
1495 std.testing.expect((try parseInt(i8, "-128", 10)) == math.minInt(i8));
1496 std.testing.expect((try parseInt(i43, "-4398046511104", 10)) == math.minInt(i43));
1495 try std.testing.expect((try parseInt(i8, "-128", 10)) == math.minInt(i8));
1496 try std.testing.expect((try parseInt(i43, "-4398046511104", 10)) == math.minInt(i43));
14971497
14981498 // empty string or bare +- is invalid
1499 std.testing.expectError(error.InvalidCharacter, parseInt(u32, "", 10));
1500 std.testing.expectError(error.InvalidCharacter, parseInt(i32, "", 10));
1501 std.testing.expectError(error.InvalidCharacter, parseInt(u32, "+", 10));
1502 std.testing.expectError(error.InvalidCharacter, parseInt(i32, "+", 10));
1503 std.testing.expectError(error.InvalidCharacter, parseInt(u32, "-", 10));
1504 std.testing.expectError(error.InvalidCharacter, parseInt(i32, "-", 10));
1499 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "", 10));
1500 try std.testing.expectError(error.InvalidCharacter, parseInt(i32, "", 10));
1501 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "+", 10));
1502 try std.testing.expectError(error.InvalidCharacter, parseInt(i32, "+", 10));
1503 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "-", 10));
1504 try std.testing.expectError(error.InvalidCharacter, parseInt(i32, "-", 10));
15051505
15061506 // autodectect the radix
1507 std.testing.expect((try parseInt(i32, "111", 0)) == 111);
1508 std.testing.expect((try parseInt(i32, "+0b111", 0)) == 7);
1509 std.testing.expect((try parseInt(i32, "+0o111", 0)) == 73);
1510 std.testing.expect((try parseInt(i32, "+0x111", 0)) == 273);
1511 std.testing.expect((try parseInt(i32, "-0b111", 0)) == -7);
1512 std.testing.expect((try parseInt(i32, "-0o111", 0)) == -73);
1513 std.testing.expect((try parseInt(i32, "-0x111", 0)) == -273);
1507 try std.testing.expect((try parseInt(i32, "111", 0)) == 111);
1508 try std.testing.expect((try parseInt(i32, "+0b111", 0)) == 7);
1509 try std.testing.expect((try parseInt(i32, "+0o111", 0)) == 73);
1510 try std.testing.expect((try parseInt(i32, "+0x111", 0)) == 273);
1511 try std.testing.expect((try parseInt(i32, "-0b111", 0)) == -7);
1512 try std.testing.expect((try parseInt(i32, "-0o111", 0)) == -73);
1513 try std.testing.expect((try parseInt(i32, "-0x111", 0)) == -273);
15141514
15151515 // bare binary/octal/decimal prefix is invalid
1516 std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0b", 0));
1517 std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0o", 0));
1518 std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0x", 0));
1516 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0b", 0));
1517 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0o", 0));
1518 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0x", 0));
15191519}
15201520
15211521fn parseWithSign(
......@@ -1583,37 +1583,37 @@ pub fn parseUnsigned(comptime T: type, buf: []const u8, radix: u8) ParseIntError
15831583}
15841584
15851585test "parseUnsigned" {
1586 std.testing.expect((try parseUnsigned(u16, "050124", 10)) == 50124);
1587 std.testing.expect((try parseUnsigned(u16, "65535", 10)) == 65535);
1588 std.testing.expectError(error.Overflow, parseUnsigned(u16, "65536", 10));
1586 try std.testing.expect((try parseUnsigned(u16, "050124", 10)) == 50124);
1587 try std.testing.expect((try parseUnsigned(u16, "65535", 10)) == 65535);
1588 try std.testing.expectError(error.Overflow, parseUnsigned(u16, "65536", 10));
15891589
1590 std.testing.expect((try parseUnsigned(u64, "0ffffffffffffffff", 16)) == 0xffffffffffffffff);
1591 std.testing.expectError(error.Overflow, parseUnsigned(u64, "10000000000000000", 16));
1590 try std.testing.expect((try parseUnsigned(u64, "0ffffffffffffffff", 16)) == 0xffffffffffffffff);
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);
1596 std.testing.expect((try parseUnsigned(u7, "1000", 2)) == 8);
1595 try std.testing.expect((try parseUnsigned(u7, "1", 10)) == 1);
1596 try std.testing.expect((try parseUnsigned(u7, "1000", 2)) == 8);
15971597
1598 std.testing.expectError(error.InvalidCharacter, parseUnsigned(u32, "f", 10));
1599 std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "109", 8));
1598 try std.testing.expectError(error.InvalidCharacter, parseUnsigned(u32, "f", 10));
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
16031603 // 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);
1605 std.testing.expect((try parseUnsigned(u1, "1", 10)) == 1);
1606 std.testing.expectError(error.Overflow, parseUnsigned(u1, "2", 10));
1607 std.testing.expect((try parseUnsigned(u1, "001", 16)) == 1);
1608 std.testing.expect((try parseUnsigned(u2, "3", 16)) == 3);
1609 std.testing.expectError(error.Overflow, parseUnsigned(u2, "4", 16));
1604 try std.testing.expect((try parseUnsigned(u1, "0", 10)) == 0);
1605 try std.testing.expect((try parseUnsigned(u1, "1", 10)) == 1);
1606 try std.testing.expectError(error.Overflow, parseUnsigned(u1, "2", 10));
1607 try std.testing.expect((try parseUnsigned(u1, "001", 16)) == 1);
1608 try std.testing.expect((try parseUnsigned(u2, "3", 16)) == 3);
1609 try std.testing.expectError(error.Overflow, parseUnsigned(u2, "4", 16));
16101610
16111611 // parseUnsigned does not expect a sign
1612 std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "+0", 10));
1613 std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "-0", 10));
1612 try std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "+0", 10));
1613 try std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "-0", 10));
16141614
16151615 // test empty string error
1616 std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "", 10));
1616 try std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "", 10));
16171617}
16181618
16191619pub const parseFloat = @import("fmt/parse_float.zig").parseFloat;
......@@ -1692,21 +1692,21 @@ test "bufPrintInt" {
16921692 var buffer: [100]u8 = undefined;
16931693 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{}));
1698 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{}));
1700 std.testing.expectEqualSlices(u8, "-BC614E", bufPrintIntToSlice(buf, @as(i32, -12345678), 16, true, FormatOptions{}));
1697 try std.testing.expectEqualSlices(u8, "-101111000110000101001110", bufPrintIntToSlice(buf, @as(i32, -12345678), 2, false, FormatOptions{}));
1698 try std.testing.expectEqualSlices(u8, "-12345678", bufPrintIntToSlice(buf, @as(i32, -12345678), 10, false, FormatOptions{}));
1699 try std.testing.expectEqualSlices(u8, "-bc614e", bufPrintIntToSlice(buf, @as(i32, -12345678), 16, false, 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 }));
1705 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 }));
1704 try std.testing.expectEqualSlices(u8, " 666", bufPrintIntToSlice(buf, @as(u32, 666), 10, false, FormatOptions{ .width = 6 }));
1705 try std.testing.expectEqualSlices(u8, " 1234", bufPrintIntToSlice(buf, @as(u32, 0x1234), 16, false, FormatOptions{ .width = 6 }));
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 }));
1709 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 try std.testing.expectEqualSlices(u8, "-42", bufPrintIntToSlice(buf, @as(i32, -42), 10, false, FormatOptions{ .width = 3 }));
17101710}
17111711
17121712pub 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,
17241724
17251725test "comptimePrint" {
17261726 @setEvalBranchQuota(2000);
1727 std.testing.expectEqual(*const [3:0]u8, @TypeOf(comptime comptimePrint("{}", .{100})));
1728 std.testing.expectEqualSlices(u8, "100", comptime comptimePrint("{}", .{100}));
1727 try std.testing.expectEqual(*const [3:0]u8, @TypeOf(comptime comptimePrint("{}", .{100})));
1728 try std.testing.expectEqualSlices(u8, "100", comptime comptimePrint("{}", .{100}));
17291729}
17301730
17311731test "parse u64 digit too big" {
......@@ -1738,7 +1738,7 @@ test "parse u64 digit too big" {
17381738
17391739test "parse unsigned comptime" {
17401740 comptime {
1741 std.testing.expect((try parseUnsigned(usize, "2", 10)) == 2);
1741 try std.testing.expect((try parseUnsigned(usize, "2", 10)) == 2);
17421742 }
17431743}
17441744
......@@ -1835,15 +1835,15 @@ test "buffer" {
18351835 var buf1: [32]u8 = undefined;
18361836 var fbs = std.io.fixedBufferStream(&buf1);
18371837 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
18401840 fbs.reset();
18411841 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
18441844 fbs.reset();
18451845 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"));
18471847 }
18481848}
18491849
......@@ -2170,10 +2170,10 @@ test "union" {
21702170
21712171 var buf: [100]u8 = undefined;
21722172 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
21752175 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@"));
21772177}
21782178
21792179test "enum" {
......@@ -2256,9 +2256,9 @@ test "hexToBytes" {
22562256 try expectFmt("90" ** 32, "{s}", .{fmtSliceHexUpper(try hexToBytes(&buf, "90" ** 32))});
22572257 try expectFmt("ABCD", "{s}", .{fmtSliceHexUpper(try hexToBytes(&buf, "ABCD"))});
22582258 try expectFmt("", "{s}", .{fmtSliceHexUpper(try hexToBytes(&buf, ""))});
2259 std.testing.expectError(error.InvalidCharacter, hexToBytes(&buf, "012Z"));
2260 std.testing.expectError(error.InvalidLength, hexToBytes(&buf, "AAA"));
2261 std.testing.expectError(error.NoSpaceLeft, hexToBytes(buf[0..1], "ABAB"));
2259 try std.testing.expectError(error.InvalidCharacter, hexToBytes(&buf, "012Z"));
2260 try std.testing.expectError(error.InvalidLength, hexToBytes(&buf, "AAA"));
2261 try std.testing.expectError(error.NoSpaceLeft, hexToBytes(buf[0..1], "ABAB"));
22622262}
22632263
22642264test "formatIntValue with comptime_int" {
......@@ -2267,7 +2267,7 @@ test "formatIntValue with comptime_int" {
22672267 var buf: [20]u8 = undefined;
22682268 var fbs = std.io.fixedBufferStream(&buf);
22692269 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"));
22712271}
22722272
22732273test "formatFloatValue with comptime_float" {
......@@ -2276,7 +2276,7 @@ test "formatFloatValue with comptime_float" {
22762276 var buf: [20]u8 = undefined;
22772277 var fbs = std.io.fixedBufferStream(&buf);
22782278 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
22812281 try expectFmt("1.0e+00", "{}", .{value});
22822282 try expectFmt("1.0e+00", "{}", .{1.0});
......@@ -2332,19 +2332,19 @@ test "formatType max_depth" {
23322332 var buf: [1000]u8 = undefined;
23332333 var fbs = std.io.fixedBufferStream(&buf);
23342334 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
23372337 fbs.reset();
23382338 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
23412341 fbs.reset();
23422342 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
23452345 fbs.reset();
23462346 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) }"));
23482348}
23492349
23502350test "positional" {
lib/std/fmt/parse_float.zig+29-29
......@@ -376,44 +376,44 @@ test "fmt.parseFloat" {
376376 inline for ([_]type{ f16, f32, f64, f128 }) |T| {
377377 const Z = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);
378378
379 testing.expectError(error.InvalidCharacter, parseFloat(T, ""));
380 testing.expectError(error.InvalidCharacter, parseFloat(T, " 1"));
381 testing.expectError(error.InvalidCharacter, parseFloat(T, "1abc"));
382 testing.expectError(error.InvalidCharacter, parseFloat(T, "+"));
383 testing.expectError(error.InvalidCharacter, parseFloat(T, "-"));
379 try testing.expectError(error.InvalidCharacter, parseFloat(T, ""));
380 try testing.expectError(error.InvalidCharacter, parseFloat(T, " 1"));
381 try testing.expectError(error.InvalidCharacter, parseFloat(T, "1abc"));
382 try testing.expectError(error.InvalidCharacter, parseFloat(T, "+"));
383 try testing.expectError(error.InvalidCharacter, parseFloat(T, "-"));
384384
385 expectEqual(try parseFloat(T, "0"), 0.0);
386 expectEqual(try parseFloat(T, "0"), 0.0);
387 expectEqual(try parseFloat(T, "+0"), 0.0);
388 expectEqual(try parseFloat(T, "-0"), 0.0);
385 try expectEqual(try parseFloat(T, "0"), 0.0);
386 try expectEqual(try parseFloat(T, "0"), 0.0);
387 try expectEqual(try parseFloat(T, "+0"), 0.0);
388 try expectEqual(try parseFloat(T, "-0"), 0.0);
389389
390 expectEqual(try parseFloat(T, "0e0"), 0);
391 expectEqual(try parseFloat(T, "2e3"), 2000.0);
392 expectEqual(try parseFloat(T, "1e0"), 1.0);
393 expectEqual(try parseFloat(T, "-2e3"), -2000.0);
394 expectEqual(try parseFloat(T, "-1e0"), -1.0);
395 expectEqual(try parseFloat(T, "1.234e3"), 1234);
390 try expectEqual(try parseFloat(T, "0e0"), 0);
391 try expectEqual(try parseFloat(T, "2e3"), 2000.0);
392 try expectEqual(try parseFloat(T, "1e0"), 1.0);
393 try expectEqual(try parseFloat(T, "-2e3"), -2000.0);
394 try expectEqual(try parseFloat(T, "-1e0"), -1.0);
395 try expectEqual(try parseFloat(T, "1.234e3"), 1234);
396396
397 expect(approxEqAbs(T, try parseFloat(T, "3.141"), 3.141, epsilon));
398 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 try expect(approxEqAbs(T, try parseFloat(T, "-3.141"), -3.141, epsilon));
399399
400 expectEqual(try parseFloat(T, "1e-700"), 0);
401 expectEqual(try parseFloat(T, "1e+700"), std.math.inf(T));
400 try expectEqual(try parseFloat(T, "1e-700"), 0);
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)));
404 expectEqual(try parseFloat(T, "inF"), std.math.inf(T));
405 expectEqual(try parseFloat(T, "-INF"), -std.math.inf(T));
403 try expectEqual(@bitCast(Z, try parseFloat(T, "nAn")), @bitCast(Z, std.math.nan(T)));
404 try 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
409409 if (T != f16) {
410 expect(approxEqAbs(T, try parseFloat(T, "1e-2"), 0.01, epsilon));
411 expect(approxEqAbs(T, try parseFloat(T, "1234e-2"), 12.34, epsilon));
410 try expect(approxEqAbs(T, try parseFloat(T, "1e-2"), 0.01, 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));
414 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));
416 expect(approxEqAbs(T, try parseFloat(T, "2.71828182845904523536"), @as(T, 2.718281828459045), epsilon));
413 try expect(approxEqAbs(T, try parseFloat(T, "123142.1"), 123142.1, epsilon));
414 try expect(approxEqAbs(T, try parseFloat(T, "-123142.1124"), @as(T, -123142.1124), epsilon));
415 try expect(approxEqAbs(T, try parseFloat(T, "0.7062146892655368"), @as(T, 0.7062146892655368), epsilon));
416 try expect(approxEqAbs(T, try parseFloat(T, "2.71828182845904523536"), @as(T, 2.718281828459045), epsilon));
417417 }
418418 }
419419}
lib/std/fmt/parse_hex_float.zig+13-13
......@@ -247,17 +247,17 @@ pub fn parseHexFloat(comptime T: type, s: []const u8) !T {
247247}
248248
249249test "special" {
250 testing.expect(math.isNan(try parseHexFloat(f32, "nAn")));
251 testing.expect(math.isPositiveInf(try parseHexFloat(f32, "iNf")));
252 testing.expect(math.isPositiveInf(try parseHexFloat(f32, "+Inf")));
253 testing.expect(math.isNegativeInf(try parseHexFloat(f32, "-iNf")));
250 try testing.expect(math.isNan(try parseHexFloat(f32, "nAn")));
251 try testing.expect(math.isPositiveInf(try parseHexFloat(f32, "iNf")));
252 try testing.expect(math.isPositiveInf(try parseHexFloat(f32, "+Inf")));
253 try testing.expect(math.isNegativeInf(try parseHexFloat(f32, "-iNf")));
254254}
255255test "zero" {
256 testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "0x0"));
257 testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "-0x0"));
258 testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "0x0p42"));
259 testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "-0x0.00000p42"));
260 testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "0x0.00000p666"));
256 try testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "0x0"));
257 try testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "-0x0"));
258 try testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "0x0p42"));
259 try testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "-0x0.00000p42"));
260 try testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "0x0.00000p666"));
261261}
262262
263263test "f16" {
......@@ -279,7 +279,7 @@ test "f16" {
279279 };
280280
281281 for (cases) |case| {
282 testing.expectEqual(case.v, try parseHexFloat(f16, case.s));
282 try testing.expectEqual(case.v, try parseHexFloat(f16, case.s));
283283 }
284284}
285285test "f32" {
......@@ -303,7 +303,7 @@ test "f32" {
303303 };
304304
305305 for (cases) |case| {
306 testing.expectEqual(case.v, try parseHexFloat(f32, case.s));
306 try testing.expectEqual(case.v, try parseHexFloat(f32, case.s));
307307 }
308308}
309309test "f64" {
......@@ -325,7 +325,7 @@ test "f64" {
325325 };
326326
327327 for (cases) |case| {
328 testing.expectEqual(case.v, try parseHexFloat(f64, case.s));
328 try testing.expectEqual(case.v, try parseHexFloat(f64, case.s));
329329 }
330330}
331331test "f128" {
......@@ -347,6 +347,6 @@ test "f128" {
347347 };
348348
349349 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)));
351351 }
352352}
lib/std/fs/path.zig+205-205
......@@ -96,72 +96,72 @@ pub fn joinZ(allocator: *Allocator, paths: []const []const u8) ![:0]u8 {
9696 return out[0 .. out.len - 1 :0];
9797}
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 {
100100 const windowsIsSep = struct {
101101 fn isSep(byte: u8) bool {
102102 return byte == '/' or byte == '\\';
103103 }
104104 }.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);
106106 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);
108108}
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 {
111111 const posixIsSep = struct {
112112 fn isSep(byte: u8) bool {
113113 return byte == '/';
114114 }
115115 }.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);
117117 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);
119119}
120120
121121test "join" {
122122 {
123123 const actual: []u8 = try join(testing.allocator, &[_][]const u8{});
124124 defer testing.allocator.free(actual);
125 testing.expectEqualSlices(u8, "", actual);
125 try testing.expectEqualSlices(u8, "", actual);
126126 }
127127 {
128128 const actual: [:0]u8 = try joinZ(testing.allocator, &[_][]const u8{});
129129 defer testing.allocator.free(actual);
130 testing.expectEqualSlices(u8, "", actual);
130 try testing.expectEqualSlices(u8, "", actual);
131131 }
132132 for (&[_]bool{ false, true }) |zero| {
133 testJoinMaybeZWindows(&[_][]const u8{}, "", zero);
134 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);
136 testJoinMaybeZWindows(&[_][]const u8{ "c:\\a\\b\\", "c" }, "c:\\a\\b\\c", zero);
133 try testJoinMaybeZWindows(&[_][]const u8{}, "", zero);
134 try 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 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);
139 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 try testJoinMaybeZWindows(&[_][]const u8{ "c:\\a\\", "b\\", "c" }, "c:\\a\\b\\c", zero);
140140
141 testJoinMaybeZWindows(
141 try testJoinMaybeZWindows(
142142 &[_][]const u8{ "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std", "io.zig" },
143143 "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std\\io.zig",
144144 zero,
145145 );
146146
147 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);
147 try 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);
151 testJoinMaybeZPosix(&[_][]const u8{ "/a/b", "c" }, "/a/b/c", zero);
152 testJoinMaybeZPosix(&[_][]const u8{ "/a/b/", "c" }, "/a/b/c", zero);
150 try testJoinMaybeZPosix(&[_][]const u8{}, "", zero);
151 try 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);
155 testJoinMaybeZPosix(&[_][]const u8{ "/a/", "b/", "c" }, "/a/b/c", zero);
154 try 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(
158158 &[_][]const u8{ "/home/andy/dev/zig/build/lib/zig/std", "io.zig" },
159159 "/home/andy/dev/zig/build/lib/zig/std/io.zig",
160160 zero,
161161 );
162162
163 testJoinMaybeZPosix(&[_][]const u8{ "a", "/c" }, "a/c", zero);
164 testJoinMaybeZPosix(&[_][]const u8{ "a/", "/c" }, "a/c", zero);
163 try testJoinMaybeZPosix(&[_][]const u8{ "a", "/c" }, "a/c", zero);
164 try testJoinMaybeZPosix(&[_][]const u8{ "a/", "/c" }, "a/c", zero);
165165 }
166166}
167167
......@@ -235,42 +235,42 @@ pub fn isAbsolutePosixZ(path_c: [*:0]const u8) bool {
235235}
236236
237237test "isAbsoluteWindows" {
238 testIsAbsoluteWindows("", false);
239 testIsAbsoluteWindows("/", true);
240 testIsAbsoluteWindows("//", true);
241 testIsAbsoluteWindows("//server", true);
242 testIsAbsoluteWindows("//server/file", true);
243 testIsAbsoluteWindows("\\\\server\\file", true);
244 testIsAbsoluteWindows("\\\\server", true);
245 testIsAbsoluteWindows("\\\\", true);
246 testIsAbsoluteWindows("c", false);
247 testIsAbsoluteWindows("c:", false);
248 testIsAbsoluteWindows("c:\\", true);
249 testIsAbsoluteWindows("c:/", true);
250 testIsAbsoluteWindows("c://", true);
251 testIsAbsoluteWindows("C:/Users/", true);
252 testIsAbsoluteWindows("C:\\Users\\", true);
253 testIsAbsoluteWindows("C:cwd/another", false);
254 testIsAbsoluteWindows("C:cwd\\another", false);
255 testIsAbsoluteWindows("directory/directory", false);
256 testIsAbsoluteWindows("directory\\directory", false);
257 testIsAbsoluteWindows("/usr/local", true);
238 try testIsAbsoluteWindows("", false);
239 try testIsAbsoluteWindows("/", true);
240 try testIsAbsoluteWindows("//", true);
241 try testIsAbsoluteWindows("//server", true);
242 try testIsAbsoluteWindows("//server/file", true);
243 try testIsAbsoluteWindows("\\\\server\\file", true);
244 try testIsAbsoluteWindows("\\\\server", true);
245 try testIsAbsoluteWindows("\\\\", true);
246 try testIsAbsoluteWindows("c", false);
247 try testIsAbsoluteWindows("c:", false);
248 try testIsAbsoluteWindows("c:\\", true);
249 try testIsAbsoluteWindows("c:/", true);
250 try testIsAbsoluteWindows("c://", true);
251 try testIsAbsoluteWindows("C:/Users/", true);
252 try testIsAbsoluteWindows("C:\\Users\\", true);
253 try testIsAbsoluteWindows("C:cwd/another", false);
254 try testIsAbsoluteWindows("C:cwd\\another", false);
255 try testIsAbsoluteWindows("directory/directory", false);
256 try testIsAbsoluteWindows("directory\\directory", false);
257 try testIsAbsoluteWindows("/usr/local", true);
258258}
259259
260260test "isAbsolutePosix" {
261 testIsAbsolutePosix("", false);
262 testIsAbsolutePosix("/home/foo", true);
263 testIsAbsolutePosix("/home/foo/..", true);
264 testIsAbsolutePosix("bar/", false);
265 testIsAbsolutePosix("./baz", false);
261 try testIsAbsolutePosix("", false);
262 try testIsAbsolutePosix("/home/foo", true);
263 try testIsAbsolutePosix("/home/foo/..", true);
264 try testIsAbsolutePosix("bar/", false);
265 try testIsAbsolutePosix("./baz", false);
266266}
267267
268fn testIsAbsoluteWindows(path: []const u8, expected_result: bool) void {
269 testing.expectEqual(expected_result, isAbsoluteWindows(path));
268fn testIsAbsoluteWindows(path: []const u8, expected_result: bool) !void {
269 try testing.expectEqual(expected_result, isAbsoluteWindows(path));
270270}
271271
272fn testIsAbsolutePosix(path: []const u8, expected_result: bool) void {
273 testing.expectEqual(expected_result, isAbsolutePosix(path));
272fn testIsAbsolutePosix(path: []const u8, expected_result: bool) !void {
273 try testing.expectEqual(expected_result, isAbsolutePosix(path));
274274}
275275
276276pub const WindowsPath = struct {
......@@ -334,33 +334,33 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {
334334test "windowsParsePath" {
335335 {
336336 const parsed = windowsParsePath("//a/b");
337 testing.expect(parsed.is_abs);
338 testing.expect(parsed.kind == WindowsPath.Kind.NetworkShare);
339 testing.expect(mem.eql(u8, parsed.disk_designator, "//a/b"));
337 try testing.expect(parsed.is_abs);
338 try testing.expect(parsed.kind == WindowsPath.Kind.NetworkShare);
339 try testing.expect(mem.eql(u8, parsed.disk_designator, "//a/b"));
340340 }
341341 {
342342 const parsed = windowsParsePath("\\\\a\\b");
343 testing.expect(parsed.is_abs);
344 testing.expect(parsed.kind == WindowsPath.Kind.NetworkShare);
345 testing.expect(mem.eql(u8, parsed.disk_designator, "\\\\a\\b"));
343 try testing.expect(parsed.is_abs);
344 try testing.expect(parsed.kind == WindowsPath.Kind.NetworkShare);
345 try testing.expect(mem.eql(u8, parsed.disk_designator, "\\\\a\\b"));
346346 }
347347 {
348348 const parsed = windowsParsePath("\\\\a\\");
349 testing.expect(!parsed.is_abs);
350 testing.expect(parsed.kind == WindowsPath.Kind.None);
351 testing.expect(mem.eql(u8, parsed.disk_designator, ""));
349 try testing.expect(!parsed.is_abs);
350 try testing.expect(parsed.kind == WindowsPath.Kind.None);
351 try testing.expect(mem.eql(u8, parsed.disk_designator, ""));
352352 }
353353 {
354354 const parsed = windowsParsePath("/usr/local");
355 testing.expect(parsed.is_abs);
356 testing.expect(parsed.kind == WindowsPath.Kind.None);
357 testing.expect(mem.eql(u8, parsed.disk_designator, ""));
355 try testing.expect(parsed.is_abs);
356 try testing.expect(parsed.kind == WindowsPath.Kind.None);
357 try testing.expect(mem.eql(u8, parsed.disk_designator, ""));
358358 }
359359 {
360360 const parsed = windowsParsePath("c:../");
361 testing.expect(!parsed.is_abs);
362 testing.expect(parsed.kind == WindowsPath.Kind.Drive);
363 testing.expect(mem.eql(u8, parsed.disk_designator, "c:"));
361 try testing.expect(!parsed.is_abs);
362 try testing.expect(parsed.kind == WindowsPath.Kind.Drive);
363 try testing.expect(mem.eql(u8, parsed.disk_designator, "c:"));
364364 }
365365}
366366
......@@ -772,13 +772,13 @@ test "resolvePosix" {
772772fn testResolveWindows(paths: []const []const u8, expected: []const u8) !void {
773773 const actual = try resolveWindows(testing.allocator, paths);
774774 defer testing.allocator.free(actual);
775 return testing.expect(mem.eql(u8, actual, expected));
775 try testing.expect(mem.eql(u8, actual, expected));
776776}
777777
778778fn testResolvePosix(paths: []const []const u8, expected: []const u8) !void {
779779 const actual = try resolvePosix(testing.allocator, paths);
780780 defer testing.allocator.free(actual);
781 return testing.expect(mem.eql(u8, actual, expected));
781 try testing.expect(mem.eql(u8, actual, expected));
782782}
783783
784784/// Strip the last component from a file path.
......@@ -856,68 +856,68 @@ pub fn dirnamePosix(path: []const u8) ?[]const u8 {
856856}
857857
858858test "dirnamePosix" {
859 testDirnamePosix("/a/b/c", "/a/b");
860 testDirnamePosix("/a/b/c///", "/a/b");
861 testDirnamePosix("/a", "/");
862 testDirnamePosix("/", null);
863 testDirnamePosix("//", null);
864 testDirnamePosix("///", null);
865 testDirnamePosix("////", null);
866 testDirnamePosix("", null);
867 testDirnamePosix("a", null);
868 testDirnamePosix("a/", null);
869 testDirnamePosix("a//", null);
859 try testDirnamePosix("/a/b/c", "/a/b");
860 try testDirnamePosix("/a/b/c///", "/a/b");
861 try testDirnamePosix("/a", "/");
862 try testDirnamePosix("/", null);
863 try testDirnamePosix("//", null);
864 try testDirnamePosix("///", null);
865 try testDirnamePosix("////", null);
866 try testDirnamePosix("", null);
867 try testDirnamePosix("a", null);
868 try testDirnamePosix("a/", null);
869 try testDirnamePosix("a//", null);
870870}
871871
872872test "dirnameWindows" {
873 testDirnameWindows("c:\\", null);
874 testDirnameWindows("c:\\foo", "c:\\");
875 testDirnameWindows("c:\\foo\\", "c:\\");
876 testDirnameWindows("c:\\foo\\bar", "c:\\foo");
877 testDirnameWindows("c:\\foo\\bar\\", "c:\\foo");
878 testDirnameWindows("c:\\foo\\bar\\baz", "c:\\foo\\bar");
879 testDirnameWindows("\\", null);
880 testDirnameWindows("\\foo", "\\");
881 testDirnameWindows("\\foo\\", "\\");
882 testDirnameWindows("\\foo\\bar", "\\foo");
883 testDirnameWindows("\\foo\\bar\\", "\\foo");
884 testDirnameWindows("\\foo\\bar\\baz", "\\foo\\bar");
885 testDirnameWindows("c:", null);
886 testDirnameWindows("c:foo", null);
887 testDirnameWindows("c:foo\\", null);
888 testDirnameWindows("c:foo\\bar", "c:foo");
889 testDirnameWindows("c:foo\\bar\\", "c:foo");
890 testDirnameWindows("c:foo\\bar\\baz", "c:foo\\bar");
891 testDirnameWindows("file:stream", null);
892 testDirnameWindows("dir\\file:stream", "dir");
893 testDirnameWindows("\\\\unc\\share", null);
894 testDirnameWindows("\\\\unc\\share\\foo", "\\\\unc\\share\\");
895 testDirnameWindows("\\\\unc\\share\\foo\\", "\\\\unc\\share\\");
896 testDirnameWindows("\\\\unc\\share\\foo\\bar", "\\\\unc\\share\\foo");
897 testDirnameWindows("\\\\unc\\share\\foo\\bar\\", "\\\\unc\\share\\foo");
898 testDirnameWindows("\\\\unc\\share\\foo\\bar\\baz", "\\\\unc\\share\\foo\\bar");
899 testDirnameWindows("/a/b/", "/a");
900 testDirnameWindows("/a/b", "/a");
901 testDirnameWindows("/a", "/");
902 testDirnameWindows("", null);
903 testDirnameWindows("/", null);
904 testDirnameWindows("////", null);
905 testDirnameWindows("foo", null);
873 try testDirnameWindows("c:\\", null);
874 try testDirnameWindows("c:\\foo", "c:\\");
875 try testDirnameWindows("c:\\foo\\", "c:\\");
876 try testDirnameWindows("c:\\foo\\bar", "c:\\foo");
877 try testDirnameWindows("c:\\foo\\bar\\", "c:\\foo");
878 try testDirnameWindows("c:\\foo\\bar\\baz", "c:\\foo\\bar");
879 try testDirnameWindows("\\", null);
880 try testDirnameWindows("\\foo", "\\");
881 try testDirnameWindows("\\foo\\", "\\");
882 try testDirnameWindows("\\foo\\bar", "\\foo");
883 try testDirnameWindows("\\foo\\bar\\", "\\foo");
884 try testDirnameWindows("\\foo\\bar\\baz", "\\foo\\bar");
885 try testDirnameWindows("c:", null);
886 try testDirnameWindows("c:foo", null);
887 try testDirnameWindows("c:foo\\", null);
888 try testDirnameWindows("c:foo\\bar", "c:foo");
889 try testDirnameWindows("c:foo\\bar\\", "c:foo");
890 try testDirnameWindows("c:foo\\bar\\baz", "c:foo\\bar");
891 try testDirnameWindows("file:stream", null);
892 try testDirnameWindows("dir\\file:stream", "dir");
893 try testDirnameWindows("\\\\unc\\share", null);
894 try testDirnameWindows("\\\\unc\\share\\foo", "\\\\unc\\share\\");
895 try testDirnameWindows("\\\\unc\\share\\foo\\", "\\\\unc\\share\\");
896 try testDirnameWindows("\\\\unc\\share\\foo\\bar", "\\\\unc\\share\\foo");
897 try testDirnameWindows("\\\\unc\\share\\foo\\bar\\", "\\\\unc\\share\\foo");
898 try testDirnameWindows("\\\\unc\\share\\foo\\bar\\baz", "\\\\unc\\share\\foo\\bar");
899 try testDirnameWindows("/a/b/", "/a");
900 try testDirnameWindows("/a/b", "/a");
901 try testDirnameWindows("/a", "/");
902 try testDirnameWindows("", null);
903 try testDirnameWindows("/", null);
904 try testDirnameWindows("////", null);
905 try testDirnameWindows("foo", null);
906906}
907907
908fn testDirnamePosix(input: []const u8, expected_output: ?[]const u8) void {
908fn testDirnamePosix(input: []const u8, expected_output: ?[]const u8) !void {
909909 if (dirnamePosix(input)) |output| {
910 testing.expect(mem.eql(u8, output, expected_output.?));
910 try testing.expect(mem.eql(u8, output, expected_output.?));
911911 } else {
912 testing.expect(expected_output == null);
912 try testing.expect(expected_output == null);
913913 }
914914}
915915
916fn testDirnameWindows(input: []const u8, expected_output: ?[]const u8) void {
916fn testDirnameWindows(input: []const u8, expected_output: ?[]const u8) !void {
917917 if (dirnameWindows(input)) |output| {
918 testing.expect(mem.eql(u8, output, expected_output.?));
918 try testing.expect(mem.eql(u8, output, expected_output.?));
919919 } else {
920 testing.expect(expected_output == null);
920 try testing.expect(expected_output == null);
921921 }
922922}
923923
......@@ -983,54 +983,54 @@ pub fn basenameWindows(path: []const u8) []const u8 {
983983}
984984
985985test "basename" {
986 testBasename("", "");
987 testBasename("/", "");
988 testBasename("/dir/basename.ext", "basename.ext");
989 testBasename("/basename.ext", "basename.ext");
990 testBasename("basename.ext", "basename.ext");
991 testBasename("basename.ext/", "basename.ext");
992 testBasename("basename.ext//", "basename.ext");
993 testBasename("/aaa/bbb", "bbb");
994 testBasename("/aaa/", "aaa");
995 testBasename("/aaa/b", "b");
996 testBasename("/a/b", "b");
997 testBasename("//a", "a");
998
999 testBasenamePosix("\\dir\\basename.ext", "\\dir\\basename.ext");
1000 testBasenamePosix("\\basename.ext", "\\basename.ext");
1001 testBasenamePosix("basename.ext", "basename.ext");
1002 testBasenamePosix("basename.ext\\", "basename.ext\\");
1003 testBasenamePosix("basename.ext\\\\", "basename.ext\\\\");
1004 testBasenamePosix("foo", "foo");
1005
1006 testBasenameWindows("\\dir\\basename.ext", "basename.ext");
1007 testBasenameWindows("\\basename.ext", "basename.ext");
1008 testBasenameWindows("basename.ext", "basename.ext");
1009 testBasenameWindows("basename.ext\\", "basename.ext");
1010 testBasenameWindows("basename.ext\\\\", "basename.ext");
1011 testBasenameWindows("foo", "foo");
1012 testBasenameWindows("C:", "");
1013 testBasenameWindows("C:.", ".");
1014 testBasenameWindows("C:\\", "");
1015 testBasenameWindows("C:\\dir\\base.ext", "base.ext");
1016 testBasenameWindows("C:\\basename.ext", "basename.ext");
1017 testBasenameWindows("C:basename.ext", "basename.ext");
1018 testBasenameWindows("C:basename.ext\\", "basename.ext");
1019 testBasenameWindows("C:basename.ext\\\\", "basename.ext");
1020 testBasenameWindows("C:foo", "foo");
1021 testBasenameWindows("file:stream", "file:stream");
986 try testBasename("", "");
987 try testBasename("/", "");
988 try testBasename("/dir/basename.ext", "basename.ext");
989 try testBasename("/basename.ext", "basename.ext");
990 try testBasename("basename.ext", "basename.ext");
991 try testBasename("basename.ext/", "basename.ext");
992 try testBasename("basename.ext//", "basename.ext");
993 try testBasename("/aaa/bbb", "bbb");
994 try testBasename("/aaa/", "aaa");
995 try testBasename("/aaa/b", "b");
996 try testBasename("/a/b", "b");
997 try testBasename("//a", "a");
998
999 try testBasenamePosix("\\dir\\basename.ext", "\\dir\\basename.ext");
1000 try testBasenamePosix("\\basename.ext", "\\basename.ext");
1001 try testBasenamePosix("basename.ext", "basename.ext");
1002 try testBasenamePosix("basename.ext\\", "basename.ext\\");
1003 try testBasenamePosix("basename.ext\\\\", "basename.ext\\\\");
1004 try testBasenamePosix("foo", "foo");
1005
1006 try testBasenameWindows("\\dir\\basename.ext", "basename.ext");
1007 try testBasenameWindows("\\basename.ext", "basename.ext");
1008 try testBasenameWindows("basename.ext", "basename.ext");
1009 try testBasenameWindows("basename.ext\\", "basename.ext");
1010 try testBasenameWindows("basename.ext\\\\", "basename.ext");
1011 try testBasenameWindows("foo", "foo");
1012 try testBasenameWindows("C:", "");
1013 try testBasenameWindows("C:.", ".");
1014 try testBasenameWindows("C:\\", "");
1015 try testBasenameWindows("C:\\dir\\base.ext", "base.ext");
1016 try testBasenameWindows("C:\\basename.ext", "basename.ext");
1017 try testBasenameWindows("C:basename.ext", "basename.ext");
1018 try testBasenameWindows("C:basename.ext\\", "basename.ext");
1019 try testBasenameWindows("C:basename.ext\\\\", "basename.ext");
1020 try testBasenameWindows("C:foo", "foo");
1021 try testBasenameWindows("file:stream", "file:stream");
10221022}
10231023
1024fn testBasename(input: []const u8, expected_output: []const u8) void {
1025 testing.expectEqualSlices(u8, expected_output, basename(input));
1024fn testBasename(input: []const u8, expected_output: []const u8) !void {
1025 try testing.expectEqualSlices(u8, expected_output, basename(input));
10261026}
10271027
1028fn testBasenamePosix(input: []const u8, expected_output: []const u8) void {
1029 testing.expectEqualSlices(u8, expected_output, basenamePosix(input));
1028fn testBasenamePosix(input: []const u8, expected_output: []const u8) !void {
1029 try testing.expectEqualSlices(u8, expected_output, basenamePosix(input));
10301030}
10311031
1032fn testBasenameWindows(input: []const u8, expected_output: []const u8) void {
1033 testing.expectEqualSlices(u8, expected_output, basenameWindows(input));
1032fn testBasenameWindows(input: []const u8, expected_output: []const u8) !void {
1033 try testing.expectEqualSlices(u8, expected_output, basenameWindows(input));
10341034}
10351035
10361036/// Returns the relative path from `from` to `to`. If `from` and `to` each
......@@ -1212,13 +1212,13 @@ test "relative" {
12121212fn testRelativePosix(from: []const u8, to: []const u8, expected_output: []const u8) !void {
12131213 const result = try relativePosix(testing.allocator, from, to);
12141214 defer testing.allocator.free(result);
1215 testing.expectEqualSlices(u8, expected_output, result);
1215 try testing.expectEqualSlices(u8, expected_output, result);
12161216}
12171217
12181218fn testRelativeWindows(from: []const u8, to: []const u8, expected_output: []const u8) !void {
12191219 const result = try relativeWindows(testing.allocator, from, to);
12201220 defer testing.allocator.free(result);
1221 testing.expectEqualSlices(u8, expected_output, result);
1221 try testing.expectEqualSlices(u8, expected_output, result);
12221222}
12231223
12241224/// Returns the extension of the file name (if any).
......@@ -1241,47 +1241,47 @@ pub fn extension(path: []const u8) []const u8 {
12411241 return filename[index..];
12421242}
12431243
1244fn testExtension(path: []const u8, expected: []const u8) void {
1245 std.testing.expectEqualStrings(expected, extension(path));
1244fn testExtension(path: []const u8, expected: []const u8) !void {
1245 try std.testing.expectEqualStrings(expected, extension(path));
12461246}
12471247
12481248test "extension" {
1249 testExtension("", "");
1250 testExtension(".", "");
1251 testExtension("a.", ".");
1252 testExtension("abc.", ".");
1253 testExtension(".a", "");
1254 testExtension(".file", "");
1255 testExtension(".gitignore", "");
1256 testExtension("file.ext", ".ext");
1257 testExtension("file.ext.", ".");
1258 testExtension("very-long-file.bruh", ".bruh");
1259 testExtension("a.b.c", ".c");
1260 testExtension("a.b.c/", ".c");
1261
1262 testExtension("/", "");
1263 testExtension("/.", "");
1264 testExtension("/a.", ".");
1265 testExtension("/abc.", ".");
1266 testExtension("/.a", "");
1267 testExtension("/.file", "");
1268 testExtension("/.gitignore", "");
1269 testExtension("/file.ext", ".ext");
1270 testExtension("/file.ext.", ".");
1271 testExtension("/very-long-file.bruh", ".bruh");
1272 testExtension("/a.b.c", ".c");
1273 testExtension("/a.b.c/", ".c");
1274
1275 testExtension("/foo/bar/bam/", "");
1276 testExtension("/foo/bar/bam/.", "");
1277 testExtension("/foo/bar/bam/a.", ".");
1278 testExtension("/foo/bar/bam/abc.", ".");
1279 testExtension("/foo/bar/bam/.a", "");
1280 testExtension("/foo/bar/bam/.file", "");
1281 testExtension("/foo/bar/bam/.gitignore", "");
1282 testExtension("/foo/bar/bam/file.ext", ".ext");
1283 testExtension("/foo/bar/bam/file.ext.", ".");
1284 testExtension("/foo/bar/bam/very-long-file.bruh", ".bruh");
1285 testExtension("/foo/bar/bam/a.b.c", ".c");
1286 testExtension("/foo/bar/bam/a.b.c/", ".c");
1249 try testExtension("", "");
1250 try testExtension(".", "");
1251 try testExtension("a.", ".");
1252 try testExtension("abc.", ".");
1253 try testExtension(".a", "");
1254 try testExtension(".file", "");
1255 try testExtension(".gitignore", "");
1256 try testExtension("file.ext", ".ext");
1257 try testExtension("file.ext.", ".");
1258 try testExtension("very-long-file.bruh", ".bruh");
1259 try testExtension("a.b.c", ".c");
1260 try testExtension("a.b.c/", ".c");
1261
1262 try testExtension("/", "");
1263 try testExtension("/.", "");
1264 try testExtension("/a.", ".");
1265 try testExtension("/abc.", ".");
1266 try testExtension("/.a", "");
1267 try testExtension("/.file", "");
1268 try testExtension("/.gitignore", "");
1269 try testExtension("/file.ext", ".ext");
1270 try testExtension("/file.ext.", ".");
1271 try testExtension("/very-long-file.bruh", ".bruh");
1272 try testExtension("/a.b.c", ".c");
1273 try testExtension("/a.b.c/", ".c");
1274
1275 try testExtension("/foo/bar/bam/", "");
1276 try testExtension("/foo/bar/bam/.", "");
1277 try testExtension("/foo/bar/bam/a.", ".");
1278 try testExtension("/foo/bar/bam/abc.", ".");
1279 try testExtension("/foo/bar/bam/.a", "");
1280 try testExtension("/foo/bar/bam/.file", "");
1281 try testExtension("/foo/bar/bam/.gitignore", "");
1282 try testExtension("/foo/bar/bam/file.ext", ".ext");
1283 try testExtension("/foo/bar/bam/file.ext.", ".");
1284 try testExtension("/foo/bar/bam/very-long-file.bruh", ".bruh");
1285 try testExtension("/foo/bar/bam/a.b.c", ".c");
1286 try testExtension("/foo/bar/bam/a.b.c/", ".c");
12871287}
lib/std/fs/test.zig+52-52
......@@ -46,7 +46,7 @@ test "Dir.readLink" {
4646fn testReadLink(dir: Dir, target_path: []const u8, symlink_path: []const u8) !void {
4747 var buffer: [fs.MAX_PATH_BYTES]u8 = undefined;
4848 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));
5050}
5151
5252test "accessAbsolute" {
......@@ -132,7 +132,7 @@ test "readLinkAbsolute" {
132132fn testReadLinkAbsolute(target_path: []const u8, symlink_path: []const u8) !void {
133133 var buffer: [fs.MAX_PATH_BYTES]u8 = undefined;
134134 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));
136136}
137137
138138test "Dir.Iterator" {
......@@ -159,9 +159,9 @@ test "Dir.Iterator" {
159159 try entries.append(Dir.Entry{ .name = name, .kind = entry.kind });
160160 }
161161
162 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 }));
164 testing.expect(contains(&entries, Dir.Entry{ .name = "some_dir", .kind = Dir.Entry.Kind.Directory }));
162 try testing.expect(entries.items.len == 2); // note that the Iterator skips '.' and '..'
163 try testing.expect(contains(&entries, Dir.Entry{ .name = "some_file", .kind = Dir.Entry.Kind.File }));
164 try testing.expect(contains(&entries, Dir.Entry{ .name = "some_dir", .kind = Dir.Entry.Kind.Directory }));
165165}
166166
167167fn entryEql(lhs: Dir.Entry, rhs: Dir.Entry) bool {
......@@ -203,7 +203,7 @@ test "Dir.realpath smoke test" {
203203 const file_path = try tmp_dir.dir.realpath("test_file", buf1[0..]);
204204 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));
207207 }
208208
209209 // Next, test alloc version
......@@ -211,7 +211,7 @@ test "Dir.realpath smoke test" {
211211 const file_path = try tmp_dir.dir.realpathAlloc(&arena.allocator, "test_file");
212212 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));
215215 }
216216}
217217
......@@ -224,7 +224,7 @@ test "readAllAlloc" {
224224
225225 const buf1 = try file.readToEndAlloc(testing.allocator, 1024);
226226 defer testing.allocator.free(buf1);
227 testing.expect(buf1.len == 0);
227 try testing.expect(buf1.len == 0);
228228
229229 const write_buf: []const u8 = "this is a test.\nthis is a test.\nthis is a test.\nthis is a test.\n";
230230 try file.writeAll(write_buf);
......@@ -233,19 +233,19 @@ test "readAllAlloc" {
233233 // max_bytes > file_size
234234 const buf2 = try file.readToEndAlloc(testing.allocator, 1024);
235235 defer testing.allocator.free(buf2);
236 testing.expectEqual(write_buf.len, buf2.len);
237 testing.expect(std.mem.eql(u8, write_buf, buf2));
236 try testing.expectEqual(write_buf.len, buf2.len);
237 try testing.expect(std.mem.eql(u8, write_buf, buf2));
238238 try file.seekTo(0);
239239
240240 // max_bytes == file_size
241241 const buf3 = try file.readToEndAlloc(testing.allocator, write_buf.len);
242242 defer testing.allocator.free(buf3);
243 testing.expectEqual(write_buf.len, buf3.len);
244 testing.expect(std.mem.eql(u8, write_buf, buf3));
243 try testing.expectEqual(write_buf.len, buf3.len);
244 try testing.expect(std.mem.eql(u8, write_buf, buf3));
245245 try file.seekTo(0);
246246
247247 // 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));
249249}
250250
251251test "directory operations on files" {
......@@ -257,22 +257,22 @@ test "directory operations on files" {
257257 var file = try tmp_dir.dir.createFile(test_file_name, .{ .read = true });
258258 file.close();
259259
260 testing.expectError(error.PathAlreadyExists, tmp_dir.dir.makeDir(test_file_name));
261 testing.expectError(error.NotDir, tmp_dir.dir.openDir(test_file_name, .{}));
262 testing.expectError(error.NotDir, tmp_dir.dir.deleteDir(test_file_name));
260 try testing.expectError(error.PathAlreadyExists, tmp_dir.dir.makeDir(test_file_name));
261 try testing.expectError(error.NotDir, tmp_dir.dir.openDir(test_file_name, .{}));
262 try testing.expectError(error.NotDir, tmp_dir.dir.deleteDir(test_file_name));
263263
264264 if (builtin.os.tag != .wasi and builtin.os.tag != .freebsd and builtin.os.tag != .openbsd) {
265265 const absolute_path = try tmp_dir.dir.realpathAlloc(testing.allocator, test_file_name);
266266 defer testing.allocator.free(absolute_path);
267267
268 testing.expectError(error.PathAlreadyExists, fs.makeDirAbsolute(absolute_path));
269 testing.expectError(error.NotDir, fs.deleteDirAbsolute(absolute_path));
268 try testing.expectError(error.PathAlreadyExists, fs.makeDirAbsolute(absolute_path));
269 try testing.expectError(error.NotDir, fs.deleteDirAbsolute(absolute_path));
270270 }
271271
272272 // ensure the file still exists and is a file as a sanity check
273273 file = try tmp_dir.dir.openFile(test_file_name, .{});
274274 const stat = try file.stat();
275 testing.expect(stat.kind == .File);
275 try testing.expect(stat.kind == .File);
276276 file.close();
277277}
278278
......@@ -287,23 +287,23 @@ test "file operations on directories" {
287287
288288 try tmp_dir.dir.makeDir(test_dir_name);
289289
290 testing.expectError(error.IsDir, tmp_dir.dir.createFile(test_dir_name, .{}));
291 testing.expectError(error.IsDir, tmp_dir.dir.deleteFile(test_dir_name));
290 try testing.expectError(error.IsDir, tmp_dir.dir.createFile(test_dir_name, .{}));
291 try testing.expectError(error.IsDir, tmp_dir.dir.deleteFile(test_dir_name));
292292 // Currently, WASI will return error.Unexpected (via ENOTCAPABLE) when attempting fd_read on a directory handle.
293293 // TODO: Re-enable on WASI once https://github.com/bytecodealliance/wasmtime/issues/1935 is resolved.
294294 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)));
296296 }
297297 // Note: The `.write = true` is necessary to ensure the error occurs on all platforms.
298298 // 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
301301 if (builtin.os.tag != .wasi and builtin.os.tag != .freebsd and builtin.os.tag != .openbsd) {
302302 const absolute_path = try tmp_dir.dir.realpathAlloc(testing.allocator, test_dir_name);
303303 defer testing.allocator.free(absolute_path);
304304
305 testing.expectError(error.IsDir, fs.createFileAbsolute(absolute_path, .{}));
306 testing.expectError(error.IsDir, fs.deleteFileAbsolute(absolute_path));
305 try testing.expectError(error.IsDir, fs.createFileAbsolute(absolute_path, .{}));
306 try testing.expectError(error.IsDir, fs.deleteFileAbsolute(absolute_path));
307307 }
308308
309309 // ensure the directory still exists as a sanity check
......@@ -316,7 +316,7 @@ test "deleteDir" {
316316 defer tmp_dir.cleanup();
317317
318318 // 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
321321 var dir = try tmp_dir.dir.makeOpenPath("test_dir", .{});
322322 var file = try dir.createFile("test_file", .{});
......@@ -326,7 +326,7 @@ test "deleteDir" {
326326 // deleting a non-empty directory
327327 // TODO: Re-enable this check on Windows, see https://github.com/ziglang/zig/issues/5537
328328 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"));
330330 }
331331
332332 dir = try tmp_dir.dir.openDir("test_dir", .{});
......@@ -341,7 +341,7 @@ test "Dir.rename files" {
341341 var tmp_dir = tmpDir(.{});
342342 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
346346 // Renaming files
347347 const test_file_name = "test_file";
......@@ -351,7 +351,7 @@ test "Dir.rename files" {
351351 try tmp_dir.dir.rename(test_file_name, renamed_test_file_name);
352352
353353 // 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, .{}));
355355 file = try tmp_dir.dir.openFile(renamed_test_file_name, .{});
356356 file.close();
357357
......@@ -363,7 +363,7 @@ test "Dir.rename files" {
363363 existing_file.close();
364364 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, .{}));
367367 file = try tmp_dir.dir.openFile("existing_file", .{});
368368 file.close();
369369}
......@@ -380,7 +380,7 @@ test "Dir.rename directories" {
380380 try tmp_dir.dir.rename("test_dir", "test_dir_renamed");
381381
382382 // 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", .{}));
384384 var dir = try tmp_dir.dir.openDir("test_dir_renamed", .{});
385385
386386 // Put a file in the directory
......@@ -391,7 +391,7 @@ test "Dir.rename directories" {
391391 try tmp_dir.dir.rename("test_dir_renamed", "test_dir_renamed_again");
392392
393393 // 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", .{}));
395395 dir = try tmp_dir.dir.openDir("test_dir_renamed_again", .{});
396396 file = try dir.openFile("test_file", .{});
397397 file.close();
......@@ -402,7 +402,7 @@ test "Dir.rename directories" {
402402 file = try target_dir.createFile("filler", .{ .read = true });
403403 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
407407 // Ensure the directory was not renamed
408408 dir = try tmp_dir.dir.openDir("test_dir_renamed_again", .{});
......@@ -421,8 +421,8 @@ test "Dir.rename file <-> dir" {
421421 var file = try tmp_dir.dir.createFile("test_file", .{ .read = true });
422422 file.close();
423423 try tmp_dir.dir.makeDir("test_dir");
424 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"));
424 try testing.expectError(error.IsDir, tmp_dir.dir.rename("test_file", "test_dir"));
425 try testing.expectError(error.NotDir, tmp_dir.dir.rename("test_dir", "test_file"));
426426}
427427
428428test "rename" {
......@@ -440,7 +440,7 @@ test "rename" {
440440 try fs.rename(tmp_dir1.dir, test_file_name, tmp_dir2.dir, renamed_test_file_name);
441441
442442 // 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, .{}));
444444 file = try tmp_dir2.dir.openFile(renamed_test_file_name, .{});
445445 file.close();
446446}
......@@ -461,7 +461,7 @@ test "renameAbsolute" {
461461 break :blk try fs.realpathAlloc(&arena.allocator, relative_path);
462462 };
463463
464 testing.expectError(error.FileNotFound, fs.renameAbsolute(
464 try testing.expectError(error.FileNotFound, fs.renameAbsolute(
465465 try fs.path.join(allocator, &[_][]const u8{ base_path, "missing_file_name" }),
466466 try fs.path.join(allocator, &[_][]const u8{ base_path, "something_else" }),
467467 ));
......@@ -477,10 +477,10 @@ test "renameAbsolute" {
477477 );
478478
479479 // 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, .{}));
481481 file = try tmp_dir.dir.openFile(renamed_test_file_name, .{});
482482 const stat = try file.stat();
483 testing.expect(stat.kind == .File);
483 try testing.expect(stat.kind == .File);
484484 file.close();
485485
486486 // Renaming directories
......@@ -493,7 +493,7 @@ test "renameAbsolute" {
493493 );
494494
495495 // 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, .{}));
497497 var dir = try tmp_dir.dir.openDir(renamed_test_dir_name, .{});
498498 dir.close();
499499}
......@@ -516,7 +516,7 @@ test "makePath, put some files in it, deleteTree" {
516516 if (tmp.dir.openDir("os_test_tmp", .{})) |dir| {
517517 @panic("expected error");
518518 } else |err| {
519 testing.expect(err == error.FileNotFound);
519 try testing.expect(err == error.FileNotFound);
520520 }
521521}
522522
......@@ -530,7 +530,7 @@ test "access file" {
530530 if (tmp.dir.access("os_test_tmp" ++ fs.path.sep_str ++ "file.txt", .{})) |ok| {
531531 @panic("expected error");
532532 } else |err| {
533 testing.expect(err == error.FileNotFound);
533 try testing.expect(err == error.FileNotFound);
534534 }
535535
536536 try tmp.dir.writeFile("os_test_tmp" ++ fs.path.sep_str ++ "file.txt", "");
......@@ -600,7 +600,7 @@ test "sendfile" {
600600 .header_count = 2,
601601 });
602602 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"));
604604}
605605
606606test "copyRangeAll" {
......@@ -626,7 +626,7 @@ test "copyRangeAll" {
626626 _ = try src_file.copyRangeAll(0, dest_file, 0, data.len);
627627
628628 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));
630630}
631631
632632test "fs.copyFile" {
......@@ -655,7 +655,7 @@ fn expectFileContents(dir: Dir, file_path: []const u8, data: []const u8) !void {
655655 const contents = try dir.readFileAlloc(testing.allocator, file_path, 1000);
656656 defer testing.allocator.free(contents);
657657
658 testing.expectEqualSlices(u8, data, contents);
658 try testing.expectEqualSlices(u8, data, contents);
659659}
660660
661661test "AtomicFile" {
......@@ -676,7 +676,7 @@ test "AtomicFile" {
676676 }
677677 const content = try tmp.dir.readFileAlloc(testing.allocator, test_out_file, 9999);
678678 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
681681 try tmp.dir.deleteFile(test_out_file);
682682}
......@@ -685,7 +685,7 @@ test "realpath" {
685685 if (builtin.os.tag == .wasi) return error.SkipZigTest;
686686
687687 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));
689689}
690690
691691test "open file with exclusive nonblocking lock twice" {
......@@ -700,7 +700,7 @@ test "open file with exclusive nonblocking lock twice" {
700700 defer file1.close();
701701
702702 const file2 = tmp.dir.createFile(filename, .{ .lock = .Exclusive, .lock_nonblocking = true });
703 testing.expectError(error.WouldBlock, file2);
703 try testing.expectError(error.WouldBlock, file2);
704704}
705705
706706test "open file with shared and exclusive nonblocking lock" {
......@@ -715,7 +715,7 @@ test "open file with shared and exclusive nonblocking lock" {
715715 defer file1.close();
716716
717717 const file2 = tmp.dir.createFile(filename, .{ .lock = .Exclusive, .lock_nonblocking = true });
718 testing.expectError(error.WouldBlock, file2);
718 try testing.expectError(error.WouldBlock, file2);
719719}
720720
721721test "open file with exclusive and shared nonblocking lock" {
......@@ -730,7 +730,7 @@ test "open file with exclusive and shared nonblocking lock" {
730730 defer file1.close();
731731
732732 const file2 = tmp.dir.createFile(filename, .{ .lock = .Shared, .lock_nonblocking = true });
733 testing.expectError(error.WouldBlock, file2);
733 try testing.expectError(error.WouldBlock, file2);
734734}
735735
736736test "open file with exclusive lock twice, make sure it waits" {
......@@ -790,7 +790,7 @@ test "open file with exclusive nonblocking lock twice (absolute paths)" {
790790
791791 const file2 = fs.createFileAbsolute(filename, .{ .lock = .Exclusive, .lock_nonblocking = true });
792792 file1.close();
793 testing.expectError(error.WouldBlock, file2);
793 try testing.expectError(error.WouldBlock, file2);
794794
795795 try fs.deleteFileAbsolute(filename);
796796}
......@@ -830,6 +830,6 @@ test "walker" {
830830 try fs.path.join(allocator, &[_][]const u8{ expected_dir_name, name });
831831
832832 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));
834834 }
835835}
lib/std/fs/wasi.zig+3-3
......@@ -174,8 +174,8 @@ test "extracting WASI preopens" {
174174
175175 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);
178178 const preopen = preopens.find(PreopenType{ .Dir = "." }) orelse unreachable;
179 std.testing.expect(preopen.@"type".eql(PreopenType{ .Dir = "." }));
180 std.testing.expectEqual(@as(usize, 3), preopen.fd);
179 try std.testing.expect(preopen.@"type".eql(PreopenType{ .Dir = "." }));
180 try std.testing.expectEqual(@as(usize, 3), preopen.fd);
181181}
lib/std/fs/watch.zig+3-3
......@@ -662,13 +662,13 @@ fn testWriteWatchWriteDelete(allocator: *Allocator) !void {
662662
663663 const read_contents = try std.fs.cwd().readFileAlloc(allocator, file_path, 1024 * 1024);
664664 defer allocator.free(read_contents);
665 testing.expectEqualSlices(u8, contents, read_contents);
665 try testing.expectEqualSlices(u8, contents, read_contents);
666666
667667 // now watch the file
668668 var watch = try Watch(void).init(allocator, 0);
669669 defer watch.deinit();
670670
671 testing.expect((try watch.addFile(file_path, {})) == null);
671 try testing.expect((try watch.addFile(file_path, {})) == null);
672672
673673 var ev = async watch.channel.get();
674674 var ev_consumed = false;
......@@ -698,7 +698,7 @@ fn testWriteWatchWriteDelete(allocator: *Allocator) !void {
698698 const contents_updated = try std.fs.cwd().readFileAlloc(allocator, file_path, 1024 * 1024);
699699 defer allocator.free(contents_updated);
700700
701 testing.expectEqualSlices(u8,
701 try testing.expectEqualSlices(u8,
702702 \\line 1
703703 \\lorem ipsum
704704 , contents_updated);
lib/std/hash/adler.zig+6-6
......@@ -99,21 +99,21 @@ pub const Adler32 = struct {
9999};
100100
101101test "adler32 sanity" {
102 testing.expectEqual(@as(u32, 0x620062), Adler32.hash("a"));
103 testing.expectEqual(@as(u32, 0xbc002ed), Adler32.hash("example"));
102 try testing.expectEqual(@as(u32, 0x620062), Adler32.hash("a"));
103 try testing.expectEqual(@as(u32, 0xbc002ed), Adler32.hash("example"));
104104}
105105
106106test "adler32 long" {
107107 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
110110 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..]));
112112}
113113
114114test "adler32 very long" {
115115 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..]));
117117}
118118
119119test "adler32 very long with variation" {
......@@ -129,5 +129,5 @@ test "adler32 very long with variation" {
129129 break :blk result;
130130 };
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..]));
133133}
lib/std/hash/auto_hash.zig+46-46
......@@ -239,18 +239,18 @@ fn testHashDeepRecursive(key: anytype) u64 {
239239
240240test "typeContainsSlice" {
241241 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));
245 testing.expect(!typeContainsSlice(u8));
244 try testing.expect(typeContainsSlice([]const u8));
245 try testing.expect(!typeContainsSlice(u8));
246246 const A = struct { x: []const u8 };
247247 const B = struct { a: A };
248248 const C = struct { b: B };
249249 const D = struct { x: u8 };
250 testing.expect(typeContainsSlice(A));
251 testing.expect(typeContainsSlice(B));
252 testing.expect(typeContainsSlice(C));
253 testing.expect(!typeContainsSlice(D));
250 try testing.expect(typeContainsSlice(A));
251 try testing.expect(typeContainsSlice(B));
252 try testing.expect(typeContainsSlice(C));
253 try testing.expect(!typeContainsSlice(D));
254254 }
255255}
256256
......@@ -261,17 +261,17 @@ test "hash pointer" {
261261 const c = &array[2];
262262 const d = a;
263263
264 testing.expect(testHashShallow(a) == testHashShallow(d));
265 testing.expect(testHashShallow(a) != testHashShallow(c));
266 testing.expect(testHashShallow(a) != testHashShallow(b));
264 try testing.expect(testHashShallow(a) == testHashShallow(d));
265 try testing.expect(testHashShallow(a) != testHashShallow(c));
266 try testing.expect(testHashShallow(a) != testHashShallow(b));
267267
268 testing.expect(testHashDeep(a) == testHashDeep(a));
269 testing.expect(testHashDeep(a) == testHashDeep(c));
270 testing.expect(testHashDeep(a) == testHashDeep(b));
268 try testing.expect(testHashDeep(a) == testHashDeep(a));
269 try testing.expect(testHashDeep(a) == testHashDeep(c));
270 try testing.expect(testHashDeep(a) == testHashDeep(b));
271271
272 testing.expect(testHashDeepRecursive(a) == testHashDeepRecursive(a));
273 testing.expect(testHashDeepRecursive(a) == testHashDeepRecursive(c));
274 testing.expect(testHashDeepRecursive(a) == testHashDeepRecursive(b));
272 try testing.expect(testHashDeepRecursive(a) == testHashDeepRecursive(a));
273 try testing.expect(testHashDeepRecursive(a) == testHashDeepRecursive(c));
274 try testing.expect(testHashDeepRecursive(a) == testHashDeepRecursive(b));
275275}
276276
277277test "hash slice shallow" {
......@@ -286,10 +286,10 @@ test "hash slice shallow" {
286286 const a = array1[runtime_zero..];
287287 const b = array2[runtime_zero..];
288288 const c = array1[runtime_zero..3];
289 testing.expect(testHashShallow(a) == testHashShallow(a));
290 testing.expect(testHashShallow(a) != testHashShallow(array1));
291 testing.expect(testHashShallow(a) != testHashShallow(b));
292 testing.expect(testHashShallow(a) != testHashShallow(c));
289 try testing.expect(testHashShallow(a) == testHashShallow(a));
290 try testing.expect(testHashShallow(a) != testHashShallow(array1));
291 try testing.expect(testHashShallow(a) != testHashShallow(b));
292 try testing.expect(testHashShallow(a) != testHashShallow(c));
293293}
294294
295295test "hash slice deep" {
......@@ -302,10 +302,10 @@ test "hash slice deep" {
302302 const a = array1[0..];
303303 const b = array2[0..];
304304 const c = array1[0..3];
305 testing.expect(testHashDeep(a) == testHashDeep(a));
306 testing.expect(testHashDeep(a) == testHashDeep(array1));
307 testing.expect(testHashDeep(a) == testHashDeep(b));
308 testing.expect(testHashDeep(a) != testHashDeep(c));
305 try testing.expect(testHashDeep(a) == testHashDeep(a));
306 try testing.expect(testHashDeep(a) == testHashDeep(array1));
307 try testing.expect(testHashDeep(a) == testHashDeep(b));
308 try testing.expect(testHashDeep(a) != testHashDeep(c));
309309}
310310
311311test "hash struct deep" {
......@@ -331,28 +331,28 @@ test "hash struct deep" {
331331 defer allocator.destroy(bar.c);
332332 defer allocator.destroy(baz.c);
333333
334 testing.expect(testHashDeep(foo) == testHashDeep(bar));
335 testing.expect(testHashDeep(foo) != testHashDeep(baz));
336 testing.expect(testHashDeep(bar) != testHashDeep(baz));
334 try testing.expect(testHashDeep(foo) == testHashDeep(bar));
335 try testing.expect(testHashDeep(foo) != testHashDeep(baz));
336 try testing.expect(testHashDeep(bar) != testHashDeep(baz));
337337
338338 var hasher = Wyhash.init(0);
339339 const h = testHashDeep(foo);
340340 autoHash(&hasher, foo.a);
341341 autoHash(&hasher, foo.b);
342342 autoHash(&hasher, foo.c.*);
343 testing.expectEqual(h, hasher.final());
343 try testing.expectEqual(h, hasher.final());
344344
345345 const h2 = testHashDeepRecursive(&foo);
346 testing.expect(h2 != testHashDeep(&foo));
347 testing.expect(h2 == testHashDeep(foo));
346 try testing.expect(h2 != testHashDeep(&foo));
347 try testing.expect(h2 == testHashDeep(foo));
348348}
349349
350350test "testHash optional" {
351351 const a: ?u32 = 123;
352352 const b: ?u32 = null;
353 testing.expectEqual(testHash(a), testHash(@as(u32, 123)));
354 testing.expect(testHash(a) != testHash(b));
355 testing.expectEqual(testHash(b), 0);
353 try testing.expectEqual(testHash(a), testHash(@as(u32, 123)));
354 try testing.expect(testHash(a) != testHash(b));
355 try testing.expectEqual(testHash(b), 0);
356356}
357357
358358test "testHash array" {
......@@ -362,7 +362,7 @@ test "testHash array" {
362362 autoHash(&hasher, @as(u32, 1));
363363 autoHash(&hasher, @as(u32, 2));
364364 autoHash(&hasher, @as(u32, 3));
365 testing.expectEqual(h, hasher.final());
365 try testing.expectEqual(h, hasher.final());
366366}
367367
368368test "testHash struct" {
......@@ -377,7 +377,7 @@ test "testHash struct" {
377377 autoHash(&hasher, @as(u32, 1));
378378 autoHash(&hasher, @as(u32, 2));
379379 autoHash(&hasher, @as(u32, 3));
380 testing.expectEqual(h, hasher.final());
380 try testing.expectEqual(h, hasher.final());
381381}
382382
383383test "testHash union" {
......@@ -390,12 +390,12 @@ test "testHash union" {
390390 const a = Foo{ .A = 18 };
391391 var b = Foo{ .B = true };
392392 const c = Foo{ .C = 18 };
393 testing.expect(testHash(a) == testHash(a));
394 testing.expect(testHash(a) != testHash(b));
395 testing.expect(testHash(a) != testHash(c));
393 try testing.expect(testHash(a) == testHash(a));
394 try testing.expect(testHash(a) != testHash(b));
395 try testing.expect(testHash(a) != testHash(c));
396396
397397 b = Foo{ .A = 18 };
398 testing.expect(testHash(a) == testHash(b));
398 try testing.expect(testHash(a) == testHash(b));
399399}
400400
401401test "testHash vector" {
......@@ -404,13 +404,13 @@ test "testHash vector" {
404404
405405 const a: meta.Vector(4, u32) = [_]u32{ 1, 2, 3, 4 };
406406 const b: meta.Vector(4, u32) = [_]u32{ 1, 2, 3, 5 };
407 testing.expect(testHash(a) == testHash(a));
408 testing.expect(testHash(a) != testHash(b));
407 try testing.expect(testHash(a) == testHash(a));
408 try testing.expect(testHash(a) != testHash(b));
409409
410410 const c: meta.Vector(4, u31) = [_]u31{ 1, 2, 3, 4 };
411411 const d: meta.Vector(4, u31) = [_]u31{ 1, 2, 3, 5 };
412 testing.expect(testHash(c) == testHash(c));
413 testing.expect(testHash(c) != testHash(d));
412 try testing.expect(testHash(c) == testHash(c));
413 try testing.expect(testHash(c) != testHash(d));
414414}
415415
416416test "testHash error union" {
......@@ -422,7 +422,7 @@ test "testHash error union" {
422422 };
423423 const f = Foo{};
424424 const g: Errors!Foo = Errors.Test;
425 testing.expect(testHash(f) != testHash(g));
426 testing.expect(testHash(f) == testHash(Foo{}));
427 testing.expect(testHash(g) == testHash(Errors.Test));
425 try testing.expect(testHash(f) != testHash(g));
426 try testing.expect(testHash(f) == testHash(Foo{}));
427 try testing.expect(testHash(g) == testHash(Errors.Test));
428428}
lib/std/hash/cityhash.zig+7-7
......@@ -381,14 +381,14 @@ fn CityHash32hashIgnoreSeed(str: []const u8, seed: u32) u32 {
381381
382382test "cityhash32" {
383383 const Test = struct {
384 fn doTest() void {
384 fn doTest() !void {
385385 // Note: SMHasher doesn't provide a 32bit version of the algorithm.
386386 // Note: The implementation was verified against the Google Abseil version.
387 std.testing.expectEqual(SMHasherTest(CityHash32hashIgnoreSeed), 0x68254F81);
388 std.testing.expectEqual(SMHasherTest(CityHash32hashIgnoreSeed), 0x68254F81);
387 try std.testing.expectEqual(SMHasherTest(CityHash32hashIgnoreSeed), 0x68254F81);
388 try std.testing.expectEqual(SMHasherTest(CityHash32hashIgnoreSeed), 0x68254F81);
389389 }
390390 };
391 Test.doTest();
391 try Test.doTest();
392392 // TODO This is uncommented to prevent OOM on the CI server. Re-enable this test
393393 // case once we ship stage2.
394394 //@setEvalBranchQuota(50000);
......@@ -397,13 +397,13 @@ test "cityhash32" {
397397
398398test "cityhash64" {
399399 const Test = struct {
400 fn doTest() void {
400 fn doTest() !void {
401401 // Note: This is not compliant with the SMHasher implementation of CityHash64!
402402 // 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);
404404 }
405405 };
406 Test.doTest();
406 try Test.doTest();
407407 // TODO This is uncommented to prevent OOM on the CI server. Re-enable this test
408408 // case once we ship stage2.
409409 //@setEvalBranchQuota(50000);
lib/std/hash/crc.zig+12-12
......@@ -109,9 +109,9 @@ test "crc32 ieee" {
109109
110110 const Crc32Ieee = Crc32WithPoly(.IEEE);
111111
112 testing.expect(Crc32Ieee.hash("") == 0x00000000);
113 testing.expect(Crc32Ieee.hash("a") == 0xe8b7be43);
114 testing.expect(Crc32Ieee.hash("abc") == 0x352441c2);
112 try testing.expect(Crc32Ieee.hash("") == 0x00000000);
113 try testing.expect(Crc32Ieee.hash("a") == 0xe8b7be43);
114 try testing.expect(Crc32Ieee.hash("abc") == 0x352441c2);
115115}
116116
117117test "crc32 castagnoli" {
......@@ -119,9 +119,9 @@ test "crc32 castagnoli" {
119119
120120 const Crc32Castagnoli = Crc32WithPoly(.Castagnoli);
121121
122 testing.expect(Crc32Castagnoli.hash("") == 0x00000000);
123 testing.expect(Crc32Castagnoli.hash("a") == 0xc1d04330);
124 testing.expect(Crc32Castagnoli.hash("abc") == 0x364b3fb7);
122 try testing.expect(Crc32Castagnoli.hash("") == 0x00000000);
123 try testing.expect(Crc32Castagnoli.hash("a") == 0xc1d04330);
124 try testing.expect(Crc32Castagnoli.hash("abc") == 0x364b3fb7);
125125}
126126
127127// half-byte lookup table implementation.
......@@ -177,9 +177,9 @@ test "small crc32 ieee" {
177177
178178 const Crc32Ieee = Crc32SmallWithPoly(.IEEE);
179179
180 testing.expect(Crc32Ieee.hash("") == 0x00000000);
181 testing.expect(Crc32Ieee.hash("a") == 0xe8b7be43);
182 testing.expect(Crc32Ieee.hash("abc") == 0x352441c2);
180 try testing.expect(Crc32Ieee.hash("") == 0x00000000);
181 try testing.expect(Crc32Ieee.hash("a") == 0xe8b7be43);
182 try testing.expect(Crc32Ieee.hash("abc") == 0x352441c2);
183183}
184184
185185test "small crc32 castagnoli" {
......@@ -187,7 +187,7 @@ test "small crc32 castagnoli" {
187187
188188 const Crc32Castagnoli = Crc32SmallWithPoly(.Castagnoli);
189189
190 testing.expect(Crc32Castagnoli.hash("") == 0x00000000);
191 testing.expect(Crc32Castagnoli.hash("a") == 0xc1d04330);
192 testing.expect(Crc32Castagnoli.hash("abc") == 0x364b3fb7);
190 try testing.expect(Crc32Castagnoli.hash("") == 0x00000000);
191 try testing.expect(Crc32Castagnoli.hash("a") == 0xc1d04330);
192 try testing.expect(Crc32Castagnoli.hash("abc") == 0x364b3fb7);
193193}
lib/std/hash/fnv.zig+8-8
......@@ -46,18 +46,18 @@ fn Fnv1a(comptime T: type, comptime prime: T, comptime offset: T) type {
4646}
4747
4848test "fnv1a-32" {
49 testing.expect(Fnv1a_32.hash("") == 0x811c9dc5);
50 testing.expect(Fnv1a_32.hash("a") == 0xe40c292c);
51 testing.expect(Fnv1a_32.hash("foobar") == 0xbf9cf968);
49 try testing.expect(Fnv1a_32.hash("") == 0x811c9dc5);
50 try testing.expect(Fnv1a_32.hash("a") == 0xe40c292c);
51 try testing.expect(Fnv1a_32.hash("foobar") == 0xbf9cf968);
5252}
5353
5454test "fnv1a-64" {
55 testing.expect(Fnv1a_64.hash("") == 0xcbf29ce484222325);
56 testing.expect(Fnv1a_64.hash("a") == 0xaf63dc4c8601ec8c);
57 testing.expect(Fnv1a_64.hash("foobar") == 0x85944171f73967e8);
55 try testing.expect(Fnv1a_64.hash("") == 0xcbf29ce484222325);
56 try testing.expect(Fnv1a_64.hash("a") == 0xaf63dc4c8601ec8c);
57 try testing.expect(Fnv1a_64.hash("foobar") == 0x85944171f73967e8);
5858}
5959
6060test "fnv1a-128" {
61 testing.expect(Fnv1a_128.hash("") == 0x6c62272e07bb014262b821756295c58d);
62 testing.expect(Fnv1a_128.hash("a") == 0xd228cb696f1a8caf78912b704e4a8964);
61 try testing.expect(Fnv1a_128.hash("") == 0x6c62272e07bb014262b821756295c58d);
62 try testing.expect(Fnv1a_128.hash("a") == 0xd228cb696f1a8caf78912b704e4a8964);
6363}
lib/std/hash/murmur.zig+9-9
......@@ -308,7 +308,7 @@ fn SMHasherTest(comptime hash_fn: anytype, comptime hashbits: u32) u32 {
308308}
309309
310310test "murmur2_32" {
311 testing.expectEqual(SMHasherTest(Murmur2_32.hashWithSeed, 32), 0x27864C1E);
311 try testing.expectEqual(SMHasherTest(Murmur2_32.hashWithSeed, 32), 0x27864C1E);
312312 var v0: u32 = 0x12345678;
313313 var v1: u64 = 0x1234567812345678;
314314 var v0le: u32 = v0;
......@@ -317,12 +317,12 @@ test "murmur2_32" {
317317 v0le = @byteSwap(u32, v0le);
318318 v1le = @byteSwap(u64, v1le);
319319 }
320 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));
320 try testing.expectEqual(Murmur2_32.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur2_32.hashUint32(v0));
321 try testing.expectEqual(Murmur2_32.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur2_32.hashUint64(v1));
322322}
323323
324324test "murmur2_64" {
325 std.testing.expectEqual(SMHasherTest(Murmur2_64.hashWithSeed, 64), 0x1F0D3804);
325 try std.testing.expectEqual(SMHasherTest(Murmur2_64.hashWithSeed, 64), 0x1F0D3804);
326326 var v0: u32 = 0x12345678;
327327 var v1: u64 = 0x1234567812345678;
328328 var v0le: u32 = v0;
......@@ -331,12 +331,12 @@ test "murmur2_64" {
331331 v0le = @byteSwap(u32, v0le);
332332 v1le = @byteSwap(u64, v1le);
333333 }
334 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));
334 try testing.expectEqual(Murmur2_64.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur2_64.hashUint32(v0));
335 try testing.expectEqual(Murmur2_64.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur2_64.hashUint64(v1));
336336}
337337
338338test "murmur3_32" {
339 std.testing.expectEqual(SMHasherTest(Murmur3_32.hashWithSeed, 32), 0xB0F57EE3);
339 try std.testing.expectEqual(SMHasherTest(Murmur3_32.hashWithSeed, 32), 0xB0F57EE3);
340340 var v0: u32 = 0x12345678;
341341 var v1: u64 = 0x1234567812345678;
342342 var v0le: u32 = v0;
......@@ -345,6 +345,6 @@ test "murmur3_32" {
345345 v0le = @byteSwap(u32, v0le);
346346 v1le = @byteSwap(u64, v1le);
347347 }
348 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));
348 try testing.expectEqual(Murmur3_32.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur3_32.hashUint32(v0));
349 try testing.expectEqual(Murmur3_32.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur3_32.hashUint64(v1));
350350}
lib/std/hash/wyhash.zig+11-11
......@@ -183,13 +183,13 @@ const expectEqual = std.testing.expectEqual;
183183test "test vectors" {
184184 const hash = Wyhash.hash;
185185
186 expectEqual(hash(0, ""), 0x0);
187 expectEqual(hash(1, "a"), 0xbed235177f41d328);
188 expectEqual(hash(2, "abc"), 0xbe348debe59b27c3);
189 expectEqual(hash(3, "message digest"), 0x37320f657213a290);
190 expectEqual(hash(4, "abcdefghijklmnopqrstuvwxyz"), 0xd0b270e1d8a7019c);
191 expectEqual(hash(5, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"), 0x602a1894d3bbfe7f);
192 expectEqual(hash(6, "12345678901234567890123456789012345678901234567890123456789012345678901234567890"), 0x829e9c148b75970e);
186 try expectEqual(hash(0, ""), 0x0);
187 try expectEqual(hash(1, "a"), 0xbed235177f41d328);
188 try expectEqual(hash(2, "abc"), 0xbe348debe59b27c3);
189 try expectEqual(hash(3, "message digest"), 0x37320f657213a290);
190 try expectEqual(hash(4, "abcdefghijklmnopqrstuvwxyz"), 0xd0b270e1d8a7019c);
191 try expectEqual(hash(5, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"), 0x602a1894d3bbfe7f);
192 try expectEqual(hash(6, "12345678901234567890123456789012345678901234567890123456789012345678901234567890"), 0x829e9c148b75970e);
193193}
194194
195195test "test vectors streaming" {
......@@ -197,19 +197,19 @@ test "test vectors streaming" {
197197 for ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") |e| {
198198 wh.update(mem.asBytes(&e));
199199 }
200 expectEqual(wh.final(), 0x602a1894d3bbfe7f);
200 try expectEqual(wh.final(), 0x602a1894d3bbfe7f);
201201
202202 const pattern = "1234567890";
203203 const count = 8;
204204 const result = 0x829e9c148b75970e;
205 expectEqual(Wyhash.hash(6, pattern ** 8), result);
205 try expectEqual(Wyhash.hash(6, pattern ** 8), result);
206206
207207 wh = Wyhash.init(6);
208208 var i: u32 = 0;
209209 while (i < count) : (i += 1) {
210210 wh.update(pattern);
211211 }
212 expectEqual(wh.final(), result);
212 try expectEqual(wh.final(), result);
213213}
214214
215215test "iterative non-divisible update" {
......@@ -231,6 +231,6 @@ test "iterative non-divisible update" {
231231 }
232232 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);
235235 }
236236}
lib/std/hash_map.zig+72-72
......@@ -824,15 +824,15 @@ test "std.hash_map basic usage" {
824824 while (it.next()) |kv| {
825825 sum += kv.key;
826826 }
827 expect(sum == total);
827 try expect(sum == total);
828828
829829 i = 0;
830830 sum = 0;
831831 while (i < count) : (i += 1) {
832 expectEqual(map.get(i).?, i);
832 try expectEqual(map.get(i).?, i);
833833 sum += map.get(i).?;
834834 }
835 expectEqual(total, sum);
835 try expectEqual(total, sum);
836836}
837837
838838test "std.hash_map ensureCapacity" {
......@@ -841,13 +841,13 @@ test "std.hash_map ensureCapacity" {
841841
842842 try map.ensureCapacity(20);
843843 const initial_capacity = map.capacity();
844 testing.expect(initial_capacity >= 20);
844 try testing.expect(initial_capacity >= 20);
845845 var i: i32 = 0;
846846 while (i < 20) : (i += 1) {
847 testing.expect(map.fetchPutAssumeCapacity(i, i + 10) == null);
847 try testing.expect(map.fetchPutAssumeCapacity(i, i + 10) == null);
848848 }
849849 // shouldn't resize from putAssumeCapacity
850 testing.expect(initial_capacity == map.capacity());
850 try testing.expect(initial_capacity == map.capacity());
851851}
852852
853853test "std.hash_map ensureCapacity with tombstones" {
......@@ -870,22 +870,22 @@ test "std.hash_map clearRetainingCapacity" {
870870 map.clearRetainingCapacity();
871871
872872 try map.put(1, 1);
873 expectEqual(map.get(1).?, 1);
874 expectEqual(map.count(), 1);
873 try expectEqual(map.get(1).?, 1);
874 try expectEqual(map.count(), 1);
875875
876876 map.clearRetainingCapacity();
877877 map.putAssumeCapacity(1, 1);
878 expectEqual(map.get(1).?, 1);
879 expectEqual(map.count(), 1);
878 try expectEqual(map.get(1).?, 1);
879 try expectEqual(map.count(), 1);
880880
881881 const cap = map.capacity();
882 expect(cap > 0);
882 try expect(cap > 0);
883883
884884 map.clearRetainingCapacity();
885885 map.clearRetainingCapacity();
886 expectEqual(map.count(), 0);
887 expectEqual(map.capacity(), cap);
888 expect(!map.contains(1));
886 try expectEqual(map.count(), 0);
887 try expectEqual(map.capacity(), cap);
888 try expect(!map.contains(1));
889889}
890890
891891test "std.hash_map grow" {
......@@ -898,19 +898,19 @@ test "std.hash_map grow" {
898898 while (i < growTo) : (i += 1) {
899899 try map.put(i, i);
900900 }
901 expectEqual(map.count(), growTo);
901 try expectEqual(map.count(), growTo);
902902
903903 i = 0;
904904 var it = map.iterator();
905905 while (it.next()) |kv| {
906 expectEqual(kv.key, kv.value);
906 try expectEqual(kv.key, kv.value);
907907 i += 1;
908908 }
909 expectEqual(i, growTo);
909 try expectEqual(i, growTo);
910910
911911 i = 0;
912912 while (i < growTo) : (i += 1) {
913 expectEqual(map.get(i).?, i);
913 try expectEqual(map.get(i).?, i);
914914 }
915915}
916916
......@@ -921,7 +921,7 @@ test "std.hash_map clone" {
921921 var a = try map.clone();
922922 defer a.deinit();
923923
924 expectEqual(a.count(), 0);
924 try expectEqual(a.count(), 0);
925925
926926 try a.put(1, 1);
927927 try a.put(2, 2);
......@@ -930,10 +930,10 @@ test "std.hash_map clone" {
930930 var b = try a.clone();
931931 defer b.deinit();
932932
933 expectEqual(b.count(), 3);
934 expectEqual(b.get(1), 1);
935 expectEqual(b.get(2), 2);
936 expectEqual(b.get(3), 3);
933 try expectEqual(b.count(), 3);
934 try expectEqual(b.get(1), 1);
935 try expectEqual(b.get(2), 2);
936 try expectEqual(b.get(3), 3);
937937}
938938
939939test "std.hash_map ensureCapacity with existing elements" {
......@@ -941,12 +941,12 @@ test "std.hash_map ensureCapacity with existing elements" {
941941 defer map.deinit();
942942
943943 try map.put(0, 0);
944 expectEqual(map.count(), 1);
945 expectEqual(map.capacity(), @TypeOf(map).Unmanaged.minimal_capacity);
944 try expectEqual(map.count(), 1);
945 try expectEqual(map.capacity(), @TypeOf(map).Unmanaged.minimal_capacity);
946946
947947 try map.ensureCapacity(65);
948 expectEqual(map.count(), 1);
949 expectEqual(map.capacity(), 128);
948 try expectEqual(map.count(), 1);
949 try expectEqual(map.capacity(), 128);
950950}
951951
952952test "std.hash_map ensureCapacity satisfies max load factor" {
......@@ -954,7 +954,7 @@ test "std.hash_map ensureCapacity satisfies max load factor" {
954954 defer map.deinit();
955955
956956 try map.ensureCapacity(127);
957 expectEqual(map.capacity(), 256);
957 try expectEqual(map.capacity(), 256);
958958}
959959
960960test "std.hash_map remove" {
......@@ -972,19 +972,19 @@ test "std.hash_map remove" {
972972 _ = map.remove(i);
973973 }
974974 }
975 expectEqual(map.count(), 10);
975 try expectEqual(map.count(), 10);
976976 var it = map.iterator();
977977 while (it.next()) |kv| {
978 expectEqual(kv.key, kv.value);
979 expect(kv.key % 3 != 0);
978 try expectEqual(kv.key, kv.value);
979 try expect(kv.key % 3 != 0);
980980 }
981981
982982 i = 0;
983983 while (i < 16) : (i += 1) {
984984 if (i % 3 == 0) {
985 expect(!map.contains(i));
985 try expect(!map.contains(i));
986986 } else {
987 expectEqual(map.get(i).?, i);
987 try expectEqual(map.get(i).?, i);
988988 }
989989 }
990990}
......@@ -1001,14 +1001,14 @@ test "std.hash_map reverse removes" {
10011001 i = 16;
10021002 while (i > 0) : (i -= 1) {
10031003 _ = map.remove(i - 1);
1004 expect(!map.contains(i - 1));
1004 try expect(!map.contains(i - 1));
10051005 var j: u32 = 0;
10061006 while (j < i - 1) : (j += 1) {
1007 expectEqual(map.get(j).?, j);
1007 try expectEqual(map.get(j).?, j);
10081008 }
10091009 }
10101010
1011 expectEqual(map.count(), 0);
1011 try expectEqual(map.count(), 0);
10121012}
10131013
10141014test "std.hash_map multiple removes on same metadata" {
......@@ -1024,17 +1024,17 @@ test "std.hash_map multiple removes on same metadata" {
10241024 _ = map.remove(15);
10251025 _ = map.remove(14);
10261026 _ = map.remove(13);
1027 expect(!map.contains(7));
1028 expect(!map.contains(15));
1029 expect(!map.contains(14));
1030 expect(!map.contains(13));
1027 try expect(!map.contains(7));
1028 try expect(!map.contains(15));
1029 try expect(!map.contains(14));
1030 try expect(!map.contains(13));
10311031
10321032 i = 0;
10331033 while (i < 13) : (i += 1) {
10341034 if (i == 7) {
1035 expect(!map.contains(i));
1035 try expect(!map.contains(i));
10361036 } else {
1037 expectEqual(map.get(i).?, i);
1037 try expectEqual(map.get(i).?, i);
10381038 }
10391039 }
10401040
......@@ -1044,7 +1044,7 @@ test "std.hash_map multiple removes on same metadata" {
10441044 try map.put(7, 7);
10451045 i = 0;
10461046 while (i < 16) : (i += 1) {
1047 expectEqual(map.get(i).?, i);
1047 try expectEqual(map.get(i).?, i);
10481048 }
10491049}
10501050
......@@ -1070,12 +1070,12 @@ test "std.hash_map put and remove loop in random order" {
10701070 for (keys.items) |key| {
10711071 try map.put(key, key);
10721072 }
1073 expectEqual(map.count(), size);
1073 try expectEqual(map.count(), size);
10741074
10751075 for (keys.items) |key| {
10761076 _ = map.remove(key);
10771077 }
1078 expectEqual(map.count(), 0);
1078 try expectEqual(map.count(), 0);
10791079 }
10801080}
10811081
......@@ -1119,7 +1119,7 @@ test "std.hash_map put" {
11191119
11201120 i = 0;
11211121 while (i < 16) : (i += 1) {
1122 expectEqual(map.get(i).?, i);
1122 try expectEqual(map.get(i).?, i);
11231123 }
11241124
11251125 i = 0;
......@@ -1129,7 +1129,7 @@ test "std.hash_map put" {
11291129
11301130 i = 0;
11311131 while (i < 16) : (i += 1) {
1132 expectEqual(map.get(i).?, i * 16 + 1);
1132 try expectEqual(map.get(i).?, i * 16 + 1);
11331133 }
11341134}
11351135
......@@ -1148,7 +1148,7 @@ test "std.hash_map putAssumeCapacity" {
11481148 while (i < 20) : (i += 1) {
11491149 sum += map.get(i).?;
11501150 }
1151 expectEqual(sum, 190);
1151 try expectEqual(sum, 190);
11521152
11531153 i = 0;
11541154 while (i < 20) : (i += 1) {
......@@ -1160,7 +1160,7 @@ test "std.hash_map putAssumeCapacity" {
11601160 while (i < 20) : (i += 1) {
11611161 sum += map.get(i).?;
11621162 }
1163 expectEqual(sum, 20);
1163 try expectEqual(sum, 20);
11641164}
11651165
11661166test "std.hash_map getOrPut" {
......@@ -1183,49 +1183,49 @@ test "std.hash_map getOrPut" {
11831183 sum += map.get(i).?;
11841184 }
11851185
1186 expectEqual(sum, 30);
1186 try expectEqual(sum, 30);
11871187}
11881188
11891189test "std.hash_map basic hash map usage" {
11901190 var map = AutoHashMap(i32, i32).init(std.testing.allocator);
11911191 defer map.deinit();
11921192
1193 testing.expect((try map.fetchPut(1, 11)) == null);
1194 testing.expect((try map.fetchPut(2, 22)) == null);
1195 testing.expect((try map.fetchPut(3, 33)) == null);
1196 testing.expect((try map.fetchPut(4, 44)) == null);
1193 try testing.expect((try map.fetchPut(1, 11)) == null);
1194 try testing.expect((try map.fetchPut(2, 22)) == null);
1195 try testing.expect((try map.fetchPut(3, 33)) == null);
1196 try testing.expect((try map.fetchPut(4, 44)) == null);
11971197
11981198 try map.putNoClobber(5, 55);
1199 testing.expect((try map.fetchPut(5, 66)).?.value == 55);
1200 testing.expect((try map.fetchPut(5, 55)).?.value == 66);
1199 try testing.expect((try map.fetchPut(5, 66)).?.value == 55);
1200 try testing.expect((try map.fetchPut(5, 55)).?.value == 66);
12011201
12021202 const gop1 = try map.getOrPut(5);
1203 testing.expect(gop1.found_existing == true);
1204 testing.expect(gop1.entry.value == 55);
1203 try testing.expect(gop1.found_existing == true);
1204 try testing.expect(gop1.entry.value == 55);
12051205 gop1.entry.value = 77;
1206 testing.expect(map.getEntry(5).?.value == 77);
1206 try testing.expect(map.getEntry(5).?.value == 77);
12071207
12081208 const gop2 = try map.getOrPut(99);
1209 testing.expect(gop2.found_existing == false);
1209 try testing.expect(gop2.found_existing == false);
12101210 gop2.entry.value = 42;
1211 testing.expect(map.getEntry(99).?.value == 42);
1211 try testing.expect(map.getEntry(99).?.value == 42);
12121212
12131213 const gop3 = try map.getOrPutValue(5, 5);
1214 testing.expect(gop3.value == 77);
1214 try testing.expect(gop3.value == 77);
12151215
12161216 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));
1220 testing.expect(map.getEntry(2).?.value == 22);
1221 testing.expect(map.get(2).? == 22);
1219 try testing.expect(map.contains(2));
1220 try testing.expect(map.getEntry(2).?.value == 22);
1221 try testing.expect(map.get(2).? == 22);
12221222
12231223 const rmv1 = map.remove(2);
1224 testing.expect(rmv1.?.key == 2);
1225 testing.expect(rmv1.?.value == 22);
1226 testing.expect(map.remove(2) == null);
1227 testing.expect(map.getEntry(2) == null);
1228 testing.expect(map.get(2) == null);
1224 try testing.expect(rmv1.?.key == 2);
1225 try testing.expect(rmv1.?.value == 22);
1226 try testing.expect(map.remove(2) == null);
1227 try testing.expect(map.getEntry(2) == null);
1228 try testing.expect(map.get(2) == null);
12291229
12301230 map.removeAssertDiscard(3);
12311231}
......@@ -1244,6 +1244,6 @@ test "std.hash_map clone" {
12441244
12451245 i = 0;
12461246 while (i < 10) : (i += 1) {
1247 testing.expect(copy.get(i).? == i * 10);
1247 try testing.expect(copy.get(i).? == i * 10);
12481248 }
12491249}
lib/std/heap.zig+43-43
......@@ -858,16 +858,16 @@ test "WasmPageAllocator internals" {
858858 if (comptime std.Target.current.isWasm()) {
859859 const conventional_memsize = WasmPageAllocator.conventional.totalPages() * mem.page_size;
860860 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
863863 var inplace = try page_allocator.realloc(initial, 1);
864 testing.expectEqual(initial.ptr, inplace.ptr);
864 try testing.expectEqual(initial.ptr, inplace.ptr);
865865 inplace = try page_allocator.realloc(inplace, 4);
866 testing.expectEqual(initial.ptr, inplace.ptr);
866 try testing.expectEqual(initial.ptr, inplace.ptr);
867867 page_allocator.free(inplace);
868868
869869 const reuse = try page_allocator.alloc(u8, 1);
870 testing.expectEqual(initial.ptr, reuse.ptr);
870 try testing.expectEqual(initial.ptr, reuse.ptr);
871871 page_allocator.free(reuse);
872872
873873 // 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" {
875875 page_allocator.free(padding);
876876
877877 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
880880 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);
882882 page_allocator.free(use_small);
883883
884884 inplace = try page_allocator.realloc(extended, 1);
885 testing.expectEqual(extended.ptr, inplace.ptr);
885 try testing.expectEqual(extended.ptr, inplace.ptr);
886886 page_allocator.free(inplace);
887887
888888 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);
890890 page_allocator.free(reuse_extended);
891891 }
892892}
......@@ -959,15 +959,15 @@ test "FixedBufferAllocator.reset" {
959959
960960 var x = try fba.allocator.create(u64);
961961 x.* = X;
962 testing.expectError(error.OutOfMemory, fba.allocator.create(u64));
962 try testing.expectError(error.OutOfMemory, fba.allocator.create(u64));
963963
964964 fba.reset();
965965 var y = try fba.allocator.create(u64);
966966 y.* = Y;
967967
968968 // we expect Y to have overwritten X.
969 testing.expect(x.* == y.*);
970 testing.expect(y.* == Y);
969 try testing.expect(x.* == y.*);
970 try testing.expect(y.* == Y);
971971}
972972
973973test "StackFallbackAllocator" {
......@@ -987,11 +987,11 @@ test "FixedBufferAllocator Reuse memory on realloc" {
987987 var fixed_buffer_allocator = FixedBufferAllocator.init(small_fixed_buffer[0..]);
988988
989989 var slice0 = try fixed_buffer_allocator.allocator.alloc(u8, 5);
990 testing.expect(slice0.len == 5);
990 try testing.expect(slice0.len == 5);
991991 var slice1 = try fixed_buffer_allocator.allocator.realloc(slice0, 10);
992 testing.expect(slice1.ptr == slice0.ptr);
993 testing.expect(slice1.len == 10);
994 testing.expectError(error.OutOfMemory, fixed_buffer_allocator.allocator.realloc(slice1, 11));
992 try testing.expect(slice1.ptr == slice0.ptr);
993 try testing.expect(slice1.len == 10);
994 try testing.expectError(error.OutOfMemory, fixed_buffer_allocator.allocator.realloc(slice1, 11));
995995 }
996996 // check that we don't re-use the memory if it's not the most recent block
997997 {
......@@ -1002,10 +1002,10 @@ test "FixedBufferAllocator Reuse memory on realloc" {
10021002 slice0[1] = 2;
10031003 var slice1 = try fixed_buffer_allocator.allocator.alloc(u8, 2);
10041004 var slice2 = try fixed_buffer_allocator.allocator.realloc(slice0, 4);
1005 testing.expect(slice0.ptr != slice2.ptr);
1006 testing.expect(slice1.ptr != slice2.ptr);
1007 testing.expect(slice2[0] == 1);
1008 testing.expect(slice2[1] == 2);
1005 try testing.expect(slice0.ptr != slice2.ptr);
1006 try testing.expect(slice1.ptr != slice2.ptr);
1007 try testing.expect(slice2[0] == 1);
1008 try testing.expect(slice2[1] == 2);
10091009 }
10101010}
10111011
......@@ -1024,28 +1024,28 @@ pub fn testAllocator(base_allocator: *mem.Allocator) !void {
10241024 const allocator = &validationAllocator.allocator;
10251025
10261026 var slice = try allocator.alloc(*i32, 100);
1027 testing.expect(slice.len == 100);
1027 try testing.expect(slice.len == 100);
10281028 for (slice) |*item, i| {
10291029 item.* = try allocator.create(i32);
10301030 item.*.* = @intCast(i32, i);
10311031 }
10321032
10331033 slice = try allocator.realloc(slice, 20000);
1034 testing.expect(slice.len == 20000);
1034 try testing.expect(slice.len == 20000);
10351035
10361036 for (slice[0..100]) |item, i| {
1037 testing.expect(item.* == @intCast(i32, i));
1037 try testing.expect(item.* == @intCast(i32, i));
10381038 allocator.destroy(item);
10391039 }
10401040
10411041 slice = allocator.shrink(slice, 50);
1042 testing.expect(slice.len == 50);
1042 try testing.expect(slice.len == 50);
10431043 slice = allocator.shrink(slice, 25);
1044 testing.expect(slice.len == 25);
1044 try testing.expect(slice.len == 25);
10451045 slice = allocator.shrink(slice, 0);
1046 testing.expect(slice.len == 0);
1046 try testing.expect(slice.len == 0);
10471047 slice = try allocator.realloc(slice, 10);
1048 testing.expect(slice.len == 10);
1048 try testing.expect(slice.len == 10);
10491049
10501050 allocator.free(slice);
10511051
......@@ -1058,7 +1058,7 @@ pub fn testAllocator(base_allocator: *mem.Allocator) !void {
10581058 allocator.destroy(zero_bit_ptr);
10591059
10601060 const oversize = try allocator.allocAdvanced(u32, null, 5, .at_least);
1061 testing.expect(oversize.len >= 5);
1061 try testing.expect(oversize.len >= 5);
10621062 for (oversize) |*item| {
10631063 item.* = 0xDEADBEEF;
10641064 }
......@@ -1073,29 +1073,29 @@ pub fn testAllocatorAligned(base_allocator: *mem.Allocator) !void {
10731073 inline for ([_]u29{ 1, 2, 4, 8, 16, 32, 64 }) |alignment| {
10741074 // initial
10751075 var slice = try allocator.alignedAlloc(u8, alignment, 10);
1076 testing.expect(slice.len == 10);
1076 try testing.expect(slice.len == 10);
10771077 // grow
10781078 slice = try allocator.realloc(slice, 100);
1079 testing.expect(slice.len == 100);
1079 try testing.expect(slice.len == 100);
10801080 // shrink
10811081 slice = allocator.shrink(slice, 10);
1082 testing.expect(slice.len == 10);
1082 try testing.expect(slice.len == 10);
10831083 // go to zero
10841084 slice = allocator.shrink(slice, 0);
1085 testing.expect(slice.len == 0);
1085 try testing.expect(slice.len == 0);
10861086 // realloc from zero
10871087 slice = try allocator.realloc(slice, 100);
1088 testing.expect(slice.len == 100);
1088 try testing.expect(slice.len == 100);
10891089 // shrink with shrink
10901090 slice = allocator.shrink(slice, 10);
1091 testing.expect(slice.len == 10);
1091 try testing.expect(slice.len == 10);
10921092 // shrink to zero
10931093 slice = allocator.shrink(slice, 0);
1094 testing.expect(slice.len == 0);
1094 try testing.expect(slice.len == 0);
10951095 }
10961096}
10971097
1098pub fn testAllocatorLargeAlignment(base_allocator: *mem.Allocator) mem.Allocator.Error!void {
1098pub fn testAllocatorLargeAlignment(base_allocator: *mem.Allocator) !void {
10991099 var validationAllocator = mem.validationWrap(base_allocator);
11001100 const allocator = &validationAllocator.allocator;
11011101
......@@ -1110,24 +1110,24 @@ pub fn testAllocatorLargeAlignment(base_allocator: *mem.Allocator) mem.Allocator
11101110 _ = @shlWithOverflow(usize, ~@as(usize, 0), @as(USizeShift, @ctz(u29, large_align)), &align_mask);
11111111
11121112 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
11151115 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
11181118 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
11211121 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
11241124 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
11271127 allocator.free(slice);
11281128}
11291129
1130pub fn testAllocatorAlignedShrink(base_allocator: *mem.Allocator) mem.Allocator.Error!void {
1130pub fn testAllocatorAlignedShrink(base_allocator: *mem.Allocator) !void {
11311131 var validationAllocator = mem.validationWrap(base_allocator);
11321132 const allocator = &validationAllocator.allocator;
11331133
......@@ -1155,8 +1155,8 @@ pub fn testAllocatorAlignedShrink(base_allocator: *mem.Allocator) mem.Allocator.
11551155
11561156 // realloc to a smaller size but with a larger alignment
11571157 slice = try allocator.reallocAdvanced(slice, mem.page_size * 32, alloc_size / 2, .exact);
1158 testing.expect(slice[0] == 0x12);
1159 testing.expect(slice[60] == 0x34);
1158 try testing.expect(slice[0] == 0x12);
1159 try testing.expect(slice[60] == 0x34);
11601160}
11611161
11621162test "heap" {
lib/std/heap/general_purpose_allocator.zig+50-50
......@@ -692,7 +692,7 @@ const test_config = Config{};
692692
693693test "small allocations - free in same order" {
694694 var gpa = GeneralPurposeAllocator(test_config){};
695 defer std.testing.expect(!gpa.deinit());
695 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
696696 const allocator = &gpa.allocator;
697697
698698 var list = std.ArrayList(*u64).init(std.testing.allocator);
......@@ -711,7 +711,7 @@ test "small allocations - free in same order" {
711711
712712test "small allocations - free in reverse order" {
713713 var gpa = GeneralPurposeAllocator(test_config){};
714 defer std.testing.expect(!gpa.deinit());
714 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
715715 const allocator = &gpa.allocator;
716716
717717 var list = std.ArrayList(*u64).init(std.testing.allocator);
......@@ -730,7 +730,7 @@ test "small allocations - free in reverse order" {
730730
731731test "large allocations" {
732732 var gpa = GeneralPurposeAllocator(test_config){};
733 defer std.testing.expect(!gpa.deinit());
733 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
734734 const allocator = &gpa.allocator;
735735
736736 const ptr1 = try allocator.alloc(u64, 42768);
......@@ -743,7 +743,7 @@ test "large allocations" {
743743
744744test "realloc" {
745745 var gpa = GeneralPurposeAllocator(test_config){};
746 defer std.testing.expect(!gpa.deinit());
746 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
747747 const allocator = &gpa.allocator;
748748
749749 var slice = try allocator.alignedAlloc(u8, @alignOf(u32), 1);
......@@ -753,19 +753,19 @@ test "realloc" {
753753 // This reallocation should keep its pointer address.
754754 const old_slice = slice;
755755 slice = try allocator.realloc(slice, 2);
756 std.testing.expect(old_slice.ptr == slice.ptr);
757 std.testing.expect(slice[0] == 0x12);
756 try std.testing.expect(old_slice.ptr == slice.ptr);
757 try std.testing.expect(slice[0] == 0x12);
758758 slice[1] = 0x34;
759759
760760 // This requires upgrading to a larger size class
761761 slice = try allocator.realloc(slice, 17);
762 std.testing.expect(slice[0] == 0x12);
763 std.testing.expect(slice[1] == 0x34);
762 try std.testing.expect(slice[0] == 0x12);
763 try std.testing.expect(slice[1] == 0x34);
764764}
765765
766766test "shrink" {
767767 var gpa = GeneralPurposeAllocator(test_config){};
768 defer std.testing.expect(!gpa.deinit());
768 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
769769 const allocator = &gpa.allocator;
770770
771771 var slice = try allocator.alloc(u8, 20);
......@@ -776,19 +776,19 @@ test "shrink" {
776776 slice = allocator.shrink(slice, 17);
777777
778778 for (slice) |b| {
779 std.testing.expect(b == 0x11);
779 try std.testing.expect(b == 0x11);
780780 }
781781
782782 slice = allocator.shrink(slice, 16);
783783
784784 for (slice) |b| {
785 std.testing.expect(b == 0x11);
785 try std.testing.expect(b == 0x11);
786786 }
787787}
788788
789789test "large object - grow" {
790790 var gpa = GeneralPurposeAllocator(test_config){};
791 defer std.testing.expect(!gpa.deinit());
791 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
792792 const allocator = &gpa.allocator;
793793
794794 var slice1 = try allocator.alloc(u8, page_size * 2 - 20);
......@@ -796,17 +796,17 @@ test "large object - grow" {
796796
797797 const old = slice1;
798798 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
801801 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
804804 slice1 = try allocator.realloc(slice1, page_size * 2 + 1);
805805}
806806
807807test "realloc small object to large object" {
808808 var gpa = GeneralPurposeAllocator(test_config){};
809 defer std.testing.expect(!gpa.deinit());
809 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
810810 const allocator = &gpa.allocator;
811811
812812 var slice = try allocator.alloc(u8, 70);
......@@ -817,13 +817,13 @@ test "realloc small object to large object" {
817817 // This requires upgrading to a large object
818818 const large_object_size = page_size * 2 + 50;
819819 slice = try allocator.realloc(slice, large_object_size);
820 std.testing.expect(slice[0] == 0x12);
821 std.testing.expect(slice[60] == 0x34);
820 try std.testing.expect(slice[0] == 0x12);
821 try std.testing.expect(slice[60] == 0x34);
822822}
823823
824824test "shrink large object to large object" {
825825 var gpa = GeneralPurposeAllocator(test_config){};
826 defer std.testing.expect(!gpa.deinit());
826 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
827827 const allocator = &gpa.allocator;
828828
829829 var slice = try allocator.alloc(u8, page_size * 2 + 50);
......@@ -832,21 +832,21 @@ test "shrink large object to large object" {
832832 slice[60] = 0x34;
833833
834834 slice = try allocator.resize(slice, page_size * 2 + 1);
835 std.testing.expect(slice[0] == 0x12);
836 std.testing.expect(slice[60] == 0x34);
835 try std.testing.expect(slice[0] == 0x12);
836 try std.testing.expect(slice[60] == 0x34);
837837
838838 slice = allocator.shrink(slice, page_size * 2 + 1);
839 std.testing.expect(slice[0] == 0x12);
840 std.testing.expect(slice[60] == 0x34);
839 try std.testing.expect(slice[0] == 0x12);
840 try std.testing.expect(slice[60] == 0x34);
841841
842842 slice = try allocator.realloc(slice, page_size * 2);
843 std.testing.expect(slice[0] == 0x12);
844 std.testing.expect(slice[60] == 0x34);
843 try std.testing.expect(slice[0] == 0x12);
844 try std.testing.expect(slice[60] == 0x34);
845845}
846846
847847test "shrink large object to large object with larger alignment" {
848848 var gpa = GeneralPurposeAllocator(test_config){};
849 defer std.testing.expect(!gpa.deinit());
849 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
850850 const allocator = &gpa.allocator;
851851
852852 var debug_buffer: [1000]u8 = undefined;
......@@ -875,13 +875,13 @@ test "shrink large object to large object with larger alignment" {
875875 slice[60] = 0x34;
876876
877877 slice = try allocator.reallocAdvanced(slice, big_alignment, alloc_size / 2, .exact);
878 std.testing.expect(slice[0] == 0x12);
879 std.testing.expect(slice[60] == 0x34);
878 try std.testing.expect(slice[0] == 0x12);
879 try std.testing.expect(slice[60] == 0x34);
880880}
881881
882882test "realloc large object to small object" {
883883 var gpa = GeneralPurposeAllocator(test_config){};
884 defer std.testing.expect(!gpa.deinit());
884 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
885885 const allocator = &gpa.allocator;
886886
887887 var slice = try allocator.alloc(u8, page_size * 2 + 50);
......@@ -890,8 +890,8 @@ test "realloc large object to small object" {
890890 slice[16] = 0x34;
891891
892892 slice = try allocator.realloc(slice, 19);
893 std.testing.expect(slice[0] == 0x12);
894 std.testing.expect(slice[16] == 0x34);
893 try std.testing.expect(slice[0] == 0x12);
894 try std.testing.expect(slice[16] == 0x34);
895895}
896896
897897test "overrideable mutexes" {
......@@ -899,7 +899,7 @@ test "overrideable mutexes" {
899899 .backing_allocator = std.testing.allocator,
900900 .mutex = std.Thread.Mutex{},
901901 };
902 defer std.testing.expect(!gpa.deinit());
902 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
903903 const allocator = &gpa.allocator;
904904
905905 const ptr = try allocator.create(i32);
......@@ -908,7 +908,7 @@ test "overrideable mutexes" {
908908
909909test "non-page-allocator backing allocator" {
910910 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");
912912 const allocator = &gpa.allocator;
913913
914914 const ptr = try allocator.create(i32);
......@@ -917,7 +917,7 @@ test "non-page-allocator backing allocator" {
917917
918918test "realloc large object to larger alignment" {
919919 var gpa = GeneralPurposeAllocator(test_config){};
920 defer std.testing.expect(!gpa.deinit());
920 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
921921 const allocator = &gpa.allocator;
922922
923923 var debug_buffer: [1000]u8 = undefined;
......@@ -943,22 +943,22 @@ test "realloc large object to larger alignment" {
943943 slice[16] = 0x34;
944944
945945 slice = try allocator.reallocAdvanced(slice, 32, page_size * 2 + 100, .exact);
946 std.testing.expect(slice[0] == 0x12);
947 std.testing.expect(slice[16] == 0x34);
946 try std.testing.expect(slice[0] == 0x12);
947 try std.testing.expect(slice[16] == 0x34);
948948
949949 slice = try allocator.reallocAdvanced(slice, 32, page_size * 2 + 25, .exact);
950 std.testing.expect(slice[0] == 0x12);
951 std.testing.expect(slice[16] == 0x34);
950 try std.testing.expect(slice[0] == 0x12);
951 try std.testing.expect(slice[16] == 0x34);
952952
953953 slice = try allocator.reallocAdvanced(slice, big_alignment, page_size * 2 + 100, .exact);
954 std.testing.expect(slice[0] == 0x12);
955 std.testing.expect(slice[16] == 0x34);
954 try std.testing.expect(slice[0] == 0x12);
955 try std.testing.expect(slice[16] == 0x34);
956956}
957957
958958test "large object shrinks to small but allocation fails during shrink" {
959959 var failing_allocator = std.testing.FailingAllocator.init(std.heap.page_allocator, 3);
960960 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");
962962 const allocator = &gpa.allocator;
963963
964964 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" {
969969 // Next allocation will fail in the backing allocator of the GeneralPurposeAllocator
970970
971971 slice = allocator.shrink(slice, 4);
972 std.testing.expect(slice[0] == 0x12);
973 std.testing.expect(slice[3] == 0x34);
972 try std.testing.expect(slice[0] == 0x12);
973 try std.testing.expect(slice[3] == 0x34);
974974}
975975
976976test "objects of size 1024 and 2048" {
977977 var gpa = GeneralPurposeAllocator(test_config){};
978 defer std.testing.expect(!gpa.deinit());
978 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
979979 const allocator = &gpa.allocator;
980980
981981 const slice = try allocator.alloc(u8, 1025);
......@@ -987,26 +987,26 @@ test "objects of size 1024 and 2048" {
987987
988988test "setting a memory cap" {
989989 var gpa = GeneralPurposeAllocator(.{ .enable_memory_limit = true }){};
990 defer std.testing.expect(!gpa.deinit());
990 defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
991991 const allocator = &gpa.allocator;
992992
993993 gpa.setRequestedMemoryLimit(1010);
994994
995995 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
998998 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
10031003 allocator.destroy(small);
1004 std.testing.expect(gpa.total_requested_bytes == 1000);
1004 try std.testing.expect(gpa.total_requested_bytes == 1000);
10051005
10061006 allocator.free(big);
1007 std.testing.expect(gpa.total_requested_bytes == 0);
1007 try std.testing.expect(gpa.total_requested_bytes == 0);
10081008
10091009 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);
10111011 allocator.free(exact);
10121012}
lib/std/heap/logging_allocator.zig+3-3
......@@ -93,11 +93,11 @@ test "LoggingAllocator" {
9393
9494 var a = try allocator.alloc(u8, 10);
9595 a = allocator.shrink(a, 5);
96 std.testing.expect(a.len == 5);
97 std.testing.expectError(error.OutOfMemory, allocator.resize(a, 20));
96 try std.testing.expect(a.len == 5);
97 try std.testing.expectError(error.OutOfMemory, allocator.resize(a, 20));
9898 allocator.free(a);
9999
100 std.testing.expectEqualSlices(u8,
100 try std.testing.expectEqualSlices(u8,
101101 \\alloc : 10 success!
102102 \\shrink: 10 to 5
103103 \\expand: 5 to 20 failure!
lib/std/io/bit_reader.zig+38-38
......@@ -185,64 +185,64 @@ test "api coverage" {
185185 const expect = testing.expect;
186186 const expectError = testing.expectError;
187187
188 expect(1 == try bit_stream_be.readBits(u2, 1, &out_bits));
189 expect(out_bits == 1);
190 expect(2 == try bit_stream_be.readBits(u5, 2, &out_bits));
191 expect(out_bits == 2);
192 expect(3 == try bit_stream_be.readBits(u128, 3, &out_bits));
193 expect(out_bits == 3);
194 expect(4 == try bit_stream_be.readBits(u8, 4, &out_bits));
195 expect(out_bits == 4);
196 expect(5 == try bit_stream_be.readBits(u9, 5, &out_bits));
197 expect(out_bits == 5);
198 expect(1 == try bit_stream_be.readBits(u1, 1, &out_bits));
199 expect(out_bits == 1);
188 try expect(1 == try bit_stream_be.readBits(u2, 1, &out_bits));
189 try expect(out_bits == 1);
190 try expect(2 == try bit_stream_be.readBits(u5, 2, &out_bits));
191 try expect(out_bits == 2);
192 try expect(3 == try bit_stream_be.readBits(u128, 3, &out_bits));
193 try expect(out_bits == 3);
194 try expect(4 == try bit_stream_be.readBits(u8, 4, &out_bits));
195 try expect(out_bits == 4);
196 try expect(5 == try bit_stream_be.readBits(u9, 5, &out_bits));
197 try expect(out_bits == 5);
198 try expect(1 == try bit_stream_be.readBits(u1, 1, &out_bits));
199 try expect(out_bits == 1);
200200
201201 mem_in_be.pos = 0;
202202 bit_stream_be.bit_count = 0;
203 expect(0b110011010000101 == try bit_stream_be.readBits(u15, 15, &out_bits));
204 expect(out_bits == 15);
203 try expect(0b110011010000101 == try bit_stream_be.readBits(u15, 15, &out_bits));
204 try expect(out_bits == 15);
205205
206206 mem_in_be.pos = 0;
207207 bit_stream_be.bit_count = 0;
208 expect(0b1100110100001011 == try bit_stream_be.readBits(u16, 16, &out_bits));
209 expect(out_bits == 16);
208 try expect(0b1100110100001011 == try bit_stream_be.readBits(u16, 16, &out_bits));
209 try expect(out_bits == 16);
210210
211211 _ = try bit_stream_be.readBits(u0, 0, &out_bits);
212212
213 expect(0 == try bit_stream_be.readBits(u1, 1, &out_bits));
214 expect(out_bits == 0);
215 expectError(error.EndOfStream, bit_stream_be.readBitsNoEof(u1, 1));
213 try expect(0 == try bit_stream_be.readBits(u1, 1, &out_bits));
214 try expect(out_bits == 0);
215 try expectError(error.EndOfStream, bit_stream_be.readBitsNoEof(u1, 1));
216216
217217 var mem_in_le = io.fixedBufferStream(&mem_le);
218218 var bit_stream_le = bitReader(.Little, mem_in_le.reader());
219219
220 expect(1 == try bit_stream_le.readBits(u2, 1, &out_bits));
221 expect(out_bits == 1);
222 expect(2 == try bit_stream_le.readBits(u5, 2, &out_bits));
223 expect(out_bits == 2);
224 expect(3 == try bit_stream_le.readBits(u128, 3, &out_bits));
225 expect(out_bits == 3);
226 expect(4 == try bit_stream_le.readBits(u8, 4, &out_bits));
227 expect(out_bits == 4);
228 expect(5 == try bit_stream_le.readBits(u9, 5, &out_bits));
229 expect(out_bits == 5);
230 expect(1 == try bit_stream_le.readBits(u1, 1, &out_bits));
231 expect(out_bits == 1);
220 try expect(1 == try bit_stream_le.readBits(u2, 1, &out_bits));
221 try expect(out_bits == 1);
222 try expect(2 == try bit_stream_le.readBits(u5, 2, &out_bits));
223 try expect(out_bits == 2);
224 try expect(3 == try bit_stream_le.readBits(u128, 3, &out_bits));
225 try expect(out_bits == 3);
226 try expect(4 == try bit_stream_le.readBits(u8, 4, &out_bits));
227 try expect(out_bits == 4);
228 try expect(5 == try bit_stream_le.readBits(u9, 5, &out_bits));
229 try expect(out_bits == 5);
230 try expect(1 == try bit_stream_le.readBits(u1, 1, &out_bits));
231 try expect(out_bits == 1);
232232
233233 mem_in_le.pos = 0;
234234 bit_stream_le.bit_count = 0;
235 expect(0b001010100011101 == try bit_stream_le.readBits(u15, 15, &out_bits));
236 expect(out_bits == 15);
235 try expect(0b001010100011101 == try bit_stream_le.readBits(u15, 15, &out_bits));
236 try expect(out_bits == 15);
237237
238238 mem_in_le.pos = 0;
239239 bit_stream_le.bit_count = 0;
240 expect(0b1001010100011101 == try bit_stream_le.readBits(u16, 16, &out_bits));
241 expect(out_bits == 16);
240 try expect(0b1001010100011101 == try bit_stream_le.readBits(u16, 16, &out_bits));
241 try expect(out_bits == 16);
242242
243243 _ = try bit_stream_le.readBits(u0, 0, &out_bits);
244244
245 expect(0 == try bit_stream_le.readBits(u1, 1, &out_bits));
246 expect(out_bits == 0);
247 expectError(error.EndOfStream, bit_stream_le.readBitsNoEof(u1, 1));
245 try expect(0 == try bit_stream_le.readBits(u1, 1, &out_bits));
246 try expect(out_bits == 0);
247 try expectError(error.EndOfStream, bit_stream_le.readBitsNoEof(u1, 1));
248248}
lib/std/io/bit_writer.zig+6-6
......@@ -163,17 +163,17 @@ test "api coverage" {
163163 try bit_stream_be.writeBits(@as(u9, 5), 5);
164164 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
168168 mem_out_be.pos = 0;
169169
170170 try bit_stream_be.writeBits(@as(u15, 0b110011010000101), 15);
171171 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
174174 mem_out_be.pos = 0;
175175 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
178178 try bit_stream_be.writeBits(@as(u0, 0), 0);
179179
......@@ -187,16 +187,16 @@ test "api coverage" {
187187 try bit_stream_le.writeBits(@as(u9, 5), 5);
188188 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
192192 mem_out_le.pos = 0;
193193 try bit_stream_le.writeBits(@as(u15, 0b110011010000101), 15);
194194 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
197197 mem_out_le.pos = 0;
198198 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
201201 try bit_stream_le.writeBits(@as(u0, 0), 0);
202202}
lib/std/io/buffered_reader.zig+1-1
......@@ -87,5 +87,5 @@ test "io.BufferedReader" {
8787
8888 const res = try stream.readAllAlloc(testing.allocator, str.len + 1);
8989 defer testing.allocator.free(res);
90 testing.expectEqualSlices(u8, str, res);
90 try testing.expectEqualSlices(u8, str, res);
9191}
lib/std/io/counting_reader.zig+2-2
......@@ -41,8 +41,8 @@ test "io.CountingReader" {
4141
4242 //read and discard all bytes
4343 while (stream.readByte()) |_| {} else |err| {
44 testing.expect(err == error.EndOfStream);
44 try testing.expect(err == error.EndOfStream);
4545 }
4646
47 testing.expect(counting_stream.bytes_read == bytes.len);
47 try testing.expect(counting_stream.bytes_read == bytes.len);
4848}
lib/std/io/counting_writer.zig+1-1
......@@ -40,5 +40,5 @@ test "io.CountingWriter" {
4040
4141 const bytes = "yay" ** 100;
4242 stream.writeAll(bytes) catch unreachable;
43 testing.expect(counting_stream.bytes_written == bytes.len);
43 try testing.expect(counting_stream.bytes_written == bytes.len);
4444}
lib/std/io/fixed_buffer_stream.zig+13-13
......@@ -134,7 +134,7 @@ test "FixedBufferStream output" {
134134 const stream = fbs.writer();
135135
136136 try stream.print("{s}{s}!", .{ "Hello", "World" });
137 testing.expectEqualSlices(u8, "HelloWorld!", fbs.getWritten());
137 try testing.expectEqualSlices(u8, "HelloWorld!", fbs.getWritten());
138138}
139139
140140test "FixedBufferStream output 2" {
......@@ -142,19 +142,19 @@ test "FixedBufferStream output 2" {
142142 var fbs = fixedBufferStream(&buffer);
143143
144144 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
147147 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("!"));
151 testing.expect(mem.eql(u8, fbs.getWritten(), "Helloworld"));
150 try testing.expectError(error.NoSpaceLeft, fbs.writer().writeAll("!"));
151 try testing.expect(mem.eql(u8, fbs.getWritten(), "Helloworld"));
152152
153153 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!"));
157 testing.expect(mem.eql(u8, fbs.getWritten(), "Hello worl"));
156 try testing.expectError(error.NoSpaceLeft, fbs.writer().writeAll("Hello world!"));
157 try testing.expect(mem.eql(u8, fbs.getWritten(), "Hello worl"));
158158}
159159
160160test "FixedBufferStream input" {
......@@ -164,13 +164,13 @@ test "FixedBufferStream input" {
164164 var dest: [4]u8 = undefined;
165165
166166 var read = try fbs.reader().read(dest[0..4]);
167 testing.expect(read == 4);
168 testing.expect(mem.eql(u8, dest[0..4], bytes[0..4]));
167 try testing.expect(read == 4);
168 try testing.expect(mem.eql(u8, dest[0..4], bytes[0..4]));
169169
170170 read = try fbs.reader().read(dest[0..4]);
171 testing.expect(read == 3);
172 testing.expect(mem.eql(u8, dest[0..3], bytes[4..7]));
171 try testing.expect(read == 3);
172 try testing.expect(mem.eql(u8, dest[0..3], bytes[4..7]));
173173
174174 read = try fbs.reader().read(dest[0..4]);
175 testing.expect(read == 0);
175 try testing.expect(read == 0);
176176}
lib/std/io/limited_reader.zig+4-4
......@@ -43,8 +43,8 @@ test "basic usage" {
4343 var early_stream = limitedReader(fbs.reader(), 3);
4444
4545 var buf: [5]u8 = undefined;
46 testing.expectEqual(@as(usize, 3), try early_stream.reader().read(&buf));
47 testing.expectEqualSlices(u8, data[0..3], buf[0..3]);
48 testing.expectEqual(@as(usize, 0), try early_stream.reader().read(&buf));
49 testing.expectError(error.EndOfStream, early_stream.reader().skipBytes(10, .{}));
46 try testing.expectEqual(@as(usize, 3), try early_stream.reader().read(&buf));
47 try testing.expectEqualSlices(u8, data[0..3], buf[0..3]);
48 try testing.expectEqual(@as(usize, 0), try early_stream.reader().read(&buf));
49 try testing.expectError(error.EndOfStream, early_stream.reader().skipBytes(10, .{}));
5050}
lib/std/io/multi_writer.zig+2-2
......@@ -52,6 +52,6 @@ test "MultiWriter" {
5252 var fbs2 = io.fixedBufferStream(&buf2);
5353 var stream = multiWriter(.{ fbs1.writer(), fbs2.writer() });
5454 try stream.writer().print("HI", .{});
55 testing.expectEqualSlices(u8, "HI", fbs1.getWritten());
56 testing.expectEqualSlices(u8, "HI", fbs2.getWritten());
55 try testing.expectEqualSlices(u8, "HI", fbs1.getWritten());
56 try testing.expectEqualSlices(u8, "HI", fbs2.getWritten());
5757}
lib/std/io/peek_stream.zig+11-11
......@@ -94,24 +94,24 @@ test "PeekStream" {
9494 try ps.putBackByte(10);
9595
9696 var read = try ps.reader().read(dest[0..4]);
97 testing.expect(read == 4);
98 testing.expect(dest[0] == 10);
99 testing.expect(dest[1] == 9);
100 testing.expect(mem.eql(u8, dest[2..4], bytes[0..2]));
97 try testing.expect(read == 4);
98 try testing.expect(dest[0] == 10);
99 try testing.expect(dest[1] == 9);
100 try testing.expect(mem.eql(u8, dest[2..4], bytes[0..2]));
101101
102102 read = try ps.reader().read(dest[0..4]);
103 testing.expect(read == 4);
104 testing.expect(mem.eql(u8, dest[0..4], bytes[2..6]));
103 try testing.expect(read == 4);
104 try testing.expect(mem.eql(u8, dest[0..4], bytes[2..6]));
105105
106106 read = try ps.reader().read(dest[0..4]);
107 testing.expect(read == 2);
108 testing.expect(mem.eql(u8, dest[0..2], bytes[6..8]));
107 try testing.expect(read == 2);
108 try testing.expect(mem.eql(u8, dest[0..2], bytes[6..8]));
109109
110110 try ps.putBackByte(11);
111111 try ps.putBackByte(12);
112112
113113 read = try ps.reader().read(dest[0..4]);
114 testing.expect(read == 2);
115 testing.expect(dest[0] == 12);
116 testing.expect(dest[1] == 11);
114 try testing.expect(read == 2);
115 try testing.expect(dest[0] == 12);
116 try testing.expect(dest[1] == 11);
117117}
lib/std/io/reader.zig+7-7
......@@ -329,26 +329,26 @@ pub fn Reader(
329329test "Reader" {
330330 var buf = "a\x02".*;
331331 const reader = std.io.fixedBufferStream(&buf).reader();
332 testing.expect((try reader.readByte()) == 'a');
333 testing.expect((try reader.readEnum(enum(u8) {
332 try testing.expect((try reader.readByte()) == 'a');
333 try testing.expect((try reader.readEnum(enum(u8) {
334334 a = 0,
335335 b = 99,
336336 c = 2,
337337 d = 3,
338338 }, undefined)) == .c);
339 testing.expectError(error.EndOfStream, reader.readByte());
339 try testing.expectError(error.EndOfStream, reader.readByte());
340340}
341341
342342test "Reader.isBytes" {
343343 const reader = std.io.fixedBufferStream("foobar").reader();
344 testing.expectEqual(true, try reader.isBytes("foo"));
345 testing.expectEqual(false, try reader.isBytes("qux"));
344 try testing.expectEqual(true, try reader.isBytes("foo"));
345 try testing.expectEqual(false, try reader.isBytes("qux"));
346346}
347347
348348test "Reader.skipBytes" {
349349 const reader = std.io.fixedBufferStream("foobar").reader();
350350 try reader.skipBytes(3, .{});
351 testing.expect(try reader.isBytes("bar"));
351 try testing.expect(try reader.isBytes("bar"));
352352 try reader.skipBytes(0, .{});
353 testing.expectError(error.EndOfStream, reader.skipBytes(1, .{}));
353 try testing.expectError(error.EndOfStream, reader.skipBytes(1, .{}));
354354}
lib/std/io/test.zig+33-33
......@@ -40,7 +40,7 @@ test "write a file, read it, then delete it" {
4040
4141 {
4242 // 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 }));
4444 }
4545
4646 {
......@@ -49,16 +49,16 @@ test "write a file, read it, then delete it" {
4949
5050 const file_size = try file.getEndPos();
5151 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
5454 var buf_stream = io.bufferedReader(file.reader());
5555 const st = buf_stream.reader();
5656 const contents = try st.readAllAlloc(std.testing.allocator, 2 * 1024);
5757 defer std.testing.allocator.free(contents);
5858
59 expect(mem.eql(u8, contents[0.."begin".len], "begin"));
60 expect(mem.eql(u8, contents["begin".len .. contents.len - "end".len], &data));
61 expect(mem.eql(u8, contents[contents.len - "end".len ..], "end"));
59 try expect(mem.eql(u8, contents[0.."begin".len], "begin"));
60 try expect(mem.eql(u8, contents["begin".len .. contents.len - "end".len], &data));
61 try expect(mem.eql(u8, contents[contents.len - "end".len ..], "end"));
6262 }
6363 try tmp.dir.deleteFile(tmp_file_name);
6464}
......@@ -90,20 +90,20 @@ test "BitStreams with File Stream" {
9090
9191 var out_bits: usize = undefined;
9292
93 expect(1 == try bit_stream.readBits(u2, 1, &out_bits));
94 expect(out_bits == 1);
95 expect(2 == try bit_stream.readBits(u5, 2, &out_bits));
96 expect(out_bits == 2);
97 expect(3 == try bit_stream.readBits(u128, 3, &out_bits));
98 expect(out_bits == 3);
99 expect(4 == try bit_stream.readBits(u8, 4, &out_bits));
100 expect(out_bits == 4);
101 expect(5 == try bit_stream.readBits(u9, 5, &out_bits));
102 expect(out_bits == 5);
103 expect(1 == try bit_stream.readBits(u1, 1, &out_bits));
104 expect(out_bits == 1);
105
106 expectError(error.EndOfStream, bit_stream.readBitsNoEof(u1, 1));
93 try expect(1 == try bit_stream.readBits(u2, 1, &out_bits));
94 try expect(out_bits == 1);
95 try expect(2 == try bit_stream.readBits(u5, 2, &out_bits));
96 try expect(out_bits == 2);
97 try expect(3 == try bit_stream.readBits(u128, 3, &out_bits));
98 try expect(out_bits == 3);
99 try expect(4 == try bit_stream.readBits(u8, 4, &out_bits));
100 try expect(out_bits == 4);
101 try expect(5 == try bit_stream.readBits(u9, 5, &out_bits));
102 try expect(out_bits == 5);
103 try expect(1 == try bit_stream.readBits(u1, 1, &out_bits));
104 try expect(out_bits == 1);
105
106 try expectError(error.EndOfStream, bit_stream.readBitsNoEof(u1, 1));
107107 }
108108 try tmp.dir.deleteFile(tmp_file_name);
109109}
......@@ -123,16 +123,16 @@ test "File seek ops" {
123123
124124 // Seek to the end
125125 try file.seekFromEnd(0);
126 expect((try file.getPos()) == try file.getEndPos());
126 try expect((try file.getPos()) == try file.getEndPos());
127127 // Negative delta
128128 try file.seekBy(-4096);
129 expect((try file.getPos()) == 4096);
129 try expect((try file.getPos()) == 4096);
130130 // Positive delta
131131 try file.seekBy(10);
132 expect((try file.getPos()) == 4106);
132 try expect((try file.getPos()) == 4106);
133133 // Absolute position
134134 try file.seekTo(1234);
135 expect((try file.getPos()) == 1234);
135 try expect((try file.getPos()) == 1234);
136136}
137137
138138test "setEndPos" {
......@@ -147,18 +147,18 @@ test "setEndPos" {
147147 }
148148
149149 // Verify that the file size changes and the file offset is not moved
150 std.testing.expect((try file.getEndPos()) == 0);
151 std.testing.expect((try file.getPos()) == 0);
150 try std.testing.expect((try file.getEndPos()) == 0);
151 try std.testing.expect((try file.getPos()) == 0);
152152 try file.setEndPos(8192);
153 std.testing.expect((try file.getEndPos()) == 8192);
154 std.testing.expect((try file.getPos()) == 0);
153 try std.testing.expect((try file.getEndPos()) == 8192);
154 try std.testing.expect((try file.getPos()) == 0);
155155 try file.seekTo(100);
156156 try file.setEndPos(4096);
157 std.testing.expect((try file.getEndPos()) == 4096);
158 std.testing.expect((try file.getPos()) == 100);
157 try std.testing.expect((try file.getEndPos()) == 4096);
158 try std.testing.expect((try file.getPos()) == 100);
159159 try file.setEndPos(0);
160 std.testing.expect((try file.getEndPos()) == 0);
161 std.testing.expect((try file.getPos()) == 100);
160 try std.testing.expect((try file.getEndPos()) == 0);
161 try std.testing.expect((try file.getPos()) == 100);
162162}
163163
164164test "updateTimes" {
......@@ -178,6 +178,6 @@ test "updateTimes" {
178178 stat_old.mtime - 5 * std.time.ns_per_s,
179179 );
180180 var stat_new = try file.stat();
181 expect(stat_new.atime < stat_old.atime);
182 expect(stat_new.mtime < stat_old.mtime);
181 try expect(stat_new.atime < stat_old.atime);
182 try expect(stat_new.mtime < stat_old.mtime);
183183}
lib/std/json.zig+139-139
......@@ -79,18 +79,18 @@ fn encodesTo(decoded: []const u8, encoded: []const u8) bool {
7979
8080test "encodesTo" {
8181 // same
82 testing.expectEqual(true, encodesTo("false", "false"));
82 try testing.expectEqual(true, encodesTo("false", "false"));
8383 // totally different
84 testing.expectEqual(false, encodesTo("false", "true"));
84 try testing.expectEqual(false, encodesTo("false", "true"));
8585 // different lengths
86 testing.expectEqual(false, encodesTo("false", "other"));
86 try testing.expectEqual(false, encodesTo("false", "other"));
8787 // with escape
88 testing.expectEqual(true, encodesTo("\\", "\\\\"));
89 testing.expectEqual(true, encodesTo("with\nescape", "with\\nescape"));
88 try testing.expectEqual(true, encodesTo("\\", "\\\\"));
89 try testing.expectEqual(true, encodesTo("with\nescape", "with\\nescape"));
9090 // with unicode
91 testing.expectEqual(true, encodesTo("ą", "\\u0105"));
92 testing.expectEqual(true, encodesTo("😂", "\\ud83d\\ude02"));
93 testing.expectEqual(true, encodesTo("withąunicode😂", "with\\u0105unicode\\ud83d\\ude02"));
91 try testing.expectEqual(true, encodesTo("ą", "\\u0105"));
92 try testing.expectEqual(true, encodesTo("😂", "\\ud83d\\ude02"));
93 try testing.expectEqual(true, encodesTo("withąunicode😂", "with\\u0105unicode\\ud83d\\ude02"));
9494}
9595
9696/// A single token slice into the parent string.
......@@ -1138,9 +1138,9 @@ pub const TokenStream = struct {
11381138 }
11391139};
11401140
1141fn checkNext(p: *TokenStream, id: std.meta.Tag(Token)) void {
1141fn checkNext(p: *TokenStream, id: std.meta.Tag(Token)) !void {
11421142 const token = (p.next() catch unreachable).?;
1143 debug.assert(std.meta.activeTag(token) == id);
1143 try testing.expect(std.meta.activeTag(token) == id);
11441144}
11451145
11461146test "json.token" {
......@@ -1163,46 +1163,46 @@ test "json.token" {
11631163
11641164 var p = TokenStream.init(s);
11651165
1166 checkNext(&p, .ObjectBegin);
1167 checkNext(&p, .String); // Image
1168 checkNext(&p, .ObjectBegin);
1169 checkNext(&p, .String); // Width
1170 checkNext(&p, .Number);
1171 checkNext(&p, .String); // Height
1172 checkNext(&p, .Number);
1173 checkNext(&p, .String); // Title
1174 checkNext(&p, .String);
1175 checkNext(&p, .String); // Thumbnail
1176 checkNext(&p, .ObjectBegin);
1177 checkNext(&p, .String); // Url
1178 checkNext(&p, .String);
1179 checkNext(&p, .String); // Height
1180 checkNext(&p, .Number);
1181 checkNext(&p, .String); // Width
1182 checkNext(&p, .Number);
1183 checkNext(&p, .ObjectEnd);
1184 checkNext(&p, .String); // Animated
1185 checkNext(&p, .False);
1186 checkNext(&p, .String); // IDs
1187 checkNext(&p, .ArrayBegin);
1188 checkNext(&p, .Number);
1189 checkNext(&p, .Number);
1190 checkNext(&p, .Number);
1191 checkNext(&p, .Number);
1192 checkNext(&p, .ArrayEnd);
1193 checkNext(&p, .ObjectEnd);
1194 checkNext(&p, .ObjectEnd);
1195
1196 testing.expect((try p.next()) == null);
1166 try checkNext(&p, .ObjectBegin);
1167 try checkNext(&p, .String); // Image
1168 try checkNext(&p, .ObjectBegin);
1169 try checkNext(&p, .String); // Width
1170 try checkNext(&p, .Number);
1171 try checkNext(&p, .String); // Height
1172 try checkNext(&p, .Number);
1173 try checkNext(&p, .String); // Title
1174 try checkNext(&p, .String);
1175 try checkNext(&p, .String); // Thumbnail
1176 try checkNext(&p, .ObjectBegin);
1177 try checkNext(&p, .String); // Url
1178 try checkNext(&p, .String);
1179 try checkNext(&p, .String); // Height
1180 try checkNext(&p, .Number);
1181 try checkNext(&p, .String); // Width
1182 try checkNext(&p, .Number);
1183 try checkNext(&p, .ObjectEnd);
1184 try checkNext(&p, .String); // Animated
1185 try checkNext(&p, .False);
1186 try checkNext(&p, .String); // IDs
1187 try checkNext(&p, .ArrayBegin);
1188 try checkNext(&p, .Number);
1189 try checkNext(&p, .Number);
1190 try checkNext(&p, .Number);
1191 try checkNext(&p, .Number);
1192 try checkNext(&p, .ArrayEnd);
1193 try checkNext(&p, .ObjectEnd);
1194 try checkNext(&p, .ObjectEnd);
1195
1196 try testing.expect((try p.next()) == null);
11971197}
11981198
11991199test "json.token mismatched close" {
12001200 var p = TokenStream.init("[102, 111, 111 }");
1201 checkNext(&p, .ArrayBegin);
1202 checkNext(&p, .Number);
1203 checkNext(&p, .Number);
1204 checkNext(&p, .Number);
1205 testing.expectError(error.UnexpectedClosingBrace, p.next());
1201 try checkNext(&p, .ArrayBegin);
1202 try checkNext(&p, .Number);
1203 try checkNext(&p, .Number);
1204 try checkNext(&p, .Number);
1205 try testing.expectError(error.UnexpectedClosingBrace, p.next());
12061206}
12071207
12081208/// 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 {
12231223}
12241224
12251225test "json.validate" {
1226 testing.expectEqual(true, validate("{}"));
1227 testing.expectEqual(true, validate("[]"));
1228 testing.expectEqual(true, validate("[{[[[[{}]]]]}]"));
1229 testing.expectEqual(false, validate("{]"));
1230 testing.expectEqual(false, validate("[}"));
1231 testing.expectEqual(false, validate("{{{{[]}}}]"));
1226 try testing.expectEqual(true, validate("{}"));
1227 try testing.expectEqual(true, validate("[]"));
1228 try testing.expectEqual(true, validate("[{[[[[{}]]]]}]"));
1229 try testing.expectEqual(false, validate("{]"));
1230 try testing.expectEqual(false, validate("[}"));
1231 try testing.expectEqual(false, validate("{{{{[]}}}]"));
12321232}
12331233
12341234const Allocator = std.mem.Allocator;
......@@ -1326,37 +1326,37 @@ test "Value.jsonStringify" {
13261326 var buffer: [10]u8 = undefined;
13271327 var fbs = std.io.fixedBufferStream(&buffer);
13281328 try @as(Value, .Null).jsonStringify(.{}, fbs.writer());
1329 testing.expectEqualSlices(u8, fbs.getWritten(), "null");
1329 try testing.expectEqualSlices(u8, fbs.getWritten(), "null");
13301330 }
13311331 {
13321332 var buffer: [10]u8 = undefined;
13331333 var fbs = std.io.fixedBufferStream(&buffer);
13341334 try (Value{ .Bool = true }).jsonStringify(.{}, fbs.writer());
1335 testing.expectEqualSlices(u8, fbs.getWritten(), "true");
1335 try testing.expectEqualSlices(u8, fbs.getWritten(), "true");
13361336 }
13371337 {
13381338 var buffer: [10]u8 = undefined;
13391339 var fbs = std.io.fixedBufferStream(&buffer);
13401340 try (Value{ .Integer = 42 }).jsonStringify(.{}, fbs.writer());
1341 testing.expectEqualSlices(u8, fbs.getWritten(), "42");
1341 try testing.expectEqualSlices(u8, fbs.getWritten(), "42");
13421342 }
13431343 {
13441344 var buffer: [10]u8 = undefined;
13451345 var fbs = std.io.fixedBufferStream(&buffer);
13461346 try (Value{ .NumberString = "43" }).jsonStringify(.{}, fbs.writer());
1347 testing.expectEqualSlices(u8, fbs.getWritten(), "43");
1347 try testing.expectEqualSlices(u8, fbs.getWritten(), "43");
13481348 }
13491349 {
13501350 var buffer: [10]u8 = undefined;
13511351 var fbs = std.io.fixedBufferStream(&buffer);
13521352 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");
13541354 }
13551355 {
13561356 var buffer: [10]u8 = undefined;
13571357 var fbs = std.io.fixedBufferStream(&buffer);
13581358 try (Value{ .String = "weeee" }).jsonStringify(.{}, fbs.writer());
1359 testing.expectEqualSlices(u8, fbs.getWritten(), "\"weeee\"");
1359 try testing.expectEqualSlices(u8, fbs.getWritten(), "\"weeee\"");
13601360 }
13611361 {
13621362 var buffer: [10]u8 = undefined;
......@@ -1369,7 +1369,7 @@ test "Value.jsonStringify" {
13691369 try (Value{
13701370 .Array = Array.fromOwnedSlice(undefined, &vals),
13711371 }).jsonStringify(.{}, fbs.writer());
1372 testing.expectEqualSlices(u8, fbs.getWritten(), "[1,2,3]");
1372 try testing.expectEqualSlices(u8, fbs.getWritten(), "[1,2,3]");
13731373 }
13741374 {
13751375 var buffer: [10]u8 = undefined;
......@@ -1378,7 +1378,7 @@ test "Value.jsonStringify" {
13781378 defer obj.deinit();
13791379 try obj.putNoClobber("a", .{ .String = "b" });
13801380 try (Value{ .Object = obj }).jsonStringify(.{}, fbs.writer());
1381 testing.expectEqualSlices(u8, fbs.getWritten(), "{\"a\":\"b\"}");
1381 try testing.expectEqualSlices(u8, fbs.getWritten(), "{\"a\":\"b\"}");
13821382 }
13831383}
13841384
......@@ -1751,17 +1751,17 @@ pub fn parseFree(comptime T: type, value: T, options: ParseOptions) void {
17511751}
17521752
17531753test "parse" {
1754 testing.expectEqual(false, try parse(bool, &TokenStream.init("false"), ParseOptions{}));
1755 testing.expectEqual(true, try parse(bool, &TokenStream.init("true"), ParseOptions{}));
1756 testing.expectEqual(@as(u1, 1), try parse(u1, &TokenStream.init("1"), ParseOptions{}));
1757 testing.expectError(error.Overflow, parse(u1, &TokenStream.init("50"), ParseOptions{}));
1758 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{}));
1760 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{}));
1762
1763 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{}));
1754 try testing.expectEqual(false, try parse(bool, &TokenStream.init("false"), ParseOptions{}));
1755 try testing.expectEqual(true, try parse(bool, &TokenStream.init("true"), ParseOptions{}));
1756 try testing.expectEqual(@as(u1, 1), try parse(u1, &TokenStream.init("1"), ParseOptions{}));
1757 try testing.expectError(error.Overflow, parse(u1, &TokenStream.init("50"), ParseOptions{}));
1758 try testing.expectEqual(@as(u64, 42), try parse(u64, &TokenStream.init("42"), ParseOptions{}));
1759 try testing.expectEqual(@as(f64, 42), try parse(f64, &TokenStream.init("42.0"), ParseOptions{}));
1760 try testing.expectEqual(@as(?bool, null), try parse(?bool, &TokenStream.init("null"), ParseOptions{}));
1761 try testing.expectEqual(@as(?bool, true), try parse(?bool, &TokenStream.init("true"), ParseOptions{}));
1762
1763 try testing.expectEqual(@as([3]u8, "foo".*), try parse([3]u8, &TokenStream.init("\"foo\""), ParseOptions{}));
1764 try testing.expectEqual(@as([3]u8, "foo".*), try parse([3]u8, &TokenStream.init("[102, 111, 111]"), ParseOptions{}));
17651765}
17661766
17671767test "parse into enum" {
......@@ -1770,31 +1770,31 @@ test "parse into enum" {
17701770 Bar,
17711771 @"with\\escape",
17721772 };
1773 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{}));
1775 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{}));
1777 testing.expectError(error.InvalidEnumTag, parse(T, &TokenStream.init("\"Qux\""), ParseOptions{}));
1773 try testing.expectEqual(@as(T, .Foo), try parse(T, &TokenStream.init("\"Foo\""), ParseOptions{}));
1774 try testing.expectEqual(@as(T, .Foo), try parse(T, &TokenStream.init("42"), ParseOptions{}));
1775 try testing.expectEqual(@as(T, .@"with\\escape"), try parse(T, &TokenStream.init("\"with\\\\escape\""), ParseOptions{}));
1776 try testing.expectError(error.InvalidEnumTag, parse(T, &TokenStream.init("5"), ParseOptions{}));
1777 try testing.expectError(error.InvalidEnumTag, parse(T, &TokenStream.init("\"Qux\""), ParseOptions{}));
17781778}
17791779
17801780test "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
17831783 const options = ParseOptions{ .allocator = testing.allocator };
17841784 {
17851785 const r = try parse([]u8, &TokenStream.init("\"foo\""), options);
17861786 defer parseFree([]u8, r, options);
1787 testing.expectEqualSlices(u8, "foo", r);
1787 try testing.expectEqualSlices(u8, "foo", r);
17881788 }
17891789 {
17901790 const r = try parse([]u8, &TokenStream.init("[102, 111, 111]"), options);
17911791 defer parseFree([]u8, r, options);
1792 testing.expectEqualSlices(u8, "foo", r);
1792 try testing.expectEqualSlices(u8, "foo", r);
17931793 }
17941794 {
17951795 const r = try parse([]u8, &TokenStream.init("\"with\\\\escape\""), options);
17961796 defer parseFree([]u8, r, options);
1797 testing.expectEqualSlices(u8, "with\\escape", r);
1797 try testing.expectEqualSlices(u8, "with\\escape", r);
17981798 }
17991799}
18001800
......@@ -1805,7 +1805,7 @@ test "parse into tagged union" {
18051805 float: f64,
18061806 string: []const u8,
18071807 };
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{}));
18091809 }
18101810
18111811 { // failing allocations should be bubbled up instantly without trying next member
......@@ -1816,7 +1816,7 @@ test "parse into tagged union" {
18161816 string: []const u8,
18171817 array: [3]u8,
18181818 };
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));
18201820 }
18211821
18221822 {
......@@ -1825,7 +1825,7 @@ test "parse into tagged union" {
18251825 x: u8,
18261826 y: u8,
18271827 };
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{}));
18291829 }
18301830
18311831 { // needs to back out when first union member doesn't match
......@@ -1833,7 +1833,7 @@ test "parse into tagged union" {
18331833 A: struct { x: u32 },
18341834 B: struct { y: u32 },
18351835 };
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{}));
18371837 }
18381838}
18391839
......@@ -1843,7 +1843,7 @@ test "parse union bubbles up AllocatorRequired" {
18431843 string: []const u8,
18441844 int: i32,
18451845 };
1846 testing.expectError(error.AllocatorRequired, parse(T, &TokenStream.init("42"), ParseOptions{}));
1846 try testing.expectError(error.AllocatorRequired, parse(T, &TokenStream.init("42"), ParseOptions{}));
18471847 }
18481848
18491849 { // string member not first in union (and matching)
......@@ -1852,7 +1852,7 @@ test "parse union bubbles up AllocatorRequired" {
18521852 float: f64,
18531853 string: []const u8,
18541854 };
1855 testing.expectError(error.AllocatorRequired, parse(T, &TokenStream.init("\"foo\""), ParseOptions{}));
1855 try testing.expectError(error.AllocatorRequired, parse(T, &TokenStream.init("\"foo\""), ParseOptions{}));
18561856 }
18571857}
18581858
......@@ -1866,11 +1866,11 @@ test "parseFree descends into tagged union" {
18661866 };
18671867 // use a string with unicode escape so we know result can't be a reference to global constant
18681868 const r = try parse(T, &TokenStream.init("\"with\\u0105unicode\""), options);
1869 testing.expectEqual(std.meta.Tag(T).string, @as(std.meta.Tag(T), r));
1870 testing.expectEqualSlices(u8, "withąunicode", r.string);
1871 testing.expectEqual(@as(usize, 0), fail_alloc.deallocations);
1869 try testing.expectEqual(std.meta.Tag(T).string, @as(std.meta.Tag(T), r));
1870 try testing.expectEqualSlices(u8, "withąunicode", r.string);
1871 try testing.expectEqual(@as(usize, 0), fail_alloc.deallocations);
18721872 parseFree(T, r, options);
1873 testing.expectEqual(@as(usize, 1), fail_alloc.deallocations);
1873 try testing.expectEqual(@as(usize, 1), fail_alloc.deallocations);
18741874}
18751875
18761876test "parse with comptime field" {
......@@ -1879,7 +1879,7 @@ test "parse with comptime field" {
18791879 comptime a: i32 = 0,
18801880 b: bool,
18811881 };
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(
18831883 \\{
18841884 \\ "a": 0,
18851885 \\ "b": true
......@@ -1912,7 +1912,7 @@ test "parse with comptime field" {
19121912
19131913test "parse into struct with no fields" {
19141914 const T = struct {};
1915 testing.expectEqual(T{}, try parse(T, &TokenStream.init("{}"), ParseOptions{}));
1915 try testing.expectEqual(T{}, try parse(T, &TokenStream.init("{}"), ParseOptions{}));
19161916}
19171917
19181918test "parse into struct with misc fields" {
......@@ -1968,24 +1968,24 @@ test "parse into struct with misc fields" {
19681968 \\}
19691969 ), options);
19701970 defer parseFree(T, r, options);
1971 testing.expectEqual(@as(i64, 420), r.int);
1972 testing.expectEqual(@as(f64, 3.14), r.float);
1973 testing.expectEqual(true, r.@"with\\escape");
1974 testing.expectEqual(false, r.@"withąunicode😂");
1975 testing.expectEqualSlices(u8, "zig", r.language);
1976 testing.expectEqual(@as(?bool, null), r.optional);
1977 testing.expectEqual(@as(i32, 42), r.default_field);
1978 testing.expectEqual(@as(f64, 66.6), r.static_array[0]);
1979 testing.expectEqual(@as(f64, 420.420), r.static_array[1]);
1980 testing.expectEqual(@as(f64, 69.69), r.static_array[2]);
1981 testing.expectEqual(@as(usize, 3), r.dynamic_array.len);
1982 testing.expectEqual(@as(f64, 66.6), r.dynamic_array[0]);
1983 testing.expectEqual(@as(f64, 420.420), r.dynamic_array[1]);
1984 testing.expectEqual(@as(f64, 69.69), r.dynamic_array[2]);
1985 testing.expectEqualSlices(u8, r.complex.nested, "zig");
1986 testing.expectEqualSlices(u8, "zig", r.veryComplex[0].foo);
1987 testing.expectEqualSlices(u8, "rocks", r.veryComplex[1].foo);
1988 testing.expectEqual(T.Union{ .float = 100000 }, r.a_union);
1971 try testing.expectEqual(@as(i64, 420), r.int);
1972 try testing.expectEqual(@as(f64, 3.14), r.float);
1973 try testing.expectEqual(true, r.@"with\\escape");
1974 try testing.expectEqual(false, r.@"withąunicode😂");
1975 try testing.expectEqualSlices(u8, "zig", r.language);
1976 try testing.expectEqual(@as(?bool, null), r.optional);
1977 try testing.expectEqual(@as(i32, 42), r.default_field);
1978 try testing.expectEqual(@as(f64, 66.6), r.static_array[0]);
1979 try testing.expectEqual(@as(f64, 420.420), r.static_array[1]);
1980 try testing.expectEqual(@as(f64, 69.69), r.static_array[2]);
1981 try testing.expectEqual(@as(usize, 3), r.dynamic_array.len);
1982 try testing.expectEqual(@as(f64, 66.6), r.dynamic_array[0]);
1983 try testing.expectEqual(@as(f64, 420.420), r.dynamic_array[1]);
1984 try testing.expectEqual(@as(f64, 69.69), r.dynamic_array[2]);
1985 try testing.expectEqualSlices(u8, r.complex.nested, "zig");
1986 try testing.expectEqualSlices(u8, "zig", r.veryComplex[0].foo);
1987 try testing.expectEqualSlices(u8, "rocks", r.veryComplex[1].foo);
1988 try testing.expectEqual(T.Union{ .float = 100000 }, r.a_union);
19891989}
19901990
19911991/// A non-stream JSON parser which constructs a tree of Value's.
......@@ -2320,28 +2320,28 @@ test "json.parser.dynamic" {
23202320 var image = root.Object.get("Image").?;
23212321
23222322 const width = image.Object.get("Width").?;
2323 testing.expect(width.Integer == 800);
2323 try testing.expect(width.Integer == 800);
23242324
23252325 const height = image.Object.get("Height").?;
2326 testing.expect(height.Integer == 600);
2326 try testing.expect(height.Integer == 600);
23272327
23282328 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
23312331 const animated = image.Object.get("Animated").?;
2332 testing.expect(animated.Bool == false);
2332 try testing.expect(animated.Bool == false);
23332333
23342334 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
23372337 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
23402340 const double = image.Object.get("double").?;
2341 testing.expect(double.Float == 1.3412);
2341 try testing.expect(double.Float == 1.3412);
23422342
23432343 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"));
23452345}
23462346
23472347test "import more json tests" {
......@@ -2388,12 +2388,12 @@ test "write json then parse it" {
23882388 var tree = try parser.parse(fixed_buffer_stream.getWritten());
23892389 defer tree.deinit();
23902390
2391 testing.expect(tree.root.Object.get("f").?.Bool == false);
2392 testing.expect(tree.root.Object.get("t").?.Bool == true);
2393 testing.expect(tree.root.Object.get("int").?.Integer == 1234);
2394 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);
2396 testing.expect(mem.eql(u8, tree.root.Object.get("str").?.String, "hello"));
2391 try testing.expect(tree.root.Object.get("f").?.Bool == false);
2392 try testing.expect(tree.root.Object.get("t").?.Bool == true);
2393 try testing.expect(tree.root.Object.get("int").?.Integer == 1234);
2394 try testing.expect(tree.root.Object.get("array").?.Array.items[0].Null == {});
2395 try testing.expect(tree.root.Object.get("array").?.Array.items[1].Float == 12.34);
2396 try testing.expect(mem.eql(u8, tree.root.Object.get("str").?.String, "hello"));
23972397}
23982398
23992399fn 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
24042404test "parsing empty string gives appropriate error" {
24052405 var arena_allocator = std.heap.ArenaAllocator.init(std.testing.allocator);
24062406 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, ""));
24082408}
24092409
24102410test "integer after float has proper type" {
......@@ -2416,7 +2416,7 @@ test "integer after float has proper type" {
24162416 \\ "ints": [1, 2, 3]
24172417 \\}
24182418 );
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);
24202420}
24212421
24222422test "escaped characters" {
......@@ -2439,16 +2439,16 @@ test "escaped characters" {
24392439
24402440 const obj = (try test_parse(&arena_allocator.allocator, input)).Object;
24412441
2442 testing.expectEqualSlices(u8, obj.get("backslash").?.String, "\\");
2443 testing.expectEqualSlices(u8, obj.get("forwardslash").?.String, "/");
2444 testing.expectEqualSlices(u8, obj.get("newline").?.String, "\n");
2445 testing.expectEqualSlices(u8, obj.get("carriagereturn").?.String, "\r");
2446 testing.expectEqualSlices(u8, obj.get("tab").?.String, "\t");
2447 testing.expectEqualSlices(u8, obj.get("formfeed").?.String, "\x0C");
2448 testing.expectEqualSlices(u8, obj.get("backspace").?.String, "\x08");
2449 testing.expectEqualSlices(u8, obj.get("doublequote").?.String, "\"");
2450 testing.expectEqualSlices(u8, obj.get("unicode").?.String, "ą");
2451 testing.expectEqualSlices(u8, obj.get("surrogatepair").?.String, "😂");
2442 try testing.expectEqualSlices(u8, obj.get("backslash").?.String, "\\");
2443 try testing.expectEqualSlices(u8, obj.get("forwardslash").?.String, "/");
2444 try testing.expectEqualSlices(u8, obj.get("newline").?.String, "\n");
2445 try testing.expectEqualSlices(u8, obj.get("carriagereturn").?.String, "\r");
2446 try testing.expectEqualSlices(u8, obj.get("tab").?.String, "\t");
2447 try testing.expectEqualSlices(u8, obj.get("formfeed").?.String, "\x0C");
2448 try testing.expectEqualSlices(u8, obj.get("backspace").?.String, "\x08");
2449 try testing.expectEqualSlices(u8, obj.get("doublequote").?.String, "\"");
2450 try testing.expectEqualSlices(u8, obj.get("unicode").?.String, "ą");
2451 try testing.expectEqualSlices(u8, obj.get("surrogatepair").?.String, "😂");
24522452}
24532453
24542454test "string copy option" {
......@@ -2471,7 +2471,7 @@ test "string copy option" {
24712471 const obj_copy = tree_copy.root.Object;
24722472
24732473 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);
24752475 }
24762476
24772477 const nocopy_addr = &obj_nocopy.get("noescape").?.String[0];
......@@ -2479,12 +2479,12 @@ test "string copy option" {
24792479
24802480 var found_nocopy = false;
24812481 for (input) |_, index| {
2482 testing.expect(copy_addr != &input[index]);
2482 try testing.expect(copy_addr != &input[index]);
24832483 if (nocopy_addr == &input[index]) {
24842484 found_nocopy = true;
24852485 }
24862486 }
2487 testing.expect(found_nocopy);
2487 try testing.expect(found_nocopy);
24882488}
24892489
24902490pub const StringifyOptions = struct {
lib/std/json/test.zig+275-275
......@@ -21,37 +21,37 @@ fn testNonStreaming(s: []const u8) !void {
2121}
2222
2323fn ok(s: []const u8) !void {
24 testing.expect(json.validate(s));
24 try testing.expect(json.validate(s));
2525
2626 try testNonStreaming(s);
2727}
2828
29fn err(s: []const u8) void {
30 testing.expect(!json.validate(s));
29fn err(s: []const u8) !void {
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)));
3333}
3434
35fn utf8Error(s: []const u8) void {
36 testing.expect(!json.validate(s));
35fn utf8Error(s: []const u8) !void {
36 try testing.expect(!json.validate(s));
3737
38 testing.expectError(error.InvalidUtf8Byte, testNonStreaming(s));
38 try testing.expectError(error.InvalidUtf8Byte, testNonStreaming(s));
3939}
4040
41fn any(s: []const u8) void {
41fn any(s: []const u8) !void {
4242 _ = json.validate(s);
4343
4444 testNonStreaming(s) catch {};
4545}
4646
47fn anyStreamingErrNonStreaming(s: []const u8) void {
47fn anyStreamingErrNonStreaming(s: []const u8) !void {
4848 _ = json.validate(s);
4949
50 testing.expect(std.meta.isError(testNonStreaming(s)));
50 try testing.expect(std.meta.isError(testNonStreaming(s)));
5151}
5252
5353fn roundTrip(s: []const u8) !void {
54 testing.expect(json.validate(s));
54 try testing.expect(json.validate(s));
5555
5656 var p = json.Parser.init(testing.allocator, false);
5757 defer p.deinit();
......@@ -63,7 +63,7 @@ fn roundTrip(s: []const u8) !void {
6363 var fbs = std.io.fixedBufferStream(&buf);
6464 try tree.root.jsonStringify(.{}, fbs.writer());
6565
66 testing.expectEqualStrings(s, fbs.getWritten());
66 try testing.expectEqualStrings(s, fbs.getWritten());
6767}
6868
6969////////////////////////////////////////////////////////////////////////////////////////////////////
......@@ -642,109 +642,109 @@ test "y_structure_whitespace_array" {
642642////////////////////////////////////////////////////////////////////////////////////////////////////
643643
644644test "n_array_1_true_without_comma" {
645 err(
645 try err(
646646 \\[1 true]
647647 );
648648}
649649
650650test "n_array_a_invalid_utf8" {
651 err(
651 try err(
652652 \\[aå]
653653 );
654654}
655655
656656test "n_array_colon_instead_of_comma" {
657 err(
657 try err(
658658 \\["": 1]
659659 );
660660}
661661
662662test "n_array_comma_after_close" {
663 err(
663 try err(
664664 \\[""],
665665 );
666666}
667667
668668test "n_array_comma_and_number" {
669 err(
669 try err(
670670 \\[,1]
671671 );
672672}
673673
674674test "n_array_double_comma" {
675 err(
675 try err(
676676 \\[1,,2]
677677 );
678678}
679679
680680test "n_array_double_extra_comma" {
681 err(
681 try err(
682682 \\["x",,]
683683 );
684684}
685685
686686test "n_array_extra_close" {
687 err(
687 try err(
688688 \\["x"]]
689689 );
690690}
691691
692692test "n_array_extra_comma" {
693 err(
693 try err(
694694 \\["",]
695695 );
696696}
697697
698698test "n_array_incomplete_invalid_value" {
699 err(
699 try err(
700700 \\[x
701701 );
702702}
703703
704704test "n_array_incomplete" {
705 err(
705 try err(
706706 \\["x"
707707 );
708708}
709709
710710test "n_array_inner_array_no_comma" {
711 err(
711 try err(
712712 \\[3[4]]
713713 );
714714}
715715
716716test "n_array_invalid_utf8" {
717 err(
717 try err(
718718 \\[ÿ]
719719 );
720720}
721721
722722test "n_array_items_separated_by_semicolon" {
723 err(
723 try err(
724724 \\[1:2]
725725 );
726726}
727727
728728test "n_array_just_comma" {
729 err(
729 try err(
730730 \\[,]
731731 );
732732}
733733
734734test "n_array_just_minus" {
735 err(
735 try err(
736736 \\[-]
737737 );
738738}
739739
740740test "n_array_missing_value" {
741 err(
741 try err(
742742 \\[ , ""]
743743 );
744744}
745745
746746test "n_array_newlines_unclosed" {
747 err(
747 try err(
748748 \\["a",
749749 \\4
750750 \\,1,
......@@ -752,41 +752,41 @@ test "n_array_newlines_unclosed" {
752752}
753753
754754test "n_array_number_and_comma" {
755 err(
755 try err(
756756 \\[1,]
757757 );
758758}
759759
760760test "n_array_number_and_several_commas" {
761 err(
761 try err(
762762 \\[1,,]
763763 );
764764}
765765
766766test "n_array_spaces_vertical_tab_formfeed" {
767 err("[\"\x0aa\"\\f]");
767 try err("[\"\x0aa\"\\f]");
768768}
769769
770770test "n_array_star_inside" {
771 err(
771 try err(
772772 \\[*]
773773 );
774774}
775775
776776test "n_array_unclosed" {
777 err(
777 try err(
778778 \\[""
779779 );
780780}
781781
782782test "n_array_unclosed_trailing_comma" {
783 err(
783 try err(
784784 \\[1,
785785 );
786786}
787787
788788test "n_array_unclosed_with_new_lines" {
789 err(
789 try err(
790790 \\[1,
791791 \\1
792792 \\,1
......@@ -794,956 +794,956 @@ test "n_array_unclosed_with_new_lines" {
794794}
795795
796796test "n_array_unclosed_with_object_inside" {
797 err(
797 try err(
798798 \\[{}
799799 );
800800}
801801
802802test "n_incomplete_false" {
803 err(
803 try err(
804804 \\[fals]
805805 );
806806}
807807
808808test "n_incomplete_null" {
809 err(
809 try err(
810810 \\[nul]
811811 );
812812}
813813
814814test "n_incomplete_true" {
815 err(
815 try err(
816816 \\[tru]
817817 );
818818}
819819
820820test "n_multidigit_number_then_00" {
821 err("123\x00");
821 try err("123\x00");
822822}
823823
824824test "n_number_0.1.2" {
825 err(
825 try err(
826826 \\[0.1.2]
827827 );
828828}
829829
830830test "n_number_-01" {
831 err(
831 try err(
832832 \\[-01]
833833 );
834834}
835835
836836test "n_number_0.3e" {
837 err(
837 try err(
838838 \\[0.3e]
839839 );
840840}
841841
842842test "n_number_0.3e+" {
843 err(
843 try err(
844844 \\[0.3e+]
845845 );
846846}
847847
848848test "n_number_0_capital_E" {
849 err(
849 try err(
850850 \\[0E]
851851 );
852852}
853853
854854test "n_number_0_capital_E+" {
855 err(
855 try err(
856856 \\[0E+]
857857 );
858858}
859859
860860test "n_number_0.e1" {
861 err(
861 try err(
862862 \\[0.e1]
863863 );
864864}
865865
866866test "n_number_0e" {
867 err(
867 try err(
868868 \\[0e]
869869 );
870870}
871871
872872test "n_number_0e+" {
873 err(
873 try err(
874874 \\[0e+]
875875 );
876876}
877877
878878test "n_number_1_000" {
879 err(
879 try err(
880880 \\[1 000.0]
881881 );
882882}
883883
884884test "n_number_1.0e-" {
885 err(
885 try err(
886886 \\[1.0e-]
887887 );
888888}
889889
890890test "n_number_1.0e" {
891 err(
891 try err(
892892 \\[1.0e]
893893 );
894894}
895895
896896test "n_number_1.0e+" {
897 err(
897 try err(
898898 \\[1.0e+]
899899 );
900900}
901901
902902test "n_number_-1.0." {
903 err(
903 try err(
904904 \\[-1.0.]
905905 );
906906}
907907
908908test "n_number_1eE2" {
909 err(
909 try err(
910910 \\[1eE2]
911911 );
912912}
913913
914914test "n_number_.-1" {
915 err(
915 try err(
916916 \\[.-1]
917917 );
918918}
919919
920920test "n_number_+1" {
921 err(
921 try err(
922922 \\[+1]
923923 );
924924}
925925
926926test "n_number_.2e-3" {
927 err(
927 try err(
928928 \\[.2e-3]
929929 );
930930}
931931
932932test "n_number_2.e-3" {
933 err(
933 try err(
934934 \\[2.e-3]
935935 );
936936}
937937
938938test "n_number_2.e+3" {
939 err(
939 try err(
940940 \\[2.e+3]
941941 );
942942}
943943
944944test "n_number_2.e3" {
945 err(
945 try err(
946946 \\[2.e3]
947947 );
948948}
949949
950950test "n_number_-2." {
951 err(
951 try err(
952952 \\[-2.]
953953 );
954954}
955955
956956test "n_number_9.e+" {
957 err(
957 try err(
958958 \\[9.e+]
959959 );
960960}
961961
962962test "n_number_expression" {
963 err(
963 try err(
964964 \\[1+2]
965965 );
966966}
967967
968968test "n_number_hex_1_digit" {
969 err(
969 try err(
970970 \\[0x1]
971971 );
972972}
973973
974974test "n_number_hex_2_digits" {
975 err(
975 try err(
976976 \\[0x42]
977977 );
978978}
979979
980980test "n_number_infinity" {
981 err(
981 try err(
982982 \\[Infinity]
983983 );
984984}
985985
986986test "n_number_+Inf" {
987 err(
987 try err(
988988 \\[+Inf]
989989 );
990990}
991991
992992test "n_number_Inf" {
993 err(
993 try err(
994994 \\[Inf]
995995 );
996996}
997997
998998test "n_number_invalid+-" {
999 err(
999 try err(
10001000 \\[0e+-1]
10011001 );
10021002}
10031003
10041004test "n_number_invalid-negative-real" {
1005 err(
1005 try err(
10061006 \\[-123.123foo]
10071007 );
10081008}
10091009
10101010test "n_number_invalid-utf-8-in-bigger-int" {
1011 err(
1011 try err(
10121012 \\[123å]
10131013 );
10141014}
10151015
10161016test "n_number_invalid-utf-8-in-exponent" {
1017 err(
1017 try err(
10181018 \\[1e1å]
10191019 );
10201020}
10211021
10221022test "n_number_invalid-utf-8-in-int" {
1023 err(
1023 try err(
10241024 \\[0å]
10251025 );
10261026}
10271027
10281028test "n_number_++" {
1029 err(
1029 try err(
10301030 \\[++1234]
10311031 );
10321032}
10331033
10341034test "n_number_minus_infinity" {
1035 err(
1035 try err(
10361036 \\[-Infinity]
10371037 );
10381038}
10391039
10401040test "n_number_minus_sign_with_trailing_garbage" {
1041 err(
1041 try err(
10421042 \\[-foo]
10431043 );
10441044}
10451045
10461046test "n_number_minus_space_1" {
1047 err(
1047 try err(
10481048 \\[- 1]
10491049 );
10501050}
10511051
10521052test "n_number_-NaN" {
1053 err(
1053 try err(
10541054 \\[-NaN]
10551055 );
10561056}
10571057
10581058test "n_number_NaN" {
1059 err(
1059 try err(
10601060 \\[NaN]
10611061 );
10621062}
10631063
10641064test "n_number_neg_int_starting_with_zero" {
1065 err(
1065 try err(
10661066 \\[-012]
10671067 );
10681068}
10691069
10701070test "n_number_neg_real_without_int_part" {
1071 err(
1071 try err(
10721072 \\[-.123]
10731073 );
10741074}
10751075
10761076test "n_number_neg_with_garbage_at_end" {
1077 err(
1077 try err(
10781078 \\[-1x]
10791079 );
10801080}
10811081
10821082test "n_number_real_garbage_after_e" {
1083 err(
1083 try err(
10841084 \\[1ea]
10851085 );
10861086}
10871087
10881088test "n_number_real_with_invalid_utf8_after_e" {
1089 err(
1089 try err(
10901090 \\[1eå]
10911091 );
10921092}
10931093
10941094test "n_number_real_without_fractional_part" {
1095 err(
1095 try err(
10961096 \\[1.]
10971097 );
10981098}
10991099
11001100test "n_number_starting_with_dot" {
1101 err(
1101 try err(
11021102 \\[.123]
11031103 );
11041104}
11051105
11061106test "n_number_U+FF11_fullwidth_digit_one" {
1107 err(
1107 try err(
11081108 \\[1]
11091109 );
11101110}
11111111
11121112test "n_number_with_alpha_char" {
1113 err(
1113 try err(
11141114 \\[1.8011670033376514H-308]
11151115 );
11161116}
11171117
11181118test "n_number_with_alpha" {
1119 err(
1119 try err(
11201120 \\[1.2a-3]
11211121 );
11221122}
11231123
11241124test "n_number_with_leading_zero" {
1125 err(
1125 try err(
11261126 \\[012]
11271127 );
11281128}
11291129
11301130test "n_object_bad_value" {
1131 err(
1131 try err(
11321132 \\["x", truth]
11331133 );
11341134}
11351135
11361136test "n_object_bracket_key" {
1137 err(
1137 try err(
11381138 \\{[: "x"}
11391139 );
11401140}
11411141
11421142test "n_object_comma_instead_of_colon" {
1143 err(
1143 try err(
11441144 \\{"x", null}
11451145 );
11461146}
11471147
11481148test "n_object_double_colon" {
1149 err(
1149 try err(
11501150 \\{"x"::"b"}
11511151 );
11521152}
11531153
11541154test "n_object_emoji" {
1155 err(
1155 try err(
11561156 \\{🇨🇭}
11571157 );
11581158}
11591159
11601160test "n_object_garbage_at_end" {
1161 err(
1161 try err(
11621162 \\{"a":"a" 123}
11631163 );
11641164}
11651165
11661166test "n_object_key_with_single_quotes" {
1167 err(
1167 try err(
11681168 \\{key: 'value'}
11691169 );
11701170}
11711171
11721172test "n_object_lone_continuation_byte_in_key_and_trailing_comma" {
1173 err(
1173 try err(
11741174 \\{"¹":"0",}
11751175 );
11761176}
11771177
11781178test "n_object_missing_colon" {
1179 err(
1179 try err(
11801180 \\{"a" b}
11811181 );
11821182}
11831183
11841184test "n_object_missing_key" {
1185 err(
1185 try err(
11861186 \\{:"b"}
11871187 );
11881188}
11891189
11901190test "n_object_missing_semicolon" {
1191 err(
1191 try err(
11921192 \\{"a" "b"}
11931193 );
11941194}
11951195
11961196test "n_object_missing_value" {
1197 err(
1197 try err(
11981198 \\{"a":
11991199 );
12001200}
12011201
12021202test "n_object_no-colon" {
1203 err(
1203 try err(
12041204 \\{"a"
12051205 );
12061206}
12071207
12081208test "n_object_non_string_key_but_huge_number_instead" {
1209 err(
1209 try err(
12101210 \\{9999E9999:1}
12111211 );
12121212}
12131213
12141214test "n_object_non_string_key" {
1215 err(
1215 try err(
12161216 \\{1:1}
12171217 );
12181218}
12191219
12201220test "n_object_repeated_null_null" {
1221 err(
1221 try err(
12221222 \\{null:null,null:null}
12231223 );
12241224}
12251225
12261226test "n_object_several_trailing_commas" {
1227 err(
1227 try err(
12281228 \\{"id":0,,,,,}
12291229 );
12301230}
12311231
12321232test "n_object_single_quote" {
1233 err(
1233 try err(
12341234 \\{'a':0}
12351235 );
12361236}
12371237
12381238test "n_object_trailing_comma" {
1239 err(
1239 try err(
12401240 \\{"id":0,}
12411241 );
12421242}
12431243
12441244test "n_object_trailing_comment" {
1245 err(
1245 try err(
12461246 \\{"a":"b"}/**/
12471247 );
12481248}
12491249
12501250test "n_object_trailing_comment_open" {
1251 err(
1251 try err(
12521252 \\{"a":"b"}/**//
12531253 );
12541254}
12551255
12561256test "n_object_trailing_comment_slash_open_incomplete" {
1257 err(
1257 try err(
12581258 \\{"a":"b"}/
12591259 );
12601260}
12611261
12621262test "n_object_trailing_comment_slash_open" {
1263 err(
1263 try err(
12641264 \\{"a":"b"}//
12651265 );
12661266}
12671267
12681268test "n_object_two_commas_in_a_row" {
1269 err(
1269 try err(
12701270 \\{"a":"b",,"c":"d"}
12711271 );
12721272}
12731273
12741274test "n_object_unquoted_key" {
1275 err(
1275 try err(
12761276 \\{a: "b"}
12771277 );
12781278}
12791279
12801280test "n_object_unterminated-value" {
1281 err(
1281 try err(
12821282 \\{"a":"a
12831283 );
12841284}
12851285
12861286test "n_object_with_single_string" {
1287 err(
1287 try err(
12881288 \\{ "foo" : "bar", "a" }
12891289 );
12901290}
12911291
12921292test "n_object_with_trailing_garbage" {
1293 err(
1293 try err(
12941294 \\{"a":"b"}#
12951295 );
12961296}
12971297
12981298test "n_single_space" {
1299 err(" ");
1299 try err(" ");
13001300}
13011301
13021302test "n_string_1_surrogate_then_escape" {
1303 err(
1303 try err(
13041304 \\["\uD800\"]
13051305 );
13061306}
13071307
13081308test "n_string_1_surrogate_then_escape_u1" {
1309 err(
1309 try err(
13101310 \\["\uD800\u1"]
13111311 );
13121312}
13131313
13141314test "n_string_1_surrogate_then_escape_u1x" {
1315 err(
1315 try err(
13161316 \\["\uD800\u1x"]
13171317 );
13181318}
13191319
13201320test "n_string_1_surrogate_then_escape_u" {
1321 err(
1321 try err(
13221322 \\["\uD800\u"]
13231323 );
13241324}
13251325
13261326test "n_string_accentuated_char_no_quotes" {
1327 err(
1327 try err(
13281328 \\[é]
13291329 );
13301330}
13311331
13321332test "n_string_backslash_00" {
1333 err("[\"\x00\"]");
1333 try err("[\"\x00\"]");
13341334}
13351335
13361336test "n_string_escaped_backslash_bad" {
1337 err(
1337 try err(
13381338 \\["\\\"]
13391339 );
13401340}
13411341
13421342test "n_string_escaped_ctrl_char_tab" {
1343 err("\x5b\x22\x5c\x09\x22\x5d");
1343 try err("\x5b\x22\x5c\x09\x22\x5d");
13441344}
13451345
13461346test "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\"]");
13481348}
13491349
13501350test "n_string_escape_x" {
1351 err(
1351 try err(
13521352 \\["\x00"]
13531353 );
13541354}
13551355
13561356test "n_string_incomplete_escaped_character" {
1357 err(
1357 try err(
13581358 \\["\u00A"]
13591359 );
13601360}
13611361
13621362test "n_string_incomplete_escape" {
1363 err(
1363 try err(
13641364 \\["\"]
13651365 );
13661366}
13671367
13681368test "n_string_incomplete_surrogate_escape_invalid" {
1369 err(
1369 try err(
13701370 \\["\uD800\uD800\x"]
13711371 );
13721372}
13731373
13741374test "n_string_incomplete_surrogate" {
1375 err(
1375 try err(
13761376 \\["\uD834\uDd"]
13771377 );
13781378}
13791379
13801380test "n_string_invalid_backslash_esc" {
1381 err(
1381 try err(
13821382 \\["\a"]
13831383 );
13841384}
13851385
13861386test "n_string_invalid_unicode_escape" {
1387 err(
1387 try err(
13881388 \\["\uqqqq"]
13891389 );
13901390}
13911391
13921392test "n_string_invalid_utf8_after_escape" {
1393 err("[\"\\\x75\xc3\xa5\"]");
1393 try err("[\"\\\x75\xc3\xa5\"]");
13941394}
13951395
13961396test "n_string_invalid-utf-8-in-escape" {
1397 err(
1397 try err(
13981398 \\["\uå"]
13991399 );
14001400}
14011401
14021402test "n_string_leading_uescaped_thinspace" {
1403 err(
1403 try err(
14041404 \\[\u0020"asd"]
14051405 );
14061406}
14071407
14081408test "n_string_no_quotes_with_bad_escape" {
1409 err(
1409 try err(
14101410 \\[\n]
14111411 );
14121412}
14131413
14141414test "n_string_single_doublequote" {
1415 err(
1415 try err(
14161416 \\"
14171417 );
14181418}
14191419
14201420test "n_string_single_quote" {
1421 err(
1421 try err(
14221422 \\['single quote']
14231423 );
14241424}
14251425
14261426test "n_string_single_string_no_double_quotes" {
1427 err(
1427 try err(
14281428 \\abc
14291429 );
14301430}
14311431
14321432test "n_string_start_escape_unclosed" {
1433 err(
1433 try err(
14341434 \\["\
14351435 );
14361436}
14371437
14381438test "n_string_unescaped_crtl_char" {
1439 err("[\"a\x00a\"]");
1439 try err("[\"a\x00a\"]");
14401440}
14411441
14421442test "n_string_unescaped_newline" {
1443 err(
1443 try err(
14441444 \\["new
14451445 \\line"]
14461446 );
14471447}
14481448
14491449test "n_string_unescaped_tab" {
1450 err("[\"\t\"]");
1450 try err("[\"\t\"]");
14511451}
14521452
14531453test "n_string_unicode_CapitalU" {
1454 err(
1454 try err(
14551455 \\"\UA66D"
14561456 );
14571457}
14581458
14591459test "n_string_with_trailing_garbage" {
1460 err(
1460 try err(
14611461 \\""x
14621462 );
14631463}
14641464
14651465test "n_structure_100000_opening_arrays" {
1466 err("[" ** 100000);
1466 try err("[" ** 100000);
14671467}
14681468
14691469test "n_structure_angle_bracket_." {
1470 err(
1470 try err(
14711471 \\<.>
14721472 );
14731473}
14741474
14751475test "n_structure_angle_bracket_null" {
1476 err(
1476 try err(
14771477 \\[<null>]
14781478 );
14791479}
14801480
14811481test "n_structure_array_trailing_garbage" {
1482 err(
1482 try err(
14831483 \\[1]x
14841484 );
14851485}
14861486
14871487test "n_structure_array_with_extra_array_close" {
1488 err(
1488 try err(
14891489 \\[1]]
14901490 );
14911491}
14921492
14931493test "n_structure_array_with_unclosed_string" {
1494 err(
1494 try err(
14951495 \\["asd]
14961496 );
14971497}
14981498
14991499test "n_structure_ascii-unicode-identifier" {
1500 err(
1500 try err(
15011501 \\aå
15021502 );
15031503}
15041504
15051505test "n_structure_capitalized_True" {
1506 err(
1506 try err(
15071507 \\[True]
15081508 );
15091509}
15101510
15111511test "n_structure_close_unopened_array" {
1512 err(
1512 try err(
15131513 \\1]
15141514 );
15151515}
15161516
15171517test "n_structure_comma_instead_of_closing_brace" {
1518 err(
1518 try err(
15191519 \\{"x": true,
15201520 );
15211521}
15221522
15231523test "n_structure_double_array" {
1524 err(
1524 try err(
15251525 \\[][]
15261526 );
15271527}
15281528
15291529test "n_structure_end_array" {
1530 err(
1530 try err(
15311531 \\]
15321532 );
15331533}
15341534
15351535test "n_structure_incomplete_UTF8_BOM" {
1536 err(
1536 try err(
15371537 \\ï»{}
15381538 );
15391539}
15401540
15411541test "n_structure_lone-invalid-utf-8" {
1542 err(
1542 try err(
15431543 \\å
15441544 );
15451545}
15461546
15471547test "n_structure_lone-open-bracket" {
1548 err(
1548 try err(
15491549 \\[
15501550 );
15511551}
15521552
15531553test "n_structure_no_data" {
1554 err(
1554 try err(
15551555 \\
15561556 );
15571557}
15581558
15591559test "n_structure_null-byte-outside-string" {
1560 err("[\x00]");
1560 try err("[\x00]");
15611561}
15621562
15631563test "n_structure_number_with_trailing_garbage" {
1564 err(
1564 try err(
15651565 \\2@
15661566 );
15671567}
15681568
15691569test "n_structure_object_followed_by_closing_object" {
1570 err(
1570 try err(
15711571 \\{}}
15721572 );
15731573}
15741574
15751575test "n_structure_object_unclosed_no_value" {
1576 err(
1576 try err(
15771577 \\{"":
15781578 );
15791579}
15801580
15811581test "n_structure_object_with_comment" {
1582 err(
1582 try err(
15831583 \\{"a":/*comment*/"b"}
15841584 );
15851585}
15861586
15871587test "n_structure_object_with_trailing_garbage" {
1588 err(
1588 try err(
15891589 \\{"a": true} "x"
15901590 );
15911591}
15921592
15931593test "n_structure_open_array_apostrophe" {
1594 err(
1594 try err(
15951595 \\['
15961596 );
15971597}
15981598
15991599test "n_structure_open_array_comma" {
1600 err(
1600 try err(
16011601 \\[,
16021602 );
16031603}
16041604
16051605test "n_structure_open_array_object" {
1606 err("[{\"\":" ** 50000);
1606 try err("[{\"\":" ** 50000);
16071607}
16081608
16091609test "n_structure_open_array_open_object" {
1610 err(
1610 try err(
16111611 \\[{
16121612 );
16131613}
16141614
16151615test "n_structure_open_array_open_string" {
1616 err(
1616 try err(
16171617 \\["a
16181618 );
16191619}
16201620
16211621test "n_structure_open_array_string" {
1622 err(
1622 try err(
16231623 \\["a"
16241624 );
16251625}
16261626
16271627test "n_structure_open_object_close_array" {
1628 err(
1628 try err(
16291629 \\{]
16301630 );
16311631}
16321632
16331633test "n_structure_open_object_comma" {
1634 err(
1634 try err(
16351635 \\{,
16361636 );
16371637}
16381638
16391639test "n_structure_open_object" {
1640 err(
1640 try err(
16411641 \\{
16421642 );
16431643}
16441644
16451645test "n_structure_open_object_open_array" {
1646 err(
1646 try err(
16471647 \\{[
16481648 );
16491649}
16501650
16511651test "n_structure_open_object_open_string" {
1652 err(
1652 try err(
16531653 \\{"a
16541654 );
16551655}
16561656
16571657test "n_structure_open_object_string_with_apostrophes" {
1658 err(
1658 try err(
16591659 \\{'a'
16601660 );
16611661}
16621662
16631663test "n_structure_open_open" {
1664 err(
1664 try err(
16651665 \\["\{["\{["\{["\{
16661666 );
16671667}
16681668
16691669test "n_structure_single_eacute" {
1670 err(
1670 try err(
16711671 \\é
16721672 );
16731673}
16741674
16751675test "n_structure_single_star" {
1676 err(
1676 try err(
16771677 \\*
16781678 );
16791679}
16801680
16811681test "n_structure_trailing_#" {
1682 err(
1682 try err(
16831683 \\{"a":"b"}#{}
16841684 );
16851685}
16861686
16871687test "n_structure_U+2060_word_joined" {
1688 err(
1688 try err(
16891689 \\[⁠]
16901690 );
16911691}
16921692
16931693test "n_structure_uescaped_LF_before_string" {
1694 err(
1694 try err(
16951695 \\[\u000A""]
16961696 );
16971697}
16981698
16991699test "n_structure_unclosed_array" {
1700 err(
1700 try err(
17011701 \\[1
17021702 );
17031703}
17041704
17051705test "n_structure_unclosed_array_partial_null" {
1706 err(
1706 try err(
17071707 \\[ false, nul
17081708 );
17091709}
17101710
17111711test "n_structure_unclosed_array_unfinished_false" {
1712 err(
1712 try err(
17131713 \\[ true, fals
17141714 );
17151715}
17161716
17171717test "n_structure_unclosed_array_unfinished_true" {
1718 err(
1718 try err(
17191719 \\[ false, tru
17201720 );
17211721}
17221722
17231723test "n_structure_unclosed_object" {
1724 err(
1724 try err(
17251725 \\{"asd":"asd"
17261726 );
17271727}
17281728
17291729test "n_structure_unicode-identifier" {
1730 err(
1730 try err(
17311731 \\Ã¥
17321732 );
17331733}
17341734
17351735test "n_structure_UTF8_BOM_no_data" {
1736 err(
1736 try err(
17371737 \\
17381738 );
17391739}
17401740
17411741test "n_structure_whitespace_formfeed" {
1742 err("[\x0c]");
1742 try err("[\x0c]");
17431743}
17441744
17451745test "n_structure_whitespace_U+2060_word_joiner" {
1746 err(
1746 try err(
17471747 \\[⁠]
17481748 );
17491749}
......@@ -1751,255 +1751,255 @@ test "n_structure_whitespace_U+2060_word_joiner" {
17511751////////////////////////////////////////////////////////////////////////////////////////////////////
17521752
17531753test "i_number_double_huge_neg_exp" {
1754 any(
1754 try any(
17551755 \\[123.456e-789]
17561756 );
17571757}
17581758
17591759test "i_number_huge_exp" {
1760 any(
1760 try any(
17611761 \\[0.4e00669999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999969999999006]
17621762 );
17631763}
17641764
17651765test "i_number_neg_int_huge_exp" {
1766 any(
1766 try any(
17671767 \\[-1e+9999]
17681768 );
17691769}
17701770
17711771test "i_number_pos_double_huge_exp" {
1772 any(
1772 try any(
17731773 \\[1.5e+9999]
17741774 );
17751775}
17761776
17771777test "i_number_real_neg_overflow" {
1778 any(
1778 try any(
17791779 \\[-123123e100000]
17801780 );
17811781}
17821782
17831783test "i_number_real_pos_overflow" {
1784 any(
1784 try any(
17851785 \\[123123e100000]
17861786 );
17871787}
17881788
17891789test "i_number_real_underflow" {
1790 any(
1790 try any(
17911791 \\[123e-10000000]
17921792 );
17931793}
17941794
17951795test "i_number_too_big_neg_int" {
1796 any(
1796 try any(
17971797 \\[-123123123123123123123123123123]
17981798 );
17991799}
18001800
18011801test "i_number_too_big_pos_int" {
1802 any(
1802 try any(
18031803 \\[100000000000000000000]
18041804 );
18051805}
18061806
18071807test "i_number_very_big_negative_int" {
1808 any(
1808 try any(
18091809 \\[-237462374673276894279832749832423479823246327846]
18101810 );
18111811}
18121812
18131813test "i_object_key_lone_2nd_surrogate" {
1814 anyStreamingErrNonStreaming(
1814 try anyStreamingErrNonStreaming(
18151815 \\{"\uDFAA":0}
18161816 );
18171817}
18181818
18191819test "i_string_1st_surrogate_but_2nd_missing" {
1820 anyStreamingErrNonStreaming(
1820 try anyStreamingErrNonStreaming(
18211821 \\["\uDADA"]
18221822 );
18231823}
18241824
18251825test "i_string_1st_valid_surrogate_2nd_invalid" {
1826 anyStreamingErrNonStreaming(
1826 try anyStreamingErrNonStreaming(
18271827 \\["\uD888\u1234"]
18281828 );
18291829}
18301830
18311831test "i_string_incomplete_surrogate_and_escape_valid" {
1832 anyStreamingErrNonStreaming(
1832 try anyStreamingErrNonStreaming(
18331833 \\["\uD800\n"]
18341834 );
18351835}
18361836
18371837test "i_string_incomplete_surrogate_pair" {
1838 anyStreamingErrNonStreaming(
1838 try anyStreamingErrNonStreaming(
18391839 \\["\uDd1ea"]
18401840 );
18411841}
18421842
18431843test "i_string_incomplete_surrogates_escape_valid" {
1844 anyStreamingErrNonStreaming(
1844 try anyStreamingErrNonStreaming(
18451845 \\["\uD800\uD800\n"]
18461846 );
18471847}
18481848
18491849test "i_string_invalid_lonely_surrogate" {
1850 anyStreamingErrNonStreaming(
1850 try anyStreamingErrNonStreaming(
18511851 \\["\ud800"]
18521852 );
18531853}
18541854
18551855test "i_string_invalid_surrogate" {
1856 anyStreamingErrNonStreaming(
1856 try anyStreamingErrNonStreaming(
18571857 \\["\ud800abc"]
18581858 );
18591859}
18601860
18611861test "i_string_invalid_utf-8" {
1862 any(
1862 try any(
18631863 \\["ÿ"]
18641864 );
18651865}
18661866
18671867test "i_string_inverted_surrogates_U+1D11E" {
1868 anyStreamingErrNonStreaming(
1868 try anyStreamingErrNonStreaming(
18691869 \\["\uDd1e\uD834"]
18701870 );
18711871}
18721872
18731873test "i_string_iso_latin_1" {
1874 any(
1874 try any(
18751875 \\["é"]
18761876 );
18771877}
18781878
18791879test "i_string_lone_second_surrogate" {
1880 anyStreamingErrNonStreaming(
1880 try anyStreamingErrNonStreaming(
18811881 \\["\uDFAA"]
18821882 );
18831883}
18841884
18851885test "i_string_lone_utf8_continuation_byte" {
1886 any(
1886 try any(
18871887 \\[""]
18881888 );
18891889}
18901890
18911891test "i_string_not_in_unicode_range" {
1892 any(
1892 try any(
18931893 \\["ô¿¿¿"]
18941894 );
18951895}
18961896
18971897test "i_string_overlong_sequence_2_bytes" {
1898 any(
1898 try any(
18991899 \\["À¯"]
19001900 );
19011901}
19021902
19031903test "i_string_overlong_sequence_6_bytes" {
1904 any(
1904 try any(
19051905 \\["üƒ¿¿¿¿"]
19061906 );
19071907}
19081908
19091909test "i_string_overlong_sequence_6_bytes_null" {
1910 any(
1910 try any(
19111911 \\["ü€€€€€"]
19121912 );
19131913}
19141914
19151915test "i_string_truncated-utf-8" {
1916 any(
1916 try any(
19171917 \\["àÿ"]
19181918 );
19191919}
19201920
19211921test "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");
19231923}
19241924
19251925test "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");
19271927}
19281928
19291929test "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");
19311931}
19321932
19331933test "i_string_UTF-8_invalid_sequence" {
1934 any(
1934 try any(
19351935 \\["日шú"]
19361936 );
19371937}
19381938
19391939test "i_string_UTF8_surrogate_U+D800" {
1940 any(
1940 try any(
19411941 \\["í €"]
19421942 );
19431943}
19441944
19451945test "i_structure_500_nested_arrays" {
1946 any(("[" ** 500) ++ ("]" ** 500));
1946 try any(("[" ** 500) ++ ("]" ** 500));
19471947}
19481948
19491949test "i_structure_UTF-8_BOM_empty_object" {
1950 any(
1950 try any(
19511951 \\{}
19521952 );
19531953}
19541954
19551955test "truncated UTF-8 sequence" {
1956 utf8Error("\"\xc2\"");
1957 utf8Error("\"\xdf\"");
1958 utf8Error("\"\xed\xa0\"");
1959 utf8Error("\"\xf0\x80\"");
1960 utf8Error("\"\xf0\x80\x80\"");
1956 try utf8Error("\"\xc2\"");
1957 try utf8Error("\"\xdf\"");
1958 try utf8Error("\"\xed\xa0\"");
1959 try utf8Error("\"\xf0\x80\"");
1960 try utf8Error("\"\xf0\x80\x80\"");
19611961}
19621962
19631963test "invalid continuation byte" {
1964 utf8Error("\"\xc2\x00\"");
1965 utf8Error("\"\xc2\x7f\"");
1966 utf8Error("\"\xc2\xc0\"");
1967 utf8Error("\"\xc3\xc1\"");
1968 utf8Error("\"\xc4\xf5\"");
1969 utf8Error("\"\xc5\xff\"");
1970 utf8Error("\"\xe4\x80\x00\"");
1971 utf8Error("\"\xe5\x80\x10\"");
1972 utf8Error("\"\xe6\x80\xc0\"");
1973 utf8Error("\"\xe7\x80\xf5\"");
1974 utf8Error("\"\xe8\x00\x80\"");
1975 utf8Error("\"\xf2\x00\x80\x80\"");
1976 utf8Error("\"\xf0\x80\x00\x80\"");
1977 utf8Error("\"\xf1\x80\xc0\x80\"");
1978 utf8Error("\"\xf2\x80\x80\x00\"");
1979 utf8Error("\"\xf3\x80\x80\xc0\"");
1980 utf8Error("\"\xf4\x80\x80\xf5\"");
1964 try utf8Error("\"\xc2\x00\"");
1965 try utf8Error("\"\xc2\x7f\"");
1966 try utf8Error("\"\xc2\xc0\"");
1967 try utf8Error("\"\xc3\xc1\"");
1968 try utf8Error("\"\xc4\xf5\"");
1969 try utf8Error("\"\xc5\xff\"");
1970 try utf8Error("\"\xe4\x80\x00\"");
1971 try utf8Error("\"\xe5\x80\x10\"");
1972 try utf8Error("\"\xe6\x80\xc0\"");
1973 try utf8Error("\"\xe7\x80\xf5\"");
1974 try utf8Error("\"\xe8\x00\x80\"");
1975 try utf8Error("\"\xf2\x00\x80\x80\"");
1976 try utf8Error("\"\xf0\x80\x00\x80\"");
1977 try utf8Error("\"\xf1\x80\xc0\x80\"");
1978 try utf8Error("\"\xf2\x80\x80\x00\"");
1979 try utf8Error("\"\xf3\x80\x80\xc0\"");
1980 try utf8Error("\"\xf4\x80\x80\xf5\"");
19811981}
19821982
19831983test "disallowed overlong form" {
1984 utf8Error("\"\xc0\x80\"");
1985 utf8Error("\"\xc0\x90\"");
1986 utf8Error("\"\xc1\x80\"");
1987 utf8Error("\"\xc1\x90\"");
1988 utf8Error("\"\xe0\x80\x80\"");
1989 utf8Error("\"\xf0\x80\x80\x80\"");
1984 try utf8Error("\"\xc0\x80\"");
1985 try utf8Error("\"\xc0\x90\"");
1986 try utf8Error("\"\xc1\x80\"");
1987 try utf8Error("\"\xc1\x90\"");
1988 try utf8Error("\"\xe0\x80\x80\"");
1989 try utf8Error("\"\xf0\x80\x80\x80\"");
19901990}
19911991
19921992test "out of UTF-16 range" {
1993 utf8Error("\"\xf4\x90\x80\x80\"");
1994 utf8Error("\"\xf5\x80\x80\x80\"");
1995 utf8Error("\"\xf6\x80\x80\x80\"");
1996 utf8Error("\"\xf7\x80\x80\x80\"");
1997 utf8Error("\"\xf8\x80\x80\x80\"");
1998 utf8Error("\"\xf9\x80\x80\x80\"");
1999 utf8Error("\"\xfa\x80\x80\x80\"");
2000 utf8Error("\"\xfb\x80\x80\x80\"");
2001 utf8Error("\"\xfc\x80\x80\x80\"");
2002 utf8Error("\"\xfd\x80\x80\x80\"");
2003 utf8Error("\"\xfe\x80\x80\x80\"");
2004 utf8Error("\"\xff\x80\x80\x80\"");
1993 try utf8Error("\"\xf4\x90\x80\x80\"");
1994 try utf8Error("\"\xf5\x80\x80\x80\"");
1995 try utf8Error("\"\xf6\x80\x80\x80\"");
1996 try utf8Error("\"\xf7\x80\x80\x80\"");
1997 try utf8Error("\"\xf8\x80\x80\x80\"");
1998 try utf8Error("\"\xf9\x80\x80\x80\"");
1999 try utf8Error("\"\xfa\x80\x80\x80\"");
2000 try utf8Error("\"\xfb\x80\x80\x80\"");
2001 try utf8Error("\"\xfc\x80\x80\x80\"");
2002 try utf8Error("\"\xfd\x80\x80\x80\"");
2003 try utf8Error("\"\xfe\x80\x80\x80\"");
2004 try utf8Error("\"\xff\x80\x80\x80\"");
20052005}
lib/std/json/write_stream.zig+1-1
......@@ -288,7 +288,7 @@ test "json write stream" {
288288 \\ "float": 3.5e+00
289289 \\}
290290 ;
291 std.testing.expect(std.mem.eql(u8, expected, result));
291 try std.testing.expect(std.mem.eql(u8, expected, result));
292292}
293293
294294fn getJsonObject(allocator: *std.mem.Allocator) !std.json.Value {
lib/std/leb128.zig+68-68
......@@ -152,22 +152,22 @@ test "writeUnsignedFixed" {
152152 {
153153 var buf: [4]u8 = undefined;
154154 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);
156156 }
157157 {
158158 var buf: [4]u8 = undefined;
159159 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);
161161 }
162162 {
163163 var buf: [4]u8 = undefined;
164164 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);
166166 }
167167 {
168168 var buf: [4]u8 = undefined;
169169 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);
171171 }
172172}
173173
......@@ -212,44 +212,44 @@ fn test_read_uleb128_seq(comptime T: type, comptime N: usize, encoded: []const u
212212
213213test "deserialize signed LEB128" {
214214 // 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
217217 // Overflow
218 testing.expectError(error.Overflow, test_read_ileb128(i8, "\x80\x80\x40"));
219 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"));
221 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"));
218 try testing.expectError(error.Overflow, test_read_ileb128(i8, "\x80\x80\x40"));
219 try testing.expectError(error.Overflow, test_read_ileb128(i16, "\x80\x80\x80\x40"));
220 try testing.expectError(error.Overflow, test_read_ileb128(i32, "\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 try testing.expectError(error.Overflow, test_read_ileb128(i8, "\xff\x7e"));
223223
224224 // Decode SLEB128
225 testing.expect((try test_read_ileb128(i64, "\x00")) == 0);
226 testing.expect((try test_read_ileb128(i64, "\x01")) == 1);
227 testing.expect((try test_read_ileb128(i64, "\x3f")) == 63);
228 testing.expect((try test_read_ileb128(i64, "\x40")) == -64);
229 testing.expect((try test_read_ileb128(i64, "\x41")) == -63);
230 testing.expect((try test_read_ileb128(i64, "\x7f")) == -1);
231 testing.expect((try test_read_ileb128(i64, "\x80\x01")) == 128);
232 testing.expect((try test_read_ileb128(i64, "\x81\x01")) == 129);
233 testing.expect((try test_read_ileb128(i64, "\xff\x7e")) == -129);
234 testing.expect((try test_read_ileb128(i64, "\x80\x7f")) == -128);
235 testing.expect((try test_read_ileb128(i64, "\x81\x7f")) == -127);
236 testing.expect((try test_read_ileb128(i64, "\xc0\x00")) == 64);
237 testing.expect((try test_read_ileb128(i64, "\xc7\x9f\x7f")) == -12345);
238 testing.expect((try test_read_ileb128(i8, "\xff\x7f")) == -1);
239 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);
241 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)));
243 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);
225 try testing.expect((try test_read_ileb128(i64, "\x00")) == 0);
226 try testing.expect((try test_read_ileb128(i64, "\x01")) == 1);
227 try testing.expect((try test_read_ileb128(i64, "\x3f")) == 63);
228 try testing.expect((try test_read_ileb128(i64, "\x40")) == -64);
229 try testing.expect((try test_read_ileb128(i64, "\x41")) == -63);
230 try testing.expect((try test_read_ileb128(i64, "\x7f")) == -1);
231 try testing.expect((try test_read_ileb128(i64, "\x80\x01")) == 128);
232 try testing.expect((try test_read_ileb128(i64, "\x81\x01")) == 129);
233 try testing.expect((try test_read_ileb128(i64, "\xff\x7e")) == -129);
234 try testing.expect((try test_read_ileb128(i64, "\x80\x7f")) == -128);
235 try testing.expect((try test_read_ileb128(i64, "\x81\x7f")) == -127);
236 try testing.expect((try test_read_ileb128(i64, "\xc0\x00")) == 64);
237 try testing.expect((try test_read_ileb128(i64, "\xc7\x9f\x7f")) == -12345);
238 try testing.expect((try test_read_ileb128(i8, "\xff\x7f")) == -1);
239 try testing.expect((try test_read_ileb128(i16, "\xff\xff\x7f")) == -1);
240 try testing.expect((try test_read_ileb128(i32, "\xff\xff\xff\xff\x7f")) == -1);
241 try testing.expect((try test_read_ileb128(i32, "\x80\x80\x80\x80\x08")) == -0x80000000);
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 try testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x40")) == -0x4000000000000000);
244 try testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x7f")) == -0x8000000000000000);
245245
246246 // Decode unnormalized SLEB128 with extra padding bytes.
247 testing.expect((try test_read_ileb128(i64, "\x80\x00")) == 0);
248 testing.expect((try test_read_ileb128(i64, "\x80\x80\x00")) == 0);
249 testing.expect((try test_read_ileb128(i64, "\xff\x00")) == 0x7f);
250 testing.expect((try test_read_ileb128(i64, "\xff\x80\x00")) == 0x7f);
251 testing.expect((try test_read_ileb128(i64, "\x80\x81\x00")) == 0x80);
252 testing.expect((try test_read_ileb128(i64, "\x80\x81\x80\x00")) == 0x80);
247 try testing.expect((try test_read_ileb128(i64, "\x80\x00")) == 0);
248 try testing.expect((try test_read_ileb128(i64, "\x80\x80\x00")) == 0);
249 try testing.expect((try test_read_ileb128(i64, "\xff\x00")) == 0x7f);
250 try testing.expect((try test_read_ileb128(i64, "\xff\x80\x00")) == 0x7f);
251 try testing.expect((try test_read_ileb128(i64, "\x80\x81\x00")) == 0x80);
252 try testing.expect((try test_read_ileb128(i64, "\x80\x81\x80\x00")) == 0x80);
253253
254254 // Decode sequence of SLEB128 values
255255 try test_read_ileb128_seq(i64, 4, "\x81\x01\x3f\x80\x7f\x80\x80\x80\x00");
......@@ -257,39 +257,39 @@ test "deserialize signed LEB128" {
257257
258258test "deserialize unsigned LEB128" {
259259 // 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
262262 // Overflow
263 testing.expectError(error.Overflow, test_read_uleb128(u8, "\x80\x02"));
264 testing.expectError(error.Overflow, test_read_uleb128(u8, "\x80\x80\x40"));
265 testing.expectError(error.Overflow, test_read_uleb128(u16, "\x80\x80\x84"));
266 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"));
268 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"));
263 try testing.expectError(error.Overflow, test_read_uleb128(u8, "\x80\x02"));
264 try testing.expectError(error.Overflow, test_read_uleb128(u8, "\x80\x80\x40"));
265 try testing.expectError(error.Overflow, test_read_uleb128(u16, "\x80\x80\x84"));
266 try testing.expectError(error.Overflow, test_read_uleb128(u16, "\x80\x80\x80\x40"));
267 try testing.expectError(error.Overflow, test_read_uleb128(u32, "\x80\x80\x80\x80\x90"));
268 try testing.expectError(error.Overflow, test_read_uleb128(u32, "\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
271271 // Decode ULEB128
272 testing.expect((try test_read_uleb128(u64, "\x00")) == 0);
273 testing.expect((try test_read_uleb128(u64, "\x01")) == 1);
274 testing.expect((try test_read_uleb128(u64, "\x3f")) == 63);
275 testing.expect((try test_read_uleb128(u64, "\x40")) == 64);
276 testing.expect((try test_read_uleb128(u64, "\x7f")) == 0x7f);
277 testing.expect((try test_read_uleb128(u64, "\x80\x01")) == 0x80);
278 testing.expect((try test_read_uleb128(u64, "\x81\x01")) == 0x81);
279 testing.expect((try test_read_uleb128(u64, "\x90\x01")) == 0x90);
280 testing.expect((try test_read_uleb128(u64, "\xff\x01")) == 0xff);
281 testing.expect((try test_read_uleb128(u64, "\x80\x02")) == 0x100);
282 testing.expect((try test_read_uleb128(u64, "\x81\x02")) == 0x101);
283 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);
272 try testing.expect((try test_read_uleb128(u64, "\x00")) == 0);
273 try testing.expect((try test_read_uleb128(u64, "\x01")) == 1);
274 try testing.expect((try test_read_uleb128(u64, "\x3f")) == 63);
275 try testing.expect((try test_read_uleb128(u64, "\x40")) == 64);
276 try testing.expect((try test_read_uleb128(u64, "\x7f")) == 0x7f);
277 try testing.expect((try test_read_uleb128(u64, "\x80\x01")) == 0x80);
278 try testing.expect((try test_read_uleb128(u64, "\x81\x01")) == 0x81);
279 try testing.expect((try test_read_uleb128(u64, "\x90\x01")) == 0x90);
280 try testing.expect((try test_read_uleb128(u64, "\xff\x01")) == 0xff);
281 try testing.expect((try test_read_uleb128(u64, "\x80\x02")) == 0x100);
282 try testing.expect((try test_read_uleb128(u64, "\x81\x02")) == 0x101);
283 try testing.expect((try test_read_uleb128(u64, "\x80\xc1\x80\x80\x10")) == 4294975616);
284 try testing.expect((try test_read_uleb128(u64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01")) == 0x8000000000000000);
285285
286286 // Decode ULEB128 with extra padding bytes
287 testing.expect((try test_read_uleb128(u64, "\x80\x00")) == 0);
288 testing.expect((try test_read_uleb128(u64, "\x80\x80\x00")) == 0);
289 testing.expect((try test_read_uleb128(u64, "\xff\x00")) == 0x7f);
290 testing.expect((try test_read_uleb128(u64, "\xff\x80\x00")) == 0x7f);
291 testing.expect((try test_read_uleb128(u64, "\x80\x81\x00")) == 0x80);
292 testing.expect((try test_read_uleb128(u64, "\x80\x81\x80\x00")) == 0x80);
287 try testing.expect((try test_read_uleb128(u64, "\x80\x00")) == 0);
288 try testing.expect((try test_read_uleb128(u64, "\x80\x80\x00")) == 0);
289 try testing.expect((try test_read_uleb128(u64, "\xff\x00")) == 0x7f);
290 try testing.expect((try test_read_uleb128(u64, "\xff\x80\x00")) == 0x7f);
291 try testing.expect((try test_read_uleb128(u64, "\x80\x81\x00")) == 0x80);
292 try testing.expect((try test_read_uleb128(u64, "\x80\x81\x80\x00")) == 0x80);
293293
294294 // Decode sequence of ULEB128 values
295295 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 {
326326 // stream write
327327 try writeStream(fbs.writer(), value);
328328 const w1_pos = fbs.pos;
329 testing.expect(w1_pos == bytes_needed);
329 try testing.expect(w1_pos == bytes_needed);
330330
331331 // stream read
332332 fbs.pos = 0;
333333 const sr = try readStream(T, fbs.reader());
334 testing.expect(fbs.pos == w1_pos);
335 testing.expect(sr == value);
334 try testing.expect(fbs.pos == w1_pos);
335 try testing.expect(sr == value);
336336
337337 // bigger type stream read
338338 fbs.pos = 0;
339339 const bsr = try readStream(B, fbs.reader());
340 testing.expect(fbs.pos == w1_pos);
341 testing.expect(bsr == value);
340 try testing.expect(fbs.pos == w1_pos);
341 try testing.expect(bsr == value);
342342}
343343
344344test "serialize unsigned LEB128" {
lib/std/linked_list.zig+20-20
......@@ -123,7 +123,7 @@ test "basic SinglyLinkedList test" {
123123 const L = SinglyLinkedList(u32);
124124 var list = L{};
125125
126 testing.expect(list.len() == 0);
126 try testing.expect(list.len() == 0);
127127
128128 var one = L.Node{ .data = 1 };
129129 var two = L.Node{ .data = 2 };
......@@ -137,14 +137,14 @@ test "basic SinglyLinkedList test" {
137137 two.insertAfter(&three); // {1, 2, 3, 5}
138138 three.insertAfter(&four); // {1, 2, 3, 4, 5}
139139
140 testing.expect(list.len() == 5);
140 try testing.expect(list.len() == 5);
141141
142142 // Traverse forwards.
143143 {
144144 var it = list.first;
145145 var index: u32 = 1;
146146 while (it) |node| : (it = node.next) {
147 testing.expect(node.data == index);
147 try testing.expect(node.data == index);
148148 index += 1;
149149 }
150150 }
......@@ -153,9 +153,9 @@ test "basic SinglyLinkedList test" {
153153 _ = list.remove(&five); // {2, 3, 4}
154154 _ = two.removeNext(); // {2, 4}
155155
156 testing.expect(list.first.?.data == 2);
157 testing.expect(list.first.?.next.?.data == 4);
158 testing.expect(list.first.?.next.?.next == null);
156 try testing.expect(list.first.?.data == 2);
157 try testing.expect(list.first.?.next.?.data == 4);
158 try testing.expect(list.first.?.next.?.next == null);
159159}
160160
161161/// A tail queue is headed by a pair of pointers, one to the head of the
......@@ -344,7 +344,7 @@ test "basic TailQueue test" {
344344 var it = list.first;
345345 var index: u32 = 1;
346346 while (it) |node| : (it = node.next) {
347 testing.expect(node.data == index);
347 try testing.expect(node.data == index);
348348 index += 1;
349349 }
350350 }
......@@ -354,7 +354,7 @@ test "basic TailQueue test" {
354354 var it = list.last;
355355 var index: u32 = 1;
356356 while (it) |node| : (it = node.prev) {
357 testing.expect(node.data == (6 - index));
357 try testing.expect(node.data == (6 - index));
358358 index += 1;
359359 }
360360 }
......@@ -363,9 +363,9 @@ test "basic TailQueue test" {
363363 var last = list.pop(); // {2, 3, 4}
364364 list.remove(&three); // {2, 4}
365365
366 testing.expect(list.first.?.data == 2);
367 testing.expect(list.last.?.data == 4);
368 testing.expect(list.len == 2);
366 try testing.expect(list.first.?.data == 2);
367 try testing.expect(list.last.?.data == 4);
368 try testing.expect(list.len == 2);
369369}
370370
371371test "TailQueue concatenation" {
......@@ -387,18 +387,18 @@ test "TailQueue concatenation" {
387387
388388 list1.concatByMoving(&list2);
389389
390 testing.expect(list1.last == &five);
391 testing.expect(list1.len == 5);
392 testing.expect(list2.first == null);
393 testing.expect(list2.last == null);
394 testing.expect(list2.len == 0);
390 try testing.expect(list1.last == &five);
391 try testing.expect(list1.len == 5);
392 try testing.expect(list2.first == null);
393 try testing.expect(list2.last == null);
394 try testing.expect(list2.len == 0);
395395
396396 // Traverse forwards.
397397 {
398398 var it = list1.first;
399399 var index: u32 = 1;
400400 while (it) |node| : (it = node.next) {
401 testing.expect(node.data == index);
401 try testing.expect(node.data == index);
402402 index += 1;
403403 }
404404 }
......@@ -408,7 +408,7 @@ test "TailQueue concatenation" {
408408 var it = list1.last;
409409 var index: u32 = 1;
410410 while (it) |node| : (it = node.prev) {
411 testing.expect(node.data == (6 - index));
411 try testing.expect(node.data == (6 - index));
412412 index += 1;
413413 }
414414 }
......@@ -421,7 +421,7 @@ test "TailQueue concatenation" {
421421 var it = list2.first;
422422 var index: u32 = 1;
423423 while (it) |node| : (it = node.next) {
424 testing.expect(node.data == index);
424 try testing.expect(node.data == index);
425425 index += 1;
426426 }
427427 }
......@@ -431,7 +431,7 @@ test "TailQueue concatenation" {
431431 var it = list2.last;
432432 var index: u32 = 1;
433433 while (it) |node| : (it = node.prev) {
434 testing.expect(node.data == (6 - index));
434 try testing.expect(node.data == (6 - index));
435435 index += 1;
436436 }
437437 }
lib/std/math.zig+353-353
......@@ -177,20 +177,20 @@ test "approxEqAbs and approxEqRel" {
177177 else => unreachable,
178178 };
179179
180 testing.expect(approxEqAbs(T, 0.0, 0.0, eps_value));
181 testing.expect(approxEqAbs(T, -0.0, -0.0, eps_value));
182 testing.expect(approxEqAbs(T, 0.0, -0.0, eps_value));
183 testing.expect(approxEqRel(T, 1.0, 1.0, sqrt_eps_value));
184 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));
186 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));
188 testing.expect(!approxEqRel(T, nan_value, nan_value, sqrt_eps_value));
189 testing.expect(approxEqRel(T, inf_value, inf_value, sqrt_eps_value));
190 testing.expect(approxEqRel(T, min_value, min_value, sqrt_eps_value));
191 testing.expect(approxEqRel(T, -min_value, -min_value, sqrt_eps_value));
192 testing.expect(approxEqAbs(T, min_value, 0.0, eps_value * 2));
193 testing.expect(approxEqAbs(T, -min_value, 0.0, eps_value * 2));
180 try testing.expect(approxEqAbs(T, 0.0, 0.0, eps_value));
181 try testing.expect(approxEqAbs(T, -0.0, -0.0, eps_value));
182 try testing.expect(approxEqAbs(T, 0.0, -0.0, eps_value));
183 try testing.expect(approxEqRel(T, 1.0, 1.0, sqrt_eps_value));
184 try testing.expect(!approxEqRel(T, 1.0, 0.0, sqrt_eps_value));
185 try testing.expect(!approxEqAbs(T, 1.0 + 2 * epsilon(T), 1.0, eps_value));
186 try testing.expect(approxEqAbs(T, 1.0 + 1 * epsilon(T), 1.0, eps_value));
187 try testing.expect(!approxEqRel(T, 1.0, nan_value, sqrt_eps_value));
188 try testing.expect(!approxEqRel(T, nan_value, nan_value, sqrt_eps_value));
189 try testing.expect(approxEqRel(T, inf_value, inf_value, sqrt_eps_value));
190 try 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 try testing.expect(approxEqAbs(T, min_value, 0.0, eps_value * 2));
193 try testing.expect(approxEqAbs(T, -min_value, 0.0, eps_value * 2));
194194 }
195195}
196196
......@@ -349,34 +349,34 @@ pub fn min(x: anytype, y: anytype) Min(@TypeOf(x), @TypeOf(y)) {
349349}
350350
351351test "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);
353353 {
354354 var a: u16 = 999;
355355 var b: u32 = 10;
356356 var result = min(a, b);
357 testing.expect(@TypeOf(result) == u16);
358 testing.expect(result == 10);
357 try testing.expect(@TypeOf(result) == u16);
358 try testing.expect(result == 10);
359359 }
360360 {
361361 var a: f64 = 10.34;
362362 var b: f32 = 999.12;
363363 var result = min(a, b);
364 testing.expect(@TypeOf(result) == f64);
365 testing.expect(result == 10.34);
364 try testing.expect(@TypeOf(result) == f64);
365 try testing.expect(result == 10.34);
366366 }
367367 {
368368 var a: i8 = -127;
369369 var b: i16 = -200;
370370 var result = min(a, b);
371 testing.expect(@TypeOf(result) == i16);
372 testing.expect(result == -200);
371 try testing.expect(@TypeOf(result) == i16);
372 try testing.expect(result == -200);
373373 }
374374 {
375375 const a = 10.34;
376376 var b: f32 = 999.12;
377377 var result = min(a, b);
378 testing.expect(@TypeOf(result) == f32);
379 testing.expect(result == 10.34);
378 try testing.expect(@TypeOf(result) == f32);
379 try testing.expect(result == 10.34);
380380 }
381381}
382382
......@@ -385,7 +385,7 @@ pub fn max(x: anytype, y: anytype) @TypeOf(x, y) {
385385}
386386
387387test "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);
389389}
390390
391391pub 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
394394}
395395test "math.clamp" {
396396 // 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);
398398 // 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);
400400 // 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
403403 // Floating point
404 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);
404 try testing.expect(std.math.clamp(@as(f32, 1.1), @as(f32, 0.0), @as(f32, 1.0)) == 1.0);
405 try testing.expect(std.math.clamp(@as(f32, -127.5), @as(f32, -200), @as(f32, -100)) == -127.5);
406406
407407 // Mix of comptime and non-comptime
408408 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);
410410}
411411
412412pub 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 {
461461}
462462
463463test "math.shl" {
464 testing.expect(shl(u8, 0b11111111, @as(usize, 3)) == 0b11111000);
465 testing.expect(shl(u8, 0b11111111, @as(usize, 8)) == 0);
466 testing.expect(shl(u8, 0b11111111, @as(usize, 9)) == 0);
467 testing.expect(shl(u8, 0b11111111, @as(isize, -2)) == 0b00111111);
468 testing.expect(shl(u8, 0b11111111, 3) == 0b11111000);
469 testing.expect(shl(u8, 0b11111111, 8) == 0);
470 testing.expect(shl(u8, 0b11111111, 9) == 0);
471 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);
473 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);
464 try testing.expect(shl(u8, 0b11111111, @as(usize, 3)) == 0b11111000);
465 try testing.expect(shl(u8, 0b11111111, @as(usize, 8)) == 0);
466 try testing.expect(shl(u8, 0b11111111, @as(usize, 9)) == 0);
467 try testing.expect(shl(u8, 0b11111111, @as(isize, -2)) == 0b00111111);
468 try testing.expect(shl(u8, 0b11111111, 3) == 0b11111000);
469 try testing.expect(shl(u8, 0b11111111, 8) == 0);
470 try testing.expect(shl(u8, 0b11111111, 9) == 0);
471 try testing.expect(shl(u8, 0b11111111, -2) == 0b00111111);
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 try testing.expect(shl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, @as(isize, -1))[0] == @as(u32, 42) >> 1);
474 try testing.expect(shl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, 33)[0] == 0);
475475}
476476
477477/// Shifts right. Overflowed bits are truncated.
......@@ -501,17 +501,17 @@ pub fn shr(comptime T: type, a: T, shift_amt: anytype) T {
501501}
502502
503503test "math.shr" {
504 testing.expect(shr(u8, 0b11111111, @as(usize, 3)) == 0b00011111);
505 testing.expect(shr(u8, 0b11111111, @as(usize, 8)) == 0);
506 testing.expect(shr(u8, 0b11111111, @as(usize, 9)) == 0);
507 testing.expect(shr(u8, 0b11111111, @as(isize, -2)) == 0b11111100);
508 testing.expect(shr(u8, 0b11111111, 3) == 0b00011111);
509 testing.expect(shr(u8, 0b11111111, 8) == 0);
510 testing.expect(shr(u8, 0b11111111, 9) == 0);
511 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);
513 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);
504 try testing.expect(shr(u8, 0b11111111, @as(usize, 3)) == 0b00011111);
505 try testing.expect(shr(u8, 0b11111111, @as(usize, 8)) == 0);
506 try testing.expect(shr(u8, 0b11111111, @as(usize, 9)) == 0);
507 try testing.expect(shr(u8, 0b11111111, @as(isize, -2)) == 0b11111100);
508 try testing.expect(shr(u8, 0b11111111, 3) == 0b00011111);
509 try testing.expect(shr(u8, 0b11111111, 8) == 0);
510 try testing.expect(shr(u8, 0b11111111, 9) == 0);
511 try testing.expect(shr(u8, 0b11111111, -2) == 0b11111100);
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 try testing.expect(shr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, @as(isize, -1))[0] == @as(u32, 42) << 1);
514 try testing.expect(shr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, 33)[0] == 0);
515515}
516516
517517/// Rotates right. Only unsigned values can be rotated.
......@@ -533,13 +533,13 @@ pub fn rotr(comptime T: type, x: T, r: anytype) T {
533533}
534534
535535test "math.rotr" {
536 testing.expect(rotr(u8, 0b00000001, @as(usize, 0)) == 0b00000001);
537 testing.expect(rotr(u8, 0b00000001, @as(usize, 9)) == 0b10000000);
538 testing.expect(rotr(u8, 0b00000001, @as(usize, 8)) == 0b00000001);
539 testing.expect(rotr(u8, 0b00000001, @as(usize, 4)) == 0b00010000);
540 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);
542 testing.expect(rotr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){1}, @as(isize, -1))[0] == @as(u32, 1) << 1);
536 try testing.expect(rotr(u8, 0b00000001, @as(usize, 0)) == 0b00000001);
537 try testing.expect(rotr(u8, 0b00000001, @as(usize, 9)) == 0b10000000);
538 try testing.expect(rotr(u8, 0b00000001, @as(usize, 8)) == 0b00000001);
539 try testing.expect(rotr(u8, 0b00000001, @as(usize, 4)) == 0b00010000);
540 try testing.expect(rotr(u8, 0b00000001, @as(isize, -1)) == 0b00000010);
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 try testing.expect(rotr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){1}, @as(isize, -1))[0] == @as(u32, 1) << 1);
543543}
544544
545545/// Rotates left. Only unsigned values can be rotated.
......@@ -561,13 +561,13 @@ pub fn rotl(comptime T: type, x: T, r: anytype) T {
561561}
562562
563563test "math.rotl" {
564 testing.expect(rotl(u8, 0b00000001, @as(usize, 0)) == 0b00000001);
565 testing.expect(rotl(u8, 0b00000001, @as(usize, 9)) == 0b00000010);
566 testing.expect(rotl(u8, 0b00000001, @as(usize, 8)) == 0b00000001);
567 testing.expect(rotl(u8, 0b00000001, @as(usize, 4)) == 0b00010000);
568 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);
570 testing.expect(rotl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){1 << 31}, @as(isize, -1))[0] == @as(u32, 1) << 30);
564 try testing.expect(rotl(u8, 0b00000001, @as(usize, 0)) == 0b00000001);
565 try testing.expect(rotl(u8, 0b00000001, @as(usize, 9)) == 0b00000010);
566 try testing.expect(rotl(u8, 0b00000001, @as(usize, 8)) == 0b00000001);
567 try testing.expect(rotl(u8, 0b00000001, @as(usize, 4)) == 0b00010000);
568 try testing.expect(rotl(u8, 0b00000001, @as(isize, -1)) == 0b10000000);
569 try testing.expect(rotl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){1 << 31}, @as(usize, 1))[0] == 1);
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);
571571}
572572
573573pub fn Log2Int(comptime T: type) type {
......@@ -598,62 +598,62 @@ pub fn IntFittingRange(comptime from: comptime_int, comptime to: comptime_int) t
598598}
599599
600600test "math.IntFittingRange" {
601 testing.expect(IntFittingRange(0, 0) == u0);
602 testing.expect(IntFittingRange(0, 1) == u1);
603 testing.expect(IntFittingRange(0, 2) == u2);
604 testing.expect(IntFittingRange(0, 3) == u2);
605 testing.expect(IntFittingRange(0, 4) == u3);
606 testing.expect(IntFittingRange(0, 7) == u3);
607 testing.expect(IntFittingRange(0, 8) == u4);
608 testing.expect(IntFittingRange(0, 9) == u4);
609 testing.expect(IntFittingRange(0, 15) == u4);
610 testing.expect(IntFittingRange(0, 16) == u5);
611 testing.expect(IntFittingRange(0, 17) == u5);
612 testing.expect(IntFittingRange(0, 4095) == u12);
613 testing.expect(IntFittingRange(2000, 4095) == u12);
614 testing.expect(IntFittingRange(0, 4096) == u13);
615 testing.expect(IntFittingRange(2000, 4096) == u13);
616 testing.expect(IntFittingRange(0, 4097) == u13);
617 testing.expect(IntFittingRange(2000, 4097) == u13);
618 testing.expect(IntFittingRange(0, 123456789123456798123456789) == u87);
619 testing.expect(IntFittingRange(0, 123456789123456798123456789123456789123456798123456789) == u177);
620
621 testing.expect(IntFittingRange(-1, -1) == i1);
622 testing.expect(IntFittingRange(-1, 0) == i1);
623 testing.expect(IntFittingRange(-1, 1) == i2);
624 testing.expect(IntFittingRange(-2, -2) == i2);
625 testing.expect(IntFittingRange(-2, -1) == i2);
626 testing.expect(IntFittingRange(-2, 0) == i2);
627 testing.expect(IntFittingRange(-2, 1) == i2);
628 testing.expect(IntFittingRange(-2, 2) == i3);
629 testing.expect(IntFittingRange(-1, 2) == i3);
630 testing.expect(IntFittingRange(-1, 3) == i3);
631 testing.expect(IntFittingRange(-1, 4) == i4);
632 testing.expect(IntFittingRange(-1, 7) == i4);
633 testing.expect(IntFittingRange(-1, 8) == i5);
634 testing.expect(IntFittingRange(-1, 9) == i5);
635 testing.expect(IntFittingRange(-1, 15) == i5);
636 testing.expect(IntFittingRange(-1, 16) == i6);
637 testing.expect(IntFittingRange(-1, 17) == i6);
638 testing.expect(IntFittingRange(-1, 4095) == i13);
639 testing.expect(IntFittingRange(-4096, 4095) == i13);
640 testing.expect(IntFittingRange(-1, 4096) == i14);
641 testing.expect(IntFittingRange(-4097, 4095) == i14);
642 testing.expect(IntFittingRange(-1, 4097) == i14);
643 testing.expect(IntFittingRange(-1, 123456789123456798123456789) == i88);
644 testing.expect(IntFittingRange(-1, 123456789123456798123456789123456789123456798123456789) == i178);
601 try testing.expect(IntFittingRange(0, 0) == u0);
602 try testing.expect(IntFittingRange(0, 1) == u1);
603 try testing.expect(IntFittingRange(0, 2) == u2);
604 try testing.expect(IntFittingRange(0, 3) == u2);
605 try testing.expect(IntFittingRange(0, 4) == u3);
606 try testing.expect(IntFittingRange(0, 7) == u3);
607 try testing.expect(IntFittingRange(0, 8) == u4);
608 try testing.expect(IntFittingRange(0, 9) == u4);
609 try testing.expect(IntFittingRange(0, 15) == u4);
610 try testing.expect(IntFittingRange(0, 16) == u5);
611 try testing.expect(IntFittingRange(0, 17) == u5);
612 try testing.expect(IntFittingRange(0, 4095) == u12);
613 try testing.expect(IntFittingRange(2000, 4095) == u12);
614 try testing.expect(IntFittingRange(0, 4096) == u13);
615 try testing.expect(IntFittingRange(2000, 4096) == u13);
616 try testing.expect(IntFittingRange(0, 4097) == u13);
617 try testing.expect(IntFittingRange(2000, 4097) == u13);
618 try testing.expect(IntFittingRange(0, 123456789123456798123456789) == u87);
619 try testing.expect(IntFittingRange(0, 123456789123456798123456789123456789123456798123456789) == u177);
620
621 try testing.expect(IntFittingRange(-1, -1) == i1);
622 try testing.expect(IntFittingRange(-1, 0) == i1);
623 try testing.expect(IntFittingRange(-1, 1) == i2);
624 try testing.expect(IntFittingRange(-2, -2) == i2);
625 try testing.expect(IntFittingRange(-2, -1) == i2);
626 try testing.expect(IntFittingRange(-2, 0) == i2);
627 try testing.expect(IntFittingRange(-2, 1) == i2);
628 try testing.expect(IntFittingRange(-2, 2) == i3);
629 try testing.expect(IntFittingRange(-1, 2) == i3);
630 try testing.expect(IntFittingRange(-1, 3) == i3);
631 try testing.expect(IntFittingRange(-1, 4) == i4);
632 try testing.expect(IntFittingRange(-1, 7) == i4);
633 try testing.expect(IntFittingRange(-1, 8) == i5);
634 try testing.expect(IntFittingRange(-1, 9) == i5);
635 try testing.expect(IntFittingRange(-1, 15) == i5);
636 try testing.expect(IntFittingRange(-1, 16) == i6);
637 try testing.expect(IntFittingRange(-1, 17) == i6);
638 try testing.expect(IntFittingRange(-1, 4095) == i13);
639 try testing.expect(IntFittingRange(-4096, 4095) == i13);
640 try testing.expect(IntFittingRange(-1, 4096) == i14);
641 try testing.expect(IntFittingRange(-4097, 4095) == i14);
642 try testing.expect(IntFittingRange(-1, 4097) == i14);
643 try testing.expect(IntFittingRange(-1, 123456789123456798123456789) == i88);
644 try testing.expect(IntFittingRange(-1, 123456789123456798123456789123456789123456798123456789) == i178);
645645}
646646
647647test "math overflow functions" {
648 testOverflow();
649 comptime testOverflow();
648 try testOverflow();
649 comptime try testOverflow();
650650}
651651
652fn testOverflow() void {
653 testing.expect((mul(i32, 3, 4) catch unreachable) == 12);
654 testing.expect((add(i32, 3, 4) catch unreachable) == 7);
655 testing.expect((sub(i32, 3, 4) catch unreachable) == -1);
656 testing.expect((shlExact(i32, 0b11, 4) catch unreachable) == 0b110000);
652fn testOverflow() !void {
653 try testing.expect((mul(i32, 3, 4) catch unreachable) == 12);
654 try testing.expect((add(i32, 3, 4) catch unreachable) == 7);
655 try testing.expect((sub(i32, 3, 4) catch unreachable) == -1);
656 try testing.expect((shlExact(i32, 0b11, 4) catch unreachable) == 0b110000);
657657}
658658
659659pub fn absInt(x: anytype) !@TypeOf(x) {
......@@ -670,23 +670,23 @@ pub fn absInt(x: anytype) !@TypeOf(x) {
670670}
671671
672672test "math.absInt" {
673 testAbsInt();
674 comptime testAbsInt();
673 try testAbsInt();
674 comptime try testAbsInt();
675675}
676fn testAbsInt() void {
677 testing.expect((absInt(@as(i32, -10)) catch unreachable) == 10);
678 testing.expect((absInt(@as(i32, 10)) catch unreachable) == 10);
676fn testAbsInt() !void {
677 try testing.expect((absInt(@as(i32, -10)) catch unreachable) == 10);
678 try testing.expect((absInt(@as(i32, 10)) catch unreachable) == 10);
679679}
680680
681681pub const absFloat = fabs;
682682
683683test "math.absFloat" {
684 testAbsFloat();
685 comptime testAbsFloat();
684 try testAbsFloat();
685 comptime try testAbsFloat();
686686}
687fn testAbsFloat() void {
688 testing.expect(absFloat(@as(f32, -10.05)) == 10.05);
689 testing.expect(absFloat(@as(f32, 10.05)) == 10.05);
687fn testAbsFloat() !void {
688 try testing.expect(absFloat(@as(f32, -10.05)) == 10.05);
689 try testing.expect(absFloat(@as(f32, 10.05)) == 10.05);
690690}
691691
692692pub 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 {
697697}
698698
699699test "math.divTrunc" {
700 testDivTrunc();
701 comptime testDivTrunc();
700 try testDivTrunc();
701 comptime try testDivTrunc();
702702}
703fn testDivTrunc() void {
704 testing.expect((divTrunc(i32, 5, 3) catch unreachable) == 1);
705 testing.expect((divTrunc(i32, -5, 3) catch unreachable) == -1);
706 testing.expectError(error.DivisionByZero, divTrunc(i8, -5, 0));
707 testing.expectError(error.Overflow, divTrunc(i8, -128, -1));
703fn testDivTrunc() !void {
704 try testing.expect((divTrunc(i32, 5, 3) catch unreachable) == 1);
705 try testing.expect((divTrunc(i32, -5, 3) catch unreachable) == -1);
706 try testing.expectError(error.DivisionByZero, divTrunc(i8, -5, 0));
707 try testing.expectError(error.Overflow, divTrunc(i8, -128, -1));
708708
709 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);
709 try 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);
711711}
712712
713713pub 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 {
718718}
719719
720720test "math.divFloor" {
721 testDivFloor();
722 comptime testDivFloor();
721 try testDivFloor();
722 comptime try testDivFloor();
723723}
724fn testDivFloor() void {
725 testing.expect((divFloor(i32, 5, 3) catch unreachable) == 1);
726 testing.expect((divFloor(i32, -5, 3) catch unreachable) == -2);
727 testing.expectError(error.DivisionByZero, divFloor(i8, -5, 0));
728 testing.expectError(error.Overflow, divFloor(i8, -128, -1));
724fn testDivFloor() !void {
725 try testing.expect((divFloor(i32, 5, 3) catch unreachable) == 1);
726 try testing.expect((divFloor(i32, -5, 3) catch unreachable) == -2);
727 try testing.expectError(error.DivisionByZero, divFloor(i8, -5, 0));
728 try testing.expectError(error.Overflow, divFloor(i8, -128, -1));
729729
730 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);
730 try testing.expect((divFloor(f32, 5.0, 3.0) catch unreachable) == 1.0);
731 try testing.expect((divFloor(f32, -5.0, 3.0) catch unreachable) == -2.0);
732732}
733733
734734pub 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 {
752752}
753753
754754test "math.divCeil" {
755 testDivCeil();
756 comptime testDivCeil();
757}
758fn testDivCeil() void {
759 testing.expectEqual(@as(i32, 2), divCeil(i32, 5, 3) catch unreachable);
760 testing.expectEqual(@as(i32, -1), divCeil(i32, -5, 3) catch unreachable);
761 testing.expectEqual(@as(i32, -1), divCeil(i32, 5, -3) catch unreachable);
762 testing.expectEqual(@as(i32, 2), divCeil(i32, -5, -3) catch unreachable);
763 testing.expectEqual(@as(i32, 0), divCeil(i32, 0, 5) catch unreachable);
764 testing.expectEqual(@as(u32, 0), divCeil(u32, 0, 5) catch unreachable);
765 testing.expectError(error.DivisionByZero, divCeil(i8, -5, 0));
766 testing.expectError(error.Overflow, divCeil(i8, -128, -1));
767
768 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);
770 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);
772 testing.expectEqual(@as(f32, 2.0), divCeil(f32, -5.0, -3.0) catch unreachable);
773
774 testing.expectEqual(6, divCeil(comptime_int, 23, 4) catch unreachable);
775 testing.expectEqual(-5, divCeil(comptime_int, -23, 4) catch unreachable);
776 testing.expectEqual(-5, divCeil(comptime_int, 23, -4) catch unreachable);
777 testing.expectEqual(6, divCeil(comptime_int, -23, -4) catch unreachable);
778 testing.expectError(error.DivisionByZero, divCeil(comptime_int, 23, 0));
779
780 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);
782 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);
784 testing.expectError(error.DivisionByZero, divCeil(comptime_float, 23.0, 0.0));
755 try testDivCeil();
756 comptime try testDivCeil();
757}
758fn testDivCeil() !void {
759 try testing.expectEqual(@as(i32, 2), divCeil(i32, 5, 3) catch unreachable);
760 try 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 try testing.expectEqual(@as(i32, 2), divCeil(i32, -5, -3) catch unreachable);
763 try testing.expectEqual(@as(i32, 0), divCeil(i32, 0, 5) catch unreachable);
764 try testing.expectEqual(@as(u32, 0), divCeil(u32, 0, 5) catch unreachable);
765 try testing.expectError(error.DivisionByZero, divCeil(i8, -5, 0));
766 try testing.expectError(error.Overflow, divCeil(i8, -128, -1));
767
768 try testing.expectEqual(@as(f32, 0.0), divCeil(f32, 0.0, 5.0) catch unreachable);
769 try testing.expectEqual(@as(f32, 2.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 try testing.expectEqual(@as(f32, -1.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);
773
774 try testing.expectEqual(6, divCeil(comptime_int, 23, 4) catch unreachable);
775 try testing.expectEqual(-5, divCeil(comptime_int, -23, 4) catch unreachable);
776 try testing.expectEqual(-5, divCeil(comptime_int, 23, -4) catch unreachable);
777 try testing.expectEqual(6, divCeil(comptime_int, -23, -4) catch unreachable);
778 try testing.expectError(error.DivisionByZero, divCeil(comptime_int, 23, 0));
779
780 try testing.expectEqual(6.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 try testing.expectEqual(-5.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 try testing.expectError(error.DivisionByZero, divCeil(comptime_float, 23.0, 0.0));
785785}
786786
787787pub 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 {
794794}
795795
796796test "math.divExact" {
797 testDivExact();
798 comptime testDivExact();
797 try testDivExact();
798 comptime try testDivExact();
799799}
800fn testDivExact() void {
801 testing.expect((divExact(i32, 10, 5) catch unreachable) == 2);
802 testing.expect((divExact(i32, -10, 5) catch unreachable) == -2);
803 testing.expectError(error.DivisionByZero, divExact(i8, -5, 0));
804 testing.expectError(error.Overflow, divExact(i8, -128, -1));
805 testing.expectError(error.UnexpectedRemainder, divExact(i32, 5, 2));
800fn testDivExact() !void {
801 try testing.expect((divExact(i32, 10, 5) catch unreachable) == 2);
802 try testing.expect((divExact(i32, -10, 5) catch unreachable) == -2);
803 try testing.expectError(error.DivisionByZero, divExact(i8, -5, 0));
804 try testing.expectError(error.Overflow, divExact(i8, -128, -1));
805 try testing.expectError(error.UnexpectedRemainder, divExact(i32, 5, 2));
806806
807 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);
809 testing.expectError(error.UnexpectedRemainder, divExact(f32, 5.0, 2.0));
807 try 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 try testing.expectError(error.UnexpectedRemainder, divExact(f32, 5.0, 2.0));
810810}
811811
812812pub 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 {
817817}
818818
819819test "math.mod" {
820 testMod();
821 comptime testMod();
820 try testMod();
821 comptime try testMod();
822822}
823fn testMod() void {
824 testing.expect((mod(i32, -5, 3) catch unreachable) == 1);
825 testing.expect((mod(i32, 5, 3) catch unreachable) == 2);
826 testing.expectError(error.NegativeDenominator, mod(i32, 10, -1));
827 testing.expectError(error.DivisionByZero, mod(i32, 10, 0));
823fn testMod() !void {
824 try testing.expect((mod(i32, -5, 3) catch unreachable) == 1);
825 try testing.expect((mod(i32, 5, 3) catch unreachable) == 2);
826 try testing.expectError(error.NegativeDenominator, mod(i32, 10, -1));
827 try testing.expectError(error.DivisionByZero, mod(i32, 10, 0));
828828
829 testing.expect((mod(f32, -5, 3) catch unreachable) == 1);
830 testing.expect((mod(f32, 5, 3) catch unreachable) == 2);
831 testing.expectError(error.NegativeDenominator, mod(f32, 10, -1));
832 testing.expectError(error.DivisionByZero, mod(f32, 10, 0));
829 try testing.expect((mod(f32, -5, 3) catch unreachable) == 1);
830 try testing.expect((mod(f32, 5, 3) catch unreachable) == 2);
831 try testing.expectError(error.NegativeDenominator, mod(f32, 10, -1));
832 try testing.expectError(error.DivisionByZero, mod(f32, 10, 0));
833833}
834834
835835pub 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 {
840840}
841841
842842test "math.rem" {
843 testRem();
844 comptime testRem();
843 try testRem();
844 comptime try testRem();
845845}
846fn testRem() void {
847 testing.expect((rem(i32, -5, 3) catch unreachable) == -2);
848 testing.expect((rem(i32, 5, 3) catch unreachable) == 2);
849 testing.expectError(error.NegativeDenominator, rem(i32, 10, -1));
850 testing.expectError(error.DivisionByZero, rem(i32, 10, 0));
846fn testRem() !void {
847 try testing.expect((rem(i32, -5, 3) catch unreachable) == -2);
848 try testing.expect((rem(i32, 5, 3) catch unreachable) == 2);
849 try testing.expectError(error.NegativeDenominator, rem(i32, 10, -1));
850 try testing.expectError(error.DivisionByZero, rem(i32, 10, 0));
851851
852 testing.expect((rem(f32, -5, 3) catch unreachable) == -2);
853 testing.expect((rem(f32, 5, 3) catch unreachable) == 2);
854 testing.expectError(error.NegativeDenominator, rem(f32, 10, -1));
855 testing.expectError(error.DivisionByZero, rem(f32, 10, 0));
852 try testing.expect((rem(f32, -5, 3) catch unreachable) == -2);
853 try testing.expect((rem(f32, 5, 3) catch unreachable) == 2);
854 try testing.expectError(error.NegativeDenominator, rem(f32, 10, -1));
855 try testing.expectError(error.DivisionByZero, rem(f32, 10, 0));
856856}
857857
858858/// Returns the absolute value of the integer parameter.
......@@ -883,11 +883,11 @@ pub fn absCast(x: anytype) switch (@typeInfo(@TypeOf(x))) {
883883}
884884
885885test "math.absCast" {
886 testing.expectEqual(@as(u1, 1), absCast(@as(i1, -1)));
887 testing.expectEqual(@as(u32, 999), absCast(@as(i32, -999)));
888 testing.expectEqual(@as(u32, 999), absCast(@as(i32, 999)));
889 testing.expectEqual(@as(u32, -minInt(i32)), absCast(@as(i32, minInt(i32))));
890 testing.expectEqual(999, absCast(-999));
886 try testing.expectEqual(@as(u1, 1), absCast(@as(i1, -1)));
887 try testing.expectEqual(@as(u32, 999), absCast(@as(i32, -999)));
888 try testing.expectEqual(@as(u32, 999), absCast(@as(i32, 999)));
889 try testing.expectEqual(@as(u32, -minInt(i32)), absCast(@as(i32, minInt(i32))));
890 try testing.expectEqual(999, absCast(-999));
891891}
892892
893893/// 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
904904}
905905
906906test "math.negateCast" {
907 testing.expect((negateCast(@as(u32, 999)) catch unreachable) == -999);
908 testing.expect(@TypeOf(negateCast(@as(u32, 999)) catch unreachable) == i32);
907 try testing.expect((negateCast(@as(u32, 999)) catch unreachable) == -999);
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));
911 testing.expect(@TypeOf(negateCast(@as(u32, -minInt(i32))) catch unreachable) == i32);
910 try testing.expect((negateCast(@as(u32, -minInt(i32))) catch unreachable) == minInt(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)));
914914}
915915
916916/// 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) {
929929}
930930
931931test "math.cast" {
932 testing.expectError(error.Overflow, cast(u8, @as(u32, 300)));
933 testing.expectError(error.Overflow, cast(i8, @as(i32, -200)));
934 testing.expectError(error.Overflow, cast(u8, @as(i8, -1)));
935 testing.expectError(error.Overflow, cast(u64, @as(i8, -1)));
932 try testing.expectError(error.Overflow, cast(u8, @as(u32, 300)));
933 try testing.expectError(error.Overflow, cast(i8, @as(i32, -200)));
934 try testing.expectError(error.Overflow, cast(u8, @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));
938 testing.expect(@TypeOf(try cast(u8, @as(u32, 255))) == u8);
937 try testing.expect((try cast(u8, @as(u32, 255))) == @as(u8, 255));
938 try testing.expect(@TypeOf(try cast(u8, @as(u32, 255))) == u8);
939939}
940940
941941pub const AlignCastError = error{UnalignedMemory};
......@@ -966,17 +966,17 @@ pub fn floorPowerOfTwo(comptime T: type, value: T) T {
966966}
967967
968968test "math.floorPowerOfTwo" {
969 testFloorPowerOfTwo();
970 comptime testFloorPowerOfTwo();
969 try testFloorPowerOfTwo();
970 comptime try testFloorPowerOfTwo();
971971}
972972
973fn testFloorPowerOfTwo() void {
974 testing.expect(floorPowerOfTwo(u32, 63) == 32);
975 testing.expect(floorPowerOfTwo(u32, 64) == 64);
976 testing.expect(floorPowerOfTwo(u32, 65) == 64);
977 testing.expect(floorPowerOfTwo(u4, 7) == 4);
978 testing.expect(floorPowerOfTwo(u4, 8) == 8);
979 testing.expect(floorPowerOfTwo(u4, 9) == 8);
973fn testFloorPowerOfTwo() !void {
974 try testing.expect(floorPowerOfTwo(u32, 63) == 32);
975 try testing.expect(floorPowerOfTwo(u32, 64) == 64);
976 try testing.expect(floorPowerOfTwo(u32, 65) == 64);
977 try testing.expect(floorPowerOfTwo(u4, 7) == 4);
978 try testing.expect(floorPowerOfTwo(u4, 8) == 8);
979 try testing.expect(floorPowerOfTwo(u4, 9) == 8);
980980}
981981
982982/// 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 {
10121012}
10131013
10141014test "math.ceilPowerOfTwoPromote" {
1015 testCeilPowerOfTwoPromote();
1016 comptime testCeilPowerOfTwoPromote();
1015 try testCeilPowerOfTwoPromote();
1016 comptime try testCeilPowerOfTwoPromote();
10171017}
10181018
1019fn testCeilPowerOfTwoPromote() void {
1020 testing.expectEqual(@as(u33, 1), ceilPowerOfTwoPromote(u32, 1));
1021 testing.expectEqual(@as(u33, 2), ceilPowerOfTwoPromote(u32, 2));
1022 testing.expectEqual(@as(u33, 64), ceilPowerOfTwoPromote(u32, 63));
1023 testing.expectEqual(@as(u33, 64), ceilPowerOfTwoPromote(u32, 64));
1024 testing.expectEqual(@as(u33, 128), ceilPowerOfTwoPromote(u32, 65));
1025 testing.expectEqual(@as(u6, 8), ceilPowerOfTwoPromote(u5, 7));
1026 testing.expectEqual(@as(u6, 8), ceilPowerOfTwoPromote(u5, 8));
1027 testing.expectEqual(@as(u6, 16), ceilPowerOfTwoPromote(u5, 9));
1028 testing.expectEqual(@as(u5, 16), ceilPowerOfTwoPromote(u4, 9));
1019fn testCeilPowerOfTwoPromote() !void {
1020 try testing.expectEqual(@as(u33, 1), ceilPowerOfTwoPromote(u32, 1));
1021 try testing.expectEqual(@as(u33, 2), ceilPowerOfTwoPromote(u32, 2));
1022 try testing.expectEqual(@as(u33, 64), ceilPowerOfTwoPromote(u32, 63));
1023 try testing.expectEqual(@as(u33, 64), ceilPowerOfTwoPromote(u32, 64));
1024 try testing.expectEqual(@as(u33, 128), ceilPowerOfTwoPromote(u32, 65));
1025 try testing.expectEqual(@as(u6, 8), ceilPowerOfTwoPromote(u5, 7));
1026 try testing.expectEqual(@as(u6, 8), ceilPowerOfTwoPromote(u5, 8));
1027 try testing.expectEqual(@as(u6, 16), ceilPowerOfTwoPromote(u5, 9));
1028 try testing.expectEqual(@as(u5, 16), ceilPowerOfTwoPromote(u4, 9));
10291029}
10301030
10311031test "math.ceilPowerOfTwo" {
......@@ -1034,15 +1034,15 @@ test "math.ceilPowerOfTwo" {
10341034}
10351035
10361036fn testCeilPowerOfTwo() !void {
1037 testing.expectEqual(@as(u32, 1), try ceilPowerOfTwo(u32, 1));
1038 testing.expectEqual(@as(u32, 2), try ceilPowerOfTwo(u32, 2));
1039 testing.expectEqual(@as(u32, 64), try ceilPowerOfTwo(u32, 63));
1040 testing.expectEqual(@as(u32, 64), try ceilPowerOfTwo(u32, 64));
1041 testing.expectEqual(@as(u32, 128), try ceilPowerOfTwo(u32, 65));
1042 testing.expectEqual(@as(u5, 8), try ceilPowerOfTwo(u5, 7));
1043 testing.expectEqual(@as(u5, 8), try ceilPowerOfTwo(u5, 8));
1044 testing.expectEqual(@as(u5, 16), try ceilPowerOfTwo(u5, 9));
1045 testing.expectError(error.Overflow, ceilPowerOfTwo(u4, 9));
1037 try testing.expectEqual(@as(u32, 1), try ceilPowerOfTwo(u32, 1));
1038 try testing.expectEqual(@as(u32, 2), try ceilPowerOfTwo(u32, 2));
1039 try testing.expectEqual(@as(u32, 64), try ceilPowerOfTwo(u32, 63));
1040 try testing.expectEqual(@as(u32, 64), try ceilPowerOfTwo(u32, 64));
1041 try testing.expectEqual(@as(u32, 128), try ceilPowerOfTwo(u32, 65));
1042 try testing.expectEqual(@as(u5, 8), try ceilPowerOfTwo(u5, 7));
1043 try testing.expectEqual(@as(u5, 8), try ceilPowerOfTwo(u5, 8));
1044 try testing.expectEqual(@as(u5, 16), try ceilPowerOfTwo(u5, 9));
1045 try testing.expectError(error.Overflow, ceilPowerOfTwo(u4, 9));
10461046}
10471047
10481048pub 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) {
10591059}
10601060
10611061test "std.math.log2_int_ceil" {
1062 testing.expect(log2_int_ceil(u32, 1) == 0);
1063 testing.expect(log2_int_ceil(u32, 2) == 1);
1064 testing.expect(log2_int_ceil(u32, 3) == 2);
1065 testing.expect(log2_int_ceil(u32, 4) == 2);
1066 testing.expect(log2_int_ceil(u32, 5) == 3);
1067 testing.expect(log2_int_ceil(u32, 6) == 3);
1068 testing.expect(log2_int_ceil(u32, 7) == 3);
1069 testing.expect(log2_int_ceil(u32, 8) == 3);
1070 testing.expect(log2_int_ceil(u32, 9) == 4);
1071 testing.expect(log2_int_ceil(u32, 10) == 4);
1062 try testing.expect(log2_int_ceil(u32, 1) == 0);
1063 try testing.expect(log2_int_ceil(u32, 2) == 1);
1064 try testing.expect(log2_int_ceil(u32, 3) == 2);
1065 try testing.expect(log2_int_ceil(u32, 4) == 2);
1066 try testing.expect(log2_int_ceil(u32, 5) == 3);
1067 try testing.expect(log2_int_ceil(u32, 6) == 3);
1068 try testing.expect(log2_int_ceil(u32, 7) == 3);
1069 try testing.expect(log2_int_ceil(u32, 8) == 3);
1070 try testing.expect(log2_int_ceil(u32, 9) == 4);
1071 try testing.expect(log2_int_ceil(u32, 10) == 4);
10721072}
10731073
10741074///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 {
11121112}
11131113
11141114test "math.lossyCast" {
1115 testing.expect(lossyCast(i16, 70000.0) == @as(i16, 32767));
1116 testing.expect(lossyCast(u32, @as(i16, -255)) == @as(u32, 0));
1117 testing.expect(lossyCast(i9, @as(u32, 200)) == @as(i9, 200));
1115 try testing.expect(lossyCast(i16, 70000.0) == @as(i16, 32767));
1116 try testing.expect(lossyCast(u32, @as(i16, -255)) == @as(u32, 0));
1117 try testing.expect(lossyCast(i9, @as(u32, 200)) == @as(i9, 200));
11181118}
11191119
11201120test "math.f64_min" {
11211121 const f64_min_u64 = 0x0010000000000000;
11221122 const fmin: f64 = f64_min;
1123 testing.expect(@bitCast(u64, fmin) == f64_min_u64);
1123 try testing.expect(@bitCast(u64, fmin) == f64_min_u64);
11241124}
11251125
11261126pub fn maxInt(comptime T: type) comptime_int {
......@@ -1139,45 +1139,45 @@ pub fn minInt(comptime T: type) comptime_int {
11391139}
11401140
11411141test "minInt and maxInt" {
1142 testing.expect(maxInt(u0) == 0);
1143 testing.expect(maxInt(u1) == 1);
1144 testing.expect(maxInt(u8) == 255);
1145 testing.expect(maxInt(u16) == 65535);
1146 testing.expect(maxInt(u32) == 4294967295);
1147 testing.expect(maxInt(u64) == 18446744073709551615);
1148 testing.expect(maxInt(u128) == 340282366920938463463374607431768211455);
1149
1150 testing.expect(maxInt(i0) == 0);
1151 testing.expect(maxInt(i1) == 0);
1152 testing.expect(maxInt(i8) == 127);
1153 testing.expect(maxInt(i16) == 32767);
1154 testing.expect(maxInt(i32) == 2147483647);
1155 testing.expect(maxInt(i63) == 4611686018427387903);
1156 testing.expect(maxInt(i64) == 9223372036854775807);
1157 testing.expect(maxInt(i128) == 170141183460469231731687303715884105727);
1158
1159 testing.expect(minInt(u0) == 0);
1160 testing.expect(minInt(u1) == 0);
1161 testing.expect(minInt(u8) == 0);
1162 testing.expect(minInt(u16) == 0);
1163 testing.expect(minInt(u32) == 0);
1164 testing.expect(minInt(u63) == 0);
1165 testing.expect(minInt(u64) == 0);
1166 testing.expect(minInt(u128) == 0);
1167
1168 testing.expect(minInt(i0) == 0);
1169 testing.expect(minInt(i1) == -1);
1170 testing.expect(minInt(i8) == -128);
1171 testing.expect(minInt(i16) == -32768);
1172 testing.expect(minInt(i32) == -2147483648);
1173 testing.expect(minInt(i63) == -4611686018427387904);
1174 testing.expect(minInt(i64) == -9223372036854775808);
1175 testing.expect(minInt(i128) == -170141183460469231731687303715884105728);
1142 try testing.expect(maxInt(u0) == 0);
1143 try testing.expect(maxInt(u1) == 1);
1144 try testing.expect(maxInt(u8) == 255);
1145 try testing.expect(maxInt(u16) == 65535);
1146 try testing.expect(maxInt(u32) == 4294967295);
1147 try testing.expect(maxInt(u64) == 18446744073709551615);
1148 try testing.expect(maxInt(u128) == 340282366920938463463374607431768211455);
1149
1150 try testing.expect(maxInt(i0) == 0);
1151 try testing.expect(maxInt(i1) == 0);
1152 try testing.expect(maxInt(i8) == 127);
1153 try testing.expect(maxInt(i16) == 32767);
1154 try testing.expect(maxInt(i32) == 2147483647);
1155 try testing.expect(maxInt(i63) == 4611686018427387903);
1156 try testing.expect(maxInt(i64) == 9223372036854775807);
1157 try testing.expect(maxInt(i128) == 170141183460469231731687303715884105727);
1158
1159 try testing.expect(minInt(u0) == 0);
1160 try testing.expect(minInt(u1) == 0);
1161 try testing.expect(minInt(u8) == 0);
1162 try testing.expect(minInt(u16) == 0);
1163 try testing.expect(minInt(u32) == 0);
1164 try testing.expect(minInt(u63) == 0);
1165 try testing.expect(minInt(u64) == 0);
1166 try testing.expect(minInt(u128) == 0);
1167
1168 try testing.expect(minInt(i0) == 0);
1169 try testing.expect(minInt(i1) == -1);
1170 try testing.expect(minInt(i8) == -128);
1171 try testing.expect(minInt(i16) == -32768);
1172 try testing.expect(minInt(i32) == -2147483648);
1173 try testing.expect(minInt(i63) == -4611686018427387904);
1174 try testing.expect(minInt(i64) == -9223372036854775808);
1175 try testing.expect(minInt(i128) == -170141183460469231731687303715884105728);
11761176}
11771177
11781178test "max value type" {
11791179 const x: u32 = maxInt(i32);
1180 testing.expect(x == 2147483647);
1180 try testing.expect(x == 2147483647);
11811181}
11821182
11831183pub 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
11861186}
11871187
11881188test "math.mulWide" {
1189 testing.expect(mulWide(u8, 5, 5) == 25);
1190 testing.expect(mulWide(i8, 5, -5) == -25);
1191 testing.expect(mulWide(u8, 100, 100) == 10000);
1189 try testing.expect(mulWide(u8, 5, 5) == 25);
1190 try testing.expect(mulWide(i8, 5, -5) == -25);
1191 try testing.expect(mulWide(u8, 100, 100) == 10000);
11921192}
11931193
11941194/// See also `CompareOperator`.
......@@ -1284,51 +1284,51 @@ pub fn compare(a: anytype, op: CompareOperator, b: anytype) bool {
12841284}
12851285
12861286test "compare between signed and unsigned" {
1287 testing.expect(compare(@as(i8, -1), .lt, @as(u8, 255)));
1288 testing.expect(compare(@as(i8, 2), .gt, @as(u8, 1)));
1289 testing.expect(!compare(@as(i8, -1), .gte, @as(u8, 255)));
1290 testing.expect(compare(@as(u8, 255), .gt, @as(i8, -1)));
1291 testing.expect(!compare(@as(u8, 255), .lte, @as(i8, -1)));
1292 testing.expect(compare(@as(i8, -1), .lt, @as(u9, 255)));
1293 testing.expect(!compare(@as(i8, -1), .gte, @as(u9, 255)));
1294 testing.expect(compare(@as(u9, 255), .gt, @as(i8, -1)));
1295 testing.expect(!compare(@as(u9, 255), .lte, @as(i8, -1)));
1296 testing.expect(compare(@as(i9, -1), .lt, @as(u8, 255)));
1297 testing.expect(!compare(@as(i9, -1), .gte, @as(u8, 255)));
1298 testing.expect(compare(@as(u8, 255), .gt, @as(i9, -1)));
1299 testing.expect(!compare(@as(u8, 255), .lte, @as(i9, -1)));
1300 testing.expect(compare(@as(u8, 1), .lt, @as(u8, 2)));
1301 testing.expect(@bitCast(u8, @as(i8, -1)) == @as(u8, 255));
1302 testing.expect(!compare(@as(u8, 255), .eq, @as(i8, -1)));
1303 testing.expect(compare(@as(u8, 1), .eq, @as(u8, 1)));
1287 try testing.expect(compare(@as(i8, -1), .lt, @as(u8, 255)));
1288 try testing.expect(compare(@as(i8, 2), .gt, @as(u8, 1)));
1289 try testing.expect(!compare(@as(i8, -1), .gte, @as(u8, 255)));
1290 try testing.expect(compare(@as(u8, 255), .gt, @as(i8, -1)));
1291 try testing.expect(!compare(@as(u8, 255), .lte, @as(i8, -1)));
1292 try testing.expect(compare(@as(i8, -1), .lt, @as(u9, 255)));
1293 try testing.expect(!compare(@as(i8, -1), .gte, @as(u9, 255)));
1294 try testing.expect(compare(@as(u9, 255), .gt, @as(i8, -1)));
1295 try testing.expect(!compare(@as(u9, 255), .lte, @as(i8, -1)));
1296 try testing.expect(compare(@as(i9, -1), .lt, @as(u8, 255)));
1297 try testing.expect(!compare(@as(i9, -1), .gte, @as(u8, 255)));
1298 try testing.expect(compare(@as(u8, 255), .gt, @as(i9, -1)));
1299 try testing.expect(!compare(@as(u8, 255), .lte, @as(i9, -1)));
1300 try testing.expect(compare(@as(u8, 1), .lt, @as(u8, 2)));
1301 try testing.expect(@bitCast(u8, @as(i8, -1)) == @as(u8, 255));
1302 try testing.expect(!compare(@as(u8, 255), .eq, @as(i8, -1)));
1303 try testing.expect(compare(@as(u8, 1), .eq, @as(u8, 1)));
13041304}
13051305
13061306test "order" {
1307 testing.expect(order(0, 0) == .eq);
1308 testing.expect(order(1, 0) == .gt);
1309 testing.expect(order(-1, 0) == .lt);
1307 try testing.expect(order(0, 0) == .eq);
1308 try testing.expect(order(1, 0) == .gt);
1309 try testing.expect(order(-1, 0) == .lt);
13101310}
13111311
13121312test "order.invert" {
1313 testing.expect(Order.invert(order(0, 0)) == .eq);
1314 testing.expect(Order.invert(order(1, 0)) == .lt);
1315 testing.expect(Order.invert(order(-1, 0)) == .gt);
1313 try testing.expect(Order.invert(order(0, 0)) == .eq);
1314 try testing.expect(Order.invert(order(1, 0)) == .lt);
1315 try testing.expect(Order.invert(order(-1, 0)) == .gt);
13161316}
13171317
13181318test "order.compare" {
1319 testing.expect(order(-1, 0).compare(.lt));
1320 testing.expect(order(-1, 0).compare(.lte));
1321 testing.expect(order(0, 0).compare(.lte));
1322 testing.expect(order(0, 0).compare(.eq));
1323 testing.expect(order(0, 0).compare(.gte));
1324 testing.expect(order(1, 0).compare(.gte));
1325 testing.expect(order(1, 0).compare(.gt));
1326 testing.expect(order(1, 0).compare(.neq));
1319 try testing.expect(order(-1, 0).compare(.lt));
1320 try testing.expect(order(-1, 0).compare(.lte));
1321 try testing.expect(order(0, 0).compare(.lte));
1322 try testing.expect(order(0, 0).compare(.eq));
1323 try testing.expect(order(0, 0).compare(.gte));
1324 try testing.expect(order(1, 0).compare(.gte));
1325 try testing.expect(order(1, 0).compare(.gt));
1326 try testing.expect(order(1, 0).compare(.neq));
13271327}
13281328
13291329test "math.comptime" {
13301330 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)));
13321332}
13331333
13341334/// 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 {
13541354
13551355test "boolMask" {
13561356 const runTest = struct {
1357 fn runTest() void {
1358 testing.expectEqual(@as(u1, 0), boolMask(u1, false));
1359 testing.expectEqual(@as(u1, 1), boolMask(u1, true));
1357 fn runTest() !void {
1358 try testing.expectEqual(@as(u1, 0), boolMask(u1, false));
1359 try testing.expectEqual(@as(u1, 1), boolMask(u1, true));
13601360
1361 testing.expectEqual(@as(i1, 0), boolMask(i1, false));
1362 testing.expectEqual(@as(i1, -1), boolMask(i1, true));
1361 try testing.expectEqual(@as(i1, 0), boolMask(i1, false));
1362 try testing.expectEqual(@as(i1, -1), boolMask(i1, true));
13631363
1364 testing.expectEqual(@as(u13, 0), boolMask(u13, false));
1365 testing.expectEqual(@as(u13, 0x1FFF), boolMask(u13, true));
1364 try testing.expectEqual(@as(u13, 0), boolMask(u13, false));
1365 try testing.expectEqual(@as(u13, 0x1FFF), boolMask(u13, true));
13661366
1367 testing.expectEqual(@as(i13, 0), boolMask(i13, false));
1368 testing.expectEqual(@as(i13, -1), boolMask(i13, true));
1367 try testing.expectEqual(@as(i13, 0), boolMask(i13, false));
1368 try testing.expectEqual(@as(i13, -1), boolMask(i13, true));
13691369
1370 testing.expectEqual(@as(u32, 0), boolMask(u32, false));
1371 testing.expectEqual(@as(u32, 0xFFFF_FFFF), boolMask(u32, true));
1370 try testing.expectEqual(@as(u32, 0), boolMask(u32, false));
1371 try testing.expectEqual(@as(u32, 0xFFFF_FFFF), boolMask(u32, true));
13721372
1373 testing.expectEqual(@as(i32, 0), boolMask(i32, false));
1374 testing.expectEqual(@as(i32, -1), boolMask(i32, true));
1373 try testing.expectEqual(@as(i32, 0), boolMask(i32, false));
1374 try testing.expectEqual(@as(i32, -1), boolMask(i32, true));
13751375 }
13761376 }.runTest;
1377 runTest();
1378 comptime runTest();
1377 try runTest();
1378 comptime try runTest();
13791379}
lib/std/math/acos.zig+18-18
......@@ -154,38 +154,38 @@ fn acos64(x: f64) f64 {
154154}
155155
156156test "math.acos" {
157 expect(acos(@as(f32, 0.0)) == acos32(0.0));
158 expect(acos(@as(f64, 0.0)) == acos64(0.0));
157 try expect(acos(@as(f32, 0.0)) == acos32(0.0));
158 try expect(acos(@as(f64, 0.0)) == acos64(0.0));
159159}
160160
161161test "math.acos32" {
162162 const epsilon = 0.000001;
163163
164 expect(math.approxEqAbs(f32, acos32(0.0), 1.570796, epsilon));
165 expect(math.approxEqAbs(f32, acos32(0.2), 1.369438, epsilon));
166 expect(math.approxEqAbs(f32, acos32(0.3434), 1.220262, epsilon));
167 expect(math.approxEqAbs(f32, acos32(0.5), 1.047198, epsilon));
168 expect(math.approxEqAbs(f32, acos32(0.8923), 0.468382, epsilon));
169 expect(math.approxEqAbs(f32, acos32(-0.2), 1.772154, epsilon));
164 try expect(math.approxEqAbs(f32, acos32(0.0), 1.570796, epsilon));
165 try expect(math.approxEqAbs(f32, acos32(0.2), 1.369438, epsilon));
166 try expect(math.approxEqAbs(f32, acos32(0.3434), 1.220262, epsilon));
167 try expect(math.approxEqAbs(f32, acos32(0.5), 1.047198, epsilon));
168 try expect(math.approxEqAbs(f32, acos32(0.8923), 0.468382, epsilon));
169 try expect(math.approxEqAbs(f32, acos32(-0.2), 1.772154, epsilon));
170170}
171171
172172test "math.acos64" {
173173 const epsilon = 0.000001;
174174
175 expect(math.approxEqAbs(f64, acos64(0.0), 1.570796, epsilon));
176 expect(math.approxEqAbs(f64, acos64(0.2), 1.369438, epsilon));
177 expect(math.approxEqAbs(f64, acos64(0.3434), 1.220262, epsilon));
178 expect(math.approxEqAbs(f64, acos64(0.5), 1.047198, epsilon));
179 expect(math.approxEqAbs(f64, acos64(0.8923), 0.468382, epsilon));
180 expect(math.approxEqAbs(f64, acos64(-0.2), 1.772154, epsilon));
175 try expect(math.approxEqAbs(f64, acos64(0.0), 1.570796, epsilon));
176 try expect(math.approxEqAbs(f64, acos64(0.2), 1.369438, epsilon));
177 try expect(math.approxEqAbs(f64, acos64(0.3434), 1.220262, epsilon));
178 try expect(math.approxEqAbs(f64, acos64(0.5), 1.047198, epsilon));
179 try expect(math.approxEqAbs(f64, acos64(0.8923), 0.468382, epsilon));
180 try expect(math.approxEqAbs(f64, acos64(-0.2), 1.772154, epsilon));
181181}
182182
183183test "math.acos32.special" {
184 expect(math.isNan(acos32(-2)));
185 expect(math.isNan(acos32(1.5)));
184 try expect(math.isNan(acos32(-2)));
185 try expect(math.isNan(acos32(1.5)));
186186}
187187
188188test "math.acos64.special" {
189 expect(math.isNan(acos64(-2)));
190 expect(math.isNan(acos64(1.5)));
189 try expect(math.isNan(acos64(-2)));
190 try expect(math.isNan(acos64(1.5)));
191191}
lib/std/math/acosh.zig+14-14
......@@ -66,34 +66,34 @@ fn acosh64(x: f64) f64 {
6666}
6767
6868test "math.acosh" {
69 expect(acosh(@as(f32, 1.5)) == acosh32(1.5));
70 expect(acosh(@as(f64, 1.5)) == acosh64(1.5));
69 try expect(acosh(@as(f32, 1.5)) == acosh32(1.5));
70 try expect(acosh(@as(f64, 1.5)) == acosh64(1.5));
7171}
7272
7373test "math.acosh32" {
7474 const epsilon = 0.000001;
7575
76 expect(math.approxEqAbs(f32, acosh32(1.5), 0.962424, epsilon));
77 expect(math.approxEqAbs(f32, acosh32(37.45), 4.315976, epsilon));
78 expect(math.approxEqAbs(f32, acosh32(89.123), 5.183133, epsilon));
79 expect(math.approxEqAbs(f32, acosh32(123123.234375), 12.414088, epsilon));
76 try expect(math.approxEqAbs(f32, acosh32(1.5), 0.962424, epsilon));
77 try expect(math.approxEqAbs(f32, acosh32(37.45), 4.315976, epsilon));
78 try expect(math.approxEqAbs(f32, acosh32(89.123), 5.183133, epsilon));
79 try expect(math.approxEqAbs(f32, acosh32(123123.234375), 12.414088, epsilon));
8080}
8181
8282test "math.acosh64" {
8383 const epsilon = 0.000001;
8484
85 expect(math.approxEqAbs(f64, acosh64(1.5), 0.962424, epsilon));
86 expect(math.approxEqAbs(f64, acosh64(37.45), 4.315976, epsilon));
87 expect(math.approxEqAbs(f64, acosh64(89.123), 5.183133, epsilon));
88 expect(math.approxEqAbs(f64, acosh64(123123.234375), 12.414088, epsilon));
85 try expect(math.approxEqAbs(f64, acosh64(1.5), 0.962424, epsilon));
86 try expect(math.approxEqAbs(f64, acosh64(37.45), 4.315976, epsilon));
87 try expect(math.approxEqAbs(f64, acosh64(89.123), 5.183133, epsilon));
88 try expect(math.approxEqAbs(f64, acosh64(123123.234375), 12.414088, epsilon));
8989}
9090
9191test "math.acosh32.special" {
92 expect(math.isNan(acosh32(math.nan(f32))));
93 expect(math.isSignalNan(acosh32(0.5)));
92 try expect(math.isNan(acosh32(math.nan(f32))));
93 try expect(math.isSignalNan(acosh32(0.5)));
9494}
9595
9696test "math.acosh64.special" {
97 expect(math.isNan(acosh64(math.nan(f64))));
98 expect(math.isSignalNan(acosh64(0.5)));
97 try expect(math.isNan(acosh64(math.nan(f64))));
98 try expect(math.isSignalNan(acosh64(0.5)));
9999}
lib/std/math/asin.zig+22-22
......@@ -147,42 +147,42 @@ fn asin64(x: f64) f64 {
147147}
148148
149149test "math.asin" {
150 expect(asin(@as(f32, 0.0)) == asin32(0.0));
151 expect(asin(@as(f64, 0.0)) == asin64(0.0));
150 try expect(asin(@as(f32, 0.0)) == asin32(0.0));
151 try expect(asin(@as(f64, 0.0)) == asin64(0.0));
152152}
153153
154154test "math.asin32" {
155155 const epsilon = 0.000001;
156156
157 expect(math.approxEqAbs(f32, asin32(0.0), 0.0, epsilon));
158 expect(math.approxEqAbs(f32, asin32(0.2), 0.201358, epsilon));
159 expect(math.approxEqAbs(f32, asin32(-0.2), -0.201358, epsilon));
160 expect(math.approxEqAbs(f32, asin32(0.3434), 0.350535, epsilon));
161 expect(math.approxEqAbs(f32, asin32(0.5), 0.523599, epsilon));
162 expect(math.approxEqAbs(f32, asin32(0.8923), 1.102415, epsilon));
157 try expect(math.approxEqAbs(f32, asin32(0.0), 0.0, epsilon));
158 try expect(math.approxEqAbs(f32, asin32(0.2), 0.201358, epsilon));
159 try expect(math.approxEqAbs(f32, asin32(-0.2), -0.201358, epsilon));
160 try expect(math.approxEqAbs(f32, asin32(0.3434), 0.350535, epsilon));
161 try expect(math.approxEqAbs(f32, asin32(0.5), 0.523599, epsilon));
162 try expect(math.approxEqAbs(f32, asin32(0.8923), 1.102415, epsilon));
163163}
164164
165165test "math.asin64" {
166166 const epsilon = 0.000001;
167167
168 expect(math.approxEqAbs(f64, asin64(0.0), 0.0, epsilon));
169 expect(math.approxEqAbs(f64, asin64(0.2), 0.201358, epsilon));
170 expect(math.approxEqAbs(f64, asin64(-0.2), -0.201358, epsilon));
171 expect(math.approxEqAbs(f64, asin64(0.3434), 0.350535, epsilon));
172 expect(math.approxEqAbs(f64, asin64(0.5), 0.523599, epsilon));
173 expect(math.approxEqAbs(f64, asin64(0.8923), 1.102415, epsilon));
168 try expect(math.approxEqAbs(f64, asin64(0.0), 0.0, epsilon));
169 try expect(math.approxEqAbs(f64, asin64(0.2), 0.201358, epsilon));
170 try expect(math.approxEqAbs(f64, asin64(-0.2), -0.201358, epsilon));
171 try expect(math.approxEqAbs(f64, asin64(0.3434), 0.350535, epsilon));
172 try expect(math.approxEqAbs(f64, asin64(0.5), 0.523599, epsilon));
173 try expect(math.approxEqAbs(f64, asin64(0.8923), 1.102415, epsilon));
174174}
175175
176176test "math.asin32.special" {
177 expect(asin32(0.0) == 0.0);
178 expect(asin32(-0.0) == -0.0);
179 expect(math.isNan(asin32(-2)));
180 expect(math.isNan(asin32(1.5)));
177 try expect(asin32(0.0) == 0.0);
178 try expect(asin32(-0.0) == -0.0);
179 try expect(math.isNan(asin32(-2)));
180 try expect(math.isNan(asin32(1.5)));
181181}
182182
183183test "math.asin64.special" {
184 expect(asin64(0.0) == 0.0);
185 expect(asin64(-0.0) == -0.0);
186 expect(math.isNan(asin64(-2)));
187 expect(math.isNan(asin64(1.5)));
184 try expect(asin64(0.0) == 0.0);
185 try expect(asin64(-0.0) == -0.0);
186 try expect(math.isNan(asin64(-2)));
187 try expect(math.isNan(asin64(1.5)));
188188}
lib/std/math/asinh.zig+26-26
......@@ -94,46 +94,46 @@ fn asinh64(x: f64) f64 {
9494}
9595
9696test "math.asinh" {
97 expect(asinh(@as(f32, 0.0)) == asinh32(0.0));
98 expect(asinh(@as(f64, 0.0)) == asinh64(0.0));
97 try expect(asinh(@as(f32, 0.0)) == asinh32(0.0));
98 try expect(asinh(@as(f64, 0.0)) == asinh64(0.0));
9999}
100100
101101test "math.asinh32" {
102102 const epsilon = 0.000001;
103103
104 expect(math.approxEqAbs(f32, asinh32(0.0), 0.0, epsilon));
105 expect(math.approxEqAbs(f32, asinh32(0.2), 0.198690, epsilon));
106 expect(math.approxEqAbs(f32, asinh32(0.8923), 0.803133, epsilon));
107 expect(math.approxEqAbs(f32, asinh32(1.5), 1.194763, epsilon));
108 expect(math.approxEqAbs(f32, asinh32(37.45), 4.316332, epsilon));
109 expect(math.approxEqAbs(f32, asinh32(89.123), 5.183196, epsilon));
110 expect(math.approxEqAbs(f32, asinh32(123123.234375), 12.414088, epsilon));
104 try expect(math.approxEqAbs(f32, asinh32(0.0), 0.0, epsilon));
105 try expect(math.approxEqAbs(f32, asinh32(0.2), 0.198690, epsilon));
106 try expect(math.approxEqAbs(f32, asinh32(0.8923), 0.803133, epsilon));
107 try expect(math.approxEqAbs(f32, asinh32(1.5), 1.194763, epsilon));
108 try expect(math.approxEqAbs(f32, asinh32(37.45), 4.316332, epsilon));
109 try expect(math.approxEqAbs(f32, asinh32(89.123), 5.183196, epsilon));
110 try expect(math.approxEqAbs(f32, asinh32(123123.234375), 12.414088, epsilon));
111111}
112112
113113test "math.asinh64" {
114114 const epsilon = 0.000001;
115115
116 expect(math.approxEqAbs(f64, asinh64(0.0), 0.0, epsilon));
117 expect(math.approxEqAbs(f64, asinh64(0.2), 0.198690, epsilon));
118 expect(math.approxEqAbs(f64, asinh64(0.8923), 0.803133, epsilon));
119 expect(math.approxEqAbs(f64, asinh64(1.5), 1.194763, epsilon));
120 expect(math.approxEqAbs(f64, asinh64(37.45), 4.316332, epsilon));
121 expect(math.approxEqAbs(f64, asinh64(89.123), 5.183196, epsilon));
122 expect(math.approxEqAbs(f64, asinh64(123123.234375), 12.414088, epsilon));
116 try expect(math.approxEqAbs(f64, asinh64(0.0), 0.0, epsilon));
117 try expect(math.approxEqAbs(f64, asinh64(0.2), 0.198690, epsilon));
118 try expect(math.approxEqAbs(f64, asinh64(0.8923), 0.803133, epsilon));
119 try expect(math.approxEqAbs(f64, asinh64(1.5), 1.194763, epsilon));
120 try expect(math.approxEqAbs(f64, asinh64(37.45), 4.316332, epsilon));
121 try expect(math.approxEqAbs(f64, asinh64(89.123), 5.183196, epsilon));
122 try expect(math.approxEqAbs(f64, asinh64(123123.234375), 12.414088, epsilon));
123123}
124124
125125test "math.asinh32.special" {
126 expect(asinh32(0.0) == 0.0);
127 expect(asinh32(-0.0) == -0.0);
128 expect(math.isPositiveInf(asinh32(math.inf(f32))));
129 expect(math.isNegativeInf(asinh32(-math.inf(f32))));
130 expect(math.isNan(asinh32(math.nan(f32))));
126 try expect(asinh32(0.0) == 0.0);
127 try expect(asinh32(-0.0) == -0.0);
128 try expect(math.isPositiveInf(asinh32(math.inf(f32))));
129 try expect(math.isNegativeInf(asinh32(-math.inf(f32))));
130 try expect(math.isNan(asinh32(math.nan(f32))));
131131}
132132
133133test "math.asinh64.special" {
134 expect(asinh64(0.0) == 0.0);
135 expect(asinh64(-0.0) == -0.0);
136 expect(math.isPositiveInf(asinh64(math.inf(f64))));
137 expect(math.isNegativeInf(asinh64(-math.inf(f64))));
138 expect(math.isNan(asinh64(math.nan(f64))));
134 try expect(asinh64(0.0) == 0.0);
135 try expect(asinh64(-0.0) == -0.0);
136 try expect(math.isPositiveInf(asinh64(math.inf(f64))));
137 try expect(math.isNegativeInf(asinh64(-math.inf(f64))));
138 try expect(math.isNan(asinh64(math.nan(f64))));
139139}
lib/std/math/atan.zig+20-20
......@@ -217,44 +217,44 @@ fn atan64(x_: f64) f64 {
217217}
218218
219219test "math.atan" {
220 expect(@bitCast(u32, atan(@as(f32, 0.2))) == @bitCast(u32, atan32(0.2)));
221 expect(atan(@as(f64, 0.2)) == atan64(0.2));
220 try expect(@bitCast(u32, atan(@as(f32, 0.2))) == @bitCast(u32, atan32(0.2)));
221 try expect(atan(@as(f64, 0.2)) == atan64(0.2));
222222}
223223
224224test "math.atan32" {
225225 const epsilon = 0.000001;
226226
227 expect(math.approxEqAbs(f32, atan32(0.2), 0.197396, epsilon));
228 expect(math.approxEqAbs(f32, atan32(-0.2), -0.197396, epsilon));
229 expect(math.approxEqAbs(f32, atan32(0.3434), 0.330783, epsilon));
230 expect(math.approxEqAbs(f32, atan32(0.8923), 0.728545, epsilon));
231 expect(math.approxEqAbs(f32, atan32(1.5), 0.982794, epsilon));
227 try expect(math.approxEqAbs(f32, atan32(0.2), 0.197396, epsilon));
228 try expect(math.approxEqAbs(f32, atan32(-0.2), -0.197396, epsilon));
229 try expect(math.approxEqAbs(f32, atan32(0.3434), 0.330783, epsilon));
230 try expect(math.approxEqAbs(f32, atan32(0.8923), 0.728545, epsilon));
231 try expect(math.approxEqAbs(f32, atan32(1.5), 0.982794, epsilon));
232232}
233233
234234test "math.atan64" {
235235 const epsilon = 0.000001;
236236
237 expect(math.approxEqAbs(f64, atan64(0.2), 0.197396, epsilon));
238 expect(math.approxEqAbs(f64, atan64(-0.2), -0.197396, epsilon));
239 expect(math.approxEqAbs(f64, atan64(0.3434), 0.330783, epsilon));
240 expect(math.approxEqAbs(f64, atan64(0.8923), 0.728545, epsilon));
241 expect(math.approxEqAbs(f64, atan64(1.5), 0.982794, epsilon));
237 try expect(math.approxEqAbs(f64, atan64(0.2), 0.197396, epsilon));
238 try expect(math.approxEqAbs(f64, atan64(-0.2), -0.197396, epsilon));
239 try expect(math.approxEqAbs(f64, atan64(0.3434), 0.330783, epsilon));
240 try expect(math.approxEqAbs(f64, atan64(0.8923), 0.728545, epsilon));
241 try expect(math.approxEqAbs(f64, atan64(1.5), 0.982794, epsilon));
242242}
243243
244244test "math.atan32.special" {
245245 const epsilon = 0.000001;
246246
247 expect(atan32(0.0) == 0.0);
248 expect(atan32(-0.0) == -0.0);
249 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));
247 try expect(atan32(0.0) == 0.0);
248 try expect(atan32(-0.0) == -0.0);
249 try 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));
251251}
252252
253253test "math.atan64.special" {
254254 const epsilon = 0.000001;
255255
256 expect(atan64(0.0) == 0.0);
257 expect(atan64(-0.0) == -0.0);
258 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));
256 try expect(atan64(0.0) == 0.0);
257 try expect(atan64(-0.0) == -0.0);
258 try 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));
260260}
lib/std/math/atan2.zig+52-52
......@@ -217,78 +217,78 @@ fn atan2_64(y: f64, x: f64) f64 {
217217}
218218
219219test "math.atan2" {
220 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));
220 try expect(atan2(f32, 0.2, 0.21) == atan2_32(0.2, 0.21));
221 try expect(atan2(f64, 0.2, 0.21) == atan2_64(0.2, 0.21));
222222}
223223
224224test "math.atan2_32" {
225225 const epsilon = 0.000001;
226226
227 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));
229 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));
231 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));
233 expect(math.approxEqAbs(f32, atan2_32(0.34, 1.243), 0.267001, epsilon));
227 try expect(math.approxEqAbs(f32, atan2_32(0.0, 0.0), 0.0, epsilon));
228 try 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 try 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 try expect(math.approxEqAbs(f32, atan2_32(0.34, -0.4), 2.437099, epsilon));
233 try expect(math.approxEqAbs(f32, atan2_32(0.34, 1.243), 0.267001, epsilon));
234234}
235235
236236test "math.atan2_64" {
237237 const epsilon = 0.000001;
238238
239 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));
241 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));
243 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));
245 expect(math.approxEqAbs(f64, atan2_64(0.34, 1.243), 0.267001, epsilon));
239 try expect(math.approxEqAbs(f64, atan2_64(0.0, 0.0), 0.0, epsilon));
240 try 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 try 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 try expect(math.approxEqAbs(f64, atan2_64(0.34, -0.4), 2.437099, epsilon));
245 try expect(math.approxEqAbs(f64, atan2_64(0.34, 1.243), 0.267001, epsilon));
246246}
247247
248248test "math.atan2_32.special" {
249249 const epsilon = 0.000001;
250250
251 expect(math.isNan(atan2_32(1.0, math.nan(f32))));
252 expect(math.isNan(atan2_32(math.nan(f32), 1.0)));
253 expect(atan2_32(0.0, 5.0) == 0.0);
254 expect(atan2_32(-0.0, 5.0) == -0.0);
255 expect(math.approxEqAbs(f32, atan2_32(0.0, -5.0), math.pi, epsilon));
251 try expect(math.isNan(atan2_32(1.0, math.nan(f32))));
252 try expect(math.isNan(atan2_32(math.nan(f32), 1.0)));
253 try expect(atan2_32(0.0, 5.0) == 0.0);
254 try expect(atan2_32(-0.0, 5.0) == -0.0);
255 try expect(math.approxEqAbs(f32, atan2_32(0.0, -5.0), math.pi, epsilon));
256256 //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));
258 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));
260 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));
262 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));
264 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);
266 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));
268 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));
257 try 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 try 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 try 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 try 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 try expect(atan2_32(1.0, math.inf(f32)) == 0.0);
266 try 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 try 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));
270270}
271271
272272test "math.atan2_64.special" {
273273 const epsilon = 0.000001;
274274
275 expect(math.isNan(atan2_64(1.0, math.nan(f64))));
276 expect(math.isNan(atan2_64(math.nan(f64), 1.0)));
277 expect(atan2_64(0.0, 5.0) == 0.0);
278 expect(atan2_64(-0.0, 5.0) == -0.0);
279 expect(math.approxEqAbs(f64, atan2_64(0.0, -5.0), math.pi, epsilon));
275 try expect(math.isNan(atan2_64(1.0, math.nan(f64))));
276 try expect(math.isNan(atan2_64(math.nan(f64), 1.0)));
277 try expect(atan2_64(0.0, 5.0) == 0.0);
278 try expect(atan2_64(-0.0, 5.0) == -0.0);
279 try expect(math.approxEqAbs(f64, atan2_64(0.0, -5.0), math.pi, epsilon));
280280 //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));
282 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));
284 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));
286 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));
288 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);
290 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));
292 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));
281 try 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 try 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 try 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 try 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 try expect(atan2_64(1.0, math.inf(f64)) == 0.0);
290 try 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 try 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));
294294}
lib/std/math/atanh.zig+18-18
......@@ -89,38 +89,38 @@ fn atanh_64(x: f64) f64 {
8989}
9090
9191test "math.atanh" {
92 expect(atanh(@as(f32, 0.0)) == atanh_32(0.0));
93 expect(atanh(@as(f64, 0.0)) == atanh_64(0.0));
92 try expect(atanh(@as(f32, 0.0)) == atanh_32(0.0));
93 try expect(atanh(@as(f64, 0.0)) == atanh_64(0.0));
9494}
9595
9696test "math.atanh_32" {
9797 const epsilon = 0.000001;
9898
99 expect(math.approxEqAbs(f32, atanh_32(0.0), 0.0, epsilon));
100 expect(math.approxEqAbs(f32, atanh_32(0.2), 0.202733, epsilon));
101 expect(math.approxEqAbs(f32, atanh_32(0.8923), 1.433099, epsilon));
99 try expect(math.approxEqAbs(f32, atanh_32(0.0), 0.0, epsilon));
100 try expect(math.approxEqAbs(f32, atanh_32(0.2), 0.202733, epsilon));
101 try expect(math.approxEqAbs(f32, atanh_32(0.8923), 1.433099, epsilon));
102102}
103103
104104test "math.atanh_64" {
105105 const epsilon = 0.000001;
106106
107 expect(math.approxEqAbs(f64, atanh_64(0.0), 0.0, epsilon));
108 expect(math.approxEqAbs(f64, atanh_64(0.2), 0.202733, epsilon));
109 expect(math.approxEqAbs(f64, atanh_64(0.8923), 1.433099, epsilon));
107 try expect(math.approxEqAbs(f64, atanh_64(0.0), 0.0, epsilon));
108 try expect(math.approxEqAbs(f64, atanh_64(0.2), 0.202733, epsilon));
109 try expect(math.approxEqAbs(f64, atanh_64(0.8923), 1.433099, epsilon));
110110}
111111
112112test "math.atanh32.special" {
113 expect(math.isPositiveInf(atanh_32(1)));
114 expect(math.isNegativeInf(atanh_32(-1)));
115 expect(math.isSignalNan(atanh_32(1.5)));
116 expect(math.isSignalNan(atanh_32(-1.5)));
117 expect(math.isNan(atanh_32(math.nan(f32))));
113 try expect(math.isPositiveInf(atanh_32(1)));
114 try expect(math.isNegativeInf(atanh_32(-1)));
115 try expect(math.isSignalNan(atanh_32(1.5)));
116 try expect(math.isSignalNan(atanh_32(-1.5)));
117 try expect(math.isNan(atanh_32(math.nan(f32))));
118118}
119119
120120test "math.atanh64.special" {
121 expect(math.isPositiveInf(atanh_64(1)));
122 expect(math.isNegativeInf(atanh_64(-1)));
123 expect(math.isSignalNan(atanh_64(1.5)));
124 expect(math.isSignalNan(atanh_64(-1.5)));
125 expect(math.isNan(atanh_64(math.nan(f64))));
121 try expect(math.isPositiveInf(atanh_64(1)));
122 try expect(math.isNegativeInf(atanh_64(-1)));
123 try expect(math.isSignalNan(atanh_64(1.5)));
124 try expect(math.isSignalNan(atanh_64(-1.5)));
125 try expect(math.isNan(atanh_64(math.nan(f64))));
126126}
lib/std/math/big/int_test.zig+211-211
......@@ -30,7 +30,7 @@ test "big.int comptime_int set" {
3030 const result = @as(Limb, s & maxInt(Limb));
3131 s >>= @typeInfo(Limb).Int.bits / 2;
3232 s >>= @typeInfo(Limb).Int.bits / 2;
33 testing.expect(a.limbs[i] == result);
33 try testing.expect(a.limbs[i] == result);
3434 }
3535}
3636
......@@ -38,37 +38,37 @@ test "big.int comptime_int set negative" {
3838 var a = try Managed.initSet(testing.allocator, -10);
3939 defer a.deinit();
4040
41 testing.expect(a.limbs[0] == 10);
42 testing.expect(a.isPositive() == false);
41 try testing.expect(a.limbs[0] == 10);
42 try testing.expect(a.isPositive() == false);
4343}
4444
4545test "big.int int set unaligned small" {
4646 var a = try Managed.initSet(testing.allocator, @as(u7, 45));
4747 defer a.deinit();
4848
49 testing.expect(a.limbs[0] == 45);
50 testing.expect(a.isPositive() == true);
49 try testing.expect(a.limbs[0] == 45);
50 try testing.expect(a.isPositive() == true);
5151}
5252
5353test "big.int comptime_int to" {
5454 var a = try Managed.initSet(testing.allocator, 0xefffffff00000001eeeeeeefaaaaaaab);
5555 defer a.deinit();
5656
57 testing.expect((try a.to(u128)) == 0xefffffff00000001eeeeeeefaaaaaaab);
57 try testing.expect((try a.to(u128)) == 0xefffffff00000001eeeeeeefaaaaaaab);
5858}
5959
6060test "big.int sub-limb to" {
6161 var a = try Managed.initSet(testing.allocator, 10);
6262 defer a.deinit();
6363
64 testing.expect((try a.to(u8)) == 10);
64 try testing.expect((try a.to(u8)) == 10);
6565}
6666
6767test "big.int to target too small error" {
6868 var a = try Managed.initSet(testing.allocator, 0xffffffff);
6969 defer a.deinit();
7070
71 testing.expectError(error.TargetTooSmall, a.to(u8));
71 try testing.expectError(error.TargetTooSmall, a.to(u8));
7272}
7373
7474test "big.int normalize" {
......@@ -81,22 +81,22 @@ test "big.int normalize" {
8181 a.limbs[2] = 3;
8282 a.limbs[3] = 0;
8383 a.normalize(4);
84 testing.expect(a.len() == 3);
84 try testing.expect(a.len() == 3);
8585
8686 a.limbs[0] = 1;
8787 a.limbs[1] = 2;
8888 a.limbs[2] = 3;
8989 a.normalize(3);
90 testing.expect(a.len() == 3);
90 try testing.expect(a.len() == 3);
9191
9292 a.limbs[0] = 0;
9393 a.limbs[1] = 0;
9494 a.normalize(2);
95 testing.expect(a.len() == 1);
95 try testing.expect(a.len() == 1);
9696
9797 a.limbs[0] = 0;
9898 a.normalize(1);
99 testing.expect(a.len() == 1);
99 try testing.expect(a.len() == 1);
100100}
101101
102102test "big.int normalize multi" {
......@@ -109,24 +109,24 @@ test "big.int normalize multi" {
109109 a.limbs[2] = 0;
110110 a.limbs[3] = 0;
111111 a.normalize(4);
112 testing.expect(a.len() == 2);
112 try testing.expect(a.len() == 2);
113113
114114 a.limbs[0] = 1;
115115 a.limbs[1] = 2;
116116 a.limbs[2] = 3;
117117 a.normalize(3);
118 testing.expect(a.len() == 3);
118 try testing.expect(a.len() == 3);
119119
120120 a.limbs[0] = 0;
121121 a.limbs[1] = 0;
122122 a.limbs[2] = 0;
123123 a.limbs[3] = 0;
124124 a.normalize(4);
125 testing.expect(a.len() == 1);
125 try testing.expect(a.len() == 1);
126126
127127 a.limbs[0] = 0;
128128 a.normalize(1);
129 testing.expect(a.len() == 1);
129 try testing.expect(a.len() == 1);
130130}
131131
132132test "big.int parity" {
......@@ -134,12 +134,12 @@ test "big.int parity" {
134134 defer a.deinit();
135135
136136 try a.set(0);
137 testing.expect(a.isEven());
138 testing.expect(!a.isOdd());
137 try testing.expect(a.isEven());
138 try testing.expect(!a.isOdd());
139139
140140 try a.set(7);
141 testing.expect(!a.isEven());
142 testing.expect(a.isOdd());
141 try testing.expect(!a.isEven());
142 try testing.expect(a.isOdd());
143143}
144144
145145test "big.int bitcount + sizeInBaseUpperBound" {
......@@ -147,27 +147,27 @@ test "big.int bitcount + sizeInBaseUpperBound" {
147147 defer a.deinit();
148148
149149 try a.set(0b100);
150 testing.expect(a.bitCountAbs() == 3);
151 testing.expect(a.sizeInBaseUpperBound(2) >= 3);
152 testing.expect(a.sizeInBaseUpperBound(10) >= 1);
150 try testing.expect(a.bitCountAbs() == 3);
151 try testing.expect(a.sizeInBaseUpperBound(2) >= 3);
152 try testing.expect(a.sizeInBaseUpperBound(10) >= 1);
153153
154154 a.negate();
155 testing.expect(a.bitCountAbs() == 3);
156 testing.expect(a.sizeInBaseUpperBound(2) >= 4);
157 testing.expect(a.sizeInBaseUpperBound(10) >= 2);
155 try testing.expect(a.bitCountAbs() == 3);
156 try testing.expect(a.sizeInBaseUpperBound(2) >= 4);
157 try testing.expect(a.sizeInBaseUpperBound(10) >= 2);
158158
159159 try a.set(0xffffffff);
160 testing.expect(a.bitCountAbs() == 32);
161 testing.expect(a.sizeInBaseUpperBound(2) >= 32);
162 testing.expect(a.sizeInBaseUpperBound(10) >= 10);
160 try testing.expect(a.bitCountAbs() == 32);
161 try testing.expect(a.sizeInBaseUpperBound(2) >= 32);
162 try testing.expect(a.sizeInBaseUpperBound(10) >= 10);
163163
164164 try a.shiftLeft(a, 5000);
165 testing.expect(a.bitCountAbs() == 5032);
166 testing.expect(a.sizeInBaseUpperBound(2) >= 5032);
165 try testing.expect(a.bitCountAbs() == 5032);
166 try testing.expect(a.sizeInBaseUpperBound(2) >= 5032);
167167 a.setSign(false);
168168
169 testing.expect(a.bitCountAbs() == 5032);
170 testing.expect(a.sizeInBaseUpperBound(2) >= 5033);
169 try testing.expect(a.bitCountAbs() == 5032);
170 try testing.expect(a.sizeInBaseUpperBound(2) >= 5033);
171171}
172172
173173test "big.int bitcount/to" {
......@@ -175,30 +175,30 @@ test "big.int bitcount/to" {
175175 defer a.deinit();
176176
177177 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);
181 testing.expect((try a.to(i0)) == 0);
180 try testing.expect((try a.to(u0)) == 0);
181 try testing.expect((try a.to(i0)) == 0);
182182
183183 try a.set(-1);
184 testing.expect(a.bitCountTwosComp() == 1);
185 testing.expect((try a.to(i1)) == -1);
184 try testing.expect(a.bitCountTwosComp() == 1);
185 try testing.expect((try a.to(i1)) == -1);
186186
187187 try a.set(-8);
188 testing.expect(a.bitCountTwosComp() == 4);
189 testing.expect((try a.to(i4)) == -8);
188 try testing.expect(a.bitCountTwosComp() == 4);
189 try testing.expect((try a.to(i4)) == -8);
190190
191191 try a.set(127);
192 testing.expect(a.bitCountTwosComp() == 7);
193 testing.expect((try a.to(u7)) == 127);
192 try testing.expect(a.bitCountTwosComp() == 7);
193 try testing.expect((try a.to(u7)) == 127);
194194
195195 try a.set(-128);
196 testing.expect(a.bitCountTwosComp() == 8);
197 testing.expect((try a.to(i8)) == -128);
196 try testing.expect(a.bitCountTwosComp() == 8);
197 try testing.expect((try a.to(i8)) == -128);
198198
199199 try a.set(-129);
200 testing.expect(a.bitCountTwosComp() == 9);
201 testing.expect((try a.to(i9)) == -129);
200 try testing.expect(a.bitCountTwosComp() == 9);
201 try testing.expect((try a.to(i9)) == -129);
202202}
203203
204204test "big.int fits" {
......@@ -206,27 +206,27 @@ test "big.int fits" {
206206 defer a.deinit();
207207
208208 try a.set(0);
209 testing.expect(a.fits(u0));
210 testing.expect(a.fits(i0));
209 try testing.expect(a.fits(u0));
210 try testing.expect(a.fits(i0));
211211
212212 try a.set(255);
213 testing.expect(!a.fits(u0));
214 testing.expect(!a.fits(u1));
215 testing.expect(!a.fits(i8));
216 testing.expect(a.fits(u8));
217 testing.expect(a.fits(u9));
218 testing.expect(a.fits(i9));
213 try testing.expect(!a.fits(u0));
214 try testing.expect(!a.fits(u1));
215 try testing.expect(!a.fits(i8));
216 try testing.expect(a.fits(u8));
217 try testing.expect(a.fits(u9));
218 try testing.expect(a.fits(i9));
219219
220220 try a.set(-128);
221 testing.expect(!a.fits(i7));
222 testing.expect(a.fits(i8));
223 testing.expect(a.fits(i9));
224 testing.expect(!a.fits(u9));
221 try testing.expect(!a.fits(i7));
222 try testing.expect(a.fits(i8));
223 try testing.expect(a.fits(i9));
224 try testing.expect(!a.fits(u9));
225225
226226 try a.set(0x1ffffffffeeeeeeee);
227 testing.expect(!a.fits(u32));
228 testing.expect(!a.fits(u64));
229 testing.expect(a.fits(u65));
227 try testing.expect(!a.fits(u32));
228 try testing.expect(!a.fits(u64));
229 try testing.expect(a.fits(u65));
230230}
231231
232232test "big.int string set" {
......@@ -234,7 +234,7 @@ test "big.int string set" {
234234 defer a.deinit();
235235
236236 try a.setString(10, "120317241209124781241290847124");
237 testing.expect((try a.to(u128)) == 120317241209124781241290847124);
237 try testing.expect((try a.to(u128)) == 120317241209124781241290847124);
238238}
239239
240240test "big.int string negative" {
......@@ -242,7 +242,7 @@ test "big.int string negative" {
242242 defer a.deinit();
243243
244244 try a.setString(10, "-1023");
245 testing.expect((try a.to(i32)) == -1023);
245 try testing.expect((try a.to(i32)) == -1023);
246246}
247247
248248test "big.int string set number with underscores" {
......@@ -250,7 +250,7 @@ test "big.int string set number with underscores" {
250250 defer a.deinit();
251251
252252 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);
254254}
255255
256256test "big.int string set case insensitive number" {
......@@ -258,19 +258,19 @@ test "big.int string set case insensitive number" {
258258 defer a.deinit();
259259
260260 try a.setString(16, "aB_cD_eF");
261 testing.expect((try a.to(u32)) == 0xabcdef);
261 try testing.expect((try a.to(u32)) == 0xabcdef);
262262}
263263
264264test "big.int string set bad char error" {
265265 var a = try Managed.init(testing.allocator);
266266 defer a.deinit();
267 testing.expectError(error.InvalidCharacter, a.setString(10, "x"));
267 try testing.expectError(error.InvalidCharacter, a.setString(10, "x"));
268268}
269269
270270test "big.int string set bad base error" {
271271 var a = try Managed.init(testing.allocator);
272272 defer a.deinit();
273 testing.expectError(error.InvalidBase, a.setString(45, "10"));
273 try testing.expectError(error.InvalidBase, a.setString(45, "10"));
274274}
275275
276276test "big.int string to" {
......@@ -281,14 +281,14 @@ test "big.int string to" {
281281 defer testing.allocator.free(as);
282282 const es = "120317241209124781241290847124";
283283
284 testing.expect(mem.eql(u8, as, es));
284 try testing.expect(mem.eql(u8, as, es));
285285}
286286
287287test "big.int string to base base error" {
288288 var a = try Managed.initSet(testing.allocator, 0xffffffff);
289289 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));
292292}
293293
294294test "big.int string to base 2" {
......@@ -299,7 +299,7 @@ test "big.int string to base 2" {
299299 defer testing.allocator.free(as);
300300 const es = "-1011";
301301
302 testing.expect(mem.eql(u8, as, es));
302 try testing.expect(mem.eql(u8, as, es));
303303}
304304
305305test "big.int string to base 16" {
......@@ -310,7 +310,7 @@ test "big.int string to base 16" {
310310 defer testing.allocator.free(as);
311311 const es = "efffffff00000001eeeeeeefaaaaaaab";
312312
313 testing.expect(mem.eql(u8, as, es));
313 try testing.expect(mem.eql(u8, as, es));
314314}
315315
316316test "big.int neg string to" {
......@@ -321,7 +321,7 @@ test "big.int neg string to" {
321321 defer testing.allocator.free(as);
322322 const es = "-123907434";
323323
324 testing.expect(mem.eql(u8, as, es));
324 try testing.expect(mem.eql(u8, as, es));
325325}
326326
327327test "big.int zero string to" {
......@@ -332,7 +332,7 @@ test "big.int zero string to" {
332332 defer testing.allocator.free(as);
333333 const es = "0";
334334
335 testing.expect(mem.eql(u8, as, es));
335 try testing.expect(mem.eql(u8, as, es));
336336}
337337
338338test "big.int clone" {
......@@ -341,12 +341,12 @@ test "big.int clone" {
341341 var b = try a.clone();
342342 defer b.deinit();
343343
344 testing.expect((try a.to(u32)) == 1234);
345 testing.expect((try b.to(u32)) == 1234);
344 try testing.expect((try a.to(u32)) == 1234);
345 try testing.expect((try b.to(u32)) == 1234);
346346
347347 try a.set(77);
348 testing.expect((try a.to(u32)) == 77);
349 testing.expect((try b.to(u32)) == 1234);
348 try testing.expect((try a.to(u32)) == 77);
349 try testing.expect((try b.to(u32)) == 1234);
350350}
351351
352352test "big.int swap" {
......@@ -355,20 +355,20 @@ test "big.int swap" {
355355 var b = try Managed.initSet(testing.allocator, 5678);
356356 defer b.deinit();
357357
358 testing.expect((try a.to(u32)) == 1234);
359 testing.expect((try b.to(u32)) == 5678);
358 try testing.expect((try a.to(u32)) == 1234);
359 try testing.expect((try b.to(u32)) == 5678);
360360
361361 a.swap(&b);
362362
363 testing.expect((try a.to(u32)) == 5678);
364 testing.expect((try b.to(u32)) == 1234);
363 try testing.expect((try a.to(u32)) == 5678);
364 try testing.expect((try b.to(u32)) == 1234);
365365}
366366
367367test "big.int to negative" {
368368 var a = try Managed.initSet(testing.allocator, -10);
369369 defer a.deinit();
370370
371 testing.expect((try a.to(i32)) == -10);
371 try testing.expect((try a.to(i32)) == -10);
372372}
373373
374374test "big.int compare" {
......@@ -377,8 +377,8 @@ test "big.int compare" {
377377 var b = try Managed.initSet(testing.allocator, 10);
378378 defer b.deinit();
379379
380 testing.expect(a.orderAbs(b) == .gt);
381 testing.expect(a.order(b) == .lt);
380 try testing.expect(a.orderAbs(b) == .gt);
381 try testing.expect(a.order(b) == .lt);
382382}
383383
384384test "big.int compare similar" {
......@@ -387,8 +387,8 @@ test "big.int compare similar" {
387387 var b = try Managed.initSet(testing.allocator, 0xffffffffeeeeeeeeffffffffeeeeeeef);
388388 defer b.deinit();
389389
390 testing.expect(a.orderAbs(b) == .lt);
391 testing.expect(b.orderAbs(a) == .gt);
390 try testing.expect(a.orderAbs(b) == .lt);
391 try testing.expect(b.orderAbs(a) == .gt);
392392}
393393
394394test "big.int compare different limb size" {
......@@ -397,8 +397,8 @@ test "big.int compare different limb size" {
397397 var b = try Managed.initSet(testing.allocator, 1);
398398 defer b.deinit();
399399
400 testing.expect(a.orderAbs(b) == .gt);
401 testing.expect(b.orderAbs(a) == .lt);
400 try testing.expect(a.orderAbs(b) == .gt);
401 try testing.expect(b.orderAbs(a) == .lt);
402402}
403403
404404test "big.int compare multi-limb" {
......@@ -407,8 +407,8 @@ test "big.int compare multi-limb" {
407407 var b = try Managed.initSet(testing.allocator, 0x7777777799999999ffffeeeeffffeeeeffffeeeee);
408408 defer b.deinit();
409409
410 testing.expect(a.orderAbs(b) == .gt);
411 testing.expect(a.order(b) == .lt);
410 try testing.expect(a.orderAbs(b) == .gt);
411 try testing.expect(a.order(b) == .lt);
412412}
413413
414414test "big.int equality" {
......@@ -417,8 +417,8 @@ test "big.int equality" {
417417 var b = try Managed.initSet(testing.allocator, -0xffffffff1);
418418 defer b.deinit();
419419
420 testing.expect(a.eqAbs(b));
421 testing.expect(!a.eq(b));
420 try testing.expect(a.eqAbs(b));
421 try testing.expect(!a.eq(b));
422422}
423423
424424test "big.int abs" {
......@@ -426,10 +426,10 @@ test "big.int abs" {
426426 defer a.deinit();
427427
428428 a.abs();
429 testing.expect((try a.to(u32)) == 5);
429 try testing.expect((try a.to(u32)) == 5);
430430
431431 a.abs();
432 testing.expect((try a.to(u32)) == 5);
432 try testing.expect((try a.to(u32)) == 5);
433433}
434434
435435test "big.int negate" {
......@@ -437,10 +437,10 @@ test "big.int negate" {
437437 defer a.deinit();
438438
439439 a.negate();
440 testing.expect((try a.to(i32)) == -5);
440 try testing.expect((try a.to(i32)) == -5);
441441
442442 a.negate();
443 testing.expect((try a.to(i32)) == 5);
443 try testing.expect((try a.to(i32)) == 5);
444444}
445445
446446test "big.int add single-single" {
......@@ -453,7 +453,7 @@ test "big.int add single-single" {
453453 defer c.deinit();
454454 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);
457457}
458458
459459test "big.int add multi-single" {
......@@ -466,10 +466,10 @@ test "big.int add multi-single" {
466466 defer c.deinit();
467467
468468 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
471471 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);
473473}
474474
475475test "big.int add multi-multi" {
......@@ -484,7 +484,7 @@ test "big.int add multi-multi" {
484484 defer c.deinit();
485485 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);
488488}
489489
490490test "big.int add zero-zero" {
......@@ -497,7 +497,7 @@ test "big.int add zero-zero" {
497497 defer c.deinit();
498498 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);
501501}
502502
503503test "big.int add alias multi-limb nonzero-zero" {
......@@ -509,7 +509,7 @@ test "big.int add alias multi-limb nonzero-zero" {
509509
510510 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);
513513}
514514
515515test "big.int add sign" {
......@@ -526,16 +526,16 @@ test "big.int add sign" {
526526 defer neg_two.deinit();
527527
528528 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
531531 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
534534 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
537537 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);
539539}
540540
541541test "big.int sub single-single" {
......@@ -548,7 +548,7 @@ test "big.int sub single-single" {
548548 defer c.deinit();
549549 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);
552552}
553553
554554test "big.int sub multi-single" {
......@@ -561,7 +561,7 @@ test "big.int sub multi-single" {
561561 defer c.deinit();
562562 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));
565565}
566566
567567test "big.int sub multi-multi" {
......@@ -577,7 +577,7 @@ test "big.int sub multi-multi" {
577577 defer c.deinit();
578578 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);
581581}
582582
583583test "big.int sub equal" {
......@@ -590,7 +590,7 @@ test "big.int sub equal" {
590590 defer c.deinit();
591591 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);
594594}
595595
596596test "big.int sub sign" {
......@@ -607,19 +607,19 @@ test "big.int sub sign" {
607607 defer neg_two.deinit();
608608
609609 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
612612 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
615615 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
618618 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
621621 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);
623623}
624624
625625test "big.int mul single-single" {
......@@ -632,7 +632,7 @@ test "big.int mul single-single" {
632632 defer c.deinit();
633633 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);
636636}
637637
638638test "big.int mul multi-single" {
......@@ -645,7 +645,7 @@ test "big.int mul multi-single" {
645645 defer c.deinit();
646646 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));
649649}
650650
651651test "big.int mul multi-multi" {
......@@ -660,7 +660,7 @@ test "big.int mul multi-multi" {
660660 defer c.deinit();
661661 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);
664664}
665665
666666test "big.int mul alias r with a" {
......@@ -671,7 +671,7 @@ test "big.int mul alias r with a" {
671671
672672 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));
675675}
676676
677677test "big.int mul alias r with b" {
......@@ -682,7 +682,7 @@ test "big.int mul alias r with b" {
682682
683683 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));
686686}
687687
688688test "big.int mul alias r with a and b" {
......@@ -691,7 +691,7 @@ test "big.int mul alias r with a and b" {
691691
692692 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));
695695}
696696
697697test "big.int mul a*0" {
......@@ -704,7 +704,7 @@ test "big.int mul a*0" {
704704 defer c.deinit();
705705 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);
708708}
709709
710710test "big.int mul 0*0" {
......@@ -717,7 +717,7 @@ test "big.int mul 0*0" {
717717 defer c.deinit();
718718 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);
721721}
722722
723723test "big.int mul large" {
......@@ -738,7 +738,7 @@ test "big.int mul large" {
738738 try b.mul(a.toConst(), a.toConst());
739739 try c.sqr(a.toConst());
740740
741 testing.expect(b.eq(c));
741 try testing.expect(b.eq(c));
742742}
743743
744744test "big.int div single-single no rem" {
......@@ -753,8 +753,8 @@ test "big.int div single-single no rem" {
753753 defer r.deinit();
754754 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
755755
756 testing.expect((try q.to(u32)) == 10);
757 testing.expect((try r.to(u32)) == 0);
756 try testing.expect((try q.to(u32)) == 10);
757 try testing.expect((try r.to(u32)) == 0);
758758}
759759
760760test "big.int div single-single with rem" {
......@@ -769,8 +769,8 @@ test "big.int div single-single with rem" {
769769 defer r.deinit();
770770 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
771771
772 testing.expect((try q.to(u32)) == 9);
773 testing.expect((try r.to(u32)) == 4);
772 try testing.expect((try q.to(u32)) == 9);
773 try testing.expect((try r.to(u32)) == 4);
774774}
775775
776776test "big.int div multi-single no rem" {
......@@ -788,8 +788,8 @@ test "big.int div multi-single no rem" {
788788 defer r.deinit();
789789 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
790790
791 testing.expect((try q.to(u64)) == op1 / op2);
792 testing.expect((try r.to(u64)) == 0);
791 try testing.expect((try q.to(u64)) == op1 / op2);
792 try testing.expect((try r.to(u64)) == 0);
793793}
794794
795795test "big.int div multi-single with rem" {
......@@ -807,8 +807,8 @@ test "big.int div multi-single with rem" {
807807 defer r.deinit();
808808 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
809809
810 testing.expect((try q.to(u64)) == op1 / op2);
811 testing.expect((try r.to(u64)) == 3);
810 try testing.expect((try q.to(u64)) == op1 / op2);
811 try testing.expect((try r.to(u64)) == 3);
812812}
813813
814814test "big.int div multi>2-single" {
......@@ -826,8 +826,8 @@ test "big.int div multi>2-single" {
826826 defer r.deinit();
827827 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
828828
829 testing.expect((try q.to(u128)) == op1 / op2);
830 testing.expect((try r.to(u32)) == 0x3e4e);
829 try testing.expect((try q.to(u128)) == op1 / op2);
830 try testing.expect((try r.to(u32)) == 0x3e4e);
831831}
832832
833833test "big.int div single-single q < r" {
......@@ -842,8 +842,8 @@ test "big.int div single-single q < r" {
842842 defer r.deinit();
843843 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
844844
845 testing.expect((try q.to(u64)) == 0);
846 testing.expect((try r.to(u64)) == 0x0078f432);
845 try testing.expect((try q.to(u64)) == 0);
846 try testing.expect((try r.to(u64)) == 0x0078f432);
847847}
848848
849849test "big.int div single-single q == r" {
......@@ -858,8 +858,8 @@ test "big.int div single-single q == r" {
858858 defer r.deinit();
859859 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
860860
861 testing.expect((try q.to(u64)) == 1);
862 testing.expect((try r.to(u64)) == 0);
861 try testing.expect((try q.to(u64)) == 1);
862 try testing.expect((try r.to(u64)) == 0);
863863}
864864
865865test "big.int div q=0 alias" {
......@@ -870,8 +870,8 @@ test "big.int div q=0 alias" {
870870
871871 try Managed.divTrunc(&a, &b, a.toConst(), b.toConst());
872872
873 testing.expect((try a.to(u64)) == 0);
874 testing.expect((try b.to(u64)) == 3);
873 try testing.expect((try a.to(u64)) == 0);
874 try testing.expect((try b.to(u64)) == 3);
875875}
876876
877877test "big.int div multi-multi q < r" {
......@@ -888,8 +888,8 @@ test "big.int div multi-multi q < r" {
888888 defer r.deinit();
889889 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
890890
891 testing.expect((try q.to(u128)) == 0);
892 testing.expect((try r.to(u128)) == op1);
891 try testing.expect((try q.to(u128)) == 0);
892 try testing.expect((try r.to(u128)) == op1);
893893}
894894
895895test "big.int div trunc single-single +/+" {
......@@ -912,8 +912,8 @@ test "big.int div trunc single-single +/+" {
912912 const eq = @divTrunc(u, v);
913913 const er = @mod(u, v);
914914
915 testing.expect((try q.to(i32)) == eq);
916 testing.expect((try r.to(i32)) == er);
915 try testing.expect((try q.to(i32)) == eq);
916 try testing.expect((try r.to(i32)) == er);
917917}
918918
919919test "big.int div trunc single-single -/+" {
......@@ -936,8 +936,8 @@ test "big.int div trunc single-single -/+" {
936936 const eq = -1;
937937 const er = -2;
938938
939 testing.expect((try q.to(i32)) == eq);
940 testing.expect((try r.to(i32)) == er);
939 try testing.expect((try q.to(i32)) == eq);
940 try testing.expect((try r.to(i32)) == er);
941941}
942942
943943test "big.int div trunc single-single +/-" {
......@@ -960,8 +960,8 @@ test "big.int div trunc single-single +/-" {
960960 const eq = -1;
961961 const er = 2;
962962
963 testing.expect((try q.to(i32)) == eq);
964 testing.expect((try r.to(i32)) == er);
963 try testing.expect((try q.to(i32)) == eq);
964 try testing.expect((try r.to(i32)) == er);
965965}
966966
967967test "big.int div trunc single-single -/-" {
......@@ -984,8 +984,8 @@ test "big.int div trunc single-single -/-" {
984984 const eq = 1;
985985 const er = -2;
986986
987 testing.expect((try q.to(i32)) == eq);
988 testing.expect((try r.to(i32)) == er);
987 try testing.expect((try q.to(i32)) == eq);
988 try testing.expect((try r.to(i32)) == er);
989989}
990990
991991test "big.int div floor single-single +/+" {
......@@ -1008,8 +1008,8 @@ test "big.int div floor single-single +/+" {
10081008 const eq = 1;
10091009 const er = 2;
10101010
1011 testing.expect((try q.to(i32)) == eq);
1012 testing.expect((try r.to(i32)) == er);
1011 try testing.expect((try q.to(i32)) == eq);
1012 try testing.expect((try r.to(i32)) == er);
10131013}
10141014
10151015test "big.int div floor single-single -/+" {
......@@ -1032,8 +1032,8 @@ test "big.int div floor single-single -/+" {
10321032 const eq = -2;
10331033 const er = 1;
10341034
1035 testing.expect((try q.to(i32)) == eq);
1036 testing.expect((try r.to(i32)) == er);
1035 try testing.expect((try q.to(i32)) == eq);
1036 try testing.expect((try r.to(i32)) == er);
10371037}
10381038
10391039test "big.int div floor single-single +/-" {
......@@ -1056,8 +1056,8 @@ test "big.int div floor single-single +/-" {
10561056 const eq = -2;
10571057 const er = -1;
10581058
1059 testing.expect((try q.to(i32)) == eq);
1060 testing.expect((try r.to(i32)) == er);
1059 try testing.expect((try q.to(i32)) == eq);
1060 try testing.expect((try r.to(i32)) == er);
10611061}
10621062
10631063test "big.int div floor single-single -/-" {
......@@ -1080,8 +1080,8 @@ test "big.int div floor single-single -/-" {
10801080 const eq = 1;
10811081 const er = -2;
10821082
1083 testing.expect((try q.to(i32)) == eq);
1084 testing.expect((try r.to(i32)) == er);
1083 try testing.expect((try q.to(i32)) == eq);
1084 try testing.expect((try r.to(i32)) == er);
10851085}
10861086
10871087test "big.int div multi-multi with rem" {
......@@ -1096,8 +1096,8 @@ test "big.int div multi-multi with rem" {
10961096 defer r.deinit();
10971097 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
10981098
1099 testing.expect((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b);
1100 testing.expect((try r.to(u128)) == 0x28de0acacd806823638);
1099 try testing.expect((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b);
1100 try testing.expect((try r.to(u128)) == 0x28de0acacd806823638);
11011101}
11021102
11031103test "big.int div multi-multi no rem" {
......@@ -1112,8 +1112,8 @@ test "big.int div multi-multi no rem" {
11121112 defer r.deinit();
11131113 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
11141114
1115 testing.expect((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b);
1116 testing.expect((try r.to(u128)) == 0);
1115 try testing.expect((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b);
1116 try testing.expect((try r.to(u128)) == 0);
11171117}
11181118
11191119test "big.int div multi-multi (2 branch)" {
......@@ -1128,8 +1128,8 @@ test "big.int div multi-multi (2 branch)" {
11281128 defer r.deinit();
11291129 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
11301130
1131 testing.expect((try q.to(u128)) == 0x10000000000000000);
1132 testing.expect((try r.to(u128)) == 0x44444443444444431111111111111111);
1131 try testing.expect((try q.to(u128)) == 0x10000000000000000);
1132 try testing.expect((try r.to(u128)) == 0x44444443444444431111111111111111);
11331133}
11341134
11351135test "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)" {
11441144 defer r.deinit();
11451145 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
11461146
1147 testing.expect((try q.to(u128)) == 0xfffffffffffffffffff);
1148 testing.expect((try r.to(u256)) == 0x1111111111111111111110b12222222222222222282);
1147 try testing.expect((try q.to(u128)) == 0xfffffffffffffffffff);
1148 try testing.expect((try r.to(u256)) == 0x1111111111111111111110b12222222222222222282);
11491149}
11501150
11511151test "big.int div multi-single zero-limb trailing" {
......@@ -1162,8 +1162,8 @@ test "big.int div multi-single zero-limb trailing" {
11621162
11631163 var expected = try Managed.initSet(testing.allocator, 0x6000000000000000000000000000000000000000000000000);
11641164 defer expected.deinit();
1165 testing.expect(q.eq(expected));
1166 testing.expect(r.eqZero());
1165 try testing.expect(q.eq(expected));
1166 try testing.expect(r.eqZero());
11671167}
11681168
11691169test "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)" {
11781178 defer r.deinit();
11791179 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
11831183 const rs = try r.toString(testing.allocator, 16, false);
11841184 defer testing.allocator.free(rs);
1185 testing.expect(std.mem.eql(u8, rs, "4444444344444443111111111111111100000000000000000000000000000000"));
1185 try testing.expect(std.mem.eql(u8, rs, "4444444344444443111111111111111100000000000000000000000000000000"));
11861186}
11871187
11881188test "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
11971197 defer r.deinit();
11981198 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
12021202 const rs = try r.toString(testing.allocator, 16, false);
12031203 defer testing.allocator.free(rs);
1204 testing.expect(std.mem.eql(u8, rs, "444444434444444311111111111111110000000000000000"));
1204 try testing.expect(std.mem.eql(u8, rs, "444444434444444311111111111111110000000000000000"));
12051205}
12061206
12071207test "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
12181218
12191219 const qs = try q.toString(testing.allocator, 16, false);
12201220 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
12231223 const rs = try r.toString(testing.allocator, 16, false);
12241224 defer testing.allocator.free(rs);
1225 testing.expect(std.mem.eql(u8, rs, "4e11f2baa5896a321d463b543d0104e30000000000000000"));
1225 try testing.expect(std.mem.eql(u8, rs, "4e11f2baa5896a321d463b543d0104e30000000000000000"));
12261226}
12271227
12281228test "big.int div multi-multi fuzz case #1" {
......@@ -1242,11 +1242,11 @@ test "big.int div multi-multi fuzz case #1" {
12421242
12431243 const qs = try q.toString(testing.allocator, 16, false);
12441244 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
12471247 const rs = try r.toString(testing.allocator, 16, false);
12481248 defer testing.allocator.free(rs);
1249 testing.expect(std.mem.eql(u8, rs, "310d1d4c414426b4836c2635bad1df3a424e50cbdd167ffccb4dfff57d36b4aae0d6ca0910698220171a0f3373c1060a046c2812f0027e321f72979daa5e7973214170d49e885de0c0ecc167837d44502430674a82522e5df6a0759548052420b91ec1"));
1249 try testing.expect(std.mem.eql(u8, rs, "310d1d4c414426b4836c2635bad1df3a424e50cbdd167ffccb4dfff57d36b4aae0d6ca0910698220171a0f3373c1060a046c2812f0027e321f72979daa5e7973214170d49e885de0c0ecc167837d44502430674a82522e5df6a0759548052420b91ec1"));
12501250}
12511251
12521252test "big.int div multi-multi fuzz case #2" {
......@@ -1266,11 +1266,11 @@ test "big.int div multi-multi fuzz case #2" {
12661266
12671267 const qs = try q.toString(testing.allocator, 16, false);
12681268 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
12711271 const rs = try r.toString(testing.allocator, 16, false);
12721272 defer testing.allocator.free(rs);
1273 testing.expect(std.mem.eql(u8, rs, "a900000000000000000000000000000000000000000000000000"));
1273 try testing.expect(std.mem.eql(u8, rs, "a900000000000000000000000000000000000000000000000000"));
12741274}
12751275
12761276test "big.int shift-right single" {
......@@ -1278,7 +1278,7 @@ test "big.int shift-right single" {
12781278 defer a.deinit();
12791279 try a.shiftRight(a, 16);
12801280
1281 testing.expect((try a.to(u32)) == 0xffff);
1281 try testing.expect((try a.to(u32)) == 0xffff);
12821282}
12831283
12841284test "big.int shift-right multi" {
......@@ -1286,13 +1286,13 @@ test "big.int shift-right multi" {
12861286 defer a.deinit();
12871287 try a.shiftRight(a, 67);
12881288
1289 testing.expect((try a.to(u64)) == 0x1fffe0001dddc222);
1289 try testing.expect((try a.to(u64)) == 0x1fffe0001dddc222);
12901290
12911291 try a.set(0xffff0000eeee1111dddd2222cccc3333);
12921292 try a.shiftRight(a, 63);
12931293 try a.shiftRight(a, 63);
12941294 try a.shiftRight(a, 2);
1295 testing.expect(a.eqZero());
1295 try testing.expect(a.eqZero());
12961296}
12971297
12981298test "big.int shift-left single" {
......@@ -1300,7 +1300,7 @@ test "big.int shift-left single" {
13001300 defer a.deinit();
13011301 try a.shiftLeft(a, 16);
13021302
1303 testing.expect((try a.to(u64)) == 0xffff0000);
1303 try testing.expect((try a.to(u64)) == 0xffff0000);
13041304}
13051305
13061306test "big.int shift-left multi" {
......@@ -1308,7 +1308,7 @@ test "big.int shift-left multi" {
13081308 defer a.deinit();
13091309 try a.shiftLeft(a, 67);
13101310
1311 testing.expect((try a.to(u128)) == 0xffff0000eeee11100000000000000000);
1311 try testing.expect((try a.to(u128)) == 0xffff0000eeee11100000000000000000);
13121312}
13131313
13141314test "big.int shift-right negative" {
......@@ -1318,12 +1318,12 @@ test "big.int shift-right negative" {
13181318 var arg = try Managed.initSet(testing.allocator, -20);
13191319 defer arg.deinit();
13201320 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
13231323 var arg2 = try Managed.initSet(testing.allocator, -5);
13241324 defer arg2.deinit();
13251325 try a.shiftRight(arg2, 10);
1326 testing.expect((try a.to(i32)) == -5 >> 10);
1326 try testing.expect((try a.to(i32)) == -5 >> 10);
13271327}
13281328
13291329test "big.int shift-left negative" {
......@@ -1333,7 +1333,7 @@ test "big.int shift-left negative" {
13331333 var arg = try Managed.initSet(testing.allocator, -10);
13341334 defer arg.deinit();
13351335 try a.shiftRight(arg, 1232);
1336 testing.expect((try a.to(i32)) == -10 >> 1232);
1336 try testing.expect((try a.to(i32)) == -10 >> 1232);
13371337}
13381338
13391339test "big.int bitwise and simple" {
......@@ -1344,7 +1344,7 @@ test "big.int bitwise and simple" {
13441344
13451345 try a.bitAnd(a, b);
13461346
1347 testing.expect((try a.to(u64)) == 0xeeeeeeee00000000);
1347 try testing.expect((try a.to(u64)) == 0xeeeeeeee00000000);
13481348}
13491349
13501350test "big.int bitwise and multi-limb" {
......@@ -1355,7 +1355,7 @@ test "big.int bitwise and multi-limb" {
13551355
13561356 try a.bitAnd(a, b);
13571357
1358 testing.expect((try a.to(u128)) == 0);
1358 try testing.expect((try a.to(u128)) == 0);
13591359}
13601360
13611361test "big.int bitwise xor simple" {
......@@ -1366,7 +1366,7 @@ test "big.int bitwise xor simple" {
13661366
13671367 try a.bitXor(a, b);
13681368
1369 testing.expect((try a.to(u64)) == 0x1111111133333333);
1369 try testing.expect((try a.to(u64)) == 0x1111111133333333);
13701370}
13711371
13721372test "big.int bitwise xor multi-limb" {
......@@ -1377,7 +1377,7 @@ test "big.int bitwise xor multi-limb" {
13771377
13781378 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));
13811381}
13821382
13831383test "big.int bitwise or simple" {
......@@ -1388,7 +1388,7 @@ test "big.int bitwise or simple" {
13881388
13891389 try a.bitOr(a, b);
13901390
1391 testing.expect((try a.to(u64)) == 0xffffffff33333333);
1391 try testing.expect((try a.to(u64)) == 0xffffffff33333333);
13921392}
13931393
13941394test "big.int bitwise or multi-limb" {
......@@ -1400,7 +1400,7 @@ test "big.int bitwise or multi-limb" {
14001400 try a.bitOr(a, b);
14011401
14021402 // 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));
14041404}
14051405
14061406test "big.int var args" {
......@@ -1410,15 +1410,15 @@ test "big.int var args" {
14101410 var b = try Managed.initSet(testing.allocator, 6);
14111411 defer b.deinit();
14121412 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
14151415 var c = try Managed.initSet(testing.allocator, 11);
14161416 defer c.deinit();
1417 testing.expect(a.order(c) == .eq);
1417 try testing.expect(a.order(c) == .eq);
14181418
14191419 var d = try Managed.initSet(testing.allocator, 14);
14201420 defer d.deinit();
1421 testing.expect(a.order(d) != .gt);
1421 try testing.expect(a.order(d) != .gt);
14221422}
14231423
14241424test "big.int gcd non-one small" {
......@@ -1431,7 +1431,7 @@ test "big.int gcd non-one small" {
14311431
14321432 try r.gcd(a, b);
14331433
1434 testing.expect((try r.to(u32)) == 1);
1434 try testing.expect((try r.to(u32)) == 1);
14351435}
14361436
14371437test "big.int gcd non-one small" {
......@@ -1444,7 +1444,7 @@ test "big.int gcd non-one small" {
14441444
14451445 try r.gcd(a, b);
14461446
1447 testing.expect((try r.to(u32)) == 38);
1447 try testing.expect((try r.to(u32)) == 38);
14481448}
14491449
14501450test "big.int gcd non-one large" {
......@@ -1457,7 +1457,7 @@ test "big.int gcd non-one large" {
14571457
14581458 try r.gcd(a, b);
14591459
1460 testing.expect((try r.to(u32)) == 4369);
1460 try testing.expect((try r.to(u32)) == 4369);
14611461}
14621462
14631463test "big.int gcd large multi-limb result" {
......@@ -1471,7 +1471,7 @@ test "big.int gcd large multi-limb result" {
14711471 try r.gcd(a, b);
14721472
14731473 const answer = (try r.to(u256));
1474 testing.expect(answer == 0xf000000ff00000fff0000ffff000fffff00ffffff1);
1474 try testing.expect(answer == 0xf000000ff00000fff0000ffff000fffff00ffffff1);
14751475}
14761476
14771477test "big.int gcd one large" {
......@@ -1484,7 +1484,7 @@ test "big.int gcd one large" {
14841484
14851485 try r.gcd(a, b);
14861486
1487 testing.expect((try r.to(u64)) == 1);
1487 try testing.expect((try r.to(u64)) == 1);
14881488}
14891489
14901490test "big.int mutable to managed" {
......@@ -1495,7 +1495,7 @@ test "big.int mutable to managed" {
14951495 var a = Mutable.init(limbs_buf, 0xdeadbeef);
14961496 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()));
14991499}
15001500
15011501test "big.int const to managed" {
......@@ -1505,7 +1505,7 @@ test "big.int const to managed" {
15051505 var b = try a.toConst().toManaged(testing.allocator);
15061506 defer b.deinit();
15071507
1508 testing.expect(a.toConst().eq(b.toConst()));
1508 try testing.expect(a.toConst().eq(b.toConst()));
15091509}
15101510
15111511test "big.int pow" {
......@@ -1514,10 +1514,10 @@ test "big.int pow" {
15141514 defer a.deinit();
15151515
15161516 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
15191519 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));
15211521 }
15221522 {
15231523 var a = try Managed.initSet(testing.allocator, 10);
......@@ -1531,11 +1531,11 @@ test "big.int pow" {
15311531 // y and a are aliased
15321532 try a.pow(a.toConst(), 123);
15331533
1534 testing.expect(a.eq(y));
1534 try testing.expect(a.eq(y));
15351535
15361536 const ys = try y.toString(testing.allocator, 16, false);
15371537 defer testing.allocator.free(ys);
1538 testing.expectEqualSlices(
1538 try testing.expectEqualSlices(
15391539 u8,
15401540 "183425a5f872f126e00a5ad62c839075cd6846c6fb0230887c7ad7a9dc530fcb" ++
15411541 "4933f60e8000000000000000000000000000000",
......@@ -1548,17 +1548,17 @@ test "big.int pow" {
15481548 defer a.deinit();
15491549
15501550 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
15531553 try a.set(1);
15541554 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));
15561556 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));
15581558 try a.set(-1);
15591559 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));
15611561 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));
15631563 }
15641564}
lib/std/math/big/rational.zig+67-67
......@@ -473,7 +473,7 @@ pub const Rational = struct {
473473};
474474
475475fn extractLowBits(a: Int, comptime T: type) T {
476 testing.expect(@typeInfo(T) == .Int);
476 debug.assert(@typeInfo(T) == .Int);
477477
478478 const t_bits = @typeInfo(T).Int.bits;
479479 const limb_bits = @typeInfo(Limb).Int.bits;
......@@ -498,19 +498,19 @@ test "big.rational extractLowBits" {
498498 defer a.deinit();
499499
500500 const a1 = extractLowBits(a, u8);
501 testing.expect(a1 == 0x21);
501 try testing.expect(a1 == 0x21);
502502
503503 const a2 = extractLowBits(a, u16);
504 testing.expect(a2 == 0x4321);
504 try testing.expect(a2 == 0x4321);
505505
506506 const a3 = extractLowBits(a, u32);
507 testing.expect(a3 == 0x87654321);
507 try testing.expect(a3 == 0x87654321);
508508
509509 const a4 = extractLowBits(a, u64);
510 testing.expect(a4 == 0x1234567887654321);
510 try testing.expect(a4 == 0x1234567887654321);
511511
512512 const a5 = extractLowBits(a, u128);
513 testing.expect(a5 == 0x11112222333344441234567887654321);
513 try testing.expect(a5 == 0x11112222333344441234567887654321);
514514}
515515
516516test "big.rational set" {
......@@ -518,28 +518,28 @@ test "big.rational set" {
518518 defer a.deinit();
519519
520520 try a.setInt(5);
521 testing.expect((try a.p.to(u32)) == 5);
522 testing.expect((try a.q.to(u32)) == 1);
521 try testing.expect((try a.p.to(u32)) == 5);
522 try testing.expect((try a.q.to(u32)) == 1);
523523
524524 try a.setRatio(7, 3);
525 testing.expect((try a.p.to(u32)) == 7);
526 testing.expect((try a.q.to(u32)) == 3);
525 try testing.expect((try a.p.to(u32)) == 7);
526 try testing.expect((try a.q.to(u32)) == 3);
527527
528528 try a.setRatio(9, 3);
529 testing.expect((try a.p.to(i32)) == 3);
530 testing.expect((try a.q.to(i32)) == 1);
529 try testing.expect((try a.p.to(i32)) == 3);
530 try testing.expect((try a.q.to(i32)) == 1);
531531
532532 try a.setRatio(-9, 3);
533 testing.expect((try a.p.to(i32)) == -3);
534 testing.expect((try a.q.to(i32)) == 1);
533 try testing.expect((try a.p.to(i32)) == -3);
534 try testing.expect((try a.q.to(i32)) == 1);
535535
536536 try a.setRatio(9, -3);
537 testing.expect((try a.p.to(i32)) == -3);
538 testing.expect((try a.q.to(i32)) == 1);
537 try testing.expect((try a.p.to(i32)) == -3);
538 try testing.expect((try a.q.to(i32)) == 1);
539539
540540 try a.setRatio(-9, -3);
541 testing.expect((try a.p.to(i32)) == 3);
542 testing.expect((try a.q.to(i32)) == 1);
541 try testing.expect((try a.p.to(i32)) == 3);
542 try testing.expect((try a.q.to(i32)) == 1);
543543}
544544
545545test "big.rational setFloat" {
......@@ -547,24 +547,24 @@ test "big.rational setFloat" {
547547 defer a.deinit();
548548
549549 try a.setFloat(f64, 2.5);
550 testing.expect((try a.p.to(i32)) == 5);
551 testing.expect((try a.q.to(i32)) == 2);
550 try testing.expect((try a.p.to(i32)) == 5);
551 try testing.expect((try a.q.to(i32)) == 2);
552552
553553 try a.setFloat(f32, -2.5);
554 testing.expect((try a.p.to(i32)) == -5);
555 testing.expect((try a.q.to(i32)) == 2);
554 try testing.expect((try a.p.to(i32)) == -5);
555 try testing.expect((try a.q.to(i32)) == 2);
556556
557557 try a.setFloat(f32, 3.141593);
558558
559559 // = 3.14159297943115234375
560 testing.expect((try a.p.to(u32)) == 3294199);
561 testing.expect((try a.q.to(u32)) == 1048576);
560 try testing.expect((try a.p.to(u32)) == 3294199);
561 try testing.expect((try a.q.to(u32)) == 1048576);
562562
563563 try a.setFloat(f64, 72.141593120712409172417410926841290461290467124);
564564
565565 // = 72.1415931207124145885245525278151035308837890625
566 testing.expect((try a.p.to(u128)) == 5076513310880537);
567 testing.expect((try a.q.to(u128)) == 70368744177664);
566 try testing.expect((try a.p.to(u128)) == 5076513310880537);
567 try testing.expect((try a.q.to(u128)) == 70368744177664);
568568}
569569
570570test "big.rational setFloatString" {
......@@ -574,8 +574,8 @@ test "big.rational setFloatString" {
574574 try a.setFloatString("72.14159312071241458852455252781510353");
575575
576576 // = 72.1415931207124145885245525278151035308837890625
577 testing.expect((try a.p.to(u128)) == 7214159312071241458852455252781510353);
578 testing.expect((try a.q.to(u128)) == 100000000000000000000000000000000000);
577 try testing.expect((try a.p.to(u128)) == 7214159312071241458852455252781510353);
578 try testing.expect((try a.q.to(u128)) == 100000000000000000000000000000000000);
579579}
580580
581581test "big.rational toFloat" {
......@@ -584,11 +584,11 @@ test "big.rational toFloat" {
584584
585585 // = 3.14159297943115234375
586586 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
589589 // = 72.1415931207124145885245525278151035308837890625
590590 try a.setRatio(5076513310880537, 70368744177664);
591 testing.expect((try a.toFloat(f64)) == 72.141593120712409172417410926841290461290467124);
591 try testing.expect((try a.toFloat(f64)) == 72.141593120712409172417410926841290461290467124);
592592}
593593
594594test "big.rational set/to Float round-trip" {
......@@ -599,7 +599,7 @@ test "big.rational set/to Float round-trip" {
599599 while (i < 512) : (i += 1) {
600600 const r = prng.random.float(f64);
601601 try a.setFloat(f64, r);
602 testing.expect((try a.toFloat(f64)) == r);
602 try testing.expect((try a.toFloat(f64)) == r);
603603 }
604604}
605605
......@@ -611,8 +611,8 @@ test "big.rational copy" {
611611 defer b.deinit();
612612
613613 try a.copyInt(b);
614 testing.expect((try a.p.to(u32)) == 5);
615 testing.expect((try a.q.to(u32)) == 1);
614 try testing.expect((try a.p.to(u32)) == 5);
615 try testing.expect((try a.q.to(u32)) == 1);
616616
617617 var c = try Int.initSet(testing.allocator, 7);
618618 defer c.deinit();
......@@ -620,8 +620,8 @@ test "big.rational copy" {
620620 defer d.deinit();
621621
622622 try a.copyRatio(c, d);
623 testing.expect((try a.p.to(u32)) == 7);
624 testing.expect((try a.q.to(u32)) == 3);
623 try testing.expect((try a.p.to(u32)) == 7);
624 try testing.expect((try a.q.to(u32)) == 3);
625625
626626 var e = try Int.initSet(testing.allocator, 9);
627627 defer e.deinit();
......@@ -629,8 +629,8 @@ test "big.rational copy" {
629629 defer f.deinit();
630630
631631 try a.copyRatio(e, f);
632 testing.expect((try a.p.to(u32)) == 3);
633 testing.expect((try a.q.to(u32)) == 1);
632 try testing.expect((try a.p.to(u32)) == 3);
633 try testing.expect((try a.q.to(u32)) == 1);
634634}
635635
636636test "big.rational negate" {
......@@ -638,16 +638,16 @@ test "big.rational negate" {
638638 defer a.deinit();
639639
640640 try a.setInt(-50);
641 testing.expect((try a.p.to(i32)) == -50);
642 testing.expect((try a.q.to(i32)) == 1);
641 try testing.expect((try a.p.to(i32)) == -50);
642 try testing.expect((try a.q.to(i32)) == 1);
643643
644644 a.negate();
645 testing.expect((try a.p.to(i32)) == 50);
646 testing.expect((try a.q.to(i32)) == 1);
645 try testing.expect((try a.p.to(i32)) == 50);
646 try testing.expect((try a.q.to(i32)) == 1);
647647
648648 a.negate();
649 testing.expect((try a.p.to(i32)) == -50);
650 testing.expect((try a.q.to(i32)) == 1);
649 try testing.expect((try a.p.to(i32)) == -50);
650 try testing.expect((try a.q.to(i32)) == 1);
651651}
652652
653653test "big.rational abs" {
......@@ -655,16 +655,16 @@ test "big.rational abs" {
655655 defer a.deinit();
656656
657657 try a.setInt(-50);
658 testing.expect((try a.p.to(i32)) == -50);
659 testing.expect((try a.q.to(i32)) == 1);
658 try testing.expect((try a.p.to(i32)) == -50);
659 try testing.expect((try a.q.to(i32)) == 1);
660660
661661 a.abs();
662 testing.expect((try a.p.to(i32)) == 50);
663 testing.expect((try a.q.to(i32)) == 1);
662 try testing.expect((try a.p.to(i32)) == 50);
663 try testing.expect((try a.q.to(i32)) == 1);
664664
665665 a.abs();
666 testing.expect((try a.p.to(i32)) == 50);
667 testing.expect((try a.q.to(i32)) == 1);
666 try testing.expect((try a.p.to(i32)) == 50);
667 try testing.expect((try a.q.to(i32)) == 1);
668668}
669669
670670test "big.rational swap" {
......@@ -676,19 +676,19 @@ test "big.rational swap" {
676676 try a.setRatio(50, 23);
677677 try b.setRatio(17, 3);
678678
679 testing.expect((try a.p.to(u32)) == 50);
680 testing.expect((try a.q.to(u32)) == 23);
679 try testing.expect((try a.p.to(u32)) == 50);
680 try testing.expect((try a.q.to(u32)) == 23);
681681
682 testing.expect((try b.p.to(u32)) == 17);
683 testing.expect((try b.q.to(u32)) == 3);
682 try testing.expect((try b.p.to(u32)) == 17);
683 try testing.expect((try b.q.to(u32)) == 3);
684684
685685 a.swap(&b);
686686
687 testing.expect((try a.p.to(u32)) == 17);
688 testing.expect((try a.q.to(u32)) == 3);
687 try testing.expect((try a.p.to(u32)) == 17);
688 try testing.expect((try a.q.to(u32)) == 3);
689689
690 testing.expect((try b.p.to(u32)) == 50);
691 testing.expect((try b.q.to(u32)) == 23);
690 try testing.expect((try b.p.to(u32)) == 50);
691 try testing.expect((try b.q.to(u32)) == 23);
692692}
693693
694694test "big.rational order" {
......@@ -699,11 +699,11 @@ test "big.rational order" {
699699
700700 try a.setRatio(500, 231);
701701 try b.setRatio(18903, 8584);
702 testing.expect((try a.order(b)) == .lt);
702 try testing.expect((try a.order(b)) == .lt);
703703
704704 try a.setRatio(890, 10);
705705 try b.setRatio(89, 1);
706 testing.expect((try a.order(b)) == .eq);
706 try testing.expect((try a.order(b)) == .eq);
707707}
708708
709709test "big.rational add single-limb" {
......@@ -714,11 +714,11 @@ test "big.rational add single-limb" {
714714
715715 try a.setRatio(500, 231);
716716 try b.setRatio(18903, 8584);
717 testing.expect((try a.order(b)) == .lt);
717 try testing.expect((try a.order(b)) == .lt);
718718
719719 try a.setRatio(890, 10);
720720 try b.setRatio(89, 1);
721 testing.expect((try a.order(b)) == .eq);
721 try testing.expect((try a.order(b)) == .eq);
722722}
723723
724724test "big.rational add" {
......@@ -734,7 +734,7 @@ test "big.rational add" {
734734 try a.add(a, b);
735735
736736 try r.setRatio(984786924199, 290395044174);
737 testing.expect((try a.order(r)) == .eq);
737 try testing.expect((try a.order(r)) == .eq);
738738}
739739
740740test "big.rational sub" {
......@@ -750,7 +750,7 @@ test "big.rational sub" {
750750 try a.sub(a, b);
751751
752752 try r.setRatio(979040510045, 290395044174);
753 testing.expect((try a.order(r)) == .eq);
753 try testing.expect((try a.order(r)) == .eq);
754754}
755755
756756test "big.rational mul" {
......@@ -766,7 +766,7 @@ test "big.rational mul" {
766766 try a.mul(a, b);
767767
768768 try r.setRatio(571481443, 17082061422);
769 testing.expect((try a.order(r)) == .eq);
769 try testing.expect((try a.order(r)) == .eq);
770770}
771771
772772test "big.rational div" {
......@@ -782,7 +782,7 @@ test "big.rational div" {
782782 try a.div(a, b);
783783
784784 try r.setRatio(75531824394, 221015929);
785 testing.expect((try a.order(r)) == .eq);
785 try testing.expect((try a.order(r)) == .eq);
786786}
787787
788788test "big.rational div" {
......@@ -795,11 +795,11 @@ test "big.rational div" {
795795 a.invert();
796796
797797 try r.setRatio(23341, 78923);
798 testing.expect((try a.order(r)) == .eq);
798 try testing.expect((try a.order(r)) == .eq);
799799
800800 try a.setRatio(-78923, 23341);
801801 a.invert();
802802
803803 try r.setRatio(-23341, 78923);
804 testing.expect((try a.order(r)) == .eq);
804 try testing.expect((try a.order(r)) == .eq);
805805}
lib/std/math/cbrt.zig+24-24
......@@ -125,44 +125,44 @@ fn cbrt64(x: f64) f64 {
125125}
126126
127127test "math.cbrt" {
128 expect(cbrt(@as(f32, 0.0)) == cbrt32(0.0));
129 expect(cbrt(@as(f64, 0.0)) == cbrt64(0.0));
128 try expect(cbrt(@as(f32, 0.0)) == cbrt32(0.0));
129 try expect(cbrt(@as(f64, 0.0)) == cbrt64(0.0));
130130}
131131
132132test "math.cbrt32" {
133133 const epsilon = 0.000001;
134134
135 expect(cbrt32(0.0) == 0.0);
136 expect(math.approxEqAbs(f32, cbrt32(0.2), 0.584804, epsilon));
137 expect(math.approxEqAbs(f32, cbrt32(0.8923), 0.962728, epsilon));
138 expect(math.approxEqAbs(f32, cbrt32(1.5), 1.144714, epsilon));
139 expect(math.approxEqAbs(f32, cbrt32(37.45), 3.345676, epsilon));
140 expect(math.approxEqAbs(f32, cbrt32(123123.234375), 49.748501, epsilon));
135 try expect(cbrt32(0.0) == 0.0);
136 try expect(math.approxEqAbs(f32, cbrt32(0.2), 0.584804, epsilon));
137 try expect(math.approxEqAbs(f32, cbrt32(0.8923), 0.962728, epsilon));
138 try expect(math.approxEqAbs(f32, cbrt32(1.5), 1.144714, epsilon));
139 try expect(math.approxEqAbs(f32, cbrt32(37.45), 3.345676, epsilon));
140 try expect(math.approxEqAbs(f32, cbrt32(123123.234375), 49.748501, epsilon));
141141}
142142
143143test "math.cbrt64" {
144144 const epsilon = 0.000001;
145145
146 expect(cbrt64(0.0) == 0.0);
147 expect(math.approxEqAbs(f64, cbrt64(0.2), 0.584804, epsilon));
148 expect(math.approxEqAbs(f64, cbrt64(0.8923), 0.962728, epsilon));
149 expect(math.approxEqAbs(f64, cbrt64(1.5), 1.144714, epsilon));
150 expect(math.approxEqAbs(f64, cbrt64(37.45), 3.345676, epsilon));
151 expect(math.approxEqAbs(f64, cbrt64(123123.234375), 49.748501, epsilon));
146 try expect(cbrt64(0.0) == 0.0);
147 try expect(math.approxEqAbs(f64, cbrt64(0.2), 0.584804, epsilon));
148 try expect(math.approxEqAbs(f64, cbrt64(0.8923), 0.962728, epsilon));
149 try expect(math.approxEqAbs(f64, cbrt64(1.5), 1.144714, epsilon));
150 try expect(math.approxEqAbs(f64, cbrt64(37.45), 3.345676, epsilon));
151 try expect(math.approxEqAbs(f64, cbrt64(123123.234375), 49.748501, epsilon));
152152}
153153
154154test "math.cbrt.special" {
155 expect(cbrt32(0.0) == 0.0);
156 expect(cbrt32(-0.0) == -0.0);
157 expect(math.isPositiveInf(cbrt32(math.inf(f32))));
158 expect(math.isNegativeInf(cbrt32(-math.inf(f32))));
159 expect(math.isNan(cbrt32(math.nan(f32))));
155 try expect(cbrt32(0.0) == 0.0);
156 try expect(cbrt32(-0.0) == -0.0);
157 try expect(math.isPositiveInf(cbrt32(math.inf(f32))));
158 try expect(math.isNegativeInf(cbrt32(-math.inf(f32))));
159 try expect(math.isNan(cbrt32(math.nan(f32))));
160160}
161161
162162test "math.cbrt64.special" {
163 expect(cbrt64(0.0) == 0.0);
164 expect(cbrt64(-0.0) == -0.0);
165 expect(math.isPositiveInf(cbrt64(math.inf(f64))));
166 expect(math.isNegativeInf(cbrt64(-math.inf(f64))));
167 expect(math.isNan(cbrt64(math.nan(f64))));
163 try expect(cbrt64(0.0) == 0.0);
164 try expect(cbrt64(-0.0) == -0.0);
165 try expect(math.isPositiveInf(cbrt64(math.inf(f64))));
166 try expect(math.isNegativeInf(cbrt64(-math.inf(f64))));
167 try expect(math.isNan(cbrt64(math.nan(f64))));
168168}
lib/std/math/ceil.zig+27-27
......@@ -120,49 +120,49 @@ fn ceil128(x: f128) f128 {
120120}
121121
122122test "math.ceil" {
123 expect(ceil(@as(f32, 0.0)) == ceil32(0.0));
124 expect(ceil(@as(f64, 0.0)) == ceil64(0.0));
125 expect(ceil(@as(f128, 0.0)) == ceil128(0.0));
123 try expect(ceil(@as(f32, 0.0)) == ceil32(0.0));
124 try expect(ceil(@as(f64, 0.0)) == ceil64(0.0));
125 try expect(ceil(@as(f128, 0.0)) == ceil128(0.0));
126126}
127127
128128test "math.ceil32" {
129 expect(ceil32(1.3) == 2.0);
130 expect(ceil32(-1.3) == -1.0);
131 expect(ceil32(0.2) == 1.0);
129 try expect(ceil32(1.3) == 2.0);
130 try expect(ceil32(-1.3) == -1.0);
131 try expect(ceil32(0.2) == 1.0);
132132}
133133
134134test "math.ceil64" {
135 expect(ceil64(1.3) == 2.0);
136 expect(ceil64(-1.3) == -1.0);
137 expect(ceil64(0.2) == 1.0);
135 try expect(ceil64(1.3) == 2.0);
136 try expect(ceil64(-1.3) == -1.0);
137 try expect(ceil64(0.2) == 1.0);
138138}
139139
140140test "math.ceil128" {
141 expect(ceil128(1.3) == 2.0);
142 expect(ceil128(-1.3) == -1.0);
143 expect(ceil128(0.2) == 1.0);
141 try expect(ceil128(1.3) == 2.0);
142 try expect(ceil128(-1.3) == -1.0);
143 try expect(ceil128(0.2) == 1.0);
144144}
145145
146146test "math.ceil32.special" {
147 expect(ceil32(0.0) == 0.0);
148 expect(ceil32(-0.0) == -0.0);
149 expect(math.isPositiveInf(ceil32(math.inf(f32))));
150 expect(math.isNegativeInf(ceil32(-math.inf(f32))));
151 expect(math.isNan(ceil32(math.nan(f32))));
147 try expect(ceil32(0.0) == 0.0);
148 try expect(ceil32(-0.0) == -0.0);
149 try expect(math.isPositiveInf(ceil32(math.inf(f32))));
150 try expect(math.isNegativeInf(ceil32(-math.inf(f32))));
151 try expect(math.isNan(ceil32(math.nan(f32))));
152152}
153153
154154test "math.ceil64.special" {
155 expect(ceil64(0.0) == 0.0);
156 expect(ceil64(-0.0) == -0.0);
157 expect(math.isPositiveInf(ceil64(math.inf(f64))));
158 expect(math.isNegativeInf(ceil64(-math.inf(f64))));
159 expect(math.isNan(ceil64(math.nan(f64))));
155 try expect(ceil64(0.0) == 0.0);
156 try expect(ceil64(-0.0) == -0.0);
157 try expect(math.isPositiveInf(ceil64(math.inf(f64))));
158 try expect(math.isNegativeInf(ceil64(-math.inf(f64))));
159 try expect(math.isNan(ceil64(math.nan(f64))));
160160}
161161
162162test "math.ceil128.special" {
163 expect(ceil128(0.0) == 0.0);
164 expect(ceil128(-0.0) == -0.0);
165 expect(math.isPositiveInf(ceil128(math.inf(f128))));
166 expect(math.isNegativeInf(ceil128(-math.inf(f128))));
167 expect(math.isNan(ceil128(math.nan(f128))));
163 try expect(ceil128(0.0) == 0.0);
164 try expect(ceil128(-0.0) == -0.0);
165 try expect(math.isPositiveInf(ceil128(math.inf(f128))));
166 try expect(math.isNegativeInf(ceil128(-math.inf(f128))));
167 try expect(math.isNan(ceil128(math.nan(f128))));
168168}
lib/std/math/complex.zig+7-7
......@@ -114,7 +114,7 @@ test "complex.add" {
114114 const b = Complex(f32).new(2, 7);
115115 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);
118118}
119119
120120test "complex.sub" {
......@@ -122,7 +122,7 @@ test "complex.sub" {
122122 const b = Complex(f32).new(2, 7);
123123 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);
126126}
127127
128128test "complex.mul" {
......@@ -130,7 +130,7 @@ test "complex.mul" {
130130 const b = Complex(f32).new(2, 7);
131131 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);
134134}
135135
136136test "complex.div" {
......@@ -138,7 +138,7 @@ test "complex.div" {
138138 const b = Complex(f32).new(2, 7);
139139 const c = a.div(b);
140140
141 testing.expect(math.approxEqAbs(f32, c.re, @as(f32, 31) / 53, epsilon) and
141 try testing.expect(math.approxEqAbs(f32, c.re, @as(f32, 31) / 53, epsilon) and
142142 math.approxEqAbs(f32, c.im, @as(f32, -29) / 53, epsilon));
143143}
144144
......@@ -146,14 +146,14 @@ test "complex.conjugate" {
146146 const a = Complex(f32).new(5, 3);
147147 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);
150150}
151151
152152test "complex.reciprocal" {
153153 const a = Complex(f32).new(5, 3);
154154 const c = a.reciprocal();
155155
156 testing.expect(math.approxEqAbs(f32, c.re, @as(f32, 5) / 34, epsilon) and
156 try testing.expect(math.approxEqAbs(f32, c.re, @as(f32, 5) / 34, epsilon) and
157157 math.approxEqAbs(f32, c.im, @as(f32, -3) / 34, epsilon));
158158}
159159
......@@ -161,7 +161,7 @@ test "complex.magnitude" {
161161 const a = Complex(f32).new(5, 3);
162162 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));
165165}
166166
167167test "complex.cmath" {
lib/std/math/complex/abs.zig+1-1
......@@ -20,5 +20,5 @@ const epsilon = 0.0001;
2020test "complex.cabs" {
2121 const a = Complex(f32).new(5, 3);
2222 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));
2424}
lib/std/math/complex/acos.zig+2-2
......@@ -22,6 +22,6 @@ test "complex.cacos" {
2222 const a = Complex(f32).new(5, 3);
2323 const c = acos(a);
2424
25 testing.expect(math.approxEqAbs(f32, c.re, 0.546975, epsilon));
26 testing.expect(math.approxEqAbs(f32, c.im, -2.452914, epsilon));
25 try testing.expect(math.approxEqAbs(f32, c.re, 0.546975, epsilon));
26 try testing.expect(math.approxEqAbs(f32, c.im, -2.452914, epsilon));
2727}
lib/std/math/complex/acosh.zig+2-2
......@@ -22,6 +22,6 @@ test "complex.cacosh" {
2222 const a = Complex(f32).new(5, 3);
2323 const c = acosh(a);
2424
25 testing.expect(math.approxEqAbs(f32, c.re, 2.452914, epsilon));
26 testing.expect(math.approxEqAbs(f32, c.im, 0.546975, epsilon));
25 try testing.expect(math.approxEqAbs(f32, c.re, 2.452914, epsilon));
26 try testing.expect(math.approxEqAbs(f32, c.im, 0.546975, epsilon));
2727}
lib/std/math/complex/arg.zig+1-1
......@@ -20,5 +20,5 @@ const epsilon = 0.0001;
2020test "complex.carg" {
2121 const a = Complex(f32).new(5, 3);
2222 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));
2424}
lib/std/math/complex/asin.zig+2-2
......@@ -28,6 +28,6 @@ test "complex.casin" {
2828 const a = Complex(f32).new(5, 3);
2929 const c = asin(a);
3030
31 testing.expect(math.approxEqAbs(f32, c.re, 1.023822, epsilon));
32 testing.expect(math.approxEqAbs(f32, c.im, 2.452914, epsilon));
31 try testing.expect(math.approxEqAbs(f32, c.re, 1.023822, epsilon));
32 try testing.expect(math.approxEqAbs(f32, c.im, 2.452914, epsilon));
3333}
lib/std/math/complex/asinh.zig+2-2
......@@ -23,6 +23,6 @@ test "complex.casinh" {
2323 const a = Complex(f32).new(5, 3);
2424 const c = asinh(a);
2525
26 testing.expect(math.approxEqAbs(f32, c.re, 2.459831, epsilon));
27 testing.expect(math.approxEqAbs(f32, c.im, 0.533999, epsilon));
26 try testing.expect(math.approxEqAbs(f32, c.re, 2.459831, epsilon));
27 try testing.expect(math.approxEqAbs(f32, c.im, 0.533999, epsilon));
2828}
lib/std/math/complex/atan.zig+4-4
......@@ -130,14 +130,14 @@ test "complex.catan32" {
130130 const a = Complex(f32).new(5, 3);
131131 const c = atan(a);
132132
133 testing.expect(math.approxEqAbs(f32, c.re, 1.423679, epsilon));
134 testing.expect(math.approxEqAbs(f32, c.im, 0.086569, epsilon));
133 try testing.expect(math.approxEqAbs(f32, c.re, 1.423679, epsilon));
134 try testing.expect(math.approxEqAbs(f32, c.im, 0.086569, epsilon));
135135}
136136
137137test "complex.catan64" {
138138 const a = Complex(f64).new(5, 3);
139139 const c = atan(a);
140140
141 testing.expect(math.approxEqAbs(f64, c.re, 1.423679, epsilon));
142 testing.expect(math.approxEqAbs(f64, c.im, 0.086569, epsilon));
141 try testing.expect(math.approxEqAbs(f64, c.re, 1.423679, epsilon));
142 try testing.expect(math.approxEqAbs(f64, c.im, 0.086569, epsilon));
143143}
lib/std/math/complex/atanh.zig+2-2
......@@ -23,6 +23,6 @@ test "complex.catanh" {
2323 const a = Complex(f32).new(5, 3);
2424 const c = atanh(a);
2525
26 testing.expect(math.approxEqAbs(f32, c.re, 0.146947, epsilon));
27 testing.expect(math.approxEqAbs(f32, c.im, 1.480870, epsilon));
26 try testing.expect(math.approxEqAbs(f32, c.re, 0.146947, epsilon));
27 try testing.expect(math.approxEqAbs(f32, c.im, 1.480870, epsilon));
2828}
lib/std/math/complex/conj.zig+1-1
......@@ -19,5 +19,5 @@ test "complex.conj" {
1919 const a = Complex(f32).new(5, 3);
2020 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);
2323}
lib/std/math/complex/cos.zig+2-2
......@@ -22,6 +22,6 @@ test "complex.ccos" {
2222 const a = Complex(f32).new(5, 3);
2323 const c = cos(a);
2424
25 testing.expect(math.approxEqAbs(f32, c.re, 2.855815, epsilon));
26 testing.expect(math.approxEqAbs(f32, c.im, 9.606383, epsilon));
25 try testing.expect(math.approxEqAbs(f32, c.re, 2.855815, epsilon));
26 try testing.expect(math.approxEqAbs(f32, c.im, 9.606383, epsilon));
2727}
lib/std/math/complex/cosh.zig+4-4
......@@ -165,14 +165,14 @@ test "complex.ccosh32" {
165165 const a = Complex(f32).new(5, 3);
166166 const c = cosh(a);
167167
168 testing.expect(math.approxEqAbs(f32, c.re, -73.467300, epsilon));
169 testing.expect(math.approxEqAbs(f32, c.im, 10.471557, epsilon));
168 try testing.expect(math.approxEqAbs(f32, c.re, -73.467300, epsilon));
169 try testing.expect(math.approxEqAbs(f32, c.im, 10.471557, epsilon));
170170}
171171
172172test "complex.ccosh64" {
173173 const a = Complex(f64).new(5, 3);
174174 const c = cosh(a);
175175
176 testing.expect(math.approxEqAbs(f64, c.re, -73.467300, epsilon));
177 testing.expect(math.approxEqAbs(f64, c.im, 10.471557, epsilon));
176 try testing.expect(math.approxEqAbs(f64, c.re, -73.467300, epsilon));
177 try testing.expect(math.approxEqAbs(f64, c.im, 10.471557, epsilon));
178178}
lib/std/math/complex/exp.zig+4-4
......@@ -131,14 +131,14 @@ test "complex.cexp32" {
131131 const a = Complex(f32).new(5, 3);
132132 const c = exp(a);
133133
134 testing.expect(math.approxEqAbs(f32, c.re, -146.927917, epsilon));
135 testing.expect(math.approxEqAbs(f32, c.im, 20.944065, epsilon));
134 try testing.expect(math.approxEqAbs(f32, c.re, -146.927917, epsilon));
135 try testing.expect(math.approxEqAbs(f32, c.im, 20.944065, epsilon));
136136}
137137
138138test "complex.cexp64" {
139139 const a = Complex(f64).new(5, 3);
140140 const c = exp(a);
141141
142 testing.expect(math.approxEqAbs(f64, c.re, -146.927917, epsilon));
143 testing.expect(math.approxEqAbs(f64, c.im, 20.944065, epsilon));
142 try testing.expect(math.approxEqAbs(f64, c.re, -146.927917, epsilon));
143 try testing.expect(math.approxEqAbs(f64, c.im, 20.944065, epsilon));
144144}
lib/std/math/complex/log.zig+2-2
......@@ -24,6 +24,6 @@ test "complex.clog" {
2424 const a = Complex(f32).new(5, 3);
2525 const c = log(a);
2626
27 testing.expect(math.approxEqAbs(f32, c.re, 1.763180, epsilon));
28 testing.expect(math.approxEqAbs(f32, c.im, 0.540419, epsilon));
27 try testing.expect(math.approxEqAbs(f32, c.re, 1.763180, epsilon));
28 try testing.expect(math.approxEqAbs(f32, c.im, 0.540419, epsilon));
2929}
lib/std/math/complex/pow.zig+2-2
......@@ -23,6 +23,6 @@ test "complex.cpow" {
2323 const b = Complex(f32).new(2.3, -1.3);
2424 const c = pow(Complex(f32), a, b);
2525
26 testing.expect(math.approxEqAbs(f32, c.re, 58.049110, epsilon));
27 testing.expect(math.approxEqAbs(f32, c.im, -101.003433, epsilon));
26 try testing.expect(math.approxEqAbs(f32, c.re, 58.049110, epsilon));
27 try testing.expect(math.approxEqAbs(f32, c.im, -101.003433, epsilon));
2828}
lib/std/math/complex/proj.zig+1-1
......@@ -26,5 +26,5 @@ test "complex.cproj" {
2626 const a = Complex(f32).new(5, 3);
2727 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);
3030}
lib/std/math/complex/sin.zig+2-2
......@@ -23,6 +23,6 @@ test "complex.csin" {
2323 const a = Complex(f32).new(5, 3);
2424 const c = sin(a);
2525
26 testing.expect(math.approxEqAbs(f32, c.re, -9.654126, epsilon));
27 testing.expect(math.approxEqAbs(f32, c.im, 2.841692, epsilon));
26 try testing.expect(math.approxEqAbs(f32, c.re, -9.654126, epsilon));
27 try testing.expect(math.approxEqAbs(f32, c.im, 2.841692, epsilon));
2828}
lib/std/math/complex/sinh.zig+4-4
......@@ -164,14 +164,14 @@ test "complex.csinh32" {
164164 const a = Complex(f32).new(5, 3);
165165 const c = sinh(a);
166166
167 testing.expect(math.approxEqAbs(f32, c.re, -73.460617, epsilon));
168 testing.expect(math.approxEqAbs(f32, c.im, 10.472508, epsilon));
167 try testing.expect(math.approxEqAbs(f32, c.re, -73.460617, epsilon));
168 try testing.expect(math.approxEqAbs(f32, c.im, 10.472508, epsilon));
169169}
170170
171171test "complex.csinh64" {
172172 const a = Complex(f64).new(5, 3);
173173 const c = sinh(a);
174174
175 testing.expect(math.approxEqAbs(f64, c.re, -73.460617, epsilon));
176 testing.expect(math.approxEqAbs(f64, c.im, 10.472508, epsilon));
175 try testing.expect(math.approxEqAbs(f64, c.re, -73.460617, epsilon));
176 try testing.expect(math.approxEqAbs(f64, c.im, 10.472508, epsilon));
177177}
lib/std/math/complex/sqrt.zig+4-4
......@@ -138,14 +138,14 @@ test "complex.csqrt32" {
138138 const a = Complex(f32).new(5, 3);
139139 const c = sqrt(a);
140140
141 testing.expect(math.approxEqAbs(f32, c.re, 2.327117, epsilon));
142 testing.expect(math.approxEqAbs(f32, c.im, 0.644574, epsilon));
141 try testing.expect(math.approxEqAbs(f32, c.re, 2.327117, epsilon));
142 try testing.expect(math.approxEqAbs(f32, c.im, 0.644574, epsilon));
143143}
144144
145145test "complex.csqrt64" {
146146 const a = Complex(f64).new(5, 3);
147147 const c = sqrt(a);
148148
149 testing.expect(math.approxEqAbs(f64, c.re, 2.3271175190399496, epsilon));
150 testing.expect(math.approxEqAbs(f64, c.im, 0.6445742373246469, epsilon));
149 try testing.expect(math.approxEqAbs(f64, c.re, 2.3271175190399496, epsilon));
150 try testing.expect(math.approxEqAbs(f64, c.im, 0.6445742373246469, epsilon));
151151}
lib/std/math/complex/tan.zig+2-2
......@@ -23,6 +23,6 @@ test "complex.ctan" {
2323 const a = Complex(f32).new(5, 3);
2424 const c = tan(a);
2525
26 testing.expect(math.approxEqAbs(f32, c.re, -0.002708233, epsilon));
27 testing.expect(math.approxEqAbs(f32, c.im, 1.004165, epsilon));
26 try testing.expect(math.approxEqAbs(f32, c.re, -0.002708233, epsilon));
27 try testing.expect(math.approxEqAbs(f32, c.im, 1.004165, epsilon));
2828}
lib/std/math/complex/tanh.zig+4-4
......@@ -113,14 +113,14 @@ test "complex.ctanh32" {
113113 const a = Complex(f32).new(5, 3);
114114 const c = tanh(a);
115115
116 testing.expect(math.approxEqAbs(f32, c.re, 0.999913, epsilon));
117 testing.expect(math.approxEqAbs(f32, c.im, -0.000025, epsilon));
116 try testing.expect(math.approxEqAbs(f32, c.re, 0.999913, epsilon));
117 try testing.expect(math.approxEqAbs(f32, c.im, -0.000025, epsilon));
118118}
119119
120120test "complex.ctanh64" {
121121 const a = Complex(f64).new(5, 3);
122122 const c = tanh(a);
123123
124 testing.expect(math.approxEqAbs(f64, c.re, 0.999913, epsilon));
125 testing.expect(math.approxEqAbs(f64, c.im, -0.000025, epsilon));
124 try testing.expect(math.approxEqAbs(f64, c.re, 0.999913, epsilon));
125 try testing.expect(math.approxEqAbs(f64, c.im, -0.000025, epsilon));
126126}
lib/std/math/copysign.zig+20-20
......@@ -62,36 +62,36 @@ fn copysign128(x: f128, y: f128) f128 {
6262}
6363
6464test "math.copysign" {
65 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));
67 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));
65 try expect(copysign(f16, 1.0, 1.0) == copysign16(1.0, 1.0));
66 try expect(copysign(f32, 1.0, 1.0) == copysign32(1.0, 1.0));
67 try expect(copysign(f64, 1.0, 1.0) == copysign64(1.0, 1.0));
68 try expect(copysign(f128, 1.0, 1.0) == copysign128(1.0, 1.0));
6969}
7070
7171test "math.copysign16" {
72 expect(copysign16(5.0, 1.0) == 5.0);
73 expect(copysign16(5.0, -1.0) == -5.0);
74 expect(copysign16(-5.0, -1.0) == -5.0);
75 expect(copysign16(-5.0, 1.0) == 5.0);
72 try expect(copysign16(5.0, 1.0) == 5.0);
73 try expect(copysign16(5.0, -1.0) == -5.0);
74 try expect(copysign16(-5.0, -1.0) == -5.0);
75 try expect(copysign16(-5.0, 1.0) == 5.0);
7676}
7777
7878test "math.copysign32" {
79 expect(copysign32(5.0, 1.0) == 5.0);
80 expect(copysign32(5.0, -1.0) == -5.0);
81 expect(copysign32(-5.0, -1.0) == -5.0);
82 expect(copysign32(-5.0, 1.0) == 5.0);
79 try expect(copysign32(5.0, 1.0) == 5.0);
80 try expect(copysign32(5.0, -1.0) == -5.0);
81 try expect(copysign32(-5.0, -1.0) == -5.0);
82 try expect(copysign32(-5.0, 1.0) == 5.0);
8383}
8484
8585test "math.copysign64" {
86 expect(copysign64(5.0, 1.0) == 5.0);
87 expect(copysign64(5.0, -1.0) == -5.0);
88 expect(copysign64(-5.0, -1.0) == -5.0);
89 expect(copysign64(-5.0, 1.0) == 5.0);
86 try expect(copysign64(5.0, 1.0) == 5.0);
87 try expect(copysign64(5.0, -1.0) == -5.0);
88 try expect(copysign64(-5.0, -1.0) == -5.0);
89 try expect(copysign64(-5.0, 1.0) == 5.0);
9090}
9191
9292test "math.copysign128" {
93 expect(copysign128(5.0, 1.0) == 5.0);
94 expect(copysign128(5.0, -1.0) == -5.0);
95 expect(copysign128(-5.0, -1.0) == -5.0);
96 expect(copysign128(-5.0, 1.0) == 5.0);
93 try expect(copysign128(5.0, 1.0) == 5.0);
94 try expect(copysign128(5.0, -1.0) == -5.0);
95 try expect(copysign128(-5.0, -1.0) == -5.0);
96 try expect(copysign128(-5.0, 1.0) == 5.0);
9797}
lib/std/math/cos.zig+22-22
......@@ -88,42 +88,42 @@ fn cos_(comptime T: type, x_: T) T {
8888}
8989
9090test "math.cos" {
91 expect(cos(@as(f32, 0.0)) == cos_(f32, 0.0));
92 expect(cos(@as(f64, 0.0)) == cos_(f64, 0.0));
91 try expect(cos(@as(f32, 0.0)) == cos_(f32, 0.0));
92 try expect(cos(@as(f64, 0.0)) == cos_(f64, 0.0));
9393}
9494
9595test "math.cos32" {
9696 const epsilon = 0.000001;
9797
98 expect(math.approxEqAbs(f32, cos_(f32, 0.0), 1.0, epsilon));
99 expect(math.approxEqAbs(f32, cos_(f32, 0.2), 0.980067, epsilon));
100 expect(math.approxEqAbs(f32, cos_(f32, 0.8923), 0.627623, epsilon));
101 expect(math.approxEqAbs(f32, cos_(f32, 1.5), 0.070737, epsilon));
102 expect(math.approxEqAbs(f32, cos_(f32, -1.5), 0.070737, epsilon));
103 expect(math.approxEqAbs(f32, cos_(f32, 37.45), 0.969132, epsilon));
104 expect(math.approxEqAbs(f32, cos_(f32, 89.123), 0.400798, epsilon));
98 try expect(math.approxEqAbs(f32, cos_(f32, 0.0), 1.0, epsilon));
99 try expect(math.approxEqAbs(f32, cos_(f32, 0.2), 0.980067, epsilon));
100 try expect(math.approxEqAbs(f32, cos_(f32, 0.8923), 0.627623, epsilon));
101 try 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 try expect(math.approxEqAbs(f32, cos_(f32, 37.45), 0.969132, epsilon));
104 try expect(math.approxEqAbs(f32, cos_(f32, 89.123), 0.400798, epsilon));
105105}
106106
107107test "math.cos64" {
108108 const epsilon = 0.000001;
109109
110 expect(math.approxEqAbs(f64, cos_(f64, 0.0), 1.0, epsilon));
111 expect(math.approxEqAbs(f64, cos_(f64, 0.2), 0.980067, epsilon));
112 expect(math.approxEqAbs(f64, cos_(f64, 0.8923), 0.627623, epsilon));
113 expect(math.approxEqAbs(f64, cos_(f64, 1.5), 0.070737, epsilon));
114 expect(math.approxEqAbs(f64, cos_(f64, -1.5), 0.070737, epsilon));
115 expect(math.approxEqAbs(f64, cos_(f64, 37.45), 0.969132, epsilon));
116 expect(math.approxEqAbs(f64, cos_(f64, 89.123), 0.40080, epsilon));
110 try expect(math.approxEqAbs(f64, cos_(f64, 0.0), 1.0, epsilon));
111 try expect(math.approxEqAbs(f64, cos_(f64, 0.2), 0.980067, epsilon));
112 try expect(math.approxEqAbs(f64, cos_(f64, 0.8923), 0.627623, epsilon));
113 try 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 try expect(math.approxEqAbs(f64, cos_(f64, 37.45), 0.969132, epsilon));
116 try expect(math.approxEqAbs(f64, cos_(f64, 89.123), 0.40080, epsilon));
117117}
118118
119119test "math.cos32.special" {
120 expect(math.isNan(cos_(f32, math.inf(f32))));
121 expect(math.isNan(cos_(f32, -math.inf(f32))));
122 expect(math.isNan(cos_(f32, math.nan(f32))));
120 try expect(math.isNan(cos_(f32, math.inf(f32))));
121 try expect(math.isNan(cos_(f32, -math.inf(f32))));
122 try expect(math.isNan(cos_(f32, math.nan(f32))));
123123}
124124
125125test "math.cos64.special" {
126 expect(math.isNan(cos_(f64, math.inf(f64))));
127 expect(math.isNan(cos_(f64, -math.inf(f64))));
128 expect(math.isNan(cos_(f64, math.nan(f64))));
126 try expect(math.isNan(cos_(f64, math.inf(f64))));
127 try expect(math.isNan(cos_(f64, -math.inf(f64))));
128 try expect(math.isNan(cos_(f64, math.nan(f64))));
129129}
lib/std/math/cosh.zig+28-28
......@@ -93,48 +93,48 @@ fn cosh64(x: f64) f64 {
9393}
9494
9595test "math.cosh" {
96 expect(cosh(@as(f32, 1.5)) == cosh32(1.5));
97 expect(cosh(@as(f64, 1.5)) == cosh64(1.5));
96 try expect(cosh(@as(f32, 1.5)) == cosh32(1.5));
97 try expect(cosh(@as(f64, 1.5)) == cosh64(1.5));
9898}
9999
100100test "math.cosh32" {
101101 const epsilon = 0.000001;
102102
103 expect(math.approxEqAbs(f32, cosh32(0.0), 1.0, epsilon));
104 expect(math.approxEqAbs(f32, cosh32(0.2), 1.020067, epsilon));
105 expect(math.approxEqAbs(f32, cosh32(0.8923), 1.425225, epsilon));
106 expect(math.approxEqAbs(f32, cosh32(1.5), 2.352410, epsilon));
107 expect(math.approxEqAbs(f32, cosh32(-0.0), 1.0, epsilon));
108 expect(math.approxEqAbs(f32, cosh32(-0.2), 1.020067, epsilon));
109 expect(math.approxEqAbs(f32, cosh32(-0.8923), 1.425225, epsilon));
110 expect(math.approxEqAbs(f32, cosh32(-1.5), 2.352410, epsilon));
103 try expect(math.approxEqAbs(f32, cosh32(0.0), 1.0, epsilon));
104 try expect(math.approxEqAbs(f32, cosh32(0.2), 1.020067, epsilon));
105 try expect(math.approxEqAbs(f32, cosh32(0.8923), 1.425225, epsilon));
106 try expect(math.approxEqAbs(f32, cosh32(1.5), 2.352410, epsilon));
107 try expect(math.approxEqAbs(f32, cosh32(-0.0), 1.0, epsilon));
108 try expect(math.approxEqAbs(f32, cosh32(-0.2), 1.020067, epsilon));
109 try expect(math.approxEqAbs(f32, cosh32(-0.8923), 1.425225, epsilon));
110 try expect(math.approxEqAbs(f32, cosh32(-1.5), 2.352410, epsilon));
111111}
112112
113113test "math.cosh64" {
114114 const epsilon = 0.000001;
115115
116 expect(math.approxEqAbs(f64, cosh64(0.0), 1.0, epsilon));
117 expect(math.approxEqAbs(f64, cosh64(0.2), 1.020067, epsilon));
118 expect(math.approxEqAbs(f64, cosh64(0.8923), 1.425225, epsilon));
119 expect(math.approxEqAbs(f64, cosh64(1.5), 2.352410, epsilon));
120 expect(math.approxEqAbs(f64, cosh64(-0.0), 1.0, epsilon));
121 expect(math.approxEqAbs(f64, cosh64(-0.2), 1.020067, epsilon));
122 expect(math.approxEqAbs(f64, cosh64(-0.8923), 1.425225, epsilon));
123 expect(math.approxEqAbs(f64, cosh64(-1.5), 2.352410, epsilon));
116 try expect(math.approxEqAbs(f64, cosh64(0.0), 1.0, epsilon));
117 try expect(math.approxEqAbs(f64, cosh64(0.2), 1.020067, epsilon));
118 try expect(math.approxEqAbs(f64, cosh64(0.8923), 1.425225, epsilon));
119 try expect(math.approxEqAbs(f64, cosh64(1.5), 2.352410, epsilon));
120 try expect(math.approxEqAbs(f64, cosh64(-0.0), 1.0, epsilon));
121 try expect(math.approxEqAbs(f64, cosh64(-0.2), 1.020067, epsilon));
122 try expect(math.approxEqAbs(f64, cosh64(-0.8923), 1.425225, epsilon));
123 try expect(math.approxEqAbs(f64, cosh64(-1.5), 2.352410, epsilon));
124124}
125125
126126test "math.cosh32.special" {
127 expect(cosh32(0.0) == 1.0);
128 expect(cosh32(-0.0) == 1.0);
129 expect(math.isPositiveInf(cosh32(math.inf(f32))));
130 expect(math.isPositiveInf(cosh32(-math.inf(f32))));
131 expect(math.isNan(cosh32(math.nan(f32))));
127 try expect(cosh32(0.0) == 1.0);
128 try expect(cosh32(-0.0) == 1.0);
129 try expect(math.isPositiveInf(cosh32(math.inf(f32))));
130 try expect(math.isPositiveInf(cosh32(-math.inf(f32))));
131 try expect(math.isNan(cosh32(math.nan(f32))));
132132}
133133
134134test "math.cosh64.special" {
135 expect(cosh64(0.0) == 1.0);
136 expect(cosh64(-0.0) == 1.0);
137 expect(math.isPositiveInf(cosh64(math.inf(f64))));
138 expect(math.isPositiveInf(cosh64(-math.inf(f64))));
139 expect(math.isNan(cosh64(math.nan(f64))));
135 try expect(cosh64(0.0) == 1.0);
136 try expect(cosh64(-0.0) == 1.0);
137 try expect(math.isPositiveInf(cosh64(math.inf(f64))));
138 try expect(math.isPositiveInf(cosh64(-math.inf(f64))));
139 try expect(math.isNan(cosh64(math.nan(f64))));
140140}
lib/std/math/exp.zig+16-16
......@@ -187,36 +187,36 @@ fn exp64(x_: f64) f64 {
187187}
188188
189189test "math.exp" {
190 expect(exp(@as(f32, 0.0)) == exp32(0.0));
191 expect(exp(@as(f64, 0.0)) == exp64(0.0));
190 try expect(exp(@as(f32, 0.0)) == exp32(0.0));
191 try expect(exp(@as(f64, 0.0)) == exp64(0.0));
192192}
193193
194194test "math.exp32" {
195195 const epsilon = 0.000001;
196196
197 expect(exp32(0.0) == 1.0);
198 expect(math.approxEqAbs(f32, exp32(0.0), 1.0, epsilon));
199 expect(math.approxEqAbs(f32, exp32(0.2), 1.221403, epsilon));
200 expect(math.approxEqAbs(f32, exp32(0.8923), 2.440737, epsilon));
201 expect(math.approxEqAbs(f32, exp32(1.5), 4.481689, epsilon));
197 try expect(exp32(0.0) == 1.0);
198 try expect(math.approxEqAbs(f32, exp32(0.0), 1.0, epsilon));
199 try expect(math.approxEqAbs(f32, exp32(0.2), 1.221403, epsilon));
200 try expect(math.approxEqAbs(f32, exp32(0.8923), 2.440737, epsilon));
201 try expect(math.approxEqAbs(f32, exp32(1.5), 4.481689, epsilon));
202202}
203203
204204test "math.exp64" {
205205 const epsilon = 0.000001;
206206
207 expect(exp64(0.0) == 1.0);
208 expect(math.approxEqAbs(f64, exp64(0.0), 1.0, epsilon));
209 expect(math.approxEqAbs(f64, exp64(0.2), 1.221403, epsilon));
210 expect(math.approxEqAbs(f64, exp64(0.8923), 2.440737, epsilon));
211 expect(math.approxEqAbs(f64, exp64(1.5), 4.481689, epsilon));
207 try expect(exp64(0.0) == 1.0);
208 try expect(math.approxEqAbs(f64, exp64(0.0), 1.0, epsilon));
209 try expect(math.approxEqAbs(f64, exp64(0.2), 1.221403, epsilon));
210 try expect(math.approxEqAbs(f64, exp64(0.8923), 2.440737, epsilon));
211 try expect(math.approxEqAbs(f64, exp64(1.5), 4.481689, epsilon));
212212}
213213
214214test "math.exp32.special" {
215 expect(math.isPositiveInf(exp32(math.inf(f32))));
216 expect(math.isNan(exp32(math.nan(f32))));
215 try expect(math.isPositiveInf(exp32(math.inf(f32))));
216 try expect(math.isNan(exp32(math.nan(f32))));
217217}
218218
219219test "math.exp64.special" {
220 expect(math.isPositiveInf(exp64(math.inf(f64))));
221 expect(math.isNan(exp64(math.nan(f64))));
220 try expect(math.isPositiveInf(exp64(math.inf(f64))));
221 try expect(math.isNan(exp64(math.nan(f64))));
222222}
lib/std/math/exp2.zig+15-15
......@@ -426,35 +426,35 @@ fn exp2_64(x: f64) f64 {
426426}
427427
428428test "math.exp2" {
429 expect(exp2(@as(f32, 0.8923)) == exp2_32(0.8923));
430 expect(exp2(@as(f64, 0.8923)) == exp2_64(0.8923));
429 try expect(exp2(@as(f32, 0.8923)) == exp2_32(0.8923));
430 try expect(exp2(@as(f64, 0.8923)) == exp2_64(0.8923));
431431}
432432
433433test "math.exp2_32" {
434434 const epsilon = 0.000001;
435435
436 expect(exp2_32(0.0) == 1.0);
437 expect(math.approxEqAbs(f32, exp2_32(0.2), 1.148698, epsilon));
438 expect(math.approxEqAbs(f32, exp2_32(0.8923), 1.856133, epsilon));
439 expect(math.approxEqAbs(f32, exp2_32(1.5), 2.828427, epsilon));
440 expect(math.approxEqAbs(f32, exp2_32(37.45), 187747237888, epsilon));
436 try expect(exp2_32(0.0) == 1.0);
437 try expect(math.approxEqAbs(f32, exp2_32(0.2), 1.148698, epsilon));
438 try expect(math.approxEqAbs(f32, exp2_32(0.8923), 1.856133, epsilon));
439 try expect(math.approxEqAbs(f32, exp2_32(1.5), 2.828427, epsilon));
440 try expect(math.approxEqAbs(f32, exp2_32(37.45), 187747237888, epsilon));
441441}
442442
443443test "math.exp2_64" {
444444 const epsilon = 0.000001;
445445
446 expect(exp2_64(0.0) == 1.0);
447 expect(math.approxEqAbs(f64, exp2_64(0.2), 1.148698, epsilon));
448 expect(math.approxEqAbs(f64, exp2_64(0.8923), 1.856133, epsilon));
449 expect(math.approxEqAbs(f64, exp2_64(1.5), 2.828427, epsilon));
446 try expect(exp2_64(0.0) == 1.0);
447 try expect(math.approxEqAbs(f64, exp2_64(0.2), 1.148698, epsilon));
448 try expect(math.approxEqAbs(f64, exp2_64(0.8923), 1.856133, epsilon));
449 try expect(math.approxEqAbs(f64, exp2_64(1.5), 2.828427, epsilon));
450450}
451451
452452test "math.exp2_32.special" {
453 expect(math.isPositiveInf(exp2_32(math.inf(f32))));
454 expect(math.isNan(exp2_32(math.nan(f32))));
453 try expect(math.isPositiveInf(exp2_32(math.inf(f32))));
454 try expect(math.isNan(exp2_32(math.nan(f32))));
455455}
456456
457457test "math.exp2_64.special" {
458 expect(math.isPositiveInf(exp2_64(math.inf(f64))));
459 expect(math.isNan(exp2_64(math.nan(f64))));
458 try expect(math.isPositiveInf(exp2_64(math.inf(f64))));
459 try expect(math.isNan(exp2_64(math.nan(f64))));
460460}
lib/std/math/expm1.zig+18-18
......@@ -292,42 +292,42 @@ fn expm1_64(x_: f64) f64 {
292292}
293293
294294test "math.exp1m" {
295 expect(expm1(@as(f32, 0.0)) == expm1_32(0.0));
296 expect(expm1(@as(f64, 0.0)) == expm1_64(0.0));
295 try expect(expm1(@as(f32, 0.0)) == expm1_32(0.0));
296 try expect(expm1(@as(f64, 0.0)) == expm1_64(0.0));
297297}
298298
299299test "math.expm1_32" {
300300 const epsilon = 0.000001;
301301
302 expect(expm1_32(0.0) == 0.0);
303 expect(math.approxEqAbs(f32, expm1_32(0.0), 0.0, epsilon));
304 expect(math.approxEqAbs(f32, expm1_32(0.2), 0.221403, epsilon));
305 expect(math.approxEqAbs(f32, expm1_32(0.8923), 1.440737, epsilon));
306 expect(math.approxEqAbs(f32, expm1_32(1.5), 3.481689, epsilon));
302 try expect(expm1_32(0.0) == 0.0);
303 try expect(math.approxEqAbs(f32, expm1_32(0.0), 0.0, epsilon));
304 try expect(math.approxEqAbs(f32, expm1_32(0.2), 0.221403, epsilon));
305 try expect(math.approxEqAbs(f32, expm1_32(0.8923), 1.440737, epsilon));
306 try expect(math.approxEqAbs(f32, expm1_32(1.5), 3.481689, epsilon));
307307}
308308
309309test "math.expm1_64" {
310310 const epsilon = 0.000001;
311311
312 expect(expm1_64(0.0) == 0.0);
313 expect(math.approxEqAbs(f64, expm1_64(0.0), 0.0, epsilon));
314 expect(math.approxEqAbs(f64, expm1_64(0.2), 0.221403, epsilon));
315 expect(math.approxEqAbs(f64, expm1_64(0.8923), 1.440737, epsilon));
316 expect(math.approxEqAbs(f64, expm1_64(1.5), 3.481689, epsilon));
312 try expect(expm1_64(0.0) == 0.0);
313 try expect(math.approxEqAbs(f64, expm1_64(0.0), 0.0, epsilon));
314 try expect(math.approxEqAbs(f64, expm1_64(0.2), 0.221403, epsilon));
315 try expect(math.approxEqAbs(f64, expm1_64(0.8923), 1.440737, epsilon));
316 try expect(math.approxEqAbs(f64, expm1_64(1.5), 3.481689, epsilon));
317317}
318318
319319test "math.expm1_32.special" {
320320 const epsilon = 0.000001;
321321
322 expect(math.isPositiveInf(expm1_32(math.inf(f32))));
323 expect(expm1_32(-math.inf(f32)) == -1.0);
324 expect(math.isNan(expm1_32(math.nan(f32))));
322 try expect(math.isPositiveInf(expm1_32(math.inf(f32))));
323 try expect(expm1_32(-math.inf(f32)) == -1.0);
324 try expect(math.isNan(expm1_32(math.nan(f32))));
325325}
326326
327327test "math.expm1_64.special" {
328328 const epsilon = 0.000001;
329329
330 expect(math.isPositiveInf(expm1_64(math.inf(f64))));
331 expect(expm1_64(-math.inf(f64)) == -1.0);
332 expect(math.isNan(expm1_64(math.nan(f64))));
330 try expect(math.isPositiveInf(expm1_64(math.inf(f64))));
331 try expect(expm1_64(-math.inf(f64)) == -1.0);
332 try expect(math.isNan(expm1_64(math.nan(f64))));
333333}
lib/std/math/fabs.zig+24-24
......@@ -55,52 +55,52 @@ fn fabs128(x: f128) f128 {
5555}
5656
5757test "math.fabs" {
58 expect(fabs(@as(f16, 1.0)) == fabs16(1.0));
59 expect(fabs(@as(f32, 1.0)) == fabs32(1.0));
60 expect(fabs(@as(f64, 1.0)) == fabs64(1.0));
61 expect(fabs(@as(f128, 1.0)) == fabs128(1.0));
58 try expect(fabs(@as(f16, 1.0)) == fabs16(1.0));
59 try expect(fabs(@as(f32, 1.0)) == fabs32(1.0));
60 try expect(fabs(@as(f64, 1.0)) == fabs64(1.0));
61 try expect(fabs(@as(f128, 1.0)) == fabs128(1.0));
6262}
6363
6464test "math.fabs16" {
65 expect(fabs16(1.0) == 1.0);
66 expect(fabs16(-1.0) == 1.0);
65 try expect(fabs16(1.0) == 1.0);
66 try expect(fabs16(-1.0) == 1.0);
6767}
6868
6969test "math.fabs32" {
70 expect(fabs32(1.0) == 1.0);
71 expect(fabs32(-1.0) == 1.0);
70 try expect(fabs32(1.0) == 1.0);
71 try expect(fabs32(-1.0) == 1.0);
7272}
7373
7474test "math.fabs64" {
75 expect(fabs64(1.0) == 1.0);
76 expect(fabs64(-1.0) == 1.0);
75 try expect(fabs64(1.0) == 1.0);
76 try expect(fabs64(-1.0) == 1.0);
7777}
7878
7979test "math.fabs128" {
80 expect(fabs128(1.0) == 1.0);
81 expect(fabs128(-1.0) == 1.0);
80 try expect(fabs128(1.0) == 1.0);
81 try expect(fabs128(-1.0) == 1.0);
8282}
8383
8484test "math.fabs16.special" {
85 expect(math.isPositiveInf(fabs(math.inf(f16))));
86 expect(math.isPositiveInf(fabs(-math.inf(f16))));
87 expect(math.isNan(fabs(math.nan(f16))));
85 try expect(math.isPositiveInf(fabs(math.inf(f16))));
86 try expect(math.isPositiveInf(fabs(-math.inf(f16))));
87 try expect(math.isNan(fabs(math.nan(f16))));
8888}
8989
9090test "math.fabs32.special" {
91 expect(math.isPositiveInf(fabs(math.inf(f32))));
92 expect(math.isPositiveInf(fabs(-math.inf(f32))));
93 expect(math.isNan(fabs(math.nan(f32))));
91 try expect(math.isPositiveInf(fabs(math.inf(f32))));
92 try expect(math.isPositiveInf(fabs(-math.inf(f32))));
93 try expect(math.isNan(fabs(math.nan(f32))));
9494}
9595
9696test "math.fabs64.special" {
97 expect(math.isPositiveInf(fabs(math.inf(f64))));
98 expect(math.isPositiveInf(fabs(-math.inf(f64))));
99 expect(math.isNan(fabs(math.nan(f64))));
97 try expect(math.isPositiveInf(fabs(math.inf(f64))));
98 try expect(math.isPositiveInf(fabs(-math.inf(f64))));
99 try expect(math.isNan(fabs(math.nan(f64))));
100100}
101101
102102test "math.fabs128.special" {
103 expect(math.isPositiveInf(fabs(math.inf(f128))));
104 expect(math.isPositiveInf(fabs(-math.inf(f128))));
105 expect(math.isNan(fabs(math.nan(f128))));
103 try expect(math.isPositiveInf(fabs(math.inf(f128))));
104 try expect(math.isPositiveInf(fabs(-math.inf(f128))));
105 try expect(math.isNan(fabs(math.nan(f128))));
106106}
lib/std/math/floor.zig+36-36
......@@ -156,64 +156,64 @@ fn floor128(x: f128) f128 {
156156}
157157
158158test "math.floor" {
159 expect(floor(@as(f16, 1.3)) == floor16(1.3));
160 expect(floor(@as(f32, 1.3)) == floor32(1.3));
161 expect(floor(@as(f64, 1.3)) == floor64(1.3));
162 expect(floor(@as(f128, 1.3)) == floor128(1.3));
159 try expect(floor(@as(f16, 1.3)) == floor16(1.3));
160 try expect(floor(@as(f32, 1.3)) == floor32(1.3));
161 try expect(floor(@as(f64, 1.3)) == floor64(1.3));
162 try expect(floor(@as(f128, 1.3)) == floor128(1.3));
163163}
164164
165165test "math.floor16" {
166 expect(floor16(1.3) == 1.0);
167 expect(floor16(-1.3) == -2.0);
168 expect(floor16(0.2) == 0.0);
166 try expect(floor16(1.3) == 1.0);
167 try expect(floor16(-1.3) == -2.0);
168 try expect(floor16(0.2) == 0.0);
169169}
170170
171171test "math.floor32" {
172 expect(floor32(1.3) == 1.0);
173 expect(floor32(-1.3) == -2.0);
174 expect(floor32(0.2) == 0.0);
172 try expect(floor32(1.3) == 1.0);
173 try expect(floor32(-1.3) == -2.0);
174 try expect(floor32(0.2) == 0.0);
175175}
176176
177177test "math.floor64" {
178 expect(floor64(1.3) == 1.0);
179 expect(floor64(-1.3) == -2.0);
180 expect(floor64(0.2) == 0.0);
178 try expect(floor64(1.3) == 1.0);
179 try expect(floor64(-1.3) == -2.0);
180 try expect(floor64(0.2) == 0.0);
181181}
182182
183183test "math.floor128" {
184 expect(floor128(1.3) == 1.0);
185 expect(floor128(-1.3) == -2.0);
186 expect(floor128(0.2) == 0.0);
184 try expect(floor128(1.3) == 1.0);
185 try expect(floor128(-1.3) == -2.0);
186 try expect(floor128(0.2) == 0.0);
187187}
188188
189189test "math.floor16.special" {
190 expect(floor16(0.0) == 0.0);
191 expect(floor16(-0.0) == -0.0);
192 expect(math.isPositiveInf(floor16(math.inf(f16))));
193 expect(math.isNegativeInf(floor16(-math.inf(f16))));
194 expect(math.isNan(floor16(math.nan(f16))));
190 try expect(floor16(0.0) == 0.0);
191 try expect(floor16(-0.0) == -0.0);
192 try expect(math.isPositiveInf(floor16(math.inf(f16))));
193 try expect(math.isNegativeInf(floor16(-math.inf(f16))));
194 try expect(math.isNan(floor16(math.nan(f16))));
195195}
196196
197197test "math.floor32.special" {
198 expect(floor32(0.0) == 0.0);
199 expect(floor32(-0.0) == -0.0);
200 expect(math.isPositiveInf(floor32(math.inf(f32))));
201 expect(math.isNegativeInf(floor32(-math.inf(f32))));
202 expect(math.isNan(floor32(math.nan(f32))));
198 try expect(floor32(0.0) == 0.0);
199 try expect(floor32(-0.0) == -0.0);
200 try expect(math.isPositiveInf(floor32(math.inf(f32))));
201 try expect(math.isNegativeInf(floor32(-math.inf(f32))));
202 try expect(math.isNan(floor32(math.nan(f32))));
203203}
204204
205205test "math.floor64.special" {
206 expect(floor64(0.0) == 0.0);
207 expect(floor64(-0.0) == -0.0);
208 expect(math.isPositiveInf(floor64(math.inf(f64))));
209 expect(math.isNegativeInf(floor64(-math.inf(f64))));
210 expect(math.isNan(floor64(math.nan(f64))));
206 try expect(floor64(0.0) == 0.0);
207 try expect(floor64(-0.0) == -0.0);
208 try expect(math.isPositiveInf(floor64(math.inf(f64))));
209 try expect(math.isNegativeInf(floor64(-math.inf(f64))));
210 try expect(math.isNan(floor64(math.nan(f64))));
211211}
212212
213213test "math.floor128.special" {
214 expect(floor128(0.0) == 0.0);
215 expect(floor128(-0.0) == -0.0);
216 expect(math.isPositiveInf(floor128(math.inf(f128))));
217 expect(math.isNegativeInf(floor128(-math.inf(f128))));
218 expect(math.isNan(floor128(math.nan(f128))));
214 try expect(floor128(0.0) == 0.0);
215 try expect(floor128(-0.0) == -0.0);
216 try expect(math.isPositiveInf(floor128(math.inf(f128))));
217 try expect(math.isNegativeInf(floor128(-math.inf(f128))));
218 try expect(math.isNan(floor128(math.nan(f128))));
219219}
lib/std/math/fma.zig+16-16
......@@ -148,30 +148,30 @@ fn add_and_denorm(a: f64, b: f64, scale: i32) f64 {
148148}
149149
150150test "math.fma" {
151 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));
151 try expect(fma(f32, 0.0, 1.0, 1.0) == fma32(0.0, 1.0, 1.0));
152 try expect(fma(f64, 0.0, 1.0, 1.0) == fma64(0.0, 1.0, 1.0));
153153}
154154
155155test "math.fma32" {
156156 const epsilon = 0.000001;
157157
158 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));
160 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));
162 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));
164 expect(math.approxEqAbs(f32, fma32(123123.234375, 5.0, 9.124), 615625.295875, epsilon));
158 try expect(math.approxEqAbs(f32, fma32(0.0, 5.0, 9.124), 9.124, epsilon));
159 try expect(math.approxEqAbs(f32, fma32(0.2, 5.0, 9.124), 10.124, epsilon));
160 try expect(math.approxEqAbs(f32, fma32(0.8923, 5.0, 9.124), 13.5855, epsilon));
161 try expect(math.approxEqAbs(f32, fma32(1.5, 5.0, 9.124), 16.624, epsilon));
162 try expect(math.approxEqAbs(f32, fma32(37.45, 5.0, 9.124), 196.374004, epsilon));
163 try expect(math.approxEqAbs(f32, fma32(89.123, 5.0, 9.124), 454.739005, epsilon));
164 try expect(math.approxEqAbs(f32, fma32(123123.234375, 5.0, 9.124), 615625.295875, epsilon));
165165}
166166
167167test "math.fma64" {
168168 const epsilon = 0.000001;
169169
170 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));
172 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));
174 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));
176 expect(math.approxEqAbs(f64, fma64(123123.234375, 5.0, 9.124), 615625.295875, epsilon));
170 try expect(math.approxEqAbs(f64, fma64(0.0, 5.0, 9.124), 9.124, epsilon));
171 try expect(math.approxEqAbs(f64, fma64(0.2, 5.0, 9.124), 10.124, epsilon));
172 try expect(math.approxEqAbs(f64, fma64(0.8923, 5.0, 9.124), 13.5855, epsilon));
173 try expect(math.approxEqAbs(f64, fma64(1.5, 5.0, 9.124), 16.624, epsilon));
174 try expect(math.approxEqAbs(f64, fma64(37.45, 5.0, 9.124), 196.374, epsilon));
175 try expect(math.approxEqAbs(f64, fma64(89.123, 5.0, 9.124), 454.739, epsilon));
176 try expect(math.approxEqAbs(f64, fma64(123123.234375, 5.0, 9.124), 615625.295875, epsilon));
177177}
lib/std/math/frexp.zig+16-16
......@@ -115,11 +115,11 @@ fn frexp64(x: f64) frexp64_result {
115115test "math.frexp" {
116116 const a = frexp(@as(f32, 1.3));
117117 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
120120 const c = frexp(@as(f64, 1.3));
121121 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);
123123}
124124
125125test "math.frexp32" {
......@@ -127,10 +127,10 @@ test "math.frexp32" {
127127 var r: frexp32_result = undefined;
128128
129129 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
132132 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);
134134}
135135
136136test "math.frexp64" {
......@@ -138,46 +138,46 @@ test "math.frexp64" {
138138 var r: frexp64_result = undefined;
139139
140140 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
143143 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);
145145}
146146
147147test "math.frexp32.special" {
148148 var r: frexp32_result = undefined;
149149
150150 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
153153 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
156156 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
159159 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
162162 r = frexp32(math.nan(f32));
163 expect(math.isNan(r.significand));
163 try expect(math.isNan(r.significand));
164164}
165165
166166test "math.frexp64.special" {
167167 var r: frexp64_result = undefined;
168168
169169 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
172172 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
175175 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
178178 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
181181 r = frexp64(math.nan(f64));
182 expect(math.isNan(r.significand));
182 try expect(math.isNan(r.significand));
183183}
lib/std/math/hypot.zig+28-28
......@@ -126,48 +126,48 @@ fn hypot64(x: f64, y: f64) f64 {
126126}
127127
128128test "math.hypot" {
129 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));
129 try expect(hypot(f32, 0.0, -1.2) == hypot32(0.0, -1.2));
130 try expect(hypot(f64, 0.0, -1.2) == hypot64(0.0, -1.2));
131131}
132132
133133test "math.hypot32" {
134134 const epsilon = 0.000001;
135135
136 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));
138 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));
140 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));
142 expect(math.approxEqAbs(f32, hypot32(123123.234375, 529428.707813), 543556.875, epsilon));
136 try expect(math.approxEqAbs(f32, hypot32(0.0, -1.2), 1.2, epsilon));
137 try expect(math.approxEqAbs(f32, hypot32(0.2, -0.34), 0.394462, epsilon));
138 try expect(math.approxEqAbs(f32, hypot32(0.8923, 2.636890), 2.783772, epsilon));
139 try expect(math.approxEqAbs(f32, hypot32(1.5, 5.25), 5.460083, epsilon));
140 try expect(math.approxEqAbs(f32, hypot32(37.45, 159.835), 164.163742, epsilon));
141 try expect(math.approxEqAbs(f32, hypot32(89.123, 382.028905), 392.286865, epsilon));
142 try expect(math.approxEqAbs(f32, hypot32(123123.234375, 529428.707813), 543556.875, epsilon));
143143}
144144
145145test "math.hypot64" {
146146 const epsilon = 0.000001;
147147
148 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));
150 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));
152 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));
154 expect(math.approxEqAbs(f64, hypot64(123123.234375, 529428.707813), 543556.885247, epsilon));
148 try expect(math.approxEqAbs(f64, hypot64(0.0, -1.2), 1.2, epsilon));
149 try expect(math.approxEqAbs(f64, hypot64(0.2, -0.34), 0.394462, epsilon));
150 try expect(math.approxEqAbs(f64, hypot64(0.8923, 2.636890), 2.783772, epsilon));
151 try expect(math.approxEqAbs(f64, hypot64(1.5, 5.25), 5.460082, epsilon));
152 try expect(math.approxEqAbs(f64, hypot64(37.45, 159.835), 164.163728, epsilon));
153 try expect(math.approxEqAbs(f64, hypot64(89.123, 382.028905), 392.286876, epsilon));
154 try expect(math.approxEqAbs(f64, hypot64(123123.234375, 529428.707813), 543556.885247, epsilon));
155155}
156156
157157test "math.hypot32.special" {
158 expect(math.isPositiveInf(hypot32(math.inf(f32), 0.0)));
159 expect(math.isPositiveInf(hypot32(-math.inf(f32), 0.0)));
160 expect(math.isPositiveInf(hypot32(0.0, math.inf(f32))));
161 expect(math.isPositiveInf(hypot32(0.0, -math.inf(f32))));
162 expect(math.isNan(hypot32(math.nan(f32), 0.0)));
163 expect(math.isNan(hypot32(0.0, math.nan(f32))));
158 try expect(math.isPositiveInf(hypot32(math.inf(f32), 0.0)));
159 try expect(math.isPositiveInf(hypot32(-math.inf(f32), 0.0)));
160 try expect(math.isPositiveInf(hypot32(0.0, math.inf(f32))));
161 try expect(math.isPositiveInf(hypot32(0.0, -math.inf(f32))));
162 try expect(math.isNan(hypot32(math.nan(f32), 0.0)));
163 try expect(math.isNan(hypot32(0.0, math.nan(f32))));
164164}
165165
166166test "math.hypot64.special" {
167 expect(math.isPositiveInf(hypot64(math.inf(f64), 0.0)));
168 expect(math.isPositiveInf(hypot64(-math.inf(f64), 0.0)));
169 expect(math.isPositiveInf(hypot64(0.0, math.inf(f64))));
170 expect(math.isPositiveInf(hypot64(0.0, -math.inf(f64))));
171 expect(math.isNan(hypot64(math.nan(f64), 0.0)));
172 expect(math.isNan(hypot64(0.0, math.nan(f64))));
167 try expect(math.isPositiveInf(hypot64(math.inf(f64), 0.0)));
168 try expect(math.isPositiveInf(hypot64(-math.inf(f64), 0.0)));
169 try expect(math.isPositiveInf(hypot64(0.0, math.inf(f64))));
170 try expect(math.isPositiveInf(hypot64(0.0, -math.inf(f64))));
171 try expect(math.isNan(hypot64(math.nan(f64), 0.0)));
172 try expect(math.isNan(hypot64(0.0, math.nan(f64))));
173173}
lib/std/math/ilogb.zig+22-22
......@@ -106,38 +106,38 @@ fn ilogb64(x: f64) i32 {
106106}
107107
108108test "math.ilogb" {
109 expect(ilogb(@as(f32, 0.2)) == ilogb32(0.2));
110 expect(ilogb(@as(f64, 0.2)) == ilogb64(0.2));
109 try expect(ilogb(@as(f32, 0.2)) == ilogb32(0.2));
110 try expect(ilogb(@as(f64, 0.2)) == ilogb64(0.2));
111111}
112112
113113test "math.ilogb32" {
114 expect(ilogb32(0.0) == fp_ilogb0);
115 expect(ilogb32(0.5) == -1);
116 expect(ilogb32(0.8923) == -1);
117 expect(ilogb32(10.0) == 3);
118 expect(ilogb32(-123984) == 16);
119 expect(ilogb32(2398.23) == 11);
114 try expect(ilogb32(0.0) == fp_ilogb0);
115 try expect(ilogb32(0.5) == -1);
116 try expect(ilogb32(0.8923) == -1);
117 try expect(ilogb32(10.0) == 3);
118 try expect(ilogb32(-123984) == 16);
119 try expect(ilogb32(2398.23) == 11);
120120}
121121
122122test "math.ilogb64" {
123 expect(ilogb64(0.0) == fp_ilogb0);
124 expect(ilogb64(0.5) == -1);
125 expect(ilogb64(0.8923) == -1);
126 expect(ilogb64(10.0) == 3);
127 expect(ilogb64(-123984) == 16);
128 expect(ilogb64(2398.23) == 11);
123 try expect(ilogb64(0.0) == fp_ilogb0);
124 try expect(ilogb64(0.5) == -1);
125 try expect(ilogb64(0.8923) == -1);
126 try expect(ilogb64(10.0) == 3);
127 try expect(ilogb64(-123984) == 16);
128 try expect(ilogb64(2398.23) == 11);
129129}
130130
131131test "math.ilogb32.special" {
132 expect(ilogb32(math.inf(f32)) == maxInt(i32));
133 expect(ilogb32(-math.inf(f32)) == maxInt(i32));
134 expect(ilogb32(0.0) == minInt(i32));
135 expect(ilogb32(math.nan(f32)) == maxInt(i32));
132 try expect(ilogb32(math.inf(f32)) == maxInt(i32));
133 try expect(ilogb32(-math.inf(f32)) == maxInt(i32));
134 try expect(ilogb32(0.0) == minInt(i32));
135 try expect(ilogb32(math.nan(f32)) == maxInt(i32));
136136}
137137
138138test "math.ilogb64.special" {
139 expect(ilogb64(math.inf(f64)) == maxInt(i32));
140 expect(ilogb64(-math.inf(f64)) == maxInt(i32));
141 expect(ilogb64(0.0) == minInt(i32));
142 expect(ilogb64(math.nan(f64)) == maxInt(i32));
139 try expect(ilogb64(math.inf(f64)) == maxInt(i32));
140 try expect(ilogb64(-math.inf(f64)) == maxInt(i32));
141 try expect(ilogb64(0.0) == minInt(i32));
142 try expect(ilogb64(math.nan(f64)) == maxInt(i32));
143143}
lib/std/math/isfinite.zig+24-24
......@@ -35,30 +35,30 @@ pub fn isFinite(x: anytype) bool {
3535}
3636
3737test "math.isFinite" {
38 expect(isFinite(@as(f16, 0.0)));
39 expect(isFinite(@as(f16, -0.0)));
40 expect(isFinite(@as(f32, 0.0)));
41 expect(isFinite(@as(f32, -0.0)));
42 expect(isFinite(@as(f64, 0.0)));
43 expect(isFinite(@as(f64, -0.0)));
44 expect(isFinite(@as(f128, 0.0)));
45 expect(isFinite(@as(f128, -0.0)));
38 try expect(isFinite(@as(f16, 0.0)));
39 try expect(isFinite(@as(f16, -0.0)));
40 try expect(isFinite(@as(f32, 0.0)));
41 try expect(isFinite(@as(f32, -0.0)));
42 try expect(isFinite(@as(f64, 0.0)));
43 try expect(isFinite(@as(f64, -0.0)));
44 try expect(isFinite(@as(f128, 0.0)));
45 try expect(isFinite(@as(f128, -0.0)));
4646
47 expect(!isFinite(math.inf(f16)));
48 expect(!isFinite(-math.inf(f16)));
49 expect(!isFinite(math.inf(f32)));
50 expect(!isFinite(-math.inf(f32)));
51 expect(!isFinite(math.inf(f64)));
52 expect(!isFinite(-math.inf(f64)));
53 expect(!isFinite(math.inf(f128)));
54 expect(!isFinite(-math.inf(f128)));
47 try expect(!isFinite(math.inf(f16)));
48 try expect(!isFinite(-math.inf(f16)));
49 try expect(!isFinite(math.inf(f32)));
50 try expect(!isFinite(-math.inf(f32)));
51 try expect(!isFinite(math.inf(f64)));
52 try expect(!isFinite(-math.inf(f64)));
53 try expect(!isFinite(math.inf(f128)));
54 try expect(!isFinite(-math.inf(f128)));
5555
56 expect(!isFinite(math.nan(f16)));
57 expect(!isFinite(-math.nan(f16)));
58 expect(!isFinite(math.nan(f32)));
59 expect(!isFinite(-math.nan(f32)));
60 expect(!isFinite(math.nan(f64)));
61 expect(!isFinite(-math.nan(f64)));
62 expect(!isFinite(math.nan(f128)));
63 expect(!isFinite(-math.nan(f128)));
56 try expect(!isFinite(math.nan(f16)));
57 try expect(!isFinite(-math.nan(f16)));
58 try expect(!isFinite(math.nan(f32)));
59 try expect(!isFinite(-math.nan(f32)));
60 try expect(!isFinite(math.nan(f64)));
61 try expect(!isFinite(-math.nan(f64)));
62 try expect(!isFinite(math.nan(f128)));
63 try expect(!isFinite(-math.nan(f128)));
6464}
lib/std/math/isinf.zig+48-48
......@@ -79,58 +79,58 @@ pub fn isNegativeInf(x: anytype) bool {
7979}
8080
8181test "math.isInf" {
82 expect(!isInf(@as(f16, 0.0)));
83 expect(!isInf(@as(f16, -0.0)));
84 expect(!isInf(@as(f32, 0.0)));
85 expect(!isInf(@as(f32, -0.0)));
86 expect(!isInf(@as(f64, 0.0)));
87 expect(!isInf(@as(f64, -0.0)));
88 expect(!isInf(@as(f128, 0.0)));
89 expect(!isInf(@as(f128, -0.0)));
90 expect(isInf(math.inf(f16)));
91 expect(isInf(-math.inf(f16)));
92 expect(isInf(math.inf(f32)));
93 expect(isInf(-math.inf(f32)));
94 expect(isInf(math.inf(f64)));
95 expect(isInf(-math.inf(f64)));
96 expect(isInf(math.inf(f128)));
97 expect(isInf(-math.inf(f128)));
82 try expect(!isInf(@as(f16, 0.0)));
83 try expect(!isInf(@as(f16, -0.0)));
84 try expect(!isInf(@as(f32, 0.0)));
85 try expect(!isInf(@as(f32, -0.0)));
86 try expect(!isInf(@as(f64, 0.0)));
87 try expect(!isInf(@as(f64, -0.0)));
88 try expect(!isInf(@as(f128, 0.0)));
89 try expect(!isInf(@as(f128, -0.0)));
90 try expect(isInf(math.inf(f16)));
91 try expect(isInf(-math.inf(f16)));
92 try expect(isInf(math.inf(f32)));
93 try expect(isInf(-math.inf(f32)));
94 try expect(isInf(math.inf(f64)));
95 try expect(isInf(-math.inf(f64)));
96 try expect(isInf(math.inf(f128)));
97 try expect(isInf(-math.inf(f128)));
9898}
9999
100100test "math.isPositiveInf" {
101 expect(!isPositiveInf(@as(f16, 0.0)));
102 expect(!isPositiveInf(@as(f16, -0.0)));
103 expect(!isPositiveInf(@as(f32, 0.0)));
104 expect(!isPositiveInf(@as(f32, -0.0)));
105 expect(!isPositiveInf(@as(f64, 0.0)));
106 expect(!isPositiveInf(@as(f64, -0.0)));
107 expect(!isPositiveInf(@as(f128, 0.0)));
108 expect(!isPositiveInf(@as(f128, -0.0)));
109 expect(isPositiveInf(math.inf(f16)));
110 expect(!isPositiveInf(-math.inf(f16)));
111 expect(isPositiveInf(math.inf(f32)));
112 expect(!isPositiveInf(-math.inf(f32)));
113 expect(isPositiveInf(math.inf(f64)));
114 expect(!isPositiveInf(-math.inf(f64)));
115 expect(isPositiveInf(math.inf(f128)));
116 expect(!isPositiveInf(-math.inf(f128)));
101 try expect(!isPositiveInf(@as(f16, 0.0)));
102 try expect(!isPositiveInf(@as(f16, -0.0)));
103 try expect(!isPositiveInf(@as(f32, 0.0)));
104 try expect(!isPositiveInf(@as(f32, -0.0)));
105 try expect(!isPositiveInf(@as(f64, 0.0)));
106 try expect(!isPositiveInf(@as(f64, -0.0)));
107 try expect(!isPositiveInf(@as(f128, 0.0)));
108 try expect(!isPositiveInf(@as(f128, -0.0)));
109 try expect(isPositiveInf(math.inf(f16)));
110 try expect(!isPositiveInf(-math.inf(f16)));
111 try expect(isPositiveInf(math.inf(f32)));
112 try expect(!isPositiveInf(-math.inf(f32)));
113 try expect(isPositiveInf(math.inf(f64)));
114 try expect(!isPositiveInf(-math.inf(f64)));
115 try expect(isPositiveInf(math.inf(f128)));
116 try expect(!isPositiveInf(-math.inf(f128)));
117117}
118118
119119test "math.isNegativeInf" {
120 expect(!isNegativeInf(@as(f16, 0.0)));
121 expect(!isNegativeInf(@as(f16, -0.0)));
122 expect(!isNegativeInf(@as(f32, 0.0)));
123 expect(!isNegativeInf(@as(f32, -0.0)));
124 expect(!isNegativeInf(@as(f64, 0.0)));
125 expect(!isNegativeInf(@as(f64, -0.0)));
126 expect(!isNegativeInf(@as(f128, 0.0)));
127 expect(!isNegativeInf(@as(f128, -0.0)));
128 expect(!isNegativeInf(math.inf(f16)));
129 expect(isNegativeInf(-math.inf(f16)));
130 expect(!isNegativeInf(math.inf(f32)));
131 expect(isNegativeInf(-math.inf(f32)));
132 expect(!isNegativeInf(math.inf(f64)));
133 expect(isNegativeInf(-math.inf(f64)));
134 expect(!isNegativeInf(math.inf(f128)));
135 expect(isNegativeInf(-math.inf(f128)));
120 try expect(!isNegativeInf(@as(f16, 0.0)));
121 try expect(!isNegativeInf(@as(f16, -0.0)));
122 try expect(!isNegativeInf(@as(f32, 0.0)));
123 try expect(!isNegativeInf(@as(f32, -0.0)));
124 try expect(!isNegativeInf(@as(f64, 0.0)));
125 try expect(!isNegativeInf(@as(f64, -0.0)));
126 try expect(!isNegativeInf(@as(f128, 0.0)));
127 try expect(!isNegativeInf(@as(f128, -0.0)));
128 try expect(!isNegativeInf(math.inf(f16)));
129 try expect(isNegativeInf(-math.inf(f16)));
130 try expect(!isNegativeInf(math.inf(f32)));
131 try expect(isNegativeInf(-math.inf(f32)));
132 try expect(!isNegativeInf(math.inf(f64)));
133 try expect(isNegativeInf(-math.inf(f64)));
134 try expect(!isNegativeInf(math.inf(f128)));
135 try expect(isNegativeInf(-math.inf(f128)));
136136}
lib/std/math/isnan.zig+8-8
......@@ -21,12 +21,12 @@ pub fn isSignalNan(x: anytype) bool {
2121}
2222
2323test "math.isNan" {
24 expect(isNan(math.nan(f16)));
25 expect(isNan(math.nan(f32)));
26 expect(isNan(math.nan(f64)));
27 expect(isNan(math.nan(f128)));
28 expect(!isNan(@as(f16, 1.0)));
29 expect(!isNan(@as(f32, 1.0)));
30 expect(!isNan(@as(f64, 1.0)));
31 expect(!isNan(@as(f128, 1.0)));
24 try expect(isNan(math.nan(f16)));
25 try expect(isNan(math.nan(f32)));
26 try expect(isNan(math.nan(f64)));
27 try expect(isNan(math.nan(f128)));
28 try expect(!isNan(@as(f16, 1.0)));
29 try expect(!isNan(@as(f32, 1.0)));
30 try expect(!isNan(@as(f64, 1.0)));
31 try expect(!isNan(@as(f128, 1.0)));
3232}
lib/std/math/isnormal.zig+9-9
......@@ -31,13 +31,13 @@ pub fn isNormal(x: anytype) bool {
3131}
3232
3333test "math.isNormal" {
34 expect(!isNormal(math.nan(f16)));
35 expect(!isNormal(math.nan(f32)));
36 expect(!isNormal(math.nan(f64)));
37 expect(!isNormal(@as(f16, 0)));
38 expect(!isNormal(@as(f32, 0)));
39 expect(!isNormal(@as(f64, 0)));
40 expect(isNormal(@as(f16, 1.0)));
41 expect(isNormal(@as(f32, 1.0)));
42 expect(isNormal(@as(f64, 1.0)));
34 try expect(!isNormal(math.nan(f16)));
35 try expect(!isNormal(math.nan(f32)));
36 try expect(!isNormal(math.nan(f64)));
37 try expect(!isNormal(@as(f16, 0)));
38 try expect(!isNormal(@as(f32, 0)));
39 try expect(!isNormal(@as(f64, 0)));
40 try expect(isNormal(@as(f16, 1.0)));
41 try expect(isNormal(@as(f32, 1.0)));
42 try expect(isNormal(@as(f64, 1.0)));
4343}
lib/std/math/ln.zig+22-22
......@@ -153,42 +153,42 @@ pub fn ln_64(x_: f64) f64 {
153153}
154154
155155test "math.ln" {
156 expect(ln(@as(f32, 0.2)) == ln_32(0.2));
157 expect(ln(@as(f64, 0.2)) == ln_64(0.2));
156 try expect(ln(@as(f32, 0.2)) == ln_32(0.2));
157 try expect(ln(@as(f64, 0.2)) == ln_64(0.2));
158158}
159159
160160test "math.ln32" {
161161 const epsilon = 0.000001;
162162
163 expect(math.approxEqAbs(f32, ln_32(0.2), -1.609438, epsilon));
164 expect(math.approxEqAbs(f32, ln_32(0.8923), -0.113953, epsilon));
165 expect(math.approxEqAbs(f32, ln_32(1.5), 0.405465, epsilon));
166 expect(math.approxEqAbs(f32, ln_32(37.45), 3.623007, epsilon));
167 expect(math.approxEqAbs(f32, ln_32(89.123), 4.490017, epsilon));
168 expect(math.approxEqAbs(f32, ln_32(123123.234375), 11.720941, epsilon));
163 try expect(math.approxEqAbs(f32, ln_32(0.2), -1.609438, epsilon));
164 try expect(math.approxEqAbs(f32, ln_32(0.8923), -0.113953, epsilon));
165 try expect(math.approxEqAbs(f32, ln_32(1.5), 0.405465, epsilon));
166 try expect(math.approxEqAbs(f32, ln_32(37.45), 3.623007, epsilon));
167 try expect(math.approxEqAbs(f32, ln_32(89.123), 4.490017, epsilon));
168 try expect(math.approxEqAbs(f32, ln_32(123123.234375), 11.720941, epsilon));
169169}
170170
171171test "math.ln64" {
172172 const epsilon = 0.000001;
173173
174 expect(math.approxEqAbs(f64, ln_64(0.2), -1.609438, epsilon));
175 expect(math.approxEqAbs(f64, ln_64(0.8923), -0.113953, epsilon));
176 expect(math.approxEqAbs(f64, ln_64(1.5), 0.405465, epsilon));
177 expect(math.approxEqAbs(f64, ln_64(37.45), 3.623007, epsilon));
178 expect(math.approxEqAbs(f64, ln_64(89.123), 4.490017, epsilon));
179 expect(math.approxEqAbs(f64, ln_64(123123.234375), 11.720941, epsilon));
174 try expect(math.approxEqAbs(f64, ln_64(0.2), -1.609438, epsilon));
175 try expect(math.approxEqAbs(f64, ln_64(0.8923), -0.113953, epsilon));
176 try expect(math.approxEqAbs(f64, ln_64(1.5), 0.405465, epsilon));
177 try expect(math.approxEqAbs(f64, ln_64(37.45), 3.623007, epsilon));
178 try expect(math.approxEqAbs(f64, ln_64(89.123), 4.490017, epsilon));
179 try expect(math.approxEqAbs(f64, ln_64(123123.234375), 11.720941, epsilon));
180180}
181181
182182test "math.ln32.special" {
183 expect(math.isPositiveInf(ln_32(math.inf(f32))));
184 expect(math.isNegativeInf(ln_32(0.0)));
185 expect(math.isNan(ln_32(-1.0)));
186 expect(math.isNan(ln_32(math.nan(f32))));
183 try expect(math.isPositiveInf(ln_32(math.inf(f32))));
184 try expect(math.isNegativeInf(ln_32(0.0)));
185 try expect(math.isNan(ln_32(-1.0)));
186 try expect(math.isNan(ln_32(math.nan(f32))));
187187}
188188
189189test "math.ln64.special" {
190 expect(math.isPositiveInf(ln_64(math.inf(f64))));
191 expect(math.isNegativeInf(ln_64(0.0)));
192 expect(math.isNan(ln_64(-1.0)));
193 expect(math.isNan(ln_64(math.nan(f64))));
190 try expect(math.isPositiveInf(ln_64(math.inf(f64))));
191 try expect(math.isNegativeInf(ln_64(0.0)));
192 try expect(math.isNan(ln_64(-1.0)));
193 try expect(math.isNan(ln_64(math.nan(f64))));
194194}
lib/std/math/log.zig+12-12
......@@ -53,25 +53,25 @@ pub fn log(comptime T: type, base: T, x: T) T {
5353}
5454
5555test "math.log integer" {
56 expect(log(u8, 2, 0x1) == 0);
57 expect(log(u8, 2, 0x2) == 1);
58 expect(log(u16, 2, 0x72) == 6);
59 expect(log(u32, 2, 0xFFFFFF) == 23);
60 expect(log(u64, 2, 0x7FF0123456789ABC) == 62);
56 try expect(log(u8, 2, 0x1) == 0);
57 try expect(log(u8, 2, 0x2) == 1);
58 try expect(log(u16, 2, 0x72) == 6);
59 try expect(log(u32, 2, 0xFFFFFF) == 23);
60 try expect(log(u64, 2, 0x7FF0123456789ABC) == 62);
6161}
6262
6363test "math.log float" {
6464 const epsilon = 0.000001;
6565
66 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));
68 expect(math.approxEqAbs(f64, log(f64, 123897, 12389216414), 1.981724596, epsilon));
66 try expect(math.approxEqAbs(f32, log(f32, 6, 0.23947), -0.797723, epsilon));
67 try expect(math.approxEqAbs(f32, log(f32, 89, 0.23947), -0.318432, epsilon));
68 try expect(math.approxEqAbs(f64, log(f64, 123897, 12389216414), 1.981724596, epsilon));
6969}
7070
7171test "math.log float_special" {
72 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)));
72 try expect(log(f32, 2, 0.2301974) == math.log2(@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)));
76 expect(log(f64, 10, 213.23019799993) == math.log10(@as(f64, 213.23019799993)));
75 try expect(log(f64, 2, 213.23019799993) == math.log2(@as(f64, 213.23019799993)));
76 try expect(log(f64, 10, 213.23019799993) == math.log10(@as(f64, 213.23019799993)));
7777}
lib/std/math/log10.zig+22-22
......@@ -181,42 +181,42 @@ pub fn log10_64(x_: f64) f64 {
181181}
182182
183183test "math.log10" {
184 testing.expect(log10(@as(f32, 0.2)) == log10_32(0.2));
185 testing.expect(log10(@as(f64, 0.2)) == log10_64(0.2));
184 try testing.expect(log10(@as(f32, 0.2)) == log10_32(0.2));
185 try testing.expect(log10(@as(f64, 0.2)) == log10_64(0.2));
186186}
187187
188188test "math.log10_32" {
189189 const epsilon = 0.000001;
190190
191 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));
193 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));
195 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));
191 try testing.expect(math.approxEqAbs(f32, log10_32(0.2), -0.698970, epsilon));
192 try testing.expect(math.approxEqAbs(f32, log10_32(0.8923), -0.049489, epsilon));
193 try testing.expect(math.approxEqAbs(f32, log10_32(1.5), 0.176091, epsilon));
194 try testing.expect(math.approxEqAbs(f32, log10_32(37.45), 1.573452, epsilon));
195 try testing.expect(math.approxEqAbs(f32, log10_32(89.123), 1.94999, epsilon));
196 try testing.expect(math.approxEqAbs(f32, log10_32(123123.234375), 5.09034, epsilon));
197197}
198198
199199test "math.log10_64" {
200200 const epsilon = 0.000001;
201201
202 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));
204 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));
206 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));
202 try testing.expect(math.approxEqAbs(f64, log10_64(0.2), -0.698970, epsilon));
203 try testing.expect(math.approxEqAbs(f64, log10_64(0.8923), -0.049489, epsilon));
204 try testing.expect(math.approxEqAbs(f64, log10_64(1.5), 0.176091, epsilon));
205 try testing.expect(math.approxEqAbs(f64, log10_64(37.45), 1.573452, epsilon));
206 try testing.expect(math.approxEqAbs(f64, log10_64(89.123), 1.94999, epsilon));
207 try testing.expect(math.approxEqAbs(f64, log10_64(123123.234375), 5.09034, epsilon));
208208}
209209
210210test "math.log10_32.special" {
211 testing.expect(math.isPositiveInf(log10_32(math.inf(f32))));
212 testing.expect(math.isNegativeInf(log10_32(0.0)));
213 testing.expect(math.isNan(log10_32(-1.0)));
214 testing.expect(math.isNan(log10_32(math.nan(f32))));
211 try testing.expect(math.isPositiveInf(log10_32(math.inf(f32))));
212 try testing.expect(math.isNegativeInf(log10_32(0.0)));
213 try testing.expect(math.isNan(log10_32(-1.0)));
214 try testing.expect(math.isNan(log10_32(math.nan(f32))));
215215}
216216
217217test "math.log10_64.special" {
218 testing.expect(math.isPositiveInf(log10_64(math.inf(f64))));
219 testing.expect(math.isNegativeInf(log10_64(0.0)));
220 testing.expect(math.isNan(log10_64(-1.0)));
221 testing.expect(math.isNan(log10_64(math.nan(f64))));
218 try testing.expect(math.isPositiveInf(log10_64(math.inf(f64))));
219 try testing.expect(math.isNegativeInf(log10_64(0.0)));
220 try testing.expect(math.isNan(log10_64(-1.0)));
221 try testing.expect(math.isNan(log10_64(math.nan(f64))));
222222}
lib/std/math/log1p.zig+28-28
......@@ -188,48 +188,48 @@ fn log1p_64(x: f64) f64 {
188188}
189189
190190test "math.log1p" {
191 expect(log1p(@as(f32, 0.0)) == log1p_32(0.0));
192 expect(log1p(@as(f64, 0.0)) == log1p_64(0.0));
191 try expect(log1p(@as(f32, 0.0)) == log1p_32(0.0));
192 try expect(log1p(@as(f64, 0.0)) == log1p_64(0.0));
193193}
194194
195195test "math.log1p_32" {
196196 const epsilon = 0.000001;
197197
198 expect(math.approxEqAbs(f32, log1p_32(0.0), 0.0, epsilon));
199 expect(math.approxEqAbs(f32, log1p_32(0.2), 0.182322, epsilon));
200 expect(math.approxEqAbs(f32, log1p_32(0.8923), 0.637793, epsilon));
201 expect(math.approxEqAbs(f32, log1p_32(1.5), 0.916291, epsilon));
202 expect(math.approxEqAbs(f32, log1p_32(37.45), 3.649359, epsilon));
203 expect(math.approxEqAbs(f32, log1p_32(89.123), 4.501175, epsilon));
204 expect(math.approxEqAbs(f32, log1p_32(123123.234375), 11.720949, epsilon));
198 try expect(math.approxEqAbs(f32, log1p_32(0.0), 0.0, epsilon));
199 try expect(math.approxEqAbs(f32, log1p_32(0.2), 0.182322, epsilon));
200 try expect(math.approxEqAbs(f32, log1p_32(0.8923), 0.637793, epsilon));
201 try expect(math.approxEqAbs(f32, log1p_32(1.5), 0.916291, epsilon));
202 try expect(math.approxEqAbs(f32, log1p_32(37.45), 3.649359, epsilon));
203 try expect(math.approxEqAbs(f32, log1p_32(89.123), 4.501175, epsilon));
204 try expect(math.approxEqAbs(f32, log1p_32(123123.234375), 11.720949, epsilon));
205205}
206206
207207test "math.log1p_64" {
208208 const epsilon = 0.000001;
209209
210 expect(math.approxEqAbs(f64, log1p_64(0.0), 0.0, epsilon));
211 expect(math.approxEqAbs(f64, log1p_64(0.2), 0.182322, epsilon));
212 expect(math.approxEqAbs(f64, log1p_64(0.8923), 0.637793, epsilon));
213 expect(math.approxEqAbs(f64, log1p_64(1.5), 0.916291, epsilon));
214 expect(math.approxEqAbs(f64, log1p_64(37.45), 3.649359, epsilon));
215 expect(math.approxEqAbs(f64, log1p_64(89.123), 4.501175, epsilon));
216 expect(math.approxEqAbs(f64, log1p_64(123123.234375), 11.720949, epsilon));
210 try expect(math.approxEqAbs(f64, log1p_64(0.0), 0.0, epsilon));
211 try expect(math.approxEqAbs(f64, log1p_64(0.2), 0.182322, epsilon));
212 try expect(math.approxEqAbs(f64, log1p_64(0.8923), 0.637793, epsilon));
213 try expect(math.approxEqAbs(f64, log1p_64(1.5), 0.916291, epsilon));
214 try expect(math.approxEqAbs(f64, log1p_64(37.45), 3.649359, epsilon));
215 try expect(math.approxEqAbs(f64, log1p_64(89.123), 4.501175, epsilon));
216 try expect(math.approxEqAbs(f64, log1p_64(123123.234375), 11.720949, epsilon));
217217}
218218
219219test "math.log1p_32.special" {
220 expect(math.isPositiveInf(log1p_32(math.inf(f32))));
221 expect(log1p_32(0.0) == 0.0);
222 expect(log1p_32(-0.0) == -0.0);
223 expect(math.isNegativeInf(log1p_32(-1.0)));
224 expect(math.isNan(log1p_32(-2.0)));
225 expect(math.isNan(log1p_32(math.nan(f32))));
220 try expect(math.isPositiveInf(log1p_32(math.inf(f32))));
221 try expect(log1p_32(0.0) == 0.0);
222 try expect(log1p_32(-0.0) == -0.0);
223 try expect(math.isNegativeInf(log1p_32(-1.0)));
224 try expect(math.isNan(log1p_32(-2.0)));
225 try expect(math.isNan(log1p_32(math.nan(f32))));
226226}
227227
228228test "math.log1p_64.special" {
229 expect(math.isPositiveInf(log1p_64(math.inf(f64))));
230 expect(log1p_64(0.0) == 0.0);
231 expect(log1p_64(-0.0) == -0.0);
232 expect(math.isNegativeInf(log1p_64(-1.0)));
233 expect(math.isNan(log1p_64(-2.0)));
234 expect(math.isNan(log1p_64(math.nan(f64))));
229 try expect(math.isPositiveInf(log1p_64(math.inf(f64))));
230 try expect(log1p_64(0.0) == 0.0);
231 try expect(log1p_64(-0.0) == -0.0);
232 try expect(math.isNegativeInf(log1p_64(-1.0)));
233 try expect(math.isNan(log1p_64(-2.0)));
234 try expect(math.isNan(log1p_64(math.nan(f64))));
235235}
lib/std/math/log2.zig+20-20
......@@ -179,40 +179,40 @@ pub fn log2_64(x_: f64) f64 {
179179}
180180
181181test "math.log2" {
182 expect(log2(@as(f32, 0.2)) == log2_32(0.2));
183 expect(log2(@as(f64, 0.2)) == log2_64(0.2));
182 try expect(log2(@as(f32, 0.2)) == log2_32(0.2));
183 try expect(log2(@as(f64, 0.2)) == log2_64(0.2));
184184}
185185
186186test "math.log2_32" {
187187 const epsilon = 0.000001;
188188
189 expect(math.approxEqAbs(f32, log2_32(0.2), -2.321928, epsilon));
190 expect(math.approxEqAbs(f32, log2_32(0.8923), -0.164399, epsilon));
191 expect(math.approxEqAbs(f32, log2_32(1.5), 0.584962, epsilon));
192 expect(math.approxEqAbs(f32, log2_32(37.45), 5.226894, epsilon));
193 expect(math.approxEqAbs(f32, log2_32(123123.234375), 16.909744, epsilon));
189 try expect(math.approxEqAbs(f32, log2_32(0.2), -2.321928, epsilon));
190 try expect(math.approxEqAbs(f32, log2_32(0.8923), -0.164399, epsilon));
191 try expect(math.approxEqAbs(f32, log2_32(1.5), 0.584962, epsilon));
192 try expect(math.approxEqAbs(f32, log2_32(37.45), 5.226894, epsilon));
193 try expect(math.approxEqAbs(f32, log2_32(123123.234375), 16.909744, epsilon));
194194}
195195
196196test "math.log2_64" {
197197 const epsilon = 0.000001;
198198
199 expect(math.approxEqAbs(f64, log2_64(0.2), -2.321928, epsilon));
200 expect(math.approxEqAbs(f64, log2_64(0.8923), -0.164399, epsilon));
201 expect(math.approxEqAbs(f64, log2_64(1.5), 0.584962, epsilon));
202 expect(math.approxEqAbs(f64, log2_64(37.45), 5.226894, epsilon));
203 expect(math.approxEqAbs(f64, log2_64(123123.234375), 16.909744, epsilon));
199 try expect(math.approxEqAbs(f64, log2_64(0.2), -2.321928, epsilon));
200 try expect(math.approxEqAbs(f64, log2_64(0.8923), -0.164399, epsilon));
201 try expect(math.approxEqAbs(f64, log2_64(1.5), 0.584962, epsilon));
202 try expect(math.approxEqAbs(f64, log2_64(37.45), 5.226894, epsilon));
203 try expect(math.approxEqAbs(f64, log2_64(123123.234375), 16.909744, epsilon));
204204}
205205
206206test "math.log2_32.special" {
207 expect(math.isPositiveInf(log2_32(math.inf(f32))));
208 expect(math.isNegativeInf(log2_32(0.0)));
209 expect(math.isNan(log2_32(-1.0)));
210 expect(math.isNan(log2_32(math.nan(f32))));
207 try expect(math.isPositiveInf(log2_32(math.inf(f32))));
208 try expect(math.isNegativeInf(log2_32(0.0)));
209 try expect(math.isNan(log2_32(-1.0)));
210 try expect(math.isNan(log2_32(math.nan(f32))));
211211}
212212
213213test "math.log2_64.special" {
214 expect(math.isPositiveInf(log2_64(math.inf(f64))));
215 expect(math.isNegativeInf(log2_64(0.0)));
216 expect(math.isNan(log2_64(-1.0)));
217 expect(math.isNan(log2_64(math.nan(f64))));
214 try expect(math.isPositiveInf(log2_64(math.inf(f64))));
215 try expect(math.isNegativeInf(log2_64(0.0)));
216 try expect(math.isNan(log2_64(-1.0)));
217 try expect(math.isNan(log2_64(math.nan(f64))));
218218}
lib/std/math/modf.zig+28-28
......@@ -131,11 +131,11 @@ test "math.modf" {
131131 const a = modf(@as(f32, 1.0));
132132 const b = modf32(1.0);
133133 // 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
136136 const c = modf(@as(f64, 1.0));
137137 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);
139139}
140140
141141test "math.modf32" {
......@@ -143,24 +143,24 @@ test "math.modf32" {
143143 var r: modf32_result = undefined;
144144
145145 r = modf32(1.0);
146 expect(math.approxEqAbs(f32, r.ipart, 1.0, epsilon));
147 expect(math.approxEqAbs(f32, r.fpart, 0.0, epsilon));
146 try expect(math.approxEqAbs(f32, r.ipart, 1.0, epsilon));
147 try expect(math.approxEqAbs(f32, r.fpart, 0.0, epsilon));
148148
149149 r = modf32(2.545);
150 expect(math.approxEqAbs(f32, r.ipart, 2.0, epsilon));
151 expect(math.approxEqAbs(f32, r.fpart, 0.545, epsilon));
150 try expect(math.approxEqAbs(f32, r.ipart, 2.0, epsilon));
151 try expect(math.approxEqAbs(f32, r.fpart, 0.545, epsilon));
152152
153153 r = modf32(3.978123);
154 expect(math.approxEqAbs(f32, r.ipart, 3.0, epsilon));
155 expect(math.approxEqAbs(f32, r.fpart, 0.978123, epsilon));
154 try expect(math.approxEqAbs(f32, r.ipart, 3.0, epsilon));
155 try expect(math.approxEqAbs(f32, r.fpart, 0.978123, epsilon));
156156
157157 r = modf32(43874.3);
158 expect(math.approxEqAbs(f32, r.ipart, 43874, epsilon));
159 expect(math.approxEqAbs(f32, r.fpart, 0.300781, epsilon));
158 try expect(math.approxEqAbs(f32, r.ipart, 43874, epsilon));
159 try expect(math.approxEqAbs(f32, r.fpart, 0.300781, epsilon));
160160
161161 r = modf32(1234.340780);
162 expect(math.approxEqAbs(f32, r.ipart, 1234, epsilon));
163 expect(math.approxEqAbs(f32, r.fpart, 0.340820, epsilon));
162 try expect(math.approxEqAbs(f32, r.ipart, 1234, epsilon));
163 try expect(math.approxEqAbs(f32, r.fpart, 0.340820, epsilon));
164164}
165165
166166test "math.modf64" {
......@@ -168,48 +168,48 @@ test "math.modf64" {
168168 var r: modf64_result = undefined;
169169
170170 r = modf64(1.0);
171 expect(math.approxEqAbs(f64, r.ipart, 1.0, epsilon));
172 expect(math.approxEqAbs(f64, r.fpart, 0.0, epsilon));
171 try expect(math.approxEqAbs(f64, r.ipart, 1.0, epsilon));
172 try expect(math.approxEqAbs(f64, r.fpart, 0.0, epsilon));
173173
174174 r = modf64(2.545);
175 expect(math.approxEqAbs(f64, r.ipart, 2.0, epsilon));
176 expect(math.approxEqAbs(f64, r.fpart, 0.545, epsilon));
175 try expect(math.approxEqAbs(f64, r.ipart, 2.0, epsilon));
176 try expect(math.approxEqAbs(f64, r.fpart, 0.545, epsilon));
177177
178178 r = modf64(3.978123);
179 expect(math.approxEqAbs(f64, r.ipart, 3.0, epsilon));
180 expect(math.approxEqAbs(f64, r.fpart, 0.978123, epsilon));
179 try expect(math.approxEqAbs(f64, r.ipart, 3.0, epsilon));
180 try expect(math.approxEqAbs(f64, r.fpart, 0.978123, epsilon));
181181
182182 r = modf64(43874.3);
183 expect(math.approxEqAbs(f64, r.ipart, 43874, epsilon));
184 expect(math.approxEqAbs(f64, r.fpart, 0.3, epsilon));
183 try expect(math.approxEqAbs(f64, r.ipart, 43874, epsilon));
184 try expect(math.approxEqAbs(f64, r.fpart, 0.3, epsilon));
185185
186186 r = modf64(1234.340780);
187 expect(math.approxEqAbs(f64, r.ipart, 1234, epsilon));
188 expect(math.approxEqAbs(f64, r.fpart, 0.340780, epsilon));
187 try expect(math.approxEqAbs(f64, r.ipart, 1234, epsilon));
188 try expect(math.approxEqAbs(f64, r.fpart, 0.340780, epsilon));
189189}
190190
191191test "math.modf32.special" {
192192 var r: modf32_result = undefined;
193193
194194 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
197197 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
200200 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));
202202}
203203
204204test "math.modf64.special" {
205205 var r: modf64_result = undefined;
206206
207207 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
210210 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
213213 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));
215215}
lib/std/math/pow.zig+52-52
......@@ -191,67 +191,67 @@ fn isOddInteger(x: f64) bool {
191191test "math.pow" {
192192 const epsilon = 0.000001;
193193
194 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));
196 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));
198 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));
194 try expect(math.approxEqAbs(f32, pow(f32, 0.0, 3.3), 0.0, epsilon));
195 try expect(math.approxEqAbs(f32, pow(f32, 0.8923, 3.3), 0.686572, epsilon));
196 try expect(math.approxEqAbs(f32, pow(f32, 0.2, 3.3), 0.004936, epsilon));
197 try expect(math.approxEqAbs(f32, pow(f32, 1.5, 3.3), 3.811546, epsilon));
198 try expect(math.approxEqAbs(f32, pow(f32, 37.45, 3.3), 155736.703125, 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));
202 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));
204 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));
206 expect(math.approxEqAbs(f64, pow(f64, 89.123, 3.3), 2722490.231436, epsilon));
201 try expect(math.approxEqAbs(f64, pow(f64, 0.0, 3.3), 0.0, epsilon));
202 try expect(math.approxEqAbs(f64, pow(f64, 0.8923, 3.3), 0.686572, epsilon));
203 try expect(math.approxEqAbs(f64, pow(f64, 0.2, 3.3), 0.004936, epsilon));
204 try expect(math.approxEqAbs(f64, pow(f64, 1.5, 3.3), 3.811546, epsilon));
205 try expect(math.approxEqAbs(f64, pow(f64, 37.45, 3.3), 155736.7160616, epsilon));
206 try expect(math.approxEqAbs(f64, pow(f64, 89.123, 3.3), 2722490.231436, epsilon));
207207}
208208
209209test "math.pow.special" {
210210 const epsilon = 0.000001;
211211
212 expect(pow(f32, 4, 0.0) == 1.0);
213 expect(pow(f32, 7, -0.0) == 1.0);
214 expect(pow(f32, 45, 1.0) == 45);
215 expect(pow(f32, -45, 1.0) == -45);
216 expect(math.isNan(pow(f32, math.nan(f32), 5.0)));
217 expect(math.isPositiveInf(pow(f32, -math.inf(f32), 0.5)));
218 expect(math.isPositiveInf(pow(f32, -0, -0.5)));
219 expect(pow(f32, -0, 0.5) == 0);
220 expect(math.isNan(pow(f32, 5.0, math.nan(f32))));
221 expect(math.isPositiveInf(pow(f32, 0.0, -1.0)));
212 try expect(pow(f32, 4, 0.0) == 1.0);
213 try expect(pow(f32, 7, -0.0) == 1.0);
214 try expect(pow(f32, 45, 1.0) == 45);
215 try expect(pow(f32, -45, 1.0) == -45);
216 try expect(math.isNan(pow(f32, math.nan(f32), 5.0)));
217 try expect(math.isPositiveInf(pow(f32, -math.inf(f32), 0.5)));
218 try expect(math.isPositiveInf(pow(f32, -0, -0.5)));
219 try expect(pow(f32, -0, 0.5) == 0);
220 try expect(math.isNan(pow(f32, 5.0, math.nan(f32))));
221 try expect(math.isPositiveInf(pow(f32, 0.0, -1.0)));
222222 //expect(math.isNegativeInf(pow(f32, -0.0, -3.0))); TODO is this required?
223 expect(math.isPositiveInf(pow(f32, 0.0, -math.inf(f32))));
224 expect(math.isPositiveInf(pow(f32, -0.0, -math.inf(f32))));
225 expect(pow(f32, 0.0, math.inf(f32)) == 0.0);
226 expect(pow(f32, -0.0, math.inf(f32)) == 0.0);
227 expect(math.isPositiveInf(pow(f32, 0.0, -2.0)));
228 expect(math.isPositiveInf(pow(f32, -0.0, -2.0)));
229 expect(pow(f32, 0.0, 1.0) == 0.0);
230 expect(pow(f32, -0.0, 1.0) == -0.0);
231 expect(pow(f32, 0.0, 2.0) == 0.0);
232 expect(pow(f32, -0.0, 2.0) == 0.0);
233 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));
235 expect(math.isPositiveInf(pow(f32, 1.2, math.inf(f32))));
236 expect(math.isPositiveInf(pow(f32, -1.2, math.inf(f32))));
237 expect(pow(f32, 1.2, -math.inf(f32)) == 0.0);
238 expect(pow(f32, -1.2, -math.inf(f32)) == 0.0);
239 expect(pow(f32, 0.2, math.inf(f32)) == 0.0);
240 expect(pow(f32, -0.2, math.inf(f32)) == 0.0);
241 expect(math.isPositiveInf(pow(f32, 0.2, -math.inf(f32))));
242 expect(math.isPositiveInf(pow(f32, -0.2, -math.inf(f32))));
243 expect(math.isPositiveInf(pow(f32, math.inf(f32), 1.0)));
244 expect(pow(f32, math.inf(f32), -1.0) == 0.0);
223 try expect(math.isPositiveInf(pow(f32, 0.0, -math.inf(f32))));
224 try expect(math.isPositiveInf(pow(f32, -0.0, -math.inf(f32))));
225 try expect(pow(f32, 0.0, math.inf(f32)) == 0.0);
226 try expect(pow(f32, -0.0, math.inf(f32)) == 0.0);
227 try expect(math.isPositiveInf(pow(f32, 0.0, -2.0)));
228 try expect(math.isPositiveInf(pow(f32, -0.0, -2.0)));
229 try expect(pow(f32, 0.0, 1.0) == 0.0);
230 try expect(pow(f32, -0.0, 1.0) == -0.0);
231 try expect(pow(f32, 0.0, 2.0) == 0.0);
232 try expect(pow(f32, -0.0, 2.0) == 0.0);
233 try 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 try expect(math.isPositiveInf(pow(f32, 1.2, math.inf(f32))));
236 try expect(math.isPositiveInf(pow(f32, -1.2, math.inf(f32))));
237 try expect(pow(f32, 1.2, -math.inf(f32)) == 0.0);
238 try expect(pow(f32, -1.2, -math.inf(f32)) == 0.0);
239 try expect(pow(f32, 0.2, math.inf(f32)) == 0.0);
240 try expect(pow(f32, -0.2, math.inf(f32)) == 0.0);
241 try expect(math.isPositiveInf(pow(f32, 0.2, -math.inf(f32))));
242 try expect(math.isPositiveInf(pow(f32, -0.2, -math.inf(f32))));
243 try expect(math.isPositiveInf(pow(f32, math.inf(f32), 1.0)));
244 try expect(pow(f32, math.inf(f32), -1.0) == 0.0);
245245 //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));
247 expect(math.isNan(pow(f32, -1.0, 1.2)));
248 expect(math.isNan(pow(f32, -12.4, 78.5)));
246 try expect(pow(f32, -math.inf(f32), -5.2) == pow(f32, -0.0, 5.2));
247 try expect(math.isNan(pow(f32, -1.0, 1.2)));
248 try expect(math.isNan(pow(f32, -12.4, 78.5)));
249249}
250250
251251test "math.pow.overflow" {
252 expect(math.isPositiveInf(pow(f64, 2, 1 << 32)));
253 expect(pow(f64, 2, -(1 << 32)) == 0);
254 expect(math.isNegativeInf(pow(f64, -2, (1 << 32) + 1)));
255 expect(pow(f64, 0.5, 1 << 45) == 0);
256 expect(math.isPositiveInf(pow(f64, 0.5, -(1 << 45))));
252 try expect(math.isPositiveInf(pow(f64, 2, 1 << 32)));
253 try expect(pow(f64, 2, -(1 << 32)) == 0);
254 try expect(math.isNegativeInf(pow(f64, -2, (1 << 32) + 1)));
255 try expect(pow(f64, 0.5, 1 << 45) == 0);
256 try expect(math.isPositiveInf(pow(f64, 0.5, -(1 << 45))));
257257}
lib/std/math/powi.zig+75-75
......@@ -112,82 +112,82 @@ pub fn powi(comptime T: type, x: T, y: T) (error{
112112}
113113
114114test "math.powi" {
115 testing.expectError(error.Underflow, powi(i8, -66, 6));
116 testing.expectError(error.Underflow, powi(i16, -13, 13));
117 testing.expectError(error.Underflow, powi(i32, -32, 21));
118 testing.expectError(error.Underflow, powi(i64, -24, 61));
119 testing.expectError(error.Underflow, powi(i17, -15, 15));
120 testing.expectError(error.Underflow, powi(i42, -6, 40));
121
122 testing.expect((try powi(i8, -5, 3)) == -125);
123 testing.expect((try powi(i16, -16, 3)) == -4096);
124 testing.expect((try powi(i32, -91, 3)) == -753571);
125 testing.expect((try powi(i64, -36, 6)) == 2176782336);
126 testing.expect((try powi(i17, -2, 15)) == -32768);
127 testing.expect((try powi(i42, -5, 7)) == -78125);
128
129 testing.expect((try powi(u8, 6, 2)) == 36);
130 testing.expect((try powi(u16, 5, 4)) == 625);
131 testing.expect((try powi(u32, 12, 6)) == 2985984);
132 testing.expect((try powi(u64, 34, 2)) == 1156);
133 testing.expect((try powi(u17, 16, 3)) == 4096);
134 testing.expect((try powi(u42, 34, 6)) == 1544804416);
135
136 testing.expectError(error.Overflow, powi(i8, 120, 7));
137 testing.expectError(error.Overflow, powi(i16, 73, 15));
138 testing.expectError(error.Overflow, powi(i32, 23, 31));
139 testing.expectError(error.Overflow, powi(i64, 68, 61));
140 testing.expectError(error.Overflow, powi(i17, 15, 15));
141 testing.expectError(error.Overflow, powi(i42, 121312, 41));
142
143 testing.expectError(error.Overflow, powi(u8, 123, 7));
144 testing.expectError(error.Overflow, powi(u16, 2313, 15));
145 testing.expectError(error.Overflow, powi(u32, 8968, 31));
146 testing.expectError(error.Overflow, powi(u64, 2342, 63));
147 testing.expectError(error.Overflow, powi(u17, 2723, 16));
148 testing.expectError(error.Overflow, powi(u42, 8234, 41));
115 try testing.expectError(error.Underflow, powi(i8, -66, 6));
116 try testing.expectError(error.Underflow, powi(i16, -13, 13));
117 try testing.expectError(error.Underflow, powi(i32, -32, 21));
118 try testing.expectError(error.Underflow, powi(i64, -24, 61));
119 try testing.expectError(error.Underflow, powi(i17, -15, 15));
120 try testing.expectError(error.Underflow, powi(i42, -6, 40));
121
122 try testing.expect((try powi(i8, -5, 3)) == -125);
123 try testing.expect((try powi(i16, -16, 3)) == -4096);
124 try testing.expect((try powi(i32, -91, 3)) == -753571);
125 try testing.expect((try powi(i64, -36, 6)) == 2176782336);
126 try testing.expect((try powi(i17, -2, 15)) == -32768);
127 try testing.expect((try powi(i42, -5, 7)) == -78125);
128
129 try testing.expect((try powi(u8, 6, 2)) == 36);
130 try testing.expect((try powi(u16, 5, 4)) == 625);
131 try testing.expect((try powi(u32, 12, 6)) == 2985984);
132 try testing.expect((try powi(u64, 34, 2)) == 1156);
133 try testing.expect((try powi(u17, 16, 3)) == 4096);
134 try testing.expect((try powi(u42, 34, 6)) == 1544804416);
135
136 try testing.expectError(error.Overflow, powi(i8, 120, 7));
137 try testing.expectError(error.Overflow, powi(i16, 73, 15));
138 try testing.expectError(error.Overflow, powi(i32, 23, 31));
139 try testing.expectError(error.Overflow, powi(i64, 68, 61));
140 try testing.expectError(error.Overflow, powi(i17, 15, 15));
141 try testing.expectError(error.Overflow, powi(i42, 121312, 41));
142
143 try testing.expectError(error.Overflow, powi(u8, 123, 7));
144 try testing.expectError(error.Overflow, powi(u16, 2313, 15));
145 try testing.expectError(error.Overflow, powi(u32, 8968, 31));
146 try testing.expectError(error.Overflow, powi(u64, 2342, 63));
147 try testing.expectError(error.Overflow, powi(u17, 2723, 16));
148 try testing.expectError(error.Overflow, powi(u42, 8234, 41));
149149}
150150
151151test "math.powi.special" {
152 testing.expectError(error.Underflow, powi(i8, -2, 8));
153 testing.expectError(error.Underflow, powi(i16, -2, 16));
154 testing.expectError(error.Underflow, powi(i32, -2, 32));
155 testing.expectError(error.Underflow, powi(i64, -2, 64));
156 testing.expectError(error.Underflow, powi(i17, -2, 17));
157 testing.expectError(error.Underflow, powi(i42, -2, 42));
158
159 testing.expect((try powi(i8, -1, 3)) == -1);
160 testing.expect((try powi(i16, -1, 2)) == 1);
161 testing.expect((try powi(i32, -1, 16)) == 1);
162 testing.expect((try powi(i64, -1, 6)) == 1);
163 testing.expect((try powi(i17, -1, 15)) == -1);
164 testing.expect((try powi(i42, -1, 7)) == -1);
165
166 testing.expect((try powi(u8, 1, 2)) == 1);
167 testing.expect((try powi(u16, 1, 4)) == 1);
168 testing.expect((try powi(u32, 1, 6)) == 1);
169 testing.expect((try powi(u64, 1, 2)) == 1);
170 testing.expect((try powi(u17, 1, 3)) == 1);
171 testing.expect((try powi(u42, 1, 6)) == 1);
172
173 testing.expectError(error.Overflow, powi(i8, 2, 7));
174 testing.expectError(error.Overflow, powi(i16, 2, 15));
175 testing.expectError(error.Overflow, powi(i32, 2, 31));
176 testing.expectError(error.Overflow, powi(i64, 2, 63));
177 testing.expectError(error.Overflow, powi(i17, 2, 16));
178 testing.expectError(error.Overflow, powi(i42, 2, 41));
179
180 testing.expectError(error.Overflow, powi(u8, 2, 8));
181 testing.expectError(error.Overflow, powi(u16, 2, 16));
182 testing.expectError(error.Overflow, powi(u32, 2, 32));
183 testing.expectError(error.Overflow, powi(u64, 2, 64));
184 testing.expectError(error.Overflow, powi(u17, 2, 17));
185 testing.expectError(error.Overflow, powi(u42, 2, 42));
186
187 testing.expect((try powi(u8, 6, 0)) == 1);
188 testing.expect((try powi(u16, 5, 0)) == 1);
189 testing.expect((try powi(u32, 12, 0)) == 1);
190 testing.expect((try powi(u64, 34, 0)) == 1);
191 testing.expect((try powi(u17, 16, 0)) == 1);
192 testing.expect((try powi(u42, 34, 0)) == 1);
152 try testing.expectError(error.Underflow, powi(i8, -2, 8));
153 try testing.expectError(error.Underflow, powi(i16, -2, 16));
154 try testing.expectError(error.Underflow, powi(i32, -2, 32));
155 try testing.expectError(error.Underflow, powi(i64, -2, 64));
156 try testing.expectError(error.Underflow, powi(i17, -2, 17));
157 try testing.expectError(error.Underflow, powi(i42, -2, 42));
158
159 try testing.expect((try powi(i8, -1, 3)) == -1);
160 try testing.expect((try powi(i16, -1, 2)) == 1);
161 try testing.expect((try powi(i32, -1, 16)) == 1);
162 try testing.expect((try powi(i64, -1, 6)) == 1);
163 try testing.expect((try powi(i17, -1, 15)) == -1);
164 try testing.expect((try powi(i42, -1, 7)) == -1);
165
166 try testing.expect((try powi(u8, 1, 2)) == 1);
167 try testing.expect((try powi(u16, 1, 4)) == 1);
168 try testing.expect((try powi(u32, 1, 6)) == 1);
169 try testing.expect((try powi(u64, 1, 2)) == 1);
170 try testing.expect((try powi(u17, 1, 3)) == 1);
171 try testing.expect((try powi(u42, 1, 6)) == 1);
172
173 try testing.expectError(error.Overflow, powi(i8, 2, 7));
174 try testing.expectError(error.Overflow, powi(i16, 2, 15));
175 try testing.expectError(error.Overflow, powi(i32, 2, 31));
176 try testing.expectError(error.Overflow, powi(i64, 2, 63));
177 try testing.expectError(error.Overflow, powi(i17, 2, 16));
178 try testing.expectError(error.Overflow, powi(i42, 2, 41));
179
180 try testing.expectError(error.Overflow, powi(u8, 2, 8));
181 try testing.expectError(error.Overflow, powi(u16, 2, 16));
182 try testing.expectError(error.Overflow, powi(u32, 2, 32));
183 try testing.expectError(error.Overflow, powi(u64, 2, 64));
184 try testing.expectError(error.Overflow, powi(u17, 2, 17));
185 try testing.expectError(error.Overflow, powi(u42, 2, 42));
186
187 try testing.expect((try powi(u8, 6, 0)) == 1);
188 try testing.expect((try powi(u16, 5, 0)) == 1);
189 try testing.expect((try powi(u32, 12, 0)) == 1);
190 try testing.expect((try powi(u64, 34, 0)) == 1);
191 try testing.expect((try powi(u17, 16, 0)) == 1);
192 try testing.expect((try powi(u42, 34, 0)) == 1);
193193}
lib/std/math/round.zig+30-30
......@@ -130,52 +130,52 @@ fn round128(x_: f128) f128 {
130130}
131131
132132test "math.round" {
133 expect(round(@as(f32, 1.3)) == round32(1.3));
134 expect(round(@as(f64, 1.3)) == round64(1.3));
135 expect(round(@as(f128, 1.3)) == round128(1.3));
133 try expect(round(@as(f32, 1.3)) == round32(1.3));
134 try expect(round(@as(f64, 1.3)) == round64(1.3));
135 try expect(round(@as(f128, 1.3)) == round128(1.3));
136136}
137137
138138test "math.round32" {
139 expect(round32(1.3) == 1.0);
140 expect(round32(-1.3) == -1.0);
141 expect(round32(0.2) == 0.0);
142 expect(round32(1.8) == 2.0);
139 try expect(round32(1.3) == 1.0);
140 try expect(round32(-1.3) == -1.0);
141 try expect(round32(0.2) == 0.0);
142 try expect(round32(1.8) == 2.0);
143143}
144144
145145test "math.round64" {
146 expect(round64(1.3) == 1.0);
147 expect(round64(-1.3) == -1.0);
148 expect(round64(0.2) == 0.0);
149 expect(round64(1.8) == 2.0);
146 try expect(round64(1.3) == 1.0);
147 try expect(round64(-1.3) == -1.0);
148 try expect(round64(0.2) == 0.0);
149 try expect(round64(1.8) == 2.0);
150150}
151151
152152test "math.round128" {
153 expect(round128(1.3) == 1.0);
154 expect(round128(-1.3) == -1.0);
155 expect(round128(0.2) == 0.0);
156 expect(round128(1.8) == 2.0);
153 try expect(round128(1.3) == 1.0);
154 try expect(round128(-1.3) == -1.0);
155 try expect(round128(0.2) == 0.0);
156 try expect(round128(1.8) == 2.0);
157157}
158158
159159test "math.round32.special" {
160 expect(round32(0.0) == 0.0);
161 expect(round32(-0.0) == -0.0);
162 expect(math.isPositiveInf(round32(math.inf(f32))));
163 expect(math.isNegativeInf(round32(-math.inf(f32))));
164 expect(math.isNan(round32(math.nan(f32))));
160 try expect(round32(0.0) == 0.0);
161 try expect(round32(-0.0) == -0.0);
162 try expect(math.isPositiveInf(round32(math.inf(f32))));
163 try expect(math.isNegativeInf(round32(-math.inf(f32))));
164 try expect(math.isNan(round32(math.nan(f32))));
165165}
166166
167167test "math.round64.special" {
168 expect(round64(0.0) == 0.0);
169 expect(round64(-0.0) == -0.0);
170 expect(math.isPositiveInf(round64(math.inf(f64))));
171 expect(math.isNegativeInf(round64(-math.inf(f64))));
172 expect(math.isNan(round64(math.nan(f64))));
168 try expect(round64(0.0) == 0.0);
169 try expect(round64(-0.0) == -0.0);
170 try expect(math.isPositiveInf(round64(math.inf(f64))));
171 try expect(math.isNegativeInf(round64(-math.inf(f64))));
172 try expect(math.isNan(round64(math.nan(f64))));
173173}
174174
175175test "math.round128.special" {
176 expect(round128(0.0) == 0.0);
177 expect(round128(-0.0) == -0.0);
178 expect(math.isPositiveInf(round128(math.inf(f128))));
179 expect(math.isNegativeInf(round128(-math.inf(f128))));
180 expect(math.isNan(round128(math.nan(f128))));
176 try expect(round128(0.0) == 0.0);
177 try expect(round128(-0.0) == -0.0);
178 try expect(math.isPositiveInf(round128(math.inf(f128))));
179 try expect(math.isNegativeInf(round128(-math.inf(f128))));
180 try expect(math.isNan(round128(math.nan(f128))));
181181}
lib/std/math/scalbn.zig+4-4
......@@ -84,14 +84,14 @@ fn scalbn64(x: f64, n_: i32) f64 {
8484}
8585
8686test "math.scalbn" {
87 expect(scalbn(@as(f32, 1.5), 4) == scalbn32(1.5, 4));
88 expect(scalbn(@as(f64, 1.5), 4) == scalbn64(1.5, 4));
87 try expect(scalbn(@as(f32, 1.5), 4) == scalbn32(1.5, 4));
88 try expect(scalbn(@as(f64, 1.5), 4) == scalbn64(1.5, 4));
8989}
9090
9191test "math.scalbn32" {
92 expect(scalbn32(1.5, 4) == 24.0);
92 try expect(scalbn32(1.5, 4) == 24.0);
9393}
9494
9595test "math.scalbn64" {
96 expect(scalbn64(1.5, 4) == 24.0);
96 try expect(scalbn64(1.5, 4) == 24.0);
9797}
lib/std/math/signbit.zig+12-12
......@@ -40,28 +40,28 @@ fn signbit128(x: f128) bool {
4040}
4141
4242test "math.signbit" {
43 expect(signbit(@as(f16, 4.0)) == signbit16(4.0));
44 expect(signbit(@as(f32, 4.0)) == signbit32(4.0));
45 expect(signbit(@as(f64, 4.0)) == signbit64(4.0));
46 expect(signbit(@as(f128, 4.0)) == signbit128(4.0));
43 try expect(signbit(@as(f16, 4.0)) == signbit16(4.0));
44 try expect(signbit(@as(f32, 4.0)) == signbit32(4.0));
45 try expect(signbit(@as(f64, 4.0)) == signbit64(4.0));
46 try expect(signbit(@as(f128, 4.0)) == signbit128(4.0));
4747}
4848
4949test "math.signbit16" {
50 expect(!signbit16(4.0));
51 expect(signbit16(-3.0));
50 try expect(!signbit16(4.0));
51 try expect(signbit16(-3.0));
5252}
5353
5454test "math.signbit32" {
55 expect(!signbit32(4.0));
56 expect(signbit32(-3.0));
55 try expect(!signbit32(4.0));
56 try expect(signbit32(-3.0));
5757}
5858
5959test "math.signbit64" {
60 expect(!signbit64(4.0));
61 expect(signbit64(-3.0));
60 try expect(!signbit64(4.0));
61 try expect(signbit64(-3.0));
6262}
6363
6464test "math.signbit128" {
65 expect(!signbit128(4.0));
66 expect(signbit128(-3.0));
65 try expect(!signbit128(4.0));
66 try expect(signbit128(-3.0));
6767}
lib/std/math/sin.zig+27-27
......@@ -89,47 +89,47 @@ fn sin_(comptime T: type, x_: T) T {
8989}
9090
9191test "math.sin" {
92 expect(sin(@as(f32, 0.0)) == sin_(f32, 0.0));
93 expect(sin(@as(f64, 0.0)) == sin_(f64, 0.0));
94 expect(comptime (math.sin(@as(f64, 2))) == math.sin(@as(f64, 2)));
92 try expect(sin(@as(f32, 0.0)) == sin_(f32, 0.0));
93 try expect(sin(@as(f64, 0.0)) == sin_(f64, 0.0));
94 try expect(comptime (math.sin(@as(f64, 2))) == math.sin(@as(f64, 2)));
9595}
9696
9797test "math.sin32" {
9898 const epsilon = 0.000001;
9999
100 expect(math.approxEqAbs(f32, sin_(f32, 0.0), 0.0, epsilon));
101 expect(math.approxEqAbs(f32, sin_(f32, 0.2), 0.198669, epsilon));
102 expect(math.approxEqAbs(f32, sin_(f32, 0.8923), 0.778517, epsilon));
103 expect(math.approxEqAbs(f32, sin_(f32, 1.5), 0.997495, epsilon));
104 expect(math.approxEqAbs(f32, sin_(f32, -1.5), -0.997495, epsilon));
105 expect(math.approxEqAbs(f32, sin_(f32, 37.45), -0.246544, epsilon));
106 expect(math.approxEqAbs(f32, sin_(f32, 89.123), 0.916166, epsilon));
100 try expect(math.approxEqAbs(f32, sin_(f32, 0.0), 0.0, epsilon));
101 try expect(math.approxEqAbs(f32, sin_(f32, 0.2), 0.198669, epsilon));
102 try expect(math.approxEqAbs(f32, sin_(f32, 0.8923), 0.778517, epsilon));
103 try 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 try expect(math.approxEqAbs(f32, sin_(f32, 37.45), -0.246544, epsilon));
106 try expect(math.approxEqAbs(f32, sin_(f32, 89.123), 0.916166, epsilon));
107107}
108108
109109test "math.sin64" {
110110 const epsilon = 0.000001;
111111
112 expect(math.approxEqAbs(f64, sin_(f64, 0.0), 0.0, epsilon));
113 expect(math.approxEqAbs(f64, sin_(f64, 0.2), 0.198669, epsilon));
114 expect(math.approxEqAbs(f64, sin_(f64, 0.8923), 0.778517, epsilon));
115 expect(math.approxEqAbs(f64, sin_(f64, 1.5), 0.997495, epsilon));
116 expect(math.approxEqAbs(f64, sin_(f64, -1.5), -0.997495, epsilon));
117 expect(math.approxEqAbs(f64, sin_(f64, 37.45), -0.246543, epsilon));
118 expect(math.approxEqAbs(f64, sin_(f64, 89.123), 0.916166, epsilon));
112 try expect(math.approxEqAbs(f64, sin_(f64, 0.0), 0.0, epsilon));
113 try expect(math.approxEqAbs(f64, sin_(f64, 0.2), 0.198669, epsilon));
114 try expect(math.approxEqAbs(f64, sin_(f64, 0.8923), 0.778517, epsilon));
115 try 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 try expect(math.approxEqAbs(f64, sin_(f64, 37.45), -0.246543, epsilon));
118 try expect(math.approxEqAbs(f64, sin_(f64, 89.123), 0.916166, epsilon));
119119}
120120
121121test "math.sin32.special" {
122 expect(sin_(f32, 0.0) == 0.0);
123 expect(sin_(f32, -0.0) == -0.0);
124 expect(math.isNan(sin_(f32, math.inf(f32))));
125 expect(math.isNan(sin_(f32, -math.inf(f32))));
126 expect(math.isNan(sin_(f32, math.nan(f32))));
122 try expect(sin_(f32, 0.0) == 0.0);
123 try expect(sin_(f32, -0.0) == -0.0);
124 try expect(math.isNan(sin_(f32, math.inf(f32))));
125 try expect(math.isNan(sin_(f32, -math.inf(f32))));
126 try expect(math.isNan(sin_(f32, math.nan(f32))));
127127}
128128
129129test "math.sin64.special" {
130 expect(sin_(f64, 0.0) == 0.0);
131 expect(sin_(f64, -0.0) == -0.0);
132 expect(math.isNan(sin_(f64, math.inf(f64))));
133 expect(math.isNan(sin_(f64, -math.inf(f64))));
134 expect(math.isNan(sin_(f64, math.nan(f64))));
130 try expect(sin_(f64, 0.0) == 0.0);
131 try expect(sin_(f64, -0.0) == -0.0);
132 try expect(math.isNan(sin_(f64, math.inf(f64))));
133 try expect(math.isNan(sin_(f64, -math.inf(f64))));
134 try expect(math.isNan(sin_(f64, math.nan(f64))));
135135}
lib/std/math/sinh.zig+28-28
......@@ -98,48 +98,48 @@ fn sinh64(x: f64) f64 {
9898}
9999
100100test "math.sinh" {
101 expect(sinh(@as(f32, 1.5)) == sinh32(1.5));
102 expect(sinh(@as(f64, 1.5)) == sinh64(1.5));
101 try expect(sinh(@as(f32, 1.5)) == sinh32(1.5));
102 try expect(sinh(@as(f64, 1.5)) == sinh64(1.5));
103103}
104104
105105test "math.sinh32" {
106106 const epsilon = 0.000001;
107107
108 expect(math.approxEqAbs(f32, sinh32(0.0), 0.0, epsilon));
109 expect(math.approxEqAbs(f32, sinh32(0.2), 0.201336, epsilon));
110 expect(math.approxEqAbs(f32, sinh32(0.8923), 1.015512, epsilon));
111 expect(math.approxEqAbs(f32, sinh32(1.5), 2.129279, epsilon));
112 expect(math.approxEqAbs(f32, sinh32(-0.0), -0.0, epsilon));
113 expect(math.approxEqAbs(f32, sinh32(-0.2), -0.201336, epsilon));
114 expect(math.approxEqAbs(f32, sinh32(-0.8923), -1.015512, epsilon));
115 expect(math.approxEqAbs(f32, sinh32(-1.5), -2.129279, epsilon));
108 try expect(math.approxEqAbs(f32, sinh32(0.0), 0.0, epsilon));
109 try expect(math.approxEqAbs(f32, sinh32(0.2), 0.201336, epsilon));
110 try expect(math.approxEqAbs(f32, sinh32(0.8923), 1.015512, epsilon));
111 try expect(math.approxEqAbs(f32, sinh32(1.5), 2.129279, epsilon));
112 try expect(math.approxEqAbs(f32, sinh32(-0.0), -0.0, epsilon));
113 try expect(math.approxEqAbs(f32, sinh32(-0.2), -0.201336, epsilon));
114 try expect(math.approxEqAbs(f32, sinh32(-0.8923), -1.015512, epsilon));
115 try expect(math.approxEqAbs(f32, sinh32(-1.5), -2.129279, epsilon));
116116}
117117
118118test "math.sinh64" {
119119 const epsilon = 0.000001;
120120
121 expect(math.approxEqAbs(f64, sinh64(0.0), 0.0, epsilon));
122 expect(math.approxEqAbs(f64, sinh64(0.2), 0.201336, epsilon));
123 expect(math.approxEqAbs(f64, sinh64(0.8923), 1.015512, epsilon));
124 expect(math.approxEqAbs(f64, sinh64(1.5), 2.129279, epsilon));
125 expect(math.approxEqAbs(f64, sinh64(-0.0), -0.0, epsilon));
126 expect(math.approxEqAbs(f64, sinh64(-0.2), -0.201336, epsilon));
127 expect(math.approxEqAbs(f64, sinh64(-0.8923), -1.015512, epsilon));
128 expect(math.approxEqAbs(f64, sinh64(-1.5), -2.129279, epsilon));
121 try expect(math.approxEqAbs(f64, sinh64(0.0), 0.0, epsilon));
122 try expect(math.approxEqAbs(f64, sinh64(0.2), 0.201336, epsilon));
123 try expect(math.approxEqAbs(f64, sinh64(0.8923), 1.015512, epsilon));
124 try expect(math.approxEqAbs(f64, sinh64(1.5), 2.129279, epsilon));
125 try expect(math.approxEqAbs(f64, sinh64(-0.0), -0.0, epsilon));
126 try expect(math.approxEqAbs(f64, sinh64(-0.2), -0.201336, epsilon));
127 try expect(math.approxEqAbs(f64, sinh64(-0.8923), -1.015512, epsilon));
128 try expect(math.approxEqAbs(f64, sinh64(-1.5), -2.129279, epsilon));
129129}
130130
131131test "math.sinh32.special" {
132 expect(sinh32(0.0) == 0.0);
133 expect(sinh32(-0.0) == -0.0);
134 expect(math.isPositiveInf(sinh32(math.inf(f32))));
135 expect(math.isNegativeInf(sinh32(-math.inf(f32))));
136 expect(math.isNan(sinh32(math.nan(f32))));
132 try expect(sinh32(0.0) == 0.0);
133 try expect(sinh32(-0.0) == -0.0);
134 try expect(math.isPositiveInf(sinh32(math.inf(f32))));
135 try expect(math.isNegativeInf(sinh32(-math.inf(f32))));
136 try expect(math.isNan(sinh32(math.nan(f32))));
137137}
138138
139139test "math.sinh64.special" {
140 expect(sinh64(0.0) == 0.0);
141 expect(sinh64(-0.0) == -0.0);
142 expect(math.isPositiveInf(sinh64(math.inf(f64))));
143 expect(math.isNegativeInf(sinh64(-math.inf(f64))));
144 expect(math.isNan(sinh64(math.nan(f64))));
140 try expect(sinh64(0.0) == 0.0);
141 try expect(sinh64(-0.0) == -0.0);
142 try expect(math.isPositiveInf(sinh64(math.inf(f64))));
143 try expect(math.isNegativeInf(sinh64(-math.inf(f64))));
144 try expect(math.isNan(sinh64(math.nan(f64))));
145145}
lib/std/math/sqrt.zig+8-8
......@@ -69,14 +69,14 @@ fn sqrt_int(comptime T: type, value: T) Sqrt(T) {
6969}
7070
7171test "math.sqrt_int" {
72 expect(sqrt_int(u0, 0) == 0);
73 expect(sqrt_int(u1, 1) == 1);
74 expect(sqrt_int(u32, 3) == 1);
75 expect(sqrt_int(u32, 4) == 2);
76 expect(sqrt_int(u32, 5) == 2);
77 expect(sqrt_int(u32, 8) == 2);
78 expect(sqrt_int(u32, 9) == 3);
79 expect(sqrt_int(u32, 10) == 3);
72 try expect(sqrt_int(u0, 0) == 0);
73 try expect(sqrt_int(u1, 1) == 1);
74 try expect(sqrt_int(u32, 3) == 1);
75 try expect(sqrt_int(u32, 4) == 2);
76 try expect(sqrt_int(u32, 5) == 2);
77 try expect(sqrt_int(u32, 8) == 2);
78 try expect(sqrt_int(u32, 9) == 3);
79 try expect(sqrt_int(u32, 10) == 3);
8080}
8181
8282/// 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 {
8080}
8181
8282test "math.tan" {
83 expect(tan(@as(f32, 0.0)) == tan_(f32, 0.0));
84 expect(tan(@as(f64, 0.0)) == tan_(f64, 0.0));
83 try expect(tan(@as(f32, 0.0)) == tan_(f32, 0.0));
84 try expect(tan(@as(f64, 0.0)) == tan_(f64, 0.0));
8585}
8686
8787test "math.tan32" {
8888 const epsilon = 0.000001;
8989
90 expect(math.approxEqAbs(f32, tan_(f32, 0.0), 0.0, epsilon));
91 expect(math.approxEqAbs(f32, tan_(f32, 0.2), 0.202710, epsilon));
92 expect(math.approxEqAbs(f32, tan_(f32, 0.8923), 1.240422, epsilon));
93 expect(math.approxEqAbs(f32, tan_(f32, 1.5), 14.101420, epsilon));
94 expect(math.approxEqAbs(f32, tan_(f32, 37.45), -0.254397, epsilon));
95 expect(math.approxEqAbs(f32, tan_(f32, 89.123), 2.285852, epsilon));
90 try expect(math.approxEqAbs(f32, tan_(f32, 0.0), 0.0, epsilon));
91 try expect(math.approxEqAbs(f32, tan_(f32, 0.2), 0.202710, epsilon));
92 try expect(math.approxEqAbs(f32, tan_(f32, 0.8923), 1.240422, epsilon));
93 try expect(math.approxEqAbs(f32, tan_(f32, 1.5), 14.101420, epsilon));
94 try expect(math.approxEqAbs(f32, tan_(f32, 37.45), -0.254397, epsilon));
95 try expect(math.approxEqAbs(f32, tan_(f32, 89.123), 2.285852, epsilon));
9696}
9797
9898test "math.tan64" {
9999 const epsilon = 0.000001;
100100
101 expect(math.approxEqAbs(f64, tan_(f64, 0.0), 0.0, epsilon));
102 expect(math.approxEqAbs(f64, tan_(f64, 0.2), 0.202710, epsilon));
103 expect(math.approxEqAbs(f64, tan_(f64, 0.8923), 1.240422, epsilon));
104 expect(math.approxEqAbs(f64, tan_(f64, 1.5), 14.101420, epsilon));
105 expect(math.approxEqAbs(f64, tan_(f64, 37.45), -0.254397, epsilon));
106 expect(math.approxEqAbs(f64, tan_(f64, 89.123), 2.2858376, epsilon));
101 try expect(math.approxEqAbs(f64, tan_(f64, 0.0), 0.0, epsilon));
102 try expect(math.approxEqAbs(f64, tan_(f64, 0.2), 0.202710, epsilon));
103 try expect(math.approxEqAbs(f64, tan_(f64, 0.8923), 1.240422, epsilon));
104 try expect(math.approxEqAbs(f64, tan_(f64, 1.5), 14.101420, epsilon));
105 try expect(math.approxEqAbs(f64, tan_(f64, 37.45), -0.254397, epsilon));
106 try expect(math.approxEqAbs(f64, tan_(f64, 89.123), 2.2858376, epsilon));
107107}
108108
109109test "math.tan32.special" {
110 expect(tan_(f32, 0.0) == 0.0);
111 expect(tan_(f32, -0.0) == -0.0);
112 expect(math.isNan(tan_(f32, math.inf(f32))));
113 expect(math.isNan(tan_(f32, -math.inf(f32))));
114 expect(math.isNan(tan_(f32, math.nan(f32))));
110 try expect(tan_(f32, 0.0) == 0.0);
111 try expect(tan_(f32, -0.0) == -0.0);
112 try expect(math.isNan(tan_(f32, math.inf(f32))));
113 try expect(math.isNan(tan_(f32, -math.inf(f32))));
114 try expect(math.isNan(tan_(f32, math.nan(f32))));
115115}
116116
117117test "math.tan64.special" {
118 expect(tan_(f64, 0.0) == 0.0);
119 expect(tan_(f64, -0.0) == -0.0);
120 expect(math.isNan(tan_(f64, math.inf(f64))));
121 expect(math.isNan(tan_(f64, -math.inf(f64))));
122 expect(math.isNan(tan_(f64, math.nan(f64))));
118 try expect(tan_(f64, 0.0) == 0.0);
119 try expect(tan_(f64, -0.0) == -0.0);
120 try expect(math.isNan(tan_(f64, math.inf(f64))));
121 try expect(math.isNan(tan_(f64, -math.inf(f64))));
122 try expect(math.isNan(tan_(f64, math.nan(f64))));
123123}
lib/std/math/tanh.zig+22-22
......@@ -124,42 +124,42 @@ fn tanh64(x: f64) f64 {
124124}
125125
126126test "math.tanh" {
127 expect(tanh(@as(f32, 1.5)) == tanh32(1.5));
128 expect(tanh(@as(f64, 1.5)) == tanh64(1.5));
127 try expect(tanh(@as(f32, 1.5)) == tanh32(1.5));
128 try expect(tanh(@as(f64, 1.5)) == tanh64(1.5));
129129}
130130
131131test "math.tanh32" {
132132 const epsilon = 0.000001;
133133
134 expect(math.approxEqAbs(f32, tanh32(0.0), 0.0, epsilon));
135 expect(math.approxEqAbs(f32, tanh32(0.2), 0.197375, epsilon));
136 expect(math.approxEqAbs(f32, tanh32(0.8923), 0.712528, epsilon));
137 expect(math.approxEqAbs(f32, tanh32(1.5), 0.905148, epsilon));
138 expect(math.approxEqAbs(f32, tanh32(37.45), 1.0, epsilon));
134 try expect(math.approxEqAbs(f32, tanh32(0.0), 0.0, epsilon));
135 try expect(math.approxEqAbs(f32, tanh32(0.2), 0.197375, epsilon));
136 try expect(math.approxEqAbs(f32, tanh32(0.8923), 0.712528, epsilon));
137 try expect(math.approxEqAbs(f32, tanh32(1.5), 0.905148, epsilon));
138 try expect(math.approxEqAbs(f32, tanh32(37.45), 1.0, epsilon));
139139}
140140
141141test "math.tanh64" {
142142 const epsilon = 0.000001;
143143
144 expect(math.approxEqAbs(f64, tanh64(0.0), 0.0, epsilon));
145 expect(math.approxEqAbs(f64, tanh64(0.2), 0.197375, epsilon));
146 expect(math.approxEqAbs(f64, tanh64(0.8923), 0.712528, epsilon));
147 expect(math.approxEqAbs(f64, tanh64(1.5), 0.905148, epsilon));
148 expect(math.approxEqAbs(f64, tanh64(37.45), 1.0, epsilon));
144 try expect(math.approxEqAbs(f64, tanh64(0.0), 0.0, epsilon));
145 try expect(math.approxEqAbs(f64, tanh64(0.2), 0.197375, epsilon));
146 try expect(math.approxEqAbs(f64, tanh64(0.8923), 0.712528, epsilon));
147 try expect(math.approxEqAbs(f64, tanh64(1.5), 0.905148, epsilon));
148 try expect(math.approxEqAbs(f64, tanh64(37.45), 1.0, epsilon));
149149}
150150
151151test "math.tanh32.special" {
152 expect(tanh32(0.0) == 0.0);
153 expect(tanh32(-0.0) == -0.0);
154 expect(tanh32(math.inf(f32)) == 1.0);
155 expect(tanh32(-math.inf(f32)) == -1.0);
156 expect(math.isNan(tanh32(math.nan(f32))));
152 try expect(tanh32(0.0) == 0.0);
153 try expect(tanh32(-0.0) == -0.0);
154 try expect(tanh32(math.inf(f32)) == 1.0);
155 try expect(tanh32(-math.inf(f32)) == -1.0);
156 try expect(math.isNan(tanh32(math.nan(f32))));
157157}
158158
159159test "math.tanh64.special" {
160 expect(tanh64(0.0) == 0.0);
161 expect(tanh64(-0.0) == -0.0);
162 expect(tanh64(math.inf(f64)) == 1.0);
163 expect(tanh64(-math.inf(f64)) == -1.0);
164 expect(math.isNan(tanh64(math.nan(f64))));
160 try expect(tanh64(0.0) == 0.0);
161 try expect(tanh64(-0.0) == -0.0);
162 try expect(tanh64(math.inf(f64)) == 1.0);
163 try expect(tanh64(-math.inf(f64)) == -1.0);
164 try expect(math.isNan(tanh64(math.nan(f64))));
165165}
lib/std/math/trunc.zig+27-27
......@@ -94,49 +94,49 @@ fn trunc128(x: f128) f128 {
9494}
9595
9696test "math.trunc" {
97 expect(trunc(@as(f32, 1.3)) == trunc32(1.3));
98 expect(trunc(@as(f64, 1.3)) == trunc64(1.3));
99 expect(trunc(@as(f128, 1.3)) == trunc128(1.3));
97 try expect(trunc(@as(f32, 1.3)) == trunc32(1.3));
98 try expect(trunc(@as(f64, 1.3)) == trunc64(1.3));
99 try expect(trunc(@as(f128, 1.3)) == trunc128(1.3));
100100}
101101
102102test "math.trunc32" {
103 expect(trunc32(1.3) == 1.0);
104 expect(trunc32(-1.3) == -1.0);
105 expect(trunc32(0.2) == 0.0);
103 try expect(trunc32(1.3) == 1.0);
104 try expect(trunc32(-1.3) == -1.0);
105 try expect(trunc32(0.2) == 0.0);
106106}
107107
108108test "math.trunc64" {
109 expect(trunc64(1.3) == 1.0);
110 expect(trunc64(-1.3) == -1.0);
111 expect(trunc64(0.2) == 0.0);
109 try expect(trunc64(1.3) == 1.0);
110 try expect(trunc64(-1.3) == -1.0);
111 try expect(trunc64(0.2) == 0.0);
112112}
113113
114114test "math.trunc128" {
115 expect(trunc128(1.3) == 1.0);
116 expect(trunc128(-1.3) == -1.0);
117 expect(trunc128(0.2) == 0.0);
115 try expect(trunc128(1.3) == 1.0);
116 try expect(trunc128(-1.3) == -1.0);
117 try expect(trunc128(0.2) == 0.0);
118118}
119119
120120test "math.trunc32.special" {
121 expect(trunc32(0.0) == 0.0); // 0x3F800000
122 expect(trunc32(-0.0) == -0.0);
123 expect(math.isPositiveInf(trunc32(math.inf(f32))));
124 expect(math.isNegativeInf(trunc32(-math.inf(f32))));
125 expect(math.isNan(trunc32(math.nan(f32))));
121 try expect(trunc32(0.0) == 0.0); // 0x3F800000
122 try expect(trunc32(-0.0) == -0.0);
123 try expect(math.isPositiveInf(trunc32(math.inf(f32))));
124 try expect(math.isNegativeInf(trunc32(-math.inf(f32))));
125 try expect(math.isNan(trunc32(math.nan(f32))));
126126}
127127
128128test "math.trunc64.special" {
129 expect(trunc64(0.0) == 0.0);
130 expect(trunc64(-0.0) == -0.0);
131 expect(math.isPositiveInf(trunc64(math.inf(f64))));
132 expect(math.isNegativeInf(trunc64(-math.inf(f64))));
133 expect(math.isNan(trunc64(math.nan(f64))));
129 try expect(trunc64(0.0) == 0.0);
130 try expect(trunc64(-0.0) == -0.0);
131 try expect(math.isPositiveInf(trunc64(math.inf(f64))));
132 try expect(math.isNegativeInf(trunc64(-math.inf(f64))));
133 try expect(math.isNan(trunc64(math.nan(f64))));
134134}
135135
136136test "math.trunc128.special" {
137 expect(trunc128(0.0) == 0.0);
138 expect(trunc128(-0.0) == -0.0);
139 expect(math.isPositiveInf(trunc128(math.inf(f128))));
140 expect(math.isNegativeInf(trunc128(-math.inf(f128))));
141 expect(math.isNan(trunc128(math.nan(f128))));
137 try expect(trunc128(0.0) == 0.0);
138 try expect(trunc128(-0.0) == -0.0);
139 try expect(math.isPositiveInf(trunc128(math.inf(f128))));
140 try expect(math.isNegativeInf(trunc128(-math.inf(f128))));
141 try expect(math.isNan(trunc128(math.nan(f128))));
142142}
lib/std/mem.zig+359-359
......@@ -142,8 +142,8 @@ fn failAllocatorAlloc(self: *Allocator, n: usize, alignment: u29, len_align: u29
142142}
143143
144144test "mem.Allocator basics" {
145 testing.expectError(error.OutOfMemory, failAllocator.alloc(u8, 1));
146 testing.expectError(error.OutOfMemory, failAllocator.allocSentinel(u8, 1, 0));
145 try testing.expectError(error.OutOfMemory, failAllocator.alloc(u8, 1));
146 try testing.expectError(error.OutOfMemory, failAllocator.allocSentinel(u8, 1, 0));
147147}
148148
149149/// Copy all of source into dest at position 0.
......@@ -276,8 +276,8 @@ test "mem.zeroes" {
276276 var a = zeroes(C_struct);
277277 a.y += 10;
278278
279 testing.expect(a.x == 0);
280 testing.expect(a.y == 10);
279 try testing.expect(a.x == 0);
280 try testing.expect(a.y == 10);
281281
282282 const ZigStruct = struct {
283283 integral_types: struct {
......@@ -314,32 +314,32 @@ test "mem.zeroes" {
314314 };
315315
316316 const b = zeroes(ZigStruct);
317 testing.expectEqual(@as(i8, 0), b.integral_types.integer_0);
318 testing.expectEqual(@as(i8, 0), b.integral_types.integer_8);
319 testing.expectEqual(@as(i16, 0), b.integral_types.integer_16);
320 testing.expectEqual(@as(i32, 0), b.integral_types.integer_32);
321 testing.expectEqual(@as(i64, 0), b.integral_types.integer_64);
322 testing.expectEqual(@as(i128, 0), b.integral_types.integer_128);
323 testing.expectEqual(@as(u8, 0), b.integral_types.unsigned_0);
324 testing.expectEqual(@as(u8, 0), b.integral_types.unsigned_8);
325 testing.expectEqual(@as(u16, 0), b.integral_types.unsigned_16);
326 testing.expectEqual(@as(u32, 0), b.integral_types.unsigned_32);
327 testing.expectEqual(@as(u64, 0), b.integral_types.unsigned_64);
328 testing.expectEqual(@as(u128, 0), b.integral_types.unsigned_128);
329 testing.expectEqual(@as(f32, 0), b.integral_types.float_32);
330 testing.expectEqual(@as(f64, 0), b.integral_types.float_64);
331 testing.expectEqual(@as(?*u8, null), b.pointers.optional);
332 testing.expectEqual(@as([*c]u8, null), b.pointers.c_pointer);
333 testing.expectEqual(@as([]u8, &[_]u8{}), b.pointers.slice);
317 try testing.expectEqual(@as(i8, 0), b.integral_types.integer_0);
318 try testing.expectEqual(@as(i8, 0), b.integral_types.integer_8);
319 try testing.expectEqual(@as(i16, 0), b.integral_types.integer_16);
320 try testing.expectEqual(@as(i32, 0), b.integral_types.integer_32);
321 try testing.expectEqual(@as(i64, 0), b.integral_types.integer_64);
322 try testing.expectEqual(@as(i128, 0), b.integral_types.integer_128);
323 try testing.expectEqual(@as(u8, 0), b.integral_types.unsigned_0);
324 try testing.expectEqual(@as(u8, 0), b.integral_types.unsigned_8);
325 try testing.expectEqual(@as(u16, 0), b.integral_types.unsigned_16);
326 try testing.expectEqual(@as(u32, 0), b.integral_types.unsigned_32);
327 try testing.expectEqual(@as(u64, 0), b.integral_types.unsigned_64);
328 try testing.expectEqual(@as(u128, 0), b.integral_types.unsigned_128);
329 try testing.expectEqual(@as(f32, 0), b.integral_types.float_32);
330 try testing.expectEqual(@as(f64, 0), b.integral_types.float_64);
331 try testing.expectEqual(@as(?*u8, null), b.pointers.optional);
332 try testing.expectEqual(@as([*c]u8, null), b.pointers.c_pointer);
333 try testing.expectEqual(@as([]u8, &[_]u8{}), b.pointers.slice);
334334 for (b.array) |e| {
335 testing.expectEqual(@as(u32, 0), e);
335 try testing.expectEqual(@as(u32, 0), e);
336336 }
337 testing.expectEqual(@splat(2, @as(u32, 0)), b.vector_u32);
338 testing.expectEqual(@splat(2, @as(f32, 0.0)), b.vector_f32);
339 testing.expectEqual(@splat(2, @as(bool, false)), b.vector_bool);
340 testing.expectEqual(@as(?u8, null), b.optional_int);
337 try testing.expectEqual(@splat(2, @as(u32, 0)), b.vector_u32);
338 try testing.expectEqual(@splat(2, @as(f32, 0.0)), b.vector_f32);
339 try testing.expectEqual(@splat(2, @as(bool, false)), b.vector_bool);
340 try testing.expectEqual(@as(?u8, null), b.optional_int);
341341 for (b.sentinel) |e| {
342 testing.expectEqual(@as(u8, 0), e);
342 try testing.expectEqual(@as(u8, 0), e);
343343 }
344344
345345 const C_union = extern union {
......@@ -348,7 +348,7 @@ test "mem.zeroes" {
348348 };
349349
350350 var c = zeroes(C_union);
351 testing.expectEqual(@as(u8, 0), c.a);
351 try testing.expectEqual(@as(u8, 0), c.a);
352352}
353353
354354/// 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" {
421421 .a = 42,
422422 });
423423
424 testing.expectEqual(S{
424 try testing.expectEqual(S{
425425 .a = 42,
426426 .b = null,
427427 .c = .{
......@@ -439,7 +439,7 @@ test "zeroInit" {
439439 };
440440
441441 const c = zeroInit(Color, .{ 255, 255 });
442 testing.expectEqual(Color{
442 try testing.expectEqual(Color{
443443 .r = 255,
444444 .g = 255,
445445 .b = 0,
......@@ -462,11 +462,11 @@ pub fn order(comptime T: type, lhs: []const T, rhs: []const T) math.Order {
462462}
463463
464464test "order" {
465 testing.expect(order(u8, "abcd", "bee") == .lt);
466 testing.expect(order(u8, "abc", "abc") == .eq);
467 testing.expect(order(u8, "abc", "abc0") == .lt);
468 testing.expect(order(u8, "", "") == .eq);
469 testing.expect(order(u8, "", "a") == .lt);
465 try testing.expect(order(u8, "abcd", "bee") == .lt);
466 try testing.expect(order(u8, "abc", "abc") == .eq);
467 try testing.expect(order(u8, "abc", "abc0") == .lt);
468 try testing.expect(order(u8, "", "") == .eq);
469 try testing.expect(order(u8, "", "a") == .lt);
470470}
471471
472472/// Returns true if lhs < rhs, false otherwise
......@@ -475,11 +475,11 @@ pub fn lessThan(comptime T: type, lhs: []const T, rhs: []const T) bool {
475475}
476476
477477test "mem.lessThan" {
478 testing.expect(lessThan(u8, "abcd", "bee"));
479 testing.expect(!lessThan(u8, "abc", "abc"));
480 testing.expect(lessThan(u8, "abc", "abc0"));
481 testing.expect(!lessThan(u8, "", ""));
482 testing.expect(lessThan(u8, "", "a"));
478 try testing.expect(lessThan(u8, "abcd", "bee"));
479 try testing.expect(!lessThan(u8, "abc", "abc"));
480 try testing.expect(lessThan(u8, "abc", "abc0"));
481 try testing.expect(!lessThan(u8, "", ""));
482 try testing.expect(lessThan(u8, "", "a"));
483483}
484484
485485/// 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 {
504504}
505505
506506test "indexOfDiff" {
507 testing.expectEqual(indexOfDiff(u8, "one", "one"), null);
508 testing.expectEqual(indexOfDiff(u8, "one two", "one"), 3);
509 testing.expectEqual(indexOfDiff(u8, "one", "one two"), 3);
510 testing.expectEqual(indexOfDiff(u8, "one twx", "one two"), 6);
511 testing.expectEqual(indexOfDiff(u8, "xne", "one"), 0);
507 try testing.expectEqual(indexOfDiff(u8, "one", "one"), null);
508 try testing.expectEqual(indexOfDiff(u8, "one two", "one"), 3);
509 try testing.expectEqual(indexOfDiff(u8, "one", "one two"), 3);
510 try testing.expectEqual(indexOfDiff(u8, "one twx", "one two"), 6);
511 try testing.expectEqual(indexOfDiff(u8, "xne", "one"), 0);
512512}
513513
514514pub const toSliceConst = @compileError("deprecated; use std.mem.spanZ");
......@@ -548,26 +548,26 @@ pub fn Span(comptime T: type) type {
548548}
549549
550550test "Span" {
551 testing.expect(Span(*[5]u16) == []u16);
552 testing.expect(Span(?*[5]u16) == ?[]u16);
553 testing.expect(Span(*const [5]u16) == []const u16);
554 testing.expect(Span(?*const [5]u16) == ?[]const u16);
555 testing.expect(Span([]u16) == []u16);
556 testing.expect(Span(?[]u16) == ?[]u16);
557 testing.expect(Span([]const u8) == []const u8);
558 testing.expect(Span(?[]const u8) == ?[]const u8);
559 testing.expect(Span([:1]u16) == [:1]u16);
560 testing.expect(Span(?[:1]u16) == ?[:1]u16);
561 testing.expect(Span([:1]const u8) == [:1]const u8);
562 testing.expect(Span(?[:1]const u8) == ?[:1]const u8);
563 testing.expect(Span([*:1]u16) == [:1]u16);
564 testing.expect(Span(?[*:1]u16) == ?[:1]u16);
565 testing.expect(Span([*:1]const u8) == [:1]const u8);
566 testing.expect(Span(?[*:1]const u8) == ?[:1]const u8);
567 testing.expect(Span([*c]u16) == [:0]u16);
568 testing.expect(Span(?[*c]u16) == ?[:0]u16);
569 testing.expect(Span([*c]const u8) == [:0]const u8);
570 testing.expect(Span(?[*c]const u8) == ?[:0]const u8);
551 try testing.expect(Span(*[5]u16) == []u16);
552 try testing.expect(Span(?*[5]u16) == ?[]u16);
553 try testing.expect(Span(*const [5]u16) == []const u16);
554 try testing.expect(Span(?*const [5]u16) == ?[]const u16);
555 try testing.expect(Span([]u16) == []u16);
556 try testing.expect(Span(?[]u16) == ?[]u16);
557 try testing.expect(Span([]const u8) == []const u8);
558 try testing.expect(Span(?[]const u8) == ?[]const u8);
559 try testing.expect(Span([:1]u16) == [:1]u16);
560 try testing.expect(Span(?[:1]u16) == ?[:1]u16);
561 try testing.expect(Span([:1]const u8) == [:1]const u8);
562 try testing.expect(Span(?[:1]const u8) == ?[:1]const u8);
563 try testing.expect(Span([*:1]u16) == [:1]u16);
564 try testing.expect(Span(?[*:1]u16) == ?[:1]u16);
565 try testing.expect(Span([*:1]const u8) == [:1]const u8);
566 try testing.expect(Span(?[*:1]const u8) == ?[:1]const u8);
567 try testing.expect(Span([*c]u16) == [:0]u16);
568 try testing.expect(Span(?[*c]u16) == ?[:0]u16);
569 try testing.expect(Span([*c]const u8) == [:0]const u8);
570 try testing.expect(Span(?[*c]const u8) == ?[:0]const u8);
571571}
572572
573573/// 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)) {
597597test "span" {
598598 var array: [5]u16 = [_]u16{ 1, 2, 3, 4, 5 };
599599 const ptr = @as([*:3]u16, array[0..2 :3]);
600 testing.expect(eql(u16, span(ptr), &[_]u16{ 1, 2 }));
601 testing.expect(eql(u16, span(&array), &[_]u16{ 1, 2, 3, 4, 5 }));
602 testing.expectEqual(@as(?[:0]u16, null), span(@as(?[*:0]u16, null)));
600 try testing.expect(eql(u16, span(ptr), &[_]u16{ 1, 2 }));
601 try testing.expect(eql(u16, span(&array), &[_]u16{ 1, 2, 3, 4, 5 }));
602 try testing.expectEqual(@as(?[:0]u16, null), span(@as(?[*:0]u16, null)));
603603}
604604
605605/// 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)) {
625625test "spanZ" {
626626 var array: [5]u16 = [_]u16{ 1, 2, 3, 4, 5 };
627627 const ptr = @as([*:3]u16, array[0..2 :3]);
628 testing.expect(eql(u16, spanZ(ptr), &[_]u16{ 1, 2 }));
629 testing.expect(eql(u16, spanZ(&array), &[_]u16{ 1, 2, 3, 4, 5 }));
630 testing.expectEqual(@as(?[:0]u16, null), spanZ(@as(?[*:0]u16, null)));
628 try testing.expect(eql(u16, spanZ(ptr), &[_]u16{ 1, 2 }));
629 try testing.expect(eql(u16, spanZ(&array), &[_]u16{ 1, 2, 3, 4, 5 }));
630 try testing.expectEqual(@as(?[:0]u16, null), spanZ(@as(?[*:0]u16, null)));
631631}
632632
633633/// Takes a pointer to an array, an array, a vector, a sentinel-terminated pointer,
......@@ -661,30 +661,30 @@ pub fn len(value: anytype) usize {
661661}
662662
663663test "len" {
664 testing.expect(len("aoeu") == 4);
664 try testing.expect(len("aoeu") == 4);
665665
666666 {
667667 var array: [5]u16 = [_]u16{ 1, 2, 3, 4, 5 };
668 testing.expect(len(&array) == 5);
669 testing.expect(len(array[0..3]) == 3);
668 try testing.expect(len(&array) == 5);
669 try testing.expect(len(array[0..3]) == 3);
670670 array[2] = 0;
671671 const ptr = @as([*:0]u16, array[0..2 :0]);
672 testing.expect(len(ptr) == 2);
672 try testing.expect(len(ptr) == 2);
673673 }
674674 {
675675 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);
677677 array[2] = 0;
678 testing.expect(len(&array) == 5);
678 try testing.expect(len(&array) == 5);
679679 }
680680 {
681681 const vector: meta.Vector(2, u32) = [2]u32{ 1, 2 };
682 testing.expect(len(vector) == 2);
682 try testing.expect(len(vector) == 2);
683683 }
684684 {
685685 const tuple = .{ 1, 2 };
686 testing.expect(len(tuple) == 2);
687 testing.expect(tuple[0] == 1);
686 try testing.expect(len(tuple) == 2);
687 try testing.expect(tuple[0] == 1);
688688 }
689689}
690690
......@@ -725,21 +725,21 @@ pub fn lenZ(ptr: anytype) usize {
725725}
726726
727727test "lenZ" {
728 testing.expect(lenZ("aoeu") == 4);
728 try testing.expect(lenZ("aoeu") == 4);
729729
730730 {
731731 var array: [5]u16 = [_]u16{ 1, 2, 3, 4, 5 };
732 testing.expect(lenZ(&array) == 5);
733 testing.expect(lenZ(array[0..3]) == 3);
732 try testing.expect(lenZ(&array) == 5);
733 try testing.expect(lenZ(array[0..3]) == 3);
734734 array[2] = 0;
735735 const ptr = @as([*:0]u16, array[0..2 :0]);
736 testing.expect(lenZ(ptr) == 2);
736 try testing.expect(lenZ(ptr) == 2);
737737 }
738738 {
739739 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);
741741 array[2] = 0;
742 testing.expect(lenZ(&array) == 2);
742 try testing.expect(lenZ(&array) == 2);
743743 }
744744}
745745
......@@ -793,10 +793,10 @@ pub fn trim(comptime T: type, slice: []const T, values_to_strip: []const T) []co
793793}
794794
795795test "mem.trim" {
796 testing.expectEqualSlices(u8, "foo\n ", trimLeft(u8, " foo\n ", " \n"));
797 testing.expectEqualSlices(u8, " foo", trimRight(u8, " foo\n ", " \n"));
798 testing.expectEqualSlices(u8, "foo", trim(u8, " foo\n ", " \n"));
799 testing.expectEqualSlices(u8, "foo", trim(u8, "foo", " \n"));
796 try testing.expectEqualSlices(u8, "foo\n ", trimLeft(u8, " foo\n ", " \n"));
797 try testing.expectEqualSlices(u8, " foo", trimRight(u8, " foo\n ", " \n"));
798 try testing.expectEqualSlices(u8, "foo", trim(u8, " foo\n ", " \n"));
799 try testing.expectEqualSlices(u8, "foo", trim(u8, "foo", " \n"));
800800}
801801
802802/// 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
951951}
952952
953953test "mem.indexOf" {
954 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);
956 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);
958
959 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);
961
962 testing.expect(indexOf(u8, "one two three four", "four").? == 14);
963 testing.expect(lastIndexOf(u8, "one two three two four", "two").? == 14);
964 testing.expect(indexOf(u8, "one two three four", "gour") == null);
965 testing.expect(lastIndexOf(u8, "one two three four", "gour") == null);
966 testing.expect(indexOf(u8, "foo", "foo").? == 0);
967 testing.expect(lastIndexOf(u8, "foo", "foo").? == 0);
968 testing.expect(indexOf(u8, "foo", "fool") == null);
969 testing.expect(lastIndexOf(u8, "foo", "lfoo") == null);
970 testing.expect(lastIndexOf(u8, "foo", "fool") == null);
971
972 testing.expect(indexOf(u8, "foo foo", "foo").? == 0);
973 testing.expect(lastIndexOf(u8, "foo foo", "foo").? == 4);
974 testing.expect(lastIndexOfAny(u8, "boo, cat", "abo").? == 6);
975 testing.expect(lastIndexOfScalar(u8, "boo", 'o').? == 2);
954 try testing.expect(indexOf(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 try testing.expect(indexOf(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);
958
959 try testing.expect(indexOf(u8, "one two three four five six seven eight nine ten", "").? == 0);
960 try testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten", "").? == 48);
961
962 try testing.expect(indexOf(u8, "one two three four", "four").? == 14);
963 try testing.expect(lastIndexOf(u8, "one two three two four", "two").? == 14);
964 try testing.expect(indexOf(u8, "one two three four", "gour") == null);
965 try testing.expect(lastIndexOf(u8, "one two three four", "gour") == null);
966 try testing.expect(indexOf(u8, "foo", "foo").? == 0);
967 try testing.expect(lastIndexOf(u8, "foo", "foo").? == 0);
968 try testing.expect(indexOf(u8, "foo", "fool") == null);
969 try testing.expect(lastIndexOf(u8, "foo", "lfoo") == null);
970 try testing.expect(lastIndexOf(u8, "foo", "fool") == null);
971
972 try testing.expect(indexOf(u8, "foo foo", "foo").? == 0);
973 try testing.expect(lastIndexOf(u8, "foo foo", "foo").? == 4);
974 try testing.expect(lastIndexOfAny(u8, "boo, cat", "abo").? == 6);
975 try testing.expect(lastIndexOfScalar(u8, "boo", 'o').? == 2);
976976}
977977
978978/// 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 {
992992}
993993
994994test "mem.count" {
995 testing.expect(count(u8, "", "h") == 0);
996 testing.expect(count(u8, "h", "h") == 1);
997 testing.expect(count(u8, "hh", "h") == 2);
998 testing.expect(count(u8, "world!", "hello") == 0);
999 testing.expect(count(u8, "hello world!", "hello") == 1);
1000 testing.expect(count(u8, " abcabc abc", "abc") == 3);
1001 testing.expect(count(u8, "udexdcbvbruhasdrw", "bruh") == 1);
1002 testing.expect(count(u8, "foo bar", "o bar") == 1);
1003 testing.expect(count(u8, "foofoofoo", "foo") == 3);
1004 testing.expect(count(u8, "fffffff", "ff") == 3);
1005 testing.expect(count(u8, "owowowu", "owowu") == 1);
995 try testing.expect(count(u8, "", "h") == 0);
996 try testing.expect(count(u8, "h", "h") == 1);
997 try testing.expect(count(u8, "hh", "h") == 2);
998 try testing.expect(count(u8, "world!", "hello") == 0);
999 try testing.expect(count(u8, "hello world!", "hello") == 1);
1000 try testing.expect(count(u8, " abcabc abc", "abc") == 3);
1001 try testing.expect(count(u8, "udexdcbvbruhasdrw", "bruh") == 1);
1002 try testing.expect(count(u8, "foo bar", "o bar") == 1);
1003 try testing.expect(count(u8, "foofoofoo", "foo") == 3);
1004 try testing.expect(count(u8, "fffffff", "ff") == 3);
1005 try testing.expect(count(u8, "owowowu", "owowu") == 1);
10061006}
10071007
10081008/// 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
10241024}
10251025
10261026test "mem.containsAtLeast" {
1027 testing.expect(containsAtLeast(u8, "aa", 0, "a"));
1028 testing.expect(containsAtLeast(u8, "aa", 1, "a"));
1029 testing.expect(containsAtLeast(u8, "aa", 2, "a"));
1030 testing.expect(!containsAtLeast(u8, "aa", 3, "a"));
1027 try testing.expect(containsAtLeast(u8, "aa", 0, "a"));
1028 try testing.expect(containsAtLeast(u8, "aa", 1, "a"));
1029 try testing.expect(containsAtLeast(u8, "aa", 2, "a"));
1030 try testing.expect(!containsAtLeast(u8, "aa", 3, "a"));
10311031
1032 testing.expect(containsAtLeast(u8, "radaradar", 1, "radar"));
1033 testing.expect(!containsAtLeast(u8, "radaradar", 2, "radar"));
1032 try testing.expect(containsAtLeast(u8, "radaradar", 1, "radar"));
1033 try testing.expect(!containsAtLeast(u8, "radaradar", 2, "radar"));
10341034
1035 testing.expect(containsAtLeast(u8, "radarradaradarradar", 3, "radar"));
1036 testing.expect(!containsAtLeast(u8, "radarradaradarradar", 4, "radar"));
1035 try testing.expect(containsAtLeast(u8, "radarradaradarradar", 3, "radar"));
1036 try testing.expect(!containsAtLeast(u8, "radarradaradarradar", 4, "radar"));
10371037
1038 testing.expect(containsAtLeast(u8, " radar radar ", 2, "radar"));
1039 testing.expect(!containsAtLeast(u8, " radar radar ", 3, "radar"));
1038 try testing.expect(containsAtLeast(u8, " radar radar ", 2, "radar"));
1039 try testing.expect(!containsAtLeast(u8, " radar radar ", 3, "radar"));
10401040}
10411041
10421042/// Reads an integer from memory with size equal to bytes.len.
......@@ -1141,34 +1141,34 @@ test "comptime read/write int" {
11411141 var bytes: [2]u8 = undefined;
11421142 writeIntLittle(u16, &bytes, 0x1234);
11431143 const result = readIntBig(u16, &bytes);
1144 testing.expect(result == 0x3412);
1144 try testing.expect(result == 0x3412);
11451145 }
11461146 comptime {
11471147 var bytes: [2]u8 = undefined;
11481148 writeIntBig(u16, &bytes, 0x1234);
11491149 const result = readIntLittle(u16, &bytes);
1150 testing.expect(result == 0x3412);
1150 try testing.expect(result == 0x3412);
11511151 }
11521152}
11531153
11541154test "readIntBig and readIntLittle" {
1155 testing.expect(readIntSliceBig(u0, &[_]u8{}) == 0x0);
1156 testing.expect(readIntSliceLittle(u0, &[_]u8{}) == 0x0);
1155 try testing.expect(readIntSliceBig(u0, &[_]u8{}) == 0x0);
1156 try testing.expect(readIntSliceLittle(u0, &[_]u8{}) == 0x0);
11571157
1158 testing.expect(readIntSliceBig(u8, &[_]u8{0x32}) == 0x32);
1159 testing.expect(readIntSliceLittle(u8, &[_]u8{0x12}) == 0x12);
1158 try testing.expect(readIntSliceBig(u8, &[_]u8{0x32}) == 0x32);
1159 try testing.expect(readIntSliceLittle(u8, &[_]u8{0x12}) == 0x12);
11601160
1161 testing.expect(readIntSliceBig(u16, &[_]u8{ 0x12, 0x34 }) == 0x1234);
1162 testing.expect(readIntSliceLittle(u16, &[_]u8{ 0x12, 0x34 }) == 0x3412);
1161 try testing.expect(readIntSliceBig(u16, &[_]u8{ 0x12, 0x34 }) == 0x1234);
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);
1165 testing.expect(readIntSliceLittle(u72, &[_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }) == 0xfedcba9876543210ec);
1164 try testing.expect(readIntSliceBig(u72, &[_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }) == 0x123456789abcdef024);
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);
1168 testing.expect(readIntSliceLittle(i8, &[_]u8{0xfe}) == -2);
1167 try testing.expect(readIntSliceBig(i8, &[_]u8{0xff}) == -1);
1168 try testing.expect(readIntSliceLittle(i8, &[_]u8{0xfe}) == -2);
11691169
1170 testing.expect(readIntSliceBig(i16, &[_]u8{ 0xff, 0xfd }) == -3);
1171 testing.expect(readIntSliceLittle(i16, &[_]u8{ 0xfc, 0xff }) == -4);
1170 try testing.expect(readIntSliceBig(i16, &[_]u8{ 0xff, 0xfd }) == -3);
1171 try testing.expect(readIntSliceLittle(i16, &[_]u8{ 0xfc, 0xff }) == -4);
11721172}
11731173
11741174/// Writes an integer to memory, storing it in twos-complement.
......@@ -1283,34 +1283,34 @@ test "writeIntBig and writeIntLittle" {
12831283 var buf9: [9]u8 = undefined;
12841284
12851285 writeIntBig(u0, &buf0, 0x0);
1286 testing.expect(eql(u8, buf0[0..], &[_]u8{}));
1286 try testing.expect(eql(u8, buf0[0..], &[_]u8{}));
12871287 writeIntLittle(u0, &buf0, 0x0);
1288 testing.expect(eql(u8, buf0[0..], &[_]u8{}));
1288 try testing.expect(eql(u8, buf0[0..], &[_]u8{}));
12891289
12901290 writeIntBig(u8, &buf1, 0x12);
1291 testing.expect(eql(u8, buf1[0..], &[_]u8{0x12}));
1291 try testing.expect(eql(u8, buf1[0..], &[_]u8{0x12}));
12921292 writeIntLittle(u8, &buf1, 0x34);
1293 testing.expect(eql(u8, buf1[0..], &[_]u8{0x34}));
1293 try testing.expect(eql(u8, buf1[0..], &[_]u8{0x34}));
12941294
12951295 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 }));
12971297 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
13001300 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 }));
13021302 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
13051305 writeIntBig(i8, &buf1, -1);
1306 testing.expect(eql(u8, buf1[0..], &[_]u8{0xff}));
1306 try testing.expect(eql(u8, buf1[0..], &[_]u8{0xff}));
13071307 writeIntLittle(i8, &buf1, -2);
1308 testing.expect(eql(u8, buf1[0..], &[_]u8{0xfe}));
1308 try testing.expect(eql(u8, buf1[0..], &[_]u8{0xfe}));
13091309
13101310 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 }));
13121312 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 }));
13141314}
13151315
13161316/// 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 {
13311331
13321332test "mem.tokenize" {
13331333 var it = tokenize(" abc def ghi ", " ");
1334 testing.expect(eql(u8, it.next().?, "abc"));
1335 testing.expect(eql(u8, it.next().?, "def"));
1336 testing.expect(eql(u8, it.next().?, "ghi"));
1337 testing.expect(it.next() == null);
1334 try testing.expect(eql(u8, it.next().?, "abc"));
1335 try testing.expect(eql(u8, it.next().?, "def"));
1336 try testing.expect(eql(u8, it.next().?, "ghi"));
1337 try testing.expect(it.next() == null);
13381338
13391339 it = tokenize("..\\bob", "\\");
1340 testing.expect(eql(u8, it.next().?, ".."));
1341 testing.expect(eql(u8, "..", "..\\bob"[0..it.index]));
1342 testing.expect(eql(u8, it.next().?, "bob"));
1343 testing.expect(it.next() == null);
1340 try testing.expect(eql(u8, it.next().?, ".."));
1341 try testing.expect(eql(u8, "..", "..\\bob"[0..it.index]));
1342 try testing.expect(eql(u8, it.next().?, "bob"));
1343 try testing.expect(it.next() == null);
13441344
13451345 it = tokenize("//a/b", "/");
1346 testing.expect(eql(u8, it.next().?, "a"));
1347 testing.expect(eql(u8, it.next().?, "b"));
1348 testing.expect(eql(u8, "//a/b", "//a/b"[0..it.index]));
1349 testing.expect(it.next() == null);
1346 try testing.expect(eql(u8, it.next().?, "a"));
1347 try testing.expect(eql(u8, it.next().?, "b"));
1348 try testing.expect(eql(u8, "//a/b", "//a/b"[0..it.index]));
1349 try testing.expect(it.next() == null);
13501350
13511351 it = tokenize("|", "|");
1352 testing.expect(it.next() == null);
1352 try testing.expect(it.next() == null);
13531353
13541354 it = tokenize("", "|");
1355 testing.expect(it.next() == null);
1355 try testing.expect(it.next() == null);
13561356
13571357 it = tokenize("hello", "");
1358 testing.expect(eql(u8, it.next().?, "hello"));
1359 testing.expect(it.next() == null);
1358 try testing.expect(eql(u8, it.next().?, "hello"));
1359 try testing.expect(it.next() == null);
13601360
13611361 it = tokenize("hello", " ");
1362 testing.expect(eql(u8, it.next().?, "hello"));
1363 testing.expect(it.next() == null);
1362 try testing.expect(eql(u8, it.next().?, "hello"));
1363 try testing.expect(it.next() == null);
13641364}
13651365
13661366test "mem.tokenize (multibyte)" {
13671367 var it = tokenize("a|b,c/d e", " /,|");
1368 testing.expect(eql(u8, it.next().?, "a"));
1369 testing.expect(eql(u8, it.next().?, "b"));
1370 testing.expect(eql(u8, it.next().?, "c"));
1371 testing.expect(eql(u8, it.next().?, "d"));
1372 testing.expect(eql(u8, it.next().?, "e"));
1373 testing.expect(it.next() == null);
1368 try testing.expect(eql(u8, it.next().?, "a"));
1369 try testing.expect(eql(u8, it.next().?, "b"));
1370 try testing.expect(eql(u8, it.next().?, "c"));
1371 try testing.expect(eql(u8, it.next().?, "d"));
1372 try testing.expect(eql(u8, it.next().?, "e"));
1373 try testing.expect(it.next() == null);
13741374}
13751375
13761376test "mem.tokenize (reset)" {
13771377 var it = tokenize(" abc def ghi ", " ");
1378 testing.expect(eql(u8, it.next().?, "abc"));
1379 testing.expect(eql(u8, it.next().?, "def"));
1380 testing.expect(eql(u8, it.next().?, "ghi"));
1378 try testing.expect(eql(u8, it.next().?, "abc"));
1379 try testing.expect(eql(u8, it.next().?, "def"));
1380 try testing.expect(eql(u8, it.next().?, "ghi"));
13811381
13821382 it.reset();
13831383
1384 testing.expect(eql(u8, it.next().?, "abc"));
1385 testing.expect(eql(u8, it.next().?, "def"));
1386 testing.expect(eql(u8, it.next().?, "ghi"));
1387 testing.expect(it.next() == null);
1384 try testing.expect(eql(u8, it.next().?, "abc"));
1385 try testing.expect(eql(u8, it.next().?, "def"));
1386 try testing.expect(eql(u8, it.next().?, "ghi"));
1387 try testing.expect(it.next() == null);
13881388}
13891389
13901390/// 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
14081408
14091409test "mem.split" {
14101410 var it = split("abc|def||ghi", "|");
1411 testing.expect(eql(u8, it.next().?, "abc"));
1412 testing.expect(eql(u8, it.next().?, "def"));
1413 testing.expect(eql(u8, it.next().?, ""));
1414 testing.expect(eql(u8, it.next().?, "ghi"));
1415 testing.expect(it.next() == null);
1411 try testing.expect(eql(u8, it.next().?, "abc"));
1412 try testing.expect(eql(u8, it.next().?, "def"));
1413 try testing.expect(eql(u8, it.next().?, ""));
1414 try testing.expect(eql(u8, it.next().?, "ghi"));
1415 try testing.expect(it.next() == null);
14161416
14171417 it = split("", "|");
1418 testing.expect(eql(u8, it.next().?, ""));
1419 testing.expect(it.next() == null);
1418 try testing.expect(eql(u8, it.next().?, ""));
1419 try testing.expect(it.next() == null);
14201420
14211421 it = split("|", "|");
1422 testing.expect(eql(u8, it.next().?, ""));
1423 testing.expect(eql(u8, it.next().?, ""));
1424 testing.expect(it.next() == null);
1422 try testing.expect(eql(u8, it.next().?, ""));
1423 try testing.expect(eql(u8, it.next().?, ""));
1424 try testing.expect(it.next() == null);
14251425
14261426 it = split("hello", " ");
1427 testing.expect(eql(u8, it.next().?, "hello"));
1428 testing.expect(it.next() == null);
1427 try testing.expect(eql(u8, it.next().?, "hello"));
1428 try testing.expect(it.next() == null);
14291429}
14301430
14311431test "mem.split (multibyte)" {
14321432 var it = split("a, b ,, c, d, e", ", ");
1433 testing.expect(eql(u8, it.next().?, "a"));
1434 testing.expect(eql(u8, it.next().?, "b ,"));
1435 testing.expect(eql(u8, it.next().?, "c"));
1436 testing.expect(eql(u8, it.next().?, "d"));
1437 testing.expect(eql(u8, it.next().?, "e"));
1438 testing.expect(it.next() == null);
1433 try testing.expect(eql(u8, it.next().?, "a"));
1434 try testing.expect(eql(u8, it.next().?, "b ,"));
1435 try testing.expect(eql(u8, it.next().?, "c"));
1436 try testing.expect(eql(u8, it.next().?, "d"));
1437 try testing.expect(eql(u8, it.next().?, "e"));
1438 try testing.expect(it.next() == null);
14391439}
14401440
14411441pub 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
14431443}
14441444
14451445test "mem.startsWith" {
1446 testing.expect(startsWith(u8, "Bob", "Bo"));
1447 testing.expect(!startsWith(u8, "Needle in haystack", "haystack"));
1446 try testing.expect(startsWith(u8, "Bob", "Bo"));
1447 try testing.expect(!startsWith(u8, "Needle in haystack", "haystack"));
14481448}
14491449
14501450pub 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 {
14521452}
14531453
14541454test "mem.endsWith" {
1455 testing.expect(endsWith(u8, "Needle in haystack", "haystack"));
1456 testing.expect(!endsWith(u8, "Bob", "Bo"));
1455 try testing.expect(endsWith(u8, "Needle in haystack", "haystack"));
1456 try testing.expect(!endsWith(u8, "Bob", "Bo"));
14571457}
14581458
14591459pub const TokenIterator = struct {
......@@ -1571,22 +1571,22 @@ test "mem.join" {
15711571 {
15721572 const str = try join(testing.allocator, ",", &[_][]const u8{});
15731573 defer testing.allocator.free(str);
1574 testing.expect(eql(u8, str, ""));
1574 try testing.expect(eql(u8, str, ""));
15751575 }
15761576 {
15771577 const str = try join(testing.allocator, ",", &[_][]const u8{ "a", "b", "c" });
15781578 defer testing.allocator.free(str);
1579 testing.expect(eql(u8, str, "a,b,c"));
1579 try testing.expect(eql(u8, str, "a,b,c"));
15801580 }
15811581 {
15821582 const str = try join(testing.allocator, ",", &[_][]const u8{"a"});
15831583 defer testing.allocator.free(str);
1584 testing.expect(eql(u8, str, "a"));
1584 try testing.expect(eql(u8, str, "a"));
15851585 }
15861586 {
15871587 const str = try join(testing.allocator, ",", &[_][]const u8{ "a", "", "b", "", "c" });
15881588 defer testing.allocator.free(str);
1589 testing.expect(eql(u8, str, "a,,b,,c"));
1589 try testing.expect(eql(u8, str, "a,,b,,c"));
15901590 }
15911591}
15921592
......@@ -1594,26 +1594,26 @@ test "mem.joinZ" {
15941594 {
15951595 const str = try joinZ(testing.allocator, ",", &[_][]const u8{});
15961596 defer testing.allocator.free(str);
1597 testing.expect(eql(u8, str, ""));
1598 testing.expectEqual(str[str.len], 0);
1597 try testing.expect(eql(u8, str, ""));
1598 try testing.expectEqual(str[str.len], 0);
15991599 }
16001600 {
16011601 const str = try joinZ(testing.allocator, ",", &[_][]const u8{ "a", "b", "c" });
16021602 defer testing.allocator.free(str);
1603 testing.expect(eql(u8, str, "a,b,c"));
1604 testing.expectEqual(str[str.len], 0);
1603 try testing.expect(eql(u8, str, "a,b,c"));
1604 try testing.expectEqual(str[str.len], 0);
16051605 }
16061606 {
16071607 const str = try joinZ(testing.allocator, ",", &[_][]const u8{"a"});
16081608 defer testing.allocator.free(str);
1609 testing.expect(eql(u8, str, "a"));
1610 testing.expectEqual(str[str.len], 0);
1609 try testing.expect(eql(u8, str, "a"));
1610 try testing.expectEqual(str[str.len], 0);
16111611 }
16121612 {
16131613 const str = try joinZ(testing.allocator, ",", &[_][]const u8{ "a", "", "b", "", "c" });
16141614 defer testing.allocator.free(str);
1615 testing.expect(eql(u8, str, "a,,b,,c"));
1616 testing.expectEqual(str[str.len], 0);
1615 try testing.expect(eql(u8, str, "a,,b,,c"));
1616 try testing.expectEqual(str[str.len], 0);
16171617 }
16181618}
16191619
......@@ -1646,7 +1646,7 @@ test "concat" {
16461646 {
16471647 const str = try concat(testing.allocator, u8, &[_][]const u8{ "abc", "def", "ghi" });
16481648 defer testing.allocator.free(str);
1649 testing.expect(eql(u8, str, "abcdefghi"));
1649 try testing.expect(eql(u8, str, "abcdefghi"));
16501650 }
16511651 {
16521652 const str = try concat(testing.allocator, u32, &[_][]const u32{
......@@ -1656,21 +1656,21 @@ test "concat" {
16561656 &[_]u32{5},
16571657 });
16581658 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 }));
16601660 }
16611661}
16621662
16631663test "testStringEquality" {
1664 testing.expect(eql(u8, "abcd", "abcd"));
1665 testing.expect(!eql(u8, "abcdef", "abZdef"));
1666 testing.expect(!eql(u8, "abcdefg", "abcdef"));
1664 try testing.expect(eql(u8, "abcd", "abcd"));
1665 try testing.expect(!eql(u8, "abcdef", "abZdef"));
1666 try testing.expect(!eql(u8, "abcdefg", "abcdef"));
16671667}
16681668
16691669test "testReadInt" {
1670 testReadIntImpl();
1671 comptime testReadIntImpl();
1670 try testReadIntImpl();
1671 comptime try testReadIntImpl();
16721672}
1673fn testReadIntImpl() void {
1673fn testReadIntImpl() !void {
16741674 {
16751675 const bytes = [_]u8{
16761676 0x12,
......@@ -1678,12 +1678,12 @@ fn testReadIntImpl() void {
16781678 0x56,
16791679 0x78,
16801680 };
1681 testing.expect(readInt(u32, &bytes, builtin.Endian.Big) == 0x12345678);
1682 testing.expect(readIntBig(u32, &bytes) == 0x12345678);
1683 testing.expect(readIntBig(i32, &bytes) == 0x12345678);
1684 testing.expect(readInt(u32, &bytes, builtin.Endian.Little) == 0x78563412);
1685 testing.expect(readIntLittle(u32, &bytes) == 0x78563412);
1686 testing.expect(readIntLittle(i32, &bytes) == 0x78563412);
1681 try testing.expect(readInt(u32, &bytes, builtin.Endian.Big) == 0x12345678);
1682 try testing.expect(readIntBig(u32, &bytes) == 0x12345678);
1683 try testing.expect(readIntBig(i32, &bytes) == 0x12345678);
1684 try testing.expect(readInt(u32, &bytes, builtin.Endian.Little) == 0x78563412);
1685 try testing.expect(readIntLittle(u32, &bytes) == 0x78563412);
1686 try testing.expect(readIntLittle(i32, &bytes) == 0x78563412);
16871687 }
16881688 {
16891689 const buf = [_]u8{
......@@ -1693,7 +1693,7 @@ fn testReadIntImpl() void {
16931693 0x34,
16941694 };
16951695 const answer = readInt(u32, &buf, builtin.Endian.Big);
1696 testing.expect(answer == 0x00001234);
1696 try testing.expect(answer == 0x00001234);
16971697 }
16981698 {
16991699 const buf = [_]u8{
......@@ -1703,41 +1703,41 @@ fn testReadIntImpl() void {
17031703 0x00,
17041704 };
17051705 const answer = readInt(u32, &buf, builtin.Endian.Little);
1706 testing.expect(answer == 0x00003412);
1706 try testing.expect(answer == 0x00003412);
17071707 }
17081708 {
17091709 const bytes = [_]u8{
17101710 0xff,
17111711 0xfe,
17121712 };
1713 testing.expect(readIntBig(u16, &bytes) == 0xfffe);
1714 testing.expect(readIntBig(i16, &bytes) == -0x0002);
1715 testing.expect(readIntLittle(u16, &bytes) == 0xfeff);
1716 testing.expect(readIntLittle(i16, &bytes) == -0x0101);
1713 try testing.expect(readIntBig(u16, &bytes) == 0xfffe);
1714 try testing.expect(readIntBig(i16, &bytes) == -0x0002);
1715 try testing.expect(readIntLittle(u16, &bytes) == 0xfeff);
1716 try testing.expect(readIntLittle(i16, &bytes) == -0x0101);
17171717 }
17181718}
17191719
17201720test "writeIntSlice" {
1721 testWriteIntImpl();
1722 comptime testWriteIntImpl();
1721 try testWriteIntImpl();
1722 comptime try testWriteIntImpl();
17231723}
1724fn testWriteIntImpl() void {
1724fn testWriteIntImpl() !void {
17251725 var bytes: [8]u8 = undefined;
17261726
17271727 writeIntSlice(u0, bytes[0..], 0, builtin.Endian.Big);
1728 testing.expect(eql(u8, &bytes, &[_]u8{
1728 try testing.expect(eql(u8, &bytes, &[_]u8{
17291729 0x00, 0x00, 0x00, 0x00,
17301730 0x00, 0x00, 0x00, 0x00,
17311731 }));
17321732
17331733 writeIntSlice(u0, bytes[0..], 0, builtin.Endian.Little);
1734 testing.expect(eql(u8, &bytes, &[_]u8{
1734 try testing.expect(eql(u8, &bytes, &[_]u8{
17351735 0x00, 0x00, 0x00, 0x00,
17361736 0x00, 0x00, 0x00, 0x00,
17371737 }));
17381738
17391739 writeIntSlice(u64, bytes[0..], 0x12345678CAFEBABE, builtin.Endian.Big);
1740 testing.expect(eql(u8, &bytes, &[_]u8{
1740 try testing.expect(eql(u8, &bytes, &[_]u8{
17411741 0x12,
17421742 0x34,
17431743 0x56,
......@@ -1749,7 +1749,7 @@ fn testWriteIntImpl() void {
17491749 }));
17501750
17511751 writeIntSlice(u64, bytes[0..], 0xBEBAFECA78563412, builtin.Endian.Little);
1752 testing.expect(eql(u8, &bytes, &[_]u8{
1752 try testing.expect(eql(u8, &bytes, &[_]u8{
17531753 0x12,
17541754 0x34,
17551755 0x56,
......@@ -1761,7 +1761,7 @@ fn testWriteIntImpl() void {
17611761 }));
17621762
17631763 writeIntSlice(u32, bytes[0..], 0x12345678, builtin.Endian.Big);
1764 testing.expect(eql(u8, &bytes, &[_]u8{
1764 try testing.expect(eql(u8, &bytes, &[_]u8{
17651765 0x00,
17661766 0x00,
17671767 0x00,
......@@ -1773,7 +1773,7 @@ fn testWriteIntImpl() void {
17731773 }));
17741774
17751775 writeIntSlice(u32, bytes[0..], 0x78563412, builtin.Endian.Little);
1776 testing.expect(eql(u8, &bytes, &[_]u8{
1776 try testing.expect(eql(u8, &bytes, &[_]u8{
17771777 0x12,
17781778 0x34,
17791779 0x56,
......@@ -1785,7 +1785,7 @@ fn testWriteIntImpl() void {
17851785 }));
17861786
17871787 writeIntSlice(u16, bytes[0..], 0x1234, builtin.Endian.Big);
1788 testing.expect(eql(u8, &bytes, &[_]u8{
1788 try testing.expect(eql(u8, &bytes, &[_]u8{
17891789 0x00,
17901790 0x00,
17911791 0x00,
......@@ -1797,7 +1797,7 @@ fn testWriteIntImpl() void {
17971797 }));
17981798
17991799 writeIntSlice(u16, bytes[0..], 0x1234, builtin.Endian.Little);
1800 testing.expect(eql(u8, &bytes, &[_]u8{
1800 try testing.expect(eql(u8, &bytes, &[_]u8{
18011801 0x34,
18021802 0x12,
18031803 0x00,
......@@ -1820,7 +1820,7 @@ pub fn min(comptime T: type, slice: []const T) T {
18201820}
18211821
18221822test "mem.min" {
1823 testing.expect(min(u8, "abcdefg") == 'a');
1823 try testing.expect(min(u8, "abcdefg") == 'a');
18241824}
18251825
18261826/// Returns the largest number in a slice. O(n).
......@@ -1834,7 +1834,7 @@ pub fn max(comptime T: type, slice: []const T) T {
18341834}
18351835
18361836test "mem.max" {
1837 testing.expect(max(u8, "abcdefg") == 'g');
1837 try testing.expect(max(u8, "abcdefg") == 'g');
18381838}
18391839
18401840pub fn swap(comptime T: type, a: *T, b: *T) void {
......@@ -1856,7 +1856,7 @@ test "reverse" {
18561856 var arr = [_]i32{ 5, 3, 1, 2, 4 };
18571857 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 }));
18601860}
18611861
18621862/// 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" {
18711871 var arr = [_]i32{ 5, 3, 1, 2, 4 };
18721872 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 }));
18751875}
18761876
18771877/// 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" {
19041904 var output: [29]u8 = undefined;
19051905 var replacements = replace(u8, "All your base are belong to us", "base", "Zig", output[0..]);
19061906 var expected: []const u8 = "All your Zig are belong to us";
1907 testing.expect(replacements == 1);
1908 testing.expectEqualStrings(expected, output[0..expected.len]);
1907 try testing.expect(replacements == 1);
1908 try testing.expectEqualStrings(expected, output[0..expected.len]);
19091909
19101910 replacements = replace(u8, "Favor reading code over writing code.", "code", "", output[0..]);
19111911 expected = "Favor reading over writing .";
1912 testing.expect(replacements == 2);
1913 testing.expectEqualStrings(expected, output[0..expected.len]);
1912 try testing.expect(replacements == 2);
1913 try testing.expectEqualStrings(expected, output[0..expected.len]);
19141914
19151915 // Empty needle is not allowed but input may be empty.
19161916 replacements = replace(u8, "", "x", "y", output[0..0]);
19171917 expected = "";
1918 testing.expect(replacements == 0);
1919 testing.expectEqualStrings(expected, output[0..expected.len]);
1918 try testing.expect(replacements == 0);
1919 try testing.expectEqualStrings(expected, output[0..expected.len]);
19201920
19211921 // Adjacent replacements.
19221922
19231923 replacements = replace(u8, "\\n\\n", "\\n", "\n", output[0..]);
19241924 expected = "\n\n";
1925 testing.expect(replacements == 2);
1926 testing.expectEqualStrings(expected, output[0..expected.len]);
1925 try testing.expect(replacements == 2);
1926 try testing.expectEqualStrings(expected, output[0..expected.len]);
19271927
19281928 replacements = replace(u8, "abbba", "b", "cd", output[0..]);
19291929 expected = "acdcdcda";
1930 testing.expect(replacements == 3);
1931 testing.expectEqualStrings(expected, output[0..expected.len]);
1930 try testing.expect(replacements == 3);
1931 try testing.expectEqualStrings(expected, output[0..expected.len]);
19321932}
19331933
19341934/// 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
19521952}
19531953
19541954test "replacementSize" {
1955 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);
1957 testing.expect(replacementSize(u8, "Only one obvious way to do things.", "things.", "things in Zig.") == 41);
1955 try testing.expect(replacementSize(u8, "All your base are belong to us", "base", "Zig") == 29);
1956 try testing.expect(replacementSize(u8, "Favor reading code over writing code.", "code", "") == 29);
1957 try testing.expect(replacementSize(u8, "Only one obvious way to do things.", "things.", "things in Zig.") == 41);
19581958
19591959 // 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
19621962 // Adjacent replacements.
1963 testing.expect(replacementSize(u8, "\\n\\n", "\\n", "\n") == 2);
1964 testing.expect(replacementSize(u8, "abbba", "b", "cd") == 8);
1963 try testing.expect(replacementSize(u8, "\\n\\n", "\\n", "\n") == 2);
1964 try testing.expect(replacementSize(u8, "abbba", "b", "cd") == 8);
19651965}
19661966
19671967/// Perform a replacement on an allocated buffer of pre-determined size. Caller must free returned memory.
......@@ -1976,11 +1976,11 @@ test "replaceOwned" {
19761976
19771977 const base_replace = replaceOwned(u8, allocator, "All your base are belong to us", "base", "Zig") catch unreachable;
19781978 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
19811981 const zen_replace = replaceOwned(u8, allocator, "Favor reading code over writing code.", " code", "") catch unreachable;
19821982 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."));
19841984}
19851985
19861986/// Converts a little-endian integer to host endianness.
......@@ -2068,12 +2068,12 @@ test "asBytes" {
20682068 .Little => "\xEF\xBE\xAD\xDE",
20692069 };
20702070
2071 testing.expect(eql(u8, asBytes(&deadbeef), deadbeef_bytes));
2071 try testing.expect(eql(u8, asBytes(&deadbeef), deadbeef_bytes));
20722072
20732073 var codeface = @as(u32, 0xC0DEFACE);
20742074 for (asBytes(&codeface).*) |*b|
20752075 b.* = 0;
2076 testing.expect(codeface == 0);
2076 try testing.expect(codeface == 0);
20772077
20782078 const S = packed struct {
20792079 a: u8,
......@@ -2088,11 +2088,11 @@ test "asBytes" {
20882088 .c = 0xDE,
20892089 .d = 0xA1,
20902090 };
2091 testing.expect(eql(u8, asBytes(&inst), "\xBE\xEF\xDE\xA1"));
2091 try testing.expect(eql(u8, asBytes(&inst), "\xBE\xEF\xDE\xA1"));
20922092
20932093 const ZST = struct {};
20942094 const zero = ZST{};
2095 testing.expect(eql(u8, asBytes(&zero), ""));
2095 try testing.expect(eql(u8, asBytes(&zero), ""));
20962096}
20972097
20982098test "asBytes preserves pointer attributes" {
......@@ -2103,10 +2103,10 @@ test "asBytes preserves pointer attributes" {
21032103 const in = @typeInfo(@TypeOf(inPtr)).Pointer;
21042104 const out = @typeInfo(@TypeOf(outSlice)).Pointer;
21052105
2106 testing.expectEqual(in.is_const, out.is_const);
2107 testing.expectEqual(in.is_volatile, out.is_volatile);
2108 testing.expectEqual(in.is_allowzero, out.is_allowzero);
2109 testing.expectEqual(in.alignment, out.alignment);
2106 try testing.expectEqual(in.is_const, out.is_const);
2107 try testing.expectEqual(in.is_volatile, out.is_volatile);
2108 try testing.expectEqual(in.is_allowzero, out.is_allowzero);
2109 try testing.expectEqual(in.alignment, out.alignment);
21102110}
21112111
21122112/// 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 {
21172117test "toBytes" {
21182118 var my_bytes = toBytes(@as(u32, 0x12345678));
21192119 switch (builtin.endian) {
2120 .Big => testing.expect(eql(u8, &my_bytes, "\x12\x34\x56\x78")),
2121 .Little => testing.expect(eql(u8, &my_bytes, "\x78\x56\x34\x12")),
2120 .Big => try testing.expect(eql(u8, &my_bytes, "\x12\x34\x56\x78")),
2121 .Little => try testing.expect(eql(u8, &my_bytes, "\x78\x56\x34\x12")),
21222122 }
21232123
21242124 my_bytes[0] = '\x99';
21252125 switch (builtin.endian) {
2126 .Big => testing.expect(eql(u8, &my_bytes, "\x99\x34\x56\x78")),
2127 .Little => testing.expect(eql(u8, &my_bytes, "\x99\x56\x34\x12")),
2126 .Big => try testing.expect(eql(u8, &my_bytes, "\x99\x34\x56\x78")),
2127 .Little => try testing.expect(eql(u8, &my_bytes, "\x99\x56\x34\x12")),
21282128 }
21292129}
21302130
......@@ -2154,17 +2154,17 @@ test "bytesAsValue" {
21542154 .Little => "\xEF\xBE\xAD\xDE",
21552155 };
21562156
2157 testing.expect(deadbeef == bytesAsValue(u32, deadbeef_bytes).*);
2157 try testing.expect(deadbeef == bytesAsValue(u32, deadbeef_bytes).*);
21582158
21592159 var codeface_bytes: [4]u8 = switch (builtin.endian) {
21602160 .Big => "\xC0\xDE\xFA\xCE",
21612161 .Little => "\xCE\xFA\xDE\xC0",
21622162 }.*;
21632163 var codeface = bytesAsValue(u32, &codeface_bytes);
2164 testing.expect(codeface.* == 0xC0DEFACE);
2164 try testing.expect(codeface.* == 0xC0DEFACE);
21652165 codeface.* = 0;
21662166 for (codeface_bytes) |b|
2167 testing.expect(b == 0);
2167 try testing.expect(b == 0);
21682168
21692169 const S = packed struct {
21702170 a: u8,
......@@ -2181,7 +2181,7 @@ test "bytesAsValue" {
21812181 };
21822182 const inst_bytes = "\xBE\xEF\xDE\xA1";
21832183 const inst2 = bytesAsValue(S, inst_bytes);
2184 testing.expect(meta.eql(inst, inst2.*));
2184 try testing.expect(meta.eql(inst, inst2.*));
21852185}
21862186
21872187test "bytesAsValue preserves pointer attributes" {
......@@ -2192,10 +2192,10 @@ test "bytesAsValue preserves pointer attributes" {
21922192 const in = @typeInfo(@TypeOf(inSlice)).Pointer;
21932193 const out = @typeInfo(@TypeOf(outPtr)).Pointer;
21942194
2195 testing.expectEqual(in.is_const, out.is_const);
2196 testing.expectEqual(in.is_volatile, out.is_volatile);
2197 testing.expectEqual(in.is_allowzero, out.is_allowzero);
2198 testing.expectEqual(in.alignment, out.alignment);
2195 try testing.expectEqual(in.is_const, out.is_const);
2196 try testing.expectEqual(in.is_volatile, out.is_volatile);
2197 try testing.expectEqual(in.is_allowzero, out.is_allowzero);
2198 try testing.expectEqual(in.alignment, out.alignment);
21992199}
22002200
22012201/// Given a pointer to an array of bytes, returns a value of the specified type backed by a
......@@ -2210,7 +2210,7 @@ test "bytesToValue" {
22102210 };
22112211
22122212 const deadbeef = bytesToValue(u32, deadbeef_bytes);
2213 testing.expect(deadbeef == @as(u32, 0xDEADBEEF));
2213 try testing.expect(deadbeef == @as(u32, 0xDEADBEEF));
22142214}
22152215
22162216fn BytesAsSliceReturnType(comptime T: type, comptime bytesType: type) type {
......@@ -2243,17 +2243,17 @@ test "bytesAsSlice" {
22432243 {
22442244 const bytes = [_]u8{ 0xDE, 0xAD, 0xBE, 0xEF };
22452245 const slice = bytesAsSlice(u16, bytes[0..]);
2246 testing.expect(slice.len == 2);
2247 testing.expect(bigToNative(u16, slice[0]) == 0xDEAD);
2248 testing.expect(bigToNative(u16, slice[1]) == 0xBEEF);
2246 try testing.expect(slice.len == 2);
2247 try testing.expect(bigToNative(u16, slice[0]) == 0xDEAD);
2248 try testing.expect(bigToNative(u16, slice[1]) == 0xBEEF);
22492249 }
22502250 {
22512251 const bytes = [_]u8{ 0xDE, 0xAD, 0xBE, 0xEF };
22522252 var runtime_zero: usize = 0;
22532253 const slice = bytesAsSlice(u16, bytes[runtime_zero..]);
2254 testing.expect(slice.len == 2);
2255 testing.expect(bigToNative(u16, slice[0]) == 0xDEAD);
2256 testing.expect(bigToNative(u16, slice[1]) == 0xBEEF);
2254 try testing.expect(slice.len == 2);
2255 try testing.expect(bigToNative(u16, slice[0]) == 0xDEAD);
2256 try testing.expect(bigToNative(u16, slice[1]) == 0xBEEF);
22572257 }
22582258}
22592259
......@@ -2261,13 +2261,13 @@ test "bytesAsSlice keeps pointer alignment" {
22612261 {
22622262 var bytes = [_]u8{ 0x01, 0x02, 0x03, 0x04 };
22632263 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);
22652265 }
22662266 {
22672267 var bytes = [_]u8{ 0x01, 0x02, 0x03, 0x04 };
22682268 var runtime_zero: usize = 0;
22692269 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);
22712271 }
22722272}
22732273
......@@ -2278,7 +2278,7 @@ test "bytesAsSlice on a packed struct" {
22782278
22792279 var b = [1]u8{9};
22802280 var f = bytesAsSlice(F, &b);
2281 testing.expect(f[0].a == 9);
2281 try testing.expect(f[0].a == 9);
22822282}
22832283
22842284test "bytesAsSlice with specified alignment" {
......@@ -2289,7 +2289,7 @@ test "bytesAsSlice with specified alignment" {
22892289 0x33,
22902290 };
22912291 const slice: []u32 = std.mem.bytesAsSlice(u32, bytes[0..]);
2292 testing.expect(slice[0] == 0x33333333);
2292 try testing.expect(slice[0] == 0x33333333);
22932293}
22942294
22952295test "bytesAsSlice preserves pointer attributes" {
......@@ -2300,10 +2300,10 @@ test "bytesAsSlice preserves pointer attributes" {
23002300 const in = @typeInfo(@TypeOf(inSlice)).Pointer;
23012301 const out = @typeInfo(@TypeOf(outSlice)).Pointer;
23022302
2303 testing.expectEqual(in.is_const, out.is_const);
2304 testing.expectEqual(in.is_volatile, out.is_volatile);
2305 testing.expectEqual(in.is_allowzero, out.is_allowzero);
2306 testing.expectEqual(in.alignment, out.alignment);
2303 try testing.expectEqual(in.is_const, out.is_const);
2304 try testing.expectEqual(in.is_volatile, out.is_volatile);
2305 try testing.expectEqual(in.is_allowzero, out.is_allowzero);
2306 try testing.expectEqual(in.alignment, out.alignment);
23072307}
23082308
23092309fn SliceAsBytesReturnType(comptime sliceType: type) type {
......@@ -2332,8 +2332,8 @@ pub fn sliceAsBytes(slice: anytype) SliceAsBytesReturnType(@TypeOf(slice)) {
23322332test "sliceAsBytes" {
23332333 const bytes = [_]u16{ 0xDEAD, 0xBEEF };
23342334 const slice = sliceAsBytes(bytes[0..]);
2335 testing.expect(slice.len == 4);
2336 testing.expect(eql(u8, slice, switch (builtin.endian) {
2335 try testing.expect(slice.len == 4);
2336 try testing.expect(eql(u8, slice, switch (builtin.endian) {
23372337 .Big => "\xDE\xAD\xBE\xEF",
23382338 .Little => "\xAD\xDE\xEF\xBE",
23392339 }));
......@@ -2342,7 +2342,7 @@ test "sliceAsBytes" {
23422342test "sliceAsBytes with sentinel slice" {
23432343 const empty_string: [:0]const u8 = "";
23442344 const bytes = sliceAsBytes(empty_string);
2345 testing.expect(bytes.len == 0);
2345 try testing.expect(bytes.len == 0);
23462346}
23472347
23482348test "sliceAsBytes packed struct at runtime and comptime" {
......@@ -2351,49 +2351,49 @@ test "sliceAsBytes packed struct at runtime and comptime" {
23512351 b: u4,
23522352 };
23532353 const S = struct {
2354 fn doTheTest() void {
2354 fn doTheTest() !void {
23552355 var foo: Foo = undefined;
23562356 var slice = sliceAsBytes(@as(*[1]Foo, &foo)[0..1]);
23572357 slice[0] = 0x13;
23582358 switch (builtin.endian) {
23592359 .Big => {
2360 testing.expect(foo.a == 0x1);
2361 testing.expect(foo.b == 0x3);
2360 try testing.expect(foo.a == 0x1);
2361 try testing.expect(foo.b == 0x3);
23622362 },
23632363 .Little => {
2364 testing.expect(foo.a == 0x3);
2365 testing.expect(foo.b == 0x1);
2364 try testing.expect(foo.a == 0x3);
2365 try testing.expect(foo.b == 0x1);
23662366 },
23672367 }
23682368 }
23692369 };
2370 S.doTheTest();
2371 comptime S.doTheTest();
2370 try S.doTheTest();
2371 comptime try S.doTheTest();
23722372}
23732373
23742374test "sliceAsBytes and bytesAsSlice back" {
2375 testing.expect(@sizeOf(i32) == 4);
2375 try testing.expect(@sizeOf(i32) == 4);
23762376
23772377 var big_thing_array = [_]i32{ 1, 2, 3, 4 };
23782378 const big_thing_slice: []i32 = big_thing_array[0..];
23792379
23802380 const bytes = sliceAsBytes(big_thing_slice);
2381 testing.expect(bytes.len == 4 * 4);
2381 try testing.expect(bytes.len == 4 * 4);
23822382
23832383 bytes[4] = 0;
23842384 bytes[5] = 0;
23852385 bytes[6] = 0;
23862386 bytes[7] = 0;
2387 testing.expect(big_thing_slice[1] == 0);
2387 try testing.expect(big_thing_slice[1] == 0);
23882388
23892389 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
23922392 big_thing_again[2] = -1;
2393 testing.expect(bytes[8] == math.maxInt(u8));
2394 testing.expect(bytes[9] == math.maxInt(u8));
2395 testing.expect(bytes[10] == math.maxInt(u8));
2396 testing.expect(bytes[11] == math.maxInt(u8));
2393 try testing.expect(bytes[8] == math.maxInt(u8));
2394 try testing.expect(bytes[9] == math.maxInt(u8));
2395 try testing.expect(bytes[10] == math.maxInt(u8));
2396 try testing.expect(bytes[11] == math.maxInt(u8));
23972397}
23982398
23992399test "sliceAsBytes preserves pointer attributes" {
......@@ -2404,10 +2404,10 @@ test "sliceAsBytes preserves pointer attributes" {
24042404 const in = @typeInfo(@TypeOf(inSlice)).Pointer;
24052405 const out = @typeInfo(@TypeOf(outSlice)).Pointer;
24062406
2407 testing.expectEqual(in.is_const, out.is_const);
2408 testing.expectEqual(in.is_volatile, out.is_volatile);
2409 testing.expectEqual(in.is_allowzero, out.is_allowzero);
2410 testing.expectEqual(in.alignment, out.alignment);
2407 try testing.expectEqual(in.is_const, out.is_const);
2408 try testing.expectEqual(in.is_volatile, out.is_volatile);
2409 try testing.expectEqual(in.is_allowzero, out.is_allowzero);
2410 try testing.expectEqual(in.alignment, out.alignment);
24112411}
24122412
24132413/// Round an address up to the nearest aligned address
......@@ -2434,18 +2434,18 @@ pub fn doNotOptimizeAway(val: anytype) void {
24342434}
24352435
24362436test "alignForward" {
2437 testing.expect(alignForward(1, 1) == 1);
2438 testing.expect(alignForward(2, 1) == 2);
2439 testing.expect(alignForward(1, 2) == 2);
2440 testing.expect(alignForward(2, 2) == 2);
2441 testing.expect(alignForward(3, 2) == 4);
2442 testing.expect(alignForward(4, 2) == 4);
2443 testing.expect(alignForward(7, 8) == 8);
2444 testing.expect(alignForward(8, 8) == 8);
2445 testing.expect(alignForward(9, 8) == 16);
2446 testing.expect(alignForward(15, 8) == 16);
2447 testing.expect(alignForward(16, 8) == 16);
2448 testing.expect(alignForward(17, 8) == 24);
2437 try testing.expect(alignForward(1, 1) == 1);
2438 try testing.expect(alignForward(2, 1) == 2);
2439 try testing.expect(alignForward(1, 2) == 2);
2440 try testing.expect(alignForward(2, 2) == 2);
2441 try testing.expect(alignForward(3, 2) == 4);
2442 try testing.expect(alignForward(4, 2) == 4);
2443 try testing.expect(alignForward(7, 8) == 8);
2444 try testing.expect(alignForward(8, 8) == 8);
2445 try testing.expect(alignForward(9, 8) == 16);
2446 try testing.expect(alignForward(15, 8) == 16);
2447 try testing.expect(alignForward(16, 8) == 16);
2448 try testing.expect(alignForward(17, 8) == 24);
24492449}
24502450
24512451/// Round an address up to the previous aligned address
......@@ -2497,19 +2497,19 @@ pub fn isAlignedGeneric(comptime T: type, addr: T, alignment: T) bool {
24972497}
24982498
24992499test "isAligned" {
2500 testing.expect(isAligned(0, 4));
2501 testing.expect(isAligned(1, 1));
2502 testing.expect(isAligned(2, 1));
2503 testing.expect(isAligned(2, 2));
2504 testing.expect(!isAligned(2, 4));
2505 testing.expect(isAligned(3, 1));
2506 testing.expect(!isAligned(3, 2));
2507 testing.expect(!isAligned(3, 4));
2508 testing.expect(isAligned(4, 4));
2509 testing.expect(isAligned(4, 2));
2510 testing.expect(isAligned(4, 1));
2511 testing.expect(!isAligned(4, 8));
2512 testing.expect(!isAligned(4, 16));
2500 try testing.expect(isAligned(0, 4));
2501 try testing.expect(isAligned(1, 1));
2502 try testing.expect(isAligned(2, 1));
2503 try testing.expect(isAligned(2, 2));
2504 try testing.expect(!isAligned(2, 4));
2505 try testing.expect(isAligned(3, 1));
2506 try testing.expect(!isAligned(3, 2));
2507 try testing.expect(!isAligned(3, 4));
2508 try testing.expect(isAligned(4, 4));
2509 try testing.expect(isAligned(4, 2));
2510 try testing.expect(isAligned(4, 1));
2511 try testing.expect(!isAligned(4, 8));
2512 try testing.expect(!isAligned(4, 16));
25132513}
25142514
25152515test "freeing empty string with null-terminated sentinel" {
lib/std/meta.zig+190-190
......@@ -47,16 +47,16 @@ test "std.meta.tagName" {
4747 var u2a = U2{ .C = 0 };
4848 var u2b = U2{ .D = 0 };
4949
50 testing.expect(mem.eql(u8, tagName(E1.A), "A"));
51 testing.expect(mem.eql(u8, tagName(E1.B), "B"));
52 testing.expect(mem.eql(u8, tagName(E2.C), "C"));
53 testing.expect(mem.eql(u8, tagName(E2.D), "D"));
54 testing.expect(mem.eql(u8, tagName(error.E), "E"));
55 testing.expect(mem.eql(u8, tagName(error.F), "F"));
56 testing.expect(mem.eql(u8, tagName(u1g), "G"));
57 testing.expect(mem.eql(u8, tagName(u1h), "H"));
58 testing.expect(mem.eql(u8, tagName(u2a), "C"));
59 testing.expect(mem.eql(u8, tagName(u2b), "D"));
50 try testing.expect(mem.eql(u8, tagName(E1.A), "A"));
51 try testing.expect(mem.eql(u8, tagName(E1.B), "B"));
52 try testing.expect(mem.eql(u8, tagName(E2.C), "C"));
53 try testing.expect(mem.eql(u8, tagName(E2.D), "D"));
54 try testing.expect(mem.eql(u8, tagName(error.E), "E"));
55 try testing.expect(mem.eql(u8, tagName(error.F), "F"));
56 try testing.expect(mem.eql(u8, tagName(u1g), "G"));
57 try testing.expect(mem.eql(u8, tagName(u1h), "H"));
58 try testing.expect(mem.eql(u8, tagName(u2a), "C"));
59 try testing.expect(mem.eql(u8, tagName(u2b), "D"));
6060}
6161
6262pub fn stringToEnum(comptime T: type, str: []const u8) ?T {
......@@ -98,9 +98,9 @@ test "std.meta.stringToEnum" {
9898 A,
9999 B,
100100 };
101 testing.expect(E1.A == stringToEnum(E1, "A").?);
102 testing.expect(E1.B == stringToEnum(E1, "B").?);
103 testing.expect(null == stringToEnum(E1, "C"));
101 try testing.expect(E1.A == stringToEnum(E1, "A").?);
102 try testing.expect(E1.B == stringToEnum(E1, "B").?);
103 try testing.expect(null == stringToEnum(E1, "C"));
104104}
105105
106106pub fn bitCount(comptime T: type) comptime_int {
......@@ -113,8 +113,8 @@ pub fn bitCount(comptime T: type) comptime_int {
113113}
114114
115115test "std.meta.bitCount" {
116 testing.expect(bitCount(u8) == 8);
117 testing.expect(bitCount(f32) == 32);
116 try testing.expect(bitCount(u8) == 8);
117 try testing.expect(bitCount(f32) == 32);
118118}
119119
120120/// Returns the alignment of type T.
......@@ -135,13 +135,13 @@ pub fn alignment(comptime T: type) comptime_int {
135135}
136136
137137test "std.meta.alignment" {
138 testing.expect(alignment(u8) == 1);
139 testing.expect(alignment(*align(1) u8) == 1);
140 testing.expect(alignment(*align(2) u8) == 2);
141 testing.expect(alignment([]align(1) u8) == 1);
142 testing.expect(alignment([]align(2) u8) == 2);
143 testing.expect(alignment(fn () void) > 0);
144 testing.expect(alignment(fn () align(128) void) == 128);
138 try testing.expect(alignment(u8) == 1);
139 try testing.expect(alignment(*align(1) u8) == 1);
140 try testing.expect(alignment(*align(2) u8) == 2);
141 try testing.expect(alignment([]align(1) u8) == 1);
142 try testing.expect(alignment([]align(2) u8) == 2);
143 try testing.expect(alignment(fn () void) > 0);
144 try testing.expect(alignment(fn () align(128) void) == 128);
145145}
146146
147147pub fn Child(comptime T: type) type {
......@@ -155,11 +155,11 @@ pub fn Child(comptime T: type) type {
155155}
156156
157157test "std.meta.Child" {
158 testing.expect(Child([1]u8) == u8);
159 testing.expect(Child(*u8) == u8);
160 testing.expect(Child([]u8) == u8);
161 testing.expect(Child(?u8) == u8);
162 testing.expect(Child(Vector(2, u8)) == u8);
158 try testing.expect(Child([1]u8) == u8);
159 try testing.expect(Child(*u8) == u8);
160 try testing.expect(Child([]u8) == u8);
161 try testing.expect(Child(?u8) == u8);
162 try testing.expect(Child(Vector(2, u8)) == u8);
163163}
164164
165165/// Given a "memory span" type, returns the "element type".
......@@ -188,13 +188,13 @@ pub fn Elem(comptime T: type) type {
188188}
189189
190190test "std.meta.Elem" {
191 testing.expect(Elem([1]u8) == u8);
192 testing.expect(Elem([*]u8) == u8);
193 testing.expect(Elem([]u8) == u8);
194 testing.expect(Elem(*[10]u8) == u8);
195 testing.expect(Elem(Vector(2, u8)) == u8);
196 testing.expect(Elem(*Vector(2, u8)) == u8);
197 testing.expect(Elem(?[*]u8) == u8);
191 try testing.expect(Elem([1]u8) == u8);
192 try testing.expect(Elem([*]u8) == u8);
193 try testing.expect(Elem([]u8) == u8);
194 try testing.expect(Elem(*[10]u8) == u8);
195 try testing.expect(Elem(Vector(2, u8)) == u8);
196 try testing.expect(Elem(*Vector(2, u8)) == u8);
197 try testing.expect(Elem(?[*]u8) == u8);
198198}
199199
200200/// 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) {
219219}
220220
221221test "std.meta.sentinel" {
222 testSentinel();
223 comptime testSentinel();
222 try testSentinel();
223 comptime try testSentinel();
224224}
225225
226fn testSentinel() void {
227 testing.expectEqual(@as(u8, 0), sentinel([:0]u8).?);
228 testing.expectEqual(@as(u8, 0), sentinel([*:0]u8).?);
229 testing.expectEqual(@as(u8, 0), sentinel([5:0]u8).?);
230 testing.expectEqual(@as(u8, 0), sentinel(*const [5:0]u8).?);
226fn testSentinel() !void {
227 try testing.expectEqual(@as(u8, 0), sentinel([:0]u8).?);
228 try testing.expectEqual(@as(u8, 0), sentinel([*:0]u8).?);
229 try testing.expectEqual(@as(u8, 0), sentinel([5:0]u8).?);
230 try testing.expectEqual(@as(u8, 0), sentinel(*const [5:0]u8).?);
231231
232 testing.expect(sentinel([]u8) == null);
233 testing.expect(sentinel([*]u8) == null);
234 testing.expect(sentinel([5]u8) == null);
235 testing.expect(sentinel(*const [5]u8) == null);
232 try testing.expect(sentinel([]u8) == null);
233 try testing.expect(sentinel([*]u8) == null);
234 try testing.expect(sentinel([5]u8) == null);
235 try testing.expect(sentinel(*const [5]u8) == null);
236236}
237237
238238/// 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
322322}
323323
324324test "std.meta.assumeSentinel" {
325 testing.expect([*:0]u8 == @TypeOf(assumeSentinel(@as([*]u8, undefined), 0)));
326 testing.expect([:0]u8 == @TypeOf(assumeSentinel(@as([]u8, undefined), 0)));
327 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)));
329 testing.expect([*:0]u16 == @TypeOf(assumeSentinel(@as([*]u16, undefined), 0)));
330 testing.expect([:0]const u16 == @TypeOf(assumeSentinel(@as([]const u16, undefined), 0)));
331 testing.expect([*:3]u8 == @TypeOf(assumeSentinel(@as([*:1]u8, undefined), 3)));
332 testing.expect([:null]?[*]u8 == @TypeOf(assumeSentinel(@as([]?[*]u8, undefined), null)));
333 testing.expect([*:null]?[*]u8 == @TypeOf(assumeSentinel(@as([*]?[*]u8, undefined), null)));
334 testing.expect(*[10:0]u8 == @TypeOf(assumeSentinel(@as(*[10]u8, undefined), 0)));
335 testing.expect(?[*:0]u8 == @TypeOf(assumeSentinel(@as(?[*]u8, undefined), 0)));
325 try testing.expect([*:0]u8 == @TypeOf(assumeSentinel(@as([*]u8, undefined), 0)));
326 try testing.expect([:0]u8 == @TypeOf(assumeSentinel(@as([]u8, undefined), 0)));
327 try 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 try testing.expect([*:0]u16 == @TypeOf(assumeSentinel(@as([*]u16, undefined), 0)));
330 try testing.expect([:0]const u16 == @TypeOf(assumeSentinel(@as([]const u16, undefined), 0)));
331 try testing.expect([*:3]u8 == @TypeOf(assumeSentinel(@as([*:1]u8, undefined), 3)));
332 try testing.expect([:null]?[*]u8 == @TypeOf(assumeSentinel(@as([]?[*]u8, undefined), null)));
333 try testing.expect([*:null]?[*]u8 == @TypeOf(assumeSentinel(@as([*]?[*]u8, undefined), null)));
334 try testing.expect(*[10:0]u8 == @TypeOf(assumeSentinel(@as(*[10]u8, undefined), 0)));
335 try testing.expect(?[*:0]u8 == @TypeOf(assumeSentinel(@as(?[*]u8, undefined), 0)));
336336}
337337
338338pub fn containerLayout(comptime T: type) TypeInfo.ContainerLayout {
......@@ -367,15 +367,15 @@ test "std.meta.containerLayout" {
367367 a: u8,
368368 };
369369
370 testing.expect(containerLayout(E1) == .Auto);
371 testing.expect(containerLayout(E2) == .Packed);
372 testing.expect(containerLayout(E3) == .Extern);
373 testing.expect(containerLayout(S1) == .Auto);
374 testing.expect(containerLayout(S2) == .Packed);
375 testing.expect(containerLayout(S3) == .Extern);
376 testing.expect(containerLayout(U1) == .Auto);
377 testing.expect(containerLayout(U2) == .Packed);
378 testing.expect(containerLayout(U3) == .Extern);
370 try testing.expect(containerLayout(E1) == .Auto);
371 try testing.expect(containerLayout(E2) == .Packed);
372 try testing.expect(containerLayout(E3) == .Extern);
373 try testing.expect(containerLayout(S1) == .Auto);
374 try testing.expect(containerLayout(S2) == .Packed);
375 try testing.expect(containerLayout(S3) == .Extern);
376 try testing.expect(containerLayout(U1) == .Auto);
377 try testing.expect(containerLayout(U2) == .Packed);
378 try testing.expect(containerLayout(U3) == .Extern);
379379}
380380
381381pub fn declarations(comptime T: type) []const TypeInfo.Declaration {
......@@ -414,8 +414,8 @@ test "std.meta.declarations" {
414414 };
415415
416416 inline for (decls) |decl| {
417 testing.expect(decl.len == 1);
418 testing.expect(comptime mem.eql(u8, decl[0].name, "a"));
417 try testing.expect(decl.len == 1);
418 try testing.expect(comptime mem.eql(u8, decl[0].name, "a"));
419419 }
420420}
421421
......@@ -450,8 +450,8 @@ test "std.meta.declarationInfo" {
450450 };
451451
452452 inline for (infos) |info| {
453 testing.expect(comptime mem.eql(u8, info.name, "a"));
454 testing.expect(!info.is_pub);
453 try testing.expect(comptime mem.eql(u8, info.name, "a"));
454 try testing.expect(!info.is_pub);
455455 }
456456}
457457
......@@ -488,16 +488,16 @@ test "std.meta.fields" {
488488 const sf = comptime fields(S1);
489489 const uf = comptime fields(U1);
490490
491 testing.expect(e1f.len == 1);
492 testing.expect(e2f.len == 1);
493 testing.expect(sf.len == 1);
494 testing.expect(uf.len == 1);
495 testing.expect(mem.eql(u8, e1f[0].name, "A"));
496 testing.expect(mem.eql(u8, e2f[0].name, "A"));
497 testing.expect(mem.eql(u8, sf[0].name, "a"));
498 testing.expect(mem.eql(u8, uf[0].name, "a"));
499 testing.expect(comptime sf[0].field_type == u8);
500 testing.expect(comptime uf[0].field_type == u8);
491 try testing.expect(e1f.len == 1);
492 try testing.expect(e2f.len == 1);
493 try testing.expect(sf.len == 1);
494 try testing.expect(uf.len == 1);
495 try testing.expect(mem.eql(u8, e1f[0].name, "A"));
496 try testing.expect(mem.eql(u8, e2f[0].name, "A"));
497 try testing.expect(mem.eql(u8, sf[0].name, "a"));
498 try testing.expect(mem.eql(u8, uf[0].name, "a"));
499 try testing.expect(comptime sf[0].field_type == u8);
500 try testing.expect(comptime uf[0].field_type == u8);
501501}
502502
503503pub fn fieldInfo(comptime T: type, comptime field: FieldEnum(T)) switch (@typeInfo(T)) {
......@@ -527,12 +527,12 @@ test "std.meta.fieldInfo" {
527527 const sf = fieldInfo(S1, .a);
528528 const uf = fieldInfo(U1, .a);
529529
530 testing.expect(mem.eql(u8, e1f.name, "A"));
531 testing.expect(mem.eql(u8, e2f.name, "A"));
532 testing.expect(mem.eql(u8, sf.name, "a"));
533 testing.expect(mem.eql(u8, uf.name, "a"));
534 testing.expect(comptime sf.field_type == u8);
535 testing.expect(comptime uf.field_type == u8);
530 try testing.expect(mem.eql(u8, e1f.name, "A"));
531 try testing.expect(mem.eql(u8, e2f.name, "A"));
532 try testing.expect(mem.eql(u8, sf.name, "a"));
533 try testing.expect(mem.eql(u8, uf.name, "a"));
534 try testing.expect(comptime sf.field_type == u8);
535 try testing.expect(comptime uf.field_type == u8);
536536}
537537
538538pub fn fieldNames(comptime T: type) *const [fields(T).len][]const u8 {
......@@ -562,16 +562,16 @@ test "std.meta.fieldNames" {
562562 const s1names = fieldNames(S1);
563563 const u1names = fieldNames(U1);
564564
565 testing.expect(e1names.len == 2);
566 testing.expectEqualSlices(u8, e1names[0], "A");
567 testing.expectEqualSlices(u8, e1names[1], "B");
568 testing.expect(e2names.len == 1);
569 testing.expectEqualSlices(u8, e2names[0], "A");
570 testing.expect(s1names.len == 1);
571 testing.expectEqualSlices(u8, s1names[0], "a");
572 testing.expect(u1names.len == 2);
573 testing.expectEqualSlices(u8, u1names[0], "a");
574 testing.expectEqualSlices(u8, u1names[1], "b");
565 try testing.expect(e1names.len == 2);
566 try testing.expectEqualSlices(u8, e1names[0], "A");
567 try testing.expectEqualSlices(u8, e1names[1], "B");
568 try testing.expect(e2names.len == 1);
569 try testing.expectEqualSlices(u8, e2names[0], "A");
570 try testing.expect(s1names.len == 1);
571 try testing.expectEqualSlices(u8, s1names[0], "a");
572 try testing.expect(u1names.len == 2);
573 try testing.expectEqualSlices(u8, u1names[0], "a");
574 try testing.expectEqualSlices(u8, u1names[1], "b");
575575}
576576
577577pub fn FieldEnum(comptime T: type) type {
......@@ -595,20 +595,20 @@ pub fn FieldEnum(comptime T: type) type {
595595 });
596596}
597597
598fn expectEqualEnum(expected: anytype, actual: @TypeOf(expected)) void {
598fn expectEqualEnum(expected: anytype, actual: @TypeOf(expected)) !void {
599599 // TODO: https://github.com/ziglang/zig/issues/7419
600600 // testing.expectEqual(@typeInfo(expected).Enum, @typeInfo(actual).Enum);
601 testing.expectEqual(@typeInfo(expected).Enum.layout, @typeInfo(actual).Enum.layout);
602 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);
604 comptime 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);
601 try testing.expectEqual(@typeInfo(expected).Enum.layout, @typeInfo(actual).Enum.layout);
602 try testing.expectEqual(@typeInfo(expected).Enum.tag_type, @typeInfo(actual).Enum.tag_type);
603 comptime try testing.expectEqualSlices(std.builtin.TypeInfo.EnumField, @typeInfo(expected).Enum.fields, @typeInfo(actual).Enum.fields);
604 comptime try testing.expectEqualSlices(std.builtin.TypeInfo.Declaration, @typeInfo(expected).Enum.decls, @typeInfo(actual).Enum.decls);
605 try testing.expectEqual(@typeInfo(expected).Enum.is_exhaustive, @typeInfo(actual).Enum.is_exhaustive);
606606}
607607
608608test "std.meta.FieldEnum" {
609 expectEqualEnum(enum { a }, FieldEnum(struct { a: u8 }));
610 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 }));
609 try expectEqualEnum(enum { a }, FieldEnum(struct { a: u8 }));
610 try expectEqualEnum(enum { a, b, c }, FieldEnum(struct { a: u8, b: void, c: f32 }));
611 try expectEqualEnum(enum { a, b, c }, FieldEnum(union { a: u8, b: void, c: f32 }));
612612}
613613
614614// Deprecated: use Tag
......@@ -632,8 +632,8 @@ test "std.meta.Tag" {
632632 D: u16,
633633 };
634634
635 testing.expect(Tag(E) == u8);
636 testing.expect(Tag(U) == E);
635 try testing.expect(Tag(E) == u8);
636 try testing.expect(Tag(U) == E);
637637}
638638
639639///Returns the active tag of a tagged union
......@@ -654,10 +654,10 @@ test "std.meta.activeTag" {
654654 };
655655
656656 var u = U{ .Int = 32 };
657 testing.expect(activeTag(u) == UE.Int);
657 try testing.expect(activeTag(u) == UE.Int);
658658
659659 u = U{ .Float = 112.9876 };
660 testing.expect(activeTag(u) == UE.Float);
660 try testing.expect(activeTag(u) == UE.Float);
661661}
662662
663663const TagPayloadType = TagPayload;
......@@ -665,7 +665,7 @@ const TagPayloadType = TagPayload;
665665///Given a tagged union type, and an enum, return the type of the union
666666/// field corresponding to the enum tag.
667667pub 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
670670 const info = @typeInfo(U).Union;
671671 const tag_info = @typeInfo(Tag(U)).Enum;
......@@ -687,7 +687,7 @@ test "std.meta.TagPayload" {
687687 };
688688 const MovedEvent = TagPayload(Event, Event.Moved);
689689 var e: Event = undefined;
690 testing.expect(MovedEvent == @TypeOf(e.Moved));
690 try testing.expect(MovedEvent == @TypeOf(e.Moved));
691691}
692692
693693/// Compares two of any type for equality. Containers are compared on a field-by-field basis,
......@@ -787,19 +787,19 @@ test "std.meta.eql" {
787787 const u_2 = U{ .s = s_1 };
788788 const u_3 = U{ .f = 24 };
789789
790 testing.expect(eql(s_1, s_3));
791 testing.expect(eql(&s_1, &s_1));
792 testing.expect(!eql(&s_1, &s_3));
793 testing.expect(eql(u_1, u_3));
794 testing.expect(!eql(u_1, u_2));
790 try testing.expect(eql(s_1, s_3));
791 try testing.expect(eql(&s_1, &s_1));
792 try testing.expect(!eql(&s_1, &s_3));
793 try testing.expect(eql(u_1, u_3));
794 try testing.expect(!eql(u_1, u_2));
795795
796796 var a1 = "abcdef".*;
797797 var a2 = "abcdef".*;
798798 var a3 = "ghijkl".*;
799799
800 testing.expect(eql(a1, a2));
801 testing.expect(!eql(a1, a3));
802 testing.expect(!eql(a1[0..], a2[0..]));
800 try testing.expect(eql(a1, a2));
801 try testing.expect(!eql(a1, a3));
802 try testing.expect(!eql(a1[0..], a2[0..]));
803803
804804 const EU = struct {
805805 fn tst(err: bool) !u8 {
......@@ -808,16 +808,16 @@ test "std.meta.eql" {
808808 }
809809 };
810810
811 testing.expect(eql(EU.tst(true), EU.tst(true)));
812 testing.expect(eql(EU.tst(false), EU.tst(false)));
813 testing.expect(!eql(EU.tst(false), EU.tst(true)));
811 try testing.expect(eql(EU.tst(true), EU.tst(true)));
812 try testing.expect(eql(EU.tst(false), EU.tst(false)));
813 try testing.expect(!eql(EU.tst(false), EU.tst(true)));
814814
815815 var v1 = @splat(4, @as(u32, 1));
816816 var v2 = @splat(4, @as(u32, 1));
817817 var v3 = @splat(4, @as(u32, 2));
818818
819 testing.expect(eql(v1, v2));
820 testing.expect(!eql(v1, v3));
819 try testing.expect(eql(v1, v2));
820 try testing.expect(!eql(v1, v3));
821821}
822822
823823test "intToEnum with error return" {
......@@ -831,9 +831,9 @@ test "intToEnum with error return" {
831831
832832 var zero: u8 = 0;
833833 var one: u16 = 1;
834 testing.expect(intToEnum(E1, zero) catch unreachable == E1.A);
835 testing.expect(intToEnum(E2, one) catch unreachable == E2.B);
836 testing.expectError(error.InvalidEnumTag, intToEnum(E1, one));
834 try testing.expect(intToEnum(E1, zero) catch unreachable == E1.A);
835 try testing.expect(intToEnum(E2, one) catch unreachable == E2.B);
836 try testing.expectError(error.InvalidEnumTag, intToEnum(E1, one));
837837}
838838
839839pub const IntToEnumError = error{InvalidEnumTag};
......@@ -1008,27 +1008,27 @@ test "std.meta.cast" {
10081008
10091009 var i = @as(i64, 10);
10101010
1011 testing.expect(cast(*u8, 16) == @intToPtr(*u8, 16));
1012 testing.expect(cast(*u64, &i).* == @as(u64, 10));
1013 testing.expect(cast(*i64, @as(?*align(1) i64, &i)) == &i);
1011 try testing.expect(cast(*u8, 16) == @intToPtr(*u8, 16));
1012 try testing.expect(cast(*u64, &i).* == @as(u64, 10));
1013 try testing.expect(cast(*i64, @as(?*align(1) i64, &i)) == &i);
10141014
1015 testing.expect(cast(?*u8, 2) == @intToPtr(*u8, 2));
1016 testing.expect(cast(?*i64, @as(*align(1) i64, &i)) == &i);
1017 testing.expect(cast(?*i64, @as(?*align(1) i64, &i)) == &i);
1015 try testing.expect(cast(?*u8, 2) == @intToPtr(*u8, 2));
1016 try 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)));
1022 testing.expectEqual(@as(u32, 4), cast(u32, @intToPtr(?*u32, 4)));
1023 testing.expectEqual(@as(u32, 10), cast(u32, @as(u64, 10)));
1024 testing.expectEqual(@as(u8, 2), cast(u8, E.Two));
1021 try testing.expectEqual(@as(u32, 4), cast(u32, @intToPtr(*u32, 4)));
1022 try testing.expectEqual(@as(u32, 4), cast(u32, @intToPtr(?*u32, 4)));
1023 try testing.expectEqual(@as(u32, 10), cast(u32, @as(u64, 10)));
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)));
1029 testing.expectEqual(@intToPtr(*u8, 2), cast(*u8, @intToPtr(*volatile u8, 2)));
1028 try testing.expectEqual(@intToPtr(*u8, 2), cast(*u8, @intToPtr(*const 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
10331033 const C_ENUM = extern enum(c_int) {
10341034 A = 0,
......@@ -1036,10 +1036,10 @@ test "std.meta.cast" {
10361036 C,
10371037 _,
10381038 };
1039 testing.expectEqual(cast(C_ENUM, @as(i64, -1)), @intToEnum(C_ENUM, -1));
1040 testing.expectEqual(cast(C_ENUM, @as(i8, 1)), .B);
1041 testing.expectEqual(cast(C_ENUM, @as(u64, 1)), .B);
1042 testing.expectEqual(cast(C_ENUM, @as(u64, 42)), @intToEnum(C_ENUM, 42));
1039 try testing.expectEqual(cast(C_ENUM, @as(i64, -1)), @intToEnum(C_ENUM, -1));
1040 try testing.expectEqual(cast(C_ENUM, @as(i8, 1)), .B);
1041 try testing.expectEqual(cast(C_ENUM, @as(u64, 1)), .B);
1042 try testing.expectEqual(cast(C_ENUM, @as(u64, 42)), @intToEnum(C_ENUM, 42));
10431043}
10441044
10451045/// Given a value returns its size as C's sizeof operator would.
......@@ -1118,43 +1118,43 @@ test "sizeof" {
11181118
11191119 const ptr_size = @sizeOf(*c_void);
11201120
1121 testing.expect(sizeof(u32) == 4);
1122 testing.expect(sizeof(@as(u32, 2)) == 4);
1123 testing.expect(sizeof(2) == @sizeOf(c_int));
1121 try testing.expect(sizeof(u32) == 4);
1122 try testing.expect(sizeof(@as(u32, 2)) == 4);
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));
1128 testing.expect(sizeof(E.One) == @sizeOf(c_int));
1127 try testing.expect(sizeof(E) == @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);
1133 testing.expect(sizeof([3]u32) == 12);
1134 testing.expect(sizeof([3:0]u32) == 16);
1135 testing.expect(sizeof(&[_]u32{ 4, 5, 6 }) == ptr_size);
1132 try testing.expect(sizeof([_]u32{ 4, 5, 6 }) == 12);
1133 try testing.expect(sizeof([3]u32) == 12);
1134 try testing.expect(sizeof([3:0]u32) == 16);
1135 try testing.expect(sizeof(&[_]u32{ 4, 5, 6 }) == ptr_size);
11361136
1137 testing.expect(sizeof(*u32) == ptr_size);
1138 testing.expect(sizeof([*]u32) == ptr_size);
1139 testing.expect(sizeof([*c]u32) == ptr_size);
1140 testing.expect(sizeof(?*u32) == ptr_size);
1141 testing.expect(sizeof(?[*]u32) == ptr_size);
1142 testing.expect(sizeof(*c_void) == ptr_size);
1143 testing.expect(sizeof(*void) == ptr_size);
1144 testing.expect(sizeof(null) == ptr_size);
1137 try testing.expect(sizeof(*u32) == ptr_size);
1138 try testing.expect(sizeof([*]u32) == ptr_size);
1139 try testing.expect(sizeof([*c]u32) == ptr_size);
1140 try testing.expect(sizeof(?*u32) == ptr_size);
1141 try testing.expect(sizeof(?[*]u32) == ptr_size);
1142 try testing.expect(sizeof(*c_void) == ptr_size);
1143 try testing.expect(sizeof(*void) == ptr_size);
1144 try testing.expect(sizeof(null) == ptr_size);
11451145
1146 testing.expect(sizeof("foobar") == 7);
1147 testing.expect(sizeof(&[_:0]u16{ 'f', 'o', 'o', 'b', 'a', 'r' }) == 14);
1148 testing.expect(sizeof(*const [4:0]u8) == 5);
1149 testing.expect(sizeof(*[4:0]u8) == ptr_size);
1150 testing.expect(sizeof([*]const [4:0]u8) == ptr_size);
1151 testing.expect(sizeof(*const *const [4:0]u8) == ptr_size);
1152 testing.expect(sizeof(*const [4]u8) == ptr_size);
1146 try testing.expect(sizeof("foobar") == 7);
1147 try testing.expect(sizeof(&[_:0]u16{ 'f', 'o', 'o', 'b', 'a', 'r' }) == 14);
1148 try testing.expect(sizeof(*const [4:0]u8) == 5);
1149 try testing.expect(sizeof(*[4:0]u8) == ptr_size);
1150 try testing.expect(sizeof([*]const [4:0]u8) == ptr_size);
1151 try testing.expect(sizeof(*const *const [4:0]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);
1157 testing.expect(sizeof(c_void) == 1);
1156 try testing.expect(sizeof(void) == 1);
1157 try testing.expect(sizeof(c_void) == 1);
11581158}
11591159
11601160pub const CIntLiteralRadix = enum { decimal, octal, hexadecimal };
......@@ -1193,7 +1193,7 @@ pub fn promoteIntLiteral(
11931193
11941194test "promoteIntLiteral" {
11951195 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
11981198 if (math.maxInt(c_longlong) == math.maxInt(c_int)) return;
11991199
......@@ -1201,11 +1201,11 @@ test "promoteIntLiteral" {
12011201 const unsigned = promoteIntLiteral(c_uint, math.maxInt(c_uint) + 1, .hexadecimal);
12021202
12031203 if (math.maxInt(c_long) > math.maxInt(c_int)) {
1204 testing.expectEqual(c_long, @TypeOf(signed_decimal));
1205 testing.expectEqual(c_ulong, @TypeOf(unsigned));
1204 try testing.expectEqual(c_long, @TypeOf(signed_decimal));
1205 try testing.expectEqual(c_ulong, @TypeOf(unsigned));
12061206 } else {
1207 testing.expectEqual(c_longlong, @TypeOf(signed_decimal));
1208 testing.expectEqual(c_ulonglong, @TypeOf(unsigned));
1207 try testing.expectEqual(c_longlong, @TypeOf(signed_decimal));
1208 try testing.expectEqual(c_ulonglong, @TypeOf(unsigned));
12091209 }
12101210}
12111211
......@@ -1347,17 +1347,17 @@ pub fn shuffleVectorIndex(comptime this_index: c_int, comptime source_vector_len
13471347test "shuffleVectorIndex" {
13481348 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);
1353 testing.expect(shuffleVectorIndex(1, vector_len) == 1);
1354 testing.expect(shuffleVectorIndex(2, vector_len) == 2);
1355 testing.expect(shuffleVectorIndex(3, vector_len) == 3);
1352 try testing.expect(shuffleVectorIndex(0, vector_len) == 0);
1353 try testing.expect(shuffleVectorIndex(1, vector_len) == 1);
1354 try testing.expect(shuffleVectorIndex(2, vector_len) == 2);
1355 try testing.expect(shuffleVectorIndex(3, vector_len) == 3);
13561356
1357 testing.expect(shuffleVectorIndex(4, vector_len) == -1);
1358 testing.expect(shuffleVectorIndex(5, vector_len) == -2);
1359 testing.expect(shuffleVectorIndex(6, vector_len) == -3);
1360 testing.expect(shuffleVectorIndex(7, vector_len) == -4);
1357 try testing.expect(shuffleVectorIndex(4, vector_len) == -1);
1358 try testing.expect(shuffleVectorIndex(5, vector_len) == -2);
1359 try testing.expect(shuffleVectorIndex(6, vector_len) == -3);
1360 try testing.expect(shuffleVectorIndex(7, vector_len) == -4);
13611361}
13621362
13631363/// Returns whether `error_union` contains an error.
......@@ -1366,6 +1366,6 @@ pub fn isError(error_union: anytype) bool {
13661366}
13671367
13681368test "isError" {
1369 std.testing.expect(isError(math.absInt(@as(i8, -128))));
1370 std.testing.expect(!isError(math.absInt(@as(i8, -127))));
1369 try std.testing.expect(isError(math.absInt(@as(i8, -128))));
1370 try std.testing.expect(!isError(math.absInt(@as(i8, -127))));
13711371}
lib/std/meta/trailer_flags.zig+7-7
......@@ -146,7 +146,7 @@ test "TrailerFlags" {
146146 b: bool,
147147 c: u64,
148148 });
149 testing.expectEqual(u2, meta.Tag(Flags.FieldEnum));
149 try testing.expectEqual(u2, meta.Tag(Flags.FieldEnum));
150150
151151 var flags = Flags.init(.{
152152 .b = true,
......@@ -158,16 +158,16 @@ test "TrailerFlags" {
158158 flags.set(slice.ptr, .b, false);
159159 flags.set(slice.ptr, .c, 12345678);
160160
161 testing.expect(flags.get(slice.ptr, .a) == null);
162 testing.expect(!flags.get(slice.ptr, .b).?);
163 testing.expect(flags.get(slice.ptr, .c).? == 12345678);
161 try testing.expect(flags.get(slice.ptr, .a) == null);
162 try testing.expect(!flags.get(slice.ptr, .b).?);
163 try testing.expect(flags.get(slice.ptr, .c).? == 12345678);
164164
165165 flags.setMany(slice.ptr, .{
166166 .b = true,
167167 .c = 5678,
168168 });
169169
170 testing.expect(flags.get(slice.ptr, .a) == null);
171 testing.expect(flags.get(slice.ptr, .b).?);
172 testing.expect(flags.get(slice.ptr, .c).? == 5678);
170 try testing.expect(flags.get(slice.ptr, .a) == null);
171 try testing.expect(flags.get(slice.ptr, .b).?);
172 try testing.expect(flags.get(slice.ptr, .c).? == 5678);
173173}
lib/std/meta/trait.zig+142-142
......@@ -45,8 +45,8 @@ test "std.meta.trait.multiTrait" {
4545 hasField("x"),
4646 hasField("y"),
4747 });
48 testing.expect(isVector(Vector2));
49 testing.expect(!isVector(u8));
48 try testing.expect(isVector(Vector2));
49 try testing.expect(!isVector(u8));
5050}
5151
5252pub fn hasFn(comptime name: []const u8) TraitFn {
......@@ -66,9 +66,9 @@ test "std.meta.trait.hasFn" {
6666 pub fn useless() void {}
6767 };
6868
69 testing.expect(hasFn("useless")(TestStruct));
70 testing.expect(!hasFn("append")(TestStruct));
71 testing.expect(!hasFn("useless")(u8));
69 try testing.expect(hasFn("useless")(TestStruct));
70 try testing.expect(!hasFn("append")(TestStruct));
71 try testing.expect(!hasFn("useless")(u8));
7272}
7373
7474pub fn hasField(comptime name: []const u8) TraitFn {
......@@ -96,11 +96,11 @@ test "std.meta.trait.hasField" {
9696 value: u32,
9797 };
9898
99 testing.expect(hasField("value")(TestStruct));
100 testing.expect(!hasField("value")(*TestStruct));
101 testing.expect(!hasField("x")(TestStruct));
102 testing.expect(!hasField("x")(**TestStruct));
103 testing.expect(!hasField("value")(u8));
99 try testing.expect(hasField("value")(TestStruct));
100 try testing.expect(!hasField("value")(*TestStruct));
101 try testing.expect(!hasField("x")(TestStruct));
102 try testing.expect(!hasField("x")(**TestStruct));
103 try testing.expect(!hasField("value")(u8));
104104}
105105
106106pub fn is(comptime id: builtin.TypeId) TraitFn {
......@@ -113,11 +113,11 @@ pub fn is(comptime id: builtin.TypeId) TraitFn {
113113}
114114
115115test "std.meta.trait.is" {
116 testing.expect(is(.Int)(u8));
117 testing.expect(!is(.Int)(f32));
118 testing.expect(is(.Pointer)(*u8));
119 testing.expect(is(.Void)(void));
120 testing.expect(!is(.Optional)(anyerror));
116 try testing.expect(is(.Int)(u8));
117 try testing.expect(!is(.Int)(f32));
118 try testing.expect(is(.Pointer)(*u8));
119 try testing.expect(is(.Void)(void));
120 try testing.expect(!is(.Optional)(anyerror));
121121}
122122
123123pub fn isPtrTo(comptime id: builtin.TypeId) TraitFn {
......@@ -131,9 +131,9 @@ pub fn isPtrTo(comptime id: builtin.TypeId) TraitFn {
131131}
132132
133133test "std.meta.trait.isPtrTo" {
134 testing.expect(!isPtrTo(.Struct)(struct {}));
135 testing.expect(isPtrTo(.Struct)(*struct {}));
136 testing.expect(!isPtrTo(.Struct)(**struct {}));
134 try testing.expect(!isPtrTo(.Struct)(struct {}));
135 try testing.expect(isPtrTo(.Struct)(*struct {}));
136 try testing.expect(!isPtrTo(.Struct)(**struct {}));
137137}
138138
139139pub fn isSliceOf(comptime id: builtin.TypeId) TraitFn {
......@@ -147,9 +147,9 @@ pub fn isSliceOf(comptime id: builtin.TypeId) TraitFn {
147147}
148148
149149test "std.meta.trait.isSliceOf" {
150 testing.expect(!isSliceOf(.Struct)(struct {}));
151 testing.expect(isSliceOf(.Struct)([]struct {}));
152 testing.expect(!isSliceOf(.Struct)([][]struct {}));
150 try testing.expect(!isSliceOf(.Struct)(struct {}));
151 try testing.expect(isSliceOf(.Struct)([]struct {}));
152 try testing.expect(!isSliceOf(.Struct)([][]struct {}));
153153}
154154
155155///////////Strait trait Fns
......@@ -170,9 +170,9 @@ test "std.meta.trait.isExtern" {
170170 const TestExStruct = extern struct {};
171171 const TestStruct = struct {};
172172
173 testing.expect(isExtern(TestExStruct));
174 testing.expect(!isExtern(TestStruct));
175 testing.expect(!isExtern(u8));
173 try testing.expect(isExtern(TestExStruct));
174 try testing.expect(!isExtern(TestStruct));
175 try testing.expect(!isExtern(u8));
176176}
177177
178178pub fn isPacked(comptime T: type) bool {
......@@ -188,9 +188,9 @@ test "std.meta.trait.isPacked" {
188188 const TestPStruct = packed struct {};
189189 const TestStruct = struct {};
190190
191 testing.expect(isPacked(TestPStruct));
192 testing.expect(!isPacked(TestStruct));
193 testing.expect(!isPacked(u8));
191 try testing.expect(isPacked(TestPStruct));
192 try testing.expect(!isPacked(TestStruct));
193 try testing.expect(!isPacked(u8));
194194}
195195
196196pub fn isUnsignedInt(comptime T: type) bool {
......@@ -201,10 +201,10 @@ pub fn isUnsignedInt(comptime T: type) bool {
201201}
202202
203203test "isUnsignedInt" {
204 testing.expect(isUnsignedInt(u32) == true);
205 testing.expect(isUnsignedInt(comptime_int) == false);
206 testing.expect(isUnsignedInt(i64) == false);
207 testing.expect(isUnsignedInt(f64) == false);
204 try testing.expect(isUnsignedInt(u32) == true);
205 try testing.expect(isUnsignedInt(comptime_int) == false);
206 try testing.expect(isUnsignedInt(i64) == false);
207 try testing.expect(isUnsignedInt(f64) == false);
208208}
209209
210210pub fn isSignedInt(comptime T: type) bool {
......@@ -216,10 +216,10 @@ pub fn isSignedInt(comptime T: type) bool {
216216}
217217
218218test "isSignedInt" {
219 testing.expect(isSignedInt(u32) == false);
220 testing.expect(isSignedInt(comptime_int) == true);
221 testing.expect(isSignedInt(i64) == true);
222 testing.expect(isSignedInt(f64) == false);
219 try testing.expect(isSignedInt(u32) == false);
220 try testing.expect(isSignedInt(comptime_int) == true);
221 try testing.expect(isSignedInt(i64) == true);
222 try testing.expect(isSignedInt(f64) == false);
223223}
224224
225225pub fn isSingleItemPtr(comptime T: type) bool {
......@@ -231,10 +231,10 @@ pub fn isSingleItemPtr(comptime T: type) bool {
231231
232232test "std.meta.trait.isSingleItemPtr" {
233233 const array = [_]u8{0} ** 10;
234 comptime testing.expect(isSingleItemPtr(@TypeOf(&array[0])));
235 comptime testing.expect(!isSingleItemPtr(@TypeOf(array)));
234 comptime try testing.expect(isSingleItemPtr(@TypeOf(&array[0])));
235 comptime try testing.expect(!isSingleItemPtr(@TypeOf(array)));
236236 var runtime_zero: usize = 0;
237 testing.expect(!isSingleItemPtr(@TypeOf(array[runtime_zero..1])));
237 try testing.expect(!isSingleItemPtr(@TypeOf(array[runtime_zero..1])));
238238}
239239
240240pub fn isManyItemPtr(comptime T: type) bool {
......@@ -247,9 +247,9 @@ pub fn isManyItemPtr(comptime T: type) bool {
247247test "std.meta.trait.isManyItemPtr" {
248248 const array = [_]u8{0} ** 10;
249249 const mip = @ptrCast([*]const u8, &array[0]);
250 testing.expect(isManyItemPtr(@TypeOf(mip)));
251 testing.expect(!isManyItemPtr(@TypeOf(array)));
252 testing.expect(!isManyItemPtr(@TypeOf(array[0..1])));
250 try testing.expect(isManyItemPtr(@TypeOf(mip)));
251 try testing.expect(!isManyItemPtr(@TypeOf(array)));
252 try testing.expect(!isManyItemPtr(@TypeOf(array[0..1])));
253253}
254254
255255pub fn isSlice(comptime T: type) bool {
......@@ -262,9 +262,9 @@ pub fn isSlice(comptime T: type) bool {
262262test "std.meta.trait.isSlice" {
263263 const array = [_]u8{0} ** 10;
264264 var runtime_zero: usize = 0;
265 testing.expect(isSlice(@TypeOf(array[runtime_zero..])));
266 testing.expect(!isSlice(@TypeOf(array)));
267 testing.expect(!isSlice(@TypeOf(&array[0])));
265 try testing.expect(isSlice(@TypeOf(array[runtime_zero..])));
266 try testing.expect(!isSlice(@TypeOf(array)));
267 try testing.expect(!isSlice(@TypeOf(&array[0])));
268268}
269269
270270pub fn isIndexable(comptime T: type) bool {
......@@ -283,12 +283,12 @@ test "std.meta.trait.isIndexable" {
283283 const vector: meta.Vector(2, u32) = [_]u32{0} ** 2;
284284 const tuple = .{ 1, 2, 3 };
285285
286 testing.expect(isIndexable(@TypeOf(array)));
287 testing.expect(isIndexable(@TypeOf(&array)));
288 testing.expect(isIndexable(@TypeOf(slice)));
289 testing.expect(!isIndexable(meta.Child(@TypeOf(slice))));
290 testing.expect(isIndexable(@TypeOf(vector)));
291 testing.expect(isIndexable(@TypeOf(tuple)));
286 try testing.expect(isIndexable(@TypeOf(array)));
287 try testing.expect(isIndexable(@TypeOf(&array)));
288 try testing.expect(isIndexable(@TypeOf(slice)));
289 try testing.expect(!isIndexable(meta.Child(@TypeOf(slice))));
290 try testing.expect(isIndexable(@TypeOf(vector)));
291 try testing.expect(isIndexable(@TypeOf(tuple)));
292292}
293293
294294pub fn isNumber(comptime T: type) bool {
......@@ -317,13 +317,13 @@ test "std.meta.trait.isNumber" {
317317 number: u8,
318318 };
319319
320 testing.expect(isNumber(u32));
321 testing.expect(isNumber(f32));
322 testing.expect(isNumber(u64));
323 testing.expect(isNumber(@TypeOf(102)));
324 testing.expect(isNumber(@TypeOf(102.123)));
325 testing.expect(!isNumber([]u8));
326 testing.expect(!isNumber(NotANumber));
320 try testing.expect(isNumber(u32));
321 try testing.expect(isNumber(f32));
322 try testing.expect(isNumber(u64));
323 try testing.expect(isNumber(@TypeOf(102)));
324 try testing.expect(isNumber(@TypeOf(102.123)));
325 try testing.expect(!isNumber([]u8));
326 try testing.expect(!isNumber(NotANumber));
327327}
328328
329329pub fn isIntegral(comptime T: type) bool {
......@@ -334,12 +334,12 @@ pub fn isIntegral(comptime T: type) bool {
334334}
335335
336336test "isIntegral" {
337 testing.expect(isIntegral(u32));
338 testing.expect(!isIntegral(f32));
339 testing.expect(isIntegral(@TypeOf(102)));
340 testing.expect(!isIntegral(@TypeOf(102.123)));
341 testing.expect(!isIntegral(*u8));
342 testing.expect(!isIntegral([]u8));
337 try testing.expect(isIntegral(u32));
338 try testing.expect(!isIntegral(f32));
339 try testing.expect(isIntegral(@TypeOf(102)));
340 try testing.expect(!isIntegral(@TypeOf(102.123)));
341 try testing.expect(!isIntegral(*u8));
342 try testing.expect(!isIntegral([]u8));
343343}
344344
345345pub fn isFloat(comptime T: type) bool {
......@@ -350,12 +350,12 @@ pub fn isFloat(comptime T: type) bool {
350350}
351351
352352test "isFloat" {
353 testing.expect(!isFloat(u32));
354 testing.expect(isFloat(f32));
355 testing.expect(!isFloat(@TypeOf(102)));
356 testing.expect(isFloat(@TypeOf(102.123)));
357 testing.expect(!isFloat(*f64));
358 testing.expect(!isFloat([]f32));
353 try testing.expect(!isFloat(u32));
354 try testing.expect(isFloat(f32));
355 try testing.expect(!isFloat(@TypeOf(102)));
356 try testing.expect(isFloat(@TypeOf(102.123)));
357 try testing.expect(!isFloat(*f64));
358 try testing.expect(!isFloat([]f32));
359359}
360360
361361pub fn isConstPtr(comptime T: type) bool {
......@@ -366,10 +366,10 @@ pub fn isConstPtr(comptime T: type) bool {
366366test "std.meta.trait.isConstPtr" {
367367 var t = @as(u8, 0);
368368 const c = @as(u8, 0);
369 testing.expect(isConstPtr(*const @TypeOf(t)));
370 testing.expect(isConstPtr(@TypeOf(&c)));
371 testing.expect(!isConstPtr(*@TypeOf(t)));
372 testing.expect(!isConstPtr(@TypeOf(6)));
369 try testing.expect(isConstPtr(*const @TypeOf(t)));
370 try testing.expect(isConstPtr(@TypeOf(&c)));
371 try testing.expect(!isConstPtr(*@TypeOf(t)));
372 try testing.expect(!isConstPtr(@TypeOf(6)));
373373}
374374
375375pub fn isContainer(comptime T: type) bool {
......@@ -389,10 +389,10 @@ test "std.meta.trait.isContainer" {
389389 B,
390390 };
391391
392 testing.expect(isContainer(TestStruct));
393 testing.expect(isContainer(TestUnion));
394 testing.expect(isContainer(TestEnum));
395 testing.expect(!isContainer(u8));
392 try testing.expect(isContainer(TestStruct));
393 try testing.expect(isContainer(TestUnion));
394 try testing.expect(isContainer(TestEnum));
395 try testing.expect(!isContainer(u8));
396396}
397397
398398pub fn isTuple(comptime T: type) bool {
......@@ -403,9 +403,9 @@ test "std.meta.trait.isTuple" {
403403 const t1 = struct {};
404404 const t2 = .{ .a = 0 };
405405 const t3 = .{ 1, 2, 3 };
406 testing.expect(!isTuple(t1));
407 testing.expect(!isTuple(@TypeOf(t2)));
408 testing.expect(isTuple(@TypeOf(t3)));
406 try testing.expect(!isTuple(t1));
407 try testing.expect(!isTuple(@TypeOf(t2)));
408 try testing.expect(isTuple(@TypeOf(t3)));
409409}
410410
411411/// Returns true if the passed type will coerce to []const u8.
......@@ -449,41 +449,41 @@ pub fn isZigString(comptime T: type) bool {
449449}
450450
451451test "std.meta.trait.isZigString" {
452 testing.expect(isZigString([]const u8));
453 testing.expect(isZigString([]u8));
454 testing.expect(isZigString([:0]const u8));
455 testing.expect(isZigString([:0]u8));
456 testing.expect(isZigString([:5]const u8));
457 testing.expect(isZigString([:5]u8));
458 testing.expect(isZigString(*const [0]u8));
459 testing.expect(isZigString(*[0]u8));
460 testing.expect(isZigString(*const [0:0]u8));
461 testing.expect(isZigString(*[0:0]u8));
462 testing.expect(isZigString(*const [0:5]u8));
463 testing.expect(isZigString(*[0:5]u8));
464 testing.expect(isZigString(*const [10]u8));
465 testing.expect(isZigString(*[10]u8));
466 testing.expect(isZigString(*const [10:0]u8));
467 testing.expect(isZigString(*[10:0]u8));
468 testing.expect(isZigString(*const [10:5]u8));
469 testing.expect(isZigString(*[10:5]u8));
470
471 testing.expect(!isZigString(u8));
472 testing.expect(!isZigString([4]u8));
473 testing.expect(!isZigString([4:0]u8));
474 testing.expect(!isZigString([*]const u8));
475 testing.expect(!isZigString([*]const [4]u8));
476 testing.expect(!isZigString([*c]const u8));
477 testing.expect(!isZigString([*c]const [4]u8));
478 testing.expect(!isZigString([*:0]const u8));
479 testing.expect(!isZigString([*:0]const u8));
480 testing.expect(!isZigString(*[]const u8));
481 testing.expect(!isZigString(?[]const u8));
482 testing.expect(!isZigString(?*const [4]u8));
483 testing.expect(!isZigString([]allowzero u8));
484 testing.expect(!isZigString([]volatile u8));
485 testing.expect(!isZigString(*allowzero [4]u8));
486 testing.expect(!isZigString(*volatile [4]u8));
452 try testing.expect(isZigString([]const u8));
453 try testing.expect(isZigString([]u8));
454 try testing.expect(isZigString([:0]const u8));
455 try testing.expect(isZigString([:0]u8));
456 try testing.expect(isZigString([:5]const u8));
457 try testing.expect(isZigString([:5]u8));
458 try testing.expect(isZigString(*const [0]u8));
459 try testing.expect(isZigString(*[0]u8));
460 try testing.expect(isZigString(*const [0:0]u8));
461 try testing.expect(isZigString(*[0:0]u8));
462 try testing.expect(isZigString(*const [0:5]u8));
463 try testing.expect(isZigString(*[0:5]u8));
464 try testing.expect(isZigString(*const [10]u8));
465 try testing.expect(isZigString(*[10]u8));
466 try testing.expect(isZigString(*const [10:0]u8));
467 try testing.expect(isZigString(*[10:0]u8));
468 try testing.expect(isZigString(*const [10:5]u8));
469 try testing.expect(isZigString(*[10:5]u8));
470
471 try testing.expect(!isZigString(u8));
472 try testing.expect(!isZigString([4]u8));
473 try testing.expect(!isZigString([4:0]u8));
474 try testing.expect(!isZigString([*]const u8));
475 try testing.expect(!isZigString([*]const [4]u8));
476 try testing.expect(!isZigString([*c]const u8));
477 try testing.expect(!isZigString([*c]const [4]u8));
478 try testing.expect(!isZigString([*:0]const u8));
479 try testing.expect(!isZigString([*:0]const u8));
480 try testing.expect(!isZigString(*[]const u8));
481 try testing.expect(!isZigString(?[]const u8));
482 try testing.expect(!isZigString(?*const [4]u8));
483 try testing.expect(!isZigString([]allowzero u8));
484 try testing.expect(!isZigString([]volatile u8));
485 try testing.expect(!isZigString(*allowzero [4]u8));
486 try testing.expect(!isZigString(*volatile [4]u8));
487487}
488488
489489pub fn hasDecls(comptime T: type, comptime names: anytype) bool {
......@@ -505,11 +505,11 @@ test "std.meta.trait.hasDecls" {
505505
506506 const tuple = .{ "a", "b", "c" };
507507
508 testing.expect(!hasDecls(TestStruct1, .{"a"}));
509 testing.expect(hasDecls(TestStruct2, .{ "a", "b" }));
510 testing.expect(hasDecls(TestStruct2, .{ "a", "b", "useless" }));
511 testing.expect(!hasDecls(TestStruct2, .{ "a", "b", "c" }));
512 testing.expect(!hasDecls(TestStruct2, tuple));
508 try testing.expect(!hasDecls(TestStruct1, .{"a"}));
509 try testing.expect(hasDecls(TestStruct2, .{ "a", "b" }));
510 try testing.expect(hasDecls(TestStruct2, .{ "a", "b", "useless" }));
511 try testing.expect(!hasDecls(TestStruct2, .{ "a", "b", "c" }));
512 try testing.expect(!hasDecls(TestStruct2, tuple));
513513}
514514
515515pub fn hasFields(comptime T: type, comptime names: anytype) bool {
......@@ -531,11 +531,11 @@ test "std.meta.trait.hasFields" {
531531
532532 const tuple = .{ "a", "b", "c" };
533533
534 testing.expect(!hasFields(TestStruct1, .{"a"}));
535 testing.expect(hasFields(TestStruct2, .{ "a", "b" }));
536 testing.expect(hasFields(TestStruct2, .{ "a", "b", "c" }));
537 testing.expect(hasFields(TestStruct2, tuple));
538 testing.expect(!hasFields(TestStruct2, .{ "a", "b", "useless" }));
534 try testing.expect(!hasFields(TestStruct1, .{"a"}));
535 try testing.expect(hasFields(TestStruct2, .{ "a", "b" }));
536 try testing.expect(hasFields(TestStruct2, .{ "a", "b", "c" }));
537 try testing.expect(hasFields(TestStruct2, tuple));
538 try testing.expect(!hasFields(TestStruct2, .{ "a", "b", "useless" }));
539539}
540540
541541pub fn hasFunctions(comptime T: type, comptime names: anytype) bool {
......@@ -555,10 +555,10 @@ test "std.meta.trait.hasFunctions" {
555555
556556 const tuple = .{ "a", "b", "c" };
557557
558 testing.expect(!hasFunctions(TestStruct1, .{"a"}));
559 testing.expect(hasFunctions(TestStruct2, .{ "a", "b" }));
560 testing.expect(!hasFunctions(TestStruct2, .{ "a", "b", "c" }));
561 testing.expect(!hasFunctions(TestStruct2, tuple));
558 try testing.expect(!hasFunctions(TestStruct1, .{"a"}));
559 try testing.expect(hasFunctions(TestStruct2, .{ "a", "b" }));
560 try testing.expect(!hasFunctions(TestStruct2, .{ "a", "b", "c" }));
561 try testing.expect(!hasFunctions(TestStruct2, tuple));
562562}
563563
564564/// True if every value of the type `T` has a unique bit pattern representing it.
......@@ -606,65 +606,65 @@ test "std.meta.trait.hasUniqueRepresentation" {
606606 b: u32,
607607 };
608608
609 testing.expect(hasUniqueRepresentation(TestStruct1));
609 try testing.expect(hasUniqueRepresentation(TestStruct1));
610610
611611 const TestStruct2 = struct {
612612 a: u32,
613613 b: u16,
614614 };
615615
616 testing.expect(!hasUniqueRepresentation(TestStruct2));
616 try testing.expect(!hasUniqueRepresentation(TestStruct2));
617617
618618 const TestStruct3 = struct {
619619 a: u32,
620620 b: u32,
621621 };
622622
623 testing.expect(hasUniqueRepresentation(TestStruct3));
623 try testing.expect(hasUniqueRepresentation(TestStruct3));
624624
625625 const TestStruct4 = struct { a: []const u8 };
626626
627 testing.expect(!hasUniqueRepresentation(TestStruct4));
627 try testing.expect(!hasUniqueRepresentation(TestStruct4));
628628
629629 const TestStruct5 = struct { a: TestStruct4 };
630630
631 testing.expect(!hasUniqueRepresentation(TestStruct5));
631 try testing.expect(!hasUniqueRepresentation(TestStruct5));
632632
633633 const TestUnion1 = packed union {
634634 a: u32,
635635 b: u16,
636636 };
637637
638 testing.expect(!hasUniqueRepresentation(TestUnion1));
638 try testing.expect(!hasUniqueRepresentation(TestUnion1));
639639
640640 const TestUnion2 = extern union {
641641 a: u32,
642642 b: u16,
643643 };
644644
645 testing.expect(!hasUniqueRepresentation(TestUnion2));
645 try testing.expect(!hasUniqueRepresentation(TestUnion2));
646646
647647 const TestUnion3 = union {
648648 a: u32,
649649 b: u16,
650650 };
651651
652 testing.expect(!hasUniqueRepresentation(TestUnion3));
652 try testing.expect(!hasUniqueRepresentation(TestUnion3));
653653
654654 const TestUnion4 = union(enum) {
655655 a: u32,
656656 b: u16,
657657 };
658658
659 testing.expect(!hasUniqueRepresentation(TestUnion4));
659 try testing.expect(!hasUniqueRepresentation(TestUnion4));
660660
661661 inline for ([_]type{ i0, u8, i16, u32, i64 }) |T| {
662 testing.expect(hasUniqueRepresentation(T));
662 try testing.expect(hasUniqueRepresentation(T));
663663 }
664664 inline for ([_]type{ i1, u9, i17, u33, i24 }) |T| {
665 testing.expect(!hasUniqueRepresentation(T));
665 try testing.expect(!hasUniqueRepresentation(T));
666666 }
667667
668 testing.expect(!hasUniqueRepresentation([]u8));
669 testing.expect(!hasUniqueRepresentation([]const u8));
668 try testing.expect(!hasUniqueRepresentation([]u8));
669 try testing.expect(!hasUniqueRepresentation([]const u8));
670670}
lib/std/multi_array_list.zig+57-57
......@@ -303,7 +303,7 @@ test "basic usage" {
303303 var list = MultiArrayList(Foo){};
304304 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
308308 try list.ensureCapacity(ally, 2);
309309
......@@ -319,12 +319,12 @@ test "basic usage" {
319319 .c = 'b',
320320 });
321321
322 testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 1, 2 });
323 testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'a', 'b' });
322 try testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 1, 2 });
323 try testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'a', 'b' });
324324
325 testing.expectEqual(@as(usize, 2), list.items(.b).len);
326 testing.expectEqualStrings("foobar", list.items(.b)[0]);
327 testing.expectEqualStrings("zigzag", list.items(.b)[1]);
325 try testing.expectEqual(@as(usize, 2), list.items(.b).len);
326 try testing.expectEqualStrings("foobar", list.items(.b)[0]);
327 try testing.expectEqualStrings("zigzag", list.items(.b)[1]);
328328
329329 try list.append(ally, .{
330330 .a = 3,
......@@ -332,13 +332,13 @@ test "basic usage" {
332332 .c = 'c',
333333 });
334334
335 testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 1, 2, 3 });
336 testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'a', 'b', 'c' });
335 try testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 1, 2, 3 });
336 try testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'a', 'b', 'c' });
337337
338 testing.expectEqual(@as(usize, 3), list.items(.b).len);
339 testing.expectEqualStrings("foobar", list.items(.b)[0]);
340 testing.expectEqualStrings("zigzag", list.items(.b)[1]);
341 testing.expectEqualStrings("fizzbuzz", list.items(.b)[2]);
338 try testing.expectEqual(@as(usize, 3), list.items(.b).len);
339 try testing.expectEqualStrings("foobar", list.items(.b)[0]);
340 try testing.expectEqualStrings("zigzag", list.items(.b)[1]);
341 try testing.expectEqualStrings("fizzbuzz", list.items(.b)[2]);
342342
343343 // Add 6 more things to force a capacity increase.
344344 var i: usize = 0;
......@@ -350,12 +350,12 @@ test "basic usage" {
350350 });
351351 }
352352
353 testing.expectEqualSlices(
353 try testing.expectEqualSlices(
354354 u32,
355355 &[_]u32{ 1, 2, 3, 4, 5, 6, 7, 8, 9 },
356356 list.items(.a),
357357 );
358 testing.expectEqualSlices(
358 try testing.expectEqualSlices(
359359 u8,
360360 &[_]u8{ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i' },
361361 list.items(.c),
......@@ -363,13 +363,13 @@ test "basic usage" {
363363
364364 list.shrinkAndFree(ally, 3);
365365
366 testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 1, 2, 3 });
367 testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'a', 'b', 'c' });
366 try testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 1, 2, 3 });
367 try testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'a', 'b', 'c' });
368368
369 testing.expectEqual(@as(usize, 3), list.items(.b).len);
370 testing.expectEqualStrings("foobar", list.items(.b)[0]);
371 testing.expectEqualStrings("zigzag", list.items(.b)[1]);
372 testing.expectEqualStrings("fizzbuzz", list.items(.b)[2]);
369 try testing.expectEqual(@as(usize, 3), list.items(.b).len);
370 try testing.expectEqualStrings("foobar", list.items(.b)[0]);
371 try testing.expectEqualStrings("zigzag", list.items(.b)[1]);
372 try testing.expectEqualStrings("fizzbuzz", list.items(.b)[2]);
373373}
374374
375375// This was observed to fail on aarch64 with LLVM 11, when the capacityInBytes
......@@ -418,37 +418,37 @@ test "regression test for @reduce bug" {
418418 try list.append(ally, .{ .tag = .eof, .start = 123 });
419419
420420 const tags = list.items(.tag);
421 testing.expectEqual(tags[1], .identifier);
422 testing.expectEqual(tags[2], .equal);
423 testing.expectEqual(tags[3], .builtin);
424 testing.expectEqual(tags[4], .l_paren);
425 testing.expectEqual(tags[5], .string_literal);
426 testing.expectEqual(tags[6], .r_paren);
427 testing.expectEqual(tags[7], .semicolon);
428 testing.expectEqual(tags[8], .keyword_pub);
429 testing.expectEqual(tags[9], .keyword_fn);
430 testing.expectEqual(tags[10], .identifier);
431 testing.expectEqual(tags[11], .l_paren);
432 testing.expectEqual(tags[12], .r_paren);
433 testing.expectEqual(tags[13], .identifier);
434 testing.expectEqual(tags[14], .bang);
435 testing.expectEqual(tags[15], .identifier);
436 testing.expectEqual(tags[16], .l_brace);
437 testing.expectEqual(tags[17], .identifier);
438 testing.expectEqual(tags[18], .period);
439 testing.expectEqual(tags[19], .identifier);
440 testing.expectEqual(tags[20], .period);
441 testing.expectEqual(tags[21], .identifier);
442 testing.expectEqual(tags[22], .l_paren);
443 testing.expectEqual(tags[23], .string_literal);
444 testing.expectEqual(tags[24], .comma);
445 testing.expectEqual(tags[25], .period);
446 testing.expectEqual(tags[26], .l_brace);
447 testing.expectEqual(tags[27], .r_brace);
448 testing.expectEqual(tags[28], .r_paren);
449 testing.expectEqual(tags[29], .semicolon);
450 testing.expectEqual(tags[30], .r_brace);
451 testing.expectEqual(tags[31], .eof);
421 try testing.expectEqual(tags[1], .identifier);
422 try testing.expectEqual(tags[2], .equal);
423 try testing.expectEqual(tags[3], .builtin);
424 try testing.expectEqual(tags[4], .l_paren);
425 try testing.expectEqual(tags[5], .string_literal);
426 try testing.expectEqual(tags[6], .r_paren);
427 try testing.expectEqual(tags[7], .semicolon);
428 try testing.expectEqual(tags[8], .keyword_pub);
429 try testing.expectEqual(tags[9], .keyword_fn);
430 try testing.expectEqual(tags[10], .identifier);
431 try testing.expectEqual(tags[11], .l_paren);
432 try testing.expectEqual(tags[12], .r_paren);
433 try testing.expectEqual(tags[13], .identifier);
434 try testing.expectEqual(tags[14], .bang);
435 try testing.expectEqual(tags[15], .identifier);
436 try testing.expectEqual(tags[16], .l_brace);
437 try testing.expectEqual(tags[17], .identifier);
438 try testing.expectEqual(tags[18], .period);
439 try testing.expectEqual(tags[19], .identifier);
440 try testing.expectEqual(tags[20], .period);
441 try testing.expectEqual(tags[21], .identifier);
442 try testing.expectEqual(tags[22], .l_paren);
443 try testing.expectEqual(tags[23], .string_literal);
444 try testing.expectEqual(tags[24], .comma);
445 try testing.expectEqual(tags[25], .period);
446 try testing.expectEqual(tags[26], .l_brace);
447 try testing.expectEqual(tags[27], .r_brace);
448 try testing.expectEqual(tags[28], .r_paren);
449 try testing.expectEqual(tags[29], .semicolon);
450 try testing.expectEqual(tags[30], .r_brace);
451 try testing.expectEqual(tags[31], .eof);
452452}
453453
454454test "ensure capacity on empty list" {
......@@ -466,15 +466,15 @@ test "ensure capacity on empty list" {
466466 list.appendAssumeCapacity(.{ .a = 1, .b = 2 });
467467 list.appendAssumeCapacity(.{ .a = 3, .b = 4 });
468468
469 testing.expectEqualSlices(u32, &[_]u32{ 1, 3 }, list.items(.a));
470 testing.expectEqualSlices(u8, &[_]u8{ 2, 4 }, list.items(.b));
469 try testing.expectEqualSlices(u32, &[_]u32{ 1, 3 }, list.items(.a));
470 try testing.expectEqualSlices(u8, &[_]u8{ 2, 4 }, list.items(.b));
471471
472472 list.len = 0;
473473 list.appendAssumeCapacity(.{ .a = 5, .b = 6 });
474474 list.appendAssumeCapacity(.{ .a = 7, .b = 8 });
475475
476 testing.expectEqualSlices(u32, &[_]u32{ 5, 7 }, list.items(.a));
477 testing.expectEqualSlices(u8, &[_]u8{ 6, 8 }, list.items(.b));
476 try testing.expectEqualSlices(u32, &[_]u32{ 5, 7 }, list.items(.a));
477 try testing.expectEqualSlices(u8, &[_]u8{ 6, 8 }, list.items(.b));
478478
479479 list.len = 0;
480480 try list.ensureCapacity(ally, 16);
......@@ -482,6 +482,6 @@ test "ensure capacity on empty list" {
482482 list.appendAssumeCapacity(.{ .a = 9, .b = 10 });
483483 list.appendAssumeCapacity(.{ .a = 11, .b = 12 });
484484
485 testing.expectEqualSlices(u32, &[_]u32{ 9, 11 }, list.items(.a));
486 testing.expectEqualSlices(u8, &[_]u8{ 10, 12 }, list.items(.b));
485 try testing.expectEqualSlices(u32, &[_]u32{ 9, 11 }, list.items(.a));
486 try testing.expectEqualSlices(u8, &[_]u8{ 10, 12 }, list.items(.b));
487487}
lib/std/net/test.zig+24-24
......@@ -38,26 +38,26 @@ test "parse and render IPv6 addresses" {
3838 for (ips) |ip, i| {
3939 var addr = net.Address.parseIp6(ip, 0) catch unreachable;
4040 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
4343 if (std.builtin.os.tag == .linux) {
4444 var addr_via_resolve = net.Address.resolveIp6(ip, 0) catch unreachable;
4545 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]));
4747 }
4848 }
4949
50 testing.expectError(error.InvalidCharacter, net.Address.parseIp6(":::", 0));
51 testing.expectError(error.Overflow, net.Address.parseIp6("FF001::FB", 0));
52 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));
54 testing.expectError(error.Incomplete, net.Address.parseIp6("FF01:", 0));
55 testing.expectError(error.InvalidIpv4Mapping, net.Address.parseIp6("::123.123.123.123", 0));
50 try testing.expectError(error.InvalidCharacter, net.Address.parseIp6(":::", 0));
51 try testing.expectError(error.Overflow, net.Address.parseIp6("FF001::FB", 0));
52 try testing.expectError(error.InvalidCharacter, net.Address.parseIp6("FF01::Fb:zig", 0));
53 try testing.expectError(error.InvalidEnd, net.Address.parseIp6("FF01:0:0:0:0:0:0:FB:", 0));
54 try testing.expectError(error.Incomplete, net.Address.parseIp6("FF01:", 0));
55 try testing.expectError(error.InvalidIpv4Mapping, net.Address.parseIp6("::123.123.123.123", 0));
5656 // TODO Make this test pass on other operating systems.
5757 if (std.builtin.os.tag == .linux) {
58 testing.expectError(error.Incomplete, net.Address.resolveIp6("ff01::fb%", 0));
59 testing.expectError(error.Overflow, net.Address.resolveIp6("ff01::fb%wlp3s0s0s0s0s0s0s0s0", 0));
60 testing.expectError(error.Overflow, net.Address.resolveIp6("ff01::fb%12345678901234", 0));
58 try testing.expectError(error.Incomplete, net.Address.resolveIp6("ff01::fb%", 0));
59 try testing.expectError(error.Overflow, net.Address.resolveIp6("ff01::fb%wlp3s0s0s0s0s0s0s0s0", 0));
60 try testing.expectError(error.Overflow, net.Address.resolveIp6("ff01::fb%12345678901234", 0));
6161 }
6262}
6363
......@@ -68,7 +68,7 @@ test "invalid but parseable IPv6 scope ids" {
6868 return error.SkipZigTest;
6969 }
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));
7272}
7373
7474test "parse and render IPv4 addresses" {
......@@ -84,14 +84,14 @@ test "parse and render IPv4 addresses" {
8484 }) |ip| {
8585 var addr = net.Address.parseIp4(ip, 0) catch unreachable;
8686 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]));
8888 }
8989
90 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));
92 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));
94 testing.expectError(error.InvalidCharacter, net.Address.parseIp4("100..0.1", 0));
90 try testing.expectError(error.Overflow, net.Address.parseIp4("256.0.0.1", 0));
91 try testing.expectError(error.InvalidCharacter, net.Address.parseIp4("x.0.0.1", 0));
92 try testing.expectError(error.InvalidEnd, net.Address.parseIp4("127.0.0.1.1", 0));
93 try testing.expectError(error.Incomplete, net.Address.parseIp4("127.0.0.", 0));
94 try testing.expectError(error.InvalidCharacter, net.Address.parseIp4("100..0.1", 0));
9595}
9696
9797test "resolve DNS" {
......@@ -169,8 +169,8 @@ test "listen on a port, send bytes, receive bytes" {
169169 var buf: [16]u8 = undefined;
170170 const n = try client.stream.reader().read(&buf);
171171
172 testing.expectEqual(@as(usize, 12), n);
173 testing.expectEqualSlices(u8, "Hello world!", buf[0..n]);
172 try testing.expectEqual(@as(usize, 12), n);
173 try testing.expectEqualSlices(u8, "Hello world!", buf[0..n]);
174174}
175175
176176test "listen on a port, send bytes, receive bytes" {
......@@ -230,7 +230,7 @@ fn testClientToHost(allocator: *mem.Allocator, name: []const u8, port: u16) anye
230230 var buf: [100]u8 = undefined;
231231 const len = try connection.read(&buf);
232232 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"));
234234}
235235
236236fn testClient(addr: net.Address) anyerror!void {
......@@ -242,7 +242,7 @@ fn testClient(addr: net.Address) anyerror!void {
242242 var buf: [100]u8 = undefined;
243243 const len = try socket_file.read(&buf);
244244 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"));
246246}
247247
248248fn testServer(server: *net.StreamServer) anyerror!void {
......@@ -293,6 +293,6 @@ test "listen on a unix socket, send bytes, receive bytes" {
293293 var buf: [16]u8 = undefined;
294294 const n = try client.stream.reader().read(&buf);
295295
296 testing.expectEqual(@as(usize, 12), n);
297 testing.expectEqualSlices(u8, "Hello world!", buf[0..n]);
296 try testing.expectEqual(@as(usize, 12), n);
297 try testing.expectEqualSlices(u8, "Hello world!", buf[0..n]);
298298}
lib/std/once.zig+1-1
......@@ -67,5 +67,5 @@ test "Once executes its function just once" {
6767 }
6868 }
6969
70 testing.expectEqual(@as(i32, 1), global_number);
70 try testing.expectEqual(@as(i32, 1), global_number);
7171}
lib/std/os/linux/bpf.zig+100-100
......@@ -737,11 +737,11 @@ pub const Insn = packed struct {
737737};
738738
739739test "insn bitsize" {
740 expectEqual(@bitSizeOf(Insn), 64);
740 try expectEqual(@bitSizeOf(Insn), 64);
741741}
742742
743fn expect_opcode(code: u8, insn: Insn) void {
744 expectEqual(code, insn.code);
743fn expect_opcode(code: u8, insn: Insn) !void {
744 try expectEqual(code, insn.code);
745745}
746746
747747// The opcodes were grabbed from https://github.com/iovisor/bpf-docs/blob/master/eBPF.md
......@@ -750,108 +750,108 @@ test "opcodes" {
750750 // loading 64-bit immediates (imm is only 32 bits wide)
751751
752752 // alu instructions
753 expect_opcode(0x07, Insn.add(.r1, 0));
754 expect_opcode(0x0f, Insn.add(.r1, .r2));
755 expect_opcode(0x17, Insn.sub(.r1, 0));
756 expect_opcode(0x1f, Insn.sub(.r1, .r2));
757 expect_opcode(0x27, Insn.mul(.r1, 0));
758 expect_opcode(0x2f, Insn.mul(.r1, .r2));
759 expect_opcode(0x37, Insn.div(.r1, 0));
760 expect_opcode(0x3f, Insn.div(.r1, .r2));
761 expect_opcode(0x47, Insn.alu_or(.r1, 0));
762 expect_opcode(0x4f, Insn.alu_or(.r1, .r2));
763 expect_opcode(0x57, Insn.alu_and(.r1, 0));
764 expect_opcode(0x5f, Insn.alu_and(.r1, .r2));
765 expect_opcode(0x67, Insn.lsh(.r1, 0));
766 expect_opcode(0x6f, Insn.lsh(.r1, .r2));
767 expect_opcode(0x77, Insn.rsh(.r1, 0));
768 expect_opcode(0x7f, Insn.rsh(.r1, .r2));
769 expect_opcode(0x87, Insn.neg(.r1));
770 expect_opcode(0x97, Insn.mod(.r1, 0));
771 expect_opcode(0x9f, Insn.mod(.r1, .r2));
772 expect_opcode(0xa7, Insn.xor(.r1, 0));
773 expect_opcode(0xaf, Insn.xor(.r1, .r2));
774 expect_opcode(0xb7, Insn.mov(.r1, 0));
775 expect_opcode(0xbf, Insn.mov(.r1, .r2));
776 expect_opcode(0xc7, Insn.arsh(.r1, 0));
777 expect_opcode(0xcf, Insn.arsh(.r1, .r2));
753 try expect_opcode(0x07, Insn.add(.r1, 0));
754 try expect_opcode(0x0f, Insn.add(.r1, .r2));
755 try expect_opcode(0x17, Insn.sub(.r1, 0));
756 try expect_opcode(0x1f, Insn.sub(.r1, .r2));
757 try expect_opcode(0x27, Insn.mul(.r1, 0));
758 try expect_opcode(0x2f, Insn.mul(.r1, .r2));
759 try expect_opcode(0x37, Insn.div(.r1, 0));
760 try expect_opcode(0x3f, Insn.div(.r1, .r2));
761 try expect_opcode(0x47, Insn.alu_or(.r1, 0));
762 try expect_opcode(0x4f, Insn.alu_or(.r1, .r2));
763 try expect_opcode(0x57, Insn.alu_and(.r1, 0));
764 try expect_opcode(0x5f, Insn.alu_and(.r1, .r2));
765 try expect_opcode(0x67, Insn.lsh(.r1, 0));
766 try expect_opcode(0x6f, Insn.lsh(.r1, .r2));
767 try expect_opcode(0x77, Insn.rsh(.r1, 0));
768 try expect_opcode(0x7f, Insn.rsh(.r1, .r2));
769 try expect_opcode(0x87, Insn.neg(.r1));
770 try expect_opcode(0x97, Insn.mod(.r1, 0));
771 try expect_opcode(0x9f, Insn.mod(.r1, .r2));
772 try expect_opcode(0xa7, Insn.xor(.r1, 0));
773 try expect_opcode(0xaf, Insn.xor(.r1, .r2));
774 try expect_opcode(0xb7, Insn.mov(.r1, 0));
775 try expect_opcode(0xbf, Insn.mov(.r1, .r2));
776 try expect_opcode(0xc7, Insn.arsh(.r1, 0));
777 try expect_opcode(0xcf, Insn.arsh(.r1, .r2));
778778
779779 // 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
782782 // TODO: byteswap instructions
783 expect_opcode(0xd4, Insn.le(.half_word, .r1));
784 expectEqual(@intCast(i32, 16), Insn.le(.half_word, .r1).imm);
785 expect_opcode(0xd4, Insn.le(.word, .r1));
786 expectEqual(@intCast(i32, 32), Insn.le(.word, .r1).imm);
787 expect_opcode(0xd4, Insn.le(.double_word, .r1));
788 expectEqual(@intCast(i32, 64), Insn.le(.double_word, .r1).imm);
789 expect_opcode(0xdc, Insn.be(.half_word, .r1));
790 expectEqual(@intCast(i32, 16), Insn.be(.half_word, .r1).imm);
791 expect_opcode(0xdc, Insn.be(.word, .r1));
792 expectEqual(@intCast(i32, 32), Insn.be(.word, .r1).imm);
793 expect_opcode(0xdc, Insn.be(.double_word, .r1));
794 expectEqual(@intCast(i32, 64), Insn.be(.double_word, .r1).imm);
783 try expect_opcode(0xd4, Insn.le(.half_word, .r1));
784 try expectEqual(@intCast(i32, 16), Insn.le(.half_word, .r1).imm);
785 try expect_opcode(0xd4, Insn.le(.word, .r1));
786 try expectEqual(@intCast(i32, 32), Insn.le(.word, .r1).imm);
787 try expect_opcode(0xd4, Insn.le(.double_word, .r1));
788 try expectEqual(@intCast(i32, 64), Insn.le(.double_word, .r1).imm);
789 try expect_opcode(0xdc, Insn.be(.half_word, .r1));
790 try expectEqual(@intCast(i32, 16), Insn.be(.half_word, .r1).imm);
791 try expect_opcode(0xdc, Insn.be(.word, .r1));
792 try expectEqual(@intCast(i32, 32), Insn.be(.word, .r1).imm);
793 try expect_opcode(0xdc, Insn.be(.double_word, .r1));
794 try expectEqual(@intCast(i32, 64), Insn.be(.double_word, .r1).imm);
795795
796796 // memory instructions
797 expect_opcode(0x18, Insn.ld_dw1(.r1, 0));
798 expect_opcode(0x00, Insn.ld_dw2(0));
797 try expect_opcode(0x18, Insn.ld_dw1(.r1, 0));
798 try expect_opcode(0x00, Insn.ld_dw2(0));
799799
800800 // loading a map fd
801 expect_opcode(0x18, Insn.ld_map_fd1(.r1, 0));
802 expectEqual(@intCast(u4, PSEUDO_MAP_FD), Insn.ld_map_fd1(.r1, 0).src);
803 expect_opcode(0x00, Insn.ld_map_fd2(0));
804
805 expect_opcode(0x38, Insn.ld_abs(.double_word, .r1, .r2, 0));
806 expect_opcode(0x20, Insn.ld_abs(.word, .r1, .r2, 0));
807 expect_opcode(0x28, Insn.ld_abs(.half_word, .r1, .r2, 0));
808 expect_opcode(0x30, Insn.ld_abs(.byte, .r1, .r2, 0));
809
810 expect_opcode(0x58, Insn.ld_ind(.double_word, .r1, .r2, 0));
811 expect_opcode(0x40, Insn.ld_ind(.word, .r1, .r2, 0));
812 expect_opcode(0x48, Insn.ld_ind(.half_word, .r1, .r2, 0));
813 expect_opcode(0x50, Insn.ld_ind(.byte, .r1, .r2, 0));
814
815 expect_opcode(0x79, Insn.ldx(.double_word, .r1, .r2, 0));
816 expect_opcode(0x61, Insn.ldx(.word, .r1, .r2, 0));
817 expect_opcode(0x69, Insn.ldx(.half_word, .r1, .r2, 0));
818 expect_opcode(0x71, Insn.ldx(.byte, .r1, .r2, 0));
819
820 expect_opcode(0x62, Insn.st(.word, .r1, 0, 0));
821 expect_opcode(0x6a, Insn.st(.half_word, .r1, 0, 0));
822 expect_opcode(0x72, Insn.st(.byte, .r1, 0, 0));
823
824 expect_opcode(0x63, Insn.stx(.word, .r1, 0, .r2));
825 expect_opcode(0x6b, Insn.stx(.half_word, .r1, 0, .r2));
826 expect_opcode(0x73, Insn.stx(.byte, .r1, 0, .r2));
827 expect_opcode(0x7b, Insn.stx(.double_word, .r1, 0, .r2));
801 try expect_opcode(0x18, Insn.ld_map_fd1(.r1, 0));
802 try expectEqual(@intCast(u4, PSEUDO_MAP_FD), Insn.ld_map_fd1(.r1, 0).src);
803 try expect_opcode(0x00, Insn.ld_map_fd2(0));
804
805 try expect_opcode(0x38, Insn.ld_abs(.double_word, .r1, .r2, 0));
806 try expect_opcode(0x20, Insn.ld_abs(.word, .r1, .r2, 0));
807 try expect_opcode(0x28, Insn.ld_abs(.half_word, .r1, .r2, 0));
808 try expect_opcode(0x30, Insn.ld_abs(.byte, .r1, .r2, 0));
809
810 try expect_opcode(0x58, Insn.ld_ind(.double_word, .r1, .r2, 0));
811 try expect_opcode(0x40, Insn.ld_ind(.word, .r1, .r2, 0));
812 try expect_opcode(0x48, Insn.ld_ind(.half_word, .r1, .r2, 0));
813 try expect_opcode(0x50, Insn.ld_ind(.byte, .r1, .r2, 0));
814
815 try expect_opcode(0x79, Insn.ldx(.double_word, .r1, .r2, 0));
816 try expect_opcode(0x61, Insn.ldx(.word, .r1, .r2, 0));
817 try expect_opcode(0x69, Insn.ldx(.half_word, .r1, .r2, 0));
818 try expect_opcode(0x71, Insn.ldx(.byte, .r1, .r2, 0));
819
820 try expect_opcode(0x62, Insn.st(.word, .r1, 0, 0));
821 try expect_opcode(0x6a, Insn.st(.half_word, .r1, 0, 0));
822 try expect_opcode(0x72, Insn.st(.byte, .r1, 0, 0));
823
824 try expect_opcode(0x63, Insn.stx(.word, .r1, 0, .r2));
825 try expect_opcode(0x6b, Insn.stx(.half_word, .r1, 0, .r2));
826 try expect_opcode(0x73, Insn.stx(.byte, .r1, 0, .r2));
827 try expect_opcode(0x7b, Insn.stx(.double_word, .r1, 0, .r2));
828828
829829 // branch instructions
830 expect_opcode(0x05, Insn.ja(0));
831 expect_opcode(0x15, Insn.jeq(.r1, 0, 0));
832 expect_opcode(0x1d, Insn.jeq(.r1, .r2, 0));
833 expect_opcode(0x25, Insn.jgt(.r1, 0, 0));
834 expect_opcode(0x2d, Insn.jgt(.r1, .r2, 0));
835 expect_opcode(0x35, Insn.jge(.r1, 0, 0));
836 expect_opcode(0x3d, Insn.jge(.r1, .r2, 0));
837 expect_opcode(0xa5, Insn.jlt(.r1, 0, 0));
838 expect_opcode(0xad, Insn.jlt(.r1, .r2, 0));
839 expect_opcode(0xb5, Insn.jle(.r1, 0, 0));
840 expect_opcode(0xbd, Insn.jle(.r1, .r2, 0));
841 expect_opcode(0x45, Insn.jset(.r1, 0, 0));
842 expect_opcode(0x4d, Insn.jset(.r1, .r2, 0));
843 expect_opcode(0x55, Insn.jne(.r1, 0, 0));
844 expect_opcode(0x5d, Insn.jne(.r1, .r2, 0));
845 expect_opcode(0x65, Insn.jsgt(.r1, 0, 0));
846 expect_opcode(0x6d, Insn.jsgt(.r1, .r2, 0));
847 expect_opcode(0x75, Insn.jsge(.r1, 0, 0));
848 expect_opcode(0x7d, Insn.jsge(.r1, .r2, 0));
849 expect_opcode(0xc5, Insn.jslt(.r1, 0, 0));
850 expect_opcode(0xcd, Insn.jslt(.r1, .r2, 0));
851 expect_opcode(0xd5, Insn.jsle(.r1, 0, 0));
852 expect_opcode(0xdd, Insn.jsle(.r1, .r2, 0));
853 expect_opcode(0x85, Insn.call(.unspec));
854 expect_opcode(0x95, Insn.exit());
830 try expect_opcode(0x05, Insn.ja(0));
831 try expect_opcode(0x15, Insn.jeq(.r1, 0, 0));
832 try expect_opcode(0x1d, Insn.jeq(.r1, .r2, 0));
833 try expect_opcode(0x25, Insn.jgt(.r1, 0, 0));
834 try expect_opcode(0x2d, Insn.jgt(.r1, .r2, 0));
835 try expect_opcode(0x35, Insn.jge(.r1, 0, 0));
836 try expect_opcode(0x3d, Insn.jge(.r1, .r2, 0));
837 try expect_opcode(0xa5, Insn.jlt(.r1, 0, 0));
838 try expect_opcode(0xad, Insn.jlt(.r1, .r2, 0));
839 try expect_opcode(0xb5, Insn.jle(.r1, 0, 0));
840 try expect_opcode(0xbd, Insn.jle(.r1, .r2, 0));
841 try expect_opcode(0x45, Insn.jset(.r1, 0, 0));
842 try expect_opcode(0x4d, Insn.jset(.r1, .r2, 0));
843 try expect_opcode(0x55, Insn.jne(.r1, 0, 0));
844 try expect_opcode(0x5d, Insn.jne(.r1, .r2, 0));
845 try expect_opcode(0x65, Insn.jsgt(.r1, 0, 0));
846 try expect_opcode(0x6d, Insn.jsgt(.r1, .r2, 0));
847 try expect_opcode(0x75, Insn.jsge(.r1, 0, 0));
848 try expect_opcode(0x7d, Insn.jsge(.r1, .r2, 0));
849 try expect_opcode(0xc5, Insn.jslt(.r1, 0, 0));
850 try expect_opcode(0xcd, Insn.jslt(.r1, .r2, 0));
851 try expect_opcode(0xd5, Insn.jsle(.r1, 0, 0));
852 try expect_opcode(0xdd, Insn.jsle(.r1, .r2, 0));
853 try expect_opcode(0x85, Insn.call(.unspec));
854 try expect_opcode(0x95, Insn.exit());
855855}
856856
857857pub const Cmd = extern enum(usize) {
......@@ -1596,7 +1596,7 @@ test "map lookup, update, and delete" {
15961596 var value = std.mem.zeroes([value_size]u8);
15971597
15981598 // 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
16011601 // succeed at updating and looking up element
16021602 try map_update_elem(map, &key, &value, 0);
......@@ -1604,14 +1604,14 @@ test "map lookup, update, and delete" {
16041604
16051605 // fails inserting more than max entries
16061606 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
16091609 // succeed at deleting an existing elem
16101610 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
16131613 // 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));
16151615}
16161616
16171617pub fn prog_load(
......@@ -1662,5 +1662,5 @@ test "prog_load" {
16621662 const prog = try prog_load(.socket_filter, &good_prog, null, "MIT", 0);
16631663 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));
16661666}
lib/std/os/linux/bpf/btf.zig+1-1
......@@ -92,7 +92,7 @@ pub const IntInfo = packed struct {
9292};
9393
9494test "IntInfo is 32 bits" {
95 std.testing.expectEqual(@bitSizeOf(IntInfo), 32);
95 try std.testing.expectEqual(@bitSizeOf(IntInfo), 32);
9696}
9797
9898/// 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(
937937test "structs/offsets/entries" {
938938 if (builtin.os.tag != .linux) return error.SkipZigTest;
939939
940 testing.expectEqual(@as(usize, 120), @sizeOf(io_uring_params));
941 testing.expectEqual(@as(usize, 64), @sizeOf(io_uring_sqe));
942 testing.expectEqual(@as(usize, 16), @sizeOf(io_uring_cqe));
940 try testing.expectEqual(@as(usize, 120), @sizeOf(io_uring_params));
941 try testing.expectEqual(@as(usize, 64), @sizeOf(io_uring_sqe));
942 try testing.expectEqual(@as(usize, 16), @sizeOf(io_uring_cqe));
943943
944 testing.expectEqual(0, linux.IORING_OFF_SQ_RING);
945 testing.expectEqual(0x8000000, linux.IORING_OFF_CQ_RING);
946 testing.expectEqual(0x10000000, linux.IORING_OFF_SQES);
944 try testing.expectEqual(0, linux.IORING_OFF_SQ_RING);
945 try testing.expectEqual(0x8000000, linux.IORING_OFF_CQ_RING);
946 try testing.expectEqual(0x10000000, linux.IORING_OFF_SQES);
947947
948 testing.expectError(error.EntriesZero, IO_Uring.init(0, 0));
949 testing.expectError(error.EntriesNotPowerOfTwo, IO_Uring.init(3, 0));
948 try testing.expectError(error.EntriesZero, IO_Uring.init(0, 0));
949 try testing.expectError(error.EntriesNotPowerOfTwo, IO_Uring.init(3, 0));
950950}
951951
952952test "nop" {
......@@ -959,11 +959,11 @@ test "nop" {
959959 };
960960 defer {
961961 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");
963963 }
964964
965965 const sqe = try ring.nop(0xaaaaaaaa);
966 testing.expectEqual(io_uring_sqe{
966 try testing.expectEqual(io_uring_sqe{
967967 .opcode = .NOP,
968968 .flags = 0,
969969 .ioprio = 0,
......@@ -979,40 +979,40 @@ test "nop" {
979979 .__pad2 = [2]u64{ 0, 0 },
980980 }, sqe.*);
981981
982 testing.expectEqual(@as(u32, 0), ring.sq.sqe_head);
983 testing.expectEqual(@as(u32, 1), ring.sq.sqe_tail);
984 testing.expectEqual(@as(u32, 0), ring.sq.tail.*);
985 testing.expectEqual(@as(u32, 0), ring.cq.head.*);
986 testing.expectEqual(@as(u32, 1), ring.sq_ready());
987 testing.expectEqual(@as(u32, 0), ring.cq_ready());
988
989 testing.expectEqual(@as(u32, 1), try ring.submit());
990 testing.expectEqual(@as(u32, 1), ring.sq.sqe_head);
991 testing.expectEqual(@as(u32, 1), ring.sq.sqe_tail);
992 testing.expectEqual(@as(u32, 1), ring.sq.tail.*);
993 testing.expectEqual(@as(u32, 0), ring.cq.head.*);
994 testing.expectEqual(@as(u32, 0), ring.sq_ready());
995
996 testing.expectEqual(io_uring_cqe{
982 try testing.expectEqual(@as(u32, 0), ring.sq.sqe_head);
983 try testing.expectEqual(@as(u32, 1), ring.sq.sqe_tail);
984 try testing.expectEqual(@as(u32, 0), ring.sq.tail.*);
985 try testing.expectEqual(@as(u32, 0), ring.cq.head.*);
986 try testing.expectEqual(@as(u32, 1), ring.sq_ready());
987 try testing.expectEqual(@as(u32, 0), ring.cq_ready());
988
989 try testing.expectEqual(@as(u32, 1), try ring.submit());
990 try testing.expectEqual(@as(u32, 1), ring.sq.sqe_head);
991 try testing.expectEqual(@as(u32, 1), ring.sq.sqe_tail);
992 try testing.expectEqual(@as(u32, 1), ring.sq.tail.*);
993 try testing.expectEqual(@as(u32, 0), ring.cq.head.*);
994 try testing.expectEqual(@as(u32, 0), ring.sq_ready());
995
996 try testing.expectEqual(io_uring_cqe{
997997 .user_data = 0xaaaaaaaa,
998998 .res = 0,
999999 .flags = 0,
10001000 }, try ring.copy_cqe());
1001 testing.expectEqual(@as(u32, 1), ring.cq.head.*);
1002 testing.expectEqual(@as(u32, 0), ring.cq_ready());
1001 try testing.expectEqual(@as(u32, 1), ring.cq.head.*);
1002 try testing.expectEqual(@as(u32, 0), ring.cq_ready());
10031003
10041004 const sqe_barrier = try ring.nop(0xbbbbbbbb);
10051005 sqe_barrier.flags |= linux.IOSQE_IO_DRAIN;
1006 testing.expectEqual(@as(u32, 1), try ring.submit());
1007 testing.expectEqual(io_uring_cqe{
1006 try testing.expectEqual(@as(u32, 1), try ring.submit());
1007 try testing.expectEqual(io_uring_cqe{
10081008 .user_data = 0xbbbbbbbb,
10091009 .res = 0,
10101010 .flags = 0,
10111011 }, try ring.copy_cqe());
1012 testing.expectEqual(@as(u32, 2), ring.sq.sqe_head);
1013 testing.expectEqual(@as(u32, 2), ring.sq.sqe_tail);
1014 testing.expectEqual(@as(u32, 2), ring.sq.tail.*);
1015 testing.expectEqual(@as(u32, 2), ring.cq.head.*);
1012 try testing.expectEqual(@as(u32, 2), ring.sq.sqe_head);
1013 try testing.expectEqual(@as(u32, 2), ring.sq.sqe_tail);
1014 try testing.expectEqual(@as(u32, 2), ring.sq.tail.*);
1015 try testing.expectEqual(@as(u32, 2), ring.cq.head.*);
10161016}
10171017
10181018test "readv" {
......@@ -1042,17 +1042,17 @@ test "readv" {
10421042 var buffer = [_]u8{42} ** 128;
10431043 var iovecs = [_]os.iovec{os.iovec{ .iov_base = &buffer, .iov_len = buffer.len }};
10441044 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);
10461046 sqe.flags |= linux.IOSQE_FIXED_FILE;
10471047
1048 testing.expectError(error.SubmissionQueueFull, ring.nop(0));
1049 testing.expectEqual(@as(u32, 1), try ring.submit());
1050 testing.expectEqual(linux.io_uring_cqe{
1048 try testing.expectError(error.SubmissionQueueFull, ring.nop(0));
1049 try testing.expectEqual(@as(u32, 1), try ring.submit());
1050 try testing.expectEqual(linux.io_uring_cqe{
10511051 .user_data = 0xcccccccc,
10521052 .res = buffer.len,
10531053 .flags = 0,
10541054 }, 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
10571057 try ring.unregister_files();
10581058}
......@@ -1083,46 +1083,46 @@ test "writev/fsync/readv" {
10831083 };
10841084
10851085 const sqe_writev = try ring.writev(0xdddddddd, fd, iovecs_write[0..], 17);
1086 testing.expectEqual(linux.IORING_OP.WRITEV, sqe_writev.opcode);
1087 testing.expectEqual(@as(u64, 17), sqe_writev.off);
1086 try testing.expectEqual(linux.IORING_OP.WRITEV, sqe_writev.opcode);
1087 try testing.expectEqual(@as(u64, 17), sqe_writev.off);
10881088 sqe_writev.flags |= linux.IOSQE_IO_LINK;
10891089
10901090 const sqe_fsync = try ring.fsync(0xeeeeeeee, fd, 0);
1091 testing.expectEqual(linux.IORING_OP.FSYNC, sqe_fsync.opcode);
1092 testing.expectEqual(fd, sqe_fsync.fd);
1091 try testing.expectEqual(linux.IORING_OP.FSYNC, sqe_fsync.opcode);
1092 try testing.expectEqual(fd, sqe_fsync.fd);
10931093 sqe_fsync.flags |= linux.IOSQE_IO_LINK;
10941094
10951095 const sqe_readv = try ring.readv(0xffffffff, fd, iovecs_read[0..], 17);
1096 testing.expectEqual(linux.IORING_OP.READV, sqe_readv.opcode);
1097 testing.expectEqual(@as(u64, 17), sqe_readv.off);
1096 try testing.expectEqual(linux.IORING_OP.READV, sqe_readv.opcode);
1097 try testing.expectEqual(@as(u64, 17), sqe_readv.off);
10981098
1099 testing.expectEqual(@as(u32, 3), ring.sq_ready());
1100 testing.expectEqual(@as(u32, 3), try ring.submit_and_wait(3));
1101 testing.expectEqual(@as(u32, 0), ring.sq_ready());
1102 testing.expectEqual(@as(u32, 3), ring.cq_ready());
1099 try testing.expectEqual(@as(u32, 3), ring.sq_ready());
1100 try testing.expectEqual(@as(u32, 3), try ring.submit_and_wait(3));
1101 try testing.expectEqual(@as(u32, 0), ring.sq_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{
11051105 .user_data = 0xdddddddd,
11061106 .res = buffer_write.len,
11071107 .flags = 0,
11081108 }, 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{
11121112 .user_data = 0xeeeeeeee,
11131113 .res = 0,
11141114 .flags = 0,
11151115 }, 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{
11191119 .user_data = 0xffffffff,
11201120 .res = buffer_read.len,
11211121 .flags = 0,
11221122 }, 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..]);
11261126}
11271127
11281128test "write/read" {
......@@ -1144,13 +1144,13 @@ test "write/read" {
11441144 const buffer_write = [_]u8{97} ** 20;
11451145 var buffer_read = [_]u8{98} ** 20;
11461146 const sqe_write = try ring.write(0x11111111, fd, buffer_write[0..], 10);
1147 testing.expectEqual(linux.IORING_OP.WRITE, sqe_write.opcode);
1148 testing.expectEqual(@as(u64, 10), sqe_write.off);
1147 try testing.expectEqual(linux.IORING_OP.WRITE, sqe_write.opcode);
1148 try testing.expectEqual(@as(u64, 10), sqe_write.off);
11491149 sqe_write.flags |= linux.IOSQE_IO_LINK;
11501150 const sqe_read = try ring.read(0x22222222, fd, buffer_read[0..], 10);
1151 testing.expectEqual(linux.IORING_OP.READ, sqe_read.opcode);
1152 testing.expectEqual(@as(u64, 10), sqe_read.off);
1153 testing.expectEqual(@as(u32, 2), try ring.submit());
1151 try testing.expectEqual(linux.IORING_OP.READ, sqe_read.opcode);
1152 try testing.expectEqual(@as(u64, 10), sqe_read.off);
1153 try testing.expectEqual(@as(u32, 2), try ring.submit());
11541154
11551155 const cqe_write = try ring.copy_cqe();
11561156 const cqe_read = try ring.copy_cqe();
......@@ -1158,17 +1158,17 @@ test "write/read" {
11581158 // https://lwn.net/Articles/809820/
11591159 if (cqe_write.res == -linux.EINVAL) return error.SkipZigTest;
11601160 if (cqe_read.res == -linux.EINVAL) return error.SkipZigTest;
1161 testing.expectEqual(linux.io_uring_cqe{
1161 try testing.expectEqual(linux.io_uring_cqe{
11621162 .user_data = 0x11111111,
11631163 .res = buffer_write.len,
11641164 .flags = 0,
11651165 }, cqe_write);
1166 testing.expectEqual(linux.io_uring_cqe{
1166 try testing.expectEqual(linux.io_uring_cqe{
11671167 .user_data = 0x22222222,
11681168 .res = buffer_read.len,
11691169 .flags = 0,
11701170 }, cqe_read);
1171 testing.expectEqualSlices(u8, buffer_write[0..], buffer_read[0..]);
1171 try testing.expectEqualSlices(u8, buffer_write[0..], buffer_read[0..]);
11721172}
11731173
11741174test "openat" {
......@@ -1187,7 +1187,7 @@ test "openat" {
11871187 const flags: u32 = os.O_CLOEXEC | os.O_RDWR | os.O_CREAT;
11881188 const mode: os.mode_t = 0o666;
11891189 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{
11911191 .opcode = .OPENAT,
11921192 .flags = 0,
11931193 .ioprio = 0,
......@@ -1202,10 +1202,10 @@ test "openat" {
12021202 .splice_fd_in = 0,
12031203 .__pad2 = [2]u64{ 0, 0 },
12041204 }, sqe_openat.*);
1205 testing.expectEqual(@as(u32, 1), try ring.submit());
1205 try testing.expectEqual(@as(u32, 1), try ring.submit());
12061206
12071207 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);
12091209 if (cqe_openat.res == -linux.EINVAL) return error.SkipZigTest;
12101210 // AT_FDCWD is not fully supported before kernel 5.6:
12111211 // See https://lore.kernel.org/io-uring/20200207155039.12819-1-axboe@kernel.dk/T/
......@@ -1214,8 +1214,8 @@ test "openat" {
12141214 return error.SkipZigTest;
12151215 }
12161216 if (cqe_openat.res <= 0) std.debug.print("\ncqe_openat.res={}\n", .{cqe_openat.res});
1217 testing.expect(cqe_openat.res > 0);
1218 testing.expectEqual(@as(u32, 0), cqe_openat.flags);
1217 try testing.expect(cqe_openat.res > 0);
1218 try testing.expectEqual(@as(u32, 0), cqe_openat.flags);
12191219
12201220 os.close(cqe_openat.res);
12211221}
......@@ -1236,13 +1236,13 @@ test "close" {
12361236 defer std.fs.cwd().deleteFile(path) catch {};
12371237
12381238 const sqe_close = try ring.close(0x44444444, file.handle);
1239 testing.expectEqual(linux.IORING_OP.CLOSE, sqe_close.opcode);
1240 testing.expectEqual(file.handle, sqe_close.fd);
1241 testing.expectEqual(@as(u32, 1), try ring.submit());
1239 try testing.expectEqual(linux.IORING_OP.CLOSE, sqe_close.opcode);
1240 try testing.expectEqual(file.handle, sqe_close.fd);
1241 try testing.expectEqual(@as(u32, 1), try ring.submit());
12421242
12431243 const cqe_close = try ring.copy_cqe();
12441244 if (cqe_close.res == -linux.EINVAL) return error.SkipZigTest;
1245 testing.expectEqual(linux.io_uring_cqe{
1245 try testing.expectEqual(linux.io_uring_cqe{
12461246 .user_data = 0x44444444,
12471247 .res = 0,
12481248 .flags = 0,
......@@ -1273,12 +1273,12 @@ test "accept/connect/send/recv" {
12731273 var accept_addr: os.sockaddr = undefined;
12741274 var accept_addr_len: os.socklen_t = @sizeOf(@TypeOf(accept_addr));
12751275 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
12781278 const client = try os.socket(address.any.family, os.SOCK_STREAM | os.SOCK_CLOEXEC, 0);
12791279 defer os.close(client);
12801280 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
12831283 var cqe_accept = try ring.copy_cqe();
12841284 if (cqe_accept.res == -linux.EINVAL) return error.SkipZigTest;
......@@ -1293,11 +1293,11 @@ test "accept/connect/send/recv" {
12931293 cqe_connect = a;
12941294 }
12951295
1296 testing.expectEqual(@as(u64, 0xaaaaaaaa), cqe_accept.user_data);
1296 try testing.expectEqual(@as(u64, 0xaaaaaaaa), cqe_accept.user_data);
12971297 if (cqe_accept.res <= 0) std.debug.print("\ncqe_accept.res={}\n", .{cqe_accept.res});
1298 testing.expect(cqe_accept.res > 0);
1299 testing.expectEqual(@as(u32, 0), cqe_accept.flags);
1300 testing.expectEqual(linux.io_uring_cqe{
1298 try testing.expect(cqe_accept.res > 0);
1299 try testing.expectEqual(@as(u32, 0), cqe_accept.flags);
1300 try testing.expectEqual(linux.io_uring_cqe{
13011301 .user_data = 0xcccccccc,
13021302 .res = 0,
13031303 .flags = 0,
......@@ -1306,11 +1306,11 @@ test "accept/connect/send/recv" {
13061306 const send = try ring.send(0xeeeeeeee, client, buffer_send[0..], 0);
13071307 send.flags |= linux.IOSQE_IO_LINK;
13081308 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
13111311 const cqe_send = try ring.copy_cqe();
13121312 if (cqe_send.res == -linux.EINVAL) return error.SkipZigTest;
1313 testing.expectEqual(linux.io_uring_cqe{
1313 try testing.expectEqual(linux.io_uring_cqe{
13141314 .user_data = 0xeeeeeeee,
13151315 .res = buffer_send.len,
13161316 .flags = 0,
......@@ -1318,13 +1318,13 @@ test "accept/connect/send/recv" {
13181318
13191319 const cqe_recv = try ring.copy_cqe();
13201320 if (cqe_recv.res == -linux.EINVAL) return error.SkipZigTest;
1321 testing.expectEqual(linux.io_uring_cqe{
1321 try testing.expectEqual(linux.io_uring_cqe{
13221322 .user_data = 0xffffffff,
13231323 .res = buffer_recv.len,
13241324 .flags = 0,
13251325 }, 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..]);
13281328}
13291329
13301330test "timeout (after a relative time)" {
......@@ -1343,12 +1343,12 @@ test "timeout (after a relative time)" {
13431343
13441344 const started = std.time.milliTimestamp();
13451345 const sqe = try ring.timeout(0x55555555, &ts, 0, 0);
1346 testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe.opcode);
1347 testing.expectEqual(@as(u32, 1), try ring.submit());
1346 try testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe.opcode);
1347 try testing.expectEqual(@as(u32, 1), try ring.submit());
13481348 const cqe = try ring.copy_cqe();
13491349 const stopped = std.time.milliTimestamp();
13501350
1351 testing.expectEqual(linux.io_uring_cqe{
1351 try testing.expectEqual(linux.io_uring_cqe{
13521352 .user_data = 0x55555555,
13531353 .res = -linux.ETIME,
13541354 .flags = 0,
......@@ -1371,20 +1371,20 @@ test "timeout (after a number of completions)" {
13711371 const ts = os.__kernel_timespec{ .tv_sec = 3, .tv_nsec = 0 };
13721372 const count_completions: u64 = 1;
13731373 const sqe_timeout = try ring.timeout(0x66666666, &ts, count_completions, 0);
1374 testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe_timeout.opcode);
1375 testing.expectEqual(count_completions, sqe_timeout.off);
1374 try testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe_timeout.opcode);
1375 try testing.expectEqual(count_completions, sqe_timeout.off);
13761376 _ = try ring.nop(0x77777777);
1377 testing.expectEqual(@as(u32, 2), try ring.submit());
1377 try testing.expectEqual(@as(u32, 2), try ring.submit());
13781378
13791379 const cqe_nop = try ring.copy_cqe();
1380 testing.expectEqual(linux.io_uring_cqe{
1380 try testing.expectEqual(linux.io_uring_cqe{
13811381 .user_data = 0x77777777,
13821382 .res = 0,
13831383 .flags = 0,
13841384 }, cqe_nop);
13851385
13861386 const cqe_timeout = try ring.copy_cqe();
1387 testing.expectEqual(linux.io_uring_cqe{
1387 try testing.expectEqual(linux.io_uring_cqe{
13881388 .user_data = 0x66666666,
13891389 .res = 0,
13901390 .flags = 0,
......@@ -1403,15 +1403,15 @@ test "timeout_remove" {
14031403
14041404 const ts = os.__kernel_timespec{ .tv_sec = 3, .tv_nsec = 0 };
14051405 const sqe_timeout = try ring.timeout(0x88888888, &ts, 0, 0);
1406 testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe_timeout.opcode);
1407 testing.expectEqual(@as(u64, 0x88888888), sqe_timeout.user_data);
1406 try testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe_timeout.opcode);
1407 try testing.expectEqual(@as(u64, 0x88888888), sqe_timeout.user_data);
14081408
14091409 const sqe_timeout_remove = try ring.timeout_remove(0x99999999, 0x88888888, 0);
1410 testing.expectEqual(linux.IORING_OP.TIMEOUT_REMOVE, sqe_timeout_remove.opcode);
1411 testing.expectEqual(@as(u64, 0x88888888), sqe_timeout_remove.addr);
1412 testing.expectEqual(@as(u64, 0x99999999), sqe_timeout_remove.user_data);
1410 try testing.expectEqual(linux.IORING_OP.TIMEOUT_REMOVE, sqe_timeout_remove.opcode);
1411 try testing.expectEqual(@as(u64, 0x88888888), sqe_timeout_remove.addr);
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
14161416 const cqe_timeout = try ring.copy_cqe();
14171417 // IORING_OP_TIMEOUT_REMOVE is not supported by this kernel version:
......@@ -1424,14 +1424,14 @@ test "timeout_remove" {
14241424 {
14251425 return error.SkipZigTest;
14261426 }
1427 testing.expectEqual(linux.io_uring_cqe{
1427 try testing.expectEqual(linux.io_uring_cqe{
14281428 .user_data = 0x88888888,
14291429 .res = -linux.ECANCELED,
14301430 .flags = 0,
14311431 }, cqe_timeout);
14321432
14331433 const cqe_timeout_remove = try ring.copy_cqe();
1434 testing.expectEqual(linux.io_uring_cqe{
1434 try testing.expectEqual(linux.io_uring_cqe{
14351435 .user_data = 0x99999999,
14361436 .res = 0,
14371437 .flags = 0,
......@@ -1453,13 +1453,13 @@ test "fallocate" {
14531453 defer file.close();
14541454 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
14581458 const len: u64 = 65536;
14591459 const sqe = try ring.fallocate(0xaaaaaaaa, file.handle, 0, 0, len);
1460 testing.expectEqual(linux.IORING_OP.FALLOCATE, sqe.opcode);
1461 testing.expectEqual(file.handle, sqe.fd);
1462 testing.expectEqual(@as(u32, 1), try ring.submit());
1460 try testing.expectEqual(linux.IORING_OP.FALLOCATE, sqe.opcode);
1461 try testing.expectEqual(file.handle, sqe.fd);
1462 try testing.expectEqual(@as(u32, 1), try ring.submit());
14631463
14641464 const cqe = try ring.copy_cqe();
14651465 switch (-cqe.res) {
......@@ -1473,11 +1473,11 @@ test "fallocate" {
14731473 linux.EOPNOTSUPP => return error.SkipZigTest,
14741474 else => |errno| std.debug.panic("unhandled errno: {}", .{errno}),
14751475 }
1476 testing.expectEqual(linux.io_uring_cqe{
1476 try testing.expectEqual(linux.io_uring_cqe{
14771477 .user_data = 0xaaaaaaaa,
14781478 .res = 0,
14791479 .flags = 0,
14801480 }, cqe);
14811481
1482 testing.expectEqual(len, (try file.stat()).size);
1482 try testing.expectEqual(len, (try file.stat()).size);
14831483}
lib/std/os/linux/test.zig+17-17
......@@ -18,7 +18,7 @@ test "fallocate" {
1818 defer file.close();
1919 defer fs.cwd().deleteFile(path) catch {};
2020
21 expect((try file.stat()).size == 0);
21 try expect((try file.stat()).size == 0);
2222
2323 const len: u64 = 65536;
2424 switch (linux.getErrno(linux.fallocate(file.handle, 0, 0, len))) {
......@@ -28,20 +28,20 @@ test "fallocate" {
2828 else => |errno| std.debug.panic("unhandled errno: {}", .{errno}),
2929 }
3030
31 expect((try file.stat()).size == len);
31 try expect((try file.stat()).size == len);
3232}
3333
3434test "getpid" {
35 expect(linux.getpid() != 0);
35 try expect(linux.getpid() != 0);
3636}
3737
3838test "timer" {
3939 const epoll_fd = linux.epoll_create();
4040 var err: usize = linux.getErrno(epoll_fd);
41 expect(err == 0);
41 try expect(err == 0);
4242
4343 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
4646 const time_interval = linux.timespec{
4747 .tv_sec = 0,
......@@ -54,7 +54,7 @@ test "timer" {
5454 };
5555
5656 err = linux.timerfd_settime(@intCast(i32, timer_fd), 0, &new_time, null);
57 expect(err == 0);
57 try expect(err == 0);
5858
5959 var event = linux.epoll_event{
6060 .events = linux.EPOLLIN | linux.EPOLLOUT | linux.EPOLLET,
......@@ -62,7 +62,7 @@ test "timer" {
6262 };
6363
6464 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
6767 const events_one: linux.epoll_event = undefined;
6868 var events = [_]linux.epoll_event{events_one} ** 8;
......@@ -93,18 +93,18 @@ test "statx" {
9393 else => unreachable,
9494 }
9595
96 expect(stat_buf.mode == statx_buf.mode);
97 expect(@bitCast(u32, stat_buf.uid) == statx_buf.uid);
98 expect(@bitCast(u32, stat_buf.gid) == statx_buf.gid);
99 expect(@bitCast(u64, @as(i64, stat_buf.size)) == statx_buf.size);
100 expect(@bitCast(u64, @as(i64, stat_buf.blksize)) == statx_buf.blksize);
101 expect(@bitCast(u64, @as(i64, stat_buf.blocks)) == statx_buf.blocks);
96 try expect(stat_buf.mode == statx_buf.mode);
97 try expect(@bitCast(u32, stat_buf.uid) == statx_buf.uid);
98 try expect(@bitCast(u32, stat_buf.gid) == statx_buf.gid);
99 try expect(@bitCast(u64, @as(i64, stat_buf.size)) == statx_buf.size);
100 try expect(@bitCast(u64, @as(i64, stat_buf.blksize)) == statx_buf.blksize);
101 try expect(@bitCast(u64, @as(i64, stat_buf.blocks)) == statx_buf.blocks);
102102}
103103
104104test "user and group ids" {
105105 if (builtin.link_libc) return error.SkipZigTest;
106 expectEqual(linux.getauxval(elf.AT_UID), linux.getuid());
107 expectEqual(linux.getauxval(elf.AT_GID), linux.getgid());
108 expectEqual(linux.getauxval(elf.AT_EUID), linux.geteuid());
109 expectEqual(linux.getauxval(elf.AT_EGID), linux.getegid());
106 try expectEqual(linux.getauxval(elf.AT_UID), linux.getuid());
107 try expectEqual(linux.getauxval(elf.AT_GID), linux.getgid());
108 try expectEqual(linux.getauxval(elf.AT_EUID), linux.geteuid());
109 try expectEqual(linux.getauxval(elf.AT_EGID), linux.getegid());
110110}
lib/std/os/test.zig+51-51
......@@ -37,7 +37,7 @@ test "chdir smoke test" {
3737 try os.chdir(old_cwd);
3838 var new_cwd_buf: [fs.MAX_PATH_BYTES]u8 = undefined;
3939 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));
4141 }
4242 {
4343 // Next, change current working directory to one level above
......@@ -45,7 +45,7 @@ test "chdir smoke test" {
4545 try os.chdir(parent);
4646 var new_cwd_buf: [fs.MAX_PATH_BYTES]u8 = undefined;
4747 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));
4949 }
5050}
5151
......@@ -77,7 +77,7 @@ test "open smoke test" {
7777
7878 // Try this again with the same flags. This op should fail with error.PathAlreadyExists.
7979 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
8282 // Try opening without `O_EXCL` flag.
8383 file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_file" });
......@@ -86,7 +86,7 @@ test "open smoke test" {
8686
8787 // Try opening as a directory which should fail.
8888 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
9191 // Create some directory
9292 file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_dir" });
......@@ -99,7 +99,7 @@ test "open smoke test" {
9999
100100 // Try opening as file which should fail.
101101 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));
103103}
104104
105105test "openat smoke test" {
......@@ -118,14 +118,14 @@ test "openat smoke test" {
118118 os.close(fd);
119119
120120 // 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
123123 // Try opening without `O_EXCL` flag.
124124 fd = try os.openat(tmp.dir.fd, "some_file", os.O_RDWR | os.O_CREAT, mode);
125125 os.close(fd);
126126
127127 // 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
130130 // Create some directory
131131 try os.mkdirat(tmp.dir.fd, "some_dir", mode);
......@@ -135,7 +135,7 @@ test "openat smoke test" {
135135 os.close(fd);
136136
137137 // 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));
139139}
140140
141141test "symlink with relative paths" {
......@@ -169,7 +169,7 @@ test "symlink with relative paths" {
169169
170170 var buffer: [fs.MAX_PATH_BYTES]u8 = undefined;
171171 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
174174 try cwd.deleteFile("file.txt");
175175 try cwd.deleteFile("symlinked");
......@@ -186,7 +186,7 @@ test "readlink on Windows" {
186186fn testReadlink(target_path: []const u8, symlink_path: []const u8) !void {
187187 var buffer: [fs.MAX_PATH_BYTES]u8 = undefined;
188188 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));
190190}
191191
192192test "link with relative paths" {
......@@ -209,15 +209,15 @@ test "link with relative paths" {
209209 const estat = try os.fstat(efd.handle);
210210 const nstat = try os.fstat(nfd.handle);
211211
212 testing.expectEqual(estat.ino, nstat.ino);
213 testing.expectEqual(@as(usize, 2), nstat.nlink);
212 try testing.expectEqual(estat.ino, nstat.ino);
213 try testing.expectEqual(@as(usize, 2), nstat.nlink);
214214 }
215215
216216 try os.unlink("new.txt");
217217
218218 {
219219 const estat = try os.fstat(efd.handle);
220 testing.expectEqual(@as(usize, 1), estat.nlink);
220 try testing.expectEqual(@as(usize, 1), estat.nlink);
221221 }
222222
223223 try cwd.deleteFile("example.txt");
......@@ -244,15 +244,15 @@ test "linkat with different directories" {
244244 const estat = try os.fstat(efd.handle);
245245 const nstat = try os.fstat(nfd.handle);
246246
247 testing.expectEqual(estat.ino, nstat.ino);
248 testing.expectEqual(@as(usize, 2), nstat.nlink);
247 try testing.expectEqual(estat.ino, nstat.ino);
248 try testing.expectEqual(@as(usize, 2), nstat.nlink);
249249 }
250250
251251 try os.unlinkat(tmp.dir.fd, "new.txt", 0);
252252
253253 {
254254 const estat = try os.fstat(efd.handle);
255 testing.expectEqual(@as(usize, 1), estat.nlink);
255 try testing.expectEqual(@as(usize, 1), estat.nlink);
256256 }
257257
258258 try cwd.deleteFile("example.txt");
......@@ -281,7 +281,7 @@ test "fstatat" {
281281 // now repeat but using `fstatat` instead
282282 const flags = if (builtin.os.tag == .wasi) 0x0 else os.AT_SYMLINK_NOFOLLOW;
283283 const statat = try os.fstatat(tmp.dir.fd, "file.txt", flags);
284 expectEqual(stat, statat);
284 try expectEqual(stat, statat);
285285}
286286
287287test "readlinkat" {
......@@ -310,7 +310,7 @@ test "readlinkat" {
310310 // read the link
311311 var buffer: [fs.MAX_PATH_BYTES]u8 = undefined;
312312 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));
314314}
315315
316316fn testThreadIdFn(thread_id: *Thread.Id) void {
......@@ -325,13 +325,13 @@ test "std.Thread.getCurrentId" {
325325 const thread_id = thread.handle();
326326 thread.wait();
327327 if (Thread.use_pthreads) {
328 expect(thread_current_id == thread_id);
328 try expect(thread_current_id == thread_id);
329329 } else if (builtin.os.tag == .windows) {
330 expect(Thread.getCurrentId() != thread_current_id);
330 try expect(Thread.getCurrentId() != thread_current_id);
331331 } else {
332332 // If the thread completes very quickly, then thread_id can be 0. See the
333333 // 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);
335335 }
336336}
337337
......@@ -350,7 +350,7 @@ test "spawn threads" {
350350 thread3.wait();
351351 thread4.wait();
352352
353 expect(shared_ctx == 4);
353 try expect(shared_ctx == 4);
354354}
355355
356356fn start1(ctx: void) u8 {
......@@ -366,23 +366,23 @@ test "cpu count" {
366366 if (builtin.os.tag == .wasi) return error.SkipZigTest;
367367
368368 const cpu_count = try Thread.cpuCount();
369 expect(cpu_count >= 1);
369 try expect(cpu_count >= 1);
370370}
371371
372372test "thread local storage" {
373373 if (builtin.single_threaded) return error.SkipZigTest;
374374 const thread1 = try Thread.spawn(testTls, {});
375375 const thread2 = try Thread.spawn(testTls, {});
376 testTls({});
376 try testTls({});
377377 thread1.wait();
378378 thread2.wait();
379379}
380380
381381threadlocal var x: i32 = 1234;
382fn testTls(context: void) void {
383 if (x != 1234) @panic("bad start value");
382fn testTls(context: void) !void {
383 if (x != 1234) return error.TlsBadStartValue;
384384 x += 1;
385 if (x != 1235) @panic("bad end value");
385 if (x != 1235) return error.TlsBadEndValue;
386386}
387387
388388test "getrandom" {
......@@ -392,7 +392,7 @@ test "getrandom" {
392392 try os.getrandom(&buf_b);
393393 // If this test fails the chance is significantly higher that there is a bug than
394394 // 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));
396396}
397397
398398test "getcwd" {
......@@ -411,7 +411,7 @@ test "sigaltstack" {
411411 // Setting a stack size less than MINSIGSTKSZ returns ENOMEM
412412 st.ss_flags = 0;
413413 st.ss_size = 1;
414 testing.expectError(error.SizeTooSmall, os.sigaltstack(&st, null));
414 try testing.expectError(error.SizeTooSmall, os.sigaltstack(&st, null));
415415}
416416
417417// If the type is not available use void to avoid erroring out when `iter_fn` is
......@@ -462,7 +462,7 @@ test "dl_iterate_phdr" {
462462
463463 var counter: usize = 0;
464464 try os.dl_iterate_phdr(&counter, IterFnError, iter_fn);
465 expect(counter != 0);
465 try expect(counter != 0);
466466}
467467
468468test "gethostname" {
......@@ -471,7 +471,7 @@ test "gethostname" {
471471
472472 var buf: [os.HOST_NAME_MAX]u8 = undefined;
473473 const hostname = try os.gethostname(&buf);
474 expect(hostname.len != 0);
474 try expect(hostname.len != 0);
475475}
476476
477477test "pipe" {
......@@ -479,10 +479,10 @@ test "pipe" {
479479 return error.SkipZigTest;
480480
481481 var fds = try os.pipe();
482 expect((try os.write(fds[1], "hello")) == 5);
482 try expect((try os.write(fds[1], "hello")) == 5);
483483 var buf: [16]u8 = undefined;
484 expect((try os.read(fds[0], buf[0..])) == 5);
485 testing.expectEqualSlices(u8, buf[0..5], "hello");
484 try expect((try os.read(fds[0], buf[0..])) == 5);
485 try testing.expectEqualSlices(u8, buf[0..5], "hello");
486486 os.close(fds[1]);
487487 os.close(fds[0]);
488488}
......@@ -501,13 +501,13 @@ test "memfd_create" {
501501 else => |e| return e,
502502 };
503503 defer std.os.close(fd);
504 expect((try std.os.write(fd, "test")) == 4);
504 try expect((try std.os.write(fd, "test")) == 4);
505505 try std.os.lseek_SET(fd, 0);
506506
507507 var buf: [10]u8 = undefined;
508508 const bytes_read = try std.os.read(fd, &buf);
509 expect(bytes_read == 4);
510 expect(mem.eql(u8, buf[0..4], "test"));
509 try expect(bytes_read == 4);
510 try expect(mem.eql(u8, buf[0..4], "test"));
511511}
512512
513513test "mmap" {
......@@ -529,14 +529,14 @@ test "mmap" {
529529 );
530530 defer os.munmap(data);
531531
532 testing.expectEqual(@as(usize, 1234), data.len);
532 try testing.expectEqual(@as(usize, 1234), data.len);
533533
534534 // 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
537537 // Make sure the memory is writeable as requested
538538 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));
540540 }
541541
542542 const test_out_file = "os_tmp_test";
......@@ -576,7 +576,7 @@ test "mmap" {
576576
577577 var i: u32 = 0;
578578 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));
580580 }
581581 }
582582
......@@ -600,7 +600,7 @@ test "mmap" {
600600
601601 var i: u32 = alloc_size / 2 / @sizeOf(u32);
602602 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));
604604 }
605605 }
606606
......@@ -609,9 +609,9 @@ test "mmap" {
609609
610610test "getenv" {
611611 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);
613613 } else {
614 expect(os.getenvZ("BOGUSDOESNOTEXISTENVVAR") == null);
614 try expect(os.getenvZ("BOGUSDOESNOTEXISTENVVAR") == null);
615615 }
616616}
617617
......@@ -633,17 +633,17 @@ test "fcntl" {
633633 // Note: The test assumes createFile opens the file with O_CLOEXEC
634634 {
635635 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);
637637 }
638638 {
639639 _ = try os.fcntl(file.handle, os.F_SETFD, 0);
640640 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);
642642 }
643643 {
644644 _ = try os.fcntl(file.handle, os.F_SETFD, os.FD_CLOEXEC);
645645 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);
647647 }
648648}
649649
......@@ -748,12 +748,12 @@ test "sigaction" {
748748 os.sigaction(os.SIGUSR1, &sa, null);
749749 // Check that we can read it back correctly.
750750 os.sigaction(os.SIGUSR1, null, &old_sa);
751 testing.expectEqual(S.handler, old_sa.handler.sigaction.?);
752 testing.expect((old_sa.flags & os.SA_SIGINFO) != 0);
751 try testing.expectEqual(S.handler, old_sa.handler.sigaction.?);
752 try testing.expect((old_sa.flags & os.SA_SIGINFO) != 0);
753753 // Invoke the handler.
754754 try os.raise(os.SIGUSR1);
755 testing.expect(signal_test_failed == false);
755 try testing.expect(signal_test_failed == false);
756756 // Check if the handler has been correctly reset to SIG_DFL
757757 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);
759759}
lib/std/os/windows.zig+3-3
......@@ -997,7 +997,7 @@ test "QueryObjectName" {
997997 var result_path = try QueryObjectName(handle, &out_buffer);
998998 const required_len_in_u16 = result_path.len + @divExact(@ptrToInt(result_path.ptr) - @ptrToInt(&out_buffer), 2) + 1;
999999 //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]));
10011001 //exactly-sufficient size
10021002 _ = try QueryObjectName(handle, out_buffer[0..required_len_in_u16]);
10031003}
......@@ -1155,8 +1155,8 @@ test "GetFinalPathNameByHandle" {
11551155
11561156 const required_len_in_u16 = nt_path.len + @divExact(@ptrToInt(nt_path.ptr) - @ptrToInt(&buffer), 2) + 1;
11571157 //check with insufficient size
1158 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]));
1158 try std.testing.expectError(error.NameTooLong, GetFinalPathNameByHandle(handle, .{ .volume_name = .Nt }, 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
11611161 //check with exactly-sufficient size
11621162 _ = 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" {
353353
354354 const PackedArray = PackedIntArray(I, int_count);
355355 const expected_bytes = ((bits * int_count) + 7) / 8;
356 testing.expect(@sizeOf(PackedArray) == expected_bytes);
356 try testing.expect(@sizeOf(PackedArray) == expected_bytes);
357357
358358 var data = @as(PackedArray, undefined);
359359
......@@ -370,7 +370,7 @@ test "PackedIntArray" {
370370 count = 0;
371371 while (i < data.len()) : (i += 1) {
372372 const val = data.get(i);
373 testing.expect(val == count);
373 try testing.expect(val == count);
374374 if (bits > 0) count +%= 1;
375375 }
376376 }
......@@ -427,7 +427,7 @@ test "PackedIntSlice" {
427427 count = 0;
428428 while (i < data.len()) : (i += 1) {
429429 const val = data.get(i);
430 testing.expect(val == count);
430 try testing.expect(val == count);
431431 if (bits > 0) count +%= 1;
432432 }
433433 }
......@@ -454,48 +454,48 @@ test "PackedIntSlice of PackedInt(Array/Slice)" {
454454
455455 //slice of array
456456 var packed_slice = packed_array.slice(2, 5);
457 testing.expect(packed_slice.len() == 3);
457 try testing.expect(packed_slice.len() == 3);
458458 const ps_bit_count = (bits * packed_slice.len()) + packed_slice.bit_offset;
459459 const ps_expected_bytes = (ps_bit_count + 7) / 8;
460 testing.expect(packed_slice.bytes.len == ps_expected_bytes);
461 testing.expect(packed_slice.get(0) == 2 % limit);
462 testing.expect(packed_slice.get(1) == 3 % limit);
463 testing.expect(packed_slice.get(2) == 4 % limit);
460 try testing.expect(packed_slice.bytes.len == ps_expected_bytes);
461 try testing.expect(packed_slice.get(0) == 2 % limit);
462 try testing.expect(packed_slice.get(1) == 3 % limit);
463 try testing.expect(packed_slice.get(2) == 4 % limit);
464464 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
467467 //write through slice
468 testing.expect(packed_array.get(3) == 7 % limit);
468 try testing.expect(packed_array.get(3) == 7 % limit);
469469
470470 //slice of a slice
471471 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);
473473 const ps2_bit_count = (bits * packed_slice_two.len()) + packed_slice_two.bit_offset;
474474 const ps2_expected_bytes = (ps2_bit_count + 7) / 8;
475 testing.expect(packed_slice_two.bytes.len == ps2_expected_bytes);
476 testing.expect(packed_slice_two.get(1) == 7 % limit);
477 testing.expect(packed_slice_two.get(2) == 4 % limit);
475 try testing.expect(packed_slice_two.bytes.len == ps2_expected_bytes);
476 try testing.expect(packed_slice_two.get(1) == 7 % limit);
477 try testing.expect(packed_slice_two.get(2) == 4 % limit);
478478
479479 //size one case
480480 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);
482482 const ps3_bit_count = (bits * packed_slice_three.len()) + packed_slice_three.bit_offset;
483483 const ps3_expected_bytes = (ps3_bit_count + 7) / 8;
484 testing.expect(packed_slice_three.bytes.len == ps3_expected_bytes);
485 testing.expect(packed_slice_three.get(0) == 7 % limit);
484 try testing.expect(packed_slice_three.bytes.len == ps3_expected_bytes);
485 try testing.expect(packed_slice_three.get(0) == 7 % limit);
486486
487487 //empty slice case
488488 const packed_slice_empty = packed_slice.slice(0, 0);
489 testing.expect(packed_slice_empty.len() == 0);
490 testing.expect(packed_slice_empty.bytes.len == 0);
489 try testing.expect(packed_slice_empty.len() == 0);
490 try testing.expect(packed_slice_empty.bytes.len == 0);
491491
492492 //slicing at byte boundaries
493493 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);
495495 const pse_bit_count = (bits * packed_slice_edge.len()) + packed_slice_edge.bit_offset;
496496 const pse_expected_bytes = (pse_bit_count + 7) / 8;
497 testing.expect(packed_slice_edge.bytes.len == pse_expected_bytes);
498 testing.expect(packed_slice_edge.bit_offset == 0);
497 try testing.expect(packed_slice_edge.bytes.len == pse_expected_bytes);
498 try testing.expect(packed_slice_edge.bit_offset == 0);
499499 }
500500}
501501
......@@ -543,7 +543,7 @@ test "PackedInt(Array/Slice) sliceCast" {
543543 .Big => 0b01,
544544 .Little => 0b10,
545545 };
546 testing.expect(packed_slice_cast_2.get(i) == val);
546 try testing.expect(packed_slice_cast_2.get(i) == val);
547547 }
548548 i = 0;
549549 while (i < packed_slice_cast_4.len()) : (i += 1) {
......@@ -551,12 +551,12 @@ test "PackedInt(Array/Slice) sliceCast" {
551551 .Big => 0b0101,
552552 .Little => 0b1010,
553553 };
554 testing.expect(packed_slice_cast_4.get(i) == val);
554 try testing.expect(packed_slice_cast_4.get(i) == val);
555555 }
556556 i = 0;
557557 while (i < packed_slice_cast_9.len()) : (i += 1) {
558558 const val = 0b010101010;
559 testing.expect(packed_slice_cast_9.get(i) == val);
559 try testing.expect(packed_slice_cast_9.get(i) == val);
560560 packed_slice_cast_9.set(i, 0b111000111);
561561 }
562562 i = 0;
......@@ -565,7 +565,7 @@ test "PackedInt(Array/Slice) sliceCast" {
565565 .Big => if (i % 2 == 0) @as(u3, 0b111) else @as(u3, 0b000),
566566 .Little => if (i % 2 == 0) @as(u3, 0b111) else @as(u3, 0b000),
567567 };
568 testing.expect(packed_slice_cast_3.get(i) == val);
568 try testing.expect(packed_slice_cast_3.get(i) == val);
569569 }
570570}
571571
......@@ -575,58 +575,58 @@ test "PackedInt(Array/Slice)Endian" {
575575 {
576576 const PackedArrayBe = PackedIntArrayEndian(u4, .Big, 8);
577577 var packed_array_be = PackedArrayBe.init([_]u4{ 0, 1, 2, 3, 4, 5, 6, 7 });
578 testing.expect(packed_array_be.bytes[0] == 0b00000001);
579 testing.expect(packed_array_be.bytes[1] == 0b00100011);
578 try testing.expect(packed_array_be.bytes[0] == 0b00000001);
579 try testing.expect(packed_array_be.bytes[1] == 0b00100011);
580580
581581 var i = @as(usize, 0);
582582 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);
584584 }
585585
586586 var packed_slice_le = packed_array_be.sliceCastEndian(u4, .Little);
587587 i = 0;
588588 while (i < packed_slice_le.len()) : (i += 1) {
589589 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);
591591 }
592592
593593 var packed_slice_le_shift = packed_array_be.slice(1, 5).sliceCastEndian(u4, .Little);
594594 i = 0;
595595 while (i < packed_slice_le_shift.len()) : (i += 1) {
596596 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);
598598 }
599599 }
600600
601601 {
602602 const PackedArrayBe = PackedIntArrayEndian(u11, .Big, 8);
603603 var packed_array_be = PackedArrayBe.init([_]u11{ 0, 1, 2, 3, 4, 5, 6, 7 });
604 testing.expect(packed_array_be.bytes[0] == 0b00000000);
605 testing.expect(packed_array_be.bytes[1] == 0b00000000);
606 testing.expect(packed_array_be.bytes[2] == 0b00000100);
607 testing.expect(packed_array_be.bytes[3] == 0b00000001);
608 testing.expect(packed_array_be.bytes[4] == 0b00000000);
604 try testing.expect(packed_array_be.bytes[0] == 0b00000000);
605 try testing.expect(packed_array_be.bytes[1] == 0b00000000);
606 try testing.expect(packed_array_be.bytes[2] == 0b00000100);
607 try testing.expect(packed_array_be.bytes[3] == 0b00000001);
608 try testing.expect(packed_array_be.bytes[4] == 0b00000000);
609609
610610 var i = @as(usize, 0);
611611 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);
613613 }
614614
615615 var packed_slice_le = packed_array_be.sliceCastEndian(u11, .Little);
616 testing.expect(packed_slice_le.get(0) == 0b00000000000);
617 testing.expect(packed_slice_le.get(1) == 0b00010000000);
618 testing.expect(packed_slice_le.get(2) == 0b00000000100);
619 testing.expect(packed_slice_le.get(3) == 0b00000000000);
620 testing.expect(packed_slice_le.get(4) == 0b00010000011);
621 testing.expect(packed_slice_le.get(5) == 0b00000000010);
622 testing.expect(packed_slice_le.get(6) == 0b10000010000);
623 testing.expect(packed_slice_le.get(7) == 0b00000111001);
616 try testing.expect(packed_slice_le.get(0) == 0b00000000000);
617 try testing.expect(packed_slice_le.get(1) == 0b00010000000);
618 try testing.expect(packed_slice_le.get(2) == 0b00000000100);
619 try testing.expect(packed_slice_le.get(3) == 0b00000000000);
620 try testing.expect(packed_slice_le.get(4) == 0b00010000011);
621 try testing.expect(packed_slice_le.get(5) == 0b00000000010);
622 try testing.expect(packed_slice_le.get(6) == 0b10000010000);
623 try testing.expect(packed_slice_le.get(7) == 0b00000111001);
624624
625625 var packed_slice_le_shift = packed_array_be.slice(1, 5).sliceCastEndian(u11, .Little);
626 testing.expect(packed_slice_le_shift.get(0) == 0b00010000000);
627 testing.expect(packed_slice_le_shift.get(1) == 0b00000000100);
628 testing.expect(packed_slice_le_shift.get(2) == 0b00000000000);
629 testing.expect(packed_slice_le_shift.get(3) == 0b00010000011);
626 try testing.expect(packed_slice_le_shift.get(0) == 0b00010000000);
627 try testing.expect(packed_slice_le_shift.get(1) == 0b00000000100);
628 try testing.expect(packed_slice_le_shift.get(2) == 0b00000000000);
629 try testing.expect(packed_slice_le_shift.get(3) == 0b00010000011);
630630 }
631631}
632632
lib/std/priority_dequeue.zig+89-89
......@@ -482,12 +482,12 @@ test "std.PriorityDequeue: add and remove min" {
482482 try queue.add(25);
483483 try queue.add(13);
484484
485 expectEqual(@as(u32, 7), queue.removeMin());
486 expectEqual(@as(u32, 12), queue.removeMin());
487 expectEqual(@as(u32, 13), queue.removeMin());
488 expectEqual(@as(u32, 23), queue.removeMin());
489 expectEqual(@as(u32, 25), queue.removeMin());
490 expectEqual(@as(u32, 54), queue.removeMin());
485 try expectEqual(@as(u32, 7), queue.removeMin());
486 try expectEqual(@as(u32, 12), queue.removeMin());
487 try expectEqual(@as(u32, 13), queue.removeMin());
488 try expectEqual(@as(u32, 23), queue.removeMin());
489 try expectEqual(@as(u32, 25), queue.removeMin());
490 try expectEqual(@as(u32, 54), queue.removeMin());
491491}
492492
493493test "std.PriorityDequeue: add and remove min structs" {
......@@ -508,12 +508,12 @@ test "std.PriorityDequeue: add and remove min structs" {
508508 try queue.add(.{ .size = 25 });
509509 try queue.add(.{ .size = 13 });
510510
511 expectEqual(@as(u32, 7), queue.removeMin().size);
512 expectEqual(@as(u32, 12), queue.removeMin().size);
513 expectEqual(@as(u32, 13), queue.removeMin().size);
514 expectEqual(@as(u32, 23), queue.removeMin().size);
515 expectEqual(@as(u32, 25), queue.removeMin().size);
516 expectEqual(@as(u32, 54), queue.removeMin().size);
511 try expectEqual(@as(u32, 7), queue.removeMin().size);
512 try expectEqual(@as(u32, 12), queue.removeMin().size);
513 try expectEqual(@as(u32, 13), queue.removeMin().size);
514 try expectEqual(@as(u32, 23), queue.removeMin().size);
515 try expectEqual(@as(u32, 25), queue.removeMin().size);
516 try expectEqual(@as(u32, 54), queue.removeMin().size);
517517}
518518
519519test "std.PriorityDequeue: add and remove max" {
......@@ -527,12 +527,12 @@ test "std.PriorityDequeue: add and remove max" {
527527 try queue.add(25);
528528 try queue.add(13);
529529
530 expectEqual(@as(u32, 54), queue.removeMax());
531 expectEqual(@as(u32, 25), queue.removeMax());
532 expectEqual(@as(u32, 23), queue.removeMax());
533 expectEqual(@as(u32, 13), queue.removeMax());
534 expectEqual(@as(u32, 12), queue.removeMax());
535 expectEqual(@as(u32, 7), queue.removeMax());
530 try expectEqual(@as(u32, 54), queue.removeMax());
531 try expectEqual(@as(u32, 25), queue.removeMax());
532 try expectEqual(@as(u32, 23), queue.removeMax());
533 try expectEqual(@as(u32, 13), queue.removeMax());
534 try expectEqual(@as(u32, 12), queue.removeMax());
535 try expectEqual(@as(u32, 7), queue.removeMax());
536536}
537537
538538test "std.PriorityDequeue: add and remove same min" {
......@@ -546,12 +546,12 @@ test "std.PriorityDequeue: add and remove same min" {
546546 try queue.add(1);
547547 try queue.add(1);
548548
549 expectEqual(@as(u32, 1), queue.removeMin());
550 expectEqual(@as(u32, 1), queue.removeMin());
551 expectEqual(@as(u32, 1), queue.removeMin());
552 expectEqual(@as(u32, 1), queue.removeMin());
553 expectEqual(@as(u32, 2), queue.removeMin());
554 expectEqual(@as(u32, 2), queue.removeMin());
549 try expectEqual(@as(u32, 1), queue.removeMin());
550 try expectEqual(@as(u32, 1), queue.removeMin());
551 try expectEqual(@as(u32, 1), queue.removeMin());
552 try expectEqual(@as(u32, 1), queue.removeMin());
553 try expectEqual(@as(u32, 2), queue.removeMin());
554 try expectEqual(@as(u32, 2), queue.removeMin());
555555}
556556
557557test "std.PriorityDequeue: add and remove same max" {
......@@ -565,20 +565,20 @@ test "std.PriorityDequeue: add and remove same max" {
565565 try queue.add(1);
566566 try queue.add(1);
567567
568 expectEqual(@as(u32, 2), queue.removeMax());
569 expectEqual(@as(u32, 2), queue.removeMax());
570 expectEqual(@as(u32, 1), queue.removeMax());
571 expectEqual(@as(u32, 1), queue.removeMax());
572 expectEqual(@as(u32, 1), queue.removeMax());
573 expectEqual(@as(u32, 1), queue.removeMax());
568 try expectEqual(@as(u32, 2), queue.removeMax());
569 try expectEqual(@as(u32, 2), queue.removeMax());
570 try expectEqual(@as(u32, 1), queue.removeMax());
571 try expectEqual(@as(u32, 1), queue.removeMax());
572 try expectEqual(@as(u32, 1), queue.removeMax());
573 try expectEqual(@as(u32, 1), queue.removeMax());
574574}
575575
576576test "std.PriorityDequeue: removeOrNull empty" {
577577 var queue = PDQ.init(testing.allocator, lessThanComparison);
578578 defer queue.deinit();
579579
580 expect(queue.removeMinOrNull() == null);
581 expect(queue.removeMaxOrNull() == null);
580 try expect(queue.removeMinOrNull() == null);
581 try expect(queue.removeMaxOrNull() == null);
582582}
583583
584584test "std.PriorityDequeue: edge case 3 elements" {
......@@ -589,9 +589,9 @@ test "std.PriorityDequeue: edge case 3 elements" {
589589 try queue.add(3);
590590 try queue.add(2);
591591
592 expectEqual(@as(u32, 2), queue.removeMin());
593 expectEqual(@as(u32, 3), queue.removeMin());
594 expectEqual(@as(u32, 9), queue.removeMin());
592 try expectEqual(@as(u32, 2), queue.removeMin());
593 try expectEqual(@as(u32, 3), queue.removeMin());
594 try expectEqual(@as(u32, 9), queue.removeMin());
595595}
596596
597597test "std.PriorityDequeue: edge case 3 elements max" {
......@@ -602,37 +602,37 @@ test "std.PriorityDequeue: edge case 3 elements max" {
602602 try queue.add(3);
603603 try queue.add(2);
604604
605 expectEqual(@as(u32, 9), queue.removeMax());
606 expectEqual(@as(u32, 3), queue.removeMax());
607 expectEqual(@as(u32, 2), queue.removeMax());
605 try expectEqual(@as(u32, 9), queue.removeMax());
606 try expectEqual(@as(u32, 3), queue.removeMax());
607 try expectEqual(@as(u32, 2), queue.removeMax());
608608}
609609
610610test "std.PriorityDequeue: peekMin" {
611611 var queue = PDQ.init(testing.allocator, lessThanComparison);
612612 defer queue.deinit();
613613
614 expect(queue.peekMin() == null);
614 try expect(queue.peekMin() == null);
615615
616616 try queue.add(9);
617617 try queue.add(3);
618618 try queue.add(2);
619619
620 expect(queue.peekMin().? == 2);
621 expect(queue.peekMin().? == 2);
620 try expect(queue.peekMin().? == 2);
621 try expect(queue.peekMin().? == 2);
622622}
623623
624624test "std.PriorityDequeue: peekMax" {
625625 var queue = PDQ.init(testing.allocator, lessThanComparison);
626626 defer queue.deinit();
627627
628 expect(queue.peekMin() == null);
628 try expect(queue.peekMin() == null);
629629
630630 try queue.add(9);
631631 try queue.add(3);
632632 try queue.add(2);
633633
634 expect(queue.peekMax().? == 9);
635 expect(queue.peekMax().? == 9);
634 try expect(queue.peekMax().? == 9);
635 try expect(queue.peekMax().? == 9);
636636}
637637
638638test "std.PriorityDequeue: sift up with odd indices" {
......@@ -645,7 +645,7 @@ test "std.PriorityDequeue: sift up with odd indices" {
645645
646646 const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
647647 for (sorted_items) |e| {
648 expectEqual(e, queue.removeMin());
648 try expectEqual(e, queue.removeMin());
649649 }
650650}
651651
......@@ -659,7 +659,7 @@ test "std.PriorityDequeue: sift up with odd indices" {
659659
660660 const sorted_items = [_]u32{ 25, 24, 24, 22, 21, 16, 15, 15, 14, 13, 12, 11, 7, 7, 6, 5, 2, 1 };
661661 for (sorted_items) |e| {
662 expectEqual(e, queue.removeMax());
662 try expectEqual(e, queue.removeMax());
663663 }
664664}
665665
......@@ -671,7 +671,7 @@ test "std.PriorityDequeue: addSlice min" {
671671
672672 const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
673673 for (sorted_items) |e| {
674 expectEqual(e, queue.removeMin());
674 try expectEqual(e, queue.removeMin());
675675 }
676676}
677677
......@@ -683,7 +683,7 @@ test "std.PriorityDequeue: addSlice max" {
683683
684684 const sorted_items = [_]u32{ 25, 24, 24, 22, 21, 16, 15, 15, 14, 13, 12, 11, 7, 7, 6, 5, 2, 1 };
685685 for (sorted_items) |e| {
686 expectEqual(e, queue.removeMax());
686 try expectEqual(e, queue.removeMax());
687687 }
688688}
689689
......@@ -692,8 +692,8 @@ test "std.PriorityDequeue: fromOwnedSlice trivial case 0" {
692692 const queue_items = try testing.allocator.dupe(u32, &items);
693693 var queue = PDQ.fromOwnedSlice(testing.allocator, lessThanComparison, queue_items[0..]);
694694 defer queue.deinit();
695 expectEqual(@as(usize, 0), queue.len);
696 expect(queue.removeMinOrNull() == null);
695 try expectEqual(@as(usize, 0), queue.len);
696 try expect(queue.removeMinOrNull() == null);
697697}
698698
699699test "std.PriorityDequeue: fromOwnedSlice trivial case 1" {
......@@ -702,9 +702,9 @@ test "std.PriorityDequeue: fromOwnedSlice trivial case 1" {
702702 var queue = PDQ.fromOwnedSlice(testing.allocator, lessThanComparison, queue_items[0..]);
703703 defer queue.deinit();
704704
705 expectEqual(@as(usize, 1), queue.len);
706 expectEqual(items[0], queue.removeMin());
707 expect(queue.removeMinOrNull() == null);
705 try expectEqual(@as(usize, 1), queue.len);
706 try expectEqual(items[0], queue.removeMin());
707 try expect(queue.removeMinOrNull() == null);
708708}
709709
710710test "std.PriorityDequeue: fromOwnedSlice" {
......@@ -715,7 +715,7 @@ test "std.PriorityDequeue: fromOwnedSlice" {
715715
716716 const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
717717 for (sorted_items) |e| {
718 expectEqual(e, queue.removeMin());
718 try expectEqual(e, queue.removeMin());
719719 }
720720}
721721
......@@ -729,9 +729,9 @@ test "std.PriorityDequeue: update min queue" {
729729 try queue.update(55, 5);
730730 try queue.update(44, 4);
731731 try queue.update(11, 1);
732 expectEqual(@as(u32, 1), queue.removeMin());
733 expectEqual(@as(u32, 4), queue.removeMin());
734 expectEqual(@as(u32, 5), queue.removeMin());
732 try expectEqual(@as(u32, 1), queue.removeMin());
733 try expectEqual(@as(u32, 4), queue.removeMin());
734 try expectEqual(@as(u32, 5), queue.removeMin());
735735}
736736
737737test "std.PriorityDequeue: update same min queue" {
......@@ -744,10 +744,10 @@ test "std.PriorityDequeue: update same min queue" {
744744 try queue.add(2);
745745 try queue.update(1, 5);
746746 try queue.update(2, 4);
747 expectEqual(@as(u32, 1), queue.removeMin());
748 expectEqual(@as(u32, 2), queue.removeMin());
749 expectEqual(@as(u32, 4), queue.removeMin());
750 expectEqual(@as(u32, 5), queue.removeMin());
747 try expectEqual(@as(u32, 1), queue.removeMin());
748 try expectEqual(@as(u32, 2), queue.removeMin());
749 try expectEqual(@as(u32, 4), queue.removeMin());
750 try expectEqual(@as(u32, 5), queue.removeMin());
751751}
752752
753753test "std.PriorityDequeue: update max queue" {
......@@ -761,9 +761,9 @@ test "std.PriorityDequeue: update max queue" {
761761 try queue.update(44, 1);
762762 try queue.update(11, 4);
763763
764 expectEqual(@as(u32, 5), queue.removeMax());
765 expectEqual(@as(u32, 4), queue.removeMax());
766 expectEqual(@as(u32, 1), queue.removeMax());
764 try expectEqual(@as(u32, 5), queue.removeMax());
765 try expectEqual(@as(u32, 4), queue.removeMax());
766 try expectEqual(@as(u32, 1), queue.removeMax());
767767}
768768
769769test "std.PriorityDequeue: update same max queue" {
......@@ -776,10 +776,10 @@ test "std.PriorityDequeue: update same max queue" {
776776 try queue.add(2);
777777 try queue.update(1, 5);
778778 try queue.update(2, 4);
779 expectEqual(@as(u32, 5), queue.removeMax());
780 expectEqual(@as(u32, 4), queue.removeMax());
781 expectEqual(@as(u32, 2), queue.removeMax());
782 expectEqual(@as(u32, 1), queue.removeMax());
779 try expectEqual(@as(u32, 5), queue.removeMax());
780 try expectEqual(@as(u32, 4), queue.removeMax());
781 try expectEqual(@as(u32, 2), queue.removeMax());
782 try expectEqual(@as(u32, 1), queue.removeMax());
783783}
784784
785785test "std.PriorityDequeue: iterator" {
......@@ -801,7 +801,7 @@ test "std.PriorityDequeue: iterator" {
801801 _ = map.remove(e);
802802 }
803803
804 expectEqual(@as(usize, 0), map.count());
804 try expectEqual(@as(usize, 0), map.count());
805805}
806806
807807test "std.PriorityDequeue: remove at index" {
......@@ -821,10 +821,10 @@ test "std.PriorityDequeue: remove at index" {
821821 idx += 1;
822822 } else unreachable;
823823
824 expectEqual(queue.removeIndex(two_idx), 2);
825 expectEqual(queue.removeMin(), 1);
826 expectEqual(queue.removeMin(), 3);
827 expectEqual(queue.removeMinOrNull(), null);
824 try expectEqual(queue.removeIndex(two_idx), 2);
825 try expectEqual(queue.removeMin(), 1);
826 try expectEqual(queue.removeMin(), 3);
827 try expectEqual(queue.removeMinOrNull(), null);
828828}
829829
830830test "std.PriorityDequeue: iterator while empty" {
......@@ -833,7 +833,7 @@ test "std.PriorityDequeue: iterator while empty" {
833833
834834 var it = queue.iterator();
835835
836 expectEqual(it.next(), null);
836 try expectEqual(it.next(), null);
837837}
838838
839839test "std.PriorityDequeue: shrinkRetainingCapacity and shrinkAndFree" {
......@@ -841,26 +841,26 @@ test "std.PriorityDequeue: shrinkRetainingCapacity and shrinkAndFree" {
841841 defer queue.deinit();
842842
843843 try queue.ensureCapacity(4);
844 expect(queue.capacity() >= 4);
844 try expect(queue.capacity() >= 4);
845845
846846 try queue.add(1);
847847 try queue.add(2);
848848 try queue.add(3);
849 expect(queue.capacity() >= 4);
850 expectEqual(@as(usize, 3), queue.len);
849 try expect(queue.capacity() >= 4);
850 try expectEqual(@as(usize, 3), queue.len);
851851
852852 queue.shrinkRetainingCapacity(3);
853 expect(queue.capacity() >= 4);
854 expectEqual(@as(usize, 3), queue.len);
853 try expect(queue.capacity() >= 4);
854 try expectEqual(@as(usize, 3), queue.len);
855855
856856 queue.shrinkAndFree(3);
857 expectEqual(@as(usize, 3), queue.capacity());
858 expectEqual(@as(usize, 3), queue.len);
857 try expectEqual(@as(usize, 3), queue.capacity());
858 try expectEqual(@as(usize, 3), queue.len);
859859
860 expectEqual(@as(u32, 3), queue.removeMax());
861 expectEqual(@as(u32, 2), queue.removeMax());
862 expectEqual(@as(u32, 1), queue.removeMax());
863 expect(queue.removeMaxOrNull() == null);
860 try expectEqual(@as(u32, 3), queue.removeMax());
861 try expectEqual(@as(u32, 2), queue.removeMax());
862 try expectEqual(@as(u32, 1), queue.removeMax());
863 try expect(queue.removeMaxOrNull() == null);
864864}
865865
866866test "std.PriorityDequeue: fuzz testing min" {
......@@ -885,7 +885,7 @@ fn fuzzTestMin(rng: *std.rand.Random, comptime queue_size: usize) !void {
885885 var last_removed: ?u32 = null;
886886 while (queue.removeMinOrNull()) |next| {
887887 if (last_removed) |last| {
888 expect(last <= next);
888 try expect(last <= next);
889889 }
890890 last_removed = next;
891891 }
......@@ -913,7 +913,7 @@ fn fuzzTestMax(rng: *std.rand.Random, queue_size: usize) !void {
913913 var last_removed: ?u32 = null;
914914 while (queue.removeMaxOrNull()) |next| {
915915 if (last_removed) |last| {
916 expect(last >= next);
916 try expect(last >= next);
917917 }
918918 last_removed = next;
919919 }
......@@ -945,13 +945,13 @@ fn fuzzTestMinMax(rng: *std.rand.Random, queue_size: usize) !void {
945945 if (i % 2 == 0) {
946946 const next = queue.removeMin();
947947 if (last_min) |last| {
948 expect(last <= next);
948 try expect(last <= next);
949949 }
950950 last_min = next;
951951 } else {
952952 const next = queue.removeMax();
953953 if (last_max) |last| {
954 expect(last >= next);
954 try expect(last >= next);
955955 }
956956 last_max = next;
957957 }
lib/std/priority_queue.zig+70-70
......@@ -290,12 +290,12 @@ test "std.PriorityQueue: add and remove min heap" {
290290 try queue.add(23);
291291 try queue.add(25);
292292 try queue.add(13);
293 expectEqual(@as(u32, 7), queue.remove());
294 expectEqual(@as(u32, 12), queue.remove());
295 expectEqual(@as(u32, 13), queue.remove());
296 expectEqual(@as(u32, 23), queue.remove());
297 expectEqual(@as(u32, 25), queue.remove());
298 expectEqual(@as(u32, 54), queue.remove());
293 try expectEqual(@as(u32, 7), queue.remove());
294 try expectEqual(@as(u32, 12), queue.remove());
295 try expectEqual(@as(u32, 13), queue.remove());
296 try expectEqual(@as(u32, 23), queue.remove());
297 try expectEqual(@as(u32, 25), queue.remove());
298 try expectEqual(@as(u32, 54), queue.remove());
299299}
300300
301301test "std.PriorityQueue: add and remove same min heap" {
......@@ -308,19 +308,19 @@ test "std.PriorityQueue: add and remove same min heap" {
308308 try queue.add(2);
309309 try queue.add(1);
310310 try queue.add(1);
311 expectEqual(@as(u32, 1), queue.remove());
312 expectEqual(@as(u32, 1), queue.remove());
313 expectEqual(@as(u32, 1), queue.remove());
314 expectEqual(@as(u32, 1), queue.remove());
315 expectEqual(@as(u32, 2), queue.remove());
316 expectEqual(@as(u32, 2), queue.remove());
311 try expectEqual(@as(u32, 1), queue.remove());
312 try expectEqual(@as(u32, 1), queue.remove());
313 try expectEqual(@as(u32, 1), queue.remove());
314 try expectEqual(@as(u32, 1), queue.remove());
315 try expectEqual(@as(u32, 2), queue.remove());
316 try expectEqual(@as(u32, 2), queue.remove());
317317}
318318
319319test "std.PriorityQueue: removeOrNull on empty" {
320320 var queue = PQ.init(testing.allocator, lessThan);
321321 defer queue.deinit();
322322
323 expect(queue.removeOrNull() == null);
323 try expect(queue.removeOrNull() == null);
324324}
325325
326326test "std.PriorityQueue: edge case 3 elements" {
......@@ -330,21 +330,21 @@ test "std.PriorityQueue: edge case 3 elements" {
330330 try queue.add(9);
331331 try queue.add(3);
332332 try queue.add(2);
333 expectEqual(@as(u32, 2), queue.remove());
334 expectEqual(@as(u32, 3), queue.remove());
335 expectEqual(@as(u32, 9), queue.remove());
333 try expectEqual(@as(u32, 2), queue.remove());
334 try expectEqual(@as(u32, 3), queue.remove());
335 try expectEqual(@as(u32, 9), queue.remove());
336336}
337337
338338test "std.PriorityQueue: peek" {
339339 var queue = PQ.init(testing.allocator, lessThan);
340340 defer queue.deinit();
341341
342 expect(queue.peek() == null);
342 try expect(queue.peek() == null);
343343 try queue.add(9);
344344 try queue.add(3);
345345 try queue.add(2);
346 expectEqual(@as(u32, 2), queue.peek().?);
347 expectEqual(@as(u32, 2), queue.peek().?);
346 try expectEqual(@as(u32, 2), queue.peek().?);
347 try expectEqual(@as(u32, 2), queue.peek().?);
348348}
349349
350350test "std.PriorityQueue: sift up with odd indices" {
......@@ -357,7 +357,7 @@ test "std.PriorityQueue: sift up with odd indices" {
357357
358358 const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
359359 for (sorted_items) |e| {
360 expectEqual(e, queue.remove());
360 try expectEqual(e, queue.remove());
361361 }
362362}
363363
......@@ -369,7 +369,7 @@ test "std.PriorityQueue: addSlice" {
369369
370370 const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
371371 for (sorted_items) |e| {
372 expectEqual(e, queue.remove());
372 try expectEqual(e, queue.remove());
373373 }
374374}
375375
......@@ -378,8 +378,8 @@ test "std.PriorityQueue: fromOwnedSlice trivial case 0" {
378378 const queue_items = try testing.allocator.dupe(u32, &items);
379379 var queue = PQ.fromOwnedSlice(testing.allocator, lessThan, queue_items[0..]);
380380 defer queue.deinit();
381 expectEqual(@as(usize, 0), queue.len);
382 expect(queue.removeOrNull() == null);
381 try expectEqual(@as(usize, 0), queue.len);
382 try expect(queue.removeOrNull() == null);
383383}
384384
385385test "std.PriorityQueue: fromOwnedSlice trivial case 1" {
......@@ -388,9 +388,9 @@ test "std.PriorityQueue: fromOwnedSlice trivial case 1" {
388388 var queue = PQ.fromOwnedSlice(testing.allocator, lessThan, queue_items[0..]);
389389 defer queue.deinit();
390390
391 expectEqual(@as(usize, 1), queue.len);
392 expectEqual(items[0], queue.remove());
393 expect(queue.removeOrNull() == null);
391 try expectEqual(@as(usize, 1), queue.len);
392 try expectEqual(items[0], queue.remove());
393 try expect(queue.removeOrNull() == null);
394394}
395395
396396test "std.PriorityQueue: fromOwnedSlice" {
......@@ -401,7 +401,7 @@ test "std.PriorityQueue: fromOwnedSlice" {
401401
402402 const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
403403 for (sorted_items) |e| {
404 expectEqual(e, queue.remove());
404 try expectEqual(e, queue.remove());
405405 }
406406}
407407
......@@ -415,12 +415,12 @@ test "std.PriorityQueue: add and remove max heap" {
415415 try queue.add(23);
416416 try queue.add(25);
417417 try queue.add(13);
418 expectEqual(@as(u32, 54), queue.remove());
419 expectEqual(@as(u32, 25), queue.remove());
420 expectEqual(@as(u32, 23), queue.remove());
421 expectEqual(@as(u32, 13), queue.remove());
422 expectEqual(@as(u32, 12), queue.remove());
423 expectEqual(@as(u32, 7), queue.remove());
418 try expectEqual(@as(u32, 54), queue.remove());
419 try expectEqual(@as(u32, 25), queue.remove());
420 try expectEqual(@as(u32, 23), queue.remove());
421 try expectEqual(@as(u32, 13), queue.remove());
422 try expectEqual(@as(u32, 12), queue.remove());
423 try expectEqual(@as(u32, 7), queue.remove());
424424}
425425
426426test "std.PriorityQueue: add and remove same max heap" {
......@@ -433,12 +433,12 @@ test "std.PriorityQueue: add and remove same max heap" {
433433 try queue.add(2);
434434 try queue.add(1);
435435 try queue.add(1);
436 expectEqual(@as(u32, 2), queue.remove());
437 expectEqual(@as(u32, 2), queue.remove());
438 expectEqual(@as(u32, 1), queue.remove());
439 expectEqual(@as(u32, 1), queue.remove());
440 expectEqual(@as(u32, 1), queue.remove());
441 expectEqual(@as(u32, 1), queue.remove());
436 try expectEqual(@as(u32, 2), queue.remove());
437 try expectEqual(@as(u32, 2), queue.remove());
438 try expectEqual(@as(u32, 1), queue.remove());
439 try expectEqual(@as(u32, 1), queue.remove());
440 try expectEqual(@as(u32, 1), queue.remove());
441 try expectEqual(@as(u32, 1), queue.remove());
442442}
443443
444444test "std.PriorityQueue: iterator" {
......@@ -460,7 +460,7 @@ test "std.PriorityQueue: iterator" {
460460 _ = map.remove(e);
461461 }
462462
463 expectEqual(@as(usize, 0), map.count());
463 try expectEqual(@as(usize, 0), map.count());
464464}
465465
466466test "std.PriorityQueue: remove at index" {
......@@ -480,10 +480,10 @@ test "std.PriorityQueue: remove at index" {
480480 idx += 1;
481481 } else unreachable;
482482
483 expectEqual(queue.removeIndex(two_idx), 2);
484 expectEqual(queue.remove(), 1);
485 expectEqual(queue.remove(), 3);
486 expectEqual(queue.removeOrNull(), null);
483 try expectEqual(queue.removeIndex(two_idx), 2);
484 try expectEqual(queue.remove(), 1);
485 try expectEqual(queue.remove(), 3);
486 try expectEqual(queue.removeOrNull(), null);
487487}
488488
489489test "std.PriorityQueue: iterator while empty" {
......@@ -492,7 +492,7 @@ test "std.PriorityQueue: iterator while empty" {
492492
493493 var it = queue.iterator();
494494
495 expectEqual(it.next(), null);
495 try expectEqual(it.next(), null);
496496}
497497
498498test "std.PriorityQueue: shrinkRetainingCapacity and shrinkAndFree" {
......@@ -500,26 +500,26 @@ test "std.PriorityQueue: shrinkRetainingCapacity and shrinkAndFree" {
500500 defer queue.deinit();
501501
502502 try queue.ensureCapacity(4);
503 expect(queue.capacity() >= 4);
503 try expect(queue.capacity() >= 4);
504504
505505 try queue.add(1);
506506 try queue.add(2);
507507 try queue.add(3);
508 expect(queue.capacity() >= 4);
509 expectEqual(@as(usize, 3), queue.len);
508 try expect(queue.capacity() >= 4);
509 try expectEqual(@as(usize, 3), queue.len);
510510
511511 queue.shrinkRetainingCapacity(3);
512 expect(queue.capacity() >= 4);
513 expectEqual(@as(usize, 3), queue.len);
512 try expect(queue.capacity() >= 4);
513 try expectEqual(@as(usize, 3), queue.len);
514514
515515 queue.shrinkAndFree(3);
516 expectEqual(@as(usize, 3), queue.capacity());
517 expectEqual(@as(usize, 3), queue.len);
516 try expectEqual(@as(usize, 3), queue.capacity());
517 try expectEqual(@as(usize, 3), queue.len);
518518
519 expectEqual(@as(u32, 1), queue.remove());
520 expectEqual(@as(u32, 2), queue.remove());
521 expectEqual(@as(u32, 3), queue.remove());
522 expect(queue.removeOrNull() == null);
519 try expectEqual(@as(u32, 1), queue.remove());
520 try expectEqual(@as(u32, 2), queue.remove());
521 try expectEqual(@as(u32, 3), queue.remove());
522 try expect(queue.removeOrNull() == null);
523523}
524524
525525test "std.PriorityQueue: update min heap" {
......@@ -532,9 +532,9 @@ test "std.PriorityQueue: update min heap" {
532532 try queue.update(55, 5);
533533 try queue.update(44, 4);
534534 try queue.update(11, 1);
535 expectEqual(@as(u32, 1), queue.remove());
536 expectEqual(@as(u32, 4), queue.remove());
537 expectEqual(@as(u32, 5), queue.remove());
535 try expectEqual(@as(u32, 1), queue.remove());
536 try expectEqual(@as(u32, 4), queue.remove());
537 try expectEqual(@as(u32, 5), queue.remove());
538538}
539539
540540test "std.PriorityQueue: update same min heap" {
......@@ -547,10 +547,10 @@ test "std.PriorityQueue: update same min heap" {
547547 try queue.add(2);
548548 try queue.update(1, 5);
549549 try queue.update(2, 4);
550 expectEqual(@as(u32, 1), queue.remove());
551 expectEqual(@as(u32, 2), queue.remove());
552 expectEqual(@as(u32, 4), queue.remove());
553 expectEqual(@as(u32, 5), queue.remove());
550 try expectEqual(@as(u32, 1), queue.remove());
551 try expectEqual(@as(u32, 2), queue.remove());
552 try expectEqual(@as(u32, 4), queue.remove());
553 try expectEqual(@as(u32, 5), queue.remove());
554554}
555555
556556test "std.PriorityQueue: update max heap" {
......@@ -563,9 +563,9 @@ test "std.PriorityQueue: update max heap" {
563563 try queue.update(55, 5);
564564 try queue.update(44, 1);
565565 try queue.update(11, 4);
566 expectEqual(@as(u32, 5), queue.remove());
567 expectEqual(@as(u32, 4), queue.remove());
568 expectEqual(@as(u32, 1), queue.remove());
566 try expectEqual(@as(u32, 5), queue.remove());
567 try expectEqual(@as(u32, 4), queue.remove());
568 try expectEqual(@as(u32, 1), queue.remove());
569569}
570570
571571test "std.PriorityQueue: update same max heap" {
......@@ -578,8 +578,8 @@ test "std.PriorityQueue: update same max heap" {
578578 try queue.add(2);
579579 try queue.update(1, 5);
580580 try queue.update(2, 4);
581 expectEqual(@as(u32, 5), queue.remove());
582 expectEqual(@as(u32, 4), queue.remove());
583 expectEqual(@as(u32, 2), queue.remove());
584 expectEqual(@as(u32, 1), queue.remove());
581 try expectEqual(@as(u32, 5), queue.remove());
582 try expectEqual(@as(u32, 4), queue.remove());
583 try expectEqual(@as(u32, 2), queue.remove());
584 try expectEqual(@as(u32, 1), queue.remove());
585585}
lib/std/process.zig+16-16
......@@ -181,7 +181,7 @@ pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) GetEnvVarOwned
181181
182182test "os.getEnvVarOwned" {
183183 var ga = std.testing.allocator;
184 testing.expectError(error.EnvironmentVariableNotFound, getEnvVarOwned(ga, "BADENV"));
184 try testing.expectError(error.EnvironmentVariableNotFound, getEnvVarOwned(ga, "BADENV"));
185185}
186186
187187pub const ArgIteratorPosix = struct {
......@@ -516,10 +516,10 @@ test "args iterator" {
516516 };
517517 const given_suffix = std.fs.path.basename(prog_name);
518518
519 testing.expect(mem.eql(u8, expected_suffix, given_suffix));
520 testing.expect(it.skip()); // Skip over zig_exe_path, passed to the test runner
521 testing.expect(it.next(ga) == null);
522 testing.expect(!it.skip());
519 try testing.expect(mem.eql(u8, expected_suffix, given_suffix));
520 try testing.expect(it.skip()); // Skip over zig_exe_path, passed to the test runner
521 try testing.expect(it.next(ga) == null);
522 try testing.expect(!it.skip());
523523}
524524
525525/// Caller must call argsFree on result.
......@@ -575,14 +575,14 @@ pub fn argsFree(allocator: *mem.Allocator, args_alloc: []const [:0]u8) void {
575575
576576test "windows arg parsing" {
577577 const utf16Literal = std.unicode.utf8ToUtf16LeStringLiteral;
578 testWindowsCmdLine(utf16Literal("a b\tc d"), &[_][]const u8{ "a", "b", "c", "d" });
579 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" });
581 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" });
583 testWindowsCmdLine(utf16Literal("a b\tc \"d f"), &[_][]const u8{ "a", "b", "c", "d f" });
584
585 testWindowsCmdLine(utf16Literal("\".\\..\\zig-cache\\build\" \"bin\\zig.exe\" \".\\..\" \".\\..\\zig-cache\" \"--help\""), &[_][]const u8{
578 try testWindowsCmdLine(utf16Literal("a b\tc d"), &[_][]const u8{ "a", "b", "c", "d" });
579 try testWindowsCmdLine(utf16Literal("\"abc\" d e"), &[_][]const u8{ "abc", "d", "e" });
580 try testWindowsCmdLine(utf16Literal("a\\\\\\b d\"e f\"g h"), &[_][]const u8{ "a\\\\\\b", "de fg", "h" });
581 try testWindowsCmdLine(utf16Literal("a\\\\\\\"b c d"), &[_][]const u8{ "a\\\"b", "c", "d" });
582 try testWindowsCmdLine(utf16Literal("a\\\\\\\\\"b c\" d e"), &[_][]const u8{ "a\\\\b c", "d", "e" });
583 try testWindowsCmdLine(utf16Literal("a b\tc \"d f"), &[_][]const u8{ "a", "b", "c", "d f" });
584
585 try testWindowsCmdLine(utf16Literal("\".\\..\\zig-cache\\build\" \"bin\\zig.exe\" \".\\..\" \".\\..\\zig-cache\" \"--help\""), &[_][]const u8{
586586 ".\\..\\zig-cache\\build",
587587 "bin\\zig.exe",
588588 ".\\..",
......@@ -591,14 +591,14 @@ test "windows arg parsing" {
591591 });
592592}
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 {
595595 var it = ArgIteratorWindows.initWithCmdLine(input_cmd_line);
596596 for (expected_args) |expected_arg| {
597597 const arg = it.next(std.testing.allocator).? catch unreachable;
598598 defer std.testing.allocator.free(arg);
599 testing.expectEqualStrings(expected_arg, arg);
599 try testing.expectEqualStrings(expected_arg, arg);
600600 }
601 testing.expect(it.next(std.testing.allocator) == null);
601 try testing.expect(it.next(std.testing.allocator) == null);
602602}
603603
604604pub const UserInfo = struct {
lib/std/rand.zig+96-96
......@@ -319,139 +319,139 @@ const SequentialPrng = struct {
319319};
320320
321321test "Random int" {
322 testRandomInt();
323 comptime testRandomInt();
322 try testRandomInt();
323 comptime try testRandomInt();
324324}
325fn testRandomInt() void {
325fn testRandomInt() !void {
326326 var r = SequentialPrng.init();
327327
328 expect(r.random.int(u0) == 0);
328 try expect(r.random.int(u0) == 0);
329329
330330 r.next_value = 0;
331 expect(r.random.int(u1) == 0);
332 expect(r.random.int(u1) == 1);
333 expect(r.random.int(u2) == 2);
334 expect(r.random.int(u2) == 3);
335 expect(r.random.int(u2) == 0);
331 try expect(r.random.int(u1) == 0);
332 try expect(r.random.int(u1) == 1);
333 try expect(r.random.int(u2) == 2);
334 try expect(r.random.int(u2) == 3);
335 try expect(r.random.int(u2) == 0);
336336
337337 r.next_value = 0xff;
338 expect(r.random.int(u8) == 0xff);
338 try expect(r.random.int(u8) == 0xff);
339339 r.next_value = 0x11;
340 expect(r.random.int(u8) == 0x11);
340 try expect(r.random.int(u8) == 0x11);
341341
342342 r.next_value = 0xff;
343 expect(r.random.int(u32) == 0xffffffff);
343 try expect(r.random.int(u32) == 0xffffffff);
344344 r.next_value = 0x11;
345 expect(r.random.int(u32) == 0x11111111);
345 try expect(r.random.int(u32) == 0x11111111);
346346
347347 r.next_value = 0xff;
348 expect(r.random.int(i32) == -1);
348 try expect(r.random.int(i32) == -1);
349349 r.next_value = 0x11;
350 expect(r.random.int(i32) == 0x11111111);
350 try expect(r.random.int(i32) == 0x11111111);
351351
352352 r.next_value = 0xff;
353 expect(r.random.int(i8) == -1);
353 try expect(r.random.int(i8) == -1);
354354 r.next_value = 0x11;
355 expect(r.random.int(i8) == 0x11);
355 try expect(r.random.int(i8) == 0x11);
356356
357357 r.next_value = 0xff;
358 expect(r.random.int(u33) == 0x1ffffffff);
358 try expect(r.random.int(u33) == 0x1ffffffff);
359359 r.next_value = 0xff;
360 expect(r.random.int(i1) == -1);
360 try expect(r.random.int(i1) == -1);
361361 r.next_value = 0xff;
362 expect(r.random.int(i2) == -1);
362 try expect(r.random.int(i2) == -1);
363363 r.next_value = 0xff;
364 expect(r.random.int(i33) == -1);
364 try expect(r.random.int(i33) == -1);
365365}
366366
367367test "Random boolean" {
368 testRandomBoolean();
369 comptime testRandomBoolean();
368 try testRandomBoolean();
369 comptime try testRandomBoolean();
370370}
371fn testRandomBoolean() void {
371fn testRandomBoolean() !void {
372372 var r = SequentialPrng.init();
373 expect(r.random.boolean() == false);
374 expect(r.random.boolean() == true);
375 expect(r.random.boolean() == false);
376 expect(r.random.boolean() == true);
373 try expect(r.random.boolean() == false);
374 try expect(r.random.boolean() == true);
375 try expect(r.random.boolean() == false);
376 try expect(r.random.boolean() == true);
377377}
378378
379379test "Random intLessThan" {
380380 @setEvalBranchQuota(10000);
381 testRandomIntLessThan();
382 comptime testRandomIntLessThan();
381 try testRandomIntLessThan();
382 comptime try testRandomIntLessThan();
383383}
384fn testRandomIntLessThan() void {
384fn testRandomIntLessThan() !void {
385385 var r = SequentialPrng.init();
386386 r.next_value = 0xff;
387 expect(r.random.uintLessThan(u8, 4) == 3);
388 expect(r.next_value == 0);
389 expect(r.random.uintLessThan(u8, 4) == 0);
390 expect(r.next_value == 1);
387 try expect(r.random.uintLessThan(u8, 4) == 3);
388 try expect(r.next_value == 0);
389 try expect(r.random.uintLessThan(u8, 4) == 0);
390 try expect(r.next_value == 1);
391391
392392 r.next_value = 0;
393 expect(r.random.uintLessThan(u64, 32) == 0);
393 try expect(r.random.uintLessThan(u64, 32) == 0);
394394
395395 // trigger the bias rejection code path
396396 r.next_value = 0;
397 expect(r.random.uintLessThan(u8, 3) == 0);
397 try expect(r.random.uintLessThan(u8, 3) == 0);
398398 // verify we incremented twice
399 expect(r.next_value == 2);
399 try expect(r.next_value == 2);
400400
401401 r.next_value = 0xff;
402 expect(r.random.intRangeLessThan(u8, 0, 0x80) == 0x7f);
402 try expect(r.random.intRangeLessThan(u8, 0, 0x80) == 0x7f);
403403 r.next_value = 0xff;
404 expect(r.random.intRangeLessThan(u8, 0x7f, 0xff) == 0xfe);
404 try expect(r.random.intRangeLessThan(u8, 0x7f, 0xff) == 0xfe);
405405
406406 r.next_value = 0xff;
407 expect(r.random.intRangeLessThan(i8, 0, 0x40) == 0x3f);
407 try expect(r.random.intRangeLessThan(i8, 0, 0x40) == 0x3f);
408408 r.next_value = 0xff;
409 expect(r.random.intRangeLessThan(i8, -0x40, 0x40) == 0x3f);
409 try expect(r.random.intRangeLessThan(i8, -0x40, 0x40) == 0x3f);
410410 r.next_value = 0xff;
411 expect(r.random.intRangeLessThan(i8, -0x80, 0) == -1);
411 try expect(r.random.intRangeLessThan(i8, -0x80, 0) == -1);
412412
413413 r.next_value = 0xff;
414 expect(r.random.intRangeLessThan(i3, -4, 0) == -1);
414 try expect(r.random.intRangeLessThan(i3, -4, 0) == -1);
415415 r.next_value = 0xff;
416 expect(r.random.intRangeLessThan(i3, -2, 2) == 1);
416 try expect(r.random.intRangeLessThan(i3, -2, 2) == 1);
417417}
418418
419419test "Random intAtMost" {
420420 @setEvalBranchQuota(10000);
421 testRandomIntAtMost();
422 comptime testRandomIntAtMost();
421 try testRandomIntAtMost();
422 comptime try testRandomIntAtMost();
423423}
424fn testRandomIntAtMost() void {
424fn testRandomIntAtMost() !void {
425425 var r = SequentialPrng.init();
426426 r.next_value = 0xff;
427 expect(r.random.uintAtMost(u8, 3) == 3);
428 expect(r.next_value == 0);
429 expect(r.random.uintAtMost(u8, 3) == 0);
427 try expect(r.random.uintAtMost(u8, 3) == 3);
428 try expect(r.next_value == 0);
429 try expect(r.random.uintAtMost(u8, 3) == 0);
430430
431431 // trigger the bias rejection code path
432432 r.next_value = 0;
433 expect(r.random.uintAtMost(u8, 2) == 0);
433 try expect(r.random.uintAtMost(u8, 2) == 0);
434434 // verify we incremented twice
435 expect(r.next_value == 2);
435 try expect(r.next_value == 2);
436436
437437 r.next_value = 0xff;
438 expect(r.random.intRangeAtMost(u8, 0, 0x7f) == 0x7f);
438 try expect(r.random.intRangeAtMost(u8, 0, 0x7f) == 0x7f);
439439 r.next_value = 0xff;
440 expect(r.random.intRangeAtMost(u8, 0x7f, 0xfe) == 0xfe);
440 try expect(r.random.intRangeAtMost(u8, 0x7f, 0xfe) == 0xfe);
441441
442442 r.next_value = 0xff;
443 expect(r.random.intRangeAtMost(i8, 0, 0x3f) == 0x3f);
443 try expect(r.random.intRangeAtMost(i8, 0, 0x3f) == 0x3f);
444444 r.next_value = 0xff;
445 expect(r.random.intRangeAtMost(i8, -0x40, 0x3f) == 0x3f);
445 try expect(r.random.intRangeAtMost(i8, -0x40, 0x3f) == 0x3f);
446446 r.next_value = 0xff;
447 expect(r.random.intRangeAtMost(i8, -0x80, -1) == -1);
447 try expect(r.random.intRangeAtMost(i8, -0x80, -1) == -1);
448448
449449 r.next_value = 0xff;
450 expect(r.random.intRangeAtMost(i3, -4, -1) == -1);
450 try expect(r.random.intRangeAtMost(i3, -4, -1) == -1);
451451 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);
455455}
456456
457457test "Random Biased" {
......@@ -459,30 +459,30 @@ test "Random Biased" {
459459 // Not thoroughly checking the logic here.
460460 // Just want to execute all the paths with different types.
461461
462 expect(r.random.uintLessThanBiased(u1, 1) == 0);
463 expect(r.random.uintLessThanBiased(u32, 10) < 10);
464 expect(r.random.uintLessThanBiased(u64, 20) < 20);
462 try expect(r.random.uintLessThanBiased(u1, 1) == 0);
463 try expect(r.random.uintLessThanBiased(u32, 10) < 10);
464 try expect(r.random.uintLessThanBiased(u64, 20) < 20);
465465
466 expect(r.random.uintAtMostBiased(u0, 0) == 0);
467 expect(r.random.uintAtMostBiased(u1, 0) <= 0);
468 expect(r.random.uintAtMostBiased(u32, 10) <= 10);
469 expect(r.random.uintAtMostBiased(u64, 20) <= 20);
466 try expect(r.random.uintAtMostBiased(u0, 0) == 0);
467 try expect(r.random.uintAtMostBiased(u1, 0) <= 0);
468 try expect(r.random.uintAtMostBiased(u32, 10) <= 10);
469 try expect(r.random.uintAtMostBiased(u64, 20) <= 20);
470470
471 expect(r.random.intRangeLessThanBiased(u1, 0, 1) == 0);
472 expect(r.random.intRangeLessThanBiased(i1, -1, 0) == -1);
473 expect(r.random.intRangeLessThanBiased(u32, 10, 20) >= 10);
474 expect(r.random.intRangeLessThanBiased(i32, 10, 20) >= 10);
475 expect(r.random.intRangeLessThanBiased(u64, 20, 40) >= 20);
476 expect(r.random.intRangeLessThanBiased(i64, 20, 40) >= 20);
471 try expect(r.random.intRangeLessThanBiased(u1, 0, 1) == 0);
472 try expect(r.random.intRangeLessThanBiased(i1, -1, 0) == -1);
473 try expect(r.random.intRangeLessThanBiased(u32, 10, 20) >= 10);
474 try expect(r.random.intRangeLessThanBiased(i32, 10, 20) >= 10);
475 try expect(r.random.intRangeLessThanBiased(u64, 20, 40) >= 20);
476 try expect(r.random.intRangeLessThanBiased(i64, 20, 40) >= 20);
477477
478478 // uncomment for broken module error:
479479 //expect(r.random.intRangeAtMostBiased(u0, 0, 0) == 0);
480 expect(r.random.intRangeAtMostBiased(u1, 0, 1) >= 0);
481 expect(r.random.intRangeAtMostBiased(i1, -1, 0) >= -1);
482 expect(r.random.intRangeAtMostBiased(u32, 10, 20) >= 10);
483 expect(r.random.intRangeAtMostBiased(i32, 10, 20) >= 10);
484 expect(r.random.intRangeAtMostBiased(u64, 20, 40) >= 20);
485 expect(r.random.intRangeAtMostBiased(i64, 20, 40) >= 20);
480 try expect(r.random.intRangeAtMostBiased(u1, 0, 1) >= 0);
481 try expect(r.random.intRangeAtMostBiased(i1, -1, 0) >= -1);
482 try expect(r.random.intRangeAtMostBiased(u32, 10, 20) >= 10);
483 try expect(r.random.intRangeAtMostBiased(i32, 10, 20) >= 10);
484 try expect(r.random.intRangeAtMostBiased(u64, 20, 40) >= 20);
485 try expect(r.random.intRangeAtMostBiased(i64, 20, 40) >= 20);
486486}
487487
488488// Generator to extend 64-bit seed values into longer sequences.
......@@ -519,7 +519,7 @@ test "splitmix64 sequence" {
519519 };
520520
521521 for (seq) |s| {
522 expect(s == r.next());
522 try expect(s == r.next());
523523 }
524524}
525525
......@@ -530,12 +530,12 @@ test "Random float" {
530530 var i: usize = 0;
531531 while (i < 1000) : (i += 1) {
532532 const val1 = prng.random.float(f32);
533 expect(val1 >= 0.0);
534 expect(val1 < 1.0);
533 try expect(val1 >= 0.0);
534 try expect(val1 < 1.0);
535535
536536 const val2 = prng.random.float(f64);
537 expect(val2 >= 0.0);
538 expect(val2 < 1.0);
537 try expect(val2 >= 0.0);
538 try expect(val2 < 1.0);
539539 }
540540}
541541
......@@ -549,12 +549,12 @@ test "Random shuffle" {
549549 while (i < 1000) : (i += 1) {
550550 prng.random.shuffle(u8, seq[0..]);
551551 seen[seq[0]] = true;
552 expect(sumArray(seq[0..]) == 10);
552 try expect(sumArray(seq[0..]) == 10);
553553 }
554554
555555 // we should see every entry at the head at least once
556556 for (seen) |e| {
557 expect(e == true);
557 try expect(e == true);
558558 }
559559}
560560
......@@ -567,17 +567,17 @@ fn sumArray(s: []const u8) u32 {
567567
568568test "Random range" {
569569 var prng = DefaultPrng.init(0);
570 testRange(&prng.random, -4, 3);
571 testRange(&prng.random, -4, -1);
572 testRange(&prng.random, 10, 14);
573 testRange(&prng.random, -0x80, 0x7f);
570 try testRange(&prng.random, -4, 3);
571 try testRange(&prng.random, -4, -1);
572 try testRange(&prng.random, 10, 14);
573 try testRange(&prng.random, -0x80, 0x7f);
574574}
575575
576fn testRange(r: *Random, start: i8, end: i8) void {
577 testRangeBias(r, start, end, true);
578 testRangeBias(r, start, end, false);
576fn testRange(r: *Random, start: i8, end: i8) !void {
577 try testRangeBias(r, start, end, true);
578 try testRangeBias(r, start, end, false);
579579}
580fn testRangeBias(r: *Random, start: i8, end: i8, biased: bool) void {
580fn testRangeBias(r: *Random, start: i8, end: i8, biased: bool) !void {
581581 const count = @intCast(usize, @as(i32, end) - @as(i32, start));
582582 var values_buffer = [_]bool{false} ** 0x100;
583583 const values = values_buffer[0..count];
......@@ -599,7 +599,7 @@ test "CSPRNG" {
599599 const a = csprng.random.int(u64);
600600 const b = csprng.random.int(u64);
601601 const c = csprng.random.int(u64);
602 expect(a ^ b ^ c != 0);
602 try expect(a ^ b ^ c != 0);
603603}
604604
605605test {
lib/std/rand/Isaac64.zig+2-2
......@@ -205,7 +205,7 @@ test "isaac64 sequence" {
205205 };
206206
207207 for (seq) |s| {
208 std.testing.expect(s == r.next());
208 try std.testing.expect(s == r.next());
209209 }
210210}
211211
......@@ -237,6 +237,6 @@ test "isaac64 fill" {
237237 var buf1: [7]u8 = undefined;
238238 std.mem.writeIntLittle(u64, &buf0, s);
239239 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..]));
241241 }
242242}
lib/std/rand/Pcg.zig+2-2
......@@ -96,7 +96,7 @@ test "pcg sequence" {
9696 };
9797
9898 for (seq) |s| {
99 std.testing.expect(s == r.next());
99 try std.testing.expect(s == r.next());
100100 }
101101}
102102
......@@ -120,6 +120,6 @@ test "pcg fill" {
120120 var buf1: [3]u8 = undefined;
121121 std.mem.writeIntLittle(u32, &buf0, s);
122122 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..]));
124124 }
125125}
lib/std/rand/Sfc64.zig+2-2
......@@ -103,7 +103,7 @@ test "Sfc64 sequence" {
103103 };
104104
105105 for (seq) |s| {
106 std.testing.expectEqual(s, r.next());
106 try std.testing.expectEqual(s, r.next());
107107 }
108108}
109109
......@@ -135,6 +135,6 @@ test "Sfc64 fill" {
135135 var buf1: [7]u8 = undefined;
136136 std.mem.writeIntLittle(u64, &buf0, s);
137137 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..]));
139139 }
140140}
lib/std/rand/Xoroshiro128.zig+3-3
......@@ -113,7 +113,7 @@ test "xoroshiro sequence" {
113113 };
114114
115115 for (seq1) |s| {
116 std.testing.expect(s == r.next());
116 try std.testing.expect(s == r.next());
117117 }
118118
119119 r.jump();
......@@ -128,7 +128,7 @@ test "xoroshiro sequence" {
128128 };
129129
130130 for (seq2) |s| {
131 std.testing.expect(s == r.next());
131 try std.testing.expect(s == r.next());
132132 }
133133}
134134
......@@ -151,6 +151,6 @@ test "xoroshiro fill" {
151151 var buf1: [7]u8 = undefined;
152152 std.mem.writeIntLittle(u64, &buf0, s);
153153 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..]));
155155 }
156156}
lib/std/sort.zig+65-65
......@@ -43,35 +43,35 @@ test "binarySearch" {
4343 return math.order(lhs, rhs);
4444 }
4545 };
46 testing.expectEqual(
46 try testing.expectEqual(
4747 @as(?usize, null),
4848 binarySearch(u32, 1, &[_]u32{}, {}, S.order_u32),
4949 );
50 testing.expectEqual(
50 try testing.expectEqual(
5151 @as(?usize, 0),
5252 binarySearch(u32, 1, &[_]u32{1}, {}, S.order_u32),
5353 );
54 testing.expectEqual(
54 try testing.expectEqual(
5555 @as(?usize, null),
5656 binarySearch(u32, 1, &[_]u32{0}, {}, S.order_u32),
5757 );
58 testing.expectEqual(
58 try testing.expectEqual(
5959 @as(?usize, null),
6060 binarySearch(u32, 0, &[_]u32{1}, {}, S.order_u32),
6161 );
62 testing.expectEqual(
62 try testing.expectEqual(
6363 @as(?usize, 4),
6464 binarySearch(u32, 5, &[_]u32{ 1, 2, 3, 4, 5 }, {}, S.order_u32),
6565 );
66 testing.expectEqual(
66 try testing.expectEqual(
6767 @as(?usize, 0),
6868 binarySearch(u32, 2, &[_]u32{ 2, 4, 8, 16, 32, 64 }, {}, S.order_u32),
6969 );
70 testing.expectEqual(
70 try testing.expectEqual(
7171 @as(?usize, 1),
7272 binarySearch(i32, -4, &[_]i32{ -7, -4, 0, 9, 10 }, {}, S.order_i32),
7373 );
74 testing.expectEqual(
74 try testing.expectEqual(
7575 @as(?usize, 3),
7676 binarySearch(i32, 98, &[_]i32{ -100, -25, 2, 98, 99, 100 }, {}, S.order_i32),
7777 );
......@@ -1152,10 +1152,10 @@ pub fn desc(comptime T: type) fn (void, T, T) bool {
11521152}
11531153
11541154test "stable sort" {
1155 testStableSort();
1156 comptime testStableSort();
1155 try testStableSort();
1156 comptime try testStableSort();
11571157}
1158fn testStableSort() void {
1158fn testStableSort() !void {
11591159 var expected = [_]IdAndValue{
11601160 IdAndValue{ .id = 0, .value = 0 },
11611161 IdAndValue{ .id = 1, .value = 0 },
......@@ -1194,8 +1194,8 @@ fn testStableSort() void {
11941194 for (cases) |*case| {
11951195 insertionSort(IdAndValue, (case.*)[0..], {}, cmpByValue);
11961196 for (case.*) |item, i| {
1197 testing.expect(item.id == expected[i].id);
1198 testing.expect(item.value == expected[i].value);
1197 try testing.expect(item.id == expected[i].id);
1198 try testing.expect(item.value == expected[i].value);
11991199 }
12001200 }
12011201}
......@@ -1245,7 +1245,7 @@ test "sort" {
12451245 const slice = buf[0..case[0].len];
12461246 mem.copy(u8, slice, case[0]);
12471247 sort(u8, slice, {}, asc_u8);
1248 testing.expect(mem.eql(u8, slice, case[1]));
1248 try testing.expect(mem.eql(u8, slice, case[1]));
12491249 }
12501250
12511251 const i32cases = [_][]const []const i32{
......@@ -1280,7 +1280,7 @@ test "sort" {
12801280 const slice = buf[0..case[0].len];
12811281 mem.copy(i32, slice, case[0]);
12821282 sort(i32, slice, {}, asc_i32);
1283 testing.expect(mem.eql(i32, slice, case[1]));
1283 try testing.expect(mem.eql(i32, slice, case[1]));
12841284 }
12851285}
12861286
......@@ -1317,7 +1317,7 @@ test "sort descending" {
13171317 const slice = buf[0..case[0].len];
13181318 mem.copy(i32, slice, case[0]);
13191319 sort(i32, slice, {}, desc_i32);
1320 testing.expect(mem.eql(i32, slice, case[1]));
1320 try testing.expect(mem.eql(i32, slice, case[1]));
13211321 }
13221322}
13231323
......@@ -1325,7 +1325,7 @@ test "another sort case" {
13251325 var arr = [_]i32{ 5, 3, 1, 2, 4 };
13261326 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 }));
13291329}
13301330
13311331test "sort fuzz testing" {
......@@ -1353,9 +1353,9 @@ fn fuzzTest(rng: *std.rand.Random) !void {
13531353 var index: usize = 1;
13541354 while (index < array.len) : (index += 1) {
13551355 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);
13571357 } else {
1358 testing.expect(array[index].value > array[index - 1].value);
1358 try testing.expect(array[index].value > array[index - 1].value);
13591359 }
13601360 }
13611361}
......@@ -1383,13 +1383,13 @@ pub fn argMin(
13831383}
13841384
13851385test "argMin" {
1386 testing.expectEqual(@as(?usize, null), argMin(i32, &[_]i32{}, {}, asc_i32));
1387 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));
1389 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));
1391 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));
1386 try testing.expectEqual(@as(?usize, null), argMin(i32, &[_]i32{}, {}, asc_i32));
1387 try testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{1}, {}, asc_i32));
1388 try testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));
1389 try testing.expectEqual(@as(?usize, 3), argMin(i32, &[_]i32{ 9, 3, 8, 2, 5 }, {}, asc_i32));
1390 try testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32));
1391 try testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{ -10, 1, 10 }, {}, asc_i32));
1392 try testing.expectEqual(@as(?usize, 3), argMin(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32));
13931393}
13941394
13951395pub fn min(
......@@ -1403,13 +1403,13 @@ pub fn min(
14031403}
14041404
14051405test "min" {
1406 testing.expectEqual(@as(?i32, null), min(i32, &[_]i32{}, {}, asc_i32));
1407 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));
1409 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));
1411 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));
1406 try testing.expectEqual(@as(?i32, null), min(i32, &[_]i32{}, {}, asc_i32));
1407 try testing.expectEqual(@as(?i32, 1), min(i32, &[_]i32{1}, {}, asc_i32));
1408 try testing.expectEqual(@as(?i32, 1), min(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));
1409 try testing.expectEqual(@as(?i32, 2), min(i32, &[_]i32{ 9, 3, 8, 2, 5 }, {}, asc_i32));
1410 try testing.expectEqual(@as(?i32, 1), min(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32));
1411 try testing.expectEqual(@as(?i32, -10), min(i32, &[_]i32{ -10, 1, 10 }, {}, asc_i32));
1412 try testing.expectEqual(@as(?i32, 7), min(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32));
14131413}
14141414
14151415pub fn argMax(
......@@ -1435,13 +1435,13 @@ pub fn argMax(
14351435}
14361436
14371437test "argMax" {
1438 testing.expectEqual(@as(?usize, null), argMax(i32, &[_]i32{}, {}, asc_i32));
1439 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));
1441 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));
1443 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));
1438 try testing.expectEqual(@as(?usize, null), argMax(i32, &[_]i32{}, {}, asc_i32));
1439 try testing.expectEqual(@as(?usize, 0), argMax(i32, &[_]i32{1}, {}, asc_i32));
1440 try testing.expectEqual(@as(?usize, 4), argMax(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));
1441 try testing.expectEqual(@as(?usize, 0), argMax(i32, &[_]i32{ 9, 3, 8, 2, 5 }, {}, asc_i32));
1442 try testing.expectEqual(@as(?usize, 0), argMax(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32));
1443 try testing.expectEqual(@as(?usize, 2), argMax(i32, &[_]i32{ -10, 1, 10 }, {}, asc_i32));
1444 try testing.expectEqual(@as(?usize, 1), argMax(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32));
14451445}
14461446
14471447pub fn max(
......@@ -1455,13 +1455,13 @@ pub fn max(
14551455}
14561456
14571457test "max" {
1458 testing.expectEqual(@as(?i32, null), max(i32, &[_]i32{}, {}, asc_i32));
1459 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));
1461 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));
1463 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));
1458 try testing.expectEqual(@as(?i32, null), max(i32, &[_]i32{}, {}, asc_i32));
1459 try testing.expectEqual(@as(?i32, 1), max(i32, &[_]i32{1}, {}, asc_i32));
1460 try testing.expectEqual(@as(?i32, 5), max(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));
1461 try testing.expectEqual(@as(?i32, 9), max(i32, &[_]i32{ 9, 3, 8, 2, 5 }, {}, asc_i32));
1462 try testing.expectEqual(@as(?i32, 1), max(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32));
1463 try testing.expectEqual(@as(?i32, 10), max(i32, &[_]i32{ -10, 1, 10 }, {}, asc_i32));
1464 try testing.expectEqual(@as(?i32, 3), max(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32));
14651465}
14661466
14671467pub fn isSorted(
......@@ -1481,28 +1481,28 @@ pub fn isSorted(
14811481}
14821482
14831483test "isSorted" {
1484 testing.expect(isSorted(i32, &[_]i32{}, {}, asc_i32));
1485 testing.expect(isSorted(i32, &[_]i32{10}, {}, asc_i32));
1486 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));
1484 try testing.expect(isSorted(i32, &[_]i32{}, {}, asc_i32));
1485 try testing.expect(isSorted(i32, &[_]i32{10}, {}, asc_i32));
1486 try testing.expect(isSorted(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, 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));
1490 testing.expect(isSorted(i32, &[_]i32{-20}, {}, desc_i32));
1491 testing.expect(isSorted(i32, &[_]i32{ 3, 2, 1, 0, -1 }, {}, desc_i32));
1492 testing.expect(isSorted(i32, &[_]i32{ 10, -10 }, {}, desc_i32));
1489 try testing.expect(isSorted(i32, &[_]i32{}, {}, desc_i32));
1490 try testing.expect(isSorted(i32, &[_]i32{-20}, {}, desc_i32));
1491 try testing.expect(isSorted(i32, &[_]i32{ 3, 2, 1, 0, -1 }, {}, 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));
1495 testing.expect(isSorted(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, desc_i32));
1494 try testing.expect(isSorted(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_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));
1498 testing.expectEqual(false, isSorted(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, desc_i32));
1497 try testing.expectEqual(false, isSorted(i32, &[_]i32{ 5, 4, 3, 2, 1 }, {}, asc_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));
1501 testing.expect(isSorted(u8, "zyxw", {}, desc_u8));
1500 try testing.expect(isSorted(u8, "abcd", {}, asc_u8));
1501 try testing.expect(isSorted(u8, "zyxw", {}, desc_u8));
15021502
1503 testing.expectEqual(false, isSorted(u8, "abcd", {}, desc_u8));
1504 testing.expectEqual(false, isSorted(u8, "zyxw", {}, asc_u8));
1503 try testing.expectEqual(false, isSorted(u8, "abcd", {}, desc_u8));
1504 try testing.expectEqual(false, isSorted(u8, "zyxw", {}, asc_u8));
15051505
1506 testing.expect(isSorted(u8, "ffff", {}, asc_u8));
1507 testing.expect(isSorted(u8, "ffff", {}, desc_u8));
1506 try testing.expect(isSorted(u8, "ffff", {}, asc_u8));
1507 try testing.expect(isSorted(u8, "ffff", {}, desc_u8));
15081508}
lib/std/special/c.zig+27-27
......@@ -161,10 +161,10 @@ fn strerror(errnum: c_int) callconv(.C) [*:0]const u8 {
161161}
162162
163163test "strncmp" {
164 std.testing.expect(strncmp("a", "b", 1) == -1);
165 std.testing.expect(strncmp("a", "c", 1) == -2);
166 std.testing.expect(strncmp("b", "a", 1) == 1);
167 std.testing.expect(strncmp("\xff", "\x02", 1) == 253);
164 try std.testing.expect(strncmp("a", "b", 1) == -1);
165 try std.testing.expect(strncmp("a", "c", 1) == -2);
166 try std.testing.expect(strncmp("b", "a", 1) == 1);
167 try std.testing.expect(strncmp("\xff", "\x02", 1) == 253);
168168}
169169
170170// Avoid dragging in the runtime safety mechanisms into this .o file,
......@@ -245,9 +245,9 @@ test "memcmp" {
245245 const arr2 = &[_]u8{ 1, 0, 1 };
246246 const arr3 = &[_]u8{ 1, 2, 1 };
247247
248 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);
250 std.testing.expect(memcmp(base_arr[0..], arr3[0..], base_arr.len) < 0);
248 try std.testing.expect(memcmp(base_arr[0..], arr1[0..], base_arr.len) == 0);
249 try std.testing.expect(memcmp(base_arr[0..], arr2[0..], base_arr.len) > 0);
250 try std.testing.expect(memcmp(base_arr[0..], arr3[0..], base_arr.len) < 0);
251251}
252252
253253export fn bcmp(vl: [*]allowzero const u8, vr: [*]allowzero const u8, n: usize) callconv(.C) isize {
......@@ -269,9 +269,9 @@ test "bcmp" {
269269 const arr2 = &[_]u8{ 1, 0, 1 };
270270 const arr3 = &[_]u8{ 1, 2, 1 };
271271
272 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);
274 std.testing.expect(bcmp(base_arr[0..], arr3[0..], base_arr.len) != 0);
272 try std.testing.expect(bcmp(base_arr[0..], arr1[0..], base_arr.len) == 0);
273 try std.testing.expect(bcmp(base_arr[0..], arr2[0..], base_arr.len) != 0);
274 try std.testing.expect(bcmp(base_arr[0..], arr3[0..], base_arr.len) != 0);
275275}
276276
277277comptime {
......@@ -865,11 +865,11 @@ test "fmod, fmodf" {
865865 const nan_val = math.nan(T);
866866 const inf_val = math.inf(T);
867867
868 std.testing.expect(isNan(generic_fmod(T, nan_val, 1.0)));
869 std.testing.expect(isNan(generic_fmod(T, 1.0, nan_val)));
870 std.testing.expect(isNan(generic_fmod(T, inf_val, 1.0)));
871 std.testing.expect(isNan(generic_fmod(T, 0.0, 0.0)));
872 std.testing.expect(isNan(generic_fmod(T, 1.0, 0.0)));
868 try std.testing.expect(isNan(generic_fmod(T, nan_val, 1.0)));
869 try std.testing.expect(isNan(generic_fmod(T, 1.0, nan_val)));
870 try std.testing.expect(isNan(generic_fmod(T, inf_val, 1.0)));
871 try std.testing.expect(isNan(generic_fmod(T, 0.0, 0.0)));
872 try std.testing.expect(isNan(generic_fmod(T, 1.0, 0.0)));
873873
874874 std.testing.expectEqual(@as(T, 0.0), generic_fmod(T, 0.0, 2.0));
875875 std.testing.expectEqual(@as(T, -0.0), generic_fmod(T, -0.0, 2.0));
......@@ -901,7 +901,7 @@ test "fmin, fminf" {
901901 inline for ([_]type{ f32, f64 }) |T| {
902902 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)));
905905 std.testing.expectEqual(@as(T, 1.0), generic_fmin(T, nan_val, 1.0));
906906 std.testing.expectEqual(@as(T, 1.0), generic_fmin(T, 1.0, nan_val));
907907
......@@ -930,7 +930,7 @@ test "fmax, fmaxf" {
930930 inline for ([_]type{ f32, f64 }) |T| {
931931 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)));
934934 std.testing.expectEqual(@as(T, 1.0), generic_fmax(T, nan_val, 1.0));
935935 std.testing.expectEqual(@as(T, 1.0), generic_fmax(T, 1.0, nan_val));
936936
......@@ -1094,11 +1094,11 @@ test "sqrt" {
10941094}
10951095
10961096test "sqrt special" {
1097 std.testing.expect(std.math.isPositiveInf(sqrt(std.math.inf(f64))));
1098 std.testing.expect(sqrt(0.0) == 0.0);
1099 std.testing.expect(sqrt(-0.0) == -0.0);
1100 std.testing.expect(isNan(sqrt(-1.0)));
1101 std.testing.expect(isNan(sqrt(std.math.nan(f64))));
1097 try std.testing.expect(std.math.isPositiveInf(sqrt(std.math.inf(f64))));
1098 try std.testing.expect(sqrt(0.0) == 0.0);
1099 try std.testing.expect(sqrt(-0.0) == -0.0);
1100 try std.testing.expect(isNan(sqrt(-1.0)));
1101 try std.testing.expect(isNan(sqrt(std.math.nan(f64))));
11021102}
11031103
11041104export fn sqrtf(x: f32) f32 {
......@@ -1199,9 +1199,9 @@ test "sqrtf" {
11991199}
12001200
12011201test "sqrtf special" {
1202 std.testing.expect(std.math.isPositiveInf(sqrtf(std.math.inf(f32))));
1203 std.testing.expect(sqrtf(0.0) == 0.0);
1204 std.testing.expect(sqrtf(-0.0) == -0.0);
1205 std.testing.expect(isNan(sqrtf(-1.0)));
1206 std.testing.expect(isNan(sqrtf(std.math.nan(f32))));
1202 try std.testing.expect(std.math.isPositiveInf(sqrtf(std.math.inf(f32))));
1203 try std.testing.expect(sqrtf(0.0) == 0.0);
1204 try std.testing.expect(sqrtf(-0.0) == -0.0);
1205 try std.testing.expect(isNan(sqrtf(-1.0)));
1206 try std.testing.expect(isNan(sqrtf(std.math.nan(f32))));
12071207}
lib/std/special/compiler_rt/comparedf2_test.zig+1-1
......@@ -101,6 +101,6 @@ const test_vectors = init: {
101101
102102test "compare f64" {
103103 for (test_vectors) |vector, i| {
104 std.testing.expect(test__cmpdf2(vector));
104 try std.testing.expect(test__cmpdf2(vector));
105105 }
106106}
lib/std/special/compiler_rt/comparesf2_test.zig+1-1
......@@ -101,6 +101,6 @@ const test_vectors = init: {
101101
102102test "compare f32" {
103103 for (test_vectors) |vector, i| {
104 std.testing.expect(test__cmpsf2(vector));
104 try std.testing.expect(test__cmpsf2(vector));
105105 }
106106}
lib/std/special/compiler_rt/divdf3_test.zig+1-1
......@@ -30,7 +30,7 @@ fn compareResultD(result: f64, expected: u64) bool {
3030fn test__divdf3(a: f64, b: f64, expected: u64) void {
3131 const x = __divdf3(a, b);
3232 const ret = compareResultD(x, expected);
33 testing.expect(ret == true);
33 try testing.expect(ret == true);
3434}
3535
3636test "divdf3" {
lib/std/special/compiler_rt/divsf3_test.zig+1-1
......@@ -30,7 +30,7 @@ fn compareResultF(result: f32, expected: u32) bool {
3030fn test__divsf3(a: f32, b: f32, expected: u32) void {
3131 const x = __divsf3(a, b);
3232 const ret = compareResultF(x, expected);
33 testing.expect(ret == true);
33 try testing.expect(ret == true);
3434}
3535
3636test "divsf3" {
lib/std/special/compiler_rt/divtf3_test.zig+1-1
......@@ -31,7 +31,7 @@ fn compareResultLD(result: f128, expectedHi: u64, expectedLo: u64) bool {
3131fn test__divtf3(a: f128, b: f128, expectedHi: u64, expectedLo: u64) void {
3232 const x = __divtf3(a, b);
3333 const ret = compareResultLD(x, expectedHi, expectedLo);
34 testing.expect(ret == true);
34 try testing.expect(ret == true);
3535}
3636
3737test "divtf3" {
lib/std/special/compiler_rt/divti3_test.zig+1-1
......@@ -8,7 +8,7 @@ const testing = @import("std").testing;
88
99fn test__divti3(a: i128, b: i128, expected: i128) void {
1010 const x = __divti3(a, b);
11 testing.expect(x == expected);
11 try testing.expect(x == expected);
1212}
1313
1414test "divti3" {
lib/std/special/compiler_rt/emutls.zig+11-11
......@@ -339,12 +339,12 @@ test "simple_allocator" {
339339
340340test "__emutls_get_address zeroed" {
341341 var ctl = emutls_control.init(usize, null);
342 expect(ctl.object.index == 0);
342 try expect(ctl.object.index == 0);
343343
344344 // retrieve a variable from ctl
345345 var x = @ptrCast(*usize, @alignCast(@alignOf(usize), __emutls_get_address(&ctl)));
346 expect(ctl.object.index != 0); // index has been allocated for this ctl
347 expect(x.* == 0); // storage has been zeroed
346 try expect(ctl.object.index != 0); // index has been allocated for this ctl
347 try expect(x.* == 0); // storage has been zeroed
348348
349349 // modify the storage
350350 x.* = 1234;
......@@ -352,26 +352,26 @@ test "__emutls_get_address zeroed" {
352352 // retrieve a variable from ctl (same ctl)
353353 var y = @ptrCast(*usize, @alignCast(@alignOf(usize), __emutls_get_address(&ctl)));
354354
355 expect(y.* == 1234); // same content that x.*
356 expect(x == y); // same pointer
355 try expect(y.* == 1234); // same content that x.*
356 try expect(x == y); // same pointer
357357}
358358
359359test "__emutls_get_address with default_value" {
360360 var value: usize = 5678; // default value
361361 var ctl = emutls_control.init(usize, &value);
362 expect(ctl.object.index == 0);
362 try expect(ctl.object.index == 0);
363363
364364 var x: *usize = @ptrCast(*usize, @alignCast(@alignOf(usize), __emutls_get_address(&ctl)));
365 expect(ctl.object.index != 0);
366 expect(x.* == 5678); // storage initialized with default value
365 try expect(ctl.object.index != 0);
366 try expect(x.* == 5678); // storage initialized with default value
367367
368368 // modify the storage
369369 x.* = 9012;
370370
371 expect(value == 5678); // the default value didn't change
371 try expect(value == 5678); // the default value didn't change
372372
373373 var y = @ptrCast(*usize, @alignCast(@alignOf(usize), __emutls_get_address(&ctl)));
374 expect(y.* == 9012); // the modified storage persists
374 try expect(y.* == 9012); // the modified storage persists
375375}
376376
377377test "test default_value with differents sizes" {
......@@ -380,7 +380,7 @@ test "test default_value with differents sizes" {
380380 var def: T = value;
381381 var ctl = emutls_control.init(T, &def);
382382 var x = ctl.get_typed_pointer(T);
383 expect(x.* == value);
383 try expect(x.* == value);
384384 }
385385 }._testType;
386386
lib/std/special/compiler_rt/fixdfdi_test.zig+1-1
......@@ -12,7 +12,7 @@ const warn = std.debug.warn;
1212fn test__fixdfdi(a: f64, expected: i64) void {
1313 const x = __fixdfdi(a);
1414 //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);
1616}
1717
1818test "fixdfdi" {
lib/std/special/compiler_rt/fixdfsi_test.zig+1-1
......@@ -12,7 +12,7 @@ const warn = std.debug.warn;
1212fn test__fixdfsi(a: f64, expected: i32) void {
1313 const x = __fixdfsi(a);
1414 //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);
1616}
1717
1818test "fixdfsi" {
lib/std/special/compiler_rt/fixdfti_test.zig+1-1
......@@ -12,7 +12,7 @@ const warn = std.debug.warn;
1212fn test__fixdfti(a: f64, expected: i128) void {
1313 const x = __fixdfti(a);
1414 //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);
1616}
1717
1818test "fixdfti" {
lib/std/special/compiler_rt/fixint_test.zig+1-1
......@@ -14,7 +14,7 @@ const fixint = @import("fixint.zig").fixint;
1414fn test__fixint(comptime fp_t: type, comptime fixint_t: type, a: fp_t, expected: fixint_t) void {
1515 const x = fixint(fp_t, fixint_t, a);
1616 //warn("a={} x={}:{x} expected={}:{x})\n", .{a, x, x, expected, expected});
17 testing.expect(x == expected);
17 try testing.expect(x == expected);
1818}
1919
2020test "fixint.i1" {
lib/std/special/compiler_rt/fixsfdi_test.zig+1-1
......@@ -12,7 +12,7 @@ const warn = std.debug.warn;
1212fn test__fixsfdi(a: f32, expected: i64) void {
1313 const x = __fixsfdi(a);
1414 //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);
1616}
1717
1818test "fixsfdi" {
lib/std/special/compiler_rt/fixsfsi_test.zig+1-1
......@@ -12,7 +12,7 @@ const warn = std.debug.warn;
1212fn test__fixsfsi(a: f32, expected: i32) void {
1313 const x = __fixsfsi(a);
1414 //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);
1616}
1717
1818test "fixsfsi" {
lib/std/special/compiler_rt/fixsfti_test.zig+1-1
......@@ -12,7 +12,7 @@ const warn = std.debug.warn;
1212fn test__fixsfti(a: f32, expected: i128) void {
1313 const x = __fixsfti(a);
1414 //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);
1616}
1717
1818test "fixsfti" {
lib/std/special/compiler_rt/fixtfdi_test.zig+1-1
......@@ -12,7 +12,7 @@ const warn = std.debug.warn;
1212fn test__fixtfdi(a: f128, expected: i64) void {
1313 const x = __fixtfdi(a);
1414 //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);
1616}
1717
1818test "fixtfdi" {
lib/std/special/compiler_rt/fixtfsi_test.zig+1-1
......@@ -12,7 +12,7 @@ const warn = std.debug.warn;
1212fn test__fixtfsi(a: f128, expected: i32) void {
1313 const x = __fixtfsi(a);
1414 //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);
1616}
1717
1818test "fixtfsi" {
lib/std/special/compiler_rt/fixtfti_test.zig+1-1
......@@ -12,7 +12,7 @@ const warn = std.debug.warn;
1212fn test__fixtfti(a: f128, expected: i128) void {
1313 const x = __fixtfti(a);
1414 //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);
1616}
1717
1818test "fixtfti" {
lib/std/special/compiler_rt/fixunsdfdi_test.zig+1-1
......@@ -8,7 +8,7 @@ const testing = @import("std").testing;
88
99fn test__fixunsdfdi(a: f64, expected: u64) void {
1010 const x = __fixunsdfdi(a);
11 testing.expect(x == expected);
11 try testing.expect(x == expected);
1212}
1313
1414test "fixunsdfdi" {
lib/std/special/compiler_rt/fixunsdfsi_test.zig+1-1
......@@ -8,7 +8,7 @@ const testing = @import("std").testing;
88
99fn test__fixunsdfsi(a: f64, expected: u32) void {
1010 const x = __fixunsdfsi(a);
11 testing.expect(x == expected);
11 try testing.expect(x == expected);
1212}
1313
1414test "fixunsdfsi" {
lib/std/special/compiler_rt/fixunsdfti_test.zig+1-1
......@@ -8,7 +8,7 @@ const testing = @import("std").testing;
88
99fn test__fixunsdfti(a: f64, expected: u128) void {
1010 const x = __fixunsdfti(a);
11 testing.expect(x == expected);
11 try testing.expect(x == expected);
1212}
1313
1414test "fixunsdfti" {
lib/std/special/compiler_rt/fixunssfdi_test.zig+1-1
......@@ -8,7 +8,7 @@ const testing = @import("std").testing;
88
99fn test__fixunssfdi(a: f32, expected: u64) void {
1010 const x = __fixunssfdi(a);
11 testing.expect(x == expected);
11 try testing.expect(x == expected);
1212}
1313
1414test "fixunssfdi" {
lib/std/special/compiler_rt/fixunssfsi_test.zig+1-1
......@@ -8,7 +8,7 @@ const testing = @import("std").testing;
88
99fn test__fixunssfsi(a: f32, expected: u32) void {
1010 const x = __fixunssfsi(a);
11 testing.expect(x == expected);
11 try testing.expect(x == expected);
1212}
1313
1414test "fixunssfsi" {
lib/std/special/compiler_rt/fixunssfti_test.zig+1-1
......@@ -8,7 +8,7 @@ const testing = @import("std").testing;
88
99fn test__fixunssfti(a: f32, expected: u128) void {
1010 const x = __fixunssfti(a);
11 testing.expect(x == expected);
11 try testing.expect(x == expected);
1212}
1313
1414test "fixunssfti" {
lib/std/special/compiler_rt/fixunstfdi_test.zig+1-1
......@@ -8,7 +8,7 @@ const testing = @import("std").testing;
88
99fn test__fixunstfdi(a: f128, expected: u64) void {
1010 const x = __fixunstfdi(a);
11 testing.expect(x == expected);
11 try testing.expect(x == expected);
1212}
1313
1414test "fixunstfdi" {
lib/std/special/compiler_rt/fixunstfsi_test.zig+1-1
......@@ -8,7 +8,7 @@ const testing = @import("std").testing;
88
99fn test__fixunstfsi(a: f128, expected: u32) void {
1010 const x = __fixunstfsi(a);
11 testing.expect(x == expected);
11 try testing.expect(x == expected);
1212}
1313
1414const 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;
88
99fn test__fixunstfti(a: f128, expected: u128) void {
1010 const x = __fixunstfti(a);
11 testing.expect(x == expected);
11 try testing.expect(x == expected);
1212}
1313
1414const 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;
88
99fn test__floatdidf(a: i64, expected: f64) void {
1010 const r = __floatdidf(a);
11 testing.expect(r == expected);
11 try testing.expect(r == expected);
1212}
1313
1414test "floatdidf" {
lib/std/special/compiler_rt/floatdisf_test.zig+1-1
......@@ -8,7 +8,7 @@ const testing = @import("std").testing;
88
99fn test__floatdisf(a: i64, expected: f32) void {
1010 const x = __floatdisf(a);
11 testing.expect(x == expected);
11 try testing.expect(x == expected);
1212}
1313
1414test "floatdisf" {
lib/std/special/compiler_rt/floatditf_test.zig+1-1
......@@ -8,7 +8,7 @@ const testing = @import("std").testing;
88
99fn test__floatditf(a: i64, expected: f128) void {
1010 const x = __floatditf(a);
11 testing.expect(x == expected);
11 try testing.expect(x == expected);
1212}
1313
1414test "floatditf" {
lib/std/special/compiler_rt/floatsiXf.zig+3-3
......@@ -86,17 +86,17 @@ pub fn __aeabi_i2f(arg: i32) callconv(.AAPCS) f32 {
8686
8787fn test_one_floatsitf(a: i32, expected: u128) void {
8888 const r = __floatsitf(a);
89 std.testing.expect(@bitCast(u128, r) == expected);
89 try std.testing.expect(@bitCast(u128, r) == expected);
9090}
9191
9292fn test_one_floatsidf(a: i32, expected: u64) void {
9393 const r = __floatsidf(a);
94 std.testing.expect(@bitCast(u64, r) == expected);
94 try std.testing.expect(@bitCast(u64, r) == expected);
9595}
9696
9797fn test_one_floatsisf(a: i32, expected: u32) void {
9898 const r = __floatsisf(a);
99 std.testing.expect(@bitCast(u32, r) == expected);
99 try std.testing.expect(@bitCast(u32, r) == expected);
100100}
101101
102102test "floatsidf" {
lib/std/special/compiler_rt/floattidf_test.zig+1-1
......@@ -8,7 +8,7 @@ const testing = @import("std").testing;
88
99fn test__floattidf(a: i128, expected: f64) void {
1010 const x = __floattidf(a);
11 testing.expect(x == expected);
11 try testing.expect(x == expected);
1212}
1313
1414test "floattidf" {
lib/std/special/compiler_rt/floattisf_test.zig+1-1
......@@ -8,7 +8,7 @@ const testing = @import("std").testing;
88
99fn test__floattisf(a: i128, expected: f32) void {
1010 const x = __floattisf(a);
11 testing.expect(x == expected);
11 try testing.expect(x == expected);
1212}
1313
1414test "floattisf" {
lib/std/special/compiler_rt/floattitf_test.zig+1-1
......@@ -8,7 +8,7 @@ const testing = @import("std").testing;
88
99fn test__floattitf(a: i128, expected: f128) void {
1010 const x = __floattitf(a);
11 testing.expect(x == expected);
11 try testing.expect(x == expected);
1212}
1313
1414test "floattitf" {
lib/std/special/compiler_rt/floatundidf_test.zig+1-1
......@@ -8,7 +8,7 @@ const testing = @import("std").testing;
88
99fn test__floatundidf(a: u64, expected: f64) void {
1010 const r = __floatundidf(a);
11 testing.expect(r == expected);
11 try testing.expect(r == expected);
1212}
1313
1414test "floatundidf" {
lib/std/special/compiler_rt/floatunsidf.zig+1-1
......@@ -30,7 +30,7 @@ pub fn __aeabi_ui2d(arg: u32) callconv(.AAPCS) f64 {
3030
3131fn test_one_floatunsidf(a: u32, expected: u64) void {
3232 const r = __floatunsidf(a);
33 std.testing.expect(@bitCast(u64, r) == expected);
33 try std.testing.expect(@bitCast(u64, r) == expected);
3434}
3535
3636test "floatsidf" {
lib/std/special/compiler_rt/floatunsisf.zig+1-1
......@@ -50,7 +50,7 @@ pub fn __aeabi_ui2f(arg: u32) callconv(.AAPCS) f32 {
5050
5151fn test_one_floatunsisf(a: u32, expected: u32) void {
5252 const r = __floatunsisf(a);
53 std.testing.expect(@bitCast(u32, r) == expected);
53 try std.testing.expect(@bitCast(u32, r) == expected);
5454}
5555
5656test "floatunsisf" {
lib/std/special/compiler_rt/floatuntidf_test.zig+1-1
......@@ -8,7 +8,7 @@ const testing = @import("std").testing;
88
99fn test__floatuntidf(a: u128, expected: f64) void {
1010 const x = __floatuntidf(a);
11 testing.expect(x == expected);
11 try testing.expect(x == expected);
1212}
1313
1414test "floatuntidf" {
lib/std/special/compiler_rt/floatuntisf_test.zig+1-1
......@@ -8,7 +8,7 @@ const testing = @import("std").testing;
88
99fn test__floatuntisf(a: u128, expected: f32) void {
1010 const x = __floatuntisf(a);
11 testing.expect(x == expected);
11 try testing.expect(x == expected);
1212}
1313
1414test "floatuntisf" {
lib/std/special/compiler_rt/floatuntitf_test.zig+1-1
......@@ -8,7 +8,7 @@ const testing = @import("std").testing;
88
99fn test__floatuntitf(a: u128, expected: f128) void {
1010 const x = __floatuntitf(a);
11 testing.expect(x == expected);
11 try testing.expect(x == expected);
1212}
1313
1414test "floatuntitf" {
lib/std/special/compiler_rt/int.zig+8-8
......@@ -64,7 +64,7 @@ test "test_divdi3" {
6464
6565fn test_one_divdi3(a: i64, b: i64, expected_q: i64) void {
6666 const q: i64 = __divdi3(a, b);
67 testing.expect(q == expected_q);
67 try testing.expect(q == expected_q);
6868}
6969
7070pub fn __moddi3(a: i64, b: i64) callconv(.C) i64 {
......@@ -104,7 +104,7 @@ test "test_moddi3" {
104104
105105fn test_one_moddi3(a: i64, b: i64, expected_r: i64) void {
106106 const r: i64 = __moddi3(a, b);
107 testing.expect(r == expected_r);
107 try testing.expect(r == expected_r);
108108}
109109
110110pub fn __udivdi3(a: u64, b: u64) callconv(.C) u64 {
......@@ -130,7 +130,7 @@ test "test_umoddi3" {
130130
131131fn test_one_umoddi3(a: u64, b: u64, expected_r: u64) void {
132132 const r = __umoddi3(a, b);
133 testing.expect(r == expected_r);
133 try testing.expect(r == expected_r);
134134}
135135
136136pub fn __divmodsi4(a: i32, b: i32, rem: *i32) callconv(.C) i32 {
......@@ -166,7 +166,7 @@ test "test_divmodsi4" {
166166fn test_one_divmodsi4(a: i32, b: i32, expected_q: i32, expected_r: i32) void {
167167 var r: i32 = undefined;
168168 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);
170170}
171171
172172pub fn __udivmodsi4(a: u32, b: u32, rem: *u32) callconv(.C) u32 {
......@@ -213,7 +213,7 @@ test "test_divsi3" {
213213
214214fn test_one_divsi3(a: i32, b: i32, expected_q: i32) void {
215215 const q: i32 = __divsi3(a, b);
216 testing.expect(q == expected_q);
216 try testing.expect(q == expected_q);
217217}
218218
219219pub fn __udivsi3(n: u32, d: u32) callconv(.C) u32 {
......@@ -400,7 +400,7 @@ test "test_udivsi3" {
400400
401401fn test_one_udivsi3(a: u32, b: u32, expected_q: u32) void {
402402 const q: u32 = __udivsi3(a, b);
403 testing.expect(q == expected_q);
403 try testing.expect(q == expected_q);
404404}
405405
406406pub fn __modsi3(n: i32, d: i32) callconv(.C) i32 {
......@@ -431,7 +431,7 @@ test "test_modsi3" {
431431
432432fn test_one_modsi3(a: i32, b: i32, expected_r: i32) void {
433433 const r: i32 = __modsi3(a, b);
434 testing.expect(r == expected_r);
434 try testing.expect(r == expected_r);
435435}
436436
437437pub fn __umodsi3(n: u32, d: u32) callconv(.C) u32 {
......@@ -583,7 +583,7 @@ test "test_umodsi3" {
583583
584584fn test_one_umodsi3(a: u32, b: u32, expected_r: u32) void {
585585 const r: u32 = __umodsi3(a, b);
586 testing.expect(r == expected_r);
586 try testing.expect(r == expected_r);
587587}
588588
589589pub 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;
88
99fn test__modti3(a: i128, b: i128, expected: i128) void {
1010 const x = __modti3(a, b);
11 testing.expect(x == expected);
11 try testing.expect(x == expected);
1212}
1313
1414test "modti3" {
lib/std/special/compiler_rt/muldi3_test.zig+1-1
......@@ -8,7 +8,7 @@ const testing = @import("std").testing;
88
99fn test__muldi3(a: i64, b: i64, expected: i64) void {
1010 const x = __muldi3(a, b);
11 testing.expect(x == expected);
11 try testing.expect(x == expected);
1212}
1313
1414test "muldi3" {
lib/std/special/compiler_rt/mulodi4_test.zig+1-1
......@@ -9,7 +9,7 @@ const testing = @import("std").testing;
99fn test__mulodi4(a: i64, b: i64, expected: i64, expected_overflow: c_int) void {
1010 var overflow: c_int = undefined;
1111 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));
1313}
1414
1515test "mulodi4" {
lib/std/special/compiler_rt/muloti4_test.zig+1-1
......@@ -9,7 +9,7 @@ const testing = @import("std").testing;
99fn test__muloti4(a: i128, b: i128, expected: i128, expected_overflow: c_int) void {
1010 var overflow: c_int = undefined;
1111 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));
1313}
1414
1515test "muloti4" {
lib/std/special/compiler_rt/multi3_test.zig+1-1
......@@ -8,7 +8,7 @@ const testing = @import("std").testing;
88
99fn test__multi3(a: i128, b: i128, expected: i128) void {
1010 const x = __multi3(a, b);
11 testing.expect(x == expected);
11 try testing.expect(x == expected);
1212}
1313
1414test "multi3" {
lib/std/special/compiler_rt/popcountdi2_test.zig+1-1
......@@ -18,7 +18,7 @@ fn naive_popcount(a_param: i64) i32 {
1818fn test__popcountdi2(a: i64) void {
1919 const x = __popcountdi2(a);
2020 const expected = naive_popcount(a);
21 testing.expect(expected == x);
21 try testing.expect(expected == x);
2222}
2323
2424test "popcountdi2" {
lib/std/special/compiler_rt/udivmoddi4_test.zig+2-2
......@@ -11,8 +11,8 @@ const testing = @import("std").testing;
1111fn test__udivmoddi4(a: u64, b: u64, expected_q: u64, expected_r: u64) void {
1212 var r: u64 = undefined;
1313 const q = __udivmoddi4(a, b, &r);
14 testing.expect(q == expected_q);
15 testing.expect(r == expected_r);
14 try testing.expect(q == expected_q);
15 try testing.expect(r == expected_r);
1616}
1717
1818test "udivmoddi4" {
lib/std/special/compiler_rt/udivmodti4_test.zig+2-2
......@@ -11,8 +11,8 @@ const testing = @import("std").testing;
1111fn test__udivmodti4(a: u128, b: u128, expected_q: u128, expected_r: u128) void {
1212 var r: u128 = undefined;
1313 const q = __udivmodti4(a, b, &r);
14 testing.expect(q == expected_q);
15 testing.expect(r == expected_r);
14 try testing.expect(q == expected_q);
15 try testing.expect(r == expected_r);
1616}
1717
1818test "udivmodti4" {
lib/std/special/init-lib/src/main.zig+1-1
......@@ -6,5 +6,5 @@ export fn add(a: i32, b: i32) i32 {
66}
77
88test "basic add functionality" {
9 testing.expect(add(3, 7) == 10);
9 try testing.expect(add(3, 7) == 10);
1010}
lib/std/time.zig+4-4
......@@ -271,7 +271,7 @@ test "timestamp" {
271271 sleep(ns_per_ms);
272272 const time_1 = milliTimestamp();
273273 const interval = time_1 - time_0;
274 testing.expect(interval > 0);
274 try testing.expect(interval > 0);
275275 // Tests should not depend on timings: skip test if outside margin.
276276 if (!(interval < margin)) return error.SkipZigTest;
277277}
......@@ -282,13 +282,13 @@ test "Timer" {
282282 var timer = try Timer.start();
283283 sleep(10 * ns_per_ms);
284284 const time_0 = timer.read();
285 testing.expect(time_0 > 0);
285 try testing.expect(time_0 > 0);
286286 // Tests should not depend on timings: skip test if outside margin.
287287 if (!(time_0 < margin)) return error.SkipZigTest;
288288
289289 const time_1 = timer.lap();
290 testing.expect(time_1 >= time_0);
290 try testing.expect(time_1 >= time_0);
291291
292292 timer.reset();
293 testing.expect(timer.read() < time_1);
293 try testing.expect(timer.read() < time_1);
294294}
lib/std/unicode.zig+172-172
......@@ -336,224 +336,224 @@ pub const Utf16LeIterator = struct {
336336};
337337
338338test "utf8 encode" {
339 comptime testUtf8Encode() catch unreachable;
339 comptime try testUtf8Encode();
340340 try testUtf8Encode();
341341}
342342fn testUtf8Encode() !void {
343343 // A few taken from wikipedia a few taken elsewhere
344344 var array: [4]u8 = undefined;
345 testing.expect((try utf8Encode(try utf8Decode("€"), array[0..])) == 3);
346 testing.expect(array[0] == 0b11100010);
347 testing.expect(array[1] == 0b10000010);
348 testing.expect(array[2] == 0b10101100);
345 try testing.expect((try utf8Encode(try utf8Decode("€"), array[0..])) == 3);
346 try testing.expect(array[0] == 0b11100010);
347 try testing.expect(array[1] == 0b10000010);
348 try testing.expect(array[2] == 0b10101100);
349349
350 testing.expect((try utf8Encode(try utf8Decode("$"), array[0..])) == 1);
351 testing.expect(array[0] == 0b00100100);
350 try testing.expect((try utf8Encode(try utf8Decode("$"), array[0..])) == 1);
351 try testing.expect(array[0] == 0b00100100);
352352
353 testing.expect((try utf8Encode(try utf8Decode("¢"), array[0..])) == 2);
354 testing.expect(array[0] == 0b11000010);
355 testing.expect(array[1] == 0b10100010);
353 try testing.expect((try utf8Encode(try utf8Decode("¢"), array[0..])) == 2);
354 try testing.expect(array[0] == 0b11000010);
355 try testing.expect(array[1] == 0b10100010);
356356
357 testing.expect((try utf8Encode(try utf8Decode("𐍈"), array[0..])) == 4);
358 testing.expect(array[0] == 0b11110000);
359 testing.expect(array[1] == 0b10010000);
360 testing.expect(array[2] == 0b10001101);
361 testing.expect(array[3] == 0b10001000);
357 try testing.expect((try utf8Encode(try utf8Decode("𐍈"), array[0..])) == 4);
358 try testing.expect(array[0] == 0b11110000);
359 try testing.expect(array[1] == 0b10010000);
360 try testing.expect(array[2] == 0b10001101);
361 try testing.expect(array[3] == 0b10001000);
362362}
363363
364364test "utf8 encode error" {
365 comptime testUtf8EncodeError();
366 testUtf8EncodeError();
365 comptime try testUtf8EncodeError();
366 try testUtf8EncodeError();
367367}
368fn testUtf8EncodeError() void {
368fn testUtf8EncodeError() !void {
369369 var array: [4]u8 = undefined;
370 testErrorEncode(0xd800, array[0..], error.Utf8CannotEncodeSurrogateHalf);
371 testErrorEncode(0xdfff, array[0..], error.Utf8CannotEncodeSurrogateHalf);
372 testErrorEncode(0x110000, array[0..], error.CodepointTooLarge);
373 testErrorEncode(0x1fffff, array[0..], error.CodepointTooLarge);
370 try testErrorEncode(0xd800, array[0..], error.Utf8CannotEncodeSurrogateHalf);
371 try testErrorEncode(0xdfff, array[0..], error.Utf8CannotEncodeSurrogateHalf);
372 try testErrorEncode(0x110000, array[0..], error.CodepointTooLarge);
373 try testErrorEncode(0x1fffff, array[0..], error.CodepointTooLarge);
374374}
375375
376fn testErrorEncode(codePoint: u21, array: []u8, expectedErr: anyerror) void {
377 testing.expectError(expectedErr, utf8Encode(codePoint, array));
376fn testErrorEncode(codePoint: u21, array: []u8, expectedErr: anyerror) !void {
377 try testing.expectError(expectedErr, utf8Encode(codePoint, array));
378378}
379379
380380test "utf8 iterator on ascii" {
381 comptime testUtf8IteratorOnAscii();
382 testUtf8IteratorOnAscii();
381 comptime try testUtf8IteratorOnAscii();
382 try testUtf8IteratorOnAscii();
383383}
384fn testUtf8IteratorOnAscii() void {
384fn testUtf8IteratorOnAscii() !void {
385385 const s = Utf8View.initComptime("abc");
386386
387387 var it1 = s.iterator();
388 testing.expect(std.mem.eql(u8, "a", it1.nextCodepointSlice().?));
389 testing.expect(std.mem.eql(u8, "b", it1.nextCodepointSlice().?));
390 testing.expect(std.mem.eql(u8, "c", it1.nextCodepointSlice().?));
391 testing.expect(it1.nextCodepointSlice() == null);
388 try testing.expect(std.mem.eql(u8, "a", it1.nextCodepointSlice().?));
389 try testing.expect(std.mem.eql(u8, "b", it1.nextCodepointSlice().?));
390 try testing.expect(std.mem.eql(u8, "c", it1.nextCodepointSlice().?));
391 try testing.expect(it1.nextCodepointSlice() == null);
392392
393393 var it2 = s.iterator();
394 testing.expect(it2.nextCodepoint().? == 'a');
395 testing.expect(it2.nextCodepoint().? == 'b');
396 testing.expect(it2.nextCodepoint().? == 'c');
397 testing.expect(it2.nextCodepoint() == null);
394 try testing.expect(it2.nextCodepoint().? == 'a');
395 try testing.expect(it2.nextCodepoint().? == 'b');
396 try testing.expect(it2.nextCodepoint().? == 'c');
397 try testing.expect(it2.nextCodepoint() == null);
398398}
399399
400400test "utf8 view bad" {
401 comptime testUtf8ViewBad();
402 testUtf8ViewBad();
401 comptime try testUtf8ViewBad();
402 try testUtf8ViewBad();
403403}
404fn testUtf8ViewBad() void {
404fn testUtf8ViewBad() !void {
405405 // Compile-time error.
406406 // 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"));
408408}
409409
410410test "utf8 view ok" {
411 comptime testUtf8ViewOk();
412 testUtf8ViewOk();
411 comptime try testUtf8ViewOk();
412 try testUtf8ViewOk();
413413}
414fn testUtf8ViewOk() void {
414fn testUtf8ViewOk() !void {
415415 const s = Utf8View.initComptime("東京市");
416416
417417 var it1 = s.iterator();
418 testing.expect(std.mem.eql(u8, "東", it1.nextCodepointSlice().?));
419 testing.expect(std.mem.eql(u8, "京", it1.nextCodepointSlice().?));
420 testing.expect(std.mem.eql(u8, "市", it1.nextCodepointSlice().?));
421 testing.expect(it1.nextCodepointSlice() == null);
418 try testing.expect(std.mem.eql(u8, "東", it1.nextCodepointSlice().?));
419 try testing.expect(std.mem.eql(u8, "京", it1.nextCodepointSlice().?));
420 try testing.expect(std.mem.eql(u8, "市", it1.nextCodepointSlice().?));
421 try testing.expect(it1.nextCodepointSlice() == null);
422422
423423 var it2 = s.iterator();
424 testing.expect(it2.nextCodepoint().? == 0x6771);
425 testing.expect(it2.nextCodepoint().? == 0x4eac);
426 testing.expect(it2.nextCodepoint().? == 0x5e02);
427 testing.expect(it2.nextCodepoint() == null);
424 try testing.expect(it2.nextCodepoint().? == 0x6771);
425 try testing.expect(it2.nextCodepoint().? == 0x4eac);
426 try testing.expect(it2.nextCodepoint().? == 0x5e02);
427 try testing.expect(it2.nextCodepoint() == null);
428428}
429429
430430test "bad utf8 slice" {
431 comptime testBadUtf8Slice();
432 testBadUtf8Slice();
431 comptime try testBadUtf8Slice();
432 try testBadUtf8Slice();
433433}
434fn testBadUtf8Slice() void {
435 testing.expect(utf8ValidateSlice("abc"));
436 testing.expect(!utf8ValidateSlice("abc\xc0"));
437 testing.expect(!utf8ValidateSlice("abc\xc0abc"));
438 testing.expect(utf8ValidateSlice("abc\xdf\xbf"));
434fn testBadUtf8Slice() !void {
435 try testing.expect(utf8ValidateSlice("abc"));
436 try testing.expect(!utf8ValidateSlice("abc\xc0"));
437 try testing.expect(!utf8ValidateSlice("abc\xc0abc"));
438 try testing.expect(utf8ValidateSlice("abc\xdf\xbf"));
439439}
440440
441441test "valid utf8" {
442 comptime testValidUtf8();
443 testValidUtf8();
444}
445fn testValidUtf8() void {
446 testValid("\x00", 0x0);
447 testValid("\x20", 0x20);
448 testValid("\x7f", 0x7f);
449 testValid("\xc2\x80", 0x80);
450 testValid("\xdf\xbf", 0x7ff);
451 testValid("\xe0\xa0\x80", 0x800);
452 testValid("\xe1\x80\x80", 0x1000);
453 testValid("\xef\xbf\xbf", 0xffff);
454 testValid("\xf0\x90\x80\x80", 0x10000);
455 testValid("\xf1\x80\x80\x80", 0x40000);
456 testValid("\xf3\xbf\xbf\xbf", 0xfffff);
457 testValid("\xf4\x8f\xbf\xbf", 0x10ffff);
442 comptime try testValidUtf8();
443 try testValidUtf8();
444}
445fn testValidUtf8() !void {
446 try testValid("\x00", 0x0);
447 try testValid("\x20", 0x20);
448 try testValid("\x7f", 0x7f);
449 try testValid("\xc2\x80", 0x80);
450 try testValid("\xdf\xbf", 0x7ff);
451 try testValid("\xe0\xa0\x80", 0x800);
452 try testValid("\xe1\x80\x80", 0x1000);
453 try testValid("\xef\xbf\xbf", 0xffff);
454 try testValid("\xf0\x90\x80\x80", 0x10000);
455 try testValid("\xf1\x80\x80\x80", 0x40000);
456 try testValid("\xf3\xbf\xbf\xbf", 0xfffff);
457 try testValid("\xf4\x8f\xbf\xbf", 0x10ffff);
458458}
459459
460460test "invalid utf8 continuation bytes" {
461 comptime testInvalidUtf8ContinuationBytes();
462 testInvalidUtf8ContinuationBytes();
461 comptime try testInvalidUtf8ContinuationBytes();
462 try testInvalidUtf8ContinuationBytes();
463463}
464fn testInvalidUtf8ContinuationBytes() void {
464fn testInvalidUtf8ContinuationBytes() !void {
465465 // unexpected continuation
466 testError("\x80", error.Utf8InvalidStartByte);
467 testError("\xbf", error.Utf8InvalidStartByte);
466 try testError("\x80", error.Utf8InvalidStartByte);
467 try testError("\xbf", error.Utf8InvalidStartByte);
468468 // too many leading 1's
469 testError("\xf8", error.Utf8InvalidStartByte);
470 testError("\xff", error.Utf8InvalidStartByte);
469 try testError("\xf8", error.Utf8InvalidStartByte);
470 try testError("\xff", error.Utf8InvalidStartByte);
471471 // expected continuation for 2 byte sequences
472 testError("\xc2", error.UnexpectedEof);
473 testError("\xc2\x00", error.Utf8ExpectedContinuation);
474 testError("\xc2\xc0", error.Utf8ExpectedContinuation);
472 try testError("\xc2", error.UnexpectedEof);
473 try testError("\xc2\x00", error.Utf8ExpectedContinuation);
474 try testError("\xc2\xc0", error.Utf8ExpectedContinuation);
475475 // expected continuation for 3 byte sequences
476 testError("\xe0", error.UnexpectedEof);
477 testError("\xe0\x00", error.UnexpectedEof);
478 testError("\xe0\xc0", error.UnexpectedEof);
479 testError("\xe0\xa0", error.UnexpectedEof);
480 testError("\xe0\xa0\x00", error.Utf8ExpectedContinuation);
481 testError("\xe0\xa0\xc0", error.Utf8ExpectedContinuation);
476 try testError("\xe0", error.UnexpectedEof);
477 try testError("\xe0\x00", error.UnexpectedEof);
478 try testError("\xe0\xc0", error.UnexpectedEof);
479 try testError("\xe0\xa0", error.UnexpectedEof);
480 try testError("\xe0\xa0\x00", error.Utf8ExpectedContinuation);
481 try testError("\xe0\xa0\xc0", error.Utf8ExpectedContinuation);
482482 // expected continuation for 4 byte sequences
483 testError("\xf0", error.UnexpectedEof);
484 testError("\xf0\x00", error.UnexpectedEof);
485 testError("\xf0\xc0", error.UnexpectedEof);
486 testError("\xf0\x90\x00", error.UnexpectedEof);
487 testError("\xf0\x90\xc0", error.UnexpectedEof);
488 testError("\xf0\x90\x80\x00", error.Utf8ExpectedContinuation);
489 testError("\xf0\x90\x80\xc0", error.Utf8ExpectedContinuation);
483 try testError("\xf0", error.UnexpectedEof);
484 try testError("\xf0\x00", error.UnexpectedEof);
485 try testError("\xf0\xc0", error.UnexpectedEof);
486 try testError("\xf0\x90\x00", error.UnexpectedEof);
487 try testError("\xf0\x90\xc0", error.UnexpectedEof);
488 try testError("\xf0\x90\x80\x00", error.Utf8ExpectedContinuation);
489 try testError("\xf0\x90\x80\xc0", error.Utf8ExpectedContinuation);
490490}
491491
492492test "overlong utf8 codepoint" {
493 comptime testOverlongUtf8Codepoint();
494 testOverlongUtf8Codepoint();
493 comptime try testOverlongUtf8Codepoint();
494 try testOverlongUtf8Codepoint();
495495}
496fn testOverlongUtf8Codepoint() void {
497 testError("\xc0\x80", error.Utf8OverlongEncoding);
498 testError("\xc1\xbf", error.Utf8OverlongEncoding);
499 testError("\xe0\x80\x80", error.Utf8OverlongEncoding);
500 testError("\xe0\x9f\xbf", error.Utf8OverlongEncoding);
501 testError("\xf0\x80\x80\x80", error.Utf8OverlongEncoding);
502 testError("\xf0\x8f\xbf\xbf", error.Utf8OverlongEncoding);
496fn testOverlongUtf8Codepoint() !void {
497 try testError("\xc0\x80", error.Utf8OverlongEncoding);
498 try testError("\xc1\xbf", error.Utf8OverlongEncoding);
499 try testError("\xe0\x80\x80", error.Utf8OverlongEncoding);
500 try testError("\xe0\x9f\xbf", error.Utf8OverlongEncoding);
501 try testError("\xf0\x80\x80\x80", error.Utf8OverlongEncoding);
502 try testError("\xf0\x8f\xbf\xbf", error.Utf8OverlongEncoding);
503503}
504504
505505test "misc invalid utf8" {
506 comptime testMiscInvalidUtf8();
507 testMiscInvalidUtf8();
506 comptime try testMiscInvalidUtf8();
507 try testMiscInvalidUtf8();
508508}
509fn testMiscInvalidUtf8() void {
509fn testMiscInvalidUtf8() !void {
510510 // codepoint out of bounds
511 testError("\xf4\x90\x80\x80", error.Utf8CodepointTooLarge);
512 testError("\xf7\xbf\xbf\xbf", error.Utf8CodepointTooLarge);
511 try testError("\xf4\x90\x80\x80", error.Utf8CodepointTooLarge);
512 try testError("\xf7\xbf\xbf\xbf", error.Utf8CodepointTooLarge);
513513 // surrogate halves
514 testValid("\xed\x9f\xbf", 0xd7ff);
515 testError("\xed\xa0\x80", error.Utf8EncodesSurrogateHalf);
516 testError("\xed\xbf\xbf", error.Utf8EncodesSurrogateHalf);
517 testValid("\xee\x80\x80", 0xe000);
514 try testValid("\xed\x9f\xbf", 0xd7ff);
515 try testError("\xed\xa0\x80", error.Utf8EncodesSurrogateHalf);
516 try testError("\xed\xbf\xbf", error.Utf8EncodesSurrogateHalf);
517 try testValid("\xee\x80\x80", 0xe000);
518518}
519519
520520test "utf8 iterator peeking" {
521 comptime testUtf8Peeking();
522 testUtf8Peeking();
521 comptime try testUtf8Peeking();
522 try testUtf8Peeking();
523523}
524524
525fn testUtf8Peeking() void {
525fn testUtf8Peeking() !void {
526526 const s = Utf8View.initComptime("noël");
527527 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)));
532 testing.expect(std.mem.eql(u8, "oë", it.peek(2)));
533 testing.expect(std.mem.eql(u8, "oël", it.peek(3)));
534 testing.expect(std.mem.eql(u8, "oël", it.peek(4)));
535 testing.expect(std.mem.eql(u8, "oël", it.peek(10)));
531 try testing.expect(std.mem.eql(u8, "o", it.peek(1)));
532 try testing.expect(std.mem.eql(u8, "oë", it.peek(2)));
533 try testing.expect(std.mem.eql(u8, "oël", it.peek(3)));
534 try testing.expect(std.mem.eql(u8, "oël", it.peek(4)));
535 try testing.expect(std.mem.eql(u8, "oël", it.peek(10)));
536536
537 testing.expect(std.mem.eql(u8, "o", it.nextCodepointSlice().?));
538 testing.expect(std.mem.eql(u8, "ë", it.nextCodepointSlice().?));
539 testing.expect(std.mem.eql(u8, "l", it.nextCodepointSlice().?));
540 testing.expect(it.nextCodepointSlice() == null);
537 try testing.expect(std.mem.eql(u8, "o", it.nextCodepointSlice().?));
538 try testing.expect(std.mem.eql(u8, "ë", it.nextCodepointSlice().?));
539 try testing.expect(std.mem.eql(u8, "l", it.nextCodepointSlice().?));
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)));
543543}
544544
545fn testError(bytes: []const u8, expected_err: anyerror) void {
546 testing.expectError(expected_err, testDecode(bytes));
545fn testError(bytes: []const u8, expected_err: anyerror) !void {
546 try testing.expectError(expected_err, testDecode(bytes));
547547}
548548
549fn testValid(bytes: []const u8, expected_codepoint: u21) void {
550 testing.expect((testDecode(bytes) catch unreachable) == expected_codepoint);
549fn testValid(bytes: []const u8, expected_codepoint: u21) !void {
550 try testing.expect((testDecode(bytes) catch unreachable) == expected_codepoint);
551551}
552552
553553fn testDecode(bytes: []const u8) !u21 {
554554 const length = try utf8ByteSequenceLength(bytes[0]);
555555 if (bytes.len < length) return error.UnexpectedEof;
556 testing.expect(bytes.len == length);
556 try testing.expect(bytes.len == length);
557557 return utf8Decode(bytes);
558558}
559559
......@@ -615,7 +615,7 @@ test "utf16leToUtf8" {
615615 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 'a');
616616 const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);
617617 defer std.testing.allocator.free(utf8);
618 testing.expect(mem.eql(u8, utf8, "Aa"));
618 try testing.expect(mem.eql(u8, utf8, "Aa"));
619619 }
620620
621621 {
......@@ -623,7 +623,7 @@ test "utf16leToUtf8" {
623623 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xffff);
624624 const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);
625625 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"));
627627 }
628628
629629 {
......@@ -632,7 +632,7 @@ test "utf16leToUtf8" {
632632 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xe000);
633633 const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);
634634 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"));
636636 }
637637
638638 {
......@@ -641,7 +641,7 @@ test "utf16leToUtf8" {
641641 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdc00);
642642 const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);
643643 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"));
645645 }
646646
647647 {
......@@ -650,7 +650,7 @@ test "utf16leToUtf8" {
650650 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdfff);
651651 const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);
652652 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"));
654654 }
655655
656656 {
......@@ -658,7 +658,7 @@ test "utf16leToUtf8" {
658658 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdc00);
659659 const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);
660660 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"));
662662 }
663663}
664664
......@@ -717,13 +717,13 @@ test "utf8ToUtf16Le" {
717717 var utf16le: [2]u16 = [_]u16{0} ** 2;
718718 {
719719 const length = try utf8ToUtf16Le(utf16le[0..], "𐐷");
720 testing.expectEqual(@as(usize, 2), length);
721 testing.expectEqualSlices(u8, "\x01\xd8\x37\xdc", mem.sliceAsBytes(utf16le[0..]));
720 try testing.expectEqual(@as(usize, 2), length);
721 try testing.expectEqualSlices(u8, "\x01\xd8\x37\xdc", mem.sliceAsBytes(utf16le[0..]));
722722 }
723723 {
724724 const length = try utf8ToUtf16Le(utf16le[0..], "\u{10FFFF}");
725 testing.expectEqual(@as(usize, 2), length);
726 testing.expectEqualSlices(u8, "\xff\xdb\xff\xdf", mem.sliceAsBytes(utf16le[0..]));
725 try testing.expectEqual(@as(usize, 2), length);
726 try testing.expectEqualSlices(u8, "\xff\xdb\xff\xdf", mem.sliceAsBytes(utf16le[0..]));
727727 }
728728}
729729
......@@ -731,14 +731,14 @@ test "utf8ToUtf16LeWithNull" {
731731 {
732732 const utf16 = try utf8ToUtf16LeWithNull(testing.allocator, "𐐷");
733733 defer testing.allocator.free(utf16);
734 testing.expectEqualSlices(u8, "\x01\xd8\x37\xdc", mem.sliceAsBytes(utf16[0..]));
735 testing.expect(utf16[2] == 0);
734 try testing.expectEqualSlices(u8, "\x01\xd8\x37\xdc", mem.sliceAsBytes(utf16[0..]));
735 try testing.expect(utf16[2] == 0);
736736 }
737737 {
738738 const utf16 = try utf8ToUtf16LeWithNull(testing.allocator, "\u{10FFFF}");
739739 defer testing.allocator.free(utf16);
740 testing.expectEqualSlices(u8, "\xff\xdb\xff\xdf", mem.sliceAsBytes(utf16[0..]));
741 testing.expect(utf16[2] == 0);
740 try testing.expectEqualSlices(u8, "\xff\xdb\xff\xdf", mem.sliceAsBytes(utf16[0..]));
741 try testing.expect(utf16[2] == 0);
742742 }
743743}
744744
......@@ -776,8 +776,8 @@ test "utf8ToUtf16LeStringLiteral" {
776776 mem.nativeToLittle(u16, 0x41),
777777 };
778778 const utf16 = utf8ToUtf16LeStringLiteral("A");
779 testing.expectEqualSlices(u16, &bytes, utf16);
780 testing.expect(utf16[1] == 0);
779 try testing.expectEqualSlices(u16, &bytes, utf16);
780 try testing.expect(utf16[1] == 0);
781781 }
782782 {
783783 const bytes = [_:0]u16{
......@@ -785,32 +785,32 @@ test "utf8ToUtf16LeStringLiteral" {
785785 mem.nativeToLittle(u16, 0xDC37),
786786 };
787787 const utf16 = utf8ToUtf16LeStringLiteral("𐐷");
788 testing.expectEqualSlices(u16, &bytes, utf16);
789 testing.expect(utf16[2] == 0);
788 try testing.expectEqualSlices(u16, &bytes, utf16);
789 try testing.expect(utf16[2] == 0);
790790 }
791791 {
792792 const bytes = [_:0]u16{
793793 mem.nativeToLittle(u16, 0x02FF),
794794 };
795795 const utf16 = utf8ToUtf16LeStringLiteral("\u{02FF}");
796 testing.expectEqualSlices(u16, &bytes, utf16);
797 testing.expect(utf16[1] == 0);
796 try testing.expectEqualSlices(u16, &bytes, utf16);
797 try testing.expect(utf16[1] == 0);
798798 }
799799 {
800800 const bytes = [_:0]u16{
801801 mem.nativeToLittle(u16, 0x7FF),
802802 };
803803 const utf16 = utf8ToUtf16LeStringLiteral("\u{7FF}");
804 testing.expectEqualSlices(u16, &bytes, utf16);
805 testing.expect(utf16[1] == 0);
804 try testing.expectEqualSlices(u16, &bytes, utf16);
805 try testing.expect(utf16[1] == 0);
806806 }
807807 {
808808 const bytes = [_:0]u16{
809809 mem.nativeToLittle(u16, 0x801),
810810 };
811811 const utf16 = utf8ToUtf16LeStringLiteral("\u{801}");
812 testing.expectEqualSlices(u16, &bytes, utf16);
813 testing.expect(utf16[1] == 0);
812 try testing.expectEqualSlices(u16, &bytes, utf16);
813 try testing.expect(utf16[1] == 0);
814814 }
815815 {
816816 const bytes = [_:0]u16{
......@@ -818,35 +818,35 @@ test "utf8ToUtf16LeStringLiteral" {
818818 mem.nativeToLittle(u16, 0xDFFF),
819819 };
820820 const utf16 = utf8ToUtf16LeStringLiteral("\u{10FFFF}");
821 testing.expectEqualSlices(u16, &bytes, utf16);
822 testing.expect(utf16[2] == 0);
821 try testing.expectEqualSlices(u16, &bytes, utf16);
822 try testing.expect(utf16[2] == 0);
823823 }
824824}
825825
826826fn testUtf8CountCodepoints() !void {
827 testing.expectEqual(@as(usize, 10), try utf8CountCodepoints("abcdefghij"));
828 testing.expectEqual(@as(usize, 10), try utf8CountCodepoints("äåéëþüúíóö"));
829 testing.expectEqual(@as(usize, 5), try utf8CountCodepoints("こんにちは"));
827 try testing.expectEqual(@as(usize, 10), try utf8CountCodepoints("abcdefghij"));
828 try testing.expectEqual(@as(usize, 10), try utf8CountCodepoints("äåéëþüúíóö"));
829 try testing.expectEqual(@as(usize, 5), try utf8CountCodepoints("こんにちは"));
830830 // testing.expectError(error.Utf8EncodesSurrogateHalf, utf8CountCodepoints("\xED\xA0\x80"));
831831}
832832
833833test "utf8 count codepoints" {
834834 try testUtf8CountCodepoints();
835 comptime testUtf8CountCodepoints() catch unreachable;
835 comptime try testUtf8CountCodepoints();
836836}
837837
838838fn testUtf8ValidCodepoint() !void {
839 testing.expect(utf8ValidCodepoint('e'));
840 testing.expect(utf8ValidCodepoint('ë'));
841 testing.expect(utf8ValidCodepoint('は'));
842 testing.expect(utf8ValidCodepoint(0xe000));
843 testing.expect(utf8ValidCodepoint(0x10ffff));
844 testing.expect(!utf8ValidCodepoint(0xd800));
845 testing.expect(!utf8ValidCodepoint(0xdfff));
846 testing.expect(!utf8ValidCodepoint(0x110000));
839 try testing.expect(utf8ValidCodepoint('e'));
840 try testing.expect(utf8ValidCodepoint('ë'));
841 try testing.expect(utf8ValidCodepoint('は'));
842 try testing.expect(utf8ValidCodepoint(0xe000));
843 try testing.expect(utf8ValidCodepoint(0x10ffff));
844 try testing.expect(!utf8ValidCodepoint(0xd800));
845 try testing.expect(!utf8ValidCodepoint(0xdfff));
846 try testing.expect(!utf8ValidCodepoint(0x110000));
847847}
848848
849849test "utf8 valid codepoint" {
850850 try testUtf8ValidCodepoint();
851 comptime testUtf8ValidCodepoint() catch unreachable;
851 comptime try testUtf8ValidCodepoint();
852852}
lib/std/valgrind/memcheck.zig+2-2
......@@ -149,7 +149,7 @@ pub fn countLeaks() CountResult {
149149}
150150
151151test "countLeaks" {
152 testing.expectEqual(
152 try testing.expectEqual(
153153 @as(CountResult, .{
154154 .leaked = 0,
155155 .dubious = 0,
......@@ -179,7 +179,7 @@ pub fn countLeakBlocks() CountResult {
179179}
180180
181181test "countLeakBlocks" {
182 testing.expectEqual(
182 try testing.expectEqual(
183183 @as(CountResult, .{
184184 .leaked = 0,
185185 .dubious = 0,
lib/std/wasm.zig+9-9
......@@ -200,11 +200,11 @@ test "Wasm - opcodes" {
200200 const local_get = opcode(.local_get);
201201 const i64_extend32_s = opcode(.i64_extend32_s);
202202
203 testing.expectEqual(@as(u16, 0x41), i32_const);
204 testing.expectEqual(@as(u16, 0x0B), end);
205 testing.expectEqual(@as(u16, 0x1A), drop);
206 testing.expectEqual(@as(u16, 0x20), local_get);
207 testing.expectEqual(@as(u16, 0xC4), i64_extend32_s);
203 try testing.expectEqual(@as(u16, 0x41), i32_const);
204 try testing.expectEqual(@as(u16, 0x0B), end);
205 try testing.expectEqual(@as(u16, 0x1A), drop);
206 try testing.expectEqual(@as(u16, 0x20), local_get);
207 try testing.expectEqual(@as(u16, 0xC4), i64_extend32_s);
208208}
209209
210210/// Enum representing all Wasm value types as per spec:
......@@ -227,10 +227,10 @@ test "Wasm - valtypes" {
227227 const _f32 = valtype(.f32);
228228 const _f64 = valtype(.f64);
229229
230 testing.expectEqual(@as(u8, 0x7F), _i32);
231 testing.expectEqual(@as(u8, 0x7E), _i64);
232 testing.expectEqual(@as(u8, 0x7D), _f32);
233 testing.expectEqual(@as(u8, 0x7C), _f64);
230 try testing.expectEqual(@as(u8, 0x7F), _i32);
231 try testing.expectEqual(@as(u8, 0x7E), _i64);
232 try testing.expectEqual(@as(u8, 0x7D), _f32);
233 try testing.expectEqual(@as(u8, 0x7C), _f64);
234234}
235235
236236/// 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" {
322322 defer conn.deinit();
323323
324324 var buf: [1]u8 = undefined;
325 testing.expectError(error.WouldBlock, client.read(&buf));
325 try testing.expectError(error.WouldBlock, client.read(&buf));
326326}
327327
328328test "tcp/listener: bind to unspecified ipv4 address" {
......@@ -335,7 +335,7 @@ test "tcp/listener: bind to unspecified ipv4 address" {
335335 try listener.listen(128);
336336
337337 const address = try listener.getLocalAddress();
338 testing.expect(address == .ipv4);
338 try testing.expect(address == .ipv4);
339339}
340340
341341test "tcp/listener: bind to unspecified ipv6 address" {
......@@ -348,5 +348,5 @@ test "tcp/listener: bind to unspecified ipv6 address" {
348348 try listener.listen(128);
349349
350350 const address = try listener.getLocalAddress();
351 testing.expect(address == .ipv6);
351 try testing.expect(address == .ipv6);
352352}
lib/std/x/os/net.zig+3-3
......@@ -499,12 +499,12 @@ test {
499499
500500test "ip: convert to and from ipv6" {
501501 try testing.expectFmt("::7f00:1", "{}", .{IPv4.localhost.toIPv6()});
502 testing.expect(!IPv4.localhost.toIPv6().mapsToIPv4());
502 try testing.expect(!IPv4.localhost.toIPv6().mapsToIPv4());
503503
504504 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);
508508 try testing.expectFmt("127.0.0.1", "{}", .{IPv4.localhost.mapToIPv6().toIPv4()});
509509}
510510
lib/std/zig.zig+19-19
......@@ -253,26 +253,26 @@ pub fn parseCharLiteral(
253253
254254test "parseCharLiteral" {
255255 var bad_index: usize = undefined;
256 std.testing.expectEqual(try parseCharLiteral("'a'", &bad_index), 'a');
257 std.testing.expectEqual(try parseCharLiteral("'ä'", &bad_index), 'ä');
258 std.testing.expectEqual(try parseCharLiteral("'\\x00'", &bad_index), 0);
259 std.testing.expectEqual(try parseCharLiteral("'\\x4f'", &bad_index), 0x4f);
260 std.testing.expectEqual(try parseCharLiteral("'\\x4F'", &bad_index), 0x4f);
261 std.testing.expectEqual(try parseCharLiteral("'ぁ'", &bad_index), 0x3041);
262 std.testing.expectEqual(try parseCharLiteral("'\\u{0}'", &bad_index), 0);
263 std.testing.expectEqual(try parseCharLiteral("'\\u{3041}'", &bad_index), 0x3041);
264 std.testing.expectEqual(try parseCharLiteral("'\\u{7f}'", &bad_index), 0x7f);
265 std.testing.expectEqual(try parseCharLiteral("'\\u{7FFF}'", &bad_index), 0x7FFF);
256 try std.testing.expectEqual(try parseCharLiteral("'a'", &bad_index), 'a');
257 try std.testing.expectEqual(try parseCharLiteral("'ä'", &bad_index), 'ä');
258 try std.testing.expectEqual(try parseCharLiteral("'\\x00'", &bad_index), 0);
259 try std.testing.expectEqual(try parseCharLiteral("'\\x4f'", &bad_index), 0x4f);
260 try std.testing.expectEqual(try parseCharLiteral("'\\x4F'", &bad_index), 0x4f);
261 try std.testing.expectEqual(try parseCharLiteral("'ぁ'", &bad_index), 0x3041);
262 try std.testing.expectEqual(try parseCharLiteral("'\\u{0}'", &bad_index), 0);
263 try std.testing.expectEqual(try parseCharLiteral("'\\u{3041}'", &bad_index), 0x3041);
264 try std.testing.expectEqual(try parseCharLiteral("'\\u{7f}'", &bad_index), 0x7f);
265 try std.testing.expectEqual(try parseCharLiteral("'\\u{7FFF}'", &bad_index), 0x7FFF);
266266
267 std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\x0'", &bad_index));
268 std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\x000'", &bad_index));
269 std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\y'", &bad_index));
270 std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u'", &bad_index));
271 std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\uFFFF'", &bad_index));
272 std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{}'", &bad_index));
273 std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{FFFFFF}'", &bad_index));
274 std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{FFFF'", &bad_index));
275 std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{FFFF}x'", &bad_index));
267 try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\x0'", &bad_index));
268 try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\x000'", &bad_index));
269 try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\y'", &bad_index));
270 try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u'", &bad_index));
271 try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\uFFFF'", &bad_index));
272 try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{}'", &bad_index));
273 try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{FFFFFF}'", &bad_index));
274 try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{FFFF'", &bad_index));
275 try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{FFFF}x'", &bad_index));
276276}
277277
278278test {
lib/std/zig/cross_target.zig+38-38
......@@ -800,7 +800,7 @@ test "CrossTarget.parse" {
800800 .{@tagName(std.Target.current.abi)},
801801 ) catch unreachable;
802802
803 std.testing.expectEqualSlices(u8, triple, text);
803 try std.testing.expectEqualSlices(u8, triple, text);
804804 }
805805 {
806806 const cross_target = try CrossTarget.parse(.{
......@@ -808,18 +808,18 @@ test "CrossTarget.parse" {
808808 .cpu_features = "native",
809809 });
810810
811 std.testing.expect(cross_target.cpu_arch.? == .aarch64);
812 std.testing.expect(cross_target.cpu_model == .native);
811 try std.testing.expect(cross_target.cpu_arch.? == .aarch64);
812 try std.testing.expect(cross_target.cpu_model == .native);
813813 }
814814 {
815815 const cross_target = try CrossTarget.parse(.{ .arch_os_abi = "native" });
816816
817 std.testing.expect(cross_target.cpu_arch == null);
818 std.testing.expect(cross_target.isNative());
817 try std.testing.expect(cross_target.cpu_arch == null);
818 try std.testing.expect(cross_target.isNative());
819819
820820 const text = try cross_target.zigTriple(std.testing.allocator);
821821 defer std.testing.allocator.free(text);
822 std.testing.expectEqualSlices(u8, "native", text);
822 try std.testing.expectEqualSlices(u8, "native", text);
823823 }
824824 {
825825 const cross_target = try CrossTarget.parse(.{
......@@ -828,23 +828,23 @@ test "CrossTarget.parse" {
828828 });
829829 const target = cross_target.toTarget();
830830
831 std.testing.expect(target.os.tag == .linux);
832 std.testing.expect(target.abi == .gnu);
833 std.testing.expect(target.cpu.arch == .x86_64);
834 std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .sse));
835 std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .avx));
836 std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .cx8));
837 std.testing.expect(Target.x86.featureSetHas(target.cpu.features, .cmov));
838 std.testing.expect(Target.x86.featureSetHas(target.cpu.features, .fxsr));
831 try std.testing.expect(target.os.tag == .linux);
832 try std.testing.expect(target.abi == .gnu);
833 try std.testing.expect(target.cpu.arch == .x86_64);
834 try std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .sse));
835 try std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .avx));
836 try std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .cx8));
837 try std.testing.expect(Target.x86.featureSetHas(target.cpu.features, .cmov));
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 }));
841 std.testing.expect(!Target.x86.featureSetHasAny(target.cpu.features, .{ .sse, .avx }));
842 std.testing.expect(Target.x86.featureSetHasAll(target.cpu.features, .{ .mmx, .x87 }));
843 std.testing.expect(!Target.x86.featureSetHasAll(target.cpu.features, .{ .mmx, .x87, .sse }));
840 try std.testing.expect(Target.x86.featureSetHasAny(target.cpu.features, .{ .sse, .avx, .cmov }));
841 try std.testing.expect(!Target.x86.featureSetHasAny(target.cpu.features, .{ .sse, .avx }));
842 try std.testing.expect(Target.x86.featureSetHasAll(target.cpu.features, .{ .mmx, .x87 }));
843 try std.testing.expect(!Target.x86.featureSetHasAll(target.cpu.features, .{ .mmx, .x87, .sse }));
844844
845845 const text = try cross_target.zigTriple(std.testing.allocator);
846846 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);
848848 }
849849 {
850850 const cross_target = try CrossTarget.parse(.{
......@@ -853,15 +853,15 @@ test "CrossTarget.parse" {
853853 });
854854 const target = cross_target.toTarget();
855855
856 std.testing.expect(target.os.tag == .linux);
857 std.testing.expect(target.abi == .musleabihf);
858 std.testing.expect(target.cpu.arch == .arm);
859 std.testing.expect(target.cpu.model == &Target.arm.cpu.generic);
860 std.testing.expect(Target.arm.featureSetHas(target.cpu.features, .v8a));
856 try std.testing.expect(target.os.tag == .linux);
857 try std.testing.expect(target.abi == .musleabihf);
858 try std.testing.expect(target.cpu.arch == .arm);
859 try std.testing.expect(target.cpu.model == &Target.arm.cpu.generic);
860 try std.testing.expect(Target.arm.featureSetHas(target.cpu.features, .v8a));
861861
862862 const text = try cross_target.zigTriple(std.testing.allocator);
863863 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);
865865 }
866866 {
867867 const cross_target = try CrossTarget.parse(.{
......@@ -870,21 +870,21 @@ test "CrossTarget.parse" {
870870 });
871871 const target = cross_target.toTarget();
872872
873 std.testing.expect(target.cpu.arch == .aarch64);
874 std.testing.expect(target.os.tag == .linux);
875 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);
877 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);
879 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);
881 std.testing.expect(target.os.version_range.linux.glibc.major == 2);
882 std.testing.expect(target.os.version_range.linux.glibc.minor == 27);
883 std.testing.expect(target.os.version_range.linux.glibc.patch == 0);
884 std.testing.expect(target.abi == .gnu);
873 try std.testing.expect(target.cpu.arch == .aarch64);
874 try std.testing.expect(target.os.tag == .linux);
875 try std.testing.expect(target.os.version_range.linux.range.min.major == 3);
876 try std.testing.expect(target.os.version_range.linux.range.min.minor == 10);
877 try std.testing.expect(target.os.version_range.linux.range.min.patch == 0);
878 try std.testing.expect(target.os.version_range.linux.range.max.major == 4);
879 try std.testing.expect(target.os.version_range.linux.range.max.minor == 4);
880 try std.testing.expect(target.os.version_range.linux.range.max.patch == 1);
881 try std.testing.expect(target.os.version_range.linux.glibc.major == 2);
882 try std.testing.expect(target.os.version_range.linux.glibc.minor == 27);
883 try std.testing.expect(target.os.version_range.linux.glibc.patch == 0);
884 try std.testing.expect(target.abi == .gnu);
885885
886886 const text = try cross_target.zigTriple(std.testing.allocator);
887887 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);
889889 }
890890}
lib/std/zig/parser_test.zig+9-10
......@@ -988,7 +988,7 @@ test "zig fmt: while else err prong with no block" {
988988 \\ const result = while (returnError()) |value| {
989989 \\ break value;
990990 \\ } else |err| @as(i32, 2);
991 \\ expect(result == 2);
991 \\ try expect(result == 2);
992992 \\}
993993 \\
994994 );
......@@ -5135,7 +5135,7 @@ test "recovery: missing while rbrace" {
51355135
51365136const std = @import("std");
51375137const mem = std.mem;
5138const warn = std.debug.warn;
5138const print = std.debug.print;
51395139const io = std.io;
51405140const maxInt = std.math.maxInt;
51415141
......@@ -5177,13 +5177,13 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {
51775177 var failing_allocator = std.testing.FailingAllocator.init(&fixed_allocator.allocator, maxInt(usize));
51785178 var anything_changed: bool = undefined;
51795179 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);
51815181 const changes_expected = source.ptr != expected_source.ptr;
51825182 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 });
51845184 return error.TestFailed;
51855185 }
5186 std.testing.expect(anything_changed == changes_expected);
5186 try std.testing.expect(anything_changed == changes_expected);
51875187 failing_allocator.allocator.free(result_source);
51885188 break :x failing_allocator.index;
51895189 };
......@@ -5198,7 +5198,7 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {
51985198 } else |err| switch (err) {
51995199 error.OutOfMemory => {
52005200 if (failing_allocator.allocated_bytes != failing_allocator.freed_bytes) {
5201 warn(
5201 print(
52025202 "\nfail_index: {d}/{d}\nallocated bytes: {d}\nfreed bytes: {d}\nallocations: {d}\ndeallocations: {d}\n",
52035203 .{
52045204 fail_index,
......@@ -5212,8 +5212,7 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {
52125212 return error.MemoryLeakDetected;
52135213 }
52145214 },
5215 error.ParseError => @panic("test failed"),
5216 else => @panic("test failed"),
5215 else => return err,
52175216 }
52185217 }
52195218}
......@@ -5227,8 +5226,8 @@ fn testError(source: []const u8, expected_errors: []const Error) !void {
52275226 var tree = try std.zig.parse(std.testing.allocator, source);
52285227 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);
52315230 for (expected_errors) |expected, i| {
5232 std.testing.expectEqual(expected, tree.errors[i].tag);
5231 try std.testing.expectEqual(expected, tree.errors[i].tag);
52335232 }
52345233}
lib/std/zig/string_literal.zig+3-3
......@@ -153,7 +153,7 @@ test "parse" {
153153 var fixed_buf_alloc = std.heap.FixedBufferAllocator.init(fixed_buf_mem[0..]);
154154 var alloc = &fixed_buf_alloc.allocator;
155155
156 expect(eql(u8, "foo", try parseAlloc(alloc, "\"foo\"")));
157 expect(eql(u8, "foo", try parseAlloc(alloc, "\"f\x6f\x6f\"")));
158 expect(eql(u8, "f💯", try parseAlloc(alloc, "\"f\u{1f4af}\"")));
156 try expect(eql(u8, "foo", try parseAlloc(alloc, "\"foo\"")));
157 try expect(eql(u8, "foo", try parseAlloc(alloc, "\"f\x6f\x6f\"")));
158 try expect(eql(u8, "f💯", try parseAlloc(alloc, "\"f\u{1f4af}\"")));
159159}
lib/std/zig/system/linux.zig+2-2
......@@ -414,8 +414,8 @@ fn testParser(
414414) !void {
415415 var fbs = io.fixedBufferStream(input);
416416 const result = try parser.parse(arch, fbs.reader());
417 testing.expectEqual(expected_model, result.?.model);
418 testing.expect(expected_model.features.eql(result.?.features));
417 try testing.expectEqual(expected_model, result.?.model);
418 try testing.expect(expected_model.features.eql(result.?.features));
419419}
420420
421421// 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)
402402 var b_got: [64]u8 = undefined;
403403 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);
406406}
407407
408408/// Detect SDK path on Darwin.
lib/std/zig/tokenizer.zig+294-294
......@@ -1503,11 +1503,11 @@ pub const Tokenizer = struct {
15031503};
15041504
15051505test "tokenizer" {
1506 testTokenize("test", &.{.keyword_test});
1506 try testTokenize("test", &.{.keyword_test});
15071507}
15081508
15091509test "line comment followed by top-level comptime" {
1510 testTokenize(
1510 try testTokenize(
15111511 \\// line comment
15121512 \\comptime {}
15131513 \\
......@@ -1519,7 +1519,7 @@ test "line comment followed by top-level comptime" {
15191519}
15201520
15211521test "tokenizer - unknown length pointer and then c pointer" {
1522 testTokenize(
1522 try testTokenize(
15231523 \\[*]u8
15241524 \\[*c]u8
15251525 , &.{
......@@ -1536,72 +1536,72 @@ test "tokenizer - unknown length pointer and then c pointer" {
15361536}
15371537
15381538test "tokenizer - code point literal with hex escape" {
1539 testTokenize(
1539 try testTokenize(
15401540 \\'\x1b'
15411541 , &.{.char_literal});
1542 testTokenize(
1542 try testTokenize(
15431543 \\'\x1'
15441544 , &.{ .invalid, .invalid });
15451545}
15461546
15471547test "tokenizer - code point literal with unicode escapes" {
15481548 // Valid unicode escapes
1549 testTokenize(
1549 try testTokenize(
15501550 \\'\u{3}'
15511551 , &.{.char_literal});
1552 testTokenize(
1552 try testTokenize(
15531553 \\'\u{01}'
15541554 , &.{.char_literal});
1555 testTokenize(
1555 try testTokenize(
15561556 \\'\u{2a}'
15571557 , &.{.char_literal});
1558 testTokenize(
1558 try testTokenize(
15591559 \\'\u{3f9}'
15601560 , &.{.char_literal});
1561 testTokenize(
1561 try testTokenize(
15621562 \\'\u{6E09aBc1523}'
15631563 , &.{.char_literal});
1564 testTokenize(
1564 try testTokenize(
15651565 \\"\u{440}"
15661566 , &.{.string_literal});
15671567
15681568 // Invalid unicode escapes
1569 testTokenize(
1569 try testTokenize(
15701570 \\'\u'
15711571 , &.{.invalid});
1572 testTokenize(
1572 try testTokenize(
15731573 \\'\u{{'
15741574 , &.{ .invalid, .invalid });
1575 testTokenize(
1575 try testTokenize(
15761576 \\'\u{}'
15771577 , &.{ .invalid, .invalid });
1578 testTokenize(
1578 try testTokenize(
15791579 \\'\u{s}'
15801580 , &.{ .invalid, .invalid });
1581 testTokenize(
1581 try testTokenize(
15821582 \\'\u{2z}'
15831583 , &.{ .invalid, .invalid });
1584 testTokenize(
1584 try testTokenize(
15851585 \\'\u{4a'
15861586 , &.{.invalid});
15871587
15881588 // Test old-style unicode literals
1589 testTokenize(
1589 try testTokenize(
15901590 \\'\u0333'
15911591 , &.{ .invalid, .invalid });
1592 testTokenize(
1592 try testTokenize(
15931593 \\'\U0333'
15941594 , &.{ .invalid, .integer_literal, .invalid });
15951595}
15961596
15971597test "tokenizer - code point literal with unicode code point" {
1598 testTokenize(
1598 try testTokenize(
15991599 \\'💩'
16001600 , &.{.char_literal});
16011601}
16021602
16031603test "tokenizer - float literal e exponent" {
1604 testTokenize("a = 4.94065645841246544177e-324;\n", &.{
1604 try testTokenize("a = 4.94065645841246544177e-324;\n", &.{
16051605 .identifier,
16061606 .equal,
16071607 .float_literal,
......@@ -1610,7 +1610,7 @@ test "tokenizer - float literal e exponent" {
16101610}
16111611
16121612test "tokenizer - float literal p exponent" {
1613 testTokenize("a = 0x1.a827999fcef32p+1022;\n", &.{
1613 try testTokenize("a = 0x1.a827999fcef32p+1022;\n", &.{
16141614 .identifier,
16151615 .equal,
16161616 .float_literal,
......@@ -1619,84 +1619,84 @@ test "tokenizer - float literal p exponent" {
16191619}
16201620
16211621test "tokenizer - chars" {
1622 testTokenize("'c'", &.{.char_literal});
1622 try testTokenize("'c'", &.{.char_literal});
16231623}
16241624
16251625test "tokenizer - invalid token characters" {
1626 testTokenize("#", &.{.invalid});
1627 testTokenize("`", &.{.invalid});
1628 testTokenize("'c", &.{.invalid});
1629 testTokenize("'", &.{.invalid});
1630 testTokenize("''", &.{ .invalid, .invalid });
1626 try testTokenize("#", &.{.invalid});
1627 try testTokenize("`", &.{.invalid});
1628 try testTokenize("'c", &.{.invalid});
1629 try testTokenize("'", &.{.invalid});
1630 try testTokenize("''", &.{ .invalid, .invalid });
16311631}
16321632
16331633test "tokenizer - invalid literal/comment characters" {
1634 testTokenize("\"\x00\"", &.{
1634 try testTokenize("\"\x00\"", &.{
16351635 .string_literal,
16361636 .invalid,
16371637 });
1638 testTokenize("//\x00", &.{
1638 try testTokenize("//\x00", &.{
16391639 .invalid,
16401640 });
1641 testTokenize("//\x1f", &.{
1641 try testTokenize("//\x1f", &.{
16421642 .invalid,
16431643 });
1644 testTokenize("//\x7f", &.{
1644 try testTokenize("//\x7f", &.{
16451645 .invalid,
16461646 });
16471647}
16481648
16491649test "tokenizer - utf8" {
1650 testTokenize("//\xc2\x80", &.{});
1651 testTokenize("//\xf4\x8f\xbf\xbf", &.{});
1650 try testTokenize("//\xc2\x80", &.{});
1651 try testTokenize("//\xf4\x8f\xbf\xbf", &.{});
16521652}
16531653
16541654test "tokenizer - invalid utf8" {
1655 testTokenize("//\x80", &.{
1655 try testTokenize("//\x80", &.{
16561656 .invalid,
16571657 });
1658 testTokenize("//\xbf", &.{
1658 try testTokenize("//\xbf", &.{
16591659 .invalid,
16601660 });
1661 testTokenize("//\xf8", &.{
1661 try testTokenize("//\xf8", &.{
16621662 .invalid,
16631663 });
1664 testTokenize("//\xff", &.{
1664 try testTokenize("//\xff", &.{
16651665 .invalid,
16661666 });
1667 testTokenize("//\xc2\xc0", &.{
1667 try testTokenize("//\xc2\xc0", &.{
16681668 .invalid,
16691669 });
1670 testTokenize("//\xe0", &.{
1670 try testTokenize("//\xe0", &.{
16711671 .invalid,
16721672 });
1673 testTokenize("//\xf0", &.{
1673 try testTokenize("//\xf0", &.{
16741674 .invalid,
16751675 });
1676 testTokenize("//\xf0\x90\x80\xc0", &.{
1676 try testTokenize("//\xf0\x90\x80\xc0", &.{
16771677 .invalid,
16781678 });
16791679}
16801680
16811681test "tokenizer - illegal unicode codepoints" {
16821682 // unicode newline characters.U+0085, U+2028, U+2029
1683 testTokenize("//\xc2\x84", &.{});
1684 testTokenize("//\xc2\x85", &.{
1683 try testTokenize("//\xc2\x84", &.{});
1684 try testTokenize("//\xc2\x85", &.{
16851685 .invalid,
16861686 });
1687 testTokenize("//\xc2\x86", &.{});
1688 testTokenize("//\xe2\x80\xa7", &.{});
1689 testTokenize("//\xe2\x80\xa8", &.{
1687 try testTokenize("//\xc2\x86", &.{});
1688 try testTokenize("//\xe2\x80\xa7", &.{});
1689 try testTokenize("//\xe2\x80\xa8", &.{
16901690 .invalid,
16911691 });
1692 testTokenize("//\xe2\x80\xa9", &.{
1692 try testTokenize("//\xe2\x80\xa9", &.{
16931693 .invalid,
16941694 });
1695 testTokenize("//\xe2\x80\xaa", &.{});
1695 try testTokenize("//\xe2\x80\xaa", &.{});
16961696}
16971697
16981698test "tokenizer - string identifier and builtin fns" {
1699 testTokenize(
1699 try testTokenize(
17001700 \\const @"if" = @import("std");
17011701 , &.{
17021702 .keyword_const,
......@@ -1711,7 +1711,7 @@ test "tokenizer - string identifier and builtin fns" {
17111711}
17121712
17131713test "tokenizer - multiline string literal with literal tab" {
1714 testTokenize(
1714 try testTokenize(
17151715 \\\\foo bar
17161716 , &.{
17171717 .multiline_string_literal_line,
......@@ -1719,7 +1719,7 @@ test "tokenizer - multiline string literal with literal tab" {
17191719}
17201720
17211721test "tokenizer - comments with literal tab" {
1722 testTokenize(
1722 try testTokenize(
17231723 \\//foo bar
17241724 \\//!foo bar
17251725 \\///foo bar
......@@ -1735,25 +1735,25 @@ test "tokenizer - comments with literal tab" {
17351735}
17361736
17371737test "tokenizer - pipe and then invalid" {
1738 testTokenize("||=", &.{
1738 try testTokenize("||=", &.{
17391739 .pipe_pipe,
17401740 .equal,
17411741 });
17421742}
17431743
17441744test "tokenizer - line comment and doc comment" {
1745 testTokenize("//", &.{});
1746 testTokenize("// a / b", &.{});
1747 testTokenize("// /", &.{});
1748 testTokenize("/// a", &.{.doc_comment});
1749 testTokenize("///", &.{.doc_comment});
1750 testTokenize("////", &.{});
1751 testTokenize("//!", &.{.container_doc_comment});
1752 testTokenize("//!!", &.{.container_doc_comment});
1745 try testTokenize("//", &.{});
1746 try testTokenize("// a / b", &.{});
1747 try testTokenize("// /", &.{});
1748 try testTokenize("/// a", &.{.doc_comment});
1749 try testTokenize("///", &.{.doc_comment});
1750 try testTokenize("////", &.{});
1751 try testTokenize("//!", &.{.container_doc_comment});
1752 try testTokenize("//!!", &.{.container_doc_comment});
17531753}
17541754
17551755test "tokenizer - line comment followed by identifier" {
1756 testTokenize(
1756 try testTokenize(
17571757 \\ Unexpected,
17581758 \\ // another
17591759 \\ Another,
......@@ -1766,14 +1766,14 @@ test "tokenizer - line comment followed by identifier" {
17661766}
17671767
17681768test "tokenizer - UTF-8 BOM is recognized and skipped" {
1769 testTokenize("\xEF\xBB\xBFa;\n", &.{
1769 try testTokenize("\xEF\xBB\xBFa;\n", &.{
17701770 .identifier,
17711771 .semicolon,
17721772 });
17731773}
17741774
17751775test "correctly parse pointer assignment" {
1776 testTokenize("b.*=3;\n", &.{
1776 try testTokenize("b.*=3;\n", &.{
17771777 .identifier,
17781778 .period_asterisk,
17791779 .equal,
......@@ -1783,14 +1783,14 @@ test "correctly parse pointer assignment" {
17831783}
17841784
17851785test "correctly parse pointer dereference followed by asterisk" {
1786 testTokenize("\"b\".* ** 10", &.{
1786 try testTokenize("\"b\".* ** 10", &.{
17871787 .string_literal,
17881788 .period_asterisk,
17891789 .asterisk_asterisk,
17901790 .integer_literal,
17911791 });
17921792
1793 testTokenize("(\"b\".*)** 10", &.{
1793 try testTokenize("(\"b\".*)** 10", &.{
17941794 .l_paren,
17951795 .string_literal,
17961796 .period_asterisk,
......@@ -1799,7 +1799,7 @@ test "correctly parse pointer dereference followed by asterisk" {
17991799 .integer_literal,
18001800 });
18011801
1802 testTokenize("\"b\".*** 10", &.{
1802 try testTokenize("\"b\".*** 10", &.{
18031803 .string_literal,
18041804 .invalid_periodasterisks,
18051805 .asterisk_asterisk,
......@@ -1808,245 +1808,245 @@ test "correctly parse pointer dereference followed by asterisk" {
18081808}
18091809
18101810test "tokenizer - range literals" {
1811 testTokenize("0...9", &.{ .integer_literal, .ellipsis3, .integer_literal });
1812 testTokenize("'0'...'9'", &.{ .char_literal, .ellipsis3, .char_literal });
1813 testTokenize("0x00...0x09", &.{ .integer_literal, .ellipsis3, .integer_literal });
1814 testTokenize("0b00...0b11", &.{ .integer_literal, .ellipsis3, .integer_literal });
1815 testTokenize("0o00...0o11", &.{ .integer_literal, .ellipsis3, .integer_literal });
1811 try testTokenize("0...9", &.{ .integer_literal, .ellipsis3, .integer_literal });
1812 try testTokenize("'0'...'9'", &.{ .char_literal, .ellipsis3, .char_literal });
1813 try testTokenize("0x00...0x09", &.{ .integer_literal, .ellipsis3, .integer_literal });
1814 try testTokenize("0b00...0b11", &.{ .integer_literal, .ellipsis3, .integer_literal });
1815 try testTokenize("0o00...0o11", &.{ .integer_literal, .ellipsis3, .integer_literal });
18161816}
18171817
18181818test "tokenizer - number literals decimal" {
1819 testTokenize("0", &.{.integer_literal});
1820 testTokenize("1", &.{.integer_literal});
1821 testTokenize("2", &.{.integer_literal});
1822 testTokenize("3", &.{.integer_literal});
1823 testTokenize("4", &.{.integer_literal});
1824 testTokenize("5", &.{.integer_literal});
1825 testTokenize("6", &.{.integer_literal});
1826 testTokenize("7", &.{.integer_literal});
1827 testTokenize("8", &.{.integer_literal});
1828 testTokenize("9", &.{.integer_literal});
1829 testTokenize("1..", &.{ .integer_literal, .ellipsis2 });
1830 testTokenize("0a", &.{ .invalid, .identifier });
1831 testTokenize("9b", &.{ .invalid, .identifier });
1832 testTokenize("1z", &.{ .invalid, .identifier });
1833 testTokenize("1z_1", &.{ .invalid, .identifier });
1834 testTokenize("9z3", &.{ .invalid, .identifier });
1835
1836 testTokenize("0_0", &.{.integer_literal});
1837 testTokenize("0001", &.{.integer_literal});
1838 testTokenize("01234567890", &.{.integer_literal});
1839 testTokenize("012_345_6789_0", &.{.integer_literal});
1840 testTokenize("0_1_2_3_4_5_6_7_8_9_0", &.{.integer_literal});
1841
1842 testTokenize("00_", &.{.invalid});
1843 testTokenize("0_0_", &.{.invalid});
1844 testTokenize("0__0", &.{ .invalid, .identifier });
1845 testTokenize("0_0f", &.{ .invalid, .identifier });
1846 testTokenize("0_0_f", &.{ .invalid, .identifier });
1847 testTokenize("0_0_f_00", &.{ .invalid, .identifier });
1848 testTokenize("1_,", &.{ .invalid, .comma });
1849
1850 testTokenize("1.", &.{.float_literal});
1851 testTokenize("0.0", &.{.float_literal});
1852 testTokenize("1.0", &.{.float_literal});
1853 testTokenize("10.0", &.{.float_literal});
1854 testTokenize("0e0", &.{.float_literal});
1855 testTokenize("1e0", &.{.float_literal});
1856 testTokenize("1e100", &.{.float_literal});
1857 testTokenize("1.e100", &.{.float_literal});
1858 testTokenize("1.0e100", &.{.float_literal});
1859 testTokenize("1.0e+100", &.{.float_literal});
1860 testTokenize("1.0e-100", &.{.float_literal});
1861 testTokenize("1_0_0_0.0_0_0_0_0_1e1_0_0_0", &.{.float_literal});
1862 testTokenize("1.+", &.{ .float_literal, .plus });
1863
1864 testTokenize("1e", &.{.invalid});
1865 testTokenize("1.0e1f0", &.{ .invalid, .identifier });
1866 testTokenize("1.0p100", &.{ .invalid, .identifier });
1867 testTokenize("1.0p-100", &.{ .invalid, .identifier, .minus, .integer_literal });
1868 testTokenize("1.0p1f0", &.{ .invalid, .identifier });
1869 testTokenize("1.0_,", &.{ .invalid, .comma });
1870 testTokenize("1_.0", &.{ .invalid, .period, .integer_literal });
1871 testTokenize("1._", &.{ .invalid, .identifier });
1872 testTokenize("1.a", &.{ .invalid, .identifier });
1873 testTokenize("1.z", &.{ .invalid, .identifier });
1874 testTokenize("1._0", &.{ .invalid, .identifier });
1875 testTokenize("1._+", &.{ .invalid, .identifier, .plus });
1876 testTokenize("1._e", &.{ .invalid, .identifier });
1877 testTokenize("1.0e", &.{.invalid});
1878 testTokenize("1.0e,", &.{ .invalid, .comma });
1879 testTokenize("1.0e_", &.{ .invalid, .identifier });
1880 testTokenize("1.0e+_", &.{ .invalid, .identifier });
1881 testTokenize("1.0e-_", &.{ .invalid, .identifier });
1882 testTokenize("1.0e0_+", &.{ .invalid, .plus });
1819 try testTokenize("0", &.{.integer_literal});
1820 try testTokenize("1", &.{.integer_literal});
1821 try testTokenize("2", &.{.integer_literal});
1822 try testTokenize("3", &.{.integer_literal});
1823 try testTokenize("4", &.{.integer_literal});
1824 try testTokenize("5", &.{.integer_literal});
1825 try testTokenize("6", &.{.integer_literal});
1826 try testTokenize("7", &.{.integer_literal});
1827 try testTokenize("8", &.{.integer_literal});
1828 try testTokenize("9", &.{.integer_literal});
1829 try testTokenize("1..", &.{ .integer_literal, .ellipsis2 });
1830 try testTokenize("0a", &.{ .invalid, .identifier });
1831 try testTokenize("9b", &.{ .invalid, .identifier });
1832 try testTokenize("1z", &.{ .invalid, .identifier });
1833 try testTokenize("1z_1", &.{ .invalid, .identifier });
1834 try testTokenize("9z3", &.{ .invalid, .identifier });
1835
1836 try testTokenize("0_0", &.{.integer_literal});
1837 try testTokenize("0001", &.{.integer_literal});
1838 try testTokenize("01234567890", &.{.integer_literal});
1839 try testTokenize("012_345_6789_0", &.{.integer_literal});
1840 try testTokenize("0_1_2_3_4_5_6_7_8_9_0", &.{.integer_literal});
1841
1842 try testTokenize("00_", &.{.invalid});
1843 try testTokenize("0_0_", &.{.invalid});
1844 try testTokenize("0__0", &.{ .invalid, .identifier });
1845 try testTokenize("0_0f", &.{ .invalid, .identifier });
1846 try testTokenize("0_0_f", &.{ .invalid, .identifier });
1847 try testTokenize("0_0_f_00", &.{ .invalid, .identifier });
1848 try testTokenize("1_,", &.{ .invalid, .comma });
1849
1850 try testTokenize("1.", &.{.float_literal});
1851 try testTokenize("0.0", &.{.float_literal});
1852 try testTokenize("1.0", &.{.float_literal});
1853 try testTokenize("10.0", &.{.float_literal});
1854 try testTokenize("0e0", &.{.float_literal});
1855 try testTokenize("1e0", &.{.float_literal});
1856 try testTokenize("1e100", &.{.float_literal});
1857 try testTokenize("1.e100", &.{.float_literal});
1858 try testTokenize("1.0e100", &.{.float_literal});
1859 try testTokenize("1.0e+100", &.{.float_literal});
1860 try testTokenize("1.0e-100", &.{.float_literal});
1861 try testTokenize("1_0_0_0.0_0_0_0_0_1e1_0_0_0", &.{.float_literal});
1862 try testTokenize("1.+", &.{ .float_literal, .plus });
1863
1864 try testTokenize("1e", &.{.invalid});
1865 try testTokenize("1.0e1f0", &.{ .invalid, .identifier });
1866 try testTokenize("1.0p100", &.{ .invalid, .identifier });
1867 try testTokenize("1.0p-100", &.{ .invalid, .identifier, .minus, .integer_literal });
1868 try testTokenize("1.0p1f0", &.{ .invalid, .identifier });
1869 try testTokenize("1.0_,", &.{ .invalid, .comma });
1870 try testTokenize("1_.0", &.{ .invalid, .period, .integer_literal });
1871 try testTokenize("1._", &.{ .invalid, .identifier });
1872 try testTokenize("1.a", &.{ .invalid, .identifier });
1873 try testTokenize("1.z", &.{ .invalid, .identifier });
1874 try testTokenize("1._0", &.{ .invalid, .identifier });
1875 try testTokenize("1._+", &.{ .invalid, .identifier, .plus });
1876 try testTokenize("1._e", &.{ .invalid, .identifier });
1877 try testTokenize("1.0e", &.{.invalid});
1878 try testTokenize("1.0e,", &.{ .invalid, .comma });
1879 try testTokenize("1.0e_", &.{ .invalid, .identifier });
1880 try testTokenize("1.0e+_", &.{ .invalid, .identifier });
1881 try testTokenize("1.0e-_", &.{ .invalid, .identifier });
1882 try testTokenize("1.0e0_+", &.{ .invalid, .plus });
18831883}
18841884
18851885test "tokenizer - number literals binary" {
1886 testTokenize("0b0", &.{.integer_literal});
1887 testTokenize("0b1", &.{.integer_literal});
1888 testTokenize("0b2", &.{ .invalid, .integer_literal });
1889 testTokenize("0b3", &.{ .invalid, .integer_literal });
1890 testTokenize("0b4", &.{ .invalid, .integer_literal });
1891 testTokenize("0b5", &.{ .invalid, .integer_literal });
1892 testTokenize("0b6", &.{ .invalid, .integer_literal });
1893 testTokenize("0b7", &.{ .invalid, .integer_literal });
1894 testTokenize("0b8", &.{ .invalid, .integer_literal });
1895 testTokenize("0b9", &.{ .invalid, .integer_literal });
1896 testTokenize("0ba", &.{ .invalid, .identifier });
1897 testTokenize("0bb", &.{ .invalid, .identifier });
1898 testTokenize("0bc", &.{ .invalid, .identifier });
1899 testTokenize("0bd", &.{ .invalid, .identifier });
1900 testTokenize("0be", &.{ .invalid, .identifier });
1901 testTokenize("0bf", &.{ .invalid, .identifier });
1902 testTokenize("0bz", &.{ .invalid, .identifier });
1903
1904 testTokenize("0b0000_0000", &.{.integer_literal});
1905 testTokenize("0b1111_1111", &.{.integer_literal});
1906 testTokenize("0b10_10_10_10", &.{.integer_literal});
1907 testTokenize("0b0_1_0_1_0_1_0_1", &.{.integer_literal});
1908 testTokenize("0b1.", &.{ .integer_literal, .period });
1909 testTokenize("0b1.0", &.{ .integer_literal, .period, .integer_literal });
1910
1911 testTokenize("0B0", &.{ .invalid, .identifier });
1912 testTokenize("0b_", &.{ .invalid, .identifier });
1913 testTokenize("0b_0", &.{ .invalid, .identifier });
1914 testTokenize("0b1_", &.{.invalid});
1915 testTokenize("0b0__1", &.{ .invalid, .identifier });
1916 testTokenize("0b0_1_", &.{.invalid});
1917 testTokenize("0b1e", &.{ .invalid, .identifier });
1918 testTokenize("0b1p", &.{ .invalid, .identifier });
1919 testTokenize("0b1e0", &.{ .invalid, .identifier });
1920 testTokenize("0b1p0", &.{ .invalid, .identifier });
1921 testTokenize("0b1_,", &.{ .invalid, .comma });
1886 try testTokenize("0b0", &.{.integer_literal});
1887 try testTokenize("0b1", &.{.integer_literal});
1888 try testTokenize("0b2", &.{ .invalid, .integer_literal });
1889 try testTokenize("0b3", &.{ .invalid, .integer_literal });
1890 try testTokenize("0b4", &.{ .invalid, .integer_literal });
1891 try testTokenize("0b5", &.{ .invalid, .integer_literal });
1892 try testTokenize("0b6", &.{ .invalid, .integer_literal });
1893 try testTokenize("0b7", &.{ .invalid, .integer_literal });
1894 try testTokenize("0b8", &.{ .invalid, .integer_literal });
1895 try testTokenize("0b9", &.{ .invalid, .integer_literal });
1896 try testTokenize("0ba", &.{ .invalid, .identifier });
1897 try testTokenize("0bb", &.{ .invalid, .identifier });
1898 try testTokenize("0bc", &.{ .invalid, .identifier });
1899 try testTokenize("0bd", &.{ .invalid, .identifier });
1900 try testTokenize("0be", &.{ .invalid, .identifier });
1901 try testTokenize("0bf", &.{ .invalid, .identifier });
1902 try testTokenize("0bz", &.{ .invalid, .identifier });
1903
1904 try testTokenize("0b0000_0000", &.{.integer_literal});
1905 try testTokenize("0b1111_1111", &.{.integer_literal});
1906 try testTokenize("0b10_10_10_10", &.{.integer_literal});
1907 try testTokenize("0b0_1_0_1_0_1_0_1", &.{.integer_literal});
1908 try testTokenize("0b1.", &.{ .integer_literal, .period });
1909 try testTokenize("0b1.0", &.{ .integer_literal, .period, .integer_literal });
1910
1911 try testTokenize("0B0", &.{ .invalid, .identifier });
1912 try testTokenize("0b_", &.{ .invalid, .identifier });
1913 try testTokenize("0b_0", &.{ .invalid, .identifier });
1914 try testTokenize("0b1_", &.{.invalid});
1915 try testTokenize("0b0__1", &.{ .invalid, .identifier });
1916 try testTokenize("0b0_1_", &.{.invalid});
1917 try testTokenize("0b1e", &.{ .invalid, .identifier });
1918 try testTokenize("0b1p", &.{ .invalid, .identifier });
1919 try testTokenize("0b1e0", &.{ .invalid, .identifier });
1920 try testTokenize("0b1p0", &.{ .invalid, .identifier });
1921 try testTokenize("0b1_,", &.{ .invalid, .comma });
19221922}
19231923
19241924test "tokenizer - number literals octal" {
1925 testTokenize("0o0", &.{.integer_literal});
1926 testTokenize("0o1", &.{.integer_literal});
1927 testTokenize("0o2", &.{.integer_literal});
1928 testTokenize("0o3", &.{.integer_literal});
1929 testTokenize("0o4", &.{.integer_literal});
1930 testTokenize("0o5", &.{.integer_literal});
1931 testTokenize("0o6", &.{.integer_literal});
1932 testTokenize("0o7", &.{.integer_literal});
1933 testTokenize("0o8", &.{ .invalid, .integer_literal });
1934 testTokenize("0o9", &.{ .invalid, .integer_literal });
1935 testTokenize("0oa", &.{ .invalid, .identifier });
1936 testTokenize("0ob", &.{ .invalid, .identifier });
1937 testTokenize("0oc", &.{ .invalid, .identifier });
1938 testTokenize("0od", &.{ .invalid, .identifier });
1939 testTokenize("0oe", &.{ .invalid, .identifier });
1940 testTokenize("0of", &.{ .invalid, .identifier });
1941 testTokenize("0oz", &.{ .invalid, .identifier });
1942
1943 testTokenize("0o01234567", &.{.integer_literal});
1944 testTokenize("0o0123_4567", &.{.integer_literal});
1945 testTokenize("0o01_23_45_67", &.{.integer_literal});
1946 testTokenize("0o0_1_2_3_4_5_6_7", &.{.integer_literal});
1947 testTokenize("0o7.", &.{ .integer_literal, .period });
1948 testTokenize("0o7.0", &.{ .integer_literal, .period, .integer_literal });
1949
1950 testTokenize("0O0", &.{ .invalid, .identifier });
1951 testTokenize("0o_", &.{ .invalid, .identifier });
1952 testTokenize("0o_0", &.{ .invalid, .identifier });
1953 testTokenize("0o1_", &.{.invalid});
1954 testTokenize("0o0__1", &.{ .invalid, .identifier });
1955 testTokenize("0o0_1_", &.{.invalid});
1956 testTokenize("0o1e", &.{ .invalid, .identifier });
1957 testTokenize("0o1p", &.{ .invalid, .identifier });
1958 testTokenize("0o1e0", &.{ .invalid, .identifier });
1959 testTokenize("0o1p0", &.{ .invalid, .identifier });
1960 testTokenize("0o_,", &.{ .invalid, .identifier, .comma });
1925 try testTokenize("0o0", &.{.integer_literal});
1926 try testTokenize("0o1", &.{.integer_literal});
1927 try testTokenize("0o2", &.{.integer_literal});
1928 try testTokenize("0o3", &.{.integer_literal});
1929 try testTokenize("0o4", &.{.integer_literal});
1930 try testTokenize("0o5", &.{.integer_literal});
1931 try testTokenize("0o6", &.{.integer_literal});
1932 try testTokenize("0o7", &.{.integer_literal});
1933 try testTokenize("0o8", &.{ .invalid, .integer_literal });
1934 try testTokenize("0o9", &.{ .invalid, .integer_literal });
1935 try testTokenize("0oa", &.{ .invalid, .identifier });
1936 try testTokenize("0ob", &.{ .invalid, .identifier });
1937 try testTokenize("0oc", &.{ .invalid, .identifier });
1938 try testTokenize("0od", &.{ .invalid, .identifier });
1939 try testTokenize("0oe", &.{ .invalid, .identifier });
1940 try testTokenize("0of", &.{ .invalid, .identifier });
1941 try testTokenize("0oz", &.{ .invalid, .identifier });
1942
1943 try testTokenize("0o01234567", &.{.integer_literal});
1944 try testTokenize("0o0123_4567", &.{.integer_literal});
1945 try testTokenize("0o01_23_45_67", &.{.integer_literal});
1946 try testTokenize("0o0_1_2_3_4_5_6_7", &.{.integer_literal});
1947 try testTokenize("0o7.", &.{ .integer_literal, .period });
1948 try testTokenize("0o7.0", &.{ .integer_literal, .period, .integer_literal });
1949
1950 try testTokenize("0O0", &.{ .invalid, .identifier });
1951 try testTokenize("0o_", &.{ .invalid, .identifier });
1952 try testTokenize("0o_0", &.{ .invalid, .identifier });
1953 try testTokenize("0o1_", &.{.invalid});
1954 try testTokenize("0o0__1", &.{ .invalid, .identifier });
1955 try testTokenize("0o0_1_", &.{.invalid});
1956 try testTokenize("0o1e", &.{ .invalid, .identifier });
1957 try testTokenize("0o1p", &.{ .invalid, .identifier });
1958 try testTokenize("0o1e0", &.{ .invalid, .identifier });
1959 try testTokenize("0o1p0", &.{ .invalid, .identifier });
1960 try testTokenize("0o_,", &.{ .invalid, .identifier, .comma });
19611961}
19621962
19631963test "tokenizer - number literals hexadeciaml" {
1964 testTokenize("0x0", &.{.integer_literal});
1965 testTokenize("0x1", &.{.integer_literal});
1966 testTokenize("0x2", &.{.integer_literal});
1967 testTokenize("0x3", &.{.integer_literal});
1968 testTokenize("0x4", &.{.integer_literal});
1969 testTokenize("0x5", &.{.integer_literal});
1970 testTokenize("0x6", &.{.integer_literal});
1971 testTokenize("0x7", &.{.integer_literal});
1972 testTokenize("0x8", &.{.integer_literal});
1973 testTokenize("0x9", &.{.integer_literal});
1974 testTokenize("0xa", &.{.integer_literal});
1975 testTokenize("0xb", &.{.integer_literal});
1976 testTokenize("0xc", &.{.integer_literal});
1977 testTokenize("0xd", &.{.integer_literal});
1978 testTokenize("0xe", &.{.integer_literal});
1979 testTokenize("0xf", &.{.integer_literal});
1980 testTokenize("0xA", &.{.integer_literal});
1981 testTokenize("0xB", &.{.integer_literal});
1982 testTokenize("0xC", &.{.integer_literal});
1983 testTokenize("0xD", &.{.integer_literal});
1984 testTokenize("0xE", &.{.integer_literal});
1985 testTokenize("0xF", &.{.integer_literal});
1986 testTokenize("0x0z", &.{ .invalid, .identifier });
1987 testTokenize("0xz", &.{ .invalid, .identifier });
1988
1989 testTokenize("0x0123456789ABCDEF", &.{.integer_literal});
1990 testTokenize("0x0123_4567_89AB_CDEF", &.{.integer_literal});
1991 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});
1993
1994 testTokenize("0X0", &.{ .invalid, .identifier });
1995 testTokenize("0x_", &.{ .invalid, .identifier });
1996 testTokenize("0x_1", &.{ .invalid, .identifier });
1997 testTokenize("0x1_", &.{.invalid});
1998 testTokenize("0x0__1", &.{ .invalid, .identifier });
1999 testTokenize("0x0_1_", &.{.invalid});
2000 testTokenize("0x_,", &.{ .invalid, .identifier, .comma });
2001
2002 testTokenize("0x1.", &.{.float_literal});
2003 testTokenize("0x1.0", &.{.float_literal});
2004 testTokenize("0xF.", &.{.float_literal});
2005 testTokenize("0xF.0", &.{.float_literal});
2006 testTokenize("0xF.F", &.{.float_literal});
2007 testTokenize("0xF.Fp0", &.{.float_literal});
2008 testTokenize("0xF.FP0", &.{.float_literal});
2009 testTokenize("0x1p0", &.{.float_literal});
2010 testTokenize("0xfp0", &.{.float_literal});
2011 testTokenize("0x1.+0xF.", &.{ .float_literal, .plus, .float_literal });
2012
2013 testTokenize("0x0123456.789ABCDEF", &.{.float_literal});
2014 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});
2016 testTokenize("0x0p0", &.{.float_literal});
2017 testTokenize("0x0.0p0", &.{.float_literal});
2018 testTokenize("0xff.ffp10", &.{.float_literal});
2019 testTokenize("0xff.ffP10", &.{.float_literal});
2020 testTokenize("0xff.p10", &.{.float_literal});
2021 testTokenize("0xffp10", &.{.float_literal});
2022 testTokenize("0xff_ff.ff_ffp1_0_0_0", &.{.float_literal});
2023 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});
2025
2026 testTokenize("0x1e", &.{.integer_literal});
2027 testTokenize("0x1e0", &.{.integer_literal});
2028 testTokenize("0x1p", &.{.invalid});
2029 testTokenize("0xfp0z1", &.{ .invalid, .identifier });
2030 testTokenize("0xff.ffpff", &.{ .invalid, .identifier });
2031 testTokenize("0x0.p", &.{.invalid});
2032 testTokenize("0x0.z", &.{ .invalid, .identifier });
2033 testTokenize("0x0._", &.{ .invalid, .identifier });
2034 testTokenize("0x0_.0", &.{ .invalid, .period, .integer_literal });
2035 testTokenize("0x0_.0.0", &.{ .invalid, .period, .float_literal });
2036 testTokenize("0x0._0", &.{ .invalid, .identifier });
2037 testTokenize("0x0.0_", &.{.invalid});
2038 testTokenize("0x0_p0", &.{ .invalid, .identifier });
2039 testTokenize("0x0_.p0", &.{ .invalid, .period, .identifier });
2040 testTokenize("0x0._p0", &.{ .invalid, .identifier });
2041 testTokenize("0x0.0_p0", &.{ .invalid, .identifier });
2042 testTokenize("0x0._0p0", &.{ .invalid, .identifier });
2043 testTokenize("0x0.0p_0", &.{ .invalid, .identifier });
2044 testTokenize("0x0.0p+_0", &.{ .invalid, .identifier });
2045 testTokenize("0x0.0p-_0", &.{ .invalid, .identifier });
2046 testTokenize("0x0.0p0_", &.{ .invalid, .eof });
1964 try testTokenize("0x0", &.{.integer_literal});
1965 try testTokenize("0x1", &.{.integer_literal});
1966 try testTokenize("0x2", &.{.integer_literal});
1967 try testTokenize("0x3", &.{.integer_literal});
1968 try testTokenize("0x4", &.{.integer_literal});
1969 try testTokenize("0x5", &.{.integer_literal});
1970 try testTokenize("0x6", &.{.integer_literal});
1971 try testTokenize("0x7", &.{.integer_literal});
1972 try testTokenize("0x8", &.{.integer_literal});
1973 try testTokenize("0x9", &.{.integer_literal});
1974 try testTokenize("0xa", &.{.integer_literal});
1975 try testTokenize("0xb", &.{.integer_literal});
1976 try testTokenize("0xc", &.{.integer_literal});
1977 try testTokenize("0xd", &.{.integer_literal});
1978 try testTokenize("0xe", &.{.integer_literal});
1979 try testTokenize("0xf", &.{.integer_literal});
1980 try testTokenize("0xA", &.{.integer_literal});
1981 try testTokenize("0xB", &.{.integer_literal});
1982 try testTokenize("0xC", &.{.integer_literal});
1983 try testTokenize("0xD", &.{.integer_literal});
1984 try testTokenize("0xE", &.{.integer_literal});
1985 try testTokenize("0xF", &.{.integer_literal});
1986 try testTokenize("0x0z", &.{ .invalid, .identifier });
1987 try testTokenize("0xz", &.{ .invalid, .identifier });
1988
1989 try testTokenize("0x0123456789ABCDEF", &.{.integer_literal});
1990 try testTokenize("0x0123_4567_89AB_CDEF", &.{.integer_literal});
1991 try testTokenize("0x01_23_45_67_89AB_CDE_F", &.{.integer_literal});
1992 try testTokenize("0x0_1_2_3_4_5_6_7_8_9_A_B_C_D_E_F", &.{.integer_literal});
1993
1994 try testTokenize("0X0", &.{ .invalid, .identifier });
1995 try testTokenize("0x_", &.{ .invalid, .identifier });
1996 try testTokenize("0x_1", &.{ .invalid, .identifier });
1997 try testTokenize("0x1_", &.{.invalid});
1998 try testTokenize("0x0__1", &.{ .invalid, .identifier });
1999 try testTokenize("0x0_1_", &.{.invalid});
2000 try testTokenize("0x_,", &.{ .invalid, .identifier, .comma });
2001
2002 try testTokenize("0x1.", &.{.float_literal});
2003 try testTokenize("0x1.0", &.{.float_literal});
2004 try testTokenize("0xF.", &.{.float_literal});
2005 try testTokenize("0xF.0", &.{.float_literal});
2006 try testTokenize("0xF.F", &.{.float_literal});
2007 try testTokenize("0xF.Fp0", &.{.float_literal});
2008 try testTokenize("0xF.FP0", &.{.float_literal});
2009 try testTokenize("0x1p0", &.{.float_literal});
2010 try testTokenize("0xfp0", &.{.float_literal});
2011 try testTokenize("0x1.+0xF.", &.{ .float_literal, .plus, .float_literal });
2012
2013 try testTokenize("0x0123456.789ABCDEF", &.{.float_literal});
2014 try testTokenize("0x0_123_456.789_ABC_DEF", &.{.float_literal});
2015 try testTokenize("0x0_1_2_3_4_5_6.7_8_9_A_B_C_D_E_F", &.{.float_literal});
2016 try testTokenize("0x0p0", &.{.float_literal});
2017 try testTokenize("0x0.0p0", &.{.float_literal});
2018 try testTokenize("0xff.ffp10", &.{.float_literal});
2019 try testTokenize("0xff.ffP10", &.{.float_literal});
2020 try testTokenize("0xff.p10", &.{.float_literal});
2021 try testTokenize("0xffp10", &.{.float_literal});
2022 try testTokenize("0xff_ff.ff_ffp1_0_0_0", &.{.float_literal});
2023 try testTokenize("0xf_f_f_f.f_f_f_fp+1_000", &.{.float_literal});
2024 try testTokenize("0xf_f_f_f.f_f_f_fp-1_00_0", &.{.float_literal});
2025
2026 try testTokenize("0x1e", &.{.integer_literal});
2027 try testTokenize("0x1e0", &.{.integer_literal});
2028 try testTokenize("0x1p", &.{.invalid});
2029 try testTokenize("0xfp0z1", &.{ .invalid, .identifier });
2030 try testTokenize("0xff.ffpff", &.{ .invalid, .identifier });
2031 try testTokenize("0x0.p", &.{.invalid});
2032 try testTokenize("0x0.z", &.{ .invalid, .identifier });
2033 try testTokenize("0x0._", &.{ .invalid, .identifier });
2034 try testTokenize("0x0_.0", &.{ .invalid, .period, .integer_literal });
2035 try testTokenize("0x0_.0.0", &.{ .invalid, .period, .float_literal });
2036 try testTokenize("0x0._0", &.{ .invalid, .identifier });
2037 try testTokenize("0x0.0_", &.{.invalid});
2038 try testTokenize("0x0_p0", &.{ .invalid, .identifier });
2039 try testTokenize("0x0_.p0", &.{ .invalid, .period, .identifier });
2040 try testTokenize("0x0._p0", &.{ .invalid, .identifier });
2041 try testTokenize("0x0.0_p0", &.{ .invalid, .identifier });
2042 try testTokenize("0x0._0p0", &.{ .invalid, .identifier });
2043 try testTokenize("0x0.0p_0", &.{ .invalid, .identifier });
2044 try testTokenize("0x0.0p+_0", &.{ .invalid, .identifier });
2045 try testTokenize("0x0.0p-_0", &.{ .invalid, .identifier });
2046 try testTokenize("0x0.0p0_", &.{ .invalid, .eof });
20472047}
20482048
2049fn testTokenize(source: []const u8, expected_tokens: []const Token.Tag) void {
2049fn testTokenize(source: []const u8, expected_tokens: []const Token.Tag) !void {
20502050 var tokenizer = Tokenizer.init(source);
20512051 for (expected_tokens) |expected_token_id| {
20522052 const token = tokenizer.next();
......@@ -2055,6 +2055,6 @@ fn testTokenize(source: []const u8, expected_tokens: []const Token.Tag) void {
20552055 }
20562056 }
20572057 const last_token = tokenizer.next();
2058 std.testing.expect(last_token.tag == .eof);
2059 std.testing.expect(last_token.loc.start == source.len);
2058 try std.testing.expect(last_token.tag == .eof);
2059 try std.testing.expect(last_token.loc.start == source.len);
20602060}