authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-02-08 18:18:47-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-02-08 18:23:38-05:00
logc2db077574be841da586fa62d67619c901dd535d
treec8eb64846fa7ffb9027fa1ca035dd8ca5712b9d4
parentbe6d022257d8d7e99bd080823d4d8f0175f320c5
signature Commit is signed but in an unrecognized format.

std.debug.assert: remove special case for test builds

Previously, std.debug.assert would `@panic` in test builds, if the assertion failed. Now, it's always `unreachable`. This makes release mode test builds more accurately test the actual code that will be run. However this requires tests to call `std.testing.expect` rather than `std.debug.assert` to make sure output is correct. Here is the explanation of when to use either one, copied from the assert doc comments: Inside a test block, it is best to use the `std.testing` module rather than assert, because assert may not detect a test failure in ReleaseFast and ReleaseSafe mode. Outside of a test block, assert is the correct function to use. closes #1304

239 files changed, 4106 insertions(+), 3960 deletions(-)

CMakeLists.txt+1
......@@ -658,6 +658,7 @@ set(ZIG_STD_FILES
658658 "special/test_runner.zig"
659659 "spinlock.zig"
660660 "statically_initialized_mutex.zig"
661 "testing.zig"
661662 "unicode.zig"
662663 "zig/ast.zig"
663664 "zig/index.zig"
doc/docgen.zig+2-2
......@@ -4,7 +4,7 @@ const io = std.io;
44const os = std.os;
55const warn = std.debug.warn;
66const mem = std.mem;
7const assert = std.debug.assert;
7const testing = std.testing;
88
99const max_doc_file_size = 10 * 1024 * 1024;
1010
......@@ -620,7 +620,7 @@ const TermState = enum {
620620test "term color" {
621621 const input_bytes = "A\x1b[32;1mgreen\x1b[0mB";
622622 const result = try termColor(std.debug.global_allocator, input_bytes);
623 assert(mem.eql(u8, result, "A<span class=\"t32\">green</span>B"));
623 testing.expectEqualSlices(u8, "A<span class=\"t32\">green</span>B", result));
624624}
625625
626626fn termColor(allocator: *mem.Allocator, input: []const u8) ![]u8 {
src-self-hosted/arg.zig+12-11
......@@ -1,5 +1,6 @@
11const std = @import("std");
22const debug = std.debug;
3const testing = std.testing;
34const mem = std.mem;
45
56const Allocator = mem.Allocator;
......@@ -272,21 +273,21 @@ test "parse arguments" {
272273
273274 var args = try Args.parse(std.debug.global_allocator, spec1, cliargs);
274275
275 debug.assert(args.present("help"));
276 debug.assert(!args.present("help2"));
277 debug.assert(!args.present("init"));
276 testing.expect(args.present("help"));
277 testing.expect(!args.present("help2"));
278 testing.expect(!args.present("init"));
278279
279 debug.assert(mem.eql(u8, args.single("build-file").?, "build.zig"));
280 debug.assert(mem.eql(u8, args.single("color").?, "on"));
280 testing.expect(mem.eql(u8, args.single("build-file").?, "build.zig"));
281 testing.expect(mem.eql(u8, args.single("color").?, "on"));
281282
282283 const objects = args.many("object").?;
283 debug.assert(mem.eql(u8, objects[0], "obj1"));
284 debug.assert(mem.eql(u8, objects[1], "obj2"));
284 testing.expect(mem.eql(u8, objects[0], "obj1"));
285 testing.expect(mem.eql(u8, objects[1], "obj2"));
285286
286 debug.assert(mem.eql(u8, args.single("library").?, "lib2"));
287 testing.expect(mem.eql(u8, args.single("library").?, "lib2"));
287288
288289 const pos = args.positionals.toSliceConst();
289 debug.assert(mem.eql(u8, pos[0], "build"));
290 debug.assert(mem.eql(u8, pos[1], "pos1"));
291 debug.assert(mem.eql(u8, pos[2], "pos2"));
290 testing.expect(mem.eql(u8, pos[0], "build"));
291 testing.expect(mem.eql(u8, pos[1], "pos1"));
292 testing.expect(mem.eql(u8, pos[2], "pos2"));
292293}
src-self-hosted/test.zig+2-2
......@@ -4,7 +4,7 @@ const builtin = @import("builtin");
44const Target = @import("target.zig").Target;
55const Compilation = @import("compilation.zig").Compilation;
66const introspect = @import("introspect.zig");
7const assertOrPanic = std.debug.assertOrPanic;
7const testing = std.testing;
88const errmsg = @import("errmsg.zig");
99const ZigCompiler = @import("compilation.zig").ZigCompiler;
1010
......@@ -210,7 +210,7 @@ pub const TestContext = struct {
210210 @panic("build incorrectly failed");
211211 },
212212 Compilation.Event.Fail => |msgs| {
213 assertOrPanic(msgs.len != 0);
213 testing.expect(msgs.len != 0);
214214 for (msgs) |msg| {
215215 if (mem.endsWith(u8, msg.realpath, path) and mem.eql(u8, msg.text, text)) {
216216 const span = msg.getSpan();
src/ir.cpp+14-10
......@@ -17543,21 +17543,16 @@ static void make_enum_field_val(IrAnalyze *ira, ConstExprValue *enum_field_val,
1754317543 enum_field_val->data.x_struct.fields = inner_fields;
1754417544}
1754517545
17546static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstExprValue **out) {
17546static Error ir_make_type_info_value(IrAnalyze *ira, AstNode *source_node, ZigType *type_entry, ConstExprValue **out) {
1754717547 Error err;
1754817548 assert(type_entry != nullptr);
1754917549 assert(!type_is_invalid(type_entry));
1755017550
17551 if ((err = ensure_complete_type(ira->codegen, type_entry)))
17551 if ((err = type_resolve(ira->codegen, type_entry, ResolveStatusSizeKnown)))
1755217552 return err;
1755317553
17554 if (type_entry == ira->codegen->builtin_types.entry_global_error_set) {
17555 zig_panic("TODO implement @typeInfo for global error set");
17556 }
17557
1755817554 ConstExprValue *result = nullptr;
17559 switch (type_entry->id)
17560 {
17555 switch (type_entry->id) {
1756117556 case ZigTypeIdInvalid:
1756217557 zig_unreachable();
1756317558 case ZigTypeIdMetaType:
......@@ -17778,6 +17773,15 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE
1777817773 ensure_field_index(result->type, "errors", 0);
1777917774
1778017775 ZigType *type_info_error_type = ir_type_info_get_type(ira, "Error", nullptr);
17776 if (!resolve_inferred_error_set(ira->codegen, type_entry, source_node)) {
17777 return ErrorSemanticAnalyzeFail;
17778 }
17779 if (type_is_global_error_set(type_entry)) {
17780 ir_add_error_node(ira, source_node,
17781 buf_sprintf("TODO: compiler bug: implement @typeInfo support for anyerror. https://github.com/ziglang/zig/issues/1936"));
17782 return ErrorSemanticAnalyzeFail;
17783 }
17784
1778117785 uint32_t error_count = type_entry->data.error_set.err_count;
1778217786 ConstExprValue *error_array = create_const_vals(1);
1778317787 error_array->special = ConstValSpecialStatic;
......@@ -18103,7 +18107,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE
1810318107 {
1810418108 ZigType *fn_type = type_entry->data.bound_fn.fn_type;
1810518109 assert(fn_type->id == ZigTypeIdFn);
18106 if ((err = ir_make_type_info_value(ira, fn_type, &result)))
18110 if ((err = ir_make_type_info_value(ira, source_node, fn_type, &result)))
1810718111 return err;
1810818112
1810918113 break;
......@@ -18128,7 +18132,7 @@ static IrInstruction *ir_analyze_instruction_type_info(IrAnalyze *ira,
1812818132 ZigType *result_type = ir_type_info_get_type(ira, nullptr, nullptr);
1812918133
1813018134 ConstExprValue *payload;
18131 if ((err = ir_make_type_info_value(ira, type_entry, &payload)))
18135 if ((err = ir_make_type_info_value(ira, instruction->base.source_node, type_entry, &payload)))
1813218136 return ira->codegen->invalid_instruction;
1813318137
1813418138 IrInstruction *result = ir_const(ira, &instruction->base, result_type);
std/array_list.zig+53-53
......@@ -1,7 +1,7 @@
11const std = @import("index.zig");
22const debug = std.debug;
33const assert = debug.assert;
4const assertError = debug.assertError;
4const testing = std.testing;
55const mem = std.mem;
66const Allocator = mem.Allocator;
77
......@@ -212,8 +212,8 @@ test "std.ArrayList.init" {
212212 var list = ArrayList(i32).init(allocator);
213213 defer list.deinit();
214214
215 assert(list.count() == 0);
216 assert(list.capacity() == 0);
215 testing.expect(list.count() == 0);
216 testing.expect(list.capacity() == 0);
217217}
218218
219219test "std.ArrayList.basic" {
......@@ -224,7 +224,7 @@ test "std.ArrayList.basic" {
224224 defer list.deinit();
225225
226226 // setting on empty list is out of bounds
227 assertError(list.setOrError(0, 1), error.OutOfBounds);
227 testing.expectError(error.OutOfBounds, list.setOrError(0, 1));
228228
229229 {
230230 var i: usize = 0;
......@@ -236,44 +236,44 @@ test "std.ArrayList.basic" {
236236 {
237237 var i: usize = 0;
238238 while (i < 10) : (i += 1) {
239 assert(list.items[i] == @intCast(i32, i + 1));
239 testing.expect(list.items[i] == @intCast(i32, i + 1));
240240 }
241241 }
242242
243243 for (list.toSlice()) |v, i| {
244 assert(v == @intCast(i32, i + 1));
244 testing.expect(v == @intCast(i32, i + 1));
245245 }
246246
247247 for (list.toSliceConst()) |v, i| {
248 assert(v == @intCast(i32, i + 1));
248 testing.expect(v == @intCast(i32, i + 1));
249249 }
250250
251 assert(list.pop() == 10);
252 assert(list.len == 9);
251 testing.expect(list.pop() == 10);
252 testing.expect(list.len == 9);
253253
254254 list.appendSlice([]const i32{
255255 1,
256256 2,
257257 3,
258258 }) catch unreachable;
259 assert(list.len == 12);
260 assert(list.pop() == 3);
261 assert(list.pop() == 2);
262 assert(list.pop() == 1);
263 assert(list.len == 9);
259 testing.expect(list.len == 12);
260 testing.expect(list.pop() == 3);
261 testing.expect(list.pop() == 2);
262 testing.expect(list.pop() == 1);
263 testing.expect(list.len == 9);
264264
265265 list.appendSlice([]const i32{}) catch unreachable;
266 assert(list.len == 9);
266 testing.expect(list.len == 9);
267267
268268 // can only set on indices < self.len
269269 list.set(7, 33);
270270 list.set(8, 42);
271271
272 assertError(list.setOrError(9, 99), error.OutOfBounds);
273 assertError(list.setOrError(10, 123), error.OutOfBounds);
272 testing.expectError(error.OutOfBounds, list.setOrError(9, 99));
273 testing.expectError(error.OutOfBounds, list.setOrError(10, 123));
274274
275 assert(list.pop() == 42);
276 assert(list.pop() == 33);
275 testing.expect(list.pop() == 42);
276 testing.expect(list.pop() == 33);
277277}
278278
279279test "std.ArrayList.swapRemove" {
......@@ -289,18 +289,18 @@ test "std.ArrayList.swapRemove" {
289289 try list.append(7);
290290
291291 //remove from middle
292 assert(list.swapRemove(3) == 4);
293 assert(list.at(3) == 7);
294 assert(list.len == 6);
292 testing.expect(list.swapRemove(3) == 4);
293 testing.expect(list.at(3) == 7);
294 testing.expect(list.len == 6);
295295
296296 //remove from end
297 assert(list.swapRemove(5) == 6);
298 assert(list.len == 5);
297 testing.expect(list.swapRemove(5) == 6);
298 testing.expect(list.len == 5);
299299
300300 //remove from front
301 assert(list.swapRemove(0) == 1);
302 assert(list.at(0) == 5);
303 assert(list.len == 4);
301 testing.expect(list.swapRemove(0) == 1);
302 testing.expect(list.at(0) == 5);
303 testing.expect(list.len == 4);
304304}
305305
306306test "std.ArrayList.swapRemoveOrError" {
......@@ -308,27 +308,27 @@ test "std.ArrayList.swapRemoveOrError" {
308308 defer list.deinit();
309309
310310 // Test just after initialization
311 assertError(list.swapRemoveOrError(0), error.OutOfBounds);
311 testing.expectError(error.OutOfBounds, list.swapRemoveOrError(0));
312312
313313 // Test after adding one item and remote it
314314 try list.append(1);
315 assert((try list.swapRemoveOrError(0)) == 1);
316 assertError(list.swapRemoveOrError(0), error.OutOfBounds);
315 testing.expect((try list.swapRemoveOrError(0)) == 1);
316 testing.expectError(error.OutOfBounds, list.swapRemoveOrError(0));
317317
318318 // Test after adding two items and remote both
319319 try list.append(1);
320320 try list.append(2);
321 assert((try list.swapRemoveOrError(1)) == 2);
322 assert((try list.swapRemoveOrError(0)) == 1);
323 assertError(list.swapRemoveOrError(0), error.OutOfBounds);
321 testing.expect((try list.swapRemoveOrError(1)) == 2);
322 testing.expect((try list.swapRemoveOrError(0)) == 1);
323 testing.expectError(error.OutOfBounds, list.swapRemoveOrError(0));
324324
325325 // Test out of bounds with one item
326326 try list.append(1);
327 assertError(list.swapRemoveOrError(1), error.OutOfBounds);
327 testing.expectError(error.OutOfBounds, list.swapRemoveOrError(1));
328328
329329 // Test out of bounds with two items
330330 try list.append(2);
331 assertError(list.swapRemoveOrError(2), error.OutOfBounds);
331 testing.expectError(error.OutOfBounds, list.swapRemoveOrError(2));
332332}
333333
334334test "std.ArrayList.iterator" {
......@@ -342,22 +342,22 @@ test "std.ArrayList.iterator" {
342342 var count: i32 = 0;
343343 var it = list.iterator();
344344 while (it.next()) |next| {
345 assert(next == count + 1);
345 testing.expect(next == count + 1);
346346 count += 1;
347347 }
348348
349 assert(count == 3);
350 assert(it.next() == null);
349 testing.expect(count == 3);
350 testing.expect(it.next() == null);
351351 it.reset();
352352 count = 0;
353353 while (it.next()) |next| {
354 assert(next == count + 1);
354 testing.expect(next == count + 1);
355355 count += 1;
356356 if (count == 2) break;
357357 }
358358
359359 it.reset();
360 assert(it.next().? == 1);
360 testing.expect(it.next().? == 1);
361361}
362362
363363test "std.ArrayList.insert" {
......@@ -368,10 +368,10 @@ test "std.ArrayList.insert" {
368368 try list.append(2);
369369 try list.append(3);
370370 try list.insert(0, 5);
371 assert(list.items[0] == 5);
372 assert(list.items[1] == 1);
373 assert(list.items[2] == 2);
374 assert(list.items[3] == 3);
371 testing.expect(list.items[0] == 5);
372 testing.expect(list.items[1] == 1);
373 testing.expect(list.items[2] == 2);
374 testing.expect(list.items[3] == 3);
375375}
376376
377377test "std.ArrayList.insertSlice" {
......@@ -386,17 +386,17 @@ test "std.ArrayList.insertSlice" {
386386 9,
387387 8,
388388 });
389 assert(list.items[0] == 1);
390 assert(list.items[1] == 9);
391 assert(list.items[2] == 8);
392 assert(list.items[3] == 2);
393 assert(list.items[4] == 3);
394 assert(list.items[5] == 4);
389 testing.expect(list.items[0] == 1);
390 testing.expect(list.items[1] == 9);
391 testing.expect(list.items[2] == 8);
392 testing.expect(list.items[3] == 2);
393 testing.expect(list.items[4] == 3);
394 testing.expect(list.items[5] == 4);
395395
396396 const items = []const i32{1};
397397 try list.insertSlice(0, items[0..0]);
398 assert(list.len == 6);
399 assert(list.items[0] == 1);
398 testing.expect(list.len == 6);
399 testing.expect(list.items[0] == 1);
400400}
401401
402402const Item = struct {
......@@ -407,5 +407,5 @@ const Item = struct {
407407test "std.ArrayList: ArrayList(T) of struct T" {
408408 var root = Item{ .integer = 1, .sub_items = ArrayList(Item).init(debug.global_allocator) };
409409 try root.sub_items.append( Item{ .integer = 42, .sub_items = ArrayList(Item).init(debug.global_allocator) } );
410 assert(root.sub_items.items[0].integer == 42);
410 testing.expect(root.sub_items.items[0].integer == 42);
411411}
std/atomic/queue.zig+12-11
......@@ -3,6 +3,7 @@ const builtin = @import("builtin");
33const AtomicOrder = builtin.AtomicOrder;
44const AtomicRmwOp = builtin.AtomicRmwOp;
55const assert = std.debug.assert;
6const expect = std.testing.expect;
67
78/// Many producer, many consumer, non-allocating, thread-safe.
89/// Uses a mutex to protect access.
......@@ -174,14 +175,14 @@ test "std.atomic.Queue" {
174175 {
175176 var i: usize = 0;
176177 while (i < put_thread_count) : (i += 1) {
177 std.debug.assertOrPanic(startPuts(&context) == 0);
178 expect(startPuts(&context) == 0);
178179 }
179180 }
180181 context.puts_done = 1;
181182 {
182183 var i: usize = 0;
183184 while (i < put_thread_count) : (i += 1) {
184 std.debug.assertOrPanic(startGets(&context) == 0);
185 expect(startGets(&context) == 0);
185186 }
186187 }
187188 } else {
......@@ -264,7 +265,7 @@ test "std.atomic.Queue single-threaded" {
264265 };
265266 queue.put(&node_1);
266267
267 assert(queue.get().?.data == 0);
268 expect(queue.get().?.data == 0);
268269
269270 var node_2 = Queue(i32).Node{
270271 .data = 2,
......@@ -280,9 +281,9 @@ test "std.atomic.Queue single-threaded" {
280281 };
281282 queue.put(&node_3);
282283
283 assert(queue.get().?.data == 1);
284 expect(queue.get().?.data == 1);
284285
285 assert(queue.get().?.data == 2);
286 expect(queue.get().?.data == 2);
286287
287288 var node_4 = Queue(i32).Node{
288289 .data = 4,
......@@ -291,12 +292,12 @@ test "std.atomic.Queue single-threaded" {
291292 };
292293 queue.put(&node_4);
293294
294 assert(queue.get().?.data == 3);
295 expect(queue.get().?.data == 3);
295296 node_3.next = null;
296297
297 assert(queue.get().?.data == 4);
298 expect(queue.get().?.data == 4);
298299
299 assert(queue.get() == null);
300 expect(queue.get() == null);
300301}
301302
302303test "std.atomic.Queue dump" {
......@@ -311,7 +312,7 @@ test "std.atomic.Queue dump" {
311312 // Test empty stream
312313 sos.reset();
313314 try queue.dumpToStream(SliceOutStream.Error, &sos.stream);
314 assert(mem.eql(u8, buffer[0..sos.pos],
315 expect(mem.eql(u8, buffer[0..sos.pos],
315316 \\head: (null)
316317 \\tail: (null)
317318 \\
......@@ -335,7 +336,7 @@ test "std.atomic.Queue dump" {
335336 \\ (null)
336337 \\
337338 , @ptrToInt(queue.head), @ptrToInt(queue.tail));
338 assert(mem.eql(u8, buffer[0..sos.pos], expected));
339 expect(mem.eql(u8, buffer[0..sos.pos], expected));
339340
340341 // Test a stream with two elements
341342 var node_1 = Queue(i32).Node{
......@@ -356,5 +357,5 @@ test "std.atomic.Queue dump" {
356357 \\ (null)
357358 \\
358359 , @ptrToInt(queue.head), @ptrToInt(queue.head.?.next), @ptrToInt(queue.tail));
359 assert(mem.eql(u8, buffer[0..sos.pos], expected));
360 expect(mem.eql(u8, buffer[0..sos.pos], expected));
360361}
std/atomic/stack.zig+3-2
......@@ -1,6 +1,7 @@
11const assert = std.debug.assert;
22const builtin = @import("builtin");
33const AtomicOrder = builtin.AtomicOrder;
4const expect = std.testing.expect;
45
56/// Many reader, many writer, non-allocating, thread-safe
67/// Uses a spinlock to protect push() and pop()
......@@ -108,14 +109,14 @@ test "std.atomic.stack" {
108109 {
109110 var i: usize = 0;
110111 while (i < put_thread_count) : (i += 1) {
111 std.debug.assertOrPanic(startPuts(&context) == 0);
112 expect(startPuts(&context) == 0);
112113 }
113114 }
114115 context.puts_done = 1;
115116 {
116117 var i: usize = 0;
117118 while (i < put_thread_count) : (i += 1) {
118 std.debug.assertOrPanic(startGets(&context) == 0);
119 expect(startGets(&context) == 0);
119120 }
120121 }
121122 } else {
std/base64.zig+7-6
......@@ -1,5 +1,6 @@
11const std = @import("index.zig");
22const assert = std.debug.assert;
3const testing = std.testing;
34const mem = std.mem;
45
56pub const standard_alphabet_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
......@@ -394,7 +395,7 @@ fn testAllApis(expected_decoded: []const u8, expected_encoded: []const u8) !void
394395 var buffer: [0x100]u8 = undefined;
395396 var encoded = buffer[0..Base64Encoder.calcSize(expected_decoded.len)];
396397 standard_encoder.encode(encoded, expected_decoded);
397 assert(mem.eql(u8, encoded, expected_encoded));
398 testing.expectEqualSlices(u8, expected_encoded, encoded);
398399 }
399400
400401 // Base64Decoder
......@@ -402,7 +403,7 @@ fn testAllApis(expected_decoded: []const u8, expected_encoded: []const u8) !void
402403 var buffer: [0x100]u8 = undefined;
403404 var decoded = buffer[0..try standard_decoder.calcSize(expected_encoded)];
404405 try standard_decoder.decode(decoded, expected_encoded);
405 assert(mem.eql(u8, decoded, expected_decoded));
406 testing.expectEqualSlices(u8, expected_decoded, decoded);
406407 }
407408
408409 // Base64DecoderWithIgnore
......@@ -411,8 +412,8 @@ fn testAllApis(expected_decoded: []const u8, expected_encoded: []const u8) !void
411412 var buffer: [0x100]u8 = undefined;
412413 var decoded = buffer[0..Base64DecoderWithIgnore.calcSizeUpperBound(expected_encoded.len)];
413414 var written = try standard_decoder_ignore_nothing.decode(decoded, expected_encoded);
414 assert(written <= decoded.len);
415 assert(mem.eql(u8, decoded[0..written], expected_decoded));
415 testing.expect(written <= decoded.len);
416 testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]);
416417 }
417418
418419 // Base64DecoderUnsafe
......@@ -420,7 +421,7 @@ fn testAllApis(expected_decoded: []const u8, expected_encoded: []const u8) !void
420421 var buffer: [0x100]u8 = undefined;
421422 var decoded = buffer[0..standard_decoder_unsafe.calcSize(expected_encoded)];
422423 standard_decoder_unsafe.decode(decoded, expected_encoded);
423 assert(mem.eql(u8, decoded, expected_decoded));
424 testing.expectEqualSlices(u8, expected_decoded, decoded);
424425 }
425426}
426427
......@@ -429,7 +430,7 @@ fn testDecodeIgnoreSpace(expected_decoded: []const u8, encoded: []const u8) !voi
429430 var buffer: [0x100]u8 = undefined;
430431 var decoded = buffer[0..Base64DecoderWithIgnore.calcSizeUpperBound(encoded.len)];
431432 var written = try standard_decoder_ignore_space.decode(decoded, encoded);
432 assert(mem.eql(u8, decoded[0..written], expected_decoded));
433 testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]);
433434}
434435
435436fn testError(encoded: []const u8, expected_err: anyerror) !void {
std/buf_map.zig+8-8
......@@ -2,7 +2,7 @@ const std = @import("index.zig");
22const HashMap = std.HashMap;
33const mem = std.mem;
44const Allocator = mem.Allocator;
5const assert = std.debug.assert;
5const testing = std.testing;
66
77/// BufMap copies keys and values before they go into the map, and
88/// frees them when they get removed.
......@@ -90,17 +90,17 @@ test "BufMap" {
9090 defer bufmap.deinit();
9191
9292 try bufmap.set("x", "1");
93 assert(mem.eql(u8, bufmap.get("x").?, "1"));
94 assert(1 == bufmap.count());
93 testing.expect(mem.eql(u8, bufmap.get("x").?, "1"));
94 testing.expect(1 == bufmap.count());
9595
9696 try bufmap.set("x", "2");
97 assert(mem.eql(u8, bufmap.get("x").?, "2"));
98 assert(1 == bufmap.count());
97 testing.expect(mem.eql(u8, bufmap.get("x").?, "2"));
98 testing.expect(1 == bufmap.count());
9999
100100 try bufmap.set("x", "3");
101 assert(mem.eql(u8, bufmap.get("x").?, "3"));
102 assert(1 == bufmap.count());
101 testing.expect(mem.eql(u8, bufmap.get("x").?, "3"));
102 testing.expect(1 == bufmap.count());
103103
104104 bufmap.delete("x");
105 assert(0 == bufmap.count());
105 testing.expect(0 == bufmap.count());
106106}
std/buf_set.zig+3-3
......@@ -2,7 +2,7 @@ const std = @import("index.zig");
22const HashMap = @import("hash_map.zig").HashMap;
33const mem = @import("mem.zig");
44const Allocator = mem.Allocator;
5const assert = std.debug.assert;
5const testing = std.testing;
66
77pub const BufSet = struct {
88 hash_map: BufSetHashMap,
......@@ -68,9 +68,9 @@ test "BufSet" {
6868 defer bufset.deinit();
6969
7070 try bufset.put("x");
71 assert(bufset.count() == 1);
71 testing.expect(bufset.count() == 1);
7272 bufset.delete("x");
73 assert(bufset.count() == 0);
73 testing.expect(bufset.count() == 0);
7474
7575 try bufset.put("x");
7676 try bufset.put("y");
std/buffer.zig+8-7
......@@ -3,6 +3,7 @@ const debug = std.debug;
33const mem = std.mem;
44const Allocator = mem.Allocator;
55const assert = debug.assert;
6const testing = std.testing;
67const ArrayList = std.ArrayList;
78
89/// A buffer that allocates memory and maintains a null byte at the end.
......@@ -141,19 +142,19 @@ test "simple Buffer" {
141142 const cstr = @import("cstr.zig");
142143
143144 var buf = try Buffer.init(debug.global_allocator, "");
144 assert(buf.len() == 0);
145 testing.expect(buf.len() == 0);
145146 try buf.append("hello");
146147 try buf.append(" ");
147148 try buf.append("world");
148 assert(buf.eql("hello world"));
149 assert(mem.eql(u8, cstr.toSliceConst(buf.toSliceConst().ptr), buf.toSliceConst()));
149 testing.expect(buf.eql("hello world"));
150 testing.expect(mem.eql(u8, cstr.toSliceConst(buf.toSliceConst().ptr), buf.toSliceConst()));
150151
151152 var buf2 = try Buffer.initFromBuffer(buf);
152 assert(buf.eql(buf2.toSliceConst()));
153 testing.expect(buf.eql(buf2.toSliceConst()));
153154
154 assert(buf.startsWith("hell"));
155 assert(buf.endsWith("orld"));
155 testing.expect(buf.startsWith("hell"));
156 testing.expect(buf.endsWith("orld"));
156157
157158 try buf2.resize(4);
158 assert(buf.startsWith(buf2.toSlice()));
159 testing.expect(buf.startsWith(buf2.toSlice()));
159160}
std/crypto/chacha20.zig+8-7
......@@ -4,6 +4,7 @@ const std = @import("../index.zig");
44const mem = std.mem;
55const endian = std.endian;
66const assert = std.debug.assert;
7const testing = std.testing;
78const builtin = @import("builtin");
89const maxInt = std.math.maxInt;
910
......@@ -216,12 +217,12 @@ test "crypto.chacha20 test vector sunscreen" {
216217 };
217218
218219 chaCha20IETF(result[0..], input[0..], 1, key, nonce);
219 assert(mem.eql(u8, expected_result, result));
220 testing.expectEqualSlices(u8, expected_result, result);
220221
221222 // Chacha20 is self-reversing.
222223 var plaintext: [114]u8 = undefined;
223224 chaCha20IETF(plaintext[0..], result[0..], 1, key, nonce);
224 assert(mem.compare(u8, input, plaintext) == mem.Compare.Equal);
225 testing.expect(mem.compare(u8, input, plaintext) == mem.Compare.Equal);
225226}
226227
227228// https://tools.ietf.org/html/draft-agl-tls-chacha20poly1305-04#section-7
......@@ -256,7 +257,7 @@ test "crypto.chacha20 test vector 1" {
256257 const nonce = []u8{ 0, 0, 0, 0, 0, 0, 0, 0 };
257258
258259 chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);
259 assert(mem.eql(u8, expected_result, result));
260 testing.expectEqualSlices(u8, expected_result, result);
260261}
261262
262263test "crypto.chacha20 test vector 2" {
......@@ -290,7 +291,7 @@ test "crypto.chacha20 test vector 2" {
290291 const nonce = []u8{ 0, 0, 0, 0, 0, 0, 0, 0 };
291292
292293 chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);
293 assert(mem.eql(u8, expected_result, result));
294 testing.expectEqualSlices(u8, expected_result, result);
294295}
295296
296297test "crypto.chacha20 test vector 3" {
......@@ -324,7 +325,7 @@ test "crypto.chacha20 test vector 3" {
324325 const nonce = []u8{ 0, 0, 0, 0, 0, 0, 0, 1 };
325326
326327 chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);
327 assert(mem.eql(u8, expected_result, result));
328 testing.expectEqualSlices(u8, expected_result, result);
328329}
329330
330331test "crypto.chacha20 test vector 4" {
......@@ -358,7 +359,7 @@ test "crypto.chacha20 test vector 4" {
358359 const nonce = []u8{ 1, 0, 0, 0, 0, 0, 0, 0 };
359360
360361 chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);
361 assert(mem.eql(u8, expected_result, result));
362 testing.expectEqualSlices(u8, expected_result, result);
362363}
363364
364365test "crypto.chacha20 test vector 5" {
......@@ -430,5 +431,5 @@ test "crypto.chacha20 test vector 5" {
430431 };
431432
432433 chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);
433 assert(mem.eql(u8, expected_result, result));
434 testing.expectEqualSlices(u8, expected_result, result);
434435}
std/crypto/poly1305.zig+1-1
......@@ -230,5 +230,5 @@ test "poly1305 rfc7439 vector1" {
230230 var mac: [16]u8 = undefined;
231231 Poly1305.create(mac[0..], msg, key);
232232
233 std.debug.assert(std.mem.eql(u8, mac, expected_mac));
233 std.testing.expectEqualSlices(u8, expected_mac, mac);
234234}
std/crypto/test.zig+5-4
......@@ -1,6 +1,7 @@
1const debug = @import("../debug/index.zig");
2const mem = @import("../mem.zig");
3const fmt = @import("../fmt/index.zig");
1const std = @import("../index.zig");
2const testing = std.testing;
3const mem = std.mem;
4const fmt = std.fmt;
45
56// Hash using the specified hasher `H` asserting `expected == H(input)`.
67pub fn assertEqualHash(comptime Hasher: var, comptime expected: []const u8, input: []const u8) void {
......@@ -17,5 +18,5 @@ pub fn assertEqual(comptime expected: []const u8, input: []const u8) void {
1718 r.* = fmt.parseInt(u8, expected[2 * i .. 2 * i + 2], 16) catch unreachable;
1819 }
1920
20 debug.assert(mem.eql(u8, expected_bytes, input));
21 testing.expectEqualSlices(u8, expected_bytes, input);
2122}
std/crypto/x25519.zig+12-12
......@@ -581,8 +581,8 @@ test "x25519 public key calculation from secret key" {
581581 var pk_calculated: [32]u8 = undefined;
582582 try fmt.hexToBytes(sk[0..], "8052030376d47112be7f73ed7a019293dd12ad910b654455798b4667d73de166");
583583 try fmt.hexToBytes(pk_expected[0..], "f1814f0e8ff1043d8a44d25babff3cedcae6c22c3edaa48f857ae70de2baae50");
584 std.debug.assert(X25519.createPublicKey(pk_calculated[0..], sk));
585 std.debug.assert(std.mem.eql(u8, pk_calculated, pk_expected));
584 std.testing.expect(X25519.createPublicKey(pk_calculated[0..], sk));
585 std.testing.expect(std.mem.eql(u8, pk_calculated, pk_expected));
586586}
587587
588588test "x25519 rfc7748 vector1" {
......@@ -593,8 +593,8 @@ test "x25519 rfc7748 vector1" {
593593
594594 var output: [32]u8 = undefined;
595595
596 std.debug.assert(X25519.create(output[0..], secret_key, public_key));
597 std.debug.assert(std.mem.eql(u8, output, expected_output));
596 std.testing.expect(X25519.create(output[0..], secret_key, public_key));
597 std.testing.expect(std.mem.eql(u8, output, expected_output));
598598}
599599
600600test "x25519 rfc7748 vector2" {
......@@ -605,8 +605,8 @@ test "x25519 rfc7748 vector2" {
605605
606606 var output: [32]u8 = undefined;
607607
608 std.debug.assert(X25519.create(output[0..], secret_key, public_key));
609 std.debug.assert(std.mem.eql(u8, output, expected_output));
608 std.testing.expect(X25519.create(output[0..], secret_key, public_key));
609 std.testing.expect(std.mem.eql(u8, output, expected_output));
610610}
611611
612612test "x25519 rfc7748 one iteration" {
......@@ -619,13 +619,13 @@ test "x25519 rfc7748 one iteration" {
619619 var i: usize = 0;
620620 while (i < 1) : (i += 1) {
621621 var output: [32]u8 = undefined;
622 std.debug.assert(X25519.create(output[0..], k, u));
622 std.testing.expect(X25519.create(output[0..], k, u));
623623
624624 std.mem.copy(u8, u[0..], k[0..]);
625625 std.mem.copy(u8, k[0..], output[0..]);
626626 }
627627
628 std.debug.assert(std.mem.eql(u8, k[0..], expected_output));
628 std.testing.expect(std.mem.eql(u8, k[0..], expected_output));
629629}
630630
631631test "x25519 rfc7748 1,000 iterations" {
......@@ -643,13 +643,13 @@ test "x25519 rfc7748 1,000 iterations" {
643643 var i: usize = 0;
644644 while (i < 1000) : (i += 1) {
645645 var output: [32]u8 = undefined;
646 std.debug.assert(X25519.create(output[0..], k, u));
646 std.testing.expect(X25519.create(output[0..], k, u));
647647
648648 std.mem.copy(u8, u[0..], k[0..]);
649649 std.mem.copy(u8, k[0..], output[0..]);
650650 }
651651
652 std.debug.assert(std.mem.eql(u8, k[0..], expected_output));
652 std.testing.expect(std.mem.eql(u8, k[0..], expected_output));
653653}
654654
655655test "x25519 rfc7748 1,000,000 iterations" {
......@@ -666,11 +666,11 @@ test "x25519 rfc7748 1,000,000 iterations" {
666666 var i: usize = 0;
667667 while (i < 1000000) : (i += 1) {
668668 var output: [32]u8 = undefined;
669 std.debug.assert(X25519.create(output[0..], k, u));
669 std.testing.expect(X25519.create(output[0..], k, u));
670670
671671 std.mem.copy(u8, u[0..], k[0..]);
672672 std.mem.copy(u8, k[0..], output[0..]);
673673 }
674674
675 std.debug.assert(std.mem.eql(u8, k[0..], expected_output));
675 std.testing.expect(std.mem.eql(u8, k[0..], expected_output));
676676}
std/cstr.zig+3-3
......@@ -2,7 +2,7 @@ const std = @import("index.zig");
22const builtin = @import("builtin");
33const debug = std.debug;
44const mem = std.mem;
5const assert = debug.assert;
5const testing = std.testing;
66
77pub const line_sep = switch (builtin.os) {
88 builtin.Os.windows => "\r\n",
......@@ -42,8 +42,8 @@ test "cstr fns" {
4242}
4343
4444fn testCStrFnsImpl() void {
45 assert(cmp(c"aoeu", c"aoez") == -1);
46 assert(len(c"123456789") == 9);
45 testing.expect(cmp(c"aoeu", c"aoez") == -1);
46 testing.expect(len(c"123456789") == 9);
4747}
4848
4949/// Returns a mutable slice with 1 more byte of length which is a null byte.
std/debug/index.zig+8-30
......@@ -107,37 +107,15 @@ pub fn dumpStackTrace(stack_trace: *const builtin.StackTrace) void {
107107/// This function invokes undefined behavior when `ok` is `false`.
108108/// In Debug and ReleaseSafe modes, calls to this function are always
109109/// generated, and the `unreachable` statement triggers a panic.
110/// In ReleaseFast and ReleaseSmall modes, calls to this function can be
111/// optimized away.
110/// In ReleaseFast and ReleaseSmall modes, calls to this function are
111/// optimized away, and in fact the optimizer is able to use the assertion
112/// in its heuristics.
113/// Inside a test block, it is best to use the `std.testing` module rather
114/// than this function, because this function may not detect a test failure
115/// in ReleaseFast and ReleaseSafe mode. Outside of a test block, this assert
116/// function is the correct function to use.
112117pub fn assert(ok: bool) void {
113 if (!ok) {
114 // In ReleaseFast test mode, we still want assert(false) to crash, so
115 // we insert an explicit call to @panic instead of unreachable.
116 // TODO we should use `assertOrPanic` in tests and remove this logic.
117 if (builtin.is_test) {
118 @panic("assertion failure");
119 } else {
120 unreachable; // assertion failure
121 }
122 }
123}
124
125/// TODO: add `==` operator for `error_union == error_set`, and then
126/// remove this function
127pub fn assertError(value: var, expected_error: anyerror) void {
128 if (value) {
129 @panic("expected error");
130 } else |actual_error| {
131 assert(actual_error == expected_error);
132 }
133}
134
135/// Call this function when you want to panic if the condition is not true.
136/// If `ok` is `false`, this function will panic in every release mode.
137pub fn assertOrPanic(ok: bool) void {
138 if (!ok) {
139 @panic("assertion failure");
140 }
118 if (!ok) unreachable; // assertion failure
141119}
142120
143121pub fn panic(comptime format: []const u8, args: ...) noreturn {
std/dynamic_library.zig+2-1
......@@ -6,6 +6,7 @@ const mem = std.mem;
66const cstr = std.cstr;
77const os = std.os;
88const assert = std.debug.assert;
9const testing = std.testing;
910const elf = std.elf;
1011const linux = os.linux;
1112const windows = os.windows;
......@@ -206,7 +207,7 @@ test "dynamic_library" {
206207 };
207208
208209 const dynlib = DynLib.open(std.debug.global_allocator, libname) catch |err| {
209 assert(err == error.FileNotFound);
210 testing.expect(err == error.FileNotFound);
210211 return;
211212 };
212213 @panic("Expected error from function");
std/event/channel.zig+5-4
......@@ -1,6 +1,7 @@
11const std = @import("../index.zig");
22const builtin = @import("builtin");
33const assert = std.debug.assert;
4const testing = std.testing;
45const AtomicRmwOp = builtin.AtomicRmwOp;
56const AtomicOrder = builtin.AtomicOrder;
67const Loop = std.event.Loop;
......@@ -350,19 +351,19 @@ async fn testChannelGetter(loop: *Loop, channel: *Channel(i32)) void {
350351
351352 const value1_promise = try async channel.get();
352353 const value1 = await value1_promise;
353 assert(value1 == 1234);
354 testing.expect(value1 == 1234);
354355
355356 const value2_promise = try async channel.get();
356357 const value2 = await value2_promise;
357 assert(value2 == 4567);
358 testing.expect(value2 == 4567);
358359
359360 const value3_promise = try async channel.getOrNull();
360361 const value3 = await value3_promise;
361 assert(value3 == null);
362 testing.expect(value3 == null);
362363
363364 const last_put = try async testPut(channel, 4444);
364365 const value4 = await try async channel.getOrNull();
365 assert(value4.? == 4444);
366 testing.expect(value4.? == 4444);
366367 await last_put;
367368}
368369
std/event/fs.zig+5-4
......@@ -2,6 +2,7 @@ const builtin = @import("builtin");
22const std = @import("../index.zig");
33const event = std.event;
44const assert = std.debug.assert;
5const testing = std.testing;
56const os = std.os;
67const mem = std.mem;
78const posix = os.posix;
......@@ -1349,13 +1350,13 @@ async fn testFsWatch(loop: *Loop) !void {
13491350 try await try async writeFile(loop, file_path, contents);
13501351
13511352 const read_contents = try await try async readFile(loop, file_path, 1024 * 1024);
1352 assert(mem.eql(u8, read_contents, contents));
1353 testing.expectEqualSlices(u8, contents, read_contents);
13531354
13541355 // now watch the file
13551356 var watch = try Watch(void).create(loop, 0);
13561357 defer watch.destroy();
13571358
1358 assert((try await try async watch.addFile(file_path, {})) == null);
1359 testing.expect((try await try async watch.addFile(file_path, {})) == null);
13591360
13601361 const ev = try async watch.channel.get();
13611362 var ev_consumed = false;
......@@ -1375,10 +1376,10 @@ async fn testFsWatch(loop: *Loop) !void {
13751376 WatchEventId.Delete => @panic("wrong event"),
13761377 }
13771378 const contents_updated = try await try async readFile(loop, file_path, 1024 * 1024);
1378 assert(mem.eql(u8, contents_updated,
1379 testing.expectEqualSlices(u8,
13791380 \\line 1
13801381 \\lorem ipsum
1381 ));
1382 , contents_updated);
13821383
13831384 // TODO test deleting the file and then re-adding it. we should get events for both
13841385}
std/event/future.zig+2-1
......@@ -1,5 +1,6 @@
11const std = @import("../index.zig");
22const assert = std.debug.assert;
3const testing = std.testing;
34const builtin = @import("builtin");
45const AtomicRmwOp = builtin.AtomicRmwOp;
56const AtomicOrder = builtin.AtomicOrder;
......@@ -114,7 +115,7 @@ async fn testFuture(loop: *Loop) void {
114115
115116 const result = (await a) + (await b);
116117 cancel c;
117 assert(result == 12);
118 testing.expect(result == 12);
118119}
119120
120121async fn waitOnFuture(future: *Future(i32)) i32 {
std/event/group.zig+3-3
......@@ -4,7 +4,7 @@ const Lock = std.event.Lock;
44const Loop = std.event.Loop;
55const AtomicRmwOp = builtin.AtomicRmwOp;
66const AtomicOrder = builtin.AtomicOrder;
7const assert = std.debug.assert;
7const testing = std.testing;
88
99/// ReturnType must be `void` or `E!void`
1010pub fn Group(comptime ReturnType: type) type {
......@@ -146,12 +146,12 @@ async fn testGroup(loop: *Loop) void {
146146 group.add(async sleepALittle(&count) catch @panic("memory")) catch @panic("memory");
147147 group.call(increaseByTen, &count) catch @panic("memory");
148148 await (async group.wait() catch @panic("memory"));
149 assert(count == 11);
149 testing.expect(count == 11);
150150
151151 var another = Group(anyerror!void).init(loop);
152152 another.add(async somethingElse() catch @panic("memory")) catch @panic("memory");
153153 another.call(doSomethingThatFails) catch @panic("memory");
154 std.debug.assertError(await (async another.wait() catch @panic("memory")), error.ItBroke);
154 testing.expectError(error.ItBroke, await (async another.wait() catch @panic("memory")));
155155}
156156
157157async fn sleepALittle(count: *usize) void {
std/event/lock.zig+2-1
......@@ -1,6 +1,7 @@
11const std = @import("../index.zig");
22const builtin = @import("builtin");
33const assert = std.debug.assert;
4const testing = std.testing;
45const mem = std.mem;
56const AtomicRmwOp = builtin.AtomicRmwOp;
67const AtomicOrder = builtin.AtomicOrder;
......@@ -141,7 +142,7 @@ test "std.event.Lock" {
141142 defer cancel handle;
142143 loop.run();
143144
144 assert(mem.eql(i32, shared_test_data, [1]i32{3 * @intCast(i32, shared_test_data.len)} ** shared_test_data.len));
145 testing.expectEqualSlices(i32, [1]i32{3 * @intCast(i32, shared_test_data.len)} ** shared_test_data.len, shared_test_data);
145146}
146147
147148async fn testLock(loop: *Loop, lock: *Lock) void {
std/event/loop.zig+3-2
......@@ -1,6 +1,7 @@
11const std = @import("../index.zig");
22const builtin = @import("builtin");
33const assert = std.debug.assert;
4const testing = std.testing;
45const mem = std.mem;
56const AtomicRmwOp = builtin.AtomicRmwOp;
67const AtomicOrder = builtin.AtomicOrder;
......@@ -896,7 +897,7 @@ test "std.event.Loop - call" {
896897
897898 loop.run();
898899
899 assert(did_it);
900 testing.expect(did_it);
900901}
901902
902903async fn testEventLoop() i32 {
......@@ -905,6 +906,6 @@ async fn testEventLoop() i32 {
905906
906907async fn testEventLoop2(h: promise->i32, did_it: *bool) void {
907908 const value = await h;
908 assert(value == 1234);
909 testing.expect(value == 1234);
909910 did_it.* = true;
910911}
std/event/net.zig+2-2
......@@ -1,6 +1,6 @@
11const std = @import("../index.zig");
22const builtin = @import("builtin");
3const assert = std.debug.assert;
3const testing = std.testing;
44const event = std.event;
55const mem = std.mem;
66const os = std.os;
......@@ -326,7 +326,7 @@ async fn doAsyncTest(loop: *Loop, address: *const std.net.Address, server: *Serv
326326 var buf: [512]u8 = undefined;
327327 const amt_read = try socket_file.read(buf[0..]);
328328 const msg = buf[0..amt_read];
329 assert(mem.eql(u8, msg, "hello from server\n"));
329 testing.expect(mem.eql(u8, msg, "hello from server\n"));
330330 server.close();
331331}
332332
std/event/rwlock.zig+4-3
......@@ -1,6 +1,7 @@
11const std = @import("../index.zig");
22const builtin = @import("builtin");
33const assert = std.debug.assert;
4const testing = std.testing;
45const mem = std.mem;
56const AtomicRmwOp = builtin.AtomicRmwOp;
67const AtomicOrder = builtin.AtomicOrder;
......@@ -231,7 +232,7 @@ test "std.event.RwLock" {
231232 loop.run();
232233
233234 const expected_result = [1]i32{shared_it_count * @intCast(i32, shared_test_data.len)} ** shared_test_data.len;
234 assert(mem.eql(i32, shared_test_data, expected_result));
235 testing.expectEqualSlices(i32, expected_result, shared_test_data);
235236}
236237
237238async fn testLock(loop: *Loop, lock: *RwLock) void {
......@@ -293,7 +294,7 @@ async fn readRunner(lock: *RwLock) void {
293294 const handle = await lock_promise;
294295 defer handle.release();
295296
296 assert(shared_test_index == 0);
297 assert(shared_test_data[i] == @intCast(i32, shared_count));
297 testing.expect(shared_test_index == 0);
298 testing.expect(shared_test_data[i] == @intCast(i32, shared_count));
298299 }
299300}
std/fmt/index.zig+79-79
......@@ -2,7 +2,7 @@ const std = @import("../index.zig");
22const math = std.math;
33const debug = std.debug;
44const assert = debug.assert;
5const assertError = debug.assertError;
5const testing = std.testing;
66const mem = std.mem;
77const builtin = @import("builtin");
88const errol = @import("errol/index.zig");
......@@ -588,7 +588,7 @@ pub fn formatFloatDecimal(
588588 }
589589
590590 // Remaining fractional portion, zero-padding if insufficient.
591 debug.assert(precision >= printed);
591 assert(precision >= printed);
592592 if (num_digits_whole_no_pad + precision - printed < float_decimal.digits.len) {
593593 try output(context, float_decimal.digits[num_digits_whole_no_pad .. num_digits_whole_no_pad + precision - printed]);
594594 return;
......@@ -798,13 +798,13 @@ pub fn parseInt(comptime T: type, buf: []const u8, radix: u8) !T {
798798}
799799
800800test "fmt.parseInt" {
801 assert((parseInt(i32, "-10", 10) catch unreachable) == -10);
802 assert((parseInt(i32, "+10", 10) catch unreachable) == 10);
803 assert(if (parseInt(i32, " 10", 10)) |_| false else |err| err == error.InvalidCharacter);
804 assert(if (parseInt(i32, "10 ", 10)) |_| false else |err| err == error.InvalidCharacter);
805 assert(if (parseInt(u32, "-10", 10)) |_| false else |err| err == error.InvalidCharacter);
806 assert((parseInt(u8, "255", 10) catch unreachable) == 255);
807 assert(if (parseInt(u8, "256", 10)) |_| false else |err| err == error.Overflow);
801 testing.expect((parseInt(i32, "-10", 10) catch unreachable) == -10);
802 testing.expect((parseInt(i32, "+10", 10) catch unreachable) == 10);
803 testing.expect(if (parseInt(i32, " 10", 10)) |_| false else |err| err == error.InvalidCharacter);
804 testing.expect(if (parseInt(i32, "10 ", 10)) |_| false else |err| err == error.InvalidCharacter);
805 testing.expect(if (parseInt(u32, "-10", 10)) |_| false else |err| err == error.InvalidCharacter);
806 testing.expect((parseInt(u8, "255", 10) catch unreachable) == 255);
807 testing.expect(if (parseInt(u8, "256", 10)) |_| false else |err| err == error.Overflow);
808808}
809809
810810const ParseUnsignedError = error{
......@@ -829,30 +829,30 @@ pub fn parseUnsigned(comptime T: type, buf: []const u8, radix: u8) ParseUnsigned
829829}
830830
831831test "parseUnsigned" {
832 assert((try parseUnsigned(u16, "050124", 10)) == 50124);
833 assert((try parseUnsigned(u16, "65535", 10)) == 65535);
834 assertError(parseUnsigned(u16, "65536", 10), error.Overflow);
832 testing.expect((try parseUnsigned(u16, "050124", 10)) == 50124);
833 testing.expect((try parseUnsigned(u16, "65535", 10)) == 65535);
834 testing.expectError(error.Overflow, parseUnsigned(u16, "65536", 10));
835835
836 assert((try parseUnsigned(u64, "0ffffffffffffffff", 16)) == 0xffffffffffffffff);
837 assertError(parseUnsigned(u64, "10000000000000000", 16), error.Overflow);
836 testing.expect((try parseUnsigned(u64, "0ffffffffffffffff", 16)) == 0xffffffffffffffff);
837 testing.expectError(error.Overflow, parseUnsigned(u64, "10000000000000000", 16));
838838
839 assert((try parseUnsigned(u32, "DeadBeef", 16)) == 0xDEADBEEF);
839 testing.expect((try parseUnsigned(u32, "DeadBeef", 16)) == 0xDEADBEEF);
840840
841 assert((try parseUnsigned(u7, "1", 10)) == 1);
842 assert((try parseUnsigned(u7, "1000", 2)) == 8);
841 testing.expect((try parseUnsigned(u7, "1", 10)) == 1);
842 testing.expect((try parseUnsigned(u7, "1000", 2)) == 8);
843843
844 assertError(parseUnsigned(u32, "f", 10), error.InvalidCharacter);
845 assertError(parseUnsigned(u8, "109", 8), error.InvalidCharacter);
844 testing.expectError(error.InvalidCharacter, parseUnsigned(u32, "f", 10));
845 testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "109", 8));
846846
847 assert((try parseUnsigned(u32, "NUMBER", 36)) == 1442151747);
847 testing.expect((try parseUnsigned(u32, "NUMBER", 36)) == 1442151747);
848848
849849 // these numbers should fit even though the radix itself doesn't fit in the destination type
850 assert((try parseUnsigned(u1, "0", 10)) == 0);
851 assert((try parseUnsigned(u1, "1", 10)) == 1);
852 assertError(parseUnsigned(u1, "2", 10), error.Overflow);
853 assert((try parseUnsigned(u1, "001", 16)) == 1);
854 assert((try parseUnsigned(u2, "3", 16)) == 3);
855 assertError(parseUnsigned(u2, "4", 16), error.Overflow);
850 testing.expect((try parseUnsigned(u1, "0", 10)) == 0);
851 testing.expect((try parseUnsigned(u1, "1", 10)) == 1);
852 testing.expectError(error.Overflow, parseUnsigned(u1, "2", 10));
853 testing.expect((try parseUnsigned(u1, "001", 16)) == 1);
854 testing.expect((try parseUnsigned(u2, "3", 16)) == 3);
855 testing.expectError(error.Overflow, parseUnsigned(u2, "4", 16));
856856}
857857
858858pub fn charToDigit(c: u8, radix: u8) (error{InvalidCharacter}!u8) {
......@@ -910,19 +910,19 @@ fn countSize(size: *usize, bytes: []const u8) (error{}!void) {
910910test "buf print int" {
911911 var buffer: [max_int_digits]u8 = undefined;
912912 const buf = buffer[0..];
913 assert(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 2, false, 0), "-101111000110000101001110"));
914 assert(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 10, false, 0), "-12345678"));
915 assert(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 16, false, 0), "-bc614e"));
916 assert(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 16, true, 0), "-BC614E"));
913 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 2, false, 0), "-101111000110000101001110"));
914 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 10, false, 0), "-12345678"));
915 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 16, false, 0), "-bc614e"));
916 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 16, true, 0), "-BC614E"));
917917
918 assert(mem.eql(u8, bufPrintIntToSlice(buf, u32(12345678), 10, true, 0), "12345678"));
918 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, u32(12345678), 10, true, 0), "12345678"));
919919
920 assert(mem.eql(u8, bufPrintIntToSlice(buf, u32(666), 10, false, 6), "000666"));
921 assert(mem.eql(u8, bufPrintIntToSlice(buf, u32(0x1234), 16, false, 6), "001234"));
922 assert(mem.eql(u8, bufPrintIntToSlice(buf, u32(0x1234), 16, false, 1), "1234"));
920 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, u32(666), 10, false, 6), "000666"));
921 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, u32(0x1234), 16, false, 6), "001234"));
922 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, u32(0x1234), 16, false, 1), "1234"));
923923
924 assert(mem.eql(u8, bufPrintIntToSlice(buf, i32(42), 10, false, 3), "+42"));
925 assert(mem.eql(u8, bufPrintIntToSlice(buf, i32(-42), 10, false, 3), "-42"));
924 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(42), 10, false, 3), "+42"));
925 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-42), 10, false, 3), "-42"));
926926}
927927
928928fn bufPrintIntToSlice(buf: []u8, value: var, base: u8, uppercase: bool, width: usize) []u8 {
......@@ -939,7 +939,7 @@ test "parse u64 digit too big" {
939939
940940test "parse unsigned comptime" {
941941 comptime {
942 assert((try parseUnsigned(usize, "2", 10)) == 2);
942 testing.expect((try parseUnsigned(usize, "2", 10)) == 2);
943943 }
944944}
945945
......@@ -977,17 +977,17 @@ test "fmt.format" {
977977 var context = BufPrintContext{ .remaining = buf1[0..] };
978978 try formatType(1234, "", &context, error{BufferTooSmall}, bufPrintWrite);
979979 var res = buf1[0 .. buf1.len - context.remaining.len];
980 assert(mem.eql(u8, res, "1234"));
980 testing.expect(mem.eql(u8, res, "1234"));
981981
982982 context = BufPrintContext{ .remaining = buf1[0..] };
983983 try formatType('a', "c", &context, error{BufferTooSmall}, bufPrintWrite);
984984 res = buf1[0 .. buf1.len - context.remaining.len];
985 assert(mem.eql(u8, res, "a"));
985 testing.expect(mem.eql(u8, res, "a"));
986986
987987 context = BufPrintContext{ .remaining = buf1[0..] };
988988 try formatType(0b1100, "b", &context, error{BufferTooSmall}, bufPrintWrite);
989989 res = buf1[0 .. buf1.len - context.remaining.len];
990 assert(mem.eql(u8, res, "1100"));
990 testing.expect(mem.eql(u8, res, "1100"));
991991 }
992992 {
993993 const value: [3]u8 = "abc";
......@@ -1053,19 +1053,19 @@ test "fmt.format" {
10531053 var buf1: [32]u8 = undefined;
10541054 const value: f32 = 1.34;
10551055 const result = try bufPrint(buf1[0..], "f32: {e}\n", value);
1056 assert(mem.eql(u8, result, "f32: 1.34000003e+00\n"));
1056 testing.expect(mem.eql(u8, result, "f32: 1.34000003e+00\n"));
10571057 }
10581058 {
10591059 var buf1: [32]u8 = undefined;
10601060 const value: f32 = 12.34;
10611061 const result = try bufPrint(buf1[0..], "f32: {e}\n", value);
1062 assert(mem.eql(u8, result, "f32: 1.23400001e+01\n"));
1062 testing.expect(mem.eql(u8, result, "f32: 1.23400001e+01\n"));
10631063 }
10641064 {
10651065 var buf1: [32]u8 = undefined;
10661066 const value: f64 = -12.34e10;
10671067 const result = try bufPrint(buf1[0..], "f64: {e}\n", value);
1068 assert(mem.eql(u8, result, "f64: -1.234e+11\n"));
1068 testing.expect(mem.eql(u8, result, "f64: -1.234e+11\n"));
10691069 }
10701070 {
10711071 // This fails on release due to a minor rounding difference.
......@@ -1075,26 +1075,26 @@ test "fmt.format" {
10751075 var buf1: [32]u8 = undefined;
10761076 const value: f64 = 9.999960e-40;
10771077 const result = try bufPrint(buf1[0..], "f64: {e}\n", value);
1078 assert(mem.eql(u8, result, "f64: 9.99996e-40\n"));
1078 testing.expect(mem.eql(u8, result, "f64: 9.99996e-40\n"));
10791079 }
10801080 }
10811081 {
10821082 var buf1: [32]u8 = undefined;
10831083 const value: f64 = 1.409706e-42;
10841084 const result = try bufPrint(buf1[0..], "f64: {e5}\n", value);
1085 assert(mem.eql(u8, result, "f64: 1.40971e-42\n"));
1085 testing.expect(mem.eql(u8, result, "f64: 1.40971e-42\n"));
10861086 }
10871087 {
10881088 var buf1: [32]u8 = undefined;
10891089 const value: f64 = @bitCast(f32, u32(814313563));
10901090 const result = try bufPrint(buf1[0..], "f64: {e5}\n", value);
1091 assert(mem.eql(u8, result, "f64: 1.00000e-09\n"));
1091 testing.expect(mem.eql(u8, result, "f64: 1.00000e-09\n"));
10921092 }
10931093 {
10941094 var buf1: [32]u8 = undefined;
10951095 const value: f64 = @bitCast(f32, u32(1006632960));
10961096 const result = try bufPrint(buf1[0..], "f64: {e5}\n", value);
1097 assert(mem.eql(u8, result, "f64: 7.81250e-03\n"));
1097 testing.expect(mem.eql(u8, result, "f64: 7.81250e-03\n"));
10981098 }
10991099 {
11001100 // libc rounds 1.000005e+05 to 1.00000e+05 but zig does 1.00001e+05.
......@@ -1102,47 +1102,47 @@ test "fmt.format" {
11021102 var buf1: [32]u8 = undefined;
11031103 const value: f64 = @bitCast(f32, u32(1203982400));
11041104 const result = try bufPrint(buf1[0..], "f64: {e5}\n", value);
1105 assert(mem.eql(u8, result, "f64: 1.00001e+05\n"));
1105 testing.expect(mem.eql(u8, result, "f64: 1.00001e+05\n"));
11061106 }
11071107 {
11081108 var buf1: [32]u8 = undefined;
11091109 const result = try bufPrint(buf1[0..], "f64: {}\n", math.nan_f64);
1110 assert(mem.eql(u8, result, "f64: nan\n"));
1110 testing.expect(mem.eql(u8, result, "f64: nan\n"));
11111111 }
11121112 if (builtin.arch != builtin.Arch.armv8) {
11131113 // negative nan is not defined by IEE 754,
11141114 // and ARM thus normalizes it to positive nan
11151115 var buf1: [32]u8 = undefined;
11161116 const result = try bufPrint(buf1[0..], "f64: {}\n", -math.nan_f64);
1117 assert(mem.eql(u8, result, "f64: -nan\n"));
1117 testing.expect(mem.eql(u8, result, "f64: -nan\n"));
11181118 }
11191119 {
11201120 var buf1: [32]u8 = undefined;
11211121 const result = try bufPrint(buf1[0..], "f64: {}\n", math.inf_f64);
1122 assert(mem.eql(u8, result, "f64: inf\n"));
1122 testing.expect(mem.eql(u8, result, "f64: inf\n"));
11231123 }
11241124 {
11251125 var buf1: [32]u8 = undefined;
11261126 const result = try bufPrint(buf1[0..], "f64: {}\n", -math.inf_f64);
1127 assert(mem.eql(u8, result, "f64: -inf\n"));
1127 testing.expect(mem.eql(u8, result, "f64: -inf\n"));
11281128 }
11291129 {
11301130 var buf1: [64]u8 = undefined;
11311131 const value: f64 = 1.52314e+29;
11321132 const result = try bufPrint(buf1[0..], "f64: {.}\n", value);
1133 assert(mem.eql(u8, result, "f64: 152314000000000000000000000000\n"));
1133 testing.expect(mem.eql(u8, result, "f64: 152314000000000000000000000000\n"));
11341134 }
11351135 {
11361136 var buf1: [32]u8 = undefined;
11371137 const value: f32 = 1.1234;
11381138 const result = try bufPrint(buf1[0..], "f32: {.1}\n", value);
1139 assert(mem.eql(u8, result, "f32: 1.1\n"));
1139 testing.expect(mem.eql(u8, result, "f32: 1.1\n"));
11401140 }
11411141 {
11421142 var buf1: [32]u8 = undefined;
11431143 const value: f32 = 1234.567;
11441144 const result = try bufPrint(buf1[0..], "f32: {.2}\n", value);
1145 assert(mem.eql(u8, result, "f32: 1234.57\n"));
1145 testing.expect(mem.eql(u8, result, "f32: 1234.57\n"));
11461146 }
11471147 {
11481148 var buf1: [32]u8 = undefined;
......@@ -1150,92 +1150,92 @@ test "fmt.format" {
11501150 const result = try bufPrint(buf1[0..], "f32: {.4}\n", value);
11511151 // -11.1234 is converted to f64 -11.12339... internally (errol3() function takes f64).
11521152 // -11.12339... is rounded back up to -11.1234
1153 assert(mem.eql(u8, result, "f32: -11.1234\n"));
1153 testing.expect(mem.eql(u8, result, "f32: -11.1234\n"));
11541154 }
11551155 {
11561156 var buf1: [32]u8 = undefined;
11571157 const value: f32 = 91.12345;
11581158 const result = try bufPrint(buf1[0..], "f32: {.5}\n", value);
1159 assert(mem.eql(u8, result, "f32: 91.12345\n"));
1159 testing.expect(mem.eql(u8, result, "f32: 91.12345\n"));
11601160 }
11611161 {
11621162 var buf1: [32]u8 = undefined;
11631163 const value: f64 = 91.12345678901235;
11641164 const result = try bufPrint(buf1[0..], "f64: {.10}\n", value);
1165 assert(mem.eql(u8, result, "f64: 91.1234567890\n"));
1165 testing.expect(mem.eql(u8, result, "f64: 91.1234567890\n"));
11661166 }
11671167 {
11681168 var buf1: [32]u8 = undefined;
11691169 const value: f64 = 0.0;
11701170 const result = try bufPrint(buf1[0..], "f64: {.5}\n", value);
1171 assert(mem.eql(u8, result, "f64: 0.00000\n"));
1171 testing.expect(mem.eql(u8, result, "f64: 0.00000\n"));
11721172 }
11731173 {
11741174 var buf1: [32]u8 = undefined;
11751175 const value: f64 = 5.700;
11761176 const result = try bufPrint(buf1[0..], "f64: {.0}\n", value);
1177 assert(mem.eql(u8, result, "f64: 6\n"));
1177 testing.expect(mem.eql(u8, result, "f64: 6\n"));
11781178 }
11791179 {
11801180 var buf1: [32]u8 = undefined;
11811181 const value: f64 = 9.999;
11821182 const result = try bufPrint(buf1[0..], "f64: {.1}\n", value);
1183 assert(mem.eql(u8, result, "f64: 10.0\n"));
1183 testing.expect(mem.eql(u8, result, "f64: 10.0\n"));
11841184 }
11851185 {
11861186 var buf1: [32]u8 = undefined;
11871187 const value: f64 = 1.0;
11881188 const result = try bufPrint(buf1[0..], "f64: {.3}\n", value);
1189 assert(mem.eql(u8, result, "f64: 1.000\n"));
1189 testing.expect(mem.eql(u8, result, "f64: 1.000\n"));
11901190 }
11911191 {
11921192 var buf1: [32]u8 = undefined;
11931193 const value: f64 = 0.0003;
11941194 const result = try bufPrint(buf1[0..], "f64: {.8}\n", value);
1195 assert(mem.eql(u8, result, "f64: 0.00030000\n"));
1195 testing.expect(mem.eql(u8, result, "f64: 0.00030000\n"));
11961196 }
11971197 {
11981198 var buf1: [32]u8 = undefined;
11991199 const value: f64 = 1.40130e-45;
12001200 const result = try bufPrint(buf1[0..], "f64: {.5}\n", value);
1201 assert(mem.eql(u8, result, "f64: 0.00000\n"));
1201 testing.expect(mem.eql(u8, result, "f64: 0.00000\n"));
12021202 }
12031203 {
12041204 var buf1: [32]u8 = undefined;
12051205 const value: f64 = 9.999960e-40;
12061206 const result = try bufPrint(buf1[0..], "f64: {.5}\n", value);
1207 assert(mem.eql(u8, result, "f64: 0.00000\n"));
1207 testing.expect(mem.eql(u8, result, "f64: 0.00000\n"));
12081208 }
12091209 // libc checks
12101210 {
12111211 var buf1: [32]u8 = undefined;
12121212 const value: f64 = f64(@bitCast(f32, u32(916964781)));
12131213 const result = try bufPrint(buf1[0..], "f64: {.5}\n", value);
1214 assert(mem.eql(u8, result, "f64: 0.00001\n"));
1214 testing.expect(mem.eql(u8, result, "f64: 0.00001\n"));
12151215 }
12161216 {
12171217 var buf1: [32]u8 = undefined;
12181218 const value: f64 = f64(@bitCast(f32, u32(925353389)));
12191219 const result = try bufPrint(buf1[0..], "f64: {.5}\n", value);
1220 assert(mem.eql(u8, result, "f64: 0.00001\n"));
1220 testing.expect(mem.eql(u8, result, "f64: 0.00001\n"));
12211221 }
12221222 {
12231223 var buf1: [32]u8 = undefined;
12241224 const value: f64 = f64(@bitCast(f32, u32(1036831278)));
12251225 const result = try bufPrint(buf1[0..], "f64: {.5}\n", value);
1226 assert(mem.eql(u8, result, "f64: 0.10000\n"));
1226 testing.expect(mem.eql(u8, result, "f64: 0.10000\n"));
12271227 }
12281228 {
12291229 var buf1: [32]u8 = undefined;
12301230 const value: f64 = f64(@bitCast(f32, u32(1065353133)));
12311231 const result = try bufPrint(buf1[0..], "f64: {.5}\n", value);
1232 assert(mem.eql(u8, result, "f64: 1.00000\n"));
1232 testing.expect(mem.eql(u8, result, "f64: 1.00000\n"));
12331233 }
12341234 {
12351235 var buf1: [32]u8 = undefined;
12361236 const value: f64 = f64(@bitCast(f32, u32(1092616192)));
12371237 const result = try bufPrint(buf1[0..], "f64: {.5}\n", value);
1238 assert(mem.eql(u8, result, "f64: 10.00000\n"));
1238 testing.expect(mem.eql(u8, result, "f64: 10.00000\n"));
12391239 }
12401240 // libc differences
12411241 {
......@@ -1245,7 +1245,7 @@ test "fmt.format" {
12451245 // floats of the form x.yyyy25 on a precision point.
12461246 const value: f64 = f64(@bitCast(f32, u32(1015021568)));
12471247 const result = try bufPrint(buf1[0..], "f64: {.5}\n", value);
1248 assert(mem.eql(u8, result, "f64: 0.01563\n"));
1248 testing.expect(mem.eql(u8, result, "f64: 0.01563\n"));
12491249 }
12501250 // std-windows-x86_64-Debug-bare test case fails
12511251 {
......@@ -1255,7 +1255,7 @@ test "fmt.format" {
12551255 var buf1: [32]u8 = undefined;
12561256 const value: f64 = f64(@bitCast(f32, u32(1518338049)));
12571257 const result = try bufPrint(buf1[0..], "f64: {.5}\n", value);
1258 assert(mem.eql(u8, result, "f64: 18014400656965630.00000\n"));
1258 testing.expect(mem.eql(u8, result, "f64: 18014400656965630.00000\n"));
12591259 }
12601260 //custom type format
12611261 {
......@@ -1336,10 +1336,10 @@ test "fmt.format" {
13361336
13371337 var buf: [100]u8 = undefined;
13381338 const uu_result = try bufPrint(buf[0..], "{}", uu_inst);
1339 debug.assert(mem.eql(u8, uu_result[0..3], "UU@"));
1339 testing.expect(mem.eql(u8, uu_result[0..3], "UU@"));
13401340
13411341 const eu_result = try bufPrint(buf[0..], "{}", eu_inst);
1342 debug.assert(mem.eql(u8, uu_result[0..3], "EU@"));
1342 testing.expect(mem.eql(u8, uu_result[0..3], "EU@"));
13431343 }
13441344 //enum format
13451345 {
......@@ -1398,11 +1398,11 @@ pub fn trim(buf: []const u8) []const u8 {
13981398}
13991399
14001400test "fmt.trim" {
1401 assert(mem.eql(u8, "abc", trim("\n abc \t")));
1402 assert(mem.eql(u8, "", trim(" ")));
1403 assert(mem.eql(u8, "", trim("")));
1404 assert(mem.eql(u8, "abc", trim(" abc")));
1405 assert(mem.eql(u8, "abc", trim("abc ")));
1401 testing.expect(mem.eql(u8, "abc", trim("\n abc \t")));
1402 testing.expect(mem.eql(u8, "", trim(" ")));
1403 testing.expect(mem.eql(u8, "", trim("")));
1404 testing.expect(mem.eql(u8, "abc", trim(" abc")));
1405 testing.expect(mem.eql(u8, "abc", trim("abc ")));
14061406}
14071407
14081408pub fn isWhiteSpace(byte: u8) bool {
std/hash/adler.zig+6-6
......@@ -4,7 +4,7 @@
44// https://github.com/madler/zlib/blob/master/adler32.c
55
66const std = @import("../index.zig");
7const debug = std.debug;
7const testing = std.testing;
88
99pub const Adler32 = struct {
1010 const base = 65521;
......@@ -89,19 +89,19 @@ pub const Adler32 = struct {
8989};
9090
9191test "adler32 sanity" {
92 debug.assert(Adler32.hash("a") == 0x620062);
93 debug.assert(Adler32.hash("example") == 0xbc002ed);
92 testing.expect(Adler32.hash("a") == 0x620062);
93 testing.expect(Adler32.hash("example") == 0xbc002ed);
9494}
9595
9696test "adler32 long" {
9797 const long1 = []u8{1} ** 1024;
98 debug.assert(Adler32.hash(long1[0..]) == 0x06780401);
98 testing.expect(Adler32.hash(long1[0..]) == 0x06780401);
9999
100100 const long2 = []u8{1} ** 1025;
101 debug.assert(Adler32.hash(long2[0..]) == 0x0a7a0402);
101 testing.expect(Adler32.hash(long2[0..]) == 0x0a7a0402);
102102}
103103
104104test "adler32 very long" {
105105 const long = []u8{1} ** 5553;
106 debug.assert(Adler32.hash(long[0..]) == 0x707f15b2);
106 testing.expect(Adler32.hash(long[0..]) == 0x707f15b2);
107107}
std/hash/crc.zig+13-12
......@@ -7,6 +7,7 @@
77
88const std = @import("../index.zig");
99const debug = std.debug;
10const testing = std.testing;
1011
1112pub const Polynomial = struct {
1213 const IEEE = 0xedb88320;
......@@ -101,17 +102,17 @@ pub fn Crc32WithPoly(comptime poly: u32) type {
101102test "crc32 ieee" {
102103 const Crc32Ieee = Crc32WithPoly(Polynomial.IEEE);
103104
104 debug.assert(Crc32Ieee.hash("") == 0x00000000);
105 debug.assert(Crc32Ieee.hash("a") == 0xe8b7be43);
106 debug.assert(Crc32Ieee.hash("abc") == 0x352441c2);
105 testing.expect(Crc32Ieee.hash("") == 0x00000000);
106 testing.expect(Crc32Ieee.hash("a") == 0xe8b7be43);
107 testing.expect(Crc32Ieee.hash("abc") == 0x352441c2);
107108}
108109
109110test "crc32 castagnoli" {
110111 const Crc32Castagnoli = Crc32WithPoly(Polynomial.Castagnoli);
111112
112 debug.assert(Crc32Castagnoli.hash("") == 0x00000000);
113 debug.assert(Crc32Castagnoli.hash("a") == 0xc1d04330);
114 debug.assert(Crc32Castagnoli.hash("abc") == 0x364b3fb7);
113 testing.expect(Crc32Castagnoli.hash("") == 0x00000000);
114 testing.expect(Crc32Castagnoli.hash("a") == 0xc1d04330);
115 testing.expect(Crc32Castagnoli.hash("abc") == 0x364b3fb7);
115116}
116117
117118// half-byte lookup table implementation.
......@@ -165,15 +166,15 @@ pub fn Crc32SmallWithPoly(comptime poly: u32) type {
165166test "small crc32 ieee" {
166167 const Crc32Ieee = Crc32SmallWithPoly(Polynomial.IEEE);
167168
168 debug.assert(Crc32Ieee.hash("") == 0x00000000);
169 debug.assert(Crc32Ieee.hash("a") == 0xe8b7be43);
170 debug.assert(Crc32Ieee.hash("abc") == 0x352441c2);
169 testing.expect(Crc32Ieee.hash("") == 0x00000000);
170 testing.expect(Crc32Ieee.hash("a") == 0xe8b7be43);
171 testing.expect(Crc32Ieee.hash("abc") == 0x352441c2);
171172}
172173
173174test "small crc32 castagnoli" {
174175 const Crc32Castagnoli = Crc32SmallWithPoly(Polynomial.Castagnoli);
175176
176 debug.assert(Crc32Castagnoli.hash("") == 0x00000000);
177 debug.assert(Crc32Castagnoli.hash("a") == 0xc1d04330);
178 debug.assert(Crc32Castagnoli.hash("abc") == 0x364b3fb7);
177 testing.expect(Crc32Castagnoli.hash("") == 0x00000000);
178 testing.expect(Crc32Castagnoli.hash("a") == 0xc1d04330);
179 testing.expect(Crc32Castagnoli.hash("abc") == 0x364b3fb7);
179180}
std/hash/fnv.zig+9-9
......@@ -5,7 +5,7 @@
55// https://tools.ietf.org/html/draft-eastlake-fnv-14
66
77const std = @import("../index.zig");
8const debug = std.debug;
8const testing = std.testing;
99
1010pub const Fnv1a_32 = Fnv1a(u32, 0x01000193, 0x811c9dc5);
1111pub const Fnv1a_64 = Fnv1a(u64, 0x100000001b3, 0xcbf29ce484222325);
......@@ -41,18 +41,18 @@ fn Fnv1a(comptime T: type, comptime prime: T, comptime offset: T) type {
4141}
4242
4343test "fnv1a-32" {
44 debug.assert(Fnv1a_32.hash("") == 0x811c9dc5);
45 debug.assert(Fnv1a_32.hash("a") == 0xe40c292c);
46 debug.assert(Fnv1a_32.hash("foobar") == 0xbf9cf968);
44 testing.expect(Fnv1a_32.hash("") == 0x811c9dc5);
45 testing.expect(Fnv1a_32.hash("a") == 0xe40c292c);
46 testing.expect(Fnv1a_32.hash("foobar") == 0xbf9cf968);
4747}
4848
4949test "fnv1a-64" {
50 debug.assert(Fnv1a_64.hash("") == 0xcbf29ce484222325);
51 debug.assert(Fnv1a_64.hash("a") == 0xaf63dc4c8601ec8c);
52 debug.assert(Fnv1a_64.hash("foobar") == 0x85944171f73967e8);
50 testing.expect(Fnv1a_64.hash("") == 0xcbf29ce484222325);
51 testing.expect(Fnv1a_64.hash("a") == 0xaf63dc4c8601ec8c);
52 testing.expect(Fnv1a_64.hash("foobar") == 0x85944171f73967e8);
5353}
5454
5555test "fnv1a-128" {
56 debug.assert(Fnv1a_128.hash("") == 0x6c62272e07bb014262b821756295c58d);
57 debug.assert(Fnv1a_128.hash("a") == 0xd228cb696f1a8caf78912b704e4a8964);
56 testing.expect(Fnv1a_128.hash("") == 0x6c62272e07bb014262b821756295c58d);
57 testing.expect(Fnv1a_128.hash("a") == 0xd228cb696f1a8caf78912b704e4a8964);
5858}
std/hash/siphash.zig+8-7
......@@ -6,7 +6,8 @@
66// https://131002.net/siphash/
77
88const std = @import("../index.zig");
9const debug = std.debug;
9const assert = std.debug.assert;
10const testing = std.testing;
1011const math = std.math;
1112const mem = std.mem;
1213
......@@ -21,8 +22,8 @@ pub fn SipHash128(comptime c_rounds: usize, comptime d_rounds: usize) type {
2122}
2223
2324fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize) type {
24 debug.assert(T == u64 or T == u128);
25 debug.assert(c_rounds > 0 and d_rounds > 0);
25 assert(T == u64 or T == u128);
26 assert(c_rounds > 0 and d_rounds > 0);
2627
2728 return struct {
2829 const Self = @This();
......@@ -40,7 +41,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)
4041 msg_len: u8,
4142
4243 pub fn init(key: []const u8) Self {
43 debug.assert(key.len >= 16);
44 assert(key.len >= 16);
4445
4546 const k0 = mem.readIntSliceLittle(u64, key[0..8]);
4647 const k1 = mem.readIntSliceLittle(u64, key[8..16]);
......@@ -119,7 +120,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)
119120 }
120121
121122 fn round(d: *Self, b: []const u8) void {
122 debug.assert(b.len == 8);
123 assert(b.len == 8);
123124
124125 const m = mem.readIntSliceLittle(u64, b[0..]);
125126 d.v3 ^= m;
......@@ -236,7 +237,7 @@ test "siphash64-2-4 sanity" {
236237 buffer[i] = @intCast(u8, i);
237238
238239 const expected = mem.readIntLittle(u64, &vector);
239 debug.assert(siphash.hash(test_key, buffer[0..i]) == expected);
240 testing.expect(siphash.hash(test_key, buffer[0..i]) == expected);
240241 }
241242}
242243
......@@ -315,6 +316,6 @@ test "siphash128-2-4 sanity" {
315316 buffer[i] = @intCast(u8, i);
316317
317318 const expected = mem.readIntLittle(u128, &vector);
318 debug.assert(siphash.hash(test_key, buffer[0..i]) == expected);
319 testing.expect(siphash.hash(test_key, buffer[0..i]) == expected);
319320 }
320321}
std/hash_map.zig+30-29
......@@ -1,6 +1,7 @@
11const std = @import("index.zig");
22const debug = std.debug;
33const assert = debug.assert;
4const testing = std.testing;
45const math = std.math;
56const mem = std.mem;
67const Allocator = mem.Allocator;
......@@ -342,37 +343,37 @@ test "basic hash map usage" {
342343 var map = AutoHashMap(i32, i32).init(&direct_allocator.allocator);
343344 defer map.deinit();
344345
345 assert((try map.put(1, 11)) == null);
346 assert((try map.put(2, 22)) == null);
347 assert((try map.put(3, 33)) == null);
348 assert((try map.put(4, 44)) == null);
349 assert((try map.put(5, 55)) == null);
346 testing.expect((try map.put(1, 11)) == null);
347 testing.expect((try map.put(2, 22)) == null);
348 testing.expect((try map.put(3, 33)) == null);
349 testing.expect((try map.put(4, 44)) == null);
350 testing.expect((try map.put(5, 55)) == null);
350351
351 assert((try map.put(5, 66)).?.value == 55);
352 assert((try map.put(5, 55)).?.value == 66);
352 testing.expect((try map.put(5, 66)).?.value == 55);
353 testing.expect((try map.put(5, 55)).?.value == 66);
353354
354355 const gop1 = try map.getOrPut(5);
355 assert(gop1.found_existing == true);
356 assert(gop1.kv.value == 55);
356 testing.expect(gop1.found_existing == true);
357 testing.expect(gop1.kv.value == 55);
357358 gop1.kv.value = 77;
358 assert(map.get(5).?.value == 77);
359 testing.expect(map.get(5).?.value == 77);
359360
360361 const gop2 = try map.getOrPut(99);
361 assert(gop2.found_existing == false);
362 testing.expect(gop2.found_existing == false);
362363 gop2.kv.value = 42;
363 assert(map.get(99).?.value == 42);
364 testing.expect(map.get(99).?.value == 42);
364365
365366 const gop3 = try map.getOrPutValue(5, 5);
366 assert(gop3.value == 77);
367 testing.expect(gop3.value == 77);
367368
368369 const gop4 = try map.getOrPutValue(100, 41);
369 assert(gop4.value == 41);
370 testing.expect(gop4.value == 41);
370371
371 assert(map.contains(2));
372 assert(map.get(2).?.value == 22);
372 testing.expect(map.contains(2));
373 testing.expect(map.get(2).?.value == 22);
373374 _ = map.remove(2);
374 assert(map.remove(2) == null);
375 assert(map.get(2) == null);
375 testing.expect(map.remove(2) == null);
376 testing.expect(map.get(2) == null);
376377}
377378
378379test "iterator hash map" {
......@@ -382,9 +383,9 @@ test "iterator hash map" {
382383 var reset_map = AutoHashMap(i32, i32).init(&direct_allocator.allocator);
383384 defer reset_map.deinit();
384385
385 assert((try reset_map.put(1, 11)) == null);
386 assert((try reset_map.put(2, 22)) == null);
387 assert((try reset_map.put(3, 33)) == null);
386 testing.expect((try reset_map.put(1, 11)) == null);
387 testing.expect((try reset_map.put(2, 22)) == null);
388 testing.expect((try reset_map.put(3, 33)) == null);
388389
389390 var keys = []i32{
390391 3,
......@@ -400,26 +401,26 @@ test "iterator hash map" {
400401 var it = reset_map.iterator();
401402 var count: usize = 0;
402403 while (it.next()) |next| {
403 assert(next.key == keys[count]);
404 assert(next.value == values[count]);
404 testing.expect(next.key == keys[count]);
405 testing.expect(next.value == values[count]);
405406 count += 1;
406407 }
407408
408 assert(count == 3);
409 assert(it.next() == null);
409 testing.expect(count == 3);
410 testing.expect(it.next() == null);
410411 it.reset();
411412 count = 0;
412413 while (it.next()) |next| {
413 assert(next.key == keys[count]);
414 assert(next.value == values[count]);
414 testing.expect(next.key == keys[count]);
415 testing.expect(next.value == values[count]);
415416 count += 1;
416417 if (count == 2) break;
417418 }
418419
419420 it.reset();
420421 var entry = it.next().?;
421 assert(entry.key == keys[0]);
422 assert(entry.value == values[0]);
422 testing.expect(entry.key == keys[0]);
423 testing.expect(entry.value == values[0]);
423424}
424425
425426pub fn getHashPtrAddrFn(comptime K: type) (fn (K) u32) {
std/heap.zig+28-27
......@@ -1,6 +1,7 @@
11const std = @import("index.zig");
22const debug = std.debug;
33const assert = debug.assert;
4const testing = std.testing;
45const mem = std.mem;
56const os = std.os;
67const builtin = @import("builtin");
......@@ -487,11 +488,11 @@ test "FixedBufferAllocator Reuse memory on realloc" {
487488 var fixed_buffer_allocator = FixedBufferAllocator.init(small_fixed_buffer[0..]);
488489
489490 var slice0 = try fixed_buffer_allocator.allocator.alloc(u8, 5);
490 assert(slice0.len == 5);
491 testing.expect(slice0.len == 5);
491492 var slice1 = try fixed_buffer_allocator.allocator.realloc(u8, slice0, 10);
492 assert(slice1.ptr == slice0.ptr);
493 assert(slice1.len == 10);
494 debug.assertError(fixed_buffer_allocator.allocator.realloc(u8, slice1, 11), error.OutOfMemory);
493 testing.expect(slice1.ptr == slice0.ptr);
494 testing.expect(slice1.len == 10);
495 testing.expectError(error.OutOfMemory, fixed_buffer_allocator.allocator.realloc(u8, slice1, 11));
495496 }
496497 // check that we don't re-use the memory if it's not the most recent block
497498 {
......@@ -502,10 +503,10 @@ test "FixedBufferAllocator Reuse memory on realloc" {
502503 slice0[1] = 2;
503504 var slice1 = try fixed_buffer_allocator.allocator.alloc(u8, 2);
504505 var slice2 = try fixed_buffer_allocator.allocator.realloc(u8, slice0, 4);
505 assert(slice0.ptr != slice2.ptr);
506 assert(slice1.ptr != slice2.ptr);
507 assert(slice2[0] == 1);
508 assert(slice2[1] == 2);
506 testing.expect(slice0.ptr != slice2.ptr);
507 testing.expect(slice1.ptr != slice2.ptr);
508 testing.expect(slice2[0] == 1);
509 testing.expect(slice2[1] == 2);
509510 }
510511}
511512
......@@ -519,28 +520,28 @@ test "ThreadSafeFixedBufferAllocator" {
519520
520521fn testAllocator(allocator: *mem.Allocator) !void {
521522 var slice = try allocator.alloc(*i32, 100);
522 assert(slice.len == 100);
523 testing.expect(slice.len == 100);
523524 for (slice) |*item, i| {
524525 item.* = try allocator.create(i32);
525526 item.*.* = @intCast(i32, i);
526527 }
527528
528529 slice = try allocator.realloc(*i32, slice, 20000);
529 assert(slice.len == 20000);
530 testing.expect(slice.len == 20000);
530531
531532 for (slice[0..100]) |item, i| {
532 assert(item.* == @intCast(i32, i));
533 testing.expect(item.* == @intCast(i32, i));
533534 allocator.destroy(item);
534535 }
535536
536537 slice = try allocator.realloc(*i32, slice, 50);
537 assert(slice.len == 50);
538 testing.expect(slice.len == 50);
538539 slice = try allocator.realloc(*i32, slice, 25);
539 assert(slice.len == 25);
540 testing.expect(slice.len == 25);
540541 slice = try allocator.realloc(*i32, slice, 0);
541 assert(slice.len == 0);
542 testing.expect(slice.len == 0);
542543 slice = try allocator.realloc(*i32, slice, 10);
543 assert(slice.len == 10);
544 testing.expect(slice.len == 10);
544545
545546 allocator.free(slice);
546547}
......@@ -548,25 +549,25 @@ fn testAllocator(allocator: *mem.Allocator) !void {
548549fn testAllocatorAligned(allocator: *mem.Allocator, comptime alignment: u29) !void {
549550 // initial
550551 var slice = try allocator.alignedAlloc(u8, alignment, 10);
551 assert(slice.len == 10);
552 testing.expect(slice.len == 10);
552553 // grow
553554 slice = try allocator.alignedRealloc(u8, alignment, slice, 100);
554 assert(slice.len == 100);
555 testing.expect(slice.len == 100);
555556 // shrink
556557 slice = try allocator.alignedRealloc(u8, alignment, slice, 10);
557 assert(slice.len == 10);
558 testing.expect(slice.len == 10);
558559 // go to zero
559560 slice = try allocator.alignedRealloc(u8, alignment, slice, 0);
560 assert(slice.len == 0);
561 testing.expect(slice.len == 0);
561562 // realloc from zero
562563 slice = try allocator.alignedRealloc(u8, alignment, slice, 100);
563 assert(slice.len == 100);
564 testing.expect(slice.len == 100);
564565 // shrink with shrink
565566 slice = allocator.alignedShrink(u8, alignment, slice, 10);
566 assert(slice.len == 10);
567 testing.expect(slice.len == 10);
567568 // shrink to zero
568569 slice = allocator.alignedShrink(u8, alignment, slice, 0);
569 assert(slice.len == 0);
570 testing.expect(slice.len == 0);
570571}
571572
572573fn testAllocatorLargeAlignment(allocator: *mem.Allocator) mem.Allocator.Error!void {
......@@ -581,19 +582,19 @@ fn testAllocatorLargeAlignment(allocator: *mem.Allocator) mem.Allocator.Error!vo
581582 _ = @shlWithOverflow(usize, ~usize(0), USizeShift(@ctz(large_align)), &align_mask);
582583
583584 var slice = try allocator.allocFn(allocator, 500, large_align);
584 debug.assert(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
585 testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
585586
586587 slice = try allocator.reallocFn(allocator, slice, 100, large_align);
587 debug.assert(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
588 testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
588589
589590 slice = try allocator.reallocFn(allocator, slice, 5000, large_align);
590 debug.assert(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
591 testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
591592
592593 slice = try allocator.reallocFn(allocator, slice, 10, large_align);
593 debug.assert(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
594 testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
594595
595596 slice = try allocator.reallocFn(allocator, slice, 20000, large_align);
596 debug.assert(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
597 testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
597598
598599 allocator.free(slice);
599600}
std/index.zig+8-7
......@@ -31,6 +31,7 @@ pub const hash_map = @import("hash_map.zig");
3131pub const heap = @import("heap.zig");
3232pub const io = @import("io.zig");
3333pub const json = @import("json.zig");
34pub const lazyInit = @import("lazy_init.zig").lazyInit;
3435pub const macho = @import("macho.zig");
3536pub const math = @import("math/index.zig");
3637pub const mem = @import("mem.zig");
......@@ -41,11 +42,10 @@ pub const pdb = @import("pdb.zig");
4142pub const rand = @import("rand/index.zig");
4243pub const rb = @import("rb.zig");
4344pub const sort = @import("sort.zig");
45pub const testing = @import("testing.zig");
4446pub const unicode = @import("unicode.zig");
4547pub const zig = @import("zig/index.zig");
4648
47pub const lazyInit = @import("lazy_init.zig").lazyInit;
48
4949test "std" {
5050 // run tests from these
5151 _ = @import("array_list.zig");
......@@ -60,7 +60,6 @@ test "std" {
6060 _ = @import("segmented_list.zig");
6161 _ = @import("spinlock.zig");
6262
63 _ = @import("dynamic_library.zig");
6463 _ = @import("base64.zig");
6564 _ = @import("build.zig");
6665 _ = @import("c/index.zig");
......@@ -69,24 +68,26 @@ test "std" {
6968 _ = @import("cstr.zig");
7069 _ = @import("debug/index.zig");
7170 _ = @import("dwarf.zig");
71 _ = @import("dynamic_library.zig");
7272 _ = @import("elf.zig");
7373 _ = @import("empty.zig");
7474 _ = @import("event.zig");
7575 _ = @import("fmt/index.zig");
7676 _ = @import("hash/index.zig");
77 _ = @import("heap.zig");
7778 _ = @import("io.zig");
7879 _ = @import("json.zig");
80 _ = @import("lazy_init.zig");
7981 _ = @import("macho.zig");
8082 _ = @import("math/index.zig");
81 _ = @import("meta/index.zig");
8283 _ = @import("mem.zig");
84 _ = @import("meta/index.zig");
8385 _ = @import("net.zig");
84 _ = @import("heap.zig");
8586 _ = @import("os/index.zig");
86 _ = @import("rand/index.zig");
8787 _ = @import("pdb.zig");
88 _ = @import("rand/index.zig");
8889 _ = @import("sort.zig");
90 _ = @import("testing.zig");
8991 _ = @import("unicode.zig");
9092 _ = @import("zig/index.zig");
91 _ = @import("lazy_init.zig");
9293}
std/io.zig+9-8
......@@ -13,6 +13,7 @@ const trait = meta.trait;
1313const Buffer = std.Buffer;
1414const fmt = std.fmt;
1515const File = std.os.File;
16const testing = std.testing;
1617
1718const is_posix = builtin.os != builtin.Os.windows;
1819const is_windows = builtin.os == builtin.Os.windows;
......@@ -664,7 +665,7 @@ test "io.SliceOutStream" {
664665 const stream = &slice_stream.stream;
665666
666667 try stream.print("{}{}!", "Hello", "World");
667 debug.assertOrPanic(mem.eql(u8, "HelloWorld!", slice_stream.getWritten()));
668 testing.expectEqualSlices(u8, "HelloWorld!", slice_stream.getWritten());
668669}
669670
670671var null_out_stream_state = NullOutStream.init();
......@@ -726,7 +727,7 @@ test "io.CountingOutStream" {
726727
727728 const bytes = "yay" ** 10000;
728729 stream.write(bytes) catch unreachable;
729 debug.assertOrPanic(counting_stream.bytes_written == bytes.len);
730 testing.expect(counting_stream.bytes_written == bytes.len);
730731}
731732
732733pub fn BufferedOutStream(comptime Error: type) type {
......@@ -1014,10 +1015,10 @@ test "io.readLineFrom" {
10141015 );
10151016 const stream = &mem_stream.stream;
10161017
1017 debug.assertOrPanic(mem.eql(u8, "Line 1", try readLineFrom(stream, &buf)));
1018 debug.assertOrPanic(mem.eql(u8, "Line 22", try readLineFrom(stream, &buf)));
1019 debug.assertError(readLineFrom(stream, &buf), error.EndOfStream);
1020 debug.assertOrPanic(mem.eql(u8, buf.toSlice(), "Line 1Line 22Line 333"));
1018 testing.expectEqualSlices(u8, "Line 1", try readLineFrom(stream, &buf));
1019 testing.expectEqualSlices(u8, "Line 22", try readLineFrom(stream, &buf));
1020 testing.expectError(error.EndOfStream, readLineFrom(stream, &buf));
1021 testing.expectEqualSlices(u8, "Line 1Line 22Line 333", buf.toSlice());
10211022}
10221023
10231024pub fn readLineSlice(slice: []u8) ![]u8 {
......@@ -1045,8 +1046,8 @@ test "io.readLineSliceFrom" {
10451046 );
10461047 const stream = &mem_stream.stream;
10471048
1048 debug.assertOrPanic(mem.eql(u8, "Line 1", try readLineSliceFrom(stream, buf[0..])));
1049 debug.assertError(readLineSliceFrom(stream, buf[0..]), error.OutOfMemory);
1049 testing.expectEqualSlices(u8, "Line 1", try readLineSliceFrom(stream, buf[0..]));
1050 testing.expectError(error.OutOfMemory, readLineSliceFrom(stream, buf[0..]));
10501051}
10511052
10521053/// Creates a deserializer that deserializes types from any stream.
std/io_test.zig+101-101
......@@ -3,8 +3,8 @@ const io = std.io;
33const meta = std.meta;
44const trait = std.trait;
55const DefaultPrng = std.rand.DefaultPrng;
6const assert = std.debug.assert;
7const assertError = std.debug.assertError;
6const expect = std.testing.expect;
7const expectError = std.testing.expectError;
88const mem = std.mem;
99const os = std.os;
1010const builtin = @import("builtin");
......@@ -35,7 +35,7 @@ test "write a file, read it, then delete it" {
3535
3636 const file_size = try file.getEndPos();
3737 const expected_file_size = "begin".len + data.len + "end".len;
38 assert(file_size == expected_file_size);
38 expect(file_size == expected_file_size);
3939
4040 var file_in_stream = file.inStream();
4141 var buf_stream = io.BufferedInStream(os.File.ReadError).init(&file_in_stream.stream);
......@@ -43,9 +43,9 @@ test "write a file, read it, then delete it" {
4343 const contents = try st.readAllAlloc(allocator, 2 * 1024);
4444 defer allocator.free(contents);
4545
46 assert(mem.eql(u8, contents[0.."begin".len], "begin"));
47 assert(mem.eql(u8, contents["begin".len .. contents.len - "end".len], data));
48 assert(mem.eql(u8, contents[contents.len - "end".len ..], "end"));
46 expect(mem.eql(u8, contents[0.."begin".len], "begin"));
47 expect(mem.eql(u8, contents["begin".len .. contents.len - "end".len], data));
48 expect(mem.eql(u8, contents[contents.len - "end".len ..], "end"));
4949 }
5050 try os.deleteFile(tmp_file_name);
5151}
......@@ -61,7 +61,7 @@ test "BufferOutStream" {
6161 const y: i32 = 1234;
6262 try buf_stream.print("x: {}\ny: {}\n", x, y);
6363
64 assert(mem.eql(u8, buffer.toSlice(), "x: 42\ny: 1234\n"));
64 expect(mem.eql(u8, buffer.toSlice(), "x: 42\ny: 1234\n"));
6565}
6666
6767test "SliceInStream" {
......@@ -71,15 +71,15 @@ test "SliceInStream" {
7171 var dest: [4]u8 = undefined;
7272
7373 var read = try ss.stream.read(dest[0..4]);
74 assert(read == 4);
75 assert(mem.eql(u8, dest[0..4], bytes[0..4]));
74 expect(read == 4);
75 expect(mem.eql(u8, dest[0..4], bytes[0..4]));
7676
7777 read = try ss.stream.read(dest[0..4]);
78 assert(read == 3);
79 assert(mem.eql(u8, dest[0..3], bytes[4..7]));
78 expect(read == 3);
79 expect(mem.eql(u8, dest[0..3], bytes[4..7]));
8080
8181 read = try ss.stream.read(dest[0..4]);
82 assert(read == 0);
82 expect(read == 0);
8383}
8484
8585test "PeekStream" {
......@@ -93,26 +93,26 @@ test "PeekStream" {
9393 ps.putBackByte(10);
9494
9595 var read = try ps.stream.read(dest[0..4]);
96 assert(read == 4);
97 assert(dest[0] == 10);
98 assert(dest[1] == 9);
99 assert(mem.eql(u8, dest[2..4], bytes[0..2]));
96 expect(read == 4);
97 expect(dest[0] == 10);
98 expect(dest[1] == 9);
99 expect(mem.eql(u8, dest[2..4], bytes[0..2]));
100100
101101 read = try ps.stream.read(dest[0..4]);
102 assert(read == 4);
103 assert(mem.eql(u8, dest[0..4], bytes[2..6]));
102 expect(read == 4);
103 expect(mem.eql(u8, dest[0..4], bytes[2..6]));
104104
105105 read = try ps.stream.read(dest[0..4]);
106 assert(read == 2);
107 assert(mem.eql(u8, dest[0..2], bytes[6..8]));
106 expect(read == 2);
107 expect(mem.eql(u8, dest[0..2], bytes[6..8]));
108108
109109 ps.putBackByte(11);
110110 ps.putBackByte(12);
111111
112112 read = try ps.stream.read(dest[0..4]);
113 assert(read == 2);
114 assert(dest[0] == 12);
115 assert(dest[1] == 11);
113 expect(read == 2);
114 expect(dest[0] == 12);
115 expect(dest[1] == 11);
116116}
117117
118118test "SliceOutStream" {
......@@ -120,19 +120,19 @@ test "SliceOutStream" {
120120 var ss = io.SliceOutStream.init(buffer[0..]);
121121
122122 try ss.stream.write("Hello");
123 assert(mem.eql(u8, ss.getWritten(), "Hello"));
123 expect(mem.eql(u8, ss.getWritten(), "Hello"));
124124
125125 try ss.stream.write("world");
126 assert(mem.eql(u8, ss.getWritten(), "Helloworld"));
126 expect(mem.eql(u8, ss.getWritten(), "Helloworld"));
127127
128 assertError(ss.stream.write("!"), error.OutOfSpace);
129 assert(mem.eql(u8, ss.getWritten(), "Helloworld"));
128 expectError(error.OutOfSpace, ss.stream.write("!"));
129 expect(mem.eql(u8, ss.getWritten(), "Helloworld"));
130130
131131 ss.reset();
132 assert(ss.getWritten().len == 0);
132 expect(ss.getWritten().len == 0);
133133
134 assertError(ss.stream.write("Hello world!"), error.OutOfSpace);
135 assert(mem.eql(u8, ss.getWritten(), "Hello worl"));
134 expectError(error.OutOfSpace, ss.stream.write("Hello world!"));
135 expect(mem.eql(u8, ss.getWritten(), "Hello worl"));
136136}
137137
138138test "BitInStream" {
......@@ -145,66 +145,66 @@ test "BitInStream" {
145145
146146 var out_bits: usize = undefined;
147147
148 assert(1 == try bit_stream_be.readBits(u2, 1, &out_bits));
149 assert(out_bits == 1);
150 assert(2 == try bit_stream_be.readBits(u5, 2, &out_bits));
151 assert(out_bits == 2);
152 assert(3 == try bit_stream_be.readBits(u128, 3, &out_bits));
153 assert(out_bits == 3);
154 assert(4 == try bit_stream_be.readBits(u8, 4, &out_bits));
155 assert(out_bits == 4);
156 assert(5 == try bit_stream_be.readBits(u9, 5, &out_bits));
157 assert(out_bits == 5);
158 assert(1 == try bit_stream_be.readBits(u1, 1, &out_bits));
159 assert(out_bits == 1);
148 expect(1 == try bit_stream_be.readBits(u2, 1, &out_bits));
149 expect(out_bits == 1);
150 expect(2 == try bit_stream_be.readBits(u5, 2, &out_bits));
151 expect(out_bits == 2);
152 expect(3 == try bit_stream_be.readBits(u128, 3, &out_bits));
153 expect(out_bits == 3);
154 expect(4 == try bit_stream_be.readBits(u8, 4, &out_bits));
155 expect(out_bits == 4);
156 expect(5 == try bit_stream_be.readBits(u9, 5, &out_bits));
157 expect(out_bits == 5);
158 expect(1 == try bit_stream_be.readBits(u1, 1, &out_bits));
159 expect(out_bits == 1);
160160
161161 mem_in_be.pos = 0;
162162 bit_stream_be.bit_count = 0;
163 assert(0b110011010000101 == try bit_stream_be.readBits(u15, 15, &out_bits));
164 assert(out_bits == 15);
163 expect(0b110011010000101 == try bit_stream_be.readBits(u15, 15, &out_bits));
164 expect(out_bits == 15);
165165
166166 mem_in_be.pos = 0;
167167 bit_stream_be.bit_count = 0;
168 assert(0b1100110100001011 == try bit_stream_be.readBits(u16, 16, &out_bits));
169 assert(out_bits == 16);
168 expect(0b1100110100001011 == try bit_stream_be.readBits(u16, 16, &out_bits));
169 expect(out_bits == 16);
170170
171171 _ = try bit_stream_be.readBits(u0, 0, &out_bits);
172172
173 assert(0 == try bit_stream_be.readBits(u1, 1, &out_bits));
174 assert(out_bits == 0);
175 assertError(bit_stream_be.readBitsNoEof(u1, 1), error.EndOfStream);
173 expect(0 == try bit_stream_be.readBits(u1, 1, &out_bits));
174 expect(out_bits == 0);
175 expectError(error.EndOfStream, bit_stream_be.readBitsNoEof(u1, 1));
176176
177177 var mem_in_le = io.SliceInStream.init(mem_le[0..]);
178178 var bit_stream_le = io.BitInStream(builtin.Endian.Little, InError).init(&mem_in_le.stream);
179179
180 assert(1 == try bit_stream_le.readBits(u2, 1, &out_bits));
181 assert(out_bits == 1);
182 assert(2 == try bit_stream_le.readBits(u5, 2, &out_bits));
183 assert(out_bits == 2);
184 assert(3 == try bit_stream_le.readBits(u128, 3, &out_bits));
185 assert(out_bits == 3);
186 assert(4 == try bit_stream_le.readBits(u8, 4, &out_bits));
187 assert(out_bits == 4);
188 assert(5 == try bit_stream_le.readBits(u9, 5, &out_bits));
189 assert(out_bits == 5);
190 assert(1 == try bit_stream_le.readBits(u1, 1, &out_bits));
191 assert(out_bits == 1);
180 expect(1 == try bit_stream_le.readBits(u2, 1, &out_bits));
181 expect(out_bits == 1);
182 expect(2 == try bit_stream_le.readBits(u5, 2, &out_bits));
183 expect(out_bits == 2);
184 expect(3 == try bit_stream_le.readBits(u128, 3, &out_bits));
185 expect(out_bits == 3);
186 expect(4 == try bit_stream_le.readBits(u8, 4, &out_bits));
187 expect(out_bits == 4);
188 expect(5 == try bit_stream_le.readBits(u9, 5, &out_bits));
189 expect(out_bits == 5);
190 expect(1 == try bit_stream_le.readBits(u1, 1, &out_bits));
191 expect(out_bits == 1);
192192
193193 mem_in_le.pos = 0;
194194 bit_stream_le.bit_count = 0;
195 assert(0b001010100011101 == try bit_stream_le.readBits(u15, 15, &out_bits));
196 assert(out_bits == 15);
195 expect(0b001010100011101 == try bit_stream_le.readBits(u15, 15, &out_bits));
196 expect(out_bits == 15);
197197
198198 mem_in_le.pos = 0;
199199 bit_stream_le.bit_count = 0;
200 assert(0b1001010100011101 == try bit_stream_le.readBits(u16, 16, &out_bits));
201 assert(out_bits == 16);
200 expect(0b1001010100011101 == try bit_stream_le.readBits(u16, 16, &out_bits));
201 expect(out_bits == 16);
202202
203203 _ = try bit_stream_le.readBits(u0, 0, &out_bits);
204204
205 assert(0 == try bit_stream_le.readBits(u1, 1, &out_bits));
206 assert(out_bits == 0);
207 assertError(bit_stream_le.readBitsNoEof(u1, 1), error.EndOfStream);
205 expect(0 == try bit_stream_le.readBits(u1, 1, &out_bits));
206 expect(out_bits == 0);
207 expectError(error.EndOfStream, bit_stream_le.readBitsNoEof(u1, 1));
208208}
209209
210210test "BitOutStream" {
......@@ -222,17 +222,17 @@ test "BitOutStream" {
222222 try bit_stream_be.writeBits(u9(5), 5);
223223 try bit_stream_be.writeBits(u1(1), 1);
224224
225 assert(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001011);
225 expect(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001011);
226226
227227 mem_out_be.pos = 0;
228228
229229 try bit_stream_be.writeBits(u15(0b110011010000101), 15);
230230 try bit_stream_be.flushBits();
231 assert(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001010);
231 expect(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001010);
232232
233233 mem_out_be.pos = 0;
234234 try bit_stream_be.writeBits(u32(0b110011010000101), 16);
235 assert(mem_be[0] == 0b01100110 and mem_be[1] == 0b10000101);
235 expect(mem_be[0] == 0b01100110 and mem_be[1] == 0b10000101);
236236
237237 try bit_stream_be.writeBits(u0(0), 0);
238238
......@@ -246,16 +246,16 @@ test "BitOutStream" {
246246 try bit_stream_le.writeBits(u9(5), 5);
247247 try bit_stream_le.writeBits(u1(1), 1);
248248
249 assert(mem_le[0] == 0b00011101 and mem_le[1] == 0b10010101);
249 expect(mem_le[0] == 0b00011101 and mem_le[1] == 0b10010101);
250250
251251 mem_out_le.pos = 0;
252252 try bit_stream_le.writeBits(u15(0b110011010000101), 15);
253253 try bit_stream_le.flushBits();
254 assert(mem_le[0] == 0b10000101 and mem_le[1] == 0b01100110);
254 expect(mem_le[0] == 0b10000101 and mem_le[1] == 0b01100110);
255255
256256 mem_out_le.pos = 0;
257257 try bit_stream_le.writeBits(u32(0b1100110100001011), 16);
258 assert(mem_le[0] == 0b00001011 and mem_le[1] == 0b11001101);
258 expect(mem_le[0] == 0b00001011 and mem_le[1] == 0b11001101);
259259
260260 try bit_stream_le.writeBits(u0(0), 0);
261261}
......@@ -290,20 +290,20 @@ test "BitStreams with File Stream" {
290290
291291 var out_bits: usize = undefined;
292292
293 assert(1 == try bit_stream.readBits(u2, 1, &out_bits));
294 assert(out_bits == 1);
295 assert(2 == try bit_stream.readBits(u5, 2, &out_bits));
296 assert(out_bits == 2);
297 assert(3 == try bit_stream.readBits(u128, 3, &out_bits));
298 assert(out_bits == 3);
299 assert(4 == try bit_stream.readBits(u8, 4, &out_bits));
300 assert(out_bits == 4);
301 assert(5 == try bit_stream.readBits(u9, 5, &out_bits));
302 assert(out_bits == 5);
303 assert(1 == try bit_stream.readBits(u1, 1, &out_bits));
304 assert(out_bits == 1);
293 expect(1 == try bit_stream.readBits(u2, 1, &out_bits));
294 expect(out_bits == 1);
295 expect(2 == try bit_stream.readBits(u5, 2, &out_bits));
296 expect(out_bits == 2);
297 expect(3 == try bit_stream.readBits(u128, 3, &out_bits));
298 expect(out_bits == 3);
299 expect(4 == try bit_stream.readBits(u8, 4, &out_bits));
300 expect(out_bits == 4);
301 expect(5 == try bit_stream.readBits(u9, 5, &out_bits));
302 expect(out_bits == 5);
303 expect(1 == try bit_stream.readBits(u1, 1, &out_bits));
304 expect(out_bits == 1);
305305
306 assertError(bit_stream.readBitsNoEof(u1, 1), error.EndOfStream);
306 expectError(error.EndOfStream, bit_stream.readBitsNoEof(u1, 1));
307307 }
308308 try os.deleteFile(tmp_file_name);
309309}
......@@ -345,8 +345,8 @@ fn testIntSerializerDeserializer(comptime endian: builtin.Endian, comptime is_pa
345345 const S = @IntType(true, i);
346346 const x = try deserializer.deserializeInt(U);
347347 const y = try deserializer.deserializeInt(S);
348 assert(x == U(i));
349 if (i != 0) assert(y == S(-1)) else assert(y == 0);
348 expect(x == U(i));
349 if (i != 0) expect(y == S(-1)) else expect(y == 0);
350350 }
351351
352352 const u8_bit_count = comptime meta.bitCount(u8);
......@@ -356,7 +356,7 @@ fn testIntSerializerDeserializer(comptime endian: builtin.Endian, comptime is_pa
356356 const extra_packed_byte = @boolToInt(total_bits % u8_bit_count > 0);
357357 const total_packed_bytes = (total_bits / u8_bit_count) + extra_packed_byte;
358358
359 assert(in.pos == if (is_packed) total_packed_bytes else total_bytes);
359 expect(in.pos == if (is_packed) total_packed_bytes else total_bytes);
360360
361361 //Verify that empty error set works with serializer.
362362 //deserializer is covered by SliceInStream
......@@ -408,14 +408,14 @@ fn testIntSerializerDeserializerInfNaN(comptime endian: builtin.Endian,
408408 const inf_check_f64 = try deserializer.deserialize(f64);
409409 //const nan_check_f128 = try deserializer.deserialize(f128);
410410 //const inf_check_f128 = try deserializer.deserialize(f128);
411 assert(std.math.isNan(nan_check_f16));
412 assert(std.math.isInf(inf_check_f16));
413 assert(std.math.isNan(nan_check_f32));
414 assert(std.math.isInf(inf_check_f32));
415 assert(std.math.isNan(nan_check_f64));
416 assert(std.math.isInf(inf_check_f64));
417 //assert(std.math.isNan(nan_check_f128));
418 //assert(std.math.isInf(inf_check_f128));
411 expect(std.math.isNan(nan_check_f16));
412 expect(std.math.isInf(inf_check_f16));
413 expect(std.math.isNan(nan_check_f32));
414 expect(std.math.isInf(inf_check_f32));
415 expect(std.math.isNan(nan_check_f64));
416 expect(std.math.isInf(inf_check_f64));
417 //expect(std.math.isNan(nan_check_f128));
418 //expect(std.math.isInf(inf_check_f128));
419419}
420420
421421test "Serializer/Deserializer Int: Inf/NaN" {
......@@ -528,7 +528,7 @@ fn testSerializerDeserializer(comptime endian: builtin.Endian, comptime is_packe
528528 try serializer.serialize(my_inst);
529529
530530 const my_copy = try deserializer.deserialize(MyStruct);
531 assert(meta.eql(my_copy, my_inst));
531 expect(meta.eql(my_copy, my_inst));
532532}
533533
534534test "Serializer/Deserializer generic" {
......@@ -565,11 +565,11 @@ fn testBadData(comptime endian: builtin.Endian, comptime is_packed: bool) !void
565565 var deserializer = io.Deserializer(endian, is_packed, InError).init(in_stream);
566566
567567 try serializer.serialize(u14(3));
568 assertError(deserializer.deserialize(A), error.InvalidEnumTag);
568 expectError(error.InvalidEnumTag, deserializer.deserialize(A));
569569 out.pos = 0;
570570 try serializer.serialize(u14(3));
571571 try serializer.serialize(u14(88));
572 assertError(deserializer.deserialize(C), error.InvalidEnumTag);
572 expectError(error.InvalidEnumTag, deserializer.deserialize(C));
573573}
574574
575575test "Deserializer bad data" {
std/json.zig+9-8
......@@ -4,6 +4,7 @@
44
55const std = @import("index.zig");
66const debug = std.debug;
7const testing = std.testing;
78const mem = std.mem;
89const maxInt = std.math.maxInt;
910
......@@ -960,7 +961,7 @@ test "json.token" {
960961 checkNext(&p, Token.Id.ObjectEnd);
961962 checkNext(&p, Token.Id.ObjectEnd);
962963
963 debug.assert((try p.next()) == null);
964 testing.expect((try p.next()) == null);
964965}
965966
966967// Validate a JSON string. This does not limit number precision so a decoder may not necessarily
......@@ -981,7 +982,7 @@ pub fn validate(s: []const u8) bool {
981982}
982983
983984test "json.validate" {
984 debug.assert(validate("{}"));
985 testing.expect(validate("{}"));
985986}
986987
987988const Allocator = std.mem.Allocator;
......@@ -1378,20 +1379,20 @@ test "json.parser.dynamic" {
13781379 var image = root.Object.get("Image").?.value;
13791380
13801381 const width = image.Object.get("Width").?.value;
1381 debug.assert(width.Integer == 800);
1382 testing.expect(width.Integer == 800);
13821383
13831384 const height = image.Object.get("Height").?.value;
1384 debug.assert(height.Integer == 600);
1385 testing.expect(height.Integer == 600);
13851386
13861387 const title = image.Object.get("Title").?.value;
1387 debug.assert(mem.eql(u8, title.String, "View from 15th Floor"));
1388 testing.expect(mem.eql(u8, title.String, "View from 15th Floor"));
13881389
13891390 const animated = image.Object.get("Animated").?.value;
1390 debug.assert(animated.Bool == false);
1391 testing.expect(animated.Bool == false);
13911392
13921393 const array_of_object = image.Object.get("ArrayOfObject").?.value;
1393 debug.assert(array_of_object.Array.len == 1);
1394 testing.expect(array_of_object.Array.len == 1);
13941395
13951396 const obj0 = array_of_object.Array.at(0).Object.get("n").?.value;
1396 debug.assert(mem.eql(u8, obj0.String, "m"));
1397 testing.expect(mem.eql(u8, obj0.String, "m"));
13971398}
std/json_test.zig+3-3
......@@ -6,15 +6,15 @@
66const std = @import("index.zig");
77
88fn ok(comptime s: []const u8) void {
9 std.debug.assert(std.json.validate(s));
9 std.testing.expect(std.json.validate(s));
1010}
1111
1212fn err(comptime s: []const u8) void {
13 std.debug.assert(!std.json.validate(s));
13 std.testing.expect(!std.json.validate(s));
1414}
1515
1616fn any(comptime s: []const u8) void {
17 std.debug.assert(true);
17 std.testing.expect(true);
1818}
1919
2020////////////////////////////////////////////////////////////////////////////////////////////////////
std/lazy_init.zig+5-4
......@@ -1,6 +1,7 @@
11const std = @import("index.zig");
22const builtin = @import("builtin");
33const assert = std.debug.assert;
4const testing = std.testing;
45const AtomicRmwOp = builtin.AtomicRmwOp;
56const AtomicOrder = builtin.AtomicOrder;
67
......@@ -63,12 +64,12 @@ test "std.lazyInit" {
6364 global_number.resolve();
6465 }
6566 if (global_number.get()) |x| {
66 assert(x.* == 1234);
67 testing.expect(x.* == 1234);
6768 } else {
6869 @panic("bad");
6970 }
7071 if (global_number.get()) |x| {
71 assert(x.* == 1234);
72 testing.expect(x.* == 1234);
7273 } else {
7374 @panic("bad");
7475 }
......@@ -80,6 +81,6 @@ test "std.lazyInit(void)" {
8081 if (global_void.get()) |_| @panic("bad") else {
8182 global_void.resolve();
8283 }
83 assert(global_void.get() != null);
84 assert(global_void.get() != null);
84 testing.expect(global_void.get() != null);
85 testing.expect(global_void.get() != null);
8586}
std/linked_list.zig+15-14
......@@ -1,6 +1,7 @@
11const std = @import("index.zig");
22const debug = std.debug;
33const assert = debug.assert;
4const testing = std.testing;
45const mem = std.mem;
56const Allocator = mem.Allocator;
67
......@@ -246,7 +247,7 @@ test "basic linked list test" {
246247 var it = list.first;
247248 var index: u32 = 1;
248249 while (it) |node| : (it = node.next) {
249 assert(node.data == index);
250 testing.expect(node.data == index);
250251 index += 1;
251252 }
252253 }
......@@ -256,7 +257,7 @@ test "basic linked list test" {
256257 var it = list.last;
257258 var index: u32 = 1;
258259 while (it) |node| : (it = node.prev) {
259 assert(node.data == (6 - index));
260 testing.expect(node.data == (6 - index));
260261 index += 1;
261262 }
262263 }
......@@ -265,9 +266,9 @@ test "basic linked list test" {
265266 var last = list.pop(); // {2, 3, 4}
266267 list.remove(three); // {2, 4}
267268
268 assert(list.first.?.data == 2);
269 assert(list.last.?.data == 4);
270 assert(list.len == 2);
269 testing.expect(list.first.?.data == 2);
270 testing.expect(list.last.?.data == 4);
271 testing.expect(list.len == 2);
271272}
272273
273274test "linked list concatenation" {
......@@ -294,18 +295,18 @@ test "linked list concatenation" {
294295
295296 list1.concatByMoving(&list2);
296297
297 assert(list1.last == five);
298 assert(list1.len == 5);
299 assert(list2.first == null);
300 assert(list2.last == null);
301 assert(list2.len == 0);
298 testing.expect(list1.last == five);
299 testing.expect(list1.len == 5);
300 testing.expect(list2.first == null);
301 testing.expect(list2.last == null);
302 testing.expect(list2.len == 0);
302303
303304 // Traverse forwards.
304305 {
305306 var it = list1.first;
306307 var index: u32 = 1;
307308 while (it) |node| : (it = node.next) {
308 assert(node.data == index);
309 testing.expect(node.data == index);
309310 index += 1;
310311 }
311312 }
......@@ -315,7 +316,7 @@ test "linked list concatenation" {
315316 var it = list1.last;
316317 var index: u32 = 1;
317318 while (it) |node| : (it = node.prev) {
318 assert(node.data == (6 - index));
319 testing.expect(node.data == (6 - index));
319320 index += 1;
320321 }
321322 }
......@@ -328,7 +329,7 @@ test "linked list concatenation" {
328329 var it = list2.first;
329330 var index: u32 = 1;
330331 while (it) |node| : (it = node.next) {
331 assert(node.data == index);
332 testing.expect(node.data == index);
332333 index += 1;
333334 }
334335 }
......@@ -338,7 +339,7 @@ test "linked list concatenation" {
338339 var it = list2.last;
339340 var index: u32 = 1;
340341 while (it) |node| : (it = node.prev) {
341 assert(node.data == (6 - index));
342 testing.expect(node.data == (6 - index));
342343 index += 1;
343344 }
344345 }
std/math/acos.zig+19-19
......@@ -4,7 +4,7 @@
44
55const std = @import("../index.zig");
66const math = std.math;
7const assert = std.debug.assert;
7const expect = std.testing.expect;
88
99pub fn acos(x: var) @typeOf(x) {
1010 const T = @typeOf(x);
......@@ -143,38 +143,38 @@ fn acos64(x: f64) f64 {
143143}
144144
145145test "math.acos" {
146 assert(acos(f32(0.0)) == acos32(0.0));
147 assert(acos(f64(0.0)) == acos64(0.0));
146 expect(acos(f32(0.0)) == acos32(0.0));
147 expect(acos(f64(0.0)) == acos64(0.0));
148148}
149149
150150test "math.acos32" {
151151 const epsilon = 0.000001;
152152
153 assert(math.approxEq(f32, acos32(0.0), 1.570796, epsilon));
154 assert(math.approxEq(f32, acos32(0.2), 1.369438, epsilon));
155 assert(math.approxEq(f32, acos32(0.3434), 1.220262, epsilon));
156 assert(math.approxEq(f32, acos32(0.5), 1.047198, epsilon));
157 assert(math.approxEq(f32, acos32(0.8923), 0.468382, epsilon));
158 assert(math.approxEq(f32, acos32(-0.2), 1.772154, epsilon));
153 expect(math.approxEq(f32, acos32(0.0), 1.570796, epsilon));
154 expect(math.approxEq(f32, acos32(0.2), 1.369438, epsilon));
155 expect(math.approxEq(f32, acos32(0.3434), 1.220262, epsilon));
156 expect(math.approxEq(f32, acos32(0.5), 1.047198, epsilon));
157 expect(math.approxEq(f32, acos32(0.8923), 0.468382, epsilon));
158 expect(math.approxEq(f32, acos32(-0.2), 1.772154, epsilon));
159159}
160160
161161test "math.acos64" {
162162 const epsilon = 0.000001;
163163
164 assert(math.approxEq(f64, acos64(0.0), 1.570796, epsilon));
165 assert(math.approxEq(f64, acos64(0.2), 1.369438, epsilon));
166 assert(math.approxEq(f64, acos64(0.3434), 1.220262, epsilon));
167 assert(math.approxEq(f64, acos64(0.5), 1.047198, epsilon));
168 assert(math.approxEq(f64, acos64(0.8923), 0.468382, epsilon));
169 assert(math.approxEq(f64, acos64(-0.2), 1.772154, epsilon));
164 expect(math.approxEq(f64, acos64(0.0), 1.570796, epsilon));
165 expect(math.approxEq(f64, acos64(0.2), 1.369438, epsilon));
166 expect(math.approxEq(f64, acos64(0.3434), 1.220262, epsilon));
167 expect(math.approxEq(f64, acos64(0.5), 1.047198, epsilon));
168 expect(math.approxEq(f64, acos64(0.8923), 0.468382, epsilon));
169 expect(math.approxEq(f64, acos64(-0.2), 1.772154, epsilon));
170170}
171171
172172test "math.acos32.special" {
173 assert(math.isNan(acos32(-2)));
174 assert(math.isNan(acos32(1.5)));
173 expect(math.isNan(acos32(-2)));
174 expect(math.isNan(acos32(1.5)));
175175}
176176
177177test "math.acos64.special" {
178 assert(math.isNan(acos64(-2)));
179 assert(math.isNan(acos64(1.5)));
178 expect(math.isNan(acos64(-2)));
179 expect(math.isNan(acos64(1.5)));
180180}
std/math/acosh.zig+15-15
......@@ -6,7 +6,7 @@
66const builtin = @import("builtin");
77const std = @import("../index.zig");
88const math = std.math;
9const assert = std.debug.assert;
9const expect = std.testing.expect;
1010
1111pub fn acosh(x: var) @typeOf(x) {
1212 const T = @typeOf(x);
......@@ -55,34 +55,34 @@ fn acosh64(x: f64) f64 {
5555}
5656
5757test "math.acosh" {
58 assert(acosh(f32(1.5)) == acosh32(1.5));
59 assert(acosh(f64(1.5)) == acosh64(1.5));
58 expect(acosh(f32(1.5)) == acosh32(1.5));
59 expect(acosh(f64(1.5)) == acosh64(1.5));
6060}
6161
6262test "math.acosh32" {
6363 const epsilon = 0.000001;
6464
65 assert(math.approxEq(f32, acosh32(1.5), 0.962424, epsilon));
66 assert(math.approxEq(f32, acosh32(37.45), 4.315976, epsilon));
67 assert(math.approxEq(f32, acosh32(89.123), 5.183133, epsilon));
68 assert(math.approxEq(f32, acosh32(123123.234375), 12.414088, epsilon));
65 expect(math.approxEq(f32, acosh32(1.5), 0.962424, epsilon));
66 expect(math.approxEq(f32, acosh32(37.45), 4.315976, epsilon));
67 expect(math.approxEq(f32, acosh32(89.123), 5.183133, epsilon));
68 expect(math.approxEq(f32, acosh32(123123.234375), 12.414088, epsilon));
6969}
7070
7171test "math.acosh64" {
7272 const epsilon = 0.000001;
7373
74 assert(math.approxEq(f64, acosh64(1.5), 0.962424, epsilon));
75 assert(math.approxEq(f64, acosh64(37.45), 4.315976, epsilon));
76 assert(math.approxEq(f64, acosh64(89.123), 5.183133, epsilon));
77 assert(math.approxEq(f64, acosh64(123123.234375), 12.414088, epsilon));
74 expect(math.approxEq(f64, acosh64(1.5), 0.962424, epsilon));
75 expect(math.approxEq(f64, acosh64(37.45), 4.315976, epsilon));
76 expect(math.approxEq(f64, acosh64(89.123), 5.183133, epsilon));
77 expect(math.approxEq(f64, acosh64(123123.234375), 12.414088, epsilon));
7878}
7979
8080test "math.acosh32.special" {
81 assert(math.isNan(acosh32(math.nan(f32))));
82 assert(math.isSignalNan(acosh32(0.5)));
81 expect(math.isNan(acosh32(math.nan(f32))));
82 expect(math.isSignalNan(acosh32(0.5)));
8383}
8484
8585test "math.acosh64.special" {
86 assert(math.isNan(acosh64(math.nan(f64))));
87 assert(math.isSignalNan(acosh64(0.5)));
86 expect(math.isNan(acosh64(math.nan(f64))));
87 expect(math.isSignalNan(acosh64(0.5)));
8888}
std/math/asin.zig+23-23
......@@ -5,7 +5,7 @@
55
66const std = @import("../index.zig");
77const math = std.math;
8const assert = std.debug.assert;
8const expect = std.testing.expect;
99
1010pub fn asin(x: var) @typeOf(x) {
1111 const T = @typeOf(x);
......@@ -136,42 +136,42 @@ fn asin64(x: f64) f64 {
136136}
137137
138138test "math.asin" {
139 assert(asin(f32(0.0)) == asin32(0.0));
140 assert(asin(f64(0.0)) == asin64(0.0));
139 expect(asin(f32(0.0)) == asin32(0.0));
140 expect(asin(f64(0.0)) == asin64(0.0));
141141}
142142
143143test "math.asin32" {
144144 const epsilon = 0.000001;
145145
146 assert(math.approxEq(f32, asin32(0.0), 0.0, epsilon));
147 assert(math.approxEq(f32, asin32(0.2), 0.201358, epsilon));
148 assert(math.approxEq(f32, asin32(-0.2), -0.201358, epsilon));
149 assert(math.approxEq(f32, asin32(0.3434), 0.350535, epsilon));
150 assert(math.approxEq(f32, asin32(0.5), 0.523599, epsilon));
151 assert(math.approxEq(f32, asin32(0.8923), 1.102415, epsilon));
146 expect(math.approxEq(f32, asin32(0.0), 0.0, epsilon));
147 expect(math.approxEq(f32, asin32(0.2), 0.201358, epsilon));
148 expect(math.approxEq(f32, asin32(-0.2), -0.201358, epsilon));
149 expect(math.approxEq(f32, asin32(0.3434), 0.350535, epsilon));
150 expect(math.approxEq(f32, asin32(0.5), 0.523599, epsilon));
151 expect(math.approxEq(f32, asin32(0.8923), 1.102415, epsilon));
152152}
153153
154154test "math.asin64" {
155155 const epsilon = 0.000001;
156156
157 assert(math.approxEq(f64, asin64(0.0), 0.0, epsilon));
158 assert(math.approxEq(f64, asin64(0.2), 0.201358, epsilon));
159 assert(math.approxEq(f64, asin64(-0.2), -0.201358, epsilon));
160 assert(math.approxEq(f64, asin64(0.3434), 0.350535, epsilon));
161 assert(math.approxEq(f64, asin64(0.5), 0.523599, epsilon));
162 assert(math.approxEq(f64, asin64(0.8923), 1.102415, epsilon));
157 expect(math.approxEq(f64, asin64(0.0), 0.0, epsilon));
158 expect(math.approxEq(f64, asin64(0.2), 0.201358, epsilon));
159 expect(math.approxEq(f64, asin64(-0.2), -0.201358, epsilon));
160 expect(math.approxEq(f64, asin64(0.3434), 0.350535, epsilon));
161 expect(math.approxEq(f64, asin64(0.5), 0.523599, epsilon));
162 expect(math.approxEq(f64, asin64(0.8923), 1.102415, epsilon));
163163}
164164
165165test "math.asin32.special" {
166 assert(asin32(0.0) == 0.0);
167 assert(asin32(-0.0) == -0.0);
168 assert(math.isNan(asin32(-2)));
169 assert(math.isNan(asin32(1.5)));
166 expect(asin32(0.0) == 0.0);
167 expect(asin32(-0.0) == -0.0);
168 expect(math.isNan(asin32(-2)));
169 expect(math.isNan(asin32(1.5)));
170170}
171171
172172test "math.asin64.special" {
173 assert(asin64(0.0) == 0.0);
174 assert(asin64(-0.0) == -0.0);
175 assert(math.isNan(asin64(-2)));
176 assert(math.isNan(asin64(1.5)));
173 expect(asin64(0.0) == 0.0);
174 expect(asin64(-0.0) == -0.0);
175 expect(math.isNan(asin64(-2)));
176 expect(math.isNan(asin64(1.5)));
177177}
std/math/asinh.zig+27-27
......@@ -6,7 +6,7 @@
66
77const std = @import("../index.zig");
88const math = std.math;
9const assert = std.debug.assert;
9const expect = std.testing.expect;
1010const maxInt = std.math.maxInt;
1111
1212pub fn asinh(x: var) @typeOf(x) {
......@@ -83,46 +83,46 @@ fn asinh64(x: f64) f64 {
8383}
8484
8585test "math.asinh" {
86 assert(asinh(f32(0.0)) == asinh32(0.0));
87 assert(asinh(f64(0.0)) == asinh64(0.0));
86 expect(asinh(f32(0.0)) == asinh32(0.0));
87 expect(asinh(f64(0.0)) == asinh64(0.0));
8888}
8989
9090test "math.asinh32" {
9191 const epsilon = 0.000001;
9292
93 assert(math.approxEq(f32, asinh32(0.0), 0.0, epsilon));
94 assert(math.approxEq(f32, asinh32(0.2), 0.198690, epsilon));
95 assert(math.approxEq(f32, asinh32(0.8923), 0.803133, epsilon));
96 assert(math.approxEq(f32, asinh32(1.5), 1.194763, epsilon));
97 assert(math.approxEq(f32, asinh32(37.45), 4.316332, epsilon));
98 assert(math.approxEq(f32, asinh32(89.123), 5.183196, epsilon));
99 assert(math.approxEq(f32, asinh32(123123.234375), 12.414088, epsilon));
93 expect(math.approxEq(f32, asinh32(0.0), 0.0, epsilon));
94 expect(math.approxEq(f32, asinh32(0.2), 0.198690, epsilon));
95 expect(math.approxEq(f32, asinh32(0.8923), 0.803133, epsilon));
96 expect(math.approxEq(f32, asinh32(1.5), 1.194763, epsilon));
97 expect(math.approxEq(f32, asinh32(37.45), 4.316332, epsilon));
98 expect(math.approxEq(f32, asinh32(89.123), 5.183196, epsilon));
99 expect(math.approxEq(f32, asinh32(123123.234375), 12.414088, epsilon));
100100}
101101
102102test "math.asinh64" {
103103 const epsilon = 0.000001;
104104
105 assert(math.approxEq(f64, asinh64(0.0), 0.0, epsilon));
106 assert(math.approxEq(f64, asinh64(0.2), 0.198690, epsilon));
107 assert(math.approxEq(f64, asinh64(0.8923), 0.803133, epsilon));
108 assert(math.approxEq(f64, asinh64(1.5), 1.194763, epsilon));
109 assert(math.approxEq(f64, asinh64(37.45), 4.316332, epsilon));
110 assert(math.approxEq(f64, asinh64(89.123), 5.183196, epsilon));
111 assert(math.approxEq(f64, asinh64(123123.234375), 12.414088, epsilon));
105 expect(math.approxEq(f64, asinh64(0.0), 0.0, epsilon));
106 expect(math.approxEq(f64, asinh64(0.2), 0.198690, epsilon));
107 expect(math.approxEq(f64, asinh64(0.8923), 0.803133, epsilon));
108 expect(math.approxEq(f64, asinh64(1.5), 1.194763, epsilon));
109 expect(math.approxEq(f64, asinh64(37.45), 4.316332, epsilon));
110 expect(math.approxEq(f64, asinh64(89.123), 5.183196, epsilon));
111 expect(math.approxEq(f64, asinh64(123123.234375), 12.414088, epsilon));
112112}
113113
114114test "math.asinh32.special" {
115 assert(asinh32(0.0) == 0.0);
116 assert(asinh32(-0.0) == -0.0);
117 assert(math.isPositiveInf(asinh32(math.inf(f32))));
118 assert(math.isNegativeInf(asinh32(-math.inf(f32))));
119 assert(math.isNan(asinh32(math.nan(f32))));
115 expect(asinh32(0.0) == 0.0);
116 expect(asinh32(-0.0) == -0.0);
117 expect(math.isPositiveInf(asinh32(math.inf(f32))));
118 expect(math.isNegativeInf(asinh32(-math.inf(f32))));
119 expect(math.isNan(asinh32(math.nan(f32))));
120120}
121121
122122test "math.asinh64.special" {
123 assert(asinh64(0.0) == 0.0);
124 assert(asinh64(-0.0) == -0.0);
125 assert(math.isPositiveInf(asinh64(math.inf(f64))));
126 assert(math.isNegativeInf(asinh64(-math.inf(f64))));
127 assert(math.isNan(asinh64(math.nan(f64))));
123 expect(asinh64(0.0) == 0.0);
124 expect(asinh64(-0.0) == -0.0);
125 expect(math.isPositiveInf(asinh64(math.inf(f64))));
126 expect(math.isNegativeInf(asinh64(-math.inf(f64))));
127 expect(math.isNan(asinh64(math.nan(f64))));
128128}
std/math/atan.zig+21-21
......@@ -5,7 +5,7 @@
55
66const std = @import("../index.zig");
77const math = std.math;
8const assert = std.debug.assert;
8const expect = std.testing.expect;
99
1010pub fn atan(x: var) @typeOf(x) {
1111 const T = @typeOf(x);
......@@ -206,44 +206,44 @@ fn atan64(x_: f64) f64 {
206206}
207207
208208test "math.atan" {
209 assert(@bitCast(u32, atan(f32(0.2))) == @bitCast(u32, atan32(0.2)));
210 assert(atan(f64(0.2)) == atan64(0.2));
209 expect(@bitCast(u32, atan(f32(0.2))) == @bitCast(u32, atan32(0.2)));
210 expect(atan(f64(0.2)) == atan64(0.2));
211211}
212212
213213test "math.atan32" {
214214 const epsilon = 0.000001;
215215
216 assert(math.approxEq(f32, atan32(0.2), 0.197396, epsilon));
217 assert(math.approxEq(f32, atan32(-0.2), -0.197396, epsilon));
218 assert(math.approxEq(f32, atan32(0.3434), 0.330783, epsilon));
219 assert(math.approxEq(f32, atan32(0.8923), 0.728545, epsilon));
220 assert(math.approxEq(f32, atan32(1.5), 0.982794, epsilon));
216 expect(math.approxEq(f32, atan32(0.2), 0.197396, epsilon));
217 expect(math.approxEq(f32, atan32(-0.2), -0.197396, epsilon));
218 expect(math.approxEq(f32, atan32(0.3434), 0.330783, epsilon));
219 expect(math.approxEq(f32, atan32(0.8923), 0.728545, epsilon));
220 expect(math.approxEq(f32, atan32(1.5), 0.982794, epsilon));
221221}
222222
223223test "math.atan64" {
224224 const epsilon = 0.000001;
225225
226 assert(math.approxEq(f64, atan64(0.2), 0.197396, epsilon));
227 assert(math.approxEq(f64, atan64(-0.2), -0.197396, epsilon));
228 assert(math.approxEq(f64, atan64(0.3434), 0.330783, epsilon));
229 assert(math.approxEq(f64, atan64(0.8923), 0.728545, epsilon));
230 assert(math.approxEq(f64, atan64(1.5), 0.982794, epsilon));
226 expect(math.approxEq(f64, atan64(0.2), 0.197396, epsilon));
227 expect(math.approxEq(f64, atan64(-0.2), -0.197396, epsilon));
228 expect(math.approxEq(f64, atan64(0.3434), 0.330783, epsilon));
229 expect(math.approxEq(f64, atan64(0.8923), 0.728545, epsilon));
230 expect(math.approxEq(f64, atan64(1.5), 0.982794, epsilon));
231231}
232232
233233test "math.atan32.special" {
234234 const epsilon = 0.000001;
235235
236 assert(atan32(0.0) == 0.0);
237 assert(atan32(-0.0) == -0.0);
238 assert(math.approxEq(f32, atan32(math.inf(f32)), math.pi / 2.0, epsilon));
239 assert(math.approxEq(f32, atan32(-math.inf(f32)), -math.pi / 2.0, epsilon));
236 expect(atan32(0.0) == 0.0);
237 expect(atan32(-0.0) == -0.0);
238 expect(math.approxEq(f32, atan32(math.inf(f32)), math.pi / 2.0, epsilon));
239 expect(math.approxEq(f32, atan32(-math.inf(f32)), -math.pi / 2.0, epsilon));
240240}
241241
242242test "math.atan64.special" {
243243 const epsilon = 0.000001;
244244
245 assert(atan64(0.0) == 0.0);
246 assert(atan64(-0.0) == -0.0);
247 assert(math.approxEq(f64, atan64(math.inf(f64)), math.pi / 2.0, epsilon));
248 assert(math.approxEq(f64, atan64(-math.inf(f64)), -math.pi / 2.0, epsilon));
245 expect(atan64(0.0) == 0.0);
246 expect(atan64(-0.0) == -0.0);
247 expect(math.approxEq(f64, atan64(math.inf(f64)), math.pi / 2.0, epsilon));
248 expect(math.approxEq(f64, atan64(-math.inf(f64)), -math.pi / 2.0, epsilon));
249249}
std/math/atan2.zig+55-55
......@@ -20,7 +20,7 @@
2020
2121const std = @import("../index.zig");
2222const math = std.math;
23const assert = std.debug.assert;
23const expect = std.testing.expect;
2424
2525pub fn atan2(comptime T: type, y: T, x: T) T {
2626 return switch (T) {
......@@ -206,78 +206,78 @@ fn atan2_64(y: f64, x: f64) f64 {
206206}
207207
208208test "math.atan2" {
209 assert(atan2(f32, 0.2, 0.21) == atan2_32(0.2, 0.21));
210 assert(atan2(f64, 0.2, 0.21) == atan2_64(0.2, 0.21));
209 expect(atan2(f32, 0.2, 0.21) == atan2_32(0.2, 0.21));
210 expect(atan2(f64, 0.2, 0.21) == atan2_64(0.2, 0.21));
211211}
212212
213213test "math.atan2_32" {
214214 const epsilon = 0.000001;
215215
216 assert(math.approxEq(f32, atan2_32(0.0, 0.0), 0.0, epsilon));
217 assert(math.approxEq(f32, atan2_32(0.2, 0.2), 0.785398, epsilon));
218 assert(math.approxEq(f32, atan2_32(-0.2, 0.2), -0.785398, epsilon));
219 assert(math.approxEq(f32, atan2_32(0.2, -0.2), 2.356194, epsilon));
220 assert(math.approxEq(f32, atan2_32(-0.2, -0.2), -2.356194, epsilon));
221 assert(math.approxEq(f32, atan2_32(0.34, -0.4), 2.437099, epsilon));
222 assert(math.approxEq(f32, atan2_32(0.34, 1.243), 0.267001, epsilon));
216 expect(math.approxEq(f32, atan2_32(0.0, 0.0), 0.0, epsilon));
217 expect(math.approxEq(f32, atan2_32(0.2, 0.2), 0.785398, epsilon));
218 expect(math.approxEq(f32, atan2_32(-0.2, 0.2), -0.785398, epsilon));
219 expect(math.approxEq(f32, atan2_32(0.2, -0.2), 2.356194, epsilon));
220 expect(math.approxEq(f32, atan2_32(-0.2, -0.2), -2.356194, epsilon));
221 expect(math.approxEq(f32, atan2_32(0.34, -0.4), 2.437099, epsilon));
222 expect(math.approxEq(f32, atan2_32(0.34, 1.243), 0.267001, epsilon));
223223}
224224
225225test "math.atan2_64" {
226226 const epsilon = 0.000001;
227227
228 assert(math.approxEq(f64, atan2_64(0.0, 0.0), 0.0, epsilon));
229 assert(math.approxEq(f64, atan2_64(0.2, 0.2), 0.785398, epsilon));
230 assert(math.approxEq(f64, atan2_64(-0.2, 0.2), -0.785398, epsilon));
231 assert(math.approxEq(f64, atan2_64(0.2, -0.2), 2.356194, epsilon));
232 assert(math.approxEq(f64, atan2_64(-0.2, -0.2), -2.356194, epsilon));
233 assert(math.approxEq(f64, atan2_64(0.34, -0.4), 2.437099, epsilon));
234 assert(math.approxEq(f64, atan2_64(0.34, 1.243), 0.267001, epsilon));
228 expect(math.approxEq(f64, atan2_64(0.0, 0.0), 0.0, epsilon));
229 expect(math.approxEq(f64, atan2_64(0.2, 0.2), 0.785398, epsilon));
230 expect(math.approxEq(f64, atan2_64(-0.2, 0.2), -0.785398, epsilon));
231 expect(math.approxEq(f64, atan2_64(0.2, -0.2), 2.356194, epsilon));
232 expect(math.approxEq(f64, atan2_64(-0.2, -0.2), -2.356194, epsilon));
233 expect(math.approxEq(f64, atan2_64(0.34, -0.4), 2.437099, epsilon));
234 expect(math.approxEq(f64, atan2_64(0.34, 1.243), 0.267001, epsilon));
235235}
236236
237237test "math.atan2_32.special" {
238238 const epsilon = 0.000001;
239239
240 assert(math.isNan(atan2_32(1.0, math.nan(f32))));
241 assert(math.isNan(atan2_32(math.nan(f32), 1.0)));
242 assert(atan2_32(0.0, 5.0) == 0.0);
243 assert(atan2_32(-0.0, 5.0) == -0.0);
244 assert(math.approxEq(f32, atan2_32(0.0, -5.0), math.pi, epsilon));
245 //assert(math.approxEq(f32, atan2_32(-0.0, -5.0), -math.pi, epsilon)); TODO support negative zero?
246 assert(math.approxEq(f32, atan2_32(1.0, 0.0), math.pi / 2.0, epsilon));
247 assert(math.approxEq(f32, atan2_32(1.0, -0.0), math.pi / 2.0, epsilon));
248 assert(math.approxEq(f32, atan2_32(-1.0, 0.0), -math.pi / 2.0, epsilon));
249 assert(math.approxEq(f32, atan2_32(-1.0, -0.0), -math.pi / 2.0, epsilon));
250 assert(math.approxEq(f32, atan2_32(math.inf(f32), math.inf(f32)), math.pi / 4.0, epsilon));
251 assert(math.approxEq(f32, atan2_32(-math.inf(f32), math.inf(f32)), -math.pi / 4.0, epsilon));
252 assert(math.approxEq(f32, atan2_32(math.inf(f32), -math.inf(f32)), 3.0 * math.pi / 4.0, epsilon));
253 assert(math.approxEq(f32, atan2_32(-math.inf(f32), -math.inf(f32)), -3.0 * math.pi / 4.0, epsilon));
254 assert(atan2_32(1.0, math.inf(f32)) == 0.0);
255 assert(math.approxEq(f32, atan2_32(1.0, -math.inf(f32)), math.pi, epsilon));
256 assert(math.approxEq(f32, atan2_32(-1.0, -math.inf(f32)), -math.pi, epsilon));
257 assert(math.approxEq(f32, atan2_32(math.inf(f32), 1.0), math.pi / 2.0, epsilon));
258 assert(math.approxEq(f32, atan2_32(-math.inf(f32), 1.0), -math.pi / 2.0, epsilon));
240 expect(math.isNan(atan2_32(1.0, math.nan(f32))));
241 expect(math.isNan(atan2_32(math.nan(f32), 1.0)));
242 expect(atan2_32(0.0, 5.0) == 0.0);
243 expect(atan2_32(-0.0, 5.0) == -0.0);
244 expect(math.approxEq(f32, atan2_32(0.0, -5.0), math.pi, epsilon));
245 //expect(math.approxEq(f32, atan2_32(-0.0, -5.0), -math.pi, epsilon)); TODO support negative zero?
246 expect(math.approxEq(f32, atan2_32(1.0, 0.0), math.pi / 2.0, epsilon));
247 expect(math.approxEq(f32, atan2_32(1.0, -0.0), math.pi / 2.0, epsilon));
248 expect(math.approxEq(f32, atan2_32(-1.0, 0.0), -math.pi / 2.0, epsilon));
249 expect(math.approxEq(f32, atan2_32(-1.0, -0.0), -math.pi / 2.0, epsilon));
250 expect(math.approxEq(f32, atan2_32(math.inf(f32), math.inf(f32)), math.pi / 4.0, epsilon));
251 expect(math.approxEq(f32, atan2_32(-math.inf(f32), math.inf(f32)), -math.pi / 4.0, epsilon));
252 expect(math.approxEq(f32, atan2_32(math.inf(f32), -math.inf(f32)), 3.0 * math.pi / 4.0, epsilon));
253 expect(math.approxEq(f32, atan2_32(-math.inf(f32), -math.inf(f32)), -3.0 * math.pi / 4.0, epsilon));
254 expect(atan2_32(1.0, math.inf(f32)) == 0.0);
255 expect(math.approxEq(f32, atan2_32(1.0, -math.inf(f32)), math.pi, epsilon));
256 expect(math.approxEq(f32, atan2_32(-1.0, -math.inf(f32)), -math.pi, epsilon));
257 expect(math.approxEq(f32, atan2_32(math.inf(f32), 1.0), math.pi / 2.0, epsilon));
258 expect(math.approxEq(f32, atan2_32(-math.inf(f32), 1.0), -math.pi / 2.0, epsilon));
259259}
260260
261261test "math.atan2_64.special" {
262262 const epsilon = 0.000001;
263263
264 assert(math.isNan(atan2_64(1.0, math.nan(f64))));
265 assert(math.isNan(atan2_64(math.nan(f64), 1.0)));
266 assert(atan2_64(0.0, 5.0) == 0.0);
267 assert(atan2_64(-0.0, 5.0) == -0.0);
268 assert(math.approxEq(f64, atan2_64(0.0, -5.0), math.pi, epsilon));
269 //assert(math.approxEq(f64, atan2_64(-0.0, -5.0), -math.pi, epsilon)); TODO support negative zero?
270 assert(math.approxEq(f64, atan2_64(1.0, 0.0), math.pi / 2.0, epsilon));
271 assert(math.approxEq(f64, atan2_64(1.0, -0.0), math.pi / 2.0, epsilon));
272 assert(math.approxEq(f64, atan2_64(-1.0, 0.0), -math.pi / 2.0, epsilon));
273 assert(math.approxEq(f64, atan2_64(-1.0, -0.0), -math.pi / 2.0, epsilon));
274 assert(math.approxEq(f64, atan2_64(math.inf(f64), math.inf(f64)), math.pi / 4.0, epsilon));
275 assert(math.approxEq(f64, atan2_64(-math.inf(f64), math.inf(f64)), -math.pi / 4.0, epsilon));
276 assert(math.approxEq(f64, atan2_64(math.inf(f64), -math.inf(f64)), 3.0 * math.pi / 4.0, epsilon));
277 assert(math.approxEq(f64, atan2_64(-math.inf(f64), -math.inf(f64)), -3.0 * math.pi / 4.0, epsilon));
278 assert(atan2_64(1.0, math.inf(f64)) == 0.0);
279 assert(math.approxEq(f64, atan2_64(1.0, -math.inf(f64)), math.pi, epsilon));
280 assert(math.approxEq(f64, atan2_64(-1.0, -math.inf(f64)), -math.pi, epsilon));
281 assert(math.approxEq(f64, atan2_64(math.inf(f64), 1.0), math.pi / 2.0, epsilon));
282 assert(math.approxEq(f64, atan2_64(-math.inf(f64), 1.0), -math.pi / 2.0, epsilon));
264 expect(math.isNan(atan2_64(1.0, math.nan(f64))));
265 expect(math.isNan(atan2_64(math.nan(f64), 1.0)));
266 expect(atan2_64(0.0, 5.0) == 0.0);
267 expect(atan2_64(-0.0, 5.0) == -0.0);
268 expect(math.approxEq(f64, atan2_64(0.0, -5.0), math.pi, epsilon));
269 //expect(math.approxEq(f64, atan2_64(-0.0, -5.0), -math.pi, epsilon)); TODO support negative zero?
270 expect(math.approxEq(f64, atan2_64(1.0, 0.0), math.pi / 2.0, epsilon));
271 expect(math.approxEq(f64, atan2_64(1.0, -0.0), math.pi / 2.0, epsilon));
272 expect(math.approxEq(f64, atan2_64(-1.0, 0.0), -math.pi / 2.0, epsilon));
273 expect(math.approxEq(f64, atan2_64(-1.0, -0.0), -math.pi / 2.0, epsilon));
274 expect(math.approxEq(f64, atan2_64(math.inf(f64), math.inf(f64)), math.pi / 4.0, epsilon));
275 expect(math.approxEq(f64, atan2_64(-math.inf(f64), math.inf(f64)), -math.pi / 4.0, epsilon));
276 expect(math.approxEq(f64, atan2_64(math.inf(f64), -math.inf(f64)), 3.0 * math.pi / 4.0, epsilon));
277 expect(math.approxEq(f64, atan2_64(-math.inf(f64), -math.inf(f64)), -3.0 * math.pi / 4.0, epsilon));
278 expect(atan2_64(1.0, math.inf(f64)) == 0.0);
279 expect(math.approxEq(f64, atan2_64(1.0, -math.inf(f64)), math.pi, epsilon));
280 expect(math.approxEq(f64, atan2_64(-1.0, -math.inf(f64)), -math.pi, epsilon));
281 expect(math.approxEq(f64, atan2_64(math.inf(f64), 1.0), math.pi / 2.0, epsilon));
282 expect(math.approxEq(f64, atan2_64(-math.inf(f64), 1.0), -math.pi / 2.0, epsilon));
283283}
std/math/atanh.zig+19-19
......@@ -6,7 +6,7 @@
66
77const std = @import("../index.zig");
88const math = std.math;
9const assert = std.debug.assert;
9const expect = std.testing.expect;
1010const maxInt = std.math.maxInt;
1111
1212pub fn atanh(x: var) @typeOf(x) {
......@@ -78,38 +78,38 @@ fn atanh_64(x: f64) f64 {
7878}
7979
8080test "math.atanh" {
81 assert(atanh(f32(0.0)) == atanh_32(0.0));
82 assert(atanh(f64(0.0)) == atanh_64(0.0));
81 expect(atanh(f32(0.0)) == atanh_32(0.0));
82 expect(atanh(f64(0.0)) == atanh_64(0.0));
8383}
8484
8585test "math.atanh_32" {
8686 const epsilon = 0.000001;
8787
88 assert(math.approxEq(f32, atanh_32(0.0), 0.0, epsilon));
89 assert(math.approxEq(f32, atanh_32(0.2), 0.202733, epsilon));
90 assert(math.approxEq(f32, atanh_32(0.8923), 1.433099, epsilon));
88 expect(math.approxEq(f32, atanh_32(0.0), 0.0, epsilon));
89 expect(math.approxEq(f32, atanh_32(0.2), 0.202733, epsilon));
90 expect(math.approxEq(f32, atanh_32(0.8923), 1.433099, epsilon));
9191}
9292
9393test "math.atanh_64" {
9494 const epsilon = 0.000001;
9595
96 assert(math.approxEq(f64, atanh_64(0.0), 0.0, epsilon));
97 assert(math.approxEq(f64, atanh_64(0.2), 0.202733, epsilon));
98 assert(math.approxEq(f64, atanh_64(0.8923), 1.433099, epsilon));
96 expect(math.approxEq(f64, atanh_64(0.0), 0.0, epsilon));
97 expect(math.approxEq(f64, atanh_64(0.2), 0.202733, epsilon));
98 expect(math.approxEq(f64, atanh_64(0.8923), 1.433099, epsilon));
9999}
100100
101101test "math.atanh32.special" {
102 assert(math.isPositiveInf(atanh_32(1)));
103 assert(math.isNegativeInf(atanh_32(-1)));
104 assert(math.isSignalNan(atanh_32(1.5)));
105 assert(math.isSignalNan(atanh_32(-1.5)));
106 assert(math.isNan(atanh_32(math.nan(f32))));
102 expect(math.isPositiveInf(atanh_32(1)));
103 expect(math.isNegativeInf(atanh_32(-1)));
104 expect(math.isSignalNan(atanh_32(1.5)));
105 expect(math.isSignalNan(atanh_32(-1.5)));
106 expect(math.isNan(atanh_32(math.nan(f32))));
107107}
108108
109109test "math.atanh64.special" {
110 assert(math.isPositiveInf(atanh_64(1)));
111 assert(math.isNegativeInf(atanh_64(-1)));
112 assert(math.isSignalNan(atanh_64(1.5)));
113 assert(math.isSignalNan(atanh_64(-1.5)));
114 assert(math.isNan(atanh_64(math.nan(f64))));
110 expect(math.isPositiveInf(atanh_64(1)));
111 expect(math.isNegativeInf(atanh_64(-1)));
112 expect(math.isSignalNan(atanh_64(1.5)));
113 expect(math.isSignalNan(atanh_64(-1.5)));
114 expect(math.isNan(atanh_64(math.nan(f64))));
115115}
std/math/big/int.zig+180-187
......@@ -1,6 +1,7 @@
11const std = @import("../../index.zig");
22const builtin = @import("builtin");
33const debug = std.debug;
4const testing = std.testing;
45const math = std.math;
56const mem = std.mem;
67const Allocator = mem.Allocator;
......@@ -1086,44 +1087,40 @@ test "big.int comptime_int set" {
10861087 const result = Limb(s & maxInt(Limb));
10871088 s >>= Limb.bit_count / 2;
10881089 s >>= Limb.bit_count / 2;
1089 debug.assert(a.limbs[i] == result);
1090 testing.expect(a.limbs[i] == result);
10901091 }
10911092}
10921093
10931094test "big.int comptime_int set negative" {
10941095 var a = try Int.initSet(al, -10);
10951096
1096 debug.assert(a.limbs[0] == 10);
1097 debug.assert(a.positive == false);
1097 testing.expect(a.limbs[0] == 10);
1098 testing.expect(a.positive == false);
10981099}
10991100
11001101test "big.int int set unaligned small" {
11011102 var a = try Int.initSet(al, u7(45));
11021103
1103 debug.assert(a.limbs[0] == 45);
1104 debug.assert(a.positive == true);
1104 testing.expect(a.limbs[0] == 45);
1105 testing.expect(a.positive == true);
11051106}
11061107
11071108test "big.int comptime_int to" {
11081109 const a = try Int.initSet(al, 0xefffffff00000001eeeeeeefaaaaaaab);
11091110
1110 debug.assert((try a.to(u128)) == 0xefffffff00000001eeeeeeefaaaaaaab);
1111 testing.expect((try a.to(u128)) == 0xefffffff00000001eeeeeeefaaaaaaab);
11111112}
11121113
11131114test "big.int sub-limb to" {
11141115 const a = try Int.initSet(al, 10);
11151116
1116 debug.assert((try a.to(u8)) == 10);
1117 testing.expect((try a.to(u8)) == 10);
11171118}
11181119
11191120test "big.int to target too small error" {
11201121 const a = try Int.initSet(al, 0xffffffff);
11211122
1122 if (a.to(u8)) |_| {
1123 unreachable;
1124 } else |err| {
1125 debug.assert(err == error.TargetTooSmall);
1126 }
1123 testing.expectError(error.TargetTooSmall, a.to(u8));
11271124}
11281125
11291126test "big.int norm1" {
......@@ -1135,22 +1132,22 @@ test "big.int norm1" {
11351132 a.limbs[2] = 3;
11361133 a.limbs[3] = 0;
11371134 a.norm1(4);
1138 debug.assert(a.len == 3);
1135 testing.expect(a.len == 3);
11391136
11401137 a.limbs[0] = 1;
11411138 a.limbs[1] = 2;
11421139 a.limbs[2] = 3;
11431140 a.norm1(3);
1144 debug.assert(a.len == 3);
1141 testing.expect(a.len == 3);
11451142
11461143 a.limbs[0] = 0;
11471144 a.limbs[1] = 0;
11481145 a.norm1(2);
1149 debug.assert(a.len == 1);
1146 testing.expect(a.len == 1);
11501147
11511148 a.limbs[0] = 0;
11521149 a.norm1(1);
1153 debug.assert(a.len == 1);
1150 testing.expect(a.len == 1);
11541151}
11551152
11561153test "big.int normN" {
......@@ -1162,144 +1159,144 @@ test "big.int normN" {
11621159 a.limbs[2] = 0;
11631160 a.limbs[3] = 0;
11641161 a.normN(4);
1165 debug.assert(a.len == 2);
1162 testing.expect(a.len == 2);
11661163
11671164 a.limbs[0] = 1;
11681165 a.limbs[1] = 2;
11691166 a.limbs[2] = 3;
11701167 a.normN(3);
1171 debug.assert(a.len == 3);
1168 testing.expect(a.len == 3);
11721169
11731170 a.limbs[0] = 0;
11741171 a.limbs[1] = 0;
11751172 a.limbs[2] = 0;
11761173 a.limbs[3] = 0;
11771174 a.normN(4);
1178 debug.assert(a.len == 1);
1175 testing.expect(a.len == 1);
11791176
11801177 a.limbs[0] = 0;
11811178 a.normN(1);
1182 debug.assert(a.len == 1);
1179 testing.expect(a.len == 1);
11831180}
11841181
11851182test "big.int parity" {
11861183 var a = try Int.init(al);
11871184 try a.set(0);
1188 debug.assert(a.isEven());
1189 debug.assert(!a.isOdd());
1185 testing.expect(a.isEven());
1186 testing.expect(!a.isOdd());
11901187
11911188 try a.set(7);
1192 debug.assert(!a.isEven());
1193 debug.assert(a.isOdd());
1189 testing.expect(!a.isEven());
1190 testing.expect(a.isOdd());
11941191}
11951192
11961193test "big.int bitcount + sizeInBase" {
11971194 var a = try Int.init(al);
11981195
11991196 try a.set(0b100);
1200 debug.assert(a.bitCountAbs() == 3);
1201 debug.assert(a.sizeInBase(2) >= 3);
1202 debug.assert(a.sizeInBase(10) >= 1);
1197 testing.expect(a.bitCountAbs() == 3);
1198 testing.expect(a.sizeInBase(2) >= 3);
1199 testing.expect(a.sizeInBase(10) >= 1);
12031200
12041201 a.negate();
1205 debug.assert(a.bitCountAbs() == 3);
1206 debug.assert(a.sizeInBase(2) >= 4);
1207 debug.assert(a.sizeInBase(10) >= 2);
1202 testing.expect(a.bitCountAbs() == 3);
1203 testing.expect(a.sizeInBase(2) >= 4);
1204 testing.expect(a.sizeInBase(10) >= 2);
12081205
12091206 try a.set(0xffffffff);
1210 debug.assert(a.bitCountAbs() == 32);
1211 debug.assert(a.sizeInBase(2) >= 32);
1212 debug.assert(a.sizeInBase(10) >= 10);
1207 testing.expect(a.bitCountAbs() == 32);
1208 testing.expect(a.sizeInBase(2) >= 32);
1209 testing.expect(a.sizeInBase(10) >= 10);
12131210
12141211 try a.shiftLeft(a, 5000);
1215 debug.assert(a.bitCountAbs() == 5032);
1216 debug.assert(a.sizeInBase(2) >= 5032);
1212 testing.expect(a.bitCountAbs() == 5032);
1213 testing.expect(a.sizeInBase(2) >= 5032);
12171214 a.positive = false;
12181215
1219 debug.assert(a.bitCountAbs() == 5032);
1220 debug.assert(a.sizeInBase(2) >= 5033);
1216 testing.expect(a.bitCountAbs() == 5032);
1217 testing.expect(a.sizeInBase(2) >= 5033);
12211218}
12221219
12231220test "big.int bitcount/to" {
12241221 var a = try Int.init(al);
12251222
12261223 try a.set(0);
1227 debug.assert(a.bitCountTwosComp() == 0);
1224 testing.expect(a.bitCountTwosComp() == 0);
12281225
12291226 // TODO: stack smashing
1230 // debug.assert((try a.to(u0)) == 0);
1227 // testing.expect((try a.to(u0)) == 0);
12311228 // TODO: sigsegv
1232 // debug.assert((try a.to(i0)) == 0);
1229 // testing.expect((try a.to(i0)) == 0);
12331230
12341231 try a.set(-1);
1235 debug.assert(a.bitCountTwosComp() == 1);
1236 debug.assert((try a.to(i1)) == -1);
1232 testing.expect(a.bitCountTwosComp() == 1);
1233 testing.expect((try a.to(i1)) == -1);
12371234
12381235 try a.set(-8);
1239 debug.assert(a.bitCountTwosComp() == 4);
1240 debug.assert((try a.to(i4)) == -8);
1236 testing.expect(a.bitCountTwosComp() == 4);
1237 testing.expect((try a.to(i4)) == -8);
12411238
12421239 try a.set(127);
1243 debug.assert(a.bitCountTwosComp() == 7);
1244 debug.assert((try a.to(u7)) == 127);
1240 testing.expect(a.bitCountTwosComp() == 7);
1241 testing.expect((try a.to(u7)) == 127);
12451242
12461243 try a.set(-128);
1247 debug.assert(a.bitCountTwosComp() == 8);
1248 debug.assert((try a.to(i8)) == -128);
1244 testing.expect(a.bitCountTwosComp() == 8);
1245 testing.expect((try a.to(i8)) == -128);
12491246
12501247 try a.set(-129);
1251 debug.assert(a.bitCountTwosComp() == 9);
1252 debug.assert((try a.to(i9)) == -129);
1248 testing.expect(a.bitCountTwosComp() == 9);
1249 testing.expect((try a.to(i9)) == -129);
12531250}
12541251
12551252test "big.int fits" {
12561253 var a = try Int.init(al);
12571254
12581255 try a.set(0);
1259 debug.assert(a.fits(u0));
1260 debug.assert(a.fits(i0));
1256 testing.expect(a.fits(u0));
1257 testing.expect(a.fits(i0));
12611258
12621259 try a.set(255);
1263 debug.assert(!a.fits(u0));
1264 debug.assert(!a.fits(u1));
1265 debug.assert(!a.fits(i8));
1266 debug.assert(a.fits(u8));
1267 debug.assert(a.fits(u9));
1268 debug.assert(a.fits(i9));
1260 testing.expect(!a.fits(u0));
1261 testing.expect(!a.fits(u1));
1262 testing.expect(!a.fits(i8));
1263 testing.expect(a.fits(u8));
1264 testing.expect(a.fits(u9));
1265 testing.expect(a.fits(i9));
12691266
12701267 try a.set(-128);
1271 debug.assert(!a.fits(i7));
1272 debug.assert(a.fits(i8));
1273 debug.assert(a.fits(i9));
1274 debug.assert(!a.fits(u9));
1268 testing.expect(!a.fits(i7));
1269 testing.expect(a.fits(i8));
1270 testing.expect(a.fits(i9));
1271 testing.expect(!a.fits(u9));
12751272
12761273 try a.set(0x1ffffffffeeeeeeee);
1277 debug.assert(!a.fits(u32));
1278 debug.assert(!a.fits(u64));
1279 debug.assert(a.fits(u65));
1274 testing.expect(!a.fits(u32));
1275 testing.expect(!a.fits(u64));
1276 testing.expect(a.fits(u65));
12801277}
12811278
12821279test "big.int string set" {
12831280 var a = try Int.init(al);
12841281 try a.setString(10, "120317241209124781241290847124");
12851282
1286 debug.assert((try a.to(u128)) == 120317241209124781241290847124);
1283 testing.expect((try a.to(u128)) == 120317241209124781241290847124);
12871284}
12881285
12891286test "big.int string negative" {
12901287 var a = try Int.init(al);
12911288 try a.setString(10, "-1023");
1292 debug.assert((try a.to(i32)) == -1023);
1289 testing.expect((try a.to(i32)) == -1023);
12931290}
12941291
12951292test "big.int string set bad char error" {
12961293 var a = try Int.init(al);
1297 a.setString(10, "x") catch |err| debug.assert(err == error.InvalidCharForDigit);
1294 testing.expectError(error.InvalidCharForDigit, a.setString(10, "x"));
12981295}
12991296
13001297test "big.int string set bad base error" {
13011298 var a = try Int.init(al);
1302 a.setString(45, "10") catch |err| debug.assert(err == error.InvalidBase);
1299 testing.expectError(error.InvalidBase, a.setString(45, "10"));
13031300}
13041301
13051302test "big.int string to" {
......@@ -1308,17 +1305,13 @@ test "big.int string to" {
13081305 const as = try a.toString(al, 10);
13091306 const es = "120317241209124781241290847124";
13101307
1311 debug.assert(mem.eql(u8, as, es));
1308 testing.expect(mem.eql(u8, as, es));
13121309}
13131310
13141311test "big.int string to base base error" {
13151312 const a = try Int.initSet(al, 0xffffffff);
13161313
1317 if (a.toString(al, 45)) |_| {
1318 unreachable;
1319 } else |err| {
1320 debug.assert(err == error.InvalidBase);
1321 }
1314 testing.expectError(error.InvalidBase, a.toString(al, 45));
13221315}
13231316
13241317test "big.int string to base 2" {
......@@ -1327,7 +1320,7 @@ test "big.int string to base 2" {
13271320 const as = try a.toString(al, 2);
13281321 const es = "-1011";
13291322
1330 debug.assert(mem.eql(u8, as, es));
1323 testing.expect(mem.eql(u8, as, es));
13311324}
13321325
13331326test "big.int string to base 16" {
......@@ -1336,7 +1329,7 @@ test "big.int string to base 16" {
13361329 const as = try a.toString(al, 16);
13371330 const es = "efffffff00000001eeeeeeefaaaaaaab";
13381331
1339 debug.assert(mem.eql(u8, as, es));
1332 testing.expect(mem.eql(u8, as, es));
13401333}
13411334
13421335test "big.int neg string to" {
......@@ -1345,7 +1338,7 @@ test "big.int neg string to" {
13451338 const as = try a.toString(al, 10);
13461339 const es = "-123907434";
13471340
1348 debug.assert(mem.eql(u8, as, es));
1341 testing.expect(mem.eql(u8, as, es));
13491342}
13501343
13511344test "big.int zero string to" {
......@@ -1354,98 +1347,98 @@ test "big.int zero string to" {
13541347 const as = try a.toString(al, 10);
13551348 const es = "0";
13561349
1357 debug.assert(mem.eql(u8, as, es));
1350 testing.expect(mem.eql(u8, as, es));
13581351}
13591352
13601353test "big.int clone" {
13611354 var a = try Int.initSet(al, 1234);
13621355 const b = try a.clone();
13631356
1364 debug.assert((try a.to(u32)) == 1234);
1365 debug.assert((try b.to(u32)) == 1234);
1357 testing.expect((try a.to(u32)) == 1234);
1358 testing.expect((try b.to(u32)) == 1234);
13661359
13671360 try a.set(77);
1368 debug.assert((try a.to(u32)) == 77);
1369 debug.assert((try b.to(u32)) == 1234);
1361 testing.expect((try a.to(u32)) == 77);
1362 testing.expect((try b.to(u32)) == 1234);
13701363}
13711364
13721365test "big.int swap" {
13731366 var a = try Int.initSet(al, 1234);
13741367 var b = try Int.initSet(al, 5678);
13751368
1376 debug.assert((try a.to(u32)) == 1234);
1377 debug.assert((try b.to(u32)) == 5678);
1369 testing.expect((try a.to(u32)) == 1234);
1370 testing.expect((try b.to(u32)) == 5678);
13781371
13791372 a.swap(&b);
13801373
1381 debug.assert((try a.to(u32)) == 5678);
1382 debug.assert((try b.to(u32)) == 1234);
1374 testing.expect((try a.to(u32)) == 5678);
1375 testing.expect((try b.to(u32)) == 1234);
13831376}
13841377
13851378test "big.int to negative" {
13861379 var a = try Int.initSet(al, -10);
13871380
1388 debug.assert((try a.to(i32)) == -10);
1381 testing.expect((try a.to(i32)) == -10);
13891382}
13901383
13911384test "big.int compare" {
13921385 var a = try Int.initSet(al, -11);
13931386 var b = try Int.initSet(al, 10);
13941387
1395 debug.assert(a.cmpAbs(b) == 1);
1396 debug.assert(a.cmp(b) == -1);
1388 testing.expect(a.cmpAbs(b) == 1);
1389 testing.expect(a.cmp(b) == -1);
13971390}
13981391
13991392test "big.int compare similar" {
14001393 var a = try Int.initSet(al, 0xffffffffeeeeeeeeffffffffeeeeeeee);
14011394 var b = try Int.initSet(al, 0xffffffffeeeeeeeeffffffffeeeeeeef);
14021395
1403 debug.assert(a.cmpAbs(b) == -1);
1404 debug.assert(b.cmpAbs(a) == 1);
1396 testing.expect(a.cmpAbs(b) == -1);
1397 testing.expect(b.cmpAbs(a) == 1);
14051398}
14061399
14071400test "big.int compare different limb size" {
14081401 var a = try Int.initSet(al, maxInt(Limb) + 1);
14091402 var b = try Int.initSet(al, 1);
14101403
1411 debug.assert(a.cmpAbs(b) == 1);
1412 debug.assert(b.cmpAbs(a) == -1);
1404 testing.expect(a.cmpAbs(b) == 1);
1405 testing.expect(b.cmpAbs(a) == -1);
14131406}
14141407
14151408test "big.int compare multi-limb" {
14161409 var a = try Int.initSet(al, -0x7777777799999999ffffeeeeffffeeeeffffeeeef);
14171410 var b = try Int.initSet(al, 0x7777777799999999ffffeeeeffffeeeeffffeeeee);
14181411
1419 debug.assert(a.cmpAbs(b) == 1);
1420 debug.assert(a.cmp(b) == -1);
1412 testing.expect(a.cmpAbs(b) == 1);
1413 testing.expect(a.cmp(b) == -1);
14211414}
14221415
14231416test "big.int equality" {
14241417 var a = try Int.initSet(al, 0xffffffff1);
14251418 var b = try Int.initSet(al, -0xffffffff1);
14261419
1427 debug.assert(a.eqAbs(b));
1428 debug.assert(!a.eq(b));
1420 testing.expect(a.eqAbs(b));
1421 testing.expect(!a.eq(b));
14291422}
14301423
14311424test "big.int abs" {
14321425 var a = try Int.initSet(al, -5);
14331426
14341427 a.abs();
1435 debug.assert((try a.to(u32)) == 5);
1428 testing.expect((try a.to(u32)) == 5);
14361429
14371430 a.abs();
1438 debug.assert((try a.to(u32)) == 5);
1431 testing.expect((try a.to(u32)) == 5);
14391432}
14401433
14411434test "big.int negate" {
14421435 var a = try Int.initSet(al, 5);
14431436
14441437 a.negate();
1445 debug.assert((try a.to(i32)) == -5);
1438 testing.expect((try a.to(i32)) == -5);
14461439
14471440 a.negate();
1448 debug.assert((try a.to(i32)) == 5);
1441 testing.expect((try a.to(i32)) == 5);
14491442}
14501443
14511444test "big.int add single-single" {
......@@ -1455,7 +1448,7 @@ test "big.int add single-single" {
14551448 var c = try Int.init(al);
14561449 try c.add(a, b);
14571450
1458 debug.assert((try c.to(u32)) == 55);
1451 testing.expect((try c.to(u32)) == 55);
14591452}
14601453
14611454test "big.int add multi-single" {
......@@ -1465,10 +1458,10 @@ test "big.int add multi-single" {
14651458 var c = try Int.init(al);
14661459
14671460 try c.add(a, b);
1468 debug.assert((try c.to(DoubleLimb)) == maxInt(Limb) + 2);
1461 testing.expect((try c.to(DoubleLimb)) == maxInt(Limb) + 2);
14691462
14701463 try c.add(b, a);
1471 debug.assert((try c.to(DoubleLimb)) == maxInt(Limb) + 2);
1464 testing.expect((try c.to(DoubleLimb)) == maxInt(Limb) + 2);
14721465}
14731466
14741467test "big.int add multi-multi" {
......@@ -1480,7 +1473,7 @@ test "big.int add multi-multi" {
14801473 var c = try Int.init(al);
14811474 try c.add(a, b);
14821475
1483 debug.assert((try c.to(u128)) == op1 + op2);
1476 testing.expect((try c.to(u128)) == op1 + op2);
14841477}
14851478
14861479test "big.int add zero-zero" {
......@@ -1490,7 +1483,7 @@ test "big.int add zero-zero" {
14901483 var c = try Int.init(al);
14911484 try c.add(a, b);
14921485
1493 debug.assert((try c.to(u32)) == 0);
1486 testing.expect((try c.to(u32)) == 0);
14941487}
14951488
14961489test "big.int add alias multi-limb nonzero-zero" {
......@@ -1500,7 +1493,7 @@ test "big.int add alias multi-limb nonzero-zero" {
15001493
15011494 try a.add(a, b);
15021495
1503 debug.assert((try a.to(u128)) == op1);
1496 testing.expect((try a.to(u128)) == op1);
15041497}
15051498
15061499test "big.int add sign" {
......@@ -1512,16 +1505,16 @@ test "big.int add sign" {
15121505 const neg_two = try Int.initSet(al, -2);
15131506
15141507 try a.add(one, two);
1515 debug.assert((try a.to(i32)) == 3);
1508 testing.expect((try a.to(i32)) == 3);
15161509
15171510 try a.add(neg_one, two);
1518 debug.assert((try a.to(i32)) == 1);
1511 testing.expect((try a.to(i32)) == 1);
15191512
15201513 try a.add(one, neg_two);
1521 debug.assert((try a.to(i32)) == -1);
1514 testing.expect((try a.to(i32)) == -1);
15221515
15231516 try a.add(neg_one, neg_two);
1524 debug.assert((try a.to(i32)) == -3);
1517 testing.expect((try a.to(i32)) == -3);
15251518}
15261519
15271520test "big.int sub single-single" {
......@@ -1531,7 +1524,7 @@ test "big.int sub single-single" {
15311524 var c = try Int.init(al);
15321525 try c.sub(a, b);
15331526
1534 debug.assert((try c.to(u32)) == 45);
1527 testing.expect((try c.to(u32)) == 45);
15351528}
15361529
15371530test "big.int sub multi-single" {
......@@ -1541,7 +1534,7 @@ test "big.int sub multi-single" {
15411534 var c = try Int.init(al);
15421535 try c.sub(a, b);
15431536
1544 debug.assert((try c.to(Limb)) == maxInt(Limb));
1537 testing.expect((try c.to(Limb)) == maxInt(Limb));
15451538}
15461539
15471540test "big.int sub multi-multi" {
......@@ -1554,7 +1547,7 @@ test "big.int sub multi-multi" {
15541547 var c = try Int.init(al);
15551548 try c.sub(a, b);
15561549
1557 debug.assert((try c.to(u128)) == op1 - op2);
1550 testing.expect((try c.to(u128)) == op1 - op2);
15581551}
15591552
15601553test "big.int sub equal" {
......@@ -1564,7 +1557,7 @@ test "big.int sub equal" {
15641557 var c = try Int.init(al);
15651558 try c.sub(a, b);
15661559
1567 debug.assert((try c.to(u32)) == 0);
1560 testing.expect((try c.to(u32)) == 0);
15681561}
15691562
15701563test "big.int sub sign" {
......@@ -1576,19 +1569,19 @@ test "big.int sub sign" {
15761569 const neg_two = try Int.initSet(al, -2);
15771570
15781571 try a.sub(one, two);
1579 debug.assert((try a.to(i32)) == -1);
1572 testing.expect((try a.to(i32)) == -1);
15801573
15811574 try a.sub(neg_one, two);
1582 debug.assert((try a.to(i32)) == -3);
1575 testing.expect((try a.to(i32)) == -3);
15831576
15841577 try a.sub(one, neg_two);
1585 debug.assert((try a.to(i32)) == 3);
1578 testing.expect((try a.to(i32)) == 3);
15861579
15871580 try a.sub(neg_one, neg_two);
1588 debug.assert((try a.to(i32)) == 1);
1581 testing.expect((try a.to(i32)) == 1);
15891582
15901583 try a.sub(neg_two, neg_one);
1591 debug.assert((try a.to(i32)) == -1);
1584 testing.expect((try a.to(i32)) == -1);
15921585}
15931586
15941587test "big.int mul single-single" {
......@@ -1598,7 +1591,7 @@ test "big.int mul single-single" {
15981591 var c = try Int.init(al);
15991592 try c.mul(a, b);
16001593
1601 debug.assert((try c.to(u64)) == 250);
1594 testing.expect((try c.to(u64)) == 250);
16021595}
16031596
16041597test "big.int mul multi-single" {
......@@ -1608,7 +1601,7 @@ test "big.int mul multi-single" {
16081601 var c = try Int.init(al);
16091602 try c.mul(a, b);
16101603
1611 debug.assert((try c.to(DoubleLimb)) == 2 * maxInt(Limb));
1604 testing.expect((try c.to(DoubleLimb)) == 2 * maxInt(Limb));
16121605}
16131606
16141607test "big.int mul multi-multi" {
......@@ -1620,7 +1613,7 @@ test "big.int mul multi-multi" {
16201613 var c = try Int.init(al);
16211614 try c.mul(a, b);
16221615
1623 debug.assert((try c.to(u256)) == op1 * op2);
1616 testing.expect((try c.to(u256)) == op1 * op2);
16241617}
16251618
16261619test "big.int mul alias r with a" {
......@@ -1629,7 +1622,7 @@ test "big.int mul alias r with a" {
16291622
16301623 try a.mul(a, b);
16311624
1632 debug.assert((try a.to(DoubleLimb)) == 2 * maxInt(Limb));
1625 testing.expect((try a.to(DoubleLimb)) == 2 * maxInt(Limb));
16331626}
16341627
16351628test "big.int mul alias r with b" {
......@@ -1638,7 +1631,7 @@ test "big.int mul alias r with b" {
16381631
16391632 try a.mul(b, a);
16401633
1641 debug.assert((try a.to(DoubleLimb)) == 2 * maxInt(Limb));
1634 testing.expect((try a.to(DoubleLimb)) == 2 * maxInt(Limb));
16421635}
16431636
16441637test "big.int mul alias r with a and b" {
......@@ -1646,7 +1639,7 @@ test "big.int mul alias r with a and b" {
16461639
16471640 try a.mul(a, a);
16481641
1649 debug.assert((try a.to(DoubleLimb)) == maxInt(Limb) * maxInt(Limb));
1642 testing.expect((try a.to(DoubleLimb)) == maxInt(Limb) * maxInt(Limb));
16501643}
16511644
16521645test "big.int mul a*0" {
......@@ -1656,7 +1649,7 @@ test "big.int mul a*0" {
16561649 var c = try Int.init(al);
16571650 try c.mul(a, b);
16581651
1659 debug.assert((try c.to(u32)) == 0);
1652 testing.expect((try c.to(u32)) == 0);
16601653}
16611654
16621655test "big.int mul 0*0" {
......@@ -1666,7 +1659,7 @@ test "big.int mul 0*0" {
16661659 var c = try Int.init(al);
16671660 try c.mul(a, b);
16681661
1669 debug.assert((try c.to(u32)) == 0);
1662 testing.expect((try c.to(u32)) == 0);
16701663}
16711664
16721665test "big.int div single-single no rem" {
......@@ -1677,8 +1670,8 @@ test "big.int div single-single no rem" {
16771670 var r = try Int.init(al);
16781671 try Int.divTrunc(&q, &r, a, b);
16791672
1680 debug.assert((try q.to(u32)) == 10);
1681 debug.assert((try r.to(u32)) == 0);
1673 testing.expect((try q.to(u32)) == 10);
1674 testing.expect((try r.to(u32)) == 0);
16821675}
16831676
16841677test "big.int div single-single with rem" {
......@@ -1689,8 +1682,8 @@ test "big.int div single-single with rem" {
16891682 var r = try Int.init(al);
16901683 try Int.divTrunc(&q, &r, a, b);
16911684
1692 debug.assert((try q.to(u32)) == 9);
1693 debug.assert((try r.to(u32)) == 4);
1685 testing.expect((try q.to(u32)) == 9);
1686 testing.expect((try r.to(u32)) == 4);
16941687}
16951688
16961689test "big.int div multi-single no rem" {
......@@ -1704,8 +1697,8 @@ test "big.int div multi-single no rem" {
17041697 var r = try Int.init(al);
17051698 try Int.divTrunc(&q, &r, a, b);
17061699
1707 debug.assert((try q.to(u64)) == op1 / op2);
1708 debug.assert((try r.to(u64)) == 0);
1700 testing.expect((try q.to(u64)) == op1 / op2);
1701 testing.expect((try r.to(u64)) == 0);
17091702}
17101703
17111704test "big.int div multi-single with rem" {
......@@ -1719,8 +1712,8 @@ test "big.int div multi-single with rem" {
17191712 var r = try Int.init(al);
17201713 try Int.divTrunc(&q, &r, a, b);
17211714
1722 debug.assert((try q.to(u64)) == op1 / op2);
1723 debug.assert((try r.to(u64)) == 3);
1715 testing.expect((try q.to(u64)) == op1 / op2);
1716 testing.expect((try r.to(u64)) == 3);
17241717}
17251718
17261719test "big.int div multi>2-single" {
......@@ -1734,8 +1727,8 @@ test "big.int div multi>2-single" {
17341727 var r = try Int.init(al);
17351728 try Int.divTrunc(&q, &r, a, b);
17361729
1737 debug.assert((try q.to(u128)) == op1 / op2);
1738 debug.assert((try r.to(u32)) == 0x3e4e);
1730 testing.expect((try q.to(u128)) == op1 / op2);
1731 testing.expect((try r.to(u32)) == 0x3e4e);
17391732}
17401733
17411734test "big.int div single-single q < r" {
......@@ -1746,8 +1739,8 @@ test "big.int div single-single q < r" {
17461739 var r = try Int.init(al);
17471740 try Int.divTrunc(&q, &r, a, b);
17481741
1749 debug.assert((try q.to(u64)) == 0);
1750 debug.assert((try r.to(u64)) == 0x0078f432);
1742 testing.expect((try q.to(u64)) == 0);
1743 testing.expect((try r.to(u64)) == 0x0078f432);
17511744}
17521745
17531746test "big.int div single-single q == r" {
......@@ -1758,8 +1751,8 @@ test "big.int div single-single q == r" {
17581751 var r = try Int.init(al);
17591752 try Int.divTrunc(&q, &r, a, b);
17601753
1761 debug.assert((try q.to(u64)) == 1);
1762 debug.assert((try r.to(u64)) == 0);
1754 testing.expect((try q.to(u64)) == 1);
1755 testing.expect((try r.to(u64)) == 0);
17631756}
17641757
17651758test "big.int div q=0 alias" {
......@@ -1768,8 +1761,8 @@ test "big.int div q=0 alias" {
17681761
17691762 try Int.divTrunc(&a, &b, a, b);
17701763
1771 debug.assert((try a.to(u64)) == 0);
1772 debug.assert((try b.to(u64)) == 3);
1764 testing.expect((try a.to(u64)) == 0);
1765 testing.expect((try b.to(u64)) == 3);
17731766}
17741767
17751768test "big.int div multi-multi q < r" {
......@@ -1782,8 +1775,8 @@ test "big.int div multi-multi q < r" {
17821775 var r = try Int.init(al);
17831776 try Int.divTrunc(&q, &r, a, b);
17841777
1785 debug.assert((try q.to(u128)) == 0);
1786 debug.assert((try r.to(u128)) == op1);
1778 testing.expect((try q.to(u128)) == 0);
1779 testing.expect((try r.to(u128)) == op1);
17871780}
17881781
17891782test "big.int div trunc single-single +/+" {
......@@ -1802,8 +1795,8 @@ test "big.int div trunc single-single +/+" {
18021795 const eq = @divTrunc(u, v);
18031796 const er = @mod(u, v);
18041797
1805 debug.assert((try q.to(i32)) == eq);
1806 debug.assert((try r.to(i32)) == er);
1798 testing.expect((try q.to(i32)) == eq);
1799 testing.expect((try r.to(i32)) == er);
18071800}
18081801
18091802test "big.int div trunc single-single -/+" {
......@@ -1822,8 +1815,8 @@ test "big.int div trunc single-single -/+" {
18221815 const eq = -1;
18231816 const er = -2;
18241817
1825 debug.assert((try q.to(i32)) == eq);
1826 debug.assert((try r.to(i32)) == er);
1818 testing.expect((try q.to(i32)) == eq);
1819 testing.expect((try r.to(i32)) == er);
18271820}
18281821
18291822test "big.int div trunc single-single +/-" {
......@@ -1842,8 +1835,8 @@ test "big.int div trunc single-single +/-" {
18421835 const eq = -1;
18431836 const er = 2;
18441837
1845 debug.assert((try q.to(i32)) == eq);
1846 debug.assert((try r.to(i32)) == er);
1838 testing.expect((try q.to(i32)) == eq);
1839 testing.expect((try r.to(i32)) == er);
18471840}
18481841
18491842test "big.int div trunc single-single -/-" {
......@@ -1862,8 +1855,8 @@ test "big.int div trunc single-single -/-" {
18621855 const eq = 1;
18631856 const er = -2;
18641857
1865 debug.assert((try q.to(i32)) == eq);
1866 debug.assert((try r.to(i32)) == er);
1858 testing.expect((try q.to(i32)) == eq);
1859 testing.expect((try r.to(i32)) == er);
18671860}
18681861
18691862test "big.int div floor single-single +/+" {
......@@ -1882,8 +1875,8 @@ test "big.int div floor single-single +/+" {
18821875 const eq = 1;
18831876 const er = 2;
18841877
1885 debug.assert((try q.to(i32)) == eq);
1886 debug.assert((try r.to(i32)) == er);
1878 testing.expect((try q.to(i32)) == eq);
1879 testing.expect((try r.to(i32)) == er);
18871880}
18881881
18891882test "big.int div floor single-single -/+" {
......@@ -1902,8 +1895,8 @@ test "big.int div floor single-single -/+" {
19021895 const eq = -2;
19031896 const er = 1;
19041897
1905 debug.assert((try q.to(i32)) == eq);
1906 debug.assert((try r.to(i32)) == er);
1898 testing.expect((try q.to(i32)) == eq);
1899 testing.expect((try r.to(i32)) == er);
19071900}
19081901
19091902test "big.int div floor single-single +/-" {
......@@ -1922,8 +1915,8 @@ test "big.int div floor single-single +/-" {
19221915 const eq = -2;
19231916 const er = -1;
19241917
1925 debug.assert((try q.to(i32)) == eq);
1926 debug.assert((try r.to(i32)) == er);
1918 testing.expect((try q.to(i32)) == eq);
1919 testing.expect((try r.to(i32)) == er);
19271920}
19281921
19291922test "big.int div floor single-single -/-" {
......@@ -1942,8 +1935,8 @@ test "big.int div floor single-single -/-" {
19421935 const eq = 1;
19431936 const er = -2;
19441937
1945 debug.assert((try q.to(i32)) == eq);
1946 debug.assert((try r.to(i32)) == er);
1938 testing.expect((try q.to(i32)) == eq);
1939 testing.expect((try r.to(i32)) == er);
19471940}
19481941
19491942test "big.int div multi-multi with rem" {
......@@ -1954,8 +1947,8 @@ test "big.int div multi-multi with rem" {
19541947 var r = try Int.init(al);
19551948 try Int.divTrunc(&q, &r, a, b);
19561949
1957 debug.assert((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b);
1958 debug.assert((try r.to(u128)) == 0x28de0acacd806823638);
1950 testing.expect((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b);
1951 testing.expect((try r.to(u128)) == 0x28de0acacd806823638);
19591952}
19601953
19611954test "big.int div multi-multi no rem" {
......@@ -1966,8 +1959,8 @@ test "big.int div multi-multi no rem" {
19661959 var r = try Int.init(al);
19671960 try Int.divTrunc(&q, &r, a, b);
19681961
1969 debug.assert((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b);
1970 debug.assert((try r.to(u128)) == 0);
1962 testing.expect((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b);
1963 testing.expect((try r.to(u128)) == 0);
19711964}
19721965
19731966test "big.int div multi-multi (2 branch)" {
......@@ -1978,8 +1971,8 @@ test "big.int div multi-multi (2 branch)" {
19781971 var r = try Int.init(al);
19791972 try Int.divTrunc(&q, &r, a, b);
19801973
1981 debug.assert((try q.to(u128)) == 0x10000000000000000);
1982 debug.assert((try r.to(u128)) == 0x44444443444444431111111111111111);
1974 testing.expect((try q.to(u128)) == 0x10000000000000000);
1975 testing.expect((try r.to(u128)) == 0x44444443444444431111111111111111);
19831976}
19841977
19851978test "big.int div multi-multi (3.1/3.3 branch)" {
......@@ -1990,53 +1983,53 @@ test "big.int div multi-multi (3.1/3.3 branch)" {
19901983 var r = try Int.init(al);
19911984 try Int.divTrunc(&q, &r, a, b);
19921985
1993 debug.assert((try q.to(u128)) == 0xfffffffffffffffffff);
1994 debug.assert((try r.to(u256)) == 0x1111111111111111111110b12222222222222222282);
1986 testing.expect((try q.to(u128)) == 0xfffffffffffffffffff);
1987 testing.expect((try r.to(u256)) == 0x1111111111111111111110b12222222222222222282);
19951988}
19961989
19971990test "big.int shift-right single" {
19981991 var a = try Int.initSet(al, 0xffff0000);
19991992 try a.shiftRight(a, 16);
20001993
2001 debug.assert((try a.to(u32)) == 0xffff);
1994 testing.expect((try a.to(u32)) == 0xffff);
20021995}
20031996
20041997test "big.int shift-right multi" {
20051998 var a = try Int.initSet(al, 0xffff0000eeee1111dddd2222cccc3333);
20061999 try a.shiftRight(a, 67);
20072000
2008 debug.assert((try a.to(u64)) == 0x1fffe0001dddc222);
2001 testing.expect((try a.to(u64)) == 0x1fffe0001dddc222);
20092002}
20102003
20112004test "big.int shift-left single" {
20122005 var a = try Int.initSet(al, 0xffff);
20132006 try a.shiftLeft(a, 16);
20142007
2015 debug.assert((try a.to(u64)) == 0xffff0000);
2008 testing.expect((try a.to(u64)) == 0xffff0000);
20162009}
20172010
20182011test "big.int shift-left multi" {
20192012 var a = try Int.initSet(al, 0x1fffe0001dddc222);
20202013 try a.shiftLeft(a, 67);
20212014
2022 debug.assert((try a.to(u128)) == 0xffff0000eeee11100000000000000000);
2015 testing.expect((try a.to(u128)) == 0xffff0000eeee11100000000000000000);
20232016}
20242017
20252018test "big.int shift-right negative" {
20262019 var a = try Int.init(al);
20272020
20282021 try a.shiftRight(try Int.initSet(al, -20), 2);
2029 debug.assert((try a.to(i32)) == -20 >> 2);
2022 testing.expect((try a.to(i32)) == -20 >> 2);
20302023
20312024 try a.shiftRight(try Int.initSet(al, -5), 10);
2032 debug.assert((try a.to(i32)) == -5 >> 10);
2025 testing.expect((try a.to(i32)) == -5 >> 10);
20332026}
20342027
20352028test "big.int shift-left negative" {
20362029 var a = try Int.init(al);
20372030
20382031 try a.shiftRight(try Int.initSet(al, -10), 1232);
2039 debug.assert((try a.to(i32)) == -10 >> 1232);
2032 testing.expect((try a.to(i32)) == -10 >> 1232);
20402033}
20412034
20422035test "big.int bitwise and simple" {
......@@ -2045,7 +2038,7 @@ test "big.int bitwise and simple" {
20452038
20462039 try a.bitAnd(a, b);
20472040
2048 debug.assert((try a.to(u64)) == 0xeeeeeeee00000000);
2041 testing.expect((try a.to(u64)) == 0xeeeeeeee00000000);
20492042}
20502043
20512044test "big.int bitwise and multi-limb" {
......@@ -2054,7 +2047,7 @@ test "big.int bitwise and multi-limb" {
20542047
20552048 try a.bitAnd(a, b);
20562049
2057 debug.assert((try a.to(u128)) == 0);
2050 testing.expect((try a.to(u128)) == 0);
20582051}
20592052
20602053test "big.int bitwise xor simple" {
......@@ -2063,7 +2056,7 @@ test "big.int bitwise xor simple" {
20632056
20642057 try a.bitXor(a, b);
20652058
2066 debug.assert((try a.to(u64)) == 0x1111111133333333);
2059 testing.expect((try a.to(u64)) == 0x1111111133333333);
20672060}
20682061
20692062test "big.int bitwise xor multi-limb" {
......@@ -2072,7 +2065,7 @@ test "big.int bitwise xor multi-limb" {
20722065
20732066 try a.bitXor(a, b);
20742067
2075 debug.assert((try a.to(DoubleLimb)) == (maxInt(Limb) + 1) ^ maxInt(Limb));
2068 testing.expect((try a.to(DoubleLimb)) == (maxInt(Limb) + 1) ^ maxInt(Limb));
20762069}
20772070
20782071test "big.int bitwise or simple" {
......@@ -2081,7 +2074,7 @@ test "big.int bitwise or simple" {
20812074
20822075 try a.bitOr(a, b);
20832076
2084 debug.assert((try a.to(u64)) == 0xffffffff33333333);
2077 testing.expect((try a.to(u64)) == 0xffffffff33333333);
20852078}
20862079
20872080test "big.int bitwise or multi-limb" {
......@@ -2091,15 +2084,15 @@ test "big.int bitwise or multi-limb" {
20912084 try a.bitOr(a, b);
20922085
20932086 // TODO: big.int.cpp or is wrong on multi-limb.
2094 debug.assert((try a.to(DoubleLimb)) == (maxInt(Limb) + 1) + maxInt(Limb));
2087 testing.expect((try a.to(DoubleLimb)) == (maxInt(Limb) + 1) + maxInt(Limb));
20952088}
20962089
20972090test "big.int var args" {
20982091 var a = try Int.initSet(al, 5);
20992092
21002093 try a.add(a, try Int.initSet(al, 6));
2101 debug.assert((try a.to(u64)) == 11);
2094 testing.expect((try a.to(u64)) == 11);
21022095
2103 debug.assert(a.cmp(try Int.initSet(al, 11)) == 0);
2104 debug.assert(a.cmp(try Int.initSet(al, 14)) <= 0);
2096 testing.expect(a.cmp(try Int.initSet(al, 11)) == 0);
2097 testing.expect(a.cmp(try Int.initSet(al, 14)) <= 0);
21052098}
std/math/cbrt.zig+25-25
......@@ -6,7 +6,7 @@
66
77const std = @import("../index.zig");
88const math = std.math;
9const assert = std.debug.assert;
9const expect = std.testing.expect;
1010
1111pub fn cbrt(x: var) @typeOf(x) {
1212 const T = @typeOf(x);
......@@ -114,44 +114,44 @@ fn cbrt64(x: f64) f64 {
114114}
115115
116116test "math.cbrt" {
117 assert(cbrt(f32(0.0)) == cbrt32(0.0));
118 assert(cbrt(f64(0.0)) == cbrt64(0.0));
117 expect(cbrt(f32(0.0)) == cbrt32(0.0));
118 expect(cbrt(f64(0.0)) == cbrt64(0.0));
119119}
120120
121121test "math.cbrt32" {
122122 const epsilon = 0.000001;
123123
124 assert(cbrt32(0.0) == 0.0);
125 assert(math.approxEq(f32, cbrt32(0.2), 0.584804, epsilon));
126 assert(math.approxEq(f32, cbrt32(0.8923), 0.962728, epsilon));
127 assert(math.approxEq(f32, cbrt32(1.5), 1.144714, epsilon));
128 assert(math.approxEq(f32, cbrt32(37.45), 3.345676, epsilon));
129 assert(math.approxEq(f32, cbrt32(123123.234375), 49.748501, epsilon));
124 expect(cbrt32(0.0) == 0.0);
125 expect(math.approxEq(f32, cbrt32(0.2), 0.584804, epsilon));
126 expect(math.approxEq(f32, cbrt32(0.8923), 0.962728, epsilon));
127 expect(math.approxEq(f32, cbrt32(1.5), 1.144714, epsilon));
128 expect(math.approxEq(f32, cbrt32(37.45), 3.345676, epsilon));
129 expect(math.approxEq(f32, cbrt32(123123.234375), 49.748501, epsilon));
130130}
131131
132132test "math.cbrt64" {
133133 const epsilon = 0.000001;
134134
135 assert(cbrt64(0.0) == 0.0);
136 assert(math.approxEq(f64, cbrt64(0.2), 0.584804, epsilon));
137 assert(math.approxEq(f64, cbrt64(0.8923), 0.962728, epsilon));
138 assert(math.approxEq(f64, cbrt64(1.5), 1.144714, epsilon));
139 assert(math.approxEq(f64, cbrt64(37.45), 3.345676, epsilon));
140 assert(math.approxEq(f64, cbrt64(123123.234375), 49.748501, epsilon));
135 expect(cbrt64(0.0) == 0.0);
136 expect(math.approxEq(f64, cbrt64(0.2), 0.584804, epsilon));
137 expect(math.approxEq(f64, cbrt64(0.8923), 0.962728, epsilon));
138 expect(math.approxEq(f64, cbrt64(1.5), 1.144714, epsilon));
139 expect(math.approxEq(f64, cbrt64(37.45), 3.345676, epsilon));
140 expect(math.approxEq(f64, cbrt64(123123.234375), 49.748501, epsilon));
141141}
142142
143143test "math.cbrt.special" {
144 assert(cbrt32(0.0) == 0.0);
145 assert(cbrt32(-0.0) == -0.0);
146 assert(math.isPositiveInf(cbrt32(math.inf(f32))));
147 assert(math.isNegativeInf(cbrt32(-math.inf(f32))));
148 assert(math.isNan(cbrt32(math.nan(f32))));
144 expect(cbrt32(0.0) == 0.0);
145 expect(cbrt32(-0.0) == -0.0);
146 expect(math.isPositiveInf(cbrt32(math.inf(f32))));
147 expect(math.isNegativeInf(cbrt32(-math.inf(f32))));
148 expect(math.isNan(cbrt32(math.nan(f32))));
149149}
150150
151151test "math.cbrt64.special" {
152 assert(cbrt64(0.0) == 0.0);
153 assert(cbrt64(-0.0) == -0.0);
154 assert(math.isPositiveInf(cbrt64(math.inf(f64))));
155 assert(math.isNegativeInf(cbrt64(-math.inf(f64))));
156 assert(math.isNan(cbrt64(math.nan(f64))));
152 expect(cbrt64(0.0) == 0.0);
153 expect(cbrt64(-0.0) == -0.0);
154 expect(math.isPositiveInf(cbrt64(math.inf(f64))));
155 expect(math.isNegativeInf(cbrt64(-math.inf(f64))));
156 expect(math.isNan(cbrt64(math.nan(f64))));
157157}
std/math/ceil.zig+19-19
......@@ -7,7 +7,7 @@
77const builtin = @import("builtin");
88const std = @import("../index.zig");
99const math = std.math;
10const assert = std.debug.assert;
10const expect = std.testing.expect;
1111
1212pub fn ceil(x: var) @typeOf(x) {
1313 const T = @typeOf(x);
......@@ -81,34 +81,34 @@ fn ceil64(x: f64) f64 {
8181}
8282
8383test "math.ceil" {
84 assert(ceil(f32(0.0)) == ceil32(0.0));
85 assert(ceil(f64(0.0)) == ceil64(0.0));
84 expect(ceil(f32(0.0)) == ceil32(0.0));
85 expect(ceil(f64(0.0)) == ceil64(0.0));
8686}
8787
8888test "math.ceil32" {
89 assert(ceil32(1.3) == 2.0);
90 assert(ceil32(-1.3) == -1.0);
91 assert(ceil32(0.2) == 1.0);
89 expect(ceil32(1.3) == 2.0);
90 expect(ceil32(-1.3) == -1.0);
91 expect(ceil32(0.2) == 1.0);
9292}
9393
9494test "math.ceil64" {
95 assert(ceil64(1.3) == 2.0);
96 assert(ceil64(-1.3) == -1.0);
97 assert(ceil64(0.2) == 1.0);
95 expect(ceil64(1.3) == 2.0);
96 expect(ceil64(-1.3) == -1.0);
97 expect(ceil64(0.2) == 1.0);
9898}
9999
100100test "math.ceil32.special" {
101 assert(ceil32(0.0) == 0.0);
102 assert(ceil32(-0.0) == -0.0);
103 assert(math.isPositiveInf(ceil32(math.inf(f32))));
104 assert(math.isNegativeInf(ceil32(-math.inf(f32))));
105 assert(math.isNan(ceil32(math.nan(f32))));
101 expect(ceil32(0.0) == 0.0);
102 expect(ceil32(-0.0) == -0.0);
103 expect(math.isPositiveInf(ceil32(math.inf(f32))));
104 expect(math.isNegativeInf(ceil32(-math.inf(f32))));
105 expect(math.isNan(ceil32(math.nan(f32))));
106106}
107107
108108test "math.ceil64.special" {
109 assert(ceil64(0.0) == 0.0);
110 assert(ceil64(-0.0) == -0.0);
111 assert(math.isPositiveInf(ceil64(math.inf(f64))));
112 assert(math.isNegativeInf(ceil64(-math.inf(f64))));
113 assert(math.isNan(ceil64(math.nan(f64))));
109 expect(ceil64(0.0) == 0.0);
110 expect(ceil64(-0.0) == -0.0);
111 expect(math.isPositiveInf(ceil64(math.inf(f64))));
112 expect(math.isNegativeInf(ceil64(-math.inf(f64))));
113 expect(math.isNan(ceil64(math.nan(f64))));
114114}
std/math/complex/abs.zig+2-2
......@@ -1,5 +1,5 @@
11const std = @import("../../index.zig");
2const debug = std.debug;
2const testing = std.testing;
33const math = std.math;
44const cmath = math.complex;
55const Complex = cmath.Complex;
......@@ -14,5 +14,5 @@ const epsilon = 0.0001;
1414test "complex.cabs" {
1515 const a = Complex(f32).new(5, 3);
1616 const c = abs(a);
17 debug.assert(math.approxEq(f32, c, 5.83095, epsilon));
17 testing.expect(math.approxEq(f32, c, 5.83095, epsilon));
1818}
std/math/complex/acos.zig+3-3
......@@ -1,5 +1,5 @@
11const std = @import("../../index.zig");
2const debug = std.debug;
2const testing = std.testing;
33const math = std.math;
44const cmath = math.complex;
55const Complex = cmath.Complex;
......@@ -16,6 +16,6 @@ test "complex.cacos" {
1616 const a = Complex(f32).new(5, 3);
1717 const c = acos(a);
1818
19 debug.assert(math.approxEq(f32, c.re, 0.546975, epsilon));
20 debug.assert(math.approxEq(f32, c.im, -2.452914, epsilon));
19 testing.expect(math.approxEq(f32, c.re, 0.546975, epsilon));
20 testing.expect(math.approxEq(f32, c.im, -2.452914, epsilon));
2121}
std/math/complex/acosh.zig+3-3
......@@ -1,5 +1,5 @@
11const std = @import("../../index.zig");
2const debug = std.debug;
2const testing = std.testing;
33const math = std.math;
44const cmath = math.complex;
55const Complex = cmath.Complex;
......@@ -16,6 +16,6 @@ test "complex.cacosh" {
1616 const a = Complex(f32).new(5, 3);
1717 const c = acosh(a);
1818
19 debug.assert(math.approxEq(f32, c.re, 2.452914, epsilon));
20 debug.assert(math.approxEq(f32, c.im, 0.546975, epsilon));
19 testing.expect(math.approxEq(f32, c.re, 2.452914, epsilon));
20 testing.expect(math.approxEq(f32, c.im, 0.546975, epsilon));
2121}
std/math/complex/arg.zig+2-2
......@@ -1,5 +1,5 @@
11const std = @import("../../index.zig");
2const debug = std.debug;
2const testing = std.testing;
33const math = std.math;
44const cmath = math.complex;
55const Complex = cmath.Complex;
......@@ -14,5 +14,5 @@ const epsilon = 0.0001;
1414test "complex.carg" {
1515 const a = Complex(f32).new(5, 3);
1616 const c = arg(a);
17 debug.assert(math.approxEq(f32, c, 0.540420, epsilon));
17 testing.expect(math.approxEq(f32, c, 0.540420, epsilon));
1818}
std/math/complex/asin.zig+3-3
......@@ -1,5 +1,5 @@
11const std = @import("../../index.zig");
2const debug = std.debug;
2const testing = std.testing;
33const math = std.math;
44const cmath = math.complex;
55const Complex = cmath.Complex;
......@@ -22,6 +22,6 @@ test "complex.casin" {
2222 const a = Complex(f32).new(5, 3);
2323 const c = asin(a);
2424
25 debug.assert(math.approxEq(f32, c.re, 1.023822, epsilon));
26 debug.assert(math.approxEq(f32, c.im, 2.452914, epsilon));
25 testing.expect(math.approxEq(f32, c.re, 1.023822, epsilon));
26 testing.expect(math.approxEq(f32, c.im, 2.452914, epsilon));
2727}
std/math/complex/asinh.zig+3-3
......@@ -1,5 +1,5 @@
11const std = @import("../../index.zig");
2const debug = std.debug;
2const testing = std.testing;
33const math = std.math;
44const cmath = math.complex;
55const Complex = cmath.Complex;
......@@ -17,6 +17,6 @@ test "complex.casinh" {
1717 const a = Complex(f32).new(5, 3);
1818 const c = asinh(a);
1919
20 debug.assert(math.approxEq(f32, c.re, 2.459831, epsilon));
21 debug.assert(math.approxEq(f32, c.im, 0.533999, epsilon));
20 testing.expect(math.approxEq(f32, c.re, 2.459831, epsilon));
21 testing.expect(math.approxEq(f32, c.im, 0.533999, epsilon));
2222}
std/math/complex/atan.zig+5-5
......@@ -1,5 +1,5 @@
11const std = @import("../../index.zig");
2const debug = std.debug;
2const testing = std.testing;
33const math = std.math;
44const cmath = math.complex;
55const Complex = cmath.Complex;
......@@ -117,14 +117,14 @@ test "complex.catan32" {
117117 const a = Complex(f32).new(5, 3);
118118 const c = atan(a);
119119
120 debug.assert(math.approxEq(f32, c.re, 1.423679, epsilon));
121 debug.assert(math.approxEq(f32, c.im, 0.086569, epsilon));
120 testing.expect(math.approxEq(f32, c.re, 1.423679, epsilon));
121 testing.expect(math.approxEq(f32, c.im, 0.086569, epsilon));
122122}
123123
124124test "complex.catan64" {
125125 const a = Complex(f64).new(5, 3);
126126 const c = atan(a);
127127
128 debug.assert(math.approxEq(f64, c.re, 1.423679, epsilon));
129 debug.assert(math.approxEq(f64, c.im, 0.086569, epsilon));
128 testing.expect(math.approxEq(f64, c.re, 1.423679, epsilon));
129 testing.expect(math.approxEq(f64, c.im, 0.086569, epsilon));
130130}
std/math/complex/atanh.zig+3-3
......@@ -1,5 +1,5 @@
11const std = @import("../../index.zig");
2const debug = std.debug;
2const testing = std.testing;
33const math = std.math;
44const cmath = math.complex;
55const Complex = cmath.Complex;
......@@ -17,6 +17,6 @@ test "complex.catanh" {
1717 const a = Complex(f32).new(5, 3);
1818 const c = atanh(a);
1919
20 debug.assert(math.approxEq(f32, c.re, 0.146947, epsilon));
21 debug.assert(math.approxEq(f32, c.im, 1.480870, epsilon));
20 testing.expect(math.approxEq(f32, c.re, 0.146947, epsilon));
21 testing.expect(math.approxEq(f32, c.im, 1.480870, epsilon));
2222}
std/math/complex/conj.zig+2-2
......@@ -1,5 +1,5 @@
11const std = @import("../../index.zig");
2const debug = std.debug;
2const testing = std.testing;
33const math = std.math;
44const cmath = math.complex;
55const Complex = cmath.Complex;
......@@ -13,5 +13,5 @@ test "complex.conj" {
1313 const a = Complex(f32).new(5, 3);
1414 const c = a.conjugate();
1515
16 debug.assert(c.re == 5 and c.im == -3);
16 testing.expect(c.re == 5 and c.im == -3);
1717}
std/math/complex/cos.zig+3-3
......@@ -1,5 +1,5 @@
11const std = @import("../../index.zig");
2const debug = std.debug;
2const testing = std.testing;
33const math = std.math;
44const cmath = math.complex;
55const Complex = cmath.Complex;
......@@ -16,6 +16,6 @@ test "complex.ccos" {
1616 const a = Complex(f32).new(5, 3);
1717 const c = cos(a);
1818
19 debug.assert(math.approxEq(f32, c.re, 2.855815, epsilon));
20 debug.assert(math.approxEq(f32, c.im, 9.606383, epsilon));
19 testing.expect(math.approxEq(f32, c.re, 2.855815, epsilon));
20 testing.expect(math.approxEq(f32, c.im, 9.606383, epsilon));
2121}
std/math/complex/cosh.zig+5-5
......@@ -1,5 +1,5 @@
11const std = @import("../../index.zig");
2const debug = std.debug;
2const testing = std.testing;
33const math = std.math;
44const cmath = math.complex;
55const Complex = cmath.Complex;
......@@ -152,14 +152,14 @@ test "complex.ccosh32" {
152152 const a = Complex(f32).new(5, 3);
153153 const c = cosh(a);
154154
155 debug.assert(math.approxEq(f32, c.re, -73.467300, epsilon));
156 debug.assert(math.approxEq(f32, c.im, 10.471557, epsilon));
155 testing.expect(math.approxEq(f32, c.re, -73.467300, epsilon));
156 testing.expect(math.approxEq(f32, c.im, 10.471557, epsilon));
157157}
158158
159159test "complex.ccosh64" {
160160 const a = Complex(f64).new(5, 3);
161161 const c = cosh(a);
162162
163 debug.assert(math.approxEq(f64, c.re, -73.467300, epsilon));
164 debug.assert(math.approxEq(f64, c.im, 10.471557, epsilon));
163 testing.expect(math.approxEq(f64, c.re, -73.467300, epsilon));
164 testing.expect(math.approxEq(f64, c.im, 10.471557, epsilon));
165165}
std/math/complex/exp.zig+5-5
......@@ -1,5 +1,5 @@
11const std = @import("../../index.zig");
2const debug = std.debug;
2const testing = std.testing;
33const math = std.math;
44const cmath = math.complex;
55const Complex = cmath.Complex;
......@@ -118,14 +118,14 @@ test "complex.cexp32" {
118118 const a = Complex(f32).new(5, 3);
119119 const c = exp(a);
120120
121 debug.assert(math.approxEq(f32, c.re, -146.927917, epsilon));
122 debug.assert(math.approxEq(f32, c.im, 20.944065, epsilon));
121 testing.expect(math.approxEq(f32, c.re, -146.927917, epsilon));
122 testing.expect(math.approxEq(f32, c.im, 20.944065, epsilon));
123123}
124124
125125test "complex.cexp64" {
126126 const a = Complex(f64).new(5, 3);
127127 const c = exp(a);
128128
129 debug.assert(math.approxEq(f64, c.re, -146.927917, epsilon));
130 debug.assert(math.approxEq(f64, c.im, 20.944065, epsilon));
129 testing.expect(math.approxEq(f64, c.re, -146.927917, epsilon));
130 testing.expect(math.approxEq(f64, c.im, 20.944065, epsilon));
131131}
std/math/complex/index.zig+8-8
......@@ -1,5 +1,5 @@
11const std = @import("../../index.zig");
2const debug = std.debug;
2const testing = std.testing;
33const math = std.math;
44
55pub const abs = @import("abs.zig").abs;
......@@ -97,7 +97,7 @@ test "complex.add" {
9797 const b = Complex(f32).new(2, 7);
9898 const c = a.add(b);
9999
100 debug.assert(c.re == 7 and c.im == 10);
100 testing.expect(c.re == 7 and c.im == 10);
101101}
102102
103103test "complex.sub" {
......@@ -105,7 +105,7 @@ test "complex.sub" {
105105 const b = Complex(f32).new(2, 7);
106106 const c = a.sub(b);
107107
108 debug.assert(c.re == 3 and c.im == -4);
108 testing.expect(c.re == 3 and c.im == -4);
109109}
110110
111111test "complex.mul" {
......@@ -113,7 +113,7 @@ test "complex.mul" {
113113 const b = Complex(f32).new(2, 7);
114114 const c = a.mul(b);
115115
116 debug.assert(c.re == -11 and c.im == 41);
116 testing.expect(c.re == -11 and c.im == 41);
117117}
118118
119119test "complex.div" {
......@@ -121,7 +121,7 @@ test "complex.div" {
121121 const b = Complex(f32).new(2, 7);
122122 const c = a.div(b);
123123
124 debug.assert(math.approxEq(f32, c.re, f32(31) / 53, epsilon) and
124 testing.expect(math.approxEq(f32, c.re, f32(31) / 53, epsilon) and
125125 math.approxEq(f32, c.im, f32(-29) / 53, epsilon));
126126}
127127
......@@ -129,14 +129,14 @@ test "complex.conjugate" {
129129 const a = Complex(f32).new(5, 3);
130130 const c = a.conjugate();
131131
132 debug.assert(c.re == 5 and c.im == -3);
132 testing.expect(c.re == 5 and c.im == -3);
133133}
134134
135135test "complex.reciprocal" {
136136 const a = Complex(f32).new(5, 3);
137137 const c = a.reciprocal();
138138
139 debug.assert(math.approxEq(f32, c.re, f32(5) / 34, epsilon) and
139 testing.expect(math.approxEq(f32, c.re, f32(5) / 34, epsilon) and
140140 math.approxEq(f32, c.im, f32(-3) / 34, epsilon));
141141}
142142
......@@ -144,7 +144,7 @@ test "complex.magnitude" {
144144 const a = Complex(f32).new(5, 3);
145145 const c = a.magnitude();
146146
147 debug.assert(math.approxEq(f32, c, 5.83095, epsilon));
147 testing.expect(math.approxEq(f32, c, 5.83095, epsilon));
148148}
149149
150150test "complex.cmath" {
std/math/complex/log.zig+3-3
......@@ -1,5 +1,5 @@
11const std = @import("../../index.zig");
2const debug = std.debug;
2const testing = std.testing;
33const math = std.math;
44const cmath = math.complex;
55const Complex = cmath.Complex;
......@@ -18,6 +18,6 @@ test "complex.clog" {
1818 const a = Complex(f32).new(5, 3);
1919 const c = log(a);
2020
21 debug.assert(math.approxEq(f32, c.re, 1.763180, epsilon));
22 debug.assert(math.approxEq(f32, c.im, 0.540419, epsilon));
21 testing.expect(math.approxEq(f32, c.re, 1.763180, epsilon));
22 testing.expect(math.approxEq(f32, c.im, 0.540419, epsilon));
2323}
std/math/complex/pow.zig+3-3
......@@ -1,5 +1,5 @@
11const std = @import("../../index.zig");
2const debug = std.debug;
2const testing = std.testing;
33const math = std.math;
44const cmath = math.complex;
55const Complex = cmath.Complex;
......@@ -17,6 +17,6 @@ test "complex.cpow" {
1717 const b = Complex(f32).new(2.3, -1.3);
1818 const c = pow(Complex(f32), a, b);
1919
20 debug.assert(math.approxEq(f32, c.re, 58.049110, epsilon));
21 debug.assert(math.approxEq(f32, c.im, -101.003433, epsilon));
20 testing.expect(math.approxEq(f32, c.re, 58.049110, epsilon));
21 testing.expect(math.approxEq(f32, c.im, -101.003433, epsilon));
2222}
std/math/complex/proj.zig+2-2
......@@ -1,5 +1,5 @@
11const std = @import("../../index.zig");
2const debug = std.debug;
2const testing = std.testing;
33const math = std.math;
44const cmath = math.complex;
55const Complex = cmath.Complex;
......@@ -20,5 +20,5 @@ test "complex.cproj" {
2020 const a = Complex(f32).new(5, 3);
2121 const c = proj(a);
2222
23 debug.assert(c.re == 5 and c.im == 3);
23 testing.expect(c.re == 5 and c.im == 3);
2424}
std/math/complex/sin.zig+3-3
......@@ -1,5 +1,5 @@
11const std = @import("../../index.zig");
2const debug = std.debug;
2const testing = std.testing;
33const math = std.math;
44const cmath = math.complex;
55const Complex = cmath.Complex;
......@@ -17,6 +17,6 @@ test "complex.csin" {
1717 const a = Complex(f32).new(5, 3);
1818 const c = sin(a);
1919
20 debug.assert(math.approxEq(f32, c.re, -9.654126, epsilon));
21 debug.assert(math.approxEq(f32, c.im, 2.841692, epsilon));
20 testing.expect(math.approxEq(f32, c.re, -9.654126, epsilon));
21 testing.expect(math.approxEq(f32, c.im, 2.841692, epsilon));
2222}
std/math/complex/sinh.zig+5-5
......@@ -1,5 +1,5 @@
11const std = @import("../../index.zig");
2const debug = std.debug;
2const testing = std.testing;
33const math = std.math;
44const cmath = math.complex;
55const Complex = cmath.Complex;
......@@ -151,14 +151,14 @@ test "complex.csinh32" {
151151 const a = Complex(f32).new(5, 3);
152152 const c = sinh(a);
153153
154 debug.assert(math.approxEq(f32, c.re, -73.460617, epsilon));
155 debug.assert(math.approxEq(f32, c.im, 10.472508, epsilon));
154 testing.expect(math.approxEq(f32, c.re, -73.460617, epsilon));
155 testing.expect(math.approxEq(f32, c.im, 10.472508, epsilon));
156156}
157157
158158test "complex.csinh64" {
159159 const a = Complex(f64).new(5, 3);
160160 const c = sinh(a);
161161
162 debug.assert(math.approxEq(f64, c.re, -73.460617, epsilon));
163 debug.assert(math.approxEq(f64, c.im, 10.472508, epsilon));
162 testing.expect(math.approxEq(f64, c.re, -73.460617, epsilon));
163 testing.expect(math.approxEq(f64, c.im, 10.472508, epsilon));
164164}
std/math/complex/sqrt.zig+5-5
......@@ -1,5 +1,5 @@
11const std = @import("../../index.zig");
2const debug = std.debug;
2const testing = std.testing;
33const math = std.math;
44const cmath = math.complex;
55const Complex = cmath.Complex;
......@@ -125,14 +125,14 @@ test "complex.csqrt32" {
125125 const a = Complex(f32).new(5, 3);
126126 const c = sqrt(a);
127127
128 debug.assert(math.approxEq(f32, c.re, 2.327117, epsilon));
129 debug.assert(math.approxEq(f32, c.im, 0.644574, epsilon));
128 testing.expect(math.approxEq(f32, c.re, 2.327117, epsilon));
129 testing.expect(math.approxEq(f32, c.im, 0.644574, epsilon));
130130}
131131
132132test "complex.csqrt64" {
133133 const a = Complex(f64).new(5, 3);
134134 const c = sqrt(a);
135135
136 debug.assert(math.approxEq(f64, c.re, 2.3271175190399496, epsilon));
137 debug.assert(math.approxEq(f64, c.im, 0.6445742373246469, epsilon));
136 testing.expect(math.approxEq(f64, c.re, 2.3271175190399496, epsilon));
137 testing.expect(math.approxEq(f64, c.im, 0.6445742373246469, epsilon));
138138}
std/math/complex/tan.zig+3-3
......@@ -1,5 +1,5 @@
11const std = @import("../../index.zig");
2const debug = std.debug;
2const testing = std.testing;
33const math = std.math;
44const cmath = math.complex;
55const Complex = cmath.Complex;
......@@ -17,6 +17,6 @@ test "complex.ctan" {
1717 const a = Complex(f32).new(5, 3);
1818 const c = tan(a);
1919
20 debug.assert(math.approxEq(f32, c.re, -0.002708233, epsilon));
21 debug.assert(math.approxEq(f32, c.im, 1.004165, epsilon));
20 testing.expect(math.approxEq(f32, c.re, -0.002708233, epsilon));
21 testing.expect(math.approxEq(f32, c.im, 1.004165, epsilon));
2222}
std/math/complex/tanh.zig+5-5
......@@ -1,5 +1,5 @@
11const std = @import("../../index.zig");
2const debug = std.debug;
2const testing = std.testing;
33const math = std.math;
44const cmath = math.complex;
55const Complex = cmath.Complex;
......@@ -100,14 +100,14 @@ test "complex.ctanh32" {
100100 const a = Complex(f32).new(5, 3);
101101 const c = tanh(a);
102102
103 debug.assert(math.approxEq(f32, c.re, 0.999913, epsilon));
104 debug.assert(math.approxEq(f32, c.im, -0.000025, epsilon));
103 testing.expect(math.approxEq(f32, c.re, 0.999913, epsilon));
104 testing.expect(math.approxEq(f32, c.im, -0.000025, epsilon));
105105}
106106
107107test "complex.ctanh64" {
108108 const a = Complex(f64).new(5, 3);
109109 const c = tanh(a);
110110
111 debug.assert(math.approxEq(f64, c.re, 0.999913, epsilon));
112 debug.assert(math.approxEq(f64, c.im, -0.000025, epsilon));
111 testing.expect(math.approxEq(f64, c.re, 0.999913, epsilon));
112 testing.expect(math.approxEq(f64, c.im, -0.000025, epsilon));
113113}
std/math/copysign.zig+16-16
......@@ -1,6 +1,6 @@
11const std = @import("../index.zig");
22const math = std.math;
3const assert = std.debug.assert;
3const expect = std.testing.expect;
44const maxInt = std.math.maxInt;
55
66pub fn copysign(comptime T: type, x: T, y: T) T {
......@@ -40,28 +40,28 @@ fn copysign64(x: f64, y: f64) f64 {
4040}
4141
4242test "math.copysign" {
43 assert(copysign(f16, 1.0, 1.0) == copysign16(1.0, 1.0));
44 assert(copysign(f32, 1.0, 1.0) == copysign32(1.0, 1.0));
45 assert(copysign(f64, 1.0, 1.0) == copysign64(1.0, 1.0));
43 expect(copysign(f16, 1.0, 1.0) == copysign16(1.0, 1.0));
44 expect(copysign(f32, 1.0, 1.0) == copysign32(1.0, 1.0));
45 expect(copysign(f64, 1.0, 1.0) == copysign64(1.0, 1.0));
4646}
4747
4848test "math.copysign16" {
49 assert(copysign16(5.0, 1.0) == 5.0);
50 assert(copysign16(5.0, -1.0) == -5.0);
51 assert(copysign16(-5.0, -1.0) == -5.0);
52 assert(copysign16(-5.0, 1.0) == 5.0);
49 expect(copysign16(5.0, 1.0) == 5.0);
50 expect(copysign16(5.0, -1.0) == -5.0);
51 expect(copysign16(-5.0, -1.0) == -5.0);
52 expect(copysign16(-5.0, 1.0) == 5.0);
5353}
5454
5555test "math.copysign32" {
56 assert(copysign32(5.0, 1.0) == 5.0);
57 assert(copysign32(5.0, -1.0) == -5.0);
58 assert(copysign32(-5.0, -1.0) == -5.0);
59 assert(copysign32(-5.0, 1.0) == 5.0);
56 expect(copysign32(5.0, 1.0) == 5.0);
57 expect(copysign32(5.0, -1.0) == -5.0);
58 expect(copysign32(-5.0, -1.0) == -5.0);
59 expect(copysign32(-5.0, 1.0) == 5.0);
6060}
6161
6262test "math.copysign64" {
63 assert(copysign64(5.0, 1.0) == 5.0);
64 assert(copysign64(5.0, -1.0) == -5.0);
65 assert(copysign64(-5.0, -1.0) == -5.0);
66 assert(copysign64(-5.0, 1.0) == 5.0);
63 expect(copysign64(5.0, 1.0) == 5.0);
64 expect(copysign64(5.0, -1.0) == -5.0);
65 expect(copysign64(-5.0, -1.0) == -5.0);
66 expect(copysign64(-5.0, 1.0) == 5.0);
6767}
std/math/cos.zig+21-21
......@@ -6,7 +6,7 @@
66const builtin = @import("builtin");
77const std = @import("../index.zig");
88const math = std.math;
9const assert = std.debug.assert;
9const expect = std.testing.expect;
1010
1111pub fn cos(x: var) @typeOf(x) {
1212 const T = @typeOf(x);
......@@ -139,40 +139,40 @@ fn cos64(x_: f64) f64 {
139139}
140140
141141test "math.cos" {
142 assert(cos(f32(0.0)) == cos32(0.0));
143 assert(cos(f64(0.0)) == cos64(0.0));
142 expect(cos(f32(0.0)) == cos32(0.0));
143 expect(cos(f64(0.0)) == cos64(0.0));
144144}
145145
146146test "math.cos32" {
147147 const epsilon = 0.000001;
148148
149 assert(math.approxEq(f32, cos32(0.0), 1.0, epsilon));
150 assert(math.approxEq(f32, cos32(0.2), 0.980067, epsilon));
151 assert(math.approxEq(f32, cos32(0.8923), 0.627623, epsilon));
152 assert(math.approxEq(f32, cos32(1.5), 0.070737, epsilon));
153 assert(math.approxEq(f32, cos32(37.45), 0.969132, epsilon));
154 assert(math.approxEq(f32, cos32(89.123), 0.400798, epsilon));
149 expect(math.approxEq(f32, cos32(0.0), 1.0, epsilon));
150 expect(math.approxEq(f32, cos32(0.2), 0.980067, epsilon));
151 expect(math.approxEq(f32, cos32(0.8923), 0.627623, epsilon));
152 expect(math.approxEq(f32, cos32(1.5), 0.070737, epsilon));
153 expect(math.approxEq(f32, cos32(37.45), 0.969132, epsilon));
154 expect(math.approxEq(f32, cos32(89.123), 0.400798, epsilon));
155155}
156156
157157test "math.cos64" {
158158 const epsilon = 0.000001;
159159
160 assert(math.approxEq(f64, cos64(0.0), 1.0, epsilon));
161 assert(math.approxEq(f64, cos64(0.2), 0.980067, epsilon));
162 assert(math.approxEq(f64, cos64(0.8923), 0.627623, epsilon));
163 assert(math.approxEq(f64, cos64(1.5), 0.070737, epsilon));
164 assert(math.approxEq(f64, cos64(37.45), 0.969132, epsilon));
165 assert(math.approxEq(f64, cos64(89.123), 0.40080, epsilon));
160 expect(math.approxEq(f64, cos64(0.0), 1.0, epsilon));
161 expect(math.approxEq(f64, cos64(0.2), 0.980067, epsilon));
162 expect(math.approxEq(f64, cos64(0.8923), 0.627623, epsilon));
163 expect(math.approxEq(f64, cos64(1.5), 0.070737, epsilon));
164 expect(math.approxEq(f64, cos64(37.45), 0.969132, epsilon));
165 expect(math.approxEq(f64, cos64(89.123), 0.40080, epsilon));
166166}
167167
168168test "math.cos32.special" {
169 assert(math.isNan(cos32(math.inf(f32))));
170 assert(math.isNan(cos32(-math.inf(f32))));
171 assert(math.isNan(cos32(math.nan(f32))));
169 expect(math.isNan(cos32(math.inf(f32))));
170 expect(math.isNan(cos32(-math.inf(f32))));
171 expect(math.isNan(cos32(math.nan(f32))));
172172}
173173
174174test "math.cos64.special" {
175 assert(math.isNan(cos64(math.inf(f64))));
176 assert(math.isNan(cos64(-math.inf(f64))));
177 assert(math.isNan(cos64(math.nan(f64))));
175 expect(math.isNan(cos64(math.inf(f64))));
176 expect(math.isNan(cos64(-math.inf(f64))));
177 expect(math.isNan(cos64(math.nan(f64))));
178178}
std/math/cosh.zig+21-21
......@@ -8,7 +8,7 @@ const builtin = @import("builtin");
88const std = @import("../index.zig");
99const math = std.math;
1010const expo2 = @import("expo2.zig").expo2;
11const assert = std.debug.assert;
11const expect = std.testing.expect;
1212const maxInt = std.math.maxInt;
1313
1414pub fn cosh(x: var) @typeOf(x) {
......@@ -82,40 +82,40 @@ fn cosh64(x: f64) f64 {
8282}
8383
8484test "math.cosh" {
85 assert(cosh(f32(1.5)) == cosh32(1.5));
86 assert(cosh(f64(1.5)) == cosh64(1.5));
85 expect(cosh(f32(1.5)) == cosh32(1.5));
86 expect(cosh(f64(1.5)) == cosh64(1.5));
8787}
8888
8989test "math.cosh32" {
9090 const epsilon = 0.000001;
9191
92 assert(math.approxEq(f32, cosh32(0.0), 1.0, epsilon));
93 assert(math.approxEq(f32, cosh32(0.2), 1.020067, epsilon));
94 assert(math.approxEq(f32, cosh32(0.8923), 1.425225, epsilon));
95 assert(math.approxEq(f32, cosh32(1.5), 2.352410, epsilon));
92 expect(math.approxEq(f32, cosh32(0.0), 1.0, epsilon));
93 expect(math.approxEq(f32, cosh32(0.2), 1.020067, epsilon));
94 expect(math.approxEq(f32, cosh32(0.8923), 1.425225, epsilon));
95 expect(math.approxEq(f32, cosh32(1.5), 2.352410, epsilon));
9696}
9797
9898test "math.cosh64" {
9999 const epsilon = 0.000001;
100100
101 assert(math.approxEq(f64, cosh64(0.0), 1.0, epsilon));
102 assert(math.approxEq(f64, cosh64(0.2), 1.020067, epsilon));
103 assert(math.approxEq(f64, cosh64(0.8923), 1.425225, epsilon));
104 assert(math.approxEq(f64, cosh64(1.5), 2.352410, epsilon));
101 expect(math.approxEq(f64, cosh64(0.0), 1.0, epsilon));
102 expect(math.approxEq(f64, cosh64(0.2), 1.020067, epsilon));
103 expect(math.approxEq(f64, cosh64(0.8923), 1.425225, epsilon));
104 expect(math.approxEq(f64, cosh64(1.5), 2.352410, epsilon));
105105}
106106
107107test "math.cosh32.special" {
108 assert(cosh32(0.0) == 1.0);
109 assert(cosh32(-0.0) == 1.0);
110 assert(math.isPositiveInf(cosh32(math.inf(f32))));
111 assert(math.isPositiveInf(cosh32(-math.inf(f32))));
112 assert(math.isNan(cosh32(math.nan(f32))));
108 expect(cosh32(0.0) == 1.0);
109 expect(cosh32(-0.0) == 1.0);
110 expect(math.isPositiveInf(cosh32(math.inf(f32))));
111 expect(math.isPositiveInf(cosh32(-math.inf(f32))));
112 expect(math.isNan(cosh32(math.nan(f32))));
113113}
114114
115115test "math.cosh64.special" {
116 assert(cosh64(0.0) == 1.0);
117 assert(cosh64(-0.0) == 1.0);
118 assert(math.isPositiveInf(cosh64(math.inf(f64))));
119 assert(math.isPositiveInf(cosh64(-math.inf(f64))));
120 assert(math.isNan(cosh64(math.nan(f64))));
116 expect(cosh64(0.0) == 1.0);
117 expect(cosh64(-0.0) == 1.0);
118 expect(math.isPositiveInf(cosh64(math.inf(f64))));
119 expect(math.isPositiveInf(cosh64(-math.inf(f64))));
120 expect(math.isNan(cosh64(math.nan(f64))));
121121}
std/math/exp2.zig+16-16
......@@ -5,7 +5,7 @@
55
66const std = @import("../index.zig");
77const math = std.math;
8const assert = std.debug.assert;
8const expect = std.testing.expect;
99
1010pub fn exp2(x: var) @typeOf(x) {
1111 const T = @typeOf(x);
......@@ -415,35 +415,35 @@ fn exp2_64(x: f64) f64 {
415415}
416416
417417test "math.exp2" {
418 assert(exp2(f32(0.8923)) == exp2_32(0.8923));
419 assert(exp2(f64(0.8923)) == exp2_64(0.8923));
418 expect(exp2(f32(0.8923)) == exp2_32(0.8923));
419 expect(exp2(f64(0.8923)) == exp2_64(0.8923));
420420}
421421
422422test "math.exp2_32" {
423423 const epsilon = 0.000001;
424424
425 assert(exp2_32(0.0) == 1.0);
426 assert(math.approxEq(f32, exp2_32(0.2), 1.148698, epsilon));
427 assert(math.approxEq(f32, exp2_32(0.8923), 1.856133, epsilon));
428 assert(math.approxEq(f32, exp2_32(1.5), 2.828427, epsilon));
429 assert(math.approxEq(f32, exp2_32(37.45), 187747237888, epsilon));
425 expect(exp2_32(0.0) == 1.0);
426 expect(math.approxEq(f32, exp2_32(0.2), 1.148698, epsilon));
427 expect(math.approxEq(f32, exp2_32(0.8923), 1.856133, epsilon));
428 expect(math.approxEq(f32, exp2_32(1.5), 2.828427, epsilon));
429 expect(math.approxEq(f32, exp2_32(37.45), 187747237888, epsilon));
430430}
431431
432432test "math.exp2_64" {
433433 const epsilon = 0.000001;
434434
435 assert(exp2_64(0.0) == 1.0);
436 assert(math.approxEq(f64, exp2_64(0.2), 1.148698, epsilon));
437 assert(math.approxEq(f64, exp2_64(0.8923), 1.856133, epsilon));
438 assert(math.approxEq(f64, exp2_64(1.5), 2.828427, epsilon));
435 expect(exp2_64(0.0) == 1.0);
436 expect(math.approxEq(f64, exp2_64(0.2), 1.148698, epsilon));
437 expect(math.approxEq(f64, exp2_64(0.8923), 1.856133, epsilon));
438 expect(math.approxEq(f64, exp2_64(1.5), 2.828427, epsilon));
439439}
440440
441441test "math.exp2_32.special" {
442 assert(math.isPositiveInf(exp2_32(math.inf(f32))));
443 assert(math.isNan(exp2_32(math.nan(f32))));
442 expect(math.isPositiveInf(exp2_32(math.inf(f32))));
443 expect(math.isNan(exp2_32(math.nan(f32))));
444444}
445445
446446test "math.exp2_64.special" {
447 assert(math.isPositiveInf(exp2_64(math.inf(f64))));
448 assert(math.isNan(exp2_64(math.nan(f64))));
447 expect(math.isPositiveInf(exp2_64(math.inf(f64))));
448 expect(math.isNan(exp2_64(math.nan(f64))));
449449}
std/math/expm1.zig+19-19
......@@ -7,7 +7,7 @@
77const builtin = @import("builtin");
88const std = @import("../index.zig");
99const math = std.math;
10const assert = std.debug.assert;
10const expect = std.testing.expect;
1111
1212pub fn expm1(x: var) @typeOf(x) {
1313 const T = @typeOf(x);
......@@ -278,42 +278,42 @@ fn expm1_64(x_: f64) f64 {
278278}
279279
280280test "math.exp1m" {
281 assert(expm1(f32(0.0)) == expm1_32(0.0));
282 assert(expm1(f64(0.0)) == expm1_64(0.0));
281 expect(expm1(f32(0.0)) == expm1_32(0.0));
282 expect(expm1(f64(0.0)) == expm1_64(0.0));
283283}
284284
285285test "math.expm1_32" {
286286 const epsilon = 0.000001;
287287
288 assert(expm1_32(0.0) == 0.0);
289 assert(math.approxEq(f32, expm1_32(0.0), 0.0, epsilon));
290 assert(math.approxEq(f32, expm1_32(0.2), 0.221403, epsilon));
291 assert(math.approxEq(f32, expm1_32(0.8923), 1.440737, epsilon));
292 assert(math.approxEq(f32, expm1_32(1.5), 3.481689, epsilon));
288 expect(expm1_32(0.0) == 0.0);
289 expect(math.approxEq(f32, expm1_32(0.0), 0.0, epsilon));
290 expect(math.approxEq(f32, expm1_32(0.2), 0.221403, epsilon));
291 expect(math.approxEq(f32, expm1_32(0.8923), 1.440737, epsilon));
292 expect(math.approxEq(f32, expm1_32(1.5), 3.481689, epsilon));
293293}
294294
295295test "math.expm1_64" {
296296 const epsilon = 0.000001;
297297
298 assert(expm1_64(0.0) == 0.0);
299 assert(math.approxEq(f64, expm1_64(0.0), 0.0, epsilon));
300 assert(math.approxEq(f64, expm1_64(0.2), 0.221403, epsilon));
301 assert(math.approxEq(f64, expm1_64(0.8923), 1.440737, epsilon));
302 assert(math.approxEq(f64, expm1_64(1.5), 3.481689, epsilon));
298 expect(expm1_64(0.0) == 0.0);
299 expect(math.approxEq(f64, expm1_64(0.0), 0.0, epsilon));
300 expect(math.approxEq(f64, expm1_64(0.2), 0.221403, epsilon));
301 expect(math.approxEq(f64, expm1_64(0.8923), 1.440737, epsilon));
302 expect(math.approxEq(f64, expm1_64(1.5), 3.481689, epsilon));
303303}
304304
305305test "math.expm1_32.special" {
306306 const epsilon = 0.000001;
307307
308 assert(math.isPositiveInf(expm1_32(math.inf(f32))));
309 assert(expm1_32(-math.inf(f32)) == -1.0);
310 assert(math.isNan(expm1_32(math.nan(f32))));
308 expect(math.isPositiveInf(expm1_32(math.inf(f32))));
309 expect(expm1_32(-math.inf(f32)) == -1.0);
310 expect(math.isNan(expm1_32(math.nan(f32))));
311311}
312312
313313test "math.expm1_64.special" {
314314 const epsilon = 0.000001;
315315
316 assert(math.isPositiveInf(expm1_64(math.inf(f64))));
317 assert(expm1_64(-math.inf(f64)) == -1.0);
318 assert(math.isNan(expm1_64(math.nan(f64))));
316 expect(math.isPositiveInf(expm1_64(math.inf(f64))));
317 expect(expm1_64(-math.inf(f64)) == -1.0);
318 expect(math.isNan(expm1_64(math.nan(f64))));
319319}
std/math/fabs.zig+19-19
......@@ -5,7 +5,7 @@
55
66const std = @import("../index.zig");
77const math = std.math;
8const assert = std.debug.assert;
8const expect = std.testing.expect;
99const maxInt = std.math.maxInt;
1010
1111pub fn fabs(x: var) @typeOf(x) {
......@@ -37,40 +37,40 @@ fn fabs64(x: f64) f64 {
3737}
3838
3939test "math.fabs" {
40 assert(fabs(f16(1.0)) == fabs16(1.0));
41 assert(fabs(f32(1.0)) == fabs32(1.0));
42 assert(fabs(f64(1.0)) == fabs64(1.0));
40 expect(fabs(f16(1.0)) == fabs16(1.0));
41 expect(fabs(f32(1.0)) == fabs32(1.0));
42 expect(fabs(f64(1.0)) == fabs64(1.0));
4343}
4444
4545test "math.fabs16" {
46 assert(fabs16(1.0) == 1.0);
47 assert(fabs16(-1.0) == 1.0);
46 expect(fabs16(1.0) == 1.0);
47 expect(fabs16(-1.0) == 1.0);
4848}
4949
5050test "math.fabs32" {
51 assert(fabs32(1.0) == 1.0);
52 assert(fabs32(-1.0) == 1.0);
51 expect(fabs32(1.0) == 1.0);
52 expect(fabs32(-1.0) == 1.0);
5353}
5454
5555test "math.fabs64" {
56 assert(fabs64(1.0) == 1.0);
57 assert(fabs64(-1.0) == 1.0);
56 expect(fabs64(1.0) == 1.0);
57 expect(fabs64(-1.0) == 1.0);
5858}
5959
6060test "math.fabs16.special" {
61 assert(math.isPositiveInf(fabs(math.inf(f16))));
62 assert(math.isPositiveInf(fabs(-math.inf(f16))));
63 assert(math.isNan(fabs(math.nan(f16))));
61 expect(math.isPositiveInf(fabs(math.inf(f16))));
62 expect(math.isPositiveInf(fabs(-math.inf(f16))));
63 expect(math.isNan(fabs(math.nan(f16))));
6464}
6565
6666test "math.fabs32.special" {
67 assert(math.isPositiveInf(fabs(math.inf(f32))));
68 assert(math.isPositiveInf(fabs(-math.inf(f32))));
69 assert(math.isNan(fabs(math.nan(f32))));
67 expect(math.isPositiveInf(fabs(math.inf(f32))));
68 expect(math.isPositiveInf(fabs(-math.inf(f32))));
69 expect(math.isNan(fabs(math.nan(f32))));
7070}
7171
7272test "math.fabs64.special" {
73 assert(math.isPositiveInf(fabs(math.inf(f64))));
74 assert(math.isPositiveInf(fabs(-math.inf(f64))));
75 assert(math.isNan(fabs(math.nan(f64))));
73 expect(math.isPositiveInf(fabs(math.inf(f64))));
74 expect(math.isPositiveInf(fabs(-math.inf(f64))));
75 expect(math.isNan(fabs(math.nan(f64))));
7676}
std/math/floor.zig+28-28
......@@ -5,7 +5,7 @@
55// - floor(nan) = nan
66
77const builtin = @import("builtin");
8const assert = std.debug.assert;
8const expect = std.testing.expect;
99const std = @import("../index.zig");
1010const math = std.math;
1111
......@@ -117,49 +117,49 @@ fn floor64(x: f64) f64 {
117117}
118118
119119test "math.floor" {
120 assert(floor(f16(1.3)) == floor16(1.3));
121 assert(floor(f32(1.3)) == floor32(1.3));
122 assert(floor(f64(1.3)) == floor64(1.3));
120 expect(floor(f16(1.3)) == floor16(1.3));
121 expect(floor(f32(1.3)) == floor32(1.3));
122 expect(floor(f64(1.3)) == floor64(1.3));
123123}
124124
125125test "math.floor16" {
126 assert(floor16(1.3) == 1.0);
127 assert(floor16(-1.3) == -2.0);
128 assert(floor16(0.2) == 0.0);
126 expect(floor16(1.3) == 1.0);
127 expect(floor16(-1.3) == -2.0);
128 expect(floor16(0.2) == 0.0);
129129}
130130
131131test "math.floor32" {
132 assert(floor32(1.3) == 1.0);
133 assert(floor32(-1.3) == -2.0);
134 assert(floor32(0.2) == 0.0);
132 expect(floor32(1.3) == 1.0);
133 expect(floor32(-1.3) == -2.0);
134 expect(floor32(0.2) == 0.0);
135135}
136136
137137test "math.floor64" {
138 assert(floor64(1.3) == 1.0);
139 assert(floor64(-1.3) == -2.0);
140 assert(floor64(0.2) == 0.0);
138 expect(floor64(1.3) == 1.0);
139 expect(floor64(-1.3) == -2.0);
140 expect(floor64(0.2) == 0.0);
141141}
142142
143143test "math.floor16.special" {
144 assert(floor16(0.0) == 0.0);
145 assert(floor16(-0.0) == -0.0);
146 assert(math.isPositiveInf(floor16(math.inf(f16))));
147 assert(math.isNegativeInf(floor16(-math.inf(f16))));
148 assert(math.isNan(floor16(math.nan(f16))));
144 expect(floor16(0.0) == 0.0);
145 expect(floor16(-0.0) == -0.0);
146 expect(math.isPositiveInf(floor16(math.inf(f16))));
147 expect(math.isNegativeInf(floor16(-math.inf(f16))));
148 expect(math.isNan(floor16(math.nan(f16))));
149149}
150150
151151test "math.floor32.special" {
152 assert(floor32(0.0) == 0.0);
153 assert(floor32(-0.0) == -0.0);
154 assert(math.isPositiveInf(floor32(math.inf(f32))));
155 assert(math.isNegativeInf(floor32(-math.inf(f32))));
156 assert(math.isNan(floor32(math.nan(f32))));
152 expect(floor32(0.0) == 0.0);
153 expect(floor32(-0.0) == -0.0);
154 expect(math.isPositiveInf(floor32(math.inf(f32))));
155 expect(math.isNegativeInf(floor32(-math.inf(f32))));
156 expect(math.isNan(floor32(math.nan(f32))));
157157}
158158
159159test "math.floor64.special" {
160 assert(floor64(0.0) == 0.0);
161 assert(floor64(-0.0) == -0.0);
162 assert(math.isPositiveInf(floor64(math.inf(f64))));
163 assert(math.isNegativeInf(floor64(-math.inf(f64))));
164 assert(math.isNan(floor64(math.nan(f64))));
160 expect(floor64(0.0) == 0.0);
161 expect(floor64(-0.0) == -0.0);
162 expect(math.isPositiveInf(floor64(math.inf(f64))));
163 expect(math.isNegativeInf(floor64(-math.inf(f64))));
164 expect(math.isNan(floor64(math.nan(f64))));
165165}
std/math/fma.zig+17-17
......@@ -1,6 +1,6 @@
11const std = @import("../index.zig");
22const math = std.math;
3const assert = std.debug.assert;
3const expect = std.testing.expect;
44
55pub fn fma(comptime T: type, x: T, y: T, z: T) T {
66 return switch (T) {
......@@ -135,30 +135,30 @@ fn add_and_denorm(a: f64, b: f64, scale: i32) f64 {
135135}
136136
137137test "math.fma" {
138 assert(fma(f32, 0.0, 1.0, 1.0) == fma32(0.0, 1.0, 1.0));
139 assert(fma(f64, 0.0, 1.0, 1.0) == fma64(0.0, 1.0, 1.0));
138 expect(fma(f32, 0.0, 1.0, 1.0) == fma32(0.0, 1.0, 1.0));
139 expect(fma(f64, 0.0, 1.0, 1.0) == fma64(0.0, 1.0, 1.0));
140140}
141141
142142test "math.fma32" {
143143 const epsilon = 0.000001;
144144
145 assert(math.approxEq(f32, fma32(0.0, 5.0, 9.124), 9.124, epsilon));
146 assert(math.approxEq(f32, fma32(0.2, 5.0, 9.124), 10.124, epsilon));
147 assert(math.approxEq(f32, fma32(0.8923, 5.0, 9.124), 13.5855, epsilon));
148 assert(math.approxEq(f32, fma32(1.5, 5.0, 9.124), 16.624, epsilon));
149 assert(math.approxEq(f32, fma32(37.45, 5.0, 9.124), 196.374004, epsilon));
150 assert(math.approxEq(f32, fma32(89.123, 5.0, 9.124), 454.739005, epsilon));
151 assert(math.approxEq(f32, fma32(123123.234375, 5.0, 9.124), 615625.295875, epsilon));
145 expect(math.approxEq(f32, fma32(0.0, 5.0, 9.124), 9.124, epsilon));
146 expect(math.approxEq(f32, fma32(0.2, 5.0, 9.124), 10.124, epsilon));
147 expect(math.approxEq(f32, fma32(0.8923, 5.0, 9.124), 13.5855, epsilon));
148 expect(math.approxEq(f32, fma32(1.5, 5.0, 9.124), 16.624, epsilon));
149 expect(math.approxEq(f32, fma32(37.45, 5.0, 9.124), 196.374004, epsilon));
150 expect(math.approxEq(f32, fma32(89.123, 5.0, 9.124), 454.739005, epsilon));
151 expect(math.approxEq(f32, fma32(123123.234375, 5.0, 9.124), 615625.295875, epsilon));
152152}
153153
154154test "math.fma64" {
155155 const epsilon = 0.000001;
156156
157 assert(math.approxEq(f64, fma64(0.0, 5.0, 9.124), 9.124, epsilon));
158 assert(math.approxEq(f64, fma64(0.2, 5.0, 9.124), 10.124, epsilon));
159 assert(math.approxEq(f64, fma64(0.8923, 5.0, 9.124), 13.5855, epsilon));
160 assert(math.approxEq(f64, fma64(1.5, 5.0, 9.124), 16.624, epsilon));
161 assert(math.approxEq(f64, fma64(37.45, 5.0, 9.124), 196.374, epsilon));
162 assert(math.approxEq(f64, fma64(89.123, 5.0, 9.124), 454.739, epsilon));
163 assert(math.approxEq(f64, fma64(123123.234375, 5.0, 9.124), 615625.295875, epsilon));
157 expect(math.approxEq(f64, fma64(0.0, 5.0, 9.124), 9.124, epsilon));
158 expect(math.approxEq(f64, fma64(0.2, 5.0, 9.124), 10.124, epsilon));
159 expect(math.approxEq(f64, fma64(0.8923, 5.0, 9.124), 13.5855, epsilon));
160 expect(math.approxEq(f64, fma64(1.5, 5.0, 9.124), 16.624, epsilon));
161 expect(math.approxEq(f64, fma64(37.45, 5.0, 9.124), 196.374, epsilon));
162 expect(math.approxEq(f64, fma64(89.123, 5.0, 9.124), 454.739, epsilon));
163 expect(math.approxEq(f64, fma64(123123.234375, 5.0, 9.124), 615625.295875, epsilon));
164164}
std/math/frexp.zig+17-17
......@@ -6,7 +6,7 @@
66
77const std = @import("../index.zig");
88const math = std.math;
9const assert = std.debug.assert;
9const expect = std.testing.expect;
1010
1111fn frexp_result(comptime T: type) type {
1212 return struct {
......@@ -103,11 +103,11 @@ fn frexp64(x: f64) frexp64_result {
103103test "math.frexp" {
104104 const a = frexp(f32(1.3));
105105 const b = frexp32(1.3);
106 assert(a.significand == b.significand and a.exponent == b.exponent);
106 expect(a.significand == b.significand and a.exponent == b.exponent);
107107
108108 const c = frexp(f64(1.3));
109109 const d = frexp64(1.3);
110 assert(c.significand == d.significand and c.exponent == d.exponent);
110 expect(c.significand == d.significand and c.exponent == d.exponent);
111111}
112112
113113test "math.frexp32" {
......@@ -115,10 +115,10 @@ test "math.frexp32" {
115115 var r: frexp32_result = undefined;
116116
117117 r = frexp32(1.3);
118 assert(math.approxEq(f32, r.significand, 0.65, epsilon) and r.exponent == 1);
118 expect(math.approxEq(f32, r.significand, 0.65, epsilon) and r.exponent == 1);
119119
120120 r = frexp32(78.0234);
121 assert(math.approxEq(f32, r.significand, 0.609558, epsilon) and r.exponent == 7);
121 expect(math.approxEq(f32, r.significand, 0.609558, epsilon) and r.exponent == 7);
122122}
123123
124124test "math.frexp64" {
......@@ -126,46 +126,46 @@ test "math.frexp64" {
126126 var r: frexp64_result = undefined;
127127
128128 r = frexp64(1.3);
129 assert(math.approxEq(f64, r.significand, 0.65, epsilon) and r.exponent == 1);
129 expect(math.approxEq(f64, r.significand, 0.65, epsilon) and r.exponent == 1);
130130
131131 r = frexp64(78.0234);
132 assert(math.approxEq(f64, r.significand, 0.609558, epsilon) and r.exponent == 7);
132 expect(math.approxEq(f64, r.significand, 0.609558, epsilon) and r.exponent == 7);
133133}
134134
135135test "math.frexp32.special" {
136136 var r: frexp32_result = undefined;
137137
138138 r = frexp32(0.0);
139 assert(r.significand == 0.0 and r.exponent == 0);
139 expect(r.significand == 0.0 and r.exponent == 0);
140140
141141 r = frexp32(-0.0);
142 assert(r.significand == -0.0 and r.exponent == 0);
142 expect(r.significand == -0.0 and r.exponent == 0);
143143
144144 r = frexp32(math.inf(f32));
145 assert(math.isPositiveInf(r.significand) and r.exponent == 0);
145 expect(math.isPositiveInf(r.significand) and r.exponent == 0);
146146
147147 r = frexp32(-math.inf(f32));
148 assert(math.isNegativeInf(r.significand) and r.exponent == 0);
148 expect(math.isNegativeInf(r.significand) and r.exponent == 0);
149149
150150 r = frexp32(math.nan(f32));
151 assert(math.isNan(r.significand));
151 expect(math.isNan(r.significand));
152152}
153153
154154test "math.frexp64.special" {
155155 var r: frexp64_result = undefined;
156156
157157 r = frexp64(0.0);
158 assert(r.significand == 0.0 and r.exponent == 0);
158 expect(r.significand == 0.0 and r.exponent == 0);
159159
160160 r = frexp64(-0.0);
161 assert(r.significand == -0.0 and r.exponent == 0);
161 expect(r.significand == -0.0 and r.exponent == 0);
162162
163163 r = frexp64(math.inf(f64));
164 assert(math.isPositiveInf(r.significand) and r.exponent == 0);
164 expect(math.isPositiveInf(r.significand) and r.exponent == 0);
165165
166166 r = frexp64(-math.inf(f64));
167 assert(math.isNegativeInf(r.significand) and r.exponent == 0);
167 expect(math.isNegativeInf(r.significand) and r.exponent == 0);
168168
169169 r = frexp64(math.nan(f64));
170 assert(math.isNan(r.significand));
170 expect(math.isNan(r.significand));
171171}
std/math/hypot.zig+29-29
......@@ -7,7 +7,7 @@
77
88const std = @import("../index.zig");
99const math = std.math;
10const assert = std.debug.assert;
10const expect = std.testing.expect;
1111const maxInt = std.math.maxInt;
1212
1313pub fn hypot(comptime T: type, x: T, y: T) T {
......@@ -115,48 +115,48 @@ fn hypot64(x: f64, y: f64) f64 {
115115}
116116
117117test "math.hypot" {
118 assert(hypot(f32, 0.0, -1.2) == hypot32(0.0, -1.2));
119 assert(hypot(f64, 0.0, -1.2) == hypot64(0.0, -1.2));
118 expect(hypot(f32, 0.0, -1.2) == hypot32(0.0, -1.2));
119 expect(hypot(f64, 0.0, -1.2) == hypot64(0.0, -1.2));
120120}
121121
122122test "math.hypot32" {
123123 const epsilon = 0.000001;
124124
125 assert(math.approxEq(f32, hypot32(0.0, -1.2), 1.2, epsilon));
126 assert(math.approxEq(f32, hypot32(0.2, -0.34), 0.394462, epsilon));
127 assert(math.approxEq(f32, hypot32(0.8923, 2.636890), 2.783772, epsilon));
128 assert(math.approxEq(f32, hypot32(1.5, 5.25), 5.460083, epsilon));
129 assert(math.approxEq(f32, hypot32(37.45, 159.835), 164.163742, epsilon));
130 assert(math.approxEq(f32, hypot32(89.123, 382.028905), 392.286865, epsilon));
131 assert(math.approxEq(f32, hypot32(123123.234375, 529428.707813), 543556.875, epsilon));
125 expect(math.approxEq(f32, hypot32(0.0, -1.2), 1.2, epsilon));
126 expect(math.approxEq(f32, hypot32(0.2, -0.34), 0.394462, epsilon));
127 expect(math.approxEq(f32, hypot32(0.8923, 2.636890), 2.783772, epsilon));
128 expect(math.approxEq(f32, hypot32(1.5, 5.25), 5.460083, epsilon));
129 expect(math.approxEq(f32, hypot32(37.45, 159.835), 164.163742, epsilon));
130 expect(math.approxEq(f32, hypot32(89.123, 382.028905), 392.286865, epsilon));
131 expect(math.approxEq(f32, hypot32(123123.234375, 529428.707813), 543556.875, epsilon));
132132}
133133
134134test "math.hypot64" {
135135 const epsilon = 0.000001;
136136
137 assert(math.approxEq(f64, hypot64(0.0, -1.2), 1.2, epsilon));
138 assert(math.approxEq(f64, hypot64(0.2, -0.34), 0.394462, epsilon));
139 assert(math.approxEq(f64, hypot64(0.8923, 2.636890), 2.783772, epsilon));
140 assert(math.approxEq(f64, hypot64(1.5, 5.25), 5.460082, epsilon));
141 assert(math.approxEq(f64, hypot64(37.45, 159.835), 164.163728, epsilon));
142 assert(math.approxEq(f64, hypot64(89.123, 382.028905), 392.286876, epsilon));
143 assert(math.approxEq(f64, hypot64(123123.234375, 529428.707813), 543556.885247, epsilon));
137 expect(math.approxEq(f64, hypot64(0.0, -1.2), 1.2, epsilon));
138 expect(math.approxEq(f64, hypot64(0.2, -0.34), 0.394462, epsilon));
139 expect(math.approxEq(f64, hypot64(0.8923, 2.636890), 2.783772, epsilon));
140 expect(math.approxEq(f64, hypot64(1.5, 5.25), 5.460082, epsilon));
141 expect(math.approxEq(f64, hypot64(37.45, 159.835), 164.163728, epsilon));
142 expect(math.approxEq(f64, hypot64(89.123, 382.028905), 392.286876, epsilon));
143 expect(math.approxEq(f64, hypot64(123123.234375, 529428.707813), 543556.885247, epsilon));
144144}
145145
146146test "math.hypot32.special" {
147 assert(math.isPositiveInf(hypot32(math.inf(f32), 0.0)));
148 assert(math.isPositiveInf(hypot32(-math.inf(f32), 0.0)));
149 assert(math.isPositiveInf(hypot32(0.0, math.inf(f32))));
150 assert(math.isPositiveInf(hypot32(0.0, -math.inf(f32))));
151 assert(math.isNan(hypot32(math.nan(f32), 0.0)));
152 assert(math.isNan(hypot32(0.0, math.nan(f32))));
147 expect(math.isPositiveInf(hypot32(math.inf(f32), 0.0)));
148 expect(math.isPositiveInf(hypot32(-math.inf(f32), 0.0)));
149 expect(math.isPositiveInf(hypot32(0.0, math.inf(f32))));
150 expect(math.isPositiveInf(hypot32(0.0, -math.inf(f32))));
151 expect(math.isNan(hypot32(math.nan(f32), 0.0)));
152 expect(math.isNan(hypot32(0.0, math.nan(f32))));
153153}
154154
155155test "math.hypot64.special" {
156 assert(math.isPositiveInf(hypot64(math.inf(f64), 0.0)));
157 assert(math.isPositiveInf(hypot64(-math.inf(f64), 0.0)));
158 assert(math.isPositiveInf(hypot64(0.0, math.inf(f64))));
159 assert(math.isPositiveInf(hypot64(0.0, -math.inf(f64))));
160 assert(math.isNan(hypot64(math.nan(f64), 0.0)));
161 assert(math.isNan(hypot64(0.0, math.nan(f64))));
156 expect(math.isPositiveInf(hypot64(math.inf(f64), 0.0)));
157 expect(math.isPositiveInf(hypot64(-math.inf(f64), 0.0)));
158 expect(math.isPositiveInf(hypot64(0.0, math.inf(f64))));
159 expect(math.isPositiveInf(hypot64(0.0, -math.inf(f64))));
160 expect(math.isNan(hypot64(math.nan(f64), 0.0)));
161 expect(math.isNan(hypot64(0.0, math.nan(f64))));
162162}
std/math/ilogb.zig+23-23
......@@ -6,7 +6,7 @@
66
77const std = @import("../index.zig");
88const math = std.math;
9const assert = std.debug.assert;
9const expect = std.testing.expect;
1010const maxInt = std.math.maxInt;
1111const minInt = std.math.minInt;
1212
......@@ -95,38 +95,38 @@ fn ilogb64(x: f64) i32 {
9595}
9696
9797test "math.ilogb" {
98 assert(ilogb(f32(0.2)) == ilogb32(0.2));
99 assert(ilogb(f64(0.2)) == ilogb64(0.2));
98 expect(ilogb(f32(0.2)) == ilogb32(0.2));
99 expect(ilogb(f64(0.2)) == ilogb64(0.2));
100100}
101101
102102test "math.ilogb32" {
103 assert(ilogb32(0.0) == fp_ilogb0);
104 assert(ilogb32(0.5) == -1);
105 assert(ilogb32(0.8923) == -1);
106 assert(ilogb32(10.0) == 3);
107 assert(ilogb32(-123984) == 16);
108 assert(ilogb32(2398.23) == 11);
103 expect(ilogb32(0.0) == fp_ilogb0);
104 expect(ilogb32(0.5) == -1);
105 expect(ilogb32(0.8923) == -1);
106 expect(ilogb32(10.0) == 3);
107 expect(ilogb32(-123984) == 16);
108 expect(ilogb32(2398.23) == 11);
109109}
110110
111111test "math.ilogb64" {
112 assert(ilogb64(0.0) == fp_ilogb0);
113 assert(ilogb64(0.5) == -1);
114 assert(ilogb64(0.8923) == -1);
115 assert(ilogb64(10.0) == 3);
116 assert(ilogb64(-123984) == 16);
117 assert(ilogb64(2398.23) == 11);
112 expect(ilogb64(0.0) == fp_ilogb0);
113 expect(ilogb64(0.5) == -1);
114 expect(ilogb64(0.8923) == -1);
115 expect(ilogb64(10.0) == 3);
116 expect(ilogb64(-123984) == 16);
117 expect(ilogb64(2398.23) == 11);
118118}
119119
120120test "math.ilogb32.special" {
121 assert(ilogb32(math.inf(f32)) == maxInt(i32));
122 assert(ilogb32(-math.inf(f32)) == maxInt(i32));
123 assert(ilogb32(0.0) == minInt(i32));
124 assert(ilogb32(math.nan(f32)) == maxInt(i32));
121 expect(ilogb32(math.inf(f32)) == maxInt(i32));
122 expect(ilogb32(-math.inf(f32)) == maxInt(i32));
123 expect(ilogb32(0.0) == minInt(i32));
124 expect(ilogb32(math.nan(f32)) == maxInt(i32));
125125}
126126
127127test "math.ilogb64.special" {
128 assert(ilogb64(math.inf(f64)) == maxInt(i32));
129 assert(ilogb64(-math.inf(f64)) == maxInt(i32));
130 assert(ilogb64(0.0) == minInt(i32));
131 assert(ilogb64(math.nan(f64)) == maxInt(i32));
128 expect(ilogb64(math.inf(f64)) == maxInt(i32));
129 expect(ilogb64(-math.inf(f64)) == maxInt(i32));
130 expect(ilogb64(0.0) == minInt(i32));
131 expect(ilogb64(math.nan(f64)) == maxInt(i32));
132132}
std/math/index.zig+172-171
......@@ -2,6 +2,7 @@ const builtin = @import("builtin");
22const std = @import("../index.zig");
33const TypeId = builtin.TypeId;
44const assert = std.debug.assert;
5const testing = std.testing;
56
67pub const e = 2.71828182845904523536028747135266249775724709369995;
78pub const pi = 3.14159265358979323846264338327950288419716939937510;
......@@ -240,7 +241,7 @@ pub fn min(x: var, y: var) @typeOf(x + y) {
240241}
241242
242243test "math.min" {
243 assert(min(i32(-1), i32(2)) == -1);
244 testing.expect(min(i32(-1), i32(2)) == -1);
244245}
245246
246247pub fn max(x: var, y: var) @typeOf(x + y) {
......@@ -248,7 +249,7 @@ pub fn max(x: var, y: var) @typeOf(x + y) {
248249}
249250
250251test "math.max" {
251 assert(max(i32(-1), i32(2)) == 2);
252 testing.expect(max(i32(-1), i32(2)) == 2);
252253}
253254
254255pub fn mul(comptime T: type, a: T, b: T) (error{Overflow}!T) {
......@@ -293,10 +294,10 @@ pub fn shl(comptime T: type, a: T, shift_amt: var) T {
293294}
294295
295296test "math.shl" {
296 assert(shl(u8, 0b11111111, usize(3)) == 0b11111000);
297 assert(shl(u8, 0b11111111, usize(8)) == 0);
298 assert(shl(u8, 0b11111111, usize(9)) == 0);
299 assert(shl(u8, 0b11111111, isize(-2)) == 0b00111111);
297 testing.expect(shl(u8, 0b11111111, usize(3)) == 0b11111000);
298 testing.expect(shl(u8, 0b11111111, usize(8)) == 0);
299 testing.expect(shl(u8, 0b11111111, usize(9)) == 0);
300 testing.expect(shl(u8, 0b11111111, isize(-2)) == 0b00111111);
300301}
301302
302303/// Shifts right. Overflowed bits are truncated.
......@@ -317,10 +318,10 @@ pub fn shr(comptime T: type, a: T, shift_amt: var) T {
317318}
318319
319320test "math.shr" {
320 assert(shr(u8, 0b11111111, usize(3)) == 0b00011111);
321 assert(shr(u8, 0b11111111, usize(8)) == 0);
322 assert(shr(u8, 0b11111111, usize(9)) == 0);
323 assert(shr(u8, 0b11111111, isize(-2)) == 0b11111100);
321 testing.expect(shr(u8, 0b11111111, usize(3)) == 0b00011111);
322 testing.expect(shr(u8, 0b11111111, usize(8)) == 0);
323 testing.expect(shr(u8, 0b11111111, usize(9)) == 0);
324 testing.expect(shr(u8, 0b11111111, isize(-2)) == 0b11111100);
324325}
325326
326327/// Rotates right. Only unsigned values can be rotated.
......@@ -335,11 +336,11 @@ pub fn rotr(comptime T: type, x: T, r: var) T {
335336}
336337
337338test "math.rotr" {
338 assert(rotr(u8, 0b00000001, usize(0)) == 0b00000001);
339 assert(rotr(u8, 0b00000001, usize(9)) == 0b10000000);
340 assert(rotr(u8, 0b00000001, usize(8)) == 0b00000001);
341 assert(rotr(u8, 0b00000001, usize(4)) == 0b00010000);
342 assert(rotr(u8, 0b00000001, isize(-1)) == 0b00000010);
339 testing.expect(rotr(u8, 0b00000001, usize(0)) == 0b00000001);
340 testing.expect(rotr(u8, 0b00000001, usize(9)) == 0b10000000);
341 testing.expect(rotr(u8, 0b00000001, usize(8)) == 0b00000001);
342 testing.expect(rotr(u8, 0b00000001, usize(4)) == 0b00010000);
343 testing.expect(rotr(u8, 0b00000001, isize(-1)) == 0b00000010);
343344}
344345
345346/// Rotates left. Only unsigned values can be rotated.
......@@ -354,11 +355,11 @@ pub fn rotl(comptime T: type, x: T, r: var) T {
354355}
355356
356357test "math.rotl" {
357 assert(rotl(u8, 0b00000001, usize(0)) == 0b00000001);
358 assert(rotl(u8, 0b00000001, usize(9)) == 0b00000010);
359 assert(rotl(u8, 0b00000001, usize(8)) == 0b00000001);
360 assert(rotl(u8, 0b00000001, usize(4)) == 0b00010000);
361 assert(rotl(u8, 0b00000001, isize(-1)) == 0b10000000);
358 testing.expect(rotl(u8, 0b00000001, usize(0)) == 0b00000001);
359 testing.expect(rotl(u8, 0b00000001, usize(9)) == 0b00000010);
360 testing.expect(rotl(u8, 0b00000001, usize(8)) == 0b00000001);
361 testing.expect(rotl(u8, 0b00000001, usize(4)) == 0b00010000);
362 testing.expect(rotl(u8, 0b00000001, isize(-1)) == 0b10000000);
362363}
363364
364365pub fn Log2Int(comptime T: type) type {
......@@ -389,50 +390,50 @@ pub fn IntFittingRange(comptime from: comptime_int, comptime to: comptime_int) t
389390}
390391
391392test "math.IntFittingRange" {
392 assert(IntFittingRange(0, 0) == u0);
393 assert(IntFittingRange(0, 1) == u1);
394 assert(IntFittingRange(0, 2) == u2);
395 assert(IntFittingRange(0, 3) == u2);
396 assert(IntFittingRange(0, 4) == u3);
397 assert(IntFittingRange(0, 7) == u3);
398 assert(IntFittingRange(0, 8) == u4);
399 assert(IntFittingRange(0, 9) == u4);
400 assert(IntFittingRange(0, 15) == u4);
401 assert(IntFittingRange(0, 16) == u5);
402 assert(IntFittingRange(0, 17) == u5);
403 assert(IntFittingRange(0, 4095) == u12);
404 assert(IntFittingRange(2000, 4095) == u12);
405 assert(IntFittingRange(0, 4096) == u13);
406 assert(IntFittingRange(2000, 4096) == u13);
407 assert(IntFittingRange(0, 4097) == u13);
408 assert(IntFittingRange(2000, 4097) == u13);
409 assert(IntFittingRange(0, 123456789123456798123456789) == u87);
410 assert(IntFittingRange(0, 123456789123456798123456789123456789123456798123456789) == u177);
411
412 assert(IntFittingRange(-1, -1) == i1);
413 assert(IntFittingRange(-1, 0) == i1);
414 assert(IntFittingRange(-1, 1) == i2);
415 assert(IntFittingRange(-2, -2) == i2);
416 assert(IntFittingRange(-2, -1) == i2);
417 assert(IntFittingRange(-2, 0) == i2);
418 assert(IntFittingRange(-2, 1) == i2);
419 assert(IntFittingRange(-2, 2) == i3);
420 assert(IntFittingRange(-1, 2) == i3);
421 assert(IntFittingRange(-1, 3) == i3);
422 assert(IntFittingRange(-1, 4) == i4);
423 assert(IntFittingRange(-1, 7) == i4);
424 assert(IntFittingRange(-1, 8) == i5);
425 assert(IntFittingRange(-1, 9) == i5);
426 assert(IntFittingRange(-1, 15) == i5);
427 assert(IntFittingRange(-1, 16) == i6);
428 assert(IntFittingRange(-1, 17) == i6);
429 assert(IntFittingRange(-1, 4095) == i13);
430 assert(IntFittingRange(-4096, 4095) == i13);
431 assert(IntFittingRange(-1, 4096) == i14);
432 assert(IntFittingRange(-4097, 4095) == i14);
433 assert(IntFittingRange(-1, 4097) == i14);
434 assert(IntFittingRange(-1, 123456789123456798123456789) == i88);
435 assert(IntFittingRange(-1, 123456789123456798123456789123456789123456798123456789) == i178);
393 testing.expect(IntFittingRange(0, 0) == u0);
394 testing.expect(IntFittingRange(0, 1) == u1);
395 testing.expect(IntFittingRange(0, 2) == u2);
396 testing.expect(IntFittingRange(0, 3) == u2);
397 testing.expect(IntFittingRange(0, 4) == u3);
398 testing.expect(IntFittingRange(0, 7) == u3);
399 testing.expect(IntFittingRange(0, 8) == u4);
400 testing.expect(IntFittingRange(0, 9) == u4);
401 testing.expect(IntFittingRange(0, 15) == u4);
402 testing.expect(IntFittingRange(0, 16) == u5);
403 testing.expect(IntFittingRange(0, 17) == u5);
404 testing.expect(IntFittingRange(0, 4095) == u12);
405 testing.expect(IntFittingRange(2000, 4095) == u12);
406 testing.expect(IntFittingRange(0, 4096) == u13);
407 testing.expect(IntFittingRange(2000, 4096) == u13);
408 testing.expect(IntFittingRange(0, 4097) == u13);
409 testing.expect(IntFittingRange(2000, 4097) == u13);
410 testing.expect(IntFittingRange(0, 123456789123456798123456789) == u87);
411 testing.expect(IntFittingRange(0, 123456789123456798123456789123456789123456798123456789) == u177);
412
413 testing.expect(IntFittingRange(-1, -1) == i1);
414 testing.expect(IntFittingRange(-1, 0) == i1);
415 testing.expect(IntFittingRange(-1, 1) == i2);
416 testing.expect(IntFittingRange(-2, -2) == i2);
417 testing.expect(IntFittingRange(-2, -1) == i2);
418 testing.expect(IntFittingRange(-2, 0) == i2);
419 testing.expect(IntFittingRange(-2, 1) == i2);
420 testing.expect(IntFittingRange(-2, 2) == i3);
421 testing.expect(IntFittingRange(-1, 2) == i3);
422 testing.expect(IntFittingRange(-1, 3) == i3);
423 testing.expect(IntFittingRange(-1, 4) == i4);
424 testing.expect(IntFittingRange(-1, 7) == i4);
425 testing.expect(IntFittingRange(-1, 8) == i5);
426 testing.expect(IntFittingRange(-1, 9) == i5);
427 testing.expect(IntFittingRange(-1, 15) == i5);
428 testing.expect(IntFittingRange(-1, 16) == i6);
429 testing.expect(IntFittingRange(-1, 17) == i6);
430 testing.expect(IntFittingRange(-1, 4095) == i13);
431 testing.expect(IntFittingRange(-4096, 4095) == i13);
432 testing.expect(IntFittingRange(-1, 4096) == i14);
433 testing.expect(IntFittingRange(-4097, 4095) == i14);
434 testing.expect(IntFittingRange(-1, 4097) == i14);
435 testing.expect(IntFittingRange(-1, 123456789123456798123456789) == i88);
436 testing.expect(IntFittingRange(-1, 123456789123456798123456789123456789123456798123456789) == i178);
436437}
437438
438439test "math overflow functions" {
......@@ -441,10 +442,10 @@ test "math overflow functions" {
441442}
442443
443444fn testOverflow() void {
444 assert((mul(i32, 3, 4) catch unreachable) == 12);
445 assert((add(i32, 3, 4) catch unreachable) == 7);
446 assert((sub(i32, 3, 4) catch unreachable) == -1);
447 assert((shlExact(i32, 0b11, 4) catch unreachable) == 0b110000);
445 testing.expect((mul(i32, 3, 4) catch unreachable) == 12);
446 testing.expect((add(i32, 3, 4) catch unreachable) == 7);
447 testing.expect((sub(i32, 3, 4) catch unreachable) == -1);
448 testing.expect((shlExact(i32, 0b11, 4) catch unreachable) == 0b110000);
448449}
449450
450451pub fn absInt(x: var) !@typeOf(x) {
......@@ -465,8 +466,8 @@ test "math.absInt" {
465466 comptime testAbsInt();
466467}
467468fn testAbsInt() void {
468 assert((absInt(i32(-10)) catch unreachable) == 10);
469 assert((absInt(i32(10)) catch unreachable) == 10);
469 testing.expect((absInt(i32(-10)) catch unreachable) == 10);
470 testing.expect((absInt(i32(10)) catch unreachable) == 10);
470471}
471472
472473pub const absFloat = @import("fabs.zig").fabs;
......@@ -483,13 +484,13 @@ test "math.divTrunc" {
483484 comptime testDivTrunc();
484485}
485486fn testDivTrunc() void {
486 assert((divTrunc(i32, 5, 3) catch unreachable) == 1);
487 assert((divTrunc(i32, -5, 3) catch unreachable) == -1);
488 if (divTrunc(i8, -5, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero);
489 if (divTrunc(i8, -128, -1)) |_| unreachable else |err| assert(err == error.Overflow);
487 testing.expect((divTrunc(i32, 5, 3) catch unreachable) == 1);
488 testing.expect((divTrunc(i32, -5, 3) catch unreachable) == -1);
489 testing.expectError(error.DivisionByZero, divTrunc(i8, -5, 0));
490 testing.expectError(error.Overflow, divTrunc(i8, -128, -1));
490491
491 assert((divTrunc(f32, 5.0, 3.0) catch unreachable) == 1.0);
492 assert((divTrunc(f32, -5.0, 3.0) catch unreachable) == -1.0);
492 testing.expect((divTrunc(f32, 5.0, 3.0) catch unreachable) == 1.0);
493 testing.expect((divTrunc(f32, -5.0, 3.0) catch unreachable) == -1.0);
493494}
494495
495496pub fn divFloor(comptime T: type, numerator: T, denominator: T) !T {
......@@ -504,13 +505,13 @@ test "math.divFloor" {
504505 comptime testDivFloor();
505506}
506507fn testDivFloor() void {
507 assert((divFloor(i32, 5, 3) catch unreachable) == 1);
508 assert((divFloor(i32, -5, 3) catch unreachable) == -2);
509 if (divFloor(i8, -5, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero);
510 if (divFloor(i8, -128, -1)) |_| unreachable else |err| assert(err == error.Overflow);
508 testing.expect((divFloor(i32, 5, 3) catch unreachable) == 1);
509 testing.expect((divFloor(i32, -5, 3) catch unreachable) == -2);
510 testing.expectError(error.DivisionByZero, divFloor(i8, -5, 0));
511 testing.expectError(error.Overflow, divFloor(i8, -128, -1));
511512
512 assert((divFloor(f32, 5.0, 3.0) catch unreachable) == 1.0);
513 assert((divFloor(f32, -5.0, 3.0) catch unreachable) == -2.0);
513 testing.expect((divFloor(f32, 5.0, 3.0) catch unreachable) == 1.0);
514 testing.expect((divFloor(f32, -5.0, 3.0) catch unreachable) == -2.0);
514515}
515516
516517pub fn divExact(comptime T: type, numerator: T, denominator: T) !T {
......@@ -527,15 +528,15 @@ test "math.divExact" {
527528 comptime testDivExact();
528529}
529530fn testDivExact() void {
530 assert((divExact(i32, 10, 5) catch unreachable) == 2);
531 assert((divExact(i32, -10, 5) catch unreachable) == -2);
532 if (divExact(i8, -5, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero);
533 if (divExact(i8, -128, -1)) |_| unreachable else |err| assert(err == error.Overflow);
534 if (divExact(i32, 5, 2)) |_| unreachable else |err| assert(err == error.UnexpectedRemainder);
531 testing.expect((divExact(i32, 10, 5) catch unreachable) == 2);
532 testing.expect((divExact(i32, -10, 5) catch unreachable) == -2);
533 testing.expectError(error.DivisionByZero, divExact(i8, -5, 0));
534 testing.expectError(error.Overflow, divExact(i8, -128, -1));
535 testing.expectError(error.UnexpectedRemainder, divExact(i32, 5, 2));
535536
536 assert((divExact(f32, 10.0, 5.0) catch unreachable) == 2.0);
537 assert((divExact(f32, -10.0, 5.0) catch unreachable) == -2.0);
538 if (divExact(f32, 5.0, 2.0)) |_| unreachable else |err| assert(err == error.UnexpectedRemainder);
537 testing.expect((divExact(f32, 10.0, 5.0) catch unreachable) == 2.0);
538 testing.expect((divExact(f32, -10.0, 5.0) catch unreachable) == -2.0);
539 testing.expectError(error.UnexpectedRemainder, divExact(f32, 5.0, 2.0));
539540}
540541
541542pub fn mod(comptime T: type, numerator: T, denominator: T) !T {
......@@ -550,15 +551,15 @@ test "math.mod" {
550551 comptime testMod();
551552}
552553fn testMod() void {
553 assert((mod(i32, -5, 3) catch unreachable) == 1);
554 assert((mod(i32, 5, 3) catch unreachable) == 2);
555 if (mod(i32, 10, -1)) |_| unreachable else |err| assert(err == error.NegativeDenominator);
556 if (mod(i32, 10, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero);
554 testing.expect((mod(i32, -5, 3) catch unreachable) == 1);
555 testing.expect((mod(i32, 5, 3) catch unreachable) == 2);
556 testing.expectError(error.NegativeDenominator, mod(i32, 10, -1));
557 testing.expectError(error.DivisionByZero, mod(i32, 10, 0));
557558
558 assert((mod(f32, -5, 3) catch unreachable) == 1);
559 assert((mod(f32, 5, 3) catch unreachable) == 2);
560 if (mod(f32, 10, -1)) |_| unreachable else |err| assert(err == error.NegativeDenominator);
561 if (mod(f32, 10, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero);
559 testing.expect((mod(f32, -5, 3) catch unreachable) == 1);
560 testing.expect((mod(f32, 5, 3) catch unreachable) == 2);
561 testing.expectError(error.NegativeDenominator, mod(f32, 10, -1));
562 testing.expectError(error.DivisionByZero, mod(f32, 10, 0));
562563}
563564
564565pub fn rem(comptime T: type, numerator: T, denominator: T) !T {
......@@ -573,15 +574,15 @@ test "math.rem" {
573574 comptime testRem();
574575}
575576fn testRem() void {
576 assert((rem(i32, -5, 3) catch unreachable) == -2);
577 assert((rem(i32, 5, 3) catch unreachable) == 2);
578 if (rem(i32, 10, -1)) |_| unreachable else |err| assert(err == error.NegativeDenominator);
579 if (rem(i32, 10, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero);
577 testing.expect((rem(i32, -5, 3) catch unreachable) == -2);
578 testing.expect((rem(i32, 5, 3) catch unreachable) == 2);
579 testing.expectError(error.NegativeDenominator, rem(i32, 10, -1));
580 testing.expectError(error.DivisionByZero, rem(i32, 10, 0));
580581
581 assert((rem(f32, -5, 3) catch unreachable) == -2);
582 assert((rem(f32, 5, 3) catch unreachable) == 2);
583 if (rem(f32, 10, -1)) |_| unreachable else |err| assert(err == error.NegativeDenominator);
584 if (rem(f32, 10, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero);
582 testing.expect((rem(f32, -5, 3) catch unreachable) == -2);
583 testing.expect((rem(f32, 5, 3) catch unreachable) == 2);
584 testing.expectError(error.NegativeDenominator, rem(f32, 10, -1));
585 testing.expectError(error.DivisionByZero, rem(f32, 10, 0));
585586}
586587
587588/// Returns the absolute value of the integer parameter.
......@@ -594,14 +595,14 @@ pub fn absCast(x: var) @IntType(false, @typeOf(x).bit_count) {
594595}
595596
596597test "math.absCast" {
597 assert(absCast(i32(-999)) == 999);
598 assert(@typeOf(absCast(i32(-999))) == u32);
598 testing.expect(absCast(i32(-999)) == 999);
599 testing.expect(@typeOf(absCast(i32(-999))) == u32);
599600
600 assert(absCast(i32(999)) == 999);
601 assert(@typeOf(absCast(i32(999))) == u32);
601 testing.expect(absCast(i32(999)) == 999);
602 testing.expect(@typeOf(absCast(i32(999))) == u32);
602603
603 assert(absCast(i32(minInt(i32))) == -minInt(i32));
604 assert(@typeOf(absCast(i32(minInt(i32)))) == u32);
604 testing.expect(absCast(i32(minInt(i32))) == -minInt(i32));
605 testing.expect(@typeOf(absCast(i32(minInt(i32)))) == u32);
605606}
606607
607608/// Returns the negation of the integer parameter.
......@@ -618,13 +619,13 @@ pub fn negateCast(x: var) !@IntType(true, @typeOf(x).bit_count) {
618619}
619620
620621test "math.negateCast" {
621 assert((negateCast(u32(999)) catch unreachable) == -999);
622 assert(@typeOf(negateCast(u32(999)) catch unreachable) == i32);
622 testing.expect((negateCast(u32(999)) catch unreachable) == -999);
623 testing.expect(@typeOf(negateCast(u32(999)) catch unreachable) == i32);
623624
624 assert((negateCast(u32(-minInt(i32))) catch unreachable) == minInt(i32));
625 assert(@typeOf(negateCast(u32(-minInt(i32))) catch unreachable) == i32);
625 testing.expect((negateCast(u32(-minInt(i32))) catch unreachable) == minInt(i32));
626 testing.expect(@typeOf(negateCast(u32(-minInt(i32))) catch unreachable) == i32);
626627
627 if (negateCast(u32(maxInt(i32) + 10))) |_| unreachable else |err| assert(err == error.Overflow);
628 testing.expectError(error.Overflow, negateCast(u32(maxInt(i32) + 10)));
628629}
629630
630631/// Cast an integer to a different integer type. If the value doesn't fit,
......@@ -642,13 +643,13 @@ pub fn cast(comptime T: type, x: var) (error{Overflow}!T) {
642643}
643644
644645test "math.cast" {
645 if (cast(u8, u32(300))) |_| @panic("fail") else |err| assert(err == error.Overflow);
646 if (cast(i8, i32(-200))) |_| @panic("fail") else |err| assert(err == error.Overflow);
647 if (cast(u8, i8(-1))) |_| @panic("fail") else |err| assert(err == error.Overflow);
648 if (cast(u64, i8(-1))) |_| @panic("fail") else |err| assert(err == error.Overflow);
646 testing.expectError(error.Overflow, cast(u8, u32(300)));
647 testing.expectError(error.Overflow, cast(i8, i32(-200)));
648 testing.expectError(error.Overflow, cast(u8, i8(-1)));
649 testing.expectError(error.Overflow, cast(u64, i8(-1)));
649650
650 assert((try cast(u8, u32(255))) == u8(255));
651 assert(@typeOf(try cast(u8, u32(255))) == u8);
651 testing.expect((try cast(u8, u32(255))) == u8(255));
652 testing.expect(@typeOf(try cast(u8, u32(255))) == u8);
652653}
653654
654655pub const AlignCastError = error{UnalignedMemory};
......@@ -692,25 +693,25 @@ pub fn log2_int_ceil(comptime T: type, x: T) Log2Int(T) {
692693}
693694
694695test "std.math.log2_int_ceil" {
695 assert(log2_int_ceil(u32, 1) == 0);
696 assert(log2_int_ceil(u32, 2) == 1);
697 assert(log2_int_ceil(u32, 3) == 2);
698 assert(log2_int_ceil(u32, 4) == 2);
699 assert(log2_int_ceil(u32, 5) == 3);
700 assert(log2_int_ceil(u32, 6) == 3);
701 assert(log2_int_ceil(u32, 7) == 3);
702 assert(log2_int_ceil(u32, 8) == 3);
703 assert(log2_int_ceil(u32, 9) == 4);
704 assert(log2_int_ceil(u32, 10) == 4);
696 testing.expect(log2_int_ceil(u32, 1) == 0);
697 testing.expect(log2_int_ceil(u32, 2) == 1);
698 testing.expect(log2_int_ceil(u32, 3) == 2);
699 testing.expect(log2_int_ceil(u32, 4) == 2);
700 testing.expect(log2_int_ceil(u32, 5) == 3);
701 testing.expect(log2_int_ceil(u32, 6) == 3);
702 testing.expect(log2_int_ceil(u32, 7) == 3);
703 testing.expect(log2_int_ceil(u32, 8) == 3);
704 testing.expect(log2_int_ceil(u32, 9) == 4);
705 testing.expect(log2_int_ceil(u32, 10) == 4);
705706}
706707
707708fn testFloorPowerOfTwo() void {
708 assert(floorPowerOfTwo(u32, 63) == 32);
709 assert(floorPowerOfTwo(u32, 64) == 64);
710 assert(floorPowerOfTwo(u32, 65) == 64);
711 assert(floorPowerOfTwo(u4, 7) == 4);
712 assert(floorPowerOfTwo(u4, 8) == 8);
713 assert(floorPowerOfTwo(u4, 9) == 8);
709 testing.expect(floorPowerOfTwo(u32, 63) == 32);
710 testing.expect(floorPowerOfTwo(u32, 64) == 64);
711 testing.expect(floorPowerOfTwo(u32, 65) == 64);
712 testing.expect(floorPowerOfTwo(u4, 7) == 4);
713 testing.expect(floorPowerOfTwo(u4, 8) == 8);
714 testing.expect(floorPowerOfTwo(u4, 9) == 8);
714715}
715716
716717pub fn lossyCast(comptime T: type, value: var) T {
......@@ -726,7 +727,7 @@ pub fn lossyCast(comptime T: type, value: var) T {
726727test "math.f64_min" {
727728 const f64_min_u64 = 0x0010000000000000;
728729 const fmin: f64 = f64_min;
729 assert(@bitCast(u64, fmin) == f64_min_u64);
730 testing.expect(@bitCast(u64, fmin) == f64_min_u64);
730731}
731732
732733pub fn maxInt(comptime T: type) comptime_int {
......@@ -745,36 +746,36 @@ pub fn minInt(comptime T: type) comptime_int {
745746}
746747
747748test "minInt and maxInt" {
748 assert(maxInt(u0) == 0);
749 assert(maxInt(u1) == 1);
750 assert(maxInt(u8) == 255);
751 assert(maxInt(u16) == 65535);
752 assert(maxInt(u32) == 4294967295);
753 assert(maxInt(u64) == 18446744073709551615);
754
755 assert(maxInt(i0) == 0);
756 assert(maxInt(i1) == 0);
757 assert(maxInt(i8) == 127);
758 assert(maxInt(i16) == 32767);
759 assert(maxInt(i32) == 2147483647);
760 assert(maxInt(i63) == 4611686018427387903);
761 assert(maxInt(i64) == 9223372036854775807);
762
763 assert(minInt(u0) == 0);
764 assert(minInt(u1) == 0);
765 assert(minInt(u8) == 0);
766 assert(minInt(u16) == 0);
767 assert(minInt(u32) == 0);
768 assert(minInt(u63) == 0);
769 assert(minInt(u64) == 0);
770
771 assert(minInt(i0) == 0);
772 assert(minInt(i1) == -1);
773 assert(minInt(i8) == -128);
774 assert(minInt(i16) == -32768);
775 assert(minInt(i32) == -2147483648);
776 assert(minInt(i63) == -4611686018427387904);
777 assert(minInt(i64) == -9223372036854775808);
749 testing.expect(maxInt(u0) == 0);
750 testing.expect(maxInt(u1) == 1);
751 testing.expect(maxInt(u8) == 255);
752 testing.expect(maxInt(u16) == 65535);
753 testing.expect(maxInt(u32) == 4294967295);
754 testing.expect(maxInt(u64) == 18446744073709551615);
755
756 testing.expect(maxInt(i0) == 0);
757 testing.expect(maxInt(i1) == 0);
758 testing.expect(maxInt(i8) == 127);
759 testing.expect(maxInt(i16) == 32767);
760 testing.expect(maxInt(i32) == 2147483647);
761 testing.expect(maxInt(i63) == 4611686018427387903);
762 testing.expect(maxInt(i64) == 9223372036854775807);
763
764 testing.expect(minInt(u0) == 0);
765 testing.expect(minInt(u1) == 0);
766 testing.expect(minInt(u8) == 0);
767 testing.expect(minInt(u16) == 0);
768 testing.expect(minInt(u32) == 0);
769 testing.expect(minInt(u63) == 0);
770 testing.expect(minInt(u64) == 0);
771
772 testing.expect(minInt(i0) == 0);
773 testing.expect(minInt(i1) == -1);
774 testing.expect(minInt(i8) == -128);
775 testing.expect(minInt(i16) == -32768);
776 testing.expect(minInt(i32) == -2147483648);
777 testing.expect(minInt(i63) == -4611686018427387904);
778 testing.expect(minInt(i64) == -9223372036854775808);
778779}
779780
780781test "max value type" {
......@@ -782,5 +783,5 @@ test "max value type" {
782783 // u32 would not work. But since the value is a number literal,
783784 // it works fine.
784785 const x: u32 = maxInt(i32);
785 assert(x == 2147483647);
786 testing.expect(x == 2147483647);
786787}
std/math/isfinite.zig+13-13
......@@ -1,6 +1,6 @@
11const std = @import("../index.zig");
22const math = std.math;
3const assert = std.debug.assert;
3const expect = std.testing.expect;
44const maxInt = std.math.maxInt;
55
66pub fn isFinite(x: var) bool {
......@@ -25,16 +25,16 @@ pub fn isFinite(x: var) bool {
2525}
2626
2727test "math.isFinite" {
28 assert(isFinite(f16(0.0)));
29 assert(isFinite(f16(-0.0)));
30 assert(isFinite(f32(0.0)));
31 assert(isFinite(f32(-0.0)));
32 assert(isFinite(f64(0.0)));
33 assert(isFinite(f64(-0.0)));
34 assert(!isFinite(math.inf(f16)));
35 assert(!isFinite(-math.inf(f16)));
36 assert(!isFinite(math.inf(f32)));
37 assert(!isFinite(-math.inf(f32)));
38 assert(!isFinite(math.inf(f64)));
39 assert(!isFinite(-math.inf(f64)));
28 expect(isFinite(f16(0.0)));
29 expect(isFinite(f16(-0.0)));
30 expect(isFinite(f32(0.0)));
31 expect(isFinite(f32(-0.0)));
32 expect(isFinite(f64(0.0)));
33 expect(isFinite(f64(-0.0)));
34 expect(!isFinite(math.inf(f16)));
35 expect(!isFinite(-math.inf(f16)));
36 expect(!isFinite(math.inf(f32)));
37 expect(!isFinite(-math.inf(f32)));
38 expect(!isFinite(math.inf(f64)));
39 expect(!isFinite(-math.inf(f64)));
4040}
std/math/isinf.zig+37-37
......@@ -1,6 +1,6 @@
11const std = @import("../index.zig");
22const math = std.math;
3const assert = std.debug.assert;
3const expect = std.testing.expect;
44const maxInt = std.math.maxInt;
55
66pub fn isInf(x: var) bool {
......@@ -61,46 +61,46 @@ pub fn isNegativeInf(x: var) bool {
6161}
6262
6363test "math.isInf" {
64 assert(!isInf(f16(0.0)));
65 assert(!isInf(f16(-0.0)));
66 assert(!isInf(f32(0.0)));
67 assert(!isInf(f32(-0.0)));
68 assert(!isInf(f64(0.0)));
69 assert(!isInf(f64(-0.0)));
70 assert(isInf(math.inf(f16)));
71 assert(isInf(-math.inf(f16)));
72 assert(isInf(math.inf(f32)));
73 assert(isInf(-math.inf(f32)));
74 assert(isInf(math.inf(f64)));
75 assert(isInf(-math.inf(f64)));
64 expect(!isInf(f16(0.0)));
65 expect(!isInf(f16(-0.0)));
66 expect(!isInf(f32(0.0)));
67 expect(!isInf(f32(-0.0)));
68 expect(!isInf(f64(0.0)));
69 expect(!isInf(f64(-0.0)));
70 expect(isInf(math.inf(f16)));
71 expect(isInf(-math.inf(f16)));
72 expect(isInf(math.inf(f32)));
73 expect(isInf(-math.inf(f32)));
74 expect(isInf(math.inf(f64)));
75 expect(isInf(-math.inf(f64)));
7676}
7777
7878test "math.isPositiveInf" {
79 assert(!isPositiveInf(f16(0.0)));
80 assert(!isPositiveInf(f16(-0.0)));
81 assert(!isPositiveInf(f32(0.0)));
82 assert(!isPositiveInf(f32(-0.0)));
83 assert(!isPositiveInf(f64(0.0)));
84 assert(!isPositiveInf(f64(-0.0)));
85 assert(isPositiveInf(math.inf(f16)));
86 assert(!isPositiveInf(-math.inf(f16)));
87 assert(isPositiveInf(math.inf(f32)));
88 assert(!isPositiveInf(-math.inf(f32)));
89 assert(isPositiveInf(math.inf(f64)));
90 assert(!isPositiveInf(-math.inf(f64)));
79 expect(!isPositiveInf(f16(0.0)));
80 expect(!isPositiveInf(f16(-0.0)));
81 expect(!isPositiveInf(f32(0.0)));
82 expect(!isPositiveInf(f32(-0.0)));
83 expect(!isPositiveInf(f64(0.0)));
84 expect(!isPositiveInf(f64(-0.0)));
85 expect(isPositiveInf(math.inf(f16)));
86 expect(!isPositiveInf(-math.inf(f16)));
87 expect(isPositiveInf(math.inf(f32)));
88 expect(!isPositiveInf(-math.inf(f32)));
89 expect(isPositiveInf(math.inf(f64)));
90 expect(!isPositiveInf(-math.inf(f64)));
9191}
9292
9393test "math.isNegativeInf" {
94 assert(!isNegativeInf(f16(0.0)));
95 assert(!isNegativeInf(f16(-0.0)));
96 assert(!isNegativeInf(f32(0.0)));
97 assert(!isNegativeInf(f32(-0.0)));
98 assert(!isNegativeInf(f64(0.0)));
99 assert(!isNegativeInf(f64(-0.0)));
100 assert(!isNegativeInf(math.inf(f16)));
101 assert(isNegativeInf(-math.inf(f16)));
102 assert(!isNegativeInf(math.inf(f32)));
103 assert(isNegativeInf(-math.inf(f32)));
104 assert(!isNegativeInf(math.inf(f64)));
105 assert(isNegativeInf(-math.inf(f64)));
94 expect(!isNegativeInf(f16(0.0)));
95 expect(!isNegativeInf(f16(-0.0)));
96 expect(!isNegativeInf(f32(0.0)));
97 expect(!isNegativeInf(f32(-0.0)));
98 expect(!isNegativeInf(f64(0.0)));
99 expect(!isNegativeInf(f64(-0.0)));
100 expect(!isNegativeInf(math.inf(f16)));
101 expect(isNegativeInf(-math.inf(f16)));
102 expect(!isNegativeInf(math.inf(f32)));
103 expect(isNegativeInf(-math.inf(f32)));
104 expect(!isNegativeInf(math.inf(f64)));
105 expect(isNegativeInf(-math.inf(f64)));
106106}
std/math/isnan.zig+7-7
......@@ -1,6 +1,6 @@
11const std = @import("../index.zig");
22const math = std.math;
3const assert = std.debug.assert;
3const expect = std.testing.expect;
44const maxInt = std.math.maxInt;
55
66pub fn isNan(x: var) bool {
......@@ -31,10 +31,10 @@ pub fn isSignalNan(x: var) bool {
3131}
3232
3333test "math.isNan" {
34 assert(isNan(math.nan(f16)));
35 assert(isNan(math.nan(f32)));
36 assert(isNan(math.nan(f64)));
37 assert(!isNan(f16(1.0)));
38 assert(!isNan(f32(1.0)));
39 assert(!isNan(f64(1.0)));
34 expect(isNan(math.nan(f16)));
35 expect(isNan(math.nan(f32)));
36 expect(isNan(math.nan(f64)));
37 expect(!isNan(f16(1.0)));
38 expect(!isNan(f32(1.0)));
39 expect(!isNan(f64(1.0)));
4040}
std/math/isnormal.zig+10-10
......@@ -1,6 +1,6 @@
11const std = @import("../index.zig");
22const math = std.math;
3const assert = std.debug.assert;
3const expect = std.testing.expect;
44const maxInt = std.math.maxInt;
55
66pub fn isNormal(x: var) bool {
......@@ -25,13 +25,13 @@ pub fn isNormal(x: var) bool {
2525}
2626
2727test "math.isNormal" {
28 assert(!isNormal(math.nan(f16)));
29 assert(!isNormal(math.nan(f32)));
30 assert(!isNormal(math.nan(f64)));
31 assert(!isNormal(f16(0)));
32 assert(!isNormal(f32(0)));
33 assert(!isNormal(f64(0)));
34 assert(isNormal(f16(1.0)));
35 assert(isNormal(f32(1.0)));
36 assert(isNormal(f64(1.0)));
28 expect(!isNormal(math.nan(f16)));
29 expect(!isNormal(math.nan(f32)));
30 expect(!isNormal(math.nan(f64)));
31 expect(!isNormal(f16(0)));
32 expect(!isNormal(f32(0)));
33 expect(!isNormal(f64(0)));
34 expect(isNormal(f16(1.0)));
35 expect(isNormal(f32(1.0)));
36 expect(isNormal(f64(1.0)));
3737}
std/math/ln.zig+23-23
......@@ -7,7 +7,7 @@
77
88const std = @import("../index.zig");
99const math = std.math;
10const assert = std.debug.assert;
10const expect = std.testing.expect;
1111const builtin = @import("builtin");
1212const TypeId = builtin.TypeId;
1313
......@@ -143,42 +143,42 @@ pub fn ln_64(x_: f64) f64 {
143143}
144144
145145test "math.ln" {
146 assert(ln(f32(0.2)) == ln_32(0.2));
147 assert(ln(f64(0.2)) == ln_64(0.2));
146 expect(ln(f32(0.2)) == ln_32(0.2));
147 expect(ln(f64(0.2)) == ln_64(0.2));
148148}
149149
150150test "math.ln32" {
151151 const epsilon = 0.000001;
152152
153 assert(math.approxEq(f32, ln_32(0.2), -1.609438, epsilon));
154 assert(math.approxEq(f32, ln_32(0.8923), -0.113953, epsilon));
155 assert(math.approxEq(f32, ln_32(1.5), 0.405465, epsilon));
156 assert(math.approxEq(f32, ln_32(37.45), 3.623007, epsilon));
157 assert(math.approxEq(f32, ln_32(89.123), 4.490017, epsilon));
158 assert(math.approxEq(f32, ln_32(123123.234375), 11.720941, epsilon));
153 expect(math.approxEq(f32, ln_32(0.2), -1.609438, epsilon));
154 expect(math.approxEq(f32, ln_32(0.8923), -0.113953, epsilon));
155 expect(math.approxEq(f32, ln_32(1.5), 0.405465, epsilon));
156 expect(math.approxEq(f32, ln_32(37.45), 3.623007, epsilon));
157 expect(math.approxEq(f32, ln_32(89.123), 4.490017, epsilon));
158 expect(math.approxEq(f32, ln_32(123123.234375), 11.720941, epsilon));
159159}
160160
161161test "math.ln64" {
162162 const epsilon = 0.000001;
163163
164 assert(math.approxEq(f64, ln_64(0.2), -1.609438, epsilon));
165 assert(math.approxEq(f64, ln_64(0.8923), -0.113953, epsilon));
166 assert(math.approxEq(f64, ln_64(1.5), 0.405465, epsilon));
167 assert(math.approxEq(f64, ln_64(37.45), 3.623007, epsilon));
168 assert(math.approxEq(f64, ln_64(89.123), 4.490017, epsilon));
169 assert(math.approxEq(f64, ln_64(123123.234375), 11.720941, epsilon));
164 expect(math.approxEq(f64, ln_64(0.2), -1.609438, epsilon));
165 expect(math.approxEq(f64, ln_64(0.8923), -0.113953, epsilon));
166 expect(math.approxEq(f64, ln_64(1.5), 0.405465, epsilon));
167 expect(math.approxEq(f64, ln_64(37.45), 3.623007, epsilon));
168 expect(math.approxEq(f64, ln_64(89.123), 4.490017, epsilon));
169 expect(math.approxEq(f64, ln_64(123123.234375), 11.720941, epsilon));
170170}
171171
172172test "math.ln32.special" {
173 assert(math.isPositiveInf(ln_32(math.inf(f32))));
174 assert(math.isNegativeInf(ln_32(0.0)));
175 assert(math.isNan(ln_32(-1.0)));
176 assert(math.isNan(ln_32(math.nan(f32))));
173 expect(math.isPositiveInf(ln_32(math.inf(f32))));
174 expect(math.isNegativeInf(ln_32(0.0)));
175 expect(math.isNan(ln_32(-1.0)));
176 expect(math.isNan(ln_32(math.nan(f32))));
177177}
178178
179179test "math.ln64.special" {
180 assert(math.isPositiveInf(ln_64(math.inf(f64))));
181 assert(math.isNegativeInf(ln_64(0.0)));
182 assert(math.isNan(ln_64(-1.0)));
183 assert(math.isNan(ln_64(math.nan(f64))));
180 expect(math.isPositiveInf(ln_64(math.inf(f64))));
181 expect(math.isNegativeInf(ln_64(0.0)));
182 expect(math.isNan(ln_64(-1.0)));
183 expect(math.isNan(ln_64(math.nan(f64))));
184184}
std/math/log.zig+13-13
......@@ -2,7 +2,7 @@ const std = @import("../index.zig");
22const math = std.math;
33const builtin = @import("builtin");
44const TypeId = builtin.TypeId;
5const assert = std.debug.assert;
5const expect = std.testing.expect;
66
77pub fn log(comptime T: type, base: T, x: T) T {
88 if (base == 2) {
......@@ -41,25 +41,25 @@ pub fn log(comptime T: type, base: T, x: T) T {
4141}
4242
4343test "math.log integer" {
44 assert(log(u8, 2, 0x1) == 0);
45 assert(log(u8, 2, 0x2) == 1);
46 assert(log(i16, 2, 0x72) == 6);
47 assert(log(u32, 2, 0xFFFFFF) == 23);
48 assert(log(u64, 2, 0x7FF0123456789ABC) == 62);
44 expect(log(u8, 2, 0x1) == 0);
45 expect(log(u8, 2, 0x2) == 1);
46 expect(log(i16, 2, 0x72) == 6);
47 expect(log(u32, 2, 0xFFFFFF) == 23);
48 expect(log(u64, 2, 0x7FF0123456789ABC) == 62);
4949}
5050
5151test "math.log float" {
5252 const epsilon = 0.000001;
5353
54 assert(math.approxEq(f32, log(f32, 6, 0.23947), -0.797723, epsilon));
55 assert(math.approxEq(f32, log(f32, 89, 0.23947), -0.318432, epsilon));
56 assert(math.approxEq(f64, log(f64, 123897, 12389216414), 1.981724596, epsilon));
54 expect(math.approxEq(f32, log(f32, 6, 0.23947), -0.797723, epsilon));
55 expect(math.approxEq(f32, log(f32, 89, 0.23947), -0.318432, epsilon));
56 expect(math.approxEq(f64, log(f64, 123897, 12389216414), 1.981724596, epsilon));
5757}
5858
5959test "math.log float_special" {
60 assert(log(f32, 2, 0.2301974) == math.log2(f32(0.2301974)));
61 assert(log(f32, 10, 0.2301974) == math.log10(f32(0.2301974)));
60 expect(log(f32, 2, 0.2301974) == math.log2(f32(0.2301974)));
61 expect(log(f32, 10, 0.2301974) == math.log10(f32(0.2301974)));
6262
63 assert(log(f64, 2, 213.23019799993) == math.log2(f64(213.23019799993)));
64 assert(log(f64, 10, 213.23019799993) == math.log10(f64(213.23019799993)));
63 expect(log(f64, 2, 213.23019799993) == math.log2(f64(213.23019799993)));
64 expect(log(f64, 10, 213.23019799993) == math.log10(f64(213.23019799993)));
6565}
std/math/log10.zig+23-23
......@@ -7,7 +7,7 @@
77
88const std = @import("../index.zig");
99const math = std.math;
10const assert = std.debug.assert;
10const testing = std.testing;
1111const builtin = @import("builtin");
1212const TypeId = builtin.TypeId;
1313const maxInt = std.math.maxInt;
......@@ -171,42 +171,42 @@ pub fn log10_64(x_: f64) f64 {
171171}
172172
173173test "math.log10" {
174 assert(log10(f32(0.2)) == log10_32(0.2));
175 assert(log10(f64(0.2)) == log10_64(0.2));
174 testing.expect(log10(f32(0.2)) == log10_32(0.2));
175 testing.expect(log10(f64(0.2)) == log10_64(0.2));
176176}
177177
178178test "math.log10_32" {
179179 const epsilon = 0.000001;
180180
181 assert(math.approxEq(f32, log10_32(0.2), -0.698970, epsilon));
182 assert(math.approxEq(f32, log10_32(0.8923), -0.049489, epsilon));
183 assert(math.approxEq(f32, log10_32(1.5), 0.176091, epsilon));
184 assert(math.approxEq(f32, log10_32(37.45), 1.573452, epsilon));
185 assert(math.approxEq(f32, log10_32(89.123), 1.94999, epsilon));
186 assert(math.approxEq(f32, log10_32(123123.234375), 5.09034, epsilon));
181 testing.expect(math.approxEq(f32, log10_32(0.2), -0.698970, epsilon));
182 testing.expect(math.approxEq(f32, log10_32(0.8923), -0.049489, epsilon));
183 testing.expect(math.approxEq(f32, log10_32(1.5), 0.176091, epsilon));
184 testing.expect(math.approxEq(f32, log10_32(37.45), 1.573452, epsilon));
185 testing.expect(math.approxEq(f32, log10_32(89.123), 1.94999, epsilon));
186 testing.expect(math.approxEq(f32, log10_32(123123.234375), 5.09034, epsilon));
187187}
188188
189189test "math.log10_64" {
190190 const epsilon = 0.000001;
191191
192 assert(math.approxEq(f64, log10_64(0.2), -0.698970, epsilon));
193 assert(math.approxEq(f64, log10_64(0.8923), -0.049489, epsilon));
194 assert(math.approxEq(f64, log10_64(1.5), 0.176091, epsilon));
195 assert(math.approxEq(f64, log10_64(37.45), 1.573452, epsilon));
196 assert(math.approxEq(f64, log10_64(89.123), 1.94999, epsilon));
197 assert(math.approxEq(f64, log10_64(123123.234375), 5.09034, epsilon));
192 testing.expect(math.approxEq(f64, log10_64(0.2), -0.698970, epsilon));
193 testing.expect(math.approxEq(f64, log10_64(0.8923), -0.049489, epsilon));
194 testing.expect(math.approxEq(f64, log10_64(1.5), 0.176091, epsilon));
195 testing.expect(math.approxEq(f64, log10_64(37.45), 1.573452, epsilon));
196 testing.expect(math.approxEq(f64, log10_64(89.123), 1.94999, epsilon));
197 testing.expect(math.approxEq(f64, log10_64(123123.234375), 5.09034, epsilon));
198198}
199199
200200test "math.log10_32.special" {
201 assert(math.isPositiveInf(log10_32(math.inf(f32))));
202 assert(math.isNegativeInf(log10_32(0.0)));
203 assert(math.isNan(log10_32(-1.0)));
204 assert(math.isNan(log10_32(math.nan(f32))));
201 testing.expect(math.isPositiveInf(log10_32(math.inf(f32))));
202 testing.expect(math.isNegativeInf(log10_32(0.0)));
203 testing.expect(math.isNan(log10_32(-1.0)));
204 testing.expect(math.isNan(log10_32(math.nan(f32))));
205205}
206206
207207test "math.log10_64.special" {
208 assert(math.isPositiveInf(log10_64(math.inf(f64))));
209 assert(math.isNegativeInf(log10_64(0.0)));
210 assert(math.isNan(log10_64(-1.0)));
211 assert(math.isNan(log10_64(math.nan(f64))));
208 testing.expect(math.isPositiveInf(log10_64(math.inf(f64))));
209 testing.expect(math.isNegativeInf(log10_64(0.0)));
210 testing.expect(math.isNan(log10_64(-1.0)));
211 testing.expect(math.isNan(log10_64(math.nan(f64))));
212212}
std/math/log1p.zig+29-29
......@@ -9,7 +9,7 @@
99const builtin = @import("builtin");
1010const std = @import("../index.zig");
1111const math = std.math;
12const assert = std.debug.assert;
12const expect = std.testing.expect;
1313
1414pub fn log1p(x: var) @typeOf(x) {
1515 const T = @typeOf(x);
......@@ -177,48 +177,48 @@ fn log1p_64(x: f64) f64 {
177177}
178178
179179test "math.log1p" {
180 assert(log1p(f32(0.0)) == log1p_32(0.0));
181 assert(log1p(f64(0.0)) == log1p_64(0.0));
180 expect(log1p(f32(0.0)) == log1p_32(0.0));
181 expect(log1p(f64(0.0)) == log1p_64(0.0));
182182}
183183
184184test "math.log1p_32" {
185185 const epsilon = 0.000001;
186186
187 assert(math.approxEq(f32, log1p_32(0.0), 0.0, epsilon));
188 assert(math.approxEq(f32, log1p_32(0.2), 0.182322, epsilon));
189 assert(math.approxEq(f32, log1p_32(0.8923), 0.637793, epsilon));
190 assert(math.approxEq(f32, log1p_32(1.5), 0.916291, epsilon));
191 assert(math.approxEq(f32, log1p_32(37.45), 3.649359, epsilon));
192 assert(math.approxEq(f32, log1p_32(89.123), 4.501175, epsilon));
193 assert(math.approxEq(f32, log1p_32(123123.234375), 11.720949, epsilon));
187 expect(math.approxEq(f32, log1p_32(0.0), 0.0, epsilon));
188 expect(math.approxEq(f32, log1p_32(0.2), 0.182322, epsilon));
189 expect(math.approxEq(f32, log1p_32(0.8923), 0.637793, epsilon));
190 expect(math.approxEq(f32, log1p_32(1.5), 0.916291, epsilon));
191 expect(math.approxEq(f32, log1p_32(37.45), 3.649359, epsilon));
192 expect(math.approxEq(f32, log1p_32(89.123), 4.501175, epsilon));
193 expect(math.approxEq(f32, log1p_32(123123.234375), 11.720949, epsilon));
194194}
195195
196196test "math.log1p_64" {
197197 const epsilon = 0.000001;
198198
199 assert(math.approxEq(f64, log1p_64(0.0), 0.0, epsilon));
200 assert(math.approxEq(f64, log1p_64(0.2), 0.182322, epsilon));
201 assert(math.approxEq(f64, log1p_64(0.8923), 0.637793, epsilon));
202 assert(math.approxEq(f64, log1p_64(1.5), 0.916291, epsilon));
203 assert(math.approxEq(f64, log1p_64(37.45), 3.649359, epsilon));
204 assert(math.approxEq(f64, log1p_64(89.123), 4.501175, epsilon));
205 assert(math.approxEq(f64, log1p_64(123123.234375), 11.720949, epsilon));
199 expect(math.approxEq(f64, log1p_64(0.0), 0.0, epsilon));
200 expect(math.approxEq(f64, log1p_64(0.2), 0.182322, epsilon));
201 expect(math.approxEq(f64, log1p_64(0.8923), 0.637793, epsilon));
202 expect(math.approxEq(f64, log1p_64(1.5), 0.916291, epsilon));
203 expect(math.approxEq(f64, log1p_64(37.45), 3.649359, epsilon));
204 expect(math.approxEq(f64, log1p_64(89.123), 4.501175, epsilon));
205 expect(math.approxEq(f64, log1p_64(123123.234375), 11.720949, epsilon));
206206}
207207
208208test "math.log1p_32.special" {
209 assert(math.isPositiveInf(log1p_32(math.inf(f32))));
210 assert(log1p_32(0.0) == 0.0);
211 assert(log1p_32(-0.0) == -0.0);
212 assert(math.isNegativeInf(log1p_32(-1.0)));
213 assert(math.isNan(log1p_32(-2.0)));
214 assert(math.isNan(log1p_32(math.nan(f32))));
209 expect(math.isPositiveInf(log1p_32(math.inf(f32))));
210 expect(log1p_32(0.0) == 0.0);
211 expect(log1p_32(-0.0) == -0.0);
212 expect(math.isNegativeInf(log1p_32(-1.0)));
213 expect(math.isNan(log1p_32(-2.0)));
214 expect(math.isNan(log1p_32(math.nan(f32))));
215215}
216216
217217test "math.log1p_64.special" {
218 assert(math.isPositiveInf(log1p_64(math.inf(f64))));
219 assert(log1p_64(0.0) == 0.0);
220 assert(log1p_64(-0.0) == -0.0);
221 assert(math.isNegativeInf(log1p_64(-1.0)));
222 assert(math.isNan(log1p_64(-2.0)));
223 assert(math.isNan(log1p_64(math.nan(f64))));
218 expect(math.isPositiveInf(log1p_64(math.inf(f64))));
219 expect(log1p_64(0.0) == 0.0);
220 expect(log1p_64(-0.0) == -0.0);
221 expect(math.isNegativeInf(log1p_64(-1.0)));
222 expect(math.isNan(log1p_64(-2.0)));
223 expect(math.isNan(log1p_64(math.nan(f64))));
224224}
std/math/log2.zig+21-21
......@@ -7,7 +7,7 @@
77
88const std = @import("../index.zig");
99const math = std.math;
10const assert = std.debug.assert;
10const expect = std.testing.expect;
1111const builtin = @import("builtin");
1212const TypeId = builtin.TypeId;
1313const maxInt = std.math.maxInt;
......@@ -169,40 +169,40 @@ pub fn log2_64(x_: f64) f64 {
169169}
170170
171171test "math.log2" {
172 assert(log2(f32(0.2)) == log2_32(0.2));
173 assert(log2(f64(0.2)) == log2_64(0.2));
172 expect(log2(f32(0.2)) == log2_32(0.2));
173 expect(log2(f64(0.2)) == log2_64(0.2));
174174}
175175
176176test "math.log2_32" {
177177 const epsilon = 0.000001;
178178
179 assert(math.approxEq(f32, log2_32(0.2), -2.321928, epsilon));
180 assert(math.approxEq(f32, log2_32(0.8923), -0.164399, epsilon));
181 assert(math.approxEq(f32, log2_32(1.5), 0.584962, epsilon));
182 assert(math.approxEq(f32, log2_32(37.45), 5.226894, epsilon));
183 assert(math.approxEq(f32, log2_32(123123.234375), 16.909744, epsilon));
179 expect(math.approxEq(f32, log2_32(0.2), -2.321928, epsilon));
180 expect(math.approxEq(f32, log2_32(0.8923), -0.164399, epsilon));
181 expect(math.approxEq(f32, log2_32(1.5), 0.584962, epsilon));
182 expect(math.approxEq(f32, log2_32(37.45), 5.226894, epsilon));
183 expect(math.approxEq(f32, log2_32(123123.234375), 16.909744, epsilon));
184184}
185185
186186test "math.log2_64" {
187187 const epsilon = 0.000001;
188188
189 assert(math.approxEq(f64, log2_64(0.2), -2.321928, epsilon));
190 assert(math.approxEq(f64, log2_64(0.8923), -0.164399, epsilon));
191 assert(math.approxEq(f64, log2_64(1.5), 0.584962, epsilon));
192 assert(math.approxEq(f64, log2_64(37.45), 5.226894, epsilon));
193 assert(math.approxEq(f64, log2_64(123123.234375), 16.909744, epsilon));
189 expect(math.approxEq(f64, log2_64(0.2), -2.321928, epsilon));
190 expect(math.approxEq(f64, log2_64(0.8923), -0.164399, epsilon));
191 expect(math.approxEq(f64, log2_64(1.5), 0.584962, epsilon));
192 expect(math.approxEq(f64, log2_64(37.45), 5.226894, epsilon));
193 expect(math.approxEq(f64, log2_64(123123.234375), 16.909744, epsilon));
194194}
195195
196196test "math.log2_32.special" {
197 assert(math.isPositiveInf(log2_32(math.inf(f32))));
198 assert(math.isNegativeInf(log2_32(0.0)));
199 assert(math.isNan(log2_32(-1.0)));
200 assert(math.isNan(log2_32(math.nan(f32))));
197 expect(math.isPositiveInf(log2_32(math.inf(f32))));
198 expect(math.isNegativeInf(log2_32(0.0)));
199 expect(math.isNan(log2_32(-1.0)));
200 expect(math.isNan(log2_32(math.nan(f32))));
201201}
202202
203203test "math.log2_64.special" {
204 assert(math.isPositiveInf(log2_64(math.inf(f64))));
205 assert(math.isNegativeInf(log2_64(0.0)));
206 assert(math.isNan(log2_64(-1.0)));
207 assert(math.isNan(log2_64(math.nan(f64))));
204 expect(math.isPositiveInf(log2_64(math.inf(f64))));
205 expect(math.isNegativeInf(log2_64(0.0)));
206 expect(math.isNan(log2_64(-1.0)));
207 expect(math.isNan(log2_64(math.nan(f64))));
208208}
std/math/modf.zig+29-29
......@@ -5,7 +5,7 @@
55
66const std = @import("../index.zig");
77const math = std.math;
8const assert = std.debug.assert;
8const expect = std.testing.expect;
99const maxInt = std.math.maxInt;
1010
1111fn modf_result(comptime T: type) type {
......@@ -119,11 +119,11 @@ test "math.modf" {
119119 const a = modf(f32(1.0));
120120 const b = modf32(1.0);
121121 // NOTE: No struct comparison on generic return type function? non-named, makes sense, but still.
122 assert(a.ipart == b.ipart and a.fpart == b.fpart);
122 expect(a.ipart == b.ipart and a.fpart == b.fpart);
123123
124124 const c = modf(f64(1.0));
125125 const d = modf64(1.0);
126 assert(a.ipart == b.ipart and a.fpart == b.fpart);
126 expect(a.ipart == b.ipart and a.fpart == b.fpart);
127127}
128128
129129test "math.modf32" {
......@@ -131,24 +131,24 @@ test "math.modf32" {
131131 var r: modf32_result = undefined;
132132
133133 r = modf32(1.0);
134 assert(math.approxEq(f32, r.ipart, 1.0, epsilon));
135 assert(math.approxEq(f32, r.fpart, 0.0, epsilon));
134 expect(math.approxEq(f32, r.ipart, 1.0, epsilon));
135 expect(math.approxEq(f32, r.fpart, 0.0, epsilon));
136136
137137 r = modf32(2.545);
138 assert(math.approxEq(f32, r.ipart, 2.0, epsilon));
139 assert(math.approxEq(f32, r.fpart, 0.545, epsilon));
138 expect(math.approxEq(f32, r.ipart, 2.0, epsilon));
139 expect(math.approxEq(f32, r.fpart, 0.545, epsilon));
140140
141141 r = modf32(3.978123);
142 assert(math.approxEq(f32, r.ipart, 3.0, epsilon));
143 assert(math.approxEq(f32, r.fpart, 0.978123, epsilon));
142 expect(math.approxEq(f32, r.ipart, 3.0, epsilon));
143 expect(math.approxEq(f32, r.fpart, 0.978123, epsilon));
144144
145145 r = modf32(43874.3);
146 assert(math.approxEq(f32, r.ipart, 43874, epsilon));
147 assert(math.approxEq(f32, r.fpart, 0.300781, epsilon));
146 expect(math.approxEq(f32, r.ipart, 43874, epsilon));
147 expect(math.approxEq(f32, r.fpart, 0.300781, epsilon));
148148
149149 r = modf32(1234.340780);
150 assert(math.approxEq(f32, r.ipart, 1234, epsilon));
151 assert(math.approxEq(f32, r.fpart, 0.340820, epsilon));
150 expect(math.approxEq(f32, r.ipart, 1234, epsilon));
151 expect(math.approxEq(f32, r.fpart, 0.340820, epsilon));
152152}
153153
154154test "math.modf64" {
......@@ -156,48 +156,48 @@ test "math.modf64" {
156156 var r: modf64_result = undefined;
157157
158158 r = modf64(1.0);
159 assert(math.approxEq(f64, r.ipart, 1.0, epsilon));
160 assert(math.approxEq(f64, r.fpart, 0.0, epsilon));
159 expect(math.approxEq(f64, r.ipart, 1.0, epsilon));
160 expect(math.approxEq(f64, r.fpart, 0.0, epsilon));
161161
162162 r = modf64(2.545);
163 assert(math.approxEq(f64, r.ipart, 2.0, epsilon));
164 assert(math.approxEq(f64, r.fpart, 0.545, epsilon));
163 expect(math.approxEq(f64, r.ipart, 2.0, epsilon));
164 expect(math.approxEq(f64, r.fpart, 0.545, epsilon));
165165
166166 r = modf64(3.978123);
167 assert(math.approxEq(f64, r.ipart, 3.0, epsilon));
168 assert(math.approxEq(f64, r.fpart, 0.978123, epsilon));
167 expect(math.approxEq(f64, r.ipart, 3.0, epsilon));
168 expect(math.approxEq(f64, r.fpart, 0.978123, epsilon));
169169
170170 r = modf64(43874.3);
171 assert(math.approxEq(f64, r.ipart, 43874, epsilon));
172 assert(math.approxEq(f64, r.fpart, 0.3, epsilon));
171 expect(math.approxEq(f64, r.ipart, 43874, epsilon));
172 expect(math.approxEq(f64, r.fpart, 0.3, epsilon));
173173
174174 r = modf64(1234.340780);
175 assert(math.approxEq(f64, r.ipart, 1234, epsilon));
176 assert(math.approxEq(f64, r.fpart, 0.340780, epsilon));
175 expect(math.approxEq(f64, r.ipart, 1234, epsilon));
176 expect(math.approxEq(f64, r.fpart, 0.340780, epsilon));
177177}
178178
179179test "math.modf32.special" {
180180 var r: modf32_result = undefined;
181181
182182 r = modf32(math.inf(f32));
183 assert(math.isPositiveInf(r.ipart) and math.isNan(r.fpart));
183 expect(math.isPositiveInf(r.ipart) and math.isNan(r.fpart));
184184
185185 r = modf32(-math.inf(f32));
186 assert(math.isNegativeInf(r.ipart) and math.isNan(r.fpart));
186 expect(math.isNegativeInf(r.ipart) and math.isNan(r.fpart));
187187
188188 r = modf32(math.nan(f32));
189 assert(math.isNan(r.ipart) and math.isNan(r.fpart));
189 expect(math.isNan(r.ipart) and math.isNan(r.fpart));
190190}
191191
192192test "math.modf64.special" {
193193 var r: modf64_result = undefined;
194194
195195 r = modf64(math.inf(f64));
196 assert(math.isPositiveInf(r.ipart) and math.isNan(r.fpart));
196 expect(math.isPositiveInf(r.ipart) and math.isNan(r.fpart));
197197
198198 r = modf64(-math.inf(f64));
199 assert(math.isNegativeInf(r.ipart) and math.isNan(r.fpart));
199 expect(math.isNegativeInf(r.ipart) and math.isNan(r.fpart));
200200
201201 r = modf64(math.nan(f64));
202 assert(math.isNan(r.ipart) and math.isNan(r.fpart));
202 expect(math.isNan(r.ipart) and math.isNan(r.fpart));
203203}
std/math/pow.zig+48-48
......@@ -24,7 +24,7 @@
2424const builtin = @import("builtin");
2525const std = @import("../index.zig");
2626const math = std.math;
27const assert = std.debug.assert;
27const expect = std.testing.expect;
2828
2929// This implementation is taken from the go stlib, musl is a bit more complex.
3030pub fn pow(comptime T: type, x: T, y: T) T {
......@@ -179,56 +179,56 @@ fn isOddInteger(x: f64) bool {
179179test "math.pow" {
180180 const epsilon = 0.000001;
181181
182 assert(math.approxEq(f32, pow(f32, 0.0, 3.3), 0.0, epsilon));
183 assert(math.approxEq(f32, pow(f32, 0.8923, 3.3), 0.686572, epsilon));
184 assert(math.approxEq(f32, pow(f32, 0.2, 3.3), 0.004936, epsilon));
185 assert(math.approxEq(f32, pow(f32, 1.5, 3.3), 3.811546, epsilon));
186 assert(math.approxEq(f32, pow(f32, 37.45, 3.3), 155736.703125, epsilon));
187 assert(math.approxEq(f32, pow(f32, 89.123, 3.3), 2722489.5, epsilon));
188
189 assert(math.approxEq(f64, pow(f64, 0.0, 3.3), 0.0, epsilon));
190 assert(math.approxEq(f64, pow(f64, 0.8923, 3.3), 0.686572, epsilon));
191 assert(math.approxEq(f64, pow(f64, 0.2, 3.3), 0.004936, epsilon));
192 assert(math.approxEq(f64, pow(f64, 1.5, 3.3), 3.811546, epsilon));
193 assert(math.approxEq(f64, pow(f64, 37.45, 3.3), 155736.7160616, epsilon));
194 assert(math.approxEq(f64, pow(f64, 89.123, 3.3), 2722490.231436, epsilon));
182 expect(math.approxEq(f32, pow(f32, 0.0, 3.3), 0.0, epsilon));
183 expect(math.approxEq(f32, pow(f32, 0.8923, 3.3), 0.686572, epsilon));
184 expect(math.approxEq(f32, pow(f32, 0.2, 3.3), 0.004936, epsilon));
185 expect(math.approxEq(f32, pow(f32, 1.5, 3.3), 3.811546, epsilon));
186 expect(math.approxEq(f32, pow(f32, 37.45, 3.3), 155736.703125, epsilon));
187 expect(math.approxEq(f32, pow(f32, 89.123, 3.3), 2722489.5, epsilon));
188
189 expect(math.approxEq(f64, pow(f64, 0.0, 3.3), 0.0, epsilon));
190 expect(math.approxEq(f64, pow(f64, 0.8923, 3.3), 0.686572, epsilon));
191 expect(math.approxEq(f64, pow(f64, 0.2, 3.3), 0.004936, epsilon));
192 expect(math.approxEq(f64, pow(f64, 1.5, 3.3), 3.811546, epsilon));
193 expect(math.approxEq(f64, pow(f64, 37.45, 3.3), 155736.7160616, epsilon));
194 expect(math.approxEq(f64, pow(f64, 89.123, 3.3), 2722490.231436, epsilon));
195195}
196196
197197test "math.pow.special" {
198198 const epsilon = 0.000001;
199199
200 assert(pow(f32, 4, 0.0) == 1.0);
201 assert(pow(f32, 7, -0.0) == 1.0);
202 assert(pow(f32, 45, 1.0) == 45);
203 assert(pow(f32, -45, 1.0) == -45);
204 assert(math.isNan(pow(f32, math.nan(f32), 5.0)));
205 assert(math.isNan(pow(f32, 5.0, math.nan(f32))));
206 assert(math.isPositiveInf(pow(f32, 0.0, -1.0)));
207 //assert(math.isNegativeInf(pow(f32, -0.0, -3.0))); TODO is this required?
208 assert(math.isPositiveInf(pow(f32, 0.0, -math.inf(f32))));
209 assert(math.isPositiveInf(pow(f32, -0.0, -math.inf(f32))));
210 assert(pow(f32, 0.0, math.inf(f32)) == 0.0);
211 assert(pow(f32, -0.0, math.inf(f32)) == 0.0);
212 assert(math.isPositiveInf(pow(f32, 0.0, -2.0)));
213 assert(math.isPositiveInf(pow(f32, -0.0, -2.0)));
214 assert(pow(f32, 0.0, 1.0) == 0.0);
215 assert(pow(f32, -0.0, 1.0) == -0.0);
216 assert(pow(f32, 0.0, 2.0) == 0.0);
217 assert(pow(f32, -0.0, 2.0) == 0.0);
218 assert(math.approxEq(f32, pow(f32, -1.0, math.inf(f32)), 1.0, epsilon));
219 assert(math.approxEq(f32, pow(f32, -1.0, -math.inf(f32)), 1.0, epsilon));
220 assert(math.isPositiveInf(pow(f32, 1.2, math.inf(f32))));
221 assert(math.isPositiveInf(pow(f32, -1.2, math.inf(f32))));
222 assert(pow(f32, 1.2, -math.inf(f32)) == 0.0);
223 assert(pow(f32, -1.2, -math.inf(f32)) == 0.0);
224 assert(pow(f32, 0.2, math.inf(f32)) == 0.0);
225 assert(pow(f32, -0.2, math.inf(f32)) == 0.0);
226 assert(math.isPositiveInf(pow(f32, 0.2, -math.inf(f32))));
227 assert(math.isPositiveInf(pow(f32, -0.2, -math.inf(f32))));
228 assert(math.isPositiveInf(pow(f32, math.inf(f32), 1.0)));
229 assert(pow(f32, math.inf(f32), -1.0) == 0.0);
230 //assert(pow(f32, -math.inf(f32), 5.0) == pow(f32, -0.0, -5.0)); TODO support negative 0?
231 assert(pow(f32, -math.inf(f32), -5.2) == pow(f32, -0.0, 5.2));
232 assert(math.isNan(pow(f32, -1.0, 1.2)));
233 assert(math.isNan(pow(f32, -12.4, 78.5)));
200 expect(pow(f32, 4, 0.0) == 1.0);
201 expect(pow(f32, 7, -0.0) == 1.0);
202 expect(pow(f32, 45, 1.0) == 45);
203 expect(pow(f32, -45, 1.0) == -45);
204 expect(math.isNan(pow(f32, math.nan(f32), 5.0)));
205 expect(math.isNan(pow(f32, 5.0, math.nan(f32))));
206 expect(math.isPositiveInf(pow(f32, 0.0, -1.0)));
207 //expect(math.isNegativeInf(pow(f32, -0.0, -3.0))); TODO is this required?
208 expect(math.isPositiveInf(pow(f32, 0.0, -math.inf(f32))));
209 expect(math.isPositiveInf(pow(f32, -0.0, -math.inf(f32))));
210 expect(pow(f32, 0.0, math.inf(f32)) == 0.0);
211 expect(pow(f32, -0.0, math.inf(f32)) == 0.0);
212 expect(math.isPositiveInf(pow(f32, 0.0, -2.0)));
213 expect(math.isPositiveInf(pow(f32, -0.0, -2.0)));
214 expect(pow(f32, 0.0, 1.0) == 0.0);
215 expect(pow(f32, -0.0, 1.0) == -0.0);
216 expect(pow(f32, 0.0, 2.0) == 0.0);
217 expect(pow(f32, -0.0, 2.0) == 0.0);
218 expect(math.approxEq(f32, pow(f32, -1.0, math.inf(f32)), 1.0, epsilon));
219 expect(math.approxEq(f32, pow(f32, -1.0, -math.inf(f32)), 1.0, epsilon));
220 expect(math.isPositiveInf(pow(f32, 1.2, math.inf(f32))));
221 expect(math.isPositiveInf(pow(f32, -1.2, math.inf(f32))));
222 expect(pow(f32, 1.2, -math.inf(f32)) == 0.0);
223 expect(pow(f32, -1.2, -math.inf(f32)) == 0.0);
224 expect(pow(f32, 0.2, math.inf(f32)) == 0.0);
225 expect(pow(f32, -0.2, math.inf(f32)) == 0.0);
226 expect(math.isPositiveInf(pow(f32, 0.2, -math.inf(f32))));
227 expect(math.isPositiveInf(pow(f32, -0.2, -math.inf(f32))));
228 expect(math.isPositiveInf(pow(f32, math.inf(f32), 1.0)));
229 expect(pow(f32, math.inf(f32), -1.0) == 0.0);
230 //expect(pow(f32, -math.inf(f32), 5.0) == pow(f32, -0.0, -5.0)); TODO support negative 0?
231 expect(pow(f32, -math.inf(f32), -5.2) == pow(f32, -0.0, 5.2));
232 expect(math.isNan(pow(f32, -1.0, 1.2)));
233 expect(math.isNan(pow(f32, -12.4, 78.5)));
234234}
std/math/powi.zig+69-69
......@@ -12,7 +12,7 @@ const builtin = @import("builtin");
1212const std = @import("../index.zig");
1313const math = std.math;
1414const assert = std.debug.assert;
15const assertError = std.debug.assertError;
15const testing = std.testing;
1616
1717// This implementation is based on that from the rust stlib
1818pub fn powi(comptime T: type, x: T, y: T) (error{
......@@ -103,75 +103,75 @@ pub fn powi(comptime T: type, x: T, y: T) (error{
103103}
104104
105105test "math.powi" {
106 assertError(powi(i8, -66, 6), error.Underflow);
107 assertError(powi(i16, -13, 13), error.Underflow);
108 assertError(powi(i32, -32, 21), error.Underflow);
109 assertError(powi(i64, -24, 61), error.Underflow);
110 assertError(powi(i17, -15, 15), error.Underflow);
111 assertError(powi(i42, -6, 40), error.Underflow);
112
113 assert((try powi(i8, -5, 3)) == -125);
114 assert((try powi(i16, -16, 3)) == -4096);
115 assert((try powi(i32, -91, 3)) == -753571);
116 assert((try powi(i64, -36, 6)) == 2176782336);
117 assert((try powi(i17, -2, 15)) == -32768);
118 assert((try powi(i42, -5, 7)) == -78125);
119
120 assert((try powi(u8, 6, 2)) == 36);
121 assert((try powi(u16, 5, 4)) == 625);
122 assert((try powi(u32, 12, 6)) == 2985984);
123 assert((try powi(u64, 34, 2)) == 1156);
124 assert((try powi(u17, 16, 3)) == 4096);
125 assert((try powi(u42, 34, 6)) == 1544804416);
126
127 assertError(powi(i8, 120, 7), error.Overflow);
128 assertError(powi(i16, 73, 15), error.Overflow);
129 assertError(powi(i32, 23, 31), error.Overflow);
130 assertError(powi(i64, 68, 61), error.Overflow);
131 assertError(powi(i17, 15, 15), error.Overflow);
132 assertError(powi(i42, 121312, 41), error.Overflow);
133
134 assertError(powi(u8, 123, 7), error.Overflow);
135 assertError(powi(u16, 2313, 15), error.Overflow);
136 assertError(powi(u32, 8968, 31), error.Overflow);
137 assertError(powi(u64, 2342, 63), error.Overflow);
138 assertError(powi(u17, 2723, 16), error.Overflow);
139 assertError(powi(u42, 8234, 41), error.Overflow);
106 testing.expectError(error.Underflow, powi(i8, -66, 6));
107 testing.expectError(error.Underflow, powi(i16, -13, 13));
108 testing.expectError(error.Underflow, powi(i32, -32, 21));
109 testing.expectError(error.Underflow, powi(i64, -24, 61));
110 testing.expectError(error.Underflow, powi(i17, -15, 15));
111 testing.expectError(error.Underflow, powi(i42, -6, 40));
112
113 testing.expect((try powi(i8, -5, 3)) == -125);
114 testing.expect((try powi(i16, -16, 3)) == -4096);
115 testing.expect((try powi(i32, -91, 3)) == -753571);
116 testing.expect((try powi(i64, -36, 6)) == 2176782336);
117 testing.expect((try powi(i17, -2, 15)) == -32768);
118 testing.expect((try powi(i42, -5, 7)) == -78125);
119
120 testing.expect((try powi(u8, 6, 2)) == 36);
121 testing.expect((try powi(u16, 5, 4)) == 625);
122 testing.expect((try powi(u32, 12, 6)) == 2985984);
123 testing.expect((try powi(u64, 34, 2)) == 1156);
124 testing.expect((try powi(u17, 16, 3)) == 4096);
125 testing.expect((try powi(u42, 34, 6)) == 1544804416);
126
127 testing.expectError(error.Overflow, powi(i8, 120, 7));
128 testing.expectError(error.Overflow, powi(i16, 73, 15));
129 testing.expectError(error.Overflow, powi(i32, 23, 31));
130 testing.expectError(error.Overflow, powi(i64, 68, 61));
131 testing.expectError(error.Overflow, powi(i17, 15, 15));
132 testing.expectError(error.Overflow, powi(i42, 121312, 41));
133
134 testing.expectError(error.Overflow, powi(u8, 123, 7));
135 testing.expectError(error.Overflow, powi(u16, 2313, 15));
136 testing.expectError(error.Overflow, powi(u32, 8968, 31));
137 testing.expectError(error.Overflow, powi(u64, 2342, 63));
138 testing.expectError(error.Overflow, powi(u17, 2723, 16));
139 testing.expectError(error.Overflow, powi(u42, 8234, 41));
140140}
141141
142142test "math.powi.special" {
143 assertError(powi(i8, -2, 8), error.Underflow);
144 assertError(powi(i16, -2, 16), error.Underflow);
145 assertError(powi(i32, -2, 32), error.Underflow);
146 assertError(powi(i64, -2, 64), error.Underflow);
147 assertError(powi(i17, -2, 17), error.Underflow);
148 assertError(powi(i42, -2, 42), error.Underflow);
149
150 assert((try powi(i8, -1, 3)) == -1);
151 assert((try powi(i16, -1, 2)) == 1);
152 assert((try powi(i32, -1, 16)) == 1);
153 assert((try powi(i64, -1, 6)) == 1);
154 assert((try powi(i17, -1, 15)) == -1);
155 assert((try powi(i42, -1, 7)) == -1);
156
157 assert((try powi(u8, 1, 2)) == 1);
158 assert((try powi(u16, 1, 4)) == 1);
159 assert((try powi(u32, 1, 6)) == 1);
160 assert((try powi(u64, 1, 2)) == 1);
161 assert((try powi(u17, 1, 3)) == 1);
162 assert((try powi(u42, 1, 6)) == 1);
163
164 assertError(powi(i8, 2, 7), error.Overflow);
165 assertError(powi(i16, 2, 15), error.Overflow);
166 assertError(powi(i32, 2, 31), error.Overflow);
167 assertError(powi(i64, 2, 63), error.Overflow);
168 assertError(powi(i17, 2, 16), error.Overflow);
169 assertError(powi(i42, 2, 41), error.Overflow);
170
171 assertError(powi(u8, 2, 8), error.Overflow);
172 assertError(powi(u16, 2, 16), error.Overflow);
173 assertError(powi(u32, 2, 32), error.Overflow);
174 assertError(powi(u64, 2, 64), error.Overflow);
175 assertError(powi(u17, 2, 17), error.Overflow);
176 assertError(powi(u42, 2, 42), error.Overflow);
143 testing.expectError(error.Underflow, powi(i8, -2, 8));
144 testing.expectError(error.Underflow, powi(i16, -2, 16));
145 testing.expectError(error.Underflow, powi(i32, -2, 32));
146 testing.expectError(error.Underflow, powi(i64, -2, 64));
147 testing.expectError(error.Underflow, powi(i17, -2, 17));
148 testing.expectError(error.Underflow, powi(i42, -2, 42));
149
150 testing.expect((try powi(i8, -1, 3)) == -1);
151 testing.expect((try powi(i16, -1, 2)) == 1);
152 testing.expect((try powi(i32, -1, 16)) == 1);
153 testing.expect((try powi(i64, -1, 6)) == 1);
154 testing.expect((try powi(i17, -1, 15)) == -1);
155 testing.expect((try powi(i42, -1, 7)) == -1);
156
157 testing.expect((try powi(u8, 1, 2)) == 1);
158 testing.expect((try powi(u16, 1, 4)) == 1);
159 testing.expect((try powi(u32, 1, 6)) == 1);
160 testing.expect((try powi(u64, 1, 2)) == 1);
161 testing.expect((try powi(u17, 1, 3)) == 1);
162 testing.expect((try powi(u42, 1, 6)) == 1);
163
164 testing.expectError(error.Overflow, powi(i8, 2, 7));
165 testing.expectError(error.Overflow, powi(i16, 2, 15));
166 testing.expectError(error.Overflow, powi(i32, 2, 31));
167 testing.expectError(error.Overflow, powi(i64, 2, 63));
168 testing.expectError(error.Overflow, powi(i17, 2, 16));
169 testing.expectError(error.Overflow, powi(i42, 2, 41));
170
171 testing.expectError(error.Overflow, powi(u8, 2, 8));
172 testing.expectError(error.Overflow, powi(u16, 2, 16));
173 testing.expectError(error.Overflow, powi(u32, 2, 32));
174 testing.expectError(error.Overflow, powi(u64, 2, 64));
175 testing.expectError(error.Overflow, powi(u17, 2, 17));
176 testing.expectError(error.Overflow, powi(u42, 2, 42));
177177}
std/math/round.zig+21-21
......@@ -5,7 +5,7 @@
55// - round(nan) = nan
66
77const builtin = @import("builtin");
8const assert = std.debug.assert;
8const expect = std.testing.expect;
99const std = @import("../index.zig");
1010const math = std.math;
1111
......@@ -85,36 +85,36 @@ fn round64(x_: f64) f64 {
8585}
8686
8787test "math.round" {
88 assert(round(f32(1.3)) == round32(1.3));
89 assert(round(f64(1.3)) == round64(1.3));
88 expect(round(f32(1.3)) == round32(1.3));
89 expect(round(f64(1.3)) == round64(1.3));
9090}
9191
9292test "math.round32" {
93 assert(round32(1.3) == 1.0);
94 assert(round32(-1.3) == -1.0);
95 assert(round32(0.2) == 0.0);
96 assert(round32(1.8) == 2.0);
93 expect(round32(1.3) == 1.0);
94 expect(round32(-1.3) == -1.0);
95 expect(round32(0.2) == 0.0);
96 expect(round32(1.8) == 2.0);
9797}
9898
9999test "math.round64" {
100 assert(round64(1.3) == 1.0);
101 assert(round64(-1.3) == -1.0);
102 assert(round64(0.2) == 0.0);
103 assert(round64(1.8) == 2.0);
100 expect(round64(1.3) == 1.0);
101 expect(round64(-1.3) == -1.0);
102 expect(round64(0.2) == 0.0);
103 expect(round64(1.8) == 2.0);
104104}
105105
106106test "math.round32.special" {
107 assert(round32(0.0) == 0.0);
108 assert(round32(-0.0) == -0.0);
109 assert(math.isPositiveInf(round32(math.inf(f32))));
110 assert(math.isNegativeInf(round32(-math.inf(f32))));
111 assert(math.isNan(round32(math.nan(f32))));
107 expect(round32(0.0) == 0.0);
108 expect(round32(-0.0) == -0.0);
109 expect(math.isPositiveInf(round32(math.inf(f32))));
110 expect(math.isNegativeInf(round32(-math.inf(f32))));
111 expect(math.isNan(round32(math.nan(f32))));
112112}
113113
114114test "math.round64.special" {
115 assert(round64(0.0) == 0.0);
116 assert(round64(-0.0) == -0.0);
117 assert(math.isPositiveInf(round64(math.inf(f64))));
118 assert(math.isNegativeInf(round64(-math.inf(f64))));
119 assert(math.isNan(round64(math.nan(f64))));
115 expect(round64(0.0) == 0.0);
116 expect(round64(-0.0) == -0.0);
117 expect(math.isPositiveInf(round64(math.inf(f64))));
118 expect(math.isNegativeInf(round64(-math.inf(f64))));
119 expect(math.isNan(round64(math.nan(f64))));
120120}
std/math/scalbn.zig+5-5
......@@ -1,6 +1,6 @@
11const std = @import("../index.zig");
22const math = std.math;
3const assert = std.debug.assert;
3const expect = std.testing.expect;
44
55pub fn scalbn(x: var, n: i32) @typeOf(x) {
66 const T = @typeOf(x);
......@@ -72,14 +72,14 @@ fn scalbn64(x: f64, n_: i32) f64 {
7272}
7373
7474test "math.scalbn" {
75 assert(scalbn(f32(1.5), 4) == scalbn32(1.5, 4));
76 assert(scalbn(f64(1.5), 4) == scalbn64(1.5, 4));
75 expect(scalbn(f32(1.5), 4) == scalbn32(1.5, 4));
76 expect(scalbn(f64(1.5), 4) == scalbn64(1.5, 4));
7777}
7878
7979test "math.scalbn32" {
80 assert(scalbn32(1.5, 4) == 24.0);
80 expect(scalbn32(1.5, 4) == 24.0);
8181}
8282
8383test "math.scalbn64" {
84 assert(scalbn64(1.5, 4) == 24.0);
84 expect(scalbn64(1.5, 4) == 24.0);
8585}
std/math/signbit.zig+10-10
......@@ -1,6 +1,6 @@
11const std = @import("../index.zig");
22const math = std.math;
3const assert = std.debug.assert;
3const expect = std.testing.expect;
44
55pub fn signbit(x: var) bool {
66 const T = @typeOf(x);
......@@ -28,22 +28,22 @@ fn signbit64(x: f64) bool {
2828}
2929
3030test "math.signbit" {
31 assert(signbit(f16(4.0)) == signbit16(4.0));
32 assert(signbit(f32(4.0)) == signbit32(4.0));
33 assert(signbit(f64(4.0)) == signbit64(4.0));
31 expect(signbit(f16(4.0)) == signbit16(4.0));
32 expect(signbit(f32(4.0)) == signbit32(4.0));
33 expect(signbit(f64(4.0)) == signbit64(4.0));
3434}
3535
3636test "math.signbit16" {
37 assert(!signbit16(4.0));
38 assert(signbit16(-3.0));
37 expect(!signbit16(4.0));
38 expect(signbit16(-3.0));
3939}
4040
4141test "math.signbit32" {
42 assert(!signbit32(4.0));
43 assert(signbit32(-3.0));
42 expect(!signbit32(4.0));
43 expect(signbit32(-3.0));
4444}
4545
4646test "math.signbit64" {
47 assert(!signbit64(4.0));
48 assert(signbit64(-3.0));
47 expect(!signbit64(4.0));
48 expect(signbit64(-3.0));
4949}
std/math/sin.zig+26-26
......@@ -7,7 +7,7 @@
77const builtin = @import("builtin");
88const std = @import("../index.zig");
99const math = std.math;
10const assert = std.debug.assert;
10const expect = std.testing.expect;
1111
1212pub fn sin(x: var) @typeOf(x) {
1313 const T = @typeOf(x);
......@@ -142,45 +142,45 @@ fn sin64(x_: f64) f64 {
142142}
143143
144144test "math.sin" {
145 assert(sin(f32(0.0)) == sin32(0.0));
146 assert(sin(f64(0.0)) == sin64(0.0));
147 assert(comptime (math.sin(f64(2))) == math.sin(f64(2)));
145 expect(sin(f32(0.0)) == sin32(0.0));
146 expect(sin(f64(0.0)) == sin64(0.0));
147 expect(comptime (math.sin(f64(2))) == math.sin(f64(2)));
148148}
149149
150150test "math.sin32" {
151151 const epsilon = 0.000001;
152152
153 assert(math.approxEq(f32, sin32(0.0), 0.0, epsilon));
154 assert(math.approxEq(f32, sin32(0.2), 0.198669, epsilon));
155 assert(math.approxEq(f32, sin32(0.8923), 0.778517, epsilon));
156 assert(math.approxEq(f32, sin32(1.5), 0.997495, epsilon));
157 assert(math.approxEq(f32, sin32(37.45), -0.246544, epsilon));
158 assert(math.approxEq(f32, sin32(89.123), 0.916166, epsilon));
153 expect(math.approxEq(f32, sin32(0.0), 0.0, epsilon));
154 expect(math.approxEq(f32, sin32(0.2), 0.198669, epsilon));
155 expect(math.approxEq(f32, sin32(0.8923), 0.778517, epsilon));
156 expect(math.approxEq(f32, sin32(1.5), 0.997495, epsilon));
157 expect(math.approxEq(f32, sin32(37.45), -0.246544, epsilon));
158 expect(math.approxEq(f32, sin32(89.123), 0.916166, epsilon));
159159}
160160
161161test "math.sin64" {
162162 const epsilon = 0.000001;
163163
164 assert(math.approxEq(f64, sin64(0.0), 0.0, epsilon));
165 assert(math.approxEq(f64, sin64(0.2), 0.198669, epsilon));
166 assert(math.approxEq(f64, sin64(0.8923), 0.778517, epsilon));
167 assert(math.approxEq(f64, sin64(1.5), 0.997495, epsilon));
168 assert(math.approxEq(f64, sin64(37.45), -0.246543, epsilon));
169 assert(math.approxEq(f64, sin64(89.123), 0.916166, epsilon));
164 expect(math.approxEq(f64, sin64(0.0), 0.0, epsilon));
165 expect(math.approxEq(f64, sin64(0.2), 0.198669, epsilon));
166 expect(math.approxEq(f64, sin64(0.8923), 0.778517, epsilon));
167 expect(math.approxEq(f64, sin64(1.5), 0.997495, epsilon));
168 expect(math.approxEq(f64, sin64(37.45), -0.246543, epsilon));
169 expect(math.approxEq(f64, sin64(89.123), 0.916166, epsilon));
170170}
171171
172172test "math.sin32.special" {
173 assert(sin32(0.0) == 0.0);
174 assert(sin32(-0.0) == -0.0);
175 assert(math.isNan(sin32(math.inf(f32))));
176 assert(math.isNan(sin32(-math.inf(f32))));
177 assert(math.isNan(sin32(math.nan(f32))));
173 expect(sin32(0.0) == 0.0);
174 expect(sin32(-0.0) == -0.0);
175 expect(math.isNan(sin32(math.inf(f32))));
176 expect(math.isNan(sin32(-math.inf(f32))));
177 expect(math.isNan(sin32(math.nan(f32))));
178178}
179179
180180test "math.sin64.special" {
181 assert(sin64(0.0) == 0.0);
182 assert(sin64(-0.0) == -0.0);
183 assert(math.isNan(sin64(math.inf(f64))));
184 assert(math.isNan(sin64(-math.inf(f64))));
185 assert(math.isNan(sin64(math.nan(f64))));
181 expect(sin64(0.0) == 0.0);
182 expect(sin64(-0.0) == -0.0);
183 expect(math.isNan(sin64(math.inf(f64))));
184 expect(math.isNan(sin64(-math.inf(f64))));
185 expect(math.isNan(sin64(math.nan(f64))));
186186}
std/math/sinh.zig+21-21
......@@ -7,7 +7,7 @@
77const builtin = @import("builtin");
88const std = @import("../index.zig");
99const math = std.math;
10const assert = std.debug.assert;
10const expect = std.testing.expect;
1111const expo2 = @import("expo2.zig").expo2;
1212const maxInt = std.math.maxInt;
1313
......@@ -87,40 +87,40 @@ fn sinh64(x: f64) f64 {
8787}
8888
8989test "math.sinh" {
90 assert(sinh(f32(1.5)) == sinh32(1.5));
91 assert(sinh(f64(1.5)) == sinh64(1.5));
90 expect(sinh(f32(1.5)) == sinh32(1.5));
91 expect(sinh(f64(1.5)) == sinh64(1.5));
9292}
9393
9494test "math.sinh32" {
9595 const epsilon = 0.000001;
9696
97 assert(math.approxEq(f32, sinh32(0.0), 0.0, epsilon));
98 assert(math.approxEq(f32, sinh32(0.2), 0.201336, epsilon));
99 assert(math.approxEq(f32, sinh32(0.8923), 1.015512, epsilon));
100 assert(math.approxEq(f32, sinh32(1.5), 2.129279, epsilon));
97 expect(math.approxEq(f32, sinh32(0.0), 0.0, epsilon));
98 expect(math.approxEq(f32, sinh32(0.2), 0.201336, epsilon));
99 expect(math.approxEq(f32, sinh32(0.8923), 1.015512, epsilon));
100 expect(math.approxEq(f32, sinh32(1.5), 2.129279, epsilon));
101101}
102102
103103test "math.sinh64" {
104104 const epsilon = 0.000001;
105105
106 assert(math.approxEq(f64, sinh64(0.0), 0.0, epsilon));
107 assert(math.approxEq(f64, sinh64(0.2), 0.201336, epsilon));
108 assert(math.approxEq(f64, sinh64(0.8923), 1.015512, epsilon));
109 assert(math.approxEq(f64, sinh64(1.5), 2.129279, epsilon));
106 expect(math.approxEq(f64, sinh64(0.0), 0.0, epsilon));
107 expect(math.approxEq(f64, sinh64(0.2), 0.201336, epsilon));
108 expect(math.approxEq(f64, sinh64(0.8923), 1.015512, epsilon));
109 expect(math.approxEq(f64, sinh64(1.5), 2.129279, epsilon));
110110}
111111
112112test "math.sinh32.special" {
113 assert(sinh32(0.0) == 0.0);
114 assert(sinh32(-0.0) == -0.0);
115 assert(math.isPositiveInf(sinh32(math.inf(f32))));
116 assert(math.isNegativeInf(sinh32(-math.inf(f32))));
117 assert(math.isNan(sinh32(math.nan(f32))));
113 expect(sinh32(0.0) == 0.0);
114 expect(sinh32(-0.0) == -0.0);
115 expect(math.isPositiveInf(sinh32(math.inf(f32))));
116 expect(math.isNegativeInf(sinh32(-math.inf(f32))));
117 expect(math.isNan(sinh32(math.nan(f32))));
118118}
119119
120120test "math.sinh64.special" {
121 assert(sinh64(0.0) == 0.0);
122 assert(sinh64(-0.0) == -0.0);
123 assert(math.isPositiveInf(sinh64(math.inf(f64))));
124 assert(math.isNegativeInf(sinh64(-math.inf(f64))));
125 assert(math.isNan(sinh64(math.nan(f64))));
121 expect(sinh64(0.0) == 0.0);
122 expect(sinh64(-0.0) == -0.0);
123 expect(math.isPositiveInf(sinh64(math.inf(f64))));
124 expect(math.isNegativeInf(sinh64(-math.inf(f64))));
125 expect(math.isNan(sinh64(math.nan(f64))));
126126}
std/math/sqrt.zig+52-52
......@@ -7,7 +7,7 @@
77
88const std = @import("../index.zig");
99const math = std.math;
10const assert = std.debug.assert;
10const expect = std.testing.expect;
1111const builtin = @import("builtin");
1212const TypeId = builtin.TypeId;
1313const maxInt = std.math.maxInt;
......@@ -32,75 +32,75 @@ pub fn sqrt(x: var) (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typ
3232}
3333
3434test "math.sqrt" {
35 assert(sqrt(f16(0.0)) == @sqrt(f16, 0.0));
36 assert(sqrt(f32(0.0)) == @sqrt(f32, 0.0));
37 assert(sqrt(f64(0.0)) == @sqrt(f64, 0.0));
35 expect(sqrt(f16(0.0)) == @sqrt(f16, 0.0));
36 expect(sqrt(f32(0.0)) == @sqrt(f32, 0.0));
37 expect(sqrt(f64(0.0)) == @sqrt(f64, 0.0));
3838}
3939
4040test "math.sqrt16" {
4141 const epsilon = 0.000001;
4242
43 assert(@sqrt(f16, 0.0) == 0.0);
44 assert(math.approxEq(f16, @sqrt(f16, 2.0), 1.414214, epsilon));
45 assert(math.approxEq(f16, @sqrt(f16, 3.6), 1.897367, epsilon));
46 assert(@sqrt(f16, 4.0) == 2.0);
47 assert(math.approxEq(f16, @sqrt(f16, 7.539840), 2.745877, epsilon));
48 assert(math.approxEq(f16, @sqrt(f16, 19.230934), 4.385309, epsilon));
49 assert(@sqrt(f16, 64.0) == 8.0);
50 assert(math.approxEq(f16, @sqrt(f16, 64.1), 8.006248, epsilon));
51 assert(math.approxEq(f16, @sqrt(f16, 8942.230469), 94.563370, epsilon));
43 expect(@sqrt(f16, 0.0) == 0.0);
44 expect(math.approxEq(f16, @sqrt(f16, 2.0), 1.414214, epsilon));
45 expect(math.approxEq(f16, @sqrt(f16, 3.6), 1.897367, epsilon));
46 expect(@sqrt(f16, 4.0) == 2.0);
47 expect(math.approxEq(f16, @sqrt(f16, 7.539840), 2.745877, epsilon));
48 expect(math.approxEq(f16, @sqrt(f16, 19.230934), 4.385309, epsilon));
49 expect(@sqrt(f16, 64.0) == 8.0);
50 expect(math.approxEq(f16, @sqrt(f16, 64.1), 8.006248, epsilon));
51 expect(math.approxEq(f16, @sqrt(f16, 8942.230469), 94.563370, epsilon));
5252}
5353
5454test "math.sqrt32" {
5555 const epsilon = 0.000001;
5656
57 assert(@sqrt(f32, 0.0) == 0.0);
58 assert(math.approxEq(f32, @sqrt(f32, 2.0), 1.414214, epsilon));
59 assert(math.approxEq(f32, @sqrt(f32, 3.6), 1.897367, epsilon));
60 assert(@sqrt(f32, 4.0) == 2.0);
61 assert(math.approxEq(f32, @sqrt(f32, 7.539840), 2.745877, epsilon));
62 assert(math.approxEq(f32, @sqrt(f32, 19.230934), 4.385309, epsilon));
63 assert(@sqrt(f32, 64.0) == 8.0);
64 assert(math.approxEq(f32, @sqrt(f32, 64.1), 8.006248, epsilon));
65 assert(math.approxEq(f32, @sqrt(f32, 8942.230469), 94.563370, epsilon));
57 expect(@sqrt(f32, 0.0) == 0.0);
58 expect(math.approxEq(f32, @sqrt(f32, 2.0), 1.414214, epsilon));
59 expect(math.approxEq(f32, @sqrt(f32, 3.6), 1.897367, epsilon));
60 expect(@sqrt(f32, 4.0) == 2.0);
61 expect(math.approxEq(f32, @sqrt(f32, 7.539840), 2.745877, epsilon));
62 expect(math.approxEq(f32, @sqrt(f32, 19.230934), 4.385309, epsilon));
63 expect(@sqrt(f32, 64.0) == 8.0);
64 expect(math.approxEq(f32, @sqrt(f32, 64.1), 8.006248, epsilon));
65 expect(math.approxEq(f32, @sqrt(f32, 8942.230469), 94.563370, epsilon));
6666}
6767
6868test "math.sqrt64" {
6969 const epsilon = 0.000001;
7070
71 assert(@sqrt(f64, 0.0) == 0.0);
72 assert(math.approxEq(f64, @sqrt(f64, 2.0), 1.414214, epsilon));
73 assert(math.approxEq(f64, @sqrt(f64, 3.6), 1.897367, epsilon));
74 assert(@sqrt(f64, 4.0) == 2.0);
75 assert(math.approxEq(f64, @sqrt(f64, 7.539840), 2.745877, epsilon));
76 assert(math.approxEq(f64, @sqrt(f64, 19.230934), 4.385309, epsilon));
77 assert(@sqrt(f64, 64.0) == 8.0);
78 assert(math.approxEq(f64, @sqrt(f64, 64.1), 8.006248, epsilon));
79 assert(math.approxEq(f64, @sqrt(f64, 8942.230469), 94.563367, epsilon));
71 expect(@sqrt(f64, 0.0) == 0.0);
72 expect(math.approxEq(f64, @sqrt(f64, 2.0), 1.414214, epsilon));
73 expect(math.approxEq(f64, @sqrt(f64, 3.6), 1.897367, epsilon));
74 expect(@sqrt(f64, 4.0) == 2.0);
75 expect(math.approxEq(f64, @sqrt(f64, 7.539840), 2.745877, epsilon));
76 expect(math.approxEq(f64, @sqrt(f64, 19.230934), 4.385309, epsilon));
77 expect(@sqrt(f64, 64.0) == 8.0);
78 expect(math.approxEq(f64, @sqrt(f64, 64.1), 8.006248, epsilon));
79 expect(math.approxEq(f64, @sqrt(f64, 8942.230469), 94.563367, epsilon));
8080}
8181
8282test "math.sqrt16.special" {
83 assert(math.isPositiveInf(@sqrt(f16, math.inf(f16))));
84 assert(@sqrt(f16, 0.0) == 0.0);
85 assert(@sqrt(f16, -0.0) == -0.0);
86 assert(math.isNan(@sqrt(f16, -1.0)));
87 assert(math.isNan(@sqrt(f16, math.nan(f16))));
83 expect(math.isPositiveInf(@sqrt(f16, math.inf(f16))));
84 expect(@sqrt(f16, 0.0) == 0.0);
85 expect(@sqrt(f16, -0.0) == -0.0);
86 expect(math.isNan(@sqrt(f16, -1.0)));
87 expect(math.isNan(@sqrt(f16, math.nan(f16))));
8888}
8989
9090test "math.sqrt32.special" {
91 assert(math.isPositiveInf(@sqrt(f32, math.inf(f32))));
92 assert(@sqrt(f32, 0.0) == 0.0);
93 assert(@sqrt(f32, -0.0) == -0.0);
94 assert(math.isNan(@sqrt(f32, -1.0)));
95 assert(math.isNan(@sqrt(f32, math.nan(f32))));
91 expect(math.isPositiveInf(@sqrt(f32, math.inf(f32))));
92 expect(@sqrt(f32, 0.0) == 0.0);
93 expect(@sqrt(f32, -0.0) == -0.0);
94 expect(math.isNan(@sqrt(f32, -1.0)));
95 expect(math.isNan(@sqrt(f32, math.nan(f32))));
9696}
9797
9898test "math.sqrt64.special" {
99 assert(math.isPositiveInf(@sqrt(f64, math.inf(f64))));
100 assert(@sqrt(f64, 0.0) == 0.0);
101 assert(@sqrt(f64, -0.0) == -0.0);
102 assert(math.isNan(@sqrt(f64, -1.0)));
103 assert(math.isNan(@sqrt(f64, math.nan(f64))));
99 expect(math.isPositiveInf(@sqrt(f64, math.inf(f64))));
100 expect(@sqrt(f64, 0.0) == 0.0);
101 expect(@sqrt(f64, -0.0) == -0.0);
102 expect(math.isNan(@sqrt(f64, -1.0)));
103 expect(math.isNan(@sqrt(f64, math.nan(f64))));
104104}
105105
106106fn sqrt_int(comptime T: type, value: T) @IntType(false, T.bit_count / 2) {
......@@ -127,10 +127,10 @@ fn sqrt_int(comptime T: type, value: T) @IntType(false, T.bit_count / 2) {
127127}
128128
129129test "math.sqrt_int" {
130 assert(sqrt_int(u32, 3) == 1);
131 assert(sqrt_int(u32, 4) == 2);
132 assert(sqrt_int(u32, 5) == 2);
133 assert(sqrt_int(u32, 8) == 2);
134 assert(sqrt_int(u32, 9) == 3);
135 assert(sqrt_int(u32, 10) == 3);
130 expect(sqrt_int(u32, 3) == 1);
131 expect(sqrt_int(u32, 4) == 2);
132 expect(sqrt_int(u32, 5) == 2);
133 expect(sqrt_int(u32, 8) == 2);
134 expect(sqrt_int(u32, 9) == 3);
135 expect(sqrt_int(u32, 10) == 3);
136136}
std/math/tan.zig+25-25
......@@ -7,7 +7,7 @@
77const builtin = @import("builtin");
88const std = @import("../index.zig");
99const math = std.math;
10const assert = std.debug.assert;
10const expect = std.testing.expect;
1111
1212pub fn tan(x: var) @typeOf(x) {
1313 const T = @typeOf(x);
......@@ -129,44 +129,44 @@ fn tan64(x_: f64) f64 {
129129}
130130
131131test "math.tan" {
132 assert(tan(f32(0.0)) == tan32(0.0));
133 assert(tan(f64(0.0)) == tan64(0.0));
132 expect(tan(f32(0.0)) == tan32(0.0));
133 expect(tan(f64(0.0)) == tan64(0.0));
134134}
135135
136136test "math.tan32" {
137137 const epsilon = 0.000001;
138138
139 assert(math.approxEq(f32, tan32(0.0), 0.0, epsilon));
140 assert(math.approxEq(f32, tan32(0.2), 0.202710, epsilon));
141 assert(math.approxEq(f32, tan32(0.8923), 1.240422, epsilon));
142 assert(math.approxEq(f32, tan32(1.5), 14.101420, epsilon));
143 assert(math.approxEq(f32, tan32(37.45), -0.254397, epsilon));
144 assert(math.approxEq(f32, tan32(89.123), 2.285852, epsilon));
139 expect(math.approxEq(f32, tan32(0.0), 0.0, epsilon));
140 expect(math.approxEq(f32, tan32(0.2), 0.202710, epsilon));
141 expect(math.approxEq(f32, tan32(0.8923), 1.240422, epsilon));
142 expect(math.approxEq(f32, tan32(1.5), 14.101420, epsilon));
143 expect(math.approxEq(f32, tan32(37.45), -0.254397, epsilon));
144 expect(math.approxEq(f32, tan32(89.123), 2.285852, epsilon));
145145}
146146
147147test "math.tan64" {
148148 const epsilon = 0.000001;
149149
150 assert(math.approxEq(f64, tan64(0.0), 0.0, epsilon));
151 assert(math.approxEq(f64, tan64(0.2), 0.202710, epsilon));
152 assert(math.approxEq(f64, tan64(0.8923), 1.240422, epsilon));
153 assert(math.approxEq(f64, tan64(1.5), 14.101420, epsilon));
154 assert(math.approxEq(f64, tan64(37.45), -0.254397, epsilon));
155 assert(math.approxEq(f64, tan64(89.123), 2.2858376, epsilon));
150 expect(math.approxEq(f64, tan64(0.0), 0.0, epsilon));
151 expect(math.approxEq(f64, tan64(0.2), 0.202710, epsilon));
152 expect(math.approxEq(f64, tan64(0.8923), 1.240422, epsilon));
153 expect(math.approxEq(f64, tan64(1.5), 14.101420, epsilon));
154 expect(math.approxEq(f64, tan64(37.45), -0.254397, epsilon));
155 expect(math.approxEq(f64, tan64(89.123), 2.2858376, epsilon));
156156}
157157
158158test "math.tan32.special" {
159 assert(tan32(0.0) == 0.0);
160 assert(tan32(-0.0) == -0.0);
161 assert(math.isNan(tan32(math.inf(f32))));
162 assert(math.isNan(tan32(-math.inf(f32))));
163 assert(math.isNan(tan32(math.nan(f32))));
159 expect(tan32(0.0) == 0.0);
160 expect(tan32(-0.0) == -0.0);
161 expect(math.isNan(tan32(math.inf(f32))));
162 expect(math.isNan(tan32(-math.inf(f32))));
163 expect(math.isNan(tan32(math.nan(f32))));
164164}
165165
166166test "math.tan64.special" {
167 assert(tan64(0.0) == 0.0);
168 assert(tan64(-0.0) == -0.0);
169 assert(math.isNan(tan64(math.inf(f64))));
170 assert(math.isNan(tan64(-math.inf(f64))));
171 assert(math.isNan(tan64(math.nan(f64))));
167 expect(tan64(0.0) == 0.0);
168 expect(tan64(-0.0) == -0.0);
169 expect(math.isNan(tan64(math.inf(f64))));
170 expect(math.isNan(tan64(-math.inf(f64))));
171 expect(math.isNan(tan64(math.nan(f64))));
172172}
std/math/tanh.zig+23-23
......@@ -7,7 +7,7 @@
77const builtin = @import("builtin");
88const std = @import("../index.zig");
99const math = std.math;
10const assert = std.debug.assert;
10const expect = std.testing.expect;
1111const expo2 = @import("expo2.zig").expo2;
1212const maxInt = std.math.maxInt;
1313
......@@ -113,42 +113,42 @@ fn tanh64(x: f64) f64 {
113113}
114114
115115test "math.tanh" {
116 assert(tanh(f32(1.5)) == tanh32(1.5));
117 assert(tanh(f64(1.5)) == tanh64(1.5));
116 expect(tanh(f32(1.5)) == tanh32(1.5));
117 expect(tanh(f64(1.5)) == tanh64(1.5));
118118}
119119
120120test "math.tanh32" {
121121 const epsilon = 0.000001;
122122
123 assert(math.approxEq(f32, tanh32(0.0), 0.0, epsilon));
124 assert(math.approxEq(f32, tanh32(0.2), 0.197375, epsilon));
125 assert(math.approxEq(f32, tanh32(0.8923), 0.712528, epsilon));
126 assert(math.approxEq(f32, tanh32(1.5), 0.905148, epsilon));
127 assert(math.approxEq(f32, tanh32(37.45), 1.0, epsilon));
123 expect(math.approxEq(f32, tanh32(0.0), 0.0, epsilon));
124 expect(math.approxEq(f32, tanh32(0.2), 0.197375, epsilon));
125 expect(math.approxEq(f32, tanh32(0.8923), 0.712528, epsilon));
126 expect(math.approxEq(f32, tanh32(1.5), 0.905148, epsilon));
127 expect(math.approxEq(f32, tanh32(37.45), 1.0, epsilon));
128128}
129129
130130test "math.tanh64" {
131131 const epsilon = 0.000001;
132132
133 assert(math.approxEq(f64, tanh64(0.0), 0.0, epsilon));
134 assert(math.approxEq(f64, tanh64(0.2), 0.197375, epsilon));
135 assert(math.approxEq(f64, tanh64(0.8923), 0.712528, epsilon));
136 assert(math.approxEq(f64, tanh64(1.5), 0.905148, epsilon));
137 assert(math.approxEq(f64, tanh64(37.45), 1.0, epsilon));
133 expect(math.approxEq(f64, tanh64(0.0), 0.0, epsilon));
134 expect(math.approxEq(f64, tanh64(0.2), 0.197375, epsilon));
135 expect(math.approxEq(f64, tanh64(0.8923), 0.712528, epsilon));
136 expect(math.approxEq(f64, tanh64(1.5), 0.905148, epsilon));
137 expect(math.approxEq(f64, tanh64(37.45), 1.0, epsilon));
138138}
139139
140140test "math.tanh32.special" {
141 assert(tanh32(0.0) == 0.0);
142 assert(tanh32(-0.0) == -0.0);
143 assert(tanh32(math.inf(f32)) == 1.0);
144 assert(tanh32(-math.inf(f32)) == -1.0);
145 assert(math.isNan(tanh32(math.nan(f32))));
141 expect(tanh32(0.0) == 0.0);
142 expect(tanh32(-0.0) == -0.0);
143 expect(tanh32(math.inf(f32)) == 1.0);
144 expect(tanh32(-math.inf(f32)) == -1.0);
145 expect(math.isNan(tanh32(math.nan(f32))));
146146}
147147
148148test "math.tanh64.special" {
149 assert(tanh64(0.0) == 0.0);
150 assert(tanh64(-0.0) == -0.0);
151 assert(tanh64(math.inf(f64)) == 1.0);
152 assert(tanh64(-math.inf(f64)) == -1.0);
153 assert(math.isNan(tanh64(math.nan(f64))));
149 expect(tanh64(0.0) == 0.0);
150 expect(tanh64(-0.0) == -0.0);
151 expect(tanh64(math.inf(f64)) == 1.0);
152 expect(tanh64(-math.inf(f64)) == -1.0);
153 expect(math.isNan(tanh64(math.nan(f64))));
154154}
std/math/trunc.zig+19-19
......@@ -6,7 +6,7 @@
66
77const std = @import("../index.zig");
88const math = std.math;
9const assert = std.debug.assert;
9const expect = std.testing.expect;
1010const maxInt = std.math.maxInt;
1111
1212pub fn trunc(x: var) @typeOf(x) {
......@@ -61,34 +61,34 @@ fn trunc64(x: f64) f64 {
6161}
6262
6363test "math.trunc" {
64 assert(trunc(f32(1.3)) == trunc32(1.3));
65 assert(trunc(f64(1.3)) == trunc64(1.3));
64 expect(trunc(f32(1.3)) == trunc32(1.3));
65 expect(trunc(f64(1.3)) == trunc64(1.3));
6666}
6767
6868test "math.trunc32" {
69 assert(trunc32(1.3) == 1.0);
70 assert(trunc32(-1.3) == -1.0);
71 assert(trunc32(0.2) == 0.0);
69 expect(trunc32(1.3) == 1.0);
70 expect(trunc32(-1.3) == -1.0);
71 expect(trunc32(0.2) == 0.0);
7272}
7373
7474test "math.trunc64" {
75 assert(trunc64(1.3) == 1.0);
76 assert(trunc64(-1.3) == -1.0);
77 assert(trunc64(0.2) == 0.0);
75 expect(trunc64(1.3) == 1.0);
76 expect(trunc64(-1.3) == -1.0);
77 expect(trunc64(0.2) == 0.0);
7878}
7979
8080test "math.trunc32.special" {
81 assert(trunc32(0.0) == 0.0); // 0x3F800000
82 assert(trunc32(-0.0) == -0.0);
83 assert(math.isPositiveInf(trunc32(math.inf(f32))));
84 assert(math.isNegativeInf(trunc32(-math.inf(f32))));
85 assert(math.isNan(trunc32(math.nan(f32))));
81 expect(trunc32(0.0) == 0.0); // 0x3F800000
82 expect(trunc32(-0.0) == -0.0);
83 expect(math.isPositiveInf(trunc32(math.inf(f32))));
84 expect(math.isNegativeInf(trunc32(-math.inf(f32))));
85 expect(math.isNan(trunc32(math.nan(f32))));
8686}
8787
8888test "math.trunc64.special" {
89 assert(trunc64(0.0) == 0.0);
90 assert(trunc64(-0.0) == -0.0);
91 assert(math.isPositiveInf(trunc64(math.inf(f64))));
92 assert(math.isNegativeInf(trunc64(-math.inf(f64))));
93 assert(math.isNan(trunc64(math.nan(f64))));
89 expect(trunc64(0.0) == 0.0);
90 expect(trunc64(-0.0) == -0.0);
91 expect(math.isPositiveInf(trunc64(math.inf(f64))));
92 expect(math.isNegativeInf(trunc64(-math.inf(f64))));
93 expect(math.isNan(trunc64(math.nan(f64))));
9494}
std/mem.zig+160-159
......@@ -6,6 +6,7 @@ const builtin = @import("builtin");
66const mem = @This();
77const meta = std.meta;
88const trait = meta.trait;
9const testing = std.testing;
910
1011pub const Allocator = struct {
1112 pub const Error = error{OutOfMemory};
......@@ -181,7 +182,7 @@ test "mem.secureZero" {
181182 set(u8, a[0..], 0);
182183 secureZero(u8, b[0..]);
183184
184 assert(eql(u8, a[0..], b[0..]));
185 testing.expectEqualSlices(u8, a[0..], b[0..]);
185186}
186187
187188pub fn compare(comptime T: type, lhs: []const T, rhs: []const T) Compare {
......@@ -210,11 +211,11 @@ pub fn compare(comptime T: type, lhs: []const T, rhs: []const T) Compare {
210211}
211212
212213test "mem.compare" {
213 assert(compare(u8, "abcd", "bee") == Compare.LessThan);
214 assert(compare(u8, "abc", "abc") == Compare.Equal);
215 assert(compare(u8, "abc", "abc0") == Compare.LessThan);
216 assert(compare(u8, "", "") == Compare.Equal);
217 assert(compare(u8, "", "a") == Compare.LessThan);
214 testing.expect(compare(u8, "abcd", "bee") == Compare.LessThan);
215 testing.expect(compare(u8, "abc", "abc") == Compare.Equal);
216 testing.expect(compare(u8, "abc", "abc0") == Compare.LessThan);
217 testing.expect(compare(u8, "", "") == Compare.Equal);
218 testing.expect(compare(u8, "", "a") == Compare.LessThan);
218219}
219220
220221/// Returns true if lhs < rhs, false otherwise
......@@ -227,11 +228,11 @@ pub fn lessThan(comptime T: type, lhs: []const T, rhs: []const T) bool {
227228}
228229
229230test "mem.lessThan" {
230 assert(lessThan(u8, "abcd", "bee"));
231 assert(!lessThan(u8, "abc", "abc"));
232 assert(lessThan(u8, "abc", "abc0"));
233 assert(!lessThan(u8, "", ""));
234 assert(lessThan(u8, "", "a"));
231 testing.expect(lessThan(u8, "abcd", "bee"));
232 testing.expect(!lessThan(u8, "abc", "abc"));
233 testing.expect(lessThan(u8, "abc", "abc0"));
234 testing.expect(!lessThan(u8, "", ""));
235 testing.expect(lessThan(u8, "", "a"));
235236}
236237
237238/// Compares two slices and returns whether they are equal.
......@@ -296,10 +297,10 @@ pub fn trim(comptime T: type, slice: []const T, values_to_strip: []const T) []co
296297}
297298
298299test "mem.trim" {
299 assert(eql(u8, trimLeft(u8, " foo\n ", " \n"), "foo\n "));
300 assert(eql(u8, trimRight(u8, " foo\n ", " \n"), " foo"));
301 assert(eql(u8, trim(u8, " foo\n ", " \n"), "foo"));
302 assert(eql(u8, trim(u8, "foo", " \n"), "foo"));
300 testing.expectEqualSlices(u8, "foo\n ", trimLeft(u8, " foo\n ", " \n"));
301 testing.expectEqualSlices(u8, " foo", trimRight(u8, " foo\n ", " \n"));
302 testing.expectEqualSlices(u8, "foo", trim(u8, " foo\n ", " \n"));
303 testing.expectEqualSlices(u8, "foo", trim(u8, "foo", " \n"));
303304}
304305
305306/// Linear search for the index of a scalar value inside a slice.
......@@ -380,20 +381,20 @@ pub fn indexOfPos(comptime T: type, haystack: []const T, start_index: usize, nee
380381}
381382
382383test "mem.indexOf" {
383 assert(indexOf(u8, "one two three four", "four").? == 14);
384 assert(lastIndexOf(u8, "one two three two four", "two").? == 14);
385 assert(indexOf(u8, "one two three four", "gour") == null);
386 assert(lastIndexOf(u8, "one two three four", "gour") == null);
387 assert(indexOf(u8, "foo", "foo").? == 0);
388 assert(lastIndexOf(u8, "foo", "foo").? == 0);
389 assert(indexOf(u8, "foo", "fool") == null);
390 assert(lastIndexOf(u8, "foo", "lfoo") == null);
391 assert(lastIndexOf(u8, "foo", "fool") == null);
392
393 assert(indexOf(u8, "foo foo", "foo").? == 0);
394 assert(lastIndexOf(u8, "foo foo", "foo").? == 4);
395 assert(lastIndexOfAny(u8, "boo, cat", "abo").? == 6);
396 assert(lastIndexOfScalar(u8, "boo", 'o').? == 2);
384 testing.expect(indexOf(u8, "one two three four", "four").? == 14);
385 testing.expect(lastIndexOf(u8, "one two three two four", "two").? == 14);
386 testing.expect(indexOf(u8, "one two three four", "gour") == null);
387 testing.expect(lastIndexOf(u8, "one two three four", "gour") == null);
388 testing.expect(indexOf(u8, "foo", "foo").? == 0);
389 testing.expect(lastIndexOf(u8, "foo", "foo").? == 0);
390 testing.expect(indexOf(u8, "foo", "fool") == null);
391 testing.expect(lastIndexOf(u8, "foo", "lfoo") == null);
392 testing.expect(lastIndexOf(u8, "foo", "fool") == null);
393
394 testing.expect(indexOf(u8, "foo foo", "foo").? == 0);
395 testing.expect(lastIndexOf(u8, "foo foo", "foo").? == 4);
396 testing.expect(lastIndexOfAny(u8, "boo, cat", "abo").? == 6);
397 testing.expect(lastIndexOfScalar(u8, "boo", 'o').? == 2);
397398}
398399
399400/// Reads an integer from memory with size equal to bytes.len.
......@@ -504,34 +505,34 @@ test "comptime read/write int" {
504505 var bytes: [2]u8 = undefined;
505506 std.mem.writeIntLittle(u16, &bytes, 0x1234);
506507 const result = std.mem.readIntBig(u16, &bytes);
507 std.debug.assert(result == 0x3412);
508 testing.expect(result == 0x3412);
508509 }
509510 comptime {
510511 var bytes: [2]u8 = undefined;
511512 std.mem.writeIntBig(u16, &bytes, 0x1234);
512513 const result = std.mem.readIntLittle(u16, &bytes);
513 std.debug.assert(result == 0x3412);
514 testing.expect(result == 0x3412);
514515 }
515516}
516517
517518test "readIntBig and readIntLittle" {
518 assert(readIntSliceBig(u0, []u8{}) == 0x0);
519 assert(readIntSliceLittle(u0, []u8{}) == 0x0);
519 testing.expect(readIntSliceBig(u0, []u8{}) == 0x0);
520 testing.expect(readIntSliceLittle(u0, []u8{}) == 0x0);
520521
521 assert(readIntSliceBig(u8, []u8{0x32}) == 0x32);
522 assert(readIntSliceLittle(u8, []u8{0x12}) == 0x12);
522 testing.expect(readIntSliceBig(u8, []u8{0x32}) == 0x32);
523 testing.expect(readIntSliceLittle(u8, []u8{0x12}) == 0x12);
523524
524 assert(readIntSliceBig(u16, []u8{ 0x12, 0x34 }) == 0x1234);
525 assert(readIntSliceLittle(u16, []u8{ 0x12, 0x34 }) == 0x3412);
525 testing.expect(readIntSliceBig(u16, []u8{ 0x12, 0x34 }) == 0x1234);
526 testing.expect(readIntSliceLittle(u16, []u8{ 0x12, 0x34 }) == 0x3412);
526527
527 assert(readIntSliceBig(u72, []u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }) == 0x123456789abcdef024);
528 assert(readIntSliceLittle(u72, []u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }) == 0xfedcba9876543210ec);
528 testing.expect(readIntSliceBig(u72, []u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }) == 0x123456789abcdef024);
529 testing.expect(readIntSliceLittle(u72, []u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }) == 0xfedcba9876543210ec);
529530
530 assert(readIntSliceBig(i8, []u8{0xff}) == -1);
531 assert(readIntSliceLittle(i8, []u8{0xfe}) == -2);
531 testing.expect(readIntSliceBig(i8, []u8{0xff}) == -1);
532 testing.expect(readIntSliceLittle(i8, []u8{0xfe}) == -2);
532533
533 assert(readIntSliceBig(i16, []u8{ 0xff, 0xfd }) == -3);
534 assert(readIntSliceLittle(i16, []u8{ 0xfc, 0xff }) == -4);
534 testing.expect(readIntSliceBig(i16, []u8{ 0xff, 0xfd }) == -3);
535 testing.expect(readIntSliceLittle(i16, []u8{ 0xfc, 0xff }) == -4);
535536}
536537
537538/// Writes an integer to memory, storing it in twos-complement.
......@@ -645,34 +646,34 @@ test "writeIntBig and writeIntLittle" {
645646 var buf9: [9]u8 = undefined;
646647
647648 writeIntBig(u0, &buf0, 0x0);
648 assert(eql_slice_u8(buf0[0..], []u8{}));
649 testing.expect(eql_slice_u8(buf0[0..], []u8{}));
649650 writeIntLittle(u0, &buf0, 0x0);
650 assert(eql_slice_u8(buf0[0..], []u8{}));
651 testing.expect(eql_slice_u8(buf0[0..], []u8{}));
651652
652653 writeIntBig(u8, &buf1, 0x12);
653 assert(eql_slice_u8(buf1[0..], []u8{0x12}));
654 testing.expect(eql_slice_u8(buf1[0..], []u8{0x12}));
654655 writeIntLittle(u8, &buf1, 0x34);
655 assert(eql_slice_u8(buf1[0..], []u8{0x34}));
656 testing.expect(eql_slice_u8(buf1[0..], []u8{0x34}));
656657
657658 writeIntBig(u16, &buf2, 0x1234);
658 assert(eql_slice_u8(buf2[0..], []u8{ 0x12, 0x34 }));
659 testing.expect(eql_slice_u8(buf2[0..], []u8{ 0x12, 0x34 }));
659660 writeIntLittle(u16, &buf2, 0x5678);
660 assert(eql_slice_u8(buf2[0..], []u8{ 0x78, 0x56 }));
661 testing.expect(eql_slice_u8(buf2[0..], []u8{ 0x78, 0x56 }));
661662
662663 writeIntBig(u72, &buf9, 0x123456789abcdef024);
663 assert(eql_slice_u8(buf9[0..], []u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }));
664 testing.expect(eql_slice_u8(buf9[0..], []u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }));
664665 writeIntLittle(u72, &buf9, 0xfedcba9876543210ec);
665 assert(eql_slice_u8(buf9[0..], []u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }));
666 testing.expect(eql_slice_u8(buf9[0..], []u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }));
666667
667668 writeIntBig(i8, &buf1, -1);
668 assert(eql_slice_u8(buf1[0..], []u8{0xff}));
669 testing.expect(eql_slice_u8(buf1[0..], []u8{0xff}));
669670 writeIntLittle(i8, &buf1, -2);
670 assert(eql_slice_u8(buf1[0..], []u8{0xfe}));
671 testing.expect(eql_slice_u8(buf1[0..], []u8{0xfe}));
671672
672673 writeIntBig(i16, &buf2, -3);
673 assert(eql_slice_u8(buf2[0..], []u8{ 0xff, 0xfd }));
674 testing.expect(eql_slice_u8(buf2[0..], []u8{ 0xff, 0xfd }));
674675 writeIntLittle(i16, &buf2, -4);
675 assert(eql_slice_u8(buf2[0..], []u8{ 0xfc, 0xff }));
676 testing.expect(eql_slice_u8(buf2[0..], []u8{ 0xfc, 0xff }));
676677}
677678
678679pub fn hash_slice_u8(k: []const u8) u32 {
......@@ -706,46 +707,46 @@ pub fn tokenize(buffer: []const u8, delimiter_bytes: []const u8) TokenIterator {
706707
707708test "mem.tokenize" {
708709 var it = tokenize(" abc def ghi ", " ");
709 assert(eql(u8, it.next().?, "abc"));
710 assert(eql(u8, it.next().?, "def"));
711 assert(eql(u8, it.next().?, "ghi"));
712 assert(it.next() == null);
710 testing.expect(eql(u8, it.next().?, "abc"));
711 testing.expect(eql(u8, it.next().?, "def"));
712 testing.expect(eql(u8, it.next().?, "ghi"));
713 testing.expect(it.next() == null);
713714
714715 it = tokenize("..\\bob", "\\");
715 assert(eql(u8, it.next().?, ".."));
716 assert(eql(u8, "..", "..\\bob"[0..it.index]));
717 assert(eql(u8, it.next().?, "bob"));
718 assert(it.next() == null);
716 testing.expect(eql(u8, it.next().?, ".."));
717 testing.expect(eql(u8, "..", "..\\bob"[0..it.index]));
718 testing.expect(eql(u8, it.next().?, "bob"));
719 testing.expect(it.next() == null);
719720
720721 it = tokenize("//a/b", "/");
721 assert(eql(u8, it.next().?, "a"));
722 assert(eql(u8, it.next().?, "b"));
723 assert(eql(u8, "//a/b", "//a/b"[0..it.index]));
724 assert(it.next() == null);
722 testing.expect(eql(u8, it.next().?, "a"));
723 testing.expect(eql(u8, it.next().?, "b"));
724 testing.expect(eql(u8, "//a/b", "//a/b"[0..it.index]));
725 testing.expect(it.next() == null);
725726
726727 it = tokenize("|", "|");
727 assert(it.next() == null);
728 testing.expect(it.next() == null);
728729
729730 it = tokenize("", "|");
730 assert(it.next() == null);
731 testing.expect(it.next() == null);
731732
732733 it = tokenize("hello", "");
733 assert(eql(u8, it.next().?, "hello"));
734 assert(it.next() == null);
734 testing.expect(eql(u8, it.next().?, "hello"));
735 testing.expect(it.next() == null);
735736
736737 it = tokenize("hello", " ");
737 assert(eql(u8, it.next().?, "hello"));
738 assert(it.next() == null);
738 testing.expect(eql(u8, it.next().?, "hello"));
739 testing.expect(it.next() == null);
739740}
740741
741742test "mem.tokenize (multibyte)" {
742743 var it = tokenize("a|b,c/d e", " /,|");
743 assert(eql(u8, it.next().?, "a"));
744 assert(eql(u8, it.next().?, "b"));
745 assert(eql(u8, it.next().?, "c"));
746 assert(eql(u8, it.next().?, "d"));
747 assert(eql(u8, it.next().?, "e"));
748 assert(it.next() == null);
744 testing.expect(eql(u8, it.next().?, "a"));
745 testing.expect(eql(u8, it.next().?, "b"));
746 testing.expect(eql(u8, it.next().?, "c"));
747 testing.expect(eql(u8, it.next().?, "d"));
748 testing.expect(eql(u8, it.next().?, "e"));
749 testing.expect(it.next() == null);
749750}
750751
751752/// Returns an iterator that iterates over the slices of `buffer` that
......@@ -769,34 +770,34 @@ pub fn separate(buffer: []const u8, delimiter: []const u8) SplitIterator {
769770
770771test "mem.separate" {
771772 var it = separate("abc|def||ghi", "|");
772 assert(eql(u8, it.next().?, "abc"));
773 assert(eql(u8, it.next().?, "def"));
774 assert(eql(u8, it.next().?, ""));
775 assert(eql(u8, it.next().?, "ghi"));
776 assert(it.next() == null);
773 testing.expect(eql(u8, it.next().?, "abc"));
774 testing.expect(eql(u8, it.next().?, "def"));
775 testing.expect(eql(u8, it.next().?, ""));
776 testing.expect(eql(u8, it.next().?, "ghi"));
777 testing.expect(it.next() == null);
777778
778779 it = separate("", "|");
779 assert(eql(u8, it.next().?, ""));
780 assert(it.next() == null);
780 testing.expect(eql(u8, it.next().?, ""));
781 testing.expect(it.next() == null);
781782
782783 it = separate("|", "|");
783 assert(eql(u8, it.next().?, ""));
784 assert(eql(u8, it.next().?, ""));
785 assert(it.next() == null);
784 testing.expect(eql(u8, it.next().?, ""));
785 testing.expect(eql(u8, it.next().?, ""));
786 testing.expect(it.next() == null);
786787
787788 it = separate("hello", " ");
788 assert(eql(u8, it.next().?, "hello"));
789 assert(it.next() == null);
789 testing.expect(eql(u8, it.next().?, "hello"));
790 testing.expect(it.next() == null);
790791}
791792
792793test "mem.separate (multibyte)" {
793794 var it = separate("a, b ,, c, d, e", ", ");
794 assert(eql(u8, it.next().?, "a"));
795 assert(eql(u8, it.next().?, "b ,"));
796 assert(eql(u8, it.next().?, "c"));
797 assert(eql(u8, it.next().?, "d"));
798 assert(eql(u8, it.next().?, "e"));
799 assert(it.next() == null);
795 testing.expect(eql(u8, it.next().?, "a"));
796 testing.expect(eql(u8, it.next().?, "b ,"));
797 testing.expect(eql(u8, it.next().?, "c"));
798 testing.expect(eql(u8, it.next().?, "d"));
799 testing.expect(eql(u8, it.next().?, "e"));
800 testing.expect(it.next() == null);
800801}
801802
802803pub fn startsWith(comptime T: type, haystack: []const T, needle: []const T) bool {
......@@ -804,8 +805,8 @@ pub fn startsWith(comptime T: type, haystack: []const T, needle: []const T) bool
804805}
805806
806807test "mem.startsWith" {
807 assert(startsWith(u8, "Bob", "Bo"));
808 assert(!startsWith(u8, "Needle in haystack", "haystack"));
808 testing.expect(startsWith(u8, "Bob", "Bo"));
809 testing.expect(!startsWith(u8, "Needle in haystack", "haystack"));
809810}
810811
811812pub fn endsWith(comptime T: type, haystack: []const T, needle: []const T) bool {
......@@ -813,8 +814,8 @@ pub fn endsWith(comptime T: type, haystack: []const T, needle: []const T) bool {
813814}
814815
815816test "mem.endsWith" {
816 assert(endsWith(u8, "Needle in haystack", "haystack"));
817 assert(!endsWith(u8, "Bob", "Bo"));
817 testing.expect(endsWith(u8, "Needle in haystack", "haystack"));
818 testing.expect(!endsWith(u8, "Bob", "Bo"));
818819}
819820
820821pub const TokenIterator = struct {
......@@ -913,15 +914,15 @@ pub fn join(allocator: *Allocator, separator: []const u8, slices: []const []cons
913914test "mem.join" {
914915 var buf: [1024]u8 = undefined;
915916 const a = &std.heap.FixedBufferAllocator.init(&buf).allocator;
916 assert(eql(u8, try join(a, ",", [][]const u8{ "a", "b", "c" }), "a,b,c"));
917 assert(eql(u8, try join(a, ",", [][]const u8{"a"}), "a"));
918 assert(eql(u8, try join(a, ",", [][]const u8{ "a", "", "b", "", "c" }), "a,,b,,c"));
917 testing.expect(eql(u8, try join(a, ",", [][]const u8{ "a", "b", "c" }), "a,b,c"));
918 testing.expect(eql(u8, try join(a, ",", [][]const u8{"a"}), "a"));
919 testing.expect(eql(u8, try join(a, ",", [][]const u8{ "a", "", "b", "", "c" }), "a,,b,,c"));
919920}
920921
921922test "testStringEquality" {
922 assert(eql(u8, "abcd", "abcd"));
923 assert(!eql(u8, "abcdef", "abZdef"));
924 assert(!eql(u8, "abcdefg", "abcdef"));
923 testing.expect(eql(u8, "abcd", "abcd"));
924 testing.expect(!eql(u8, "abcdef", "abZdef"));
925 testing.expect(!eql(u8, "abcdefg", "abcdef"));
925926}
926927
927928test "testReadInt" {
......@@ -936,12 +937,12 @@ fn testReadIntImpl() void {
936937 0x56,
937938 0x78,
938939 };
939 assert(readInt(u32, &bytes, builtin.Endian.Big) == 0x12345678);
940 assert(readIntBig(u32, &bytes) == 0x12345678);
941 assert(readIntBig(i32, &bytes) == 0x12345678);
942 assert(readInt(u32, &bytes, builtin.Endian.Little) == 0x78563412);
943 assert(readIntLittle(u32, &bytes) == 0x78563412);
944 assert(readIntLittle(i32, &bytes) == 0x78563412);
940 testing.expect(readInt(u32, &bytes, builtin.Endian.Big) == 0x12345678);
941 testing.expect(readIntBig(u32, &bytes) == 0x12345678);
942 testing.expect(readIntBig(i32, &bytes) == 0x12345678);
943 testing.expect(readInt(u32, &bytes, builtin.Endian.Little) == 0x78563412);
944 testing.expect(readIntLittle(u32, &bytes) == 0x78563412);
945 testing.expect(readIntLittle(i32, &bytes) == 0x78563412);
945946 }
946947 {
947948 const buf = []u8{
......@@ -951,7 +952,7 @@ fn testReadIntImpl() void {
951952 0x34,
952953 };
953954 const answer = readInt(u32, &buf, builtin.Endian.Big);
954 assert(answer == 0x00001234);
955 testing.expect(answer == 0x00001234);
955956 }
956957 {
957958 const buf = []u8{
......@@ -961,17 +962,17 @@ fn testReadIntImpl() void {
961962 0x00,
962963 };
963964 const answer = readInt(u32, &buf, builtin.Endian.Little);
964 assert(answer == 0x00003412);
965 testing.expect(answer == 0x00003412);
965966 }
966967 {
967968 const bytes = []u8{
968969 0xff,
969970 0xfe,
970971 };
971 assert(readIntBig(u16, &bytes) == 0xfffe);
972 assert(readIntBig(i16, &bytes) == -0x0002);
973 assert(readIntLittle(u16, &bytes) == 0xfeff);
974 assert(readIntLittle(i16, &bytes) == -0x0101);
972 testing.expect(readIntBig(u16, &bytes) == 0xfffe);
973 testing.expect(readIntBig(i16, &bytes) == -0x0002);
974 testing.expect(readIntLittle(u16, &bytes) == 0xfeff);
975 testing.expect(readIntLittle(i16, &bytes) == -0x0101);
975976 }
976977}
977978
......@@ -983,19 +984,19 @@ fn testWriteIntImpl() void {
983984 var bytes: [8]u8 = undefined;
984985
985986 writeIntSlice(u0, bytes[0..], 0, builtin.Endian.Big);
986 assert(eql(u8, bytes, []u8{
987 testing.expect(eql(u8, bytes, []u8{
987988 0x00, 0x00, 0x00, 0x00,
988989 0x00, 0x00, 0x00, 0x00,
989990 }));
990991
991992 writeIntSlice(u0, bytes[0..], 0, builtin.Endian.Little);
992 assert(eql(u8, bytes, []u8{
993 testing.expect(eql(u8, bytes, []u8{
993994 0x00, 0x00, 0x00, 0x00,
994995 0x00, 0x00, 0x00, 0x00,
995996 }));
996997
997998 writeIntSlice(u64, bytes[0..], 0x12345678CAFEBABE, builtin.Endian.Big);
998 assert(eql(u8, bytes, []u8{
999 testing.expect(eql(u8, bytes, []u8{
9991000 0x12,
10001001 0x34,
10011002 0x56,
......@@ -1007,7 +1008,7 @@ fn testWriteIntImpl() void {
10071008 }));
10081009
10091010 writeIntSlice(u64, bytes[0..], 0xBEBAFECA78563412, builtin.Endian.Little);
1010 assert(eql(u8, bytes, []u8{
1011 testing.expect(eql(u8, bytes, []u8{
10111012 0x12,
10121013 0x34,
10131014 0x56,
......@@ -1019,7 +1020,7 @@ fn testWriteIntImpl() void {
10191020 }));
10201021
10211022 writeIntSlice(u32, bytes[0..], 0x12345678, builtin.Endian.Big);
1022 assert(eql(u8, bytes, []u8{
1023 testing.expect(eql(u8, bytes, []u8{
10231024 0x00,
10241025 0x00,
10251026 0x00,
......@@ -1031,7 +1032,7 @@ fn testWriteIntImpl() void {
10311032 }));
10321033
10331034 writeIntSlice(u32, bytes[0..], 0x78563412, builtin.Endian.Little);
1034 assert(eql(u8, bytes, []u8{
1035 testing.expect(eql(u8, bytes, []u8{
10351036 0x12,
10361037 0x34,
10371038 0x56,
......@@ -1043,7 +1044,7 @@ fn testWriteIntImpl() void {
10431044 }));
10441045
10451046 writeIntSlice(u16, bytes[0..], 0x1234, builtin.Endian.Big);
1046 assert(eql(u8, bytes, []u8{
1047 testing.expect(eql(u8, bytes, []u8{
10471048 0x00,
10481049 0x00,
10491050 0x00,
......@@ -1055,7 +1056,7 @@ fn testWriteIntImpl() void {
10551056 }));
10561057
10571058 writeIntSlice(u16, bytes[0..], 0x1234, builtin.Endian.Little);
1058 assert(eql(u8, bytes, []u8{
1059 testing.expect(eql(u8, bytes, []u8{
10591060 0x34,
10601061 0x12,
10611062 0x00,
......@@ -1076,7 +1077,7 @@ pub fn min(comptime T: type, slice: []const T) T {
10761077}
10771078
10781079test "mem.min" {
1079 assert(min(u8, "abcdefg") == 'a');
1080 testing.expect(min(u8, "abcdefg") == 'a');
10801081}
10811082
10821083pub fn max(comptime T: type, slice: []const T) T {
......@@ -1088,7 +1089,7 @@ pub fn max(comptime T: type, slice: []const T) T {
10881089}
10891090
10901091test "mem.max" {
1091 assert(max(u8, "abcdefg") == 'g');
1092 testing.expect(max(u8, "abcdefg") == 'g');
10921093}
10931094
10941095pub fn swap(comptime T: type, a: *T, b: *T) void {
......@@ -1116,7 +1117,7 @@ test "std.mem.reverse" {
11161117 };
11171118 reverse(i32, arr[0..]);
11181119
1119 assert(eql(i32, arr, []i32{
1120 testing.expect(eql(i32, arr, []i32{
11201121 4,
11211122 2,
11221123 1,
......@@ -1143,7 +1144,7 @@ test "std.mem.rotate" {
11431144 };
11441145 rotate(i32, arr[0..], 2);
11451146
1146 assert(eql(i32, arr, []i32{
1147 testing.expect(eql(i32, arr, []i32{
11471148 1,
11481149 2,
11491150 4,
......@@ -1225,12 +1226,12 @@ test "std.mem.asBytes" {
12251226 builtin.Endian.Little => "\xEF\xBE\xAD\xDE",
12261227 };
12271228
1228 debug.assert(std.mem.eql(u8, asBytes(&deadbeef), deadbeef_bytes));
1229 testing.expect(std.mem.eql(u8, asBytes(&deadbeef), deadbeef_bytes));
12291230
12301231 var codeface = u32(0xC0DEFACE);
12311232 for (asBytes(&codeface).*) |*b|
12321233 b.* = 0;
1233 debug.assert(codeface == 0);
1234 testing.expect(codeface == 0);
12341235
12351236 const S = packed struct {
12361237 a: u8,
......@@ -1245,7 +1246,7 @@ test "std.mem.asBytes" {
12451246 .c = 0xDE,
12461247 .d = 0xA1,
12471248 };
1248 debug.assert(std.mem.eql(u8, asBytes(&inst), "\xBE\xEF\xDE\xA1"));
1249 testing.expect(std.mem.eql(u8, asBytes(&inst), "\xBE\xEF\xDE\xA1"));
12491250}
12501251
12511252///Given any value, returns a copy of its bytes in an array.
......@@ -1256,14 +1257,14 @@ pub fn toBytes(value: var) [@sizeOf(@typeOf(value))]u8 {
12561257test "std.mem.toBytes" {
12571258 var my_bytes = toBytes(u32(0x12345678));
12581259 switch (builtin.endian) {
1259 builtin.Endian.Big => debug.assert(std.mem.eql(u8, my_bytes, "\x12\x34\x56\x78")),
1260 builtin.Endian.Little => debug.assert(std.mem.eql(u8, my_bytes, "\x78\x56\x34\x12")),
1260 builtin.Endian.Big => testing.expect(std.mem.eql(u8, my_bytes, "\x12\x34\x56\x78")),
1261 builtin.Endian.Little => testing.expect(std.mem.eql(u8, my_bytes, "\x78\x56\x34\x12")),
12611262 }
12621263
12631264 my_bytes[0] = '\x99';
12641265 switch (builtin.endian) {
1265 builtin.Endian.Big => debug.assert(std.mem.eql(u8, my_bytes, "\x99\x34\x56\x78")),
1266 builtin.Endian.Little => debug.assert(std.mem.eql(u8, my_bytes, "\x99\x56\x34\x12")),
1266 builtin.Endian.Big => testing.expect(std.mem.eql(u8, my_bytes, "\x99\x34\x56\x78")),
1267 builtin.Endian.Little => testing.expect(std.mem.eql(u8, my_bytes, "\x99\x56\x34\x12")),
12671268 }
12681269}
12691270
......@@ -1292,17 +1293,17 @@ test "std.mem.bytesAsValue" {
12921293 builtin.Endian.Little => "\xEF\xBE\xAD\xDE",
12931294 };
12941295
1295 debug.assert(deadbeef == bytesAsValue(u32, &deadbeef_bytes).*);
1296 testing.expect(deadbeef == bytesAsValue(u32, &deadbeef_bytes).*);
12961297
12971298 var codeface_bytes = switch (builtin.endian) {
12981299 builtin.Endian.Big => "\xC0\xDE\xFA\xCE",
12991300 builtin.Endian.Little => "\xCE\xFA\xDE\xC0",
13001301 };
13011302 var codeface = bytesAsValue(u32, &codeface_bytes);
1302 debug.assert(codeface.* == 0xC0DEFACE);
1303 testing.expect(codeface.* == 0xC0DEFACE);
13031304 codeface.* = 0;
13041305 for (codeface_bytes) |b|
1305 debug.assert(b == 0);
1306 testing.expect(b == 0);
13061307
13071308 const S = packed struct {
13081309 a: u8,
......@@ -1319,7 +1320,7 @@ test "std.mem.bytesAsValue" {
13191320 };
13201321 const inst_bytes = "\xBE\xEF\xDE\xA1";
13211322 const inst2 = bytesAsValue(S, &inst_bytes);
1322 debug.assert(meta.eql(inst, inst2.*));
1323 testing.expect(meta.eql(inst, inst2.*));
13231324}
13241325
13251326///Given a pointer to an array of bytes, returns a value of the specified type backed by a
......@@ -1334,7 +1335,7 @@ test "std.mem.bytesToValue" {
13341335 };
13351336
13361337 const deadbeef = bytesToValue(u32, deadbeef_bytes);
1337 debug.assert(deadbeef == u32(0xDEADBEEF));
1338 testing.expect(deadbeef == u32(0xDEADBEEF));
13381339}
13391340
13401341fn SubArrayPtrReturnType(comptime T: type, comptime length: usize) type {
......@@ -1345,7 +1346,7 @@ fn SubArrayPtrReturnType(comptime T: type, comptime length: usize) type {
13451346
13461347///Given a pointer to an array, returns a pointer to a portion of that array, preserving constness.
13471348pub fn subArrayPtr(ptr: var, comptime start: usize, comptime length: usize) SubArrayPtrReturnType(@typeOf(ptr), length) {
1348 debug.assert(start + length <= ptr.*.len);
1349 assert(start + length <= ptr.*.len);
13491350
13501351 const ReturnType = SubArrayPtrReturnType(@typeOf(ptr), length);
13511352 const T = meta.Child(meta.Child(@typeOf(ptr)));
......@@ -1355,14 +1356,14 @@ pub fn subArrayPtr(ptr: var, comptime start: usize, comptime length: usize) SubA
13551356test "std.mem.subArrayPtr" {
13561357 const a1 = "abcdef";
13571358 const sub1 = subArrayPtr(&a1, 2, 3);
1358 debug.assert(std.mem.eql(u8, sub1.*, "cde"));
1359 testing.expect(std.mem.eql(u8, sub1.*, "cde"));
13591360
13601361 var a2 = "abcdef";
13611362 var sub2 = subArrayPtr(&a2, 2, 3);
13621363
1363 debug.assert(std.mem.eql(u8, sub2, "cde"));
1364 testing.expect(std.mem.eql(u8, sub2, "cde"));
13641365 sub2[1] = 'X';
1365 debug.assert(std.mem.eql(u8, a2, "abcXef"));
1366 testing.expect(std.mem.eql(u8, a2, "abcXef"));
13661367}
13671368
13681369/// Round an address up to the nearest aligned address
......@@ -1371,16 +1372,16 @@ pub fn alignForward(addr: usize, alignment: usize) usize {
13711372}
13721373
13731374test "std.mem.alignForward" {
1374 debug.assertOrPanic(alignForward(1, 1) == 1);
1375 debug.assertOrPanic(alignForward(2, 1) == 2);
1376 debug.assertOrPanic(alignForward(1, 2) == 2);
1377 debug.assertOrPanic(alignForward(2, 2) == 2);
1378 debug.assertOrPanic(alignForward(3, 2) == 4);
1379 debug.assertOrPanic(alignForward(4, 2) == 4);
1380 debug.assertOrPanic(alignForward(7, 8) == 8);
1381 debug.assertOrPanic(alignForward(8, 8) == 8);
1382 debug.assertOrPanic(alignForward(9, 8) == 16);
1383 debug.assertOrPanic(alignForward(15, 8) == 16);
1384 debug.assertOrPanic(alignForward(16, 8) == 16);
1385 debug.assertOrPanic(alignForward(17, 8) == 24);
1375 testing.expect(alignForward(1, 1) == 1);
1376 testing.expect(alignForward(2, 1) == 2);
1377 testing.expect(alignForward(1, 2) == 2);
1378 testing.expect(alignForward(2, 2) == 2);
1379 testing.expect(alignForward(3, 2) == 4);
1380 testing.expect(alignForward(4, 2) == 4);
1381 testing.expect(alignForward(7, 8) == 8);
1382 testing.expect(alignForward(8, 8) == 8);
1383 testing.expect(alignForward(9, 8) == 16);
1384 testing.expect(alignForward(15, 8) == 16);
1385 testing.expect(alignForward(16, 8) == 16);
1386 testing.expect(alignForward(17, 8) == 24);
13861387}
std/meta/index.zig+76-75
......@@ -3,6 +3,7 @@ const builtin = @import("builtin");
33const debug = std.debug;
44const mem = std.mem;
55const math = std.math;
6const testing = std.testing;
67
78pub const trait = @import("trait.zig");
89
......@@ -64,16 +65,16 @@ test "std.meta.tagName" {
6465 var u2a = U2{ .C = 0 };
6566 var u2b = U2{ .D = 0 };
6667
67 debug.assert(mem.eql(u8, tagName(E1.A), "A"));
68 debug.assert(mem.eql(u8, tagName(E1.B), "B"));
69 debug.assert(mem.eql(u8, tagName(E2.C), "C"));
70 debug.assert(mem.eql(u8, tagName(E2.D), "D"));
71 debug.assert(mem.eql(u8, tagName(error.E), "E"));
72 debug.assert(mem.eql(u8, tagName(error.F), "F"));
73 debug.assert(mem.eql(u8, tagName(u1g), "G"));
74 debug.assert(mem.eql(u8, tagName(u1h), "H"));
75 debug.assert(mem.eql(u8, tagName(u2a), "C"));
76 debug.assert(mem.eql(u8, tagName(u2b), "D"));
68 testing.expect(mem.eql(u8, tagName(E1.A), "A"));
69 testing.expect(mem.eql(u8, tagName(E1.B), "B"));
70 testing.expect(mem.eql(u8, tagName(E2.C), "C"));
71 testing.expect(mem.eql(u8, tagName(E2.D), "D"));
72 testing.expect(mem.eql(u8, tagName(error.E), "E"));
73 testing.expect(mem.eql(u8, tagName(error.F), "F"));
74 testing.expect(mem.eql(u8, tagName(u1g), "G"));
75 testing.expect(mem.eql(u8, tagName(u1h), "H"));
76 testing.expect(mem.eql(u8, tagName(u2a), "C"));
77 testing.expect(mem.eql(u8, tagName(u2b), "D"));
7778}
7879
7980pub fn stringToEnum(comptime T: type, str: []const u8) ?T {
......@@ -90,9 +91,9 @@ test "std.meta.stringToEnum" {
9091 A,
9192 B,
9293 };
93 debug.assert(E1.A == stringToEnum(E1, "A").?);
94 debug.assert(E1.B == stringToEnum(E1, "B").?);
95 debug.assert(null == stringToEnum(E1, "C"));
94 testing.expect(E1.A == stringToEnum(E1, "A").?);
95 testing.expect(E1.B == stringToEnum(E1, "B").?);
96 testing.expect(null == stringToEnum(E1, "C"));
9697}
9798
9899pub fn bitCount(comptime T: type) comptime_int {
......@@ -104,8 +105,8 @@ pub fn bitCount(comptime T: type) comptime_int {
104105}
105106
106107test "std.meta.bitCount" {
107 debug.assert(bitCount(u8) == 8);
108 debug.assert(bitCount(f32) == 32);
108 testing.expect(bitCount(u8) == 8);
109 testing.expect(bitCount(f32) == 32);
109110}
110111
111112pub fn alignment(comptime T: type) comptime_int {
......@@ -115,11 +116,11 @@ pub fn alignment(comptime T: type) comptime_int {
115116}
116117
117118test "std.meta.alignment" {
118 debug.assert(alignment(u8) == 1);
119 debug.assert(alignment(*align(1) u8) == 1);
120 debug.assert(alignment(*align(2) u8) == 2);
121 debug.assert(alignment([]align(1) u8) == 1);
122 debug.assert(alignment([]align(2) u8) == 2);
119 testing.expect(alignment(u8) == 1);
120 testing.expect(alignment(*align(1) u8) == 1);
121 testing.expect(alignment(*align(2) u8) == 2);
122 testing.expect(alignment([]align(1) u8) == 1);
123 testing.expect(alignment([]align(2) u8) == 2);
123124}
124125
125126pub fn Child(comptime T: type) type {
......@@ -133,11 +134,11 @@ pub fn Child(comptime T: type) type {
133134}
134135
135136test "std.meta.Child" {
136 debug.assert(Child([1]u8) == u8);
137 debug.assert(Child(*u8) == u8);
138 debug.assert(Child([]u8) == u8);
139 debug.assert(Child(?u8) == u8);
140 debug.assert(Child(promise->u8) == u8);
137 testing.expect(Child([1]u8) == u8);
138 testing.expect(Child(*u8) == u8);
139 testing.expect(Child([]u8) == u8);
140 testing.expect(Child(?u8) == u8);
141 testing.expect(Child(promise->u8) == u8);
141142}
142143
143144pub fn containerLayout(comptime T: type) TypeInfo.ContainerLayout {
......@@ -172,15 +173,15 @@ test "std.meta.containerLayout" {
172173 a: u8,
173174 };
174175
175 debug.assert(containerLayout(E1) == TypeInfo.ContainerLayout.Auto);
176 debug.assert(containerLayout(E2) == TypeInfo.ContainerLayout.Packed);
177 debug.assert(containerLayout(E3) == TypeInfo.ContainerLayout.Extern);
178 debug.assert(containerLayout(S1) == TypeInfo.ContainerLayout.Auto);
179 debug.assert(containerLayout(S2) == TypeInfo.ContainerLayout.Packed);
180 debug.assert(containerLayout(S3) == TypeInfo.ContainerLayout.Extern);
181 debug.assert(containerLayout(U1) == TypeInfo.ContainerLayout.Auto);
182 debug.assert(containerLayout(U2) == TypeInfo.ContainerLayout.Packed);
183 debug.assert(containerLayout(U3) == TypeInfo.ContainerLayout.Extern);
176 testing.expect(containerLayout(E1) == TypeInfo.ContainerLayout.Auto);
177 testing.expect(containerLayout(E2) == TypeInfo.ContainerLayout.Packed);
178 testing.expect(containerLayout(E3) == TypeInfo.ContainerLayout.Extern);
179 testing.expect(containerLayout(S1) == TypeInfo.ContainerLayout.Auto);
180 testing.expect(containerLayout(S2) == TypeInfo.ContainerLayout.Packed);
181 testing.expect(containerLayout(S3) == TypeInfo.ContainerLayout.Extern);
182 testing.expect(containerLayout(U1) == TypeInfo.ContainerLayout.Auto);
183 testing.expect(containerLayout(U2) == TypeInfo.ContainerLayout.Packed);
184 testing.expect(containerLayout(U3) == TypeInfo.ContainerLayout.Extern);
184185}
185186
186187pub fn definitions(comptime T: type) []TypeInfo.Definition {
......@@ -214,8 +215,8 @@ test "std.meta.definitions" {
214215 };
215216
216217 inline for (defs) |def| {
217 debug.assert(def.len == 1);
218 debug.assert(comptime mem.eql(u8, def[0].name, "a"));
218 testing.expect(def.len == 1);
219 testing.expect(comptime mem.eql(u8, def[0].name, "a"));
219220 }
220221}
221222
......@@ -250,8 +251,8 @@ test "std.meta.definitionInfo" {
250251 };
251252
252253 inline for (infos) |info| {
253 debug.assert(comptime mem.eql(u8, info.name, "a"));
254 debug.assert(!info.is_pub);
254 testing.expect(comptime mem.eql(u8, info.name, "a"));
255 testing.expect(!info.is_pub);
255256 }
256257}
257258
......@@ -288,16 +289,16 @@ test "std.meta.fields" {
288289 const sf = comptime fields(S1);
289290 const uf = comptime fields(U1);
290291
291 debug.assert(e1f.len == 1);
292 debug.assert(e2f.len == 1);
293 debug.assert(sf.len == 1);
294 debug.assert(uf.len == 1);
295 debug.assert(mem.eql(u8, e1f[0].name, "A"));
296 debug.assert(mem.eql(u8, e2f[0].name, "A"));
297 debug.assert(mem.eql(u8, sf[0].name, "a"));
298 debug.assert(mem.eql(u8, uf[0].name, "a"));
299 debug.assert(comptime sf[0].field_type == u8);
300 debug.assert(comptime uf[0].field_type == u8);
292 testing.expect(e1f.len == 1);
293 testing.expect(e2f.len == 1);
294 testing.expect(sf.len == 1);
295 testing.expect(uf.len == 1);
296 testing.expect(mem.eql(u8, e1f[0].name, "A"));
297 testing.expect(mem.eql(u8, e2f[0].name, "A"));
298 testing.expect(mem.eql(u8, sf[0].name, "a"));
299 testing.expect(mem.eql(u8, uf[0].name, "a"));
300 testing.expect(comptime sf[0].field_type == u8);
301 testing.expect(comptime uf[0].field_type == u8);
301302}
302303
303304pub fn fieldInfo(comptime T: type, comptime field_name: []const u8) switch (@typeInfo(T)) {
......@@ -332,12 +333,12 @@ test "std.meta.fieldInfo" {
332333 const sf = comptime fieldInfo(S1, "a");
333334 const uf = comptime fieldInfo(U1, "a");
334335
335 debug.assert(mem.eql(u8, e1f.name, "A"));
336 debug.assert(mem.eql(u8, e2f.name, "A"));
337 debug.assert(mem.eql(u8, sf.name, "a"));
338 debug.assert(mem.eql(u8, uf.name, "a"));
339 debug.assert(comptime sf.field_type == u8);
340 debug.assert(comptime uf.field_type == u8);
336 testing.expect(mem.eql(u8, e1f.name, "A"));
337 testing.expect(mem.eql(u8, e2f.name, "A"));
338 testing.expect(mem.eql(u8, sf.name, "a"));
339 testing.expect(mem.eql(u8, uf.name, "a"));
340 testing.expect(comptime sf.field_type == u8);
341 testing.expect(comptime uf.field_type == u8);
341342}
342343
343344pub fn TagType(comptime T: type) type {
......@@ -358,8 +359,8 @@ test "std.meta.TagType" {
358359 D: u16,
359360 };
360361
361 debug.assert(TagType(E) == u8);
362 debug.assert(TagType(U) == E);
362 testing.expect(TagType(E) == u8);
363 testing.expect(TagType(U) == E);
363364}
364365
365366///Returns the active tag of a tagged union
......@@ -380,18 +381,18 @@ test "std.meta.activeTag" {
380381 };
381382
382383 var u = U{ .Int = 32 };
383 debug.assert(activeTag(u) == UE.Int);
384 testing.expect(activeTag(u) == UE.Int);
384385
385386 u = U{ .Float = 112.9876 };
386 debug.assert(activeTag(u) == UE.Float);
387 testing.expect(activeTag(u) == UE.Float);
387388}
388389
389390///Given a tagged union type, and an enum, return the type of the union
390391/// field corresponding to the enum tag.
391392pub fn TagPayloadType(comptime U: type, tag: var) type {
392393 const Tag = @typeOf(tag);
393 debug.assert(trait.is(builtin.TypeId.Union)(U));
394 debug.assert(trait.is(builtin.TypeId.Enum)(Tag));
394 testing.expect(trait.is(builtin.TypeId.Union)(U));
395 testing.expect(trait.is(builtin.TypeId.Enum)(Tag));
395396
396397 const info = @typeInfo(U).Union;
397398
......@@ -410,7 +411,7 @@ test "std.meta.TagPayloadType" {
410411 };
411412 const MovedEvent = TagPayloadType(Event, Event.Moved);
412413 var e: Event = undefined;
413 debug.assert(MovedEvent == @typeOf(e.Moved));
414 testing.expect(MovedEvent == @typeOf(e.Moved));
414415}
415416
416417///Compares two of any type for equality. Containers are compared on a field-by-field basis,
......@@ -509,19 +510,19 @@ test "std.meta.eql" {
509510 const u_2 = U{ .s = s_1 };
510511 const u_3 = U{ .f = 24 };
511512
512 debug.assert(eql(s_1, s_3));
513 debug.assert(eql(&s_1, &s_1));
514 debug.assert(!eql(&s_1, &s_3));
515 debug.assert(eql(u_1, u_3));
516 debug.assert(!eql(u_1, u_2));
513 testing.expect(eql(s_1, s_3));
514 testing.expect(eql(&s_1, &s_1));
515 testing.expect(!eql(&s_1, &s_3));
516 testing.expect(eql(u_1, u_3));
517 testing.expect(!eql(u_1, u_2));
517518
518519 var a1 = "abcdef";
519520 var a2 = "abcdef";
520521 var a3 = "ghijkl";
521522
522 debug.assert(eql(a1, a2));
523 debug.assert(!eql(a1, a3));
524 debug.assert(!eql(a1[0..], a2[0..]));
523 testing.expect(eql(a1, a2));
524 testing.expect(!eql(a1, a3));
525 testing.expect(!eql(a1[0..], a2[0..]));
525526
526527 const EU = struct {
527528 fn tst(err: bool) !u8 {
......@@ -530,9 +531,9 @@ test "std.meta.eql" {
530531 }
531532 };
532533
533 debug.assert(eql(EU.tst(true), EU.tst(true)));
534 debug.assert(eql(EU.tst(false), EU.tst(false)));
535 debug.assert(!eql(EU.tst(false), EU.tst(true)));
534 testing.expect(eql(EU.tst(true), EU.tst(true)));
535 testing.expect(eql(EU.tst(false), EU.tst(false)));
536 testing.expect(!eql(EU.tst(false), EU.tst(true)));
536537}
537538
538539test "intToEnum with error return" {
......@@ -546,9 +547,9 @@ test "intToEnum with error return" {
546547
547548 var zero: u8 = 0;
548549 var one: u16 = 1;
549 debug.assert(intToEnum(E1, zero) catch unreachable == E1.A);
550 debug.assert(intToEnum(E2, one) catch unreachable == E2.B);
551 debug.assertError(intToEnum(E1, one), error.InvalidEnumTag);
550 testing.expect(intToEnum(E1, zero) catch unreachable == E1.A);
551 testing.expect(intToEnum(E2, one) catch unreachable == E2.B);
552 testing.expectError(error.InvalidEnumTag, intToEnum(E1, one));
552553}
553554
554555pub const IntToEnumError = error{InvalidEnumTag};
std/meta/trait.zig+67-66
......@@ -2,6 +2,7 @@ const std = @import("../index.zig");
22const builtin = @import("builtin");
33const mem = std.mem;
44const debug = std.debug;
5const testing = std.testing;
56const warn = debug.warn;
67
78const meta = @import("index.zig");
......@@ -50,8 +51,8 @@ test "std.meta.trait.multiTrait" {
5051 hasField("x"),
5152 hasField("y"),
5253 });
53 debug.assert(isVector(Vector2));
54 debug.assert(!isVector(u8));
54 testing.expect(isVector(Vector2));
55 testing.expect(!isVector(u8));
5556}
5657
5758///
......@@ -85,12 +86,12 @@ test "std.meta.trait.hasDef" {
8586 const value = u8(16);
8687 };
8788
88 debug.assert(hasDef("value")(TestStruct));
89 debug.assert(!hasDef("value")(TestStructFail));
90 debug.assert(!hasDef("value")(*TestStruct));
91 debug.assert(!hasDef("value")(**TestStructFail));
92 debug.assert(!hasDef("x")(TestStruct));
93 debug.assert(!hasDef("value")(u8));
89 testing.expect(hasDef("value")(TestStruct));
90 testing.expect(!hasDef("value")(TestStructFail));
91 testing.expect(!hasDef("value")(*TestStruct));
92 testing.expect(!hasDef("value")(**TestStructFail));
93 testing.expect(!hasDef("x")(TestStruct));
94 testing.expect(!hasDef("value")(u8));
9495}
9596
9697///
......@@ -111,9 +112,9 @@ test "std.meta.trait.hasFn" {
111112 pub fn useless() void {}
112113 };
113114
114 debug.assert(hasFn("useless")(TestStruct));
115 debug.assert(!hasFn("append")(TestStruct));
116 debug.assert(!hasFn("useless")(u8));
115 testing.expect(hasFn("useless")(TestStruct));
116 testing.expect(!hasFn("append")(TestStruct));
117 testing.expect(!hasFn("useless")(u8));
117118}
118119
119120///
......@@ -143,11 +144,11 @@ test "std.meta.trait.hasField" {
143144 value: u32,
144145 };
145146
146 debug.assert(hasField("value")(TestStruct));
147 debug.assert(!hasField("value")(*TestStruct));
148 debug.assert(!hasField("x")(TestStruct));
149 debug.assert(!hasField("x")(**TestStruct));
150 debug.assert(!hasField("value")(u8));
147 testing.expect(hasField("value")(TestStruct));
148 testing.expect(!hasField("value")(*TestStruct));
149 testing.expect(!hasField("x")(TestStruct));
150 testing.expect(!hasField("x")(**TestStruct));
151 testing.expect(!hasField("value")(u8));
151152}
152153
153154///
......@@ -161,11 +162,11 @@ pub fn is(comptime id: builtin.TypeId) TraitFn {
161162}
162163
163164test "std.meta.trait.is" {
164 debug.assert(is(builtin.TypeId.Int)(u8));
165 debug.assert(!is(builtin.TypeId.Int)(f32));
166 debug.assert(is(builtin.TypeId.Pointer)(*u8));
167 debug.assert(is(builtin.TypeId.Void)(void));
168 debug.assert(!is(builtin.TypeId.Optional)(anyerror));
165 testing.expect(is(builtin.TypeId.Int)(u8));
166 testing.expect(!is(builtin.TypeId.Int)(f32));
167 testing.expect(is(builtin.TypeId.Pointer)(*u8));
168 testing.expect(is(builtin.TypeId.Void)(void));
169 testing.expect(!is(builtin.TypeId.Optional)(anyerror));
169170}
170171
171172///
......@@ -180,9 +181,9 @@ pub fn isPtrTo(comptime id: builtin.TypeId) TraitFn {
180181}
181182
182183test "std.meta.trait.isPtrTo" {
183 debug.assert(!isPtrTo(builtin.TypeId.Struct)(struct {}));
184 debug.assert(isPtrTo(builtin.TypeId.Struct)(*struct {}));
185 debug.assert(!isPtrTo(builtin.TypeId.Struct)(**struct {}));
184 testing.expect(!isPtrTo(builtin.TypeId.Struct)(struct {}));
185 testing.expect(isPtrTo(builtin.TypeId.Struct)(*struct {}));
186 testing.expect(!isPtrTo(builtin.TypeId.Struct)(**struct {}));
186187}
187188
188189///////////Strait trait Fns
......@@ -205,9 +206,9 @@ test "std.meta.trait.isExtern" {
205206 const TestExStruct = extern struct {};
206207 const TestStruct = struct {};
207208
208 debug.assert(isExtern(TestExStruct));
209 debug.assert(!isExtern(TestStruct));
210 debug.assert(!isExtern(u8));
209 testing.expect(isExtern(TestExStruct));
210 testing.expect(!isExtern(TestStruct));
211 testing.expect(!isExtern(u8));
211212}
212213
213214///
......@@ -226,9 +227,9 @@ test "std.meta.trait.isPacked" {
226227 const TestPStruct = packed struct {};
227228 const TestStruct = struct {};
228229
229 debug.assert(isPacked(TestPStruct));
230 debug.assert(!isPacked(TestStruct));
231 debug.assert(!isPacked(u8));
230 testing.expect(isPacked(TestPStruct));
231 testing.expect(!isPacked(TestStruct));
232 testing.expect(!isPacked(u8));
232233}
233234
234235///
......@@ -240,10 +241,10 @@ pub fn isUnsignedInt(comptime T: type) bool {
240241}
241242
242243test "isUnsignedInt" {
243 debug.assert(isUnsignedInt(u32) == true);
244 debug.assert(isUnsignedInt(comptime_int) == false);
245 debug.assert(isUnsignedInt(i64) == false);
246 debug.assert(isUnsignedInt(f64) == false);
244 testing.expect(isUnsignedInt(u32) == true);
245 testing.expect(isUnsignedInt(comptime_int) == false);
246 testing.expect(isUnsignedInt(i64) == false);
247 testing.expect(isUnsignedInt(f64) == false);
247248}
248249
249250///
......@@ -256,10 +257,10 @@ pub fn isSignedInt(comptime T: type) bool {
256257}
257258
258259test "isSignedInt" {
259 debug.assert(isSignedInt(u32) == false);
260 debug.assert(isSignedInt(comptime_int) == true);
261 debug.assert(isSignedInt(i64) == true);
262 debug.assert(isSignedInt(f64) == false);
260 testing.expect(isSignedInt(u32) == false);
261 testing.expect(isSignedInt(comptime_int) == true);
262 testing.expect(isSignedInt(i64) == true);
263 testing.expect(isSignedInt(f64) == false);
263264}
264265
265266///
......@@ -273,9 +274,9 @@ pub fn isSingleItemPtr(comptime T: type) bool {
273274
274275test "std.meta.trait.isSingleItemPtr" {
275276 const array = []u8{0} ** 10;
276 debug.assert(isSingleItemPtr(@typeOf(&array[0])));
277 debug.assert(!isSingleItemPtr(@typeOf(array)));
278 debug.assert(!isSingleItemPtr(@typeOf(array[0..1])));
277 testing.expect(isSingleItemPtr(@typeOf(&array[0])));
278 testing.expect(!isSingleItemPtr(@typeOf(array)));
279 testing.expect(!isSingleItemPtr(@typeOf(array[0..1])));
279280}
280281
281282///
......@@ -290,9 +291,9 @@ pub fn isManyItemPtr(comptime T: type) bool {
290291test "std.meta.trait.isManyItemPtr" {
291292 const array = []u8{0} ** 10;
292293 const mip = @ptrCast([*]const u8, &array[0]);
293 debug.assert(isManyItemPtr(@typeOf(mip)));
294 debug.assert(!isManyItemPtr(@typeOf(array)));
295 debug.assert(!isManyItemPtr(@typeOf(array[0..1])));
294 testing.expect(isManyItemPtr(@typeOf(mip)));
295 testing.expect(!isManyItemPtr(@typeOf(array)));
296 testing.expect(!isManyItemPtr(@typeOf(array[0..1])));
296297}
297298
298299///
......@@ -306,9 +307,9 @@ pub fn isSlice(comptime T: type) bool {
306307
307308test "std.meta.trait.isSlice" {
308309 const array = []u8{0} ** 10;
309 debug.assert(isSlice(@typeOf(array[0..])));
310 debug.assert(!isSlice(@typeOf(array)));
311 debug.assert(!isSlice(@typeOf(&array[0])));
310 testing.expect(isSlice(@typeOf(array[0..])));
311 testing.expect(!isSlice(@typeOf(array)));
312 testing.expect(!isSlice(@typeOf(&array[0])));
312313}
313314
314315///
......@@ -328,10 +329,10 @@ test "std.meta.trait.isIndexable" {
328329 const array = []u8{0} ** 10;
329330 const slice = array[0..];
330331
331 debug.assert(isIndexable(@typeOf(array)));
332 debug.assert(isIndexable(@typeOf(&array)));
333 debug.assert(isIndexable(@typeOf(slice)));
334 debug.assert(!isIndexable(meta.Child(@typeOf(slice))));
332 testing.expect(isIndexable(@typeOf(array)));
333 testing.expect(isIndexable(@typeOf(&array)));
334 testing.expect(isIndexable(@typeOf(slice)));
335 testing.expect(!isIndexable(meta.Child(@typeOf(slice))));
335336}
336337
337338///
......@@ -347,13 +348,13 @@ test "std.meta.trait.isNumber" {
347348 number: u8,
348349 };
349350
350 debug.assert(isNumber(u32));
351 debug.assert(isNumber(f32));
352 debug.assert(isNumber(u64));
353 debug.assert(isNumber(@typeOf(102)));
354 debug.assert(isNumber(@typeOf(102.123)));
355 debug.assert(!isNumber([]u8));
356 debug.assert(!isNumber(NotANumber));
351 testing.expect(isNumber(u32));
352 testing.expect(isNumber(f32));
353 testing.expect(isNumber(u64));
354 testing.expect(isNumber(@typeOf(102)));
355 testing.expect(isNumber(@typeOf(102.123)));
356 testing.expect(!isNumber([]u8));
357 testing.expect(!isNumber(NotANumber));
357358}
358359
359360///
......@@ -366,10 +367,10 @@ pub fn isConstPtr(comptime T: type) bool {
366367test "std.meta.trait.isConstPtr" {
367368 var t = u8(0);
368369 const c = u8(0);
369 debug.assert(isConstPtr(*const @typeOf(t)));
370 debug.assert(isConstPtr(@typeOf(&c)));
371 debug.assert(!isConstPtr(*@typeOf(t)));
372 debug.assert(!isConstPtr(@typeOf(6)));
370 testing.expect(isConstPtr(*const @typeOf(t)));
371 testing.expect(isConstPtr(@typeOf(&c)));
372 testing.expect(!isConstPtr(*@typeOf(t)));
373 testing.expect(!isConstPtr(@typeOf(6)));
373374}
374375
375376///
......@@ -393,8 +394,8 @@ test "std.meta.trait.isContainer" {
393394 B,
394395 };
395396
396 debug.assert(isContainer(TestStruct));
397 debug.assert(isContainer(TestUnion));
398 debug.assert(isContainer(TestEnum));
399 debug.assert(!isContainer(u8));
397 testing.expect(isContainer(TestStruct));
398 testing.expect(isContainer(TestUnion));
399 testing.expect(isContainer(TestEnum));
400 testing.expect(!isContainer(u8));
400401}
std/mutex.zig+3-3
......@@ -2,7 +2,7 @@ const std = @import("index.zig");
22const builtin = @import("builtin");
33const AtomicOrder = builtin.AtomicOrder;
44const AtomicRmwOp = builtin.AtomicRmwOp;
5const assert = std.debug.assert;
5const testing = std.testing;
66const SpinLock = std.SpinLock;
77const linux = std.os.linux;
88const windows = std.os.windows;
......@@ -149,7 +149,7 @@ test "std.Mutex" {
149149
150150 if (builtin.single_threaded) {
151151 worker(&context);
152 std.debug.assertOrPanic(context.data == TestContext.incr_count);
152 testing.expect(context.data == TestContext.incr_count);
153153 } else {
154154 const thread_count = 10;
155155 var threads: [thread_count]*std.os.Thread = undefined;
......@@ -159,7 +159,7 @@ test "std.Mutex" {
159159 for (threads) |t|
160160 t.wait();
161161
162 std.debug.assertOrPanic(context.data == thread_count * TestContext.incr_count);
162 testing.expect(context.data == thread_count * TestContext.incr_count);
163163 }
164164}
165165
std/os/child_process.zig-1
......@@ -7,7 +7,6 @@ const posix = os.posix;
77const windows = os.windows;
88const mem = std.mem;
99const debug = std.debug;
10const assert = debug.assert;
1110const BufMap = std.BufMap;
1211const Buffer = std.Buffer;
1312const builtin = @import("builtin");
std/os/index.zig+5-4
......@@ -91,6 +91,7 @@ pub const GetAppDataDirError = @import("get_app_data_dir.zig").GetAppDataDirErro
9191
9292const debug = std.debug;
9393const assert = debug.assert;
94const testing = std.testing;
9495
9596const c = std.c;
9697
......@@ -172,7 +173,7 @@ test "os.getRandomBytes" {
172173 try getRandomBytes(buf_b[0..]);
173174
174175 // Check if random (not 100% conclusive)
175 assert(!mem.eql(u8, buf_a, buf_b));
176 testing.expect(!mem.eql(u8, buf_a, buf_b));
176177}
177178
178179/// Raises a signal in the current kernel thread, ending its execution.
......@@ -828,7 +829,7 @@ pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) GetEnvVarOwned
828829
829830test "os.getEnvVarOwned" {
830831 var ga = debug.global_allocator;
831 debug.assertError(getEnvVarOwned(ga, "BADENV"), error.EnvironmentVariableNotFound);
832 testing.expectError(error.EnvironmentVariableNotFound, getEnvVarOwned(ga, "BADENV"));
832833}
833834
834835/// Caller must free the returned memory.
......@@ -2219,9 +2220,9 @@ fn testWindowsCmdLine(input_cmd_line: [*]const u8, expected_args: []const []cons
22192220 var it = ArgIteratorWindows.initWithCmdLine(input_cmd_line);
22202221 for (expected_args) |expected_arg| {
22212222 const arg = it.next(debug.global_allocator).? catch unreachable;
2222 assert(mem.eql(u8, arg, expected_arg));
2223 testing.expectEqualSlices(u8, expected_arg, arg);
22232224 }
2224 assert(it.next(debug.global_allocator) == null);
2225 testing.expect(it.next(debug.global_allocator) == null);
22252226}
22262227
22272228// TODO make this a build variable that you can set
std/os/linux/test.zig+6-6
......@@ -1,19 +1,19 @@
11const std = @import("../../index.zig");
22const builtin = @import("builtin");
33const linux = std.os.linux;
4const assert = std.debug.assert;
4const expect = std.testing.expect;
55
66test "getpid" {
7 assert(linux.getpid() != 0);
7 expect(linux.getpid() != 0);
88}
99
1010test "timer" {
1111 const epoll_fd = linux.epoll_create();
1212 var err = linux.getErrno(epoll_fd);
13 assert(err == 0);
13 expect(err == 0);
1414
1515 const timer_fd = linux.timerfd_create(linux.CLOCK_MONOTONIC, 0);
16 assert(linux.getErrno(timer_fd) == 0);
16 expect(linux.getErrno(timer_fd) == 0);
1717
1818 const time_interval = linux.timespec{
1919 .tv_sec = 0,
......@@ -26,7 +26,7 @@ test "timer" {
2626 };
2727
2828 err = linux.timerfd_settime(@intCast(i32, timer_fd), 0, &new_time, null);
29 assert(err == 0);
29 expect(err == 0);
3030
3131 var event = linux.epoll_event{
3232 .events = linux.EPOLLIN | linux.EPOLLOUT | linux.EPOLLET,
......@@ -34,7 +34,7 @@ test "timer" {
3434 };
3535
3636 err = linux.epoll_ctl(@intCast(i32, epoll_fd), linux.EPOLL_CTL_ADD, @intCast(i32, timer_fd), &event);
37 assert(err == 0);
37 expect(err == 0);
3838
3939 const events_one: linux.epoll_event = undefined;
4040 var events = []linux.epoll_event{events_one} ** 8;
std/os/path.zig+58-57
......@@ -3,6 +3,7 @@ const builtin = @import("builtin");
33const Os = builtin.Os;
44const debug = std.debug;
55const assert = debug.assert;
6const testing = std.testing;
67const mem = std.mem;
78const fmt = std.fmt;
89const Allocator = mem.Allocator;
......@@ -94,14 +95,14 @@ fn testJoinWindows(paths: []const []const u8, expected: []const u8) void {
9495 var buf: [1024]u8 = undefined;
9596 const a = &std.heap.FixedBufferAllocator.init(&buf).allocator;
9697 const actual = joinWindows(a, paths) catch @panic("fail");
97 debug.assertOrPanic(mem.eql(u8, actual, expected));
98 testing.expectEqualSlices(u8, expected, actual);
9899}
99100
100101fn testJoinPosix(paths: []const []const u8, expected: []const u8) void {
101102 var buf: [1024]u8 = undefined;
102103 const a = &std.heap.FixedBufferAllocator.init(&buf).allocator;
103104 const actual = joinPosix(a, paths) catch @panic("fail");
104 debug.assertOrPanic(mem.eql(u8, actual, expected));
105 testing.expectEqualSlices(u8, expected, actual);
105106}
106107
107108test "os.path.join" {
......@@ -193,11 +194,11 @@ test "os.path.isAbsolutePosix" {
193194}
194195
195196fn testIsAbsoluteWindows(path: []const u8, expected_result: bool) void {
196 assert(isAbsoluteWindows(path) == expected_result);
197 testing.expectEqual(expected_result, isAbsoluteWindows(path));
197198}
198199
199200fn testIsAbsolutePosix(path: []const u8, expected_result: bool) void {
200 assert(isAbsolutePosix(path) == expected_result);
201 testing.expectEqual(expected_result, isAbsolutePosix(path));
201202}
202203
203204pub const WindowsPath = struct {
......@@ -281,33 +282,33 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {
281282test "os.path.windowsParsePath" {
282283 {
283284 const parsed = windowsParsePath("//a/b");
284 assert(parsed.is_abs);
285 assert(parsed.kind == WindowsPath.Kind.NetworkShare);
286 assert(mem.eql(u8, parsed.disk_designator, "//a/b"));
285 testing.expect(parsed.is_abs);
286 testing.expect(parsed.kind == WindowsPath.Kind.NetworkShare);
287 testing.expect(mem.eql(u8, parsed.disk_designator, "//a/b"));
287288 }
288289 {
289290 const parsed = windowsParsePath("\\\\a\\b");
290 assert(parsed.is_abs);
291 assert(parsed.kind == WindowsPath.Kind.NetworkShare);
292 assert(mem.eql(u8, parsed.disk_designator, "\\\\a\\b"));
291 testing.expect(parsed.is_abs);
292 testing.expect(parsed.kind == WindowsPath.Kind.NetworkShare);
293 testing.expect(mem.eql(u8, parsed.disk_designator, "\\\\a\\b"));
293294 }
294295 {
295296 const parsed = windowsParsePath("\\\\a\\");
296 assert(!parsed.is_abs);
297 assert(parsed.kind == WindowsPath.Kind.None);
298 assert(mem.eql(u8, parsed.disk_designator, ""));
297 testing.expect(!parsed.is_abs);
298 testing.expect(parsed.kind == WindowsPath.Kind.None);
299 testing.expect(mem.eql(u8, parsed.disk_designator, ""));
299300 }
300301 {
301302 const parsed = windowsParsePath("/usr/local");
302 assert(parsed.is_abs);
303 assert(parsed.kind == WindowsPath.Kind.None);
304 assert(mem.eql(u8, parsed.disk_designator, ""));
303 testing.expect(parsed.is_abs);
304 testing.expect(parsed.kind == WindowsPath.Kind.None);
305 testing.expect(mem.eql(u8, parsed.disk_designator, ""));
305306 }
306307 {
307308 const parsed = windowsParsePath("c:../");
308 assert(!parsed.is_abs);
309 assert(parsed.kind == WindowsPath.Kind.Drive);
310 assert(mem.eql(u8, parsed.disk_designator, "c:"));
309 testing.expect(!parsed.is_abs);
310 testing.expect(parsed.kind == WindowsPath.Kind.Drive);
311 testing.expect(mem.eql(u8, parsed.disk_designator, "c:"));
311312 }
312313}
313314
......@@ -642,10 +643,10 @@ test "os.path.resolve" {
642643 if (windowsParsePath(cwd).kind == WindowsPath.Kind.Drive) {
643644 cwd[0] = asciiUpper(cwd[0]);
644645 }
645 assert(mem.eql(u8, testResolveWindows([][]const u8{"."}), cwd));
646 testing.expect(mem.eql(u8, testResolveWindows([][]const u8{"."}), cwd));
646647 } else {
647 assert(mem.eql(u8, testResolvePosix([][]const u8{ "a/b/c/", "../../.." }), cwd));
648 assert(mem.eql(u8, testResolvePosix([][]const u8{"."}), cwd));
648 testing.expect(mem.eql(u8, testResolvePosix([][]const u8{ "a/b/c/", "../../.." }), cwd));
649 testing.expect(mem.eql(u8, testResolvePosix([][]const u8{"."}), cwd));
649650 }
650651}
651652
......@@ -662,7 +663,7 @@ test "os.path.resolveWindows" {
662663 if (parsed_cwd.kind == WindowsPath.Kind.Drive) {
663664 expected[0] = asciiUpper(parsed_cwd.disk_designator[0]);
664665 }
665 assert(mem.eql(u8, result, expected));
666 testing.expect(mem.eql(u8, result, expected));
666667 }
667668 {
668669 const result = testResolveWindows([][]const u8{ "usr/local", "lib\\zig" });
......@@ -673,36 +674,36 @@ test "os.path.resolveWindows" {
673674 if (parsed_cwd.kind == WindowsPath.Kind.Drive) {
674675 expected[0] = asciiUpper(parsed_cwd.disk_designator[0]);
675676 }
676 assert(mem.eql(u8, result, expected));
677 testing.expect(mem.eql(u8, result, expected));
677678 }
678679 }
679680
680 assert(mem.eql(u8, testResolveWindows([][]const u8{ "c:\\a\\b\\c", "/hi", "ok" }), "C:\\hi\\ok"));
681 assert(mem.eql(u8, testResolveWindows([][]const u8{ "c:/blah\\blah", "d:/games", "c:../a" }), "C:\\blah\\a"));
682 assert(mem.eql(u8, testResolveWindows([][]const u8{ "c:/blah\\blah", "d:/games", "C:../a" }), "C:\\blah\\a"));
683 assert(mem.eql(u8, testResolveWindows([][]const u8{ "c:/ignore", "d:\\a/b\\c/d", "\\e.exe" }), "D:\\e.exe"));
684 assert(mem.eql(u8, testResolveWindows([][]const u8{ "c:/ignore", "c:/some/file" }), "C:\\some\\file"));
685 assert(mem.eql(u8, testResolveWindows([][]const u8{ "d:/ignore", "d:some/dir//" }), "D:\\ignore\\some\\dir"));
686 assert(mem.eql(u8, testResolveWindows([][]const u8{ "//server/share", "..", "relative\\" }), "\\\\server\\share\\relative"));
687 assert(mem.eql(u8, testResolveWindows([][]const u8{ "c:/", "//" }), "C:\\"));
688 assert(mem.eql(u8, testResolveWindows([][]const u8{ "c:/", "//dir" }), "C:\\dir"));
689 assert(mem.eql(u8, testResolveWindows([][]const u8{ "c:/", "//server/share" }), "\\\\server\\share\\"));
690 assert(mem.eql(u8, testResolveWindows([][]const u8{ "c:/", "//server//share" }), "\\\\server\\share\\"));
691 assert(mem.eql(u8, testResolveWindows([][]const u8{ "c:/", "///some//dir" }), "C:\\some\\dir"));
692 assert(mem.eql(u8, testResolveWindows([][]const u8{ "C:\\foo\\tmp.3\\", "..\\tmp.3\\cycles\\root.js" }), "C:\\foo\\tmp.3\\cycles\\root.js"));
681 testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "c:\\a\\b\\c", "/hi", "ok" }), "C:\\hi\\ok"));
682 testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "c:/blah\\blah", "d:/games", "c:../a" }), "C:\\blah\\a"));
683 testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "c:/blah\\blah", "d:/games", "C:../a" }), "C:\\blah\\a"));
684 testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "c:/ignore", "d:\\a/b\\c/d", "\\e.exe" }), "D:\\e.exe"));
685 testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "c:/ignore", "c:/some/file" }), "C:\\some\\file"));
686 testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "d:/ignore", "d:some/dir//" }), "D:\\ignore\\some\\dir"));
687 testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "//server/share", "..", "relative\\" }), "\\\\server\\share\\relative"));
688 testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "c:/", "//" }), "C:\\"));
689 testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "c:/", "//dir" }), "C:\\dir"));
690 testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "c:/", "//server/share" }), "\\\\server\\share\\"));
691 testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "c:/", "//server//share" }), "\\\\server\\share\\"));
692 testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "c:/", "///some//dir" }), "C:\\some\\dir"));
693 testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "C:\\foo\\tmp.3\\", "..\\tmp.3\\cycles\\root.js" }), "C:\\foo\\tmp.3\\cycles\\root.js"));
693694}
694695
695696test "os.path.resolvePosix" {
696 assert(mem.eql(u8, testResolvePosix([][]const u8{ "/a/b", "c" }), "/a/b/c"));
697 assert(mem.eql(u8, testResolvePosix([][]const u8{ "/a/b", "c", "//d", "e///" }), "/d/e"));
698 assert(mem.eql(u8, testResolvePosix([][]const u8{ "/a/b/c", "..", "../" }), "/a"));
699 assert(mem.eql(u8, testResolvePosix([][]const u8{ "/", "..", ".." }), "/"));
700 assert(mem.eql(u8, testResolvePosix([][]const u8{"/a/b/c/"}), "/a/b/c"));
701
702 assert(mem.eql(u8, testResolvePosix([][]const u8{ "/var/lib", "../", "file/" }), "/var/file"));
703 assert(mem.eql(u8, testResolvePosix([][]const u8{ "/var/lib", "/../", "file/" }), "/file"));
704 assert(mem.eql(u8, testResolvePosix([][]const u8{ "/some/dir", ".", "/absolute/" }), "/absolute"));
705 assert(mem.eql(u8, testResolvePosix([][]const u8{ "/foo/tmp.3/", "../tmp.3/cycles/root.js" }), "/foo/tmp.3/cycles/root.js"));
697 testing.expect(mem.eql(u8, testResolvePosix([][]const u8{ "/a/b", "c" }), "/a/b/c"));
698 testing.expect(mem.eql(u8, testResolvePosix([][]const u8{ "/a/b", "c", "//d", "e///" }), "/d/e"));
699 testing.expect(mem.eql(u8, testResolvePosix([][]const u8{ "/a/b/c", "..", "../" }), "/a"));
700 testing.expect(mem.eql(u8, testResolvePosix([][]const u8{ "/", "..", ".." }), "/"));
701 testing.expect(mem.eql(u8, testResolvePosix([][]const u8{"/a/b/c/"}), "/a/b/c"));
702
703 testing.expect(mem.eql(u8, testResolvePosix([][]const u8{ "/var/lib", "../", "file/" }), "/var/file"));
704 testing.expect(mem.eql(u8, testResolvePosix([][]const u8{ "/var/lib", "/../", "file/" }), "/file"));
705 testing.expect(mem.eql(u8, testResolvePosix([][]const u8{ "/some/dir", ".", "/absolute/" }), "/absolute"));
706 testing.expect(mem.eql(u8, testResolvePosix([][]const u8{ "/foo/tmp.3/", "../tmp.3/cycles/root.js" }), "/foo/tmp.3/cycles/root.js"));
706707}
707708
708709fn testResolveWindows(paths: []const []const u8) []u8 {
......@@ -833,17 +834,17 @@ test "os.path.dirnameWindows" {
833834
834835fn testDirnamePosix(input: []const u8, expected_output: ?[]const u8) void {
835836 if (dirnamePosix(input)) |output| {
836 assert(mem.eql(u8, output, expected_output.?));
837 testing.expect(mem.eql(u8, output, expected_output.?));
837838 } else {
838 assert(expected_output == null);
839 testing.expect(expected_output == null);
839840 }
840841}
841842
842843fn testDirnameWindows(input: []const u8, expected_output: ?[]const u8) void {
843844 if (dirnameWindows(input)) |output| {
844 assert(mem.eql(u8, output, expected_output.?));
845 testing.expect(mem.eql(u8, output, expected_output.?));
845846 } else {
846 assert(expected_output == null);
847 testing.expect(expected_output == null);
847848 }
848849}
849850
......@@ -948,15 +949,15 @@ test "os.path.basename" {
948949}
949950
950951fn testBasename(input: []const u8, expected_output: []const u8) void {
951 assert(mem.eql(u8, basename(input), expected_output));
952 testing.expectEqualSlices(u8, expected_output, basename(input));
952953}
953954
954955fn testBasenamePosix(input: []const u8, expected_output: []const u8) void {
955 assert(mem.eql(u8, basenamePosix(input), expected_output));
956 testing.expectEqualSlices(u8, expected_output, basenamePosix(input));
956957}
957958
958959fn testBasenameWindows(input: []const u8, expected_output: []const u8) void {
959 assert(mem.eql(u8, basenameWindows(input), expected_output));
960 testing.expectEqualSlices(u8, expected_output, basenameWindows(input));
960961}
961962
962963/// Returns the relative path from `from` to `to`. If `from` and `to` each
......@@ -1131,12 +1132,12 @@ test "os.path.relative" {
11311132
11321133fn testRelativePosix(from: []const u8, to: []const u8, expected_output: []const u8) void {
11331134 const result = relativePosix(debug.global_allocator, from, to) catch unreachable;
1134 assert(mem.eql(u8, result, expected_output));
1135 testing.expectEqualSlices(u8, expected_output, result);
11351136}
11361137
11371138fn testRelativeWindows(from: []const u8, to: []const u8, expected_output: []const u8) void {
11381139 const result = relativeWindows(debug.global_allocator, from, to) catch unreachable;
1139 assert(mem.eql(u8, result, expected_output));
1140 testing.expectEqualSlices(u8, expected_output, result);
11401141}
11411142
11421143pub const RealError = error{
......@@ -1283,5 +1284,5 @@ pub fn realAlloc(allocator: *Allocator, pathname: []const u8) ![]u8 {
12831284test "os.path.real" {
12841285 // at least call it so it gets compiled
12851286 var buf: [os.MAX_PATH_BYTES]u8 = undefined;
1286 std.debug.assertError(real(&buf, "definitely_bogus_does_not_exist1234"), error.FileNotFound);
1287 testing.expectError(error.FileNotFound, real(&buf, "definitely_bogus_does_not_exist1234"));
12871288}
std/os/test.zig+8-8
......@@ -1,6 +1,6 @@
11const std = @import("../index.zig");
22const os = std.os;
3const assert = std.debug.assert;
3const expect = std.testing.expect;
44const io = std.io;
55const mem = std.mem;
66
......@@ -18,7 +18,7 @@ test "makePath, put some files in it, deleteTree" {
1818 if (os.Dir.open(a, "os_test_tmp")) |dir| {
1919 @panic("expected error");
2020 } else |err| {
21 assert(err == error.FileNotFound);
21 expect(err == error.FileNotFound);
2222 }
2323}
2424
......@@ -27,7 +27,7 @@ test "access file" {
2727 if (os.File.access("os_test_tmp" ++ os.path.sep_str ++ "file.txt")) |ok| {
2828 @panic("expected error");
2929 } else |err| {
30 assert(err == error.FileNotFound);
30 expect(err == error.FileNotFound);
3131 }
3232
3333 try io.writeFile("os_test_tmp" ++ os.path.sep_str ++ "file.txt", "");
......@@ -47,9 +47,9 @@ test "std.os.Thread.getCurrentId" {
4747 const thread_id = thread.handle();
4848 thread.wait();
4949 switch (builtin.os) {
50 builtin.Os.windows => assert(os.Thread.getCurrentId() != thread_current_id),
50 builtin.Os.windows => expect(os.Thread.getCurrentId() != thread_current_id),
5151 else => {
52 assert(thread_current_id == thread_id);
52 expect(thread_current_id == thread_id);
5353 },
5454 }
5555}
......@@ -69,7 +69,7 @@ test "spawn threads" {
6969 thread3.wait();
7070 thread4.wait();
7171
72 assert(shared_ctx == 4);
72 expect(shared_ctx == 4);
7373}
7474
7575fn start1(ctx: void) u8 {
......@@ -83,7 +83,7 @@ fn start2(ctx: *i32) u8 {
8383
8484test "cpu count" {
8585 const cpu_count = try std.os.cpuCount(a);
86 assert(cpu_count >= 1);
86 expect(cpu_count >= 1);
8787}
8888
8989test "AtomicFile" {
......@@ -101,7 +101,7 @@ test "AtomicFile" {
101101 try af.finish();
102102 }
103103 const content = try io.readFileAlloc(allocator, test_out_file);
104 assert(mem.eql(u8, content, test_content));
104 expect(mem.eql(u8, content, test_content));
105105
106106 try os.deleteFile(test_out_file);
107107}
std/os/time.zig+5-4
......@@ -2,6 +2,7 @@ const std = @import("../index.zig");
22const builtin = @import("builtin");
33const Os = builtin.Os;
44const debug = std.debug;
5const testing = std.testing;
56
67const windows = std.os.windows;
78const linux = std.os.linux;
......@@ -270,7 +271,7 @@ test "os.time.timestamp" {
270271 sleep(ns_per_ms);
271272 const time_1 = milliTimestamp();
272273 const interval = time_1 - time_0;
273 debug.assert(interval > 0 and interval < margin);
274 testing.expect(interval > 0 and interval < margin);
274275}
275276
276277test "os.time.Timer" {
......@@ -280,11 +281,11 @@ test "os.time.Timer" {
280281 var timer = try Timer.start();
281282 sleep(10 * ns_per_ms);
282283 const time_0 = timer.read();
283 debug.assert(time_0 > 0 and time_0 < margin);
284 testing.expect(time_0 > 0 and time_0 < margin);
284285
285286 const time_1 = timer.lap();
286 debug.assert(time_1 >= time_0);
287 testing.expect(time_1 >= time_0);
287288
288289 timer.reset();
289 debug.assert(timer.read() < time_1);
290 testing.expect(timer.read() < time_1);
290291}
std/rand/index.zig+81-80
......@@ -17,6 +17,7 @@
1717const std = @import("../index.zig");
1818const builtin = @import("builtin");
1919const assert = std.debug.assert;
20const expect = std.testing.expect;
2021const mem = std.mem;
2122const math = std.math;
2223const ziggurat = @import("ziggurat.zig");
......@@ -316,43 +317,43 @@ test "Random int" {
316317fn testRandomInt() void {
317318 var r = SequentialPrng.init();
318319
319 assert(r.random.int(u0) == 0);
320 expect(r.random.int(u0) == 0);
320321
321322 r.next_value = 0;
322 assert(r.random.int(u1) == 0);
323 assert(r.random.int(u1) == 1);
324 assert(r.random.int(u2) == 2);
325 assert(r.random.int(u2) == 3);
326 assert(r.random.int(u2) == 0);
323 expect(r.random.int(u1) == 0);
324 expect(r.random.int(u1) == 1);
325 expect(r.random.int(u2) == 2);
326 expect(r.random.int(u2) == 3);
327 expect(r.random.int(u2) == 0);
327328
328329 r.next_value = 0xff;
329 assert(r.random.int(u8) == 0xff);
330 expect(r.random.int(u8) == 0xff);
330331 r.next_value = 0x11;
331 assert(r.random.int(u8) == 0x11);
332 expect(r.random.int(u8) == 0x11);
332333
333334 r.next_value = 0xff;
334 assert(r.random.int(u32) == 0xffffffff);
335 expect(r.random.int(u32) == 0xffffffff);
335336 r.next_value = 0x11;
336 assert(r.random.int(u32) == 0x11111111);
337 expect(r.random.int(u32) == 0x11111111);
337338
338339 r.next_value = 0xff;
339 assert(r.random.int(i32) == -1);
340 expect(r.random.int(i32) == -1);
340341 r.next_value = 0x11;
341 assert(r.random.int(i32) == 0x11111111);
342 expect(r.random.int(i32) == 0x11111111);
342343
343344 r.next_value = 0xff;
344 assert(r.random.int(i8) == -1);
345 expect(r.random.int(i8) == -1);
345346 r.next_value = 0x11;
346 assert(r.random.int(i8) == 0x11);
347 expect(r.random.int(i8) == 0x11);
347348
348349 r.next_value = 0xff;
349 assert(r.random.int(u33) == 0x1ffffffff);
350 expect(r.random.int(u33) == 0x1ffffffff);
350351 r.next_value = 0xff;
351 assert(r.random.int(i1) == -1);
352 expect(r.random.int(i1) == -1);
352353 r.next_value = 0xff;
353 assert(r.random.int(i2) == -1);
354 expect(r.random.int(i2) == -1);
354355 r.next_value = 0xff;
355 assert(r.random.int(i33) == -1);
356 expect(r.random.int(i33) == -1);
356357}
357358
358359test "Random boolean" {
......@@ -361,10 +362,10 @@ test "Random boolean" {
361362}
362363fn testRandomBoolean() void {
363364 var r = SequentialPrng.init();
364 assert(r.random.boolean() == false);
365 assert(r.random.boolean() == true);
366 assert(r.random.boolean() == false);
367 assert(r.random.boolean() == true);
365 expect(r.random.boolean() == false);
366 expect(r.random.boolean() == true);
367 expect(r.random.boolean() == false);
368 expect(r.random.boolean() == true);
368369}
369370
370371test "Random intLessThan" {
......@@ -375,36 +376,36 @@ test "Random intLessThan" {
375376fn testRandomIntLessThan() void {
376377 var r = SequentialPrng.init();
377378 r.next_value = 0xff;
378 assert(r.random.uintLessThan(u8, 4) == 3);
379 assert(r.next_value == 0);
380 assert(r.random.uintLessThan(u8, 4) == 0);
381 assert(r.next_value == 1);
379 expect(r.random.uintLessThan(u8, 4) == 3);
380 expect(r.next_value == 0);
381 expect(r.random.uintLessThan(u8, 4) == 0);
382 expect(r.next_value == 1);
382383
383384 r.next_value = 0;
384 assert(r.random.uintLessThan(u64, 32) == 0);
385 expect(r.random.uintLessThan(u64, 32) == 0);
385386
386387 // trigger the bias rejection code path
387388 r.next_value = 0;
388 assert(r.random.uintLessThan(u8, 3) == 0);
389 expect(r.random.uintLessThan(u8, 3) == 0);
389390 // verify we incremented twice
390 assert(r.next_value == 2);
391 expect(r.next_value == 2);
391392
392393 r.next_value = 0xff;
393 assert(r.random.intRangeLessThan(u8, 0, 0x80) == 0x7f);
394 expect(r.random.intRangeLessThan(u8, 0, 0x80) == 0x7f);
394395 r.next_value = 0xff;
395 assert(r.random.intRangeLessThan(u8, 0x7f, 0xff) == 0xfe);
396 expect(r.random.intRangeLessThan(u8, 0x7f, 0xff) == 0xfe);
396397
397398 r.next_value = 0xff;
398 assert(r.random.intRangeLessThan(i8, 0, 0x40) == 0x3f);
399 expect(r.random.intRangeLessThan(i8, 0, 0x40) == 0x3f);
399400 r.next_value = 0xff;
400 assert(r.random.intRangeLessThan(i8, -0x40, 0x40) == 0x3f);
401 expect(r.random.intRangeLessThan(i8, -0x40, 0x40) == 0x3f);
401402 r.next_value = 0xff;
402 assert(r.random.intRangeLessThan(i8, -0x80, 0) == -1);
403 expect(r.random.intRangeLessThan(i8, -0x80, 0) == -1);
403404
404405 r.next_value = 0xff;
405 assert(r.random.intRangeLessThan(i3, -4, 0) == -1);
406 expect(r.random.intRangeLessThan(i3, -4, 0) == -1);
406407 r.next_value = 0xff;
407 assert(r.random.intRangeLessThan(i3, -2, 2) == 1);
408 expect(r.random.intRangeLessThan(i3, -2, 2) == 1);
408409}
409410
410411test "Random intAtMost" {
......@@ -415,34 +416,34 @@ test "Random intAtMost" {
415416fn testRandomIntAtMost() void {
416417 var r = SequentialPrng.init();
417418 r.next_value = 0xff;
418 assert(r.random.uintAtMost(u8, 3) == 3);
419 assert(r.next_value == 0);
420 assert(r.random.uintAtMost(u8, 3) == 0);
419 expect(r.random.uintAtMost(u8, 3) == 3);
420 expect(r.next_value == 0);
421 expect(r.random.uintAtMost(u8, 3) == 0);
421422
422423 // trigger the bias rejection code path
423424 r.next_value = 0;
424 assert(r.random.uintAtMost(u8, 2) == 0);
425 expect(r.random.uintAtMost(u8, 2) == 0);
425426 // verify we incremented twice
426 assert(r.next_value == 2);
427 expect(r.next_value == 2);
427428
428429 r.next_value = 0xff;
429 assert(r.random.intRangeAtMost(u8, 0, 0x7f) == 0x7f);
430 expect(r.random.intRangeAtMost(u8, 0, 0x7f) == 0x7f);
430431 r.next_value = 0xff;
431 assert(r.random.intRangeAtMost(u8, 0x7f, 0xfe) == 0xfe);
432 expect(r.random.intRangeAtMost(u8, 0x7f, 0xfe) == 0xfe);
432433
433434 r.next_value = 0xff;
434 assert(r.random.intRangeAtMost(i8, 0, 0x3f) == 0x3f);
435 expect(r.random.intRangeAtMost(i8, 0, 0x3f) == 0x3f);
435436 r.next_value = 0xff;
436 assert(r.random.intRangeAtMost(i8, -0x40, 0x3f) == 0x3f);
437 expect(r.random.intRangeAtMost(i8, -0x40, 0x3f) == 0x3f);
437438 r.next_value = 0xff;
438 assert(r.random.intRangeAtMost(i8, -0x80, -1) == -1);
439 expect(r.random.intRangeAtMost(i8, -0x80, -1) == -1);
439440
440441 r.next_value = 0xff;
441 assert(r.random.intRangeAtMost(i3, -4, -1) == -1);
442 expect(r.random.intRangeAtMost(i3, -4, -1) == -1);
442443 r.next_value = 0xff;
443 assert(r.random.intRangeAtMost(i3, -2, 1) == 1);
444 expect(r.random.intRangeAtMost(i3, -2, 1) == 1);
444445
445 assert(r.random.uintAtMost(u0, 0) == 0);
446 expect(r.random.uintAtMost(u0, 0) == 0);
446447}
447448
448449test "Random Biased" {
......@@ -450,30 +451,30 @@ test "Random Biased" {
450451 // Not thoroughly checking the logic here.
451452 // Just want to execute all the paths with different types.
452453
453 assert(r.random.uintLessThanBiased(u1, 1) == 0);
454 assert(r.random.uintLessThanBiased(u32, 10) < 10);
455 assert(r.random.uintLessThanBiased(u64, 20) < 20);
454 expect(r.random.uintLessThanBiased(u1, 1) == 0);
455 expect(r.random.uintLessThanBiased(u32, 10) < 10);
456 expect(r.random.uintLessThanBiased(u64, 20) < 20);
456457
457 assert(r.random.uintAtMostBiased(u0, 0) == 0);
458 assert(r.random.uintAtMostBiased(u1, 0) <= 0);
459 assert(r.random.uintAtMostBiased(u32, 10) <= 10);
460 assert(r.random.uintAtMostBiased(u64, 20) <= 20);
458 expect(r.random.uintAtMostBiased(u0, 0) == 0);
459 expect(r.random.uintAtMostBiased(u1, 0) <= 0);
460 expect(r.random.uintAtMostBiased(u32, 10) <= 10);
461 expect(r.random.uintAtMostBiased(u64, 20) <= 20);
461462
462 assert(r.random.intRangeLessThanBiased(u1, 0, 1) == 0);
463 assert(r.random.intRangeLessThanBiased(i1, -1, 0) == -1);
464 assert(r.random.intRangeLessThanBiased(u32, 10, 20) >= 10);
465 assert(r.random.intRangeLessThanBiased(i32, 10, 20) >= 10);
466 assert(r.random.intRangeLessThanBiased(u64, 20, 40) >= 20);
467 assert(r.random.intRangeLessThanBiased(i64, 20, 40) >= 20);
463 expect(r.random.intRangeLessThanBiased(u1, 0, 1) == 0);
464 expect(r.random.intRangeLessThanBiased(i1, -1, 0) == -1);
465 expect(r.random.intRangeLessThanBiased(u32, 10, 20) >= 10);
466 expect(r.random.intRangeLessThanBiased(i32, 10, 20) >= 10);
467 expect(r.random.intRangeLessThanBiased(u64, 20, 40) >= 20);
468 expect(r.random.intRangeLessThanBiased(i64, 20, 40) >= 20);
468469
469470 // uncomment for broken module error:
470 //assert(r.random.intRangeAtMostBiased(u0, 0, 0) == 0);
471 assert(r.random.intRangeAtMostBiased(u1, 0, 1) >= 0);
472 assert(r.random.intRangeAtMostBiased(i1, -1, 0) >= -1);
473 assert(r.random.intRangeAtMostBiased(u32, 10, 20) >= 10);
474 assert(r.random.intRangeAtMostBiased(i32, 10, 20) >= 10);
475 assert(r.random.intRangeAtMostBiased(u64, 20, 40) >= 20);
476 assert(r.random.intRangeAtMostBiased(i64, 20, 40) >= 20);
471 //expect(r.random.intRangeAtMostBiased(u0, 0, 0) == 0);
472 expect(r.random.intRangeAtMostBiased(u1, 0, 1) >= 0);
473 expect(r.random.intRangeAtMostBiased(i1, -1, 0) >= -1);
474 expect(r.random.intRangeAtMostBiased(u32, 10, 20) >= 10);
475 expect(r.random.intRangeAtMostBiased(i32, 10, 20) >= 10);
476 expect(r.random.intRangeAtMostBiased(u64, 20, 40) >= 20);
477 expect(r.random.intRangeAtMostBiased(i64, 20, 40) >= 20);
477478}
478479
479480// Generator to extend 64-bit seed values into longer sequences.
......@@ -510,7 +511,7 @@ test "splitmix64 sequence" {
510511 };
511512
512513 for (seq) |s| {
513 std.debug.assert(s == r.next());
514 expect(s == r.next());
514515 }
515516}
516517
......@@ -603,7 +604,7 @@ test "pcg sequence" {
603604 };
604605
605606 for (seq) |s| {
606 std.debug.assert(s == r.next());
607 expect(s == r.next());
607608 }
608609}
609610
......@@ -712,7 +713,7 @@ test "xoroshiro sequence" {
712713 };
713714
714715 for (seq1) |s| {
715 std.debug.assert(s == r.next());
716 expect(s == r.next());
716717 }
717718
718719 r.jump();
......@@ -727,7 +728,7 @@ test "xoroshiro sequence" {
727728 };
728729
729730 for (seq2) |s| {
730 std.debug.assert(s == r.next());
731 expect(s == r.next());
731732 }
732733}
733734
......@@ -930,7 +931,7 @@ test "isaac64 sequence" {
930931 };
931932
932933 for (seq) |s| {
933 std.debug.assert(s == r.next());
934 expect(s == r.next());
934935 }
935936}
936937
......@@ -941,12 +942,12 @@ test "Random float" {
941942 var i: usize = 0;
942943 while (i < 1000) : (i += 1) {
943944 const val1 = prng.random.float(f32);
944 std.debug.assert(val1 >= 0.0);
945 std.debug.assert(val1 < 1.0);
945 expect(val1 >= 0.0);
946 expect(val1 < 1.0);
946947
947948 const val2 = prng.random.float(f64);
948 std.debug.assert(val2 >= 0.0);
949 std.debug.assert(val2 < 1.0);
949 expect(val2 >= 0.0);
950 expect(val2 < 1.0);
950951 }
951952}
952953
......@@ -960,12 +961,12 @@ test "Random shuffle" {
960961 while (i < 1000) : (i += 1) {
961962 prng.random.shuffle(u8, seq[0..]);
962963 seen[seq[0]] = true;
963 std.debug.assert(sumArray(seq[0..]) == 10);
964 expect(sumArray(seq[0..]) == 10);
964965 }
965966
966967 // we should see every entry at the head at least once
967968 for (seen) |e| {
968 std.debug.assert(e == true);
969 expect(e == true);
969970 }
970971}
971972
std/rb.zig+3-2
......@@ -1,5 +1,6 @@
11const std = @import("index.zig");
22const assert = std.debug.assert;
3const testing = std.testing;
34const mem = std.mem; // For mem.Compare
45
56const Color = enum(u1) {
......@@ -533,13 +534,13 @@ test "rb" {
533534 _ = tree.insert(&ns[8].node);
534535 _ = tree.insert(&ns[9].node);
535536 tree.remove(&ns[3].node);
536 assert(tree.insert(&dup.node) == &ns[7].node);
537 testing.expect(tree.insert(&dup.node) == &ns[7].node);
537538 try tree.replace(&ns[7].node, &dup.node);
538539
539540 var num: *testNumber = undefined;
540541 num = testGetNumber(tree.first().?);
541542 while (num.node.next() != null) {
542 assert(testGetNumber(num.node.next().?).value > num.value);
543 testing.expect(testGetNumber(num.node.next().?).value > num.value);
543544 num = testGetNumber(num.node.next().?);
544545 }
545546}
std/segmented_list.zig+16-15
......@@ -1,5 +1,6 @@
11const std = @import("index.zig");
22const assert = std.debug.assert;
3const testing = std.testing;
34const Allocator = std.mem.Allocator;
45
56// Imagine that `fn at(self: *Self, index: usize) &T` is a customer asking for a box
......@@ -352,14 +353,14 @@ fn testSegmentedList(comptime prealloc: usize, allocator: *Allocator) !void {
352353 var i: usize = 0;
353354 while (i < 100) : (i += 1) {
354355 try list.push(@intCast(i32, i + 1));
355 assert(list.len == i + 1);
356 testing.expect(list.len == i + 1);
356357 }
357358 }
358359
359360 {
360361 var i: usize = 0;
361362 while (i < 100) : (i += 1) {
362 assert(list.at(i).* == @intCast(i32, i + 1));
363 testing.expect(list.at(i).* == @intCast(i32, i + 1));
363364 }
364365 }
365366
......@@ -368,35 +369,35 @@ fn testSegmentedList(comptime prealloc: usize, allocator: *Allocator) !void {
368369 var x: i32 = 0;
369370 while (it.next()) |item| {
370371 x += 1;
371 assert(item.* == x);
372 testing.expect(item.* == x);
372373 }
373 assert(x == 100);
374 testing.expect(x == 100);
374375 while (it.prev()) |item| : (x -= 1) {
375 assert(item.* == x);
376 testing.expect(item.* == x);
376377 }
377 assert(x == 0);
378 testing.expect(x == 0);
378379 }
379380
380 assert(list.pop().? == 100);
381 assert(list.len == 99);
381 testing.expect(list.pop().? == 100);
382 testing.expect(list.len == 99);
382383
383384 try list.pushMany([]i32{
384385 1,
385386 2,
386387 3,
387388 });
388 assert(list.len == 102);
389 assert(list.pop().? == 3);
390 assert(list.pop().? == 2);
391 assert(list.pop().? == 1);
392 assert(list.len == 99);
389 testing.expect(list.len == 102);
390 testing.expect(list.pop().? == 3);
391 testing.expect(list.pop().? == 2);
392 testing.expect(list.pop().? == 1);
393 testing.expect(list.len == 99);
393394
394395 try list.pushMany([]const i32{});
395 assert(list.len == 99);
396 testing.expect(list.len == 99);
396397
397398 var i: i32 = 99;
398399 while (list.pop()) |item| : (i -= 1) {
399 assert(item == i);
400 testing.expect(item == i);
400401 list.shrinkCapacity(list.len);
401402 }
402403}
std/sort.zig+9-8
......@@ -1,5 +1,6 @@
11const std = @import("index.zig");
22const assert = std.debug.assert;
3const testing = std.testing;
34const mem = std.mem;
45const math = std.math;
56const builtin = @import("builtin");
......@@ -1031,8 +1032,8 @@ fn testStableSort() void {
10311032 for (cases) |*case| {
10321033 insertionSort(IdAndValue, (case.*)[0..], cmpByValue);
10331034 for (case.*) |item, i| {
1034 assert(item.id == expected[i].id);
1035 assert(item.value == expected[i].value);
1035 testing.expect(item.id == expected[i].id);
1036 testing.expect(item.value == expected[i].value);
10361037 }
10371038 }
10381039}
......@@ -1077,7 +1078,7 @@ test "std.sort" {
10771078 const slice = buf[0..case[0].len];
10781079 mem.copy(u8, slice, case[0]);
10791080 sort(u8, slice, asc(u8));
1080 assert(mem.eql(u8, slice, case[1]));
1081 testing.expect(mem.eql(u8, slice, case[1]));
10811082 }
10821083
10831084 const i32cases = [][]const []const i32{
......@@ -1112,7 +1113,7 @@ test "std.sort" {
11121113 const slice = buf[0..case[0].len];
11131114 mem.copy(i32, slice, case[0]);
11141115 sort(i32, slice, asc(i32));
1115 assert(mem.eql(i32, slice, case[1]));
1116 testing.expect(mem.eql(i32, slice, case[1]));
11161117 }
11171118}
11181119
......@@ -1149,7 +1150,7 @@ test "std.sort descending" {
11491150 const slice = buf[0..case[0].len];
11501151 mem.copy(i32, slice, case[0]);
11511152 sort(i32, slice, desc(i32));
1152 assert(mem.eql(i32, slice, case[1]));
1153 testing.expect(mem.eql(i32, slice, case[1]));
11531154 }
11541155}
11551156
......@@ -1157,7 +1158,7 @@ test "another sort case" {
11571158 var arr = []i32{ 5, 3, 1, 2, 4 };
11581159 sort(i32, arr[0..], asc(i32));
11591160
1160 assert(mem.eql(i32, arr, []i32{ 1, 2, 3, 4, 5 }));
1161 testing.expect(mem.eql(i32, arr, []i32{ 1, 2, 3, 4, 5 }));
11611162}
11621163
11631164test "sort fuzz testing" {
......@@ -1185,9 +1186,9 @@ fn fuzzTest(rng: *std.rand.Random) void {
11851186 var index: usize = 1;
11861187 while (index < array.len) : (index += 1) {
11871188 if (array[index].value == array[index - 1].value) {
1188 assert(array[index].id > array[index - 1].id);
1189 testing.expect(array[index].id > array[index - 1].id);
11891190 } else {
1190 assert(array[index].value > array[index - 1].value);
1191 testing.expect(array[index].value > array[index - 1].value);
11911192 }
11921193 }
11931194}
std/special/compiler_rt/divti3_test.zig+2-2
......@@ -1,9 +1,9 @@
11const __divti3 = @import("divti3.zig").__divti3;
2const assert = @import("std").debug.assert;
2const testing = @import("std").testing;
33
44fn test__divti3(a: i128, b: i128, expected: i128) void {
55 const x = __divti3(a, b);
6 assert(x == expected);
6 testing.expect(x == expected);
77}
88
99test "divti3" {
std/special/compiler_rt/extendXfYf2_test.zig-1
......@@ -1,7 +1,6 @@
11const __extenddftf2 = @import("extendXfYf2.zig").__extenddftf2;
22const __extendhfsf2 = @import("extendXfYf2.zig").__extendhfsf2;
33const __extendsftf2 = @import("extendXfYf2.zig").__extendsftf2;
4const assert = @import("std").debug.assert;
54
65fn test__extenddftf2(a: f64, expectedHi: u64, expectedLo: u64) void {
76 const x = __extenddftf2(a);
std/special/compiler_rt/fixdfdi_test.zig+2-2
......@@ -1,13 +1,13 @@
11const __fixdfdi = @import("fixdfdi.zig").__fixdfdi;
22const std = @import("std");
33const math = std.math;
4const assert = std.debug.assert;
4const testing = std.testing;
55const warn = std.debug.warn;
66
77fn test__fixdfdi(a: f64, expected: i64) void {
88 const x = __fixdfdi(a);
99 //warn("a={}:{x} x={}:{x} expected={}:{x}:u64({x})\n", a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u64, expected));
10 assert(x == expected);
10 testing.expect(x == expected);
1111}
1212
1313test "fixdfdi" {
std/special/compiler_rt/fixdfsi_test.zig+2-2
......@@ -1,13 +1,13 @@
11const __fixdfsi = @import("fixdfsi.zig").__fixdfsi;
22const std = @import("std");
33const math = std.math;
4const assert = std.debug.assert;
4const testing = std.testing;
55const warn = std.debug.warn;
66
77fn test__fixdfsi(a: f64, expected: i32) void {
88 const x = __fixdfsi(a);
99 //warn("a={}:{x} x={}:{x} expected={}:{x}:u64({x})\n", a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u32, expected));
10 assert(x == expected);
10 testing.expect(x == expected);
1111}
1212
1313test "fixdfsi" {
std/special/compiler_rt/fixdfti_test.zig+2-2
......@@ -1,13 +1,13 @@
11const __fixdfti = @import("fixdfti.zig").__fixdfti;
22const std = @import("std");
33const math = std.math;
4const assert = std.debug.assert;
4const testing = std.testing;
55const warn = std.debug.warn;
66
77fn test__fixdfti(a: f64, expected: i128) void {
88 const x = __fixdfti(a);
99 //warn("a={}:{x} x={}:{x} expected={}:{x}:u64({x})\n", a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u128, expected));
10 assert(x == expected);
10 testing.expect(x == expected);
1111}
1212
1313test "fixdfti" {
std/special/compiler_rt/fixint_test.zig+2-2
......@@ -1,7 +1,7 @@
11const is_test = @import("builtin").is_test;
22const std = @import("std");
33const math = std.math;
4const assert = std.debug.assert;
4const testing = std.testing;
55const warn = std.debug.warn;
66
77const fixint = @import("fixint.zig").fixint;
......@@ -9,7 +9,7 @@ const fixint = @import("fixint.zig").fixint;
99fn test__fixint(comptime fp_t: type, comptime fixint_t: type, a: fp_t, expected: fixint_t) void {
1010 const x = fixint(fp_t, fixint_t, a);
1111 //warn("a={} x={}:{x} expected={}:{x})\n", a, x, x, expected, expected);
12 assert(x == expected);
12 testing.expect(x == expected);
1313}
1414
1515test "fixint.i1" {
std/special/compiler_rt/fixsfdi_test.zig+2-2
......@@ -1,13 +1,13 @@
11const __fixsfdi = @import("fixsfdi.zig").__fixsfdi;
22const std = @import("std");
33const math = std.math;
4const assert = std.debug.assert;
4const testing = std.testing;
55const warn = std.debug.warn;
66
77fn test__fixsfdi(a: f32, expected: i64) void {
88 const x = __fixsfdi(a);
99 //warn("a={}:{x} x={}:{x} expected={}:{x}:u32({x})\n", a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u64, expected));
10 assert(x == expected);
10 testing.expect(x == expected);
1111}
1212
1313test "fixsfdi" {
std/special/compiler_rt/fixsfsi_test.zig+2-2
......@@ -1,13 +1,13 @@
11const __fixsfsi = @import("fixsfsi.zig").__fixsfsi;
22const std = @import("std");
33const math = std.math;
4const assert = std.debug.assert;
4const testing = std.testing;
55const warn = std.debug.warn;
66
77fn test__fixsfsi(a: f32, expected: i32) void {
88 const x = __fixsfsi(a);
99 //warn("a={}:{x} x={}:{x} expected={}:{x}:u32({x})\n", a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u32, expected));
10 assert(x == expected);
10 testing.expect(x == expected);
1111}
1212
1313test "fixsfsi" {
std/special/compiler_rt/fixsfti_test.zig+2-2
......@@ -1,13 +1,13 @@
11const __fixsfti = @import("fixsfti.zig").__fixsfti;
22const std = @import("std");
33const math = std.math;
4const assert = std.debug.assert;
4const testing = std.testing;
55const warn = std.debug.warn;
66
77fn test__fixsfti(a: f32, expected: i128) void {
88 const x = __fixsfti(a);
99 //warn("a={}:{x} x={}:{x} expected={}:{x}:u128({x})\n", a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u128, expected));
10 assert(x == expected);
10 testing.expect(x == expected);
1111}
1212
1313test "fixsfti" {
std/special/compiler_rt/fixtfdi_test.zig+2-2
......@@ -1,13 +1,13 @@
11const __fixtfdi = @import("fixtfdi.zig").__fixtfdi;
22const std = @import("std");
33const math = std.math;
4const assert = std.debug.assert;
4const testing = std.testing;
55const warn = std.debug.warn;
66
77fn test__fixtfdi(a: f128, expected: i64) void {
88 const x = __fixtfdi(a);
99 //warn("a={}:{x} x={}:{x} expected={}:{x}:u64({x})\n", a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u64, expected));
10 assert(x == expected);
10 testing.expect(x == expected);
1111}
1212
1313test "fixtfdi" {
std/special/compiler_rt/fixtfsi_test.zig+2-2
......@@ -1,13 +1,13 @@
11const __fixtfsi = @import("fixtfsi.zig").__fixtfsi;
22const std = @import("std");
33const math = std.math;
4const assert = std.debug.assert;
4const testing = std.testing;
55const warn = std.debug.warn;
66
77fn test__fixtfsi(a: f128, expected: i32) void {
88 const x = __fixtfsi(a);
99 //warn("a={}:{x} x={}:{x} expected={}:{x}:u32({x})\n", a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u32, expected));
10 assert(x == expected);
10 testing.expect(x == expected);
1111}
1212
1313test "fixtfsi" {
std/special/compiler_rt/fixtfti_test.zig+2-2
......@@ -1,13 +1,13 @@
11const __fixtfti = @import("fixtfti.zig").__fixtfti;
22const std = @import("std");
33const math = std.math;
4const assert = std.debug.assert;
4const testing = std.testing;
55const warn = std.debug.warn;
66
77fn test__fixtfti(a: f128, expected: i128) void {
88 const x = __fixtfti(a);
99 //warn("a={}:{x} x={}:{x} expected={}:{x}:u128({x})\n", a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u128, expected));
10 assert(x == expected);
10 testing.expect(x == expected);
1111}
1212
1313test "fixtfti" {
std/special/compiler_rt/fixunsdfdi_test.zig+2-2
......@@ -1,9 +1,9 @@
11const __fixunsdfdi = @import("fixunsdfdi.zig").__fixunsdfdi;
2const assert = @import("std").debug.assert;
2const testing = @import("std").testing;
33
44fn test__fixunsdfdi(a: f64, expected: u64) void {
55 const x = __fixunsdfdi(a);
6 assert(x == expected);
6 testing.expect(x == expected);
77}
88
99test "fixunsdfdi" {
std/special/compiler_rt/fixunsdfsi_test.zig+2-2
......@@ -1,9 +1,9 @@
11const __fixunsdfsi = @import("fixunsdfsi.zig").__fixunsdfsi;
2const assert = @import("std").debug.assert;
2const testing = @import("std").testing;
33
44fn test__fixunsdfsi(a: f64, expected: u32) void {
55 const x = __fixunsdfsi(a);
6 assert(x == expected);
6 testing.expect(x == expected);
77}
88
99test "fixunsdfsi" {
std/special/compiler_rt/fixunsdfti_test.zig+2-2
......@@ -1,9 +1,9 @@
11const __fixunsdfti = @import("fixunsdfti.zig").__fixunsdfti;
2const assert = @import("std").debug.assert;
2const testing = @import("std").testing;
33
44fn test__fixunsdfti(a: f64, expected: u128) void {
55 const x = __fixunsdfti(a);
6 assert(x == expected);
6 testing.expect(x == expected);
77}
88
99test "fixunsdfti" {
std/special/compiler_rt/fixunssfdi_test.zig+2-2
......@@ -1,9 +1,9 @@
11const __fixunssfdi = @import("fixunssfdi.zig").__fixunssfdi;
2const assert = @import("std").debug.assert;
2const testing = @import("std").testing;
33
44fn test__fixunssfdi(a: f32, expected: u64) void {
55 const x = __fixunssfdi(a);
6 assert(x == expected);
6 testing.expect(x == expected);
77}
88
99test "fixunssfdi" {
std/special/compiler_rt/fixunssfsi_test.zig+2-2
......@@ -1,9 +1,9 @@
11const __fixunssfsi = @import("fixunssfsi.zig").__fixunssfsi;
2const assert = @import("std").debug.assert;
2const testing = @import("std").testing;
33
44fn test__fixunssfsi(a: f32, expected: u32) void {
55 const x = __fixunssfsi(a);
6 assert(x == expected);
6 testing.expect(x == expected);
77}
88
99test "fixunssfsi" {
std/special/compiler_rt/fixunssfti_test.zig+2-2
......@@ -1,9 +1,9 @@
11const __fixunssfti = @import("fixunssfti.zig").__fixunssfti;
2const assert = @import("std").debug.assert;
2const testing = @import("std").testing;
33
44fn test__fixunssfti(a: f32, expected: u128) void {
55 const x = __fixunssfti(a);
6 assert(x == expected);
6 testing.expect(x == expected);
77}
88
99test "fixunssfti" {
std/special/compiler_rt/fixunstfdi_test.zig+2-2
......@@ -1,9 +1,9 @@
11const __fixunstfdi = @import("fixunstfdi.zig").__fixunstfdi;
2const assert = @import("std").debug.assert;
2const testing = @import("std").testing;
33
44fn test__fixunstfdi(a: f128, expected: u64) void {
55 const x = __fixunstfdi(a);
6 assert(x == expected);
6 testing.expect(x == expected);
77}
88
99test "fixunstfdi" {
std/special/compiler_rt/fixunstfsi_test.zig+2-2
......@@ -1,9 +1,9 @@
11const __fixunstfsi = @import("fixunstfsi.zig").__fixunstfsi;
2const assert = @import("std").debug.assert;
2const testing = @import("std").testing;
33
44fn test__fixunstfsi(a: f128, expected: u32) void {
55 const x = __fixunstfsi(a);
6 assert(x == expected);
6 testing.expect(x == expected);
77}
88
99const inf128 = @bitCast(f128, u128(0x7fff0000000000000000000000000000));
std/special/compiler_rt/fixunstfti_test.zig+2-2
......@@ -1,9 +1,9 @@
11const __fixunstfti = @import("fixunstfti.zig").__fixunstfti;
2const assert = @import("std").debug.assert;
2const testing = @import("std").testing;
33
44fn test__fixunstfti(a: f128, expected: u128) void {
55 const x = __fixunstfti(a);
6 assert(x == expected);
6 testing.expect(x == expected);
77}
88
99const inf128 = @bitCast(f128, u128(0x7fff0000000000000000000000000000));
std/special/compiler_rt/floattidf_test.zig+2-2
......@@ -1,9 +1,9 @@
11const __floattidf = @import("floattidf.zig").__floattidf;
2const assert = @import("std").debug.assert;
2const testing = @import("std").testing;
33
44fn test__floattidf(a: i128, expected: f64) void {
55 const x = __floattidf(a);
6 assert(x == expected);
6 testing.expect(x == expected);
77}
88
99test "floattidf" {
std/special/compiler_rt/floattisf_test.zig+2-2
......@@ -1,9 +1,9 @@
11const __floattisf = @import("floattisf.zig").__floattisf;
2const assert = @import("std").debug.assert;
2const testing = @import("std").testing;
33
44fn test__floattisf(a: i128, expected: f32) void {
55 const x = __floattisf(a);
6 assert(x == expected);
6 testing.expect(x == expected);
77}
88
99test "floattisf" {
std/special/compiler_rt/floattitf_test.zig+2-2
......@@ -1,9 +1,9 @@
11const __floattitf = @import("floattitf.zig").__floattitf;
2const assert = @import("std").debug.assert;
2const testing = @import("std").testing;
33
44fn test__floattitf(a: i128, expected: f128) void {
55 const x = __floattitf(a);
6 assert(x == expected);
6 testing.expect(x == expected);
77}
88
99test "floattitf" {
std/special/compiler_rt/floatunditf_test.zig-1
......@@ -1,5 +1,4 @@
11const __floatunditf = @import("floatunditf.zig").__floatunditf;
2const assert = @import("std").debug.assert;
32
43fn test__floatunditf(a: u128, expected_hi: u64, expected_lo: u64) void {
54 const x = __floatunditf(a);
std/special/compiler_rt/floatunsitf_test.zig-1
......@@ -1,5 +1,4 @@
11const __floatunsitf = @import("floatunsitf.zig").__floatunsitf;
2const assert = @import("std").debug.assert;
32
43fn test__floatunsitf(a: u64, expected_hi: u64, expected_lo: u64) void {
54 const x = __floatunsitf(a);
std/special/compiler_rt/floatuntidf_test.zig+2-2
......@@ -1,9 +1,9 @@
11const __floatuntidf = @import("floatuntidf.zig").__floatuntidf;
2const assert = @import("std").debug.assert;
2const testing = @import("std").testing;
33
44fn test__floatuntidf(a: u128, expected: f64) void {
55 const x = __floatuntidf(a);
6 assert(x == expected);
6 testing.expect(x == expected);
77}
88
99test "floatuntidf" {
std/special/compiler_rt/floatuntisf_test.zig+2-2
......@@ -1,9 +1,9 @@
11const __floatuntisf = @import("floatuntisf.zig").__floatuntisf;
2const assert = @import("std").debug.assert;
2const testing = @import("std").testing;
33
44fn test__floatuntisf(a: u128, expected: f32) void {
55 const x = __floatuntisf(a);
6 assert(x == expected);
6 testing.expect(x == expected);
77}
88
99test "floatuntisf" {
std/special/compiler_rt/floatuntitf_test.zig+2-2
......@@ -1,9 +1,9 @@
11const __floatuntitf = @import("floatuntitf.zig").__floatuntitf;
2const assert = @import("std").debug.assert;
2const testing = @import("std").testing;
33
44fn test__floatuntitf(a: u128, expected: f128) void {
55 const x = __floatuntitf(a);
6 assert(x == expected);
6 testing.expect(x == expected);
77}
88
99test "floatuntitf" {
std/special/compiler_rt/index.zig+3-2
......@@ -110,6 +110,7 @@ comptime {
110110
111111const std = @import("std");
112112const assert = std.debug.assert;
113const testing = std.testing;
113114
114115const __udivmoddi4 = @import("udivmoddi4.zig").__udivmoddi4;
115116
......@@ -417,7 +418,7 @@ test "test_umoddi3" {
417418
418419fn test_one_umoddi3(a: u64, b: u64, expected_r: u64) void {
419420 const r = __umoddi3(a, b);
420 assert(r == expected_r);
421 testing.expect(r == expected_r);
421422}
422423
423424test "test_udivsi3" {
......@@ -1091,5 +1092,5 @@ test "test_udivsi3" {
10911092
10921093fn test_one_udivsi3(a: u32, b: u32, expected_q: u32) void {
10931094 const q: u32 = __udivsi3(a, b);
1094 assert(q == expected_q);
1095 testing.expect(q == expected_q);
10951096}
std/special/compiler_rt/muloti4_test.zig+2-2
......@@ -1,10 +1,10 @@
11const __muloti4 = @import("muloti4.zig").__muloti4;
2const assert = @import("std").debug.assert;
2const testing = @import("std").testing;
33
44fn test__muloti4(a: i128, b: i128, expected: i128, expected_overflow: c_int) void {
55 var overflow: c_int = undefined;
66 const x = __muloti4(a, b, &overflow);
7 assert(overflow == expected_overflow and (expected_overflow != 0 or x == expected));
7 testing.expect(overflow == expected_overflow and (expected_overflow != 0 or x == expected));
88}
99
1010test "muloti4" {
std/special/compiler_rt/multi3_test.zig+2-2
......@@ -1,9 +1,9 @@
11const __multi3 = @import("multi3.zig").__multi3;
2const assert = @import("std").debug.assert;
2const testing = @import("std").testing;
33
44fn test__multi3(a: i128, b: i128, expected: i128) void {
55 const x = __multi3(a, b);
6 assert(x == expected);
6 testing.expect(x == expected);
77}
88
99test "multi3" {
std/special/compiler_rt/udivmoddi4_test.zig+3-3
......@@ -1,13 +1,13 @@
11// Disable formatting to avoid unnecessary source repository bloat.
22// zig fmt: off
33const __udivmoddi4 = @import("udivmoddi4.zig").__udivmoddi4;
4const assert = @import("std").debug.assert;
4const testing = @import("std").testing;
55
66fn test__udivmoddi4(a: u64, b: u64, expected_q: u64, expected_r: u64) void {
77 var r: u64 = undefined;
88 const q = __udivmoddi4(a, b, &r);
9 assert(q == expected_q);
10 assert(r == expected_r);
9 testing.expect(q == expected_q);
10 testing.expect(r == expected_r);
1111}
1212
1313test "udivmoddi4" {
std/special/compiler_rt/udivmodti4_test.zig+3-3
......@@ -1,13 +1,13 @@
11// Disable formatting to avoid unnecessary source repository bloat.
22// zig fmt: off
33const __udivmodti4 = @import("udivmodti4.zig").__udivmodti4;
4const assert = @import("std").debug.assert;
4const testing = @import("std").testing;
55
66fn test__udivmodti4(a: u128, b: u128, expected_q: u128, expected_r: u128) void {
77 var r: u128 = undefined;
88 const q = __udivmodti4(a, b, &r);
9 assert(q == expected_q);
10 assert(r == expected_r);
9 testing.expect(q == expected_q);
10 testing.expect(r == expected_r);
1111}
1212
1313test "udivmodti4" {
std/special/init-lib/src/main.zig+2-2
......@@ -1,10 +1,10 @@
11const std = @import("std");
2const assertOrPanic = std.debug.assertOrPanic;
2const testing = std.testing;
33
44export fn add(a: i32, b: i32) i32 {
55 return a + b;
66}
77
88test "basic add functionality" {
9 assertOrPanic(add(3, 7) == 10);
9 testing.expect(add(3, 7) == 10);
1010}
std/statically_initialized_mutex.zig+3-2
......@@ -3,6 +3,7 @@ const builtin = @import("builtin");
33const AtomicOrder = builtin.AtomicOrder;
44const AtomicRmwOp = builtin.AtomicRmwOp;
55const assert = std.debug.assert;
6const expect = std.testing.expect;
67const windows = std.os.windows;
78
89/// Lock may be held only once. If the same thread
......@@ -95,7 +96,7 @@ test "std.StaticallyInitializedMutex" {
9596
9697 if (builtin.single_threaded) {
9798 TestContext.worker(&context);
98 std.debug.assertOrPanic(context.data == TestContext.incr_count);
99 expect(context.data == TestContext.incr_count);
99100 } else {
100101 const thread_count = 10;
101102 var threads: [thread_count]*std.os.Thread = undefined;
......@@ -105,6 +106,6 @@ test "std.StaticallyInitializedMutex" {
105106 for (threads) |t|
106107 t.wait();
107108
108 std.debug.assertOrPanic(context.data == thread_count * TestContext.incr_count);
109 expect(context.data == thread_count * TestContext.incr_count);
109110 }
110111}
std/testing.zig created+152
......@@ -0,0 +1,152 @@
1const builtin = @import("builtin");
2const TypeId = builtin.TypeId;
3const std = @import("index.zig");
4
5/// This function is intended to be used only in tests. It prints diagnostics to stderr
6/// and then aborts when actual_error_union is not expected_error.
7pub fn expectError(expected_error: anyerror, actual_error_union: var) void {
8 // TODO remove the workaround here for https://github.com/ziglang/zig/issues/1936
9 if (actual_error_union) |actual_payload| {
10 // TODO remove workaround here for https://github.com/ziglang/zig/issues/557
11 if (@sizeOf(@typeOf(actual_payload)) == 0) {
12 std.debug.panic("expected error.{}, found {} value", @errorName(expected_error), @typeName(@typeOf(actual_payload)));
13 } else {
14 std.debug.panic("expected error.{}, found {}", @errorName(expected_error), actual_payload);
15 }
16 } else |actual_error| {
17 if (expected_error != actual_error) {
18 std.debug.panic("expected error.{}, found error.{}", @errorName(expected_error), @errorName(actual_error));
19 }
20 }
21}
22
23/// This function is intended to be used only in tests. When the two values are not
24/// equal, prints diagnostics to stderr to show exactly how they are not equal,
25/// then aborts.
26/// The types must match exactly.
27pub fn expectEqual(expected: var, actual: var) void {
28 if (@typeOf(actual) != @typeOf(expected)) {
29 @compileError("type mismatch. expected " ++ @typeName(@typeOf(expected)) ++ ", found " ++ @typeName(@typeOf(actual)));
30 }
31
32 switch (@typeInfo(@typeOf(actual))) {
33 TypeId.NoReturn,
34 TypeId.BoundFn,
35 TypeId.ArgTuple,
36 TypeId.Opaque,
37 => @compileError("value of type " ++ @typeName(@typeOf(actual)) ++ " encountered"),
38
39 TypeId.Undefined,
40 TypeId.Null,
41 TypeId.Void,
42 => return,
43
44 TypeId.Type,
45 TypeId.Bool,
46 TypeId.Int,
47 TypeId.Float,
48 TypeId.ComptimeFloat,
49 TypeId.ComptimeInt,
50 TypeId.Enum,
51 TypeId.Namespace,
52 TypeId.Fn,
53 TypeId.Promise,
54 TypeId.Vector,
55 TypeId.ErrorSet,
56 => {
57 if (actual != expected) {
58 std.debug.panic("expected {}, found {}", expected, actual);
59 }
60 },
61
62 TypeId.Pointer => |pointer| {
63 switch (pointer.size) {
64 builtin.TypeInfo.Pointer.Size.One,
65 builtin.TypeInfo.Pointer.Size.Many,
66 => {
67 if (actual != expected) {
68 std.debug.panic("expected {}, found {}", expected, actual);
69 }
70 },
71
72 builtin.TypeInfo.Pointer.Size.Slice => {
73 if (actual.ptr != expected.ptr) {
74 std.debug.panic("expected slice ptr {}, found {}", expected.ptr, actual.ptr);
75 }
76 if (actual.len != expected.len) {
77 std.debug.panic("expected slice len {}, found {}", expected.len, actual.len);
78 }
79 },
80 }
81 },
82
83 TypeId.Array => |array| expectEqualSlices(array.child, &expected, &actual),
84
85 TypeId.Struct => {
86 @compileError("TODO implement testing.expectEqual for structs");
87 },
88
89 TypeId.Union => |union_info| {
90 if (union_info.tag_type == null) {
91 @compileError("Unable to compare untagged union values");
92 }
93 @compileError("TODO implement testing.expectEqual for tagged unions");
94 },
95
96 TypeId.Optional => {
97 if (expected) |expected_payload| {
98 if (actual) |actual_payload| {
99 expectEqual(expected_payload, actual_payload);
100 } else {
101 std.debug.panic("expected {}, found null", expected_payload);
102 }
103 } else {
104 if (actual) |actual_payload| {
105 std.debug.panic("expected null, found {}", actual_payload);
106 }
107 }
108 },
109
110 TypeId.ErrorUnion => {
111 if (expected) |expected_payload| {
112 if (actual) |actual_payload| {
113 expectEqual(expected_payload, actual_payload);
114 } else |actual_err| {
115 std.debug.panic("expected {}, found {}", expected_payload, actual_err);
116 }
117 } else |expected_err| {
118 if (actual) |actual_payload| {
119 std.debug.panic("expected {}, found {}", expected_err, actual_payload);
120 } else |actual_err| {
121 expectEqual(expected_err, actual_err);
122 }
123 }
124 },
125
126 }
127}
128
129/// This function is intended to be used only in tests. When the two slices are not
130/// equal, prints diagnostics to stderr to show exactly how they are not equal,
131/// then aborts.
132pub fn expectEqualSlices(comptime T: type, expected: []const T, actual: []const T) void {
133 // TODO better printing of the difference
134 // If the arrays are small enough we could print the whole thing
135 // If the child type is u8 and no weird bytes, we could print it as strings
136 // Even for the length difference, it would be useful to see the values of the slices probably.
137 if (expected.len != actual.len) {
138 std.debug.panic("slice lengths differ. expected {}, found {}", expected.len, actual.len);
139 }
140 var i: usize = 0;
141 while (i < expected.len) : (i += 1) {
142 if (expected[i] != actual[i]) {
143 std.debug.panic("index {} incorrect. expected {}, found {}", i, expected[i], actual[i]);
144 }
145 }
146}
147
148/// This function is intended to be used only in tests. When `ok` is false, the test fails.
149/// A message is printed to stderr and then abort is called.
150pub fn expect(ok: bool) void {
151 if (!ok) @panic("test failure");
152}
std/unicode.zig+53-66
......@@ -1,7 +1,7 @@
11const std = @import("./index.zig");
22const builtin = @import("builtin");
3const debug = std.debug;
43const assert = std.debug.assert;
4const testing = std.testing;
55const mem = std.mem;
66
77/// Returns how many bytes the UTF-8 representation would require
......@@ -32,7 +32,7 @@ pub fn utf8ByteSequenceLength(first_byte: u8) !u3 {
3232/// Returns: the number of bytes written to out.
3333pub fn utf8Encode(c: u32, out: []u8) !u3 {
3434 const length = try utf8CodepointSequenceLength(c);
35 debug.assert(out.len >= length);
35 assert(out.len >= length);
3636 switch (length) {
3737 // The pattern for each is the same
3838 // - Increasing the initial shift by 6 each time
......@@ -81,8 +81,8 @@ const Utf8Decode2Error = error{
8181 Utf8OverlongEncoding,
8282};
8383pub fn utf8Decode2(bytes: []const u8) Utf8Decode2Error!u32 {
84 debug.assert(bytes.len == 2);
85 debug.assert(bytes[0] & 0b11100000 == 0b11000000);
84 assert(bytes.len == 2);
85 assert(bytes[0] & 0b11100000 == 0b11000000);
8686 var value: u32 = bytes[0] & 0b00011111;
8787
8888 if (bytes[1] & 0b11000000 != 0b10000000) return error.Utf8ExpectedContinuation;
......@@ -100,8 +100,8 @@ const Utf8Decode3Error = error{
100100 Utf8EncodesSurrogateHalf,
101101};
102102pub fn utf8Decode3(bytes: []const u8) Utf8Decode3Error!u32 {
103 debug.assert(bytes.len == 3);
104 debug.assert(bytes[0] & 0b11110000 == 0b11100000);
103 assert(bytes.len == 3);
104 assert(bytes[0] & 0b11110000 == 0b11100000);
105105 var value: u32 = bytes[0] & 0b00001111;
106106
107107 if (bytes[1] & 0b11000000 != 0b10000000) return error.Utf8ExpectedContinuation;
......@@ -124,8 +124,8 @@ const Utf8Decode4Error = error{
124124 Utf8CodepointTooLarge,
125125};
126126pub fn utf8Decode4(bytes: []const u8) Utf8Decode4Error!u32 {
127 debug.assert(bytes.len == 4);
128 debug.assert(bytes[0] & 0b11111000 == 0b11110000);
127 assert(bytes.len == 4);
128 assert(bytes[0] & 0b11111000 == 0b11110000);
129129 var value: u32 = bytes[0] & 0b00000111;
130130
131131 if (bytes[1] & 0b11000000 != 0b10000000) return error.Utf8ExpectedContinuation;
......@@ -274,23 +274,23 @@ test "utf8 encode" {
274274fn testUtf8Encode() !void {
275275 // A few taken from wikipedia a few taken elsewhere
276276 var array: [4]u8 = undefined;
277 debug.assert((try utf8Encode(try utf8Decode("€"), array[0..])) == 3);
278 debug.assert(array[0] == 0b11100010);
279 debug.assert(array[1] == 0b10000010);
280 debug.assert(array[2] == 0b10101100);
277 testing.expect((try utf8Encode(try utf8Decode("€"), array[0..])) == 3);
278 testing.expect(array[0] == 0b11100010);
279 testing.expect(array[1] == 0b10000010);
280 testing.expect(array[2] == 0b10101100);
281281
282 debug.assert((try utf8Encode(try utf8Decode("$"), array[0..])) == 1);
283 debug.assert(array[0] == 0b00100100);
282 testing.expect((try utf8Encode(try utf8Decode("$"), array[0..])) == 1);
283 testing.expect(array[0] == 0b00100100);
284284
285 debug.assert((try utf8Encode(try utf8Decode("¢"), array[0..])) == 2);
286 debug.assert(array[0] == 0b11000010);
287 debug.assert(array[1] == 0b10100010);
285 testing.expect((try utf8Encode(try utf8Decode("¢"), array[0..])) == 2);
286 testing.expect(array[0] == 0b11000010);
287 testing.expect(array[1] == 0b10100010);
288288
289 debug.assert((try utf8Encode(try utf8Decode("𐍈"), array[0..])) == 4);
290 debug.assert(array[0] == 0b11110000);
291 debug.assert(array[1] == 0b10010000);
292 debug.assert(array[2] == 0b10001101);
293 debug.assert(array[3] == 0b10001000);
289 testing.expect((try utf8Encode(try utf8Decode("𐍈"), array[0..])) == 4);
290 testing.expect(array[0] == 0b11110000);
291 testing.expect(array[1] == 0b10010000);
292 testing.expect(array[2] == 0b10001101);
293 testing.expect(array[3] == 0b10001000);
294294}
295295
296296test "utf8 encode error" {
......@@ -306,11 +306,7 @@ fn testUtf8EncodeError() void {
306306}
307307
308308fn testErrorEncode(codePoint: u32, array: []u8, expectedErr: anyerror) void {
309 if (utf8Encode(codePoint, array)) |_| {
310 unreachable;
311 } else |err| {
312 debug.assert(err == expectedErr);
313 }
309 testing.expectError(expectedErr, utf8Encode(codePoint, array));
314310}
315311
316312test "utf8 iterator on ascii" {
......@@ -321,16 +317,16 @@ fn testUtf8IteratorOnAscii() void {
321317 const s = Utf8View.initComptime("abc");
322318
323319 var it1 = s.iterator();
324 debug.assert(std.mem.eql(u8, "a", it1.nextCodepointSlice().?));
325 debug.assert(std.mem.eql(u8, "b", it1.nextCodepointSlice().?));
326 debug.assert(std.mem.eql(u8, "c", it1.nextCodepointSlice().?));
327 debug.assert(it1.nextCodepointSlice() == null);
320 testing.expect(std.mem.eql(u8, "a", it1.nextCodepointSlice().?));
321 testing.expect(std.mem.eql(u8, "b", it1.nextCodepointSlice().?));
322 testing.expect(std.mem.eql(u8, "c", it1.nextCodepointSlice().?));
323 testing.expect(it1.nextCodepointSlice() == null);
328324
329325 var it2 = s.iterator();
330 debug.assert(it2.nextCodepoint().? == 'a');
331 debug.assert(it2.nextCodepoint().? == 'b');
332 debug.assert(it2.nextCodepoint().? == 'c');
333 debug.assert(it2.nextCodepoint() == null);
326 testing.expect(it2.nextCodepoint().? == 'a');
327 testing.expect(it2.nextCodepoint().? == 'b');
328 testing.expect(it2.nextCodepoint().? == 'c');
329 testing.expect(it2.nextCodepoint() == null);
334330}
335331
336332test "utf8 view bad" {
......@@ -340,12 +336,7 @@ test "utf8 view bad" {
340336fn testUtf8ViewBad() void {
341337 // Compile-time error.
342338 // const s3 = Utf8View.initComptime("\xfe\xf2");
343 const s = Utf8View.init("hel\xadlo");
344 if (s) |_| {
345 unreachable;
346 } else |err| {
347 debug.assert(err == error.InvalidUtf8);
348 }
339 testing.expectError(error.InvalidUtf8, Utf8View.init("hel\xadlo"));
349340}
350341
351342test "utf8 view ok" {
......@@ -356,16 +347,16 @@ fn testUtf8ViewOk() void {
356347 const s = Utf8View.initComptime("東京市");
357348
358349 var it1 = s.iterator();
359 debug.assert(std.mem.eql(u8, "東", it1.nextCodepointSlice().?));
360 debug.assert(std.mem.eql(u8, "京", it1.nextCodepointSlice().?));
361 debug.assert(std.mem.eql(u8, "市", it1.nextCodepointSlice().?));
362 debug.assert(it1.nextCodepointSlice() == null);
350 testing.expect(std.mem.eql(u8, "東", it1.nextCodepointSlice().?));
351 testing.expect(std.mem.eql(u8, "京", it1.nextCodepointSlice().?));
352 testing.expect(std.mem.eql(u8, "市", it1.nextCodepointSlice().?));
353 testing.expect(it1.nextCodepointSlice() == null);
363354
364355 var it2 = s.iterator();
365 debug.assert(it2.nextCodepoint().? == 0x6771);
366 debug.assert(it2.nextCodepoint().? == 0x4eac);
367 debug.assert(it2.nextCodepoint().? == 0x5e02);
368 debug.assert(it2.nextCodepoint() == null);
356 testing.expect(it2.nextCodepoint().? == 0x6771);
357 testing.expect(it2.nextCodepoint().? == 0x4eac);
358 testing.expect(it2.nextCodepoint().? == 0x5e02);
359 testing.expect(it2.nextCodepoint() == null);
369360}
370361
371362test "bad utf8 slice" {
......@@ -373,10 +364,10 @@ test "bad utf8 slice" {
373364 testBadUtf8Slice();
374365}
375366fn testBadUtf8Slice() void {
376 debug.assert(utf8ValidateSlice("abc"));
377 debug.assert(!utf8ValidateSlice("abc\xc0"));
378 debug.assert(!utf8ValidateSlice("abc\xc0abc"));
379 debug.assert(utf8ValidateSlice("abc\xdf\xbf"));
367 testing.expect(utf8ValidateSlice("abc"));
368 testing.expect(!utf8ValidateSlice("abc\xc0"));
369 testing.expect(!utf8ValidateSlice("abc\xc0abc"));
370 testing.expect(utf8ValidateSlice("abc\xdf\xbf"));
380371}
381372
382373test "valid utf8" {
......@@ -459,21 +450,17 @@ fn testMiscInvalidUtf8() void {
459450}
460451
461452fn testError(bytes: []const u8, expected_err: anyerror) void {
462 if (testDecode(bytes)) |_| {
463 unreachable;
464 } else |err| {
465 debug.assert(err == expected_err);
466 }
453 testing.expectError(expected_err, testDecode(bytes));
467454}
468455
469456fn testValid(bytes: []const u8, expected_codepoint: u32) void {
470 debug.assert((testDecode(bytes) catch unreachable) == expected_codepoint);
457 testing.expect((testDecode(bytes) catch unreachable) == expected_codepoint);
471458}
472459
473460fn testDecode(bytes: []const u8) !u32 {
474461 const length = try utf8ByteSequenceLength(bytes[0]);
475462 if (bytes.len < length) return error.UnexpectedEof;
476 debug.assert(bytes.len == length);
463 testing.expect(bytes.len == length);
477464 return utf8Decode(bytes);
478465}
479466
......@@ -513,14 +500,14 @@ test "utf16leToUtf8" {
513500 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 'A');
514501 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 'a');
515502 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le);
516 assert(mem.eql(u8, utf8, "Aa"));
503 testing.expect(mem.eql(u8, utf8, "Aa"));
517504 }
518505
519506 {
520507 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0x80);
521508 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xffff);
522509 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le);
523 assert(mem.eql(u8, utf8, "\xc2\x80" ++ "\xef\xbf\xbf"));
510 testing.expect(mem.eql(u8, utf8, "\xc2\x80" ++ "\xef\xbf\xbf"));
524511 }
525512
526513 {
......@@ -528,7 +515,7 @@ test "utf16leToUtf8" {
528515 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xd7ff);
529516 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xe000);
530517 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le);
531 assert(mem.eql(u8, utf8, "\xed\x9f\xbf" ++ "\xee\x80\x80"));
518 testing.expect(mem.eql(u8, utf8, "\xed\x9f\xbf" ++ "\xee\x80\x80"));
532519 }
533520
534521 {
......@@ -536,7 +523,7 @@ test "utf16leToUtf8" {
536523 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xd800);
537524 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdc00);
538525 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le);
539 assert(mem.eql(u8, utf8, "\xf0\x90\x80\x80"));
526 testing.expect(mem.eql(u8, utf8, "\xf0\x90\x80\x80"));
540527 }
541528
542529 {
......@@ -544,14 +531,14 @@ test "utf16leToUtf8" {
544531 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xdbff);
545532 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdfff);
546533 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le);
547 assert(mem.eql(u8, utf8, "\xf4\x8f\xbf\xbf"));
534 testing.expect(mem.eql(u8, utf8, "\xf4\x8f\xbf\xbf"));
548535 }
549536
550537 {
551538 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xdbff);
552539 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdc00);
553540 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le);
554 assert(mem.eql(u8, utf8, "\xf4\x8f\xb0\x80"));
541 testing.expect(mem.eql(u8, utf8, "\xf4\x8f\xb0\x80"));
555542 }
556543}
557544
std/zig/ast.zig+2-1
......@@ -1,5 +1,6 @@
11const std = @import("../index.zig");
22const assert = std.debug.assert;
3const testing = std.testing;
34const SegmentedList = std.SegmentedList;
45const mem = std.mem;
56const Token = std.zig.Token;
......@@ -2224,5 +2225,5 @@ test "iterate" {
22242225 .shebang = null,
22252226 };
22262227 var base = &root.base;
2227 assert(base.iterate(0) == null);
2228 testing.expect(base.iterate(0) == null);
22282229}
std/zig/parser_test.zig+1-1
......@@ -1940,7 +1940,7 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {
19401940 warn("std.zig.render returned {} instead of {}\n", anything_changed, changes_expected);
19411941 return error.TestFailed;
19421942 }
1943 std.debug.assert(anything_changed == changes_expected);
1943 std.testing.expect(anything_changed == changes_expected);
19441944 failing_allocator.allocator.free(result_source);
19451945 break :x failing_allocator.index;
19461946 };
std/zig/tokenizer.zig+1-1
......@@ -1345,5 +1345,5 @@ fn testTokenize(source: []const u8, expected_tokens: []const Token.Id) void {
13451345 }
13461346 }
13471347 const last_token = tokenizer.next();
1348 std.debug.assert(last_token.id == Token.Id.Eof);
1348 std.testing.expect(last_token.id == Token.Id.Eof);
13491349}
test/cli.zig+5-5
......@@ -1,7 +1,7 @@
11const std = @import("std");
22const builtin = @import("builtin");
33const os = std.os;
4const assertOrPanic = std.debug.assertOrPanic;
4const testing = std.testing;
55
66var a: *std.mem.Allocator = undefined;
77
......@@ -87,13 +87,13 @@ fn exec(cwd: []const u8, argv: []const []const u8) !os.ChildProcess.ExecResult {
8787fn testZigInitLib(zig_exe: []const u8, dir_path: []const u8) !void {
8888 _ = try exec(dir_path, [][]const u8{ zig_exe, "init-lib" });
8989 const test_result = try exec(dir_path, [][]const u8{ zig_exe, "build", "test" });
90 assertOrPanic(std.mem.endsWith(u8, test_result.stderr, "All tests passed.\n"));
90 testing.expect(std.mem.endsWith(u8, test_result.stderr, "All tests passed.\n"));
9191}
9292
9393fn testZigInitExe(zig_exe: []const u8, dir_path: []const u8) !void {
9494 _ = try exec(dir_path, [][]const u8{ zig_exe, "init-exe" });
9595 const run_result = try exec(dir_path, [][]const u8{ zig_exe, "build", "run" });
96 assertOrPanic(std.mem.eql(u8, run_result.stderr, "All your base are belong to us.\n"));
96 testing.expect(std.mem.eql(u8, run_result.stderr, "All your base are belong to us.\n"));
9797}
9898
9999fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void {
......@@ -126,6 +126,6 @@ fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void {
126126 _ = try exec(dir_path, args);
127127
128128 const out_asm = try std.io.readFileAlloc(a, example_s_path);
129 assertOrPanic(std.mem.indexOf(u8, out_asm, "square:") != null);
130 assertOrPanic(std.mem.indexOf(u8, out_asm, "imul\tedi, edi") != null);
129 testing.expect(std.mem.indexOf(u8, out_asm, "square:") != null);
130 testing.expect(std.mem.indexOf(u8, out_asm, "imul\tedi, edi") != null);
131131}
test/stage1/behavior/align.zig+36-36
......@@ -1,13 +1,13 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;
1const expect = @import("std").testing.expect;
22const builtin = @import("builtin");
33
44var foo: u8 align(4) = 100;
55
66test "global variable alignment" {
7 assertOrPanic(@typeOf(&foo).alignment == 4);
8 assertOrPanic(@typeOf(&foo) == *align(4) u8);
7 expect(@typeOf(&foo).alignment == 4);
8 expect(@typeOf(&foo) == *align(4) u8);
99 const slice = (*[1]u8)(&foo)[0..];
10 assertOrPanic(@typeOf(slice) == []align(4) u8);
10 expect(@typeOf(slice) == []align(4) u8);
1111}
1212
1313fn derp() align(@sizeOf(usize) * 2) i32 {
......@@ -17,9 +17,9 @@ fn noop1() align(1) void {}
1717fn noop4() align(4) void {}
1818
1919test "function alignment" {
20 assertOrPanic(derp() == 1234);
21 assertOrPanic(@typeOf(noop1) == fn () align(1) void);
22 assertOrPanic(@typeOf(noop4) == fn () align(4) void);
20 expect(derp() == 1234);
21 expect(@typeOf(noop1) == fn () align(1) void);
22 expect(@typeOf(noop4) == fn () align(4) void);
2323 noop1();
2424 noop4();
2525}
......@@ -30,7 +30,7 @@ var baz: packed struct {
3030} = undefined;
3131
3232test "packed struct alignment" {
33 assertOrPanic(@typeOf(&baz.b) == *align(1) u32);
33 expect(@typeOf(&baz.b) == *align(1) u32);
3434}
3535
3636const blah: packed struct {
......@@ -40,17 +40,17 @@ const blah: packed struct {
4040} = undefined;
4141
4242test "bit field alignment" {
43 assertOrPanic(@typeOf(&blah.b) == *align(1:3:1) const u3);
43 expect(@typeOf(&blah.b) == *align(1:3:1) const u3);
4444}
4545
4646test "default alignment allows unspecified in type syntax" {
47 assertOrPanic(*u32 == *align(@alignOf(u32)) u32);
47 expect(*u32 == *align(@alignOf(u32)) u32);
4848}
4949
5050test "implicitly decreasing pointer alignment" {
5151 const a: u32 align(4) = 3;
5252 const b: u32 align(8) = 4;
53 assertOrPanic(addUnaligned(&a, &b) == 7);
53 expect(addUnaligned(&a, &b) == 7);
5454}
5555
5656fn addUnaligned(a: *align(1) const u32, b: *align(1) const u32) u32 {
......@@ -60,7 +60,7 @@ fn addUnaligned(a: *align(1) const u32, b: *align(1) const u32) u32 {
6060test "implicitly decreasing slice alignment" {
6161 const a: u32 align(4) = 3;
6262 const b: u32 align(8) = 4;
63 assertOrPanic(addUnalignedSlice((*[1]u32)(&a)[0..], (*[1]u32)(&b)[0..]) == 7);
63 expect(addUnalignedSlice((*[1]u32)(&a)[0..], (*[1]u32)(&b)[0..]) == 7);
6464}
6565fn addUnalignedSlice(a: []align(1) const u32, b: []align(1) const u32) u32 {
6666 return a[0] + b[0];
......@@ -77,7 +77,7 @@ fn testBytesAlign(b: u8) void {
7777 b,
7878 };
7979 const ptr = @ptrCast(*u32, &bytes[0]);
80 assertOrPanic(ptr.* == 0x33333333);
80 expect(ptr.* == 0x33333333);
8181}
8282
8383test "specifying alignment allows slice cast" {
......@@ -91,13 +91,13 @@ fn testBytesAlignSlice(b: u8) void {
9191 b,
9292 };
9393 const slice: []u32 = @bytesToSlice(u32, bytes[0..]);
94 assertOrPanic(slice[0] == 0x33333333);
94 expect(slice[0] == 0x33333333);
9595}
9696
9797test "@alignCast pointers" {
9898 var x: u32 align(4) = 1;
9999 expectsOnly1(&x);
100 assertOrPanic(x == 2);
100 expect(x == 2);
101101}
102102fn expectsOnly1(x: *align(1) u32) void {
103103 expects4(@alignCast(4, x));
......@@ -113,7 +113,7 @@ test "@alignCast slices" {
113113 };
114114 const slice = array[0..];
115115 sliceExpectsOnly1(slice);
116 assertOrPanic(slice[0] == 2);
116 expect(slice[0] == 2);
117117}
118118fn sliceExpectsOnly1(slice: []align(1) u32) void {
119119 sliceExpects4(@alignCast(4, slice));
......@@ -128,7 +128,7 @@ test "implicitly decreasing fn alignment" {
128128}
129129
130130fn testImplicitlyDecreaseFnAlign(ptr: fn () align(1) i32, answer: i32) void {
131 assertOrPanic(ptr() == answer);
131 expect(ptr() == answer);
132132}
133133
134134fn alignedSmall() align(8) i32 {
......@@ -139,7 +139,7 @@ fn alignedBig() align(16) i32 {
139139}
140140
141141test "@alignCast functions" {
142 assertOrPanic(fnExpectsOnly1(simple4) == 0x19);
142 expect(fnExpectsOnly1(simple4) == 0x19);
143143}
144144fn fnExpectsOnly1(ptr: fn () align(1) i32) i32 {
145145 return fnExpects4(@alignCast(4, ptr));
......@@ -152,9 +152,9 @@ fn simple4() align(4) i32 {
152152}
153153
154154test "generic function with align param" {
155 assertOrPanic(whyWouldYouEverDoThis(1) == 0x1);
156 assertOrPanic(whyWouldYouEverDoThis(4) == 0x1);
157 assertOrPanic(whyWouldYouEverDoThis(8) == 0x1);
155 expect(whyWouldYouEverDoThis(1) == 0x1);
156 expect(whyWouldYouEverDoThis(4) == 0x1);
157 expect(whyWouldYouEverDoThis(8) == 0x1);
158158}
159159
160160fn whyWouldYouEverDoThis(comptime align_bytes: u8) align(align_bytes) u8 {
......@@ -164,28 +164,28 @@ fn whyWouldYouEverDoThis(comptime align_bytes: u8) align(align_bytes) u8 {
164164test "@ptrCast preserves alignment of bigger source" {
165165 var x: u32 align(16) = 1234;
166166 const ptr = @ptrCast(*u8, &x);
167 assertOrPanic(@typeOf(ptr) == *align(16) u8);
167 expect(@typeOf(ptr) == *align(16) u8);
168168}
169169
170170test "runtime known array index has best alignment possible" {
171171 // take full advantage of over-alignment
172172 var array align(4) = []u8{ 1, 2, 3, 4 };
173 assertOrPanic(@typeOf(&array[0]) == *align(4) u8);
174 assertOrPanic(@typeOf(&array[1]) == *u8);
175 assertOrPanic(@typeOf(&array[2]) == *align(2) u8);
176 assertOrPanic(@typeOf(&array[3]) == *u8);
173 expect(@typeOf(&array[0]) == *align(4) u8);
174 expect(@typeOf(&array[1]) == *u8);
175 expect(@typeOf(&array[2]) == *align(2) u8);
176 expect(@typeOf(&array[3]) == *u8);
177177
178178 // because align is too small but we still figure out to use 2
179179 var bigger align(2) = []u64{ 1, 2, 3, 4 };
180 assertOrPanic(@typeOf(&bigger[0]) == *align(2) u64);
181 assertOrPanic(@typeOf(&bigger[1]) == *align(2) u64);
182 assertOrPanic(@typeOf(&bigger[2]) == *align(2) u64);
183 assertOrPanic(@typeOf(&bigger[3]) == *align(2) u64);
180 expect(@typeOf(&bigger[0]) == *align(2) u64);
181 expect(@typeOf(&bigger[1]) == *align(2) u64);
182 expect(@typeOf(&bigger[2]) == *align(2) u64);
183 expect(@typeOf(&bigger[3]) == *align(2) u64);
184184
185185 // because pointer is align 2 and u32 align % 2 == 0 we can assume align 2
186186 var smaller align(2) = []u32{ 1, 2, 3, 4 };
187 comptime assertOrPanic(@typeOf(smaller[0..]) == []align(2) u32);
188 comptime assertOrPanic(@typeOf(smaller[0..].ptr) == [*]align(2) u32);
187 comptime expect(@typeOf(smaller[0..]) == []align(2) u32);
188 comptime expect(@typeOf(smaller[0..].ptr) == [*]align(2) u32);
189189 testIndex(smaller[0..].ptr, 0, *align(2) u32);
190190 testIndex(smaller[0..].ptr, 1, *align(2) u32);
191191 testIndex(smaller[0..].ptr, 2, *align(2) u32);
......@@ -198,14 +198,14 @@ test "runtime known array index has best alignment possible" {
198198 testIndex2(array[0..].ptr, 3, *u8);
199199}
200200fn testIndex(smaller: [*]align(2) u32, index: usize, comptime T: type) void {
201 comptime assertOrPanic(@typeOf(&smaller[index]) == T);
201 comptime expect(@typeOf(&smaller[index]) == T);
202202}
203203fn testIndex2(ptr: [*]align(4) u8, index: usize, comptime T: type) void {
204 comptime assertOrPanic(@typeOf(&ptr[index]) == T);
204 comptime expect(@typeOf(&ptr[index]) == T);
205205}
206206
207207test "alignstack" {
208 assertOrPanic(fnWithAlignedStack() == 1234);
208 expect(fnWithAlignedStack() == 1234);
209209}
210210
211211fn fnWithAlignedStack() i32 {
......@@ -214,7 +214,7 @@ fn fnWithAlignedStack() i32 {
214214}
215215
216216test "alignment of structs" {
217 assertOrPanic(@alignOf(struct {
217 expect(@alignOf(struct {
218218 a: i32,
219219 b: *i32,
220220 }) == @alignOf(usize));
test/stage1/behavior/alignof.zig+3-3
......@@ -1,5 +1,5 @@
11const std = @import("std");
2const assertOrPanic = std.debug.assertOrPanic;
2const expect = std.testing.expect;
33const builtin = @import("builtin");
44const maxInt = std.math.maxInt;
55
......@@ -10,9 +10,9 @@ const Foo = struct {
1010};
1111
1212test "@alignOf(T) before referencing T" {
13 comptime assertOrPanic(@alignOf(Foo) != maxInt(usize));
13 comptime expect(@alignOf(Foo) != maxInt(usize));
1414 if (builtin.arch == builtin.Arch.x86_64) {
15 comptime assertOrPanic(@alignOf(Foo) == 4);
15 comptime expect(@alignOf(Foo) == 4);
1616 }
1717}
1818
test/stage1/behavior/array.zig+55-55
......@@ -1,4 +1,4 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;
1const expect = @import("std").testing.expect;
22const mem = @import("std").mem;
33
44test "arrays" {
......@@ -18,8 +18,8 @@ test "arrays" {
1818 i += 1;
1919 }
2020
21 assertOrPanic(accumulator == 15);
22 assertOrPanic(getArrayLen(array) == 5);
21 expect(accumulator == 15);
22 expect(getArrayLen(array) == 5);
2323}
2424fn getArrayLen(a: []const u32) usize {
2525 return a.len;
......@@ -29,8 +29,8 @@ test "void arrays" {
2929 var array: [4]void = undefined;
3030 array[0] = void{};
3131 array[1] = array[2];
32 assertOrPanic(@sizeOf(@typeOf(array)) == 0);
33 assertOrPanic(array.len == 4);
32 expect(@sizeOf(@typeOf(array)) == 0);
33 expect(array.len == 4);
3434}
3535
3636test "array literal" {
......@@ -41,12 +41,12 @@ test "array literal" {
4141 1,
4242 };
4343
44 assertOrPanic(hex_mult.len == 4);
45 assertOrPanic(hex_mult[1] == 256);
44 expect(hex_mult.len == 4);
45 expect(hex_mult[1] == 256);
4646}
4747
4848test "array dot len const expr" {
49 assertOrPanic(comptime x: {
49 expect(comptime x: {
5050 break :x some_array.len == 4;
5151 });
5252}
......@@ -70,11 +70,11 @@ test "nested arrays" {
7070 "thing",
7171 };
7272 for (array_of_strings) |s, i| {
73 if (i == 0) assertOrPanic(mem.eql(u8, s, "hello"));
74 if (i == 1) assertOrPanic(mem.eql(u8, s, "this"));
75 if (i == 2) assertOrPanic(mem.eql(u8, s, "is"));
76 if (i == 3) assertOrPanic(mem.eql(u8, s, "my"));
77 if (i == 4) assertOrPanic(mem.eql(u8, s, "thing"));
73 if (i == 0) expect(mem.eql(u8, s, "hello"));
74 if (i == 1) expect(mem.eql(u8, s, "this"));
75 if (i == 2) expect(mem.eql(u8, s, "is"));
76 if (i == 3) expect(mem.eql(u8, s, "my"));
77 if (i == 4) expect(mem.eql(u8, s, "thing"));
7878 }
7979}
8080
......@@ -92,9 +92,9 @@ test "set global var array via slice embedded in struct" {
9292 s.a[1].b = 2;
9393 s.a[2].b = 3;
9494
95 assertOrPanic(s_array[0].b == 1);
96 assertOrPanic(s_array[1].b == 2);
97 assertOrPanic(s_array[2].b == 3);
95 expect(s_array[0].b == 1);
96 expect(s_array[1].b == 2);
97 expect(s_array[2].b == 3);
9898}
9999
100100test "array literal with specified size" {
......@@ -102,27 +102,27 @@ test "array literal with specified size" {
102102 1,
103103 2,
104104 };
105 assertOrPanic(array[0] == 1);
106 assertOrPanic(array[1] == 2);
105 expect(array[0] == 1);
106 expect(array[1] == 2);
107107}
108108
109109test "array child property" {
110110 var x: [5]i32 = undefined;
111 assertOrPanic(@typeOf(x).Child == i32);
111 expect(@typeOf(x).Child == i32);
112112}
113113
114114test "array len property" {
115115 var x: [5]i32 = undefined;
116 assertOrPanic(@typeOf(x).len == 5);
116 expect(@typeOf(x).len == 5);
117117}
118118
119119test "array len field" {
120120 var arr = [4]u8{ 0, 0, 0, 0 };
121121 var ptr = &arr;
122 assertOrPanic(arr.len == 4);
123 comptime assertOrPanic(arr.len == 4);
124 assertOrPanic(ptr.len == 4);
125 comptime assertOrPanic(ptr.len == 4);
122 expect(arr.len == 4);
123 comptime expect(arr.len == 4);
124 expect(ptr.len == 4);
125 comptime expect(ptr.len == 4);
126126}
127127
128128test "single-item pointer to array indexing and slicing" {
......@@ -133,7 +133,7 @@ test "single-item pointer to array indexing and slicing" {
133133fn testSingleItemPtrArrayIndexSlice() void {
134134 var array = "aaaa";
135135 doSomeMangling(&array);
136 assertOrPanic(mem.eql(u8, "azya", array));
136 expect(mem.eql(u8, "azya", array));
137137}
138138
139139fn doSomeMangling(array: *[4]u8) void {
......@@ -150,7 +150,7 @@ fn testImplicitCastSingleItemPtr() void {
150150 var byte: u8 = 100;
151151 const slice = (*[1]u8)(&byte)[0..];
152152 slice[0] += 1;
153 assertOrPanic(byte == 101);
153 expect(byte == 101);
154154}
155155
156156fn testArrayByValAtComptime(b: [2]u8) u8 {
......@@ -165,7 +165,7 @@ test "comptime evalutating function that takes array by value" {
165165
166166test "implicit comptime in array type size" {
167167 var arr: [plusOne(10)]bool = undefined;
168 assertOrPanic(arr.len == 11);
168 expect(arr.len == 11);
169169}
170170
171171fn plusOne(x: u32) u32 {
......@@ -197,15 +197,15 @@ test "array literal as argument to function" {
197197 });
198198 }
199199 fn foo(x: []const i32) void {
200 assertOrPanic(x[0] == 1);
201 assertOrPanic(x[1] == 2);
202 assertOrPanic(x[2] == 3);
200 expect(x[0] == 1);
201 expect(x[1] == 2);
202 expect(x[2] == 3);
203203 }
204204 fn foo2(trash: bool, x: []const i32) void {
205 assertOrPanic(trash);
206 assertOrPanic(x[0] == 1);
207 assertOrPanic(x[1] == 2);
208 assertOrPanic(x[2] == 3);
205 expect(trash);
206 expect(x[0] == 1);
207 expect(x[1] == 2);
208 expect(x[2] == 3);
209209 }
210210 };
211211 S.entry(2);
......@@ -229,12 +229,12 @@ test "double nested array to const slice cast in array literal" {
229229 []i32{1},
230230 []i32{ two, 3 },
231231 };
232 assertOrPanic(cases2.len == 2);
233 assertOrPanic(cases2[0].len == 1);
234 assertOrPanic(cases2[0][0] == 1);
235 assertOrPanic(cases2[1].len == 2);
236 assertOrPanic(cases2[1][0] == 2);
237 assertOrPanic(cases2[1][1] == 3);
232 expect(cases2.len == 2);
233 expect(cases2[0].len == 1);
234 expect(cases2[0][0] == 1);
235 expect(cases2[1].len == 2);
236 expect(cases2[1][0] == 2);
237 expect(cases2[1][1] == 3);
238238
239239 const cases3 = [][]const []const i32{
240240 [][]const i32{[]i32{1}},
......@@ -248,21 +248,21 @@ test "double nested array to const slice cast in array literal" {
248248 }
249249
250250 fn check(cases: []const []const []const i32) void {
251 assertOrPanic(cases.len == 3);
252 assertOrPanic(cases[0].len == 1);
253 assertOrPanic(cases[0][0].len == 1);
254 assertOrPanic(cases[0][0][0] == 1);
255 assertOrPanic(cases[1].len == 1);
256 assertOrPanic(cases[1][0].len == 2);
257 assertOrPanic(cases[1][0][0] == 2);
258 assertOrPanic(cases[1][0][1] == 3);
259 assertOrPanic(cases[2].len == 2);
260 assertOrPanic(cases[2][0].len == 1);
261 assertOrPanic(cases[2][0][0] == 4);
262 assertOrPanic(cases[2][1].len == 3);
263 assertOrPanic(cases[2][1][0] == 5);
264 assertOrPanic(cases[2][1][1] == 6);
265 assertOrPanic(cases[2][1][2] == 7);
251 expect(cases.len == 3);
252 expect(cases[0].len == 1);
253 expect(cases[0][0].len == 1);
254 expect(cases[0][0][0] == 1);
255 expect(cases[1].len == 1);
256 expect(cases[1][0].len == 2);
257 expect(cases[1][0][0] == 2);
258 expect(cases[1][0][1] == 3);
259 expect(cases[2].len == 2);
260 expect(cases[2][0].len == 1);
261 expect(cases[2][0][0] == 4);
262 expect(cases[2][1].len == 3);
263 expect(cases[2][1][0] == 5);
264 expect(cases[2][1][1] == 6);
265 expect(cases[2][1][2] == 7);
266266 }
267267 };
268268 S.entry(2);
test/stage1/behavior/asm.zig+2-2
......@@ -1,5 +1,5 @@
11const config = @import("builtin");
2const assertOrPanic = @import("std").debug.assertOrPanic;
2const expect = @import("std").testing.expect;
33
44comptime {
55 if (config.arch == config.Arch.x86_64 and config.os == config.Os.linux) {
......@@ -13,7 +13,7 @@ comptime {
1313
1414test "module level assembly" {
1515 if (config.arch == config.Arch.x86_64 and config.os == config.Os.linux) {
16 assertOrPanic(aoeu() == 1234);
16 expect(aoeu() == 1234);
1717 }
1818}
1919
test/stage1/behavior/atomics.zig+16-16
......@@ -1,5 +1,5 @@
11const std = @import("std");
2const assertOrPanic = std.debug.assertOrPanic;
2const expect = std.testing.expect;
33const builtin = @import("builtin");
44const AtomicRmwOp = builtin.AtomicRmwOp;
55const AtomicOrder = builtin.AtomicOrder;
......@@ -7,18 +7,18 @@ const AtomicOrder = builtin.AtomicOrder;
77test "cmpxchg" {
88 var x: i32 = 1234;
99 if (@cmpxchgWeak(i32, &x, 99, 5678, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) |x1| {
10 assertOrPanic(x1 == 1234);
10 expect(x1 == 1234);
1111 } else {
1212 @panic("cmpxchg should have failed");
1313 }
1414
1515 while (@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) |x1| {
16 assertOrPanic(x1 == 1234);
16 expect(x1 == 1234);
1717 }
18 assertOrPanic(x == 5678);
18 expect(x == 5678);
1919
20 assertOrPanic(@cmpxchgStrong(i32, &x, 5678, 42, AtomicOrder.SeqCst, AtomicOrder.SeqCst) == null);
21 assertOrPanic(x == 42);
20 expect(@cmpxchgStrong(i32, &x, 5678, 42, AtomicOrder.SeqCst, AtomicOrder.SeqCst) == null);
21 expect(x == 42);
2222}
2323
2424test "fence" {
......@@ -30,24 +30,24 @@ test "fence" {
3030test "atomicrmw and atomicload" {
3131 var data: u8 = 200;
3232 testAtomicRmw(&data);
33 assertOrPanic(data == 42);
33 expect(data == 42);
3434 testAtomicLoad(&data);
3535}
3636
3737fn testAtomicRmw(ptr: *u8) void {
3838 const prev_value = @atomicRmw(u8, ptr, AtomicRmwOp.Xchg, 42, AtomicOrder.SeqCst);
39 assertOrPanic(prev_value == 200);
39 expect(prev_value == 200);
4040 comptime {
4141 var x: i32 = 1234;
4242 const y: i32 = 12345;
43 assertOrPanic(@atomicLoad(i32, &x, AtomicOrder.SeqCst) == 1234);
44 assertOrPanic(@atomicLoad(i32, &y, AtomicOrder.SeqCst) == 12345);
43 expect(@atomicLoad(i32, &x, AtomicOrder.SeqCst) == 1234);
44 expect(@atomicLoad(i32, &y, AtomicOrder.SeqCst) == 12345);
4545 }
4646}
4747
4848fn testAtomicLoad(ptr: *u8) void {
4949 const x = @atomicLoad(u8, ptr, AtomicOrder.SeqCst);
50 assertOrPanic(x == 42);
50 expect(x == 42);
5151}
5252
5353test "cmpxchg with ptr" {
......@@ -56,16 +56,16 @@ test "cmpxchg with ptr" {
5656 var data3: i32 = 9101;
5757 var x: *i32 = &data1;
5858 if (@cmpxchgWeak(*i32, &x, &data2, &data3, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) |x1| {
59 assertOrPanic(x1 == &data1);
59 expect(x1 == &data1);
6060 } else {
6161 @panic("cmpxchg should have failed");
6262 }
6363
6464 while (@cmpxchgWeak(*i32, &x, &data1, &data3, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) |x1| {
65 assertOrPanic(x1 == &data1);
65 expect(x1 == &data1);
6666 }
67 assertOrPanic(x == &data3);
67 expect(x == &data3);
6868
69 assertOrPanic(@cmpxchgStrong(*i32, &x, &data3, &data2, AtomicOrder.SeqCst, AtomicOrder.SeqCst) == null);
70 assertOrPanic(x == &data2);
69 expect(@cmpxchgStrong(*i32, &x, &data3, &data2, AtomicOrder.SeqCst, AtomicOrder.SeqCst) == null);
70 expect(x == &data2);
7171}
test/stage1/behavior/bit_shifting.zig+5-5
......@@ -1,9 +1,9 @@
11const std = @import("std");
2const assertOrPanic = std.debug.assertOrPanic;
2const expect = std.testing.expect;
33
44fn ShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, comptime V: type) type {
5 assertOrPanic(Key == @IntType(false, Key.bit_count));
6 assertOrPanic(Key.bit_count >= mask_bit_count);
5 expect(Key == @IntType(false, Key.bit_count));
6 expect(Key.bit_count >= mask_bit_count);
77 const ShardKey = @IntType(false, mask_bit_count);
88 const shift_amount = Key.bit_count - ShardKey.bit_count;
99 return struct {
......@@ -77,12 +77,12 @@ fn testShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, c
7777 var node_buffer: [node_count]Table.Node = undefined;
7878 for (node_buffer) |*node, i| {
7979 const key = @intCast(Key, i);
80 assertOrPanic(table.get(key) == null);
80 expect(table.get(key) == null);
8181 node.init(key, {});
8282 table.put(node);
8383 }
8484
8585 for (node_buffer) |*node, i| {
86 assertOrPanic(table.get(@intCast(Key, i)) == node);
86 expect(table.get(@intCast(Key, i)) == node);
8787 }
8888}
test/stage1/behavior/bitcast.zig+4-4
......@@ -1,5 +1,5 @@
11const std = @import("std");
2const assertOrPanic = std.debug.assertOrPanic;
2const expect = std.testing.expect;
33const maxInt = std.math.maxInt;
44
55test "@bitCast i32 -> u32" {
......@@ -8,8 +8,8 @@ test "@bitCast i32 -> u32" {
88}
99
1010fn testBitCast_i32_u32() void {
11 assertOrPanic(conv(-1) == maxInt(u32));
12 assertOrPanic(conv2(maxInt(u32)) == -1);
11 expect(conv(-1) == maxInt(u32));
12 expect(conv2(maxInt(u32)) == -1);
1313}
1414
1515fn conv(x: i32) u32 {
......@@ -27,7 +27,7 @@ test "@bitCast extern enum to its integer type" {
2727 fn testBitCastExternEnum() void {
2828 var SOCK_DGRAM = @This().B;
2929 var sock_dgram = @bitCast(c_int, SOCK_DGRAM);
30 assertOrPanic(sock_dgram == 1);
30 expect(sock_dgram == 1);
3131 }
3232 };
3333
test/stage1/behavior/bitreverse.zig+43-43
......@@ -1,5 +1,5 @@
11const std = @import("std");
2const assertOrPanic = std.debug.assertOrPanic;
2const expect = std.testing.expect;
33const minInt = std.math.minInt;
44
55test "@bitreverse" {
......@@ -9,73 +9,73 @@ test "@bitreverse" {
99
1010fn testBitReverse() void {
1111 // using comptime_ints, unsigned
12 assertOrPanic(@bitreverse(u0, 0) == 0);
13 assertOrPanic(@bitreverse(u5, 0x12) == 0x9);
14 assertOrPanic(@bitreverse(u8, 0x12) == 0x48);
15 assertOrPanic(@bitreverse(u16, 0x1234) == 0x2c48);
16 assertOrPanic(@bitreverse(u24, 0x123456) == 0x6a2c48);
17 assertOrPanic(@bitreverse(u32, 0x12345678) == 0x1e6a2c48);
18 assertOrPanic(@bitreverse(u40, 0x123456789a) == 0x591e6a2c48);
19 assertOrPanic(@bitreverse(u48, 0x123456789abc) == 0x3d591e6a2c48);
20 assertOrPanic(@bitreverse(u56, 0x123456789abcde) == 0x7b3d591e6a2c48);
21 assertOrPanic(@bitreverse(u64, 0x123456789abcdef1) == 0x8f7b3d591e6a2c48);
22 assertOrPanic(@bitreverse(u128, 0x123456789abcdef11121314151617181) == 0x818e868a828c84888f7b3d591e6a2c48);
12 expect(@bitreverse(u0, 0) == 0);
13 expect(@bitreverse(u5, 0x12) == 0x9);
14 expect(@bitreverse(u8, 0x12) == 0x48);
15 expect(@bitreverse(u16, 0x1234) == 0x2c48);
16 expect(@bitreverse(u24, 0x123456) == 0x6a2c48);
17 expect(@bitreverse(u32, 0x12345678) == 0x1e6a2c48);
18 expect(@bitreverse(u40, 0x123456789a) == 0x591e6a2c48);
19 expect(@bitreverse(u48, 0x123456789abc) == 0x3d591e6a2c48);
20 expect(@bitreverse(u56, 0x123456789abcde) == 0x7b3d591e6a2c48);
21 expect(@bitreverse(u64, 0x123456789abcdef1) == 0x8f7b3d591e6a2c48);
22 expect(@bitreverse(u128, 0x123456789abcdef11121314151617181) == 0x818e868a828c84888f7b3d591e6a2c48);
2323
2424 // using runtime uints, unsigned
2525 var num0: u0 = 0;
26 assertOrPanic(@bitreverse(u0, num0) == 0);
26 expect(@bitreverse(u0, num0) == 0);
2727 var num5: u5 = 0x12;
28 assertOrPanic(@bitreverse(u5, num5) == 0x9);
28 expect(@bitreverse(u5, num5) == 0x9);
2929 var num8: u8 = 0x12;
30 assertOrPanic(@bitreverse(u8, num8) == 0x48);
30 expect(@bitreverse(u8, num8) == 0x48);
3131 var num16: u16 = 0x1234;
32 assertOrPanic(@bitreverse(u16, num16) == 0x2c48);
32 expect(@bitreverse(u16, num16) == 0x2c48);
3333 var num24: u24 = 0x123456;
34 assertOrPanic(@bitreverse(u24, num24) == 0x6a2c48);
34 expect(@bitreverse(u24, num24) == 0x6a2c48);
3535 var num32: u32 = 0x12345678;
36 assertOrPanic(@bitreverse(u32, num32) == 0x1e6a2c48);
36 expect(@bitreverse(u32, num32) == 0x1e6a2c48);
3737 var num40: u40 = 0x123456789a;
38 assertOrPanic(@bitreverse(u40, num40) == 0x591e6a2c48);
38 expect(@bitreverse(u40, num40) == 0x591e6a2c48);
3939 var num48: u48 = 0x123456789abc;
40 assertOrPanic(@bitreverse(u48, num48) == 0x3d591e6a2c48);
40 expect(@bitreverse(u48, num48) == 0x3d591e6a2c48);
4141 var num56: u56 = 0x123456789abcde;
42 assertOrPanic(@bitreverse(u56, num56) == 0x7b3d591e6a2c48);
42 expect(@bitreverse(u56, num56) == 0x7b3d591e6a2c48);
4343 var num64: u64 = 0x123456789abcdef1;
44 assertOrPanic(@bitreverse(u64, num64) == 0x8f7b3d591e6a2c48);
44 expect(@bitreverse(u64, num64) == 0x8f7b3d591e6a2c48);
4545 var num128: u128 = 0x123456789abcdef11121314151617181;
46 assertOrPanic(@bitreverse(u128, num128) == 0x818e868a828c84888f7b3d591e6a2c48);
46 expect(@bitreverse(u128, num128) == 0x818e868a828c84888f7b3d591e6a2c48);
4747
4848 // using comptime_ints, signed, positive
49 assertOrPanic(@bitreverse(i0, 0) == 0);
50 assertOrPanic(@bitreverse(i8, @bitCast(i8, u8(0x92))) == @bitCast(i8, u8(0x49)));
51 assertOrPanic(@bitreverse(i16, @bitCast(i16, u16(0x1234))) == @bitCast(i16, u16(0x2c48)));
52 assertOrPanic(@bitreverse(i24, @bitCast(i24, u24(0x123456))) == @bitCast(i24, u24(0x6a2c48)));
53 assertOrPanic(@bitreverse(i32, @bitCast(i32, u32(0x12345678))) == @bitCast(i32, u32(0x1e6a2c48)));
54 assertOrPanic(@bitreverse(i40, @bitCast(i40, u40(0x123456789a))) == @bitCast(i40, u40(0x591e6a2c48)));
55 assertOrPanic(@bitreverse(i48, @bitCast(i48, u48(0x123456789abc))) == @bitCast(i48, u48(0x3d591e6a2c48)));
56 assertOrPanic(@bitreverse(i56, @bitCast(i56, u56(0x123456789abcde))) == @bitCast(i56, u56(0x7b3d591e6a2c48)));
57 assertOrPanic(@bitreverse(i64, @bitCast(i64, u64(0x123456789abcdef1))) == @bitCast(i64, u64(0x8f7b3d591e6a2c48)));
58 assertOrPanic(@bitreverse(i128, @bitCast(i128, u128(0x123456789abcdef11121314151617181))) == @bitCast(i128, u128(0x818e868a828c84888f7b3d591e6a2c48)));
49 expect(@bitreverse(i0, 0) == 0);
50 expect(@bitreverse(i8, @bitCast(i8, u8(0x92))) == @bitCast(i8, u8(0x49)));
51 expect(@bitreverse(i16, @bitCast(i16, u16(0x1234))) == @bitCast(i16, u16(0x2c48)));
52 expect(@bitreverse(i24, @bitCast(i24, u24(0x123456))) == @bitCast(i24, u24(0x6a2c48)));
53 expect(@bitreverse(i32, @bitCast(i32, u32(0x12345678))) == @bitCast(i32, u32(0x1e6a2c48)));
54 expect(@bitreverse(i40, @bitCast(i40, u40(0x123456789a))) == @bitCast(i40, u40(0x591e6a2c48)));
55 expect(@bitreverse(i48, @bitCast(i48, u48(0x123456789abc))) == @bitCast(i48, u48(0x3d591e6a2c48)));
56 expect(@bitreverse(i56, @bitCast(i56, u56(0x123456789abcde))) == @bitCast(i56, u56(0x7b3d591e6a2c48)));
57 expect(@bitreverse(i64, @bitCast(i64, u64(0x123456789abcdef1))) == @bitCast(i64, u64(0x8f7b3d591e6a2c48)));
58 expect(@bitreverse(i128, @bitCast(i128, u128(0x123456789abcdef11121314151617181))) == @bitCast(i128, u128(0x818e868a828c84888f7b3d591e6a2c48)));
5959
6060 // using comptime_ints, signed, negative. Compare to runtime ints returned from llvm.
6161 var neg5: i5 = minInt(i5) + 1;
62 assertOrPanic(@bitreverse(i5, minInt(i5) + 1) == @bitreverse(i5, neg5));
62 expect(@bitreverse(i5, minInt(i5) + 1) == @bitreverse(i5, neg5));
6363 var neg8: i8 = -18;
64 assertOrPanic(@bitreverse(i8, -18) == @bitreverse(i8, neg8));
64 expect(@bitreverse(i8, -18) == @bitreverse(i8, neg8));
6565 var neg16: i16 = -32694;
66 assertOrPanic(@bitreverse(i16, -32694) == @bitreverse(i16, neg16));
66 expect(@bitreverse(i16, -32694) == @bitreverse(i16, neg16));
6767 var neg24: i24 = -6773785;
68 assertOrPanic(@bitreverse(i24, -6773785) == @bitreverse(i24, neg24));
68 expect(@bitreverse(i24, -6773785) == @bitreverse(i24, neg24));
6969 var neg32: i32 = -16773785;
70 assertOrPanic(@bitreverse(i32, -16773785) == @bitreverse(i32, neg32));
70 expect(@bitreverse(i32, -16773785) == @bitreverse(i32, neg32));
7171 var neg40: i40 = minInt(i40) + 12345;
72 assertOrPanic(@bitreverse(i40, minInt(i40) + 12345) == @bitreverse(i40, neg40));
72 expect(@bitreverse(i40, minInt(i40) + 12345) == @bitreverse(i40, neg40));
7373 var neg48: i48 = minInt(i48) + 12345;
74 assertOrPanic(@bitreverse(i48, minInt(i48) + 12345) == @bitreverse(i48, neg48));
74 expect(@bitreverse(i48, minInt(i48) + 12345) == @bitreverse(i48, neg48));
7575 var neg56: i56 = minInt(i56) + 12345;
76 assertOrPanic(@bitreverse(i56, minInt(i56) + 12345) == @bitreverse(i56, neg56));
76 expect(@bitreverse(i56, minInt(i56) + 12345) == @bitreverse(i56, neg56));
7777 var neg64: i64 = minInt(i64) + 12345;
78 assertOrPanic(@bitreverse(i64, minInt(i64) + 12345) == @bitreverse(i64, neg64));
78 expect(@bitreverse(i64, minInt(i64) + 12345) == @bitreverse(i64, neg64));
7979 var neg128: i128 = minInt(i128) + 12345;
80 assertOrPanic(@bitreverse(i128, minInt(i128) + 12345) == @bitreverse(i128, neg128));
80 expect(@bitreverse(i128, minInt(i128) + 12345) == @bitreverse(i128, neg128));
8181}
test/stage1/behavior/bool.zig+10-10
......@@ -1,25 +1,25 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;
1const expect = @import("std").testing.expect;
22
33test "bool literals" {
4 assertOrPanic(true);
5 assertOrPanic(!false);
4 expect(true);
5 expect(!false);
66}
77
88test "cast bool to int" {
99 const t = true;
1010 const f = false;
11 assertOrPanic(@boolToInt(t) == u32(1));
12 assertOrPanic(@boolToInt(f) == u32(0));
11 expect(@boolToInt(t) == u32(1));
12 expect(@boolToInt(f) == u32(0));
1313 nonConstCastBoolToInt(t, f);
1414}
1515
1616fn nonConstCastBoolToInt(t: bool, f: bool) void {
17 assertOrPanic(@boolToInt(t) == u32(1));
18 assertOrPanic(@boolToInt(f) == u32(0));
17 expect(@boolToInt(t) == u32(1));
18 expect(@boolToInt(f) == u32(0));
1919}
2020
2121test "bool cmp" {
22 assertOrPanic(testBoolCmp(true, false) == false);
22 expect(testBoolCmp(true, false) == false);
2323}
2424fn testBoolCmp(a: bool, b: bool) bool {
2525 return a == b;
......@@ -30,6 +30,6 @@ const global_t = true;
3030const not_global_f = !global_f;
3131const not_global_t = !global_t;
3232test "compile time bool not" {
33 assertOrPanic(not_global_f);
34 assertOrPanic(!not_global_t);
33 expect(not_global_f);
34 expect(!not_global_t);
3535}
test/stage1/behavior/bswap.zig+21-21
......@@ -1,5 +1,5 @@
11const std = @import("std");
2const assertOrPanic = std.debug.assertOrPanic;
2const expect = std.testing.expect;
33
44test "@bswap" {
55 comptime testByteSwap();
......@@ -7,26 +7,26 @@ test "@bswap" {
77}
88
99fn testByteSwap() void {
10 assertOrPanic(@bswap(u0, 0) == 0);
11 assertOrPanic(@bswap(u8, 0x12) == 0x12);
12 assertOrPanic(@bswap(u16, 0x1234) == 0x3412);
13 assertOrPanic(@bswap(u24, 0x123456) == 0x563412);
14 assertOrPanic(@bswap(u32, 0x12345678) == 0x78563412);
15 assertOrPanic(@bswap(u40, 0x123456789a) == 0x9a78563412);
16 assertOrPanic(@bswap(u48, 0x123456789abc) == 0xbc9a78563412);
17 assertOrPanic(@bswap(u56, 0x123456789abcde) == 0xdebc9a78563412);
18 assertOrPanic(@bswap(u64, 0x123456789abcdef1) == 0xf1debc9a78563412);
19 assertOrPanic(@bswap(u128, 0x123456789abcdef11121314151617181) == 0x8171615141312111f1debc9a78563412);
10 expect(@bswap(u0, 0) == 0);
11 expect(@bswap(u8, 0x12) == 0x12);
12 expect(@bswap(u16, 0x1234) == 0x3412);
13 expect(@bswap(u24, 0x123456) == 0x563412);
14 expect(@bswap(u32, 0x12345678) == 0x78563412);
15 expect(@bswap(u40, 0x123456789a) == 0x9a78563412);
16 expect(@bswap(u48, 0x123456789abc) == 0xbc9a78563412);
17 expect(@bswap(u56, 0x123456789abcde) == 0xdebc9a78563412);
18 expect(@bswap(u64, 0x123456789abcdef1) == 0xf1debc9a78563412);
19 expect(@bswap(u128, 0x123456789abcdef11121314151617181) == 0x8171615141312111f1debc9a78563412);
2020
21 assertOrPanic(@bswap(i0, 0) == 0);
22 assertOrPanic(@bswap(i8, -50) == -50);
23 assertOrPanic(@bswap(i16, @bitCast(i16, u16(0x1234))) == @bitCast(i16, u16(0x3412)));
24 assertOrPanic(@bswap(i24, @bitCast(i24, u24(0x123456))) == @bitCast(i24, u24(0x563412)));
25 assertOrPanic(@bswap(i32, @bitCast(i32, u32(0x12345678))) == @bitCast(i32, u32(0x78563412)));
26 assertOrPanic(@bswap(i40, @bitCast(i40, u40(0x123456789a))) == @bitCast(i40, u40(0x9a78563412)));
27 assertOrPanic(@bswap(i48, @bitCast(i48, u48(0x123456789abc))) == @bitCast(i48, u48(0xbc9a78563412)));
28 assertOrPanic(@bswap(i56, @bitCast(i56, u56(0x123456789abcde))) == @bitCast(i56, u56(0xdebc9a78563412)));
29 assertOrPanic(@bswap(i64, @bitCast(i64, u64(0x123456789abcdef1))) == @bitCast(i64, u64(0xf1debc9a78563412)));
30 assertOrPanic(@bswap(i128, @bitCast(i128, u128(0x123456789abcdef11121314151617181))) ==
21 expect(@bswap(i0, 0) == 0);
22 expect(@bswap(i8, -50) == -50);
23 expect(@bswap(i16, @bitCast(i16, u16(0x1234))) == @bitCast(i16, u16(0x3412)));
24 expect(@bswap(i24, @bitCast(i24, u24(0x123456))) == @bitCast(i24, u24(0x563412)));
25 expect(@bswap(i32, @bitCast(i32, u32(0x12345678))) == @bitCast(i32, u32(0x78563412)));
26 expect(@bswap(i40, @bitCast(i40, u40(0x123456789a))) == @bitCast(i40, u40(0x9a78563412)));
27 expect(@bswap(i48, @bitCast(i48, u48(0x123456789abc))) == @bitCast(i48, u48(0xbc9a78563412)));
28 expect(@bswap(i56, @bitCast(i56, u56(0x123456789abcde))) == @bitCast(i56, u56(0xdebc9a78563412)));
29 expect(@bswap(i64, @bitCast(i64, u64(0x123456789abcdef1))) == @bitCast(i64, u64(0xf1debc9a78563412)));
30 expect(@bswap(i128, @bitCast(i128, u128(0x123456789abcdef11121314151617181))) ==
3131 @bitCast(i128, u128(0x8171615141312111f1debc9a78563412)));
3232}
test/stage1/behavior/bugs/1076.zig+2-2
......@@ -1,6 +1,6 @@
11const std = @import("std");
22const mem = std.mem;
3const assertOrPanic = std.debug.assertOrPanic;
3const expect = std.testing.expect;
44
55test "comptime code should not modify constant data" {
66 testCastPtrOfArrayToSliceAndPtr();
......@@ -11,6 +11,6 @@ fn testCastPtrOfArrayToSliceAndPtr() void {
1111 var array = "aoeu";
1212 const x: [*]u8 = &array;
1313 x[0] += 1;
14 assertOrPanic(mem.eql(u8, array[0..], "boeu"));
14 expect(mem.eql(u8, array[0..], "boeu"));
1515}
1616
test/stage1/behavior/bugs/1277.zig+1-1
......@@ -11,5 +11,5 @@ fn f() i32 {
1111}
1212
1313test "don't emit an LLVM global for a const function when it's in an optional in a struct" {
14 std.debug.assertOrPanic(s.f.?() == 1234);
14 std.testing.expect(s.f.?() == 1234);
1515}
test/stage1/behavior/bugs/1322.zig+2-2
......@@ -13,7 +13,7 @@ const C = struct {};
1313
1414test "tagged union with all void fields but a meaningful tag" {
1515 var a: A = A{ .b = B{ .c = C{} } };
16 std.debug.assertOrPanic(@TagType(B)(a.b) == @TagType(B).c);
16 std.testing.expect(@TagType(B)(a.b) == @TagType(B).c);
1717 a = A{ .b = B.None };
18 std.debug.assertOrPanic(@TagType(B)(a.b) == @TagType(B).None);
18 std.testing.expect(@TagType(B)(a.b) == @TagType(B).None);
1919}
test/stage1/behavior/bugs/1381.zig+1-1
......@@ -17,5 +17,5 @@ test "union that needs padding bytes inside an array" {
1717 };
1818
1919 const a = as[0].B;
20 std.debug.assertOrPanic(a.D == 1);
20 std.testing.expect(a.D == 1);
2121}
test/stage1/behavior/bugs/1421.zig+2-2
......@@ -1,6 +1,6 @@
11const std = @import("std");
22const builtin = @import("builtin");
3const assertOrPanic = std.debug.assertOrPanic;
3const expect = std.testing.expect;
44
55const S = struct {
66 fn method() builtin.TypeInfo {
......@@ -10,5 +10,5 @@ const S = struct {
1010
1111test "functions with return type required to be comptime are generic" {
1212 const ti = S.method();
13 assertOrPanic(builtin.TypeId(ti) == builtin.TypeId.Struct);
13 expect(builtin.TypeId(ti) == builtin.TypeId.Struct);
1414}
test/stage1/behavior/bugs/1442.zig+1-1
......@@ -7,5 +7,5 @@ const Union = union(enum) {
77
88test "const error union field alignment" {
99 var union_or_err: anyerror!Union = Union{ .Color = 1234 };
10 std.debug.assertOrPanic((union_or_err catch unreachable).Color == 1234);
10 std.testing.expect((union_or_err catch unreachable).Color == 1234);
1111}
test/stage1/behavior/bugs/1486.zig+3-3
......@@ -1,11 +1,11 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;
1const expect = @import("std").testing.expect;
22
33const ptr = &global;
44var global: u64 = 123;
55
66test "constant pointer to global variable causes runtime load" {
77 global = 1234;
8 assertOrPanic(&global == ptr);
9 assertOrPanic(ptr.* == 1234);
8 expect(&global == ptr);
9 expect(ptr.* == 1234);
1010}
1111
test/stage1/behavior/bugs/394.zig+2-2
......@@ -7,12 +7,12 @@ const S = struct {
77 y: E,
88};
99
10const assertOrPanic = @import("std").debug.assertOrPanic;
10const expect = @import("std").testing.expect;
1111
1212test "bug 394 fixed" {
1313 const x = S{
1414 .x = 3,
1515 .y = E{ .B = 1 },
1616 };
17 assertOrPanic(x.x == 3);
17 expect(x.x == 3);
1818}
test/stage1/behavior/bugs/655.zig+2-2
......@@ -3,10 +3,10 @@ const other_file = @import("655_other_file.zig");
33
44test "function with *const parameter with type dereferenced by namespace" {
55 const x: other_file.Integer = 1234;
6 comptime std.debug.assertOrPanic(@typeOf(&x) == *const other_file.Integer);
6 comptime std.testing.expect(@typeOf(&x) == *const other_file.Integer);
77 foo(&x);
88}
99
1010fn foo(x: *const other_file.Integer) void {
11 std.debug.assertOrPanic(x.* == 1234);
11 std.testing.expect(x.* == 1234);
1212}
test/stage1/behavior/bugs/656.zig+2-2
......@@ -1,4 +1,4 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;
1const expect = @import("std").testing.expect;
22
33const PrefixOp = union(enum) {
44 Return,
......@@ -22,7 +22,7 @@ fn foo(a: bool, b: bool) void {
2222 PrefixOp.AddrOf => |addr_of_info| {
2323 if (b) {}
2424 if (addr_of_info.align_expr) |align_expr| {
25 assertOrPanic(align_expr == 1234);
25 expect(align_expr == 1234);
2626 }
2727 },
2828 PrefixOp.Return => {},
test/stage1/behavior/bugs/726.zig+3-3
......@@ -1,9 +1,9 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;
1const expect = @import("std").testing.expect;
22
33test "@ptrCast from const to nullable" {
44 const c: u8 = 4;
55 var x: ?*const u8 = @ptrCast(?*const u8, &c);
6 assertOrPanic(x.?.* == 4);
6 expect(x.?.* == 4);
77}
88
99test "@ptrCast from var in empty struct to nullable" {
......@@ -11,6 +11,6 @@ test "@ptrCast from var in empty struct to nullable" {
1111 var c: u8 = 4;
1212 };
1313 var x: ?*const u8 = @ptrCast(?*const u8, &container.c);
14 assertOrPanic(x.?.* == 4);
14 expect(x.?.* == 4);
1515}
1616
test/stage1/behavior/bugs/920.zig+1-1
......@@ -60,6 +60,6 @@ test "bug 920 fixed" {
6060 };
6161
6262 for (NormalDist1.f) |_, i| {
63 std.debug.assertOrPanic(NormalDist1.f[i] == NormalDist.f[i]);
63 std.testing.expect(NormalDist1.f[i] == NormalDist.f[i]);
6464 }
6565}
test/stage1/behavior/byval_arg_var.zig+1-1
......@@ -6,7 +6,7 @@ test "pass string literal byvalue to a generic var param" {
66 start();
77 blowUpStack(10);
88
9 std.debug.assertOrPanic(std.mem.eql(u8, result, "string literal"));
9 std.testing.expect(std.mem.eql(u8, result, "string literal"));
1010}
1111
1212fn start() void {
test/stage1/behavior/cancel.zig+7-7
......@@ -10,9 +10,9 @@ test "cancel forwards" {
1010
1111 const p = async<&da.allocator> f1() catch unreachable;
1212 cancel p;
13 std.debug.assertOrPanic(defer_f1);
14 std.debug.assertOrPanic(defer_f2);
15 std.debug.assertOrPanic(defer_f3);
13 std.testing.expect(defer_f1);
14 std.testing.expect(defer_f2);
15 std.testing.expect(defer_f3);
1616}
1717
1818async fn f1() void {
......@@ -47,10 +47,10 @@ test "cancel backwards" {
4747
4848 const p = async<&da.allocator> b1() catch unreachable;
4949 cancel p;
50 std.debug.assertOrPanic(defer_b1);
51 std.debug.assertOrPanic(defer_b2);
52 std.debug.assertOrPanic(defer_b3);
53 std.debug.assertOrPanic(defer_b4);
50 std.testing.expect(defer_b1);
51 std.testing.expect(defer_b2);
52 std.testing.expect(defer_b3);
53 std.testing.expect(defer_b4);
5454}
5555
5656async fn b1() void {
test/stage1/behavior/cast.zig+79-79
......@@ -1,5 +1,5 @@
11const std = @import("std");
2const assertOrPanic = std.debug.assertOrPanic;
2const expect = std.testing.expect;
33const mem = std.mem;
44const maxInt = std.math.maxInt;
55
......@@ -7,12 +7,12 @@ test "int to ptr cast" {
77 const x = usize(13);
88 const y = @intToPtr(*u8, x);
99 const z = @ptrToInt(y);
10 assertOrPanic(z == 13);
10 expect(z == 13);
1111}
1212
1313test "integer literal to pointer cast" {
1414 const vga_mem = @intToPtr(*u16, 0xB8000);
15 assertOrPanic(@ptrToInt(vga_mem) == 0xB8000);
15 expect(@ptrToInt(vga_mem) == 0xB8000);
1616}
1717
1818test "pointer reinterpret const float to int" {
......@@ -20,7 +20,7 @@ test "pointer reinterpret const float to int" {
2020 const float_ptr = &float;
2121 const int_ptr = @ptrCast(*const i32, float_ptr);
2222 const int_val = int_ptr.*;
23 assertOrPanic(int_val == 858993411);
23 expect(int_val == 858993411);
2424}
2525
2626test "implicitly cast indirect pointer to maybe-indirect pointer" {
......@@ -44,10 +44,10 @@ test "implicitly cast indirect pointer to maybe-indirect pointer" {
4444 const p = &s;
4545 const q = &p;
4646 const r = &q;
47 assertOrPanic(42 == S.constConst(q));
48 assertOrPanic(42 == S.maybeConstConst(q));
49 assertOrPanic(42 == S.constConstConst(r));
50 assertOrPanic(42 == S.maybeConstConstConst(r));
47 expect(42 == S.constConst(q));
48 expect(42 == S.maybeConstConst(q));
49 expect(42 == S.constConstConst(r));
50 expect(42 == S.maybeConstConstConst(r));
5151}
5252
5353test "explicit cast from integer to error type" {
......@@ -57,14 +57,14 @@ test "explicit cast from integer to error type" {
5757fn testCastIntToErr(err: anyerror) void {
5858 const x = @errorToInt(err);
5959 const y = @intToError(x);
60 assertOrPanic(error.ItBroke == y);
60 expect(error.ItBroke == y);
6161}
6262
6363test "peer resolve arrays of different size to const slice" {
64 assertOrPanic(mem.eql(u8, boolToStr(true), "true"));
65 assertOrPanic(mem.eql(u8, boolToStr(false), "false"));
66 comptime assertOrPanic(mem.eql(u8, boolToStr(true), "true"));
67 comptime assertOrPanic(mem.eql(u8, boolToStr(false), "false"));
64 expect(mem.eql(u8, boolToStr(true), "true"));
65 expect(mem.eql(u8, boolToStr(false), "false"));
66 comptime expect(mem.eql(u8, boolToStr(true), "true"));
67 comptime expect(mem.eql(u8, boolToStr(false), "false"));
6868}
6969fn boolToStr(b: bool) []const u8 {
7070 return if (b) "true" else "false";
......@@ -77,8 +77,8 @@ test "peer resolve array and const slice" {
7777fn testPeerResolveArrayConstSlice(b: bool) void {
7878 const value1 = if (b) "aoeu" else ([]const u8)("zz");
7979 const value2 = if (b) ([]const u8)("zz") else "aoeu";
80 assertOrPanic(mem.eql(u8, value1, "aoeu"));
81 assertOrPanic(mem.eql(u8, value2, "zz"));
80 expect(mem.eql(u8, value1, "aoeu"));
81 expect(mem.eql(u8, value2, "zz"));
8282}
8383
8484test "implicitly cast from T to anyerror!?T" {
......@@ -92,14 +92,14 @@ const A = struct {
9292fn castToOptionalTypeError(z: i32) void {
9393 const x = i32(1);
9494 const y: anyerror!?i32 = x;
95 assertOrPanic((try y).? == 1);
95 expect((try y).? == 1);
9696
9797 const f = z;
9898 const g: anyerror!?i32 = f;
9999
100100 const a = A{ .a = z };
101101 const b: anyerror!?A = a;
102 assertOrPanic((b catch unreachable).?.a == 1);
102 expect((b catch unreachable).?.a == 1);
103103}
104104
105105test "implicitly cast from int to anyerror!?T" {
......@@ -114,7 +114,7 @@ fn implicitIntLitToOptional() void {
114114test "return null from fn() anyerror!?&T" {
115115 const a = returnNullFromOptionalTypeErrorRef();
116116 const b = returnNullLitFromOptionalTypeErrorRef();
117 assertOrPanic((try a) == null and (try b) == null);
117 expect((try a) == null and (try b) == null);
118118}
119119fn returnNullFromOptionalTypeErrorRef() anyerror!?*A {
120120 const a: ?*A = null;
......@@ -125,11 +125,11 @@ fn returnNullLitFromOptionalTypeErrorRef() anyerror!?*A {
125125}
126126
127127test "peer type resolution: ?T and T" {
128 assertOrPanic(peerTypeTAndOptionalT(true, false).? == 0);
129 assertOrPanic(peerTypeTAndOptionalT(false, false).? == 3);
128 expect(peerTypeTAndOptionalT(true, false).? == 0);
129 expect(peerTypeTAndOptionalT(false, false).? == 3);
130130 comptime {
131 assertOrPanic(peerTypeTAndOptionalT(true, false).? == 0);
132 assertOrPanic(peerTypeTAndOptionalT(false, false).? == 3);
131 expect(peerTypeTAndOptionalT(true, false).? == 0);
132 expect(peerTypeTAndOptionalT(false, false).? == 3);
133133 }
134134}
135135fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize {
......@@ -141,11 +141,11 @@ fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize {
141141}
142142
143143test "peer type resolution: [0]u8 and []const u8" {
144 assertOrPanic(peerTypeEmptyArrayAndSlice(true, "hi").len == 0);
145 assertOrPanic(peerTypeEmptyArrayAndSlice(false, "hi").len == 1);
144 expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0);
145 expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1);
146146 comptime {
147 assertOrPanic(peerTypeEmptyArrayAndSlice(true, "hi").len == 0);
148 assertOrPanic(peerTypeEmptyArrayAndSlice(false, "hi").len == 1);
147 expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0);
148 expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1);
149149 }
150150}
151151fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 {
......@@ -157,8 +157,8 @@ fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 {
157157}
158158
159159test "implicitly cast from [N]T to ?[]const T" {
160 assertOrPanic(mem.eql(u8, castToOptionalSlice().?, "hi"));
161 comptime assertOrPanic(mem.eql(u8, castToOptionalSlice().?, "hi"));
160 expect(mem.eql(u8, castToOptionalSlice().?, "hi"));
161 comptime expect(mem.eql(u8, castToOptionalSlice().?, "hi"));
162162}
163163
164164fn castToOptionalSlice() ?[]const u8 {
......@@ -171,7 +171,7 @@ test "implicitly cast from [0]T to anyerror![]T" {
171171}
172172
173173fn testCastZeroArrayToErrSliceMut() void {
174 assertOrPanic((gimmeErrOrSlice() catch unreachable).len == 0);
174 expect((gimmeErrOrSlice() catch unreachable).len == 0);
175175}
176176
177177fn gimmeErrOrSlice() anyerror![]u8 {
......@@ -182,14 +182,14 @@ test "peer type resolution: [0]u8, []const u8, and anyerror![]u8" {
182182 {
183183 var data = "hi";
184184 const slice = data[0..];
185 assertOrPanic((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
186 assertOrPanic((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
185 expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
186 expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
187187 }
188188 comptime {
189189 var data = "hi";
190190 const slice = data[0..];
191 assertOrPanic((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
192 assertOrPanic((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
191 expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
192 expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
193193 }
194194}
195195fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 {
......@@ -207,7 +207,7 @@ test "resolve undefined with integer" {
207207fn testResolveUndefWithInt(b: bool, x: i32) void {
208208 const value = if (b) x else undefined;
209209 if (b) {
210 assertOrPanic(value == x);
210 expect(value == x);
211211 }
212212}
213213
......@@ -219,17 +219,17 @@ test "implicit cast from &const [N]T to []const T" {
219219fn testCastConstArrayRefToConstSlice() void {
220220 const blah = "aoeu";
221221 const const_array_ref = &blah;
222 assertOrPanic(@typeOf(const_array_ref) == *const [4]u8);
222 expect(@typeOf(const_array_ref) == *const [4]u8);
223223 const slice: []const u8 = const_array_ref;
224 assertOrPanic(mem.eql(u8, slice, "aoeu"));
224 expect(mem.eql(u8, slice, "aoeu"));
225225}
226226
227227test "peer type resolution: error and [N]T" {
228228 // TODO: implicit error!T to error!U where T can implicitly cast to U
229 //assertOrPanic(mem.eql(u8, try testPeerErrorAndArray(0), "OK"));
230 //comptime assertOrPanic(mem.eql(u8, try testPeerErrorAndArray(0), "OK"));
231 assertOrPanic(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK"));
232 comptime assertOrPanic(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK"));
229 //expect(mem.eql(u8, try testPeerErrorAndArray(0), "OK"));
230 //comptime expect(mem.eql(u8, try testPeerErrorAndArray(0), "OK"));
231 expect(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK"));
232 comptime expect(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK"));
233233}
234234
235235//fn testPeerErrorAndArray(x: u8) error![]const u8 {
......@@ -253,9 +253,9 @@ test "@floatToInt" {
253253
254254fn testFloatToInts() void {
255255 const x = i32(1e4);
256 assertOrPanic(x == 10000);
256 expect(x == 10000);
257257 const y = @floatToInt(i32, f32(1e4));
258 assertOrPanic(y == 10000);
258 expect(y == 10000);
259259 expectFloatToInt(f16, 255.1, u8, 255);
260260 expectFloatToInt(f16, 127.2, i8, 127);
261261 expectFloatToInt(f16, -128.2, i8, -128);
......@@ -266,7 +266,7 @@ fn testFloatToInts() void {
266266}
267267
268268fn expectFloatToInt(comptime F: type, f: F, comptime I: type, i: I) void {
269 assertOrPanic(@floatToInt(I, f) == i);
269 expect(@floatToInt(I, f) == i);
270270}
271271
272272test "cast u128 to f128 and back" {
......@@ -275,7 +275,7 @@ test "cast u128 to f128 and back" {
275275}
276276
277277fn testCast128() void {
278 assertOrPanic(cast128Int(cast128Float(0x7fff0000000000000000000000000000)) == 0x7fff0000000000000000000000000000);
278 expect(cast128Int(cast128Float(0x7fff0000000000000000000000000000)) == 0x7fff0000000000000000000000000000);
279279}
280280
281281fn cast128Int(x: f128) u128 {
......@@ -295,9 +295,9 @@ test "const slice widen cast" {
295295 };
296296
297297 const u32_value = @bytesToSlice(u32, bytes[0..])[0];
298 assertOrPanic(u32_value == 0x12121212);
298 expect(u32_value == 0x12121212);
299299
300 assertOrPanic(@bitCast(u32, bytes) == 0x12121212);
300 expect(@bitCast(u32, bytes) == 0x12121212);
301301}
302302
303303test "single-item pointer of array to slice and to unknown length pointer" {
......@@ -309,76 +309,76 @@ fn testCastPtrOfArrayToSliceAndPtr() void {
309309 var array = "aoeu";
310310 const x: [*]u8 = &array;
311311 x[0] += 1;
312 assertOrPanic(mem.eql(u8, array[0..], "boeu"));
312 expect(mem.eql(u8, array[0..], "boeu"));
313313 const y: []u8 = &array;
314314 y[0] += 1;
315 assertOrPanic(mem.eql(u8, array[0..], "coeu"));
315 expect(mem.eql(u8, array[0..], "coeu"));
316316}
317317
318318test "cast *[1][*]const u8 to [*]const ?[*]const u8" {
319319 const window_name = [1][*]const u8{c"window name"};
320320 const x: [*]const ?[*]const u8 = &window_name;
321 assertOrPanic(mem.eql(u8, std.cstr.toSliceConst(x[0].?), "window name"));
321 expect(mem.eql(u8, std.cstr.toSliceConst(x[0].?), "window name"));
322322}
323323
324324test "@intCast comptime_int" {
325325 const result = @intCast(i32, 1234);
326 assertOrPanic(@typeOf(result) == i32);
327 assertOrPanic(result == 1234);
326 expect(@typeOf(result) == i32);
327 expect(result == 1234);
328328}
329329
330330test "@floatCast comptime_int and comptime_float" {
331331 {
332332 const result = @floatCast(f16, 1234);
333 assertOrPanic(@typeOf(result) == f16);
334 assertOrPanic(result == 1234.0);
333 expect(@typeOf(result) == f16);
334 expect(result == 1234.0);
335335 }
336336 {
337337 const result = @floatCast(f16, 1234.0);
338 assertOrPanic(@typeOf(result) == f16);
339 assertOrPanic(result == 1234.0);
338 expect(@typeOf(result) == f16);
339 expect(result == 1234.0);
340340 }
341341 {
342342 const result = @floatCast(f32, 1234);
343 assertOrPanic(@typeOf(result) == f32);
344 assertOrPanic(result == 1234.0);
343 expect(@typeOf(result) == f32);
344 expect(result == 1234.0);
345345 }
346346 {
347347 const result = @floatCast(f32, 1234.0);
348 assertOrPanic(@typeOf(result) == f32);
349 assertOrPanic(result == 1234.0);
348 expect(@typeOf(result) == f32);
349 expect(result == 1234.0);
350350 }
351351}
352352
353353test "comptime_int @intToFloat" {
354354 {
355355 const result = @intToFloat(f16, 1234);
356 assertOrPanic(@typeOf(result) == f16);
357 assertOrPanic(result == 1234.0);
356 expect(@typeOf(result) == f16);
357 expect(result == 1234.0);
358358 }
359359 {
360360 const result = @intToFloat(f32, 1234);
361 assertOrPanic(@typeOf(result) == f32);
362 assertOrPanic(result == 1234.0);
361 expect(@typeOf(result) == f32);
362 expect(result == 1234.0);
363363 }
364364}
365365
366366test "@bytesToSlice keeps pointer alignment" {
367367 var bytes = []u8{ 0x01, 0x02, 0x03, 0x04 };
368368 const numbers = @bytesToSlice(u32, bytes[0..]);
369 comptime assertOrPanic(@typeOf(numbers) == []align(@alignOf(@typeOf(bytes))) u32);
369 comptime expect(@typeOf(numbers) == []align(@alignOf(@typeOf(bytes))) u32);
370370}
371371
372372test "@intCast i32 to u7" {
373373 var x: u128 = maxInt(u128);
374374 var y: i32 = 120;
375375 var z = x >> @intCast(u7, y);
376 assertOrPanic(z == 0xff);
376 expect(z == 0xff);
377377}
378378
379379test "implicit cast undefined to optional" {
380 assertOrPanic(MakeType(void).getNull() == null);
381 assertOrPanic(MakeType(void).getNonNull() != null);
380 expect(MakeType(void).getNull() == null);
381 expect(MakeType(void).getNonNull() != null);
382382}
383383
384384fn MakeType(comptime T: type) type {
......@@ -398,16 +398,16 @@ test "implicit cast from *[N]T to ?[*]T" {
398398 var y: [4]u16 = [4]u16{ 0, 1, 2, 3 };
399399
400400 x = &y;
401 assertOrPanic(std.mem.eql(u16, x.?[0..4], y[0..4]));
401 expect(std.mem.eql(u16, x.?[0..4], y[0..4]));
402402 x.?[0] = 8;
403403 y[3] = 6;
404 assertOrPanic(std.mem.eql(u16, x.?[0..4], y[0..4]));
404 expect(std.mem.eql(u16, x.?[0..4], y[0..4]));
405405}
406406
407407test "implicit cast from *T to ?*c_void" {
408408 var a: u8 = 1;
409409 incrementVoidPtrValue(&a);
410 std.debug.assertOrPanic(a == 2);
410 std.testing.expect(a == 2);
411411}
412412
413413fn incrementVoidPtrValue(value: ?*c_void) void {
......@@ -417,7 +417,7 @@ fn incrementVoidPtrValue(value: ?*c_void) void {
417417test "implicit cast from [*]T to ?*c_void" {
418418 var a = []u8{ 3, 2, 1 };
419419 incrementVoidPtrArray(a[0..].ptr, 3);
420 assertOrPanic(std.mem.eql(u8, a, []u8{ 4, 3, 2 }));
420 expect(std.mem.eql(u8, a, []u8{ 4, 3, 2 }));
421421}
422422
423423fn incrementVoidPtrArray(array: ?*c_void, len: usize) void {
......@@ -441,27 +441,27 @@ pub const FUNCTION_CONSTANT = @intToPtr(PFN_void, maxInt(usize));
441441pub const PFN_void = extern fn (*c_void) void;
442442
443443fn foobar(func: PFN_void) void {
444 std.debug.assertOrPanic(@ptrToInt(func) == maxInt(usize));
444 std.testing.expect(@ptrToInt(func) == maxInt(usize));
445445}
446446
447447test "implicit ptr to *c_void" {
448448 var a: u32 = 1;
449449 var ptr: *c_void = &a;
450450 var b: *u32 = @ptrCast(*u32, ptr);
451 assertOrPanic(b.* == 1);
451 expect(b.* == 1);
452452 var ptr2: ?*c_void = &a;
453453 var c: *u32 = @ptrCast(*u32, ptr2.?);
454 assertOrPanic(c.* == 1);
454 expect(c.* == 1);
455455}
456456
457457test "@intCast to comptime_int" {
458 assertOrPanic(@intCast(comptime_int, 0) == 0);
458 expect(@intCast(comptime_int, 0) == 0);
459459}
460460
461461test "implicit cast comptime numbers to any type when the value fits" {
462462 const a: u64 = 255;
463463 var b: u8 = a;
464 assertOrPanic(b == 255);
464 expect(b == 255);
465465}
466466
467467test "@intToEnum passed a comptime_int to an enum with one item" {
......@@ -469,14 +469,14 @@ test "@intToEnum passed a comptime_int to an enum with one item" {
469469 A,
470470 };
471471 const x = @intToEnum(E, 0);
472 assertOrPanic(x == E.A);
472 expect(x == E.A);
473473}
474474
475475test "@intCast to u0 and use the result" {
476476 const S = struct {
477477 fn doTheTest(zero: u1, one: u1, bigzero: i32) void {
478 assertOrPanic((one << @intCast(u0, bigzero)) == 1);
479 assertOrPanic((zero << @intCast(u0, bigzero)) == 0);
478 expect((one << @intCast(u0, bigzero)) == 1);
479 expect((zero << @intCast(u0, bigzero)) == 0);
480480 }
481481 };
482482 S.doTheTest(0, 1, 0);
test/stage1/behavior/const_slice_child.zig+7-6
......@@ -1,5 +1,6 @@
1const debug = @import("std").debug;
2const assertOrPanic = debug.assertOrPanic;
1const std = @import("std");
2const debug = std.debug;
3const expect = std.testing.expect;
34
45var argv: [*]const [*]const u8 = undefined;
56
......@@ -15,10 +16,10 @@ test "const slice child" {
1516}
1617
1718fn foo(args: [][]const u8) void {
18 assertOrPanic(args.len == 3);
19 assertOrPanic(streql(args[0], "one"));
20 assertOrPanic(streql(args[1], "two"));
21 assertOrPanic(streql(args[2], "three"));
19 expect(args.len == 3);
20 expect(streql(args[0], "one"));
21 expect(streql(args[1], "two"));
22 expect(streql(args[2], "three"));
2223}
2324
2425fn bar(argc: usize) void {
test/stage1/behavior/coroutine_await_struct.zig+3-3
......@@ -1,6 +1,6 @@
11const std = @import("std");
22const builtin = @import("builtin");
3const assertOrPanic = std.debug.assertOrPanic;
3const expect = std.testing.expect;
44
55const Foo = struct {
66 x: i32,
......@@ -18,8 +18,8 @@ test "coroutine await struct" {
1818 await_seq('f');
1919 resume await_a_promise;
2020 await_seq('i');
21 assertOrPanic(await_final_result.x == 1234);
22 assertOrPanic(std.mem.eql(u8, await_points, "abcdefghi"));
21 expect(await_final_result.x == 1234);
22 expect(std.mem.eql(u8, await_points, "abcdefghi"));
2323}
2424async fn await_amain() void {
2525 await_seq('b');
test/stage1/behavior/coroutines.zig+18-18
......@@ -1,6 +1,6 @@
11const std = @import("std");
22const builtin = @import("builtin");
3const assertOrPanic = std.debug.assertOrPanic;
3const expect = std.testing.expect;
44
55var x: i32 = 1;
66
......@@ -9,9 +9,9 @@ test "create a coroutine and cancel it" {
99 defer da.deinit();
1010
1111 const p = try async<&da.allocator> simpleAsyncFn();
12 comptime assertOrPanic(@typeOf(p) == promise->void);
12 comptime expect(@typeOf(p) == promise->void);
1313 cancel p;
14 assertOrPanic(x == 2);
14 expect(x == 2);
1515}
1616async fn simpleAsyncFn() void {
1717 x += 1;
......@@ -31,7 +31,7 @@ test "coroutine suspend, resume, cancel" {
3131 cancel p;
3232 seq('g');
3333
34 assertOrPanic(std.mem.eql(u8, points, "abcdefg"));
34 expect(std.mem.eql(u8, points, "abcdefg"));
3535}
3636async fn testAsyncSeq() void {
3737 defer seq('e');
......@@ -53,9 +53,9 @@ test "coroutine suspend with block" {
5353 defer da.deinit();
5454
5555 const p = try async<&da.allocator> testSuspendBlock();
56 std.debug.assertOrPanic(!result);
56 std.testing.expect(!result);
5757 resume a_promise;
58 std.debug.assertOrPanic(result);
58 std.testing.expect(result);
5959 cancel p;
6060}
6161
......@@ -63,13 +63,13 @@ var a_promise: promise = undefined;
6363var result = false;
6464async fn testSuspendBlock() void {
6565 suspend {
66 comptime assertOrPanic(@typeOf(@handle()) == promise->void);
66 comptime expect(@typeOf(@handle()) == promise->void);
6767 a_promise = @handle();
6868 }
6969
7070 //Test to make sure that @handle() works as advertised (issue #1296)
7171 //var our_handle: promise = @handle();
72 assertOrPanic(a_promise == @handle());
72 expect(a_promise == @handle());
7373
7474 result = true;
7575}
......@@ -86,8 +86,8 @@ test "coroutine await" {
8686 await_seq('f');
8787 resume await_a_promise;
8888 await_seq('i');
89 assertOrPanic(await_final_result == 1234);
90 assertOrPanic(std.mem.eql(u8, await_points, "abcdefghi"));
89 expect(await_final_result == 1234);
90 expect(std.mem.eql(u8, await_points, "abcdefghi"));
9191}
9292async fn await_amain() void {
9393 await_seq('b');
......@@ -123,8 +123,8 @@ test "coroutine await early return" {
123123 early_seq('a');
124124 const p = async<&da.allocator> early_amain() catch @panic("out of memory");
125125 early_seq('f');
126 assertOrPanic(early_final_result == 1234);
127 assertOrPanic(std.mem.eql(u8, early_points, "abcdef"));
126 expect(early_final_result == 1234);
127 expect(std.mem.eql(u8, early_points, "abcdef"));
128128}
129129async fn early_amain() void {
130130 early_seq('b');
......@@ -170,7 +170,7 @@ test "async function with dot syntax" {
170170 defer da.deinit();
171171 const p = try async<&da.allocator> S.foo();
172172 cancel p;
173 assertOrPanic(S.y == 2);
173 expect(S.y == 2);
174174}
175175
176176test "async fn pointer in a struct field" {
......@@ -182,9 +182,9 @@ test "async fn pointer in a struct field" {
182182 var da = std.heap.DirectAllocator.init();
183183 defer da.deinit();
184184 const p = (async<&da.allocator> foo.bar(&data)) catch unreachable;
185 assertOrPanic(data == 2);
185 expect(data == 2);
186186 cancel p;
187 assertOrPanic(data == 4);
187 expect(data == 4);
188188}
189189async<*std.mem.Allocator> fn simpleAsyncFn2(y: *i32) void {
190190 defer y.* += 2;
......@@ -230,9 +230,9 @@ async fn suspendThenFail() anyerror!void {
230230}
231231async fn printTrace(p: promise->(anyerror!void)) void {
232232 (await p) catch |e| {
233 std.debug.assertOrPanic(e == error.Fail);
233 std.testing.expect(e == error.Fail);
234234 if (@errorReturnTrace()) |trace| {
235 assertOrPanic(trace.index == 1);
235 expect(trace.index == 1);
236236 } else switch (builtin.mode) {
237237 builtin.Mode.Debug, builtin.Mode.ReleaseSafe => @panic("expected return trace"),
238238 builtin.Mode.ReleaseFast, builtin.Mode.ReleaseSmall => {},
......@@ -246,7 +246,7 @@ test "break from suspend" {
246246 var my_result: i32 = 1;
247247 const p = try async<a> testBreakFromSuspend(&my_result);
248248 cancel p;
249 std.debug.assertOrPanic(my_result == 2);
249 std.testing.expect(my_result == 2);
250250}
251251async fn testBreakFromSuspend(my_result: *i32) void {
252252 suspend {
test/stage1/behavior/defer.zig+12-12
......@@ -1,4 +1,4 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;
1const expect = @import("std").testing.expect;
22
33var result: [3]u8 = undefined;
44var index: usize = undefined;
......@@ -21,18 +21,18 @@ fn runSomeErrorDefers(x: bool) !bool {
2121}
2222
2323test "mixing normal and error defers" {
24 assertOrPanic(runSomeErrorDefers(true) catch unreachable);
25 assertOrPanic(result[0] == 'c');
26 assertOrPanic(result[1] == 'a');
24 expect(runSomeErrorDefers(true) catch unreachable);
25 expect(result[0] == 'c');
26 expect(result[1] == 'a');
2727
2828 const ok = runSomeErrorDefers(false) catch |err| x: {
29 assertOrPanic(err == error.FalseNotAllowed);
29 expect(err == error.FalseNotAllowed);
3030 break :x true;
3131 };
32 assertOrPanic(ok);
33 assertOrPanic(result[0] == 'c');
34 assertOrPanic(result[1] == 'b');
35 assertOrPanic(result[2] == 'a');
32 expect(ok);
33 expect(result[0] == 'c');
34 expect(result[1] == 'b');
35 expect(result[2] == 'a');
3636}
3737
3838test "break and continue inside loop inside defer expression" {
......@@ -47,7 +47,7 @@ fn testBreakContInDefer(x: usize) void {
4747 if (i < 5) continue;
4848 if (i == 5) break;
4949 }
50 assertOrPanic(i == 5);
50 expect(i == 5);
5151 }
5252}
5353
......@@ -59,11 +59,11 @@ test "defer and labeled break" {
5959 break :blk;
6060 }
6161
62 assertOrPanic(i == 1);
62 expect(i == 1);
6363}
6464
6565test "errdefer does not apply to fn inside fn" {
66 if (testNestedFnErrDefer()) |_| @panic("expected error") else |e| assertOrPanic(e == error.Bad);
66 if (testNestedFnErrDefer()) |_| @panic("expected error") else |e| expect(e == error.Bad);
6767}
6868
6969fn testNestedFnErrDefer() anyerror!void {
test/stage1/behavior/enum.zig+37-37
......@@ -1,4 +1,4 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;
1const expect = @import("std").testing.expect;
22const mem = @import("std").mem;
33
44test "enum type" {
......@@ -11,16 +11,16 @@ test "enum type" {
1111 };
1212 const bar = Bar.B;
1313
14 assertOrPanic(bar == Bar.B);
15 assertOrPanic(@memberCount(Foo) == 3);
16 assertOrPanic(@memberCount(Bar) == 4);
17 assertOrPanic(@sizeOf(Foo) == @sizeOf(FooNoVoid));
18 assertOrPanic(@sizeOf(Bar) == 1);
14 expect(bar == Bar.B);
15 expect(@memberCount(Foo) == 3);
16 expect(@memberCount(Bar) == 4);
17 expect(@sizeOf(Foo) == @sizeOf(FooNoVoid));
18 expect(@sizeOf(Bar) == 1);
1919}
2020
2121test "enum as return value" {
2222 switch (returnAnInt(13)) {
23 Foo.One => |value| assertOrPanic(value == 13),
23 Foo.One => |value| expect(value == 13),
2424 else => unreachable,
2525 }
2626}
......@@ -92,14 +92,14 @@ test "enum to int" {
9292}
9393
9494fn shouldEqual(n: Number, expected: u3) void {
95 assertOrPanic(@enumToInt(n) == expected);
95 expect(@enumToInt(n) == expected);
9696}
9797
9898test "int to enum" {
9999 testIntToEnumEval(3);
100100}
101101fn testIntToEnumEval(x: i32) void {
102 assertOrPanic(@intToEnum(IntToEnumNumber, @intCast(u3, x)) == IntToEnumNumber.Three);
102 expect(@intToEnum(IntToEnumNumber, @intCast(u3, x)) == IntToEnumNumber.Three);
103103}
104104const IntToEnumNumber = enum {
105105 Zero,
......@@ -110,8 +110,8 @@ const IntToEnumNumber = enum {
110110};
111111
112112test "@tagName" {
113 assertOrPanic(mem.eql(u8, testEnumTagNameBare(BareNumber.Three), "Three"));
114 comptime assertOrPanic(mem.eql(u8, testEnumTagNameBare(BareNumber.Three), "Three"));
113 expect(mem.eql(u8, testEnumTagNameBare(BareNumber.Three), "Three"));
114 comptime expect(mem.eql(u8, testEnumTagNameBare(BareNumber.Three), "Three"));
115115}
116116
117117fn testEnumTagNameBare(n: BareNumber) []const u8 {
......@@ -126,8 +126,8 @@ const BareNumber = enum {
126126
127127test "enum alignment" {
128128 comptime {
129 assertOrPanic(@alignOf(AlignTestEnum) >= @alignOf([9]u8));
130 assertOrPanic(@alignOf(AlignTestEnum) >= @alignOf(u64));
129 expect(@alignOf(AlignTestEnum) >= @alignOf([9]u8));
130 expect(@alignOf(AlignTestEnum) >= @alignOf(u64));
131131 }
132132}
133133
......@@ -663,10 +663,10 @@ const ValueCount257 = enum {
663663
664664test "enum sizes" {
665665 comptime {
666 assertOrPanic(@sizeOf(ValueCount1) == 0);
667 assertOrPanic(@sizeOf(ValueCount2) == 1);
668 assertOrPanic(@sizeOf(ValueCount256) == 1);
669 assertOrPanic(@sizeOf(ValueCount257) == 2);
666 expect(@sizeOf(ValueCount1) == 0);
667 expect(@sizeOf(ValueCount2) == 1);
668 expect(@sizeOf(ValueCount256) == 1);
669 expect(@sizeOf(ValueCount257) == 2);
670670 }
671671}
672672
......@@ -685,12 +685,12 @@ test "set enum tag type" {
685685 {
686686 var x = Small.One;
687687 x = Small.Two;
688 comptime assertOrPanic(@TagType(Small) == u2);
688 comptime expect(@TagType(Small) == u2);
689689 }
690690 {
691691 var x = Small2.One;
692692 x = Small2.Two;
693 comptime assertOrPanic(@TagType(Small2) == u2);
693 comptime expect(@TagType(Small2) == u2);
694694 }
695695}
696696
......@@ -737,17 +737,17 @@ const bit_field_1 = BitFieldOfEnums{
737737
738738test "bit field access with enum fields" {
739739 var data = bit_field_1;
740 assertOrPanic(getA(&data) == A.Two);
741 assertOrPanic(getB(&data) == B.Three3);
742 assertOrPanic(getC(&data) == C.Four4);
743 comptime assertOrPanic(@sizeOf(BitFieldOfEnums) == 1);
740 expect(getA(&data) == A.Two);
741 expect(getB(&data) == B.Three3);
742 expect(getC(&data) == C.Four4);
743 comptime expect(@sizeOf(BitFieldOfEnums) == 1);
744744
745745 data.b = B.Four3;
746 assertOrPanic(data.b == B.Four3);
746 expect(data.b == B.Four3);
747747
748748 data.a = A.Three;
749 assertOrPanic(data.a == A.Three);
750 assertOrPanic(data.b == B.Four3);
749 expect(data.a == A.Three);
750 expect(data.b == B.Four3);
751751}
752752
753753fn getA(data: *const BitFieldOfEnums) A {
......@@ -768,7 +768,7 @@ test "casting enum to its tag type" {
768768}
769769
770770fn testCastEnumToTagType(value: Small2) void {
771 assertOrPanic(@enumToInt(value) == 1);
771 expect(@enumToInt(value) == 1);
772772}
773773
774774const MultipleChoice = enum(u32) {
......@@ -784,8 +784,8 @@ test "enum with specified tag values" {
784784}
785785
786786fn testEnumWithSpecifiedTagValues(x: MultipleChoice) void {
787 assertOrPanic(@enumToInt(x) == 60);
788 assertOrPanic(1234 == switch (x) {
787 expect(@enumToInt(x) == 60);
788 expect(1234 == switch (x) {
789789 MultipleChoice.A => 1,
790790 MultipleChoice.B => 2,
791791 MultipleChoice.C => u32(1234),
......@@ -811,8 +811,8 @@ test "enum with specified and unspecified tag values" {
811811}
812812
813813fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void {
814 assertOrPanic(@enumToInt(x) == 1000);
815 assertOrPanic(1234 == switch (x) {
814 expect(@enumToInt(x) == 1000);
815 expect(1234 == switch (x) {
816816 MultipleChoice2.A => 1,
817817 MultipleChoice2.B => 2,
818818 MultipleChoice2.C => 3,
......@@ -826,8 +826,8 @@ fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void {
826826}
827827
828828test "cast integer literal to enum" {
829 assertOrPanic(@intToEnum(MultipleChoice2, 0) == MultipleChoice2.Unspecified1);
830 assertOrPanic(@intToEnum(MultipleChoice2, 40) == MultipleChoice2.B);
829 expect(@intToEnum(MultipleChoice2, 0) == MultipleChoice2.Unspecified1);
830 expect(@intToEnum(MultipleChoice2, 40) == MultipleChoice2.B);
831831}
832832
833833const EnumWithOneMember = enum {
......@@ -865,14 +865,14 @@ const EnumWithTagValues = enum(u4) {
865865 D = 1 << 3,
866866};
867867test "enum with tag values don't require parens" {
868 assertOrPanic(@enumToInt(EnumWithTagValues.C) == 0b0100);
868 expect(@enumToInt(EnumWithTagValues.C) == 0b0100);
869869}
870870
871871test "enum with 1 field but explicit tag type should still have the tag type" {
872872 const Enum = enum(u8) {
873873 B = 2,
874874 };
875 comptime @import("std").debug.assertOrPanic(@sizeOf(Enum) == @sizeOf(u8));
875 comptime @import("std").testing.expect(@sizeOf(Enum) == @sizeOf(u8));
876876}
877877
878878test "empty extern enum with members" {
......@@ -881,7 +881,7 @@ test "empty extern enum with members" {
881881 B,
882882 C,
883883 };
884 assertOrPanic(@sizeOf(E) == @sizeOf(c_int));
884 expect(@sizeOf(E) == @sizeOf(c_int));
885885}
886886
887887test "tag name with assigned enum values" {
......@@ -890,5 +890,5 @@ test "tag name with assigned enum values" {
890890 B = 0,
891891 };
892892 var b = LocalFoo.B;
893 assertOrPanic(mem.eql(u8, @tagName(b), "B"));
893 expect(mem.eql(u8, @tagName(b), "B"));
894894}
test/stage1/behavior/enum_with_members.zig+5-5
......@@ -1,4 +1,4 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;
1const expect = @import("std").testing.expect;
22const mem = @import("std").mem;
33const fmt = @import("std").fmt;
44
......@@ -19,9 +19,9 @@ test "enum with members" {
1919 const b = ET{ .UINT = 42 };
2020 var buf: [20]u8 = undefined;
2121
22 assertOrPanic((a.print(buf[0..]) catch unreachable) == 3);
23 assertOrPanic(mem.eql(u8, buf[0..3], "-42"));
22 expect((a.print(buf[0..]) catch unreachable) == 3);
23 expect(mem.eql(u8, buf[0..3], "-42"));
2424
25 assertOrPanic((b.print(buf[0..]) catch unreachable) == 2);
26 assertOrPanic(mem.eql(u8, buf[0..2], "42"));
25 expect((b.print(buf[0..]) catch unreachable) == 2);
26 expect(mem.eql(u8, buf[0..2], "42"));
2727}
test/stage1/behavior/error.zig+31-31
......@@ -1,6 +1,6 @@
11const std = @import("std");
2const assertOrPanic = std.debug.assertOrPanic;
3const assertError = std.debug.assertError;
2const expect = std.testing.expect;
3const expectError = std.testing.expectError;
44const mem = std.mem;
55const builtin = @import("builtin");
66
......@@ -19,7 +19,7 @@ pub fn baz() anyerror!i32 {
1919}
2020
2121test "error wrapping" {
22 assertOrPanic((baz() catch unreachable) == 15);
22 expect((baz() catch unreachable) == 15);
2323}
2424
2525fn gimmeItBroke() []const u8 {
......@@ -27,14 +27,14 @@ fn gimmeItBroke() []const u8 {
2727}
2828
2929test "@errorName" {
30 assertOrPanic(mem.eql(u8, @errorName(error.AnError), "AnError"));
31 assertOrPanic(mem.eql(u8, @errorName(error.ALongerErrorName), "ALongerErrorName"));
30 expect(mem.eql(u8, @errorName(error.AnError), "AnError"));
31 expect(mem.eql(u8, @errorName(error.ALongerErrorName), "ALongerErrorName"));
3232}
3333
3434test "error values" {
3535 const a = @errorToInt(error.err1);
3636 const b = @errorToInt(error.err2);
37 assertOrPanic(a != b);
37 expect(a != b);
3838}
3939
4040test "redefinition of error values allowed" {
......@@ -47,8 +47,8 @@ fn shouldBeNotEqual(a: anyerror, b: anyerror) void {
4747test "error binary operator" {
4848 const a = errBinaryOperatorG(true) catch 3;
4949 const b = errBinaryOperatorG(false) catch 3;
50 assertOrPanic(a == 3);
51 assertOrPanic(b == 10);
50 expect(a == 3);
51 expect(b == 10);
5252}
5353fn errBinaryOperatorG(x: bool) anyerror!isize {
5454 return if (x) error.ItBroke else isize(10);
......@@ -56,7 +56,7 @@ fn errBinaryOperatorG(x: bool) anyerror!isize {
5656
5757test "unwrap simple value from error" {
5858 const i = unwrapSimpleValueFromErrorDo() catch unreachable;
59 assertOrPanic(i == 13);
59 expect(i == 13);
6060}
6161fn unwrapSimpleValueFromErrorDo() anyerror!isize {
6262 return 13;
......@@ -82,10 +82,10 @@ test "error union type " {
8282
8383fn testErrorUnionType() void {
8484 const x: anyerror!i32 = 1234;
85 if (x) |value| assertOrPanic(value == 1234) else |_| unreachable;
86 assertOrPanic(@typeId(@typeOf(x)) == builtin.TypeId.ErrorUnion);
87 assertOrPanic(@typeId(@typeOf(x).ErrorSet) == builtin.TypeId.ErrorSet);
88 assertOrPanic(@typeOf(x).ErrorSet == anyerror);
85 if (x) |value| expect(value == 1234) else |_| unreachable;
86 expect(@typeId(@typeOf(x)) == builtin.TypeId.ErrorUnion);
87 expect(@typeId(@typeOf(x).ErrorSet) == builtin.TypeId.ErrorSet);
88 expect(@typeOf(x).ErrorSet == anyerror);
8989}
9090
9191test "error set type" {
......@@ -99,12 +99,12 @@ const MyErrSet = error{
9999};
100100
101101fn testErrorSetType() void {
102 assertOrPanic(@memberCount(MyErrSet) == 2);
102 expect(@memberCount(MyErrSet) == 2);
103103
104104 const a: MyErrSet!i32 = 5678;
105105 const b: MyErrSet!i32 = MyErrSet.OutOfMemory;
106106
107 if (a) |value| assertOrPanic(value == 5678) else |err| switch (err) {
107 if (a) |value| expect(value == 5678) else |err| switch (err) {
108108 error.OutOfMemory => unreachable,
109109 error.FileNotFound => unreachable,
110110 }
......@@ -127,7 +127,7 @@ const Set2 = error{
127127fn testExplicitErrorSetCast(set1: Set1) void {
128128 var x = @errSetCast(Set2, set1);
129129 var y = @errSetCast(Set1, x);
130 assertOrPanic(y == error.A);
130 expect(y == error.A);
131131}
132132
133133test "comptime test error for empty error set" {
......@@ -138,12 +138,12 @@ test "comptime test error for empty error set" {
138138const EmptyErrorSet = error{};
139139
140140fn testComptimeTestErrorEmptySet(x: EmptyErrorSet!i32) void {
141 if (x) |v| assertOrPanic(v == 1234) else |err| @compileError("bad");
141 if (x) |v| expect(v == 1234) else |err| @compileError("bad");
142142}
143143
144144test "syntax: optional operator in front of error union operator" {
145145 comptime {
146 assertOrPanic(?(anyerror!i32) == ?(anyerror!i32));
146 expect(?(anyerror!i32) == ?(anyerror!i32));
147147 }
148148}
149149
......@@ -173,7 +173,7 @@ fn testErrorUnionPeerTypeResolution(x: i32) void {
173173 if (y) |_| {
174174 @panic("expected error");
175175 } else |e| {
176 assertOrPanic(e == error.A);
176 expect(e == error.A);
177177 }
178178}
179179
......@@ -282,13 +282,13 @@ test "nested error union function call in optional unwrap" {
282282 return null;
283283 }
284284 };
285 assertOrPanic((try S.errorable()) == 1234);
286 assertError(S.errorable2(), error.Failure);
287 assertError(S.errorable3(), error.Other);
285 expect((try S.errorable()) == 1234);
286 expectError(error.Failure, S.errorable2());
287 expectError(error.Other, S.errorable3());
288288 comptime {
289 assertOrPanic((try S.errorable()) == 1234);
290 assertError(S.errorable2(), error.Failure);
291 assertError(S.errorable3(), error.Other);
289 expect((try S.errorable()) == 1234);
290 expectError(error.Failure, S.errorable2());
291 expectError(error.Other, S.errorable3());
292292 }
293293}
294294
......@@ -303,7 +303,7 @@ test "widen cast integer payload of error union function call" {
303303 return 1234;
304304 }
305305 };
306 assertOrPanic((try S.errorable()) == 1234);
306 expect((try S.errorable()) == 1234);
307307}
308308
309309test "return function call to error set from error union function" {
......@@ -316,17 +316,17 @@ test "return function call to error set from error union function" {
316316 return error.Failure;
317317 }
318318 };
319 assertError(S.errorable(), error.Failure);
320 comptime assertError(S.errorable(), error.Failure);
319 expectError(error.Failure, S.errorable());
320 comptime expectError(error.Failure, S.errorable());
321321}
322322
323323test "optional error set is the same size as error set" {
324 comptime assertOrPanic(@sizeOf(?anyerror) == @sizeOf(anyerror));
324 comptime expect(@sizeOf(?anyerror) == @sizeOf(anyerror));
325325 const S = struct {
326326 fn returnsOptErrSet() ?anyerror {
327327 return null;
328328 }
329329 };
330 assertOrPanic(S.returnsOptErrSet() == null);
331 comptime assertOrPanic(S.returnsOptErrSet() == null);
330 expect(S.returnsOptErrSet() == null);
331 comptime expect(S.returnsOptErrSet() == null);
332332}
test/stage1/behavior/eval.zig+116-116
......@@ -1,9 +1,9 @@
11const std = @import("std");
2const assertOrPanic = std.debug.assertOrPanic;
2const expect = std.testing.expect;
33const builtin = @import("builtin");
44
55test "compile time recursion" {
6 assertOrPanic(some_data.len == 21);
6 expect(some_data.len == 21);
77}
88var some_data: [@intCast(usize, fibonacci(7))]u8 = undefined;
99fn fibonacci(x: i32) i32 {
......@@ -16,7 +16,7 @@ fn unwrapAndAddOne(blah: ?i32) i32 {
1616}
1717const should_be_1235 = unwrapAndAddOne(1234);
1818test "static add one" {
19 assertOrPanic(should_be_1235 == 1235);
19 expect(should_be_1235 == 1235);
2020}
2121
2222test "inlined loop" {
......@@ -24,7 +24,7 @@ test "inlined loop" {
2424 comptime var sum = 0;
2525 inline while (i <= 5) : (i += 1)
2626 sum += i;
27 assertOrPanic(sum == 15);
27 expect(sum == 15);
2828}
2929
3030fn gimme1or2(comptime a: bool) i32 {
......@@ -34,12 +34,12 @@ fn gimme1or2(comptime a: bool) i32 {
3434 return z;
3535}
3636test "inline variable gets result of const if" {
37 assertOrPanic(gimme1or2(true) == 1);
38 assertOrPanic(gimme1or2(false) == 2);
37 expect(gimme1or2(true) == 1);
38 expect(gimme1or2(false) == 2);
3939}
4040
4141test "static function evaluation" {
42 assertOrPanic(statically_added_number == 3);
42 expect(statically_added_number == 3);
4343}
4444const statically_added_number = staticAdd(1, 2);
4545fn staticAdd(a: i32, b: i32) i32 {
......@@ -47,8 +47,8 @@ fn staticAdd(a: i32, b: i32) i32 {
4747}
4848
4949test "const expr eval on single expr blocks" {
50 assertOrPanic(constExprEvalOnSingleExprBlocksFn(1, true) == 3);
51 comptime assertOrPanic(constExprEvalOnSingleExprBlocksFn(1, true) == 3);
50 expect(constExprEvalOnSingleExprBlocksFn(1, true) == 3);
51 comptime expect(constExprEvalOnSingleExprBlocksFn(1, true) == 3);
5252}
5353
5454fn constExprEvalOnSingleExprBlocksFn(x: i32, b: bool) i32 {
......@@ -64,10 +64,10 @@ fn constExprEvalOnSingleExprBlocksFn(x: i32, b: bool) i32 {
6464}
6565
6666test "statically initialized list" {
67 assertOrPanic(static_point_list[0].x == 1);
68 assertOrPanic(static_point_list[0].y == 2);
69 assertOrPanic(static_point_list[1].x == 3);
70 assertOrPanic(static_point_list[1].y == 4);
67 expect(static_point_list[0].x == 1);
68 expect(static_point_list[0].y == 2);
69 expect(static_point_list[1].x == 3);
70 expect(static_point_list[1].y == 4);
7171}
7272const Point = struct {
7373 x: i32,
......@@ -85,8 +85,8 @@ fn makePoint(x: i32, y: i32) Point {
8585}
8686
8787test "static eval list init" {
88 assertOrPanic(static_vec3.data[2] == 1.0);
89 assertOrPanic(vec3(0.0, 0.0, 3.0).data[2] == 3.0);
88 expect(static_vec3.data[2] == 1.0);
89 expect(vec3(0.0, 0.0, 3.0).data[2] == 3.0);
9090}
9191const static_vec3 = vec3(0.0, 0.0, 1.0);
9292pub const Vec3 = struct {
......@@ -102,12 +102,12 @@ pub fn vec3(x: f32, y: f32, z: f32) Vec3 {
102102
103103test "constant expressions" {
104104 var array: [array_size]u8 = undefined;
105 assertOrPanic(@sizeOf(@typeOf(array)) == 20);
105 expect(@sizeOf(@typeOf(array)) == 20);
106106}
107107const array_size: u8 = 20;
108108
109109test "constant struct with negation" {
110 assertOrPanic(vertices[0].x == -0.6);
110 expect(vertices[0].x == -0.6);
111111}
112112const Vertex = struct {
113113 x: f32,
......@@ -142,7 +142,7 @@ const vertices = []Vertex{
142142
143143test "statically initialized struct" {
144144 st_init_str_foo.x += 1;
145 assertOrPanic(st_init_str_foo.x == 14);
145 expect(st_init_str_foo.x == 14);
146146}
147147const StInitStrFoo = struct {
148148 x: i32,
......@@ -155,7 +155,7 @@ var st_init_str_foo = StInitStrFoo{
155155
156156test "statically initalized array literal" {
157157 const y: [4]u8 = st_init_arr_lit_x;
158 assertOrPanic(y[3] == 4);
158 expect(y[3] == 4);
159159}
160160const st_init_arr_lit_x = []u8{
161161 1,
......@@ -167,15 +167,15 @@ const st_init_arr_lit_x = []u8{
167167test "const slice" {
168168 comptime {
169169 const a = "1234567890";
170 assertOrPanic(a.len == 10);
170 expect(a.len == 10);
171171 const b = a[1..2];
172 assertOrPanic(b.len == 1);
173 assertOrPanic(b[0] == '2');
172 expect(b.len == 1);
173 expect(b[0] == '2');
174174 }
175175}
176176
177177test "try to trick eval with runtime if" {
178 assertOrPanic(testTryToTrickEvalWithRuntimeIf(true) == 10);
178 expect(testTryToTrickEvalWithRuntimeIf(true) == 10);
179179}
180180
181181fn testTryToTrickEvalWithRuntimeIf(b: bool) usize {
......@@ -201,16 +201,16 @@ fn letsTryToCompareBools(a: bool, b: bool) bool {
201201 return max(bool, a, b);
202202}
203203test "inlined block and runtime block phi" {
204 assertOrPanic(letsTryToCompareBools(true, true));
205 assertOrPanic(letsTryToCompareBools(true, false));
206 assertOrPanic(letsTryToCompareBools(false, true));
207 assertOrPanic(!letsTryToCompareBools(false, false));
204 expect(letsTryToCompareBools(true, true));
205 expect(letsTryToCompareBools(true, false));
206 expect(letsTryToCompareBools(false, true));
207 expect(!letsTryToCompareBools(false, false));
208208
209209 comptime {
210 assertOrPanic(letsTryToCompareBools(true, true));
211 assertOrPanic(letsTryToCompareBools(true, false));
212 assertOrPanic(letsTryToCompareBools(false, true));
213 assertOrPanic(!letsTryToCompareBools(false, false));
210 expect(letsTryToCompareBools(true, true));
211 expect(letsTryToCompareBools(true, false));
212 expect(letsTryToCompareBools(false, true));
213 expect(!letsTryToCompareBools(false, false));
214214 }
215215}
216216
......@@ -255,14 +255,14 @@ fn performFn(comptime prefix_char: u8, start_value: i32) i32 {
255255}
256256
257257test "comptime iterate over fn ptr list" {
258 assertOrPanic(performFn('t', 1) == 6);
259 assertOrPanic(performFn('o', 0) == 1);
260 assertOrPanic(performFn('w', 99) == 99);
258 expect(performFn('t', 1) == 6);
259 expect(performFn('o', 0) == 1);
260 expect(performFn('w', 99) == 99);
261261}
262262
263263test "eval @setRuntimeSafety at compile-time" {
264264 const result = comptime fnWithSetRuntimeSafety();
265 assertOrPanic(result == 1234);
265 expect(result == 1234);
266266}
267267
268268fn fnWithSetRuntimeSafety() i32 {
......@@ -272,7 +272,7 @@ fn fnWithSetRuntimeSafety() i32 {
272272
273273test "eval @setFloatMode at compile-time" {
274274 const result = comptime fnWithFloatMode();
275 assertOrPanic(result == 1234.0);
275 expect(result == 1234.0);
276276}
277277
278278fn fnWithFloatMode() f32 {
......@@ -293,15 +293,15 @@ var simple_struct = SimpleStruct{ .field = 1234 };
293293const bound_fn = simple_struct.method;
294294
295295test "call method on bound fn referring to var instance" {
296 assertOrPanic(bound_fn() == 1237);
296 expect(bound_fn() == 1237);
297297}
298298
299299test "ptr to local array argument at comptime" {
300300 comptime {
301301 var bytes: [10]u8 = undefined;
302302 modifySomeBytes(bytes[0..]);
303 assertOrPanic(bytes[0] == 'a');
304 assertOrPanic(bytes[9] == 'b');
303 expect(bytes[0] == 'a');
304 expect(bytes[9] == 'b');
305305 }
306306}
307307
......@@ -329,9 +329,9 @@ fn testCompTimeUIntComparisons(x: u32) void {
329329}
330330
331331test "const ptr to variable data changes at runtime" {
332 assertOrPanic(foo_ref.name[0] == 'a');
332 expect(foo_ref.name[0] == 'a');
333333 foo_ref.name = "b";
334 assertOrPanic(foo_ref.name[0] == 'b');
334 expect(foo_ref.name[0] == 'b');
335335}
336336
337337const Foo = struct {
......@@ -342,8 +342,8 @@ var foo_contents = Foo{ .name = "a" };
342342const foo_ref = &foo_contents;
343343
344344test "create global array with for loop" {
345 assertOrPanic(global_array[5] == 5 * 5);
346 assertOrPanic(global_array[9] == 9 * 9);
345 expect(global_array[5] == 5 * 5);
346 expect(global_array[9] == 9 * 9);
347347}
348348
349349const global_array = x: {
......@@ -358,7 +358,7 @@ test "compile-time downcast when the bits fit" {
358358 comptime {
359359 const spartan_count: u16 = 255;
360360 const byte = @intCast(u8, spartan_count);
361 assertOrPanic(byte == 255);
361 expect(byte == 255);
362362 }
363363}
364364
......@@ -366,44 +366,44 @@ const hi1 = "hi";
366366const hi2 = hi1;
367367test "const global shares pointer with other same one" {
368368 assertEqualPtrs(&hi1[0], &hi2[0]);
369 comptime assertOrPanic(&hi1[0] == &hi2[0]);
369 comptime expect(&hi1[0] == &hi2[0]);
370370}
371371fn assertEqualPtrs(ptr1: *const u8, ptr2: *const u8) void {
372 assertOrPanic(ptr1 == ptr2);
372 expect(ptr1 == ptr2);
373373}
374374
375375test "@setEvalBranchQuota" {
376376 comptime {
377 // 1001 for the loop and then 1 more for the assertOrPanic fn call
377 // 1001 for the loop and then 1 more for the expect fn call
378378 @setEvalBranchQuota(1002);
379379 var i = 0;
380380 var sum = 0;
381381 while (i < 1001) : (i += 1) {
382382 sum += i;
383383 }
384 assertOrPanic(sum == 500500);
384 expect(sum == 500500);
385385 }
386386}
387387
388388// TODO test "float literal at compile time not lossy" {
389// TODO assertOrPanic(16777216.0 + 1.0 == 16777217.0);
390// TODO assertOrPanic(9007199254740992.0 + 1.0 == 9007199254740993.0);
389// TODO expect(16777216.0 + 1.0 == 16777217.0);
390// TODO expect(9007199254740992.0 + 1.0 == 9007199254740993.0);
391391// TODO }
392392
393393test "f32 at compile time is lossy" {
394 assertOrPanic(f32(1 << 24) + 1 == 1 << 24);
394 expect(f32(1 << 24) + 1 == 1 << 24);
395395}
396396
397397test "f64 at compile time is lossy" {
398 assertOrPanic(f64(1 << 53) + 1 == 1 << 53);
398 expect(f64(1 << 53) + 1 == 1 << 53);
399399}
400400
401401test "f128 at compile time is lossy" {
402 assertOrPanic(f128(10384593717069655257060992658440192.0) + 1 == 10384593717069655257060992658440192.0);
402 expect(f128(10384593717069655257060992658440192.0) + 1 == 10384593717069655257060992658440192.0);
403403}
404404
405405comptime {
406 assertOrPanic(f128(1 << 113) == 10384593717069655257060992658440192);
406 expect(f128(1 << 113) == 10384593717069655257060992658440192);
407407}
408408
409409pub fn TypeWithCompTimeSlice(comptime field_name: []const u8) type {
......@@ -415,15 +415,15 @@ pub fn TypeWithCompTimeSlice(comptime field_name: []const u8) type {
415415test "string literal used as comptime slice is memoized" {
416416 const a = "link";
417417 const b = "link";
418 comptime assertOrPanic(TypeWithCompTimeSlice(a).Node == TypeWithCompTimeSlice(b).Node);
419 comptime assertOrPanic(TypeWithCompTimeSlice("link").Node == TypeWithCompTimeSlice("link").Node);
418 comptime expect(TypeWithCompTimeSlice(a).Node == TypeWithCompTimeSlice(b).Node);
419 comptime expect(TypeWithCompTimeSlice("link").Node == TypeWithCompTimeSlice("link").Node);
420420}
421421
422422test "comptime slice of undefined pointer of length 0" {
423423 const slice1 = ([*]i32)(undefined)[0..0];
424 assertOrPanic(slice1.len == 0);
424 expect(slice1.len == 0);
425425 const slice2 = ([*]i32)(undefined)[100..100];
426 assertOrPanic(slice2.len == 0);
426 expect(slice2.len == 0);
427427}
428428
429429fn copyWithPartialInline(s: []u32, b: []u8) void {
......@@ -445,16 +445,16 @@ test "binary math operator in partially inlined function" {
445445 r.* = @intCast(u8, i + 1);
446446
447447 copyWithPartialInline(s[0..], b[0..]);
448 assertOrPanic(s[0] == 0x1020304);
449 assertOrPanic(s[1] == 0x5060708);
450 assertOrPanic(s[2] == 0x90a0b0c);
451 assertOrPanic(s[3] == 0xd0e0f10);
448 expect(s[0] == 0x1020304);
449 expect(s[1] == 0x5060708);
450 expect(s[2] == 0x90a0b0c);
451 expect(s[3] == 0xd0e0f10);
452452}
453453
454454test "comptime function with the same args is memoized" {
455455 comptime {
456 assertOrPanic(MakeType(i32) == MakeType(i32));
457 assertOrPanic(MakeType(i32) != MakeType(f64));
456 expect(MakeType(i32) == MakeType(i32));
457 expect(MakeType(i32) != MakeType(f64));
458458 }
459459}
460460
......@@ -470,7 +470,7 @@ test "comptime function with mutable pointer is not memoized" {
470470 const ptr = &x;
471471 increment(ptr);
472472 increment(ptr);
473 assertOrPanic(x == 3);
473 expect(x == 3);
474474 }
475475}
476476
......@@ -496,14 +496,14 @@ fn doesAlotT(comptime T: type, value: usize) T {
496496}
497497
498498test "@setEvalBranchQuota at same scope as generic function call" {
499 assertOrPanic(doesAlotT(u32, 2) == 2);
499 expect(doesAlotT(u32, 2) == 2);
500500}
501501
502502test "comptime slice of slice preserves comptime var" {
503503 comptime {
504504 var buff: [10]u8 = undefined;
505505 buff[0..][0..][0] = 1;
506 assertOrPanic(buff[0..][0..][0] == 1);
506 expect(buff[0..][0..][0] == 1);
507507 }
508508}
509509
......@@ -512,7 +512,7 @@ test "comptime slice of pointer preserves comptime var" {
512512 var buff: [10]u8 = undefined;
513513 var a = buff[0..].ptr;
514514 a[0..1][0] = 1;
515 assertOrPanic(buff[0..][0..][0] == 1);
515 expect(buff[0..][0..][0] == 1);
516516 }
517517}
518518
......@@ -526,9 +526,9 @@ const SingleFieldStruct = struct {
526526test "const ptr to comptime mutable data is not memoized" {
527527 comptime {
528528 var foo = SingleFieldStruct{ .x = 1 };
529 assertOrPanic(foo.read_x() == 1);
529 expect(foo.read_x() == 1);
530530 foo.x = 2;
531 assertOrPanic(foo.read_x() == 2);
531 expect(foo.read_x() == 2);
532532 }
533533}
534534
......@@ -537,7 +537,7 @@ test "array concat of slices gives slice" {
537537 var a: []const u8 = "aoeu";
538538 var b: []const u8 = "asdf";
539539 const c = a ++ b;
540 assertOrPanic(std.mem.eql(u8, c, "aoeuasdf"));
540 expect(std.mem.eql(u8, c, "aoeuasdf"));
541541 }
542542}
543543
......@@ -554,14 +554,14 @@ test "comptime shlWithOverflow" {
554554 break :amt amt;
555555 };
556556
557 assertOrPanic(ct_shifted == rt_shifted);
557 expect(ct_shifted == rt_shifted);
558558}
559559
560560test "runtime 128 bit integer division" {
561561 var a: u128 = 152313999999999991610955792383;
562562 var b: u128 = 10000000000000000000;
563563 var c = a / b;
564 assertOrPanic(c == 15231399999);
564 expect(c == 15231399999);
565565}
566566
567567pub const Info = struct {
......@@ -574,20 +574,20 @@ test "comptime modification of const struct field" {
574574 comptime {
575575 var res = diamond_info;
576576 res.version = 1;
577 assertOrPanic(diamond_info.version == 0);
578 assertOrPanic(res.version == 1);
577 expect(diamond_info.version == 0);
578 expect(res.version == 1);
579579 }
580580}
581581
582582test "pointer to type" {
583583 comptime {
584584 var T: type = i32;
585 assertOrPanic(T == i32);
585 expect(T == i32);
586586 var ptr = &T;
587 assertOrPanic(@typeOf(ptr) == *type);
587 expect(@typeOf(ptr) == *type);
588588 ptr.* = f32;
589 assertOrPanic(T == f32);
590 assertOrPanic(*T == *f32);
589 expect(T == f32);
590 expect(*T == *f32);
591591 }
592592}
593593
......@@ -596,17 +596,17 @@ test "slice of type" {
596596 var types_array = []type{ i32, f64, type };
597597 for (types_array) |T, i| {
598598 switch (i) {
599 0 => assertOrPanic(T == i32),
600 1 => assertOrPanic(T == f64),
601 2 => assertOrPanic(T == type),
599 0 => expect(T == i32),
600 1 => expect(T == f64),
601 2 => expect(T == type),
602602 else => unreachable,
603603 }
604604 }
605605 for (types_array[0..]) |T, i| {
606606 switch (i) {
607 0 => assertOrPanic(T == i32),
608 1 => assertOrPanic(T == f64),
609 2 => assertOrPanic(T == type),
607 0 => expect(T == i32),
608 1 => expect(T == f64),
609 2 => expect(T == type),
610610 else => unreachable,
611611 }
612612 }
......@@ -623,7 +623,7 @@ fn wrap(comptime T: type) Wrapper {
623623
624624test "function which returns struct with type field causes implicit comptime" {
625625 const ty = wrap(i32).T;
626 assertOrPanic(ty == i32);
626 expect(ty == i32);
627627}
628628
629629test "call method with comptime pass-by-non-copying-value self parameter" {
......@@ -637,12 +637,12 @@ test "call method with comptime pass-by-non-copying-value self parameter" {
637637
638638 const s = S{ .a = 2 };
639639 var b = s.b();
640 assertOrPanic(b == 2);
640 expect(b == 2);
641641}
642642
643643test "@tagName of @typeId" {
644644 const str = @tagName(@typeId(u8));
645 assertOrPanic(std.mem.eql(u8, str, "Int"));
645 expect(std.mem.eql(u8, str, "Int"));
646646}
647647
648648test "setting backward branch quota just before a generic fn call" {
......@@ -663,8 +663,8 @@ fn testVarInsideInlineLoop(args: ...) void {
663663 comptime var i = 0;
664664 inline while (i < args.len) : (i += 1) {
665665 const x = args[i];
666 if (i == 0) assertOrPanic(x);
667 if (i == 1) assertOrPanic(x == 42);
666 if (i == 0) expect(x);
667 if (i == 1) expect(x == 42);
668668 }
669669}
670670
......@@ -674,7 +674,7 @@ test "inline for with same type but different values" {
674674 var a: T = undefined;
675675 res += a.len;
676676 }
677 assertOrPanic(res == 5);
677 expect(res == 5);
678678}
679679
680680test "refer to the type of a generic function" {
......@@ -688,13 +688,13 @@ fn doNothingWithType(comptime T: type) void {}
688688test "zero extend from u0 to u1" {
689689 var zero_u0: u0 = 0;
690690 var zero_u1: u1 = zero_u0;
691 assertOrPanic(zero_u1 == 0);
691 expect(zero_u1 == 0);
692692}
693693
694694test "bit shift a u1" {
695695 var x: u1 = 1;
696696 var y = x << 0;
697 assertOrPanic(y == 1);
697 expect(y == 1);
698698}
699699
700700test "@bytesToslice on a packed struct" {
......@@ -704,7 +704,7 @@ test "@bytesToslice on a packed struct" {
704704
705705 var b = [1]u8{9};
706706 var f = @bytesToSlice(F, b);
707 assertOrPanic(f[0].a == 9);
707 expect(f[0].a == 9);
708708}
709709
710710test "comptime pointer cast array and then slice" {
......@@ -716,8 +716,8 @@ test "comptime pointer cast array and then slice" {
716716 const ptrB: [*]const u8 = &array;
717717 const sliceB: []const u8 = ptrB[0..2];
718718
719 assertOrPanic(sliceA[1] == 2);
720 assertOrPanic(sliceB[1] == 2);
719 expect(sliceA[1] == 2);
720 expect(sliceB[1] == 2);
721721}
722722
723723test "slice bounds in comptime concatenation" {
......@@ -726,47 +726,47 @@ test "slice bounds in comptime concatenation" {
726726 break :blk b[8..9];
727727 };
728728 const str = "" ++ bs;
729 assertOrPanic(str.len == 1);
730 assertOrPanic(std.mem.eql(u8, str, "1"));
729 expect(str.len == 1);
730 expect(std.mem.eql(u8, str, "1"));
731731
732732 const str2 = bs ++ "";
733 assertOrPanic(str2.len == 1);
734 assertOrPanic(std.mem.eql(u8, str2, "1"));
733 expect(str2.len == 1);
734 expect(std.mem.eql(u8, str2, "1"));
735735}
736736
737737test "comptime bitwise operators" {
738738 comptime {
739 assertOrPanic(3 & 1 == 1);
740 assertOrPanic(3 & -1 == 3);
741 assertOrPanic(-3 & -1 == -3);
742 assertOrPanic(3 | -1 == -1);
743 assertOrPanic(-3 | -1 == -1);
744 assertOrPanic(3 ^ -1 == -4);
745 assertOrPanic(-3 ^ -1 == 2);
746 assertOrPanic(~i8(-1) == 0);
747 assertOrPanic(~i128(-1) == 0);
748 assertOrPanic(18446744073709551615 & 18446744073709551611 == 18446744073709551611);
749 assertOrPanic(-18446744073709551615 & -18446744073709551611 == -18446744073709551615);
750 assertOrPanic(~u128(0) == 0xffffffffffffffffffffffffffffffff);
739 expect(3 & 1 == 1);
740 expect(3 & -1 == 3);
741 expect(-3 & -1 == -3);
742 expect(3 | -1 == -1);
743 expect(-3 | -1 == -1);
744 expect(3 ^ -1 == -4);
745 expect(-3 ^ -1 == 2);
746 expect(~i8(-1) == 0);
747 expect(~i128(-1) == 0);
748 expect(18446744073709551615 & 18446744073709551611 == 18446744073709551611);
749 expect(-18446744073709551615 & -18446744073709551611 == -18446744073709551615);
750 expect(~u128(0) == 0xffffffffffffffffffffffffffffffff);
751751 }
752752}
753753
754754test "*align(1) u16 is the same as *align(1:0:2) u16" {
755755 comptime {
756 assertOrPanic(*align(1:0:2) u16 == *align(1) u16);
756 expect(*align(1:0:2) u16 == *align(1) u16);
757757 // TODO add parsing support for this syntax
758 //assertOrPanic(*align(:0:2) u16 == *u16);
758 //expect(*align(:0:2) u16 == *u16);
759759 }
760760}
761761
762762test "array concatenation forces comptime" {
763763 var a = oneItem(3) ++ oneItem(4);
764 assertOrPanic(std.mem.eql(i32, a, []i32{ 3, 4 }));
764 expect(std.mem.eql(i32, a, []i32{ 3, 4 }));
765765}
766766
767767test "array multiplication forces comptime" {
768768 var a = oneItem(3) ** scalar(2);
769 assertOrPanic(std.mem.eql(i32, a, []i32{ 3, 3 }));
769 expect(std.mem.eql(i32, a, []i32{ 3, 3 }));
770770}
771771
772772fn oneItem(x: i32) [1]i32 {
test/stage1/behavior/field_parent_ptr.zig+7-7
......@@ -1,4 +1,4 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;
1const expect = @import("std").testing.expect;
22
33test "@fieldParentPtr non-first field" {
44 testParentFieldPtr(&foo.c);
......@@ -25,17 +25,17 @@ const foo = Foo{
2525};
2626
2727fn testParentFieldPtr(c: *const i32) void {
28 assertOrPanic(c == &foo.c);
28 expect(c == &foo.c);
2929
3030 const base = @fieldParentPtr(Foo, "c", c);
31 assertOrPanic(base == &foo);
32 assertOrPanic(&base.c == c);
31 expect(base == &foo);
32 expect(&base.c == c);
3333}
3434
3535fn testParentFieldPtrFirst(a: *const bool) void {
36 assertOrPanic(a == &foo.a);
36 expect(a == &foo.a);
3737
3838 const base = @fieldParentPtr(Foo, "a", a);
39 assertOrPanic(base == &foo);
40 assertOrPanic(&base.a == a);
39 expect(base == &foo);
40 expect(&base.a == a);
4141}
test/stage1/behavior/fn.zig+19-19
......@@ -1,7 +1,7 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;
1const expect = @import("std").testing.expect;
22
33test "params" {
4 assertOrPanic(testParamsAdd(22, 11) == 33);
4 expect(testParamsAdd(22, 11) == 33);
55}
66fn testParamsAdd(a: i32, b: i32) i32 {
77 return a + b;
......@@ -21,32 +21,32 @@ test "void parameters" {
2121fn voidFun(a: i32, b: void, c: i32, d: void) void {
2222 const v = b;
2323 const vv: void = if (a == 1) v else {};
24 assertOrPanic(a + c == 3);
24 expect(a + c == 3);
2525 return vv;
2626}
2727
2828test "mutable local variables" {
2929 var zero: i32 = 0;
30 assertOrPanic(zero == 0);
30 expect(zero == 0);
3131
3232 var i = i32(0);
3333 while (i != 3) {
3434 i += 1;
3535 }
36 assertOrPanic(i == 3);
36 expect(i == 3);
3737}
3838
3939test "separate block scopes" {
4040 {
4141 const no_conflict: i32 = 5;
42 assertOrPanic(no_conflict == 5);
42 expect(no_conflict == 5);
4343 }
4444
4545 const c = x: {
4646 const no_conflict = i32(10);
4747 break :x no_conflict;
4848 };
49 assertOrPanic(c == 10);
49 expect(c == 10);
5050}
5151
5252test "call function with empty string" {
......@@ -59,7 +59,7 @@ fn @"weird function name"() i32 {
5959 return 1234;
6060}
6161test "weird function name" {
62 assertOrPanic(@"weird function name"() == 1234);
62 expect(@"weird function name"() == 1234);
6363}
6464
6565test "implicit cast function unreachable return" {
......@@ -80,7 +80,7 @@ test "function pointers" {
8080 fn4,
8181 };
8282 for (fns) |f, i| {
83 assertOrPanic(f() == @intCast(u32, i) + 5);
83 expect(f() == @intCast(u32, i) + 5);
8484 }
8585}
8686fn fn1() u32 {
......@@ -97,7 +97,7 @@ fn fn4() u32 {
9797}
9898
9999test "inline function call" {
100 assertOrPanic(@inlineCall(add, 3, 9) == 12);
100 expect(@inlineCall(add, 3, 9) == 12);
101101}
102102
103103fn add(a: i32, b: i32) i32 {
......@@ -110,7 +110,7 @@ test "number literal as an argument" {
110110}
111111
112112fn numberLiteralArg(a: var) void {
113 assertOrPanic(a == 3);
113 expect(a == 3);
114114}
115115
116116test "assign inline fn to const variable" {
......@@ -121,7 +121,7 @@ test "assign inline fn to const variable" {
121121inline fn inlineFn() void {}
122122
123123test "pass by non-copying value" {
124 assertOrPanic(addPointCoords(Point{ .x = 1, .y = 2 }) == 3);
124 expect(addPointCoords(Point{ .x = 1, .y = 2 }) == 3);
125125}
126126
127127const Point = struct {
......@@ -134,17 +134,17 @@ fn addPointCoords(pt: Point) i32 {
134134}
135135
136136test "pass by non-copying value through var arg" {
137 assertOrPanic(addPointCoordsVar(Point{ .x = 1, .y = 2 }) == 3);
137 expect(addPointCoordsVar(Point{ .x = 1, .y = 2 }) == 3);
138138}
139139
140140fn addPointCoordsVar(pt: var) i32 {
141 comptime assertOrPanic(@typeOf(pt) == Point);
141 comptime expect(@typeOf(pt) == Point);
142142 return pt.x + pt.y;
143143}
144144
145145test "pass by non-copying value as method" {
146146 var pt = Point2{ .x = 1, .y = 2 };
147 assertOrPanic(pt.addPointCoords() == 3);
147 expect(pt.addPointCoords() == 3);
148148}
149149
150150const Point2 = struct {
......@@ -158,7 +158,7 @@ const Point2 = struct {
158158
159159test "pass by non-copying value as method, which is generic" {
160160 var pt = Point3{ .x = 1, .y = 2 };
161 assertOrPanic(pt.addPointCoords(i32) == 3);
161 expect(pt.addPointCoords(i32) == 3);
162162}
163163
164164const Point3 = struct {
......@@ -173,7 +173,7 @@ const Point3 = struct {
173173test "pass by non-copying value as method, at comptime" {
174174 comptime {
175175 var pt = Point2{ .x = 1, .y = 2 };
176 assertOrPanic(pt.addPointCoords() == 3);
176 expect(pt.addPointCoords() == 3);
177177 }
178178}
179179
......@@ -189,7 +189,7 @@ fn outer(y: u32) fn (u32) u32 {
189189
190190test "return inner function which references comptime variable of outer function" {
191191 var func = outer(10);
192 assertOrPanic(func(3) == 7);
192 expect(func(3) == 7);
193193}
194194
195195test "extern struct with stdcallcc fn pointer" {
......@@ -203,6 +203,6 @@ test "extern struct with stdcallcc fn pointer" {
203203
204204 var s: S = undefined;
205205 s.ptr = S.foo;
206 assertOrPanic(s.ptr() == 1234);
206 expect(s.ptr() == 1234);
207207}
208208
test/stage1/behavior/fn_in_struct_in_comptime.zig+2-2
......@@ -1,4 +1,4 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;
1const expect = @import("std").testing.expect;
22
33fn get_foo() fn (*u8) usize {
44 comptime {
......@@ -13,5 +13,5 @@ fn get_foo() fn (*u8) usize {
1313
1414test "define a function in an anonymous struct in comptime" {
1515 const foo = get_foo();
16 assertOrPanic(foo(@intToPtr(*u8, 12345)) == 12345);
16 expect(foo(@intToPtr(*u8, 12345)) == 12345);
1717}
test/stage1/behavior/for.zig+5-5
......@@ -1,5 +1,5 @@
11const std = @import("std");
2const assertOrPanic = std.debug.assertOrPanic;
2const expect = std.testing.expect;
33const mem = std.mem;
44
55test "continue in for loop" {
......@@ -26,7 +26,7 @@ test "for loop with pointer elem var" {
2626 var target: [source.len]u8 = undefined;
2727 mem.copy(u8, target[0..], source);
2828 mangleString(target[0..]);
29 assertOrPanic(mem.eql(u8, target, "bcdefgh"));
29 expect(mem.eql(u8, target, "bcdefgh"));
3030}
3131fn mangleString(s: []u8) void {
3232 for (s) |*c| {
......@@ -68,7 +68,7 @@ test "basic for loop" {
6868 buf_index += 1;
6969 }
7070
71 assertOrPanic(mem.eql(u8, buffer[0..buf_index], expected_result));
71 expect(mem.eql(u8, buffer[0..buf_index], expected_result));
7272}
7373
7474test "break from outer for loop" {
......@@ -85,7 +85,7 @@ fn testBreakOuter() void {
8585 break :outer;
8686 }
8787 }
88 assertOrPanic(count == 1);
88 expect(count == 1);
8989}
9090
9191test "continue outer for loop" {
......@@ -102,5 +102,5 @@ fn testContinueOuter() void {
102102 continue :outer;
103103 }
104104 }
105 assertOrPanic(counter == array.len);
105 expect(counter == array.len);
106106}
test/stage1/behavior/generics.zig+23-23
......@@ -1,9 +1,9 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;
1const expect = @import("std").testing.expect;
22
33test "simple generic fn" {
4 assertOrPanic(max(i32, 3, -1) == 3);
5 assertOrPanic(max(f32, 0.123, 0.456) == 0.456);
6 assertOrPanic(add(2, 3) == 5);
4 expect(max(i32, 3, -1) == 3);
5 expect(max(f32, 0.123, 0.456) == 0.456);
6 expect(add(2, 3) == 5);
77}
88
99fn max(comptime T: type, a: T, b: T) T {
......@@ -16,7 +16,7 @@ fn add(comptime a: i32, b: i32) i32 {
1616
1717const the_max = max(u32, 1234, 5678);
1818test "compile time generic eval" {
19 assertOrPanic(the_max == 5678);
19 expect(the_max == 5678);
2020}
2121
2222fn gimmeTheBigOne(a: u32, b: u32) u32 {
......@@ -32,19 +32,19 @@ fn sameButWithFloats(a: f64, b: f64) f64 {
3232}
3333
3434test "fn with comptime args" {
35 assertOrPanic(gimmeTheBigOne(1234, 5678) == 5678);
36 assertOrPanic(shouldCallSameInstance(34, 12) == 34);
37 assertOrPanic(sameButWithFloats(0.43, 0.49) == 0.49);
35 expect(gimmeTheBigOne(1234, 5678) == 5678);
36 expect(shouldCallSameInstance(34, 12) == 34);
37 expect(sameButWithFloats(0.43, 0.49) == 0.49);
3838}
3939
4040test "var params" {
41 assertOrPanic(max_i32(12, 34) == 34);
42 assertOrPanic(max_f64(1.2, 3.4) == 3.4);
41 expect(max_i32(12, 34) == 34);
42 expect(max_f64(1.2, 3.4) == 3.4);
4343}
4444
4545comptime {
46 assertOrPanic(max_i32(12, 34) == 34);
47 assertOrPanic(max_f64(1.2, 3.4) == 3.4);
46 expect(max_i32(12, 34) == 34);
47 expect(max_f64(1.2, 3.4) == 3.4);
4848}
4949
5050fn max_var(a: var, b: var) @typeOf(a + b) {
......@@ -76,8 +76,8 @@ test "function with return type type" {
7676 var list2: List(i32) = undefined;
7777 list.length = 10;
7878 list2.length = 10;
79 assertOrPanic(list.prealloc_items.len == 8);
80 assertOrPanic(list2.prealloc_items.len == 8);
79 expect(list.prealloc_items.len == 8);
80 expect(list2.prealloc_items.len == 8);
8181}
8282
8383test "generic struct" {
......@@ -89,9 +89,9 @@ test "generic struct" {
8989 .value = true,
9090 .next = null,
9191 };
92 assertOrPanic(a1.value == 13);
93 assertOrPanic(a1.value == a1.getVal());
94 assertOrPanic(b1.getVal());
92 expect(a1.value == 13);
93 expect(a1.value == a1.getVal());
94 expect(b1.getVal());
9595}
9696fn GenNode(comptime T: type) type {
9797 return struct {
......@@ -104,7 +104,7 @@ fn GenNode(comptime T: type) type {
104104}
105105
106106test "const decls in struct" {
107 assertOrPanic(GenericDataThing(3).count_plus_one == 4);
107 expect(GenericDataThing(3).count_plus_one == 4);
108108}
109109fn GenericDataThing(comptime count: isize) type {
110110 return struct {
......@@ -113,15 +113,15 @@ fn GenericDataThing(comptime count: isize) type {
113113}
114114
115115test "use generic param in generic param" {
116 assertOrPanic(aGenericFn(i32, 3, 4) == 7);
116 expect(aGenericFn(i32, 3, 4) == 7);
117117}
118118fn aGenericFn(comptime T: type, comptime a: T, b: T) T {
119119 return a + b;
120120}
121121
122122test "generic fn with implicit cast" {
123 assertOrPanic(getFirstByte(u8, []u8{13}) == 13);
124 assertOrPanic(getFirstByte(u16, []u16{
123 expect(getFirstByte(u8, []u8{13}) == 13);
124 expect(getFirstByte(u16, []u16{
125125 0,
126126 13,
127127 }) == 0);
......@@ -146,6 +146,6 @@ fn foo2(arg: var) bool {
146146}
147147
148148test "array of generic fns" {
149 assertOrPanic(foos[0](true));
150 assertOrPanic(!foos[1](true));
149 expect(foos[0](true));
150 expect(!foos[1](true));
151151}
test/stage1/behavior/if.zig+2-2
......@@ -1,4 +1,4 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;
1const expect = @import("std").testing.expect;
22
33test "if statements" {
44 shouldBeEqual(1, 1);
......@@ -24,7 +24,7 @@ fn firstEqlThird(a: i32, b: i32, c: i32) void {
2424}
2525
2626test "else if expression" {
27 assertOrPanic(elseIfExpressionF(1) == 1);
27 expect(elseIfExpressionF(1) == 1);
2828}
2929fn elseIfExpressionF(c: u8) u8 {
3030 if (c == 0) {
test/stage1/behavior/import.zig+3-3
......@@ -1,10 +1,10 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;
1const expect = @import("std").testing.expect;
22const a_namespace = @import("import/a_namespace.zig");
33
44test "call fn via namespace lookup" {
5 assertOrPanic(a_namespace.foo() == 1234);
5 expect(a_namespace.foo() == 1234);
66}
77
88test "importing the same thing gives the same import" {
9 assertOrPanic(@import("std") == @import("std"));
9 expect(@import("std") == @import("std"));
1010}
test/stage1/behavior/incomplete_struct_param_tld.zig+2-2
......@@ -1,4 +1,4 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;
1const expect = @import("std").testing.expect;
22
33const A = struct {
44 b: B,
......@@ -26,5 +26,5 @@ test "incomplete struct param top level declaration" {
2626 .c = C{ .x = 13 },
2727 },
2828 };
29 assertOrPanic(foo(a) == 13);
29 expect(foo(a) == 13);
3030}
test/stage1/behavior/inttoptr.zig+1-1
......@@ -1,6 +1,6 @@
11const builtin = @import("builtin");
22const std = @import("std");
3const assertOrPanic = std.debug.assertOrPanic;
3const expect = std.testing.expect;
44
55test "casting random address to function pointer" {
66 randomAddressToFunction();
test/stage1/behavior/ir_block_deps.zig+3-3
......@@ -1,4 +1,4 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;
1const expect = @import("std").testing.expect;
22
33fn foo(id: u64) !i32 {
44 return switch (id) {
......@@ -16,6 +16,6 @@ fn getErrInt() anyerror!i32 {
1616}
1717
1818test "ir block deps" {
19 assertOrPanic((foo(1) catch unreachable) == 0);
20 assertOrPanic((foo(2) catch unreachable) == 0);
19 expect((foo(1) catch unreachable) == 0);
20 expect((foo(2) catch unreachable) == 0);
2121}
test/stage1/behavior/math.zig+131-131
......@@ -1,5 +1,5 @@
11const std = @import("std");
2const assertOrPanic = std.debug.assertOrPanic;
2const expect = std.testing.expect;
33const maxInt = std.math.maxInt;
44const minInt = std.math.minInt;
55
......@@ -8,57 +8,57 @@ test "division" {
88 comptime testDivision();
99}
1010fn testDivision() void {
11 assertOrPanic(div(u32, 13, 3) == 4);
12 assertOrPanic(div(f16, 1.0, 2.0) == 0.5);
13 assertOrPanic(div(f32, 1.0, 2.0) == 0.5);
14
15 assertOrPanic(divExact(u32, 55, 11) == 5);
16 assertOrPanic(divExact(i32, -55, 11) == -5);
17 assertOrPanic(divExact(f16, 55.0, 11.0) == 5.0);
18 assertOrPanic(divExact(f16, -55.0, 11.0) == -5.0);
19 assertOrPanic(divExact(f32, 55.0, 11.0) == 5.0);
20 assertOrPanic(divExact(f32, -55.0, 11.0) == -5.0);
21
22 assertOrPanic(divFloor(i32, 5, 3) == 1);
23 assertOrPanic(divFloor(i32, -5, 3) == -2);
24 assertOrPanic(divFloor(f16, 5.0, 3.0) == 1.0);
25 assertOrPanic(divFloor(f16, -5.0, 3.0) == -2.0);
26 assertOrPanic(divFloor(f32, 5.0, 3.0) == 1.0);
27 assertOrPanic(divFloor(f32, -5.0, 3.0) == -2.0);
28 assertOrPanic(divFloor(i32, -0x80000000, -2) == 0x40000000);
29 assertOrPanic(divFloor(i32, 0, -0x80000000) == 0);
30 assertOrPanic(divFloor(i32, -0x40000001, 0x40000000) == -2);
31 assertOrPanic(divFloor(i32, -0x80000000, 1) == -0x80000000);
32
33 assertOrPanic(divTrunc(i32, 5, 3) == 1);
34 assertOrPanic(divTrunc(i32, -5, 3) == -1);
35 assertOrPanic(divTrunc(f16, 5.0, 3.0) == 1.0);
36 assertOrPanic(divTrunc(f16, -5.0, 3.0) == -1.0);
37 assertOrPanic(divTrunc(f32, 5.0, 3.0) == 1.0);
38 assertOrPanic(divTrunc(f32, -5.0, 3.0) == -1.0);
39 assertOrPanic(divTrunc(f64, 5.0, 3.0) == 1.0);
40 assertOrPanic(divTrunc(f64, -5.0, 3.0) == -1.0);
11 expect(div(u32, 13, 3) == 4);
12 expect(div(f16, 1.0, 2.0) == 0.5);
13 expect(div(f32, 1.0, 2.0) == 0.5);
14
15 expect(divExact(u32, 55, 11) == 5);
16 expect(divExact(i32, -55, 11) == -5);
17 expect(divExact(f16, 55.0, 11.0) == 5.0);
18 expect(divExact(f16, -55.0, 11.0) == -5.0);
19 expect(divExact(f32, 55.0, 11.0) == 5.0);
20 expect(divExact(f32, -55.0, 11.0) == -5.0);
21
22 expect(divFloor(i32, 5, 3) == 1);
23 expect(divFloor(i32, -5, 3) == -2);
24 expect(divFloor(f16, 5.0, 3.0) == 1.0);
25 expect(divFloor(f16, -5.0, 3.0) == -2.0);
26 expect(divFloor(f32, 5.0, 3.0) == 1.0);
27 expect(divFloor(f32, -5.0, 3.0) == -2.0);
28 expect(divFloor(i32, -0x80000000, -2) == 0x40000000);
29 expect(divFloor(i32, 0, -0x80000000) == 0);
30 expect(divFloor(i32, -0x40000001, 0x40000000) == -2);
31 expect(divFloor(i32, -0x80000000, 1) == -0x80000000);
32
33 expect(divTrunc(i32, 5, 3) == 1);
34 expect(divTrunc(i32, -5, 3) == -1);
35 expect(divTrunc(f16, 5.0, 3.0) == 1.0);
36 expect(divTrunc(f16, -5.0, 3.0) == -1.0);
37 expect(divTrunc(f32, 5.0, 3.0) == 1.0);
38 expect(divTrunc(f32, -5.0, 3.0) == -1.0);
39 expect(divTrunc(f64, 5.0, 3.0) == 1.0);
40 expect(divTrunc(f64, -5.0, 3.0) == -1.0);
4141
4242 comptime {
43 assertOrPanic(
43 expect(
4444 1194735857077236777412821811143690633098347576 % 508740759824825164163191790951174292733114988 == 177254337427586449086438229241342047632117600,
4545 );
46 assertOrPanic(
46 expect(
4747 @rem(-1194735857077236777412821811143690633098347576, 508740759824825164163191790951174292733114988) == -177254337427586449086438229241342047632117600,
4848 );
49 assertOrPanic(
49 expect(
5050 1194735857077236777412821811143690633098347576 / 508740759824825164163191790951174292733114988 == 2,
5151 );
52 assertOrPanic(
52 expect(
5353 @divTrunc(-1194735857077236777412821811143690633098347576, 508740759824825164163191790951174292733114988) == -2,
5454 );
55 assertOrPanic(
55 expect(
5656 @divTrunc(1194735857077236777412821811143690633098347576, -508740759824825164163191790951174292733114988) == -2,
5757 );
58 assertOrPanic(
58 expect(
5959 @divTrunc(-1194735857077236777412821811143690633098347576, -508740759824825164163191790951174292733114988) == 2,
6060 );
61 assertOrPanic(
61 expect(
6262 4126227191251978491697987544882340798050766755606969681711 % 10 == 1,
6363 );
6464 }
......@@ -78,9 +78,9 @@ fn divTrunc(comptime T: type, a: T, b: T) T {
7878
7979test "@addWithOverflow" {
8080 var result: u8 = undefined;
81 assertOrPanic(@addWithOverflow(u8, 250, 100, &result));
82 assertOrPanic(!@addWithOverflow(u8, 100, 150, &result));
83 assertOrPanic(result == 250);
81 expect(@addWithOverflow(u8, 250, 100, &result));
82 expect(!@addWithOverflow(u8, 100, 150, &result));
83 expect(result == 250);
8484}
8585
8686// TODO test mulWithOverflow
......@@ -88,9 +88,9 @@ test "@addWithOverflow" {
8888
8989test "@shlWithOverflow" {
9090 var result: u16 = undefined;
91 assertOrPanic(@shlWithOverflow(u16, 0b0010111111111111, 3, &result));
92 assertOrPanic(!@shlWithOverflow(u16, 0b0010111111111111, 2, &result));
93 assertOrPanic(result == 0b1011111111111100);
91 expect(@shlWithOverflow(u16, 0b0010111111111111, 3, &result));
92 expect(!@shlWithOverflow(u16, 0b0010111111111111, 2, &result));
93 expect(result == 0b1011111111111100);
9494}
9595
9696test "@clz" {
......@@ -99,11 +99,11 @@ test "@clz" {
9999}
100100
101101fn testClz() void {
102 assertOrPanic(clz(u8(0b00001010)) == 4);
103 assertOrPanic(clz(u8(0b10001010)) == 0);
104 assertOrPanic(clz(u8(0b00000000)) == 8);
105 assertOrPanic(clz(u128(0xffffffffffffffff)) == 64);
106 assertOrPanic(clz(u128(0x10000000000000000)) == 63);
102 expect(clz(u8(0b00001010)) == 4);
103 expect(clz(u8(0b10001010)) == 0);
104 expect(clz(u8(0b00000000)) == 8);
105 expect(clz(u128(0xffffffffffffffff)) == 64);
106 expect(clz(u128(0x10000000000000000)) == 63);
107107}
108108
109109fn clz(x: var) usize {
......@@ -116,9 +116,9 @@ test "@ctz" {
116116}
117117
118118fn testCtz() void {
119 assertOrPanic(ctz(u8(0b10100000)) == 5);
120 assertOrPanic(ctz(u8(0b10001010)) == 1);
121 assertOrPanic(ctz(u8(0b00000000)) == 8);
119 expect(ctz(u8(0b10100000)) == 5);
120 expect(ctz(u8(0b10001010)) == 1);
121 expect(ctz(u8(0b00000000)) == 8);
122122}
123123
124124fn ctz(x: var) usize {
......@@ -128,27 +128,27 @@ fn ctz(x: var) usize {
128128test "assignment operators" {
129129 var i: u32 = 0;
130130 i += 5;
131 assertOrPanic(i == 5);
131 expect(i == 5);
132132 i -= 2;
133 assertOrPanic(i == 3);
133 expect(i == 3);
134134 i *= 20;
135 assertOrPanic(i == 60);
135 expect(i == 60);
136136 i /= 3;
137 assertOrPanic(i == 20);
137 expect(i == 20);
138138 i %= 11;
139 assertOrPanic(i == 9);
139 expect(i == 9);
140140 i <<= 1;
141 assertOrPanic(i == 18);
141 expect(i == 18);
142142 i >>= 2;
143 assertOrPanic(i == 4);
143 expect(i == 4);
144144 i = 6;
145145 i &= 5;
146 assertOrPanic(i == 4);
146 expect(i == 4);
147147 i ^= 6;
148 assertOrPanic(i == 2);
148 expect(i == 2);
149149 i = 6;
150150 i |= 3;
151 assertOrPanic(i == 7);
151 expect(i == 7);
152152}
153153
154154test "three expr in a row" {
......@@ -170,14 +170,14 @@ fn testThreeExprInARow(f: bool, t: bool) void {
170170 assertFalse(i32(7) != --(i32(7)));
171171}
172172fn assertFalse(b: bool) void {
173 assertOrPanic(!b);
173 expect(!b);
174174}
175175
176176test "const number literal" {
177177 const one = 1;
178178 const eleven = ten + one;
179179
180 assertOrPanic(eleven == 11);
180 expect(eleven == 11);
181181}
182182const ten = 10;
183183
......@@ -187,9 +187,9 @@ test "unsigned wrapping" {
187187}
188188fn testUnsignedWrappingEval(x: u32) void {
189189 const zero = x +% 1;
190 assertOrPanic(zero == 0);
190 expect(zero == 0);
191191 const orig = zero -% 1;
192 assertOrPanic(orig == maxInt(u32));
192 expect(orig == maxInt(u32));
193193}
194194
195195test "signed wrapping" {
......@@ -198,9 +198,9 @@ test "signed wrapping" {
198198}
199199fn testSignedWrappingEval(x: i32) void {
200200 const min_val = x +% 1;
201 assertOrPanic(min_val == minInt(i32));
201 expect(min_val == minInt(i32));
202202 const max_val = min_val -% 1;
203 assertOrPanic(max_val == maxInt(i32));
203 expect(max_val == maxInt(i32));
204204}
205205
206206test "negation wrapping" {
......@@ -208,9 +208,9 @@ test "negation wrapping" {
208208 comptime testNegationWrappingEval(minInt(i16));
209209}
210210fn testNegationWrappingEval(x: i16) void {
211 assertOrPanic(x == -32768);
211 expect(x == -32768);
212212 const neg = -%x;
213 assertOrPanic(neg == -32768);
213 expect(neg == -32768);
214214}
215215
216216test "unsigned 64-bit division" {
......@@ -219,8 +219,8 @@ test "unsigned 64-bit division" {
219219}
220220fn test_u64_div() void {
221221 const result = divWithResult(1152921504606846976, 34359738365);
222 assertOrPanic(result.quotient == 33554432);
223 assertOrPanic(result.remainder == 100663296);
222 expect(result.quotient == 33554432);
223 expect(result.remainder == 100663296);
224224}
225225fn divWithResult(a: u64, b: u64) DivResult {
226226 return DivResult{
......@@ -234,36 +234,36 @@ const DivResult = struct {
234234};
235235
236236test "binary not" {
237 assertOrPanic(comptime x: {
237 expect(comptime x: {
238238 break :x ~u16(0b1010101010101010) == 0b0101010101010101;
239239 });
240 assertOrPanic(comptime x: {
240 expect(comptime x: {
241241 break :x ~u64(2147483647) == 18446744071562067968;
242242 });
243243 testBinaryNot(0b1010101010101010);
244244}
245245
246246fn testBinaryNot(x: u16) void {
247 assertOrPanic(~x == 0b0101010101010101);
247 expect(~x == 0b0101010101010101);
248248}
249249
250250test "small int addition" {
251251 var x: @IntType(false, 2) = 0;
252 assertOrPanic(x == 0);
252 expect(x == 0);
253253
254254 x += 1;
255 assertOrPanic(x == 1);
255 expect(x == 1);
256256
257257 x += 1;
258 assertOrPanic(x == 2);
258 expect(x == 2);
259259
260260 x += 1;
261 assertOrPanic(x == 3);
261 expect(x == 3);
262262
263263 var result: @typeOf(x) = 3;
264 assertOrPanic(@addWithOverflow(@typeOf(x), x, 1, &result));
264 expect(@addWithOverflow(@typeOf(x), x, 1, &result));
265265
266 assertOrPanic(result == 0);
266 expect(result == 0);
267267}
268268
269269test "float equality" {
......@@ -276,20 +276,20 @@ test "float equality" {
276276
277277fn testFloatEqualityImpl(x: f64, y: f64) void {
278278 const y2 = x + 1.0;
279 assertOrPanic(y == y2);
279 expect(y == y2);
280280}
281281
282282test "allow signed integer division/remainder when values are comptime known and positive or exact" {
283 assertOrPanic(5 / 3 == 1);
284 assertOrPanic(-5 / -3 == 1);
285 assertOrPanic(-6 / 3 == -2);
283 expect(5 / 3 == 1);
284 expect(-5 / -3 == 1);
285 expect(-6 / 3 == -2);
286286
287 assertOrPanic(5 % 3 == 2);
288 assertOrPanic(-6 % 3 == 0);
287 expect(5 % 3 == 2);
288 expect(-6 % 3 == 0);
289289}
290290
291291test "hex float literal parsing" {
292 comptime assertOrPanic(0x1.0 == 1.0);
292 comptime expect(0x1.0 == 1.0);
293293}
294294
295295test "quad hex float literal parsing in range" {
......@@ -304,7 +304,7 @@ test "quad hex float literal parsing accurate" {
304304
305305 // implied 1 is dropped, with an exponent of 0 (0x3fff) after biasing.
306306 const expected: u128 = 0x3fff1111222233334444555566667777;
307 assertOrPanic(@bitCast(u128, a) == expected);
307 expect(@bitCast(u128, a) == expected);
308308}
309309
310310test "hex float literal within range" {
......@@ -319,7 +319,7 @@ test "truncating shift left" {
319319}
320320fn testShlTrunc(x: u16) void {
321321 const shifted = x << 1;
322 assertOrPanic(shifted == 65534);
322 expect(shifted == 65534);
323323}
324324
325325test "truncating shift right" {
......@@ -328,7 +328,7 @@ test "truncating shift right" {
328328}
329329fn testShrTrunc(x: u16) void {
330330 const shifted = x >> 1;
331 assertOrPanic(shifted == 32767);
331 expect(shifted == 32767);
332332}
333333
334334test "exact shift left" {
......@@ -337,7 +337,7 @@ test "exact shift left" {
337337}
338338fn testShlExact(x: u8) void {
339339 const shifted = @shlExact(x, 2);
340 assertOrPanic(shifted == 0b11010100);
340 expect(shifted == 0b11010100);
341341}
342342
343343test "exact shift right" {
......@@ -346,22 +346,22 @@ test "exact shift right" {
346346}
347347fn testShrExact(x: u8) void {
348348 const shifted = @shrExact(x, 2);
349 assertOrPanic(shifted == 0b00101101);
349 expect(shifted == 0b00101101);
350350}
351351
352352test "comptime_int addition" {
353353 comptime {
354 assertOrPanic(35361831660712422535336160538497375248 + 101752735581729509668353361206450473702 == 137114567242441932203689521744947848950);
355 assertOrPanic(594491908217841670578297176641415611445982232488944558774612 + 390603545391089362063884922208143568023166603618446395589768 == 985095453608931032642182098849559179469148836107390954364380);
354 expect(35361831660712422535336160538497375248 + 101752735581729509668353361206450473702 == 137114567242441932203689521744947848950);
355 expect(594491908217841670578297176641415611445982232488944558774612 + 390603545391089362063884922208143568023166603618446395589768 == 985095453608931032642182098849559179469148836107390954364380);
356356 }
357357}
358358
359359test "comptime_int multiplication" {
360360 comptime {
361 assertOrPanic(
361 expect(
362362 45960427431263824329884196484953148229 * 128339149605334697009938835852565949723 == 5898522172026096622534201617172456926982464453350084962781392314016180490567,
363363 );
364 assertOrPanic(
364 expect(
365365 594491908217841670578297176641415611445982232488944558774612 * 390603545391089362063884922208143568023166603618446395589768 == 232210647056203049913662402532976186578842425262306016094292237500303028346593132411865381225871291702600263463125370016,
366366 );
367367 }
......@@ -369,7 +369,7 @@ test "comptime_int multiplication" {
369369
370370test "comptime_int shifting" {
371371 comptime {
372 assertOrPanic((u128(1) << 127) == 0x80000000000000000000000000000000);
372 expect((u128(1) << 127) == 0x80000000000000000000000000000000);
373373 }
374374}
375375
......@@ -377,16 +377,16 @@ test "comptime_int multi-limb shift and mask" {
377377 comptime {
378378 var a = 0xefffffffa0000001eeeeeeefaaaaaaab;
379379
380 assertOrPanic(u32(a & 0xffffffff) == 0xaaaaaaab);
380 expect(u32(a & 0xffffffff) == 0xaaaaaaab);
381381 a >>= 32;
382 assertOrPanic(u32(a & 0xffffffff) == 0xeeeeeeef);
382 expect(u32(a & 0xffffffff) == 0xeeeeeeef);
383383 a >>= 32;
384 assertOrPanic(u32(a & 0xffffffff) == 0xa0000001);
384 expect(u32(a & 0xffffffff) == 0xa0000001);
385385 a >>= 32;
386 assertOrPanic(u32(a & 0xffffffff) == 0xefffffff);
386 expect(u32(a & 0xffffffff) == 0xefffffff);
387387 a >>= 32;
388388
389 assertOrPanic(a == 0);
389 expect(a == 0);
390390 }
391391}
392392
......@@ -394,7 +394,7 @@ test "comptime_int multi-limb partial shift right" {
394394 comptime {
395395 var a = 0x1ffffffffeeeeeeee;
396396 a >>= 16;
397 assertOrPanic(a == 0x1ffffffffeeee);
397 expect(a == 0x1ffffffffeeee);
398398 }
399399}
400400
......@@ -404,23 +404,23 @@ test "xor" {
404404}
405405
406406fn test_xor() void {
407 assertOrPanic(0xFF ^ 0x00 == 0xFF);
408 assertOrPanic(0xF0 ^ 0x0F == 0xFF);
409 assertOrPanic(0xFF ^ 0xF0 == 0x0F);
410 assertOrPanic(0xFF ^ 0x0F == 0xF0);
411 assertOrPanic(0xFF ^ 0xFF == 0x00);
407 expect(0xFF ^ 0x00 == 0xFF);
408 expect(0xF0 ^ 0x0F == 0xFF);
409 expect(0xFF ^ 0xF0 == 0x0F);
410 expect(0xFF ^ 0x0F == 0xF0);
411 expect(0xFF ^ 0xFF == 0x00);
412412}
413413
414414test "comptime_int xor" {
415415 comptime {
416 assertOrPanic(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ^ 0x00000000000000000000000000000000 == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
417 assertOrPanic(0xFFFFFFFFFFFFFFFF0000000000000000 ^ 0x0000000000000000FFFFFFFFFFFFFFFF == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
418 assertOrPanic(0xFFFFFFFFFFFFFFFF0000000000000000 ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0x0000000000000000FFFFFFFFFFFFFFFF);
419 assertOrPanic(0x0000000000000000FFFFFFFFFFFFFFFF ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0xFFFFFFFFFFFFFFFF0000000000000000);
420 assertOrPanic(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0x00000000000000000000000000000000);
421 assertOrPanic(0xFFFFFFFF00000000FFFFFFFF00000000 ^ 0x00000000FFFFFFFF00000000FFFFFFFF == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
422 assertOrPanic(0xFFFFFFFF00000000FFFFFFFF00000000 ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0x00000000FFFFFFFF00000000FFFFFFFF);
423 assertOrPanic(0x00000000FFFFFFFF00000000FFFFFFFF ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0xFFFFFFFF00000000FFFFFFFF00000000);
416 expect(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ^ 0x00000000000000000000000000000000 == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
417 expect(0xFFFFFFFFFFFFFFFF0000000000000000 ^ 0x0000000000000000FFFFFFFFFFFFFFFF == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
418 expect(0xFFFFFFFFFFFFFFFF0000000000000000 ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0x0000000000000000FFFFFFFFFFFFFFFF);
419 expect(0x0000000000000000FFFFFFFFFFFFFFFF ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0xFFFFFFFFFFFFFFFF0000000000000000);
420 expect(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0x00000000000000000000000000000000);
421 expect(0xFFFFFFFF00000000FFFFFFFF00000000 ^ 0x00000000FFFFFFFF00000000FFFFFFFF == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
422 expect(0xFFFFFFFF00000000FFFFFFFF00000000 ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0x00000000FFFFFFFF00000000FFFFFFFF);
423 expect(0x00000000FFFFFFFF00000000FFFFFFFF ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0xFFFFFFFF00000000FFFFFFFF00000000);
424424 }
425425}
426426
......@@ -434,23 +434,23 @@ fn make_f128(x: f128) f128 {
434434}
435435
436436fn test_f128() void {
437 assertOrPanic(@sizeOf(f128) == 16);
438 assertOrPanic(make_f128(1.0) == 1.0);
439 assertOrPanic(make_f128(1.0) != 1.1);
440 assertOrPanic(make_f128(1.0) > 0.9);
441 assertOrPanic(make_f128(1.0) >= 0.9);
442 assertOrPanic(make_f128(1.0) >= 1.0);
437 expect(@sizeOf(f128) == 16);
438 expect(make_f128(1.0) == 1.0);
439 expect(make_f128(1.0) != 1.1);
440 expect(make_f128(1.0) > 0.9);
441 expect(make_f128(1.0) >= 0.9);
442 expect(make_f128(1.0) >= 1.0);
443443 should_not_be_zero(1.0);
444444}
445445
446446fn should_not_be_zero(x: f128) void {
447 assertOrPanic(x != 0.0);
447 expect(x != 0.0);
448448}
449449
450450test "comptime float rem int" {
451451 comptime {
452452 var x = f32(1) % 2;
453 assertOrPanic(x == 1.0);
453 expect(x == 1.0);
454454 }
455455}
456456
......@@ -465,8 +465,8 @@ test "remainder division" {
465465}
466466
467467fn remdiv(comptime T: type) void {
468 assertOrPanic(T(1) == T(1) % T(2));
469 assertOrPanic(T(1) == T(7) % T(3));
468 expect(T(1) == T(1) % T(2));
469 expect(T(1) == T(7) % T(3));
470470}
471471
472472test "@sqrt" {
......@@ -480,19 +480,19 @@ test "@sqrt" {
480480 const x = 14.0;
481481 const y = x * x;
482482 const z = @sqrt(@typeOf(y), y);
483 comptime assertOrPanic(z == x);
483 comptime expect(z == x);
484484}
485485
486486fn testSqrt(comptime T: type, x: T) void {
487 assertOrPanic(@sqrt(T, x * x) == x);
487 expect(@sqrt(T, x * x) == x);
488488}
489489
490490test "comptime_int param and return" {
491491 const a = comptimeAdd(35361831660712422535336160538497375248, 101752735581729509668353361206450473702);
492 assertOrPanic(a == 137114567242441932203689521744947848950);
492 expect(a == 137114567242441932203689521744947848950);
493493
494494 const b = comptimeAdd(594491908217841670578297176641415611445982232488944558774612, 390603545391089362063884922208143568023166603618446395589768);
495 assertOrPanic(b == 985095453608931032642182098849559179469148836107390954364380);
495 expect(b == 985095453608931032642182098849559179469148836107390954364380);
496496}
497497
498498fn comptimeAdd(comptime a: comptime_int, comptime b: comptime_int) comptime_int {
test/stage1/behavior/misc.zig+138-138
......@@ -1,5 +1,5 @@
11const std = @import("std");
2const assertOrPanic = std.debug.assertOrPanic;
2const expect = std.testing.expect;
33const mem = std.mem;
44const cstr = std.cstr;
55const builtin = @import("builtin");
......@@ -26,38 +26,38 @@ test "call disabled extern fn" {
2626}
2727
2828test "@IntType builtin" {
29 assertOrPanic(@IntType(true, 8) == i8);
30 assertOrPanic(@IntType(true, 16) == i16);
31 assertOrPanic(@IntType(true, 32) == i32);
32 assertOrPanic(@IntType(true, 64) == i64);
33
34 assertOrPanic(@IntType(false, 8) == u8);
35 assertOrPanic(@IntType(false, 16) == u16);
36 assertOrPanic(@IntType(false, 32) == u32);
37 assertOrPanic(@IntType(false, 64) == u64);
38
39 assertOrPanic(i8.bit_count == 8);
40 assertOrPanic(i16.bit_count == 16);
41 assertOrPanic(i32.bit_count == 32);
42 assertOrPanic(i64.bit_count == 64);
43
44 assertOrPanic(i8.is_signed);
45 assertOrPanic(i16.is_signed);
46 assertOrPanic(i32.is_signed);
47 assertOrPanic(i64.is_signed);
48 assertOrPanic(isize.is_signed);
49
50 assertOrPanic(!u8.is_signed);
51 assertOrPanic(!u16.is_signed);
52 assertOrPanic(!u32.is_signed);
53 assertOrPanic(!u64.is_signed);
54 assertOrPanic(!usize.is_signed);
29 expect(@IntType(true, 8) == i8);
30 expect(@IntType(true, 16) == i16);
31 expect(@IntType(true, 32) == i32);
32 expect(@IntType(true, 64) == i64);
33
34 expect(@IntType(false, 8) == u8);
35 expect(@IntType(false, 16) == u16);
36 expect(@IntType(false, 32) == u32);
37 expect(@IntType(false, 64) == u64);
38
39 expect(i8.bit_count == 8);
40 expect(i16.bit_count == 16);
41 expect(i32.bit_count == 32);
42 expect(i64.bit_count == 64);
43
44 expect(i8.is_signed);
45 expect(i16.is_signed);
46 expect(i32.is_signed);
47 expect(i64.is_signed);
48 expect(isize.is_signed);
49
50 expect(!u8.is_signed);
51 expect(!u16.is_signed);
52 expect(!u32.is_signed);
53 expect(!u64.is_signed);
54 expect(!usize.is_signed);
5555}
5656
5757test "floating point primitive bit counts" {
58 assertOrPanic(f16.bit_count == 16);
59 assertOrPanic(f32.bit_count == 32);
60 assertOrPanic(f64.bit_count == 64);
58 expect(f16.bit_count == 16);
59 expect(f32.bit_count == 32);
60 expect(f64.bit_count == 64);
6161}
6262
6363test "short circuit" {
......@@ -72,7 +72,7 @@ fn testShortCircuit(f: bool, t: bool) void {
7272 var hit_4 = f;
7373
7474 if (t or x: {
75 assertOrPanic(f);
75 expect(f);
7676 break :x f;
7777 }) {
7878 hit_1 = t;
......@@ -81,31 +81,31 @@ fn testShortCircuit(f: bool, t: bool) void {
8181 hit_2 = t;
8282 break :x f;
8383 }) {
84 assertOrPanic(f);
84 expect(f);
8585 }
8686
8787 if (t and x: {
8888 hit_3 = t;
8989 break :x f;
9090 }) {
91 assertOrPanic(f);
91 expect(f);
9292 }
9393 if (f and x: {
94 assertOrPanic(f);
94 expect(f);
9595 break :x f;
9696 }) {
97 assertOrPanic(f);
97 expect(f);
9898 } else {
9999 hit_4 = t;
100100 }
101 assertOrPanic(hit_1);
102 assertOrPanic(hit_2);
103 assertOrPanic(hit_3);
104 assertOrPanic(hit_4);
101 expect(hit_1);
102 expect(hit_2);
103 expect(hit_3);
104 expect(hit_4);
105105}
106106
107107test "truncate" {
108 assertOrPanic(testTruncate(0x10fd) == 0xfd);
108 expect(testTruncate(0x10fd) == 0xfd);
109109}
110110fn testTruncate(x: u32) u8 {
111111 return @truncate(u8, x);
......@@ -116,16 +116,16 @@ fn first4KeysOfHomeRow() []const u8 {
116116}
117117
118118test "return string from function" {
119 assertOrPanic(mem.eql(u8, first4KeysOfHomeRow(), "aoeu"));
119 expect(mem.eql(u8, first4KeysOfHomeRow(), "aoeu"));
120120}
121121
122122const g1: i32 = 1233 + 1;
123123var g2: i32 = 0;
124124
125125test "global variables" {
126 assertOrPanic(g2 == 0);
126 expect(g2 == 0);
127127 g2 = g1;
128 assertOrPanic(g2 == 1234);
128 expect(g2 == 1234);
129129}
130130
131131test "memcpy and memset intrinsics" {
......@@ -142,7 +142,7 @@ test "builtin static eval" {
142142 const x: i32 = comptime x: {
143143 break :x 1 + 2 + 3;
144144 };
145 assertOrPanic(x == comptime 6);
145 expect(x == comptime 6);
146146}
147147
148148test "slicing" {
......@@ -163,7 +163,7 @@ test "slicing" {
163163
164164test "constant equal function pointers" {
165165 const alias = emptyFn;
166 assertOrPanic(comptime x: {
166 expect(comptime x: {
167167 break :x emptyFn == alias;
168168 });
169169}
......@@ -171,25 +171,25 @@ test "constant equal function pointers" {
171171fn emptyFn() void {}
172172
173173test "hex escape" {
174 assertOrPanic(mem.eql(u8, "\x68\x65\x6c\x6c\x6f", "hello"));
174 expect(mem.eql(u8, "\x68\x65\x6c\x6c\x6f", "hello"));
175175}
176176
177177test "string concatenation" {
178 assertOrPanic(mem.eql(u8, "OK" ++ " IT " ++ "WORKED", "OK IT WORKED"));
178 expect(mem.eql(u8, "OK" ++ " IT " ++ "WORKED", "OK IT WORKED"));
179179}
180180
181181test "array mult operator" {
182 assertOrPanic(mem.eql(u8, "ab" ** 5, "ababababab"));
182 expect(mem.eql(u8, "ab" ** 5, "ababababab"));
183183}
184184
185185test "string escapes" {
186 assertOrPanic(mem.eql(u8, "\"", "\x22"));
187 assertOrPanic(mem.eql(u8, "\'", "\x27"));
188 assertOrPanic(mem.eql(u8, "\n", "\x0a"));
189 assertOrPanic(mem.eql(u8, "\r", "\x0d"));
190 assertOrPanic(mem.eql(u8, "\t", "\x09"));
191 assertOrPanic(mem.eql(u8, "\\", "\x5c"));
192 assertOrPanic(mem.eql(u8, "\u1234\u0069", "\xe1\x88\xb4\x69"));
186 expect(mem.eql(u8, "\"", "\x22"));
187 expect(mem.eql(u8, "\'", "\x27"));
188 expect(mem.eql(u8, "\n", "\x0a"));
189 expect(mem.eql(u8, "\r", "\x0d"));
190 expect(mem.eql(u8, "\t", "\x09"));
191 expect(mem.eql(u8, "\\", "\x5c"));
192 expect(mem.eql(u8, "\u1234\u0069", "\xe1\x88\xb4\x69"));
193193}
194194
195195test "multiline string" {
......@@ -199,7 +199,7 @@ test "multiline string" {
199199 \\three
200200 ;
201201 const s2 = "one\ntwo)\nthree";
202 assertOrPanic(mem.eql(u8, s1, s2));
202 expect(mem.eql(u8, s1, s2));
203203}
204204
205205test "multiline C string" {
......@@ -209,11 +209,11 @@ test "multiline C string" {
209209 c\\three
210210 ;
211211 const s2 = c"one\ntwo)\nthree";
212 assertOrPanic(cstr.cmp(s1, s2) == 0);
212 expect(cstr.cmp(s1, s2) == 0);
213213}
214214
215215test "type equality" {
216 assertOrPanic(*const u8 != *u8);
216 expect(*const u8 != *u8);
217217}
218218
219219const global_a: i32 = 1234;
......@@ -221,7 +221,7 @@ const global_b: *const i32 = &global_a;
221221const global_c: *const f32 = @ptrCast(*const f32, global_b);
222222test "compile time global reinterpret" {
223223 const d = @ptrCast(*const i32, global_c);
224 assertOrPanic(d.* == 1234);
224 expect(d.* == 1234);
225225}
226226
227227test "explicit cast maybe pointers" {
......@@ -247,8 +247,8 @@ test "cast undefined" {
247247fn testCastUndefined(x: []const u8) void {}
248248
249249test "cast small unsigned to larger signed" {
250 assertOrPanic(castSmallUnsignedToLargerSigned1(200) == i16(200));
251 assertOrPanic(castSmallUnsignedToLargerSigned2(9999) == i64(9999));
250 expect(castSmallUnsignedToLargerSigned1(200) == i16(200));
251 expect(castSmallUnsignedToLargerSigned2(9999) == i64(9999));
252252}
253253fn castSmallUnsignedToLargerSigned1(x: u8) i16 {
254254 return x;
......@@ -258,7 +258,7 @@ fn castSmallUnsignedToLargerSigned2(x: u16) i64 {
258258}
259259
260260test "implicit cast after unreachable" {
261 assertOrPanic(outer() == 1234);
261 expect(outer() == 1234);
262262}
263263fn inner() i32 {
264264 return 1234;
......@@ -273,13 +273,13 @@ test "pointer dereferencing" {
273273
274274 y.* += 1;
275275
276 assertOrPanic(x == 4);
277 assertOrPanic(y.* == 4);
276 expect(x == 4);
277 expect(y.* == 4);
278278}
279279
280280test "call result of if else expression" {
281 assertOrPanic(mem.eql(u8, f2(true), "a"));
282 assertOrPanic(mem.eql(u8, f2(false), "b"));
281 expect(mem.eql(u8, f2(true), "a"));
282 expect(mem.eql(u8, f2(false), "b"));
283283}
284284fn f2(x: bool) []const u8 {
285285 return (if (x) fA else fB)();
......@@ -321,8 +321,8 @@ const test3_bar = Test3Foo{ .Two = 13 };
321321fn test3_1(f: Test3Foo) void {
322322 switch (f) {
323323 Test3Foo.Three => |pt| {
324 assertOrPanic(pt.x == 3);
325 assertOrPanic(pt.y == 4);
324 expect(pt.x == 3);
325 expect(pt.y == 4);
326326 },
327327 else => unreachable,
328328 }
......@@ -330,14 +330,14 @@ fn test3_1(f: Test3Foo) void {
330330fn test3_2(f: Test3Foo) void {
331331 switch (f) {
332332 Test3Foo.Two => |x| {
333 assertOrPanic(x == 13);
333 expect(x == 13);
334334 },
335335 else => unreachable,
336336 }
337337}
338338
339339test "character literals" {
340 assertOrPanic('\'' == single_quote);
340 expect('\'' == single_quote);
341341}
342342const single_quote = '\'';
343343
......@@ -346,13 +346,13 @@ test "take address of parameter" {
346346}
347347fn testTakeAddressOfParameter(f: f32) void {
348348 const f_ptr = &f;
349 assertOrPanic(f_ptr.* == 12.34);
349 expect(f_ptr.* == 12.34);
350350}
351351
352352test "pointer comparison" {
353353 const a = ([]const u8)("a");
354354 const b = &a;
355 assertOrPanic(ptrEql(b, b));
355 expect(ptrEql(b, b));
356356}
357357fn ptrEql(a: *const []const u8, b: *const []const u8) bool {
358358 return a == b;
......@@ -367,31 +367,31 @@ test "C string concatenation" {
367367 {
368368 var i: u32 = 0;
369369 while (i < len_with_null) : (i += 1) {
370 assertOrPanic(a[i] == b[i]);
370 expect(a[i] == b[i]);
371371 }
372372 }
373 assertOrPanic(a[len] == 0);
374 assertOrPanic(b[len] == 0);
373 expect(a[len] == 0);
374 expect(b[len] == 0);
375375}
376376
377377test "cast slice to u8 slice" {
378 assertOrPanic(@sizeOf(i32) == 4);
378 expect(@sizeOf(i32) == 4);
379379 var big_thing_array = []i32{ 1, 2, 3, 4 };
380380 const big_thing_slice: []i32 = big_thing_array[0..];
381381 const bytes = @sliceToBytes(big_thing_slice);
382 assertOrPanic(bytes.len == 4 * 4);
382 expect(bytes.len == 4 * 4);
383383 bytes[4] = 0;
384384 bytes[5] = 0;
385385 bytes[6] = 0;
386386 bytes[7] = 0;
387 assertOrPanic(big_thing_slice[1] == 0);
387 expect(big_thing_slice[1] == 0);
388388 const big_thing_again = @bytesToSlice(i32, bytes);
389 assertOrPanic(big_thing_again[2] == 3);
389 expect(big_thing_again[2] == 3);
390390 big_thing_again[2] = -1;
391 assertOrPanic(bytes[8] == maxInt(u8));
392 assertOrPanic(bytes[9] == maxInt(u8));
393 assertOrPanic(bytes[10] == maxInt(u8));
394 assertOrPanic(bytes[11] == maxInt(u8));
391 expect(bytes[8] == maxInt(u8));
392 expect(bytes[9] == maxInt(u8));
393 expect(bytes[10] == maxInt(u8));
394 expect(bytes[11] == maxInt(u8));
395395}
396396
397397test "pointer to void return type" {
......@@ -408,7 +408,7 @@ fn testPointerToVoidReturnType2() *const void {
408408
409409test "non const ptr to aliased type" {
410410 const int = i32;
411 assertOrPanic(?*int == ?*i32);
411 expect(?*int == ?*i32);
412412}
413413
414414test "array 2D const double ptr" {
......@@ -421,8 +421,8 @@ test "array 2D const double ptr" {
421421
422422fn testArray2DConstDoublePtr(ptr: *const f32) void {
423423 const ptr2 = @ptrCast([*]const f32, ptr);
424 assertOrPanic(ptr2[0] == 1.0);
425 assertOrPanic(ptr2[1] == 2.0);
424 expect(ptr2[0] == 1.0);
425 expect(ptr2[1] == 2.0);
426426}
427427
428428const Tid = builtin.TypeId;
......@@ -444,32 +444,32 @@ const AUnion = union {
444444
445445test "@typeId" {
446446 comptime {
447 assertOrPanic(@typeId(type) == Tid.Type);
448 assertOrPanic(@typeId(void) == Tid.Void);
449 assertOrPanic(@typeId(bool) == Tid.Bool);
450 assertOrPanic(@typeId(noreturn) == Tid.NoReturn);
451 assertOrPanic(@typeId(i8) == Tid.Int);
452 assertOrPanic(@typeId(u8) == Tid.Int);
453 assertOrPanic(@typeId(i64) == Tid.Int);
454 assertOrPanic(@typeId(u64) == Tid.Int);
455 assertOrPanic(@typeId(f32) == Tid.Float);
456 assertOrPanic(@typeId(f64) == Tid.Float);
457 assertOrPanic(@typeId(*f32) == Tid.Pointer);
458 assertOrPanic(@typeId([2]u8) == Tid.Array);
459 assertOrPanic(@typeId(AStruct) == Tid.Struct);
460 assertOrPanic(@typeId(@typeOf(1)) == Tid.ComptimeInt);
461 assertOrPanic(@typeId(@typeOf(1.0)) == Tid.ComptimeFloat);
462 assertOrPanic(@typeId(@typeOf(undefined)) == Tid.Undefined);
463 assertOrPanic(@typeId(@typeOf(null)) == Tid.Null);
464 assertOrPanic(@typeId(?i32) == Tid.Optional);
465 assertOrPanic(@typeId(anyerror!i32) == Tid.ErrorUnion);
466 assertOrPanic(@typeId(anyerror) == Tid.ErrorSet);
467 assertOrPanic(@typeId(AnEnum) == Tid.Enum);
468 assertOrPanic(@typeId(@typeOf(AUnionEnum.One)) == Tid.Enum);
469 assertOrPanic(@typeId(AUnionEnum) == Tid.Union);
470 assertOrPanic(@typeId(AUnion) == Tid.Union);
471 assertOrPanic(@typeId(fn () void) == Tid.Fn);
472 assertOrPanic(@typeId(@typeOf(builtin)) == Tid.Namespace);
447 expect(@typeId(type) == Tid.Type);
448 expect(@typeId(void) == Tid.Void);
449 expect(@typeId(bool) == Tid.Bool);
450 expect(@typeId(noreturn) == Tid.NoReturn);
451 expect(@typeId(i8) == Tid.Int);
452 expect(@typeId(u8) == Tid.Int);
453 expect(@typeId(i64) == Tid.Int);
454 expect(@typeId(u64) == Tid.Int);
455 expect(@typeId(f32) == Tid.Float);
456 expect(@typeId(f64) == Tid.Float);
457 expect(@typeId(*f32) == Tid.Pointer);
458 expect(@typeId([2]u8) == Tid.Array);
459 expect(@typeId(AStruct) == Tid.Struct);
460 expect(@typeId(@typeOf(1)) == Tid.ComptimeInt);
461 expect(@typeId(@typeOf(1.0)) == Tid.ComptimeFloat);
462 expect(@typeId(@typeOf(undefined)) == Tid.Undefined);
463 expect(@typeId(@typeOf(null)) == Tid.Null);
464 expect(@typeId(?i32) == Tid.Optional);
465 expect(@typeId(anyerror!i32) == Tid.ErrorUnion);
466 expect(@typeId(anyerror) == Tid.ErrorSet);
467 expect(@typeId(AnEnum) == Tid.Enum);
468 expect(@typeId(@typeOf(AUnionEnum.One)) == Tid.Enum);
469 expect(@typeId(AUnionEnum) == Tid.Union);
470 expect(@typeId(AUnion) == Tid.Union);
471 expect(@typeId(fn () void) == Tid.Fn);
472 expect(@typeId(@typeOf(builtin)) == Tid.Namespace);
473473 // TODO bound fn
474474 // TODO arg tuple
475475 // TODO opaque
......@@ -485,13 +485,13 @@ test "@typeName" {
485485 Unused,
486486 };
487487 comptime {
488 assertOrPanic(mem.eql(u8, @typeName(i64), "i64"));
489 assertOrPanic(mem.eql(u8, @typeName(*usize), "*usize"));
488 expect(mem.eql(u8, @typeName(i64), "i64"));
489 expect(mem.eql(u8, @typeName(*usize), "*usize"));
490490 // https://github.com/ziglang/zig/issues/675
491 assertOrPanic(mem.eql(u8, @typeName(TypeFromFn(u8)), "TypeFromFn(u8)"));
492 assertOrPanic(mem.eql(u8, @typeName(Struct), "Struct"));
493 assertOrPanic(mem.eql(u8, @typeName(Union), "Union"));
494 assertOrPanic(mem.eql(u8, @typeName(Enum), "Enum"));
491 expect(mem.eql(u8, @typeName(TypeFromFn(u8)), "TypeFromFn(u8)"));
492 expect(mem.eql(u8, @typeName(Struct), "Struct"));
493 expect(mem.eql(u8, @typeName(Union), "Union"));
494 expect(mem.eql(u8, @typeName(Enum), "Enum"));
495495 }
496496}
497497
......@@ -501,14 +501,14 @@ fn TypeFromFn(comptime T: type) type {
501501
502502test "double implicit cast in same expression" {
503503 var x = i32(u16(nine()));
504 assertOrPanic(x == 9);
504 expect(x == 9);
505505}
506506fn nine() u8 {
507507 return 9;
508508}
509509
510510test "global variable initialized to global variable array element" {
511 assertOrPanic(global_ptr == &gdt[0]);
511 expect(global_ptr == &gdt[0]);
512512}
513513const GDTEntry = struct {
514514 field: i32,
......@@ -529,9 +529,9 @@ export fn writeToVRam() void {
529529const OpaqueA = @OpaqueType();
530530const OpaqueB = @OpaqueType();
531531test "@OpaqueType" {
532 assertOrPanic(*OpaqueA != *OpaqueB);
533 assertOrPanic(mem.eql(u8, @typeName(OpaqueA), "OpaqueA"));
534 assertOrPanic(mem.eql(u8, @typeName(OpaqueB), "OpaqueB"));
532 expect(*OpaqueA != *OpaqueB);
533 expect(mem.eql(u8, @typeName(OpaqueA), "OpaqueA"));
534 expect(mem.eql(u8, @typeName(OpaqueB), "OpaqueB"));
535535}
536536
537537test "variable is allowed to be a pointer to an opaque type" {
......@@ -571,7 +571,7 @@ fn fnThatClosesOverLocalConst() type {
571571
572572test "function closes over local const" {
573573 const x = fnThatClosesOverLocalConst().g();
574 assertOrPanic(x == 1);
574 expect(x == 1);
575575}
576576
577577test "cold function" {
......@@ -608,21 +608,21 @@ export fn testPackedStuff(a: *const PackedStruct, b: *const PackedUnion, c: Pack
608608test "slicing zero length array" {
609609 const s1 = ""[0..];
610610 const s2 = ([]u32{})[0..];
611 assertOrPanic(s1.len == 0);
612 assertOrPanic(s2.len == 0);
613 assertOrPanic(mem.eql(u8, s1, ""));
614 assertOrPanic(mem.eql(u32, s2, []u32{}));
611 expect(s1.len == 0);
612 expect(s2.len == 0);
613 expect(mem.eql(u8, s1, ""));
614 expect(mem.eql(u32, s2, []u32{}));
615615}
616616
617617const addr1 = @ptrCast(*const u8, emptyFn);
618618test "comptime cast fn to ptr" {
619619 const addr2 = @ptrCast(*const u8, emptyFn);
620 comptime assertOrPanic(addr1 == addr2);
620 comptime expect(addr1 == addr2);
621621}
622622
623623test "equality compare fn ptrs" {
624624 var a = emptyFn;
625 assertOrPanic(a == a);
625 expect(a == a);
626626}
627627
628628test "self reference through fn ptr field" {
......@@ -637,26 +637,26 @@ test "self reference through fn ptr field" {
637637 };
638638 var a: S.A = undefined;
639639 a.f = S.foo;
640 assertOrPanic(a.f(a) == 12);
640 expect(a.f(a) == 12);
641641}
642642
643643test "volatile load and store" {
644644 var number: i32 = 1234;
645645 const ptr = (*volatile i32)(&number);
646646 ptr.* += 1;
647 assertOrPanic(ptr.* == 1235);
647 expect(ptr.* == 1235);
648648}
649649
650650test "slice string literal has type []const u8" {
651651 comptime {
652 assertOrPanic(@typeOf("aoeu"[0..]) == []const u8);
652 expect(@typeOf("aoeu"[0..]) == []const u8);
653653 const array = []i32{ 1, 2, 3, 4 };
654 assertOrPanic(@typeOf(array[0..]) == []const i32);
654 expect(@typeOf(array[0..]) == []const i32);
655655 }
656656}
657657
658658test "pointer child field" {
659 assertOrPanic((*u32).Child == u32);
659 expect((*u32).Child == u32);
660660}
661661
662662test "struct inside function" {
......@@ -675,11 +675,11 @@ fn testStructInFn() void {
675675
676676 block.kind += 1;
677677
678 assertOrPanic(block.kind == 1235);
678 expect(block.kind == 1235);
679679}
680680
681681test "fn call returning scalar optional in equality expression" {
682 assertOrPanic(getNull() == null);
682 expect(getNull() == null);
683683}
684684
685685fn getNull() ?*i32 {
......@@ -691,5 +691,5 @@ test "thread local variable" {
691691 threadlocal var t: i32 = 1234;
692692 };
693693 S.t += 1;
694 assertOrPanic(S.t == 1235);
694 expect(S.t == 1235);
695695}
test/stage1/behavior/namespace_depends_on_compile_var/index.zig+3-3
......@@ -1,11 +1,11 @@
11const builtin = @import("builtin");
2const assertOrPanic = @import("std").debug.assertOrPanic;
2const expect = @import("std").testing.expect;
33
44test "namespace depends on compile var" {
55 if (some_namespace.a_bool) {
6 assertOrPanic(some_namespace.a_bool);
6 expect(some_namespace.a_bool);
77 } else {
8 assertOrPanic(!some_namespace.a_bool);
8 expect(!some_namespace.a_bool);
99 }
1010}
1111const some_namespace = switch (builtin.os) {
test/stage1/behavior/new_stack_call.zig+5-5
......@@ -1,5 +1,5 @@
11const std = @import("std");
2const assertOrPanic = std.debug.assertOrPanic;
2const expect = std.testing.expect;
33
44var new_stack_bytes: [1024]u8 = undefined;
55
......@@ -10,17 +10,17 @@ test "calling a function with a new stack" {
1010 const b = @newStackCall(new_stack_bytes[512..], targetFunction, arg);
1111 _ = targetFunction(arg);
1212
13 assertOrPanic(arg == 1234);
14 assertOrPanic(a < b);
13 expect(arg == 1234);
14 expect(a < b);
1515}
1616
1717fn targetFunction(x: i32) usize {
18 assertOrPanic(x == 1234);
18 expect(x == 1234);
1919
2020 var local_variable: i32 = 42;
2121 const ptr = &local_variable;
2222 ptr.* += 1;
2323
24 assertOrPanic(local_variable == 43);
24 expect(local_variable == 43);
2525 return @ptrToInt(ptr);
2626}
test/stage1/behavior/null.zig+17-17
......@@ -1,4 +1,4 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;
1const expect = @import("std").testing.expect;
22
33test "optional type" {
44 const x: ?bool = true;
......@@ -17,13 +17,13 @@ test "optional type" {
1717
1818 const z = next_x orelse 1234;
1919
20 assertOrPanic(z == 1234);
20 expect(z == 1234);
2121
2222 const final_x: ?i32 = 13;
2323
2424 const num = final_x orelse unreachable;
2525
26 assertOrPanic(num == 13);
26 expect(num == 13);
2727}
2828
2929test "test maybe object and get a pointer to the inner value" {
......@@ -33,7 +33,7 @@ test "test maybe object and get a pointer to the inner value" {
3333 b.* = false;
3434 }
3535
36 assertOrPanic(maybe_bool.? == false);
36 expect(maybe_bool.? == false);
3737}
3838
3939test "rhs maybe unwrap return" {
......@@ -47,9 +47,9 @@ test "maybe return" {
4747}
4848
4949fn maybeReturnImpl() void {
50 assertOrPanic(foo(1235).?);
50 expect(foo(1235).?);
5151 if (foo(null) != null) unreachable;
52 assertOrPanic(!foo(1234).?);
52 expect(!foo(1234).?);
5353}
5454
5555fn foo(x: ?i32) ?bool {
......@@ -58,7 +58,7 @@ fn foo(x: ?i32) ?bool {
5858}
5959
6060test "if var maybe pointer" {
61 assertOrPanic(shouldBeAPlus1(Particle{
61 expect(shouldBeAPlus1(Particle{
6262 .a = 14,
6363 .b = 1,
6464 .c = 1,
......@@ -84,10 +84,10 @@ const Particle = struct {
8484
8585test "null literal outside function" {
8686 const is_null = here_is_a_null_literal.context == null;
87 assertOrPanic(is_null);
87 expect(is_null);
8888
8989 const is_non_null = here_is_a_null_literal.context != null;
90 assertOrPanic(!is_non_null);
90 expect(!is_non_null);
9191}
9292const SillyStruct = struct {
9393 context: ?i32,
......@@ -98,8 +98,8 @@ test "test null runtime" {
9898 testTestNullRuntime(null);
9999}
100100fn testTestNullRuntime(x: ?i32) void {
101 assertOrPanic(x == null);
102 assertOrPanic(!(x != null));
101 expect(x == null);
102 expect(!(x != null));
103103}
104104
105105test "optional void" {
......@@ -108,8 +108,8 @@ test "optional void" {
108108}
109109
110110fn optionalVoidImpl() void {
111 assertOrPanic(bar(null) == null);
112 assertOrPanic(bar({}) != null);
111 expect(bar(null) == null);
112 expect(bar({}) != null);
113113}
114114
115115fn bar(x: ?void) ?void {
......@@ -133,7 +133,7 @@ test "unwrap optional which is field of global var" {
133133 }
134134 struct_with_optional.field = 1234;
135135 if (struct_with_optional.field) |payload| {
136 assertOrPanic(payload == 1234);
136 expect(payload == 1234);
137137 } else {
138138 unreachable;
139139 }
......@@ -141,13 +141,13 @@ test "unwrap optional which is field of global var" {
141141
142142test "null with default unwrap" {
143143 const x: i32 = null orelse 1;
144 assertOrPanic(x == 1);
144 expect(x == 1);
145145}
146146
147147test "optional types" {
148148 comptime {
149149 const opt_type_struct = StructWithOptionalType{ .t = u8 };
150 assertOrPanic(opt_type_struct.t != null and opt_type_struct.t.? == u8);
150 expect(opt_type_struct.t != null and opt_type_struct.t.? == u8);
151151 }
152152}
153153
......@@ -158,5 +158,5 @@ const StructWithOptionalType = struct {
158158test "optional pointer to 0 bit type null value at runtime" {
159159 const EmptyStruct = struct {};
160160 var x: ?*EmptyStruct = null;
161 assertOrPanic(x == null);
161 expect(x == null);
162162}
test/stage1/behavior/optional.zig+14-14
......@@ -1,11 +1,11 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;
1const expect = @import("std").testing.expect;
22
33pub const EmptyStruct = struct {};
44
55test "optional pointer to size zero struct" {
66 var e = EmptyStruct{};
77 var o: ?*EmptyStruct = &e;
8 assertOrPanic(o != null);
8 expect(o != null);
99}
1010
1111test "equality compare nullable pointers" {
......@@ -18,15 +18,15 @@ fn testNullPtrsEql() void {
1818
1919 var x: ?*i32 = null;
2020 var y: ?*i32 = null;
21 assertOrPanic(x == y);
21 expect(x == y);
2222 y = &number;
23 assertOrPanic(x != y);
24 assertOrPanic(x != &number);
25 assertOrPanic(&number != x);
23 expect(x != y);
24 expect(x != &number);
25 expect(&number != x);
2626 x = &number;
27 assertOrPanic(x == y);
28 assertOrPanic(x == &number);
29 assertOrPanic(&number == x);
27 expect(x == y);
28 expect(x == &number);
29 expect(&number == x);
3030}
3131
3232test "address of unwrap optional" {
......@@ -43,7 +43,7 @@ test "address of unwrap optional" {
4343 };
4444 S.global = S.Foo{ .a = 1234 };
4545 const foo = S.getFoo() catch unreachable;
46 assertOrPanic(foo.a == 1234);
46 expect(foo.a == 1234);
4747}
4848
4949test "passing an optional integer as a parameter" {
......@@ -57,15 +57,15 @@ test "passing an optional integer as a parameter" {
5757 return x.? == 1234;
5858 }
5959 };
60 assertOrPanic(S.entry());
61 comptime assertOrPanic(S.entry());
60 expect(S.entry());
61 comptime expect(S.entry());
6262}
6363
6464test "unwrap function call with optional pointer return value" {
6565 const S = struct {
6666 fn entry() void {
67 assertOrPanic(foo().?.* == 1234);
68 assertOrPanic(bar() == null);
67 expect(foo().?.* == 1234);
68 expect(bar() == null);
6969 }
7070 const global: i32 = 1234;
7171 fn foo() ?*const i32 {
test/stage1/behavior/pointers.zig+12-12
......@@ -1,5 +1,5 @@
11const std = @import("std");
2const assertOrPanic = std.debug.assertOrPanic;
2const expect = std.testing.expect;
33
44test "dereference pointer" {
55 comptime testDerefPtr();
......@@ -10,33 +10,33 @@ fn testDerefPtr() void {
1010 var x: i32 = 1234;
1111 var y = &x;
1212 y.* += 1;
13 assertOrPanic(x == 1235);
13 expect(x == 1235);
1414}
1515
1616test "pointer arithmetic" {
1717 var ptr = c"abcd";
1818
19 assertOrPanic(ptr[0] == 'a');
19 expect(ptr[0] == 'a');
2020 ptr += 1;
21 assertOrPanic(ptr[0] == 'b');
21 expect(ptr[0] == 'b');
2222 ptr += 1;
23 assertOrPanic(ptr[0] == 'c');
23 expect(ptr[0] == 'c');
2424 ptr += 1;
25 assertOrPanic(ptr[0] == 'd');
25 expect(ptr[0] == 'd');
2626 ptr += 1;
27 assertOrPanic(ptr[0] == 0);
27 expect(ptr[0] == 0);
2828 ptr -= 1;
29 assertOrPanic(ptr[0] == 'd');
29 expect(ptr[0] == 'd');
3030 ptr -= 1;
31 assertOrPanic(ptr[0] == 'c');
31 expect(ptr[0] == 'c');
3232 ptr -= 1;
33 assertOrPanic(ptr[0] == 'b');
33 expect(ptr[0] == 'b');
3434 ptr -= 1;
35 assertOrPanic(ptr[0] == 'a');
35 expect(ptr[0] == 'a');
3636}
3737
3838test "double pointer parsing" {
39 comptime assertOrPanic(PtrOf(PtrOf(i32)) == **i32);
39 comptime expect(PtrOf(PtrOf(i32)) == **i32);
4040}
4141
4242fn PtrOf(comptime T: type) type {
test/stage1/behavior/popcount.zig+5-5
......@@ -1,4 +1,4 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;
1const expect = @import("std").testing.expect;
22
33test "@popCount" {
44 comptime testPopCount();
......@@ -8,18 +8,18 @@ test "@popCount" {
88fn testPopCount() void {
99 {
1010 var x: u32 = 0xaa;
11 assertOrPanic(@popCount(x) == 4);
11 expect(@popCount(x) == 4);
1212 }
1313 {
1414 var x: u32 = 0xaaaaaaaa;
15 assertOrPanic(@popCount(x) == 16);
15 expect(@popCount(x) == 16);
1616 }
1717 {
1818 var x: i16 = -1;
19 assertOrPanic(@popCount(x) == 16);
19 expect(@popCount(x) == 16);
2020 }
2121 comptime {
22 assertOrPanic(@popCount(0b11111111000110001100010000100001000011000011100101010001) == 24);
22 expect(@popCount(0b11111111000110001100010000100001000011000011100101010001) == 24);
2323 }
2424}
2525
test/stage1/behavior/ptrcast.zig+4-4
......@@ -1,6 +1,6 @@
11const builtin = @import("builtin");
22const std = @import("std");
3const assertOrPanic = std.debug.assertOrPanic;
3const expect = std.testing.expect;
44
55test "reinterpret bytes as integer with nonzero offset" {
66 testReinterpretBytesAsInteger();
......@@ -13,7 +13,7 @@ fn testReinterpretBytesAsInteger() void {
1313 builtin.Endian.Little => 0xab785634,
1414 builtin.Endian.Big => 0x345678ab,
1515 };
16 assertOrPanic(@ptrCast(*align(1) const u32, bytes[1..5].ptr).* == expected);
16 expect(@ptrCast(*align(1) const u32, bytes[1..5].ptr).* == expected);
1717}
1818
1919test "reinterpret bytes of an array into an extern struct" {
......@@ -32,12 +32,12 @@ fn testReinterpretBytesAsExternStruct() void {
3232
3333 var ptr = @ptrCast(*const S, &bytes);
3434 var val = ptr.c;
35 assertOrPanic(val == 5);
35 expect(val == 5);
3636}
3737
3838test "reinterpret struct field at comptime" {
3939 const numLittle = comptime Bytes.init(0x12345678);
40 assertOrPanic(std.mem.eql(u8, []u8{ 0x78, 0x56, 0x34, 0x12 }, numLittle.bytes));
40 expect(std.mem.eql(u8, []u8{ 0x78, 0x56, 0x34, 0x12 }, numLittle.bytes));
4141}
4242
4343const Bytes = struct {
test/stage1/behavior/pub_enum/index.zig+3-3
......@@ -1,13 +1,13 @@
11const other = @import("other.zig");
2const assertOrPanic = @import("std").debug.assertOrPanic;
2const expect = @import("std").testing.expect;
33
44test "pub enum" {
55 pubEnumTest(other.APubEnum.Two);
66}
77fn pubEnumTest(foo: other.APubEnum) void {
8 assertOrPanic(foo == other.APubEnum.Two);
8 expect(foo == other.APubEnum.Two);
99}
1010
1111test "cast with imported symbol" {
12 assertOrPanic(other.size_t(42) == 42);
12 expect(other.size_t(42) == 42);
1313}
test/stage1/behavior/ref_var_in_if_after_if_2nd_switch_prong.zig+5-5
......@@ -1,14 +1,14 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;
1const expect = @import("std").testing.expect;
22const mem = @import("std").mem;
33
44var ok: bool = false;
55test "reference a variable in an if after an if in the 2nd switch prong" {
66 foo(true, Num.Two, false, "aoeu");
7 assertOrPanic(!ok);
7 expect(!ok);
88 foo(false, Num.One, false, "aoeu");
9 assertOrPanic(!ok);
9 expect(!ok);
1010 foo(true, Num.One, false, "aoeu");
11 assertOrPanic(ok);
11 expect(ok);
1212}
1313
1414const Num = enum {
......@@ -32,6 +32,6 @@ fn foo(c: bool, k: Num, c2: bool, b: []const u8) void {
3232}
3333
3434fn a(x: []const u8) void {
35 assertOrPanic(mem.eql(u8, x, "aoeu"));
35 expect(mem.eql(u8, x, "aoeu"));
3636 ok = true;
3737}
test/stage1/behavior/reflection.zig+39-39
......@@ -1,25 +1,25 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;
1const expect = @import("std").testing.expect;
22const mem = @import("std").mem;
33const reflection = @This();
44
55test "reflection: array, pointer, optional, error union type child" {
66 comptime {
7 assertOrPanic(([10]u8).Child == u8);
8 assertOrPanic((*u8).Child == u8);
9 assertOrPanic((anyerror!u8).Payload == u8);
10 assertOrPanic((?u8).Child == u8);
7 expect(([10]u8).Child == u8);
8 expect((*u8).Child == u8);
9 expect((anyerror!u8).Payload == u8);
10 expect((?u8).Child == u8);
1111 }
1212}
1313
1414test "reflection: function return type, var args, and param types" {
1515 comptime {
16 assertOrPanic(@typeOf(dummy).ReturnType == i32);
17 assertOrPanic(!@typeOf(dummy).is_var_args);
18 assertOrPanic(@typeOf(dummy_varargs).is_var_args);
19 assertOrPanic(@typeOf(dummy).arg_count == 3);
20 assertOrPanic(@ArgType(@typeOf(dummy), 0) == bool);
21 assertOrPanic(@ArgType(@typeOf(dummy), 1) == i32);
22 assertOrPanic(@ArgType(@typeOf(dummy), 2) == f32);
16 expect(@typeOf(dummy).ReturnType == i32);
17 expect(!@typeOf(dummy).is_var_args);
18 expect(@typeOf(dummy_varargs).is_var_args);
19 expect(@typeOf(dummy).arg_count == 3);
20 expect(@ArgType(@typeOf(dummy), 0) == bool);
21 expect(@ArgType(@typeOf(dummy), 1) == i32);
22 expect(@ArgType(@typeOf(dummy), 2) == f32);
2323 }
2424}
2525
......@@ -30,31 +30,31 @@ fn dummy_varargs(args: ...) void {}
3030
3131test "reflection: struct member types and names" {
3232 comptime {
33 assertOrPanic(@memberCount(Foo) == 3);
33 expect(@memberCount(Foo) == 3);
3434
35 assertOrPanic(@memberType(Foo, 0) == i32);
36 assertOrPanic(@memberType(Foo, 1) == bool);
37 assertOrPanic(@memberType(Foo, 2) == void);
35 expect(@memberType(Foo, 0) == i32);
36 expect(@memberType(Foo, 1) == bool);
37 expect(@memberType(Foo, 2) == void);
3838
39 assertOrPanic(mem.eql(u8, @memberName(Foo, 0), "one"));
40 assertOrPanic(mem.eql(u8, @memberName(Foo, 1), "two"));
41 assertOrPanic(mem.eql(u8, @memberName(Foo, 2), "three"));
39 expect(mem.eql(u8, @memberName(Foo, 0), "one"));
40 expect(mem.eql(u8, @memberName(Foo, 1), "two"));
41 expect(mem.eql(u8, @memberName(Foo, 2), "three"));
4242 }
4343}
4444
4545test "reflection: enum member types and names" {
4646 comptime {
47 assertOrPanic(@memberCount(Bar) == 4);
47 expect(@memberCount(Bar) == 4);
4848
49 assertOrPanic(@memberType(Bar, 0) == void);
50 assertOrPanic(@memberType(Bar, 1) == i32);
51 assertOrPanic(@memberType(Bar, 2) == bool);
52 assertOrPanic(@memberType(Bar, 3) == f64);
49 expect(@memberType(Bar, 0) == void);
50 expect(@memberType(Bar, 1) == i32);
51 expect(@memberType(Bar, 2) == bool);
52 expect(@memberType(Bar, 3) == f64);
5353
54 assertOrPanic(mem.eql(u8, @memberName(Bar, 0), "One"));
55 assertOrPanic(mem.eql(u8, @memberName(Bar, 1), "Two"));
56 assertOrPanic(mem.eql(u8, @memberName(Bar, 2), "Three"));
57 assertOrPanic(mem.eql(u8, @memberName(Bar, 3), "Four"));
54 expect(mem.eql(u8, @memberName(Bar, 0), "One"));
55 expect(mem.eql(u8, @memberName(Bar, 1), "Two"));
56 expect(mem.eql(u8, @memberName(Bar, 2), "Three"));
57 expect(mem.eql(u8, @memberName(Bar, 3), "Four"));
5858 }
5959}
6060
......@@ -65,18 +65,18 @@ test "reflection: @field" {
6565 .three = void{},
6666 };
6767
68 assertOrPanic(f.one == f.one);
69 assertOrPanic(@field(f, "o" ++ "ne") == f.one);
70 assertOrPanic(@field(f, "t" ++ "wo") == f.two);
71 assertOrPanic(@field(f, "th" ++ "ree") == f.three);
72 assertOrPanic(@field(Foo, "const" ++ "ant") == Foo.constant);
73 assertOrPanic(@field(Bar, "O" ++ "ne") == Bar.One);
74 assertOrPanic(@field(Bar, "T" ++ "wo") == Bar.Two);
75 assertOrPanic(@field(Bar, "Th" ++ "ree") == Bar.Three);
76 assertOrPanic(@field(Bar, "F" ++ "our") == Bar.Four);
77 assertOrPanic(@field(reflection, "dum" ++ "my")(true, 1, 2) == dummy(true, 1, 2));
68 expect(f.one == f.one);
69 expect(@field(f, "o" ++ "ne") == f.one);
70 expect(@field(f, "t" ++ "wo") == f.two);
71 expect(@field(f, "th" ++ "ree") == f.three);
72 expect(@field(Foo, "const" ++ "ant") == Foo.constant);
73 expect(@field(Bar, "O" ++ "ne") == Bar.One);
74 expect(@field(Bar, "T" ++ "wo") == Bar.Two);
75 expect(@field(Bar, "Th" ++ "ree") == Bar.Three);
76 expect(@field(Bar, "F" ++ "our") == Bar.Four);
77 expect(@field(reflection, "dum" ++ "my")(true, 1, 2) == dummy(true, 1, 2));
7878 @field(f, "o" ++ "ne") = 4;
79 assertOrPanic(f.one == 4);
79 expect(f.one == 4);
8080}
8181
8282const Foo = struct {
test/stage1/behavior/sizeof_and_typeof.zig+30-30
......@@ -1,9 +1,9 @@
11const builtin = @import("builtin");
2const assertOrPanic = @import("std").debug.assertOrPanic;
2const expect = @import("std").testing.expect;
33
44test "@sizeOf and @typeOf" {
55 const y: @typeOf(x) = 120;
6 assertOrPanic(@sizeOf(@typeOf(y)) == 2);
6 expect(@sizeOf(@typeOf(y)) == 2);
77}
88const x: u16 = 13;
99const z: @typeOf(x) = 19;
......@@ -30,40 +30,40 @@ const P = packed struct {
3030
3131test "@byteOffsetOf" {
3232 // Packed structs have fixed memory layout
33 assertOrPanic(@byteOffsetOf(P, "a") == 0);
34 assertOrPanic(@byteOffsetOf(P, "b") == 1);
35 assertOrPanic(@byteOffsetOf(P, "c") == 5);
36 assertOrPanic(@byteOffsetOf(P, "d") == 6);
37 assertOrPanic(@byteOffsetOf(P, "e") == 6);
38 assertOrPanic(@byteOffsetOf(P, "f") == 7);
39 assertOrPanic(@byteOffsetOf(P, "g") == 9);
33 expect(@byteOffsetOf(P, "a") == 0);
34 expect(@byteOffsetOf(P, "b") == 1);
35 expect(@byteOffsetOf(P, "c") == 5);
36 expect(@byteOffsetOf(P, "d") == 6);
37 expect(@byteOffsetOf(P, "e") == 6);
38 expect(@byteOffsetOf(P, "f") == 7);
39 expect(@byteOffsetOf(P, "g") == 9);
4040
4141 // Normal struct fields can be moved/padded
4242 var a: A = undefined;
43 assertOrPanic(@ptrToInt(&a.a) - @ptrToInt(&a) == @byteOffsetOf(A, "a"));
44 assertOrPanic(@ptrToInt(&a.b) - @ptrToInt(&a) == @byteOffsetOf(A, "b"));
45 assertOrPanic(@ptrToInt(&a.c) - @ptrToInt(&a) == @byteOffsetOf(A, "c"));
46 assertOrPanic(@ptrToInt(&a.d) - @ptrToInt(&a) == @byteOffsetOf(A, "d"));
47 assertOrPanic(@ptrToInt(&a.e) - @ptrToInt(&a) == @byteOffsetOf(A, "e"));
48 assertOrPanic(@ptrToInt(&a.f) - @ptrToInt(&a) == @byteOffsetOf(A, "f"));
49 assertOrPanic(@ptrToInt(&a.g) - @ptrToInt(&a) == @byteOffsetOf(A, "g"));
43 expect(@ptrToInt(&a.a) - @ptrToInt(&a) == @byteOffsetOf(A, "a"));
44 expect(@ptrToInt(&a.b) - @ptrToInt(&a) == @byteOffsetOf(A, "b"));
45 expect(@ptrToInt(&a.c) - @ptrToInt(&a) == @byteOffsetOf(A, "c"));
46 expect(@ptrToInt(&a.d) - @ptrToInt(&a) == @byteOffsetOf(A, "d"));
47 expect(@ptrToInt(&a.e) - @ptrToInt(&a) == @byteOffsetOf(A, "e"));
48 expect(@ptrToInt(&a.f) - @ptrToInt(&a) == @byteOffsetOf(A, "f"));
49 expect(@ptrToInt(&a.g) - @ptrToInt(&a) == @byteOffsetOf(A, "g"));
5050}
5151
5252test "@bitOffsetOf" {
5353 // Packed structs have fixed memory layout
54 assertOrPanic(@bitOffsetOf(P, "a") == 0);
55 assertOrPanic(@bitOffsetOf(P, "b") == 8);
56 assertOrPanic(@bitOffsetOf(P, "c") == 40);
57 assertOrPanic(@bitOffsetOf(P, "d") == 48);
58 assertOrPanic(@bitOffsetOf(P, "e") == 51);
59 assertOrPanic(@bitOffsetOf(P, "f") == 56);
60 assertOrPanic(@bitOffsetOf(P, "g") == 72);
54 expect(@bitOffsetOf(P, "a") == 0);
55 expect(@bitOffsetOf(P, "b") == 8);
56 expect(@bitOffsetOf(P, "c") == 40);
57 expect(@bitOffsetOf(P, "d") == 48);
58 expect(@bitOffsetOf(P, "e") == 51);
59 expect(@bitOffsetOf(P, "f") == 56);
60 expect(@bitOffsetOf(P, "g") == 72);
6161
62 assertOrPanic(@byteOffsetOf(A, "a") * 8 == @bitOffsetOf(A, "a"));
63 assertOrPanic(@byteOffsetOf(A, "b") * 8 == @bitOffsetOf(A, "b"));
64 assertOrPanic(@byteOffsetOf(A, "c") * 8 == @bitOffsetOf(A, "c"));
65 assertOrPanic(@byteOffsetOf(A, "d") * 8 == @bitOffsetOf(A, "d"));
66 assertOrPanic(@byteOffsetOf(A, "e") * 8 == @bitOffsetOf(A, "e"));
67 assertOrPanic(@byteOffsetOf(A, "f") * 8 == @bitOffsetOf(A, "f"));
68 assertOrPanic(@byteOffsetOf(A, "g") * 8 == @bitOffsetOf(A, "g"));
62 expect(@byteOffsetOf(A, "a") * 8 == @bitOffsetOf(A, "a"));
63 expect(@byteOffsetOf(A, "b") * 8 == @bitOffsetOf(A, "b"));
64 expect(@byteOffsetOf(A, "c") * 8 == @bitOffsetOf(A, "c"));
65 expect(@byteOffsetOf(A, "d") * 8 == @bitOffsetOf(A, "d"));
66 expect(@byteOffsetOf(A, "e") * 8 == @bitOffsetOf(A, "e"));
67 expect(@byteOffsetOf(A, "f") * 8 == @bitOffsetOf(A, "f"));
68 expect(@byteOffsetOf(A, "g") * 8 == @bitOffsetOf(A, "g"));
6969}
test/stage1/behavior/slice.zig+8-8
......@@ -1,20 +1,20 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;
1const expect = @import("std").testing.expect;
22const mem = @import("std").mem;
33
44const x = @intToPtr([*]i32, 0x1000)[0..0x500];
55const y = x[0x100..];
66test "compile time slice of pointer to hard coded address" {
7 assertOrPanic(@ptrToInt(x.ptr) == 0x1000);
8 assertOrPanic(x.len == 0x500);
7 expect(@ptrToInt(x.ptr) == 0x1000);
8 expect(x.len == 0x500);
99
10 assertOrPanic(@ptrToInt(y.ptr) == 0x1100);
11 assertOrPanic(y.len == 0x400);
10 expect(@ptrToInt(y.ptr) == 0x1100);
11 expect(y.len == 0x400);
1212}
1313
1414test "slice child property" {
1515 var array: [5]i32 = undefined;
1616 var slice = array[0..];
17 assertOrPanic(@typeOf(slice).Child == i32);
17 expect(@typeOf(slice).Child == i32);
1818}
1919
2020test "runtime safety lets us slice from len..len" {
......@@ -23,7 +23,7 @@ test "runtime safety lets us slice from len..len" {
2323 2,
2424 3,
2525 };
26 assertOrPanic(mem.eql(u8, sliceFromLenToLen(an_array[0..], 3, 3), ""));
26 expect(mem.eql(u8, sliceFromLenToLen(an_array[0..], 3, 3), ""));
2727}
2828
2929fn sliceFromLenToLen(a_slice: []u8, start: usize, end: usize) []u8 {
......@@ -36,5 +36,5 @@ test "implicitly cast array of size 0 to slice" {
3636}
3737
3838fn assertLenIsZero(msg: []const u8) void {
39 assertOrPanic(msg.len == 0);
39 expect(msg.len == 0);
4040}
test/stage1/behavior/struct.zig+92-92
......@@ -1,5 +1,5 @@
11const std = @import("std");
2const assertOrPanic = std.debug.assertOrPanic;
2const expect = std.testing.expect;
33const builtin = @import("builtin");
44const maxInt = std.math.maxInt;
55
......@@ -12,7 +12,7 @@ const empty_global_instance = StructWithNoFields{};
1212
1313test "call struct static method" {
1414 const result = StructWithNoFields.add(3, 4);
15 assertOrPanic(result == 7);
15 expect(result == 7);
1616}
1717
1818test "return empty struct instance" {
......@@ -25,7 +25,7 @@ fn returnEmptyStructInstance() StructWithNoFields {
2525const should_be_11 = StructWithNoFields.add(5, 6);
2626
2727test "invoke static method in global scope" {
28 assertOrPanic(should_be_11 == 11);
28 expect(should_be_11 == 11);
2929}
3030
3131test "void struct fields" {
......@@ -34,8 +34,8 @@ test "void struct fields" {
3434 .b = 1,
3535 .c = void{},
3636 };
37 assertOrPanic(foo.b == 1);
38 assertOrPanic(@sizeOf(VoidStructFieldsFoo) == 4);
37 expect(foo.b == 1);
38 expect(@sizeOf(VoidStructFieldsFoo) == 4);
3939}
4040const VoidStructFieldsFoo = struct {
4141 a: void,
......@@ -50,7 +50,7 @@ test "structs" {
5050 foo.b = foo.a == 1;
5151 testFoo(foo);
5252 testMutation(&foo);
53 assertOrPanic(foo.c == 100);
53 expect(foo.c == 100);
5454}
5555const StructFoo = struct {
5656 a: i32,
......@@ -58,7 +58,7 @@ const StructFoo = struct {
5858 c: f32,
5959};
6060fn testFoo(foo: StructFoo) void {
61 assertOrPanic(foo.b);
61 expect(foo.b);
6262}
6363fn testMutation(foo: *StructFoo) void {
6464 foo.c = 100;
......@@ -83,7 +83,7 @@ test "struct point to self" {
8383
8484 root.next = &node;
8585
86 assertOrPanic(node.next.next.next.val.x == 1);
86 expect(node.next.next.next.val.x == 1);
8787}
8888
8989test "struct byval assign" {
......@@ -92,18 +92,18 @@ test "struct byval assign" {
9292
9393 foo1.a = 1234;
9494 foo2.a = 0;
95 assertOrPanic(foo2.a == 0);
95 expect(foo2.a == 0);
9696 foo2 = foo1;
97 assertOrPanic(foo2.a == 1234);
97 expect(foo2.a == 1234);
9898}
9999
100100fn structInitializer() void {
101101 const val = Val{ .x = 42 };
102 assertOrPanic(val.x == 42);
102 expect(val.x == 42);
103103}
104104
105105test "fn call of struct field" {
106 assertOrPanic(callStructField(Foo{ .ptr = aFunc }) == 13);
106 expect(callStructField(Foo{ .ptr = aFunc }) == 13);
107107}
108108
109109const Foo = struct {
......@@ -122,7 +122,7 @@ test "store member function in variable" {
122122 const instance = MemberFnTestFoo{ .x = 1234 };
123123 const memberFn = MemberFnTestFoo.member;
124124 const result = memberFn(instance);
125 assertOrPanic(result == 1234);
125 expect(result == 1234);
126126}
127127const MemberFnTestFoo = struct {
128128 x: i32,
......@@ -134,12 +134,12 @@ const MemberFnTestFoo = struct {
134134test "call member function directly" {
135135 const instance = MemberFnTestFoo{ .x = 1234 };
136136 const result = MemberFnTestFoo.member(instance);
137 assertOrPanic(result == 1234);
137 expect(result == 1234);
138138}
139139
140140test "member functions" {
141141 const r = MemberFnRand{ .seed = 1234 };
142 assertOrPanic(r.getSeed() == 1234);
142 expect(r.getSeed() == 1234);
143143}
144144const MemberFnRand = struct {
145145 seed: u32,
......@@ -150,7 +150,7 @@ const MemberFnRand = struct {
150150
151151test "return struct byval from function" {
152152 const bar = makeBar(1234, 5678);
153 assertOrPanic(bar.y == 5678);
153 expect(bar.y == 5678);
154154}
155155const Bar = struct {
156156 x: i32,
......@@ -165,7 +165,7 @@ fn makeBar(x: i32, y: i32) Bar {
165165
166166test "empty struct method call" {
167167 const es = EmptyStruct{};
168 assertOrPanic(es.method() == 1234);
168 expect(es.method() == 1234);
169169}
170170const EmptyStruct = struct {
171171 fn method(es: *const EmptyStruct) i32 {
......@@ -182,7 +182,7 @@ fn testReturnEmptyStructFromFn() EmptyStruct2 {
182182}
183183
184184test "pass slice of empty struct to fn" {
185 assertOrPanic(testPassSliceOfEmptyStructToFn([]EmptyStruct2{EmptyStruct2{}}) == 1);
185 expect(testPassSliceOfEmptyStructToFn([]EmptyStruct2{EmptyStruct2{}}) == 1);
186186}
187187fn testPassSliceOfEmptyStructToFn(slice: []const EmptyStruct2) usize {
188188 return slice.len;
......@@ -200,7 +200,7 @@ test "packed struct" {
200200 };
201201 foo.y += 1;
202202 const four = foo.x + foo.y;
203 assertOrPanic(four == 4);
203 expect(four == 4);
204204}
205205
206206const BitField1 = packed struct {
......@@ -217,17 +217,17 @@ const bit_field_1 = BitField1{
217217
218218test "bit field access" {
219219 var data = bit_field_1;
220 assertOrPanic(getA(&data) == 1);
221 assertOrPanic(getB(&data) == 2);
222 assertOrPanic(getC(&data) == 3);
223 comptime assertOrPanic(@sizeOf(BitField1) == 1);
220 expect(getA(&data) == 1);
221 expect(getB(&data) == 2);
222 expect(getC(&data) == 3);
223 comptime expect(@sizeOf(BitField1) == 1);
224224
225225 data.b += 1;
226 assertOrPanic(data.b == 3);
226 expect(data.b == 3);
227227
228228 data.a += 1;
229 assertOrPanic(data.a == 2);
230 assertOrPanic(data.b == 3);
229 expect(data.a == 2);
230 expect(data.b == 3);
231231}
232232
233233fn getA(data: *const BitField1) u3 {
......@@ -254,8 +254,8 @@ const Foo96Bits = packed struct {
254254
255255test "packed struct 24bits" {
256256 comptime {
257 assertOrPanic(@sizeOf(Foo24Bits) == 3);
258 assertOrPanic(@sizeOf(Foo96Bits) == 12);
257 expect(@sizeOf(Foo24Bits) == 3);
258 expect(@sizeOf(Foo96Bits) == 12);
259259 }
260260
261261 var value = Foo96Bits{
......@@ -265,28 +265,28 @@ test "packed struct 24bits" {
265265 .d = 0,
266266 };
267267 value.a += 1;
268 assertOrPanic(value.a == 1);
269 assertOrPanic(value.b == 0);
270 assertOrPanic(value.c == 0);
271 assertOrPanic(value.d == 0);
268 expect(value.a == 1);
269 expect(value.b == 0);
270 expect(value.c == 0);
271 expect(value.d == 0);
272272
273273 value.b += 1;
274 assertOrPanic(value.a == 1);
275 assertOrPanic(value.b == 1);
276 assertOrPanic(value.c == 0);
277 assertOrPanic(value.d == 0);
274 expect(value.a == 1);
275 expect(value.b == 1);
276 expect(value.c == 0);
277 expect(value.d == 0);
278278
279279 value.c += 1;
280 assertOrPanic(value.a == 1);
281 assertOrPanic(value.b == 1);
282 assertOrPanic(value.c == 1);
283 assertOrPanic(value.d == 0);
280 expect(value.a == 1);
281 expect(value.b == 1);
282 expect(value.c == 1);
283 expect(value.d == 0);
284284
285285 value.d += 1;
286 assertOrPanic(value.a == 1);
287 assertOrPanic(value.b == 1);
288 assertOrPanic(value.c == 1);
289 assertOrPanic(value.d == 1);
286 expect(value.a == 1);
287 expect(value.b == 1);
288 expect(value.c == 1);
289 expect(value.d == 1);
290290}
291291
292292const FooArray24Bits = packed struct {
......@@ -297,43 +297,43 @@ const FooArray24Bits = packed struct {
297297
298298test "packed array 24bits" {
299299 comptime {
300 assertOrPanic(@sizeOf([9]Foo24Bits) == 9 * 3);
301 assertOrPanic(@sizeOf(FooArray24Bits) == 2 + 2 * 3 + 2);
300 expect(@sizeOf([9]Foo24Bits) == 9 * 3);
301 expect(@sizeOf(FooArray24Bits) == 2 + 2 * 3 + 2);
302302 }
303303
304304 var bytes = []u8{0} ** (@sizeOf(FooArray24Bits) + 1);
305305 bytes[bytes.len - 1] = 0xaa;
306306 const ptr = &@bytesToSlice(FooArray24Bits, bytes[0 .. bytes.len - 1])[0];
307 assertOrPanic(ptr.a == 0);
308 assertOrPanic(ptr.b[0].field == 0);
309 assertOrPanic(ptr.b[1].field == 0);
310 assertOrPanic(ptr.c == 0);
307 expect(ptr.a == 0);
308 expect(ptr.b[0].field == 0);
309 expect(ptr.b[1].field == 0);
310 expect(ptr.c == 0);
311311
312312 ptr.a = maxInt(u16);
313 assertOrPanic(ptr.a == maxInt(u16));
314 assertOrPanic(ptr.b[0].field == 0);
315 assertOrPanic(ptr.b[1].field == 0);
316 assertOrPanic(ptr.c == 0);
313 expect(ptr.a == maxInt(u16));
314 expect(ptr.b[0].field == 0);
315 expect(ptr.b[1].field == 0);
316 expect(ptr.c == 0);
317317
318318 ptr.b[0].field = maxInt(u24);
319 assertOrPanic(ptr.a == maxInt(u16));
320 assertOrPanic(ptr.b[0].field == maxInt(u24));
321 assertOrPanic(ptr.b[1].field == 0);
322 assertOrPanic(ptr.c == 0);
319 expect(ptr.a == maxInt(u16));
320 expect(ptr.b[0].field == maxInt(u24));
321 expect(ptr.b[1].field == 0);
322 expect(ptr.c == 0);
323323
324324 ptr.b[1].field = maxInt(u24);
325 assertOrPanic(ptr.a == maxInt(u16));
326 assertOrPanic(ptr.b[0].field == maxInt(u24));
327 assertOrPanic(ptr.b[1].field == maxInt(u24));
328 assertOrPanic(ptr.c == 0);
325 expect(ptr.a == maxInt(u16));
326 expect(ptr.b[0].field == maxInt(u24));
327 expect(ptr.b[1].field == maxInt(u24));
328 expect(ptr.c == 0);
329329
330330 ptr.c = maxInt(u16);
331 assertOrPanic(ptr.a == maxInt(u16));
332 assertOrPanic(ptr.b[0].field == maxInt(u24));
333 assertOrPanic(ptr.b[1].field == maxInt(u24));
334 assertOrPanic(ptr.c == maxInt(u16));
331 expect(ptr.a == maxInt(u16));
332 expect(ptr.b[0].field == maxInt(u24));
333 expect(ptr.b[1].field == maxInt(u24));
334 expect(ptr.c == maxInt(u16));
335335
336 assertOrPanic(bytes[bytes.len - 1] == 0xaa);
336 expect(bytes[bytes.len - 1] == 0xaa);
337337}
338338
339339const FooStructAligned = packed struct {
......@@ -347,17 +347,17 @@ const FooArrayOfAligned = packed struct {
347347
348348test "aligned array of packed struct" {
349349 comptime {
350 assertOrPanic(@sizeOf(FooStructAligned) == 2);
351 assertOrPanic(@sizeOf(FooArrayOfAligned) == 2 * 2);
350 expect(@sizeOf(FooStructAligned) == 2);
351 expect(@sizeOf(FooArrayOfAligned) == 2 * 2);
352352 }
353353
354354 var bytes = []u8{0xbb} ** @sizeOf(FooArrayOfAligned);
355355 const ptr = &@bytesToSlice(FooArrayOfAligned, bytes[0..bytes.len])[0];
356356
357 assertOrPanic(ptr.a[0].a == 0xbb);
358 assertOrPanic(ptr.a[0].b == 0xbb);
359 assertOrPanic(ptr.a[1].a == 0xbb);
360 assertOrPanic(ptr.a[1].b == 0xbb);
357 expect(ptr.a[0].a == 0xbb);
358 expect(ptr.a[0].b == 0xbb);
359 expect(ptr.a[1].a == 0xbb);
360 expect(ptr.a[1].b == 0xbb);
361361}
362362
363363test "runtime struct initialization of bitfield" {
......@@ -370,10 +370,10 @@ test "runtime struct initialization of bitfield" {
370370 .y = @intCast(u4, x2),
371371 };
372372
373 assertOrPanic(s1.x == x1);
374 assertOrPanic(s1.y == x1);
375 assertOrPanic(s2.x == @intCast(u4, x2));
376 assertOrPanic(s2.y == @intCast(u4, x2));
373 expect(s1.x == x1);
374 expect(s1.y == x1);
375 expect(s2.x == @intCast(u4, x2));
376 expect(s2.y == @intCast(u4, x2));
377377}
378378
379379var x1 = u4(1);
......@@ -400,18 +400,18 @@ test "native bit field understands endianness" {
400400 @memcpy(bytes[0..].ptr, @ptrCast([*]u8, &all), 8);
401401 var bitfields = @ptrCast(*Bitfields, bytes[0..].ptr).*;
402402
403 assertOrPanic(bitfields.f1 == 0x1111);
404 assertOrPanic(bitfields.f2 == 0x2222);
405 assertOrPanic(bitfields.f3 == 0x33);
406 assertOrPanic(bitfields.f4 == 0x44);
407 assertOrPanic(bitfields.f5 == 0x5);
408 assertOrPanic(bitfields.f6 == 0x6);
409 assertOrPanic(bitfields.f7 == 0x77);
403 expect(bitfields.f1 == 0x1111);
404 expect(bitfields.f2 == 0x2222);
405 expect(bitfields.f3 == 0x33);
406 expect(bitfields.f4 == 0x44);
407 expect(bitfields.f5 == 0x5);
408 expect(bitfields.f6 == 0x6);
409 expect(bitfields.f7 == 0x77);
410410}
411411
412412test "align 1 field before self referential align 8 field as slice return type" {
413413 const result = alloc(Expr);
414 assertOrPanic(result.len == 0);
414 expect(result.len == 0);
415415}
416416
417417const Expr = union(enum) {
......@@ -434,10 +434,10 @@ test "call method with mutable reference to struct with no fields" {
434434 };
435435
436436 var s = S{};
437 assertOrPanic(S.doC(&s));
438 assertOrPanic(s.doC());
439 assertOrPanic(S.do(&s));
440 assertOrPanic(s.do());
437 expect(S.doC(&s));
438 expect(s.doC());
439 expect(S.do(&s));
440 expect(s.do());
441441}
442442
443443test "implicit cast packed struct field to const ptr" {
......@@ -453,7 +453,7 @@ test "implicit cast packed struct field to const ptr" {
453453 var lup: LevelUpMove = undefined;
454454 lup.level = 12;
455455 const res = LevelUpMove.toInt(lup.level);
456 assertOrPanic(res == 12);
456 expect(res == 12);
457457}
458458
459459test "pointer to packed struct member in a stack variable" {
......@@ -464,7 +464,7 @@ test "pointer to packed struct member in a stack variable" {
464464
465465 var s = S{ .a = 2, .b = 0 };
466466 var b_ptr = &s.b;
467 assertOrPanic(s.b == 0);
467 expect(s.b == 0);
468468 b_ptr.* = 2;
469 assertOrPanic(s.b == 2);
469 expect(s.b == 2);
470470}
test/stage1/behavior/struct_contains_null_ptr_itself.zig+2-2
......@@ -1,9 +1,9 @@
11const std = @import("std");
2const assertOrPanic = std.debug.assertOrPanic;
2const expect = std.testing.expect;
33
44test "struct contains null pointer which contains original struct" {
55 var x: ?*NodeLineComment = null;
6 assertOrPanic(x == null);
6 expect(x == null);
77}
88
99pub const Node = struct {
test/stage1/behavior/struct_contains_slice_of_itself.zig+13-13
......@@ -1,4 +1,4 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;
1const expect = @import("std").testing.expect;
22
33const Node = struct {
44 payload: i32,
......@@ -39,12 +39,12 @@ test "struct contains slice of itself" {
3939 .payload = 1234,
4040 .children = nodes[0..],
4141 };
42 assertOrPanic(root.payload == 1234);
43 assertOrPanic(root.children[0].payload == 1);
44 assertOrPanic(root.children[1].payload == 2);
45 assertOrPanic(root.children[2].payload == 3);
46 assertOrPanic(root.children[2].children[0].payload == 31);
47 assertOrPanic(root.children[2].children[1].payload == 32);
42 expect(root.payload == 1234);
43 expect(root.children[0].payload == 1);
44 expect(root.children[1].payload == 2);
45 expect(root.children[2].payload == 3);
46 expect(root.children[2].children[0].payload == 31);
47 expect(root.children[2].children[1].payload == 32);
4848}
4949
5050test "struct contains aligned slice of itself" {
......@@ -76,10 +76,10 @@ test "struct contains aligned slice of itself" {
7676 .payload = 1234,
7777 .children = nodes[0..],
7878 };
79 assertOrPanic(root.payload == 1234);
80 assertOrPanic(root.children[0].payload == 1);
81 assertOrPanic(root.children[1].payload == 2);
82 assertOrPanic(root.children[2].payload == 3);
83 assertOrPanic(root.children[2].children[0].payload == 31);
84 assertOrPanic(root.children[2].children[1].payload == 32);
79 expect(root.payload == 1234);
80 expect(root.children[0].payload == 1);
81 expect(root.children[1].payload == 2);
82 expect(root.children[2].payload == 3);
83 expect(root.children[2].children[0].payload == 31);
84 expect(root.children[2].children[1].payload == 32);
8585}
test/stage1/behavior/switch.zig+33-33
......@@ -1,4 +1,4 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;
1const expect = @import("std").testing.expect;
22
33test "switch with numbers" {
44 testSwitchWithNumbers(13);
......@@ -10,14 +10,14 @@ fn testSwitchWithNumbers(x: u32) void {
1010 13 => true,
1111 else => false,
1212 };
13 assertOrPanic(result);
13 expect(result);
1414}
1515
1616test "switch with all ranges" {
17 assertOrPanic(testSwitchWithAllRanges(50, 3) == 1);
18 assertOrPanic(testSwitchWithAllRanges(101, 0) == 2);
19 assertOrPanic(testSwitchWithAllRanges(300, 5) == 3);
20 assertOrPanic(testSwitchWithAllRanges(301, 6) == 6);
17 expect(testSwitchWithAllRanges(50, 3) == 1);
18 expect(testSwitchWithAllRanges(101, 0) == 2);
19 expect(testSwitchWithAllRanges(300, 5) == 3);
20 expect(testSwitchWithAllRanges(301, 6) == 6);
2121}
2222
2323fn testSwitchWithAllRanges(x: u32, y: u32) u32 {
......@@ -40,7 +40,7 @@ test "implicit comptime switch" {
4040 };
4141
4242 comptime {
43 assertOrPanic(result + 1 == 14);
43 expect(result + 1 == 14);
4444 }
4545}
4646
......@@ -71,7 +71,7 @@ fn nonConstSwitch(foo: SwitchStatmentFoo) void {
7171 SwitchStatmentFoo.C => 3,
7272 SwitchStatmentFoo.D => 4,
7373 };
74 assertOrPanic(val == 3);
74 expect(val == 3);
7575}
7676const SwitchStatmentFoo = enum {
7777 A,
......@@ -93,10 +93,10 @@ const SwitchProngWithVarEnum = union(enum) {
9393fn switchProngWithVarFn(a: SwitchProngWithVarEnum) void {
9494 switch (a) {
9595 SwitchProngWithVarEnum.One => |x| {
96 assertOrPanic(x == 13);
96 expect(x == 13);
9797 },
9898 SwitchProngWithVarEnum.Two => |x| {
99 assertOrPanic(x == 13.0);
99 expect(x == 13.0);
100100 },
101101 SwitchProngWithVarEnum.Meh => |x| {
102102 const v: void = x;
......@@ -116,7 +116,7 @@ fn testSwitchEnumPtrCapture() void {
116116 else => unreachable,
117117 }
118118 switch (value) {
119 SwitchProngWithVarEnum.One => |x| assertOrPanic(x == 1235),
119 SwitchProngWithVarEnum.One => |x| expect(x == 1235),
120120 else => unreachable,
121121 }
122122}
......@@ -127,7 +127,7 @@ test "switch with multiple expressions" {
127127 4, 5, 6 => 2,
128128 else => i32(3),
129129 };
130 assertOrPanic(x == 2);
130 expect(x == 2);
131131}
132132fn returnsFive() i32 {
133133 return 5;
......@@ -149,12 +149,12 @@ fn returnsFalse() bool {
149149 }
150150}
151151test "switch on const enum with var" {
152 assertOrPanic(!returnsFalse());
152 expect(!returnsFalse());
153153}
154154
155155test "switch on type" {
156 assertOrPanic(trueIfBoolFalseOtherwise(bool));
157 assertOrPanic(!trueIfBoolFalseOtherwise(i32));
156 expect(trueIfBoolFalseOtherwise(bool));
157 expect(!trueIfBoolFalseOtherwise(i32));
158158}
159159
160160fn trueIfBoolFalseOtherwise(comptime T: type) bool {
......@@ -170,16 +170,16 @@ test "switch handles all cases of number" {
170170}
171171
172172fn testSwitchHandleAllCases() void {
173 assertOrPanic(testSwitchHandleAllCasesExhaustive(0) == 3);
174 assertOrPanic(testSwitchHandleAllCasesExhaustive(1) == 2);
175 assertOrPanic(testSwitchHandleAllCasesExhaustive(2) == 1);
176 assertOrPanic(testSwitchHandleAllCasesExhaustive(3) == 0);
173 expect(testSwitchHandleAllCasesExhaustive(0) == 3);
174 expect(testSwitchHandleAllCasesExhaustive(1) == 2);
175 expect(testSwitchHandleAllCasesExhaustive(2) == 1);
176 expect(testSwitchHandleAllCasesExhaustive(3) == 0);
177177
178 assertOrPanic(testSwitchHandleAllCasesRange(100) == 0);
179 assertOrPanic(testSwitchHandleAllCasesRange(200) == 1);
180 assertOrPanic(testSwitchHandleAllCasesRange(201) == 2);
181 assertOrPanic(testSwitchHandleAllCasesRange(202) == 4);
182 assertOrPanic(testSwitchHandleAllCasesRange(230) == 3);
178 expect(testSwitchHandleAllCasesRange(100) == 0);
179 expect(testSwitchHandleAllCasesRange(200) == 1);
180 expect(testSwitchHandleAllCasesRange(201) == 2);
181 expect(testSwitchHandleAllCasesRange(202) == 4);
182 expect(testSwitchHandleAllCasesRange(230) == 3);
183183}
184184
185185fn testSwitchHandleAllCasesExhaustive(x: u2) u2 {
......@@ -207,8 +207,8 @@ test "switch all prongs unreachable" {
207207}
208208
209209fn testAllProngsUnreachable() void {
210 assertOrPanic(switchWithUnreachable(1) == 2);
211 assertOrPanic(switchWithUnreachable(2) == 10);
210 expect(switchWithUnreachable(1) == 2);
211 expect(switchWithUnreachable(2) == 10);
212212}
213213
214214fn switchWithUnreachable(x: i32) i32 {
......@@ -230,7 +230,7 @@ test "capture value of switch with all unreachable prongs" {
230230 const x = return_a_number() catch |err| switch (err) {
231231 else => unreachable,
232232 };
233 assertOrPanic(x == 1);
233 expect(x == 1);
234234}
235235
236236test "switching on booleans" {
......@@ -239,14 +239,14 @@ test "switching on booleans" {
239239}
240240
241241fn testSwitchOnBools() void {
242 assertOrPanic(testSwitchOnBoolsTrueAndFalse(true) == false);
243 assertOrPanic(testSwitchOnBoolsTrueAndFalse(false) == true);
242 expect(testSwitchOnBoolsTrueAndFalse(true) == false);
243 expect(testSwitchOnBoolsTrueAndFalse(false) == true);
244244
245 assertOrPanic(testSwitchOnBoolsTrueWithElse(true) == false);
246 assertOrPanic(testSwitchOnBoolsTrueWithElse(false) == true);
245 expect(testSwitchOnBoolsTrueWithElse(true) == false);
246 expect(testSwitchOnBoolsTrueWithElse(false) == true);
247247
248 assertOrPanic(testSwitchOnBoolsFalseWithElse(true) == false);
249 assertOrPanic(testSwitchOnBoolsFalseWithElse(false) == true);
248 expect(testSwitchOnBoolsFalseWithElse(true) == false);
249 expect(testSwitchOnBoolsFalseWithElse(false) == true);
250250}
251251
252252fn testSwitchOnBoolsTrueAndFalse(x: bool) bool {
test/stage1/behavior/switch_prong_err_enum.zig+3-3
......@@ -1,4 +1,4 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;
1const expect = @import("std").testing.expect;
22
33var read_count: u64 = 0;
44
......@@ -22,9 +22,9 @@ fn doThing(form_id: u64) anyerror!FormValue {
2222test "switch prong returns error enum" {
2323 switch (doThing(17) catch unreachable) {
2424 FormValue.Address => |payload| {
25 assertOrPanic(payload == 1);
25 expect(payload == 1);
2626 },
2727 else => unreachable,
2828 }
29 assertOrPanic(read_count == 1);
29 expect(read_count == 1);
3030}
test/stage1/behavior/switch_prong_implicit_cast.zig+2-2
......@@ -1,4 +1,4 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;
1const expect = @import("std").testing.expect;
22
33const FormValue = union(enum) {
44 One: void,
......@@ -18,5 +18,5 @@ test "switch prong implicit cast" {
1818 FormValue.One => false,
1919 FormValue.Two => |x| x,
2020 };
21 assertOrPanic(result);
21 expect(result);
2222}
test/stage1/behavior/this.zig+4-4
......@@ -1,4 +1,4 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;
1const expect = @import("std").testing.expect;
22
33const module = @This();
44
......@@ -20,7 +20,7 @@ fn add(x: i32, y: i32) i32 {
2020}
2121
2222test "this refer to module call private fn" {
23 assertOrPanic(module.add(1, 2) == 3);
23 expect(module.add(1, 2) == 3);
2424}
2525
2626test "this refer to container" {
......@@ -29,7 +29,7 @@ test "this refer to container" {
2929 .y = 34,
3030 };
3131 pt.addOne();
32 assertOrPanic(pt.x == 13);
33 assertOrPanic(pt.y == 35);
32 expect(pt.x == 13);
33 expect(pt.y == 35);
3434}
3535
test/stage1/behavior/truncate.zig+2-2
......@@ -1,8 +1,8 @@
11const std = @import("std");
2const assertOrPanic = std.debug.assertOrPanic;
2const expect = std.testing.expect;
33
44test "truncate u0 to larger integer allowed and has comptime known result" {
55 var x: u0 = 0;
66 const y = @truncate(u8, x);
7 comptime assertOrPanic(y == 0);
7 comptime expect(y == 0);
88}
test/stage1/behavior/try.zig+5-5
......@@ -1,4 +1,4 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;
1const expect = @import("std").testing.expect;
22
33test "try on error union" {
44 tryOnErrorUnionImpl();
......@@ -11,7 +11,7 @@ fn tryOnErrorUnionImpl() void {
1111 error.CrappedOut => i32(2),
1212 else => unreachable,
1313 };
14 assertOrPanic(x == 11);
14 expect(x == 11);
1515}
1616
1717fn returnsTen() anyerror!i32 {
......@@ -20,10 +20,10 @@ fn returnsTen() anyerror!i32 {
2020
2121test "try without vars" {
2222 const result1 = if (failIfTrue(true)) 1 else |_| i32(2);
23 assertOrPanic(result1 == 2);
23 expect(result1 == 2);
2424
2525 const result2 = if (failIfTrue(false)) 1 else |_| i32(2);
26 assertOrPanic(result2 == 1);
26 expect(result2 == 1);
2727}
2828
2929fn failIfTrue(ok: bool) anyerror!void {
......@@ -38,6 +38,6 @@ test "try then not executed with assignment" {
3838 if (failIfTrue(true)) {
3939 unreachable;
4040 } else |err| {
41 assertOrPanic(err == error.ItBroke);
41 expect(err == error.ItBroke);
4242 }
4343}
test/stage1/behavior/type_info.zig+91-91
......@@ -1,4 +1,4 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;
1const expect = @import("std").testing.expect;
22const mem = @import("std").mem;
33const TypeInfo = @import("builtin").TypeInfo;
44const TypeId = @import("builtin").TypeId;
......@@ -9,10 +9,10 @@ test "type info: tag type, void info" {
99}
1010
1111fn testBasic() void {
12 assertOrPanic(@TagType(TypeInfo) == TypeId);
12 expect(@TagType(TypeInfo) == TypeId);
1313 const void_info = @typeInfo(void);
14 assertOrPanic(TypeId(void_info) == TypeId.Void);
15 assertOrPanic(void_info.Void == {});
14 expect(TypeId(void_info) == TypeId.Void);
15 expect(void_info.Void == {});
1616}
1717
1818test "type info: integer, floating point type info" {
......@@ -22,13 +22,13 @@ test "type info: integer, floating point type info" {
2222
2323fn testIntFloat() void {
2424 const u8_info = @typeInfo(u8);
25 assertOrPanic(TypeId(u8_info) == TypeId.Int);
26 assertOrPanic(!u8_info.Int.is_signed);
27 assertOrPanic(u8_info.Int.bits == 8);
25 expect(TypeId(u8_info) == TypeId.Int);
26 expect(!u8_info.Int.is_signed);
27 expect(u8_info.Int.bits == 8);
2828
2929 const f64_info = @typeInfo(f64);
30 assertOrPanic(TypeId(f64_info) == TypeId.Float);
31 assertOrPanic(f64_info.Float.bits == 64);
30 expect(TypeId(f64_info) == TypeId.Float);
31 expect(f64_info.Float.bits == 64);
3232}
3333
3434test "type info: pointer type info" {
......@@ -38,12 +38,12 @@ test "type info: pointer type info" {
3838
3939fn testPointer() void {
4040 const u32_ptr_info = @typeInfo(*u32);
41 assertOrPanic(TypeId(u32_ptr_info) == TypeId.Pointer);
42 assertOrPanic(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.One);
43 assertOrPanic(u32_ptr_info.Pointer.is_const == false);
44 assertOrPanic(u32_ptr_info.Pointer.is_volatile == false);
45 assertOrPanic(u32_ptr_info.Pointer.alignment == @alignOf(u32));
46 assertOrPanic(u32_ptr_info.Pointer.child == u32);
41 expect(TypeId(u32_ptr_info) == TypeId.Pointer);
42 expect(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.One);
43 expect(u32_ptr_info.Pointer.is_const == false);
44 expect(u32_ptr_info.Pointer.is_volatile == false);
45 expect(u32_ptr_info.Pointer.alignment == @alignOf(u32));
46 expect(u32_ptr_info.Pointer.child == u32);
4747}
4848
4949test "type info: unknown length pointer type info" {
......@@ -53,12 +53,12 @@ test "type info: unknown length pointer type info" {
5353
5454fn testUnknownLenPtr() void {
5555 const u32_ptr_info = @typeInfo([*]const volatile f64);
56 assertOrPanic(TypeId(u32_ptr_info) == TypeId.Pointer);
57 assertOrPanic(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.Many);
58 assertOrPanic(u32_ptr_info.Pointer.is_const == true);
59 assertOrPanic(u32_ptr_info.Pointer.is_volatile == true);
60 assertOrPanic(u32_ptr_info.Pointer.alignment == @alignOf(f64));
61 assertOrPanic(u32_ptr_info.Pointer.child == f64);
56 expect(TypeId(u32_ptr_info) == TypeId.Pointer);
57 expect(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.Many);
58 expect(u32_ptr_info.Pointer.is_const == true);
59 expect(u32_ptr_info.Pointer.is_volatile == true);
60 expect(u32_ptr_info.Pointer.alignment == @alignOf(f64));
61 expect(u32_ptr_info.Pointer.child == f64);
6262}
6363
6464test "type info: slice type info" {
......@@ -68,12 +68,12 @@ test "type info: slice type info" {
6868
6969fn testSlice() void {
7070 const u32_slice_info = @typeInfo([]u32);
71 assertOrPanic(TypeId(u32_slice_info) == TypeId.Pointer);
72 assertOrPanic(u32_slice_info.Pointer.size == TypeInfo.Pointer.Size.Slice);
73 assertOrPanic(u32_slice_info.Pointer.is_const == false);
74 assertOrPanic(u32_slice_info.Pointer.is_volatile == false);
75 assertOrPanic(u32_slice_info.Pointer.alignment == 4);
76 assertOrPanic(u32_slice_info.Pointer.child == u32);
71 expect(TypeId(u32_slice_info) == TypeId.Pointer);
72 expect(u32_slice_info.Pointer.size == TypeInfo.Pointer.Size.Slice);
73 expect(u32_slice_info.Pointer.is_const == false);
74 expect(u32_slice_info.Pointer.is_volatile == false);
75 expect(u32_slice_info.Pointer.alignment == 4);
76 expect(u32_slice_info.Pointer.child == u32);
7777}
7878
7979test "type info: array type info" {
......@@ -83,9 +83,9 @@ test "type info: array type info" {
8383
8484fn testArray() void {
8585 const arr_info = @typeInfo([42]bool);
86 assertOrPanic(TypeId(arr_info) == TypeId.Array);
87 assertOrPanic(arr_info.Array.len == 42);
88 assertOrPanic(arr_info.Array.child == bool);
86 expect(TypeId(arr_info) == TypeId.Array);
87 expect(arr_info.Array.len == 42);
88 expect(arr_info.Array.child == bool);
8989}
9090
9191test "type info: optional type info" {
......@@ -95,8 +95,8 @@ test "type info: optional type info" {
9595
9696fn testOptional() void {
9797 const null_info = @typeInfo(?void);
98 assertOrPanic(TypeId(null_info) == TypeId.Optional);
99 assertOrPanic(null_info.Optional.child == void);
98 expect(TypeId(null_info) == TypeId.Optional);
99 expect(null_info.Optional.child == void);
100100}
101101
102102test "type info: promise info" {
......@@ -106,12 +106,12 @@ test "type info: promise info" {
106106
107107fn testPromise() void {
108108 const null_promise_info = @typeInfo(promise);
109 assertOrPanic(TypeId(null_promise_info) == TypeId.Promise);
110 assertOrPanic(null_promise_info.Promise.child == null);
109 expect(TypeId(null_promise_info) == TypeId.Promise);
110 expect(null_promise_info.Promise.child == null);
111111
112112 const promise_info = @typeInfo(promise->usize);
113 assertOrPanic(TypeId(promise_info) == TypeId.Promise);
114 assertOrPanic(promise_info.Promise.child.? == usize);
113 expect(TypeId(promise_info) == TypeId.Promise);
114 expect(promise_info.Promise.child.? == usize);
115115}
116116
117117test "type info: error set, error union info" {
......@@ -127,15 +127,15 @@ fn testErrorSet() void {
127127 };
128128
129129 const error_set_info = @typeInfo(TestErrorSet);
130 assertOrPanic(TypeId(error_set_info) == TypeId.ErrorSet);
131 assertOrPanic(error_set_info.ErrorSet.errors.len == 3);
132 assertOrPanic(mem.eql(u8, error_set_info.ErrorSet.errors[0].name, "First"));
133 assertOrPanic(error_set_info.ErrorSet.errors[2].value == @errorToInt(TestErrorSet.Third));
130 expect(TypeId(error_set_info) == TypeId.ErrorSet);
131 expect(error_set_info.ErrorSet.errors.len == 3);
132 expect(mem.eql(u8, error_set_info.ErrorSet.errors[0].name, "First"));
133 expect(error_set_info.ErrorSet.errors[2].value == @errorToInt(TestErrorSet.Third));
134134
135135 const error_union_info = @typeInfo(TestErrorSet!usize);
136 assertOrPanic(TypeId(error_union_info) == TypeId.ErrorUnion);
137 assertOrPanic(error_union_info.ErrorUnion.error_set == TestErrorSet);
138 assertOrPanic(error_union_info.ErrorUnion.payload == usize);
136 expect(TypeId(error_union_info) == TypeId.ErrorUnion);
137 expect(error_union_info.ErrorUnion.error_set == TestErrorSet);
138 expect(error_union_info.ErrorUnion.payload == usize);
139139}
140140
141141test "type info: enum info" {
......@@ -152,13 +152,13 @@ fn testEnum() void {
152152 };
153153
154154 const os_info = @typeInfo(Os);
155 assertOrPanic(TypeId(os_info) == TypeId.Enum);
156 assertOrPanic(os_info.Enum.layout == TypeInfo.ContainerLayout.Auto);
157 assertOrPanic(os_info.Enum.fields.len == 4);
158 assertOrPanic(mem.eql(u8, os_info.Enum.fields[1].name, "Macos"));
159 assertOrPanic(os_info.Enum.fields[3].value == 3);
160 assertOrPanic(os_info.Enum.tag_type == u2);
161 assertOrPanic(os_info.Enum.defs.len == 0);
155 expect(TypeId(os_info) == TypeId.Enum);
156 expect(os_info.Enum.layout == TypeInfo.ContainerLayout.Auto);
157 expect(os_info.Enum.fields.len == 4);
158 expect(mem.eql(u8, os_info.Enum.fields[1].name, "Macos"));
159 expect(os_info.Enum.fields[3].value == 3);
160 expect(os_info.Enum.tag_type == u2);
161 expect(os_info.Enum.defs.len == 0);
162162}
163163
164164test "type info: union info" {
......@@ -168,14 +168,14 @@ test "type info: union info" {
168168
169169fn testUnion() void {
170170 const typeinfo_info = @typeInfo(TypeInfo);
171 assertOrPanic(TypeId(typeinfo_info) == TypeId.Union);
172 assertOrPanic(typeinfo_info.Union.layout == TypeInfo.ContainerLayout.Auto);
173 assertOrPanic(typeinfo_info.Union.tag_type.? == TypeId);
174 assertOrPanic(typeinfo_info.Union.fields.len == 25);
175 assertOrPanic(typeinfo_info.Union.fields[4].enum_field != null);
176 assertOrPanic(typeinfo_info.Union.fields[4].enum_field.?.value == 4);
177 assertOrPanic(typeinfo_info.Union.fields[4].field_type == @typeOf(@typeInfo(u8).Int));
178 assertOrPanic(typeinfo_info.Union.defs.len == 21);
171 expect(TypeId(typeinfo_info) == TypeId.Union);
172 expect(typeinfo_info.Union.layout == TypeInfo.ContainerLayout.Auto);
173 expect(typeinfo_info.Union.tag_type.? == TypeId);
174 expect(typeinfo_info.Union.fields.len == 25);
175 expect(typeinfo_info.Union.fields[4].enum_field != null);
176 expect(typeinfo_info.Union.fields[4].enum_field.?.value == 4);
177 expect(typeinfo_info.Union.fields[4].field_type == @typeOf(@typeInfo(u8).Int));
178 expect(typeinfo_info.Union.defs.len == 21);
179179
180180 const TestNoTagUnion = union {
181181 Foo: void,
......@@ -183,22 +183,22 @@ fn testUnion() void {
183183 };
184184
185185 const notag_union_info = @typeInfo(TestNoTagUnion);
186 assertOrPanic(TypeId(notag_union_info) == TypeId.Union);
187 assertOrPanic(notag_union_info.Union.tag_type == null);
188 assertOrPanic(notag_union_info.Union.layout == TypeInfo.ContainerLayout.Auto);
189 assertOrPanic(notag_union_info.Union.fields.len == 2);
190 assertOrPanic(notag_union_info.Union.fields[0].enum_field == null);
191 assertOrPanic(notag_union_info.Union.fields[1].field_type == u32);
186 expect(TypeId(notag_union_info) == TypeId.Union);
187 expect(notag_union_info.Union.tag_type == null);
188 expect(notag_union_info.Union.layout == TypeInfo.ContainerLayout.Auto);
189 expect(notag_union_info.Union.fields.len == 2);
190 expect(notag_union_info.Union.fields[0].enum_field == null);
191 expect(notag_union_info.Union.fields[1].field_type == u32);
192192
193193 const TestExternUnion = extern union {
194194 foo: *c_void,
195195 };
196196
197197 const extern_union_info = @typeInfo(TestExternUnion);
198 assertOrPanic(extern_union_info.Union.layout == TypeInfo.ContainerLayout.Extern);
199 assertOrPanic(extern_union_info.Union.tag_type == null);
200 assertOrPanic(extern_union_info.Union.fields[0].enum_field == null);
201 assertOrPanic(extern_union_info.Union.fields[0].field_type == *c_void);
198 expect(extern_union_info.Union.layout == TypeInfo.ContainerLayout.Extern);
199 expect(extern_union_info.Union.tag_type == null);
200 expect(extern_union_info.Union.fields[0].enum_field == null);
201 expect(extern_union_info.Union.fields[0].field_type == *c_void);
202202}
203203
204204test "type info: struct info" {
......@@ -208,17 +208,17 @@ test "type info: struct info" {
208208
209209fn testStruct() void {
210210 const struct_info = @typeInfo(TestStruct);
211 assertOrPanic(TypeId(struct_info) == TypeId.Struct);
212 assertOrPanic(struct_info.Struct.layout == TypeInfo.ContainerLayout.Packed);
213 assertOrPanic(struct_info.Struct.fields.len == 3);
214 assertOrPanic(struct_info.Struct.fields[1].offset == null);
215 assertOrPanic(struct_info.Struct.fields[2].field_type == *TestStruct);
216 assertOrPanic(struct_info.Struct.defs.len == 2);
217 assertOrPanic(struct_info.Struct.defs[0].is_pub);
218 assertOrPanic(!struct_info.Struct.defs[0].data.Fn.is_extern);
219 assertOrPanic(struct_info.Struct.defs[0].data.Fn.lib_name == null);
220 assertOrPanic(struct_info.Struct.defs[0].data.Fn.return_type == void);
221 assertOrPanic(struct_info.Struct.defs[0].data.Fn.fn_type == fn (*const TestStruct) void);
211 expect(TypeId(struct_info) == TypeId.Struct);
212 expect(struct_info.Struct.layout == TypeInfo.ContainerLayout.Packed);
213 expect(struct_info.Struct.fields.len == 3);
214 expect(struct_info.Struct.fields[1].offset == null);
215 expect(struct_info.Struct.fields[2].field_type == *TestStruct);
216 expect(struct_info.Struct.defs.len == 2);
217 expect(struct_info.Struct.defs[0].is_pub);
218 expect(!struct_info.Struct.defs[0].data.Fn.is_extern);
219 expect(struct_info.Struct.defs[0].data.Fn.lib_name == null);
220 expect(struct_info.Struct.defs[0].data.Fn.return_type == void);
221 expect(struct_info.Struct.defs[0].data.Fn.fn_type == fn (*const TestStruct) void);
222222}
223223
224224const TestStruct = packed struct {
......@@ -238,18 +238,18 @@ test "type info: function type info" {
238238
239239fn testFunction() void {
240240 const fn_info = @typeInfo(@typeOf(foo));
241 assertOrPanic(TypeId(fn_info) == TypeId.Fn);
242 assertOrPanic(fn_info.Fn.calling_convention == TypeInfo.CallingConvention.Unspecified);
243 assertOrPanic(fn_info.Fn.is_generic);
244 assertOrPanic(fn_info.Fn.args.len == 2);
245 assertOrPanic(fn_info.Fn.is_var_args);
246 assertOrPanic(fn_info.Fn.return_type == null);
247 assertOrPanic(fn_info.Fn.async_allocator_type == null);
241 expect(TypeId(fn_info) == TypeId.Fn);
242 expect(fn_info.Fn.calling_convention == TypeInfo.CallingConvention.Unspecified);
243 expect(fn_info.Fn.is_generic);
244 expect(fn_info.Fn.args.len == 2);
245 expect(fn_info.Fn.is_var_args);
246 expect(fn_info.Fn.return_type == null);
247 expect(fn_info.Fn.async_allocator_type == null);
248248
249249 const test_instance: TestStruct = undefined;
250250 const bound_fn_info = @typeInfo(@typeOf(test_instance.foo));
251 assertOrPanic(TypeId(bound_fn_info) == TypeId.BoundFn);
252 assertOrPanic(bound_fn_info.BoundFn.args[0].arg_type.? == *const TestStruct);
251 expect(TypeId(bound_fn_info) == TypeId.BoundFn);
252 expect(bound_fn_info.BoundFn.args[0].arg_type.? == *const TestStruct);
253253}
254254
255255fn foo(comptime a: usize, b: bool, args: ...) usize {
......@@ -270,7 +270,7 @@ test "type info: vectors" {
270270
271271fn testVector() void {
272272 const vec_info = @typeInfo(@Vector(4, i32));
273 assertOrPanic(TypeId(vec_info) == TypeId.Vector);
274 assertOrPanic(vec_info.Vector.len == 4);
275 assertOrPanic(vec_info.Vector.child == i32);
273 expect(TypeId(vec_info) == TypeId.Vector);
274 expect(vec_info.Vector.len == 4);
275 expect(vec_info.Vector.child == i32);
276276}
test/stage1/behavior/undefined.zig+14-14
......@@ -1,4 +1,4 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;
1const expect = @import("std").testing.expect;
22const mem = @import("std").mem;
33
44fn initStaticArray() [10]i32 {
......@@ -11,16 +11,16 @@ fn initStaticArray() [10]i32 {
1111}
1212const static_array = initStaticArray();
1313test "init static array to undefined" {
14 assertOrPanic(static_array[0] == 1);
15 assertOrPanic(static_array[4] == 2);
16 assertOrPanic(static_array[7] == 3);
17 assertOrPanic(static_array[9] == 4);
14 expect(static_array[0] == 1);
15 expect(static_array[4] == 2);
16 expect(static_array[7] == 3);
17 expect(static_array[9] == 4);
1818
1919 comptime {
20 assertOrPanic(static_array[0] == 1);
21 assertOrPanic(static_array[4] == 2);
22 assertOrPanic(static_array[7] == 3);
23 assertOrPanic(static_array[9] == 4);
20 expect(static_array[0] == 1);
21 expect(static_array[4] == 2);
22 expect(static_array[7] == 3);
23 expect(static_array[9] == 4);
2424 }
2525}
2626
......@@ -40,12 +40,12 @@ test "assign undefined to struct" {
4040 comptime {
4141 var foo: Foo = undefined;
4242 setFooX(&foo);
43 assertOrPanic(foo.x == 2);
43 expect(foo.x == 2);
4444 }
4545 {
4646 var foo: Foo = undefined;
4747 setFooX(&foo);
48 assertOrPanic(foo.x == 2);
48 expect(foo.x == 2);
4949 }
5050}
5151
......@@ -53,17 +53,17 @@ test "assign undefined to struct with method" {
5353 comptime {
5454 var foo: Foo = undefined;
5555 foo.setFooXMethod();
56 assertOrPanic(foo.x == 3);
56 expect(foo.x == 3);
5757 }
5858 {
5959 var foo: Foo = undefined;
6060 foo.setFooXMethod();
61 assertOrPanic(foo.x == 3);
61 expect(foo.x == 3);
6262 }
6363}
6464
6565test "type name of undefined" {
6666 const x = undefined;
67 assertOrPanic(mem.eql(u8, @typeName(@typeOf(x)), "(undefined)"));
67 expect(mem.eql(u8, @typeName(@typeOf(x)), "(undefined)"));
6868}
6969
test/stage1/behavior/underscore.zig+1-1
......@@ -1,5 +1,5 @@
11const std = @import("std");
2const assertOrPanic = std.debug.assertOrPanic;
2const expect = std.testing.expect;
33
44test "ignore lval with underscore" {
55 _ = false;
test/stage1/behavior/union.zig+38-38
......@@ -1,4 +1,4 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;
1const expect = @import("std").testing.expect;
22
33const Value = union(enum) {
44 Int: u64,
......@@ -27,11 +27,11 @@ const array = []Value{
2727
2828test "unions embedded in aggregate types" {
2929 switch (array[1]) {
30 Value.Array => |arr| assertOrPanic(arr[4] == 3),
30 Value.Array => |arr| expect(arr[4] == 3),
3131 else => unreachable,
3232 }
3333 switch ((err catch unreachable).val1) {
34 Value.Int => |x| assertOrPanic(x == 1234),
34 Value.Int => |x| expect(x == 1234),
3535 else => unreachable,
3636 }
3737}
......@@ -43,18 +43,18 @@ const Foo = union {
4343
4444test "basic unions" {
4545 var foo = Foo{ .int = 1 };
46 assertOrPanic(foo.int == 1);
46 expect(foo.int == 1);
4747 foo = Foo{ .float = 12.34 };
48 assertOrPanic(foo.float == 12.34);
48 expect(foo.float == 12.34);
4949}
5050
5151test "comptime union field access" {
5252 comptime {
5353 var foo = Foo{ .int = 0 };
54 assertOrPanic(foo.int == 0);
54 expect(foo.int == 0);
5555
5656 foo = Foo{ .float = 42.42 };
57 assertOrPanic(foo.float == 42.42);
57 expect(foo.float == 42.42);
5858 }
5959}
6060
......@@ -62,10 +62,10 @@ test "init union with runtime value" {
6262 var foo: Foo = undefined;
6363
6464 setFloat(&foo, 12.34);
65 assertOrPanic(foo.float == 12.34);
65 expect(foo.float == 12.34);
6666
6767 setInt(&foo, 42);
68 assertOrPanic(foo.int == 42);
68 expect(foo.int == 42);
6969}
7070
7171fn setFloat(foo: *Foo, x: f64) void {
......@@ -83,9 +83,9 @@ const FooExtern = extern union {
8383
8484test "basic extern unions" {
8585 var foo = FooExtern{ .int = 1 };
86 assertOrPanic(foo.int == 1);
86 expect(foo.int == 1);
8787 foo.float = 12.34;
88 assertOrPanic(foo.float == 12.34);
88 expect(foo.float == 12.34);
8989}
9090
9191const Letter = enum {
......@@ -105,11 +105,11 @@ test "union with specified enum tag" {
105105}
106106
107107fn doTest() void {
108 assertOrPanic(bar(Payload{ .A = 1234 }) == -10);
108 expect(bar(Payload{ .A = 1234 }) == -10);
109109}
110110
111111fn bar(value: Payload) i32 {
112 assertOrPanic(Letter(value) == Letter.A);
112 expect(Letter(value) == Letter.A);
113113 return switch (value) {
114114 Payload.A => |x| return x - 1244,
115115 Payload.B => |x| if (x == 12.34) i32(20) else 21,
......@@ -125,8 +125,8 @@ const MultipleChoice = union(enum(u32)) {
125125};
126126test "simple union(enum(u32))" {
127127 var x = MultipleChoice.C;
128 assertOrPanic(x == MultipleChoice.C);
129 assertOrPanic(@enumToInt(@TagType(MultipleChoice)(x)) == 60);
128 expect(x == MultipleChoice.C);
129 expect(@enumToInt(@TagType(MultipleChoice)(x)) == 60);
130130}
131131
132132const MultipleChoice2 = union(enum(u32)) {
......@@ -142,14 +142,14 @@ const MultipleChoice2 = union(enum(u32)) {
142142};
143143
144144test "union(enum(u32)) with specified and unspecified tag values" {
145 comptime assertOrPanic(@TagType(@TagType(MultipleChoice2)) == u32);
145 comptime expect(@TagType(@TagType(MultipleChoice2)) == u32);
146146 testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2{ .C = 123 });
147147 comptime testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2{ .C = 123 });
148148}
149149
150150fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void {
151 assertOrPanic(@enumToInt(@TagType(MultipleChoice2)(x)) == 60);
152 assertOrPanic(1123 == switch (x) {
151 expect(@enumToInt(@TagType(MultipleChoice2)(x)) == 60);
152 expect(1123 == switch (x) {
153153 MultipleChoice2.A => 1,
154154 MultipleChoice2.B => 2,
155155 MultipleChoice2.C => |v| i32(1000) + v,
......@@ -167,7 +167,7 @@ const ExternPtrOrInt = extern union {
167167 int: u64,
168168};
169169test "extern union size" {
170 comptime assertOrPanic(@sizeOf(ExternPtrOrInt) == 8);
170 comptime expect(@sizeOf(ExternPtrOrInt) == 8);
171171}
172172
173173const PackedPtrOrInt = packed union {
......@@ -175,14 +175,14 @@ const PackedPtrOrInt = packed union {
175175 int: u64,
176176};
177177test "extern union size" {
178 comptime assertOrPanic(@sizeOf(PackedPtrOrInt) == 8);
178 comptime expect(@sizeOf(PackedPtrOrInt) == 8);
179179}
180180
181181const ZeroBits = union {
182182 OnlyField: void,
183183};
184184test "union with only 1 field which is void should be zero bits" {
185 comptime assertOrPanic(@sizeOf(ZeroBits) == 0);
185 comptime expect(@sizeOf(ZeroBits) == 0);
186186}
187187
188188const TheTag = enum {
......@@ -196,9 +196,9 @@ const TheUnion = union(TheTag) {
196196 C: i32,
197197};
198198test "union field access gives the enum values" {
199 assertOrPanic(TheUnion.A == TheTag.A);
200 assertOrPanic(TheUnion.B == TheTag.B);
201 assertOrPanic(TheUnion.C == TheTag.C);
199 expect(TheUnion.A == TheTag.A);
200 expect(TheUnion.B == TheTag.B);
201 expect(TheUnion.C == TheTag.C);
202202}
203203
204204test "cast union to tag type of union" {
......@@ -207,12 +207,12 @@ test "cast union to tag type of union" {
207207}
208208
209209fn testCastUnionToTagType(x: TheUnion) void {
210 assertOrPanic(TheTag(x) == TheTag.B);
210 expect(TheTag(x) == TheTag.B);
211211}
212212
213213test "cast tag type of union to union" {
214214 var x: Value2 = Letter2.B;
215 assertOrPanic(Letter2(x) == Letter2.B);
215 expect(Letter2(x) == Letter2.B);
216216}
217217const Letter2 = enum {
218218 A,
......@@ -227,11 +227,11 @@ const Value2 = union(Letter2) {
227227
228228test "implicit cast union to its tag type" {
229229 var x: Value2 = Letter2.B;
230 assertOrPanic(x == Letter2.B);
230 expect(x == Letter2.B);
231231 giveMeLetterB(x);
232232}
233233fn giveMeLetterB(x: Letter2) void {
234 assertOrPanic(x == Value2.B);
234 expect(x == Value2.B);
235235}
236236
237237pub const PackThis = union(enum) {
......@@ -244,7 +244,7 @@ test "constant packed union" {
244244}
245245
246246fn testConstPackedUnion(expected_tokens: []const PackThis) void {
247 assertOrPanic(expected_tokens[0].StringLiteral == 1);
247 expect(expected_tokens[0].StringLiteral == 1);
248248}
249249
250250test "switch on union with only 1 field" {
......@@ -256,7 +256,7 @@ test "switch on union with only 1 field" {
256256 z = PartialInstWithPayload{ .Compiled = 1234 };
257257 switch (z) {
258258 PartialInstWithPayload.Compiled => |x| {
259 assertOrPanic(x == 1234);
259 expect(x == 1234);
260260 return;
261261 },
262262 }
......@@ -282,11 +282,11 @@ test "access a member of tagged union with conflicting enum tag name" {
282282 const B = void;
283283 };
284284
285 comptime assertOrPanic(Bar.A == u8);
285 comptime expect(Bar.A == u8);
286286}
287287
288288test "tagged union initialization with runtime void" {
289 assertOrPanic(testTaggedUnionInit({}));
289 expect(testTaggedUnionInit({}));
290290}
291291
292292const TaggedUnionWithAVoid = union(enum) {
......@@ -324,9 +324,9 @@ test "union with only 1 field casted to its enum type" {
324324
325325 var e = Expr{ .Literal = Literal{ .Bool = true } };
326326 const Tag = @TagType(Expr);
327 comptime assertOrPanic(@TagType(Tag) == comptime_int);
327 comptime expect(@TagType(Tag) == comptime_int);
328328 var t = Tag(e);
329 assertOrPanic(t == Expr.Literal);
329 expect(t == Expr.Literal);
330330}
331331
332332test "union with only 1 field casted to its enum type which has enum value specified" {
......@@ -344,9 +344,9 @@ test "union with only 1 field casted to its enum type which has enum value speci
344344 };
345345
346346 var e = Expr{ .Literal = Literal{ .Bool = true } };
347 comptime assertOrPanic(@TagType(Tag) == comptime_int);
347 comptime expect(@TagType(Tag) == comptime_int);
348348 var t = Tag(e);
349 assertOrPanic(t == Expr.Literal);
350 assertOrPanic(@enumToInt(t) == 33);
351 comptime assertOrPanic(@enumToInt(t) == 33);
349 expect(t == Expr.Literal);
350 expect(@enumToInt(t) == 33);
351 comptime expect(@enumToInt(t) == 33);
352352}
test/stage1/behavior/var_args.zig+17-17
......@@ -1,4 +1,4 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;
1const expect = @import("std").testing.expect;
22
33fn add(args: ...) i32 {
44 var sum = i32(0);
......@@ -12,9 +12,9 @@ fn add(args: ...) i32 {
1212}
1313
1414test "add arbitrary args" {
15 assertOrPanic(add(i32(1), i32(2), i32(3), i32(4)) == 10);
16 assertOrPanic(add(i32(1234)) == 1234);
17 assertOrPanic(add() == 0);
15 expect(add(i32(1), i32(2), i32(3), i32(4)) == 10);
16 expect(add(i32(1234)) == 1234);
17 expect(add() == 0);
1818}
1919
2020fn readFirstVarArg(args: ...) void {
......@@ -26,9 +26,9 @@ test "send void arg to var args" {
2626}
2727
2828test "pass args directly" {
29 assertOrPanic(addSomeStuff(i32(1), i32(2), i32(3), i32(4)) == 10);
30 assertOrPanic(addSomeStuff(i32(1234)) == 1234);
31 assertOrPanic(addSomeStuff() == 0);
29 expect(addSomeStuff(i32(1), i32(2), i32(3), i32(4)) == 10);
30 expect(addSomeStuff(i32(1234)) == 1234);
31 expect(addSomeStuff() == 0);
3232}
3333
3434fn addSomeStuff(args: ...) i32 {
......@@ -36,24 +36,24 @@ fn addSomeStuff(args: ...) i32 {
3636}
3737
3838test "runtime parameter before var args" {
39 assertOrPanic(extraFn(10) == 0);
40 assertOrPanic(extraFn(10, false) == 1);
41 assertOrPanic(extraFn(10, false, true) == 2);
39 expect(extraFn(10) == 0);
40 expect(extraFn(10, false) == 1);
41 expect(extraFn(10, false, true) == 2);
4242
4343 // TODO issue #313
4444 //comptime {
45 // assertOrPanic(extraFn(10) == 0);
46 // assertOrPanic(extraFn(10, false) == 1);
47 // assertOrPanic(extraFn(10, false, true) == 2);
45 // expect(extraFn(10) == 0);
46 // expect(extraFn(10, false) == 1);
47 // expect(extraFn(10, false, true) == 2);
4848 //}
4949}
5050
5151fn extraFn(extra: u32, args: ...) usize {
5252 if (args.len >= 1) {
53 assertOrPanic(args[0] == false);
53 expect(args[0] == false);
5454 }
5555 if (args.len >= 2) {
56 assertOrPanic(args[1] == true);
56 expect(args[1] == true);
5757 }
5858 return args.len;
5959}
......@@ -71,8 +71,8 @@ fn foo2(args: ...) bool {
7171}
7272
7373test "array of var args functions" {
74 assertOrPanic(foos[0]());
75 assertOrPanic(!foos[1]());
74 expect(foos[0]());
75 expect(!foos[1]());
7676}
7777
7878test "pass zero length array to var args param" {
test/stage1/behavior/vector.zig+4-4
......@@ -1,15 +1,15 @@
11const std = @import("std");
22const mem = std.mem;
3const assertOrPanic = std.debug.assertOrPanic;
3const expect = std.testing.expect;
44
55test "vector wrap operators" {
66 const S = struct {
77 fn doTheTest() void {
88 const v: @Vector(4, i32) = [4]i32{ 10, 20, 30, 40 };
99 const x: @Vector(4, i32) = [4]i32{ 1, 2, 3, 4 };
10 assertOrPanic(mem.eql(i32, ([4]i32)(v +% x), [4]i32{ 11, 22, 33, 44 }));
11 assertOrPanic(mem.eql(i32, ([4]i32)(v -% x), [4]i32{ 9, 18, 27, 36 }));
12 assertOrPanic(mem.eql(i32, ([4]i32)(v *% x), [4]i32{ 10, 40, 90, 160 }));
10 expect(mem.eql(i32, ([4]i32)(v +% x), [4]i32{ 11, 22, 33, 44 }));
11 expect(mem.eql(i32, ([4]i32)(v -% x), [4]i32{ 9, 18, 27, 36 }));
12 expect(mem.eql(i32, ([4]i32)(v *% x), [4]i32{ 10, 40, 90, 160 }));
1313 }
1414 };
1515 S.doTheTest();
test/stage1/behavior/void.zig+4-4
......@@ -1,4 +1,4 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;
1const expect = @import("std").testing.expect;
22
33const Foo = struct {
44 a: void,
......@@ -13,14 +13,14 @@ test "compare void with void compile time known" {
1313 .b = 1,
1414 .c = {},
1515 };
16 assertOrPanic(foo.a == {});
16 expect(foo.a == {});
1717 }
1818}
1919
2020test "iterate over a void slice" {
2121 var j: usize = 0;
2222 for (times(10)) |_, i| {
23 assertOrPanic(i == j);
23 expect(i == j);
2424 j += 1;
2525 }
2626}
......@@ -31,5 +31,5 @@ fn times(n: usize) []const void {
3131
3232test "void optional" {
3333 var x: ?void = {};
34 assertOrPanic(x != null);
34 expect(x != null);
3535}
test/stage1/behavior/while.zig+22-22
......@@ -1,12 +1,12 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;
1const expect = @import("std").testing.expect;
22
33test "while loop" {
44 var i: i32 = 0;
55 while (i < 4) {
66 i += 1;
77 }
8 assertOrPanic(i == 4);
9 assertOrPanic(whileLoop1() == 1);
8 expect(i == 4);
9 expect(whileLoop1() == 1);
1010}
1111fn whileLoop1() i32 {
1212 return whileLoop2();
......@@ -18,7 +18,7 @@ fn whileLoop2() i32 {
1818}
1919
2020test "static eval while" {
21 assertOrPanic(static_eval_while_number == 1);
21 expect(static_eval_while_number == 1);
2222}
2323const static_eval_while_number = staticWhileLoop1();
2424fn staticWhileLoop1() i32 {
......@@ -32,7 +32,7 @@ fn staticWhileLoop2() i32 {
3232
3333test "continue and break" {
3434 runContinueAndBreakTest();
35 assertOrPanic(continue_and_break_counter == 8);
35 expect(continue_and_break_counter == 8);
3636}
3737var continue_and_break_counter: i32 = 0;
3838fn runContinueAndBreakTest() void {
......@@ -45,7 +45,7 @@ fn runContinueAndBreakTest() void {
4545 }
4646 break;
4747 }
48 assertOrPanic(i == 4);
48 expect(i == 4);
4949}
5050
5151test "return with implicit cast from while loop" {
......@@ -66,7 +66,7 @@ test "while with continue expression" {
6666 sum += i;
6767 }
6868 }
69 assertOrPanic(sum == 40);
69 expect(sum == 40);
7070}
7171
7272test "while with else" {
......@@ -78,8 +78,8 @@ test "while with else" {
7878 } else {
7979 got_else += 1;
8080 }
81 assertOrPanic(sum == 10);
82 assertOrPanic(got_else == 1);
81 expect(sum == 10);
82 expect(got_else == 1);
8383}
8484
8585test "while with optional as condition" {
......@@ -88,7 +88,7 @@ test "while with optional as condition" {
8888 while (getNumberOrNull()) |value| {
8989 sum += value;
9090 }
91 assertOrPanic(sum == 45);
91 expect(sum == 45);
9292}
9393
9494test "while with optional as condition with else" {
......@@ -97,12 +97,12 @@ test "while with optional as condition with else" {
9797 var got_else: i32 = 0;
9898 while (getNumberOrNull()) |value| {
9999 sum += value;
100 assertOrPanic(got_else == 0);
100 expect(got_else == 0);
101101 } else {
102102 got_else += 1;
103103 }
104 assertOrPanic(sum == 45);
105 assertOrPanic(got_else == 1);
104 expect(sum == 45);
105 expect(got_else == 1);
106106}
107107
108108test "while with error union condition" {
......@@ -112,11 +112,11 @@ test "while with error union condition" {
112112 while (getNumberOrErr()) |value| {
113113 sum += value;
114114 } else |err| {
115 assertOrPanic(err == error.OutOfNumbers);
115 expect(err == error.OutOfNumbers);
116116 got_else += 1;
117117 }
118 assertOrPanic(sum == 45);
119 assertOrPanic(got_else == 1);
118 expect(sum == 45);
119 expect(got_else == 1);
120120}
121121
122122var numbers_left: i32 = undefined;
......@@ -138,7 +138,7 @@ test "while on optional with else result follow else prong" {
138138 break value;
139139 } else
140140 i32(2);
141 assertOrPanic(result == 2);
141 expect(result == 2);
142142}
143143
144144test "while on optional with else result follow break prong" {
......@@ -146,7 +146,7 @@ test "while on optional with else result follow break prong" {
146146 break value;
147147 } else
148148 i32(2);
149 assertOrPanic(result == 10);
149 expect(result == 10);
150150}
151151
152152test "while on error union with else result follow else prong" {
......@@ -154,7 +154,7 @@ test "while on error union with else result follow else prong" {
154154 break value;
155155 } else |err|
156156 i32(2);
157 assertOrPanic(result == 2);
157 expect(result == 2);
158158}
159159
160160test "while on error union with else result follow break prong" {
......@@ -162,7 +162,7 @@ test "while on error union with else result follow break prong" {
162162 break value;
163163 } else |err|
164164 i32(2);
165 assertOrPanic(result == 10);
165 expect(result == 10);
166166}
167167
168168test "while on bool with else result follow else prong" {
......@@ -170,7 +170,7 @@ test "while on bool with else result follow else prong" {
170170 break i32(10);
171171 } else
172172 i32(2);
173 assertOrPanic(result == 2);
173 expect(result == 2);
174174}
175175
176176test "while on bool with else result follow break prong" {
......@@ -178,7 +178,7 @@ test "while on bool with else result follow break prong" {
178178 break i32(10);
179179 } else
180180 i32(2);
181 assertOrPanic(result == 10);
181 expect(result == 10);
182182}
183183
184184test "break from outer while loop" {
test/stage1/behavior/widening.zig+4-4
......@@ -1,5 +1,5 @@
11const std = @import("std");
2const assertOrPanic = std.debug.assertOrPanic;
2const expect = std.testing.expect;
33const mem = std.mem;
44
55test "integer widening" {
......@@ -9,13 +9,13 @@ test "integer widening" {
99 var d: u64 = c;
1010 var e: u64 = d;
1111 var f: u128 = e;
12 assertOrPanic(f == a);
12 expect(f == a);
1313}
1414
1515test "implicit unsigned integer to signed integer" {
1616 var a: u8 = 250;
1717 var b: i16 = a;
18 assertOrPanic(b == 250);
18 expect(b == 250);
1919}
2020
2121test "float widening" {
......@@ -23,6 +23,6 @@ test "float widening" {
2323 var b: f32 = a;
2424 var c: f64 = b;
2525 var d: f128 = c;
26 assertOrPanic(d == a);
26 expect(d == a);
2727}
2828
test/stage1/c_abi/main.zig+41-41
......@@ -1,5 +1,5 @@
11const std = @import("std");
2const assertOrPanic = std.debug.assertOrPanic;
2const expect = std.testing.expect;
33
44extern fn run_c_tests() void;
55
......@@ -33,28 +33,28 @@ test "C ABI integers" {
3333}
3434
3535export fn zig_u8(x: u8) void {
36 assertOrPanic(x == 0xff);
36 expect(x == 0xff);
3737}
3838export fn zig_u16(x: u16) void {
39 assertOrPanic(x == 0xfffe);
39 expect(x == 0xfffe);
4040}
4141export fn zig_u32(x: u32) void {
42 assertOrPanic(x == 0xfffffffd);
42 expect(x == 0xfffffffd);
4343}
4444export fn zig_u64(x: u64) void {
45 assertOrPanic(x == 0xfffffffffffffffc);
45 expect(x == 0xfffffffffffffffc);
4646}
4747export fn zig_i8(x: i8) void {
48 assertOrPanic(x == -1);
48 expect(x == -1);
4949}
5050export fn zig_i16(x: i16) void {
51 assertOrPanic(x == -2);
51 expect(x == -2);
5252}
5353export fn zig_i32(x: i32) void {
54 assertOrPanic(x == -3);
54 expect(x == -3);
5555}
5656export fn zig_i64(x: i64) void {
57 assertOrPanic(x == -4);
57 expect(x == -4);
5858}
5959
6060extern fn c_f32(f32) void;
......@@ -66,10 +66,10 @@ test "C ABI floats" {
6666}
6767
6868export fn zig_f32(x: f32) void {
69 assertOrPanic(x == 12.34);
69 expect(x == 12.34);
7070}
7171export fn zig_f64(x: f64) void {
72 assertOrPanic(x == 56.78);
72 expect(x == 56.78);
7373}
7474
7575extern fn c_ptr(*c_void) void;
......@@ -79,7 +79,7 @@ test "C ABI pointer" {
7979}
8080
8181export fn zig_ptr(x: *c_void) void {
82 assertOrPanic(@ptrToInt(x) == 0xdeadbeef);
82 expect(@ptrToInt(x) == 0xdeadbeef);
8383}
8484
8585extern fn c_bool(bool) void;
......@@ -89,7 +89,7 @@ test "C ABI bool" {
8989}
9090
9191export fn zig_bool(x: bool) void {
92 assertOrPanic(x);
92 expect(x);
9393}
9494
9595extern fn c_array([10]u8) void;
......@@ -100,7 +100,7 @@ test "C ABI array" {
100100}
101101
102102export fn zig_array(x: [10]u8) void {
103 assertOrPanic(std.mem.eql(u8, x, "1234567890"));
103 expect(std.mem.eql(u8, x, "1234567890"));
104104}
105105
106106const BigStruct = extern struct {
......@@ -124,11 +124,11 @@ test "C ABI big struct" {
124124}
125125
126126export fn zig_big_struct(x: BigStruct) void {
127 assertOrPanic(x.a == 1);
128 assertOrPanic(x.b == 2);
129 assertOrPanic(x.c == 3);
130 assertOrPanic(x.d == 4);
131 assertOrPanic(x.e == 5);
127 expect(x.a == 1);
128 expect(x.b == 2);
129 expect(x.c == 3);
130 expect(x.d == 4);
131 expect(x.e == 5);
132132}
133133
134134const BigUnion = extern union {
......@@ -150,11 +150,11 @@ test "C ABI big union" {
150150}
151151
152152export fn zig_big_union(x: BigUnion) void {
153 assertOrPanic(x.a.a == 1);
154 assertOrPanic(x.a.b == 2);
155 assertOrPanic(x.a.c == 3);
156 assertOrPanic(x.a.d == 4);
157 assertOrPanic(x.a.e == 5);
153 expect(x.a.a == 1);
154 expect(x.a.b == 2);
155 expect(x.a.c == 3);
156 expect(x.a.d == 4);
157 expect(x.a.e == 5);
158158}
159159
160160const SmallStructInts = extern struct {
......@@ -176,10 +176,10 @@ test "C ABI small struct of ints" {
176176}
177177
178178export fn zig_small_struct_ints(x: SmallStructInts) void {
179 assertOrPanic(x.a == 1);
180 assertOrPanic(x.b == 2);
181 assertOrPanic(x.c == 3);
182 assertOrPanic(x.d == 4);
179 expect(x.a == 1);
180 expect(x.b == 2);
181 expect(x.c == 3);
182 expect(x.d == 4);
183183}
184184
185185const SplitStructInt = extern struct {
......@@ -199,9 +199,9 @@ test "C ABI split struct of ints" {
199199}
200200
201201export fn zig_split_struct_ints(x: SplitStructInt) void {
202 assertOrPanic(x.a == 1234);
203 assertOrPanic(x.b == 100);
204 assertOrPanic(x.c == 1337);
202 expect(x.a == 1234);
203 expect(x.b == 100);
204 expect(x.c == 1337);
205205}
206206
207207extern fn c_big_struct_both(BigStruct) BigStruct;
......@@ -215,19 +215,19 @@ test "C ABI sret and byval together" {
215215 .e = 5,
216216 };
217217 var y = c_big_struct_both(s);
218 assertOrPanic(y.a == 10);
219 assertOrPanic(y.b == 11);
220 assertOrPanic(y.c == 12);
221 assertOrPanic(y.d == 13);
222 assertOrPanic(y.e == 14);
218 expect(y.a == 10);
219 expect(y.b == 11);
220 expect(y.c == 12);
221 expect(y.d == 13);
222 expect(y.e == 14);
223223}
224224
225225export fn zig_big_struct_both(x: BigStruct) BigStruct {
226 assertOrPanic(x.a == 30);
227 assertOrPanic(x.b == 31);
228 assertOrPanic(x.c == 32);
229 assertOrPanic(x.d == 33);
230 assertOrPanic(x.e == 34);
226 expect(x.a == 30);
227 expect(x.b == 31);
228 expect(x.c == 32);
229 expect(x.d == 33);
230 expect(x.e == 34);
231231 var s = BigStruct{
232232 .a = 20,
233233 .b = 21,
test/standalone/brace_expansion/main.zig+3-6
......@@ -3,6 +3,7 @@ const io = std.io;
33const mem = std.mem;
44const debug = std.debug;
55const assert = debug.assert;
6const testing = std.testing;
67const Buffer = std.Buffer;
78const ArrayList = std.ArrayList;
89const maxInt = std.math.maxInt;
......@@ -220,11 +221,7 @@ fn expectError(test_input: []const u8, expected_err: anyerror) void {
220221 var output_buf = Buffer.initSize(global_allocator, 0) catch unreachable;
221222 defer output_buf.deinit();
222223
223 if (expandString(test_input, &output_buf)) {
224 unreachable;
225 } else |err| {
226 assert(expected_err == err);
227 }
224 testing.expectError(expected_err, expandString(test_input, &output_buf));
228225}
229226
230227test "valid inputs" {
......@@ -256,5 +253,5 @@ fn expectExpansion(test_input: []const u8, expected_result: []const u8) void {
256253
257254 expandString(test_input, &result) catch unreachable;
258255
259 assert(mem.eql(u8, result.toSlice(), expected_result));
256 testing.expectEqualSlices(u8, expected_result, result.toSlice());
260257}
test/standalone/issue_794/main.zig+2-2
......@@ -1,7 +1,7 @@
11const c = @cImport(@cInclude("foo.h"));
22const std = @import("std");
3const assert = std.debug.assert;
3const testing = std.testing;
44
55test "c import" {
6 comptime assert(c.NUMBER == 1234);
6 comptime testing.expect(c.NUMBER == 1234);
77}