authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-02-09 18:57:39-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-02-09 18:57:39-05:00
log1864acd32608ae917f8afc11b11f08a4bb362cef
treed96b50a927fc67583d88c71822513594609621fb
parent48c1e235cb620dacc30254d0898390b4d97f3e73
parentca8580ece1ab07215b72394cc4ab3030bf9df139
signaturelock-open Commit is signed but in an unrecognized format.

Merge remote-tracking branch 'origin/master' into llvm8


250 files changed, 4516 insertions(+), 4106 deletions(-)

CMakeLists.txt+1
...@@ -661,6 +661,7 @@ set(ZIG_STD_FILES...@@ -661,6 +661,7 @@ set(ZIG_STD_FILES
661 "special/test_runner.zig"661 "special/test_runner.zig"
662 "spinlock.zig"662 "spinlock.zig"
663 "statically_initialized_mutex.zig"663 "statically_initialized_mutex.zig"
664 "testing.zig"
664 "unicode.zig"665 "unicode.zig"
665 "zig/ast.zig"666 "zig/ast.zig"
666 "zig/index.zig"667 "zig/index.zig"
cmake/Findllvm.cmake+4
...@@ -19,6 +19,10 @@ if ("${LLVM_CONFIG_EXE}" STREQUAL "LLVM_CONFIG_EXE-NOTFOUND")...@@ -19,6 +19,10 @@ if ("${LLVM_CONFIG_EXE}" STREQUAL "LLVM_CONFIG_EXE-NOTFOUND")
19 message(FATAL_ERROR "unable to find llvm-config")19 message(FATAL_ERROR "unable to find llvm-config")
20endif()20endif()
2121
22if ("${LLVM_CONFIG_EXE}" STREQUAL "LLVM_CONFIG_EXE-NOTFOUND")
23 message(FATAL_ERROR "unable to find llvm-config")
24endif()
25
22execute_process(26execute_process(
23 COMMAND ${LLVM_CONFIG_EXE} --version27 COMMAND ${LLVM_CONFIG_EXE} --version
24 OUTPUT_VARIABLE LLVM_CONFIG_VERSION28 OUTPUT_VARIABLE LLVM_CONFIG_VERSION
doc/docgen.zig+3-2
...@@ -4,7 +4,7 @@ const io = std.io;...@@ -4,7 +4,7 @@ const io = std.io;
4const os = std.os;4const os = std.os;
5const warn = std.debug.warn;5const warn = std.debug.warn;
6const mem = std.mem;6const mem = std.mem;
7const assert = std.debug.assert;7const testing = std.testing;
88
9const max_doc_file_size = 10 * 1024 * 1024;9const max_doc_file_size = 10 * 1024 * 1024;
1010
...@@ -620,7 +620,7 @@ const TermState = enum {...@@ -620,7 +620,7 @@ const TermState = enum {
620test "term color" {620test "term color" {
621 const input_bytes = "A\x1b[32;1mgreen\x1b[0mB";621 const input_bytes = "A\x1b[32;1mgreen\x1b[0mB";
622 const result = try termColor(std.debug.global_allocator, input_bytes);622 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);
624}624}
625625
626fn termColor(allocator: *mem.Allocator, input: []const u8) ![]u8 {626fn termColor(allocator: *mem.Allocator, input: []const u8) ![]u8 {
...@@ -770,6 +770,7 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Tok...@@ -770,6 +770,7 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Tok
770 std.zig.Token.Id.Keyword_suspend,770 std.zig.Token.Id.Keyword_suspend,
771 std.zig.Token.Id.Keyword_switch,771 std.zig.Token.Id.Keyword_switch,
772 std.zig.Token.Id.Keyword_test,772 std.zig.Token.Id.Keyword_test,
773 std.zig.Token.Id.Keyword_threadlocal,
773 std.zig.Token.Id.Keyword_try,774 std.zig.Token.Id.Keyword_try,
774 std.zig.Token.Id.Keyword_union,775 std.zig.Token.Id.Keyword_union,
775 std.zig.Token.Id.Keyword_unreachable,776 std.zig.Token.Id.Keyword_unreachable,
doc/langref.html.in+1-1
...@@ -4627,7 +4627,7 @@ test "fibonacci" {...@@ -4627,7 +4627,7 @@ test "fibonacci" {
4627 <p>4627 <p>
4628 What if we fix the base case, but put the wrong value in the {#syntax#}assert{#endsyntax#} line?4628 What if we fix the base case, but put the wrong value in the {#syntax#}assert{#endsyntax#} line?
4629 </p>4629 </p>
4630 {#code_begin|test_err|encountered @panic at compile-time#}4630 {#code_begin|test_err|unable to evaluate constant expression#}
4631const assert = @import("std").debug.assert;4631const assert = @import("std").debug.assert;
46324632
4633fn fibonacci(index: i32) i32 {4633fn fibonacci(index: i32) i32 {
src-self-hosted/arg.zig+12-11
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1const std = @import("std");1const std = @import("std");
2const debug = std.debug;2const debug = std.debug;
3const testing = std.testing;
3const mem = std.mem;4const mem = std.mem;
45
5const Allocator = mem.Allocator;6const Allocator = mem.Allocator;
...@@ -272,21 +273,21 @@ test "parse arguments" {...@@ -272,21 +273,21 @@ test "parse arguments" {
272273
273 var args = try Args.parse(std.debug.global_allocator, spec1, cliargs);274 var args = try Args.parse(std.debug.global_allocator, spec1, cliargs);
274275
275 debug.assert(args.present("help"));276 testing.expect(args.present("help"));
276 debug.assert(!args.present("help2"));277 testing.expect(!args.present("help2"));
277 debug.assert(!args.present("init"));278 testing.expect(!args.present("init"));
278279
279 debug.assert(mem.eql(u8, args.single("build-file").?, "build.zig"));280 testing.expect(mem.eql(u8, args.single("build-file").?, "build.zig"));
280 debug.assert(mem.eql(u8, args.single("color").?, "on"));281 testing.expect(mem.eql(u8, args.single("color").?, "on"));
281282
282 const objects = args.many("object").?;283 const objects = args.many("object").?;
283 debug.assert(mem.eql(u8, objects[0], "obj1"));284 testing.expect(mem.eql(u8, objects[0], "obj1"));
284 debug.assert(mem.eql(u8, objects[1], "obj2"));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
288 const pos = args.positionals.toSliceConst();289 const pos = args.positionals.toSliceConst();
289 debug.assert(mem.eql(u8, pos[0], "build"));290 testing.expect(mem.eql(u8, pos[0], "build"));
290 debug.assert(mem.eql(u8, pos[1], "pos1"));291 testing.expect(mem.eql(u8, pos[1], "pos1"));
291 debug.assert(mem.eql(u8, pos[2], "pos2"));292 testing.expect(mem.eql(u8, pos[2], "pos2"));
292}293}
src-self-hosted/test.zig+2-2
...@@ -4,7 +4,7 @@ const builtin = @import("builtin");...@@ -4,7 +4,7 @@ const builtin = @import("builtin");
4const Target = @import("target.zig").Target;4const Target = @import("target.zig").Target;
5const Compilation = @import("compilation.zig").Compilation;5const Compilation = @import("compilation.zig").Compilation;
6const introspect = @import("introspect.zig");6const introspect = @import("introspect.zig");
7const assertOrPanic = std.debug.assertOrPanic;7const testing = std.testing;
8const errmsg = @import("errmsg.zig");8const errmsg = @import("errmsg.zig");
9const ZigCompiler = @import("compilation.zig").ZigCompiler;9const ZigCompiler = @import("compilation.zig").ZigCompiler;
1010
...@@ -210,7 +210,7 @@ pub const TestContext = struct {...@@ -210,7 +210,7 @@ pub const TestContext = struct {
210 @panic("build incorrectly failed");210 @panic("build incorrectly failed");
211 },211 },
212 Compilation.Event.Fail => |msgs| {212 Compilation.Event.Fail => |msgs| {
213 assertOrPanic(msgs.len != 0);213 testing.expect(msgs.len != 0);
214 for (msgs) |msg| {214 for (msgs) |msg| {
215 if (mem.endsWith(u8, msg.realpath, path) and mem.eql(u8, msg.text, text)) {215 if (mem.endsWith(u8, msg.realpath, path) and mem.eql(u8, msg.text, text)) {
216 const span = msg.getSpan();216 const span = msg.getSpan();
src/all_types.hpp+10
...@@ -1538,6 +1538,8 @@ enum ZigLLVMFnId {...@@ -1538,6 +1538,8 @@ enum ZigLLVMFnId {
1538 ZigLLVMFnIdBitReverse,1538 ZigLLVMFnIdBitReverse,
1539};1539};
15401540
1541// There are a bunch of places in code that rely on these values being in
1542// exactly this order.
1541enum AddSubMul {1543enum AddSubMul {
1542 AddSubMulAdd = 0,1544 AddSubMulAdd = 0,
1543 AddSubMulSub = 1,1545 AddSubMulSub = 1,
...@@ -1563,6 +1565,7 @@ struct ZigLLVMFnKey {...@@ -1563,6 +1565,7 @@ struct ZigLLVMFnKey {
1563 struct {1565 struct {
1564 AddSubMul add_sub_mul;1566 AddSubMul add_sub_mul;
1565 uint32_t bit_count;1567 uint32_t bit_count;
1568 uint32_t vector_len; // 0 means not a vector
1566 bool is_signed;1569 bool is_signed;
1567 } overflow_arithmetic;1570 } overflow_arithmetic;
1568 struct {1571 struct {
...@@ -2239,6 +2242,7 @@ enum IrInstructionId {...@@ -2239,6 +2242,7 @@ enum IrInstructionId {
2239 IrInstructionIdCheckRuntimeScope,2242 IrInstructionIdCheckRuntimeScope,
2240 IrInstructionIdVectorToArray,2243 IrInstructionIdVectorToArray,
2241 IrInstructionIdArrayToVector,2244 IrInstructionIdArrayToVector,
2245 IrInstructionIdAssertZero,
2242};2246};
22432247
2244struct IrInstruction {2248struct IrInstruction {
...@@ -3381,6 +3385,12 @@ struct IrInstructionVectorToArray {...@@ -3381,6 +3385,12 @@ struct IrInstructionVectorToArray {
3381 LLVMValueRef tmp_ptr;3385 LLVMValueRef tmp_ptr;
3382};3386};
33833387
3388struct IrInstructionAssertZero {
3389 IrInstruction base;
3390
3391 IrInstruction *target;
3392};
3393
3384static const size_t slice_ptr_index = 0;3394static const size_t slice_ptr_index = 0;
3385static const size_t slice_len_index = 1;3395static const size_t slice_len_index = 1;
33863396
src/analyze.cpp+4-2
...@@ -6361,7 +6361,8 @@ uint32_t zig_llvm_fn_key_hash(ZigLLVMFnKey x) {...@@ -6361,7 +6361,8 @@ uint32_t zig_llvm_fn_key_hash(ZigLLVMFnKey x) {
6361 case ZigLLVMFnIdOverflowArithmetic:6361 case ZigLLVMFnIdOverflowArithmetic:
6362 return ((uint32_t)(x.data.overflow_arithmetic.bit_count) * 87135777) +6362 return ((uint32_t)(x.data.overflow_arithmetic.bit_count) * 87135777) +
6363 ((uint32_t)(x.data.overflow_arithmetic.add_sub_mul) * 31640542) +6363 ((uint32_t)(x.data.overflow_arithmetic.add_sub_mul) * 31640542) +
6364 ((uint32_t)(x.data.overflow_arithmetic.is_signed) ? 1062315172 : 314955820);6364 ((uint32_t)(x.data.overflow_arithmetic.is_signed) ? 1062315172 : 314955820) +
6365 x.data.overflow_arithmetic.vector_len * 1435156945;
6365 }6366 }
6366 zig_unreachable();6367 zig_unreachable();
6367}6368}
...@@ -6387,7 +6388,8 @@ bool zig_llvm_fn_key_eql(ZigLLVMFnKey a, ZigLLVMFnKey b) {...@@ -6387,7 +6388,8 @@ bool zig_llvm_fn_key_eql(ZigLLVMFnKey a, ZigLLVMFnKey b) {
6387 case ZigLLVMFnIdOverflowArithmetic:6388 case ZigLLVMFnIdOverflowArithmetic:
6388 return (a.data.overflow_arithmetic.bit_count == b.data.overflow_arithmetic.bit_count) &&6389 return (a.data.overflow_arithmetic.bit_count == b.data.overflow_arithmetic.bit_count) &&
6389 (a.data.overflow_arithmetic.add_sub_mul == b.data.overflow_arithmetic.add_sub_mul) &&6390 (a.data.overflow_arithmetic.add_sub_mul == b.data.overflow_arithmetic.add_sub_mul) &&
6390 (a.data.overflow_arithmetic.is_signed == b.data.overflow_arithmetic.is_signed);6391 (a.data.overflow_arithmetic.is_signed == b.data.overflow_arithmetic.is_signed) &&
6392 (a.data.overflow_arithmetic.vector_len == b.data.overflow_arithmetic.vector_len);
6391 }6393 }
6392 zig_unreachable();6394 zig_unreachable();
6393}6395}
src/codegen.cpp+144-93
...@@ -715,38 +715,59 @@ static void clear_debug_source_node(CodeGen *g) {...@@ -715,38 +715,59 @@ static void clear_debug_source_node(CodeGen *g) {
715 ZigLLVMClearCurrentDebugLocation(g->builder);715 ZigLLVMClearCurrentDebugLocation(g->builder);
716}716}
717717
718static LLVMValueRef get_arithmetic_overflow_fn(CodeGen *g, ZigType *type_entry,718static LLVMValueRef get_arithmetic_overflow_fn(CodeGen *g, ZigType *operand_type,
719 const char *signed_name, const char *unsigned_name)719 const char *signed_name, const char *unsigned_name)
720{720{
721 ZigType *int_type = (operand_type->id == ZigTypeIdVector) ? operand_type->data.vector.elem_type : operand_type;
721 char fn_name[64];722 char fn_name[64];
722723
723 assert(type_entry->id == ZigTypeIdInt);724 assert(int_type->id == ZigTypeIdInt);
724 const char *signed_str = type_entry->data.integral.is_signed ? signed_name : unsigned_name;725 const char *signed_str = int_type->data.integral.is_signed ? signed_name : unsigned_name;
725 sprintf(fn_name, "llvm.%s.with.overflow.i%" PRIu32, signed_str, type_entry->data.integral.bit_count);
726726
727 LLVMTypeRef return_elem_types[] = {
728 type_entry->type_ref,
729 LLVMInt1Type(),
730 };
731 LLVMTypeRef param_types[] = {727 LLVMTypeRef param_types[] = {
732 type_entry->type_ref,728 operand_type->type_ref,
733 type_entry->type_ref,729 operand_type->type_ref,
734 };730 };
735 LLVMTypeRef return_struct_type = LLVMStructType(return_elem_types, 2, false);731
736 LLVMTypeRef fn_type = LLVMFunctionType(return_struct_type, param_types, 2, false);732 if (operand_type->id == ZigTypeIdVector) {
737 LLVMValueRef fn_val = LLVMAddFunction(g->module, fn_name, fn_type);733 sprintf(fn_name, "llvm.%s.with.overflow.v%" PRIu32 "i%" PRIu32, signed_str,
738 assert(LLVMGetIntrinsicID(fn_val));734 operand_type->data.vector.len, int_type->data.integral.bit_count);
739 return fn_val;735
736 LLVMTypeRef return_elem_types[] = {
737 operand_type->type_ref,
738 LLVMVectorType(LLVMInt1Type(), operand_type->data.vector.len),
739 };
740 LLVMTypeRef return_struct_type = LLVMStructType(return_elem_types, 2, false);
741 LLVMTypeRef fn_type = LLVMFunctionType(return_struct_type, param_types, 2, false);
742 LLVMValueRef fn_val = LLVMAddFunction(g->module, fn_name, fn_type);
743 assert(LLVMGetIntrinsicID(fn_val));
744 return fn_val;
745 } else {
746 sprintf(fn_name, "llvm.%s.with.overflow.i%" PRIu32, signed_str, int_type->data.integral.bit_count);
747
748 LLVMTypeRef return_elem_types[] = {
749 operand_type->type_ref,
750 LLVMInt1Type(),
751 };
752 LLVMTypeRef return_struct_type = LLVMStructType(return_elem_types, 2, false);
753 LLVMTypeRef fn_type = LLVMFunctionType(return_struct_type, param_types, 2, false);
754 LLVMValueRef fn_val = LLVMAddFunction(g->module, fn_name, fn_type);
755 assert(LLVMGetIntrinsicID(fn_val));
756 return fn_val;
757 }
740}758}
741759
742static LLVMValueRef get_int_overflow_fn(CodeGen *g, ZigType *type_entry, AddSubMul add_sub_mul) {760static LLVMValueRef get_int_overflow_fn(CodeGen *g, ZigType *operand_type, AddSubMul add_sub_mul) {
743 assert(type_entry->id == ZigTypeIdInt);761 ZigType *int_type = (operand_type->id == ZigTypeIdVector) ? operand_type->data.vector.elem_type : operand_type;
762 assert(int_type->id == ZigTypeIdInt);
744763
745 ZigLLVMFnKey key = {};764 ZigLLVMFnKey key = {};
746 key.id = ZigLLVMFnIdOverflowArithmetic;765 key.id = ZigLLVMFnIdOverflowArithmetic;
747 key.data.overflow_arithmetic.is_signed = type_entry->data.integral.is_signed;766 key.data.overflow_arithmetic.is_signed = int_type->data.integral.is_signed;
748 key.data.overflow_arithmetic.add_sub_mul = add_sub_mul;767 key.data.overflow_arithmetic.add_sub_mul = add_sub_mul;
749 key.data.overflow_arithmetic.bit_count = (uint32_t)type_entry->data.integral.bit_count;768 key.data.overflow_arithmetic.bit_count = (uint32_t)int_type->data.integral.bit_count;
769 key.data.overflow_arithmetic.vector_len = (operand_type->id == ZigTypeIdVector) ?
770 operand_type->data.vector.len : 0;
750771
751 auto existing_entry = g->llvm_fn_table.maybe_get(key);772 auto existing_entry = g->llvm_fn_table.maybe_get(key);
752 if (existing_entry)773 if (existing_entry)
...@@ -755,13 +776,13 @@ static LLVMValueRef get_int_overflow_fn(CodeGen *g, ZigType *type_entry, AddSubM...@@ -755,13 +776,13 @@ static LLVMValueRef get_int_overflow_fn(CodeGen *g, ZigType *type_entry, AddSubM
755 LLVMValueRef fn_val;776 LLVMValueRef fn_val;
756 switch (add_sub_mul) {777 switch (add_sub_mul) {
757 case AddSubMulAdd:778 case AddSubMulAdd:
758 fn_val = get_arithmetic_overflow_fn(g, type_entry, "sadd", "uadd");779 fn_val = get_arithmetic_overflow_fn(g, operand_type, "sadd", "uadd");
759 break;780 break;
760 case AddSubMulSub:781 case AddSubMulSub:
761 fn_val = get_arithmetic_overflow_fn(g, type_entry, "ssub", "usub");782 fn_val = get_arithmetic_overflow_fn(g, operand_type, "ssub", "usub");
762 break;783 break;
763 case AddSubMulMul:784 case AddSubMulMul:
764 fn_val = get_arithmetic_overflow_fn(g, type_entry, "smul", "umul");785 fn_val = get_arithmetic_overflow_fn(g, operand_type, "smul", "umul");
765 break;786 break;
766 }787 }
767788
...@@ -1651,10 +1672,25 @@ static void add_bounds_check(CodeGen *g, LLVMValueRef target_val,...@@ -1651,10 +1672,25 @@ static void add_bounds_check(CodeGen *g, LLVMValueRef target_val,
1651 LLVMPositionBuilderAtEnd(g->builder, ok_block);1672 LLVMPositionBuilderAtEnd(g->builder, ok_block);
1652}1673}
16531674
1675static LLVMValueRef gen_assert_zero(CodeGen *g, LLVMValueRef expr_val, ZigType *int_type) {
1676 LLVMValueRef zero = LLVMConstNull(int_type->type_ref);
1677 LLVMValueRef ok_bit = LLVMBuildICmp(g->builder, LLVMIntEQ, expr_val, zero, "");
1678 LLVMBasicBlockRef ok_block = LLVMAppendBasicBlock(g->cur_fn_val, "CastShortenOk");
1679 LLVMBasicBlockRef fail_block = LLVMAppendBasicBlock(g->cur_fn_val, "CastShortenFail");
1680 LLVMBuildCondBr(g->builder, ok_bit, ok_block, fail_block);
1681
1682 LLVMPositionBuilderAtEnd(g->builder, fail_block);
1683 gen_safety_crash(g, PanicMsgIdCastTruncatedData);
1684
1685 LLVMPositionBuilderAtEnd(g->builder, ok_block);
1686 return nullptr;
1687}
1688
1654static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_runtime_safety, ZigType *actual_type,1689static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_runtime_safety, ZigType *actual_type,
1655 ZigType *wanted_type, LLVMValueRef expr_val)1690 ZigType *wanted_type, LLVMValueRef expr_val)
1656{1691{
1657 assert(actual_type->id == wanted_type->id);1692 assert(actual_type->id == wanted_type->id);
1693 assert(expr_val != nullptr);
16581694
1659 uint64_t actual_bits;1695 uint64_t actual_bits;
1660 uint64_t wanted_bits;1696 uint64_t wanted_bits;
...@@ -1707,17 +1743,7 @@ static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_runtime_safety, Z...@@ -1707,17 +1743,7 @@ static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_runtime_safety, Z
1707 if (!want_runtime_safety)1743 if (!want_runtime_safety)
1708 return nullptr;1744 return nullptr;
17091745
1710 LLVMValueRef zero = LLVMConstNull(actual_type->type_ref);1746 return gen_assert_zero(g, expr_val, actual_type);
1711 LLVMValueRef ok_bit = LLVMBuildICmp(g->builder, LLVMIntEQ, expr_val, zero, "");
1712 LLVMBasicBlockRef ok_block = LLVMAppendBasicBlock(g->cur_fn_val, "CastShortenOk");
1713 LLVMBasicBlockRef fail_block = LLVMAppendBasicBlock(g->cur_fn_val, "CastShortenFail");
1714 LLVMBuildCondBr(g->builder, ok_bit, ok_block, fail_block);
1715
1716 LLVMPositionBuilderAtEnd(g->builder, fail_block);
1717 gen_safety_crash(g, PanicMsgIdCastTruncatedData);
1718
1719 LLVMPositionBuilderAtEnd(g->builder, ok_block);
1720 return nullptr;
1721 }1747 }
1722 LLVMValueRef trunc_val = LLVMBuildTrunc(g->builder, expr_val, wanted_type->type_ref, "");1748 LLVMValueRef trunc_val = LLVMBuildTrunc(g->builder, expr_val, wanted_type->type_ref, "");
1723 if (!want_runtime_safety) {1749 if (!want_runtime_safety) {
...@@ -1747,17 +1773,49 @@ static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_runtime_safety, Z...@@ -1747,17 +1773,49 @@ static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_runtime_safety, Z
1747 }1773 }
1748}1774}
17491775
1750static LLVMValueRef gen_overflow_op(CodeGen *g, ZigType *type_entry, AddSubMul op,1776typedef LLVMValueRef (*BuildBinOpFunc)(LLVMBuilderRef, LLVMValueRef, LLVMValueRef, const char *);
1777// These are lookup table using the AddSubMul enum as the lookup.
1778// If AddSubMul ever changes, then these tables will be out of
1779// date.
1780static const BuildBinOpFunc float_op[3] = { LLVMBuildFAdd, LLVMBuildFSub, LLVMBuildFMul };
1781static const BuildBinOpFunc wrap_op[3] = { LLVMBuildAdd, LLVMBuildSub, LLVMBuildMul };
1782static const BuildBinOpFunc signed_op[3] = { LLVMBuildNSWAdd, LLVMBuildNSWSub, LLVMBuildNSWMul };
1783static const BuildBinOpFunc unsigned_op[3] = { LLVMBuildNUWAdd, LLVMBuildNUWSub, LLVMBuildNUWMul };
1784
1785static LLVMValueRef gen_overflow_op(CodeGen *g, ZigType *operand_type, AddSubMul op,
1751 LLVMValueRef val1, LLVMValueRef val2)1786 LLVMValueRef val1, LLVMValueRef val2)
1752{1787{
1753 LLVMValueRef fn_val = get_int_overflow_fn(g, type_entry, op);1788 LLVMValueRef overflow_bit;
1754 LLVMValueRef params[] = {1789 LLVMValueRef result;
1755 val1,1790
1756 val2,1791 if (operand_type->id == ZigTypeIdVector) {
1757 };1792 ZigType *int_type = operand_type->data.vector.elem_type;
1758 LLVMValueRef result_struct = LLVMBuildCall(g->builder, fn_val, params, 2, "");1793 assert(int_type->id == ZigTypeIdInt);
1759 LLVMValueRef result = LLVMBuildExtractValue(g->builder, result_struct, 0, "");1794 LLVMTypeRef one_more_bit_int = LLVMIntType(int_type->data.integral.bit_count + 1);
1760 LLVMValueRef overflow_bit = LLVMBuildExtractValue(g->builder, result_struct, 1, "");1795 LLVMTypeRef one_more_bit_int_vector = LLVMVectorType(one_more_bit_int, operand_type->data.vector.len);
1796 const auto buildExtFn = int_type->data.integral.is_signed ? LLVMBuildSExt : LLVMBuildZExt;
1797 LLVMValueRef extended1 = buildExtFn(g->builder, val1, one_more_bit_int_vector, "");
1798 LLVMValueRef extended2 = buildExtFn(g->builder, val2, one_more_bit_int_vector, "");
1799 LLVMValueRef extended_result = wrap_op[op](g->builder, extended1, extended2, "");
1800 result = LLVMBuildTrunc(g->builder, extended_result, operand_type->type_ref, "");
1801
1802 LLVMValueRef re_extended_result = buildExtFn(g->builder, result, one_more_bit_int_vector, "");
1803 LLVMValueRef overflow_vector = LLVMBuildICmp(g->builder, LLVMIntNE, extended_result, re_extended_result, "");
1804 LLVMTypeRef bitcast_int_type = LLVMIntType(operand_type->data.vector.len);
1805 LLVMValueRef bitcasted_overflow = LLVMBuildBitCast(g->builder, overflow_vector, bitcast_int_type, "");
1806 LLVMValueRef zero = LLVMConstNull(bitcast_int_type);
1807 overflow_bit = LLVMBuildICmp(g->builder, LLVMIntNE, bitcasted_overflow, zero, "");
1808 } else {
1809 LLVMValueRef fn_val = get_int_overflow_fn(g, operand_type, op);
1810 LLVMValueRef params[] = {
1811 val1,
1812 val2,
1813 };
1814 LLVMValueRef result_struct = LLVMBuildCall(g->builder, fn_val, params, 2, "");
1815 result = LLVMBuildExtractValue(g->builder, result_struct, 0, "");
1816 overflow_bit = LLVMBuildExtractValue(g->builder, result_struct, 1, "");
1817 }
1818
1761 LLVMBasicBlockRef fail_block = LLVMAppendBasicBlock(g->cur_fn_val, "OverflowFail");1819 LLVMBasicBlockRef fail_block = LLVMAppendBasicBlock(g->cur_fn_val, "OverflowFail");
1762 LLVMBasicBlockRef ok_block = LLVMAppendBasicBlock(g->cur_fn_val, "OverflowOk");1820 LLVMBasicBlockRef ok_block = LLVMAppendBasicBlock(g->cur_fn_val, "OverflowOk");
1763 LLVMBuildCondBr(g->builder, overflow_bit, fail_block, ok_block);1821 LLVMBuildCondBr(g->builder, overflow_bit, fail_block, ok_block);
...@@ -2586,8 +2644,6 @@ static LLVMValueRef gen_rem(CodeGen *g, bool want_runtime_safety, bool want_fast...@@ -2586,8 +2644,6 @@ static LLVMValueRef gen_rem(CodeGen *g, bool want_runtime_safety, bool want_fast
25862644
2587}2645}
25882646
2589typedef LLVMValueRef (*BuildBinOpFunc)(LLVMBuilderRef, LLVMValueRef, LLVMValueRef, const char *);
2590
2591static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,2647static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
2592 IrInstructionBinOp *bin_op_instruction)2648 IrInstructionBinOp *bin_op_instruction)
2593{2649{
...@@ -2603,7 +2659,8 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,...@@ -2603,7 +2659,8 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
2603 (op_id == IrBinOpAdd || op_id == IrBinOpSub) &&2659 (op_id == IrBinOpAdd || op_id == IrBinOpSub) &&
2604 op1->value.type->data.pointer.ptr_len == PtrLenUnknown)2660 op1->value.type->data.pointer.ptr_len == PtrLenUnknown)
2605 );2661 );
2606 ZigType *type_entry = op1->value.type;2662 ZigType *operand_type = op1->value.type;
2663 ZigType *scalar_type = (operand_type->id == ZigTypeIdVector) ? operand_type->data.vector.elem_type : operand_type;
26072664
2608 bool want_runtime_safety = bin_op_instruction->safety_check_on &&2665 bool want_runtime_safety = bin_op_instruction->safety_check_on &&
2609 ir_want_runtime_safety(g, &bin_op_instruction->base);2666 ir_want_runtime_safety(g, &bin_op_instruction->base);
...@@ -2629,17 +2686,17 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,...@@ -2629,17 +2686,17 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
2629 case IrBinOpCmpGreaterThan:2686 case IrBinOpCmpGreaterThan:
2630 case IrBinOpCmpLessOrEq:2687 case IrBinOpCmpLessOrEq:
2631 case IrBinOpCmpGreaterOrEq:2688 case IrBinOpCmpGreaterOrEq:
2632 if (type_entry->id == ZigTypeIdFloat) {2689 if (scalar_type->id == ZigTypeIdFloat) {
2633 ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &bin_op_instruction->base));2690 ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &bin_op_instruction->base));
2634 LLVMRealPredicate pred = cmp_op_to_real_predicate(op_id);2691 LLVMRealPredicate pred = cmp_op_to_real_predicate(op_id);
2635 return LLVMBuildFCmp(g->builder, pred, op1_value, op2_value, "");2692 return LLVMBuildFCmp(g->builder, pred, op1_value, op2_value, "");
2636 } else if (type_entry->id == ZigTypeIdInt) {2693 } else if (scalar_type->id == ZigTypeIdInt) {
2637 LLVMIntPredicate pred = cmp_op_to_int_predicate(op_id, type_entry->data.integral.is_signed);2694 LLVMIntPredicate pred = cmp_op_to_int_predicate(op_id, scalar_type->data.integral.is_signed);
2638 return LLVMBuildICmp(g->builder, pred, op1_value, op2_value, "");2695 return LLVMBuildICmp(g->builder, pred, op1_value, op2_value, "");
2639 } else if (type_entry->id == ZigTypeIdEnum ||2696 } else if (scalar_type->id == ZigTypeIdEnum ||
2640 type_entry->id == ZigTypeIdErrorSet ||2697 scalar_type->id == ZigTypeIdErrorSet ||
2641 type_entry->id == ZigTypeIdBool ||2698 scalar_type->id == ZigTypeIdBool ||
2642 get_codegen_ptr_type(type_entry) != nullptr)2699 get_codegen_ptr_type(scalar_type) != nullptr)
2643 {2700 {
2644 LLVMIntPredicate pred = cmp_op_to_int_predicate(op_id, false);2701 LLVMIntPredicate pred = cmp_op_to_int_predicate(op_id, false);
2645 return LLVMBuildICmp(g->builder, pred, op1_value, op2_value, "");2702 return LLVMBuildICmp(g->builder, pred, op1_value, op2_value, "");
...@@ -2652,31 +2709,16 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,...@@ -2652,31 +2709,16 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
2652 case IrBinOpAddWrap:2709 case IrBinOpAddWrap:
2653 case IrBinOpSub:2710 case IrBinOpSub:
2654 case IrBinOpSubWrap: {2711 case IrBinOpSubWrap: {
2655 // These are lookup table using the AddSubMul enum as the lookup.
2656 // If AddSubMul ever changes, then these tables will be out of
2657 // date.
2658 static const BuildBinOpFunc float_op[3] = { LLVMBuildFAdd, LLVMBuildFSub, LLVMBuildFMul };
2659 static const BuildBinOpFunc wrap_op[3] = { LLVMBuildAdd, LLVMBuildSub, LLVMBuildMul };
2660 static const BuildBinOpFunc signed_op[3] = { LLVMBuildNSWAdd, LLVMBuildNSWSub, LLVMBuildNSWMul };
2661 static const BuildBinOpFunc unsigned_op[3] = { LLVMBuildNUWAdd, LLVMBuildNUWSub, LLVMBuildNUWMul };
2662
2663 bool is_vector = type_entry->id == ZigTypeIdVector;
2664 bool is_wrapping = (op_id == IrBinOpSubWrap || op_id == IrBinOpAddWrap || op_id == IrBinOpMultWrap);2712 bool is_wrapping = (op_id == IrBinOpSubWrap || op_id == IrBinOpAddWrap || op_id == IrBinOpMultWrap);
2665 AddSubMul add_sub_mul =2713 AddSubMul add_sub_mul =
2666 op_id == IrBinOpAdd || op_id == IrBinOpAddWrap ? AddSubMulAdd :2714 op_id == IrBinOpAdd || op_id == IrBinOpAddWrap ? AddSubMulAdd :
2667 op_id == IrBinOpSub || op_id == IrBinOpSubWrap ? AddSubMulSub :2715 op_id == IrBinOpSub || op_id == IrBinOpSubWrap ? AddSubMulSub :
2668 AddSubMulMul;2716 AddSubMulMul;
26692717
2670 // The code that is generated for vectors and scalars are the same,2718 if (scalar_type->id == ZigTypeIdPointer) {
2671 // so we can just set type_entry to the vectors elem_type an avoid2719 assert(scalar_type->data.pointer.ptr_len == PtrLenUnknown);
2672 // a lot of repeated code.
2673 if (is_vector)
2674 type_entry = type_entry->data.vector.elem_type;
2675
2676 if (type_entry->id == ZigTypeIdPointer) {
2677 assert(type_entry->data.pointer.ptr_len == PtrLenUnknown);
2678 LLVMValueRef subscript_value;2720 LLVMValueRef subscript_value;
2679 if (is_vector)2721 if (operand_type->id == ZigTypeIdVector)
2680 zig_panic("TODO: Implement vector operations on pointers.");2722 zig_panic("TODO: Implement vector operations on pointers.");
26812723
2682 switch (add_sub_mul) {2724 switch (add_sub_mul) {
...@@ -2692,17 +2734,15 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,...@@ -2692,17 +2734,15 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
26922734
2693 // TODO runtime safety2735 // TODO runtime safety
2694 return LLVMBuildInBoundsGEP(g->builder, op1_value, &subscript_value, 1, "");2736 return LLVMBuildInBoundsGEP(g->builder, op1_value, &subscript_value, 1, "");
2695 } else if (type_entry->id == ZigTypeIdFloat) {2737 } else if (scalar_type->id == ZigTypeIdFloat) {
2696 ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &bin_op_instruction->base));2738 ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &bin_op_instruction->base));
2697 return float_op[add_sub_mul](g->builder, op1_value, op2_value, "");2739 return float_op[add_sub_mul](g->builder, op1_value, op2_value, "");
2698 } else if (type_entry->id == ZigTypeIdInt) {2740 } else if (scalar_type->id == ZigTypeIdInt) {
2699 if (is_wrapping) {2741 if (is_wrapping) {
2700 return wrap_op[add_sub_mul](g->builder, op1_value, op2_value, "");2742 return wrap_op[add_sub_mul](g->builder, op1_value, op2_value, "");
2701 } else if (want_runtime_safety) {2743 } else if (want_runtime_safety) {
2702 if (is_vector)2744 return gen_overflow_op(g, operand_type, add_sub_mul, op1_value, op2_value);
2703 zig_panic("TODO: Implement runtime safety vector operations.");2745 } else if (scalar_type->data.integral.is_signed) {
2704 return gen_overflow_op(g, type_entry, add_sub_mul, op1_value, op2_value);
2705 } else if (type_entry->data.integral.is_signed) {
2706 return signed_op[add_sub_mul](g->builder, op1_value, op2_value, "");2746 return signed_op[add_sub_mul](g->builder, op1_value, op2_value, "");
2707 } else {2747 } else {
2708 return unsigned_op[add_sub_mul](g->builder, op1_value, op2_value, "");2748 return unsigned_op[add_sub_mul](g->builder, op1_value, op2_value, "");
...@@ -2720,15 +2760,14 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,...@@ -2720,15 +2760,14 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
2720 case IrBinOpBitShiftLeftLossy:2760 case IrBinOpBitShiftLeftLossy:
2721 case IrBinOpBitShiftLeftExact:2761 case IrBinOpBitShiftLeftExact:
2722 {2762 {
2723 assert(type_entry->id == ZigTypeIdInt);2763 assert(scalar_type->id == ZigTypeIdInt);
2724 LLVMValueRef op2_casted = gen_widen_or_shorten(g, false, op2->value.type,2764 LLVMValueRef op2_casted = gen_widen_or_shorten(g, false, op2->value.type, scalar_type, op2_value);
2725 type_entry, op2_value);
2726 bool is_sloppy = (op_id == IrBinOpBitShiftLeftLossy);2765 bool is_sloppy = (op_id == IrBinOpBitShiftLeftLossy);
2727 if (is_sloppy) {2766 if (is_sloppy) {
2728 return LLVMBuildShl(g->builder, op1_value, op2_casted, "");2767 return LLVMBuildShl(g->builder, op1_value, op2_casted, "");
2729 } else if (want_runtime_safety) {2768 } else if (want_runtime_safety) {
2730 return gen_overflow_shl_op(g, type_entry, op1_value, op2_casted);2769 return gen_overflow_shl_op(g, scalar_type, op1_value, op2_casted);
2731 } else if (type_entry->data.integral.is_signed) {2770 } else if (scalar_type->data.integral.is_signed) {
2732 return ZigLLVMBuildNSWShl(g->builder, op1_value, op2_casted, "");2771 return ZigLLVMBuildNSWShl(g->builder, op1_value, op2_casted, "");
2733 } else {2772 } else {
2734 return ZigLLVMBuildNUWShl(g->builder, op1_value, op2_casted, "");2773 return ZigLLVMBuildNUWShl(g->builder, op1_value, op2_casted, "");
...@@ -2737,19 +2776,18 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,...@@ -2737,19 +2776,18 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
2737 case IrBinOpBitShiftRightLossy:2776 case IrBinOpBitShiftRightLossy:
2738 case IrBinOpBitShiftRightExact:2777 case IrBinOpBitShiftRightExact:
2739 {2778 {
2740 assert(type_entry->id == ZigTypeIdInt);2779 assert(scalar_type->id == ZigTypeIdInt);
2741 LLVMValueRef op2_casted = gen_widen_or_shorten(g, false, op2->value.type,2780 LLVMValueRef op2_casted = gen_widen_or_shorten(g, false, op2->value.type, scalar_type, op2_value);
2742 type_entry, op2_value);
2743 bool is_sloppy = (op_id == IrBinOpBitShiftRightLossy);2781 bool is_sloppy = (op_id == IrBinOpBitShiftRightLossy);
2744 if (is_sloppy) {2782 if (is_sloppy) {
2745 if (type_entry->data.integral.is_signed) {2783 if (scalar_type->data.integral.is_signed) {
2746 return LLVMBuildAShr(g->builder, op1_value, op2_casted, "");2784 return LLVMBuildAShr(g->builder, op1_value, op2_casted, "");
2747 } else {2785 } else {
2748 return LLVMBuildLShr(g->builder, op1_value, op2_casted, "");2786 return LLVMBuildLShr(g->builder, op1_value, op2_casted, "");
2749 }2787 }
2750 } else if (want_runtime_safety) {2788 } else if (want_runtime_safety) {
2751 return gen_overflow_shr_op(g, type_entry, op1_value, op2_casted);2789 return gen_overflow_shr_op(g, scalar_type, op1_value, op2_casted);
2752 } else if (type_entry->data.integral.is_signed) {2790 } else if (scalar_type->data.integral.is_signed) {
2753 return ZigLLVMBuildAShrExact(g->builder, op1_value, op2_casted, "");2791 return ZigLLVMBuildAShrExact(g->builder, op1_value, op2_casted, "");
2754 } else {2792 } else {
2755 return ZigLLVMBuildLShrExact(g->builder, op1_value, op2_casted, "");2793 return ZigLLVMBuildLShrExact(g->builder, op1_value, op2_casted, "");
...@@ -2757,22 +2795,22 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,...@@ -2757,22 +2795,22 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
2757 }2795 }
2758 case IrBinOpDivUnspecified:2796 case IrBinOpDivUnspecified:
2759 return gen_div(g, want_runtime_safety, ir_want_fast_math(g, &bin_op_instruction->base),2797 return gen_div(g, want_runtime_safety, ir_want_fast_math(g, &bin_op_instruction->base),
2760 op1_value, op2_value, type_entry, DivKindFloat);2798 op1_value, op2_value, scalar_type, DivKindFloat);
2761 case IrBinOpDivExact:2799 case IrBinOpDivExact:
2762 return gen_div(g, want_runtime_safety, ir_want_fast_math(g, &bin_op_instruction->base),2800 return gen_div(g, want_runtime_safety, ir_want_fast_math(g, &bin_op_instruction->base),
2763 op1_value, op2_value, type_entry, DivKindExact);2801 op1_value, op2_value, scalar_type, DivKindExact);
2764 case IrBinOpDivTrunc:2802 case IrBinOpDivTrunc:
2765 return gen_div(g, want_runtime_safety, ir_want_fast_math(g, &bin_op_instruction->base),2803 return gen_div(g, want_runtime_safety, ir_want_fast_math(g, &bin_op_instruction->base),
2766 op1_value, op2_value, type_entry, DivKindTrunc);2804 op1_value, op2_value, scalar_type, DivKindTrunc);
2767 case IrBinOpDivFloor:2805 case IrBinOpDivFloor:
2768 return gen_div(g, want_runtime_safety, ir_want_fast_math(g, &bin_op_instruction->base),2806 return gen_div(g, want_runtime_safety, ir_want_fast_math(g, &bin_op_instruction->base),
2769 op1_value, op2_value, type_entry, DivKindFloor);2807 op1_value, op2_value, scalar_type, DivKindFloor);
2770 case IrBinOpRemRem:2808 case IrBinOpRemRem:
2771 return gen_rem(g, want_runtime_safety, ir_want_fast_math(g, &bin_op_instruction->base),2809 return gen_rem(g, want_runtime_safety, ir_want_fast_math(g, &bin_op_instruction->base),
2772 op1_value, op2_value, type_entry, RemKindRem);2810 op1_value, op2_value, scalar_type, RemKindRem);
2773 case IrBinOpRemMod:2811 case IrBinOpRemMod:
2774 return gen_rem(g, want_runtime_safety, ir_want_fast_math(g, &bin_op_instruction->base),2812 return gen_rem(g, want_runtime_safety, ir_want_fast_math(g, &bin_op_instruction->base),
2775 op1_value, op2_value, type_entry, RemKindMod);2813 op1_value, op2_value, scalar_type, RemKindMod);
2776 }2814 }
2777 zig_unreachable();2815 zig_unreachable();
2778}2816}
...@@ -5209,6 +5247,17 @@ static LLVMValueRef ir_render_array_to_vector(CodeGen *g, IrExecutable *executab...@@ -5209,6 +5247,17 @@ static LLVMValueRef ir_render_array_to_vector(CodeGen *g, IrExecutable *executab
5209 return gen_load_untyped(g, casted_ptr, 0, false, "");5247 return gen_load_untyped(g, casted_ptr, 0, false, "");
5210}5248}
52115249
5250static LLVMValueRef ir_render_assert_zero(CodeGen *g, IrExecutable *executable,
5251 IrInstructionAssertZero *instruction)
5252{
5253 LLVMValueRef target = ir_llvm_value(g, instruction->target);
5254 ZigType *int_type = instruction->target->value.type;
5255 if (ir_want_runtime_safety(g, &instruction->base)) {
5256 return gen_assert_zero(g, target, int_type);
5257 }
5258 return nullptr;
5259}
5260
5212static void set_debug_location(CodeGen *g, IrInstruction *instruction) {5261static void set_debug_location(CodeGen *g, IrInstruction *instruction) {
5213 AstNode *source_node = instruction->source_node;5262 AstNode *source_node = instruction->source_node;
5214 Scope *scope = instruction->scope;5263 Scope *scope = instruction->scope;
...@@ -5458,6 +5507,8 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,...@@ -5458,6 +5507,8 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
5458 return ir_render_array_to_vector(g, executable, (IrInstructionArrayToVector *)instruction);5507 return ir_render_array_to_vector(g, executable, (IrInstructionArrayToVector *)instruction);
5459 case IrInstructionIdVectorToArray:5508 case IrInstructionIdVectorToArray:
5460 return ir_render_vector_to_array(g, executable, (IrInstructionVectorToArray *)instruction);5509 return ir_render_vector_to_array(g, executable, (IrInstructionVectorToArray *)instruction);
5510 case IrInstructionIdAssertZero:
5511 return ir_render_assert_zero(g, executable, (IrInstructionAssertZero *)instruction);
5461 }5512 }
5462 zig_unreachable();5513 zig_unreachable();
5463}5514}
src/ir.cpp+52-14
...@@ -908,6 +908,10 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionArrayToVector *)...@@ -908,6 +908,10 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionArrayToVector *)
908 return IrInstructionIdArrayToVector;908 return IrInstructionIdArrayToVector;
909}909}
910910
911static constexpr IrInstructionId ir_instruction_id(IrInstructionAssertZero *) {
912 return IrInstructionIdAssertZero;
913}
914
911template<typename T>915template<typename T>
912static T *ir_create_instruction(IrBuilder *irb, Scope *scope, AstNode *source_node) {916static T *ir_create_instruction(IrBuilder *irb, Scope *scope, AstNode *source_node) {
913 T *special_instruction = allocate<T>(1);917 T *special_instruction = allocate<T>(1);
...@@ -2858,6 +2862,19 @@ static IrInstruction *ir_build_array_to_vector(IrAnalyze *ira, IrInstruction *so...@@ -2858,6 +2862,19 @@ static IrInstruction *ir_build_array_to_vector(IrAnalyze *ira, IrInstruction *so
2858 return &instruction->base;2862 return &instruction->base;
2859}2863}
28602864
2865static IrInstruction *ir_build_assert_zero(IrAnalyze *ira, IrInstruction *source_instruction,
2866 IrInstruction *target)
2867{
2868 IrInstructionAssertZero *instruction = ir_build_instruction<IrInstructionAssertZero>(&ira->new_irb,
2869 source_instruction->scope, source_instruction->source_node);
2870 instruction->base.value.type = ira->codegen->builtin_types.entry_void;
2871 instruction->target = target;
2872
2873 ir_ref_instruction(target, ira->new_irb.current_basic_block);
2874
2875 return &instruction->base;
2876}
2877
2861static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_scope, size_t *results) {2878static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_scope, size_t *results) {
2862 results[ReturnKindUnconditional] = 0;2879 results[ReturnKindUnconditional] = 0;
2863 results[ReturnKindError] = 0;2880 results[ReturnKindError] = 0;
...@@ -10395,6 +10412,18 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction...@@ -10395,6 +10412,18 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction
10395 return result;10412 return result;
10396 }10413 }
1039710414
10415 // If the destination integer type has no bits, then we can emit a comptime
10416 // zero. However, we still want to emit a runtime safety check to make sure
10417 // the target is zero.
10418 if (!type_has_bits(wanted_type)) {
10419 assert(wanted_type->id == ZigTypeIdInt);
10420 assert(type_has_bits(target->value.type));
10421 ir_build_assert_zero(ira, source_instr, target);
10422 IrInstruction *result = ir_const_unsigned(ira, source_instr, 0);
10423 result->value.type = wanted_type;
10424 return result;
10425 }
10426
10398 IrInstruction *result = ir_build_widen_or_shorten(&ira->new_irb, source_instr->scope,10427 IrInstruction *result = ir_build_widen_or_shorten(&ira->new_irb, source_instr->scope,
10399 source_instr->source_node, target);10428 source_instr->source_node, target);
10400 result->value.type = wanted_type;10429 result->value.type = wanted_type;
...@@ -11481,10 +11510,13 @@ static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructio...@@ -11481,10 +11510,13 @@ static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructio
11481 return ir_unreach_error(ira);11510 return ir_unreach_error(ira);
1148211511
11483 IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->explicit_return_type);11512 IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->explicit_return_type);
11484 if (type_is_invalid(casted_value->value.type) && ira->explicit_return_type_source_node != nullptr) {11513 if (type_is_invalid(casted_value->value.type)) {
11485 ErrorMsg *msg = ira->codegen->errors.last();11514 AstNode *source_node = ira->explicit_return_type_source_node;
11486 add_error_note(ira->codegen, msg, ira->explicit_return_type_source_node,11515 if (source_node != nullptr) {
11487 buf_sprintf("return type declared here"));11516 ErrorMsg *msg = ira->codegen->errors.last();
11517 add_error_note(ira->codegen, msg, source_node,
11518 buf_sprintf("return type declared here"));
11519 }
11488 return ir_unreach_error(ira);11520 return ir_unreach_error(ira);
11489 }11521 }
1149011522
...@@ -17514,21 +17546,16 @@ static void make_enum_field_val(IrAnalyze *ira, ConstExprValue *enum_field_val,...@@ -17514,21 +17546,16 @@ static void make_enum_field_val(IrAnalyze *ira, ConstExprValue *enum_field_val,
17514 enum_field_val->data.x_struct.fields = inner_fields;17546 enum_field_val->data.x_struct.fields = inner_fields;
17515}17547}
1751617548
17517static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstExprValue **out) {17549static Error ir_make_type_info_value(IrAnalyze *ira, AstNode *source_node, ZigType *type_entry, ConstExprValue **out) {
17518 Error err;17550 Error err;
17519 assert(type_entry != nullptr);17551 assert(type_entry != nullptr);
17520 assert(!type_is_invalid(type_entry));17552 assert(!type_is_invalid(type_entry));
1752117553
17522 if ((err = ensure_complete_type(ira->codegen, type_entry)))17554 if ((err = type_resolve(ira->codegen, type_entry, ResolveStatusSizeKnown)))
17523 return err;17555 return err;
1752417556
17525 if (type_entry == ira->codegen->builtin_types.entry_global_error_set) {
17526 zig_panic("TODO implement @typeInfo for global error set");
17527 }
17528
17529 ConstExprValue *result = nullptr;17557 ConstExprValue *result = nullptr;
17530 switch (type_entry->id)17558 switch (type_entry->id) {
17531 {
17532 case ZigTypeIdInvalid:17559 case ZigTypeIdInvalid:
17533 zig_unreachable();17560 zig_unreachable();
17534 case ZigTypeIdMetaType:17561 case ZigTypeIdMetaType:
...@@ -17749,6 +17776,15 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE...@@ -17749,6 +17776,15 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE
17749 ensure_field_index(result->type, "errors", 0);17776 ensure_field_index(result->type, "errors", 0);
1775017777
17751 ZigType *type_info_error_type = ir_type_info_get_type(ira, "Error", nullptr);17778 ZigType *type_info_error_type = ir_type_info_get_type(ira, "Error", nullptr);
17779 if (!resolve_inferred_error_set(ira->codegen, type_entry, source_node)) {
17780 return ErrorSemanticAnalyzeFail;
17781 }
17782 if (type_is_global_error_set(type_entry)) {
17783 ir_add_error_node(ira, source_node,
17784 buf_sprintf("TODO: compiler bug: implement @typeInfo support for anyerror. https://github.com/ziglang/zig/issues/1936"));
17785 return ErrorSemanticAnalyzeFail;
17786 }
17787
17752 uint32_t error_count = type_entry->data.error_set.err_count;17788 uint32_t error_count = type_entry->data.error_set.err_count;
17753 ConstExprValue *error_array = create_const_vals(1);17789 ConstExprValue *error_array = create_const_vals(1);
17754 error_array->special = ConstValSpecialStatic;17790 error_array->special = ConstValSpecialStatic;
...@@ -18074,7 +18110,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE...@@ -18074,7 +18110,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE
18074 {18110 {
18075 ZigType *fn_type = type_entry->data.bound_fn.fn_type;18111 ZigType *fn_type = type_entry->data.bound_fn.fn_type;
18076 assert(fn_type->id == ZigTypeIdFn);18112 assert(fn_type->id == ZigTypeIdFn);
18077 if ((err = ir_make_type_info_value(ira, fn_type, &result)))18113 if ((err = ir_make_type_info_value(ira, source_node, fn_type, &result)))
18078 return err;18114 return err;
1807918115
18080 break;18116 break;
...@@ -18099,7 +18135,7 @@ static IrInstruction *ir_analyze_instruction_type_info(IrAnalyze *ira,...@@ -18099,7 +18135,7 @@ static IrInstruction *ir_analyze_instruction_type_info(IrAnalyze *ira,
18099 ZigType *result_type = ir_type_info_get_type(ira, nullptr, nullptr);18135 ZigType *result_type = ir_type_info_get_type(ira, nullptr, nullptr);
1810018136
18101 ConstExprValue *payload;18137 ConstExprValue *payload;
18102 if ((err = ir_make_type_info_value(ira, type_entry, &payload)))18138 if ((err = ir_make_type_info_value(ira, instruction->base.source_node, type_entry, &payload)))
18103 return ira->codegen->invalid_instruction;18139 return ira->codegen->invalid_instruction;
1810418140
18105 IrInstruction *result = ir_const(ira, &instruction->base, result_type);18141 IrInstruction *result = ir_const(ira, &instruction->base, result_type);
...@@ -21705,6 +21741,7 @@ static IrInstruction *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructio...@@ -21705,6 +21741,7 @@ static IrInstruction *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructio
21705 case IrInstructionIdCmpxchgGen:21741 case IrInstructionIdCmpxchgGen:
21706 case IrInstructionIdArrayToVector:21742 case IrInstructionIdArrayToVector:
21707 case IrInstructionIdVectorToArray:21743 case IrInstructionIdVectorToArray:
21744 case IrInstructionIdAssertZero:
21708 zig_unreachable();21745 zig_unreachable();
2170921746
21710 case IrInstructionIdReturn:21747 case IrInstructionIdReturn:
...@@ -22103,6 +22140,7 @@ bool ir_has_side_effects(IrInstruction *instruction) {...@@ -22103,6 +22140,7 @@ bool ir_has_side_effects(IrInstruction *instruction) {
22103 case IrInstructionIdAtomicRmw:22140 case IrInstructionIdAtomicRmw:
22104 case IrInstructionIdCmpxchgGen:22141 case IrInstructionIdCmpxchgGen:
22105 case IrInstructionIdCmpxchgSrc:22142 case IrInstructionIdCmpxchgSrc:
22143 case IrInstructionIdAssertZero:
22106 return true;22144 return true;
2210722145
22108 case IrInstructionIdPhi:22146 case IrInstructionIdPhi:
src/ir_print.cpp+9
...@@ -984,6 +984,12 @@ static void ir_print_vector_to_array(IrPrint *irp, IrInstructionVectorToArray *i...@@ -984,6 +984,12 @@ static void ir_print_vector_to_array(IrPrint *irp, IrInstructionVectorToArray *i
984 fprintf(irp->f, ")");984 fprintf(irp->f, ")");
985}985}
986986
987static void ir_print_assert_zero(IrPrint *irp, IrInstructionAssertZero *instruction) {
988 fprintf(irp->f, "AssertZero(");
989 ir_print_other_instruction(irp, instruction->target);
990 fprintf(irp->f, ")");
991}
992
987static void ir_print_int_to_err(IrPrint *irp, IrInstructionIntToErr *instruction) {993static void ir_print_int_to_err(IrPrint *irp, IrInstructionIntToErr *instruction) {
988 fprintf(irp->f, "inttoerr ");994 fprintf(irp->f, "inttoerr ");
989 ir_print_other_instruction(irp, instruction->target);995 ir_print_other_instruction(irp, instruction->target);
...@@ -1843,6 +1849,9 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {...@@ -1843,6 +1849,9 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
1843 case IrInstructionIdVectorToArray:1849 case IrInstructionIdVectorToArray:
1844 ir_print_vector_to_array(irp, (IrInstructionVectorToArray *)instruction);1850 ir_print_vector_to_array(irp, (IrInstructionVectorToArray *)instruction);
1845 break;1851 break;
1852 case IrInstructionIdAssertZero:
1853 ir_print_assert_zero(irp, (IrInstructionAssertZero *)instruction);
1854 break;
1846 }1855 }
1847 fprintf(irp->f, "\n");1856 fprintf(irp->f, "\n");
1848}1857}
std/array_list.zig+53-53
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const std = @import("index.zig");1const std = @import("index.zig");
2const debug = std.debug;2const debug = std.debug;
3const assert = debug.assert;3const assert = debug.assert;
4const assertError = debug.assertError;4const testing = std.testing;
5const mem = std.mem;5const mem = std.mem;
6const Allocator = mem.Allocator;6const Allocator = mem.Allocator;
77
...@@ -212,8 +212,8 @@ test "std.ArrayList.init" {...@@ -212,8 +212,8 @@ test "std.ArrayList.init" {
212 var list = ArrayList(i32).init(allocator);212 var list = ArrayList(i32).init(allocator);
213 defer list.deinit();213 defer list.deinit();
214214
215 assert(list.count() == 0);215 testing.expect(list.count() == 0);
216 assert(list.capacity() == 0);216 testing.expect(list.capacity() == 0);
217}217}
218218
219test "std.ArrayList.basic" {219test "std.ArrayList.basic" {
...@@ -224,7 +224,7 @@ test "std.ArrayList.basic" {...@@ -224,7 +224,7 @@ test "std.ArrayList.basic" {
224 defer list.deinit();224 defer list.deinit();
225225
226 // setting on empty list is out of bounds226 // 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
229 {229 {
230 var i: usize = 0;230 var i: usize = 0;
...@@ -236,44 +236,44 @@ test "std.ArrayList.basic" {...@@ -236,44 +236,44 @@ test "std.ArrayList.basic" {
236 {236 {
237 var i: usize = 0;237 var i: usize = 0;
238 while (i < 10) : (i += 1) {238 while (i < 10) : (i += 1) {
239 assert(list.items[i] == @intCast(i32, i + 1));239 testing.expect(list.items[i] == @intCast(i32, i + 1));
240 }240 }
241 }241 }
242242
243 for (list.toSlice()) |v, i| {243 for (list.toSlice()) |v, i| {
244 assert(v == @intCast(i32, i + 1));244 testing.expect(v == @intCast(i32, i + 1));
245 }245 }
246246
247 for (list.toSliceConst()) |v, i| {247 for (list.toSliceConst()) |v, i| {
248 assert(v == @intCast(i32, i + 1));248 testing.expect(v == @intCast(i32, i + 1));
249 }249 }
250250
251 assert(list.pop() == 10);251 testing.expect(list.pop() == 10);
252 assert(list.len == 9);252 testing.expect(list.len == 9);
253253
254 list.appendSlice([]const i32{254 list.appendSlice([]const i32{
255 1,255 1,
256 2,256 2,
257 3,257 3,
258 }) catch unreachable;258 }) catch unreachable;
259 assert(list.len == 12);259 testing.expect(list.len == 12);
260 assert(list.pop() == 3);260 testing.expect(list.pop() == 3);
261 assert(list.pop() == 2);261 testing.expect(list.pop() == 2);
262 assert(list.pop() == 1);262 testing.expect(list.pop() == 1);
263 assert(list.len == 9);263 testing.expect(list.len == 9);
264264
265 list.appendSlice([]const i32{}) catch unreachable;265 list.appendSlice([]const i32{}) catch unreachable;
266 assert(list.len == 9);266 testing.expect(list.len == 9);
267267
268 // can only set on indices < self.len268 // can only set on indices < self.len
269 list.set(7, 33);269 list.set(7, 33);
270 list.set(8, 42);270 list.set(8, 42);
271271
272 assertError(list.setOrError(9, 99), error.OutOfBounds);272 testing.expectError(error.OutOfBounds, list.setOrError(9, 99));
273 assertError(list.setOrError(10, 123), error.OutOfBounds);273 testing.expectError(error.OutOfBounds, list.setOrError(10, 123));
274274
275 assert(list.pop() == 42);275 testing.expect(list.pop() == 42);
276 assert(list.pop() == 33);276 testing.expect(list.pop() == 33);
277}277}
278278
279test "std.ArrayList.swapRemove" {279test "std.ArrayList.swapRemove" {
...@@ -289,18 +289,18 @@ test "std.ArrayList.swapRemove" {...@@ -289,18 +289,18 @@ test "std.ArrayList.swapRemove" {
289 try list.append(7);289 try list.append(7);
290290
291 //remove from middle291 //remove from middle
292 assert(list.swapRemove(3) == 4);292 testing.expect(list.swapRemove(3) == 4);
293 assert(list.at(3) == 7);293 testing.expect(list.at(3) == 7);
294 assert(list.len == 6);294 testing.expect(list.len == 6);
295295
296 //remove from end296 //remove from end
297 assert(list.swapRemove(5) == 6);297 testing.expect(list.swapRemove(5) == 6);
298 assert(list.len == 5);298 testing.expect(list.len == 5);
299299
300 //remove from front300 //remove from front
301 assert(list.swapRemove(0) == 1);301 testing.expect(list.swapRemove(0) == 1);
302 assert(list.at(0) == 5);302 testing.expect(list.at(0) == 5);
303 assert(list.len == 4);303 testing.expect(list.len == 4);
304}304}
305305
306test "std.ArrayList.swapRemoveOrError" {306test "std.ArrayList.swapRemoveOrError" {
...@@ -308,27 +308,27 @@ test "std.ArrayList.swapRemoveOrError" {...@@ -308,27 +308,27 @@ test "std.ArrayList.swapRemoveOrError" {
308 defer list.deinit();308 defer list.deinit();
309309
310 // Test just after initialization310 // Test just after initialization
311 assertError(list.swapRemoveOrError(0), error.OutOfBounds);311 testing.expectError(error.OutOfBounds, list.swapRemoveOrError(0));
312312
313 // Test after adding one item and remote it313 // Test after adding one item and remote it
314 try list.append(1);314 try list.append(1);
315 assert((try list.swapRemoveOrError(0)) == 1);315 testing.expect((try list.swapRemoveOrError(0)) == 1);
316 assertError(list.swapRemoveOrError(0), error.OutOfBounds);316 testing.expectError(error.OutOfBounds, list.swapRemoveOrError(0));
317317
318 // Test after adding two items and remote both318 // Test after adding two items and remote both
319 try list.append(1);319 try list.append(1);
320 try list.append(2);320 try list.append(2);
321 assert((try list.swapRemoveOrError(1)) == 2);321 testing.expect((try list.swapRemoveOrError(1)) == 2);
322 assert((try list.swapRemoveOrError(0)) == 1);322 testing.expect((try list.swapRemoveOrError(0)) == 1);
323 assertError(list.swapRemoveOrError(0), error.OutOfBounds);323 testing.expectError(error.OutOfBounds, list.swapRemoveOrError(0));
324324
325 // Test out of bounds with one item325 // Test out of bounds with one item
326 try list.append(1);326 try list.append(1);
327 assertError(list.swapRemoveOrError(1), error.OutOfBounds);327 testing.expectError(error.OutOfBounds, list.swapRemoveOrError(1));
328328
329 // Test out of bounds with two items329 // Test out of bounds with two items
330 try list.append(2);330 try list.append(2);
331 assertError(list.swapRemoveOrError(2), error.OutOfBounds);331 testing.expectError(error.OutOfBounds, list.swapRemoveOrError(2));
332}332}
333333
334test "std.ArrayList.iterator" {334test "std.ArrayList.iterator" {
...@@ -342,22 +342,22 @@ test "std.ArrayList.iterator" {...@@ -342,22 +342,22 @@ test "std.ArrayList.iterator" {
342 var count: i32 = 0;342 var count: i32 = 0;
343 var it = list.iterator();343 var it = list.iterator();
344 while (it.next()) |next| {344 while (it.next()) |next| {
345 assert(next == count + 1);345 testing.expect(next == count + 1);
346 count += 1;346 count += 1;
347 }347 }
348348
349 assert(count == 3);349 testing.expect(count == 3);
350 assert(it.next() == null);350 testing.expect(it.next() == null);
351 it.reset();351 it.reset();
352 count = 0;352 count = 0;
353 while (it.next()) |next| {353 while (it.next()) |next| {
354 assert(next == count + 1);354 testing.expect(next == count + 1);
355 count += 1;355 count += 1;
356 if (count == 2) break;356 if (count == 2) break;
357 }357 }
358358
359 it.reset();359 it.reset();
360 assert(it.next().? == 1);360 testing.expect(it.next().? == 1);
361}361}
362362
363test "std.ArrayList.insert" {363test "std.ArrayList.insert" {
...@@ -368,10 +368,10 @@ test "std.ArrayList.insert" {...@@ -368,10 +368,10 @@ test "std.ArrayList.insert" {
368 try list.append(2);368 try list.append(2);
369 try list.append(3);369 try list.append(3);
370 try list.insert(0, 5);370 try list.insert(0, 5);
371 assert(list.items[0] == 5);371 testing.expect(list.items[0] == 5);
372 assert(list.items[1] == 1);372 testing.expect(list.items[1] == 1);
373 assert(list.items[2] == 2);373 testing.expect(list.items[2] == 2);
374 assert(list.items[3] == 3);374 testing.expect(list.items[3] == 3);
375}375}
376376
377test "std.ArrayList.insertSlice" {377test "std.ArrayList.insertSlice" {
...@@ -386,17 +386,17 @@ test "std.ArrayList.insertSlice" {...@@ -386,17 +386,17 @@ test "std.ArrayList.insertSlice" {
386 9,386 9,
387 8,387 8,
388 });388 });
389 assert(list.items[0] == 1);389 testing.expect(list.items[0] == 1);
390 assert(list.items[1] == 9);390 testing.expect(list.items[1] == 9);
391 assert(list.items[2] == 8);391 testing.expect(list.items[2] == 8);
392 assert(list.items[3] == 2);392 testing.expect(list.items[3] == 2);
393 assert(list.items[4] == 3);393 testing.expect(list.items[4] == 3);
394 assert(list.items[5] == 4);394 testing.expect(list.items[5] == 4);
395395
396 const items = []const i32{1};396 const items = []const i32{1};
397 try list.insertSlice(0, items[0..0]);397 try list.insertSlice(0, items[0..0]);
398 assert(list.len == 6);398 testing.expect(list.len == 6);
399 assert(list.items[0] == 1);399 testing.expect(list.items[0] == 1);
400}400}
401401
402const Item = struct {402const Item = struct {
...@@ -407,5 +407,5 @@ const Item = struct {...@@ -407,5 +407,5 @@ const Item = struct {
407test "std.ArrayList: ArrayList(T) of struct T" {407test "std.ArrayList: ArrayList(T) of struct T" {
408 var root = Item{ .integer = 1, .sub_items = ArrayList(Item).init(debug.global_allocator) };408 var root = Item{ .integer = 1, .sub_items = ArrayList(Item).init(debug.global_allocator) };
409 try root.sub_items.append( Item{ .integer = 42, .sub_items = ArrayList(Item).init(debug.global_allocator) } );409 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);
411}411}
std/atomic/queue.zig+12-11
...@@ -3,6 +3,7 @@ const builtin = @import("builtin");...@@ -3,6 +3,7 @@ const builtin = @import("builtin");
3const AtomicOrder = builtin.AtomicOrder;3const AtomicOrder = builtin.AtomicOrder;
4const AtomicRmwOp = builtin.AtomicRmwOp;4const AtomicRmwOp = builtin.AtomicRmwOp;
5const assert = std.debug.assert;5const assert = std.debug.assert;
6const expect = std.testing.expect;
67
7/// Many producer, many consumer, non-allocating, thread-safe.8/// Many producer, many consumer, non-allocating, thread-safe.
8/// Uses a mutex to protect access.9/// Uses a mutex to protect access.
...@@ -174,14 +175,14 @@ test "std.atomic.Queue" {...@@ -174,14 +175,14 @@ test "std.atomic.Queue" {
174 {175 {
175 var i: usize = 0;176 var i: usize = 0;
176 while (i < put_thread_count) : (i += 1) {177 while (i < put_thread_count) : (i += 1) {
177 std.debug.assertOrPanic(startPuts(&context) == 0);178 expect(startPuts(&context) == 0);
178 }179 }
179 }180 }
180 context.puts_done = 1;181 context.puts_done = 1;
181 {182 {
182 var i: usize = 0;183 var i: usize = 0;
183 while (i < put_thread_count) : (i += 1) {184 while (i < put_thread_count) : (i += 1) {
184 std.debug.assertOrPanic(startGets(&context) == 0);185 expect(startGets(&context) == 0);
185 }186 }
186 }187 }
187 } else {188 } else {
...@@ -264,7 +265,7 @@ test "std.atomic.Queue single-threaded" {...@@ -264,7 +265,7 @@ test "std.atomic.Queue single-threaded" {
264 };265 };
265 queue.put(&node_1);266 queue.put(&node_1);
266267
267 assert(queue.get().?.data == 0);268 expect(queue.get().?.data == 0);
268269
269 var node_2 = Queue(i32).Node{270 var node_2 = Queue(i32).Node{
270 .data = 2,271 .data = 2,
...@@ -280,9 +281,9 @@ test "std.atomic.Queue single-threaded" {...@@ -280,9 +281,9 @@ test "std.atomic.Queue single-threaded" {
280 };281 };
281 queue.put(&node_3);282 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
287 var node_4 = Queue(i32).Node{288 var node_4 = Queue(i32).Node{
288 .data = 4,289 .data = 4,
...@@ -291,12 +292,12 @@ test "std.atomic.Queue single-threaded" {...@@ -291,12 +292,12 @@ test "std.atomic.Queue single-threaded" {
291 };292 };
292 queue.put(&node_4);293 queue.put(&node_4);
293294
294 assert(queue.get().?.data == 3);295 expect(queue.get().?.data == 3);
295 node_3.next = null;296 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);
300}301}
301302
302test "std.atomic.Queue dump" {303test "std.atomic.Queue dump" {
...@@ -311,7 +312,7 @@ test "std.atomic.Queue dump" {...@@ -311,7 +312,7 @@ test "std.atomic.Queue dump" {
311 // Test empty stream312 // Test empty stream
312 sos.reset();313 sos.reset();
313 try queue.dumpToStream(SliceOutStream.Error, &sos.stream);314 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],
315 \\head: (null)316 \\head: (null)
316 \\tail: (null)317 \\tail: (null)
317 \\318 \\
...@@ -335,7 +336,7 @@ test "std.atomic.Queue dump" {...@@ -335,7 +336,7 @@ test "std.atomic.Queue dump" {
335 \\ (null)336 \\ (null)
336 \\337 \\
337 , @ptrToInt(queue.head), @ptrToInt(queue.tail));338 , @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
340 // Test a stream with two elements341 // Test a stream with two elements
341 var node_1 = Queue(i32).Node{342 var node_1 = Queue(i32).Node{
...@@ -356,5 +357,5 @@ test "std.atomic.Queue dump" {...@@ -356,5 +357,5 @@ test "std.atomic.Queue dump" {
356 \\ (null)357 \\ (null)
357 \\358 \\
358 , @ptrToInt(queue.head), @ptrToInt(queue.head.?.next), @ptrToInt(queue.tail));359 , @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));
360}361}
std/atomic/stack.zig+3-2
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const assert = std.debug.assert;1const assert = std.debug.assert;
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const AtomicOrder = builtin.AtomicOrder;3const AtomicOrder = builtin.AtomicOrder;
4const expect = std.testing.expect;
45
5/// Many reader, many writer, non-allocating, thread-safe6/// Many reader, many writer, non-allocating, thread-safe
6/// Uses a spinlock to protect push() and pop()7/// Uses a spinlock to protect push() and pop()
...@@ -108,14 +109,14 @@ test "std.atomic.stack" {...@@ -108,14 +109,14 @@ test "std.atomic.stack" {
108 {109 {
109 var i: usize = 0;110 var i: usize = 0;
110 while (i < put_thread_count) : (i += 1) {111 while (i < put_thread_count) : (i += 1) {
111 std.debug.assertOrPanic(startPuts(&context) == 0);112 expect(startPuts(&context) == 0);
112 }113 }
113 }114 }
114 context.puts_done = 1;115 context.puts_done = 1;
115 {116 {
116 var i: usize = 0;117 var i: usize = 0;
117 while (i < put_thread_count) : (i += 1) {118 while (i < put_thread_count) : (i += 1) {
118 std.debug.assertOrPanic(startGets(&context) == 0);119 expect(startGets(&context) == 0);
119 }120 }
120 }121 }
121 } else {122 } else {
std/base64.zig+7-6
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1const std = @import("index.zig");1const std = @import("index.zig");
2const assert = std.debug.assert;2const assert = std.debug.assert;
3const testing = std.testing;
3const mem = std.mem;4const mem = std.mem;
45
5pub const standard_alphabet_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";6pub const standard_alphabet_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
...@@ -394,7 +395,7 @@ fn testAllApis(expected_decoded: []const u8, expected_encoded: []const u8) !void...@@ -394,7 +395,7 @@ fn testAllApis(expected_decoded: []const u8, expected_encoded: []const u8) !void
394 var buffer: [0x100]u8 = undefined;395 var buffer: [0x100]u8 = undefined;
395 var encoded = buffer[0..Base64Encoder.calcSize(expected_decoded.len)];396 var encoded = buffer[0..Base64Encoder.calcSize(expected_decoded.len)];
396 standard_encoder.encode(encoded, expected_decoded);397 standard_encoder.encode(encoded, expected_decoded);
397 assert(mem.eql(u8, encoded, expected_encoded));398 testing.expectEqualSlices(u8, expected_encoded, encoded);
398 }399 }
399400
400 // Base64Decoder401 // Base64Decoder
...@@ -402,7 +403,7 @@ fn testAllApis(expected_decoded: []const u8, expected_encoded: []const u8) !void...@@ -402,7 +403,7 @@ fn testAllApis(expected_decoded: []const u8, expected_encoded: []const u8) !void
402 var buffer: [0x100]u8 = undefined;403 var buffer: [0x100]u8 = undefined;
403 var decoded = buffer[0..try standard_decoder.calcSize(expected_encoded)];404 var decoded = buffer[0..try standard_decoder.calcSize(expected_encoded)];
404 try standard_decoder.decode(decoded, expected_encoded);405 try standard_decoder.decode(decoded, expected_encoded);
405 assert(mem.eql(u8, decoded, expected_decoded));406 testing.expectEqualSlices(u8, expected_decoded, decoded);
406 }407 }
407408
408 // Base64DecoderWithIgnore409 // Base64DecoderWithIgnore
...@@ -411,8 +412,8 @@ fn testAllApis(expected_decoded: []const u8, expected_encoded: []const u8) !void...@@ -411,8 +412,8 @@ fn testAllApis(expected_decoded: []const u8, expected_encoded: []const u8) !void
411 var buffer: [0x100]u8 = undefined;412 var buffer: [0x100]u8 = undefined;
412 var decoded = buffer[0..Base64DecoderWithIgnore.calcSizeUpperBound(expected_encoded.len)];413 var decoded = buffer[0..Base64DecoderWithIgnore.calcSizeUpperBound(expected_encoded.len)];
413 var written = try standard_decoder_ignore_nothing.decode(decoded, expected_encoded);414 var written = try standard_decoder_ignore_nothing.decode(decoded, expected_encoded);
414 assert(written <= decoded.len);415 testing.expect(written <= decoded.len);
415 assert(mem.eql(u8, decoded[0..written], expected_decoded));416 testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]);
416 }417 }
417418
418 // Base64DecoderUnsafe419 // Base64DecoderUnsafe
...@@ -420,7 +421,7 @@ fn testAllApis(expected_decoded: []const u8, expected_encoded: []const u8) !void...@@ -420,7 +421,7 @@ fn testAllApis(expected_decoded: []const u8, expected_encoded: []const u8) !void
420 var buffer: [0x100]u8 = undefined;421 var buffer: [0x100]u8 = undefined;
421 var decoded = buffer[0..standard_decoder_unsafe.calcSize(expected_encoded)];422 var decoded = buffer[0..standard_decoder_unsafe.calcSize(expected_encoded)];
422 standard_decoder_unsafe.decode(decoded, expected_encoded);423 standard_decoder_unsafe.decode(decoded, expected_encoded);
423 assert(mem.eql(u8, decoded, expected_decoded));424 testing.expectEqualSlices(u8, expected_decoded, decoded);
424 }425 }
425}426}
426427
...@@ -429,7 +430,7 @@ fn testDecodeIgnoreSpace(expected_decoded: []const u8, encoded: []const u8) !voi...@@ -429,7 +430,7 @@ fn testDecodeIgnoreSpace(expected_decoded: []const u8, encoded: []const u8) !voi
429 var buffer: [0x100]u8 = undefined;430 var buffer: [0x100]u8 = undefined;
430 var decoded = buffer[0..Base64DecoderWithIgnore.calcSizeUpperBound(encoded.len)];431 var decoded = buffer[0..Base64DecoderWithIgnore.calcSizeUpperBound(encoded.len)];
431 var written = try standard_decoder_ignore_space.decode(decoded, encoded);432 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]);
433}434}
434435
435fn testError(encoded: []const u8, expected_err: anyerror) !void {436fn testError(encoded: []const u8, expected_err: anyerror) !void {
std/buf_map.zig+8-8
...@@ -2,7 +2,7 @@ const std = @import("index.zig");...@@ -2,7 +2,7 @@ const std = @import("index.zig");
2const HashMap = std.HashMap;2const HashMap = std.HashMap;
3const mem = std.mem;3const mem = std.mem;
4const Allocator = mem.Allocator;4const Allocator = mem.Allocator;
5const assert = std.debug.assert;5const testing = std.testing;
66
7/// BufMap copies keys and values before they go into the map, and7/// BufMap copies keys and values before they go into the map, and
8/// frees them when they get removed.8/// frees them when they get removed.
...@@ -90,17 +90,17 @@ test "BufMap" {...@@ -90,17 +90,17 @@ test "BufMap" {
90 defer bufmap.deinit();90 defer bufmap.deinit();
9191
92 try bufmap.set("x", "1");92 try bufmap.set("x", "1");
93 assert(mem.eql(u8, bufmap.get("x").?, "1"));93 testing.expect(mem.eql(u8, bufmap.get("x").?, "1"));
94 assert(1 == bufmap.count());94 testing.expect(1 == bufmap.count());
9595
96 try bufmap.set("x", "2");96 try bufmap.set("x", "2");
97 assert(mem.eql(u8, bufmap.get("x").?, "2"));97 testing.expect(mem.eql(u8, bufmap.get("x").?, "2"));
98 assert(1 == bufmap.count());98 testing.expect(1 == bufmap.count());
9999
100 try bufmap.set("x", "3");100 try bufmap.set("x", "3");
101 assert(mem.eql(u8, bufmap.get("x").?, "3"));101 testing.expect(mem.eql(u8, bufmap.get("x").?, "3"));
102 assert(1 == bufmap.count());102 testing.expect(1 == bufmap.count());
103103
104 bufmap.delete("x");104 bufmap.delete("x");
105 assert(0 == bufmap.count());105 testing.expect(0 == bufmap.count());
106}106}
std/buf_set.zig+3-3
...@@ -2,7 +2,7 @@ const std = @import("index.zig");...@@ -2,7 +2,7 @@ const std = @import("index.zig");
2const HashMap = @import("hash_map.zig").HashMap;2const HashMap = @import("hash_map.zig").HashMap;
3const mem = @import("mem.zig");3const mem = @import("mem.zig");
4const Allocator = mem.Allocator;4const Allocator = mem.Allocator;
5const assert = std.debug.assert;5const testing = std.testing;
66
7pub const BufSet = struct {7pub const BufSet = struct {
8 hash_map: BufSetHashMap,8 hash_map: BufSetHashMap,
...@@ -68,9 +68,9 @@ test "BufSet" {...@@ -68,9 +68,9 @@ test "BufSet" {
68 defer bufset.deinit();68 defer bufset.deinit();
6969
70 try bufset.put("x");70 try bufset.put("x");
71 assert(bufset.count() == 1);71 testing.expect(bufset.count() == 1);
72 bufset.delete("x");72 bufset.delete("x");
73 assert(bufset.count() == 0);73 testing.expect(bufset.count() == 0);
7474
75 try bufset.put("x");75 try bufset.put("x");
76 try bufset.put("y");76 try bufset.put("y");
std/buffer.zig+8-7
...@@ -3,6 +3,7 @@ const debug = std.debug;...@@ -3,6 +3,7 @@ const debug = std.debug;
3const mem = std.mem;3const mem = std.mem;
4const Allocator = mem.Allocator;4const Allocator = mem.Allocator;
5const assert = debug.assert;5const assert = debug.assert;
6const testing = std.testing;
6const ArrayList = std.ArrayList;7const ArrayList = std.ArrayList;
78
8/// A buffer that allocates memory and maintains a null byte at the end.9/// A buffer that allocates memory and maintains a null byte at the end.
...@@ -141,19 +142,19 @@ test "simple Buffer" {...@@ -141,19 +142,19 @@ test "simple Buffer" {
141 const cstr = @import("cstr.zig");142 const cstr = @import("cstr.zig");
142143
143 var buf = try Buffer.init(debug.global_allocator, "");144 var buf = try Buffer.init(debug.global_allocator, "");
144 assert(buf.len() == 0);145 testing.expect(buf.len() == 0);
145 try buf.append("hello");146 try buf.append("hello");
146 try buf.append(" ");147 try buf.append(" ");
147 try buf.append("world");148 try buf.append("world");
148 assert(buf.eql("hello world"));149 testing.expect(buf.eql("hello world"));
149 assert(mem.eql(u8, cstr.toSliceConst(buf.toSliceConst().ptr), buf.toSliceConst()));150 testing.expect(mem.eql(u8, cstr.toSliceConst(buf.toSliceConst().ptr), buf.toSliceConst()));
150151
151 var buf2 = try Buffer.initFromBuffer(buf);152 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 testing.expect(buf.startsWith("hell"));
155 assert(buf.endsWith("orld"));156 testing.expect(buf.endsWith("orld"));
156157
157 try buf2.resize(4);158 try buf2.resize(4);
158 assert(buf.startsWith(buf2.toSlice()));159 testing.expect(buf.startsWith(buf2.toSlice()));
159}160}
std/crypto/chacha20.zig+8-7
...@@ -4,6 +4,7 @@ const std = @import("../index.zig");...@@ -4,6 +4,7 @@ const std = @import("../index.zig");
4const mem = std.mem;4const mem = std.mem;
5const endian = std.endian;5const endian = std.endian;
6const assert = std.debug.assert;6const assert = std.debug.assert;
7const testing = std.testing;
7const builtin = @import("builtin");8const builtin = @import("builtin");
8const maxInt = std.math.maxInt;9const maxInt = std.math.maxInt;
910
...@@ -216,12 +217,12 @@ test "crypto.chacha20 test vector sunscreen" {...@@ -216,12 +217,12 @@ test "crypto.chacha20 test vector sunscreen" {
216 };217 };
217218
218 chaCha20IETF(result[0..], input[0..], 1, key, nonce);219 chaCha20IETF(result[0..], input[0..], 1, key, nonce);
219 assert(mem.eql(u8, expected_result, result));220 testing.expectEqualSlices(u8, expected_result, result);
220221
221 // Chacha20 is self-reversing.222 // Chacha20 is self-reversing.
222 var plaintext: [114]u8 = undefined;223 var plaintext: [114]u8 = undefined;
223 chaCha20IETF(plaintext[0..], result[0..], 1, key, nonce);224 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);
225}226}
226227
227// https://tools.ietf.org/html/draft-agl-tls-chacha20poly1305-04#section-7228// https://tools.ietf.org/html/draft-agl-tls-chacha20poly1305-04#section-7
...@@ -256,7 +257,7 @@ test "crypto.chacha20 test vector 1" {...@@ -256,7 +257,7 @@ test "crypto.chacha20 test vector 1" {
256 const nonce = []u8{ 0, 0, 0, 0, 0, 0, 0, 0 };257 const nonce = []u8{ 0, 0, 0, 0, 0, 0, 0, 0 };
257258
258 chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);259 chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);
259 assert(mem.eql(u8, expected_result, result));260 testing.expectEqualSlices(u8, expected_result, result);
260}261}
261262
262test "crypto.chacha20 test vector 2" {263test "crypto.chacha20 test vector 2" {
...@@ -290,7 +291,7 @@ test "crypto.chacha20 test vector 2" {...@@ -290,7 +291,7 @@ test "crypto.chacha20 test vector 2" {
290 const nonce = []u8{ 0, 0, 0, 0, 0, 0, 0, 0 };291 const nonce = []u8{ 0, 0, 0, 0, 0, 0, 0, 0 };
291292
292 chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);293 chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);
293 assert(mem.eql(u8, expected_result, result));294 testing.expectEqualSlices(u8, expected_result, result);
294}295}
295296
296test "crypto.chacha20 test vector 3" {297test "crypto.chacha20 test vector 3" {
...@@ -324,7 +325,7 @@ test "crypto.chacha20 test vector 3" {...@@ -324,7 +325,7 @@ test "crypto.chacha20 test vector 3" {
324 const nonce = []u8{ 0, 0, 0, 0, 0, 0, 0, 1 };325 const nonce = []u8{ 0, 0, 0, 0, 0, 0, 0, 1 };
325326
326 chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);327 chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);
327 assert(mem.eql(u8, expected_result, result));328 testing.expectEqualSlices(u8, expected_result, result);
328}329}
329330
330test "crypto.chacha20 test vector 4" {331test "crypto.chacha20 test vector 4" {
...@@ -358,7 +359,7 @@ test "crypto.chacha20 test vector 4" {...@@ -358,7 +359,7 @@ test "crypto.chacha20 test vector 4" {
358 const nonce = []u8{ 1, 0, 0, 0, 0, 0, 0, 0 };359 const nonce = []u8{ 1, 0, 0, 0, 0, 0, 0, 0 };
359360
360 chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);361 chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);
361 assert(mem.eql(u8, expected_result, result));362 testing.expectEqualSlices(u8, expected_result, result);
362}363}
363364
364test "crypto.chacha20 test vector 5" {365test "crypto.chacha20 test vector 5" {
...@@ -430,5 +431,5 @@ test "crypto.chacha20 test vector 5" {...@@ -430,5 +431,5 @@ test "crypto.chacha20 test vector 5" {
430 };431 };
431432
432 chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);433 chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);
433 assert(mem.eql(u8, expected_result, result));434 testing.expectEqualSlices(u8, expected_result, result);
434}435}
std/crypto/poly1305.zig+1-1
...@@ -230,5 +230,5 @@ test "poly1305 rfc7439 vector1" {...@@ -230,5 +230,5 @@ test "poly1305 rfc7439 vector1" {
230 var mac: [16]u8 = undefined;230 var mac: [16]u8 = undefined;
231 Poly1305.create(mac[0..], msg, key);231 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);
234}234}
std/crypto/test.zig+5-4
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const debug = @import("../debug/index.zig");1const std = @import("../index.zig");
2const mem = @import("../mem.zig");2const testing = std.testing;
3const fmt = @import("../fmt/index.zig");3const mem = std.mem;
4const fmt = std.fmt;
45
5// Hash using the specified hasher `H` asserting `expected == H(input)`.6// Hash using the specified hasher `H` asserting `expected == H(input)`.
6pub fn assertEqualHash(comptime Hasher: var, comptime expected: []const u8, input: []const u8) void {7pub 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 {...@@ -17,5 +18,5 @@ pub fn assertEqual(comptime expected: []const u8, input: []const u8) void {
17 r.* = fmt.parseInt(u8, expected[2 * i .. 2 * i + 2], 16) catch unreachable;18 r.* = fmt.parseInt(u8, expected[2 * i .. 2 * i + 2], 16) catch unreachable;
18 }19 }
1920
20 debug.assert(mem.eql(u8, expected_bytes, input));21 testing.expectEqualSlices(u8, expected_bytes, input);
21}22}
std/crypto/x25519.zig+12-12
...@@ -581,8 +581,8 @@ test "x25519 public key calculation from secret key" {...@@ -581,8 +581,8 @@ test "x25519 public key calculation from secret key" {
581 var pk_calculated: [32]u8 = undefined;581 var pk_calculated: [32]u8 = undefined;
582 try fmt.hexToBytes(sk[0..], "8052030376d47112be7f73ed7a019293dd12ad910b654455798b4667d73de166");582 try fmt.hexToBytes(sk[0..], "8052030376d47112be7f73ed7a019293dd12ad910b654455798b4667d73de166");
583 try fmt.hexToBytes(pk_expected[0..], "f1814f0e8ff1043d8a44d25babff3cedcae6c22c3edaa48f857ae70de2baae50");583 try fmt.hexToBytes(pk_expected[0..], "f1814f0e8ff1043d8a44d25babff3cedcae6c22c3edaa48f857ae70de2baae50");
584 std.debug.assert(X25519.createPublicKey(pk_calculated[0..], sk));584 std.testing.expect(X25519.createPublicKey(pk_calculated[0..], sk));
585 std.debug.assert(std.mem.eql(u8, pk_calculated, pk_expected));585 std.testing.expect(std.mem.eql(u8, pk_calculated, pk_expected));
586}586}
587587
588test "x25519 rfc7748 vector1" {588test "x25519 rfc7748 vector1" {
...@@ -593,8 +593,8 @@ test "x25519 rfc7748 vector1" {...@@ -593,8 +593,8 @@ test "x25519 rfc7748 vector1" {
593593
594 var output: [32]u8 = undefined;594 var output: [32]u8 = undefined;
595595
596 std.debug.assert(X25519.create(output[0..], secret_key, public_key));596 std.testing.expect(X25519.create(output[0..], secret_key, public_key));
597 std.debug.assert(std.mem.eql(u8, output, expected_output));597 std.testing.expect(std.mem.eql(u8, output, expected_output));
598}598}
599599
600test "x25519 rfc7748 vector2" {600test "x25519 rfc7748 vector2" {
...@@ -605,8 +605,8 @@ test "x25519 rfc7748 vector2" {...@@ -605,8 +605,8 @@ test "x25519 rfc7748 vector2" {
605605
606 var output: [32]u8 = undefined;606 var output: [32]u8 = undefined;
607607
608 std.debug.assert(X25519.create(output[0..], secret_key, public_key));608 std.testing.expect(X25519.create(output[0..], secret_key, public_key));
609 std.debug.assert(std.mem.eql(u8, output, expected_output));609 std.testing.expect(std.mem.eql(u8, output, expected_output));
610}610}
611611
612test "x25519 rfc7748 one iteration" {612test "x25519 rfc7748 one iteration" {
...@@ -619,13 +619,13 @@ test "x25519 rfc7748 one iteration" {...@@ -619,13 +619,13 @@ test "x25519 rfc7748 one iteration" {
619 var i: usize = 0;619 var i: usize = 0;
620 while (i < 1) : (i += 1) {620 while (i < 1) : (i += 1) {
621 var output: [32]u8 = undefined;621 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
624 std.mem.copy(u8, u[0..], k[0..]);624 std.mem.copy(u8, u[0..], k[0..]);
625 std.mem.copy(u8, k[0..], output[0..]);625 std.mem.copy(u8, k[0..], output[0..]);
626 }626 }
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));
629}629}
630630
631test "x25519 rfc7748 1,000 iterations" {631test "x25519 rfc7748 1,000 iterations" {
...@@ -643,13 +643,13 @@ test "x25519 rfc7748 1,000 iterations" {...@@ -643,13 +643,13 @@ test "x25519 rfc7748 1,000 iterations" {
643 var i: usize = 0;643 var i: usize = 0;
644 while (i < 1000) : (i += 1) {644 while (i < 1000) : (i += 1) {
645 var output: [32]u8 = undefined;645 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
648 std.mem.copy(u8, u[0..], k[0..]);648 std.mem.copy(u8, u[0..], k[0..]);
649 std.mem.copy(u8, k[0..], output[0..]);649 std.mem.copy(u8, k[0..], output[0..]);
650 }650 }
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));
653}653}
654654
655test "x25519 rfc7748 1,000,000 iterations" {655test "x25519 rfc7748 1,000,000 iterations" {
...@@ -666,11 +666,11 @@ test "x25519 rfc7748 1,000,000 iterations" {...@@ -666,11 +666,11 @@ test "x25519 rfc7748 1,000,000 iterations" {
666 var i: usize = 0;666 var i: usize = 0;
667 while (i < 1000000) : (i += 1) {667 while (i < 1000000) : (i += 1) {
668 var output: [32]u8 = undefined;668 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
671 std.mem.copy(u8, u[0..], k[0..]);671 std.mem.copy(u8, u[0..], k[0..]);
672 std.mem.copy(u8, k[0..], output[0..]);672 std.mem.copy(u8, k[0..], output[0..]);
673 }673 }
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));
676}676}
std/cstr.zig+3-3
...@@ -2,7 +2,7 @@ const std = @import("index.zig");...@@ -2,7 +2,7 @@ const std = @import("index.zig");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const debug = std.debug;3const debug = std.debug;
4const mem = std.mem;4const mem = std.mem;
5const assert = debug.assert;5const testing = std.testing;
66
7pub const line_sep = switch (builtin.os) {7pub const line_sep = switch (builtin.os) {
8 builtin.Os.windows => "\r\n",8 builtin.Os.windows => "\r\n",
...@@ -42,8 +42,8 @@ test "cstr fns" {...@@ -42,8 +42,8 @@ test "cstr fns" {
42}42}
4343
44fn testCStrFnsImpl() void {44fn testCStrFnsImpl() void {
45 assert(cmp(c"aoeu", c"aoez") == -1);45 testing.expect(cmp(c"aoeu", c"aoez") == -1);
46 assert(len(c"123456789") == 9);46 testing.expect(len(c"123456789") == 9);
47}47}
4848
49/// Returns a mutable slice with 1 more byte of length which is a null byte.49/// 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 {...@@ -107,37 +107,15 @@ pub fn dumpStackTrace(stack_trace: *const builtin.StackTrace) void {
107/// This function invokes undefined behavior when `ok` is `false`.107/// This function invokes undefined behavior when `ok` is `false`.
108/// In Debug and ReleaseSafe modes, calls to this function are always108/// In Debug and ReleaseSafe modes, calls to this function are always
109/// generated, and the `unreachable` statement triggers a panic.109/// generated, and the `unreachable` statement triggers a panic.
110/// In ReleaseFast and ReleaseSmall modes, calls to this function can be110/// In ReleaseFast and ReleaseSmall modes, calls to this function are
111/// optimized away.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.
112pub fn assert(ok: bool) void {117pub fn assert(ok: bool) void {
113 if (!ok) {118 if (!ok) unreachable; // assertion failure
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 }
141}119}
142120
143pub fn panic(comptime format: []const u8, args: ...) noreturn {121pub fn panic(comptime format: []const u8, args: ...) noreturn {
std/dynamic_library.zig+2-1
...@@ -6,6 +6,7 @@ const mem = std.mem;...@@ -6,6 +6,7 @@ const mem = std.mem;
6const cstr = std.cstr;6const cstr = std.cstr;
7const os = std.os;7const os = std.os;
8const assert = std.debug.assert;8const assert = std.debug.assert;
9const testing = std.testing;
9const elf = std.elf;10const elf = std.elf;
10const linux = os.linux;11const linux = os.linux;
11const windows = os.windows;12const windows = os.windows;
...@@ -206,7 +207,7 @@ test "dynamic_library" {...@@ -206,7 +207,7 @@ test "dynamic_library" {
206 };207 };
207208
208 const dynlib = DynLib.open(std.debug.global_allocator, libname) catch |err| {209 const dynlib = DynLib.open(std.debug.global_allocator, libname) catch |err| {
209 assert(err == error.FileNotFound);210 testing.expect(err == error.FileNotFound);
210 return;211 return;
211 };212 };
212 @panic("Expected error from function");213 @panic("Expected error from function");
std/event/channel.zig+5-4
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const std = @import("../index.zig");1const std = @import("../index.zig");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const assert = std.debug.assert;3const assert = std.debug.assert;
4const testing = std.testing;
4const AtomicRmwOp = builtin.AtomicRmwOp;5const AtomicRmwOp = builtin.AtomicRmwOp;
5const AtomicOrder = builtin.AtomicOrder;6const AtomicOrder = builtin.AtomicOrder;
6const Loop = std.event.Loop;7const Loop = std.event.Loop;
...@@ -350,19 +351,19 @@ async fn testChannelGetter(loop: *Loop, channel: *Channel(i32)) void {...@@ -350,19 +351,19 @@ async fn testChannelGetter(loop: *Loop, channel: *Channel(i32)) void {
350351
351 const value1_promise = try async channel.get();352 const value1_promise = try async channel.get();
352 const value1 = await value1_promise;353 const value1 = await value1_promise;
353 assert(value1 == 1234);354 testing.expect(value1 == 1234);
354355
355 const value2_promise = try async channel.get();356 const value2_promise = try async channel.get();
356 const value2 = await value2_promise;357 const value2 = await value2_promise;
357 assert(value2 == 4567);358 testing.expect(value2 == 4567);
358359
359 const value3_promise = try async channel.getOrNull();360 const value3_promise = try async channel.getOrNull();
360 const value3 = await value3_promise;361 const value3 = await value3_promise;
361 assert(value3 == null);362 testing.expect(value3 == null);
362363
363 const last_put = try async testPut(channel, 4444);364 const last_put = try async testPut(channel, 4444);
364 const value4 = await try async channel.getOrNull();365 const value4 = await try async channel.getOrNull();
365 assert(value4.? == 4444);366 testing.expect(value4.? == 4444);
366 await last_put;367 await last_put;
367}368}
368369
std/event/fs.zig+5-4
...@@ -2,6 +2,7 @@ const builtin = @import("builtin");...@@ -2,6 +2,7 @@ const builtin = @import("builtin");
2const std = @import("../index.zig");2const std = @import("../index.zig");
3const event = std.event;3const event = std.event;
4const assert = std.debug.assert;4const assert = std.debug.assert;
5const testing = std.testing;
5const os = std.os;6const os = std.os;
6const mem = std.mem;7const mem = std.mem;
7const posix = os.posix;8const posix = os.posix;
...@@ -1349,13 +1350,13 @@ async fn testFsWatch(loop: *Loop) !void {...@@ -1349,13 +1350,13 @@ async fn testFsWatch(loop: *Loop) !void {
1349 try await try async writeFile(loop, file_path, contents);1350 try await try async writeFile(loop, file_path, contents);
13501351
1351 const read_contents = try await try async readFile(loop, file_path, 1024 * 1024);1352 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
1354 // now watch the file1355 // now watch the file
1355 var watch = try Watch(void).create(loop, 0);1356 var watch = try Watch(void).create(loop, 0);
1356 defer watch.destroy();1357 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
1360 const ev = try async watch.channel.get();1361 const ev = try async watch.channel.get();
1361 var ev_consumed = false;1362 var ev_consumed = false;
...@@ -1375,10 +1376,10 @@ async fn testFsWatch(loop: *Loop) !void {...@@ -1375,10 +1376,10 @@ async fn testFsWatch(loop: *Loop) !void {
1375 WatchEventId.Delete => @panic("wrong event"),1376 WatchEventId.Delete => @panic("wrong event"),
1376 }1377 }
1377 const contents_updated = try await try async readFile(loop, file_path, 1024 * 1024);1378 const contents_updated = try await try async readFile(loop, file_path, 1024 * 1024);
1378 assert(mem.eql(u8, contents_updated,1379 testing.expectEqualSlices(u8,
1379 \\line 11380 \\line 1
1380 \\lorem ipsum1381 \\lorem ipsum
1381 ));1382 , contents_updated);
13821383
1383 // TODO test deleting the file and then re-adding it. we should get events for both1384 // TODO test deleting the file and then re-adding it. we should get events for both
1384}1385}
std/event/future.zig+2-1
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1const std = @import("../index.zig");1const std = @import("../index.zig");
2const assert = std.debug.assert;2const assert = std.debug.assert;
3const testing = std.testing;
3const builtin = @import("builtin");4const builtin = @import("builtin");
4const AtomicRmwOp = builtin.AtomicRmwOp;5const AtomicRmwOp = builtin.AtomicRmwOp;
5const AtomicOrder = builtin.AtomicOrder;6const AtomicOrder = builtin.AtomicOrder;
...@@ -114,7 +115,7 @@ async fn testFuture(loop: *Loop) void {...@@ -114,7 +115,7 @@ async fn testFuture(loop: *Loop) void {
114115
115 const result = (await a) + (await b);116 const result = (await a) + (await b);
116 cancel c;117 cancel c;
117 assert(result == 12);118 testing.expect(result == 12);
118}119}
119120
120async fn waitOnFuture(future: *Future(i32)) i32 {121async fn waitOnFuture(future: *Future(i32)) i32 {
std/event/group.zig+3-3
...@@ -4,7 +4,7 @@ const Lock = std.event.Lock;...@@ -4,7 +4,7 @@ const Lock = std.event.Lock;
4const Loop = std.event.Loop;4const Loop = std.event.Loop;
5const AtomicRmwOp = builtin.AtomicRmwOp;5const AtomicRmwOp = builtin.AtomicRmwOp;
6const AtomicOrder = builtin.AtomicOrder;6const AtomicOrder = builtin.AtomicOrder;
7const assert = std.debug.assert;7const testing = std.testing;
88
9/// ReturnType must be `void` or `E!void`9/// ReturnType must be `void` or `E!void`
10pub fn Group(comptime ReturnType: type) type {10pub fn Group(comptime ReturnType: type) type {
...@@ -146,12 +146,12 @@ async fn testGroup(loop: *Loop) void {...@@ -146,12 +146,12 @@ async fn testGroup(loop: *Loop) void {
146 group.add(async sleepALittle(&count) catch @panic("memory")) catch @panic("memory");146 group.add(async sleepALittle(&count) catch @panic("memory")) catch @panic("memory");
147 group.call(increaseByTen, &count) catch @panic("memory");147 group.call(increaseByTen, &count) catch @panic("memory");
148 await (async group.wait() catch @panic("memory"));148 await (async group.wait() catch @panic("memory"));
149 assert(count == 11);149 testing.expect(count == 11);
150150
151 var another = Group(anyerror!void).init(loop);151 var another = Group(anyerror!void).init(loop);
152 another.add(async somethingElse() catch @panic("memory")) catch @panic("memory");152 another.add(async somethingElse() catch @panic("memory")) catch @panic("memory");
153 another.call(doSomethingThatFails) catch @panic("memory");153 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")));
155}155}
156156
157async fn sleepALittle(count: *usize) void {157async fn sleepALittle(count: *usize) void {
std/event/lock.zig+2-1
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const std = @import("../index.zig");1const std = @import("../index.zig");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const assert = std.debug.assert;3const assert = std.debug.assert;
4const testing = std.testing;
4const mem = std.mem;5const mem = std.mem;
5const AtomicRmwOp = builtin.AtomicRmwOp;6const AtomicRmwOp = builtin.AtomicRmwOp;
6const AtomicOrder = builtin.AtomicOrder;7const AtomicOrder = builtin.AtomicOrder;
...@@ -141,7 +142,7 @@ test "std.event.Lock" {...@@ -141,7 +142,7 @@ test "std.event.Lock" {
141 defer cancel handle;142 defer cancel handle;
142 loop.run();143 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);
145}146}
146147
147async fn testLock(loop: *Loop, lock: *Lock) void {148async fn testLock(loop: *Loop, lock: *Lock) void {
std/event/loop.zig+3-2
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const std = @import("../index.zig");1const std = @import("../index.zig");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const assert = std.debug.assert;3const assert = std.debug.assert;
4const testing = std.testing;
4const mem = std.mem;5const mem = std.mem;
5const AtomicRmwOp = builtin.AtomicRmwOp;6const AtomicRmwOp = builtin.AtomicRmwOp;
6const AtomicOrder = builtin.AtomicOrder;7const AtomicOrder = builtin.AtomicOrder;
...@@ -896,7 +897,7 @@ test "std.event.Loop - call" {...@@ -896,7 +897,7 @@ test "std.event.Loop - call" {
896897
897 loop.run();898 loop.run();
898899
899 assert(did_it);900 testing.expect(did_it);
900}901}
901902
902async fn testEventLoop() i32 {903async fn testEventLoop() i32 {
...@@ -905,6 +906,6 @@ async fn testEventLoop() i32 {...@@ -905,6 +906,6 @@ async fn testEventLoop() i32 {
905906
906async fn testEventLoop2(h: promise->i32, did_it: *bool) void {907async fn testEventLoop2(h: promise->i32, did_it: *bool) void {
907 const value = await h;908 const value = await h;
908 assert(value == 1234);909 testing.expect(value == 1234);
909 did_it.* = true;910 did_it.* = true;
910}911}
std/event/net.zig+2-2
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const std = @import("../index.zig");1const std = @import("../index.zig");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const assert = std.debug.assert;3const testing = std.testing;
4const event = std.event;4const event = std.event;
5const mem = std.mem;5const mem = std.mem;
6const os = std.os;6const os = std.os;
...@@ -326,7 +326,7 @@ async fn doAsyncTest(loop: *Loop, address: *const std.net.Address, server: *Serv...@@ -326,7 +326,7 @@ async fn doAsyncTest(loop: *Loop, address: *const std.net.Address, server: *Serv
326 var buf: [512]u8 = undefined;326 var buf: [512]u8 = undefined;
327 const amt_read = try socket_file.read(buf[0..]);327 const amt_read = try socket_file.read(buf[0..]);
328 const msg = buf[0..amt_read];328 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"));
330 server.close();330 server.close();
331}331}
332332
std/event/rwlock.zig+4-3
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const std = @import("../index.zig");1const std = @import("../index.zig");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const assert = std.debug.assert;3const assert = std.debug.assert;
4const testing = std.testing;
4const mem = std.mem;5const mem = std.mem;
5const AtomicRmwOp = builtin.AtomicRmwOp;6const AtomicRmwOp = builtin.AtomicRmwOp;
6const AtomicOrder = builtin.AtomicOrder;7const AtomicOrder = builtin.AtomicOrder;
...@@ -231,7 +232,7 @@ test "std.event.RwLock" {...@@ -231,7 +232,7 @@ test "std.event.RwLock" {
231 loop.run();232 loop.run();
232233
233 const expected_result = [1]i32{shared_it_count * @intCast(i32, shared_test_data.len)} ** shared_test_data.len;234 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);
235}236}
236237
237async fn testLock(loop: *Loop, lock: *RwLock) void {238async fn testLock(loop: *Loop, lock: *RwLock) void {
...@@ -293,7 +294,7 @@ async fn readRunner(lock: *RwLock) void {...@@ -293,7 +294,7 @@ async fn readRunner(lock: *RwLock) void {
293 const handle = await lock_promise;294 const handle = await lock_promise;
294 defer handle.release();295 defer handle.release();
295296
296 assert(shared_test_index == 0);297 testing.expect(shared_test_index == 0);
297 assert(shared_test_data[i] == @intCast(i32, shared_count));298 testing.expect(shared_test_data[i] == @intCast(i32, shared_count));
298 }299 }
299}300}
std/fmt/index.zig+79-79
...@@ -2,7 +2,7 @@ const std = @import("../index.zig");...@@ -2,7 +2,7 @@ const std = @import("../index.zig");
2const math = std.math;2const math = std.math;
3const debug = std.debug;3const debug = std.debug;
4const assert = debug.assert;4const assert = debug.assert;
5const assertError = debug.assertError;5const testing = std.testing;
6const mem = std.mem;6const mem = std.mem;
7const builtin = @import("builtin");7const builtin = @import("builtin");
8const errol = @import("errol/index.zig");8const errol = @import("errol/index.zig");
...@@ -588,7 +588,7 @@ pub fn formatFloatDecimal(...@@ -588,7 +588,7 @@ pub fn formatFloatDecimal(
588 }588 }
589589
590 // Remaining fractional portion, zero-padding if insufficient.590 // Remaining fractional portion, zero-padding if insufficient.
591 debug.assert(precision >= printed);591 assert(precision >= printed);
592 if (num_digits_whole_no_pad + precision - printed < float_decimal.digits.len) {592 if (num_digits_whole_no_pad + precision - printed < float_decimal.digits.len) {
593 try output(context, float_decimal.digits[num_digits_whole_no_pad .. num_digits_whole_no_pad + precision - printed]);593 try output(context, float_decimal.digits[num_digits_whole_no_pad .. num_digits_whole_no_pad + precision - printed]);
594 return;594 return;
...@@ -798,13 +798,13 @@ pub fn parseInt(comptime T: type, buf: []const u8, radix: u8) !T {...@@ -798,13 +798,13 @@ pub fn parseInt(comptime T: type, buf: []const u8, radix: u8) !T {
798}798}
799799
800test "fmt.parseInt" {800test "fmt.parseInt" {
801 assert((parseInt(i32, "-10", 10) catch unreachable) == -10);801 testing.expect((parseInt(i32, "-10", 10) catch unreachable) == -10);
802 assert((parseInt(i32, "+10", 10) catch unreachable) == 10);802 testing.expect((parseInt(i32, "+10", 10) catch unreachable) == 10);
803 assert(if (parseInt(i32, " 10", 10)) |_| false else |err| err == error.InvalidCharacter);803 testing.expect(if (parseInt(i32, " 10", 10)) |_| false else |err| err == error.InvalidCharacter);
804 assert(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 assert(if (parseInt(u32, "-10", 10)) |_| false else |err| err == error.InvalidCharacter);805 testing.expect(if (parseInt(u32, "-10", 10)) |_| false else |err| err == error.InvalidCharacter);
806 assert((parseInt(u8, "255", 10) catch unreachable) == 255);806 testing.expect((parseInt(u8, "255", 10) catch unreachable) == 255);
807 assert(if (parseInt(u8, "256", 10)) |_| false else |err| err == error.Overflow);807 testing.expect(if (parseInt(u8, "256", 10)) |_| false else |err| err == error.Overflow);
808}808}
809809
810const ParseUnsignedError = error{810const ParseUnsignedError = error{
...@@ -829,30 +829,30 @@ pub fn parseUnsigned(comptime T: type, buf: []const u8, radix: u8) ParseUnsigned...@@ -829,30 +829,30 @@ pub fn parseUnsigned(comptime T: type, buf: []const u8, radix: u8) ParseUnsigned
829}829}
830830
831test "parseUnsigned" {831test "parseUnsigned" {
832 assert((try parseUnsigned(u16, "050124", 10)) == 50124);832 testing.expect((try parseUnsigned(u16, "050124", 10)) == 50124);
833 assert((try parseUnsigned(u16, "65535", 10)) == 65535);833 testing.expect((try parseUnsigned(u16, "65535", 10)) == 65535);
834 assertError(parseUnsigned(u16, "65536", 10), error.Overflow);834 testing.expectError(error.Overflow, parseUnsigned(u16, "65536", 10));
835835
836 assert((try parseUnsigned(u64, "0ffffffffffffffff", 16)) == 0xffffffffffffffff);836 testing.expect((try parseUnsigned(u64, "0ffffffffffffffff", 16)) == 0xffffffffffffffff);
837 assertError(parseUnsigned(u64, "10000000000000000", 16), error.Overflow);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);841 testing.expect((try parseUnsigned(u7, "1", 10)) == 1);
842 assert((try parseUnsigned(u7, "1000", 2)) == 8);842 testing.expect((try parseUnsigned(u7, "1000", 2)) == 8);
843843
844 assertError(parseUnsigned(u32, "f", 10), error.InvalidCharacter);844 testing.expectError(error.InvalidCharacter, parseUnsigned(u32, "f", 10));
845 assertError(parseUnsigned(u8, "109", 8), error.InvalidCharacter);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
849 // these numbers should fit even though the radix itself doesn't fit in the destination type849 // these numbers should fit even though the radix itself doesn't fit in the destination type
850 assert((try parseUnsigned(u1, "0", 10)) == 0);850 testing.expect((try parseUnsigned(u1, "0", 10)) == 0);
851 assert((try parseUnsigned(u1, "1", 10)) == 1);851 testing.expect((try parseUnsigned(u1, "1", 10)) == 1);
852 assertError(parseUnsigned(u1, "2", 10), error.Overflow);852 testing.expectError(error.Overflow, parseUnsigned(u1, "2", 10));
853 assert((try parseUnsigned(u1, "001", 16)) == 1);853 testing.expect((try parseUnsigned(u1, "001", 16)) == 1);
854 assert((try parseUnsigned(u2, "3", 16)) == 3);854 testing.expect((try parseUnsigned(u2, "3", 16)) == 3);
855 assertError(parseUnsigned(u2, "4", 16), error.Overflow);855 testing.expectError(error.Overflow, parseUnsigned(u2, "4", 16));
856}856}
857857
858pub fn charToDigit(c: u8, radix: u8) (error{InvalidCharacter}!u8) {858pub fn charToDigit(c: u8, radix: u8) (error{InvalidCharacter}!u8) {
...@@ -910,19 +910,19 @@ fn countSize(size: *usize, bytes: []const u8) (error{}!void) {...@@ -910,19 +910,19 @@ fn countSize(size: *usize, bytes: []const u8) (error{}!void) {
910test "buf print int" {910test "buf print int" {
911 var buffer: [max_int_digits]u8 = undefined;911 var buffer: [max_int_digits]u8 = undefined;
912 const buf = buffer[0..];912 const buf = buffer[0..];
913 assert(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 2, false, 0), "-101111000110000101001110"));913 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 2, false, 0), "-101111000110000101001110"));
914 assert(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 10, false, 0), "-12345678"));914 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 10, false, 0), "-12345678"));
915 assert(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 16, false, 0), "-bc614e"));915 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 16, false, 0), "-bc614e"));
916 assert(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 16, true, 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"));920 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, u32(666), 10, false, 6), "000666"));
921 assert(mem.eql(u8, bufPrintIntToSlice(buf, u32(0x1234), 16, false, 6), "001234"));921 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, u32(0x1234), 16, false, 6), "001234"));
922 assert(mem.eql(u8, bufPrintIntToSlice(buf, u32(0x1234), 16, false, 1), "1234"));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"));924 testing.expect(mem.eql(u8, bufPrintIntToSlice(buf, i32(42), 10, false, 3), "+42"));
925 assert(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"));
926}926}
927927
928fn bufPrintIntToSlice(buf: []u8, value: var, base: u8, uppercase: bool, width: usize) []u8 {928fn bufPrintIntToSlice(buf: []u8, value: var, base: u8, uppercase: bool, width: usize) []u8 {
...@@ -939,7 +939,7 @@ test "parse u64 digit too big" {...@@ -939,7 +939,7 @@ test "parse u64 digit too big" {
939939
940test "parse unsigned comptime" {940test "parse unsigned comptime" {
941 comptime {941 comptime {
942 assert((try parseUnsigned(usize, "2", 10)) == 2);942 testing.expect((try parseUnsigned(usize, "2", 10)) == 2);
943 }943 }
944}944}
945945
...@@ -977,17 +977,17 @@ test "fmt.format" {...@@ -977,17 +977,17 @@ test "fmt.format" {
977 var context = BufPrintContext{ .remaining = buf1[0..] };977 var context = BufPrintContext{ .remaining = buf1[0..] };
978 try formatType(1234, "", &context, error{BufferTooSmall}, bufPrintWrite);978 try formatType(1234, "", &context, error{BufferTooSmall}, bufPrintWrite);
979 var res = buf1[0 .. buf1.len - context.remaining.len];979 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
982 context = BufPrintContext{ .remaining = buf1[0..] };982 context = BufPrintContext{ .remaining = buf1[0..] };
983 try formatType('a', "c", &context, error{BufferTooSmall}, bufPrintWrite);983 try formatType('a', "c", &context, error{BufferTooSmall}, bufPrintWrite);
984 res = buf1[0 .. buf1.len - context.remaining.len];984 res = buf1[0 .. buf1.len - context.remaining.len];
985 assert(mem.eql(u8, res, "a"));985 testing.expect(mem.eql(u8, res, "a"));
986986
987 context = BufPrintContext{ .remaining = buf1[0..] };987 context = BufPrintContext{ .remaining = buf1[0..] };
988 try formatType(0b1100, "b", &context, error{BufferTooSmall}, bufPrintWrite);988 try formatType(0b1100, "b", &context, error{BufferTooSmall}, bufPrintWrite);
989 res = buf1[0 .. buf1.len - context.remaining.len];989 res = buf1[0 .. buf1.len - context.remaining.len];
990 assert(mem.eql(u8, res, "1100"));990 testing.expect(mem.eql(u8, res, "1100"));
991 }991 }
992 {992 {
993 const value: [3]u8 = "abc";993 const value: [3]u8 = "abc";
...@@ -1053,19 +1053,19 @@ test "fmt.format" {...@@ -1053,19 +1053,19 @@ test "fmt.format" {
1053 var buf1: [32]u8 = undefined;1053 var buf1: [32]u8 = undefined;
1054 const value: f32 = 1.34;1054 const value: f32 = 1.34;
1055 const result = try bufPrint(buf1[0..], "f32: {e}\n", value);1055 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"));
1057 }1057 }
1058 {1058 {
1059 var buf1: [32]u8 = undefined;1059 var buf1: [32]u8 = undefined;
1060 const value: f32 = 12.34;1060 const value: f32 = 12.34;
1061 const result = try bufPrint(buf1[0..], "f32: {e}\n", value);1061 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"));
1063 }1063 }
1064 {1064 {
1065 var buf1: [32]u8 = undefined;1065 var buf1: [32]u8 = undefined;
1066 const value: f64 = -12.34e10;1066 const value: f64 = -12.34e10;
1067 const result = try bufPrint(buf1[0..], "f64: {e}\n", value);1067 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"));
1069 }1069 }
1070 {1070 {
1071 // This fails on release due to a minor rounding difference.1071 // This fails on release due to a minor rounding difference.
...@@ -1075,26 +1075,26 @@ test "fmt.format" {...@@ -1075,26 +1075,26 @@ test "fmt.format" {
1075 var buf1: [32]u8 = undefined;1075 var buf1: [32]u8 = undefined;
1076 const value: f64 = 9.999960e-40;1076 const value: f64 = 9.999960e-40;
1077 const result = try bufPrint(buf1[0..], "f64: {e}\n", value);1077 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"));
1079 }1079 }
1080 }1080 }
1081 {1081 {
1082 var buf1: [32]u8 = undefined;1082 var buf1: [32]u8 = undefined;
1083 const value: f64 = 1.409706e-42;1083 const value: f64 = 1.409706e-42;
1084 const result = try bufPrint(buf1[0..], "f64: {e5}\n", value);1084 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"));
1086 }1086 }
1087 {1087 {
1088 var buf1: [32]u8 = undefined;1088 var buf1: [32]u8 = undefined;
1089 const value: f64 = @bitCast(f32, u32(814313563));1089 const value: f64 = @bitCast(f32, u32(814313563));
1090 const result = try bufPrint(buf1[0..], "f64: {e5}\n", value);1090 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"));
1092 }1092 }
1093 {1093 {
1094 var buf1: [32]u8 = undefined;1094 var buf1: [32]u8 = undefined;
1095 const value: f64 = @bitCast(f32, u32(1006632960));1095 const value: f64 = @bitCast(f32, u32(1006632960));
1096 const result = try bufPrint(buf1[0..], "f64: {e5}\n", value);1096 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"));
1098 }1098 }
1099 {1099 {
1100 // libc rounds 1.000005e+05 to 1.00000e+05 but zig does 1.00001e+05.1100 // libc rounds 1.000005e+05 to 1.00000e+05 but zig does 1.00001e+05.
...@@ -1102,47 +1102,47 @@ test "fmt.format" {...@@ -1102,47 +1102,47 @@ test "fmt.format" {
1102 var buf1: [32]u8 = undefined;1102 var buf1: [32]u8 = undefined;
1103 const value: f64 = @bitCast(f32, u32(1203982400));1103 const value: f64 = @bitCast(f32, u32(1203982400));
1104 const result = try bufPrint(buf1[0..], "f64: {e5}\n", value);1104 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"));
1106 }1106 }
1107 {1107 {
1108 var buf1: [32]u8 = undefined;1108 var buf1: [32]u8 = undefined;
1109 const result = try bufPrint(buf1[0..], "f64: {}\n", math.nan_f64);1109 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"));
1111 }1111 }
1112 if (builtin.arch != builtin.Arch.armv8) {1112 if (builtin.arch != builtin.Arch.armv8) {
1113 // negative nan is not defined by IEE 754,1113 // negative nan is not defined by IEE 754,
1114 // and ARM thus normalizes it to positive nan1114 // and ARM thus normalizes it to positive nan
1115 var buf1: [32]u8 = undefined;1115 var buf1: [32]u8 = undefined;
1116 const result = try bufPrint(buf1[0..], "f64: {}\n", -math.nan_f64);1116 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"));
1118 }1118 }
1119 {1119 {
1120 var buf1: [32]u8 = undefined;1120 var buf1: [32]u8 = undefined;
1121 const result = try bufPrint(buf1[0..], "f64: {}\n", math.inf_f64);1121 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"));
1123 }1123 }
1124 {1124 {
1125 var buf1: [32]u8 = undefined;1125 var buf1: [32]u8 = undefined;
1126 const result = try bufPrint(buf1[0..], "f64: {}\n", -math.inf_f64);1126 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"));
1128 }1128 }
1129 {1129 {
1130 var buf1: [64]u8 = undefined;1130 var buf1: [64]u8 = undefined;
1131 const value: f64 = 1.52314e+29;1131 const value: f64 = 1.52314e+29;
1132 const result = try bufPrint(buf1[0..], "f64: {.}\n", value);1132 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"));
1134 }1134 }
1135 {1135 {
1136 var buf1: [32]u8 = undefined;1136 var buf1: [32]u8 = undefined;
1137 const value: f32 = 1.1234;1137 const value: f32 = 1.1234;
1138 const result = try bufPrint(buf1[0..], "f32: {.1}\n", value);1138 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"));
1140 }1140 }
1141 {1141 {
1142 var buf1: [32]u8 = undefined;1142 var buf1: [32]u8 = undefined;
1143 const value: f32 = 1234.567;1143 const value: f32 = 1234.567;
1144 const result = try bufPrint(buf1[0..], "f32: {.2}\n", value);1144 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"));
1146 }1146 }
1147 {1147 {
1148 var buf1: [32]u8 = undefined;1148 var buf1: [32]u8 = undefined;
...@@ -1150,92 +1150,92 @@ test "fmt.format" {...@@ -1150,92 +1150,92 @@ test "fmt.format" {
1150 const result = try bufPrint(buf1[0..], "f32: {.4}\n", value);1150 const result = try bufPrint(buf1[0..], "f32: {.4}\n", value);
1151 // -11.1234 is converted to f64 -11.12339... internally (errol3() function takes f64).1151 // -11.1234 is converted to f64 -11.12339... internally (errol3() function takes f64).
1152 // -11.12339... is rounded back up to -11.12341152 // -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"));
1154 }1154 }
1155 {1155 {
1156 var buf1: [32]u8 = undefined;1156 var buf1: [32]u8 = undefined;
1157 const value: f32 = 91.12345;1157 const value: f32 = 91.12345;
1158 const result = try bufPrint(buf1[0..], "f32: {.5}\n", value);1158 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"));
1160 }1160 }
1161 {1161 {
1162 var buf1: [32]u8 = undefined;1162 var buf1: [32]u8 = undefined;
1163 const value: f64 = 91.12345678901235;1163 const value: f64 = 91.12345678901235;
1164 const result = try bufPrint(buf1[0..], "f64: {.10}\n", value);1164 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"));
1166 }1166 }
1167 {1167 {
1168 var buf1: [32]u8 = undefined;1168 var buf1: [32]u8 = undefined;
1169 const value: f64 = 0.0;1169 const value: f64 = 0.0;
1170 const result = try bufPrint(buf1[0..], "f64: {.5}\n", value);1170 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"));
1172 }1172 }
1173 {1173 {
1174 var buf1: [32]u8 = undefined;1174 var buf1: [32]u8 = undefined;
1175 const value: f64 = 5.700;1175 const value: f64 = 5.700;
1176 const result = try bufPrint(buf1[0..], "f64: {.0}\n", value);1176 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"));
1178 }1178 }
1179 {1179 {
1180 var buf1: [32]u8 = undefined;1180 var buf1: [32]u8 = undefined;
1181 const value: f64 = 9.999;1181 const value: f64 = 9.999;
1182 const result = try bufPrint(buf1[0..], "f64: {.1}\n", value);1182 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"));
1184 }1184 }
1185 {1185 {
1186 var buf1: [32]u8 = undefined;1186 var buf1: [32]u8 = undefined;
1187 const value: f64 = 1.0;1187 const value: f64 = 1.0;
1188 const result = try bufPrint(buf1[0..], "f64: {.3}\n", value);1188 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"));
1190 }1190 }
1191 {1191 {
1192 var buf1: [32]u8 = undefined;1192 var buf1: [32]u8 = undefined;
1193 const value: f64 = 0.0003;1193 const value: f64 = 0.0003;
1194 const result = try bufPrint(buf1[0..], "f64: {.8}\n", value);1194 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"));
1196 }1196 }
1197 {1197 {
1198 var buf1: [32]u8 = undefined;1198 var buf1: [32]u8 = undefined;
1199 const value: f64 = 1.40130e-45;1199 const value: f64 = 1.40130e-45;
1200 const result = try bufPrint(buf1[0..], "f64: {.5}\n", value);1200 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"));
1202 }1202 }
1203 {1203 {
1204 var buf1: [32]u8 = undefined;1204 var buf1: [32]u8 = undefined;
1205 const value: f64 = 9.999960e-40;1205 const value: f64 = 9.999960e-40;
1206 const result = try bufPrint(buf1[0..], "f64: {.5}\n", value);1206 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"));
1208 }1208 }
1209 // libc checks1209 // libc checks
1210 {1210 {
1211 var buf1: [32]u8 = undefined;1211 var buf1: [32]u8 = undefined;
1212 const value: f64 = f64(@bitCast(f32, u32(916964781)));1212 const value: f64 = f64(@bitCast(f32, u32(916964781)));
1213 const result = try bufPrint(buf1[0..], "f64: {.5}\n", value);1213 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"));
1215 }1215 }
1216 {1216 {
1217 var buf1: [32]u8 = undefined;1217 var buf1: [32]u8 = undefined;
1218 const value: f64 = f64(@bitCast(f32, u32(925353389)));1218 const value: f64 = f64(@bitCast(f32, u32(925353389)));
1219 const result = try bufPrint(buf1[0..], "f64: {.5}\n", value);1219 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"));
1221 }1221 }
1222 {1222 {
1223 var buf1: [32]u8 = undefined;1223 var buf1: [32]u8 = undefined;
1224 const value: f64 = f64(@bitCast(f32, u32(1036831278)));1224 const value: f64 = f64(@bitCast(f32, u32(1036831278)));
1225 const result = try bufPrint(buf1[0..], "f64: {.5}\n", value);1225 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"));
1227 }1227 }
1228 {1228 {
1229 var buf1: [32]u8 = undefined;1229 var buf1: [32]u8 = undefined;
1230 const value: f64 = f64(@bitCast(f32, u32(1065353133)));1230 const value: f64 = f64(@bitCast(f32, u32(1065353133)));
1231 const result = try bufPrint(buf1[0..], "f64: {.5}\n", value);1231 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"));
1233 }1233 }
1234 {1234 {
1235 var buf1: [32]u8 = undefined;1235 var buf1: [32]u8 = undefined;
1236 const value: f64 = f64(@bitCast(f32, u32(1092616192)));1236 const value: f64 = f64(@bitCast(f32, u32(1092616192)));
1237 const result = try bufPrint(buf1[0..], "f64: {.5}\n", value);1237 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"));
1239 }1239 }
1240 // libc differences1240 // libc differences
1241 {1241 {
...@@ -1245,7 +1245,7 @@ test "fmt.format" {...@@ -1245,7 +1245,7 @@ test "fmt.format" {
1245 // floats of the form x.yyyy25 on a precision point.1245 // floats of the form x.yyyy25 on a precision point.
1246 const value: f64 = f64(@bitCast(f32, u32(1015021568)));1246 const value: f64 = f64(@bitCast(f32, u32(1015021568)));
1247 const result = try bufPrint(buf1[0..], "f64: {.5}\n", value);1247 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"));
1249 }1249 }
1250 // std-windows-x86_64-Debug-bare test case fails1250 // std-windows-x86_64-Debug-bare test case fails
1251 {1251 {
...@@ -1255,7 +1255,7 @@ test "fmt.format" {...@@ -1255,7 +1255,7 @@ test "fmt.format" {
1255 var buf1: [32]u8 = undefined;1255 var buf1: [32]u8 = undefined;
1256 const value: f64 = f64(@bitCast(f32, u32(1518338049)));1256 const value: f64 = f64(@bitCast(f32, u32(1518338049)));
1257 const result = try bufPrint(buf1[0..], "f64: {.5}\n", value);1257 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"));
1259 }1259 }
1260 //custom type format1260 //custom type format
1261 {1261 {
...@@ -1336,10 +1336,10 @@ test "fmt.format" {...@@ -1336,10 +1336,10 @@ test "fmt.format" {
13361336
1337 var buf: [100]u8 = undefined;1337 var buf: [100]u8 = undefined;
1338 const uu_result = try bufPrint(buf[0..], "{}", uu_inst);1338 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
1341 const eu_result = try bufPrint(buf[0..], "{}", eu_inst);1341 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@"));
1343 }1343 }
1344 //enum format1344 //enum format
1345 {1345 {
...@@ -1398,11 +1398,11 @@ pub fn trim(buf: []const u8) []const u8 {...@@ -1398,11 +1398,11 @@ pub fn trim(buf: []const u8) []const u8 {
1398}1398}
13991399
1400test "fmt.trim" {1400test "fmt.trim" {
1401 assert(mem.eql(u8, "abc", trim("\n abc \t")));1401 testing.expect(mem.eql(u8, "abc", trim("\n abc \t")));
1402 assert(mem.eql(u8, "", trim(" ")));1402 testing.expect(mem.eql(u8, "", trim(" ")));
1403 assert(mem.eql(u8, "", trim("")));1403 testing.expect(mem.eql(u8, "", trim("")));
1404 assert(mem.eql(u8, "abc", trim(" abc")));1404 testing.expect(mem.eql(u8, "abc", trim(" abc")));
1405 assert(mem.eql(u8, "abc", trim("abc ")));1405 testing.expect(mem.eql(u8, "abc", trim("abc ")));
1406}1406}
14071407
1408pub fn isWhiteSpace(byte: u8) bool {1408pub fn isWhiteSpace(byte: u8) bool {
std/hash/adler.zig+6-6
...@@ -4,7 +4,7 @@...@@ -4,7 +4,7 @@
4// https://github.com/madler/zlib/blob/master/adler32.c4// https://github.com/madler/zlib/blob/master/adler32.c
55
6const std = @import("../index.zig");6const std = @import("../index.zig");
7const debug = std.debug;7const testing = std.testing;
88
9pub const Adler32 = struct {9pub const Adler32 = struct {
10 const base = 65521;10 const base = 65521;
...@@ -89,19 +89,19 @@ pub const Adler32 = struct {...@@ -89,19 +89,19 @@ pub const Adler32 = struct {
89};89};
9090
91test "adler32 sanity" {91test "adler32 sanity" {
92 debug.assert(Adler32.hash("a") == 0x620062);92 testing.expect(Adler32.hash("a") == 0x620062);
93 debug.assert(Adler32.hash("example") == 0xbc002ed);93 testing.expect(Adler32.hash("example") == 0xbc002ed);
94}94}
9595
96test "adler32 long" {96test "adler32 long" {
97 const long1 = []u8{1} ** 1024;97 const long1 = []u8{1} ** 1024;
98 debug.assert(Adler32.hash(long1[0..]) == 0x06780401);98 testing.expect(Adler32.hash(long1[0..]) == 0x06780401);
9999
100 const long2 = []u8{1} ** 1025;100 const long2 = []u8{1} ** 1025;
101 debug.assert(Adler32.hash(long2[0..]) == 0x0a7a0402);101 testing.expect(Adler32.hash(long2[0..]) == 0x0a7a0402);
102}102}
103103
104test "adler32 very long" {104test "adler32 very long" {
105 const long = []u8{1} ** 5553;105 const long = []u8{1} ** 5553;
106 debug.assert(Adler32.hash(long[0..]) == 0x707f15b2);106 testing.expect(Adler32.hash(long[0..]) == 0x707f15b2);
107}107}
std/hash/crc.zig+13-12
...@@ -7,6 +7,7 @@...@@ -7,6 +7,7 @@
77
8const std = @import("../index.zig");8const std = @import("../index.zig");
9const debug = std.debug;9const debug = std.debug;
10const testing = std.testing;
1011
11pub const Polynomial = struct {12pub const Polynomial = struct {
12 const IEEE = 0xedb88320;13 const IEEE = 0xedb88320;
...@@ -101,17 +102,17 @@ pub fn Crc32WithPoly(comptime poly: u32) type {...@@ -101,17 +102,17 @@ pub fn Crc32WithPoly(comptime poly: u32) type {
101test "crc32 ieee" {102test "crc32 ieee" {
102 const Crc32Ieee = Crc32WithPoly(Polynomial.IEEE);103 const Crc32Ieee = Crc32WithPoly(Polynomial.IEEE);
103104
104 debug.assert(Crc32Ieee.hash("") == 0x00000000);105 testing.expect(Crc32Ieee.hash("") == 0x00000000);
105 debug.assert(Crc32Ieee.hash("a") == 0xe8b7be43);106 testing.expect(Crc32Ieee.hash("a") == 0xe8b7be43);
106 debug.assert(Crc32Ieee.hash("abc") == 0x352441c2);107 testing.expect(Crc32Ieee.hash("abc") == 0x352441c2);
107}108}
108109
109test "crc32 castagnoli" {110test "crc32 castagnoli" {
110 const Crc32Castagnoli = Crc32WithPoly(Polynomial.Castagnoli);111 const Crc32Castagnoli = Crc32WithPoly(Polynomial.Castagnoli);
111112
112 debug.assert(Crc32Castagnoli.hash("") == 0x00000000);113 testing.expect(Crc32Castagnoli.hash("") == 0x00000000);
113 debug.assert(Crc32Castagnoli.hash("a") == 0xc1d04330);114 testing.expect(Crc32Castagnoli.hash("a") == 0xc1d04330);
114 debug.assert(Crc32Castagnoli.hash("abc") == 0x364b3fb7);115 testing.expect(Crc32Castagnoli.hash("abc") == 0x364b3fb7);
115}116}
116117
117// half-byte lookup table implementation.118// half-byte lookup table implementation.
...@@ -165,15 +166,15 @@ pub fn Crc32SmallWithPoly(comptime poly: u32) type {...@@ -165,15 +166,15 @@ pub fn Crc32SmallWithPoly(comptime poly: u32) type {
165test "small crc32 ieee" {166test "small crc32 ieee" {
166 const Crc32Ieee = Crc32SmallWithPoly(Polynomial.IEEE);167 const Crc32Ieee = Crc32SmallWithPoly(Polynomial.IEEE);
167168
168 debug.assert(Crc32Ieee.hash("") == 0x00000000);169 testing.expect(Crc32Ieee.hash("") == 0x00000000);
169 debug.assert(Crc32Ieee.hash("a") == 0xe8b7be43);170 testing.expect(Crc32Ieee.hash("a") == 0xe8b7be43);
170 debug.assert(Crc32Ieee.hash("abc") == 0x352441c2);171 testing.expect(Crc32Ieee.hash("abc") == 0x352441c2);
171}172}
172173
173test "small crc32 castagnoli" {174test "small crc32 castagnoli" {
174 const Crc32Castagnoli = Crc32SmallWithPoly(Polynomial.Castagnoli);175 const Crc32Castagnoli = Crc32SmallWithPoly(Polynomial.Castagnoli);
175176
176 debug.assert(Crc32Castagnoli.hash("") == 0x00000000);177 testing.expect(Crc32Castagnoli.hash("") == 0x00000000);
177 debug.assert(Crc32Castagnoli.hash("a") == 0xc1d04330);178 testing.expect(Crc32Castagnoli.hash("a") == 0xc1d04330);
178 debug.assert(Crc32Castagnoli.hash("abc") == 0x364b3fb7);179 testing.expect(Crc32Castagnoli.hash("abc") == 0x364b3fb7);
179}180}
std/hash/fnv.zig+9-9
...@@ -5,7 +5,7 @@...@@ -5,7 +5,7 @@
5// https://tools.ietf.org/html/draft-eastlake-fnv-145// https://tools.ietf.org/html/draft-eastlake-fnv-14
66
7const std = @import("../index.zig");7const std = @import("../index.zig");
8const debug = std.debug;8const testing = std.testing;
99
10pub const Fnv1a_32 = Fnv1a(u32, 0x01000193, 0x811c9dc5);10pub const Fnv1a_32 = Fnv1a(u32, 0x01000193, 0x811c9dc5);
11pub const Fnv1a_64 = Fnv1a(u64, 0x100000001b3, 0xcbf29ce484222325);11pub const Fnv1a_64 = Fnv1a(u64, 0x100000001b3, 0xcbf29ce484222325);
...@@ -41,18 +41,18 @@ fn Fnv1a(comptime T: type, comptime prime: T, comptime offset: T) type {...@@ -41,18 +41,18 @@ fn Fnv1a(comptime T: type, comptime prime: T, comptime offset: T) type {
41}41}
4242
43test "fnv1a-32" {43test "fnv1a-32" {
44 debug.assert(Fnv1a_32.hash("") == 0x811c9dc5);44 testing.expect(Fnv1a_32.hash("") == 0x811c9dc5);
45 debug.assert(Fnv1a_32.hash("a") == 0xe40c292c);45 testing.expect(Fnv1a_32.hash("a") == 0xe40c292c);
46 debug.assert(Fnv1a_32.hash("foobar") == 0xbf9cf968);46 testing.expect(Fnv1a_32.hash("foobar") == 0xbf9cf968);
47}47}
4848
49test "fnv1a-64" {49test "fnv1a-64" {
50 debug.assert(Fnv1a_64.hash("") == 0xcbf29ce484222325);50 testing.expect(Fnv1a_64.hash("") == 0xcbf29ce484222325);
51 debug.assert(Fnv1a_64.hash("a") == 0xaf63dc4c8601ec8c);51 testing.expect(Fnv1a_64.hash("a") == 0xaf63dc4c8601ec8c);
52 debug.assert(Fnv1a_64.hash("foobar") == 0x85944171f73967e8);52 testing.expect(Fnv1a_64.hash("foobar") == 0x85944171f73967e8);
53}53}
5454
55test "fnv1a-128" {55test "fnv1a-128" {
56 debug.assert(Fnv1a_128.hash("") == 0x6c62272e07bb014262b821756295c58d);56 testing.expect(Fnv1a_128.hash("") == 0x6c62272e07bb014262b821756295c58d);
57 debug.assert(Fnv1a_128.hash("a") == 0xd228cb696f1a8caf78912b704e4a8964);57 testing.expect(Fnv1a_128.hash("a") == 0xd228cb696f1a8caf78912b704e4a8964);
58}58}
std/hash/siphash.zig+8-7
...@@ -6,7 +6,8 @@...@@ -6,7 +6,8 @@
6// https://131002.net/siphash/6// https://131002.net/siphash/
77
8const std = @import("../index.zig");8const std = @import("../index.zig");
9const debug = std.debug;9const assert = std.debug.assert;
10const testing = std.testing;
10const math = std.math;11const math = std.math;
11const mem = std.mem;12const mem = std.mem;
1213
...@@ -21,8 +22,8 @@ pub fn SipHash128(comptime c_rounds: usize, comptime d_rounds: usize) type {...@@ -21,8 +22,8 @@ pub fn SipHash128(comptime c_rounds: usize, comptime d_rounds: usize) type {
21}22}
2223
23fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize) type {24fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize) type {
24 debug.assert(T == u64 or T == u128);25 assert(T == u64 or T == u128);
25 debug.assert(c_rounds > 0 and d_rounds > 0);26 assert(c_rounds > 0 and d_rounds > 0);
2627
27 return struct {28 return struct {
28 const Self = @This();29 const Self = @This();
...@@ -40,7 +41,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)...@@ -40,7 +41,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)
40 msg_len: u8,41 msg_len: u8,
4142
42 pub fn init(key: []const u8) Self {43 pub fn init(key: []const u8) Self {
43 debug.assert(key.len >= 16);44 assert(key.len >= 16);
4445
45 const k0 = mem.readIntSliceLittle(u64, key[0..8]);46 const k0 = mem.readIntSliceLittle(u64, key[0..8]);
46 const k1 = mem.readIntSliceLittle(u64, key[8..16]);47 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)...@@ -119,7 +120,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)
119 }120 }
120121
121 fn round(d: *Self, b: []const u8) void {122 fn round(d: *Self, b: []const u8) void {
122 debug.assert(b.len == 8);123 assert(b.len == 8);
123124
124 const m = mem.readIntSliceLittle(u64, b[0..]);125 const m = mem.readIntSliceLittle(u64, b[0..]);
125 d.v3 ^= m;126 d.v3 ^= m;
...@@ -236,7 +237,7 @@ test "siphash64-2-4 sanity" {...@@ -236,7 +237,7 @@ test "siphash64-2-4 sanity" {
236 buffer[i] = @intCast(u8, i);237 buffer[i] = @intCast(u8, i);
237238
238 const expected = mem.readIntLittle(u64, &vector);239 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);
240 }241 }
241}242}
242243
...@@ -315,6 +316,6 @@ test "siphash128-2-4 sanity" {...@@ -315,6 +316,6 @@ test "siphash128-2-4 sanity" {
315 buffer[i] = @intCast(u8, i);316 buffer[i] = @intCast(u8, i);
316317
317 const expected = mem.readIntLittle(u128, &vector);318 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);
319 }320 }
320}321}
std/hash_map.zig+30-29
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const std = @import("index.zig");1const std = @import("index.zig");
2const debug = std.debug;2const debug = std.debug;
3const assert = debug.assert;3const assert = debug.assert;
4const testing = std.testing;
4const math = std.math;5const math = std.math;
5const mem = std.mem;6const mem = std.mem;
6const Allocator = mem.Allocator;7const Allocator = mem.Allocator;
...@@ -342,37 +343,37 @@ test "basic hash map usage" {...@@ -342,37 +343,37 @@ test "basic hash map usage" {
342 var map = AutoHashMap(i32, i32).init(&direct_allocator.allocator);343 var map = AutoHashMap(i32, i32).init(&direct_allocator.allocator);
343 defer map.deinit();344 defer map.deinit();
344345
345 assert((try map.put(1, 11)) == null);346 testing.expect((try map.put(1, 11)) == null);
346 assert((try map.put(2, 22)) == null);347 testing.expect((try map.put(2, 22)) == null);
347 assert((try map.put(3, 33)) == null);348 testing.expect((try map.put(3, 33)) == null);
348 assert((try map.put(4, 44)) == null);349 testing.expect((try map.put(4, 44)) == null);
349 assert((try map.put(5, 55)) == null);350 testing.expect((try map.put(5, 55)) == null);
350351
351 assert((try map.put(5, 66)).?.value == 55);352 testing.expect((try map.put(5, 66)).?.value == 55);
352 assert((try map.put(5, 55)).?.value == 66);353 testing.expect((try map.put(5, 55)).?.value == 66);
353354
354 const gop1 = try map.getOrPut(5);355 const gop1 = try map.getOrPut(5);
355 assert(gop1.found_existing == true);356 testing.expect(gop1.found_existing == true);
356 assert(gop1.kv.value == 55);357 testing.expect(gop1.kv.value == 55);
357 gop1.kv.value = 77;358 gop1.kv.value = 77;
358 assert(map.get(5).?.value == 77);359 testing.expect(map.get(5).?.value == 77);
359360
360 const gop2 = try map.getOrPut(99);361 const gop2 = try map.getOrPut(99);
361 assert(gop2.found_existing == false);362 testing.expect(gop2.found_existing == false);
362 gop2.kv.value = 42;363 gop2.kv.value = 42;
363 assert(map.get(99).?.value == 42);364 testing.expect(map.get(99).?.value == 42);
364365
365 const gop3 = try map.getOrPutValue(5, 5);366 const gop3 = try map.getOrPutValue(5, 5);
366 assert(gop3.value == 77);367 testing.expect(gop3.value == 77);
367368
368 const gop4 = try map.getOrPutValue(100, 41);369 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 testing.expect(map.contains(2));
372 assert(map.get(2).?.value == 22);373 testing.expect(map.get(2).?.value == 22);
373 _ = map.remove(2);374 _ = map.remove(2);
374 assert(map.remove(2) == null);375 testing.expect(map.remove(2) == null);
375 assert(map.get(2) == null);376 testing.expect(map.get(2) == null);
376}377}
377378
378test "iterator hash map" {379test "iterator hash map" {
...@@ -382,9 +383,9 @@ test "iterator hash map" {...@@ -382,9 +383,9 @@ test "iterator hash map" {
382 var reset_map = AutoHashMap(i32, i32).init(&direct_allocator.allocator);383 var reset_map = AutoHashMap(i32, i32).init(&direct_allocator.allocator);
383 defer reset_map.deinit();384 defer reset_map.deinit();
384385
385 assert((try reset_map.put(1, 11)) == null);386 testing.expect((try reset_map.put(1, 11)) == null);
386 assert((try reset_map.put(2, 22)) == null);387 testing.expect((try reset_map.put(2, 22)) == null);
387 assert((try reset_map.put(3, 33)) == null);388 testing.expect((try reset_map.put(3, 33)) == null);
388389
389 var keys = []i32{390 var keys = []i32{
390 3,391 3,
...@@ -400,26 +401,26 @@ test "iterator hash map" {...@@ -400,26 +401,26 @@ test "iterator hash map" {
400 var it = reset_map.iterator();401 var it = reset_map.iterator();
401 var count: usize = 0;402 var count: usize = 0;
402 while (it.next()) |next| {403 while (it.next()) |next| {
403 assert(next.key == keys[count]);404 testing.expect(next.key == keys[count]);
404 assert(next.value == values[count]);405 testing.expect(next.value == values[count]);
405 count += 1;406 count += 1;
406 }407 }
407408
408 assert(count == 3);409 testing.expect(count == 3);
409 assert(it.next() == null);410 testing.expect(it.next() == null);
410 it.reset();411 it.reset();
411 count = 0;412 count = 0;
412 while (it.next()) |next| {413 while (it.next()) |next| {
413 assert(next.key == keys[count]);414 testing.expect(next.key == keys[count]);
414 assert(next.value == values[count]);415 testing.expect(next.value == values[count]);
415 count += 1;416 count += 1;
416 if (count == 2) break;417 if (count == 2) break;
417 }418 }
418419
419 it.reset();420 it.reset();
420 var entry = it.next().?;421 var entry = it.next().?;
421 assert(entry.key == keys[0]);422 testing.expect(entry.key == keys[0]);
422 assert(entry.value == values[0]);423 testing.expect(entry.value == values[0]);
423}424}
424425
425pub fn getHashPtrAddrFn(comptime K: type) (fn (K) u32) {426pub fn getHashPtrAddrFn(comptime K: type) (fn (K) u32) {
std/heap.zig+74-67
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const std = @import("index.zig");1const std = @import("index.zig");
2const debug = std.debug;2const debug = std.debug;
3const assert = debug.assert;3const assert = debug.assert;
4const testing = std.testing;
4const mem = std.mem;5const mem = std.mem;
5const os = std.os;6const os = std.os;
6const builtin = @import("builtin");7const builtin = @import("builtin");
...@@ -321,51 +322,57 @@ pub const FixedBufferAllocator = struct {...@@ -321,51 +322,57 @@ pub const FixedBufferAllocator = struct {
321 fn free(allocator: *Allocator, bytes: []u8) void {}322 fn free(allocator: *Allocator, bytes: []u8) void {}
322};323};
323324
324/// lock free325pub const ThreadSafeFixedBufferAllocator = blk: {
325pub const ThreadSafeFixedBufferAllocator = struct {326 if (builtin.single_threaded) {
326 allocator: Allocator,327 break :blk FixedBufferAllocator;
327 end_index: usize,328 } else {
328 buffer: []u8,329 /// lock free
330 break :blk struct {
331 allocator: Allocator,
332 end_index: usize,
333 buffer: []u8,
334
335 pub fn init(buffer: []u8) ThreadSafeFixedBufferAllocator {
336 return ThreadSafeFixedBufferAllocator{
337 .allocator = Allocator{
338 .allocFn = alloc,
339 .reallocFn = realloc,
340 .freeFn = free,
341 },
342 .buffer = buffer,
343 .end_index = 0,
344 };
345 }
329346
330 pub fn init(buffer: []u8) ThreadSafeFixedBufferAllocator {347 fn alloc(allocator: *Allocator, n: usize, alignment: u29) ![]u8 {
331 return ThreadSafeFixedBufferAllocator{348 const self = @fieldParentPtr(ThreadSafeFixedBufferAllocator, "allocator", allocator);
332 .allocator = Allocator{349 var end_index = @atomicLoad(usize, &self.end_index, builtin.AtomicOrder.SeqCst);
333 .allocFn = alloc,350 while (true) {
334 .reallocFn = realloc,351 const addr = @ptrToInt(self.buffer.ptr) + end_index;
335 .freeFn = free,352 const rem = @rem(addr, alignment);
336 },353 const march_forward_bytes = if (rem == 0) 0 else (alignment - rem);
337 .buffer = buffer,354 const adjusted_index = end_index + march_forward_bytes;
338 .end_index = 0,355 const new_end_index = adjusted_index + n;
339 };356 if (new_end_index > self.buffer.len) {
340 }357 return error.OutOfMemory;
358 }
359 end_index = @cmpxchgWeak(usize, &self.end_index, end_index, new_end_index, builtin.AtomicOrder.SeqCst, builtin.AtomicOrder.SeqCst) orelse return self.buffer[adjusted_index..new_end_index];
360 }
361 }
341362
342 fn alloc(allocator: *Allocator, n: usize, alignment: u29) ![]u8 {363 fn realloc(allocator: *Allocator, old_mem: []u8, new_size: usize, alignment: u29) ![]u8 {
343 const self = @fieldParentPtr(ThreadSafeFixedBufferAllocator, "allocator", allocator);364 if (new_size <= old_mem.len) {
344 var end_index = @atomicLoad(usize, &self.end_index, builtin.AtomicOrder.SeqCst);365 return old_mem[0..new_size];
345 while (true) {366 } else {
346 const addr = @ptrToInt(self.buffer.ptr) + end_index;367 const result = try alloc(allocator, new_size, alignment);
347 const rem = @rem(addr, alignment);368 mem.copy(u8, result, old_mem);
348 const march_forward_bytes = if (rem == 0) 0 else (alignment - rem);369 return result;
349 const adjusted_index = end_index + march_forward_bytes;370 }
350 const new_end_index = adjusted_index + n;
351 if (new_end_index > self.buffer.len) {
352 return error.OutOfMemory;
353 }371 }
354 end_index = @cmpxchgWeak(usize, &self.end_index, end_index, new_end_index, builtin.AtomicOrder.SeqCst, builtin.AtomicOrder.SeqCst) orelse return self.buffer[adjusted_index..new_end_index];
355 }
356 }
357372
358 fn realloc(allocator: *Allocator, old_mem: []u8, new_size: usize, alignment: u29) ![]u8 {373 fn free(allocator: *Allocator, bytes: []u8) void {}
359 if (new_size <= old_mem.len) {374 };
360 return old_mem[0..new_size];
361 } else {
362 const result = try alloc(allocator, new_size, alignment);
363 mem.copy(u8, result, old_mem);
364 return result;
365 }
366 }375 }
367
368 fn free(allocator: *Allocator, bytes: []u8) void {}
369};376};
370377
371pub fn stackFallback(comptime size: usize, fallback_allocator: *Allocator) StackFallbackAllocator(size) {378pub fn stackFallback(comptime size: usize, fallback_allocator: *Allocator) StackFallbackAllocator(size) {
...@@ -481,11 +488,11 @@ test "FixedBufferAllocator Reuse memory on realloc" {...@@ -481,11 +488,11 @@ test "FixedBufferAllocator Reuse memory on realloc" {
481 var fixed_buffer_allocator = FixedBufferAllocator.init(small_fixed_buffer[0..]);488 var fixed_buffer_allocator = FixedBufferAllocator.init(small_fixed_buffer[0..]);
482489
483 var slice0 = try fixed_buffer_allocator.allocator.alloc(u8, 5);490 var slice0 = try fixed_buffer_allocator.allocator.alloc(u8, 5);
484 assert(slice0.len == 5);491 testing.expect(slice0.len == 5);
485 var slice1 = try fixed_buffer_allocator.allocator.realloc(u8, slice0, 10);492 var slice1 = try fixed_buffer_allocator.allocator.realloc(u8, slice0, 10);
486 assert(slice1.ptr == slice0.ptr);493 testing.expect(slice1.ptr == slice0.ptr);
487 assert(slice1.len == 10);494 testing.expect(slice1.len == 10);
488 debug.assertError(fixed_buffer_allocator.allocator.realloc(u8, slice1, 11), error.OutOfMemory);495 testing.expectError(error.OutOfMemory, fixed_buffer_allocator.allocator.realloc(u8, slice1, 11));
489 }496 }
490 // check that we don't re-use the memory if it's not the most recent block497 // check that we don't re-use the memory if it's not the most recent block
491 {498 {
...@@ -496,10 +503,10 @@ test "FixedBufferAllocator Reuse memory on realloc" {...@@ -496,10 +503,10 @@ test "FixedBufferAllocator Reuse memory on realloc" {
496 slice0[1] = 2;503 slice0[1] = 2;
497 var slice1 = try fixed_buffer_allocator.allocator.alloc(u8, 2);504 var slice1 = try fixed_buffer_allocator.allocator.alloc(u8, 2);
498 var slice2 = try fixed_buffer_allocator.allocator.realloc(u8, slice0, 4);505 var slice2 = try fixed_buffer_allocator.allocator.realloc(u8, slice0, 4);
499 assert(slice0.ptr != slice2.ptr);506 testing.expect(slice0.ptr != slice2.ptr);
500 assert(slice1.ptr != slice2.ptr);507 testing.expect(slice1.ptr != slice2.ptr);
501 assert(slice2[0] == 1);508 testing.expect(slice2[0] == 1);
502 assert(slice2[1] == 2);509 testing.expect(slice2[1] == 2);
503 }510 }
504}511}
505512
...@@ -513,28 +520,28 @@ test "ThreadSafeFixedBufferAllocator" {...@@ -513,28 +520,28 @@ test "ThreadSafeFixedBufferAllocator" {
513520
514fn testAllocator(allocator: *mem.Allocator) !void {521fn testAllocator(allocator: *mem.Allocator) !void {
515 var slice = try allocator.alloc(*i32, 100);522 var slice = try allocator.alloc(*i32, 100);
516 assert(slice.len == 100);523 testing.expect(slice.len == 100);
517 for (slice) |*item, i| {524 for (slice) |*item, i| {
518 item.* = try allocator.create(i32);525 item.* = try allocator.create(i32);
519 item.*.* = @intCast(i32, i);526 item.*.* = @intCast(i32, i);
520 }527 }
521528
522 slice = try allocator.realloc(*i32, slice, 20000);529 slice = try allocator.realloc(*i32, slice, 20000);
523 assert(slice.len == 20000);530 testing.expect(slice.len == 20000);
524531
525 for (slice[0..100]) |item, i| {532 for (slice[0..100]) |item, i| {
526 assert(item.* == @intCast(i32, i));533 testing.expect(item.* == @intCast(i32, i));
527 allocator.destroy(item);534 allocator.destroy(item);
528 }535 }
529536
530 slice = try allocator.realloc(*i32, slice, 50);537 slice = try allocator.realloc(*i32, slice, 50);
531 assert(slice.len == 50);538 testing.expect(slice.len == 50);
532 slice = try allocator.realloc(*i32, slice, 25);539 slice = try allocator.realloc(*i32, slice, 25);
533 assert(slice.len == 25);540 testing.expect(slice.len == 25);
534 slice = try allocator.realloc(*i32, slice, 0);541 slice = try allocator.realloc(*i32, slice, 0);
535 assert(slice.len == 0);542 testing.expect(slice.len == 0);
536 slice = try allocator.realloc(*i32, slice, 10);543 slice = try allocator.realloc(*i32, slice, 10);
537 assert(slice.len == 10);544 testing.expect(slice.len == 10);
538545
539 allocator.free(slice);546 allocator.free(slice);
540}547}
...@@ -542,25 +549,25 @@ fn testAllocator(allocator: *mem.Allocator) !void {...@@ -542,25 +549,25 @@ fn testAllocator(allocator: *mem.Allocator) !void {
542fn testAllocatorAligned(allocator: *mem.Allocator, comptime alignment: u29) !void {549fn testAllocatorAligned(allocator: *mem.Allocator, comptime alignment: u29) !void {
543 // initial550 // initial
544 var slice = try allocator.alignedAlloc(u8, alignment, 10);551 var slice = try allocator.alignedAlloc(u8, alignment, 10);
545 assert(slice.len == 10);552 testing.expect(slice.len == 10);
546 // grow553 // grow
547 slice = try allocator.alignedRealloc(u8, alignment, slice, 100);554 slice = try allocator.alignedRealloc(u8, alignment, slice, 100);
548 assert(slice.len == 100);555 testing.expect(slice.len == 100);
549 // shrink556 // shrink
550 slice = try allocator.alignedRealloc(u8, alignment, slice, 10);557 slice = try allocator.alignedRealloc(u8, alignment, slice, 10);
551 assert(slice.len == 10);558 testing.expect(slice.len == 10);
552 // go to zero559 // go to zero
553 slice = try allocator.alignedRealloc(u8, alignment, slice, 0);560 slice = try allocator.alignedRealloc(u8, alignment, slice, 0);
554 assert(slice.len == 0);561 testing.expect(slice.len == 0);
555 // realloc from zero562 // realloc from zero
556 slice = try allocator.alignedRealloc(u8, alignment, slice, 100);563 slice = try allocator.alignedRealloc(u8, alignment, slice, 100);
557 assert(slice.len == 100);564 testing.expect(slice.len == 100);
558 // shrink with shrink565 // shrink with shrink
559 slice = allocator.alignedShrink(u8, alignment, slice, 10);566 slice = allocator.alignedShrink(u8, alignment, slice, 10);
560 assert(slice.len == 10);567 testing.expect(slice.len == 10);
561 // shrink to zero568 // shrink to zero
562 slice = allocator.alignedShrink(u8, alignment, slice, 0);569 slice = allocator.alignedShrink(u8, alignment, slice, 0);
563 assert(slice.len == 0);570 testing.expect(slice.len == 0);
564}571}
565572
566fn testAllocatorLargeAlignment(allocator: *mem.Allocator) mem.Allocator.Error!void {573fn testAllocatorLargeAlignment(allocator: *mem.Allocator) mem.Allocator.Error!void {
...@@ -575,19 +582,19 @@ fn testAllocatorLargeAlignment(allocator: *mem.Allocator) mem.Allocator.Error!vo...@@ -575,19 +582,19 @@ fn testAllocatorLargeAlignment(allocator: *mem.Allocator) mem.Allocator.Error!vo
575 _ = @shlWithOverflow(usize, ~usize(0), USizeShift(@ctz(large_align)), &align_mask);582 _ = @shlWithOverflow(usize, ~usize(0), USizeShift(@ctz(large_align)), &align_mask);
576583
577 var slice = try allocator.allocFn(allocator, 500, large_align);584 var slice = try allocator.allocFn(allocator, 500, large_align);
578 debug.assert(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));585 testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
579586
580 slice = try allocator.reallocFn(allocator, slice, 100, large_align);587 slice = try allocator.reallocFn(allocator, slice, 100, large_align);
581 debug.assert(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));588 testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
582589
583 slice = try allocator.reallocFn(allocator, slice, 5000, large_align);590 slice = try allocator.reallocFn(allocator, slice, 5000, large_align);
584 debug.assert(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));591 testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
585592
586 slice = try allocator.reallocFn(allocator, slice, 10, large_align);593 slice = try allocator.reallocFn(allocator, slice, 10, large_align);
587 debug.assert(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));594 testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
588595
589 slice = try allocator.reallocFn(allocator, slice, 20000, large_align);596 slice = try allocator.reallocFn(allocator, slice, 20000, large_align);
590 debug.assert(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));597 testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
591598
592 allocator.free(slice);599 allocator.free(slice);
593}600}
std/index.zig+8-7
...@@ -31,6 +31,7 @@ pub const hash_map = @import("hash_map.zig");...@@ -31,6 +31,7 @@ pub const hash_map = @import("hash_map.zig");
31pub const heap = @import("heap.zig");31pub const heap = @import("heap.zig");
32pub const io = @import("io.zig");32pub const io = @import("io.zig");
33pub const json = @import("json.zig");33pub const json = @import("json.zig");
34pub const lazyInit = @import("lazy_init.zig").lazyInit;
34pub const macho = @import("macho.zig");35pub const macho = @import("macho.zig");
35pub const math = @import("math/index.zig");36pub const math = @import("math/index.zig");
36pub const mem = @import("mem.zig");37pub const mem = @import("mem.zig");
...@@ -41,11 +42,10 @@ pub const pdb = @import("pdb.zig");...@@ -41,11 +42,10 @@ pub const pdb = @import("pdb.zig");
41pub const rand = @import("rand/index.zig");42pub const rand = @import("rand/index.zig");
42pub const rb = @import("rb.zig");43pub const rb = @import("rb.zig");
43pub const sort = @import("sort.zig");44pub const sort = @import("sort.zig");
45pub const testing = @import("testing.zig");
44pub const unicode = @import("unicode.zig");46pub const unicode = @import("unicode.zig");
45pub const zig = @import("zig/index.zig");47pub const zig = @import("zig/index.zig");
4648
47pub const lazyInit = @import("lazy_init.zig").lazyInit;
48
49test "std" {49test "std" {
50 // run tests from these50 // run tests from these
51 _ = @import("array_list.zig");51 _ = @import("array_list.zig");
...@@ -60,7 +60,6 @@ test "std" {...@@ -60,7 +60,6 @@ test "std" {
60 _ = @import("segmented_list.zig");60 _ = @import("segmented_list.zig");
61 _ = @import("spinlock.zig");61 _ = @import("spinlock.zig");
62 62
63 _ = @import("dynamic_library.zig");
64 _ = @import("base64.zig");63 _ = @import("base64.zig");
65 _ = @import("build.zig");64 _ = @import("build.zig");
66 _ = @import("c/index.zig");65 _ = @import("c/index.zig");
...@@ -69,24 +68,26 @@ test "std" {...@@ -69,24 +68,26 @@ test "std" {
69 _ = @import("cstr.zig");68 _ = @import("cstr.zig");
70 _ = @import("debug/index.zig");69 _ = @import("debug/index.zig");
71 _ = @import("dwarf.zig");70 _ = @import("dwarf.zig");
71 _ = @import("dynamic_library.zig");
72 _ = @import("elf.zig");72 _ = @import("elf.zig");
73 _ = @import("empty.zig");73 _ = @import("empty.zig");
74 _ = @import("event.zig");74 _ = @import("event.zig");
75 _ = @import("fmt/index.zig");75 _ = @import("fmt/index.zig");
76 _ = @import("hash/index.zig");76 _ = @import("hash/index.zig");
77 _ = @import("heap.zig");
77 _ = @import("io.zig");78 _ = @import("io.zig");
78 _ = @import("json.zig");79 _ = @import("json.zig");
80 _ = @import("lazy_init.zig");
79 _ = @import("macho.zig");81 _ = @import("macho.zig");
80 _ = @import("math/index.zig");82 _ = @import("math/index.zig");
81 _ = @import("meta/index.zig");
82 _ = @import("mem.zig");83 _ = @import("mem.zig");
84 _ = @import("meta/index.zig");
83 _ = @import("net.zig");85 _ = @import("net.zig");
84 _ = @import("heap.zig");
85 _ = @import("os/index.zig");86 _ = @import("os/index.zig");
86 _ = @import("rand/index.zig");
87 _ = @import("pdb.zig");87 _ = @import("pdb.zig");
88 _ = @import("rand/index.zig");
88 _ = @import("sort.zig");89 _ = @import("sort.zig");
90 _ = @import("testing.zig");
89 _ = @import("unicode.zig");91 _ = @import("unicode.zig");
90 _ = @import("zig/index.zig");92 _ = @import("zig/index.zig");
91 _ = @import("lazy_init.zig");
92}93}
std/io.zig+9-8
...@@ -13,6 +13,7 @@ const trait = meta.trait;...@@ -13,6 +13,7 @@ const trait = meta.trait;
13const Buffer = std.Buffer;13const Buffer = std.Buffer;
14const fmt = std.fmt;14const fmt = std.fmt;
15const File = std.os.File;15const File = std.os.File;
16const testing = std.testing;
1617
17const is_posix = builtin.os != builtin.Os.windows;18const is_posix = builtin.os != builtin.Os.windows;
18const is_windows = builtin.os == builtin.Os.windows;19const is_windows = builtin.os == builtin.Os.windows;
...@@ -664,7 +665,7 @@ test "io.SliceOutStream" {...@@ -664,7 +665,7 @@ test "io.SliceOutStream" {
664 const stream = &slice_stream.stream;665 const stream = &slice_stream.stream;
665666
666 try stream.print("{}{}!", "Hello", "World");667 try stream.print("{}{}!", "Hello", "World");
667 debug.assertOrPanic(mem.eql(u8, "HelloWorld!", slice_stream.getWritten()));668 testing.expectEqualSlices(u8, "HelloWorld!", slice_stream.getWritten());
668}669}
669670
670var null_out_stream_state = NullOutStream.init();671var null_out_stream_state = NullOutStream.init();
...@@ -726,7 +727,7 @@ test "io.CountingOutStream" {...@@ -726,7 +727,7 @@ test "io.CountingOutStream" {
726727
727 const bytes = "yay" ** 10000;728 const bytes = "yay" ** 10000;
728 stream.write(bytes) catch unreachable;729 stream.write(bytes) catch unreachable;
729 debug.assertOrPanic(counting_stream.bytes_written == bytes.len);730 testing.expect(counting_stream.bytes_written == bytes.len);
730}731}
731732
732pub fn BufferedOutStream(comptime Error: type) type {733pub fn BufferedOutStream(comptime Error: type) type {
...@@ -1014,10 +1015,10 @@ test "io.readLineFrom" {...@@ -1014,10 +1015,10 @@ test "io.readLineFrom" {
1014 );1015 );
1015 const stream = &mem_stream.stream;1016 const stream = &mem_stream.stream;
10161017
1017 debug.assertOrPanic(mem.eql(u8, "Line 1", try readLineFrom(stream, &buf)));1018 testing.expectEqualSlices(u8, "Line 1", try readLineFrom(stream, &buf));
1018 debug.assertOrPanic(mem.eql(u8, "Line 22", try readLineFrom(stream, &buf)));1019 testing.expectEqualSlices(u8, "Line 22", try readLineFrom(stream, &buf));
1019 debug.assertError(readLineFrom(stream, &buf), error.EndOfStream);1020 testing.expectError(error.EndOfStream, readLineFrom(stream, &buf));
1020 debug.assertOrPanic(mem.eql(u8, buf.toSlice(), "Line 1Line 22Line 333"));1021 testing.expectEqualSlices(u8, "Line 1Line 22Line 333", buf.toSlice());
1021}1022}
10221023
1023pub fn readLineSlice(slice: []u8) ![]u8 {1024pub fn readLineSlice(slice: []u8) ![]u8 {
...@@ -1045,8 +1046,8 @@ test "io.readLineSliceFrom" {...@@ -1045,8 +1046,8 @@ test "io.readLineSliceFrom" {
1045 );1046 );
1046 const stream = &mem_stream.stream;1047 const stream = &mem_stream.stream;
10471048
1048 debug.assertOrPanic(mem.eql(u8, "Line 1", try readLineSliceFrom(stream, buf[0..])));1049 testing.expectEqualSlices(u8, "Line 1", try readLineSliceFrom(stream, buf[0..]));
1049 debug.assertError(readLineSliceFrom(stream, buf[0..]), error.OutOfMemory);1050 testing.expectError(error.OutOfMemory, readLineSliceFrom(stream, buf[0..]));
1050}1051}
10511052
1052/// Creates a deserializer that deserializes types from any stream.1053/// Creates a deserializer that deserializes types from any stream.
std/io_test.zig+101-101
...@@ -3,8 +3,8 @@ const io = std.io;...@@ -3,8 +3,8 @@ const io = std.io;
3const meta = std.meta;3const meta = std.meta;
4const trait = std.trait;4const trait = std.trait;
5const DefaultPrng = std.rand.DefaultPrng;5const DefaultPrng = std.rand.DefaultPrng;
6const assert = std.debug.assert;6const expect = std.testing.expect;
7const assertError = std.debug.assertError;7const expectError = std.testing.expectError;
8const mem = std.mem;8const mem = std.mem;
9const os = std.os;9const os = std.os;
10const builtin = @import("builtin");10const builtin = @import("builtin");
...@@ -35,7 +35,7 @@ test "write a file, read it, then delete it" {...@@ -35,7 +35,7 @@ test "write a file, read it, then delete it" {
3535
36 const file_size = try file.getEndPos();36 const file_size = try file.getEndPos();
37 const expected_file_size = "begin".len + data.len + "end".len;37 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
40 var file_in_stream = file.inStream();40 var file_in_stream = file.inStream();
41 var buf_stream = io.BufferedInStream(os.File.ReadError).init(&file_in_stream.stream);41 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" {...@@ -43,9 +43,9 @@ test "write a file, read it, then delete it" {
43 const contents = try st.readAllAlloc(allocator, 2 * 1024);43 const contents = try st.readAllAlloc(allocator, 2 * 1024);
44 defer allocator.free(contents);44 defer allocator.free(contents);
4545
46 assert(mem.eql(u8, contents[0.."begin".len], "begin"));46 expect(mem.eql(u8, contents[0.."begin".len], "begin"));
47 assert(mem.eql(u8, contents["begin".len .. contents.len - "end".len], data));47 expect(mem.eql(u8, contents["begin".len .. contents.len - "end".len], data));
48 assert(mem.eql(u8, contents[contents.len - "end".len ..], "end"));48 expect(mem.eql(u8, contents[contents.len - "end".len ..], "end"));
49 }49 }
50 try os.deleteFile(tmp_file_name);50 try os.deleteFile(tmp_file_name);
51}51}
...@@ -61,7 +61,7 @@ test "BufferOutStream" {...@@ -61,7 +61,7 @@ test "BufferOutStream" {
61 const y: i32 = 1234;61 const y: i32 = 1234;
62 try buf_stream.print("x: {}\ny: {}\n", x, y);62 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"));
65}65}
6666
67test "SliceInStream" {67test "SliceInStream" {
...@@ -71,15 +71,15 @@ test "SliceInStream" {...@@ -71,15 +71,15 @@ test "SliceInStream" {
71 var dest: [4]u8 = undefined;71 var dest: [4]u8 = undefined;
7272
73 var read = try ss.stream.read(dest[0..4]);73 var read = try ss.stream.read(dest[0..4]);
74 assert(read == 4);74 expect(read == 4);
75 assert(mem.eql(u8, dest[0..4], bytes[0..4]));75 expect(mem.eql(u8, dest[0..4], bytes[0..4]));
7676
77 read = try ss.stream.read(dest[0..4]);77 read = try ss.stream.read(dest[0..4]);
78 assert(read == 3);78 expect(read == 3);
79 assert(mem.eql(u8, dest[0..3], bytes[4..7]));79 expect(mem.eql(u8, dest[0..3], bytes[4..7]));
8080
81 read = try ss.stream.read(dest[0..4]);81 read = try ss.stream.read(dest[0..4]);
82 assert(read == 0);82 expect(read == 0);
83}83}
8484
85test "PeekStream" {85test "PeekStream" {
...@@ -93,26 +93,26 @@ test "PeekStream" {...@@ -93,26 +93,26 @@ test "PeekStream" {
93 ps.putBackByte(10);93 ps.putBackByte(10);
9494
95 var read = try ps.stream.read(dest[0..4]);95 var read = try ps.stream.read(dest[0..4]);
96 assert(read == 4);96 expect(read == 4);
97 assert(dest[0] == 10);97 expect(dest[0] == 10);
98 assert(dest[1] == 9);98 expect(dest[1] == 9);
99 assert(mem.eql(u8, dest[2..4], bytes[0..2]));99 expect(mem.eql(u8, dest[2..4], bytes[0..2]));
100100
101 read = try ps.stream.read(dest[0..4]);101 read = try ps.stream.read(dest[0..4]);
102 assert(read == 4);102 expect(read == 4);
103 assert(mem.eql(u8, dest[0..4], bytes[2..6]));103 expect(mem.eql(u8, dest[0..4], bytes[2..6]));
104104
105 read = try ps.stream.read(dest[0..4]);105 read = try ps.stream.read(dest[0..4]);
106 assert(read == 2);106 expect(read == 2);
107 assert(mem.eql(u8, dest[0..2], bytes[6..8]));107 expect(mem.eql(u8, dest[0..2], bytes[6..8]));
108108
109 ps.putBackByte(11);109 ps.putBackByte(11);
110 ps.putBackByte(12);110 ps.putBackByte(12);
111111
112 read = try ps.stream.read(dest[0..4]);112 read = try ps.stream.read(dest[0..4]);
113 assert(read == 2);113 expect(read == 2);
114 assert(dest[0] == 12);114 expect(dest[0] == 12);
115 assert(dest[1] == 11);115 expect(dest[1] == 11);
116}116}
117117
118test "SliceOutStream" {118test "SliceOutStream" {
...@@ -120,19 +120,19 @@ test "SliceOutStream" {...@@ -120,19 +120,19 @@ test "SliceOutStream" {
120 var ss = io.SliceOutStream.init(buffer[0..]);120 var ss = io.SliceOutStream.init(buffer[0..]);
121121
122 try ss.stream.write("Hello");122 try ss.stream.write("Hello");
123 assert(mem.eql(u8, ss.getWritten(), "Hello"));123 expect(mem.eql(u8, ss.getWritten(), "Hello"));
124124
125 try ss.stream.write("world");125 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);128 expectError(error.OutOfSpace, ss.stream.write("!"));
129 assert(mem.eql(u8, ss.getWritten(), "Helloworld"));129 expect(mem.eql(u8, ss.getWritten(), "Helloworld"));
130130
131 ss.reset();131 ss.reset();
132 assert(ss.getWritten().len == 0);132 expect(ss.getWritten().len == 0);
133133
134 assertError(ss.stream.write("Hello world!"), error.OutOfSpace);134 expectError(error.OutOfSpace, ss.stream.write("Hello world!"));
135 assert(mem.eql(u8, ss.getWritten(), "Hello worl"));135 expect(mem.eql(u8, ss.getWritten(), "Hello worl"));
136}136}
137137
138test "BitInStream" {138test "BitInStream" {
...@@ -145,66 +145,66 @@ test "BitInStream" {...@@ -145,66 +145,66 @@ test "BitInStream" {
145145
146 var out_bits: usize = undefined;146 var out_bits: usize = undefined;
147147
148 assert(1 == try bit_stream_be.readBits(u2, 1, &out_bits));148 expect(1 == try bit_stream_be.readBits(u2, 1, &out_bits));
149 assert(out_bits == 1);149 expect(out_bits == 1);
150 assert(2 == try bit_stream_be.readBits(u5, 2, &out_bits));150 expect(2 == try bit_stream_be.readBits(u5, 2, &out_bits));
151 assert(out_bits == 2);151 expect(out_bits == 2);
152 assert(3 == try bit_stream_be.readBits(u128, 3, &out_bits));152 expect(3 == try bit_stream_be.readBits(u128, 3, &out_bits));
153 assert(out_bits == 3);153 expect(out_bits == 3);
154 assert(4 == try bit_stream_be.readBits(u8, 4, &out_bits));154 expect(4 == try bit_stream_be.readBits(u8, 4, &out_bits));
155 assert(out_bits == 4);155 expect(out_bits == 4);
156 assert(5 == try bit_stream_be.readBits(u9, 5, &out_bits));156 expect(5 == try bit_stream_be.readBits(u9, 5, &out_bits));
157 assert(out_bits == 5);157 expect(out_bits == 5);
158 assert(1 == try bit_stream_be.readBits(u1, 1, &out_bits));158 expect(1 == try bit_stream_be.readBits(u1, 1, &out_bits));
159 assert(out_bits == 1);159 expect(out_bits == 1);
160160
161 mem_in_be.pos = 0;161 mem_in_be.pos = 0;
162 bit_stream_be.bit_count = 0;162 bit_stream_be.bit_count = 0;
163 assert(0b110011010000101 == try bit_stream_be.readBits(u15, 15, &out_bits));163 expect(0b110011010000101 == try bit_stream_be.readBits(u15, 15, &out_bits));
164 assert(out_bits == 15);164 expect(out_bits == 15);
165165
166 mem_in_be.pos = 0;166 mem_in_be.pos = 0;
167 bit_stream_be.bit_count = 0;167 bit_stream_be.bit_count = 0;
168 assert(0b1100110100001011 == try bit_stream_be.readBits(u16, 16, &out_bits));168 expect(0b1100110100001011 == try bit_stream_be.readBits(u16, 16, &out_bits));
169 assert(out_bits == 16);169 expect(out_bits == 16);
170170
171 _ = try bit_stream_be.readBits(u0, 0, &out_bits);171 _ = try bit_stream_be.readBits(u0, 0, &out_bits);
172 172
173 assert(0 == try bit_stream_be.readBits(u1, 1, &out_bits));173 expect(0 == try bit_stream_be.readBits(u1, 1, &out_bits));
174 assert(out_bits == 0);174 expect(out_bits == 0);
175 assertError(bit_stream_be.readBitsNoEof(u1, 1), error.EndOfStream);175 expectError(error.EndOfStream, bit_stream_be.readBitsNoEof(u1, 1));
176176
177 var mem_in_le = io.SliceInStream.init(mem_le[0..]);177 var mem_in_le = io.SliceInStream.init(mem_le[0..]);
178 var bit_stream_le = io.BitInStream(builtin.Endian.Little, InError).init(&mem_in_le.stream);178 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));180 expect(1 == try bit_stream_le.readBits(u2, 1, &out_bits));
181 assert(out_bits == 1);181 expect(out_bits == 1);
182 assert(2 == try bit_stream_le.readBits(u5, 2, &out_bits));182 expect(2 == try bit_stream_le.readBits(u5, 2, &out_bits));
183 assert(out_bits == 2);183 expect(out_bits == 2);
184 assert(3 == try bit_stream_le.readBits(u128, 3, &out_bits));184 expect(3 == try bit_stream_le.readBits(u128, 3, &out_bits));
185 assert(out_bits == 3);185 expect(out_bits == 3);
186 assert(4 == try bit_stream_le.readBits(u8, 4, &out_bits));186 expect(4 == try bit_stream_le.readBits(u8, 4, &out_bits));
187 assert(out_bits == 4);187 expect(out_bits == 4);
188 assert(5 == try bit_stream_le.readBits(u9, 5, &out_bits));188 expect(5 == try bit_stream_le.readBits(u9, 5, &out_bits));
189 assert(out_bits == 5);189 expect(out_bits == 5);
190 assert(1 == try bit_stream_le.readBits(u1, 1, &out_bits));190 expect(1 == try bit_stream_le.readBits(u1, 1, &out_bits));
191 assert(out_bits == 1);191 expect(out_bits == 1);
192192
193 mem_in_le.pos = 0;193 mem_in_le.pos = 0;
194 bit_stream_le.bit_count = 0;194 bit_stream_le.bit_count = 0;
195 assert(0b001010100011101 == try bit_stream_le.readBits(u15, 15, &out_bits));195 expect(0b001010100011101 == try bit_stream_le.readBits(u15, 15, &out_bits));
196 assert(out_bits == 15);196 expect(out_bits == 15);
197197
198 mem_in_le.pos = 0;198 mem_in_le.pos = 0;
199 bit_stream_le.bit_count = 0;199 bit_stream_le.bit_count = 0;
200 assert(0b1001010100011101 == try bit_stream_le.readBits(u16, 16, &out_bits));200 expect(0b1001010100011101 == try bit_stream_le.readBits(u16, 16, &out_bits));
201 assert(out_bits == 16);201 expect(out_bits == 16);
202202
203 _ = try bit_stream_le.readBits(u0, 0, &out_bits);203 _ = try bit_stream_le.readBits(u0, 0, &out_bits);
204 204
205 assert(0 == try bit_stream_le.readBits(u1, 1, &out_bits));205 expect(0 == try bit_stream_le.readBits(u1, 1, &out_bits));
206 assert(out_bits == 0);206 expect(out_bits == 0);
207 assertError(bit_stream_le.readBitsNoEof(u1, 1), error.EndOfStream);207 expectError(error.EndOfStream, bit_stream_le.readBitsNoEof(u1, 1));
208}208}
209209
210test "BitOutStream" {210test "BitOutStream" {
...@@ -222,17 +222,17 @@ test "BitOutStream" {...@@ -222,17 +222,17 @@ test "BitOutStream" {
222 try bit_stream_be.writeBits(u9(5), 5);222 try bit_stream_be.writeBits(u9(5), 5);
223 try bit_stream_be.writeBits(u1(1), 1);223 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
227 mem_out_be.pos = 0;227 mem_out_be.pos = 0;
228228
229 try bit_stream_be.writeBits(u15(0b110011010000101), 15);229 try bit_stream_be.writeBits(u15(0b110011010000101), 15);
230 try bit_stream_be.flushBits();230 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
233 mem_out_be.pos = 0;233 mem_out_be.pos = 0;
234 try bit_stream_be.writeBits(u32(0b110011010000101), 16);234 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
237 try bit_stream_be.writeBits(u0(0), 0);237 try bit_stream_be.writeBits(u0(0), 0);
238238
...@@ -246,16 +246,16 @@ test "BitOutStream" {...@@ -246,16 +246,16 @@ test "BitOutStream" {
246 try bit_stream_le.writeBits(u9(5), 5);246 try bit_stream_le.writeBits(u9(5), 5);
247 try bit_stream_le.writeBits(u1(1), 1);247 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
251 mem_out_le.pos = 0;251 mem_out_le.pos = 0;
252 try bit_stream_le.writeBits(u15(0b110011010000101), 15);252 try bit_stream_le.writeBits(u15(0b110011010000101), 15);
253 try bit_stream_le.flushBits();253 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
256 mem_out_le.pos = 0;256 mem_out_le.pos = 0;
257 try bit_stream_le.writeBits(u32(0b1100110100001011), 16);257 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
260 try bit_stream_le.writeBits(u0(0), 0);260 try bit_stream_le.writeBits(u0(0), 0);
261}261}
...@@ -290,20 +290,20 @@ test "BitStreams with File Stream" {...@@ -290,20 +290,20 @@ test "BitStreams with File Stream" {
290 290
291 var out_bits: usize = undefined;291 var out_bits: usize = undefined;
292292
293 assert(1 == try bit_stream.readBits(u2, 1, &out_bits));293 expect(1 == try bit_stream.readBits(u2, 1, &out_bits));
294 assert(out_bits == 1);294 expect(out_bits == 1);
295 assert(2 == try bit_stream.readBits(u5, 2, &out_bits));295 expect(2 == try bit_stream.readBits(u5, 2, &out_bits));
296 assert(out_bits == 2);296 expect(out_bits == 2);
297 assert(3 == try bit_stream.readBits(u128, 3, &out_bits));297 expect(3 == try bit_stream.readBits(u128, 3, &out_bits));
298 assert(out_bits == 3);298 expect(out_bits == 3);
299 assert(4 == try bit_stream.readBits(u8, 4, &out_bits));299 expect(4 == try bit_stream.readBits(u8, 4, &out_bits));
300 assert(out_bits == 4);300 expect(out_bits == 4);
301 assert(5 == try bit_stream.readBits(u9, 5, &out_bits));301 expect(5 == try bit_stream.readBits(u9, 5, &out_bits));
302 assert(out_bits == 5);302 expect(out_bits == 5);
303 assert(1 == try bit_stream.readBits(u1, 1, &out_bits));303 expect(1 == try bit_stream.readBits(u1, 1, &out_bits));
304 assert(out_bits == 1);304 expect(out_bits == 1);
305 305
306 assertError(bit_stream.readBitsNoEof(u1, 1), error.EndOfStream);306 expectError(error.EndOfStream, bit_stream.readBitsNoEof(u1, 1));
307 }307 }
308 try os.deleteFile(tmp_file_name);308 try os.deleteFile(tmp_file_name);
309}309}
...@@ -345,8 +345,8 @@ fn testIntSerializerDeserializer(comptime endian: builtin.Endian, comptime is_pa...@@ -345,8 +345,8 @@ fn testIntSerializerDeserializer(comptime endian: builtin.Endian, comptime is_pa
345 const S = @IntType(true, i);345 const S = @IntType(true, i);
346 const x = try deserializer.deserializeInt(U);346 const x = try deserializer.deserializeInt(U);
347 const y = try deserializer.deserializeInt(S);347 const y = try deserializer.deserializeInt(S);
348 assert(x == U(i));348 expect(x == U(i));
349 if (i != 0) assert(y == S(-1)) else assert(y == 0);349 if (i != 0) expect(y == S(-1)) else expect(y == 0);
350 }350 }
351351
352 const u8_bit_count = comptime meta.bitCount(u8);352 const u8_bit_count = comptime meta.bitCount(u8);
...@@ -356,7 +356,7 @@ fn testIntSerializerDeserializer(comptime endian: builtin.Endian, comptime is_pa...@@ -356,7 +356,7 @@ fn testIntSerializerDeserializer(comptime endian: builtin.Endian, comptime is_pa
356 const extra_packed_byte = @boolToInt(total_bits % u8_bit_count > 0);356 const extra_packed_byte = @boolToInt(total_bits % u8_bit_count > 0);
357 const total_packed_bytes = (total_bits / u8_bit_count) + extra_packed_byte;357 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
361 //Verify that empty error set works with serializer.361 //Verify that empty error set works with serializer.
362 //deserializer is covered by SliceInStream362 //deserializer is covered by SliceInStream
...@@ -408,14 +408,14 @@ fn testIntSerializerDeserializerInfNaN(comptime endian: builtin.Endian,...@@ -408,14 +408,14 @@ fn testIntSerializerDeserializerInfNaN(comptime endian: builtin.Endian,
408 const inf_check_f64 = try deserializer.deserialize(f64);408 const inf_check_f64 = try deserializer.deserialize(f64);
409 //const nan_check_f128 = try deserializer.deserialize(f128);409 //const nan_check_f128 = try deserializer.deserialize(f128);
410 //const inf_check_f128 = try deserializer.deserialize(f128);410 //const inf_check_f128 = try deserializer.deserialize(f128);
411 assert(std.math.isNan(nan_check_f16));411 expect(std.math.isNan(nan_check_f16));
412 assert(std.math.isInf(inf_check_f16));412 expect(std.math.isInf(inf_check_f16));
413 assert(std.math.isNan(nan_check_f32));413 expect(std.math.isNan(nan_check_f32));
414 assert(std.math.isInf(inf_check_f32));414 expect(std.math.isInf(inf_check_f32));
415 assert(std.math.isNan(nan_check_f64));415 expect(std.math.isNan(nan_check_f64));
416 assert(std.math.isInf(inf_check_f64));416 expect(std.math.isInf(inf_check_f64));
417 //assert(std.math.isNan(nan_check_f128));417 //expect(std.math.isNan(nan_check_f128));
418 //assert(std.math.isInf(inf_check_f128));418 //expect(std.math.isInf(inf_check_f128));
419}419}
420420
421test "Serializer/Deserializer Int: Inf/NaN" {421test "Serializer/Deserializer Int: Inf/NaN" {
...@@ -528,7 +528,7 @@ fn testSerializerDeserializer(comptime endian: builtin.Endian, comptime is_packe...@@ -528,7 +528,7 @@ fn testSerializerDeserializer(comptime endian: builtin.Endian, comptime is_packe
528 try serializer.serialize(my_inst);528 try serializer.serialize(my_inst);
529529
530 const my_copy = try deserializer.deserialize(MyStruct);530 const my_copy = try deserializer.deserialize(MyStruct);
531 assert(meta.eql(my_copy, my_inst));531 expect(meta.eql(my_copy, my_inst));
532}532}
533533
534test "Serializer/Deserializer generic" {534test "Serializer/Deserializer generic" {
...@@ -565,11 +565,11 @@ fn testBadData(comptime endian: builtin.Endian, comptime is_packed: bool) !void...@@ -565,11 +565,11 @@ fn testBadData(comptime endian: builtin.Endian, comptime is_packed: bool) !void
565 var deserializer = io.Deserializer(endian, is_packed, InError).init(in_stream);565 var deserializer = io.Deserializer(endian, is_packed, InError).init(in_stream);
566566
567 try serializer.serialize(u14(3));567 try serializer.serialize(u14(3));
568 assertError(deserializer.deserialize(A), error.InvalidEnumTag);568 expectError(error.InvalidEnumTag, deserializer.deserialize(A));
569 out.pos = 0;569 out.pos = 0;
570 try serializer.serialize(u14(3));570 try serializer.serialize(u14(3));
571 try serializer.serialize(u14(88));571 try serializer.serialize(u14(88));
572 assertError(deserializer.deserialize(C), error.InvalidEnumTag);572 expectError(error.InvalidEnumTag, deserializer.deserialize(C));
573}573}
574574
575test "Deserializer bad data" {575test "Deserializer bad data" {
std/json.zig+9-8
...@@ -4,6 +4,7 @@...@@ -4,6 +4,7 @@
44
5const std = @import("index.zig");5const std = @import("index.zig");
6const debug = std.debug;6const debug = std.debug;
7const testing = std.testing;
7const mem = std.mem;8const mem = std.mem;
8const maxInt = std.math.maxInt;9const maxInt = std.math.maxInt;
910
...@@ -960,7 +961,7 @@ test "json.token" {...@@ -960,7 +961,7 @@ test "json.token" {
960 checkNext(&p, Token.Id.ObjectEnd);961 checkNext(&p, Token.Id.ObjectEnd);
961 checkNext(&p, Token.Id.ObjectEnd);962 checkNext(&p, Token.Id.ObjectEnd);
962963
963 debug.assert((try p.next()) == null);964 testing.expect((try p.next()) == null);
964}965}
965966
966// Validate a JSON string. This does not limit number precision so a decoder may not necessarily967// 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 {...@@ -981,7 +982,7 @@ pub fn validate(s: []const u8) bool {
981}982}
982983
983test "json.validate" {984test "json.validate" {
984 debug.assert(validate("{}"));985 testing.expect(validate("{}"));
985}986}
986987
987const Allocator = std.mem.Allocator;988const Allocator = std.mem.Allocator;
...@@ -1378,20 +1379,20 @@ test "json.parser.dynamic" {...@@ -1378,20 +1379,20 @@ test "json.parser.dynamic" {
1378 var image = root.Object.get("Image").?.value;1379 var image = root.Object.get("Image").?.value;
13791380
1380 const width = image.Object.get("Width").?.value;1381 const width = image.Object.get("Width").?.value;
1381 debug.assert(width.Integer == 800);1382 testing.expect(width.Integer == 800);
13821383
1383 const height = image.Object.get("Height").?.value;1384 const height = image.Object.get("Height").?.value;
1384 debug.assert(height.Integer == 600);1385 testing.expect(height.Integer == 600);
13851386
1386 const title = image.Object.get("Title").?.value;1387 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
1389 const animated = image.Object.get("Animated").?.value;1390 const animated = image.Object.get("Animated").?.value;
1390 debug.assert(animated.Bool == false);1391 testing.expect(animated.Bool == false);
13911392
1392 const array_of_object = image.Object.get("ArrayOfObject").?.value;1393 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
1395 const obj0 = array_of_object.Array.at(0).Object.get("n").?.value;1396 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"));
1397}1398}
std/json_test.zig+3-3
...@@ -6,15 +6,15 @@...@@ -6,15 +6,15 @@
6const std = @import("index.zig");6const std = @import("index.zig");
77
8fn ok(comptime s: []const u8) void {8fn ok(comptime s: []const u8) void {
9 std.debug.assert(std.json.validate(s));9 std.testing.expect(std.json.validate(s));
10}10}
1111
12fn err(comptime s: []const u8) void {12fn err(comptime s: []const u8) void {
13 std.debug.assert(!std.json.validate(s));13 std.testing.expect(!std.json.validate(s));
14}14}
1515
16fn any(comptime s: []const u8) void {16fn any(comptime s: []const u8) void {
17 std.debug.assert(true);17 std.testing.expect(true);
18}18}
1919
20////////////////////////////////////////////////////////////////////////////////////////////////////20////////////////////////////////////////////////////////////////////////////////////////////////////
std/lazy_init.zig+5-4
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const std = @import("index.zig");1const std = @import("index.zig");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const assert = std.debug.assert;3const assert = std.debug.assert;
4const testing = std.testing;
4const AtomicRmwOp = builtin.AtomicRmwOp;5const AtomicRmwOp = builtin.AtomicRmwOp;
5const AtomicOrder = builtin.AtomicOrder;6const AtomicOrder = builtin.AtomicOrder;
67
...@@ -63,12 +64,12 @@ test "std.lazyInit" {...@@ -63,12 +64,12 @@ test "std.lazyInit" {
63 global_number.resolve();64 global_number.resolve();
64 }65 }
65 if (global_number.get()) |x| {66 if (global_number.get()) |x| {
66 assert(x.* == 1234);67 testing.expect(x.* == 1234);
67 } else {68 } else {
68 @panic("bad");69 @panic("bad");
69 }70 }
70 if (global_number.get()) |x| {71 if (global_number.get()) |x| {
71 assert(x.* == 1234);72 testing.expect(x.* == 1234);
72 } else {73 } else {
73 @panic("bad");74 @panic("bad");
74 }75 }
...@@ -80,6 +81,6 @@ test "std.lazyInit(void)" {...@@ -80,6 +81,6 @@ test "std.lazyInit(void)" {
80 if (global_void.get()) |_| @panic("bad") else {81 if (global_void.get()) |_| @panic("bad") else {
81 global_void.resolve();82 global_void.resolve();
82 }83 }
83 assert(global_void.get() != null);84 testing.expect(global_void.get() != null);
84 assert(global_void.get() != null);85 testing.expect(global_void.get() != null);
85}86}
std/linked_list.zig+15-14
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const std = @import("index.zig");1const std = @import("index.zig");
2const debug = std.debug;2const debug = std.debug;
3const assert = debug.assert;3const assert = debug.assert;
4const testing = std.testing;
4const mem = std.mem;5const mem = std.mem;
5const Allocator = mem.Allocator;6const Allocator = mem.Allocator;
67
...@@ -246,7 +247,7 @@ test "basic linked list test" {...@@ -246,7 +247,7 @@ test "basic linked list test" {
246 var it = list.first;247 var it = list.first;
247 var index: u32 = 1;248 var index: u32 = 1;
248 while (it) |node| : (it = node.next) {249 while (it) |node| : (it = node.next) {
249 assert(node.data == index);250 testing.expect(node.data == index);
250 index += 1;251 index += 1;
251 }252 }
252 }253 }
...@@ -256,7 +257,7 @@ test "basic linked list test" {...@@ -256,7 +257,7 @@ test "basic linked list test" {
256 var it = list.last;257 var it = list.last;
257 var index: u32 = 1;258 var index: u32 = 1;
258 while (it) |node| : (it = node.prev) {259 while (it) |node| : (it = node.prev) {
259 assert(node.data == (6 - index));260 testing.expect(node.data == (6 - index));
260 index += 1;261 index += 1;
261 }262 }
262 }263 }
...@@ -265,9 +266,9 @@ test "basic linked list test" {...@@ -265,9 +266,9 @@ test "basic linked list test" {
265 var last = list.pop(); // {2, 3, 4}266 var last = list.pop(); // {2, 3, 4}
266 list.remove(three); // {2, 4}267 list.remove(three); // {2, 4}
267268
268 assert(list.first.?.data == 2);269 testing.expect(list.first.?.data == 2);
269 assert(list.last.?.data == 4);270 testing.expect(list.last.?.data == 4);
270 assert(list.len == 2);271 testing.expect(list.len == 2);
271}272}
272273
273test "linked list concatenation" {274test "linked list concatenation" {
...@@ -294,18 +295,18 @@ test "linked list concatenation" {...@@ -294,18 +295,18 @@ test "linked list concatenation" {
294295
295 list1.concatByMoving(&list2);296 list1.concatByMoving(&list2);
296297
297 assert(list1.last == five);298 testing.expect(list1.last == five);
298 assert(list1.len == 5);299 testing.expect(list1.len == 5);
299 assert(list2.first == null);300 testing.expect(list2.first == null);
300 assert(list2.last == null);301 testing.expect(list2.last == null);
301 assert(list2.len == 0);302 testing.expect(list2.len == 0);
302303
303 // Traverse forwards.304 // Traverse forwards.
304 {305 {
305 var it = list1.first;306 var it = list1.first;
306 var index: u32 = 1;307 var index: u32 = 1;
307 while (it) |node| : (it = node.next) {308 while (it) |node| : (it = node.next) {
308 assert(node.data == index);309 testing.expect(node.data == index);
309 index += 1;310 index += 1;
310 }311 }
311 }312 }
...@@ -315,7 +316,7 @@ test "linked list concatenation" {...@@ -315,7 +316,7 @@ test "linked list concatenation" {
315 var it = list1.last;316 var it = list1.last;
316 var index: u32 = 1;317 var index: u32 = 1;
317 while (it) |node| : (it = node.prev) {318 while (it) |node| : (it = node.prev) {
318 assert(node.data == (6 - index));319 testing.expect(node.data == (6 - index));
319 index += 1;320 index += 1;
320 }321 }
321 }322 }
...@@ -328,7 +329,7 @@ test "linked list concatenation" {...@@ -328,7 +329,7 @@ test "linked list concatenation" {
328 var it = list2.first;329 var it = list2.first;
329 var index: u32 = 1;330 var index: u32 = 1;
330 while (it) |node| : (it = node.next) {331 while (it) |node| : (it = node.next) {
331 assert(node.data == index);332 testing.expect(node.data == index);
332 index += 1;333 index += 1;
333 }334 }
334 }335 }
...@@ -338,7 +339,7 @@ test "linked list concatenation" {...@@ -338,7 +339,7 @@ test "linked list concatenation" {
338 var it = list2.last;339 var it = list2.last;
339 var index: u32 = 1;340 var index: u32 = 1;
340 while (it) |node| : (it = node.prev) {341 while (it) |node| : (it = node.prev) {
341 assert(node.data == (6 - index));342 testing.expect(node.data == (6 - index));
342 index += 1;343 index += 1;
343 }344 }
344 }345 }
std/math/acos.zig+19-19
...@@ -4,7 +4,7 @@...@@ -4,7 +4,7 @@
44
5const std = @import("../index.zig");5const std = @import("../index.zig");
6const math = std.math;6const math = std.math;
7const assert = std.debug.assert;7const expect = std.testing.expect;
88
9pub fn acos(x: var) @typeOf(x) {9pub fn acos(x: var) @typeOf(x) {
10 const T = @typeOf(x);10 const T = @typeOf(x);
...@@ -143,38 +143,38 @@ fn acos64(x: f64) f64 {...@@ -143,38 +143,38 @@ fn acos64(x: f64) f64 {
143}143}
144144
145test "math.acos" {145test "math.acos" {
146 assert(acos(f32(0.0)) == acos32(0.0));146 expect(acos(f32(0.0)) == acos32(0.0));
147 assert(acos(f64(0.0)) == acos64(0.0));147 expect(acos(f64(0.0)) == acos64(0.0));
148}148}
149149
150test "math.acos32" {150test "math.acos32" {
151 const epsilon = 0.000001;151 const epsilon = 0.000001;
152152
153 assert(math.approxEq(f32, acos32(0.0), 1.570796, epsilon));153 expect(math.approxEq(f32, acos32(0.0), 1.570796, epsilon));
154 assert(math.approxEq(f32, acos32(0.2), 1.369438, epsilon));154 expect(math.approxEq(f32, acos32(0.2), 1.369438, epsilon));
155 assert(math.approxEq(f32, acos32(0.3434), 1.220262, epsilon));155 expect(math.approxEq(f32, acos32(0.3434), 1.220262, epsilon));
156 assert(math.approxEq(f32, acos32(0.5), 1.047198, epsilon));156 expect(math.approxEq(f32, acos32(0.5), 1.047198, epsilon));
157 assert(math.approxEq(f32, acos32(0.8923), 0.468382, epsilon));157 expect(math.approxEq(f32, acos32(0.8923), 0.468382, epsilon));
158 assert(math.approxEq(f32, acos32(-0.2), 1.772154, epsilon));158 expect(math.approxEq(f32, acos32(-0.2), 1.772154, epsilon));
159}159}
160160
161test "math.acos64" {161test "math.acos64" {
162 const epsilon = 0.000001;162 const epsilon = 0.000001;
163163
164 assert(math.approxEq(f64, acos64(0.0), 1.570796, epsilon));164 expect(math.approxEq(f64, acos64(0.0), 1.570796, epsilon));
165 assert(math.approxEq(f64, acos64(0.2), 1.369438, epsilon));165 expect(math.approxEq(f64, acos64(0.2), 1.369438, epsilon));
166 assert(math.approxEq(f64, acos64(0.3434), 1.220262, epsilon));166 expect(math.approxEq(f64, acos64(0.3434), 1.220262, epsilon));
167 assert(math.approxEq(f64, acos64(0.5), 1.047198, epsilon));167 expect(math.approxEq(f64, acos64(0.5), 1.047198, epsilon));
168 assert(math.approxEq(f64, acos64(0.8923), 0.468382, epsilon));168 expect(math.approxEq(f64, acos64(0.8923), 0.468382, epsilon));
169 assert(math.approxEq(f64, acos64(-0.2), 1.772154, epsilon));169 expect(math.approxEq(f64, acos64(-0.2), 1.772154, epsilon));
170}170}
171171
172test "math.acos32.special" {172test "math.acos32.special" {
173 assert(math.isNan(acos32(-2)));173 expect(math.isNan(acos32(-2)));
174 assert(math.isNan(acos32(1.5)));174 expect(math.isNan(acos32(1.5)));
175}175}
176176
177test "math.acos64.special" {177test "math.acos64.special" {
178 assert(math.isNan(acos64(-2)));178 expect(math.isNan(acos64(-2)));
179 assert(math.isNan(acos64(1.5)));179 expect(math.isNan(acos64(1.5)));
180}180}
std/math/acosh.zig+15-15
...@@ -6,7 +6,7 @@...@@ -6,7 +6,7 @@
6const builtin = @import("builtin");6const builtin = @import("builtin");
7const std = @import("../index.zig");7const std = @import("../index.zig");
8const math = std.math;8const math = std.math;
9const assert = std.debug.assert;9const expect = std.testing.expect;
1010
11pub fn acosh(x: var) @typeOf(x) {11pub fn acosh(x: var) @typeOf(x) {
12 const T = @typeOf(x);12 const T = @typeOf(x);
...@@ -55,34 +55,34 @@ fn acosh64(x: f64) f64 {...@@ -55,34 +55,34 @@ fn acosh64(x: f64) f64 {
55}55}
5656
57test "math.acosh" {57test "math.acosh" {
58 assert(acosh(f32(1.5)) == acosh32(1.5));58 expect(acosh(f32(1.5)) == acosh32(1.5));
59 assert(acosh(f64(1.5)) == acosh64(1.5));59 expect(acosh(f64(1.5)) == acosh64(1.5));
60}60}
6161
62test "math.acosh32" {62test "math.acosh32" {
63 const epsilon = 0.000001;63 const epsilon = 0.000001;
6464
65 assert(math.approxEq(f32, acosh32(1.5), 0.962424, epsilon));65 expect(math.approxEq(f32, acosh32(1.5), 0.962424, epsilon));
66 assert(math.approxEq(f32, acosh32(37.45), 4.315976, epsilon));66 expect(math.approxEq(f32, acosh32(37.45), 4.315976, epsilon));
67 assert(math.approxEq(f32, acosh32(89.123), 5.183133, epsilon));67 expect(math.approxEq(f32, acosh32(89.123), 5.183133, epsilon));
68 assert(math.approxEq(f32, acosh32(123123.234375), 12.414088, epsilon));68 expect(math.approxEq(f32, acosh32(123123.234375), 12.414088, epsilon));
69}69}
7070
71test "math.acosh64" {71test "math.acosh64" {
72 const epsilon = 0.000001;72 const epsilon = 0.000001;
7373
74 assert(math.approxEq(f64, acosh64(1.5), 0.962424, epsilon));74 expect(math.approxEq(f64, acosh64(1.5), 0.962424, epsilon));
75 assert(math.approxEq(f64, acosh64(37.45), 4.315976, epsilon));75 expect(math.approxEq(f64, acosh64(37.45), 4.315976, epsilon));
76 assert(math.approxEq(f64, acosh64(89.123), 5.183133, epsilon));76 expect(math.approxEq(f64, acosh64(89.123), 5.183133, epsilon));
77 assert(math.approxEq(f64, acosh64(123123.234375), 12.414088, epsilon));77 expect(math.approxEq(f64, acosh64(123123.234375), 12.414088, epsilon));
78}78}
7979
80test "math.acosh32.special" {80test "math.acosh32.special" {
81 assert(math.isNan(acosh32(math.nan(f32))));81 expect(math.isNan(acosh32(math.nan(f32))));
82 assert(math.isSignalNan(acosh32(0.5)));82 expect(math.isSignalNan(acosh32(0.5)));
83}83}
8484
85test "math.acosh64.special" {85test "math.acosh64.special" {
86 assert(math.isNan(acosh64(math.nan(f64))));86 expect(math.isNan(acosh64(math.nan(f64))));
87 assert(math.isSignalNan(acosh64(0.5)));87 expect(math.isSignalNan(acosh64(0.5)));
88}88}
std/math/asin.zig+23-23
...@@ -5,7 +5,7 @@...@@ -5,7 +5,7 @@
55
6const std = @import("../index.zig");6const std = @import("../index.zig");
7const math = std.math;7const math = std.math;
8const assert = std.debug.assert;8const expect = std.testing.expect;
99
10pub fn asin(x: var) @typeOf(x) {10pub fn asin(x: var) @typeOf(x) {
11 const T = @typeOf(x);11 const T = @typeOf(x);
...@@ -136,42 +136,42 @@ fn asin64(x: f64) f64 {...@@ -136,42 +136,42 @@ fn asin64(x: f64) f64 {
136}136}
137137
138test "math.asin" {138test "math.asin" {
139 assert(asin(f32(0.0)) == asin32(0.0));139 expect(asin(f32(0.0)) == asin32(0.0));
140 assert(asin(f64(0.0)) == asin64(0.0));140 expect(asin(f64(0.0)) == asin64(0.0));
141}141}
142142
143test "math.asin32" {143test "math.asin32" {
144 const epsilon = 0.000001;144 const epsilon = 0.000001;
145145
146 assert(math.approxEq(f32, asin32(0.0), 0.0, epsilon));146 expect(math.approxEq(f32, asin32(0.0), 0.0, epsilon));
147 assert(math.approxEq(f32, asin32(0.2), 0.201358, epsilon));147 expect(math.approxEq(f32, asin32(0.2), 0.201358, epsilon));
148 assert(math.approxEq(f32, asin32(-0.2), -0.201358, epsilon));148 expect(math.approxEq(f32, asin32(-0.2), -0.201358, epsilon));
149 assert(math.approxEq(f32, asin32(0.3434), 0.350535, epsilon));149 expect(math.approxEq(f32, asin32(0.3434), 0.350535, epsilon));
150 assert(math.approxEq(f32, asin32(0.5), 0.523599, epsilon));150 expect(math.approxEq(f32, asin32(0.5), 0.523599, epsilon));
151 assert(math.approxEq(f32, asin32(0.8923), 1.102415, epsilon));151 expect(math.approxEq(f32, asin32(0.8923), 1.102415, epsilon));
152}152}
153153
154test "math.asin64" {154test "math.asin64" {
155 const epsilon = 0.000001;155 const epsilon = 0.000001;
156156
157 assert(math.approxEq(f64, asin64(0.0), 0.0, epsilon));157 expect(math.approxEq(f64, asin64(0.0), 0.0, epsilon));
158 assert(math.approxEq(f64, asin64(0.2), 0.201358, epsilon));158 expect(math.approxEq(f64, asin64(0.2), 0.201358, epsilon));
159 assert(math.approxEq(f64, asin64(-0.2), -0.201358, epsilon));159 expect(math.approxEq(f64, asin64(-0.2), -0.201358, epsilon));
160 assert(math.approxEq(f64, asin64(0.3434), 0.350535, epsilon));160 expect(math.approxEq(f64, asin64(0.3434), 0.350535, epsilon));
161 assert(math.approxEq(f64, asin64(0.5), 0.523599, epsilon));161 expect(math.approxEq(f64, asin64(0.5), 0.523599, epsilon));
162 assert(math.approxEq(f64, asin64(0.8923), 1.102415, epsilon));162 expect(math.approxEq(f64, asin64(0.8923), 1.102415, epsilon));
163}163}
164164
165test "math.asin32.special" {165test "math.asin32.special" {
166 assert(asin32(0.0) == 0.0);166 expect(asin32(0.0) == 0.0);
167 assert(asin32(-0.0) == -0.0);167 expect(asin32(-0.0) == -0.0);
168 assert(math.isNan(asin32(-2)));168 expect(math.isNan(asin32(-2)));
169 assert(math.isNan(asin32(1.5)));169 expect(math.isNan(asin32(1.5)));
170}170}
171171
172test "math.asin64.special" {172test "math.asin64.special" {
173 assert(asin64(0.0) == 0.0);173 expect(asin64(0.0) == 0.0);
174 assert(asin64(-0.0) == -0.0);174 expect(asin64(-0.0) == -0.0);
175 assert(math.isNan(asin64(-2)));175 expect(math.isNan(asin64(-2)));
176 assert(math.isNan(asin64(1.5)));176 expect(math.isNan(asin64(1.5)));
177}177}
std/math/asinh.zig+27-27
...@@ -6,7 +6,7 @@...@@ -6,7 +6,7 @@
66
7const std = @import("../index.zig");7const std = @import("../index.zig");
8const math = std.math;8const math = std.math;
9const assert = std.debug.assert;9const expect = std.testing.expect;
10const maxInt = std.math.maxInt;10const maxInt = std.math.maxInt;
1111
12pub fn asinh(x: var) @typeOf(x) {12pub fn asinh(x: var) @typeOf(x) {
...@@ -83,46 +83,46 @@ fn asinh64(x: f64) f64 {...@@ -83,46 +83,46 @@ fn asinh64(x: f64) f64 {
83}83}
8484
85test "math.asinh" {85test "math.asinh" {
86 assert(asinh(f32(0.0)) == asinh32(0.0));86 expect(asinh(f32(0.0)) == asinh32(0.0));
87 assert(asinh(f64(0.0)) == asinh64(0.0));87 expect(asinh(f64(0.0)) == asinh64(0.0));
88}88}
8989
90test "math.asinh32" {90test "math.asinh32" {
91 const epsilon = 0.000001;91 const epsilon = 0.000001;
9292
93 assert(math.approxEq(f32, asinh32(0.0), 0.0, epsilon));93 expect(math.approxEq(f32, asinh32(0.0), 0.0, epsilon));
94 assert(math.approxEq(f32, asinh32(0.2), 0.198690, epsilon));94 expect(math.approxEq(f32, asinh32(0.2), 0.198690, epsilon));
95 assert(math.approxEq(f32, asinh32(0.8923), 0.803133, epsilon));95 expect(math.approxEq(f32, asinh32(0.8923), 0.803133, epsilon));
96 assert(math.approxEq(f32, asinh32(1.5), 1.194763, epsilon));96 expect(math.approxEq(f32, asinh32(1.5), 1.194763, epsilon));
97 assert(math.approxEq(f32, asinh32(37.45), 4.316332, epsilon));97 expect(math.approxEq(f32, asinh32(37.45), 4.316332, epsilon));
98 assert(math.approxEq(f32, asinh32(89.123), 5.183196, epsilon));98 expect(math.approxEq(f32, asinh32(89.123), 5.183196, epsilon));
99 assert(math.approxEq(f32, asinh32(123123.234375), 12.414088, epsilon));99 expect(math.approxEq(f32, asinh32(123123.234375), 12.414088, epsilon));
100}100}
101101
102test "math.asinh64" {102test "math.asinh64" {
103 const epsilon = 0.000001;103 const epsilon = 0.000001;
104104
105 assert(math.approxEq(f64, asinh64(0.0), 0.0, epsilon));105 expect(math.approxEq(f64, asinh64(0.0), 0.0, epsilon));
106 assert(math.approxEq(f64, asinh64(0.2), 0.198690, epsilon));106 expect(math.approxEq(f64, asinh64(0.2), 0.198690, epsilon));
107 assert(math.approxEq(f64, asinh64(0.8923), 0.803133, epsilon));107 expect(math.approxEq(f64, asinh64(0.8923), 0.803133, epsilon));
108 assert(math.approxEq(f64, asinh64(1.5), 1.194763, epsilon));108 expect(math.approxEq(f64, asinh64(1.5), 1.194763, epsilon));
109 assert(math.approxEq(f64, asinh64(37.45), 4.316332, epsilon));109 expect(math.approxEq(f64, asinh64(37.45), 4.316332, epsilon));
110 assert(math.approxEq(f64, asinh64(89.123), 5.183196, epsilon));110 expect(math.approxEq(f64, asinh64(89.123), 5.183196, epsilon));
111 assert(math.approxEq(f64, asinh64(123123.234375), 12.414088, epsilon));111 expect(math.approxEq(f64, asinh64(123123.234375), 12.414088, epsilon));
112}112}
113113
114test "math.asinh32.special" {114test "math.asinh32.special" {
115 assert(asinh32(0.0) == 0.0);115 expect(asinh32(0.0) == 0.0);
116 assert(asinh32(-0.0) == -0.0);116 expect(asinh32(-0.0) == -0.0);
117 assert(math.isPositiveInf(asinh32(math.inf(f32))));117 expect(math.isPositiveInf(asinh32(math.inf(f32))));
118 assert(math.isNegativeInf(asinh32(-math.inf(f32))));118 expect(math.isNegativeInf(asinh32(-math.inf(f32))));
119 assert(math.isNan(asinh32(math.nan(f32))));119 expect(math.isNan(asinh32(math.nan(f32))));
120}120}
121121
122test "math.asinh64.special" {122test "math.asinh64.special" {
123 assert(asinh64(0.0) == 0.0);123 expect(asinh64(0.0) == 0.0);
124 assert(asinh64(-0.0) == -0.0);124 expect(asinh64(-0.0) == -0.0);
125 assert(math.isPositiveInf(asinh64(math.inf(f64))));125 expect(math.isPositiveInf(asinh64(math.inf(f64))));
126 assert(math.isNegativeInf(asinh64(-math.inf(f64))));126 expect(math.isNegativeInf(asinh64(-math.inf(f64))));
127 assert(math.isNan(asinh64(math.nan(f64))));127 expect(math.isNan(asinh64(math.nan(f64))));
128}128}
std/math/atan.zig+21-21
...@@ -5,7 +5,7 @@...@@ -5,7 +5,7 @@
55
6const std = @import("../index.zig");6const std = @import("../index.zig");
7const math = std.math;7const math = std.math;
8const assert = std.debug.assert;8const expect = std.testing.expect;
99
10pub fn atan(x: var) @typeOf(x) {10pub fn atan(x: var) @typeOf(x) {
11 const T = @typeOf(x);11 const T = @typeOf(x);
...@@ -206,44 +206,44 @@ fn atan64(x_: f64) f64 {...@@ -206,44 +206,44 @@ fn atan64(x_: f64) f64 {
206}206}
207207
208test "math.atan" {208test "math.atan" {
209 assert(@bitCast(u32, atan(f32(0.2))) == @bitCast(u32, atan32(0.2)));209 expect(@bitCast(u32, atan(f32(0.2))) == @bitCast(u32, atan32(0.2)));
210 assert(atan(f64(0.2)) == atan64(0.2));210 expect(atan(f64(0.2)) == atan64(0.2));
211}211}
212212
213test "math.atan32" {213test "math.atan32" {
214 const epsilon = 0.000001;214 const epsilon = 0.000001;
215215
216 assert(math.approxEq(f32, atan32(0.2), 0.197396, epsilon));216 expect(math.approxEq(f32, atan32(0.2), 0.197396, epsilon));
217 assert(math.approxEq(f32, atan32(-0.2), -0.197396, epsilon));217 expect(math.approxEq(f32, atan32(-0.2), -0.197396, epsilon));
218 assert(math.approxEq(f32, atan32(0.3434), 0.330783, epsilon));218 expect(math.approxEq(f32, atan32(0.3434), 0.330783, epsilon));
219 assert(math.approxEq(f32, atan32(0.8923), 0.728545, epsilon));219 expect(math.approxEq(f32, atan32(0.8923), 0.728545, epsilon));
220 assert(math.approxEq(f32, atan32(1.5), 0.982794, epsilon));220 expect(math.approxEq(f32, atan32(1.5), 0.982794, epsilon));
221}221}
222222
223test "math.atan64" {223test "math.atan64" {
224 const epsilon = 0.000001;224 const epsilon = 0.000001;
225225
226 assert(math.approxEq(f64, atan64(0.2), 0.197396, epsilon));226 expect(math.approxEq(f64, atan64(0.2), 0.197396, epsilon));
227 assert(math.approxEq(f64, atan64(-0.2), -0.197396, epsilon));227 expect(math.approxEq(f64, atan64(-0.2), -0.197396, epsilon));
228 assert(math.approxEq(f64, atan64(0.3434), 0.330783, epsilon));228 expect(math.approxEq(f64, atan64(0.3434), 0.330783, epsilon));
229 assert(math.approxEq(f64, atan64(0.8923), 0.728545, epsilon));229 expect(math.approxEq(f64, atan64(0.8923), 0.728545, epsilon));
230 assert(math.approxEq(f64, atan64(1.5), 0.982794, epsilon));230 expect(math.approxEq(f64, atan64(1.5), 0.982794, epsilon));
231}231}
232232
233test "math.atan32.special" {233test "math.atan32.special" {
234 const epsilon = 0.000001;234 const epsilon = 0.000001;
235235
236 assert(atan32(0.0) == 0.0);236 expect(atan32(0.0) == 0.0);
237 assert(atan32(-0.0) == -0.0);237 expect(atan32(-0.0) == -0.0);
238 assert(math.approxEq(f32, atan32(math.inf(f32)), math.pi / 2.0, epsilon));238 expect(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));239 expect(math.approxEq(f32, atan32(-math.inf(f32)), -math.pi / 2.0, epsilon));
240}240}
241241
242test "math.atan64.special" {242test "math.atan64.special" {
243 const epsilon = 0.000001;243 const epsilon = 0.000001;
244244
245 assert(atan64(0.0) == 0.0);245 expect(atan64(0.0) == 0.0);
246 assert(atan64(-0.0) == -0.0);246 expect(atan64(-0.0) == -0.0);
247 assert(math.approxEq(f64, atan64(math.inf(f64)), math.pi / 2.0, epsilon));247 expect(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));248 expect(math.approxEq(f64, atan64(-math.inf(f64)), -math.pi / 2.0, epsilon));
249}249}
std/math/atan2.zig+55-55
...@@ -20,7 +20,7 @@...@@ -20,7 +20,7 @@
2020
21const std = @import("../index.zig");21const std = @import("../index.zig");
22const math = std.math;22const math = std.math;
23const assert = std.debug.assert;23const expect = std.testing.expect;
2424
25pub fn atan2(comptime T: type, y: T, x: T) T {25pub fn atan2(comptime T: type, y: T, x: T) T {
26 return switch (T) {26 return switch (T) {
...@@ -206,78 +206,78 @@ fn atan2_64(y: f64, x: f64) f64 {...@@ -206,78 +206,78 @@ fn atan2_64(y: f64, x: f64) f64 {
206}206}
207207
208test "math.atan2" {208test "math.atan2" {
209 assert(atan2(f32, 0.2, 0.21) == atan2_32(0.2, 0.21));209 expect(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));210 expect(atan2(f64, 0.2, 0.21) == atan2_64(0.2, 0.21));
211}211}
212212
213test "math.atan2_32" {213test "math.atan2_32" {
214 const epsilon = 0.000001;214 const epsilon = 0.000001;
215215
216 assert(math.approxEq(f32, atan2_32(0.0, 0.0), 0.0, epsilon));216 expect(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));217 expect(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));218 expect(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));219 expect(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));220 expect(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));221 expect(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));222 expect(math.approxEq(f32, atan2_32(0.34, 1.243), 0.267001, epsilon));
223}223}
224224
225test "math.atan2_64" {225test "math.atan2_64" {
226 const epsilon = 0.000001;226 const epsilon = 0.000001;
227227
228 assert(math.approxEq(f64, atan2_64(0.0, 0.0), 0.0, epsilon));228 expect(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));229 expect(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));230 expect(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));231 expect(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));232 expect(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));233 expect(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));234 expect(math.approxEq(f64, atan2_64(0.34, 1.243), 0.267001, epsilon));
235}235}
236236
237test "math.atan2_32.special" {237test "math.atan2_32.special" {
238 const epsilon = 0.000001;238 const epsilon = 0.000001;
239239
240 assert(math.isNan(atan2_32(1.0, math.nan(f32))));240 expect(math.isNan(atan2_32(1.0, math.nan(f32))));
241 assert(math.isNan(atan2_32(math.nan(f32), 1.0)));241 expect(math.isNan(atan2_32(math.nan(f32), 1.0)));
242 assert(atan2_32(0.0, 5.0) == 0.0);242 expect(atan2_32(0.0, 5.0) == 0.0);
243 assert(atan2_32(-0.0, 5.0) == -0.0);243 expect(atan2_32(-0.0, 5.0) == -0.0);
244 assert(math.approxEq(f32, atan2_32(0.0, -5.0), math.pi, epsilon));244 expect(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?245 //expect(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));246 expect(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));247 expect(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));248 expect(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));249 expect(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));250 expect(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));251 expect(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));252 expect(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));253 expect(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);254 expect(atan2_32(1.0, math.inf(f32)) == 0.0);
255 assert(math.approxEq(f32, atan2_32(1.0, -math.inf(f32)), math.pi, epsilon));255 expect(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));256 expect(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));257 expect(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));258 expect(math.approxEq(f32, atan2_32(-math.inf(f32), 1.0), -math.pi / 2.0, epsilon));
259}259}
260260
261test "math.atan2_64.special" {261test "math.atan2_64.special" {
262 const epsilon = 0.000001;262 const epsilon = 0.000001;
263263
264 assert(math.isNan(atan2_64(1.0, math.nan(f64))));264 expect(math.isNan(atan2_64(1.0, math.nan(f64))));
265 assert(math.isNan(atan2_64(math.nan(f64), 1.0)));265 expect(math.isNan(atan2_64(math.nan(f64), 1.0)));
266 assert(atan2_64(0.0, 5.0) == 0.0);266 expect(atan2_64(0.0, 5.0) == 0.0);
267 assert(atan2_64(-0.0, 5.0) == -0.0);267 expect(atan2_64(-0.0, 5.0) == -0.0);
268 assert(math.approxEq(f64, atan2_64(0.0, -5.0), math.pi, epsilon));268 expect(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?269 //expect(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));270 expect(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));271 expect(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));272 expect(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));273 expect(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));274 expect(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));275 expect(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));276 expect(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));277 expect(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);278 expect(atan2_64(1.0, math.inf(f64)) == 0.0);
279 assert(math.approxEq(f64, atan2_64(1.0, -math.inf(f64)), math.pi, epsilon));279 expect(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));280 expect(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));281 expect(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));282 expect(math.approxEq(f64, atan2_64(-math.inf(f64), 1.0), -math.pi / 2.0, epsilon));
283}283}
std/math/atanh.zig+19-19
...@@ -6,7 +6,7 @@...@@ -6,7 +6,7 @@
66
7const std = @import("../index.zig");7const std = @import("../index.zig");
8const math = std.math;8const math = std.math;
9const assert = std.debug.assert;9const expect = std.testing.expect;
10const maxInt = std.math.maxInt;10const maxInt = std.math.maxInt;
1111
12pub fn atanh(x: var) @typeOf(x) {12pub fn atanh(x: var) @typeOf(x) {
...@@ -78,38 +78,38 @@ fn atanh_64(x: f64) f64 {...@@ -78,38 +78,38 @@ fn atanh_64(x: f64) f64 {
78}78}
7979
80test "math.atanh" {80test "math.atanh" {
81 assert(atanh(f32(0.0)) == atanh_32(0.0));81 expect(atanh(f32(0.0)) == atanh_32(0.0));
82 assert(atanh(f64(0.0)) == atanh_64(0.0));82 expect(atanh(f64(0.0)) == atanh_64(0.0));
83}83}
8484
85test "math.atanh_32" {85test "math.atanh_32" {
86 const epsilon = 0.000001;86 const epsilon = 0.000001;
8787
88 assert(math.approxEq(f32, atanh_32(0.0), 0.0, epsilon));88 expect(math.approxEq(f32, atanh_32(0.0), 0.0, epsilon));
89 assert(math.approxEq(f32, atanh_32(0.2), 0.202733, epsilon));89 expect(math.approxEq(f32, atanh_32(0.2), 0.202733, epsilon));
90 assert(math.approxEq(f32, atanh_32(0.8923), 1.433099, epsilon));90 expect(math.approxEq(f32, atanh_32(0.8923), 1.433099, epsilon));
91}91}
9292
93test "math.atanh_64" {93test "math.atanh_64" {
94 const epsilon = 0.000001;94 const epsilon = 0.000001;
9595
96 assert(math.approxEq(f64, atanh_64(0.0), 0.0, epsilon));96 expect(math.approxEq(f64, atanh_64(0.0), 0.0, epsilon));
97 assert(math.approxEq(f64, atanh_64(0.2), 0.202733, epsilon));97 expect(math.approxEq(f64, atanh_64(0.2), 0.202733, epsilon));
98 assert(math.approxEq(f64, atanh_64(0.8923), 1.433099, epsilon));98 expect(math.approxEq(f64, atanh_64(0.8923), 1.433099, epsilon));
99}99}
100100
101test "math.atanh32.special" {101test "math.atanh32.special" {
102 assert(math.isPositiveInf(atanh_32(1)));102 expect(math.isPositiveInf(atanh_32(1)));
103 assert(math.isNegativeInf(atanh_32(-1)));103 expect(math.isNegativeInf(atanh_32(-1)));
104 assert(math.isSignalNan(atanh_32(1.5)));104 expect(math.isSignalNan(atanh_32(1.5)));
105 assert(math.isSignalNan(atanh_32(-1.5)));105 expect(math.isSignalNan(atanh_32(-1.5)));
106 assert(math.isNan(atanh_32(math.nan(f32))));106 expect(math.isNan(atanh_32(math.nan(f32))));
107}107}
108108
109test "math.atanh64.special" {109test "math.atanh64.special" {
110 assert(math.isPositiveInf(atanh_64(1)));110 expect(math.isPositiveInf(atanh_64(1)));
111 assert(math.isNegativeInf(atanh_64(-1)));111 expect(math.isNegativeInf(atanh_64(-1)));
112 assert(math.isSignalNan(atanh_64(1.5)));112 expect(math.isSignalNan(atanh_64(1.5)));
113 assert(math.isSignalNan(atanh_64(-1.5)));113 expect(math.isSignalNan(atanh_64(-1.5)));
114 assert(math.isNan(atanh_64(math.nan(f64))));114 expect(math.isNan(atanh_64(math.nan(f64))));
115}115}
std/math/big/int.zig+180-187
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const std = @import("../../index.zig");1const std = @import("../../index.zig");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const debug = std.debug;3const debug = std.debug;
4const testing = std.testing;
4const math = std.math;5const math = std.math;
5const mem = std.mem;6const mem = std.mem;
6const Allocator = mem.Allocator;7const Allocator = mem.Allocator;
...@@ -1086,44 +1087,40 @@ test "big.int comptime_int set" {...@@ -1086,44 +1087,40 @@ test "big.int comptime_int set" {
1086 const result = Limb(s & maxInt(Limb));1087 const result = Limb(s & maxInt(Limb));
1087 s >>= Limb.bit_count / 2;1088 s >>= Limb.bit_count / 2;
1088 s >>= Limb.bit_count / 2;1089 s >>= Limb.bit_count / 2;
1089 debug.assert(a.limbs[i] == result);1090 testing.expect(a.limbs[i] == result);
1090 }1091 }
1091}1092}
10921093
1093test "big.int comptime_int set negative" {1094test "big.int comptime_int set negative" {
1094 var a = try Int.initSet(al, -10);1095 var a = try Int.initSet(al, -10);
10951096
1096 debug.assert(a.limbs[0] == 10);1097 testing.expect(a.limbs[0] == 10);
1097 debug.assert(a.positive == false);1098 testing.expect(a.positive == false);
1098}1099}
10991100
1100test "big.int int set unaligned small" {1101test "big.int int set unaligned small" {
1101 var a = try Int.initSet(al, u7(45));1102 var a = try Int.initSet(al, u7(45));
11021103
1103 debug.assert(a.limbs[0] == 45);1104 testing.expect(a.limbs[0] == 45);
1104 debug.assert(a.positive == true);1105 testing.expect(a.positive == true);
1105}1106}
11061107
1107test "big.int comptime_int to" {1108test "big.int comptime_int to" {
1108 const a = try Int.initSet(al, 0xefffffff00000001eeeeeeefaaaaaaab);1109 const a = try Int.initSet(al, 0xefffffff00000001eeeeeeefaaaaaaab);
11091110
1110 debug.assert((try a.to(u128)) == 0xefffffff00000001eeeeeeefaaaaaaab);1111 testing.expect((try a.to(u128)) == 0xefffffff00000001eeeeeeefaaaaaaab);
1111}1112}
11121113
1113test "big.int sub-limb to" {1114test "big.int sub-limb to" {
1114 const a = try Int.initSet(al, 10);1115 const a = try Int.initSet(al, 10);
11151116
1116 debug.assert((try a.to(u8)) == 10);1117 testing.expect((try a.to(u8)) == 10);
1117}1118}
11181119
1119test "big.int to target too small error" {1120test "big.int to target too small error" {
1120 const a = try Int.initSet(al, 0xffffffff);1121 const a = try Int.initSet(al, 0xffffffff);
11211122
1122 if (a.to(u8)) |_| {1123 testing.expectError(error.TargetTooSmall, a.to(u8));
1123 unreachable;
1124 } else |err| {
1125 debug.assert(err == error.TargetTooSmall);
1126 }
1127}1124}
11281125
1129test "big.int norm1" {1126test "big.int norm1" {
...@@ -1135,22 +1132,22 @@ test "big.int norm1" {...@@ -1135,22 +1132,22 @@ test "big.int norm1" {
1135 a.limbs[2] = 3;1132 a.limbs[2] = 3;
1136 a.limbs[3] = 0;1133 a.limbs[3] = 0;
1137 a.norm1(4);1134 a.norm1(4);
1138 debug.assert(a.len == 3);1135 testing.expect(a.len == 3);
11391136
1140 a.limbs[0] = 1;1137 a.limbs[0] = 1;
1141 a.limbs[1] = 2;1138 a.limbs[1] = 2;
1142 a.limbs[2] = 3;1139 a.limbs[2] = 3;
1143 a.norm1(3);1140 a.norm1(3);
1144 debug.assert(a.len == 3);1141 testing.expect(a.len == 3);
11451142
1146 a.limbs[0] = 0;1143 a.limbs[0] = 0;
1147 a.limbs[1] = 0;1144 a.limbs[1] = 0;
1148 a.norm1(2);1145 a.norm1(2);
1149 debug.assert(a.len == 1);1146 testing.expect(a.len == 1);
11501147
1151 a.limbs[0] = 0;1148 a.limbs[0] = 0;
1152 a.norm1(1);1149 a.norm1(1);
1153 debug.assert(a.len == 1);1150 testing.expect(a.len == 1);
1154}1151}
11551152
1156test "big.int normN" {1153test "big.int normN" {
...@@ -1162,144 +1159,144 @@ test "big.int normN" {...@@ -1162,144 +1159,144 @@ test "big.int normN" {
1162 a.limbs[2] = 0;1159 a.limbs[2] = 0;
1163 a.limbs[3] = 0;1160 a.limbs[3] = 0;
1164 a.normN(4);1161 a.normN(4);
1165 debug.assert(a.len == 2);1162 testing.expect(a.len == 2);
11661163
1167 a.limbs[0] = 1;1164 a.limbs[0] = 1;
1168 a.limbs[1] = 2;1165 a.limbs[1] = 2;
1169 a.limbs[2] = 3;1166 a.limbs[2] = 3;
1170 a.normN(3);1167 a.normN(3);
1171 debug.assert(a.len == 3);1168 testing.expect(a.len == 3);
11721169
1173 a.limbs[0] = 0;1170 a.limbs[0] = 0;
1174 a.limbs[1] = 0;1171 a.limbs[1] = 0;
1175 a.limbs[2] = 0;1172 a.limbs[2] = 0;
1176 a.limbs[3] = 0;1173 a.limbs[3] = 0;
1177 a.normN(4);1174 a.normN(4);
1178 debug.assert(a.len == 1);1175 testing.expect(a.len == 1);
11791176
1180 a.limbs[0] = 0;1177 a.limbs[0] = 0;
1181 a.normN(1);1178 a.normN(1);
1182 debug.assert(a.len == 1);1179 testing.expect(a.len == 1);
1183}1180}
11841181
1185test "big.int parity" {1182test "big.int parity" {
1186 var a = try Int.init(al);1183 var a = try Int.init(al);
1187 try a.set(0);1184 try a.set(0);
1188 debug.assert(a.isEven());1185 testing.expect(a.isEven());
1189 debug.assert(!a.isOdd());1186 testing.expect(!a.isOdd());
11901187
1191 try a.set(7);1188 try a.set(7);
1192 debug.assert(!a.isEven());1189 testing.expect(!a.isEven());
1193 debug.assert(a.isOdd());1190 testing.expect(a.isOdd());
1194}1191}
11951192
1196test "big.int bitcount + sizeInBase" {1193test "big.int bitcount + sizeInBase" {
1197 var a = try Int.init(al);1194 var a = try Int.init(al);
11981195
1199 try a.set(0b100);1196 try a.set(0b100);
1200 debug.assert(a.bitCountAbs() == 3);1197 testing.expect(a.bitCountAbs() == 3);
1201 debug.assert(a.sizeInBase(2) >= 3);1198 testing.expect(a.sizeInBase(2) >= 3);
1202 debug.assert(a.sizeInBase(10) >= 1);1199 testing.expect(a.sizeInBase(10) >= 1);
12031200
1204 a.negate();1201 a.negate();
1205 debug.assert(a.bitCountAbs() == 3);1202 testing.expect(a.bitCountAbs() == 3);
1206 debug.assert(a.sizeInBase(2) >= 4);1203 testing.expect(a.sizeInBase(2) >= 4);
1207 debug.assert(a.sizeInBase(10) >= 2);1204 testing.expect(a.sizeInBase(10) >= 2);
12081205
1209 try a.set(0xffffffff);1206 try a.set(0xffffffff);
1210 debug.assert(a.bitCountAbs() == 32);1207 testing.expect(a.bitCountAbs() == 32);
1211 debug.assert(a.sizeInBase(2) >= 32);1208 testing.expect(a.sizeInBase(2) >= 32);
1212 debug.assert(a.sizeInBase(10) >= 10);1209 testing.expect(a.sizeInBase(10) >= 10);
12131210
1214 try a.shiftLeft(a, 5000);1211 try a.shiftLeft(a, 5000);
1215 debug.assert(a.bitCountAbs() == 5032);1212 testing.expect(a.bitCountAbs() == 5032);
1216 debug.assert(a.sizeInBase(2) >= 5032);1213 testing.expect(a.sizeInBase(2) >= 5032);
1217 a.positive = false;1214 a.positive = false;
12181215
1219 debug.assert(a.bitCountAbs() == 5032);1216 testing.expect(a.bitCountAbs() == 5032);
1220 debug.assert(a.sizeInBase(2) >= 5033);1217 testing.expect(a.sizeInBase(2) >= 5033);
1221}1218}
12221219
1223test "big.int bitcount/to" {1220test "big.int bitcount/to" {
1224 var a = try Int.init(al);1221 var a = try Int.init(al);
12251222
1226 try a.set(0);1223 try a.set(0);
1227 debug.assert(a.bitCountTwosComp() == 0);1224 testing.expect(a.bitCountTwosComp() == 0);
12281225
1229 // TODO: stack smashing1226 // TODO: stack smashing
1230 // debug.assert((try a.to(u0)) == 0);1227 // testing.expect((try a.to(u0)) == 0);
1231 // TODO: sigsegv1228 // TODO: sigsegv
1232 // debug.assert((try a.to(i0)) == 0);1229 // testing.expect((try a.to(i0)) == 0);
12331230
1234 try a.set(-1);1231 try a.set(-1);
1235 debug.assert(a.bitCountTwosComp() == 1);1232 testing.expect(a.bitCountTwosComp() == 1);
1236 debug.assert((try a.to(i1)) == -1);1233 testing.expect((try a.to(i1)) == -1);
12371234
1238 try a.set(-8);1235 try a.set(-8);
1239 debug.assert(a.bitCountTwosComp() == 4);1236 testing.expect(a.bitCountTwosComp() == 4);
1240 debug.assert((try a.to(i4)) == -8);1237 testing.expect((try a.to(i4)) == -8);
12411238
1242 try a.set(127);1239 try a.set(127);
1243 debug.assert(a.bitCountTwosComp() == 7);1240 testing.expect(a.bitCountTwosComp() == 7);
1244 debug.assert((try a.to(u7)) == 127);1241 testing.expect((try a.to(u7)) == 127);
12451242
1246 try a.set(-128);1243 try a.set(-128);
1247 debug.assert(a.bitCountTwosComp() == 8);1244 testing.expect(a.bitCountTwosComp() == 8);
1248 debug.assert((try a.to(i8)) == -128);1245 testing.expect((try a.to(i8)) == -128);
12491246
1250 try a.set(-129);1247 try a.set(-129);
1251 debug.assert(a.bitCountTwosComp() == 9);1248 testing.expect(a.bitCountTwosComp() == 9);
1252 debug.assert((try a.to(i9)) == -129);1249 testing.expect((try a.to(i9)) == -129);
1253}1250}
12541251
1255test "big.int fits" {1252test "big.int fits" {
1256 var a = try Int.init(al);1253 var a = try Int.init(al);
12571254
1258 try a.set(0);1255 try a.set(0);
1259 debug.assert(a.fits(u0));1256 testing.expect(a.fits(u0));
1260 debug.assert(a.fits(i0));1257 testing.expect(a.fits(i0));
12611258
1262 try a.set(255);1259 try a.set(255);
1263 debug.assert(!a.fits(u0));1260 testing.expect(!a.fits(u0));
1264 debug.assert(!a.fits(u1));1261 testing.expect(!a.fits(u1));
1265 debug.assert(!a.fits(i8));1262 testing.expect(!a.fits(i8));
1266 debug.assert(a.fits(u8));1263 testing.expect(a.fits(u8));
1267 debug.assert(a.fits(u9));1264 testing.expect(a.fits(u9));
1268 debug.assert(a.fits(i9));1265 testing.expect(a.fits(i9));
12691266
1270 try a.set(-128);1267 try a.set(-128);
1271 debug.assert(!a.fits(i7));1268 testing.expect(!a.fits(i7));
1272 debug.assert(a.fits(i8));1269 testing.expect(a.fits(i8));
1273 debug.assert(a.fits(i9));1270 testing.expect(a.fits(i9));
1274 debug.assert(!a.fits(u9));1271 testing.expect(!a.fits(u9));
12751272
1276 try a.set(0x1ffffffffeeeeeeee);1273 try a.set(0x1ffffffffeeeeeeee);
1277 debug.assert(!a.fits(u32));1274 testing.expect(!a.fits(u32));
1278 debug.assert(!a.fits(u64));1275 testing.expect(!a.fits(u64));
1279 debug.assert(a.fits(u65));1276 testing.expect(a.fits(u65));
1280}1277}
12811278
1282test "big.int string set" {1279test "big.int string set" {
1283 var a = try Int.init(al);1280 var a = try Int.init(al);
1284 try a.setString(10, "120317241209124781241290847124");1281 try a.setString(10, "120317241209124781241290847124");
12851282
1286 debug.assert((try a.to(u128)) == 120317241209124781241290847124);1283 testing.expect((try a.to(u128)) == 120317241209124781241290847124);
1287}1284}
12881285
1289test "big.int string negative" {1286test "big.int string negative" {
1290 var a = try Int.init(al);1287 var a = try Int.init(al);
1291 try a.setString(10, "-1023");1288 try a.setString(10, "-1023");
1292 debug.assert((try a.to(i32)) == -1023);1289 testing.expect((try a.to(i32)) == -1023);
1293}1290}
12941291
1295test "big.int string set bad char error" {1292test "big.int string set bad char error" {
1296 var a = try Int.init(al);1293 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"));
1298}1295}
12991296
1300test "big.int string set bad base error" {1297test "big.int string set bad base error" {
1301 var a = try Int.init(al);1298 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"));
1303}1300}
13041301
1305test "big.int string to" {1302test "big.int string to" {
...@@ -1308,17 +1305,13 @@ test "big.int string to" {...@@ -1308,17 +1305,13 @@ test "big.int string to" {
1308 const as = try a.toString(al, 10);1305 const as = try a.toString(al, 10);
1309 const es = "120317241209124781241290847124";1306 const es = "120317241209124781241290847124";
13101307
1311 debug.assert(mem.eql(u8, as, es));1308 testing.expect(mem.eql(u8, as, es));
1312}1309}
13131310
1314test "big.int string to base base error" {1311test "big.int string to base base error" {
1315 const a = try Int.initSet(al, 0xffffffff);1312 const a = try Int.initSet(al, 0xffffffff);
13161313
1317 if (a.toString(al, 45)) |_| {1314 testing.expectError(error.InvalidBase, a.toString(al, 45));
1318 unreachable;
1319 } else |err| {
1320 debug.assert(err == error.InvalidBase);
1321 }
1322}1315}
13231316
1324test "big.int string to base 2" {1317test "big.int string to base 2" {
...@@ -1327,7 +1320,7 @@ test "big.int string to base 2" {...@@ -1327,7 +1320,7 @@ test "big.int string to base 2" {
1327 const as = try a.toString(al, 2);1320 const as = try a.toString(al, 2);
1328 const es = "-1011";1321 const es = "-1011";
13291322
1330 debug.assert(mem.eql(u8, as, es));1323 testing.expect(mem.eql(u8, as, es));
1331}1324}
13321325
1333test "big.int string to base 16" {1326test "big.int string to base 16" {
...@@ -1336,7 +1329,7 @@ test "big.int string to base 16" {...@@ -1336,7 +1329,7 @@ test "big.int string to base 16" {
1336 const as = try a.toString(al, 16);1329 const as = try a.toString(al, 16);
1337 const es = "efffffff00000001eeeeeeefaaaaaaab";1330 const es = "efffffff00000001eeeeeeefaaaaaaab";
13381331
1339 debug.assert(mem.eql(u8, as, es));1332 testing.expect(mem.eql(u8, as, es));
1340}1333}
13411334
1342test "big.int neg string to" {1335test "big.int neg string to" {
...@@ -1345,7 +1338,7 @@ test "big.int neg string to" {...@@ -1345,7 +1338,7 @@ test "big.int neg string to" {
1345 const as = try a.toString(al, 10);1338 const as = try a.toString(al, 10);
1346 const es = "-123907434";1339 const es = "-123907434";
13471340
1348 debug.assert(mem.eql(u8, as, es));1341 testing.expect(mem.eql(u8, as, es));
1349}1342}
13501343
1351test "big.int zero string to" {1344test "big.int zero string to" {
...@@ -1354,98 +1347,98 @@ test "big.int zero string to" {...@@ -1354,98 +1347,98 @@ test "big.int zero string to" {
1354 const as = try a.toString(al, 10);1347 const as = try a.toString(al, 10);
1355 const es = "0";1348 const es = "0";
13561349
1357 debug.assert(mem.eql(u8, as, es));1350 testing.expect(mem.eql(u8, as, es));
1358}1351}
13591352
1360test "big.int clone" {1353test "big.int clone" {
1361 var a = try Int.initSet(al, 1234);1354 var a = try Int.initSet(al, 1234);
1362 const b = try a.clone();1355 const b = try a.clone();
13631356
1364 debug.assert((try a.to(u32)) == 1234);1357 testing.expect((try a.to(u32)) == 1234);
1365 debug.assert((try b.to(u32)) == 1234);1358 testing.expect((try b.to(u32)) == 1234);
13661359
1367 try a.set(77);1360 try a.set(77);
1368 debug.assert((try a.to(u32)) == 77);1361 testing.expect((try a.to(u32)) == 77);
1369 debug.assert((try b.to(u32)) == 1234);1362 testing.expect((try b.to(u32)) == 1234);
1370}1363}
13711364
1372test "big.int swap" {1365test "big.int swap" {
1373 var a = try Int.initSet(al, 1234);1366 var a = try Int.initSet(al, 1234);
1374 var b = try Int.initSet(al, 5678);1367 var b = try Int.initSet(al, 5678);
13751368
1376 debug.assert((try a.to(u32)) == 1234);1369 testing.expect((try a.to(u32)) == 1234);
1377 debug.assert((try b.to(u32)) == 5678);1370 testing.expect((try b.to(u32)) == 5678);
13781371
1379 a.swap(&b);1372 a.swap(&b);
13801373
1381 debug.assert((try a.to(u32)) == 5678);1374 testing.expect((try a.to(u32)) == 5678);
1382 debug.assert((try b.to(u32)) == 1234);1375 testing.expect((try b.to(u32)) == 1234);
1383}1376}
13841377
1385test "big.int to negative" {1378test "big.int to negative" {
1386 var a = try Int.initSet(al, -10);1379 var a = try Int.initSet(al, -10);
13871380
1388 debug.assert((try a.to(i32)) == -10);1381 testing.expect((try a.to(i32)) == -10);
1389}1382}
13901383
1391test "big.int compare" {1384test "big.int compare" {
1392 var a = try Int.initSet(al, -11);1385 var a = try Int.initSet(al, -11);
1393 var b = try Int.initSet(al, 10);1386 var b = try Int.initSet(al, 10);
13941387
1395 debug.assert(a.cmpAbs(b) == 1);1388 testing.expect(a.cmpAbs(b) == 1);
1396 debug.assert(a.cmp(b) == -1);1389 testing.expect(a.cmp(b) == -1);
1397}1390}
13981391
1399test "big.int compare similar" {1392test "big.int compare similar" {
1400 var a = try Int.initSet(al, 0xffffffffeeeeeeeeffffffffeeeeeeee);1393 var a = try Int.initSet(al, 0xffffffffeeeeeeeeffffffffeeeeeeee);
1401 var b = try Int.initSet(al, 0xffffffffeeeeeeeeffffffffeeeeeeef);1394 var b = try Int.initSet(al, 0xffffffffeeeeeeeeffffffffeeeeeeef);
14021395
1403 debug.assert(a.cmpAbs(b) == -1);1396 testing.expect(a.cmpAbs(b) == -1);
1404 debug.assert(b.cmpAbs(a) == 1);1397 testing.expect(b.cmpAbs(a) == 1);
1405}1398}
14061399
1407test "big.int compare different limb size" {1400test "big.int compare different limb size" {
1408 var a = try Int.initSet(al, maxInt(Limb) + 1);1401 var a = try Int.initSet(al, maxInt(Limb) + 1);
1409 var b = try Int.initSet(al, 1);1402 var b = try Int.initSet(al, 1);
14101403
1411 debug.assert(a.cmpAbs(b) == 1);1404 testing.expect(a.cmpAbs(b) == 1);
1412 debug.assert(b.cmpAbs(a) == -1);1405 testing.expect(b.cmpAbs(a) == -1);
1413}1406}
14141407
1415test "big.int compare multi-limb" {1408test "big.int compare multi-limb" {
1416 var a = try Int.initSet(al, -0x7777777799999999ffffeeeeffffeeeeffffeeeef);1409 var a = try Int.initSet(al, -0x7777777799999999ffffeeeeffffeeeeffffeeeef);
1417 var b = try Int.initSet(al, 0x7777777799999999ffffeeeeffffeeeeffffeeeee);1410 var b = try Int.initSet(al, 0x7777777799999999ffffeeeeffffeeeeffffeeeee);
14181411
1419 debug.assert(a.cmpAbs(b) == 1);1412 testing.expect(a.cmpAbs(b) == 1);
1420 debug.assert(a.cmp(b) == -1);1413 testing.expect(a.cmp(b) == -1);
1421}1414}
14221415
1423test "big.int equality" {1416test "big.int equality" {
1424 var a = try Int.initSet(al, 0xffffffff1);1417 var a = try Int.initSet(al, 0xffffffff1);
1425 var b = try Int.initSet(al, -0xffffffff1);1418 var b = try Int.initSet(al, -0xffffffff1);
14261419
1427 debug.assert(a.eqAbs(b));1420 testing.expect(a.eqAbs(b));
1428 debug.assert(!a.eq(b));1421 testing.expect(!a.eq(b));
1429}1422}
14301423
1431test "big.int abs" {1424test "big.int abs" {
1432 var a = try Int.initSet(al, -5);1425 var a = try Int.initSet(al, -5);
14331426
1434 a.abs();1427 a.abs();
1435 debug.assert((try a.to(u32)) == 5);1428 testing.expect((try a.to(u32)) == 5);
14361429
1437 a.abs();1430 a.abs();
1438 debug.assert((try a.to(u32)) == 5);1431 testing.expect((try a.to(u32)) == 5);
1439}1432}
14401433
1441test "big.int negate" {1434test "big.int negate" {
1442 var a = try Int.initSet(al, 5);1435 var a = try Int.initSet(al, 5);
14431436
1444 a.negate();1437 a.negate();
1445 debug.assert((try a.to(i32)) == -5);1438 testing.expect((try a.to(i32)) == -5);
14461439
1447 a.negate();1440 a.negate();
1448 debug.assert((try a.to(i32)) == 5);1441 testing.expect((try a.to(i32)) == 5);
1449}1442}
14501443
1451test "big.int add single-single" {1444test "big.int add single-single" {
...@@ -1455,7 +1448,7 @@ test "big.int add single-single" {...@@ -1455,7 +1448,7 @@ test "big.int add single-single" {
1455 var c = try Int.init(al);1448 var c = try Int.init(al);
1456 try c.add(a, b);1449 try c.add(a, b);
14571450
1458 debug.assert((try c.to(u32)) == 55);1451 testing.expect((try c.to(u32)) == 55);
1459}1452}
14601453
1461test "big.int add multi-single" {1454test "big.int add multi-single" {
...@@ -1465,10 +1458,10 @@ test "big.int add multi-single" {...@@ -1465,10 +1458,10 @@ test "big.int add multi-single" {
1465 var c = try Int.init(al);1458 var c = try Int.init(al);
14661459
1467 try c.add(a, b);1460 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
1470 try c.add(b, a);1463 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);
1472}1465}
14731466
1474test "big.int add multi-multi" {1467test "big.int add multi-multi" {
...@@ -1480,7 +1473,7 @@ test "big.int add multi-multi" {...@@ -1480,7 +1473,7 @@ test "big.int add multi-multi" {
1480 var c = try Int.init(al);1473 var c = try Int.init(al);
1481 try c.add(a, b);1474 try c.add(a, b);
14821475
1483 debug.assert((try c.to(u128)) == op1 + op2);1476 testing.expect((try c.to(u128)) == op1 + op2);
1484}1477}
14851478
1486test "big.int add zero-zero" {1479test "big.int add zero-zero" {
...@@ -1490,7 +1483,7 @@ test "big.int add zero-zero" {...@@ -1490,7 +1483,7 @@ test "big.int add zero-zero" {
1490 var c = try Int.init(al);1483 var c = try Int.init(al);
1491 try c.add(a, b);1484 try c.add(a, b);
14921485
1493 debug.assert((try c.to(u32)) == 0);1486 testing.expect((try c.to(u32)) == 0);
1494}1487}
14951488
1496test "big.int add alias multi-limb nonzero-zero" {1489test "big.int add alias multi-limb nonzero-zero" {
...@@ -1500,7 +1493,7 @@ test "big.int add alias multi-limb nonzero-zero" {...@@ -1500,7 +1493,7 @@ test "big.int add alias multi-limb nonzero-zero" {
15001493
1501 try a.add(a, b);1494 try a.add(a, b);
15021495
1503 debug.assert((try a.to(u128)) == op1);1496 testing.expect((try a.to(u128)) == op1);
1504}1497}
15051498
1506test "big.int add sign" {1499test "big.int add sign" {
...@@ -1512,16 +1505,16 @@ test "big.int add sign" {...@@ -1512,16 +1505,16 @@ test "big.int add sign" {
1512 const neg_two = try Int.initSet(al, -2);1505 const neg_two = try Int.initSet(al, -2);
15131506
1514 try a.add(one, two);1507 try a.add(one, two);
1515 debug.assert((try a.to(i32)) == 3);1508 testing.expect((try a.to(i32)) == 3);
15161509
1517 try a.add(neg_one, two);1510 try a.add(neg_one, two);
1518 debug.assert((try a.to(i32)) == 1);1511 testing.expect((try a.to(i32)) == 1);
15191512
1520 try a.add(one, neg_two);1513 try a.add(one, neg_two);
1521 debug.assert((try a.to(i32)) == -1);1514 testing.expect((try a.to(i32)) == -1);
15221515
1523 try a.add(neg_one, neg_two);1516 try a.add(neg_one, neg_two);
1524 debug.assert((try a.to(i32)) == -3);1517 testing.expect((try a.to(i32)) == -3);
1525}1518}
15261519
1527test "big.int sub single-single" {1520test "big.int sub single-single" {
...@@ -1531,7 +1524,7 @@ test "big.int sub single-single" {...@@ -1531,7 +1524,7 @@ test "big.int sub single-single" {
1531 var c = try Int.init(al);1524 var c = try Int.init(al);
1532 try c.sub(a, b);1525 try c.sub(a, b);
15331526
1534 debug.assert((try c.to(u32)) == 45);1527 testing.expect((try c.to(u32)) == 45);
1535}1528}
15361529
1537test "big.int sub multi-single" {1530test "big.int sub multi-single" {
...@@ -1541,7 +1534,7 @@ test "big.int sub multi-single" {...@@ -1541,7 +1534,7 @@ test "big.int sub multi-single" {
1541 var c = try Int.init(al);1534 var c = try Int.init(al);
1542 try c.sub(a, b);1535 try c.sub(a, b);
15431536
1544 debug.assert((try c.to(Limb)) == maxInt(Limb));1537 testing.expect((try c.to(Limb)) == maxInt(Limb));
1545}1538}
15461539
1547test "big.int sub multi-multi" {1540test "big.int sub multi-multi" {
...@@ -1554,7 +1547,7 @@ test "big.int sub multi-multi" {...@@ -1554,7 +1547,7 @@ test "big.int sub multi-multi" {
1554 var c = try Int.init(al);1547 var c = try Int.init(al);
1555 try c.sub(a, b);1548 try c.sub(a, b);
15561549
1557 debug.assert((try c.to(u128)) == op1 - op2);1550 testing.expect((try c.to(u128)) == op1 - op2);
1558}1551}
15591552
1560test "big.int sub equal" {1553test "big.int sub equal" {
...@@ -1564,7 +1557,7 @@ test "big.int sub equal" {...@@ -1564,7 +1557,7 @@ test "big.int sub equal" {
1564 var c = try Int.init(al);1557 var c = try Int.init(al);
1565 try c.sub(a, b);1558 try c.sub(a, b);
15661559
1567 debug.assert((try c.to(u32)) == 0);1560 testing.expect((try c.to(u32)) == 0);
1568}1561}
15691562
1570test "big.int sub sign" {1563test "big.int sub sign" {
...@@ -1576,19 +1569,19 @@ test "big.int sub sign" {...@@ -1576,19 +1569,19 @@ test "big.int sub sign" {
1576 const neg_two = try Int.initSet(al, -2);1569 const neg_two = try Int.initSet(al, -2);
15771570
1578 try a.sub(one, two);1571 try a.sub(one, two);
1579 debug.assert((try a.to(i32)) == -1);1572 testing.expect((try a.to(i32)) == -1);
15801573
1581 try a.sub(neg_one, two);1574 try a.sub(neg_one, two);
1582 debug.assert((try a.to(i32)) == -3);1575 testing.expect((try a.to(i32)) == -3);
15831576
1584 try a.sub(one, neg_two);1577 try a.sub(one, neg_two);
1585 debug.assert((try a.to(i32)) == 3);1578 testing.expect((try a.to(i32)) == 3);
15861579
1587 try a.sub(neg_one, neg_two);1580 try a.sub(neg_one, neg_two);
1588 debug.assert((try a.to(i32)) == 1);1581 testing.expect((try a.to(i32)) == 1);
15891582
1590 try a.sub(neg_two, neg_one);1583 try a.sub(neg_two, neg_one);
1591 debug.assert((try a.to(i32)) == -1);1584 testing.expect((try a.to(i32)) == -1);
1592}1585}
15931586
1594test "big.int mul single-single" {1587test "big.int mul single-single" {
...@@ -1598,7 +1591,7 @@ test "big.int mul single-single" {...@@ -1598,7 +1591,7 @@ test "big.int mul single-single" {
1598 var c = try Int.init(al);1591 var c = try Int.init(al);
1599 try c.mul(a, b);1592 try c.mul(a, b);
16001593
1601 debug.assert((try c.to(u64)) == 250);1594 testing.expect((try c.to(u64)) == 250);
1602}1595}
16031596
1604test "big.int mul multi-single" {1597test "big.int mul multi-single" {
...@@ -1608,7 +1601,7 @@ test "big.int mul multi-single" {...@@ -1608,7 +1601,7 @@ test "big.int mul multi-single" {
1608 var c = try Int.init(al);1601 var c = try Int.init(al);
1609 try c.mul(a, b);1602 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));
1612}1605}
16131606
1614test "big.int mul multi-multi" {1607test "big.int mul multi-multi" {
...@@ -1620,7 +1613,7 @@ test "big.int mul multi-multi" {...@@ -1620,7 +1613,7 @@ test "big.int mul multi-multi" {
1620 var c = try Int.init(al);1613 var c = try Int.init(al);
1621 try c.mul(a, b);1614 try c.mul(a, b);
16221615
1623 debug.assert((try c.to(u256)) == op1 * op2);1616 testing.expect((try c.to(u256)) == op1 * op2);
1624}1617}
16251618
1626test "big.int mul alias r with a" {1619test "big.int mul alias r with a" {
...@@ -1629,7 +1622,7 @@ test "big.int mul alias r with a" {...@@ -1629,7 +1622,7 @@ test "big.int mul alias r with a" {
16291622
1630 try a.mul(a, b);1623 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));
1633}1626}
16341627
1635test "big.int mul alias r with b" {1628test "big.int mul alias r with b" {
...@@ -1638,7 +1631,7 @@ test "big.int mul alias r with b" {...@@ -1638,7 +1631,7 @@ test "big.int mul alias r with b" {
16381631
1639 try a.mul(b, a);1632 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));
1642}1635}
16431636
1644test "big.int mul alias r with a and b" {1637test "big.int mul alias r with a and b" {
...@@ -1646,7 +1639,7 @@ test "big.int mul alias r with a and b" {...@@ -1646,7 +1639,7 @@ test "big.int mul alias r with a and b" {
16461639
1647 try a.mul(a, a);1640 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));
1650}1643}
16511644
1652test "big.int mul a*0" {1645test "big.int mul a*0" {
...@@ -1656,7 +1649,7 @@ test "big.int mul a*0" {...@@ -1656,7 +1649,7 @@ test "big.int mul a*0" {
1656 var c = try Int.init(al);1649 var c = try Int.init(al);
1657 try c.mul(a, b);1650 try c.mul(a, b);
16581651
1659 debug.assert((try c.to(u32)) == 0);1652 testing.expect((try c.to(u32)) == 0);
1660}1653}
16611654
1662test "big.int mul 0*0" {1655test "big.int mul 0*0" {
...@@ -1666,7 +1659,7 @@ test "big.int mul 0*0" {...@@ -1666,7 +1659,7 @@ test "big.int mul 0*0" {
1666 var c = try Int.init(al);1659 var c = try Int.init(al);
1667 try c.mul(a, b);1660 try c.mul(a, b);
16681661
1669 debug.assert((try c.to(u32)) == 0);1662 testing.expect((try c.to(u32)) == 0);
1670}1663}
16711664
1672test "big.int div single-single no rem" {1665test "big.int div single-single no rem" {
...@@ -1677,8 +1670,8 @@ test "big.int div single-single no rem" {...@@ -1677,8 +1670,8 @@ test "big.int div single-single no rem" {
1677 var r = try Int.init(al);1670 var r = try Int.init(al);
1678 try Int.divTrunc(&q, &r, a, b);1671 try Int.divTrunc(&q, &r, a, b);
16791672
1680 debug.assert((try q.to(u32)) == 10);1673 testing.expect((try q.to(u32)) == 10);
1681 debug.assert((try r.to(u32)) == 0);1674 testing.expect((try r.to(u32)) == 0);
1682}1675}
16831676
1684test "big.int div single-single with rem" {1677test "big.int div single-single with rem" {
...@@ -1689,8 +1682,8 @@ test "big.int div single-single with rem" {...@@ -1689,8 +1682,8 @@ test "big.int div single-single with rem" {
1689 var r = try Int.init(al);1682 var r = try Int.init(al);
1690 try Int.divTrunc(&q, &r, a, b);1683 try Int.divTrunc(&q, &r, a, b);
16911684
1692 debug.assert((try q.to(u32)) == 9);1685 testing.expect((try q.to(u32)) == 9);
1693 debug.assert((try r.to(u32)) == 4);1686 testing.expect((try r.to(u32)) == 4);
1694}1687}
16951688
1696test "big.int div multi-single no rem" {1689test "big.int div multi-single no rem" {
...@@ -1704,8 +1697,8 @@ test "big.int div multi-single no rem" {...@@ -1704,8 +1697,8 @@ test "big.int div multi-single no rem" {
1704 var r = try Int.init(al);1697 var r = try Int.init(al);
1705 try Int.divTrunc(&q, &r, a, b);1698 try Int.divTrunc(&q, &r, a, b);
17061699
1707 debug.assert((try q.to(u64)) == op1 / op2);1700 testing.expect((try q.to(u64)) == op1 / op2);
1708 debug.assert((try r.to(u64)) == 0);1701 testing.expect((try r.to(u64)) == 0);
1709}1702}
17101703
1711test "big.int div multi-single with rem" {1704test "big.int div multi-single with rem" {
...@@ -1719,8 +1712,8 @@ test "big.int div multi-single with rem" {...@@ -1719,8 +1712,8 @@ test "big.int div multi-single with rem" {
1719 var r = try Int.init(al);1712 var r = try Int.init(al);
1720 try Int.divTrunc(&q, &r, a, b);1713 try Int.divTrunc(&q, &r, a, b);
17211714
1722 debug.assert((try q.to(u64)) == op1 / op2);1715 testing.expect((try q.to(u64)) == op1 / op2);
1723 debug.assert((try r.to(u64)) == 3);1716 testing.expect((try r.to(u64)) == 3);
1724}1717}
17251718
1726test "big.int div multi>2-single" {1719test "big.int div multi>2-single" {
...@@ -1734,8 +1727,8 @@ test "big.int div multi>2-single" {...@@ -1734,8 +1727,8 @@ test "big.int div multi>2-single" {
1734 var r = try Int.init(al);1727 var r = try Int.init(al);
1735 try Int.divTrunc(&q, &r, a, b);1728 try Int.divTrunc(&q, &r, a, b);
17361729
1737 debug.assert((try q.to(u128)) == op1 / op2);1730 testing.expect((try q.to(u128)) == op1 / op2);
1738 debug.assert((try r.to(u32)) == 0x3e4e);1731 testing.expect((try r.to(u32)) == 0x3e4e);
1739}1732}
17401733
1741test "big.int div single-single q < r" {1734test "big.int div single-single q < r" {
...@@ -1746,8 +1739,8 @@ test "big.int div single-single q < r" {...@@ -1746,8 +1739,8 @@ test "big.int div single-single q < r" {
1746 var r = try Int.init(al);1739 var r = try Int.init(al);
1747 try Int.divTrunc(&q, &r, a, b);1740 try Int.divTrunc(&q, &r, a, b);
17481741
1749 debug.assert((try q.to(u64)) == 0);1742 testing.expect((try q.to(u64)) == 0);
1750 debug.assert((try r.to(u64)) == 0x0078f432);1743 testing.expect((try r.to(u64)) == 0x0078f432);
1751}1744}
17521745
1753test "big.int div single-single q == r" {1746test "big.int div single-single q == r" {
...@@ -1758,8 +1751,8 @@ test "big.int div single-single q == r" {...@@ -1758,8 +1751,8 @@ test "big.int div single-single q == r" {
1758 var r = try Int.init(al);1751 var r = try Int.init(al);
1759 try Int.divTrunc(&q, &r, a, b);1752 try Int.divTrunc(&q, &r, a, b);
17601753
1761 debug.assert((try q.to(u64)) == 1);1754 testing.expect((try q.to(u64)) == 1);
1762 debug.assert((try r.to(u64)) == 0);1755 testing.expect((try r.to(u64)) == 0);
1763}1756}
17641757
1765test "big.int div q=0 alias" {1758test "big.int div q=0 alias" {
...@@ -1768,8 +1761,8 @@ test "big.int div q=0 alias" {...@@ -1768,8 +1761,8 @@ test "big.int div q=0 alias" {
17681761
1769 try Int.divTrunc(&a, &b, a, b);1762 try Int.divTrunc(&a, &b, a, b);
17701763
1771 debug.assert((try a.to(u64)) == 0);1764 testing.expect((try a.to(u64)) == 0);
1772 debug.assert((try b.to(u64)) == 3);1765 testing.expect((try b.to(u64)) == 3);
1773}1766}
17741767
1775test "big.int div multi-multi q < r" {1768test "big.int div multi-multi q < r" {
...@@ -1782,8 +1775,8 @@ test "big.int div multi-multi q < r" {...@@ -1782,8 +1775,8 @@ test "big.int div multi-multi q < r" {
1782 var r = try Int.init(al);1775 var r = try Int.init(al);
1783 try Int.divTrunc(&q, &r, a, b);1776 try Int.divTrunc(&q, &r, a, b);
17841777
1785 debug.assert((try q.to(u128)) == 0);1778 testing.expect((try q.to(u128)) == 0);
1786 debug.assert((try r.to(u128)) == op1);1779 testing.expect((try r.to(u128)) == op1);
1787}1780}
17881781
1789test "big.int div trunc single-single +/+" {1782test "big.int div trunc single-single +/+" {
...@@ -1802,8 +1795,8 @@ test "big.int div trunc single-single +/+" {...@@ -1802,8 +1795,8 @@ test "big.int div trunc single-single +/+" {
1802 const eq = @divTrunc(u, v);1795 const eq = @divTrunc(u, v);
1803 const er = @mod(u, v);1796 const er = @mod(u, v);
18041797
1805 debug.assert((try q.to(i32)) == eq);1798 testing.expect((try q.to(i32)) == eq);
1806 debug.assert((try r.to(i32)) == er);1799 testing.expect((try r.to(i32)) == er);
1807}1800}
18081801
1809test "big.int div trunc single-single -/+" {1802test "big.int div trunc single-single -/+" {
...@@ -1822,8 +1815,8 @@ test "big.int div trunc single-single -/+" {...@@ -1822,8 +1815,8 @@ test "big.int div trunc single-single -/+" {
1822 const eq = -1;1815 const eq = -1;
1823 const er = -2;1816 const er = -2;
18241817
1825 debug.assert((try q.to(i32)) == eq);1818 testing.expect((try q.to(i32)) == eq);
1826 debug.assert((try r.to(i32)) == er);1819 testing.expect((try r.to(i32)) == er);
1827}1820}
18281821
1829test "big.int div trunc single-single +/-" {1822test "big.int div trunc single-single +/-" {
...@@ -1842,8 +1835,8 @@ test "big.int div trunc single-single +/-" {...@@ -1842,8 +1835,8 @@ test "big.int div trunc single-single +/-" {
1842 const eq = -1;1835 const eq = -1;
1843 const er = 2;1836 const er = 2;
18441837
1845 debug.assert((try q.to(i32)) == eq);1838 testing.expect((try q.to(i32)) == eq);
1846 debug.assert((try r.to(i32)) == er);1839 testing.expect((try r.to(i32)) == er);
1847}1840}
18481841
1849test "big.int div trunc single-single -/-" {1842test "big.int div trunc single-single -/-" {
...@@ -1862,8 +1855,8 @@ test "big.int div trunc single-single -/-" {...@@ -1862,8 +1855,8 @@ test "big.int div trunc single-single -/-" {
1862 const eq = 1;1855 const eq = 1;
1863 const er = -2;1856 const er = -2;
18641857
1865 debug.assert((try q.to(i32)) == eq);1858 testing.expect((try q.to(i32)) == eq);
1866 debug.assert((try r.to(i32)) == er);1859 testing.expect((try r.to(i32)) == er);
1867}1860}
18681861
1869test "big.int div floor single-single +/+" {1862test "big.int div floor single-single +/+" {
...@@ -1882,8 +1875,8 @@ test "big.int div floor single-single +/+" {...@@ -1882,8 +1875,8 @@ test "big.int div floor single-single +/+" {
1882 const eq = 1;1875 const eq = 1;
1883 const er = 2;1876 const er = 2;
18841877
1885 debug.assert((try q.to(i32)) == eq);1878 testing.expect((try q.to(i32)) == eq);
1886 debug.assert((try r.to(i32)) == er);1879 testing.expect((try r.to(i32)) == er);
1887}1880}
18881881
1889test "big.int div floor single-single -/+" {1882test "big.int div floor single-single -/+" {
...@@ -1902,8 +1895,8 @@ test "big.int div floor single-single -/+" {...@@ -1902,8 +1895,8 @@ test "big.int div floor single-single -/+" {
1902 const eq = -2;1895 const eq = -2;
1903 const er = 1;1896 const er = 1;
19041897
1905 debug.assert((try q.to(i32)) == eq);1898 testing.expect((try q.to(i32)) == eq);
1906 debug.assert((try r.to(i32)) == er);1899 testing.expect((try r.to(i32)) == er);
1907}1900}
19081901
1909test "big.int div floor single-single +/-" {1902test "big.int div floor single-single +/-" {
...@@ -1922,8 +1915,8 @@ test "big.int div floor single-single +/-" {...@@ -1922,8 +1915,8 @@ test "big.int div floor single-single +/-" {
1922 const eq = -2;1915 const eq = -2;
1923 const er = -1;1916 const er = -1;
19241917
1925 debug.assert((try q.to(i32)) == eq);1918 testing.expect((try q.to(i32)) == eq);
1926 debug.assert((try r.to(i32)) == er);1919 testing.expect((try r.to(i32)) == er);
1927}1920}
19281921
1929test "big.int div floor single-single -/-" {1922test "big.int div floor single-single -/-" {
...@@ -1942,8 +1935,8 @@ test "big.int div floor single-single -/-" {...@@ -1942,8 +1935,8 @@ test "big.int div floor single-single -/-" {
1942 const eq = 1;1935 const eq = 1;
1943 const er = -2;1936 const er = -2;
19441937
1945 debug.assert((try q.to(i32)) == eq);1938 testing.expect((try q.to(i32)) == eq);
1946 debug.assert((try r.to(i32)) == er);1939 testing.expect((try r.to(i32)) == er);
1947}1940}
19481941
1949test "big.int div multi-multi with rem" {1942test "big.int div multi-multi with rem" {
...@@ -1954,8 +1947,8 @@ test "big.int div multi-multi with rem" {...@@ -1954,8 +1947,8 @@ test "big.int div multi-multi with rem" {
1954 var r = try Int.init(al);1947 var r = try Int.init(al);
1955 try Int.divTrunc(&q, &r, a, b);1948 try Int.divTrunc(&q, &r, a, b);
19561949
1957 debug.assert((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b);1950 testing.expect((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b);
1958 debug.assert((try r.to(u128)) == 0x28de0acacd806823638);1951 testing.expect((try r.to(u128)) == 0x28de0acacd806823638);
1959}1952}
19601953
1961test "big.int div multi-multi no rem" {1954test "big.int div multi-multi no rem" {
...@@ -1966,8 +1959,8 @@ test "big.int div multi-multi no rem" {...@@ -1966,8 +1959,8 @@ test "big.int div multi-multi no rem" {
1966 var r = try Int.init(al);1959 var r = try Int.init(al);
1967 try Int.divTrunc(&q, &r, a, b);1960 try Int.divTrunc(&q, &r, a, b);
19681961
1969 debug.assert((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b);1962 testing.expect((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b);
1970 debug.assert((try r.to(u128)) == 0);1963 testing.expect((try r.to(u128)) == 0);
1971}1964}
19721965
1973test "big.int div multi-multi (2 branch)" {1966test "big.int div multi-multi (2 branch)" {
...@@ -1978,8 +1971,8 @@ test "big.int div multi-multi (2 branch)" {...@@ -1978,8 +1971,8 @@ test "big.int div multi-multi (2 branch)" {
1978 var r = try Int.init(al);1971 var r = try Int.init(al);
1979 try Int.divTrunc(&q, &r, a, b);1972 try Int.divTrunc(&q, &r, a, b);
19801973
1981 debug.assert((try q.to(u128)) == 0x10000000000000000);1974 testing.expect((try q.to(u128)) == 0x10000000000000000);
1982 debug.assert((try r.to(u128)) == 0x44444443444444431111111111111111);1975 testing.expect((try r.to(u128)) == 0x44444443444444431111111111111111);
1983}1976}
19841977
1985test "big.int div multi-multi (3.1/3.3 branch)" {1978test "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)" {...@@ -1990,53 +1983,53 @@ test "big.int div multi-multi (3.1/3.3 branch)" {
1990 var r = try Int.init(al);1983 var r = try Int.init(al);
1991 try Int.divTrunc(&q, &r, a, b);1984 try Int.divTrunc(&q, &r, a, b);
19921985
1993 debug.assert((try q.to(u128)) == 0xfffffffffffffffffff);1986 testing.expect((try q.to(u128)) == 0xfffffffffffffffffff);
1994 debug.assert((try r.to(u256)) == 0x1111111111111111111110b12222222222222222282);1987 testing.expect((try r.to(u256)) == 0x1111111111111111111110b12222222222222222282);
1995}1988}
19961989
1997test "big.int shift-right single" {1990test "big.int shift-right single" {
1998 var a = try Int.initSet(al, 0xffff0000);1991 var a = try Int.initSet(al, 0xffff0000);
1999 try a.shiftRight(a, 16);1992 try a.shiftRight(a, 16);
20001993
2001 debug.assert((try a.to(u32)) == 0xffff);1994 testing.expect((try a.to(u32)) == 0xffff);
2002}1995}
20031996
2004test "big.int shift-right multi" {1997test "big.int shift-right multi" {
2005 var a = try Int.initSet(al, 0xffff0000eeee1111dddd2222cccc3333);1998 var a = try Int.initSet(al, 0xffff0000eeee1111dddd2222cccc3333);
2006 try a.shiftRight(a, 67);1999 try a.shiftRight(a, 67);
20072000
2008 debug.assert((try a.to(u64)) == 0x1fffe0001dddc222);2001 testing.expect((try a.to(u64)) == 0x1fffe0001dddc222);
2009}2002}
20102003
2011test "big.int shift-left single" {2004test "big.int shift-left single" {
2012 var a = try Int.initSet(al, 0xffff);2005 var a = try Int.initSet(al, 0xffff);
2013 try a.shiftLeft(a, 16);2006 try a.shiftLeft(a, 16);
20142007
2015 debug.assert((try a.to(u64)) == 0xffff0000);2008 testing.expect((try a.to(u64)) == 0xffff0000);
2016}2009}
20172010
2018test "big.int shift-left multi" {2011test "big.int shift-left multi" {
2019 var a = try Int.initSet(al, 0x1fffe0001dddc222);2012 var a = try Int.initSet(al, 0x1fffe0001dddc222);
2020 try a.shiftLeft(a, 67);2013 try a.shiftLeft(a, 67);
20212014
2022 debug.assert((try a.to(u128)) == 0xffff0000eeee11100000000000000000);2015 testing.expect((try a.to(u128)) == 0xffff0000eeee11100000000000000000);
2023}2016}
20242017
2025test "big.int shift-right negative" {2018test "big.int shift-right negative" {
2026 var a = try Int.init(al);2019 var a = try Int.init(al);
20272020
2028 try a.shiftRight(try Int.initSet(al, -20), 2);2021 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
2031 try a.shiftRight(try Int.initSet(al, -5), 10);2024 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);
2033}2026}
20342027
2035test "big.int shift-left negative" {2028test "big.int shift-left negative" {
2036 var a = try Int.init(al);2029 var a = try Int.init(al);
20372030
2038 try a.shiftRight(try Int.initSet(al, -10), 1232);2031 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);
2040}2033}
20412034
2042test "big.int bitwise and simple" {2035test "big.int bitwise and simple" {
...@@ -2045,7 +2038,7 @@ test "big.int bitwise and simple" {...@@ -2045,7 +2038,7 @@ test "big.int bitwise and simple" {
20452038
2046 try a.bitAnd(a, b);2039 try a.bitAnd(a, b);
20472040
2048 debug.assert((try a.to(u64)) == 0xeeeeeeee00000000);2041 testing.expect((try a.to(u64)) == 0xeeeeeeee00000000);
2049}2042}
20502043
2051test "big.int bitwise and multi-limb" {2044test "big.int bitwise and multi-limb" {
...@@ -2054,7 +2047,7 @@ test "big.int bitwise and multi-limb" {...@@ -2054,7 +2047,7 @@ test "big.int bitwise and multi-limb" {
20542047
2055 try a.bitAnd(a, b);2048 try a.bitAnd(a, b);
20562049
2057 debug.assert((try a.to(u128)) == 0);2050 testing.expect((try a.to(u128)) == 0);
2058}2051}
20592052
2060test "big.int bitwise xor simple" {2053test "big.int bitwise xor simple" {
...@@ -2063,7 +2056,7 @@ test "big.int bitwise xor simple" {...@@ -2063,7 +2056,7 @@ test "big.int bitwise xor simple" {
20632056
2064 try a.bitXor(a, b);2057 try a.bitXor(a, b);
20652058
2066 debug.assert((try a.to(u64)) == 0x1111111133333333);2059 testing.expect((try a.to(u64)) == 0x1111111133333333);
2067}2060}
20682061
2069test "big.int bitwise xor multi-limb" {2062test "big.int bitwise xor multi-limb" {
...@@ -2072,7 +2065,7 @@ test "big.int bitwise xor multi-limb" {...@@ -2072,7 +2065,7 @@ test "big.int bitwise xor multi-limb" {
20722065
2073 try a.bitXor(a, b);2066 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));
2076}2069}
20772070
2078test "big.int bitwise or simple" {2071test "big.int bitwise or simple" {
...@@ -2081,7 +2074,7 @@ test "big.int bitwise or simple" {...@@ -2081,7 +2074,7 @@ test "big.int bitwise or simple" {
20812074
2082 try a.bitOr(a, b);2075 try a.bitOr(a, b);
20832076
2084 debug.assert((try a.to(u64)) == 0xffffffff33333333);2077 testing.expect((try a.to(u64)) == 0xffffffff33333333);
2085}2078}
20862079
2087test "big.int bitwise or multi-limb" {2080test "big.int bitwise or multi-limb" {
...@@ -2091,15 +2084,15 @@ test "big.int bitwise or multi-limb" {...@@ -2091,15 +2084,15 @@ test "big.int bitwise or multi-limb" {
2091 try a.bitOr(a, b);2084 try a.bitOr(a, b);
20922085
2093 // TODO: big.int.cpp or is wrong on multi-limb.2086 // 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));
2095}2088}
20962089
2097test "big.int var args" {2090test "big.int var args" {
2098 var a = try Int.initSet(al, 5);2091 var a = try Int.initSet(al, 5);
20992092
2100 try a.add(a, try Int.initSet(al, 6));2093 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);2096 testing.expect(a.cmp(try Int.initSet(al, 11)) == 0);
2104 debug.assert(a.cmp(try Int.initSet(al, 14)) <= 0);2097 testing.expect(a.cmp(try Int.initSet(al, 14)) <= 0);
2105}2098}
std/math/cbrt.zig+25-25
...@@ -6,7 +6,7 @@...@@ -6,7 +6,7 @@
66
7const std = @import("../index.zig");7const std = @import("../index.zig");
8const math = std.math;8const math = std.math;
9const assert = std.debug.assert;9const expect = std.testing.expect;
1010
11pub fn cbrt(x: var) @typeOf(x) {11pub fn cbrt(x: var) @typeOf(x) {
12 const T = @typeOf(x);12 const T = @typeOf(x);
...@@ -114,44 +114,44 @@ fn cbrt64(x: f64) f64 {...@@ -114,44 +114,44 @@ fn cbrt64(x: f64) f64 {
114}114}
115115
116test "math.cbrt" {116test "math.cbrt" {
117 assert(cbrt(f32(0.0)) == cbrt32(0.0));117 expect(cbrt(f32(0.0)) == cbrt32(0.0));
118 assert(cbrt(f64(0.0)) == cbrt64(0.0));118 expect(cbrt(f64(0.0)) == cbrt64(0.0));
119}119}
120120
121test "math.cbrt32" {121test "math.cbrt32" {
122 const epsilon = 0.000001;122 const epsilon = 0.000001;
123123
124 assert(cbrt32(0.0) == 0.0);124 expect(cbrt32(0.0) == 0.0);
125 assert(math.approxEq(f32, cbrt32(0.2), 0.584804, epsilon));125 expect(math.approxEq(f32, cbrt32(0.2), 0.584804, epsilon));
126 assert(math.approxEq(f32, cbrt32(0.8923), 0.962728, epsilon));126 expect(math.approxEq(f32, cbrt32(0.8923), 0.962728, epsilon));
127 assert(math.approxEq(f32, cbrt32(1.5), 1.144714, epsilon));127 expect(math.approxEq(f32, cbrt32(1.5), 1.144714, epsilon));
128 assert(math.approxEq(f32, cbrt32(37.45), 3.345676, epsilon));128 expect(math.approxEq(f32, cbrt32(37.45), 3.345676, epsilon));
129 assert(math.approxEq(f32, cbrt32(123123.234375), 49.748501, epsilon));129 expect(math.approxEq(f32, cbrt32(123123.234375), 49.748501, epsilon));
130}130}
131131
132test "math.cbrt64" {132test "math.cbrt64" {
133 const epsilon = 0.000001;133 const epsilon = 0.000001;
134134
135 assert(cbrt64(0.0) == 0.0);135 expect(cbrt64(0.0) == 0.0);
136 assert(math.approxEq(f64, cbrt64(0.2), 0.584804, epsilon));136 expect(math.approxEq(f64, cbrt64(0.2), 0.584804, epsilon));
137 assert(math.approxEq(f64, cbrt64(0.8923), 0.962728, epsilon));137 expect(math.approxEq(f64, cbrt64(0.8923), 0.962728, epsilon));
138 assert(math.approxEq(f64, cbrt64(1.5), 1.144714, epsilon));138 expect(math.approxEq(f64, cbrt64(1.5), 1.144714, epsilon));
139 assert(math.approxEq(f64, cbrt64(37.45), 3.345676, epsilon));139 expect(math.approxEq(f64, cbrt64(37.45), 3.345676, epsilon));
140 assert(math.approxEq(f64, cbrt64(123123.234375), 49.748501, epsilon));140 expect(math.approxEq(f64, cbrt64(123123.234375), 49.748501, epsilon));
141}141}
142142
143test "math.cbrt.special" {143test "math.cbrt.special" {
144 assert(cbrt32(0.0) == 0.0);144 expect(cbrt32(0.0) == 0.0);
145 assert(cbrt32(-0.0) == -0.0);145 expect(cbrt32(-0.0) == -0.0);
146 assert(math.isPositiveInf(cbrt32(math.inf(f32))));146 expect(math.isPositiveInf(cbrt32(math.inf(f32))));
147 assert(math.isNegativeInf(cbrt32(-math.inf(f32))));147 expect(math.isNegativeInf(cbrt32(-math.inf(f32))));
148 assert(math.isNan(cbrt32(math.nan(f32))));148 expect(math.isNan(cbrt32(math.nan(f32))));
149}149}
150150
151test "math.cbrt64.special" {151test "math.cbrt64.special" {
152 assert(cbrt64(0.0) == 0.0);152 expect(cbrt64(0.0) == 0.0);
153 assert(cbrt64(-0.0) == -0.0);153 expect(cbrt64(-0.0) == -0.0);
154 assert(math.isPositiveInf(cbrt64(math.inf(f64))));154 expect(math.isPositiveInf(cbrt64(math.inf(f64))));
155 assert(math.isNegativeInf(cbrt64(-math.inf(f64))));155 expect(math.isNegativeInf(cbrt64(-math.inf(f64))));
156 assert(math.isNan(cbrt64(math.nan(f64))));156 expect(math.isNan(cbrt64(math.nan(f64))));
157}157}
std/math/ceil.zig+19-19
...@@ -7,7 +7,7 @@...@@ -7,7 +7,7 @@
7const builtin = @import("builtin");7const builtin = @import("builtin");
8const std = @import("../index.zig");8const std = @import("../index.zig");
9const math = std.math;9const math = std.math;
10const assert = std.debug.assert;10const expect = std.testing.expect;
1111
12pub fn ceil(x: var) @typeOf(x) {12pub fn ceil(x: var) @typeOf(x) {
13 const T = @typeOf(x);13 const T = @typeOf(x);
...@@ -81,34 +81,34 @@ fn ceil64(x: f64) f64 {...@@ -81,34 +81,34 @@ fn ceil64(x: f64) f64 {
81}81}
8282
83test "math.ceil" {83test "math.ceil" {
84 assert(ceil(f32(0.0)) == ceil32(0.0));84 expect(ceil(f32(0.0)) == ceil32(0.0));
85 assert(ceil(f64(0.0)) == ceil64(0.0));85 expect(ceil(f64(0.0)) == ceil64(0.0));
86}86}
8787
88test "math.ceil32" {88test "math.ceil32" {
89 assert(ceil32(1.3) == 2.0);89 expect(ceil32(1.3) == 2.0);
90 assert(ceil32(-1.3) == -1.0);90 expect(ceil32(-1.3) == -1.0);
91 assert(ceil32(0.2) == 1.0);91 expect(ceil32(0.2) == 1.0);
92}92}
9393
94test "math.ceil64" {94test "math.ceil64" {
95 assert(ceil64(1.3) == 2.0);95 expect(ceil64(1.3) == 2.0);
96 assert(ceil64(-1.3) == -1.0);96 expect(ceil64(-1.3) == -1.0);
97 assert(ceil64(0.2) == 1.0);97 expect(ceil64(0.2) == 1.0);
98}98}
9999
100test "math.ceil32.special" {100test "math.ceil32.special" {
101 assert(ceil32(0.0) == 0.0);101 expect(ceil32(0.0) == 0.0);
102 assert(ceil32(-0.0) == -0.0);102 expect(ceil32(-0.0) == -0.0);
103 assert(math.isPositiveInf(ceil32(math.inf(f32))));103 expect(math.isPositiveInf(ceil32(math.inf(f32))));
104 assert(math.isNegativeInf(ceil32(-math.inf(f32))));104 expect(math.isNegativeInf(ceil32(-math.inf(f32))));
105 assert(math.isNan(ceil32(math.nan(f32))));105 expect(math.isNan(ceil32(math.nan(f32))));
106}106}
107107
108test "math.ceil64.special" {108test "math.ceil64.special" {
109 assert(ceil64(0.0) == 0.0);109 expect(ceil64(0.0) == 0.0);
110 assert(ceil64(-0.0) == -0.0);110 expect(ceil64(-0.0) == -0.0);
111 assert(math.isPositiveInf(ceil64(math.inf(f64))));111 expect(math.isPositiveInf(ceil64(math.inf(f64))));
112 assert(math.isNegativeInf(ceil64(-math.inf(f64))));112 expect(math.isNegativeInf(ceil64(-math.inf(f64))));
113 assert(math.isNan(ceil64(math.nan(f64))));113 expect(math.isNan(ceil64(math.nan(f64))));
114}114}
std/math/complex/abs.zig+2-2
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("../../index.zig");1const std = @import("../../index.zig");
2const debug = std.debug;2const testing = std.testing;
3const math = std.math;3const math = std.math;
4const cmath = math.complex;4const cmath = math.complex;
5const Complex = cmath.Complex;5const Complex = cmath.Complex;
...@@ -14,5 +14,5 @@ const epsilon = 0.0001;...@@ -14,5 +14,5 @@ const epsilon = 0.0001;
14test "complex.cabs" {14test "complex.cabs" {
15 const a = Complex(f32).new(5, 3);15 const a = Complex(f32).new(5, 3);
16 const c = abs(a);16 const c = abs(a);
17 debug.assert(math.approxEq(f32, c, 5.83095, epsilon));17 testing.expect(math.approxEq(f32, c, 5.83095, epsilon));
18}18}
std/math/complex/acos.zig+3-3
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("../../index.zig");1const std = @import("../../index.zig");
2const debug = std.debug;2const testing = std.testing;
3const math = std.math;3const math = std.math;
4const cmath = math.complex;4const cmath = math.complex;
5const Complex = cmath.Complex;5const Complex = cmath.Complex;
...@@ -16,6 +16,6 @@ test "complex.cacos" {...@@ -16,6 +16,6 @@ test "complex.cacos" {
16 const a = Complex(f32).new(5, 3);16 const a = Complex(f32).new(5, 3);
17 const c = acos(a);17 const c = acos(a);
1818
19 debug.assert(math.approxEq(f32, c.re, 0.546975, epsilon));19 testing.expect(math.approxEq(f32, c.re, 0.546975, epsilon));
20 debug.assert(math.approxEq(f32, c.im, -2.452914, epsilon));20 testing.expect(math.approxEq(f32, c.im, -2.452914, epsilon));
21}21}
std/math/complex/acosh.zig+3-3
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("../../index.zig");1const std = @import("../../index.zig");
2const debug = std.debug;2const testing = std.testing;
3const math = std.math;3const math = std.math;
4const cmath = math.complex;4const cmath = math.complex;
5const Complex = cmath.Complex;5const Complex = cmath.Complex;
...@@ -16,6 +16,6 @@ test "complex.cacosh" {...@@ -16,6 +16,6 @@ test "complex.cacosh" {
16 const a = Complex(f32).new(5, 3);16 const a = Complex(f32).new(5, 3);
17 const c = acosh(a);17 const c = acosh(a);
1818
19 debug.assert(math.approxEq(f32, c.re, 2.452914, epsilon));19 testing.expect(math.approxEq(f32, c.re, 2.452914, epsilon));
20 debug.assert(math.approxEq(f32, c.im, 0.546975, epsilon));20 testing.expect(math.approxEq(f32, c.im, 0.546975, epsilon));
21}21}
std/math/complex/arg.zig+2-2
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("../../index.zig");1const std = @import("../../index.zig");
2const debug = std.debug;2const testing = std.testing;
3const math = std.math;3const math = std.math;
4const cmath = math.complex;4const cmath = math.complex;
5const Complex = cmath.Complex;5const Complex = cmath.Complex;
...@@ -14,5 +14,5 @@ const epsilon = 0.0001;...@@ -14,5 +14,5 @@ const epsilon = 0.0001;
14test "complex.carg" {14test "complex.carg" {
15 const a = Complex(f32).new(5, 3);15 const a = Complex(f32).new(5, 3);
16 const c = arg(a);16 const c = arg(a);
17 debug.assert(math.approxEq(f32, c, 0.540420, epsilon));17 testing.expect(math.approxEq(f32, c, 0.540420, epsilon));
18}18}
std/math/complex/asin.zig+3-3
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("../../index.zig");1const std = @import("../../index.zig");
2const debug = std.debug;2const testing = std.testing;
3const math = std.math;3const math = std.math;
4const cmath = math.complex;4const cmath = math.complex;
5const Complex = cmath.Complex;5const Complex = cmath.Complex;
...@@ -22,6 +22,6 @@ test "complex.casin" {...@@ -22,6 +22,6 @@ test "complex.casin" {
22 const a = Complex(f32).new(5, 3);22 const a = Complex(f32).new(5, 3);
23 const c = asin(a);23 const c = asin(a);
2424
25 debug.assert(math.approxEq(f32, c.re, 1.023822, epsilon));25 testing.expect(math.approxEq(f32, c.re, 1.023822, epsilon));
26 debug.assert(math.approxEq(f32, c.im, 2.452914, epsilon));26 testing.expect(math.approxEq(f32, c.im, 2.452914, epsilon));
27}27}
std/math/complex/asinh.zig+3-3
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("../../index.zig");1const std = @import("../../index.zig");
2const debug = std.debug;2const testing = std.testing;
3const math = std.math;3const math = std.math;
4const cmath = math.complex;4const cmath = math.complex;
5const Complex = cmath.Complex;5const Complex = cmath.Complex;
...@@ -17,6 +17,6 @@ test "complex.casinh" {...@@ -17,6 +17,6 @@ test "complex.casinh" {
17 const a = Complex(f32).new(5, 3);17 const a = Complex(f32).new(5, 3);
18 const c = asinh(a);18 const c = asinh(a);
1919
20 debug.assert(math.approxEq(f32, c.re, 2.459831, epsilon));20 testing.expect(math.approxEq(f32, c.re, 2.459831, epsilon));
21 debug.assert(math.approxEq(f32, c.im, 0.533999, epsilon));21 testing.expect(math.approxEq(f32, c.im, 0.533999, epsilon));
22}22}
std/math/complex/atan.zig+5-5
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("../../index.zig");1const std = @import("../../index.zig");
2const debug = std.debug;2const testing = std.testing;
3const math = std.math;3const math = std.math;
4const cmath = math.complex;4const cmath = math.complex;
5const Complex = cmath.Complex;5const Complex = cmath.Complex;
...@@ -117,14 +117,14 @@ test "complex.catan32" {...@@ -117,14 +117,14 @@ test "complex.catan32" {
117 const a = Complex(f32).new(5, 3);117 const a = Complex(f32).new(5, 3);
118 const c = atan(a);118 const c = atan(a);
119119
120 debug.assert(math.approxEq(f32, c.re, 1.423679, epsilon));120 testing.expect(math.approxEq(f32, c.re, 1.423679, epsilon));
121 debug.assert(math.approxEq(f32, c.im, 0.086569, epsilon));121 testing.expect(math.approxEq(f32, c.im, 0.086569, epsilon));
122}122}
123123
124test "complex.catan64" {124test "complex.catan64" {
125 const a = Complex(f64).new(5, 3);125 const a = Complex(f64).new(5, 3);
126 const c = atan(a);126 const c = atan(a);
127127
128 debug.assert(math.approxEq(f64, c.re, 1.423679, epsilon));128 testing.expect(math.approxEq(f64, c.re, 1.423679, epsilon));
129 debug.assert(math.approxEq(f64, c.im, 0.086569, epsilon));129 testing.expect(math.approxEq(f64, c.im, 0.086569, epsilon));
130}130}
std/math/complex/atanh.zig+3-3
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("../../index.zig");1const std = @import("../../index.zig");
2const debug = std.debug;2const testing = std.testing;
3const math = std.math;3const math = std.math;
4const cmath = math.complex;4const cmath = math.complex;
5const Complex = cmath.Complex;5const Complex = cmath.Complex;
...@@ -17,6 +17,6 @@ test "complex.catanh" {...@@ -17,6 +17,6 @@ test "complex.catanh" {
17 const a = Complex(f32).new(5, 3);17 const a = Complex(f32).new(5, 3);
18 const c = atanh(a);18 const c = atanh(a);
1919
20 debug.assert(math.approxEq(f32, c.re, 0.146947, epsilon));20 testing.expect(math.approxEq(f32, c.re, 0.146947, epsilon));
21 debug.assert(math.approxEq(f32, c.im, 1.480870, epsilon));21 testing.expect(math.approxEq(f32, c.im, 1.480870, epsilon));
22}22}
std/math/complex/conj.zig+2-2
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("../../index.zig");1const std = @import("../../index.zig");
2const debug = std.debug;2const testing = std.testing;
3const math = std.math;3const math = std.math;
4const cmath = math.complex;4const cmath = math.complex;
5const Complex = cmath.Complex;5const Complex = cmath.Complex;
...@@ -13,5 +13,5 @@ test "complex.conj" {...@@ -13,5 +13,5 @@ test "complex.conj" {
13 const a = Complex(f32).new(5, 3);13 const a = Complex(f32).new(5, 3);
14 const c = a.conjugate();14 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);
17}17}
std/math/complex/cos.zig+3-3
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("../../index.zig");1const std = @import("../../index.zig");
2const debug = std.debug;2const testing = std.testing;
3const math = std.math;3const math = std.math;
4const cmath = math.complex;4const cmath = math.complex;
5const Complex = cmath.Complex;5const Complex = cmath.Complex;
...@@ -16,6 +16,6 @@ test "complex.ccos" {...@@ -16,6 +16,6 @@ test "complex.ccos" {
16 const a = Complex(f32).new(5, 3);16 const a = Complex(f32).new(5, 3);
17 const c = cos(a);17 const c = cos(a);
1818
19 debug.assert(math.approxEq(f32, c.re, 2.855815, epsilon));19 testing.expect(math.approxEq(f32, c.re, 2.855815, epsilon));
20 debug.assert(math.approxEq(f32, c.im, 9.606383, epsilon));20 testing.expect(math.approxEq(f32, c.im, 9.606383, epsilon));
21}21}
std/math/complex/cosh.zig+5-5
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("../../index.zig");1const std = @import("../../index.zig");
2const debug = std.debug;2const testing = std.testing;
3const math = std.math;3const math = std.math;
4const cmath = math.complex;4const cmath = math.complex;
5const Complex = cmath.Complex;5const Complex = cmath.Complex;
...@@ -152,14 +152,14 @@ test "complex.ccosh32" {...@@ -152,14 +152,14 @@ test "complex.ccosh32" {
152 const a = Complex(f32).new(5, 3);152 const a = Complex(f32).new(5, 3);
153 const c = cosh(a);153 const c = cosh(a);
154154
155 debug.assert(math.approxEq(f32, c.re, -73.467300, epsilon));155 testing.expect(math.approxEq(f32, c.re, -73.467300, epsilon));
156 debug.assert(math.approxEq(f32, c.im, 10.471557, epsilon));156 testing.expect(math.approxEq(f32, c.im, 10.471557, epsilon));
157}157}
158158
159test "complex.ccosh64" {159test "complex.ccosh64" {
160 const a = Complex(f64).new(5, 3);160 const a = Complex(f64).new(5, 3);
161 const c = cosh(a);161 const c = cosh(a);
162162
163 debug.assert(math.approxEq(f64, c.re, -73.467300, epsilon));163 testing.expect(math.approxEq(f64, c.re, -73.467300, epsilon));
164 debug.assert(math.approxEq(f64, c.im, 10.471557, epsilon));164 testing.expect(math.approxEq(f64, c.im, 10.471557, epsilon));
165}165}
std/math/complex/exp.zig+5-5
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("../../index.zig");1const std = @import("../../index.zig");
2const debug = std.debug;2const testing = std.testing;
3const math = std.math;3const math = std.math;
4const cmath = math.complex;4const cmath = math.complex;
5const Complex = cmath.Complex;5const Complex = cmath.Complex;
...@@ -118,14 +118,14 @@ test "complex.cexp32" {...@@ -118,14 +118,14 @@ test "complex.cexp32" {
118 const a = Complex(f32).new(5, 3);118 const a = Complex(f32).new(5, 3);
119 const c = exp(a);119 const c = exp(a);
120120
121 debug.assert(math.approxEq(f32, c.re, -146.927917, epsilon));121 testing.expect(math.approxEq(f32, c.re, -146.927917, epsilon));
122 debug.assert(math.approxEq(f32, c.im, 20.944065, epsilon));122 testing.expect(math.approxEq(f32, c.im, 20.944065, epsilon));
123}123}
124124
125test "complex.cexp64" {125test "complex.cexp64" {
126 const a = Complex(f64).new(5, 3);126 const a = Complex(f64).new(5, 3);
127 const c = exp(a);127 const c = exp(a);
128128
129 debug.assert(math.approxEq(f64, c.re, -146.927917, epsilon));129 testing.expect(math.approxEq(f64, c.re, -146.927917, epsilon));
130 debug.assert(math.approxEq(f64, c.im, 20.944065, epsilon));130 testing.expect(math.approxEq(f64, c.im, 20.944065, epsilon));
131}131}
std/math/complex/index.zig+8-8
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("../../index.zig");1const std = @import("../../index.zig");
2const debug = std.debug;2const testing = std.testing;
3const math = std.math;3const math = std.math;
44
5pub const abs = @import("abs.zig").abs;5pub const abs = @import("abs.zig").abs;
...@@ -97,7 +97,7 @@ test "complex.add" {...@@ -97,7 +97,7 @@ test "complex.add" {
97 const b = Complex(f32).new(2, 7);97 const b = Complex(f32).new(2, 7);
98 const c = a.add(b);98 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);
101}101}
102102
103test "complex.sub" {103test "complex.sub" {
...@@ -105,7 +105,7 @@ test "complex.sub" {...@@ -105,7 +105,7 @@ test "complex.sub" {
105 const b = Complex(f32).new(2, 7);105 const b = Complex(f32).new(2, 7);
106 const c = a.sub(b);106 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);
109}109}
110110
111test "complex.mul" {111test "complex.mul" {
...@@ -113,7 +113,7 @@ test "complex.mul" {...@@ -113,7 +113,7 @@ test "complex.mul" {
113 const b = Complex(f32).new(2, 7);113 const b = Complex(f32).new(2, 7);
114 const c = a.mul(b);114 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);
117}117}
118118
119test "complex.div" {119test "complex.div" {
...@@ -121,7 +121,7 @@ test "complex.div" {...@@ -121,7 +121,7 @@ test "complex.div" {
121 const b = Complex(f32).new(2, 7);121 const b = Complex(f32).new(2, 7);
122 const c = a.div(b);122 const c = a.div(b);
123123
124 debug.assert(math.approxEq(f32, c.re, f32(31) / 53, epsilon) and124 testing.expect(math.approxEq(f32, c.re, f32(31) / 53, epsilon) and
125 math.approxEq(f32, c.im, f32(-29) / 53, epsilon));125 math.approxEq(f32, c.im, f32(-29) / 53, epsilon));
126}126}
127127
...@@ -129,14 +129,14 @@ test "complex.conjugate" {...@@ -129,14 +129,14 @@ test "complex.conjugate" {
129 const a = Complex(f32).new(5, 3);129 const a = Complex(f32).new(5, 3);
130 const c = a.conjugate();130 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);
133}133}
134134
135test "complex.reciprocal" {135test "complex.reciprocal" {
136 const a = Complex(f32).new(5, 3);136 const a = Complex(f32).new(5, 3);
137 const c = a.reciprocal();137 const c = a.reciprocal();
138138
139 debug.assert(math.approxEq(f32, c.re, f32(5) / 34, epsilon) and139 testing.expect(math.approxEq(f32, c.re, f32(5) / 34, epsilon) and
140 math.approxEq(f32, c.im, f32(-3) / 34, epsilon));140 math.approxEq(f32, c.im, f32(-3) / 34, epsilon));
141}141}
142142
...@@ -144,7 +144,7 @@ test "complex.magnitude" {...@@ -144,7 +144,7 @@ test "complex.magnitude" {
144 const a = Complex(f32).new(5, 3);144 const a = Complex(f32).new(5, 3);
145 const c = a.magnitude();145 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));
148}148}
149149
150test "complex.cmath" {150test "complex.cmath" {
std/math/complex/log.zig+3-3
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("../../index.zig");1const std = @import("../../index.zig");
2const debug = std.debug;2const testing = std.testing;
3const math = std.math;3const math = std.math;
4const cmath = math.complex;4const cmath = math.complex;
5const Complex = cmath.Complex;5const Complex = cmath.Complex;
...@@ -18,6 +18,6 @@ test "complex.clog" {...@@ -18,6 +18,6 @@ test "complex.clog" {
18 const a = Complex(f32).new(5, 3);18 const a = Complex(f32).new(5, 3);
19 const c = log(a);19 const c = log(a);
2020
21 debug.assert(math.approxEq(f32, c.re, 1.763180, epsilon));21 testing.expect(math.approxEq(f32, c.re, 1.763180, epsilon));
22 debug.assert(math.approxEq(f32, c.im, 0.540419, epsilon));22 testing.expect(math.approxEq(f32, c.im, 0.540419, epsilon));
23}23}
std/math/complex/pow.zig+3-3
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("../../index.zig");1const std = @import("../../index.zig");
2const debug = std.debug;2const testing = std.testing;
3const math = std.math;3const math = std.math;
4const cmath = math.complex;4const cmath = math.complex;
5const Complex = cmath.Complex;5const Complex = cmath.Complex;
...@@ -17,6 +17,6 @@ test "complex.cpow" {...@@ -17,6 +17,6 @@ test "complex.cpow" {
17 const b = Complex(f32).new(2.3, -1.3);17 const b = Complex(f32).new(2.3, -1.3);
18 const c = pow(Complex(f32), a, b);18 const c = pow(Complex(f32), a, b);
1919
20 debug.assert(math.approxEq(f32, c.re, 58.049110, epsilon));20 testing.expect(math.approxEq(f32, c.re, 58.049110, epsilon));
21 debug.assert(math.approxEq(f32, c.im, -101.003433, epsilon));21 testing.expect(math.approxEq(f32, c.im, -101.003433, epsilon));
22}22}
std/math/complex/proj.zig+2-2
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("../../index.zig");1const std = @import("../../index.zig");
2const debug = std.debug;2const testing = std.testing;
3const math = std.math;3const math = std.math;
4const cmath = math.complex;4const cmath = math.complex;
5const Complex = cmath.Complex;5const Complex = cmath.Complex;
...@@ -20,5 +20,5 @@ test "complex.cproj" {...@@ -20,5 +20,5 @@ test "complex.cproj" {
20 const a = Complex(f32).new(5, 3);20 const a = Complex(f32).new(5, 3);
21 const c = proj(a);21 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);
24}24}
std/math/complex/sin.zig+3-3
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("../../index.zig");1const std = @import("../../index.zig");
2const debug = std.debug;2const testing = std.testing;
3const math = std.math;3const math = std.math;
4const cmath = math.complex;4const cmath = math.complex;
5const Complex = cmath.Complex;5const Complex = cmath.Complex;
...@@ -17,6 +17,6 @@ test "complex.csin" {...@@ -17,6 +17,6 @@ test "complex.csin" {
17 const a = Complex(f32).new(5, 3);17 const a = Complex(f32).new(5, 3);
18 const c = sin(a);18 const c = sin(a);
1919
20 debug.assert(math.approxEq(f32, c.re, -9.654126, epsilon));20 testing.expect(math.approxEq(f32, c.re, -9.654126, epsilon));
21 debug.assert(math.approxEq(f32, c.im, 2.841692, epsilon));21 testing.expect(math.approxEq(f32, c.im, 2.841692, epsilon));
22}22}
std/math/complex/sinh.zig+5-5
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("../../index.zig");1const std = @import("../../index.zig");
2const debug = std.debug;2const testing = std.testing;
3const math = std.math;3const math = std.math;
4const cmath = math.complex;4const cmath = math.complex;
5const Complex = cmath.Complex;5const Complex = cmath.Complex;
...@@ -151,14 +151,14 @@ test "complex.csinh32" {...@@ -151,14 +151,14 @@ test "complex.csinh32" {
151 const a = Complex(f32).new(5, 3);151 const a = Complex(f32).new(5, 3);
152 const c = sinh(a);152 const c = sinh(a);
153153
154 debug.assert(math.approxEq(f32, c.re, -73.460617, epsilon));154 testing.expect(math.approxEq(f32, c.re, -73.460617, epsilon));
155 debug.assert(math.approxEq(f32, c.im, 10.472508, epsilon));155 testing.expect(math.approxEq(f32, c.im, 10.472508, epsilon));
156}156}
157157
158test "complex.csinh64" {158test "complex.csinh64" {
159 const a = Complex(f64).new(5, 3);159 const a = Complex(f64).new(5, 3);
160 const c = sinh(a);160 const c = sinh(a);
161161
162 debug.assert(math.approxEq(f64, c.re, -73.460617, epsilon));162 testing.expect(math.approxEq(f64, c.re, -73.460617, epsilon));
163 debug.assert(math.approxEq(f64, c.im, 10.472508, epsilon));163 testing.expect(math.approxEq(f64, c.im, 10.472508, epsilon));
164}164}
std/math/complex/sqrt.zig+5-5
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("../../index.zig");1const std = @import("../../index.zig");
2const debug = std.debug;2const testing = std.testing;
3const math = std.math;3const math = std.math;
4const cmath = math.complex;4const cmath = math.complex;
5const Complex = cmath.Complex;5const Complex = cmath.Complex;
...@@ -125,14 +125,14 @@ test "complex.csqrt32" {...@@ -125,14 +125,14 @@ test "complex.csqrt32" {
125 const a = Complex(f32).new(5, 3);125 const a = Complex(f32).new(5, 3);
126 const c = sqrt(a);126 const c = sqrt(a);
127127
128 debug.assert(math.approxEq(f32, c.re, 2.327117, epsilon));128 testing.expect(math.approxEq(f32, c.re, 2.327117, epsilon));
129 debug.assert(math.approxEq(f32, c.im, 0.644574, epsilon));129 testing.expect(math.approxEq(f32, c.im, 0.644574, epsilon));
130}130}
131131
132test "complex.csqrt64" {132test "complex.csqrt64" {
133 const a = Complex(f64).new(5, 3);133 const a = Complex(f64).new(5, 3);
134 const c = sqrt(a);134 const c = sqrt(a);
135135
136 debug.assert(math.approxEq(f64, c.re, 2.3271175190399496, epsilon));136 testing.expect(math.approxEq(f64, c.re, 2.3271175190399496, epsilon));
137 debug.assert(math.approxEq(f64, c.im, 0.6445742373246469, epsilon));137 testing.expect(math.approxEq(f64, c.im, 0.6445742373246469, epsilon));
138}138}
std/math/complex/tan.zig+3-3
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("../../index.zig");1const std = @import("../../index.zig");
2const debug = std.debug;2const testing = std.testing;
3const math = std.math;3const math = std.math;
4const cmath = math.complex;4const cmath = math.complex;
5const Complex = cmath.Complex;5const Complex = cmath.Complex;
...@@ -17,6 +17,6 @@ test "complex.ctan" {...@@ -17,6 +17,6 @@ test "complex.ctan" {
17 const a = Complex(f32).new(5, 3);17 const a = Complex(f32).new(5, 3);
18 const c = tan(a);18 const c = tan(a);
1919
20 debug.assert(math.approxEq(f32, c.re, -0.002708233, epsilon));20 testing.expect(math.approxEq(f32, c.re, -0.002708233, epsilon));
21 debug.assert(math.approxEq(f32, c.im, 1.004165, epsilon));21 testing.expect(math.approxEq(f32, c.im, 1.004165, epsilon));
22}22}
std/math/complex/tanh.zig+5-5
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("../../index.zig");1const std = @import("../../index.zig");
2const debug = std.debug;2const testing = std.testing;
3const math = std.math;3const math = std.math;
4const cmath = math.complex;4const cmath = math.complex;
5const Complex = cmath.Complex;5const Complex = cmath.Complex;
...@@ -100,14 +100,14 @@ test "complex.ctanh32" {...@@ -100,14 +100,14 @@ test "complex.ctanh32" {
100 const a = Complex(f32).new(5, 3);100 const a = Complex(f32).new(5, 3);
101 const c = tanh(a);101 const c = tanh(a);
102102
103 debug.assert(math.approxEq(f32, c.re, 0.999913, epsilon));103 testing.expect(math.approxEq(f32, c.re, 0.999913, epsilon));
104 debug.assert(math.approxEq(f32, c.im, -0.000025, epsilon));104 testing.expect(math.approxEq(f32, c.im, -0.000025, epsilon));
105}105}
106106
107test "complex.ctanh64" {107test "complex.ctanh64" {
108 const a = Complex(f64).new(5, 3);108 const a = Complex(f64).new(5, 3);
109 const c = tanh(a);109 const c = tanh(a);
110110
111 debug.assert(math.approxEq(f64, c.re, 0.999913, epsilon));111 testing.expect(math.approxEq(f64, c.re, 0.999913, epsilon));
112 debug.assert(math.approxEq(f64, c.im, -0.000025, epsilon));112 testing.expect(math.approxEq(f64, c.im, -0.000025, epsilon));
113}113}
std/math/copysign.zig+16-16
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const std = @import("../index.zig");1const std = @import("../index.zig");
2const math = std.math;2const math = std.math;
3const assert = std.debug.assert;3const expect = std.testing.expect;
4const maxInt = std.math.maxInt;4const maxInt = std.math.maxInt;
55
6pub fn copysign(comptime T: type, x: T, y: T) T {6pub fn copysign(comptime T: type, x: T, y: T) T {
...@@ -40,28 +40,28 @@ fn copysign64(x: f64, y: f64) f64 {...@@ -40,28 +40,28 @@ fn copysign64(x: f64, y: f64) f64 {
40}40}
4141
42test "math.copysign" {42test "math.copysign" {
43 assert(copysign(f16, 1.0, 1.0) == copysign16(1.0, 1.0));43 expect(copysign(f16, 1.0, 1.0) == copysign16(1.0, 1.0));
44 assert(copysign(f32, 1.0, 1.0) == copysign32(1.0, 1.0));44 expect(copysign(f32, 1.0, 1.0) == copysign32(1.0, 1.0));
45 assert(copysign(f64, 1.0, 1.0) == copysign64(1.0, 1.0));45 expect(copysign(f64, 1.0, 1.0) == copysign64(1.0, 1.0));
46}46}
4747
48test "math.copysign16" {48test "math.copysign16" {
49 assert(copysign16(5.0, 1.0) == 5.0);49 expect(copysign16(5.0, 1.0) == 5.0);
50 assert(copysign16(5.0, -1.0) == -5.0);50 expect(copysign16(5.0, -1.0) == -5.0);
51 assert(copysign16(-5.0, -1.0) == -5.0);51 expect(copysign16(-5.0, -1.0) == -5.0);
52 assert(copysign16(-5.0, 1.0) == 5.0);52 expect(copysign16(-5.0, 1.0) == 5.0);
53}53}
5454
55test "math.copysign32" {55test "math.copysign32" {
56 assert(copysign32(5.0, 1.0) == 5.0);56 expect(copysign32(5.0, 1.0) == 5.0);
57 assert(copysign32(5.0, -1.0) == -5.0);57 expect(copysign32(5.0, -1.0) == -5.0);
58 assert(copysign32(-5.0, -1.0) == -5.0);58 expect(copysign32(-5.0, -1.0) == -5.0);
59 assert(copysign32(-5.0, 1.0) == 5.0);59 expect(copysign32(-5.0, 1.0) == 5.0);
60}60}
6161
62test "math.copysign64" {62test "math.copysign64" {
63 assert(copysign64(5.0, 1.0) == 5.0);63 expect(copysign64(5.0, 1.0) == 5.0);
64 assert(copysign64(5.0, -1.0) == -5.0);64 expect(copysign64(5.0, -1.0) == -5.0);
65 assert(copysign64(-5.0, -1.0) == -5.0);65 expect(copysign64(-5.0, -1.0) == -5.0);
66 assert(copysign64(-5.0, 1.0) == 5.0);66 expect(copysign64(-5.0, 1.0) == 5.0);
67}67}
std/math/cos.zig+21-21
...@@ -6,7 +6,7 @@...@@ -6,7 +6,7 @@
6const builtin = @import("builtin");6const builtin = @import("builtin");
7const std = @import("../index.zig");7const std = @import("../index.zig");
8const math = std.math;8const math = std.math;
9const assert = std.debug.assert;9const expect = std.testing.expect;
1010
11pub fn cos(x: var) @typeOf(x) {11pub fn cos(x: var) @typeOf(x) {
12 const T = @typeOf(x);12 const T = @typeOf(x);
...@@ -139,40 +139,40 @@ fn cos64(x_: f64) f64 {...@@ -139,40 +139,40 @@ fn cos64(x_: f64) f64 {
139}139}
140140
141test "math.cos" {141test "math.cos" {
142 assert(cos(f32(0.0)) == cos32(0.0));142 expect(cos(f32(0.0)) == cos32(0.0));
143 assert(cos(f64(0.0)) == cos64(0.0));143 expect(cos(f64(0.0)) == cos64(0.0));
144}144}
145145
146test "math.cos32" {146test "math.cos32" {
147 const epsilon = 0.000001;147 const epsilon = 0.000001;
148148
149 assert(math.approxEq(f32, cos32(0.0), 1.0, epsilon));149 expect(math.approxEq(f32, cos32(0.0), 1.0, epsilon));
150 assert(math.approxEq(f32, cos32(0.2), 0.980067, epsilon));150 expect(math.approxEq(f32, cos32(0.2), 0.980067, epsilon));
151 assert(math.approxEq(f32, cos32(0.8923), 0.627623, epsilon));151 expect(math.approxEq(f32, cos32(0.8923), 0.627623, epsilon));
152 assert(math.approxEq(f32, cos32(1.5), 0.070737, epsilon));152 expect(math.approxEq(f32, cos32(1.5), 0.070737, epsilon));
153 assert(math.approxEq(f32, cos32(37.45), 0.969132, epsilon));153 expect(math.approxEq(f32, cos32(37.45), 0.969132, epsilon));
154 assert(math.approxEq(f32, cos32(89.123), 0.400798, epsilon));154 expect(math.approxEq(f32, cos32(89.123), 0.400798, epsilon));
155}155}
156156
157test "math.cos64" {157test "math.cos64" {
158 const epsilon = 0.000001;158 const epsilon = 0.000001;
159159
160 assert(math.approxEq(f64, cos64(0.0), 1.0, epsilon));160 expect(math.approxEq(f64, cos64(0.0), 1.0, epsilon));
161 assert(math.approxEq(f64, cos64(0.2), 0.980067, epsilon));161 expect(math.approxEq(f64, cos64(0.2), 0.980067, epsilon));
162 assert(math.approxEq(f64, cos64(0.8923), 0.627623, epsilon));162 expect(math.approxEq(f64, cos64(0.8923), 0.627623, epsilon));
163 assert(math.approxEq(f64, cos64(1.5), 0.070737, epsilon));163 expect(math.approxEq(f64, cos64(1.5), 0.070737, epsilon));
164 assert(math.approxEq(f64, cos64(37.45), 0.969132, epsilon));164 expect(math.approxEq(f64, cos64(37.45), 0.969132, epsilon));
165 assert(math.approxEq(f64, cos64(89.123), 0.40080, epsilon));165 expect(math.approxEq(f64, cos64(89.123), 0.40080, epsilon));
166}166}
167167
168test "math.cos32.special" {168test "math.cos32.special" {
169 assert(math.isNan(cos32(math.inf(f32))));169 expect(math.isNan(cos32(math.inf(f32))));
170 assert(math.isNan(cos32(-math.inf(f32))));170 expect(math.isNan(cos32(-math.inf(f32))));
171 assert(math.isNan(cos32(math.nan(f32))));171 expect(math.isNan(cos32(math.nan(f32))));
172}172}
173173
174test "math.cos64.special" {174test "math.cos64.special" {
175 assert(math.isNan(cos64(math.inf(f64))));175 expect(math.isNan(cos64(math.inf(f64))));
176 assert(math.isNan(cos64(-math.inf(f64))));176 expect(math.isNan(cos64(-math.inf(f64))));
177 assert(math.isNan(cos64(math.nan(f64))));177 expect(math.isNan(cos64(math.nan(f64))));
178}178}
std/math/cosh.zig+21-21
...@@ -8,7 +8,7 @@ const builtin = @import("builtin");...@@ -8,7 +8,7 @@ const builtin = @import("builtin");
8const std = @import("../index.zig");8const std = @import("../index.zig");
9const math = std.math;9const math = std.math;
10const expo2 = @import("expo2.zig").expo2;10const expo2 = @import("expo2.zig").expo2;
11const assert = std.debug.assert;11const expect = std.testing.expect;
12const maxInt = std.math.maxInt;12const maxInt = std.math.maxInt;
1313
14pub fn cosh(x: var) @typeOf(x) {14pub fn cosh(x: var) @typeOf(x) {
...@@ -82,40 +82,40 @@ fn cosh64(x: f64) f64 {...@@ -82,40 +82,40 @@ fn cosh64(x: f64) f64 {
82}82}
8383
84test "math.cosh" {84test "math.cosh" {
85 assert(cosh(f32(1.5)) == cosh32(1.5));85 expect(cosh(f32(1.5)) == cosh32(1.5));
86 assert(cosh(f64(1.5)) == cosh64(1.5));86 expect(cosh(f64(1.5)) == cosh64(1.5));
87}87}
8888
89test "math.cosh32" {89test "math.cosh32" {
90 const epsilon = 0.000001;90 const epsilon = 0.000001;
9191
92 assert(math.approxEq(f32, cosh32(0.0), 1.0, epsilon));92 expect(math.approxEq(f32, cosh32(0.0), 1.0, epsilon));
93 assert(math.approxEq(f32, cosh32(0.2), 1.020067, epsilon));93 expect(math.approxEq(f32, cosh32(0.2), 1.020067, epsilon));
94 assert(math.approxEq(f32, cosh32(0.8923), 1.425225, epsilon));94 expect(math.approxEq(f32, cosh32(0.8923), 1.425225, epsilon));
95 assert(math.approxEq(f32, cosh32(1.5), 2.352410, epsilon));95 expect(math.approxEq(f32, cosh32(1.5), 2.352410, epsilon));
96}96}
9797
98test "math.cosh64" {98test "math.cosh64" {
99 const epsilon = 0.000001;99 const epsilon = 0.000001;
100100
101 assert(math.approxEq(f64, cosh64(0.0), 1.0, epsilon));101 expect(math.approxEq(f64, cosh64(0.0), 1.0, epsilon));
102 assert(math.approxEq(f64, cosh64(0.2), 1.020067, epsilon));102 expect(math.approxEq(f64, cosh64(0.2), 1.020067, epsilon));
103 assert(math.approxEq(f64, cosh64(0.8923), 1.425225, epsilon));103 expect(math.approxEq(f64, cosh64(0.8923), 1.425225, epsilon));
104 assert(math.approxEq(f64, cosh64(1.5), 2.352410, epsilon));104 expect(math.approxEq(f64, cosh64(1.5), 2.352410, epsilon));
105}105}
106106
107test "math.cosh32.special" {107test "math.cosh32.special" {
108 assert(cosh32(0.0) == 1.0);108 expect(cosh32(0.0) == 1.0);
109 assert(cosh32(-0.0) == 1.0);109 expect(cosh32(-0.0) == 1.0);
110 assert(math.isPositiveInf(cosh32(math.inf(f32))));110 expect(math.isPositiveInf(cosh32(math.inf(f32))));
111 assert(math.isPositiveInf(cosh32(-math.inf(f32))));111 expect(math.isPositiveInf(cosh32(-math.inf(f32))));
112 assert(math.isNan(cosh32(math.nan(f32))));112 expect(math.isNan(cosh32(math.nan(f32))));
113}113}
114114
115test "math.cosh64.special" {115test "math.cosh64.special" {
116 assert(cosh64(0.0) == 1.0);116 expect(cosh64(0.0) == 1.0);
117 assert(cosh64(-0.0) == 1.0);117 expect(cosh64(-0.0) == 1.0);
118 assert(math.isPositiveInf(cosh64(math.inf(f64))));118 expect(math.isPositiveInf(cosh64(math.inf(f64))));
119 assert(math.isPositiveInf(cosh64(-math.inf(f64))));119 expect(math.isPositiveInf(cosh64(-math.inf(f64))));
120 assert(math.isNan(cosh64(math.nan(f64))));120 expect(math.isNan(cosh64(math.nan(f64))));
121}121}
std/math/exp2.zig+16-16
...@@ -5,7 +5,7 @@...@@ -5,7 +5,7 @@
55
6const std = @import("../index.zig");6const std = @import("../index.zig");
7const math = std.math;7const math = std.math;
8const assert = std.debug.assert;8const expect = std.testing.expect;
99
10pub fn exp2(x: var) @typeOf(x) {10pub fn exp2(x: var) @typeOf(x) {
11 const T = @typeOf(x);11 const T = @typeOf(x);
...@@ -415,35 +415,35 @@ fn exp2_64(x: f64) f64 {...@@ -415,35 +415,35 @@ fn exp2_64(x: f64) f64 {
415}415}
416416
417test "math.exp2" {417test "math.exp2" {
418 assert(exp2(f32(0.8923)) == exp2_32(0.8923));418 expect(exp2(f32(0.8923)) == exp2_32(0.8923));
419 assert(exp2(f64(0.8923)) == exp2_64(0.8923));419 expect(exp2(f64(0.8923)) == exp2_64(0.8923));
420}420}
421421
422test "math.exp2_32" {422test "math.exp2_32" {
423 const epsilon = 0.000001;423 const epsilon = 0.000001;
424424
425 assert(exp2_32(0.0) == 1.0);425 expect(exp2_32(0.0) == 1.0);
426 assert(math.approxEq(f32, exp2_32(0.2), 1.148698, epsilon));426 expect(math.approxEq(f32, exp2_32(0.2), 1.148698, epsilon));
427 assert(math.approxEq(f32, exp2_32(0.8923), 1.856133, epsilon));427 expect(math.approxEq(f32, exp2_32(0.8923), 1.856133, epsilon));
428 assert(math.approxEq(f32, exp2_32(1.5), 2.828427, epsilon));428 expect(math.approxEq(f32, exp2_32(1.5), 2.828427, epsilon));
429 assert(math.approxEq(f32, exp2_32(37.45), 187747237888, epsilon));429 expect(math.approxEq(f32, exp2_32(37.45), 187747237888, epsilon));
430}430}
431431
432test "math.exp2_64" {432test "math.exp2_64" {
433 const epsilon = 0.000001;433 const epsilon = 0.000001;
434434
435 assert(exp2_64(0.0) == 1.0);435 expect(exp2_64(0.0) == 1.0);
436 assert(math.approxEq(f64, exp2_64(0.2), 1.148698, epsilon));436 expect(math.approxEq(f64, exp2_64(0.2), 1.148698, epsilon));
437 assert(math.approxEq(f64, exp2_64(0.8923), 1.856133, epsilon));437 expect(math.approxEq(f64, exp2_64(0.8923), 1.856133, epsilon));
438 assert(math.approxEq(f64, exp2_64(1.5), 2.828427, epsilon));438 expect(math.approxEq(f64, exp2_64(1.5), 2.828427, epsilon));
439}439}
440440
441test "math.exp2_32.special" {441test "math.exp2_32.special" {
442 assert(math.isPositiveInf(exp2_32(math.inf(f32))));442 expect(math.isPositiveInf(exp2_32(math.inf(f32))));
443 assert(math.isNan(exp2_32(math.nan(f32))));443 expect(math.isNan(exp2_32(math.nan(f32))));
444}444}
445445
446test "math.exp2_64.special" {446test "math.exp2_64.special" {
447 assert(math.isPositiveInf(exp2_64(math.inf(f64))));447 expect(math.isPositiveInf(exp2_64(math.inf(f64))));
448 assert(math.isNan(exp2_64(math.nan(f64))));448 expect(math.isNan(exp2_64(math.nan(f64))));
449}449}
std/math/expm1.zig+19-19
...@@ -7,7 +7,7 @@...@@ -7,7 +7,7 @@
7const builtin = @import("builtin");7const builtin = @import("builtin");
8const std = @import("../index.zig");8const std = @import("../index.zig");
9const math = std.math;9const math = std.math;
10const assert = std.debug.assert;10const expect = std.testing.expect;
1111
12pub fn expm1(x: var) @typeOf(x) {12pub fn expm1(x: var) @typeOf(x) {
13 const T = @typeOf(x);13 const T = @typeOf(x);
...@@ -278,42 +278,42 @@ fn expm1_64(x_: f64) f64 {...@@ -278,42 +278,42 @@ fn expm1_64(x_: f64) f64 {
278}278}
279279
280test "math.exp1m" {280test "math.exp1m" {
281 assert(expm1(f32(0.0)) == expm1_32(0.0));281 expect(expm1(f32(0.0)) == expm1_32(0.0));
282 assert(expm1(f64(0.0)) == expm1_64(0.0));282 expect(expm1(f64(0.0)) == expm1_64(0.0));
283}283}
284284
285test "math.expm1_32" {285test "math.expm1_32" {
286 const epsilon = 0.000001;286 const epsilon = 0.000001;
287287
288 assert(expm1_32(0.0) == 0.0);288 expect(expm1_32(0.0) == 0.0);
289 assert(math.approxEq(f32, expm1_32(0.0), 0.0, epsilon));289 expect(math.approxEq(f32, expm1_32(0.0), 0.0, epsilon));
290 assert(math.approxEq(f32, expm1_32(0.2), 0.221403, epsilon));290 expect(math.approxEq(f32, expm1_32(0.2), 0.221403, epsilon));
291 assert(math.approxEq(f32, expm1_32(0.8923), 1.440737, epsilon));291 expect(math.approxEq(f32, expm1_32(0.8923), 1.440737, epsilon));
292 assert(math.approxEq(f32, expm1_32(1.5), 3.481689, epsilon));292 expect(math.approxEq(f32, expm1_32(1.5), 3.481689, epsilon));
293}293}
294294
295test "math.expm1_64" {295test "math.expm1_64" {
296 const epsilon = 0.000001;296 const epsilon = 0.000001;
297297
298 assert(expm1_64(0.0) == 0.0);298 expect(expm1_64(0.0) == 0.0);
299 assert(math.approxEq(f64, expm1_64(0.0), 0.0, epsilon));299 expect(math.approxEq(f64, expm1_64(0.0), 0.0, epsilon));
300 assert(math.approxEq(f64, expm1_64(0.2), 0.221403, epsilon));300 expect(math.approxEq(f64, expm1_64(0.2), 0.221403, epsilon));
301 assert(math.approxEq(f64, expm1_64(0.8923), 1.440737, epsilon));301 expect(math.approxEq(f64, expm1_64(0.8923), 1.440737, epsilon));
302 assert(math.approxEq(f64, expm1_64(1.5), 3.481689, epsilon));302 expect(math.approxEq(f64, expm1_64(1.5), 3.481689, epsilon));
303}303}
304304
305test "math.expm1_32.special" {305test "math.expm1_32.special" {
306 const epsilon = 0.000001;306 const epsilon = 0.000001;
307307
308 assert(math.isPositiveInf(expm1_32(math.inf(f32))));308 expect(math.isPositiveInf(expm1_32(math.inf(f32))));
309 assert(expm1_32(-math.inf(f32)) == -1.0);309 expect(expm1_32(-math.inf(f32)) == -1.0);
310 assert(math.isNan(expm1_32(math.nan(f32))));310 expect(math.isNan(expm1_32(math.nan(f32))));
311}311}
312312
313test "math.expm1_64.special" {313test "math.expm1_64.special" {
314 const epsilon = 0.000001;314 const epsilon = 0.000001;
315315
316 assert(math.isPositiveInf(expm1_64(math.inf(f64))));316 expect(math.isPositiveInf(expm1_64(math.inf(f64))));
317 assert(expm1_64(-math.inf(f64)) == -1.0);317 expect(expm1_64(-math.inf(f64)) == -1.0);
318 assert(math.isNan(expm1_64(math.nan(f64))));318 expect(math.isNan(expm1_64(math.nan(f64))));
319}319}
std/math/fabs.zig+19-19
...@@ -5,7 +5,7 @@...@@ -5,7 +5,7 @@
55
6const std = @import("../index.zig");6const std = @import("../index.zig");
7const math = std.math;7const math = std.math;
8const assert = std.debug.assert;8const expect = std.testing.expect;
9const maxInt = std.math.maxInt;9const maxInt = std.math.maxInt;
1010
11pub fn fabs(x: var) @typeOf(x) {11pub fn fabs(x: var) @typeOf(x) {
...@@ -37,40 +37,40 @@ fn fabs64(x: f64) f64 {...@@ -37,40 +37,40 @@ fn fabs64(x: f64) f64 {
37}37}
3838
39test "math.fabs" {39test "math.fabs" {
40 assert(fabs(f16(1.0)) == fabs16(1.0));40 expect(fabs(f16(1.0)) == fabs16(1.0));
41 assert(fabs(f32(1.0)) == fabs32(1.0));41 expect(fabs(f32(1.0)) == fabs32(1.0));
42 assert(fabs(f64(1.0)) == fabs64(1.0));42 expect(fabs(f64(1.0)) == fabs64(1.0));
43}43}
4444
45test "math.fabs16" {45test "math.fabs16" {
46 assert(fabs16(1.0) == 1.0);46 expect(fabs16(1.0) == 1.0);
47 assert(fabs16(-1.0) == 1.0);47 expect(fabs16(-1.0) == 1.0);
48}48}
4949
50test "math.fabs32" {50test "math.fabs32" {
51 assert(fabs32(1.0) == 1.0);51 expect(fabs32(1.0) == 1.0);
52 assert(fabs32(-1.0) == 1.0);52 expect(fabs32(-1.0) == 1.0);
53}53}
5454
55test "math.fabs64" {55test "math.fabs64" {
56 assert(fabs64(1.0) == 1.0);56 expect(fabs64(1.0) == 1.0);
57 assert(fabs64(-1.0) == 1.0);57 expect(fabs64(-1.0) == 1.0);
58}58}
5959
60test "math.fabs16.special" {60test "math.fabs16.special" {
61 assert(math.isPositiveInf(fabs(math.inf(f16))));61 expect(math.isPositiveInf(fabs(math.inf(f16))));
62 assert(math.isPositiveInf(fabs(-math.inf(f16))));62 expect(math.isPositiveInf(fabs(-math.inf(f16))));
63 assert(math.isNan(fabs(math.nan(f16))));63 expect(math.isNan(fabs(math.nan(f16))));
64}64}
6565
66test "math.fabs32.special" {66test "math.fabs32.special" {
67 assert(math.isPositiveInf(fabs(math.inf(f32))));67 expect(math.isPositiveInf(fabs(math.inf(f32))));
68 assert(math.isPositiveInf(fabs(-math.inf(f32))));68 expect(math.isPositiveInf(fabs(-math.inf(f32))));
69 assert(math.isNan(fabs(math.nan(f32))));69 expect(math.isNan(fabs(math.nan(f32))));
70}70}
7171
72test "math.fabs64.special" {72test "math.fabs64.special" {
73 assert(math.isPositiveInf(fabs(math.inf(f64))));73 expect(math.isPositiveInf(fabs(math.inf(f64))));
74 assert(math.isPositiveInf(fabs(-math.inf(f64))));74 expect(math.isPositiveInf(fabs(-math.inf(f64))));
75 assert(math.isNan(fabs(math.nan(f64))));75 expect(math.isNan(fabs(math.nan(f64))));
76}76}
std/math/floor.zig+28-28
...@@ -5,7 +5,7 @@...@@ -5,7 +5,7 @@
5// - floor(nan) = nan5// - floor(nan) = nan
66
7const builtin = @import("builtin");7const builtin = @import("builtin");
8const assert = std.debug.assert;8const expect = std.testing.expect;
9const std = @import("../index.zig");9const std = @import("../index.zig");
10const math = std.math;10const math = std.math;
1111
...@@ -117,49 +117,49 @@ fn floor64(x: f64) f64 {...@@ -117,49 +117,49 @@ fn floor64(x: f64) f64 {
117}117}
118118
119test "math.floor" {119test "math.floor" {
120 assert(floor(f16(1.3)) == floor16(1.3));120 expect(floor(f16(1.3)) == floor16(1.3));
121 assert(floor(f32(1.3)) == floor32(1.3));121 expect(floor(f32(1.3)) == floor32(1.3));
122 assert(floor(f64(1.3)) == floor64(1.3));122 expect(floor(f64(1.3)) == floor64(1.3));
123}123}
124124
125test "math.floor16" {125test "math.floor16" {
126 assert(floor16(1.3) == 1.0);126 expect(floor16(1.3) == 1.0);
127 assert(floor16(-1.3) == -2.0);127 expect(floor16(-1.3) == -2.0);
128 assert(floor16(0.2) == 0.0);128 expect(floor16(0.2) == 0.0);
129}129}
130130
131test "math.floor32" {131test "math.floor32" {
132 assert(floor32(1.3) == 1.0);132 expect(floor32(1.3) == 1.0);
133 assert(floor32(-1.3) == -2.0);133 expect(floor32(-1.3) == -2.0);
134 assert(floor32(0.2) == 0.0);134 expect(floor32(0.2) == 0.0);
135}135}
136136
137test "math.floor64" {137test "math.floor64" {
138 assert(floor64(1.3) == 1.0);138 expect(floor64(1.3) == 1.0);
139 assert(floor64(-1.3) == -2.0);139 expect(floor64(-1.3) == -2.0);
140 assert(floor64(0.2) == 0.0);140 expect(floor64(0.2) == 0.0);
141}141}
142142
143test "math.floor16.special" {143test "math.floor16.special" {
144 assert(floor16(0.0) == 0.0);144 expect(floor16(0.0) == 0.0);
145 assert(floor16(-0.0) == -0.0);145 expect(floor16(-0.0) == -0.0);
146 assert(math.isPositiveInf(floor16(math.inf(f16))));146 expect(math.isPositiveInf(floor16(math.inf(f16))));
147 assert(math.isNegativeInf(floor16(-math.inf(f16))));147 expect(math.isNegativeInf(floor16(-math.inf(f16))));
148 assert(math.isNan(floor16(math.nan(f16))));148 expect(math.isNan(floor16(math.nan(f16))));
149}149}
150150
151test "math.floor32.special" {151test "math.floor32.special" {
152 assert(floor32(0.0) == 0.0);152 expect(floor32(0.0) == 0.0);
153 assert(floor32(-0.0) == -0.0);153 expect(floor32(-0.0) == -0.0);
154 assert(math.isPositiveInf(floor32(math.inf(f32))));154 expect(math.isPositiveInf(floor32(math.inf(f32))));
155 assert(math.isNegativeInf(floor32(-math.inf(f32))));155 expect(math.isNegativeInf(floor32(-math.inf(f32))));
156 assert(math.isNan(floor32(math.nan(f32))));156 expect(math.isNan(floor32(math.nan(f32))));
157}157}
158158
159test "math.floor64.special" {159test "math.floor64.special" {
160 assert(floor64(0.0) == 0.0);160 expect(floor64(0.0) == 0.0);
161 assert(floor64(-0.0) == -0.0);161 expect(floor64(-0.0) == -0.0);
162 assert(math.isPositiveInf(floor64(math.inf(f64))));162 expect(math.isPositiveInf(floor64(math.inf(f64))));
163 assert(math.isNegativeInf(floor64(-math.inf(f64))));163 expect(math.isNegativeInf(floor64(-math.inf(f64))));
164 assert(math.isNan(floor64(math.nan(f64))));164 expect(math.isNan(floor64(math.nan(f64))));
165}165}
std/math/fma.zig+17-17
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const std = @import("../index.zig");1const std = @import("../index.zig");
2const math = std.math;2const math = std.math;
3const assert = std.debug.assert;3const expect = std.testing.expect;
44
5pub fn fma(comptime T: type, x: T, y: T, z: T) T {5pub fn fma(comptime T: type, x: T, y: T, z: T) T {
6 return switch (T) {6 return switch (T) {
...@@ -135,30 +135,30 @@ fn add_and_denorm(a: f64, b: f64, scale: i32) f64 {...@@ -135,30 +135,30 @@ fn add_and_denorm(a: f64, b: f64, scale: i32) f64 {
135}135}
136136
137test "math.fma" {137test "math.fma" {
138 assert(fma(f32, 0.0, 1.0, 1.0) == fma32(0.0, 1.0, 1.0));138 expect(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));139 expect(fma(f64, 0.0, 1.0, 1.0) == fma64(0.0, 1.0, 1.0));
140}140}
141141
142test "math.fma32" {142test "math.fma32" {
143 const epsilon = 0.000001;143 const epsilon = 0.000001;
144144
145 assert(math.approxEq(f32, fma32(0.0, 5.0, 9.124), 9.124, epsilon));145 expect(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));146 expect(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));147 expect(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));148 expect(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));149 expect(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));150 expect(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));151 expect(math.approxEq(f32, fma32(123123.234375, 5.0, 9.124), 615625.295875, epsilon));
152}152}
153153
154test "math.fma64" {154test "math.fma64" {
155 const epsilon = 0.000001;155 const epsilon = 0.000001;
156156
157 assert(math.approxEq(f64, fma64(0.0, 5.0, 9.124), 9.124, epsilon));157 expect(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));158 expect(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));159 expect(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));160 expect(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));161 expect(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));162 expect(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));163 expect(math.approxEq(f64, fma64(123123.234375, 5.0, 9.124), 615625.295875, epsilon));
164}164}
std/math/frexp.zig+17-17
...@@ -6,7 +6,7 @@...@@ -6,7 +6,7 @@
66
7const std = @import("../index.zig");7const std = @import("../index.zig");
8const math = std.math;8const math = std.math;
9const assert = std.debug.assert;9const expect = std.testing.expect;
1010
11fn frexp_result(comptime T: type) type {11fn frexp_result(comptime T: type) type {
12 return struct {12 return struct {
...@@ -103,11 +103,11 @@ fn frexp64(x: f64) frexp64_result {...@@ -103,11 +103,11 @@ fn frexp64(x: f64) frexp64_result {
103test "math.frexp" {103test "math.frexp" {
104 const a = frexp(f32(1.3));104 const a = frexp(f32(1.3));
105 const b = frexp32(1.3);105 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
108 const c = frexp(f64(1.3));108 const c = frexp(f64(1.3));
109 const d = frexp64(1.3);109 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);
111}111}
112112
113test "math.frexp32" {113test "math.frexp32" {
...@@ -115,10 +115,10 @@ test "math.frexp32" {...@@ -115,10 +115,10 @@ test "math.frexp32" {
115 var r: frexp32_result = undefined;115 var r: frexp32_result = undefined;
116116
117 r = frexp32(1.3);117 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
120 r = frexp32(78.0234);120 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);
122}122}
123123
124test "math.frexp64" {124test "math.frexp64" {
...@@ -126,46 +126,46 @@ test "math.frexp64" {...@@ -126,46 +126,46 @@ test "math.frexp64" {
126 var r: frexp64_result = undefined;126 var r: frexp64_result = undefined;
127127
128 r = frexp64(1.3);128 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
131 r = frexp64(78.0234);131 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);
133}133}
134134
135test "math.frexp32.special" {135test "math.frexp32.special" {
136 var r: frexp32_result = undefined;136 var r: frexp32_result = undefined;
137137
138 r = frexp32(0.0);138 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
141 r = frexp32(-0.0);141 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
144 r = frexp32(math.inf(f32));144 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
147 r = frexp32(-math.inf(f32));147 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
150 r = frexp32(math.nan(f32));150 r = frexp32(math.nan(f32));
151 assert(math.isNan(r.significand));151 expect(math.isNan(r.significand));
152}152}
153153
154test "math.frexp64.special" {154test "math.frexp64.special" {
155 var r: frexp64_result = undefined;155 var r: frexp64_result = undefined;
156156
157 r = frexp64(0.0);157 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
160 r = frexp64(-0.0);160 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
163 r = frexp64(math.inf(f64));163 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
166 r = frexp64(-math.inf(f64));166 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
169 r = frexp64(math.nan(f64));169 r = frexp64(math.nan(f64));
170 assert(math.isNan(r.significand));170 expect(math.isNan(r.significand));
171}171}
std/math/hypot.zig+29-29
...@@ -7,7 +7,7 @@...@@ -7,7 +7,7 @@
77
8const std = @import("../index.zig");8const std = @import("../index.zig");
9const math = std.math;9const math = std.math;
10const assert = std.debug.assert;10const expect = std.testing.expect;
11const maxInt = std.math.maxInt;11const maxInt = std.math.maxInt;
1212
13pub fn hypot(comptime T: type, x: T, y: T) T {13pub fn hypot(comptime T: type, x: T, y: T) T {
...@@ -115,48 +115,48 @@ fn hypot64(x: f64, y: f64) f64 {...@@ -115,48 +115,48 @@ fn hypot64(x: f64, y: f64) f64 {
115}115}
116116
117test "math.hypot" {117test "math.hypot" {
118 assert(hypot(f32, 0.0, -1.2) == hypot32(0.0, -1.2));118 expect(hypot(f32, 0.0, -1.2) == hypot32(0.0, -1.2));
119 assert(hypot(f64, 0.0, -1.2) == hypot64(0.0, -1.2));119 expect(hypot(f64, 0.0, -1.2) == hypot64(0.0, -1.2));
120}120}
121121
122test "math.hypot32" {122test "math.hypot32" {
123 const epsilon = 0.000001;123 const epsilon = 0.000001;
124124
125 assert(math.approxEq(f32, hypot32(0.0, -1.2), 1.2, epsilon));125 expect(math.approxEq(f32, hypot32(0.0, -1.2), 1.2, epsilon));
126 assert(math.approxEq(f32, hypot32(0.2, -0.34), 0.394462, epsilon));126 expect(math.approxEq(f32, hypot32(0.2, -0.34), 0.394462, epsilon));
127 assert(math.approxEq(f32, hypot32(0.8923, 2.636890), 2.783772, epsilon));127 expect(math.approxEq(f32, hypot32(0.8923, 2.636890), 2.783772, epsilon));
128 assert(math.approxEq(f32, hypot32(1.5, 5.25), 5.460083, epsilon));128 expect(math.approxEq(f32, hypot32(1.5, 5.25), 5.460083, epsilon));
129 assert(math.approxEq(f32, hypot32(37.45, 159.835), 164.163742, epsilon));129 expect(math.approxEq(f32, hypot32(37.45, 159.835), 164.163742, epsilon));
130 assert(math.approxEq(f32, hypot32(89.123, 382.028905), 392.286865, epsilon));130 expect(math.approxEq(f32, hypot32(89.123, 382.028905), 392.286865, epsilon));
131 assert(math.approxEq(f32, hypot32(123123.234375, 529428.707813), 543556.875, epsilon));131 expect(math.approxEq(f32, hypot32(123123.234375, 529428.707813), 543556.875, epsilon));
132}132}
133133
134test "math.hypot64" {134test "math.hypot64" {
135 const epsilon = 0.000001;135 const epsilon = 0.000001;
136136
137 assert(math.approxEq(f64, hypot64(0.0, -1.2), 1.2, epsilon));137 expect(math.approxEq(f64, hypot64(0.0, -1.2), 1.2, epsilon));
138 assert(math.approxEq(f64, hypot64(0.2, -0.34), 0.394462, epsilon));138 expect(math.approxEq(f64, hypot64(0.2, -0.34), 0.394462, epsilon));
139 assert(math.approxEq(f64, hypot64(0.8923, 2.636890), 2.783772, epsilon));139 expect(math.approxEq(f64, hypot64(0.8923, 2.636890), 2.783772, epsilon));
140 assert(math.approxEq(f64, hypot64(1.5, 5.25), 5.460082, epsilon));140 expect(math.approxEq(f64, hypot64(1.5, 5.25), 5.460082, epsilon));
141 assert(math.approxEq(f64, hypot64(37.45, 159.835), 164.163728, epsilon));141 expect(math.approxEq(f64, hypot64(37.45, 159.835), 164.163728, epsilon));
142 assert(math.approxEq(f64, hypot64(89.123, 382.028905), 392.286876, epsilon));142 expect(math.approxEq(f64, hypot64(89.123, 382.028905), 392.286876, epsilon));
143 assert(math.approxEq(f64, hypot64(123123.234375, 529428.707813), 543556.885247, epsilon));143 expect(math.approxEq(f64, hypot64(123123.234375, 529428.707813), 543556.885247, epsilon));
144}144}
145145
146test "math.hypot32.special" {146test "math.hypot32.special" {
147 assert(math.isPositiveInf(hypot32(math.inf(f32), 0.0)));147 expect(math.isPositiveInf(hypot32(math.inf(f32), 0.0)));
148 assert(math.isPositiveInf(hypot32(-math.inf(f32), 0.0)));148 expect(math.isPositiveInf(hypot32(-math.inf(f32), 0.0)));
149 assert(math.isPositiveInf(hypot32(0.0, math.inf(f32))));149 expect(math.isPositiveInf(hypot32(0.0, math.inf(f32))));
150 assert(math.isPositiveInf(hypot32(0.0, -math.inf(f32))));150 expect(math.isPositiveInf(hypot32(0.0, -math.inf(f32))));
151 assert(math.isNan(hypot32(math.nan(f32), 0.0)));151 expect(math.isNan(hypot32(math.nan(f32), 0.0)));
152 assert(math.isNan(hypot32(0.0, math.nan(f32))));152 expect(math.isNan(hypot32(0.0, math.nan(f32))));
153}153}
154154
155test "math.hypot64.special" {155test "math.hypot64.special" {
156 assert(math.isPositiveInf(hypot64(math.inf(f64), 0.0)));156 expect(math.isPositiveInf(hypot64(math.inf(f64), 0.0)));
157 assert(math.isPositiveInf(hypot64(-math.inf(f64), 0.0)));157 expect(math.isPositiveInf(hypot64(-math.inf(f64), 0.0)));
158 assert(math.isPositiveInf(hypot64(0.0, math.inf(f64))));158 expect(math.isPositiveInf(hypot64(0.0, math.inf(f64))));
159 assert(math.isPositiveInf(hypot64(0.0, -math.inf(f64))));159 expect(math.isPositiveInf(hypot64(0.0, -math.inf(f64))));
160 assert(math.isNan(hypot64(math.nan(f64), 0.0)));160 expect(math.isNan(hypot64(math.nan(f64), 0.0)));
161 assert(math.isNan(hypot64(0.0, math.nan(f64))));161 expect(math.isNan(hypot64(0.0, math.nan(f64))));
162}162}
std/math/ilogb.zig+23-23
...@@ -6,7 +6,7 @@...@@ -6,7 +6,7 @@
66
7const std = @import("../index.zig");7const std = @import("../index.zig");
8const math = std.math;8const math = std.math;
9const assert = std.debug.assert;9const expect = std.testing.expect;
10const maxInt = std.math.maxInt;10const maxInt = std.math.maxInt;
11const minInt = std.math.minInt;11const minInt = std.math.minInt;
1212
...@@ -95,38 +95,38 @@ fn ilogb64(x: f64) i32 {...@@ -95,38 +95,38 @@ fn ilogb64(x: f64) i32 {
95}95}
9696
97test "math.ilogb" {97test "math.ilogb" {
98 assert(ilogb(f32(0.2)) == ilogb32(0.2));98 expect(ilogb(f32(0.2)) == ilogb32(0.2));
99 assert(ilogb(f64(0.2)) == ilogb64(0.2));99 expect(ilogb(f64(0.2)) == ilogb64(0.2));
100}100}
101101
102test "math.ilogb32" {102test "math.ilogb32" {
103 assert(ilogb32(0.0) == fp_ilogb0);103 expect(ilogb32(0.0) == fp_ilogb0);
104 assert(ilogb32(0.5) == -1);104 expect(ilogb32(0.5) == -1);
105 assert(ilogb32(0.8923) == -1);105 expect(ilogb32(0.8923) == -1);
106 assert(ilogb32(10.0) == 3);106 expect(ilogb32(10.0) == 3);
107 assert(ilogb32(-123984) == 16);107 expect(ilogb32(-123984) == 16);
108 assert(ilogb32(2398.23) == 11);108 expect(ilogb32(2398.23) == 11);
109}109}
110110
111test "math.ilogb64" {111test "math.ilogb64" {
112 assert(ilogb64(0.0) == fp_ilogb0);112 expect(ilogb64(0.0) == fp_ilogb0);
113 assert(ilogb64(0.5) == -1);113 expect(ilogb64(0.5) == -1);
114 assert(ilogb64(0.8923) == -1);114 expect(ilogb64(0.8923) == -1);
115 assert(ilogb64(10.0) == 3);115 expect(ilogb64(10.0) == 3);
116 assert(ilogb64(-123984) == 16);116 expect(ilogb64(-123984) == 16);
117 assert(ilogb64(2398.23) == 11);117 expect(ilogb64(2398.23) == 11);
118}118}
119119
120test "math.ilogb32.special" {120test "math.ilogb32.special" {
121 assert(ilogb32(math.inf(f32)) == maxInt(i32));121 expect(ilogb32(math.inf(f32)) == maxInt(i32));
122 assert(ilogb32(-math.inf(f32)) == maxInt(i32));122 expect(ilogb32(-math.inf(f32)) == maxInt(i32));
123 assert(ilogb32(0.0) == minInt(i32));123 expect(ilogb32(0.0) == minInt(i32));
124 assert(ilogb32(math.nan(f32)) == maxInt(i32));124 expect(ilogb32(math.nan(f32)) == maxInt(i32));
125}125}
126126
127test "math.ilogb64.special" {127test "math.ilogb64.special" {
128 assert(ilogb64(math.inf(f64)) == maxInt(i32));128 expect(ilogb64(math.inf(f64)) == maxInt(i32));
129 assert(ilogb64(-math.inf(f64)) == maxInt(i32));129 expect(ilogb64(-math.inf(f64)) == maxInt(i32));
130 assert(ilogb64(0.0) == minInt(i32));130 expect(ilogb64(0.0) == minInt(i32));
131 assert(ilogb64(math.nan(f64)) == maxInt(i32));131 expect(ilogb64(math.nan(f64)) == maxInt(i32));
132}132}
std/math/index.zig+172-171
...@@ -2,6 +2,7 @@ const builtin = @import("builtin");...@@ -2,6 +2,7 @@ const builtin = @import("builtin");
2const std = @import("../index.zig");2const std = @import("../index.zig");
3const TypeId = builtin.TypeId;3const TypeId = builtin.TypeId;
4const assert = std.debug.assert;4const assert = std.debug.assert;
5const testing = std.testing;
56
6pub const e = 2.71828182845904523536028747135266249775724709369995;7pub const e = 2.71828182845904523536028747135266249775724709369995;
7pub const pi = 3.14159265358979323846264338327950288419716939937510;8pub const pi = 3.14159265358979323846264338327950288419716939937510;
...@@ -240,7 +241,7 @@ pub fn min(x: var, y: var) @typeOf(x + y) {...@@ -240,7 +241,7 @@ pub fn min(x: var, y: var) @typeOf(x + y) {
240}241}
241242
242test "math.min" {243test "math.min" {
243 assert(min(i32(-1), i32(2)) == -1);244 testing.expect(min(i32(-1), i32(2)) == -1);
244}245}
245246
246pub fn max(x: var, y: var) @typeOf(x + y) {247pub fn max(x: var, y: var) @typeOf(x + y) {
...@@ -248,7 +249,7 @@ pub fn max(x: var, y: var) @typeOf(x + y) {...@@ -248,7 +249,7 @@ pub fn max(x: var, y: var) @typeOf(x + y) {
248}249}
249250
250test "math.max" {251test "math.max" {
251 assert(max(i32(-1), i32(2)) == 2);252 testing.expect(max(i32(-1), i32(2)) == 2);
252}253}
253254
254pub fn mul(comptime T: type, a: T, b: T) (error{Overflow}!T) {255pub 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 {...@@ -293,10 +294,10 @@ pub fn shl(comptime T: type, a: T, shift_amt: var) T {
293}294}
294295
295test "math.shl" {296test "math.shl" {
296 assert(shl(u8, 0b11111111, usize(3)) == 0b11111000);297 testing.expect(shl(u8, 0b11111111, usize(3)) == 0b11111000);
297 assert(shl(u8, 0b11111111, usize(8)) == 0);298 testing.expect(shl(u8, 0b11111111, usize(8)) == 0);
298 assert(shl(u8, 0b11111111, usize(9)) == 0);299 testing.expect(shl(u8, 0b11111111, usize(9)) == 0);
299 assert(shl(u8, 0b11111111, isize(-2)) == 0b00111111);300 testing.expect(shl(u8, 0b11111111, isize(-2)) == 0b00111111);
300}301}
301302
302/// Shifts right. Overflowed bits are truncated.303/// Shifts right. Overflowed bits are truncated.
...@@ -317,10 +318,10 @@ pub fn shr(comptime T: type, a: T, shift_amt: var) T {...@@ -317,10 +318,10 @@ pub fn shr(comptime T: type, a: T, shift_amt: var) T {
317}318}
318319
319test "math.shr" {320test "math.shr" {
320 assert(shr(u8, 0b11111111, usize(3)) == 0b00011111);321 testing.expect(shr(u8, 0b11111111, usize(3)) == 0b00011111);
321 assert(shr(u8, 0b11111111, usize(8)) == 0);322 testing.expect(shr(u8, 0b11111111, usize(8)) == 0);
322 assert(shr(u8, 0b11111111, usize(9)) == 0);323 testing.expect(shr(u8, 0b11111111, usize(9)) == 0);
323 assert(shr(u8, 0b11111111, isize(-2)) == 0b11111100);324 testing.expect(shr(u8, 0b11111111, isize(-2)) == 0b11111100);
324}325}
325326
326/// Rotates right. Only unsigned values can be rotated.327/// Rotates right. Only unsigned values can be rotated.
...@@ -335,11 +336,11 @@ pub fn rotr(comptime T: type, x: T, r: var) T {...@@ -335,11 +336,11 @@ pub fn rotr(comptime T: type, x: T, r: var) T {
335}336}
336337
337test "math.rotr" {338test "math.rotr" {
338 assert(rotr(u8, 0b00000001, usize(0)) == 0b00000001);339 testing.expect(rotr(u8, 0b00000001, usize(0)) == 0b00000001);
339 assert(rotr(u8, 0b00000001, usize(9)) == 0b10000000);340 testing.expect(rotr(u8, 0b00000001, usize(9)) == 0b10000000);
340 assert(rotr(u8, 0b00000001, usize(8)) == 0b00000001);341 testing.expect(rotr(u8, 0b00000001, usize(8)) == 0b00000001);
341 assert(rotr(u8, 0b00000001, usize(4)) == 0b00010000);342 testing.expect(rotr(u8, 0b00000001, usize(4)) == 0b00010000);
342 assert(rotr(u8, 0b00000001, isize(-1)) == 0b00000010);343 testing.expect(rotr(u8, 0b00000001, isize(-1)) == 0b00000010);
343}344}
344345
345/// Rotates left. Only unsigned values can be rotated.346/// Rotates left. Only unsigned values can be rotated.
...@@ -354,11 +355,11 @@ pub fn rotl(comptime T: type, x: T, r: var) T {...@@ -354,11 +355,11 @@ pub fn rotl(comptime T: type, x: T, r: var) T {
354}355}
355356
356test "math.rotl" {357test "math.rotl" {
357 assert(rotl(u8, 0b00000001, usize(0)) == 0b00000001);358 testing.expect(rotl(u8, 0b00000001, usize(0)) == 0b00000001);
358 assert(rotl(u8, 0b00000001, usize(9)) == 0b00000010);359 testing.expect(rotl(u8, 0b00000001, usize(9)) == 0b00000010);
359 assert(rotl(u8, 0b00000001, usize(8)) == 0b00000001);360 testing.expect(rotl(u8, 0b00000001, usize(8)) == 0b00000001);
360 assert(rotl(u8, 0b00000001, usize(4)) == 0b00010000);361 testing.expect(rotl(u8, 0b00000001, usize(4)) == 0b00010000);
361 assert(rotl(u8, 0b00000001, isize(-1)) == 0b10000000);362 testing.expect(rotl(u8, 0b00000001, isize(-1)) == 0b10000000);
362}363}
363364
364pub fn Log2Int(comptime T: type) type {365pub fn Log2Int(comptime T: type) type {
...@@ -389,50 +390,50 @@ pub fn IntFittingRange(comptime from: comptime_int, comptime to: comptime_int) t...@@ -389,50 +390,50 @@ pub fn IntFittingRange(comptime from: comptime_int, comptime to: comptime_int) t
389}390}
390391
391test "math.IntFittingRange" {392test "math.IntFittingRange" {
392 assert(IntFittingRange(0, 0) == u0);393 testing.expect(IntFittingRange(0, 0) == u0);
393 assert(IntFittingRange(0, 1) == u1);394 testing.expect(IntFittingRange(0, 1) == u1);
394 assert(IntFittingRange(0, 2) == u2);395 testing.expect(IntFittingRange(0, 2) == u2);
395 assert(IntFittingRange(0, 3) == u2);396 testing.expect(IntFittingRange(0, 3) == u2);
396 assert(IntFittingRange(0, 4) == u3);397 testing.expect(IntFittingRange(0, 4) == u3);
397 assert(IntFittingRange(0, 7) == u3);398 testing.expect(IntFittingRange(0, 7) == u3);
398 assert(IntFittingRange(0, 8) == u4);399 testing.expect(IntFittingRange(0, 8) == u4);
399 assert(IntFittingRange(0, 9) == u4);400 testing.expect(IntFittingRange(0, 9) == u4);
400 assert(IntFittingRange(0, 15) == u4);401 testing.expect(IntFittingRange(0, 15) == u4);
401 assert(IntFittingRange(0, 16) == u5);402 testing.expect(IntFittingRange(0, 16) == u5);
402 assert(IntFittingRange(0, 17) == u5);403 testing.expect(IntFittingRange(0, 17) == u5);
403 assert(IntFittingRange(0, 4095) == u12);404 testing.expect(IntFittingRange(0, 4095) == u12);
404 assert(IntFittingRange(2000, 4095) == u12);405 testing.expect(IntFittingRange(2000, 4095) == u12);
405 assert(IntFittingRange(0, 4096) == u13);406 testing.expect(IntFittingRange(0, 4096) == u13);
406 assert(IntFittingRange(2000, 4096) == u13);407 testing.expect(IntFittingRange(2000, 4096) == u13);
407 assert(IntFittingRange(0, 4097) == u13);408 testing.expect(IntFittingRange(0, 4097) == u13);
408 assert(IntFittingRange(2000, 4097) == u13);409 testing.expect(IntFittingRange(2000, 4097) == u13);
409 assert(IntFittingRange(0, 123456789123456798123456789) == u87);410 testing.expect(IntFittingRange(0, 123456789123456798123456789) == u87);
410 assert(IntFittingRange(0, 123456789123456798123456789123456789123456798123456789) == u177);411 testing.expect(IntFittingRange(0, 123456789123456798123456789123456789123456798123456789) == u177);
411412
412 assert(IntFittingRange(-1, -1) == i1);413 testing.expect(IntFittingRange(-1, -1) == i1);
413 assert(IntFittingRange(-1, 0) == i1);414 testing.expect(IntFittingRange(-1, 0) == i1);
414 assert(IntFittingRange(-1, 1) == i2);415 testing.expect(IntFittingRange(-1, 1) == i2);
415 assert(IntFittingRange(-2, -2) == i2);416 testing.expect(IntFittingRange(-2, -2) == i2);
416 assert(IntFittingRange(-2, -1) == i2);417 testing.expect(IntFittingRange(-2, -1) == i2);
417 assert(IntFittingRange(-2, 0) == i2);418 testing.expect(IntFittingRange(-2, 0) == i2);
418 assert(IntFittingRange(-2, 1) == i2);419 testing.expect(IntFittingRange(-2, 1) == i2);
419 assert(IntFittingRange(-2, 2) == i3);420 testing.expect(IntFittingRange(-2, 2) == i3);
420 assert(IntFittingRange(-1, 2) == i3);421 testing.expect(IntFittingRange(-1, 2) == i3);
421 assert(IntFittingRange(-1, 3) == i3);422 testing.expect(IntFittingRange(-1, 3) == i3);
422 assert(IntFittingRange(-1, 4) == i4);423 testing.expect(IntFittingRange(-1, 4) == i4);
423 assert(IntFittingRange(-1, 7) == i4);424 testing.expect(IntFittingRange(-1, 7) == i4);
424 assert(IntFittingRange(-1, 8) == i5);425 testing.expect(IntFittingRange(-1, 8) == i5);
425 assert(IntFittingRange(-1, 9) == i5);426 testing.expect(IntFittingRange(-1, 9) == i5);
426 assert(IntFittingRange(-1, 15) == i5);427 testing.expect(IntFittingRange(-1, 15) == i5);
427 assert(IntFittingRange(-1, 16) == i6);428 testing.expect(IntFittingRange(-1, 16) == i6);
428 assert(IntFittingRange(-1, 17) == i6);429 testing.expect(IntFittingRange(-1, 17) == i6);
429 assert(IntFittingRange(-1, 4095) == i13);430 testing.expect(IntFittingRange(-1, 4095) == i13);
430 assert(IntFittingRange(-4096, 4095) == i13);431 testing.expect(IntFittingRange(-4096, 4095) == i13);
431 assert(IntFittingRange(-1, 4096) == i14);432 testing.expect(IntFittingRange(-1, 4096) == i14);
432 assert(IntFittingRange(-4097, 4095) == i14);433 testing.expect(IntFittingRange(-4097, 4095) == i14);
433 assert(IntFittingRange(-1, 4097) == i14);434 testing.expect(IntFittingRange(-1, 4097) == i14);
434 assert(IntFittingRange(-1, 123456789123456798123456789) == i88);435 testing.expect(IntFittingRange(-1, 123456789123456798123456789) == i88);
435 assert(IntFittingRange(-1, 123456789123456798123456789123456789123456798123456789) == i178);436 testing.expect(IntFittingRange(-1, 123456789123456798123456789123456789123456798123456789) == i178);
436}437}
437438
438test "math overflow functions" {439test "math overflow functions" {
...@@ -441,10 +442,10 @@ test "math overflow functions" {...@@ -441,10 +442,10 @@ test "math overflow functions" {
441}442}
442443
443fn testOverflow() void {444fn testOverflow() void {
444 assert((mul(i32, 3, 4) catch unreachable) == 12);445 testing.expect((mul(i32, 3, 4) catch unreachable) == 12);
445 assert((add(i32, 3, 4) catch unreachable) == 7);446 testing.expect((add(i32, 3, 4) catch unreachable) == 7);
446 assert((sub(i32, 3, 4) catch unreachable) == -1);447 testing.expect((sub(i32, 3, 4) catch unreachable) == -1);
447 assert((shlExact(i32, 0b11, 4) catch unreachable) == 0b110000);448 testing.expect((shlExact(i32, 0b11, 4) catch unreachable) == 0b110000);
448}449}
449450
450pub fn absInt(x: var) !@typeOf(x) {451pub fn absInt(x: var) !@typeOf(x) {
...@@ -465,8 +466,8 @@ test "math.absInt" {...@@ -465,8 +466,8 @@ test "math.absInt" {
465 comptime testAbsInt();466 comptime testAbsInt();
466}467}
467fn testAbsInt() void {468fn testAbsInt() void {
468 assert((absInt(i32(-10)) catch unreachable) == 10);469 testing.expect((absInt(i32(-10)) catch unreachable) == 10);
469 assert((absInt(i32(10)) catch unreachable) == 10);470 testing.expect((absInt(i32(10)) catch unreachable) == 10);
470}471}
471472
472pub const absFloat = @import("fabs.zig").fabs;473pub const absFloat = @import("fabs.zig").fabs;
...@@ -483,13 +484,13 @@ test "math.divTrunc" {...@@ -483,13 +484,13 @@ test "math.divTrunc" {
483 comptime testDivTrunc();484 comptime testDivTrunc();
484}485}
485fn testDivTrunc() void {486fn testDivTrunc() void {
486 assert((divTrunc(i32, 5, 3) catch unreachable) == 1);487 testing.expect((divTrunc(i32, 5, 3) catch unreachable) == 1);
487 assert((divTrunc(i32, -5, 3) catch unreachable) == -1);488 testing.expect((divTrunc(i32, -5, 3) catch unreachable) == -1);
488 if (divTrunc(i8, -5, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero);489 testing.expectError(error.DivisionByZero, divTrunc(i8, -5, 0));
489 if (divTrunc(i8, -128, -1)) |_| unreachable else |err| assert(err == error.Overflow);490 testing.expectError(error.Overflow, divTrunc(i8, -128, -1));
490491
491 assert((divTrunc(f32, 5.0, 3.0) catch unreachable) == 1.0);492 testing.expect((divTrunc(f32, 5.0, 3.0) catch unreachable) == 1.0);
492 assert((divTrunc(f32, -5.0, 3.0) catch unreachable) == -1.0);493 testing.expect((divTrunc(f32, -5.0, 3.0) catch unreachable) == -1.0);
493}494}
494495
495pub fn divFloor(comptime T: type, numerator: T, denominator: T) !T {496pub fn divFloor(comptime T: type, numerator: T, denominator: T) !T {
...@@ -504,13 +505,13 @@ test "math.divFloor" {...@@ -504,13 +505,13 @@ test "math.divFloor" {
504 comptime testDivFloor();505 comptime testDivFloor();
505}506}
506fn testDivFloor() void {507fn testDivFloor() void {
507 assert((divFloor(i32, 5, 3) catch unreachable) == 1);508 testing.expect((divFloor(i32, 5, 3) catch unreachable) == 1);
508 assert((divFloor(i32, -5, 3) catch unreachable) == -2);509 testing.expect((divFloor(i32, -5, 3) catch unreachable) == -2);
509 if (divFloor(i8, -5, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero);510 testing.expectError(error.DivisionByZero, divFloor(i8, -5, 0));
510 if (divFloor(i8, -128, -1)) |_| unreachable else |err| assert(err == error.Overflow);511 testing.expectError(error.Overflow, divFloor(i8, -128, -1));
511512
512 assert((divFloor(f32, 5.0, 3.0) catch unreachable) == 1.0);513 testing.expect((divFloor(f32, 5.0, 3.0) catch unreachable) == 1.0);
513 assert((divFloor(f32, -5.0, 3.0) catch unreachable) == -2.0);514 testing.expect((divFloor(f32, -5.0, 3.0) catch unreachable) == -2.0);
514}515}
515516
516pub fn divExact(comptime T: type, numerator: T, denominator: T) !T {517pub fn divExact(comptime T: type, numerator: T, denominator: T) !T {
...@@ -527,15 +528,15 @@ test "math.divExact" {...@@ -527,15 +528,15 @@ test "math.divExact" {
527 comptime testDivExact();528 comptime testDivExact();
528}529}
529fn testDivExact() void {530fn testDivExact() void {
530 assert((divExact(i32, 10, 5) catch unreachable) == 2);531 testing.expect((divExact(i32, 10, 5) catch unreachable) == 2);
531 assert((divExact(i32, -10, 5) catch unreachable) == -2);532 testing.expect((divExact(i32, -10, 5) catch unreachable) == -2);
532 if (divExact(i8, -5, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero);533 testing.expectError(error.DivisionByZero, divExact(i8, -5, 0));
533 if (divExact(i8, -128, -1)) |_| unreachable else |err| assert(err == error.Overflow);534 testing.expectError(error.Overflow, divExact(i8, -128, -1));
534 if (divExact(i32, 5, 2)) |_| unreachable else |err| assert(err == error.UnexpectedRemainder);535 testing.expectError(error.UnexpectedRemainder, divExact(i32, 5, 2));
535536
536 assert((divExact(f32, 10.0, 5.0) catch unreachable) == 2.0);537 testing.expect((divExact(f32, 10.0, 5.0) catch unreachable) == 2.0);
537 assert((divExact(f32, -10.0, 5.0) catch unreachable) == -2.0);538 testing.expect((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);539 testing.expectError(error.UnexpectedRemainder, divExact(f32, 5.0, 2.0));
539}540}
540541
541pub fn mod(comptime T: type, numerator: T, denominator: T) !T {542pub fn mod(comptime T: type, numerator: T, denominator: T) !T {
...@@ -550,15 +551,15 @@ test "math.mod" {...@@ -550,15 +551,15 @@ test "math.mod" {
550 comptime testMod();551 comptime testMod();
551}552}
552fn testMod() void {553fn testMod() void {
553 assert((mod(i32, -5, 3) catch unreachable) == 1);554 testing.expect((mod(i32, -5, 3) catch unreachable) == 1);
554 assert((mod(i32, 5, 3) catch unreachable) == 2);555 testing.expect((mod(i32, 5, 3) catch unreachable) == 2);
555 if (mod(i32, 10, -1)) |_| unreachable else |err| assert(err == error.NegativeDenominator);556 testing.expectError(error.NegativeDenominator, mod(i32, 10, -1));
556 if (mod(i32, 10, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero);557 testing.expectError(error.DivisionByZero, mod(i32, 10, 0));
557558
558 assert((mod(f32, -5, 3) catch unreachable) == 1);559 testing.expect((mod(f32, -5, 3) catch unreachable) == 1);
559 assert((mod(f32, 5, 3) catch unreachable) == 2);560 testing.expect((mod(f32, 5, 3) catch unreachable) == 2);
560 if (mod(f32, 10, -1)) |_| unreachable else |err| assert(err == error.NegativeDenominator);561 testing.expectError(error.NegativeDenominator, mod(f32, 10, -1));
561 if (mod(f32, 10, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero);562 testing.expectError(error.DivisionByZero, mod(f32, 10, 0));
562}563}
563564
564pub fn rem(comptime T: type, numerator: T, denominator: T) !T {565pub fn rem(comptime T: type, numerator: T, denominator: T) !T {
...@@ -573,15 +574,15 @@ test "math.rem" {...@@ -573,15 +574,15 @@ test "math.rem" {
573 comptime testRem();574 comptime testRem();
574}575}
575fn testRem() void {576fn testRem() void {
576 assert((rem(i32, -5, 3) catch unreachable) == -2);577 testing.expect((rem(i32, -5, 3) catch unreachable) == -2);
577 assert((rem(i32, 5, 3) catch unreachable) == 2);578 testing.expect((rem(i32, 5, 3) catch unreachable) == 2);
578 if (rem(i32, 10, -1)) |_| unreachable else |err| assert(err == error.NegativeDenominator);579 testing.expectError(error.NegativeDenominator, rem(i32, 10, -1));
579 if (rem(i32, 10, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero);580 testing.expectError(error.DivisionByZero, rem(i32, 10, 0));
580581
581 assert((rem(f32, -5, 3) catch unreachable) == -2);582 testing.expect((rem(f32, -5, 3) catch unreachable) == -2);
582 assert((rem(f32, 5, 3) catch unreachable) == 2);583 testing.expect((rem(f32, 5, 3) catch unreachable) == 2);
583 if (rem(f32, 10, -1)) |_| unreachable else |err| assert(err == error.NegativeDenominator);584 testing.expectError(error.NegativeDenominator, rem(f32, 10, -1));
584 if (rem(f32, 10, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero);585 testing.expectError(error.DivisionByZero, rem(f32, 10, 0));
585}586}
586587
587/// Returns the absolute value of the integer parameter.588/// Returns the absolute value of the integer parameter.
...@@ -594,14 +595,14 @@ pub fn absCast(x: var) @IntType(false, @typeOf(x).bit_count) {...@@ -594,14 +595,14 @@ pub fn absCast(x: var) @IntType(false, @typeOf(x).bit_count) {
594}595}
595596
596test "math.absCast" {597test "math.absCast" {
597 assert(absCast(i32(-999)) == 999);598 testing.expect(absCast(i32(-999)) == 999);
598 assert(@typeOf(absCast(i32(-999))) == u32);599 testing.expect(@typeOf(absCast(i32(-999))) == u32);
599600
600 assert(absCast(i32(999)) == 999);601 testing.expect(absCast(i32(999)) == 999);
601 assert(@typeOf(absCast(i32(999))) == u32);602 testing.expect(@typeOf(absCast(i32(999))) == u32);
602603
603 assert(absCast(i32(minInt(i32))) == -minInt(i32));604 testing.expect(absCast(i32(minInt(i32))) == -minInt(i32));
604 assert(@typeOf(absCast(i32(minInt(i32)))) == u32);605 testing.expect(@typeOf(absCast(i32(minInt(i32)))) == u32);
605}606}
606607
607/// Returns the negation of the integer parameter.608/// Returns the negation of the integer parameter.
...@@ -618,13 +619,13 @@ pub fn negateCast(x: var) !@IntType(true, @typeOf(x).bit_count) {...@@ -618,13 +619,13 @@ pub fn negateCast(x: var) !@IntType(true, @typeOf(x).bit_count) {
618}619}
619620
620test "math.negateCast" {621test "math.negateCast" {
621 assert((negateCast(u32(999)) catch unreachable) == -999);622 testing.expect((negateCast(u32(999)) catch unreachable) == -999);
622 assert(@typeOf(negateCast(u32(999)) catch unreachable) == i32);623 testing.expect(@typeOf(negateCast(u32(999)) catch unreachable) == i32);
623624
624 assert((negateCast(u32(-minInt(i32))) catch unreachable) == minInt(i32));625 testing.expect((negateCast(u32(-minInt(i32))) catch unreachable) == minInt(i32));
625 assert(@typeOf(negateCast(u32(-minInt(i32))) catch unreachable) == 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)));
628}629}
629630
630/// Cast an integer to a different integer type. If the value doesn't fit,631/// 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) {...@@ -642,13 +643,13 @@ pub fn cast(comptime T: type, x: var) (error{Overflow}!T) {
642}643}
643644
644test "math.cast" {645test "math.cast" {
645 if (cast(u8, u32(300))) |_| @panic("fail") else |err| assert(err == error.Overflow);646 testing.expectError(error.Overflow, cast(u8, u32(300)));
646 if (cast(i8, i32(-200))) |_| @panic("fail") else |err| assert(err == error.Overflow);647 testing.expectError(error.Overflow, cast(i8, i32(-200)));
647 if (cast(u8, i8(-1))) |_| @panic("fail") else |err| assert(err == error.Overflow);648 testing.expectError(error.Overflow, cast(u8, i8(-1)));
648 if (cast(u64, i8(-1))) |_| @panic("fail") else |err| assert(err == error.Overflow);649 testing.expectError(error.Overflow, cast(u64, i8(-1)));
649650
650 assert((try cast(u8, u32(255))) == u8(255));651 testing.expect((try cast(u8, u32(255))) == u8(255));
651 assert(@typeOf(try cast(u8, u32(255))) == u8);652 testing.expect(@typeOf(try cast(u8, u32(255))) == u8);
652}653}
653654
654pub const AlignCastError = error{UnalignedMemory};655pub const AlignCastError = error{UnalignedMemory};
...@@ -692,25 +693,25 @@ pub fn log2_int_ceil(comptime T: type, x: T) Log2Int(T) {...@@ -692,25 +693,25 @@ pub fn log2_int_ceil(comptime T: type, x: T) Log2Int(T) {
692}693}
693694
694test "std.math.log2_int_ceil" {695test "std.math.log2_int_ceil" {
695 assert(log2_int_ceil(u32, 1) == 0);696 testing.expect(log2_int_ceil(u32, 1) == 0);
696 assert(log2_int_ceil(u32, 2) == 1);697 testing.expect(log2_int_ceil(u32, 2) == 1);
697 assert(log2_int_ceil(u32, 3) == 2);698 testing.expect(log2_int_ceil(u32, 3) == 2);
698 assert(log2_int_ceil(u32, 4) == 2);699 testing.expect(log2_int_ceil(u32, 4) == 2);
699 assert(log2_int_ceil(u32, 5) == 3);700 testing.expect(log2_int_ceil(u32, 5) == 3);
700 assert(log2_int_ceil(u32, 6) == 3);701 testing.expect(log2_int_ceil(u32, 6) == 3);
701 assert(log2_int_ceil(u32, 7) == 3);702 testing.expect(log2_int_ceil(u32, 7) == 3);
702 assert(log2_int_ceil(u32, 8) == 3);703 testing.expect(log2_int_ceil(u32, 8) == 3);
703 assert(log2_int_ceil(u32, 9) == 4);704 testing.expect(log2_int_ceil(u32, 9) == 4);
704 assert(log2_int_ceil(u32, 10) == 4);705 testing.expect(log2_int_ceil(u32, 10) == 4);
705}706}
706707
707fn testFloorPowerOfTwo() void {708fn testFloorPowerOfTwo() void {
708 assert(floorPowerOfTwo(u32, 63) == 32);709 testing.expect(floorPowerOfTwo(u32, 63) == 32);
709 assert(floorPowerOfTwo(u32, 64) == 64);710 testing.expect(floorPowerOfTwo(u32, 64) == 64);
710 assert(floorPowerOfTwo(u32, 65) == 64);711 testing.expect(floorPowerOfTwo(u32, 65) == 64);
711 assert(floorPowerOfTwo(u4, 7) == 4);712 testing.expect(floorPowerOfTwo(u4, 7) == 4);
712 assert(floorPowerOfTwo(u4, 8) == 8);713 testing.expect(floorPowerOfTwo(u4, 8) == 8);
713 assert(floorPowerOfTwo(u4, 9) == 8);714 testing.expect(floorPowerOfTwo(u4, 9) == 8);
714}715}
715716
716pub fn lossyCast(comptime T: type, value: var) T {717pub fn lossyCast(comptime T: type, value: var) T {
...@@ -726,7 +727,7 @@ pub fn lossyCast(comptime T: type, value: var) T {...@@ -726,7 +727,7 @@ pub fn lossyCast(comptime T: type, value: var) T {
726test "math.f64_min" {727test "math.f64_min" {
727 const f64_min_u64 = 0x0010000000000000;728 const f64_min_u64 = 0x0010000000000000;
728 const fmin: f64 = f64_min;729 const fmin: f64 = f64_min;
729 assert(@bitCast(u64, fmin) == f64_min_u64);730 testing.expect(@bitCast(u64, fmin) == f64_min_u64);
730}731}
731732
732pub fn maxInt(comptime T: type) comptime_int {733pub fn maxInt(comptime T: type) comptime_int {
...@@ -745,36 +746,36 @@ pub fn minInt(comptime T: type) comptime_int {...@@ -745,36 +746,36 @@ pub fn minInt(comptime T: type) comptime_int {
745}746}
746747
747test "minInt and maxInt" {748test "minInt and maxInt" {
748 assert(maxInt(u0) == 0);749 testing.expect(maxInt(u0) == 0);
749 assert(maxInt(u1) == 1);750 testing.expect(maxInt(u1) == 1);
750 assert(maxInt(u8) == 255);751 testing.expect(maxInt(u8) == 255);
751 assert(maxInt(u16) == 65535);752 testing.expect(maxInt(u16) == 65535);
752 assert(maxInt(u32) == 4294967295);753 testing.expect(maxInt(u32) == 4294967295);
753 assert(maxInt(u64) == 18446744073709551615);754 testing.expect(maxInt(u64) == 18446744073709551615);
754755
755 assert(maxInt(i0) == 0);756 testing.expect(maxInt(i0) == 0);
756 assert(maxInt(i1) == 0);757 testing.expect(maxInt(i1) == 0);
757 assert(maxInt(i8) == 127);758 testing.expect(maxInt(i8) == 127);
758 assert(maxInt(i16) == 32767);759 testing.expect(maxInt(i16) == 32767);
759 assert(maxInt(i32) == 2147483647);760 testing.expect(maxInt(i32) == 2147483647);
760 assert(maxInt(i63) == 4611686018427387903);761 testing.expect(maxInt(i63) == 4611686018427387903);
761 assert(maxInt(i64) == 9223372036854775807);762 testing.expect(maxInt(i64) == 9223372036854775807);
762763
763 assert(minInt(u0) == 0);764 testing.expect(minInt(u0) == 0);
764 assert(minInt(u1) == 0);765 testing.expect(minInt(u1) == 0);
765 assert(minInt(u8) == 0);766 testing.expect(minInt(u8) == 0);
766 assert(minInt(u16) == 0);767 testing.expect(minInt(u16) == 0);
767 assert(minInt(u32) == 0);768 testing.expect(minInt(u32) == 0);
768 assert(minInt(u63) == 0);769 testing.expect(minInt(u63) == 0);
769 assert(minInt(u64) == 0);770 testing.expect(minInt(u64) == 0);
770771
771 assert(minInt(i0) == 0);772 testing.expect(minInt(i0) == 0);
772 assert(minInt(i1) == -1);773 testing.expect(minInt(i1) == -1);
773 assert(minInt(i8) == -128);774 testing.expect(minInt(i8) == -128);
774 assert(minInt(i16) == -32768);775 testing.expect(minInt(i16) == -32768);
775 assert(minInt(i32) == -2147483648);776 testing.expect(minInt(i32) == -2147483648);
776 assert(minInt(i63) == -4611686018427387904);777 testing.expect(minInt(i63) == -4611686018427387904);
777 assert(minInt(i64) == -9223372036854775808);778 testing.expect(minInt(i64) == -9223372036854775808);
778}779}
779780
780test "max value type" {781test "max value type" {
...@@ -782,5 +783,5 @@ test "max value type" {...@@ -782,5 +783,5 @@ test "max value type" {
782 // u32 would not work. But since the value is a number literal,783 // u32 would not work. But since the value is a number literal,
783 // it works fine.784 // it works fine.
784 const x: u32 = maxInt(i32);785 const x: u32 = maxInt(i32);
785 assert(x == 2147483647);786 testing.expect(x == 2147483647);
786}787}
std/math/isfinite.zig+13-13
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const std = @import("../index.zig");1const std = @import("../index.zig");
2const math = std.math;2const math = std.math;
3const assert = std.debug.assert;3const expect = std.testing.expect;
4const maxInt = std.math.maxInt;4const maxInt = std.math.maxInt;
55
6pub fn isFinite(x: var) bool {6pub fn isFinite(x: var) bool {
...@@ -25,16 +25,16 @@ pub fn isFinite(x: var) bool {...@@ -25,16 +25,16 @@ pub fn isFinite(x: var) bool {
25}25}
2626
27test "math.isFinite" {27test "math.isFinite" {
28 assert(isFinite(f16(0.0)));28 expect(isFinite(f16(0.0)));
29 assert(isFinite(f16(-0.0)));29 expect(isFinite(f16(-0.0)));
30 assert(isFinite(f32(0.0)));30 expect(isFinite(f32(0.0)));
31 assert(isFinite(f32(-0.0)));31 expect(isFinite(f32(-0.0)));
32 assert(isFinite(f64(0.0)));32 expect(isFinite(f64(0.0)));
33 assert(isFinite(f64(-0.0)));33 expect(isFinite(f64(-0.0)));
34 assert(!isFinite(math.inf(f16)));34 expect(!isFinite(math.inf(f16)));
35 assert(!isFinite(-math.inf(f16)));35 expect(!isFinite(-math.inf(f16)));
36 assert(!isFinite(math.inf(f32)));36 expect(!isFinite(math.inf(f32)));
37 assert(!isFinite(-math.inf(f32)));37 expect(!isFinite(-math.inf(f32)));
38 assert(!isFinite(math.inf(f64)));38 expect(!isFinite(math.inf(f64)));
39 assert(!isFinite(-math.inf(f64)));39 expect(!isFinite(-math.inf(f64)));
40}40}
std/math/isinf.zig+37-37
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const std = @import("../index.zig");1const std = @import("../index.zig");
2const math = std.math;2const math = std.math;
3const assert = std.debug.assert;3const expect = std.testing.expect;
4const maxInt = std.math.maxInt;4const maxInt = std.math.maxInt;
55
6pub fn isInf(x: var) bool {6pub fn isInf(x: var) bool {
...@@ -61,46 +61,46 @@ pub fn isNegativeInf(x: var) bool {...@@ -61,46 +61,46 @@ pub fn isNegativeInf(x: var) bool {
61}61}
6262
63test "math.isInf" {63test "math.isInf" {
64 assert(!isInf(f16(0.0)));64 expect(!isInf(f16(0.0)));
65 assert(!isInf(f16(-0.0)));65 expect(!isInf(f16(-0.0)));
66 assert(!isInf(f32(0.0)));66 expect(!isInf(f32(0.0)));
67 assert(!isInf(f32(-0.0)));67 expect(!isInf(f32(-0.0)));
68 assert(!isInf(f64(0.0)));68 expect(!isInf(f64(0.0)));
69 assert(!isInf(f64(-0.0)));69 expect(!isInf(f64(-0.0)));
70 assert(isInf(math.inf(f16)));70 expect(isInf(math.inf(f16)));
71 assert(isInf(-math.inf(f16)));71 expect(isInf(-math.inf(f16)));
72 assert(isInf(math.inf(f32)));72 expect(isInf(math.inf(f32)));
73 assert(isInf(-math.inf(f32)));73 expect(isInf(-math.inf(f32)));
74 assert(isInf(math.inf(f64)));74 expect(isInf(math.inf(f64)));
75 assert(isInf(-math.inf(f64)));75 expect(isInf(-math.inf(f64)));
76}76}
7777
78test "math.isPositiveInf" {78test "math.isPositiveInf" {
79 assert(!isPositiveInf(f16(0.0)));79 expect(!isPositiveInf(f16(0.0)));
80 assert(!isPositiveInf(f16(-0.0)));80 expect(!isPositiveInf(f16(-0.0)));
81 assert(!isPositiveInf(f32(0.0)));81 expect(!isPositiveInf(f32(0.0)));
82 assert(!isPositiveInf(f32(-0.0)));82 expect(!isPositiveInf(f32(-0.0)));
83 assert(!isPositiveInf(f64(0.0)));83 expect(!isPositiveInf(f64(0.0)));
84 assert(!isPositiveInf(f64(-0.0)));84 expect(!isPositiveInf(f64(-0.0)));
85 assert(isPositiveInf(math.inf(f16)));85 expect(isPositiveInf(math.inf(f16)));
86 assert(!isPositiveInf(-math.inf(f16)));86 expect(!isPositiveInf(-math.inf(f16)));
87 assert(isPositiveInf(math.inf(f32)));87 expect(isPositiveInf(math.inf(f32)));
88 assert(!isPositiveInf(-math.inf(f32)));88 expect(!isPositiveInf(-math.inf(f32)));
89 assert(isPositiveInf(math.inf(f64)));89 expect(isPositiveInf(math.inf(f64)));
90 assert(!isPositiveInf(-math.inf(f64)));90 expect(!isPositiveInf(-math.inf(f64)));
91}91}
9292
93test "math.isNegativeInf" {93test "math.isNegativeInf" {
94 assert(!isNegativeInf(f16(0.0)));94 expect(!isNegativeInf(f16(0.0)));
95 assert(!isNegativeInf(f16(-0.0)));95 expect(!isNegativeInf(f16(-0.0)));
96 assert(!isNegativeInf(f32(0.0)));96 expect(!isNegativeInf(f32(0.0)));
97 assert(!isNegativeInf(f32(-0.0)));97 expect(!isNegativeInf(f32(-0.0)));
98 assert(!isNegativeInf(f64(0.0)));98 expect(!isNegativeInf(f64(0.0)));
99 assert(!isNegativeInf(f64(-0.0)));99 expect(!isNegativeInf(f64(-0.0)));
100 assert(!isNegativeInf(math.inf(f16)));100 expect(!isNegativeInf(math.inf(f16)));
101 assert(isNegativeInf(-math.inf(f16)));101 expect(isNegativeInf(-math.inf(f16)));
102 assert(!isNegativeInf(math.inf(f32)));102 expect(!isNegativeInf(math.inf(f32)));
103 assert(isNegativeInf(-math.inf(f32)));103 expect(isNegativeInf(-math.inf(f32)));
104 assert(!isNegativeInf(math.inf(f64)));104 expect(!isNegativeInf(math.inf(f64)));
105 assert(isNegativeInf(-math.inf(f64)));105 expect(isNegativeInf(-math.inf(f64)));
106}106}
std/math/isnan.zig+7-7
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const std = @import("../index.zig");1const std = @import("../index.zig");
2const math = std.math;2const math = std.math;
3const assert = std.debug.assert;3const expect = std.testing.expect;
4const maxInt = std.math.maxInt;4const maxInt = std.math.maxInt;
55
6pub fn isNan(x: var) bool {6pub fn isNan(x: var) bool {
...@@ -31,10 +31,10 @@ pub fn isSignalNan(x: var) bool {...@@ -31,10 +31,10 @@ pub fn isSignalNan(x: var) bool {
31}31}
3232
33test "math.isNan" {33test "math.isNan" {
34 assert(isNan(math.nan(f16)));34 expect(isNan(math.nan(f16)));
35 assert(isNan(math.nan(f32)));35 expect(isNan(math.nan(f32)));
36 assert(isNan(math.nan(f64)));36 expect(isNan(math.nan(f64)));
37 assert(!isNan(f16(1.0)));37 expect(!isNan(f16(1.0)));
38 assert(!isNan(f32(1.0)));38 expect(!isNan(f32(1.0)));
39 assert(!isNan(f64(1.0)));39 expect(!isNan(f64(1.0)));
40}40}
std/math/isnormal.zig+10-10
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const std = @import("../index.zig");1const std = @import("../index.zig");
2const math = std.math;2const math = std.math;
3const assert = std.debug.assert;3const expect = std.testing.expect;
4const maxInt = std.math.maxInt;4const maxInt = std.math.maxInt;
55
6pub fn isNormal(x: var) bool {6pub fn isNormal(x: var) bool {
...@@ -25,13 +25,13 @@ pub fn isNormal(x: var) bool {...@@ -25,13 +25,13 @@ pub fn isNormal(x: var) bool {
25}25}
2626
27test "math.isNormal" {27test "math.isNormal" {
28 assert(!isNormal(math.nan(f16)));28 expect(!isNormal(math.nan(f16)));
29 assert(!isNormal(math.nan(f32)));29 expect(!isNormal(math.nan(f32)));
30 assert(!isNormal(math.nan(f64)));30 expect(!isNormal(math.nan(f64)));
31 assert(!isNormal(f16(0)));31 expect(!isNormal(f16(0)));
32 assert(!isNormal(f32(0)));32 expect(!isNormal(f32(0)));
33 assert(!isNormal(f64(0)));33 expect(!isNormal(f64(0)));
34 assert(isNormal(f16(1.0)));34 expect(isNormal(f16(1.0)));
35 assert(isNormal(f32(1.0)));35 expect(isNormal(f32(1.0)));
36 assert(isNormal(f64(1.0)));36 expect(isNormal(f64(1.0)));
37}37}
std/math/ln.zig+23-23
...@@ -7,7 +7,7 @@...@@ -7,7 +7,7 @@
77
8const std = @import("../index.zig");8const std = @import("../index.zig");
9const math = std.math;9const math = std.math;
10const assert = std.debug.assert;10const expect = std.testing.expect;
11const builtin = @import("builtin");11const builtin = @import("builtin");
12const TypeId = builtin.TypeId;12const TypeId = builtin.TypeId;
1313
...@@ -143,42 +143,42 @@ pub fn ln_64(x_: f64) f64 {...@@ -143,42 +143,42 @@ pub fn ln_64(x_: f64) f64 {
143}143}
144144
145test "math.ln" {145test "math.ln" {
146 assert(ln(f32(0.2)) == ln_32(0.2));146 expect(ln(f32(0.2)) == ln_32(0.2));
147 assert(ln(f64(0.2)) == ln_64(0.2));147 expect(ln(f64(0.2)) == ln_64(0.2));
148}148}
149149
150test "math.ln32" {150test "math.ln32" {
151 const epsilon = 0.000001;151 const epsilon = 0.000001;
152152
153 assert(math.approxEq(f32, ln_32(0.2), -1.609438, epsilon));153 expect(math.approxEq(f32, ln_32(0.2), -1.609438, epsilon));
154 assert(math.approxEq(f32, ln_32(0.8923), -0.113953, epsilon));154 expect(math.approxEq(f32, ln_32(0.8923), -0.113953, epsilon));
155 assert(math.approxEq(f32, ln_32(1.5), 0.405465, epsilon));155 expect(math.approxEq(f32, ln_32(1.5), 0.405465, epsilon));
156 assert(math.approxEq(f32, ln_32(37.45), 3.623007, epsilon));156 expect(math.approxEq(f32, ln_32(37.45), 3.623007, epsilon));
157 assert(math.approxEq(f32, ln_32(89.123), 4.490017, epsilon));157 expect(math.approxEq(f32, ln_32(89.123), 4.490017, epsilon));
158 assert(math.approxEq(f32, ln_32(123123.234375), 11.720941, epsilon));158 expect(math.approxEq(f32, ln_32(123123.234375), 11.720941, epsilon));
159}159}
160160
161test "math.ln64" {161test "math.ln64" {
162 const epsilon = 0.000001;162 const epsilon = 0.000001;
163163
164 assert(math.approxEq(f64, ln_64(0.2), -1.609438, epsilon));164 expect(math.approxEq(f64, ln_64(0.2), -1.609438, epsilon));
165 assert(math.approxEq(f64, ln_64(0.8923), -0.113953, epsilon));165 expect(math.approxEq(f64, ln_64(0.8923), -0.113953, epsilon));
166 assert(math.approxEq(f64, ln_64(1.5), 0.405465, epsilon));166 expect(math.approxEq(f64, ln_64(1.5), 0.405465, epsilon));
167 assert(math.approxEq(f64, ln_64(37.45), 3.623007, epsilon));167 expect(math.approxEq(f64, ln_64(37.45), 3.623007, epsilon));
168 assert(math.approxEq(f64, ln_64(89.123), 4.490017, epsilon));168 expect(math.approxEq(f64, ln_64(89.123), 4.490017, epsilon));
169 assert(math.approxEq(f64, ln_64(123123.234375), 11.720941, epsilon));169 expect(math.approxEq(f64, ln_64(123123.234375), 11.720941, epsilon));
170}170}
171171
172test "math.ln32.special" {172test "math.ln32.special" {
173 assert(math.isPositiveInf(ln_32(math.inf(f32))));173 expect(math.isPositiveInf(ln_32(math.inf(f32))));
174 assert(math.isNegativeInf(ln_32(0.0)));174 expect(math.isNegativeInf(ln_32(0.0)));
175 assert(math.isNan(ln_32(-1.0)));175 expect(math.isNan(ln_32(-1.0)));
176 assert(math.isNan(ln_32(math.nan(f32))));176 expect(math.isNan(ln_32(math.nan(f32))));
177}177}
178178
179test "math.ln64.special" {179test "math.ln64.special" {
180 assert(math.isPositiveInf(ln_64(math.inf(f64))));180 expect(math.isPositiveInf(ln_64(math.inf(f64))));
181 assert(math.isNegativeInf(ln_64(0.0)));181 expect(math.isNegativeInf(ln_64(0.0)));
182 assert(math.isNan(ln_64(-1.0)));182 expect(math.isNan(ln_64(-1.0)));
183 assert(math.isNan(ln_64(math.nan(f64))));183 expect(math.isNan(ln_64(math.nan(f64))));
184}184}
std/math/log.zig+13-13
...@@ -2,7 +2,7 @@ const std = @import("../index.zig");...@@ -2,7 +2,7 @@ const std = @import("../index.zig");
2const math = std.math;2const math = std.math;
3const builtin = @import("builtin");3const builtin = @import("builtin");
4const TypeId = builtin.TypeId;4const TypeId = builtin.TypeId;
5const assert = std.debug.assert;5const expect = std.testing.expect;
66
7pub fn log(comptime T: type, base: T, x: T) T {7pub fn log(comptime T: type, base: T, x: T) T {
8 if (base == 2) {8 if (base == 2) {
...@@ -41,25 +41,25 @@ pub fn log(comptime T: type, base: T, x: T) T {...@@ -41,25 +41,25 @@ pub fn log(comptime T: type, base: T, x: T) T {
41}41}
4242
43test "math.log integer" {43test "math.log integer" {
44 assert(log(u8, 2, 0x1) == 0);44 expect(log(u8, 2, 0x1) == 0);
45 assert(log(u8, 2, 0x2) == 1);45 expect(log(u8, 2, 0x2) == 1);
46 assert(log(i16, 2, 0x72) == 6);46 expect(log(i16, 2, 0x72) == 6);
47 assert(log(u32, 2, 0xFFFFFF) == 23);47 expect(log(u32, 2, 0xFFFFFF) == 23);
48 assert(log(u64, 2, 0x7FF0123456789ABC) == 62);48 expect(log(u64, 2, 0x7FF0123456789ABC) == 62);
49}49}
5050
51test "math.log float" {51test "math.log float" {
52 const epsilon = 0.000001;52 const epsilon = 0.000001;
5353
54 assert(math.approxEq(f32, log(f32, 6, 0.23947), -0.797723, epsilon));54 expect(math.approxEq(f32, log(f32, 6, 0.23947), -0.797723, epsilon));
55 assert(math.approxEq(f32, log(f32, 89, 0.23947), -0.318432, epsilon));55 expect(math.approxEq(f32, log(f32, 89, 0.23947), -0.318432, epsilon));
56 assert(math.approxEq(f64, log(f64, 123897, 12389216414), 1.981724596, epsilon));56 expect(math.approxEq(f64, log(f64, 123897, 12389216414), 1.981724596, epsilon));
57}57}
5858
59test "math.log float_special" {59test "math.log float_special" {
60 assert(log(f32, 2, 0.2301974) == math.log2(f32(0.2301974)));60 expect(log(f32, 2, 0.2301974) == math.log2(f32(0.2301974)));
61 assert(log(f32, 10, 0.2301974) == math.log10(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)));63 expect(log(f64, 2, 213.23019799993) == math.log2(f64(213.23019799993)));
64 assert(log(f64, 10, 213.23019799993) == math.log10(f64(213.23019799993)));64 expect(log(f64, 10, 213.23019799993) == math.log10(f64(213.23019799993)));
65}65}
std/math/log10.zig+23-23
...@@ -7,7 +7,7 @@...@@ -7,7 +7,7 @@
77
8const std = @import("../index.zig");8const std = @import("../index.zig");
9const math = std.math;9const math = std.math;
10const assert = std.debug.assert;10const testing = std.testing;
11const builtin = @import("builtin");11const builtin = @import("builtin");
12const TypeId = builtin.TypeId;12const TypeId = builtin.TypeId;
13const maxInt = std.math.maxInt;13const maxInt = std.math.maxInt;
...@@ -171,42 +171,42 @@ pub fn log10_64(x_: f64) f64 {...@@ -171,42 +171,42 @@ pub fn log10_64(x_: f64) f64 {
171}171}
172172
173test "math.log10" {173test "math.log10" {
174 assert(log10(f32(0.2)) == log10_32(0.2));174 testing.expect(log10(f32(0.2)) == log10_32(0.2));
175 assert(log10(f64(0.2)) == log10_64(0.2));175 testing.expect(log10(f64(0.2)) == log10_64(0.2));
176}176}
177177
178test "math.log10_32" {178test "math.log10_32" {
179 const epsilon = 0.000001;179 const epsilon = 0.000001;
180180
181 assert(math.approxEq(f32, log10_32(0.2), -0.698970, epsilon));181 testing.expect(math.approxEq(f32, log10_32(0.2), -0.698970, epsilon));
182 assert(math.approxEq(f32, log10_32(0.8923), -0.049489, epsilon));182 testing.expect(math.approxEq(f32, log10_32(0.8923), -0.049489, epsilon));
183 assert(math.approxEq(f32, log10_32(1.5), 0.176091, epsilon));183 testing.expect(math.approxEq(f32, log10_32(1.5), 0.176091, epsilon));
184 assert(math.approxEq(f32, log10_32(37.45), 1.573452, epsilon));184 testing.expect(math.approxEq(f32, log10_32(37.45), 1.573452, epsilon));
185 assert(math.approxEq(f32, log10_32(89.123), 1.94999, epsilon));185 testing.expect(math.approxEq(f32, log10_32(89.123), 1.94999, epsilon));
186 assert(math.approxEq(f32, log10_32(123123.234375), 5.09034, epsilon));186 testing.expect(math.approxEq(f32, log10_32(123123.234375), 5.09034, epsilon));
187}187}
188188
189test "math.log10_64" {189test "math.log10_64" {
190 const epsilon = 0.000001;190 const epsilon = 0.000001;
191191
192 assert(math.approxEq(f64, log10_64(0.2), -0.698970, epsilon));192 testing.expect(math.approxEq(f64, log10_64(0.2), -0.698970, epsilon));
193 assert(math.approxEq(f64, log10_64(0.8923), -0.049489, epsilon));193 testing.expect(math.approxEq(f64, log10_64(0.8923), -0.049489, epsilon));
194 assert(math.approxEq(f64, log10_64(1.5), 0.176091, epsilon));194 testing.expect(math.approxEq(f64, log10_64(1.5), 0.176091, epsilon));
195 assert(math.approxEq(f64, log10_64(37.45), 1.573452, epsilon));195 testing.expect(math.approxEq(f64, log10_64(37.45), 1.573452, epsilon));
196 assert(math.approxEq(f64, log10_64(89.123), 1.94999, epsilon));196 testing.expect(math.approxEq(f64, log10_64(89.123), 1.94999, epsilon));
197 assert(math.approxEq(f64, log10_64(123123.234375), 5.09034, epsilon));197 testing.expect(math.approxEq(f64, log10_64(123123.234375), 5.09034, epsilon));
198}198}
199199
200test "math.log10_32.special" {200test "math.log10_32.special" {
201 assert(math.isPositiveInf(log10_32(math.inf(f32))));201 testing.expect(math.isPositiveInf(log10_32(math.inf(f32))));
202 assert(math.isNegativeInf(log10_32(0.0)));202 testing.expect(math.isNegativeInf(log10_32(0.0)));
203 assert(math.isNan(log10_32(-1.0)));203 testing.expect(math.isNan(log10_32(-1.0)));
204 assert(math.isNan(log10_32(math.nan(f32))));204 testing.expect(math.isNan(log10_32(math.nan(f32))));
205}205}
206206
207test "math.log10_64.special" {207test "math.log10_64.special" {
208 assert(math.isPositiveInf(log10_64(math.inf(f64))));208 testing.expect(math.isPositiveInf(log10_64(math.inf(f64))));
209 assert(math.isNegativeInf(log10_64(0.0)));209 testing.expect(math.isNegativeInf(log10_64(0.0)));
210 assert(math.isNan(log10_64(-1.0)));210 testing.expect(math.isNan(log10_64(-1.0)));
211 assert(math.isNan(log10_64(math.nan(f64))));211 testing.expect(math.isNan(log10_64(math.nan(f64))));
212}212}
std/math/log1p.zig+29-29
...@@ -9,7 +9,7 @@...@@ -9,7 +9,7 @@
9const builtin = @import("builtin");9const builtin = @import("builtin");
10const std = @import("../index.zig");10const std = @import("../index.zig");
11const math = std.math;11const math = std.math;
12const assert = std.debug.assert;12const expect = std.testing.expect;
1313
14pub fn log1p(x: var) @typeOf(x) {14pub fn log1p(x: var) @typeOf(x) {
15 const T = @typeOf(x);15 const T = @typeOf(x);
...@@ -177,48 +177,48 @@ fn log1p_64(x: f64) f64 {...@@ -177,48 +177,48 @@ fn log1p_64(x: f64) f64 {
177}177}
178178
179test "math.log1p" {179test "math.log1p" {
180 assert(log1p(f32(0.0)) == log1p_32(0.0));180 expect(log1p(f32(0.0)) == log1p_32(0.0));
181 assert(log1p(f64(0.0)) == log1p_64(0.0));181 expect(log1p(f64(0.0)) == log1p_64(0.0));
182}182}
183183
184test "math.log1p_32" {184test "math.log1p_32" {
185 const epsilon = 0.000001;185 const epsilon = 0.000001;
186186
187 assert(math.approxEq(f32, log1p_32(0.0), 0.0, epsilon));187 expect(math.approxEq(f32, log1p_32(0.0), 0.0, epsilon));
188 assert(math.approxEq(f32, log1p_32(0.2), 0.182322, epsilon));188 expect(math.approxEq(f32, log1p_32(0.2), 0.182322, epsilon));
189 assert(math.approxEq(f32, log1p_32(0.8923), 0.637793, epsilon));189 expect(math.approxEq(f32, log1p_32(0.8923), 0.637793, epsilon));
190 assert(math.approxEq(f32, log1p_32(1.5), 0.916291, epsilon));190 expect(math.approxEq(f32, log1p_32(1.5), 0.916291, epsilon));
191 assert(math.approxEq(f32, log1p_32(37.45), 3.649359, epsilon));191 expect(math.approxEq(f32, log1p_32(37.45), 3.649359, epsilon));
192 assert(math.approxEq(f32, log1p_32(89.123), 4.501175, epsilon));192 expect(math.approxEq(f32, log1p_32(89.123), 4.501175, epsilon));
193 assert(math.approxEq(f32, log1p_32(123123.234375), 11.720949, epsilon));193 expect(math.approxEq(f32, log1p_32(123123.234375), 11.720949, epsilon));
194}194}
195195
196test "math.log1p_64" {196test "math.log1p_64" {
197 const epsilon = 0.000001;197 const epsilon = 0.000001;
198198
199 assert(math.approxEq(f64, log1p_64(0.0), 0.0, epsilon));199 expect(math.approxEq(f64, log1p_64(0.0), 0.0, epsilon));
200 assert(math.approxEq(f64, log1p_64(0.2), 0.182322, epsilon));200 expect(math.approxEq(f64, log1p_64(0.2), 0.182322, epsilon));
201 assert(math.approxEq(f64, log1p_64(0.8923), 0.637793, epsilon));201 expect(math.approxEq(f64, log1p_64(0.8923), 0.637793, epsilon));
202 assert(math.approxEq(f64, log1p_64(1.5), 0.916291, epsilon));202 expect(math.approxEq(f64, log1p_64(1.5), 0.916291, epsilon));
203 assert(math.approxEq(f64, log1p_64(37.45), 3.649359, epsilon));203 expect(math.approxEq(f64, log1p_64(37.45), 3.649359, epsilon));
204 assert(math.approxEq(f64, log1p_64(89.123), 4.501175, epsilon));204 expect(math.approxEq(f64, log1p_64(89.123), 4.501175, epsilon));
205 assert(math.approxEq(f64, log1p_64(123123.234375), 11.720949, epsilon));205 expect(math.approxEq(f64, log1p_64(123123.234375), 11.720949, epsilon));
206}206}
207207
208test "math.log1p_32.special" {208test "math.log1p_32.special" {
209 assert(math.isPositiveInf(log1p_32(math.inf(f32))));209 expect(math.isPositiveInf(log1p_32(math.inf(f32))));
210 assert(log1p_32(0.0) == 0.0);210 expect(log1p_32(0.0) == 0.0);
211 assert(log1p_32(-0.0) == -0.0);211 expect(log1p_32(-0.0) == -0.0);
212 assert(math.isNegativeInf(log1p_32(-1.0)));212 expect(math.isNegativeInf(log1p_32(-1.0)));
213 assert(math.isNan(log1p_32(-2.0)));213 expect(math.isNan(log1p_32(-2.0)));
214 assert(math.isNan(log1p_32(math.nan(f32))));214 expect(math.isNan(log1p_32(math.nan(f32))));
215}215}
216216
217test "math.log1p_64.special" {217test "math.log1p_64.special" {
218 assert(math.isPositiveInf(log1p_64(math.inf(f64))));218 expect(math.isPositiveInf(log1p_64(math.inf(f64))));
219 assert(log1p_64(0.0) == 0.0);219 expect(log1p_64(0.0) == 0.0);
220 assert(log1p_64(-0.0) == -0.0);220 expect(log1p_64(-0.0) == -0.0);
221 assert(math.isNegativeInf(log1p_64(-1.0)));221 expect(math.isNegativeInf(log1p_64(-1.0)));
222 assert(math.isNan(log1p_64(-2.0)));222 expect(math.isNan(log1p_64(-2.0)));
223 assert(math.isNan(log1p_64(math.nan(f64))));223 expect(math.isNan(log1p_64(math.nan(f64))));
224}224}
std/math/log2.zig+21-21
...@@ -7,7 +7,7 @@...@@ -7,7 +7,7 @@
77
8const std = @import("../index.zig");8const std = @import("../index.zig");
9const math = std.math;9const math = std.math;
10const assert = std.debug.assert;10const expect = std.testing.expect;
11const builtin = @import("builtin");11const builtin = @import("builtin");
12const TypeId = builtin.TypeId;12const TypeId = builtin.TypeId;
13const maxInt = std.math.maxInt;13const maxInt = std.math.maxInt;
...@@ -169,40 +169,40 @@ pub fn log2_64(x_: f64) f64 {...@@ -169,40 +169,40 @@ pub fn log2_64(x_: f64) f64 {
169}169}
170170
171test "math.log2" {171test "math.log2" {
172 assert(log2(f32(0.2)) == log2_32(0.2));172 expect(log2(f32(0.2)) == log2_32(0.2));
173 assert(log2(f64(0.2)) == log2_64(0.2));173 expect(log2(f64(0.2)) == log2_64(0.2));
174}174}
175175
176test "math.log2_32" {176test "math.log2_32" {
177 const epsilon = 0.000001;177 const epsilon = 0.000001;
178178
179 assert(math.approxEq(f32, log2_32(0.2), -2.321928, epsilon));179 expect(math.approxEq(f32, log2_32(0.2), -2.321928, epsilon));
180 assert(math.approxEq(f32, log2_32(0.8923), -0.164399, epsilon));180 expect(math.approxEq(f32, log2_32(0.8923), -0.164399, epsilon));
181 assert(math.approxEq(f32, log2_32(1.5), 0.584962, epsilon));181 expect(math.approxEq(f32, log2_32(1.5), 0.584962, epsilon));
182 assert(math.approxEq(f32, log2_32(37.45), 5.226894, epsilon));182 expect(math.approxEq(f32, log2_32(37.45), 5.226894, epsilon));
183 assert(math.approxEq(f32, log2_32(123123.234375), 16.909744, epsilon));183 expect(math.approxEq(f32, log2_32(123123.234375), 16.909744, epsilon));
184}184}
185185
186test "math.log2_64" {186test "math.log2_64" {
187 const epsilon = 0.000001;187 const epsilon = 0.000001;
188188
189 assert(math.approxEq(f64, log2_64(0.2), -2.321928, epsilon));189 expect(math.approxEq(f64, log2_64(0.2), -2.321928, epsilon));
190 assert(math.approxEq(f64, log2_64(0.8923), -0.164399, epsilon));190 expect(math.approxEq(f64, log2_64(0.8923), -0.164399, epsilon));
191 assert(math.approxEq(f64, log2_64(1.5), 0.584962, epsilon));191 expect(math.approxEq(f64, log2_64(1.5), 0.584962, epsilon));
192 assert(math.approxEq(f64, log2_64(37.45), 5.226894, epsilon));192 expect(math.approxEq(f64, log2_64(37.45), 5.226894, epsilon));
193 assert(math.approxEq(f64, log2_64(123123.234375), 16.909744, epsilon));193 expect(math.approxEq(f64, log2_64(123123.234375), 16.909744, epsilon));
194}194}
195195
196test "math.log2_32.special" {196test "math.log2_32.special" {
197 assert(math.isPositiveInf(log2_32(math.inf(f32))));197 expect(math.isPositiveInf(log2_32(math.inf(f32))));
198 assert(math.isNegativeInf(log2_32(0.0)));198 expect(math.isNegativeInf(log2_32(0.0)));
199 assert(math.isNan(log2_32(-1.0)));199 expect(math.isNan(log2_32(-1.0)));
200 assert(math.isNan(log2_32(math.nan(f32))));200 expect(math.isNan(log2_32(math.nan(f32))));
201}201}
202202
203test "math.log2_64.special" {203test "math.log2_64.special" {
204 assert(math.isPositiveInf(log2_64(math.inf(f64))));204 expect(math.isPositiveInf(log2_64(math.inf(f64))));
205 assert(math.isNegativeInf(log2_64(0.0)));205 expect(math.isNegativeInf(log2_64(0.0)));
206 assert(math.isNan(log2_64(-1.0)));206 expect(math.isNan(log2_64(-1.0)));
207 assert(math.isNan(log2_64(math.nan(f64))));207 expect(math.isNan(log2_64(math.nan(f64))));
208}208}
std/math/modf.zig+29-29
...@@ -5,7 +5,7 @@...@@ -5,7 +5,7 @@
55
6const std = @import("../index.zig");6const std = @import("../index.zig");
7const math = std.math;7const math = std.math;
8const assert = std.debug.assert;8const expect = std.testing.expect;
9const maxInt = std.math.maxInt;9const maxInt = std.math.maxInt;
1010
11fn modf_result(comptime T: type) type {11fn modf_result(comptime T: type) type {
...@@ -119,11 +119,11 @@ test "math.modf" {...@@ -119,11 +119,11 @@ test "math.modf" {
119 const a = modf(f32(1.0));119 const a = modf(f32(1.0));
120 const b = modf32(1.0);120 const b = modf32(1.0);
121 // NOTE: No struct comparison on generic return type function? non-named, makes sense, but still.121 // 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
124 const c = modf(f64(1.0));124 const c = modf(f64(1.0));
125 const d = modf64(1.0);125 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);
127}127}
128128
129test "math.modf32" {129test "math.modf32" {
...@@ -131,24 +131,24 @@ test "math.modf32" {...@@ -131,24 +131,24 @@ test "math.modf32" {
131 var r: modf32_result = undefined;131 var r: modf32_result = undefined;
132132
133 r = modf32(1.0);133 r = modf32(1.0);
134 assert(math.approxEq(f32, r.ipart, 1.0, epsilon));134 expect(math.approxEq(f32, r.ipart, 1.0, epsilon));
135 assert(math.approxEq(f32, r.fpart, 0.0, epsilon));135 expect(math.approxEq(f32, r.fpart, 0.0, epsilon));
136136
137 r = modf32(2.545);137 r = modf32(2.545);
138 assert(math.approxEq(f32, r.ipart, 2.0, epsilon));138 expect(math.approxEq(f32, r.ipart, 2.0, epsilon));
139 assert(math.approxEq(f32, r.fpart, 0.545, epsilon));139 expect(math.approxEq(f32, r.fpart, 0.545, epsilon));
140140
141 r = modf32(3.978123);141 r = modf32(3.978123);
142 assert(math.approxEq(f32, r.ipart, 3.0, epsilon));142 expect(math.approxEq(f32, r.ipart, 3.0, epsilon));
143 assert(math.approxEq(f32, r.fpart, 0.978123, epsilon));143 expect(math.approxEq(f32, r.fpart, 0.978123, epsilon));
144144
145 r = modf32(43874.3);145 r = modf32(43874.3);
146 assert(math.approxEq(f32, r.ipart, 43874, epsilon));146 expect(math.approxEq(f32, r.ipart, 43874, epsilon));
147 assert(math.approxEq(f32, r.fpart, 0.300781, epsilon));147 expect(math.approxEq(f32, r.fpart, 0.300781, epsilon));
148148
149 r = modf32(1234.340780);149 r = modf32(1234.340780);
150 assert(math.approxEq(f32, r.ipart, 1234, epsilon));150 expect(math.approxEq(f32, r.ipart, 1234, epsilon));
151 assert(math.approxEq(f32, r.fpart, 0.340820, epsilon));151 expect(math.approxEq(f32, r.fpart, 0.340820, epsilon));
152}152}
153153
154test "math.modf64" {154test "math.modf64" {
...@@ -156,48 +156,48 @@ test "math.modf64" {...@@ -156,48 +156,48 @@ test "math.modf64" {
156 var r: modf64_result = undefined;156 var r: modf64_result = undefined;
157157
158 r = modf64(1.0);158 r = modf64(1.0);
159 assert(math.approxEq(f64, r.ipart, 1.0, epsilon));159 expect(math.approxEq(f64, r.ipart, 1.0, epsilon));
160 assert(math.approxEq(f64, r.fpart, 0.0, epsilon));160 expect(math.approxEq(f64, r.fpart, 0.0, epsilon));
161161
162 r = modf64(2.545);162 r = modf64(2.545);
163 assert(math.approxEq(f64, r.ipart, 2.0, epsilon));163 expect(math.approxEq(f64, r.ipart, 2.0, epsilon));
164 assert(math.approxEq(f64, r.fpart, 0.545, epsilon));164 expect(math.approxEq(f64, r.fpart, 0.545, epsilon));
165165
166 r = modf64(3.978123);166 r = modf64(3.978123);
167 assert(math.approxEq(f64, r.ipart, 3.0, epsilon));167 expect(math.approxEq(f64, r.ipart, 3.0, epsilon));
168 assert(math.approxEq(f64, r.fpart, 0.978123, epsilon));168 expect(math.approxEq(f64, r.fpart, 0.978123, epsilon));
169169
170 r = modf64(43874.3);170 r = modf64(43874.3);
171 assert(math.approxEq(f64, r.ipart, 43874, epsilon));171 expect(math.approxEq(f64, r.ipart, 43874, epsilon));
172 assert(math.approxEq(f64, r.fpart, 0.3, epsilon));172 expect(math.approxEq(f64, r.fpart, 0.3, epsilon));
173173
174 r = modf64(1234.340780);174 r = modf64(1234.340780);
175 assert(math.approxEq(f64, r.ipart, 1234, epsilon));175 expect(math.approxEq(f64, r.ipart, 1234, epsilon));
176 assert(math.approxEq(f64, r.fpart, 0.340780, epsilon));176 expect(math.approxEq(f64, r.fpart, 0.340780, epsilon));
177}177}
178178
179test "math.modf32.special" {179test "math.modf32.special" {
180 var r: modf32_result = undefined;180 var r: modf32_result = undefined;
181181
182 r = modf32(math.inf(f32));182 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
185 r = modf32(-math.inf(f32));185 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
188 r = modf32(math.nan(f32));188 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));
190}190}
191191
192test "math.modf64.special" {192test "math.modf64.special" {
193 var r: modf64_result = undefined;193 var r: modf64_result = undefined;
194194
195 r = modf64(math.inf(f64));195 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
198 r = modf64(-math.inf(f64));198 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
201 r = modf64(math.nan(f64));201 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));
203}203}
std/math/pow.zig+48-48
...@@ -24,7 +24,7 @@...@@ -24,7 +24,7 @@
24const builtin = @import("builtin");24const builtin = @import("builtin");
25const std = @import("../index.zig");25const std = @import("../index.zig");
26const math = std.math;26const math = std.math;
27const assert = std.debug.assert;27const expect = std.testing.expect;
2828
29// This implementation is taken from the go stlib, musl is a bit more complex.29// This implementation is taken from the go stlib, musl is a bit more complex.
30pub fn pow(comptime T: type, x: T, y: T) T {30pub fn pow(comptime T: type, x: T, y: T) T {
...@@ -179,56 +179,56 @@ fn isOddInteger(x: f64) bool {...@@ -179,56 +179,56 @@ fn isOddInteger(x: f64) bool {
179test "math.pow" {179test "math.pow" {
180 const epsilon = 0.000001;180 const epsilon = 0.000001;
181181
182 assert(math.approxEq(f32, pow(f32, 0.0, 3.3), 0.0, epsilon));182 expect(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));183 expect(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));184 expect(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));185 expect(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));186 expect(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));187 expect(math.approxEq(f32, pow(f32, 89.123, 3.3), 2722489.5, epsilon));
188188
189 assert(math.approxEq(f64, pow(f64, 0.0, 3.3), 0.0, epsilon));189 expect(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));190 expect(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));191 expect(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));192 expect(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));193 expect(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));194 expect(math.approxEq(f64, pow(f64, 89.123, 3.3), 2722490.231436, epsilon));
195}195}
196196
197test "math.pow.special" {197test "math.pow.special" {
198 const epsilon = 0.000001;198 const epsilon = 0.000001;
199199
200 assert(pow(f32, 4, 0.0) == 1.0);200 expect(pow(f32, 4, 0.0) == 1.0);
201 assert(pow(f32, 7, -0.0) == 1.0);201 expect(pow(f32, 7, -0.0) == 1.0);
202 assert(pow(f32, 45, 1.0) == 45);202 expect(pow(f32, 45, 1.0) == 45);
203 assert(pow(f32, -45, 1.0) == -45);203 expect(pow(f32, -45, 1.0) == -45);
204 assert(math.isNan(pow(f32, math.nan(f32), 5.0)));204 expect(math.isNan(pow(f32, math.nan(f32), 5.0)));
205 assert(math.isNan(pow(f32, 5.0, math.nan(f32))));205 expect(math.isNan(pow(f32, 5.0, math.nan(f32))));
206 assert(math.isPositiveInf(pow(f32, 0.0, -1.0)));206 expect(math.isPositiveInf(pow(f32, 0.0, -1.0)));
207 //assert(math.isNegativeInf(pow(f32, -0.0, -3.0))); TODO is this required?207 //expect(math.isNegativeInf(pow(f32, -0.0, -3.0))); TODO is this required?
208 assert(math.isPositiveInf(pow(f32, 0.0, -math.inf(f32))));208 expect(math.isPositiveInf(pow(f32, 0.0, -math.inf(f32))));
209 assert(math.isPositiveInf(pow(f32, -0.0, -math.inf(f32))));209 expect(math.isPositiveInf(pow(f32, -0.0, -math.inf(f32))));
210 assert(pow(f32, 0.0, math.inf(f32)) == 0.0);210 expect(pow(f32, 0.0, math.inf(f32)) == 0.0);
211 assert(pow(f32, -0.0, math.inf(f32)) == 0.0);211 expect(pow(f32, -0.0, math.inf(f32)) == 0.0);
212 assert(math.isPositiveInf(pow(f32, 0.0, -2.0)));212 expect(math.isPositiveInf(pow(f32, 0.0, -2.0)));
213 assert(math.isPositiveInf(pow(f32, -0.0, -2.0)));213 expect(math.isPositiveInf(pow(f32, -0.0, -2.0)));
214 assert(pow(f32, 0.0, 1.0) == 0.0);214 expect(pow(f32, 0.0, 1.0) == 0.0);
215 assert(pow(f32, -0.0, 1.0) == -0.0);215 expect(pow(f32, -0.0, 1.0) == -0.0);
216 assert(pow(f32, 0.0, 2.0) == 0.0);216 expect(pow(f32, 0.0, 2.0) == 0.0);
217 assert(pow(f32, -0.0, 2.0) == 0.0);217 expect(pow(f32, -0.0, 2.0) == 0.0);
218 assert(math.approxEq(f32, pow(f32, -1.0, math.inf(f32)), 1.0, epsilon));218 expect(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));219 expect(math.approxEq(f32, pow(f32, -1.0, -math.inf(f32)), 1.0, epsilon));
220 assert(math.isPositiveInf(pow(f32, 1.2, math.inf(f32))));220 expect(math.isPositiveInf(pow(f32, 1.2, math.inf(f32))));
221 assert(math.isPositiveInf(pow(f32, -1.2, math.inf(f32))));221 expect(math.isPositiveInf(pow(f32, -1.2, math.inf(f32))));
222 assert(pow(f32, 1.2, -math.inf(f32)) == 0.0);222 expect(pow(f32, 1.2, -math.inf(f32)) == 0.0);
223 assert(pow(f32, -1.2, -math.inf(f32)) == 0.0);223 expect(pow(f32, -1.2, -math.inf(f32)) == 0.0);
224 assert(pow(f32, 0.2, math.inf(f32)) == 0.0);224 expect(pow(f32, 0.2, math.inf(f32)) == 0.0);
225 assert(pow(f32, -0.2, math.inf(f32)) == 0.0);225 expect(pow(f32, -0.2, math.inf(f32)) == 0.0);
226 assert(math.isPositiveInf(pow(f32, 0.2, -math.inf(f32))));226 expect(math.isPositiveInf(pow(f32, 0.2, -math.inf(f32))));
227 assert(math.isPositiveInf(pow(f32, -0.2, -math.inf(f32))));227 expect(math.isPositiveInf(pow(f32, -0.2, -math.inf(f32))));
228 assert(math.isPositiveInf(pow(f32, math.inf(f32), 1.0)));228 expect(math.isPositiveInf(pow(f32, math.inf(f32), 1.0)));
229 assert(pow(f32, math.inf(f32), -1.0) == 0.0);229 expect(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?230 //expect(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));231 expect(pow(f32, -math.inf(f32), -5.2) == pow(f32, -0.0, 5.2));
232 assert(math.isNan(pow(f32, -1.0, 1.2)));232 expect(math.isNan(pow(f32, -1.0, 1.2)));
233 assert(math.isNan(pow(f32, -12.4, 78.5)));233 expect(math.isNan(pow(f32, -12.4, 78.5)));
234}234}
std/math/powi.zig+69-69
...@@ -12,7 +12,7 @@ const builtin = @import("builtin");...@@ -12,7 +12,7 @@ const builtin = @import("builtin");
12const std = @import("../index.zig");12const std = @import("../index.zig");
13const math = std.math;13const math = std.math;
14const assert = std.debug.assert;14const assert = std.debug.assert;
15const assertError = std.debug.assertError;15const testing = std.testing;
1616
17// This implementation is based on that from the rust stlib17// This implementation is based on that from the rust stlib
18pub fn powi(comptime T: type, x: T, y: T) (error{18pub 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{...@@ -103,75 +103,75 @@ pub fn powi(comptime T: type, x: T, y: T) (error{
103}103}
104104
105test "math.powi" {105test "math.powi" {
106 assertError(powi(i8, -66, 6), error.Underflow);106 testing.expectError(error.Underflow, powi(i8, -66, 6));
107 assertError(powi(i16, -13, 13), error.Underflow);107 testing.expectError(error.Underflow, powi(i16, -13, 13));
108 assertError(powi(i32, -32, 21), error.Underflow);108 testing.expectError(error.Underflow, powi(i32, -32, 21));
109 assertError(powi(i64, -24, 61), error.Underflow);109 testing.expectError(error.Underflow, powi(i64, -24, 61));
110 assertError(powi(i17, -15, 15), error.Underflow);110 testing.expectError(error.Underflow, powi(i17, -15, 15));
111 assertError(powi(i42, -6, 40), error.Underflow);111 testing.expectError(error.Underflow, powi(i42, -6, 40));
112112
113 assert((try powi(i8, -5, 3)) == -125);113 testing.expect((try powi(i8, -5, 3)) == -125);
114 assert((try powi(i16, -16, 3)) == -4096);114 testing.expect((try powi(i16, -16, 3)) == -4096);
115 assert((try powi(i32, -91, 3)) == -753571);115 testing.expect((try powi(i32, -91, 3)) == -753571);
116 assert((try powi(i64, -36, 6)) == 2176782336);116 testing.expect((try powi(i64, -36, 6)) == 2176782336);
117 assert((try powi(i17, -2, 15)) == -32768);117 testing.expect((try powi(i17, -2, 15)) == -32768);
118 assert((try powi(i42, -5, 7)) == -78125);118 testing.expect((try powi(i42, -5, 7)) == -78125);
119119
120 assert((try powi(u8, 6, 2)) == 36);120 testing.expect((try powi(u8, 6, 2)) == 36);
121 assert((try powi(u16, 5, 4)) == 625);121 testing.expect((try powi(u16, 5, 4)) == 625);
122 assert((try powi(u32, 12, 6)) == 2985984);122 testing.expect((try powi(u32, 12, 6)) == 2985984);
123 assert((try powi(u64, 34, 2)) == 1156);123 testing.expect((try powi(u64, 34, 2)) == 1156);
124 assert((try powi(u17, 16, 3)) == 4096);124 testing.expect((try powi(u17, 16, 3)) == 4096);
125 assert((try powi(u42, 34, 6)) == 1544804416);125 testing.expect((try powi(u42, 34, 6)) == 1544804416);
126126
127 assertError(powi(i8, 120, 7), error.Overflow);127 testing.expectError(error.Overflow, powi(i8, 120, 7));
128 assertError(powi(i16, 73, 15), error.Overflow);128 testing.expectError(error.Overflow, powi(i16, 73, 15));
129 assertError(powi(i32, 23, 31), error.Overflow);129 testing.expectError(error.Overflow, powi(i32, 23, 31));
130 assertError(powi(i64, 68, 61), error.Overflow);130 testing.expectError(error.Overflow, powi(i64, 68, 61));
131 assertError(powi(i17, 15, 15), error.Overflow);131 testing.expectError(error.Overflow, powi(i17, 15, 15));
132 assertError(powi(i42, 121312, 41), error.Overflow);132 testing.expectError(error.Overflow, powi(i42, 121312, 41));
133133
134 assertError(powi(u8, 123, 7), error.Overflow);134 testing.expectError(error.Overflow, powi(u8, 123, 7));
135 assertError(powi(u16, 2313, 15), error.Overflow);135 testing.expectError(error.Overflow, powi(u16, 2313, 15));
136 assertError(powi(u32, 8968, 31), error.Overflow);136 testing.expectError(error.Overflow, powi(u32, 8968, 31));
137 assertError(powi(u64, 2342, 63), error.Overflow);137 testing.expectError(error.Overflow, powi(u64, 2342, 63));
138 assertError(powi(u17, 2723, 16), error.Overflow);138 testing.expectError(error.Overflow, powi(u17, 2723, 16));
139 assertError(powi(u42, 8234, 41), error.Overflow);139 testing.expectError(error.Overflow, powi(u42, 8234, 41));
140}140}
141141
142test "math.powi.special" {142test "math.powi.special" {
143 assertError(powi(i8, -2, 8), error.Underflow);143 testing.expectError(error.Underflow, powi(i8, -2, 8));
144 assertError(powi(i16, -2, 16), error.Underflow);144 testing.expectError(error.Underflow, powi(i16, -2, 16));
145 assertError(powi(i32, -2, 32), error.Underflow);145 testing.expectError(error.Underflow, powi(i32, -2, 32));
146 assertError(powi(i64, -2, 64), error.Underflow);146 testing.expectError(error.Underflow, powi(i64, -2, 64));
147 assertError(powi(i17, -2, 17), error.Underflow);147 testing.expectError(error.Underflow, powi(i17, -2, 17));
148 assertError(powi(i42, -2, 42), error.Underflow);148 testing.expectError(error.Underflow, powi(i42, -2, 42));
149149
150 assert((try powi(i8, -1, 3)) == -1);150 testing.expect((try powi(i8, -1, 3)) == -1);
151 assert((try powi(i16, -1, 2)) == 1);151 testing.expect((try powi(i16, -1, 2)) == 1);
152 assert((try powi(i32, -1, 16)) == 1);152 testing.expect((try powi(i32, -1, 16)) == 1);
153 assert((try powi(i64, -1, 6)) == 1);153 testing.expect((try powi(i64, -1, 6)) == 1);
154 assert((try powi(i17, -1, 15)) == -1);154 testing.expect((try powi(i17, -1, 15)) == -1);
155 assert((try powi(i42, -1, 7)) == -1);155 testing.expect((try powi(i42, -1, 7)) == -1);
156156
157 assert((try powi(u8, 1, 2)) == 1);157 testing.expect((try powi(u8, 1, 2)) == 1);
158 assert((try powi(u16, 1, 4)) == 1);158 testing.expect((try powi(u16, 1, 4)) == 1);
159 assert((try powi(u32, 1, 6)) == 1);159 testing.expect((try powi(u32, 1, 6)) == 1);
160 assert((try powi(u64, 1, 2)) == 1);160 testing.expect((try powi(u64, 1, 2)) == 1);
161 assert((try powi(u17, 1, 3)) == 1);161 testing.expect((try powi(u17, 1, 3)) == 1);
162 assert((try powi(u42, 1, 6)) == 1);162 testing.expect((try powi(u42, 1, 6)) == 1);
163163
164 assertError(powi(i8, 2, 7), error.Overflow);164 testing.expectError(error.Overflow, powi(i8, 2, 7));
165 assertError(powi(i16, 2, 15), error.Overflow);165 testing.expectError(error.Overflow, powi(i16, 2, 15));
166 assertError(powi(i32, 2, 31), error.Overflow);166 testing.expectError(error.Overflow, powi(i32, 2, 31));
167 assertError(powi(i64, 2, 63), error.Overflow);167 testing.expectError(error.Overflow, powi(i64, 2, 63));
168 assertError(powi(i17, 2, 16), error.Overflow);168 testing.expectError(error.Overflow, powi(i17, 2, 16));
169 assertError(powi(i42, 2, 41), error.Overflow);169 testing.expectError(error.Overflow, powi(i42, 2, 41));
170170
171 assertError(powi(u8, 2, 8), error.Overflow);171 testing.expectError(error.Overflow, powi(u8, 2, 8));
172 assertError(powi(u16, 2, 16), error.Overflow);172 testing.expectError(error.Overflow, powi(u16, 2, 16));
173 assertError(powi(u32, 2, 32), error.Overflow);173 testing.expectError(error.Overflow, powi(u32, 2, 32));
174 assertError(powi(u64, 2, 64), error.Overflow);174 testing.expectError(error.Overflow, powi(u64, 2, 64));
175 assertError(powi(u17, 2, 17), error.Overflow);175 testing.expectError(error.Overflow, powi(u17, 2, 17));
176 assertError(powi(u42, 2, 42), error.Overflow);176 testing.expectError(error.Overflow, powi(u42, 2, 42));
177}177}
std/math/round.zig+21-21
...@@ -5,7 +5,7 @@...@@ -5,7 +5,7 @@
5// - round(nan) = nan5// - round(nan) = nan
66
7const builtin = @import("builtin");7const builtin = @import("builtin");
8const assert = std.debug.assert;8const expect = std.testing.expect;
9const std = @import("../index.zig");9const std = @import("../index.zig");
10const math = std.math;10const math = std.math;
1111
...@@ -85,36 +85,36 @@ fn round64(x_: f64) f64 {...@@ -85,36 +85,36 @@ fn round64(x_: f64) f64 {
85}85}
8686
87test "math.round" {87test "math.round" {
88 assert(round(f32(1.3)) == round32(1.3));88 expect(round(f32(1.3)) == round32(1.3));
89 assert(round(f64(1.3)) == round64(1.3));89 expect(round(f64(1.3)) == round64(1.3));
90}90}
9191
92test "math.round32" {92test "math.round32" {
93 assert(round32(1.3) == 1.0);93 expect(round32(1.3) == 1.0);
94 assert(round32(-1.3) == -1.0);94 expect(round32(-1.3) == -1.0);
95 assert(round32(0.2) == 0.0);95 expect(round32(0.2) == 0.0);
96 assert(round32(1.8) == 2.0);96 expect(round32(1.8) == 2.0);
97}97}
9898
99test "math.round64" {99test "math.round64" {
100 assert(round64(1.3) == 1.0);100 expect(round64(1.3) == 1.0);
101 assert(round64(-1.3) == -1.0);101 expect(round64(-1.3) == -1.0);
102 assert(round64(0.2) == 0.0);102 expect(round64(0.2) == 0.0);
103 assert(round64(1.8) == 2.0);103 expect(round64(1.8) == 2.0);
104}104}
105105
106test "math.round32.special" {106test "math.round32.special" {
107 assert(round32(0.0) == 0.0);107 expect(round32(0.0) == 0.0);
108 assert(round32(-0.0) == -0.0);108 expect(round32(-0.0) == -0.0);
109 assert(math.isPositiveInf(round32(math.inf(f32))));109 expect(math.isPositiveInf(round32(math.inf(f32))));
110 assert(math.isNegativeInf(round32(-math.inf(f32))));110 expect(math.isNegativeInf(round32(-math.inf(f32))));
111 assert(math.isNan(round32(math.nan(f32))));111 expect(math.isNan(round32(math.nan(f32))));
112}112}
113113
114test "math.round64.special" {114test "math.round64.special" {
115 assert(round64(0.0) == 0.0);115 expect(round64(0.0) == 0.0);
116 assert(round64(-0.0) == -0.0);116 expect(round64(-0.0) == -0.0);
117 assert(math.isPositiveInf(round64(math.inf(f64))));117 expect(math.isPositiveInf(round64(math.inf(f64))));
118 assert(math.isNegativeInf(round64(-math.inf(f64))));118 expect(math.isNegativeInf(round64(-math.inf(f64))));
119 assert(math.isNan(round64(math.nan(f64))));119 expect(math.isNan(round64(math.nan(f64))));
120}120}
std/math/scalbn.zig+5-5
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const std = @import("../index.zig");1const std = @import("../index.zig");
2const math = std.math;2const math = std.math;
3const assert = std.debug.assert;3const expect = std.testing.expect;
44
5pub fn scalbn(x: var, n: i32) @typeOf(x) {5pub fn scalbn(x: var, n: i32) @typeOf(x) {
6 const T = @typeOf(x);6 const T = @typeOf(x);
...@@ -72,14 +72,14 @@ fn scalbn64(x: f64, n_: i32) f64 {...@@ -72,14 +72,14 @@ fn scalbn64(x: f64, n_: i32) f64 {
72}72}
7373
74test "math.scalbn" {74test "math.scalbn" {
75 assert(scalbn(f32(1.5), 4) == scalbn32(1.5, 4));75 expect(scalbn(f32(1.5), 4) == scalbn32(1.5, 4));
76 assert(scalbn(f64(1.5), 4) == scalbn64(1.5, 4));76 expect(scalbn(f64(1.5), 4) == scalbn64(1.5, 4));
77}77}
7878
79test "math.scalbn32" {79test "math.scalbn32" {
80 assert(scalbn32(1.5, 4) == 24.0);80 expect(scalbn32(1.5, 4) == 24.0);
81}81}
8282
83test "math.scalbn64" {83test "math.scalbn64" {
84 assert(scalbn64(1.5, 4) == 24.0);84 expect(scalbn64(1.5, 4) == 24.0);
85}85}
std/math/signbit.zig+10-10
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const std = @import("../index.zig");1const std = @import("../index.zig");
2const math = std.math;2const math = std.math;
3const assert = std.debug.assert;3const expect = std.testing.expect;
44
5pub fn signbit(x: var) bool {5pub fn signbit(x: var) bool {
6 const T = @typeOf(x);6 const T = @typeOf(x);
...@@ -28,22 +28,22 @@ fn signbit64(x: f64) bool {...@@ -28,22 +28,22 @@ fn signbit64(x: f64) bool {
28}28}
2929
30test "math.signbit" {30test "math.signbit" {
31 assert(signbit(f16(4.0)) == signbit16(4.0));31 expect(signbit(f16(4.0)) == signbit16(4.0));
32 assert(signbit(f32(4.0)) == signbit32(4.0));32 expect(signbit(f32(4.0)) == signbit32(4.0));
33 assert(signbit(f64(4.0)) == signbit64(4.0));33 expect(signbit(f64(4.0)) == signbit64(4.0));
34}34}
3535
36test "math.signbit16" {36test "math.signbit16" {
37 assert(!signbit16(4.0));37 expect(!signbit16(4.0));
38 assert(signbit16(-3.0));38 expect(signbit16(-3.0));
39}39}
4040
41test "math.signbit32" {41test "math.signbit32" {
42 assert(!signbit32(4.0));42 expect(!signbit32(4.0));
43 assert(signbit32(-3.0));43 expect(signbit32(-3.0));
44}44}
4545
46test "math.signbit64" {46test "math.signbit64" {
47 assert(!signbit64(4.0));47 expect(!signbit64(4.0));
48 assert(signbit64(-3.0));48 expect(signbit64(-3.0));
49}49}
std/math/sin.zig+26-26
...@@ -7,7 +7,7 @@...@@ -7,7 +7,7 @@
7const builtin = @import("builtin");7const builtin = @import("builtin");
8const std = @import("../index.zig");8const std = @import("../index.zig");
9const math = std.math;9const math = std.math;
10const assert = std.debug.assert;10const expect = std.testing.expect;
1111
12pub fn sin(x: var) @typeOf(x) {12pub fn sin(x: var) @typeOf(x) {
13 const T = @typeOf(x);13 const T = @typeOf(x);
...@@ -142,45 +142,45 @@ fn sin64(x_: f64) f64 {...@@ -142,45 +142,45 @@ fn sin64(x_: f64) f64 {
142}142}
143143
144test "math.sin" {144test "math.sin" {
145 assert(sin(f32(0.0)) == sin32(0.0));145 expect(sin(f32(0.0)) == sin32(0.0));
146 assert(sin(f64(0.0)) == sin64(0.0));146 expect(sin(f64(0.0)) == sin64(0.0));
147 assert(comptime (math.sin(f64(2))) == math.sin(f64(2)));147 expect(comptime (math.sin(f64(2))) == math.sin(f64(2)));
148}148}
149149
150test "math.sin32" {150test "math.sin32" {
151 const epsilon = 0.000001;151 const epsilon = 0.000001;
152152
153 assert(math.approxEq(f32, sin32(0.0), 0.0, epsilon));153 expect(math.approxEq(f32, sin32(0.0), 0.0, epsilon));
154 assert(math.approxEq(f32, sin32(0.2), 0.198669, epsilon));154 expect(math.approxEq(f32, sin32(0.2), 0.198669, epsilon));
155 assert(math.approxEq(f32, sin32(0.8923), 0.778517, epsilon));155 expect(math.approxEq(f32, sin32(0.8923), 0.778517, epsilon));
156 assert(math.approxEq(f32, sin32(1.5), 0.997495, epsilon));156 expect(math.approxEq(f32, sin32(1.5), 0.997495, epsilon));
157 assert(math.approxEq(f32, sin32(37.45), -0.246544, epsilon));157 expect(math.approxEq(f32, sin32(37.45), -0.246544, epsilon));
158 assert(math.approxEq(f32, sin32(89.123), 0.916166, epsilon));158 expect(math.approxEq(f32, sin32(89.123), 0.916166, epsilon));
159}159}
160160
161test "math.sin64" {161test "math.sin64" {
162 const epsilon = 0.000001;162 const epsilon = 0.000001;
163163
164 assert(math.approxEq(f64, sin64(0.0), 0.0, epsilon));164 expect(math.approxEq(f64, sin64(0.0), 0.0, epsilon));
165 assert(math.approxEq(f64, sin64(0.2), 0.198669, epsilon));165 expect(math.approxEq(f64, sin64(0.2), 0.198669, epsilon));
166 assert(math.approxEq(f64, sin64(0.8923), 0.778517, epsilon));166 expect(math.approxEq(f64, sin64(0.8923), 0.778517, epsilon));
167 assert(math.approxEq(f64, sin64(1.5), 0.997495, epsilon));167 expect(math.approxEq(f64, sin64(1.5), 0.997495, epsilon));
168 assert(math.approxEq(f64, sin64(37.45), -0.246543, epsilon));168 expect(math.approxEq(f64, sin64(37.45), -0.246543, epsilon));
169 assert(math.approxEq(f64, sin64(89.123), 0.916166, epsilon));169 expect(math.approxEq(f64, sin64(89.123), 0.916166, epsilon));
170}170}
171171
172test "math.sin32.special" {172test "math.sin32.special" {
173 assert(sin32(0.0) == 0.0);173 expect(sin32(0.0) == 0.0);
174 assert(sin32(-0.0) == -0.0);174 expect(sin32(-0.0) == -0.0);
175 assert(math.isNan(sin32(math.inf(f32))));175 expect(math.isNan(sin32(math.inf(f32))));
176 assert(math.isNan(sin32(-math.inf(f32))));176 expect(math.isNan(sin32(-math.inf(f32))));
177 assert(math.isNan(sin32(math.nan(f32))));177 expect(math.isNan(sin32(math.nan(f32))));
178}178}
179179
180test "math.sin64.special" {180test "math.sin64.special" {
181 assert(sin64(0.0) == 0.0);181 expect(sin64(0.0) == 0.0);
182 assert(sin64(-0.0) == -0.0);182 expect(sin64(-0.0) == -0.0);
183 assert(math.isNan(sin64(math.inf(f64))));183 expect(math.isNan(sin64(math.inf(f64))));
184 assert(math.isNan(sin64(-math.inf(f64))));184 expect(math.isNan(sin64(-math.inf(f64))));
185 assert(math.isNan(sin64(math.nan(f64))));185 expect(math.isNan(sin64(math.nan(f64))));
186}186}
std/math/sinh.zig+21-21
...@@ -7,7 +7,7 @@...@@ -7,7 +7,7 @@
7const builtin = @import("builtin");7const builtin = @import("builtin");
8const std = @import("../index.zig");8const std = @import("../index.zig");
9const math = std.math;9const math = std.math;
10const assert = std.debug.assert;10const expect = std.testing.expect;
11const expo2 = @import("expo2.zig").expo2;11const expo2 = @import("expo2.zig").expo2;
12const maxInt = std.math.maxInt;12const maxInt = std.math.maxInt;
1313
...@@ -87,40 +87,40 @@ fn sinh64(x: f64) f64 {...@@ -87,40 +87,40 @@ fn sinh64(x: f64) f64 {
87}87}
8888
89test "math.sinh" {89test "math.sinh" {
90 assert(sinh(f32(1.5)) == sinh32(1.5));90 expect(sinh(f32(1.5)) == sinh32(1.5));
91 assert(sinh(f64(1.5)) == sinh64(1.5));91 expect(sinh(f64(1.5)) == sinh64(1.5));
92}92}
9393
94test "math.sinh32" {94test "math.sinh32" {
95 const epsilon = 0.000001;95 const epsilon = 0.000001;
9696
97 assert(math.approxEq(f32, sinh32(0.0), 0.0, epsilon));97 expect(math.approxEq(f32, sinh32(0.0), 0.0, epsilon));
98 assert(math.approxEq(f32, sinh32(0.2), 0.201336, epsilon));98 expect(math.approxEq(f32, sinh32(0.2), 0.201336, epsilon));
99 assert(math.approxEq(f32, sinh32(0.8923), 1.015512, epsilon));99 expect(math.approxEq(f32, sinh32(0.8923), 1.015512, epsilon));
100 assert(math.approxEq(f32, sinh32(1.5), 2.129279, epsilon));100 expect(math.approxEq(f32, sinh32(1.5), 2.129279, epsilon));
101}101}
102102
103test "math.sinh64" {103test "math.sinh64" {
104 const epsilon = 0.000001;104 const epsilon = 0.000001;
105105
106 assert(math.approxEq(f64, sinh64(0.0), 0.0, epsilon));106 expect(math.approxEq(f64, sinh64(0.0), 0.0, epsilon));
107 assert(math.approxEq(f64, sinh64(0.2), 0.201336, epsilon));107 expect(math.approxEq(f64, sinh64(0.2), 0.201336, epsilon));
108 assert(math.approxEq(f64, sinh64(0.8923), 1.015512, epsilon));108 expect(math.approxEq(f64, sinh64(0.8923), 1.015512, epsilon));
109 assert(math.approxEq(f64, sinh64(1.5), 2.129279, epsilon));109 expect(math.approxEq(f64, sinh64(1.5), 2.129279, epsilon));
110}110}
111111
112test "math.sinh32.special" {112test "math.sinh32.special" {
113 assert(sinh32(0.0) == 0.0);113 expect(sinh32(0.0) == 0.0);
114 assert(sinh32(-0.0) == -0.0);114 expect(sinh32(-0.0) == -0.0);
115 assert(math.isPositiveInf(sinh32(math.inf(f32))));115 expect(math.isPositiveInf(sinh32(math.inf(f32))));
116 assert(math.isNegativeInf(sinh32(-math.inf(f32))));116 expect(math.isNegativeInf(sinh32(-math.inf(f32))));
117 assert(math.isNan(sinh32(math.nan(f32))));117 expect(math.isNan(sinh32(math.nan(f32))));
118}118}
119119
120test "math.sinh64.special" {120test "math.sinh64.special" {
121 assert(sinh64(0.0) == 0.0);121 expect(sinh64(0.0) == 0.0);
122 assert(sinh64(-0.0) == -0.0);122 expect(sinh64(-0.0) == -0.0);
123 assert(math.isPositiveInf(sinh64(math.inf(f64))));123 expect(math.isPositiveInf(sinh64(math.inf(f64))));
124 assert(math.isNegativeInf(sinh64(-math.inf(f64))));124 expect(math.isNegativeInf(sinh64(-math.inf(f64))));
125 assert(math.isNan(sinh64(math.nan(f64))));125 expect(math.isNan(sinh64(math.nan(f64))));
126}126}
std/math/sqrt.zig+52-52
...@@ -7,7 +7,7 @@...@@ -7,7 +7,7 @@
77
8const std = @import("../index.zig");8const std = @import("../index.zig");
9const math = std.math;9const math = std.math;
10const assert = std.debug.assert;10const expect = std.testing.expect;
11const builtin = @import("builtin");11const builtin = @import("builtin");
12const TypeId = builtin.TypeId;12const TypeId = builtin.TypeId;
13const maxInt = std.math.maxInt;13const maxInt = std.math.maxInt;
...@@ -32,75 +32,75 @@ pub fn sqrt(x: var) (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typ...@@ -32,75 +32,75 @@ pub fn sqrt(x: var) (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typ
32}32}
3333
34test "math.sqrt" {34test "math.sqrt" {
35 assert(sqrt(f16(0.0)) == @sqrt(f16, 0.0));35 expect(sqrt(f16(0.0)) == @sqrt(f16, 0.0));
36 assert(sqrt(f32(0.0)) == @sqrt(f32, 0.0));36 expect(sqrt(f32(0.0)) == @sqrt(f32, 0.0));
37 assert(sqrt(f64(0.0)) == @sqrt(f64, 0.0));37 expect(sqrt(f64(0.0)) == @sqrt(f64, 0.0));
38}38}
3939
40test "math.sqrt16" {40test "math.sqrt16" {
41 const epsilon = 0.000001;41 const epsilon = 0.000001;
4242
43 assert(@sqrt(f16, 0.0) == 0.0);43 expect(@sqrt(f16, 0.0) == 0.0);
44 assert(math.approxEq(f16, @sqrt(f16, 2.0), 1.414214, epsilon));44 expect(math.approxEq(f16, @sqrt(f16, 2.0), 1.414214, epsilon));
45 assert(math.approxEq(f16, @sqrt(f16, 3.6), 1.897367, epsilon));45 expect(math.approxEq(f16, @sqrt(f16, 3.6), 1.897367, epsilon));
46 assert(@sqrt(f16, 4.0) == 2.0);46 expect(@sqrt(f16, 4.0) == 2.0);
47 assert(math.approxEq(f16, @sqrt(f16, 7.539840), 2.745877, epsilon));47 expect(math.approxEq(f16, @sqrt(f16, 7.539840), 2.745877, epsilon));
48 assert(math.approxEq(f16, @sqrt(f16, 19.230934), 4.385309, epsilon));48 expect(math.approxEq(f16, @sqrt(f16, 19.230934), 4.385309, epsilon));
49 assert(@sqrt(f16, 64.0) == 8.0);49 expect(@sqrt(f16, 64.0) == 8.0);
50 assert(math.approxEq(f16, @sqrt(f16, 64.1), 8.006248, epsilon));50 expect(math.approxEq(f16, @sqrt(f16, 64.1), 8.006248, epsilon));
51 assert(math.approxEq(f16, @sqrt(f16, 8942.230469), 94.563370, epsilon));51 expect(math.approxEq(f16, @sqrt(f16, 8942.230469), 94.563370, epsilon));
52}52}
5353
54test "math.sqrt32" {54test "math.sqrt32" {
55 const epsilon = 0.000001;55 const epsilon = 0.000001;
5656
57 assert(@sqrt(f32, 0.0) == 0.0);57 expect(@sqrt(f32, 0.0) == 0.0);
58 assert(math.approxEq(f32, @sqrt(f32, 2.0), 1.414214, epsilon));58 expect(math.approxEq(f32, @sqrt(f32, 2.0), 1.414214, epsilon));
59 assert(math.approxEq(f32, @sqrt(f32, 3.6), 1.897367, epsilon));59 expect(math.approxEq(f32, @sqrt(f32, 3.6), 1.897367, epsilon));
60 assert(@sqrt(f32, 4.0) == 2.0);60 expect(@sqrt(f32, 4.0) == 2.0);
61 assert(math.approxEq(f32, @sqrt(f32, 7.539840), 2.745877, epsilon));61 expect(math.approxEq(f32, @sqrt(f32, 7.539840), 2.745877, epsilon));
62 assert(math.approxEq(f32, @sqrt(f32, 19.230934), 4.385309, epsilon));62 expect(math.approxEq(f32, @sqrt(f32, 19.230934), 4.385309, epsilon));
63 assert(@sqrt(f32, 64.0) == 8.0);63 expect(@sqrt(f32, 64.0) == 8.0);
64 assert(math.approxEq(f32, @sqrt(f32, 64.1), 8.006248, epsilon));64 expect(math.approxEq(f32, @sqrt(f32, 64.1), 8.006248, epsilon));
65 assert(math.approxEq(f32, @sqrt(f32, 8942.230469), 94.563370, epsilon));65 expect(math.approxEq(f32, @sqrt(f32, 8942.230469), 94.563370, epsilon));
66}66}
6767
68test "math.sqrt64" {68test "math.sqrt64" {
69 const epsilon = 0.000001;69 const epsilon = 0.000001;
7070
71 assert(@sqrt(f64, 0.0) == 0.0);71 expect(@sqrt(f64, 0.0) == 0.0);
72 assert(math.approxEq(f64, @sqrt(f64, 2.0), 1.414214, epsilon));72 expect(math.approxEq(f64, @sqrt(f64, 2.0), 1.414214, epsilon));
73 assert(math.approxEq(f64, @sqrt(f64, 3.6), 1.897367, epsilon));73 expect(math.approxEq(f64, @sqrt(f64, 3.6), 1.897367, epsilon));
74 assert(@sqrt(f64, 4.0) == 2.0);74 expect(@sqrt(f64, 4.0) == 2.0);
75 assert(math.approxEq(f64, @sqrt(f64, 7.539840), 2.745877, epsilon));75 expect(math.approxEq(f64, @sqrt(f64, 7.539840), 2.745877, epsilon));
76 assert(math.approxEq(f64, @sqrt(f64, 19.230934), 4.385309, epsilon));76 expect(math.approxEq(f64, @sqrt(f64, 19.230934), 4.385309, epsilon));
77 assert(@sqrt(f64, 64.0) == 8.0);77 expect(@sqrt(f64, 64.0) == 8.0);
78 assert(math.approxEq(f64, @sqrt(f64, 64.1), 8.006248, epsilon));78 expect(math.approxEq(f64, @sqrt(f64, 64.1), 8.006248, epsilon));
79 assert(math.approxEq(f64, @sqrt(f64, 8942.230469), 94.563367, epsilon));79 expect(math.approxEq(f64, @sqrt(f64, 8942.230469), 94.563367, epsilon));
80}80}
8181
82test "math.sqrt16.special" {82test "math.sqrt16.special" {
83 assert(math.isPositiveInf(@sqrt(f16, math.inf(f16))));83 expect(math.isPositiveInf(@sqrt(f16, math.inf(f16))));
84 assert(@sqrt(f16, 0.0) == 0.0);84 expect(@sqrt(f16, 0.0) == 0.0);
85 assert(@sqrt(f16, -0.0) == -0.0);85 expect(@sqrt(f16, -0.0) == -0.0);
86 assert(math.isNan(@sqrt(f16, -1.0)));86 expect(math.isNan(@sqrt(f16, -1.0)));
87 assert(math.isNan(@sqrt(f16, math.nan(f16))));87 expect(math.isNan(@sqrt(f16, math.nan(f16))));
88}88}
8989
90test "math.sqrt32.special" {90test "math.sqrt32.special" {
91 assert(math.isPositiveInf(@sqrt(f32, math.inf(f32))));91 expect(math.isPositiveInf(@sqrt(f32, math.inf(f32))));
92 assert(@sqrt(f32, 0.0) == 0.0);92 expect(@sqrt(f32, 0.0) == 0.0);
93 assert(@sqrt(f32, -0.0) == -0.0);93 expect(@sqrt(f32, -0.0) == -0.0);
94 assert(math.isNan(@sqrt(f32, -1.0)));94 expect(math.isNan(@sqrt(f32, -1.0)));
95 assert(math.isNan(@sqrt(f32, math.nan(f32))));95 expect(math.isNan(@sqrt(f32, math.nan(f32))));
96}96}
9797
98test "math.sqrt64.special" {98test "math.sqrt64.special" {
99 assert(math.isPositiveInf(@sqrt(f64, math.inf(f64))));99 expect(math.isPositiveInf(@sqrt(f64, math.inf(f64))));
100 assert(@sqrt(f64, 0.0) == 0.0);100 expect(@sqrt(f64, 0.0) == 0.0);
101 assert(@sqrt(f64, -0.0) == -0.0);101 expect(@sqrt(f64, -0.0) == -0.0);
102 assert(math.isNan(@sqrt(f64, -1.0)));102 expect(math.isNan(@sqrt(f64, -1.0)));
103 assert(math.isNan(@sqrt(f64, math.nan(f64))));103 expect(math.isNan(@sqrt(f64, math.nan(f64))));
104}104}
105105
106fn sqrt_int(comptime T: type, value: T) @IntType(false, T.bit_count / 2) {106fn 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) {...@@ -127,10 +127,10 @@ fn sqrt_int(comptime T: type, value: T) @IntType(false, T.bit_count / 2) {
127}127}
128128
129test "math.sqrt_int" {129test "math.sqrt_int" {
130 assert(sqrt_int(u32, 3) == 1);130 expect(sqrt_int(u32, 3) == 1);
131 assert(sqrt_int(u32, 4) == 2);131 expect(sqrt_int(u32, 4) == 2);
132 assert(sqrt_int(u32, 5) == 2);132 expect(sqrt_int(u32, 5) == 2);
133 assert(sqrt_int(u32, 8) == 2);133 expect(sqrt_int(u32, 8) == 2);
134 assert(sqrt_int(u32, 9) == 3);134 expect(sqrt_int(u32, 9) == 3);
135 assert(sqrt_int(u32, 10) == 3);135 expect(sqrt_int(u32, 10) == 3);
136}136}
std/math/tan.zig+25-25
...@@ -7,7 +7,7 @@...@@ -7,7 +7,7 @@
7const builtin = @import("builtin");7const builtin = @import("builtin");
8const std = @import("../index.zig");8const std = @import("../index.zig");
9const math = std.math;9const math = std.math;
10const assert = std.debug.assert;10const expect = std.testing.expect;
1111
12pub fn tan(x: var) @typeOf(x) {12pub fn tan(x: var) @typeOf(x) {
13 const T = @typeOf(x);13 const T = @typeOf(x);
...@@ -129,44 +129,44 @@ fn tan64(x_: f64) f64 {...@@ -129,44 +129,44 @@ fn tan64(x_: f64) f64 {
129}129}
130130
131test "math.tan" {131test "math.tan" {
132 assert(tan(f32(0.0)) == tan32(0.0));132 expect(tan(f32(0.0)) == tan32(0.0));
133 assert(tan(f64(0.0)) == tan64(0.0));133 expect(tan(f64(0.0)) == tan64(0.0));
134}134}
135135
136test "math.tan32" {136test "math.tan32" {
137 const epsilon = 0.000001;137 const epsilon = 0.000001;
138138
139 assert(math.approxEq(f32, tan32(0.0), 0.0, epsilon));139 expect(math.approxEq(f32, tan32(0.0), 0.0, epsilon));
140 assert(math.approxEq(f32, tan32(0.2), 0.202710, epsilon));140 expect(math.approxEq(f32, tan32(0.2), 0.202710, epsilon));
141 assert(math.approxEq(f32, tan32(0.8923), 1.240422, epsilon));141 expect(math.approxEq(f32, tan32(0.8923), 1.240422, epsilon));
142 assert(math.approxEq(f32, tan32(1.5), 14.101420, epsilon));142 expect(math.approxEq(f32, tan32(1.5), 14.101420, epsilon));
143 assert(math.approxEq(f32, tan32(37.45), -0.254397, epsilon));143 expect(math.approxEq(f32, tan32(37.45), -0.254397, epsilon));
144 assert(math.approxEq(f32, tan32(89.123), 2.285852, epsilon));144 expect(math.approxEq(f32, tan32(89.123), 2.285852, epsilon));
145}145}
146146
147test "math.tan64" {147test "math.tan64" {
148 const epsilon = 0.000001;148 const epsilon = 0.000001;
149149
150 assert(math.approxEq(f64, tan64(0.0), 0.0, epsilon));150 expect(math.approxEq(f64, tan64(0.0), 0.0, epsilon));
151 assert(math.approxEq(f64, tan64(0.2), 0.202710, epsilon));151 expect(math.approxEq(f64, tan64(0.2), 0.202710, epsilon));
152 assert(math.approxEq(f64, tan64(0.8923), 1.240422, epsilon));152 expect(math.approxEq(f64, tan64(0.8923), 1.240422, epsilon));
153 assert(math.approxEq(f64, tan64(1.5), 14.101420, epsilon));153 expect(math.approxEq(f64, tan64(1.5), 14.101420, epsilon));
154 assert(math.approxEq(f64, tan64(37.45), -0.254397, epsilon));154 expect(math.approxEq(f64, tan64(37.45), -0.254397, epsilon));
155 assert(math.approxEq(f64, tan64(89.123), 2.2858376, epsilon));155 expect(math.approxEq(f64, tan64(89.123), 2.2858376, epsilon));
156}156}
157157
158test "math.tan32.special" {158test "math.tan32.special" {
159 assert(tan32(0.0) == 0.0);159 expect(tan32(0.0) == 0.0);
160 assert(tan32(-0.0) == -0.0);160 expect(tan32(-0.0) == -0.0);
161 assert(math.isNan(tan32(math.inf(f32))));161 expect(math.isNan(tan32(math.inf(f32))));
162 assert(math.isNan(tan32(-math.inf(f32))));162 expect(math.isNan(tan32(-math.inf(f32))));
163 assert(math.isNan(tan32(math.nan(f32))));163 expect(math.isNan(tan32(math.nan(f32))));
164}164}
165165
166test "math.tan64.special" {166test "math.tan64.special" {
167 assert(tan64(0.0) == 0.0);167 expect(tan64(0.0) == 0.0);
168 assert(tan64(-0.0) == -0.0);168 expect(tan64(-0.0) == -0.0);
169 assert(math.isNan(tan64(math.inf(f64))));169 expect(math.isNan(tan64(math.inf(f64))));
170 assert(math.isNan(tan64(-math.inf(f64))));170 expect(math.isNan(tan64(-math.inf(f64))));
171 assert(math.isNan(tan64(math.nan(f64))));171 expect(math.isNan(tan64(math.nan(f64))));
172}172}
std/math/tanh.zig+23-23
...@@ -7,7 +7,7 @@...@@ -7,7 +7,7 @@
7const builtin = @import("builtin");7const builtin = @import("builtin");
8const std = @import("../index.zig");8const std = @import("../index.zig");
9const math = std.math;9const math = std.math;
10const assert = std.debug.assert;10const expect = std.testing.expect;
11const expo2 = @import("expo2.zig").expo2;11const expo2 = @import("expo2.zig").expo2;
12const maxInt = std.math.maxInt;12const maxInt = std.math.maxInt;
1313
...@@ -113,42 +113,42 @@ fn tanh64(x: f64) f64 {...@@ -113,42 +113,42 @@ fn tanh64(x: f64) f64 {
113}113}
114114
115test "math.tanh" {115test "math.tanh" {
116 assert(tanh(f32(1.5)) == tanh32(1.5));116 expect(tanh(f32(1.5)) == tanh32(1.5));
117 assert(tanh(f64(1.5)) == tanh64(1.5));117 expect(tanh(f64(1.5)) == tanh64(1.5));
118}118}
119119
120test "math.tanh32" {120test "math.tanh32" {
121 const epsilon = 0.000001;121 const epsilon = 0.000001;
122122
123 assert(math.approxEq(f32, tanh32(0.0), 0.0, epsilon));123 expect(math.approxEq(f32, tanh32(0.0), 0.0, epsilon));
124 assert(math.approxEq(f32, tanh32(0.2), 0.197375, epsilon));124 expect(math.approxEq(f32, tanh32(0.2), 0.197375, epsilon));
125 assert(math.approxEq(f32, tanh32(0.8923), 0.712528, epsilon));125 expect(math.approxEq(f32, tanh32(0.8923), 0.712528, epsilon));
126 assert(math.approxEq(f32, tanh32(1.5), 0.905148, epsilon));126 expect(math.approxEq(f32, tanh32(1.5), 0.905148, epsilon));
127 assert(math.approxEq(f32, tanh32(37.45), 1.0, epsilon));127 expect(math.approxEq(f32, tanh32(37.45), 1.0, epsilon));
128}128}
129129
130test "math.tanh64" {130test "math.tanh64" {
131 const epsilon = 0.000001;131 const epsilon = 0.000001;
132132
133 assert(math.approxEq(f64, tanh64(0.0), 0.0, epsilon));133 expect(math.approxEq(f64, tanh64(0.0), 0.0, epsilon));
134 assert(math.approxEq(f64, tanh64(0.2), 0.197375, epsilon));134 expect(math.approxEq(f64, tanh64(0.2), 0.197375, epsilon));
135 assert(math.approxEq(f64, tanh64(0.8923), 0.712528, epsilon));135 expect(math.approxEq(f64, tanh64(0.8923), 0.712528, epsilon));
136 assert(math.approxEq(f64, tanh64(1.5), 0.905148, epsilon));136 expect(math.approxEq(f64, tanh64(1.5), 0.905148, epsilon));
137 assert(math.approxEq(f64, tanh64(37.45), 1.0, epsilon));137 expect(math.approxEq(f64, tanh64(37.45), 1.0, epsilon));
138}138}
139139
140test "math.tanh32.special" {140test "math.tanh32.special" {
141 assert(tanh32(0.0) == 0.0);141 expect(tanh32(0.0) == 0.0);
142 assert(tanh32(-0.0) == -0.0);142 expect(tanh32(-0.0) == -0.0);
143 assert(tanh32(math.inf(f32)) == 1.0);143 expect(tanh32(math.inf(f32)) == 1.0);
144 assert(tanh32(-math.inf(f32)) == -1.0);144 expect(tanh32(-math.inf(f32)) == -1.0);
145 assert(math.isNan(tanh32(math.nan(f32))));145 expect(math.isNan(tanh32(math.nan(f32))));
146}146}
147147
148test "math.tanh64.special" {148test "math.tanh64.special" {
149 assert(tanh64(0.0) == 0.0);149 expect(tanh64(0.0) == 0.0);
150 assert(tanh64(-0.0) == -0.0);150 expect(tanh64(-0.0) == -0.0);
151 assert(tanh64(math.inf(f64)) == 1.0);151 expect(tanh64(math.inf(f64)) == 1.0);
152 assert(tanh64(-math.inf(f64)) == -1.0);152 expect(tanh64(-math.inf(f64)) == -1.0);
153 assert(math.isNan(tanh64(math.nan(f64))));153 expect(math.isNan(tanh64(math.nan(f64))));
154}154}
std/math/trunc.zig+19-19
...@@ -6,7 +6,7 @@...@@ -6,7 +6,7 @@
66
7const std = @import("../index.zig");7const std = @import("../index.zig");
8const math = std.math;8const math = std.math;
9const assert = std.debug.assert;9const expect = std.testing.expect;
10const maxInt = std.math.maxInt;10const maxInt = std.math.maxInt;
1111
12pub fn trunc(x: var) @typeOf(x) {12pub fn trunc(x: var) @typeOf(x) {
...@@ -61,34 +61,34 @@ fn trunc64(x: f64) f64 {...@@ -61,34 +61,34 @@ fn trunc64(x: f64) f64 {
61}61}
6262
63test "math.trunc" {63test "math.trunc" {
64 assert(trunc(f32(1.3)) == trunc32(1.3));64 expect(trunc(f32(1.3)) == trunc32(1.3));
65 assert(trunc(f64(1.3)) == trunc64(1.3));65 expect(trunc(f64(1.3)) == trunc64(1.3));
66}66}
6767
68test "math.trunc32" {68test "math.trunc32" {
69 assert(trunc32(1.3) == 1.0);69 expect(trunc32(1.3) == 1.0);
70 assert(trunc32(-1.3) == -1.0);70 expect(trunc32(-1.3) == -1.0);
71 assert(trunc32(0.2) == 0.0);71 expect(trunc32(0.2) == 0.0);
72}72}
7373
74test "math.trunc64" {74test "math.trunc64" {
75 assert(trunc64(1.3) == 1.0);75 expect(trunc64(1.3) == 1.0);
76 assert(trunc64(-1.3) == -1.0);76 expect(trunc64(-1.3) == -1.0);
77 assert(trunc64(0.2) == 0.0);77 expect(trunc64(0.2) == 0.0);
78}78}
7979
80test "math.trunc32.special" {80test "math.trunc32.special" {
81 assert(trunc32(0.0) == 0.0); // 0x3F80000081 expect(trunc32(0.0) == 0.0); // 0x3F800000
82 assert(trunc32(-0.0) == -0.0);82 expect(trunc32(-0.0) == -0.0);
83 assert(math.isPositiveInf(trunc32(math.inf(f32))));83 expect(math.isPositiveInf(trunc32(math.inf(f32))));
84 assert(math.isNegativeInf(trunc32(-math.inf(f32))));84 expect(math.isNegativeInf(trunc32(-math.inf(f32))));
85 assert(math.isNan(trunc32(math.nan(f32))));85 expect(math.isNan(trunc32(math.nan(f32))));
86}86}
8787
88test "math.trunc64.special" {88test "math.trunc64.special" {
89 assert(trunc64(0.0) == 0.0);89 expect(trunc64(0.0) == 0.0);
90 assert(trunc64(-0.0) == -0.0);90 expect(trunc64(-0.0) == -0.0);
91 assert(math.isPositiveInf(trunc64(math.inf(f64))));91 expect(math.isPositiveInf(trunc64(math.inf(f64))));
92 assert(math.isNegativeInf(trunc64(-math.inf(f64))));92 expect(math.isNegativeInf(trunc64(-math.inf(f64))));
93 assert(math.isNan(trunc64(math.nan(f64))));93 expect(math.isNan(trunc64(math.nan(f64))));
94}94}
std/mem.zig+160-159
...@@ -6,6 +6,7 @@ const builtin = @import("builtin");...@@ -6,6 +6,7 @@ const builtin = @import("builtin");
6const mem = @This();6const mem = @This();
7const meta = std.meta;7const meta = std.meta;
8const trait = meta.trait;8const trait = meta.trait;
9const testing = std.testing;
910
10pub const Allocator = struct {11pub const Allocator = struct {
11 pub const Error = error{OutOfMemory};12 pub const Error = error{OutOfMemory};
...@@ -181,7 +182,7 @@ test "mem.secureZero" {...@@ -181,7 +182,7 @@ test "mem.secureZero" {
181 set(u8, a[0..], 0);182 set(u8, a[0..], 0);
182 secureZero(u8, b[0..]);183 secureZero(u8, b[0..]);
183184
184 assert(eql(u8, a[0..], b[0..]));185 testing.expectEqualSlices(u8, a[0..], b[0..]);
185}186}
186187
187pub fn compare(comptime T: type, lhs: []const T, rhs: []const T) Compare {188pub 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 {...@@ -210,11 +211,11 @@ pub fn compare(comptime T: type, lhs: []const T, rhs: []const T) Compare {
210}211}
211212
212test "mem.compare" {213test "mem.compare" {
213 assert(compare(u8, "abcd", "bee") == Compare.LessThan);214 testing.expect(compare(u8, "abcd", "bee") == Compare.LessThan);
214 assert(compare(u8, "abc", "abc") == Compare.Equal);215 testing.expect(compare(u8, "abc", "abc") == Compare.Equal);
215 assert(compare(u8, "abc", "abc0") == Compare.LessThan);216 testing.expect(compare(u8, "abc", "abc0") == Compare.LessThan);
216 assert(compare(u8, "", "") == Compare.Equal);217 testing.expect(compare(u8, "", "") == Compare.Equal);
217 assert(compare(u8, "", "a") == Compare.LessThan);218 testing.expect(compare(u8, "", "a") == Compare.LessThan);
218}219}
219220
220/// Returns true if lhs < rhs, false otherwise221/// Returns true if lhs < rhs, false otherwise
...@@ -227,11 +228,11 @@ pub fn lessThan(comptime T: type, lhs: []const T, rhs: []const T) bool {...@@ -227,11 +228,11 @@ pub fn lessThan(comptime T: type, lhs: []const T, rhs: []const T) bool {
227}228}
228229
229test "mem.lessThan" {230test "mem.lessThan" {
230 assert(lessThan(u8, "abcd", "bee"));231 testing.expect(lessThan(u8, "abcd", "bee"));
231 assert(!lessThan(u8, "abc", "abc"));232 testing.expect(!lessThan(u8, "abc", "abc"));
232 assert(lessThan(u8, "abc", "abc0"));233 testing.expect(lessThan(u8, "abc", "abc0"));
233 assert(!lessThan(u8, "", ""));234 testing.expect(!lessThan(u8, "", ""));
234 assert(lessThan(u8, "", "a"));235 testing.expect(lessThan(u8, "", "a"));
235}236}
236237
237/// Compares two slices and returns whether they are equal.238/// 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...@@ -296,10 +297,10 @@ pub fn trim(comptime T: type, slice: []const T, values_to_strip: []const T) []co
296}297}
297298
298test "mem.trim" {299test "mem.trim" {
299 assert(eql(u8, trimLeft(u8, " foo\n ", " \n"), "foo\n "));300 testing.expectEqualSlices(u8, "foo\n ", trimLeft(u8, " foo\n ", " \n"));
300 assert(eql(u8, trimRight(u8, " foo\n ", " \n"), " foo"));301 testing.expectEqualSlices(u8, " foo", trimRight(u8, " foo\n ", " \n"));
301 assert(eql(u8, trim(u8, " foo\n ", " \n"), "foo"));302 testing.expectEqualSlices(u8, "foo", trim(u8, " foo\n ", " \n"));
302 assert(eql(u8, trim(u8, "foo", " \n"), "foo"));303 testing.expectEqualSlices(u8, "foo", trim(u8, "foo", " \n"));
303}304}
304305
305/// Linear search for the index of a scalar value inside a slice.306/// 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...@@ -380,20 +381,20 @@ pub fn indexOfPos(comptime T: type, haystack: []const T, start_index: usize, nee
380}381}
381382
382test "mem.indexOf" {383test "mem.indexOf" {
383 assert(indexOf(u8, "one two three four", "four").? == 14);384 testing.expect(indexOf(u8, "one two three four", "four").? == 14);
384 assert(lastIndexOf(u8, "one two three two four", "two").? == 14);385 testing.expect(lastIndexOf(u8, "one two three two four", "two").? == 14);
385 assert(indexOf(u8, "one two three four", "gour") == null);386 testing.expect(indexOf(u8, "one two three four", "gour") == null);
386 assert(lastIndexOf(u8, "one two three four", "gour") == null);387 testing.expect(lastIndexOf(u8, "one two three four", "gour") == null);
387 assert(indexOf(u8, "foo", "foo").? == 0);388 testing.expect(indexOf(u8, "foo", "foo").? == 0);
388 assert(lastIndexOf(u8, "foo", "foo").? == 0);389 testing.expect(lastIndexOf(u8, "foo", "foo").? == 0);
389 assert(indexOf(u8, "foo", "fool") == null);390 testing.expect(indexOf(u8, "foo", "fool") == null);
390 assert(lastIndexOf(u8, "foo", "lfoo") == null);391 testing.expect(lastIndexOf(u8, "foo", "lfoo") == null);
391 assert(lastIndexOf(u8, "foo", "fool") == null);392 testing.expect(lastIndexOf(u8, "foo", "fool") == null);
392393
393 assert(indexOf(u8, "foo foo", "foo").? == 0);394 testing.expect(indexOf(u8, "foo foo", "foo").? == 0);
394 assert(lastIndexOf(u8, "foo foo", "foo").? == 4);395 testing.expect(lastIndexOf(u8, "foo foo", "foo").? == 4);
395 assert(lastIndexOfAny(u8, "boo, cat", "abo").? == 6);396 testing.expect(lastIndexOfAny(u8, "boo, cat", "abo").? == 6);
396 assert(lastIndexOfScalar(u8, "boo", 'o').? == 2);397 testing.expect(lastIndexOfScalar(u8, "boo", 'o').? == 2);
397}398}
398399
399/// Reads an integer from memory with size equal to bytes.len.400/// Reads an integer from memory with size equal to bytes.len.
...@@ -504,34 +505,34 @@ test "comptime read/write int" {...@@ -504,34 +505,34 @@ test "comptime read/write int" {
504 var bytes: [2]u8 = undefined;505 var bytes: [2]u8 = undefined;
505 std.mem.writeIntLittle(u16, &bytes, 0x1234);506 std.mem.writeIntLittle(u16, &bytes, 0x1234);
506 const result = std.mem.readIntBig(u16, &bytes);507 const result = std.mem.readIntBig(u16, &bytes);
507 std.debug.assert(result == 0x3412);508 testing.expect(result == 0x3412);
508 }509 }
509 comptime {510 comptime {
510 var bytes: [2]u8 = undefined;511 var bytes: [2]u8 = undefined;
511 std.mem.writeIntBig(u16, &bytes, 0x1234);512 std.mem.writeIntBig(u16, &bytes, 0x1234);
512 const result = std.mem.readIntLittle(u16, &bytes);513 const result = std.mem.readIntLittle(u16, &bytes);
513 std.debug.assert(result == 0x3412);514 testing.expect(result == 0x3412);
514 }515 }
515}516}
516517
517test "readIntBig and readIntLittle" {518test "readIntBig and readIntLittle" {
518 assert(readIntSliceBig(u0, []u8{}) == 0x0);519 testing.expect(readIntSliceBig(u0, []u8{}) == 0x0);
519 assert(readIntSliceLittle(u0, []u8{}) == 0x0);520 testing.expect(readIntSliceLittle(u0, []u8{}) == 0x0);
520521
521 assert(readIntSliceBig(u8, []u8{0x32}) == 0x32);522 testing.expect(readIntSliceBig(u8, []u8{0x32}) == 0x32);
522 assert(readIntSliceLittle(u8, []u8{0x12}) == 0x12);523 testing.expect(readIntSliceLittle(u8, []u8{0x12}) == 0x12);
523524
524 assert(readIntSliceBig(u16, []u8{ 0x12, 0x34 }) == 0x1234);525 testing.expect(readIntSliceBig(u16, []u8{ 0x12, 0x34 }) == 0x1234);
525 assert(readIntSliceLittle(u16, []u8{ 0x12, 0x34 }) == 0x3412);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 testing.expect(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);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 testing.expect(readIntSliceBig(i8, []u8{0xff}) == -1);
531 assert(readIntSliceLittle(i8, []u8{0xfe}) == -2);532 testing.expect(readIntSliceLittle(i8, []u8{0xfe}) == -2);
532533
533 assert(readIntSliceBig(i16, []u8{ 0xff, 0xfd }) == -3);534 testing.expect(readIntSliceBig(i16, []u8{ 0xff, 0xfd }) == -3);
534 assert(readIntSliceLittle(i16, []u8{ 0xfc, 0xff }) == -4);535 testing.expect(readIntSliceLittle(i16, []u8{ 0xfc, 0xff }) == -4);
535}536}
536537
537/// Writes an integer to memory, storing it in twos-complement.538/// Writes an integer to memory, storing it in twos-complement.
...@@ -645,34 +646,34 @@ test "writeIntBig and writeIntLittle" {...@@ -645,34 +646,34 @@ test "writeIntBig and writeIntLittle" {
645 var buf9: [9]u8 = undefined;646 var buf9: [9]u8 = undefined;
646647
647 writeIntBig(u0, &buf0, 0x0);648 writeIntBig(u0, &buf0, 0x0);
648 assert(eql_slice_u8(buf0[0..], []u8{}));649 testing.expect(eql_slice_u8(buf0[0..], []u8{}));
649 writeIntLittle(u0, &buf0, 0x0);650 writeIntLittle(u0, &buf0, 0x0);
650 assert(eql_slice_u8(buf0[0..], []u8{}));651 testing.expect(eql_slice_u8(buf0[0..], []u8{}));
651652
652 writeIntBig(u8, &buf1, 0x12);653 writeIntBig(u8, &buf1, 0x12);
653 assert(eql_slice_u8(buf1[0..], []u8{0x12}));654 testing.expect(eql_slice_u8(buf1[0..], []u8{0x12}));
654 writeIntLittle(u8, &buf1, 0x34);655 writeIntLittle(u8, &buf1, 0x34);
655 assert(eql_slice_u8(buf1[0..], []u8{0x34}));656 testing.expect(eql_slice_u8(buf1[0..], []u8{0x34}));
656657
657 writeIntBig(u16, &buf2, 0x1234);658 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 }));
659 writeIntLittle(u16, &buf2, 0x5678);660 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
662 writeIntBig(u72, &buf9, 0x123456789abcdef024);663 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 }));
664 writeIntLittle(u72, &buf9, 0xfedcba9876543210ec);665 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
667 writeIntBig(i8, &buf1, -1);668 writeIntBig(i8, &buf1, -1);
668 assert(eql_slice_u8(buf1[0..], []u8{0xff}));669 testing.expect(eql_slice_u8(buf1[0..], []u8{0xff}));
669 writeIntLittle(i8, &buf1, -2);670 writeIntLittle(i8, &buf1, -2);
670 assert(eql_slice_u8(buf1[0..], []u8{0xfe}));671 testing.expect(eql_slice_u8(buf1[0..], []u8{0xfe}));
671672
672 writeIntBig(i16, &buf2, -3);673 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 }));
674 writeIntLittle(i16, &buf2, -4);675 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 }));
676}677}
677678
678pub fn hash_slice_u8(k: []const u8) u32 {679pub fn hash_slice_u8(k: []const u8) u32 {
...@@ -706,46 +707,46 @@ pub fn tokenize(buffer: []const u8, delimiter_bytes: []const u8) TokenIterator {...@@ -706,46 +707,46 @@ pub fn tokenize(buffer: []const u8, delimiter_bytes: []const u8) TokenIterator {
706707
707test "mem.tokenize" {708test "mem.tokenize" {
708 var it = tokenize(" abc def ghi ", " ");709 var it = tokenize(" abc def ghi ", " ");
709 assert(eql(u8, it.next().?, "abc"));710 testing.expect(eql(u8, it.next().?, "abc"));
710 assert(eql(u8, it.next().?, "def"));711 testing.expect(eql(u8, it.next().?, "def"));
711 assert(eql(u8, it.next().?, "ghi"));712 testing.expect(eql(u8, it.next().?, "ghi"));
712 assert(it.next() == null);713 testing.expect(it.next() == null);
713714
714 it = tokenize("..\\bob", "\\");715 it = tokenize("..\\bob", "\\");
715 assert(eql(u8, it.next().?, ".."));716 testing.expect(eql(u8, it.next().?, ".."));
716 assert(eql(u8, "..", "..\\bob"[0..it.index]));717 testing.expect(eql(u8, "..", "..\\bob"[0..it.index]));
717 assert(eql(u8, it.next().?, "bob"));718 testing.expect(eql(u8, it.next().?, "bob"));
718 assert(it.next() == null);719 testing.expect(it.next() == null);
719720
720 it = tokenize("//a/b", "/");721 it = tokenize("//a/b", "/");
721 assert(eql(u8, it.next().?, "a"));722 testing.expect(eql(u8, it.next().?, "a"));
722 assert(eql(u8, it.next().?, "b"));723 testing.expect(eql(u8, it.next().?, "b"));
723 assert(eql(u8, "//a/b", "//a/b"[0..it.index]));724 testing.expect(eql(u8, "//a/b", "//a/b"[0..it.index]));
724 assert(it.next() == null);725 testing.expect(it.next() == null);
725726
726 it = tokenize("|", "|");727 it = tokenize("|", "|");
727 assert(it.next() == null);728 testing.expect(it.next() == null);
728729
729 it = tokenize("", "|");730 it = tokenize("", "|");
730 assert(it.next() == null);731 testing.expect(it.next() == null);
731732
732 it = tokenize("hello", "");733 it = tokenize("hello", "");
733 assert(eql(u8, it.next().?, "hello"));734 testing.expect(eql(u8, it.next().?, "hello"));
734 assert(it.next() == null);735 testing.expect(it.next() == null);
735736
736 it = tokenize("hello", " ");737 it = tokenize("hello", " ");
737 assert(eql(u8, it.next().?, "hello"));738 testing.expect(eql(u8, it.next().?, "hello"));
738 assert(it.next() == null);739 testing.expect(it.next() == null);
739}740}
740741
741test "mem.tokenize (multibyte)" {742test "mem.tokenize (multibyte)" {
742 var it = tokenize("a|b,c/d e", " /,|");743 var it = tokenize("a|b,c/d e", " /,|");
743 assert(eql(u8, it.next().?, "a"));744 testing.expect(eql(u8, it.next().?, "a"));
744 assert(eql(u8, it.next().?, "b"));745 testing.expect(eql(u8, it.next().?, "b"));
745 assert(eql(u8, it.next().?, "c"));746 testing.expect(eql(u8, it.next().?, "c"));
746 assert(eql(u8, it.next().?, "d"));747 testing.expect(eql(u8, it.next().?, "d"));
747 assert(eql(u8, it.next().?, "e"));748 testing.expect(eql(u8, it.next().?, "e"));
748 assert(it.next() == null);749 testing.expect(it.next() == null);
749}750}
750751
751/// Returns an iterator that iterates over the slices of `buffer` that752/// 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 {...@@ -769,34 +770,34 @@ pub fn separate(buffer: []const u8, delimiter: []const u8) SplitIterator {
769770
770test "mem.separate" {771test "mem.separate" {
771 var it = separate("abc|def||ghi", "|");772 var it = separate("abc|def||ghi", "|");
772 assert(eql(u8, it.next().?, "abc"));773 testing.expect(eql(u8, it.next().?, "abc"));
773 assert(eql(u8, it.next().?, "def"));774 testing.expect(eql(u8, it.next().?, "def"));
774 assert(eql(u8, it.next().?, ""));775 testing.expect(eql(u8, it.next().?, ""));
775 assert(eql(u8, it.next().?, "ghi"));776 testing.expect(eql(u8, it.next().?, "ghi"));
776 assert(it.next() == null);777 testing.expect(it.next() == null);
777778
778 it = separate("", "|");779 it = separate("", "|");
779 assert(eql(u8, it.next().?, ""));780 testing.expect(eql(u8, it.next().?, ""));
780 assert(it.next() == null);781 testing.expect(it.next() == null);
781782
782 it = separate("|", "|");783 it = separate("|", "|");
783 assert(eql(u8, it.next().?, ""));784 testing.expect(eql(u8, it.next().?, ""));
784 assert(eql(u8, it.next().?, ""));785 testing.expect(eql(u8, it.next().?, ""));
785 assert(it.next() == null);786 testing.expect(it.next() == null);
786787
787 it = separate("hello", " ");788 it = separate("hello", " ");
788 assert(eql(u8, it.next().?, "hello"));789 testing.expect(eql(u8, it.next().?, "hello"));
789 assert(it.next() == null);790 testing.expect(it.next() == null);
790}791}
791792
792test "mem.separate (multibyte)" {793test "mem.separate (multibyte)" {
793 var it = separate("a, b ,, c, d, e", ", ");794 var it = separate("a, b ,, c, d, e", ", ");
794 assert(eql(u8, it.next().?, "a"));795 testing.expect(eql(u8, it.next().?, "a"));
795 assert(eql(u8, it.next().?, "b ,"));796 testing.expect(eql(u8, it.next().?, "b ,"));
796 assert(eql(u8, it.next().?, "c"));797 testing.expect(eql(u8, it.next().?, "c"));
797 assert(eql(u8, it.next().?, "d"));798 testing.expect(eql(u8, it.next().?, "d"));
798 assert(eql(u8, it.next().?, "e"));799 testing.expect(eql(u8, it.next().?, "e"));
799 assert(it.next() == null);800 testing.expect(it.next() == null);
800}801}
801802
802pub fn startsWith(comptime T: type, haystack: []const T, needle: []const T) bool {803pub 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...@@ -804,8 +805,8 @@ pub fn startsWith(comptime T: type, haystack: []const T, needle: []const T) bool
804}805}
805806
806test "mem.startsWith" {807test "mem.startsWith" {
807 assert(startsWith(u8, "Bob", "Bo"));808 testing.expect(startsWith(u8, "Bob", "Bo"));
808 assert(!startsWith(u8, "Needle in haystack", "haystack"));809 testing.expect(!startsWith(u8, "Needle in haystack", "haystack"));
809}810}
810811
811pub fn endsWith(comptime T: type, haystack: []const T, needle: []const T) bool {812pub 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 {...@@ -813,8 +814,8 @@ pub fn endsWith(comptime T: type, haystack: []const T, needle: []const T) bool {
813}814}
814815
815test "mem.endsWith" {816test "mem.endsWith" {
816 assert(endsWith(u8, "Needle in haystack", "haystack"));817 testing.expect(endsWith(u8, "Needle in haystack", "haystack"));
817 assert(!endsWith(u8, "Bob", "Bo"));818 testing.expect(!endsWith(u8, "Bob", "Bo"));
818}819}
819820
820pub const TokenIterator = struct {821pub const TokenIterator = struct {
...@@ -913,15 +914,15 @@ pub fn join(allocator: *Allocator, separator: []const u8, slices: []const []cons...@@ -913,15 +914,15 @@ pub fn join(allocator: *Allocator, separator: []const u8, slices: []const []cons
913test "mem.join" {914test "mem.join" {
914 var buf: [1024]u8 = undefined;915 var buf: [1024]u8 = undefined;
915 const a = &std.heap.FixedBufferAllocator.init(&buf).allocator;916 const a = &std.heap.FixedBufferAllocator.init(&buf).allocator;
916 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"));
917 assert(eql(u8, try join(a, ",", [][]const u8{"a"}), "a"));918 testing.expect(eql(u8, try join(a, ",", [][]const u8{"a"}), "a"));
918 assert(eql(u8, try join(a, ",", [][]const u8{ "a", "", "b", "", "c" }), "a,,b,,c"));919 testing.expect(eql(u8, try join(a, ",", [][]const u8{ "a", "", "b", "", "c" }), "a,,b,,c"));
919}920}
920921
921test "testStringEquality" {922test "testStringEquality" {
922 assert(eql(u8, "abcd", "abcd"));923 testing.expect(eql(u8, "abcd", "abcd"));
923 assert(!eql(u8, "abcdef", "abZdef"));924 testing.expect(!eql(u8, "abcdef", "abZdef"));
924 assert(!eql(u8, "abcdefg", "abcdef"));925 testing.expect(!eql(u8, "abcdefg", "abcdef"));
925}926}
926927
927test "testReadInt" {928test "testReadInt" {
...@@ -936,12 +937,12 @@ fn testReadIntImpl() void {...@@ -936,12 +937,12 @@ fn testReadIntImpl() void {
936 0x56,937 0x56,
937 0x78,938 0x78,
938 };939 };
939 assert(readInt(u32, &bytes, builtin.Endian.Big) == 0x12345678);940 testing.expect(readInt(u32, &bytes, builtin.Endian.Big) == 0x12345678);
940 assert(readIntBig(u32, &bytes) == 0x12345678);941 testing.expect(readIntBig(u32, &bytes) == 0x12345678);
941 assert(readIntBig(i32, &bytes) == 0x12345678);942 testing.expect(readIntBig(i32, &bytes) == 0x12345678);
942 assert(readInt(u32, &bytes, builtin.Endian.Little) == 0x78563412);943 testing.expect(readInt(u32, &bytes, builtin.Endian.Little) == 0x78563412);
943 assert(readIntLittle(u32, &bytes) == 0x78563412);944 testing.expect(readIntLittle(u32, &bytes) == 0x78563412);
944 assert(readIntLittle(i32, &bytes) == 0x78563412);945 testing.expect(readIntLittle(i32, &bytes) == 0x78563412);
945 }946 }
946 {947 {
947 const buf = []u8{948 const buf = []u8{
...@@ -951,7 +952,7 @@ fn testReadIntImpl() void {...@@ -951,7 +952,7 @@ fn testReadIntImpl() void {
951 0x34,952 0x34,
952 };953 };
953 const answer = readInt(u32, &buf, builtin.Endian.Big);954 const answer = readInt(u32, &buf, builtin.Endian.Big);
954 assert(answer == 0x00001234);955 testing.expect(answer == 0x00001234);
955 }956 }
956 {957 {
957 const buf = []u8{958 const buf = []u8{
...@@ -961,17 +962,17 @@ fn testReadIntImpl() void {...@@ -961,17 +962,17 @@ fn testReadIntImpl() void {
961 0x00,962 0x00,
962 };963 };
963 const answer = readInt(u32, &buf, builtin.Endian.Little);964 const answer = readInt(u32, &buf, builtin.Endian.Little);
964 assert(answer == 0x00003412);965 testing.expect(answer == 0x00003412);
965 }966 }
966 {967 {
967 const bytes = []u8{968 const bytes = []u8{
968 0xff,969 0xff,
969 0xfe,970 0xfe,
970 };971 };
971 assert(readIntBig(u16, &bytes) == 0xfffe);972 testing.expect(readIntBig(u16, &bytes) == 0xfffe);
972 assert(readIntBig(i16, &bytes) == -0x0002);973 testing.expect(readIntBig(i16, &bytes) == -0x0002);
973 assert(readIntLittle(u16, &bytes) == 0xfeff);974 testing.expect(readIntLittle(u16, &bytes) == 0xfeff);
974 assert(readIntLittle(i16, &bytes) == -0x0101);975 testing.expect(readIntLittle(i16, &bytes) == -0x0101);
975 }976 }
976}977}
977978
...@@ -983,19 +984,19 @@ fn testWriteIntImpl() void {...@@ -983,19 +984,19 @@ fn testWriteIntImpl() void {
983 var bytes: [8]u8 = undefined;984 var bytes: [8]u8 = undefined;
984985
985 writeIntSlice(u0, bytes[0..], 0, builtin.Endian.Big);986 writeIntSlice(u0, bytes[0..], 0, builtin.Endian.Big);
986 assert(eql(u8, bytes, []u8{987 testing.expect(eql(u8, bytes, []u8{
987 0x00, 0x00, 0x00, 0x00,988 0x00, 0x00, 0x00, 0x00,
988 0x00, 0x00, 0x00, 0x00,989 0x00, 0x00, 0x00, 0x00,
989 }));990 }));
990991
991 writeIntSlice(u0, bytes[0..], 0, builtin.Endian.Little);992 writeIntSlice(u0, bytes[0..], 0, builtin.Endian.Little);
992 assert(eql(u8, bytes, []u8{993 testing.expect(eql(u8, bytes, []u8{
993 0x00, 0x00, 0x00, 0x00,994 0x00, 0x00, 0x00, 0x00,
994 0x00, 0x00, 0x00, 0x00,995 0x00, 0x00, 0x00, 0x00,
995 }));996 }));
996997
997 writeIntSlice(u64, bytes[0..], 0x12345678CAFEBABE, builtin.Endian.Big);998 writeIntSlice(u64, bytes[0..], 0x12345678CAFEBABE, builtin.Endian.Big);
998 assert(eql(u8, bytes, []u8{999 testing.expect(eql(u8, bytes, []u8{
999 0x12,1000 0x12,
1000 0x34,1001 0x34,
1001 0x56,1002 0x56,
...@@ -1007,7 +1008,7 @@ fn testWriteIntImpl() void {...@@ -1007,7 +1008,7 @@ fn testWriteIntImpl() void {
1007 }));1008 }));
10081009
1009 writeIntSlice(u64, bytes[0..], 0xBEBAFECA78563412, builtin.Endian.Little);1010 writeIntSlice(u64, bytes[0..], 0xBEBAFECA78563412, builtin.Endian.Little);
1010 assert(eql(u8, bytes, []u8{1011 testing.expect(eql(u8, bytes, []u8{
1011 0x12,1012 0x12,
1012 0x34,1013 0x34,
1013 0x56,1014 0x56,
...@@ -1019,7 +1020,7 @@ fn testWriteIntImpl() void {...@@ -1019,7 +1020,7 @@ fn testWriteIntImpl() void {
1019 }));1020 }));
10201021
1021 writeIntSlice(u32, bytes[0..], 0x12345678, builtin.Endian.Big);1022 writeIntSlice(u32, bytes[0..], 0x12345678, builtin.Endian.Big);
1022 assert(eql(u8, bytes, []u8{1023 testing.expect(eql(u8, bytes, []u8{
1023 0x00,1024 0x00,
1024 0x00,1025 0x00,
1025 0x00,1026 0x00,
...@@ -1031,7 +1032,7 @@ fn testWriteIntImpl() void {...@@ -1031,7 +1032,7 @@ fn testWriteIntImpl() void {
1031 }));1032 }));
10321033
1033 writeIntSlice(u32, bytes[0..], 0x78563412, builtin.Endian.Little);1034 writeIntSlice(u32, bytes[0..], 0x78563412, builtin.Endian.Little);
1034 assert(eql(u8, bytes, []u8{1035 testing.expect(eql(u8, bytes, []u8{
1035 0x12,1036 0x12,
1036 0x34,1037 0x34,
1037 0x56,1038 0x56,
...@@ -1043,7 +1044,7 @@ fn testWriteIntImpl() void {...@@ -1043,7 +1044,7 @@ fn testWriteIntImpl() void {
1043 }));1044 }));
10441045
1045 writeIntSlice(u16, bytes[0..], 0x1234, builtin.Endian.Big);1046 writeIntSlice(u16, bytes[0..], 0x1234, builtin.Endian.Big);
1046 assert(eql(u8, bytes, []u8{1047 testing.expect(eql(u8, bytes, []u8{
1047 0x00,1048 0x00,
1048 0x00,1049 0x00,
1049 0x00,1050 0x00,
...@@ -1055,7 +1056,7 @@ fn testWriteIntImpl() void {...@@ -1055,7 +1056,7 @@ fn testWriteIntImpl() void {
1055 }));1056 }));
10561057
1057 writeIntSlice(u16, bytes[0..], 0x1234, builtin.Endian.Little);1058 writeIntSlice(u16, bytes[0..], 0x1234, builtin.Endian.Little);
1058 assert(eql(u8, bytes, []u8{1059 testing.expect(eql(u8, bytes, []u8{
1059 0x34,1060 0x34,
1060 0x12,1061 0x12,
1061 0x00,1062 0x00,
...@@ -1076,7 +1077,7 @@ pub fn min(comptime T: type, slice: []const T) T {...@@ -1076,7 +1077,7 @@ pub fn min(comptime T: type, slice: []const T) T {
1076}1077}
10771078
1078test "mem.min" {1079test "mem.min" {
1079 assert(min(u8, "abcdefg") == 'a');1080 testing.expect(min(u8, "abcdefg") == 'a');
1080}1081}
10811082
1082pub fn max(comptime T: type, slice: []const T) T {1083pub fn max(comptime T: type, slice: []const T) T {
...@@ -1088,7 +1089,7 @@ pub fn max(comptime T: type, slice: []const T) T {...@@ -1088,7 +1089,7 @@ pub fn max(comptime T: type, slice: []const T) T {
1088}1089}
10891090
1090test "mem.max" {1091test "mem.max" {
1091 assert(max(u8, "abcdefg") == 'g');1092 testing.expect(max(u8, "abcdefg") == 'g');
1092}1093}
10931094
1094pub fn swap(comptime T: type, a: *T, b: *T) void {1095pub fn swap(comptime T: type, a: *T, b: *T) void {
...@@ -1116,7 +1117,7 @@ test "std.mem.reverse" {...@@ -1116,7 +1117,7 @@ test "std.mem.reverse" {
1116 };1117 };
1117 reverse(i32, arr[0..]);1118 reverse(i32, arr[0..]);
11181119
1119 assert(eql(i32, arr, []i32{1120 testing.expect(eql(i32, arr, []i32{
1120 4,1121 4,
1121 2,1122 2,
1122 1,1123 1,
...@@ -1143,7 +1144,7 @@ test "std.mem.rotate" {...@@ -1143,7 +1144,7 @@ test "std.mem.rotate" {
1143 };1144 };
1144 rotate(i32, arr[0..], 2);1145 rotate(i32, arr[0..], 2);
11451146
1146 assert(eql(i32, arr, []i32{1147 testing.expect(eql(i32, arr, []i32{
1147 1,1148 1,
1148 2,1149 2,
1149 4,1150 4,
...@@ -1225,12 +1226,12 @@ test "std.mem.asBytes" {...@@ -1225,12 +1226,12 @@ test "std.mem.asBytes" {
1225 builtin.Endian.Little => "\xEF\xBE\xAD\xDE",1226 builtin.Endian.Little => "\xEF\xBE\xAD\xDE",
1226 };1227 };
12271228
1228 debug.assert(std.mem.eql(u8, asBytes(&deadbeef), deadbeef_bytes));1229 testing.expect(std.mem.eql(u8, asBytes(&deadbeef), deadbeef_bytes));
12291230
1230 var codeface = u32(0xC0DEFACE);1231 var codeface = u32(0xC0DEFACE);
1231 for (asBytes(&codeface).*) |*b|1232 for (asBytes(&codeface).*) |*b|
1232 b.* = 0;1233 b.* = 0;
1233 debug.assert(codeface == 0);1234 testing.expect(codeface == 0);
12341235
1235 const S = packed struct {1236 const S = packed struct {
1236 a: u8,1237 a: u8,
...@@ -1245,7 +1246,7 @@ test "std.mem.asBytes" {...@@ -1245,7 +1246,7 @@ test "std.mem.asBytes" {
1245 .c = 0xDE,1246 .c = 0xDE,
1246 .d = 0xA1,1247 .d = 0xA1,
1247 };1248 };
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"));
1249}1250}
12501251
1251///Given any value, returns a copy of its bytes in an array.1252///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 {...@@ -1256,14 +1257,14 @@ pub fn toBytes(value: var) [@sizeOf(@typeOf(value))]u8 {
1256test "std.mem.toBytes" {1257test "std.mem.toBytes" {
1257 var my_bytes = toBytes(u32(0x12345678));1258 var my_bytes = toBytes(u32(0x12345678));
1258 switch (builtin.endian) {1259 switch (builtin.endian) {
1259 builtin.Endian.Big => debug.assert(std.mem.eql(u8, my_bytes, "\x12\x34\x56\x78")),1260 builtin.Endian.Big => testing.expect(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")),1261 builtin.Endian.Little => testing.expect(std.mem.eql(u8, my_bytes, "\x78\x56\x34\x12")),
1261 }1262 }
12621263
1263 my_bytes[0] = '\x99';1264 my_bytes[0] = '\x99';
1264 switch (builtin.endian) {1265 switch (builtin.endian) {
1265 builtin.Endian.Big => debug.assert(std.mem.eql(u8, my_bytes, "\x99\x34\x56\x78")),1266 builtin.Endian.Big => testing.expect(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")),1267 builtin.Endian.Little => testing.expect(std.mem.eql(u8, my_bytes, "\x99\x56\x34\x12")),
1267 }1268 }
1268}1269}
12691270
...@@ -1292,17 +1293,17 @@ test "std.mem.bytesAsValue" {...@@ -1292,17 +1293,17 @@ test "std.mem.bytesAsValue" {
1292 builtin.Endian.Little => "\xEF\xBE\xAD\xDE",1293 builtin.Endian.Little => "\xEF\xBE\xAD\xDE",
1293 };1294 };
12941295
1295 debug.assert(deadbeef == bytesAsValue(u32, &deadbeef_bytes).*);1296 testing.expect(deadbeef == bytesAsValue(u32, &deadbeef_bytes).*);
12961297
1297 var codeface_bytes = switch (builtin.endian) {1298 var codeface_bytes = switch (builtin.endian) {
1298 builtin.Endian.Big => "\xC0\xDE\xFA\xCE",1299 builtin.Endian.Big => "\xC0\xDE\xFA\xCE",
1299 builtin.Endian.Little => "\xCE\xFA\xDE\xC0",1300 builtin.Endian.Little => "\xCE\xFA\xDE\xC0",
1300 };1301 };
1301 var codeface = bytesAsValue(u32, &codeface_bytes);1302 var codeface = bytesAsValue(u32, &codeface_bytes);
1302 debug.assert(codeface.* == 0xC0DEFACE);1303 testing.expect(codeface.* == 0xC0DEFACE);
1303 codeface.* = 0;1304 codeface.* = 0;
1304 for (codeface_bytes) |b|1305 for (codeface_bytes) |b|
1305 debug.assert(b == 0);1306 testing.expect(b == 0);
13061307
1307 const S = packed struct {1308 const S = packed struct {
1308 a: u8,1309 a: u8,
...@@ -1319,7 +1320,7 @@ test "std.mem.bytesAsValue" {...@@ -1319,7 +1320,7 @@ test "std.mem.bytesAsValue" {
1319 };1320 };
1320 const inst_bytes = "\xBE\xEF\xDE\xA1";1321 const inst_bytes = "\xBE\xEF\xDE\xA1";
1321 const inst2 = bytesAsValue(S, &inst_bytes);1322 const inst2 = bytesAsValue(S, &inst_bytes);
1322 debug.assert(meta.eql(inst, inst2.*));1323 testing.expect(meta.eql(inst, inst2.*));
1323}1324}
13241325
1325///Given a pointer to an array of bytes, returns a value of the specified type backed by a1326///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" {...@@ -1334,7 +1335,7 @@ test "std.mem.bytesToValue" {
1334 };1335 };
13351336
1336 const deadbeef = bytesToValue(u32, deadbeef_bytes);1337 const deadbeef = bytesToValue(u32, deadbeef_bytes);
1337 debug.assert(deadbeef == u32(0xDEADBEEF));1338 testing.expect(deadbeef == u32(0xDEADBEEF));
1338}1339}
13391340
1340fn SubArrayPtrReturnType(comptime T: type, comptime length: usize) type {1341fn SubArrayPtrReturnType(comptime T: type, comptime length: usize) type {
...@@ -1345,7 +1346,7 @@ fn SubArrayPtrReturnType(comptime T: type, comptime length: usize) type {...@@ -1345,7 +1346,7 @@ fn SubArrayPtrReturnType(comptime T: type, comptime length: usize) type {
13451346
1346///Given a pointer to an array, returns a pointer to a portion of that array, preserving constness.1347///Given a pointer to an array, returns a pointer to a portion of that array, preserving constness.
1347pub fn subArrayPtr(ptr: var, comptime start: usize, comptime length: usize) SubArrayPtrReturnType(@typeOf(ptr), length) {1348pub 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
1350 const ReturnType = SubArrayPtrReturnType(@typeOf(ptr), length);1351 const ReturnType = SubArrayPtrReturnType(@typeOf(ptr), length);
1351 const T = meta.Child(meta.Child(@typeOf(ptr)));1352 const T = meta.Child(meta.Child(@typeOf(ptr)));
...@@ -1355,14 +1356,14 @@ pub fn subArrayPtr(ptr: var, comptime start: usize, comptime length: usize) SubA...@@ -1355,14 +1356,14 @@ pub fn subArrayPtr(ptr: var, comptime start: usize, comptime length: usize) SubA
1355test "std.mem.subArrayPtr" {1356test "std.mem.subArrayPtr" {
1356 const a1 = "abcdef";1357 const a1 = "abcdef";
1357 const sub1 = subArrayPtr(&a1, 2, 3);1358 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
1360 var a2 = "abcdef";1361 var a2 = "abcdef";
1361 var sub2 = subArrayPtr(&a2, 2, 3);1362 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"));
1364 sub2[1] = 'X';1365 sub2[1] = 'X';
1365 debug.assert(std.mem.eql(u8, a2, "abcXef"));1366 testing.expect(std.mem.eql(u8, a2, "abcXef"));
1366}1367}
13671368
1368/// Round an address up to the nearest aligned address1369/// Round an address up to the nearest aligned address
...@@ -1371,16 +1372,16 @@ pub fn alignForward(addr: usize, alignment: usize) usize {...@@ -1371,16 +1372,16 @@ pub fn alignForward(addr: usize, alignment: usize) usize {
1371}1372}
13721373
1373test "std.mem.alignForward" {1374test "std.mem.alignForward" {
1374 debug.assertOrPanic(alignForward(1, 1) == 1);1375 testing.expect(alignForward(1, 1) == 1);
1375 debug.assertOrPanic(alignForward(2, 1) == 2);1376 testing.expect(alignForward(2, 1) == 2);
1376 debug.assertOrPanic(alignForward(1, 2) == 2);1377 testing.expect(alignForward(1, 2) == 2);
1377 debug.assertOrPanic(alignForward(2, 2) == 2);1378 testing.expect(alignForward(2, 2) == 2);
1378 debug.assertOrPanic(alignForward(3, 2) == 4);1379 testing.expect(alignForward(3, 2) == 4);
1379 debug.assertOrPanic(alignForward(4, 2) == 4);1380 testing.expect(alignForward(4, 2) == 4);
1380 debug.assertOrPanic(alignForward(7, 8) == 8);1381 testing.expect(alignForward(7, 8) == 8);
1381 debug.assertOrPanic(alignForward(8, 8) == 8);1382 testing.expect(alignForward(8, 8) == 8);
1382 debug.assertOrPanic(alignForward(9, 8) == 16);1383 testing.expect(alignForward(9, 8) == 16);
1383 debug.assertOrPanic(alignForward(15, 8) == 16);1384 testing.expect(alignForward(15, 8) == 16);
1384 debug.assertOrPanic(alignForward(16, 8) == 16);1385 testing.expect(alignForward(16, 8) == 16);
1385 debug.assertOrPanic(alignForward(17, 8) == 24);1386 testing.expect(alignForward(17, 8) == 24);
1386}1387}
std/meta/index.zig+76-75
...@@ -3,6 +3,7 @@ const builtin = @import("builtin");...@@ -3,6 +3,7 @@ const builtin = @import("builtin");
3const debug = std.debug;3const debug = std.debug;
4const mem = std.mem;4const mem = std.mem;
5const math = std.math;5const math = std.math;
6const testing = std.testing;
67
7pub const trait = @import("trait.zig");8pub const trait = @import("trait.zig");
89
...@@ -64,16 +65,16 @@ test "std.meta.tagName" {...@@ -64,16 +65,16 @@ test "std.meta.tagName" {
64 var u2a = U2{ .C = 0 };65 var u2a = U2{ .C = 0 };
65 var u2b = U2{ .D = 0 };66 var u2b = U2{ .D = 0 };
6667
67 debug.assert(mem.eql(u8, tagName(E1.A), "A"));68 testing.expect(mem.eql(u8, tagName(E1.A), "A"));
68 debug.assert(mem.eql(u8, tagName(E1.B), "B"));69 testing.expect(mem.eql(u8, tagName(E1.B), "B"));
69 debug.assert(mem.eql(u8, tagName(E2.C), "C"));70 testing.expect(mem.eql(u8, tagName(E2.C), "C"));
70 debug.assert(mem.eql(u8, tagName(E2.D), "D"));71 testing.expect(mem.eql(u8, tagName(E2.D), "D"));
71 debug.assert(mem.eql(u8, tagName(error.E), "E"));72 testing.expect(mem.eql(u8, tagName(error.E), "E"));
72 debug.assert(mem.eql(u8, tagName(error.F), "F"));73 testing.expect(mem.eql(u8, tagName(error.F), "F"));
73 debug.assert(mem.eql(u8, tagName(u1g), "G"));74 testing.expect(mem.eql(u8, tagName(u1g), "G"));
74 debug.assert(mem.eql(u8, tagName(u1h), "H"));75 testing.expect(mem.eql(u8, tagName(u1h), "H"));
75 debug.assert(mem.eql(u8, tagName(u2a), "C"));76 testing.expect(mem.eql(u8, tagName(u2a), "C"));
76 debug.assert(mem.eql(u8, tagName(u2b), "D"));77 testing.expect(mem.eql(u8, tagName(u2b), "D"));
77}78}
7879
79pub fn stringToEnum(comptime T: type, str: []const u8) ?T {80pub fn stringToEnum(comptime T: type, str: []const u8) ?T {
...@@ -90,9 +91,9 @@ test "std.meta.stringToEnum" {...@@ -90,9 +91,9 @@ test "std.meta.stringToEnum" {
90 A,91 A,
91 B,92 B,
92 };93 };
93 debug.assert(E1.A == stringToEnum(E1, "A").?);94 testing.expect(E1.A == stringToEnum(E1, "A").?);
94 debug.assert(E1.B == stringToEnum(E1, "B").?);95 testing.expect(E1.B == stringToEnum(E1, "B").?);
95 debug.assert(null == stringToEnum(E1, "C"));96 testing.expect(null == stringToEnum(E1, "C"));
96}97}
9798
98pub fn bitCount(comptime T: type) comptime_int {99pub fn bitCount(comptime T: type) comptime_int {
...@@ -104,8 +105,8 @@ pub fn bitCount(comptime T: type) comptime_int {...@@ -104,8 +105,8 @@ pub fn bitCount(comptime T: type) comptime_int {
104}105}
105106
106test "std.meta.bitCount" {107test "std.meta.bitCount" {
107 debug.assert(bitCount(u8) == 8);108 testing.expect(bitCount(u8) == 8);
108 debug.assert(bitCount(f32) == 32);109 testing.expect(bitCount(f32) == 32);
109}110}
110111
111pub fn alignment(comptime T: type) comptime_int {112pub fn alignment(comptime T: type) comptime_int {
...@@ -115,11 +116,11 @@ pub fn alignment(comptime T: type) comptime_int {...@@ -115,11 +116,11 @@ pub fn alignment(comptime T: type) comptime_int {
115}116}
116117
117test "std.meta.alignment" {118test "std.meta.alignment" {
118 debug.assert(alignment(u8) == 1);119 testing.expect(alignment(u8) == 1);
119 debug.assert(alignment(*align(1) u8) == 1);120 testing.expect(alignment(*align(1) u8) == 1);
120 debug.assert(alignment(*align(2) u8) == 2);121 testing.expect(alignment(*align(2) u8) == 2);
121 debug.assert(alignment([]align(1) u8) == 1);122 testing.expect(alignment([]align(1) u8) == 1);
122 debug.assert(alignment([]align(2) u8) == 2);123 testing.expect(alignment([]align(2) u8) == 2);
123}124}
124125
125pub fn Child(comptime T: type) type {126pub fn Child(comptime T: type) type {
...@@ -133,11 +134,11 @@ pub fn Child(comptime T: type) type {...@@ -133,11 +134,11 @@ pub fn Child(comptime T: type) type {
133}134}
134135
135test "std.meta.Child" {136test "std.meta.Child" {
136 debug.assert(Child([1]u8) == u8);137 testing.expect(Child([1]u8) == u8);
137 debug.assert(Child(*u8) == u8);138 testing.expect(Child(*u8) == u8);
138 debug.assert(Child([]u8) == u8);139 testing.expect(Child([]u8) == u8);
139 debug.assert(Child(?u8) == u8);140 testing.expect(Child(?u8) == u8);
140 debug.assert(Child(promise->u8) == u8);141 testing.expect(Child(promise->u8) == u8);
141}142}
142143
143pub fn containerLayout(comptime T: type) TypeInfo.ContainerLayout {144pub fn containerLayout(comptime T: type) TypeInfo.ContainerLayout {
...@@ -172,15 +173,15 @@ test "std.meta.containerLayout" {...@@ -172,15 +173,15 @@ test "std.meta.containerLayout" {
172 a: u8,173 a: u8,
173 };174 };
174175
175 debug.assert(containerLayout(E1) == TypeInfo.ContainerLayout.Auto);176 testing.expect(containerLayout(E1) == TypeInfo.ContainerLayout.Auto);
176 debug.assert(containerLayout(E2) == TypeInfo.ContainerLayout.Packed);177 testing.expect(containerLayout(E2) == TypeInfo.ContainerLayout.Packed);
177 debug.assert(containerLayout(E3) == TypeInfo.ContainerLayout.Extern);178 testing.expect(containerLayout(E3) == TypeInfo.ContainerLayout.Extern);
178 debug.assert(containerLayout(S1) == TypeInfo.ContainerLayout.Auto);179 testing.expect(containerLayout(S1) == TypeInfo.ContainerLayout.Auto);
179 debug.assert(containerLayout(S2) == TypeInfo.ContainerLayout.Packed);180 testing.expect(containerLayout(S2) == TypeInfo.ContainerLayout.Packed);
180 debug.assert(containerLayout(S3) == TypeInfo.ContainerLayout.Extern);181 testing.expect(containerLayout(S3) == TypeInfo.ContainerLayout.Extern);
181 debug.assert(containerLayout(U1) == TypeInfo.ContainerLayout.Auto);182 testing.expect(containerLayout(U1) == TypeInfo.ContainerLayout.Auto);
182 debug.assert(containerLayout(U2) == TypeInfo.ContainerLayout.Packed);183 testing.expect(containerLayout(U2) == TypeInfo.ContainerLayout.Packed);
183 debug.assert(containerLayout(U3) == TypeInfo.ContainerLayout.Extern);184 testing.expect(containerLayout(U3) == TypeInfo.ContainerLayout.Extern);
184}185}
185186
186pub fn definitions(comptime T: type) []TypeInfo.Definition {187pub fn definitions(comptime T: type) []TypeInfo.Definition {
...@@ -214,8 +215,8 @@ test "std.meta.definitions" {...@@ -214,8 +215,8 @@ test "std.meta.definitions" {
214 };215 };
215216
216 inline for (defs) |def| {217 inline for (defs) |def| {
217 debug.assert(def.len == 1);218 testing.expect(def.len == 1);
218 debug.assert(comptime mem.eql(u8, def[0].name, "a"));219 testing.expect(comptime mem.eql(u8, def[0].name, "a"));
219 }220 }
220}221}
221222
...@@ -250,8 +251,8 @@ test "std.meta.definitionInfo" {...@@ -250,8 +251,8 @@ test "std.meta.definitionInfo" {
250 };251 };
251252
252 inline for (infos) |info| {253 inline for (infos) |info| {
253 debug.assert(comptime mem.eql(u8, info.name, "a"));254 testing.expect(comptime mem.eql(u8, info.name, "a"));
254 debug.assert(!info.is_pub);255 testing.expect(!info.is_pub);
255 }256 }
256}257}
257258
...@@ -288,16 +289,16 @@ test "std.meta.fields" {...@@ -288,16 +289,16 @@ test "std.meta.fields" {
288 const sf = comptime fields(S1);289 const sf = comptime fields(S1);
289 const uf = comptime fields(U1);290 const uf = comptime fields(U1);
290291
291 debug.assert(e1f.len == 1);292 testing.expect(e1f.len == 1);
292 debug.assert(e2f.len == 1);293 testing.expect(e2f.len == 1);
293 debug.assert(sf.len == 1);294 testing.expect(sf.len == 1);
294 debug.assert(uf.len == 1);295 testing.expect(uf.len == 1);
295 debug.assert(mem.eql(u8, e1f[0].name, "A"));296 testing.expect(mem.eql(u8, e1f[0].name, "A"));
296 debug.assert(mem.eql(u8, e2f[0].name, "A"));297 testing.expect(mem.eql(u8, e2f[0].name, "A"));
297 debug.assert(mem.eql(u8, sf[0].name, "a"));298 testing.expect(mem.eql(u8, sf[0].name, "a"));
298 debug.assert(mem.eql(u8, uf[0].name, "a"));299 testing.expect(mem.eql(u8, uf[0].name, "a"));
299 debug.assert(comptime sf[0].field_type == u8);300 testing.expect(comptime sf[0].field_type == u8);
300 debug.assert(comptime uf[0].field_type == u8);301 testing.expect(comptime uf[0].field_type == u8);
301}302}
302303
303pub fn fieldInfo(comptime T: type, comptime field_name: []const u8) switch (@typeInfo(T)) {304pub fn fieldInfo(comptime T: type, comptime field_name: []const u8) switch (@typeInfo(T)) {
...@@ -332,12 +333,12 @@ test "std.meta.fieldInfo" {...@@ -332,12 +333,12 @@ test "std.meta.fieldInfo" {
332 const sf = comptime fieldInfo(S1, "a");333 const sf = comptime fieldInfo(S1, "a");
333 const uf = comptime fieldInfo(U1, "a");334 const uf = comptime fieldInfo(U1, "a");
334335
335 debug.assert(mem.eql(u8, e1f.name, "A"));336 testing.expect(mem.eql(u8, e1f.name, "A"));
336 debug.assert(mem.eql(u8, e2f.name, "A"));337 testing.expect(mem.eql(u8, e2f.name, "A"));
337 debug.assert(mem.eql(u8, sf.name, "a"));338 testing.expect(mem.eql(u8, sf.name, "a"));
338 debug.assert(mem.eql(u8, uf.name, "a"));339 testing.expect(mem.eql(u8, uf.name, "a"));
339 debug.assert(comptime sf.field_type == u8);340 testing.expect(comptime sf.field_type == u8);
340 debug.assert(comptime uf.field_type == u8);341 testing.expect(comptime uf.field_type == u8);
341}342}
342343
343pub fn TagType(comptime T: type) type {344pub fn TagType(comptime T: type) type {
...@@ -358,8 +359,8 @@ test "std.meta.TagType" {...@@ -358,8 +359,8 @@ test "std.meta.TagType" {
358 D: u16,359 D: u16,
359 };360 };
360361
361 debug.assert(TagType(E) == u8);362 testing.expect(TagType(E) == u8);
362 debug.assert(TagType(U) == E);363 testing.expect(TagType(U) == E);
363}364}
364365
365///Returns the active tag of a tagged union366///Returns the active tag of a tagged union
...@@ -380,18 +381,18 @@ test "std.meta.activeTag" {...@@ -380,18 +381,18 @@ test "std.meta.activeTag" {
380 };381 };
381382
382 var u = U{ .Int = 32 };383 var u = U{ .Int = 32 };
383 debug.assert(activeTag(u) == UE.Int);384 testing.expect(activeTag(u) == UE.Int);
384385
385 u = U{ .Float = 112.9876 };386 u = U{ .Float = 112.9876 };
386 debug.assert(activeTag(u) == UE.Float);387 testing.expect(activeTag(u) == UE.Float);
387}388}
388389
389///Given a tagged union type, and an enum, return the type of the union390///Given a tagged union type, and an enum, return the type of the union
390/// field corresponding to the enum tag.391/// field corresponding to the enum tag.
391pub fn TagPayloadType(comptime U: type, tag: var) type {392pub fn TagPayloadType(comptime U: type, tag: var) type {
392 const Tag = @typeOf(tag);393 const Tag = @typeOf(tag);
393 debug.assert(trait.is(builtin.TypeId.Union)(U));394 testing.expect(trait.is(builtin.TypeId.Union)(U));
394 debug.assert(trait.is(builtin.TypeId.Enum)(Tag));395 testing.expect(trait.is(builtin.TypeId.Enum)(Tag));
395396
396 const info = @typeInfo(U).Union;397 const info = @typeInfo(U).Union;
397398
...@@ -410,7 +411,7 @@ test "std.meta.TagPayloadType" {...@@ -410,7 +411,7 @@ test "std.meta.TagPayloadType" {
410 };411 };
411 const MovedEvent = TagPayloadType(Event, Event.Moved);412 const MovedEvent = TagPayloadType(Event, Event.Moved);
412 var e: Event = undefined;413 var e: Event = undefined;
413 debug.assert(MovedEvent == @typeOf(e.Moved));414 testing.expect(MovedEvent == @typeOf(e.Moved));
414}415}
415416
416///Compares two of any type for equality. Containers are compared on a field-by-field basis,417///Compares two of any type for equality. Containers are compared on a field-by-field basis,
...@@ -509,19 +510,19 @@ test "std.meta.eql" {...@@ -509,19 +510,19 @@ test "std.meta.eql" {
509 const u_2 = U{ .s = s_1 };510 const u_2 = U{ .s = s_1 };
510 const u_3 = U{ .f = 24 };511 const u_3 = U{ .f = 24 };
511512
512 debug.assert(eql(s_1, s_3));513 testing.expect(eql(s_1, s_3));
513 debug.assert(eql(&s_1, &s_1));514 testing.expect(eql(&s_1, &s_1));
514 debug.assert(!eql(&s_1, &s_3));515 testing.expect(!eql(&s_1, &s_3));
515 debug.assert(eql(u_1, u_3));516 testing.expect(eql(u_1, u_3));
516 debug.assert(!eql(u_1, u_2));517 testing.expect(!eql(u_1, u_2));
517518
518 var a1 = "abcdef";519 var a1 = "abcdef";
519 var a2 = "abcdef";520 var a2 = "abcdef";
520 var a3 = "ghijkl";521 var a3 = "ghijkl";
521522
522 debug.assert(eql(a1, a2));523 testing.expect(eql(a1, a2));
523 debug.assert(!eql(a1, a3));524 testing.expect(!eql(a1, a3));
524 debug.assert(!eql(a1[0..], a2[0..]));525 testing.expect(!eql(a1[0..], a2[0..]));
525526
526 const EU = struct {527 const EU = struct {
527 fn tst(err: bool) !u8 {528 fn tst(err: bool) !u8 {
...@@ -530,9 +531,9 @@ test "std.meta.eql" {...@@ -530,9 +531,9 @@ test "std.meta.eql" {
530 }531 }
531 };532 };
532533
533 debug.assert(eql(EU.tst(true), EU.tst(true)));534 testing.expect(eql(EU.tst(true), EU.tst(true)));
534 debug.assert(eql(EU.tst(false), EU.tst(false)));535 testing.expect(eql(EU.tst(false), EU.tst(false)));
535 debug.assert(!eql(EU.tst(false), EU.tst(true)));536 testing.expect(!eql(EU.tst(false), EU.tst(true)));
536}537}
537538
538test "intToEnum with error return" {539test "intToEnum with error return" {
...@@ -546,9 +547,9 @@ test "intToEnum with error return" {...@@ -546,9 +547,9 @@ test "intToEnum with error return" {
546547
547 var zero: u8 = 0;548 var zero: u8 = 0;
548 var one: u16 = 1;549 var one: u16 = 1;
549 debug.assert(intToEnum(E1, zero) catch unreachable == E1.A);550 testing.expect(intToEnum(E1, zero) catch unreachable == E1.A);
550 debug.assert(intToEnum(E2, one) catch unreachable == E2.B);551 testing.expect(intToEnum(E2, one) catch unreachable == E2.B);
551 debug.assertError(intToEnum(E1, one), error.InvalidEnumTag);552 testing.expectError(error.InvalidEnumTag, intToEnum(E1, one));
552}553}
553554
554pub const IntToEnumError = error{InvalidEnumTag};555pub const IntToEnumError = error{InvalidEnumTag};
std/meta/trait.zig+67-66
...@@ -2,6 +2,7 @@ const std = @import("../index.zig");...@@ -2,6 +2,7 @@ const std = @import("../index.zig");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const mem = std.mem;3const mem = std.mem;
4const debug = std.debug;4const debug = std.debug;
5const testing = std.testing;
5const warn = debug.warn;6const warn = debug.warn;
67
7const meta = @import("index.zig");8const meta = @import("index.zig");
...@@ -50,8 +51,8 @@ test "std.meta.trait.multiTrait" {...@@ -50,8 +51,8 @@ test "std.meta.trait.multiTrait" {
50 hasField("x"),51 hasField("x"),
51 hasField("y"),52 hasField("y"),
52 });53 });
53 debug.assert(isVector(Vector2));54 testing.expect(isVector(Vector2));
54 debug.assert(!isVector(u8));55 testing.expect(!isVector(u8));
55}56}
5657
57///58///
...@@ -85,12 +86,12 @@ test "std.meta.trait.hasDef" {...@@ -85,12 +86,12 @@ test "std.meta.trait.hasDef" {
85 const value = u8(16);86 const value = u8(16);
86 };87 };
8788
88 debug.assert(hasDef("value")(TestStruct));89 testing.expect(hasDef("value")(TestStruct));
89 debug.assert(!hasDef("value")(TestStructFail));90 testing.expect(!hasDef("value")(TestStructFail));
90 debug.assert(!hasDef("value")(*TestStruct));91 testing.expect(!hasDef("value")(*TestStruct));
91 debug.assert(!hasDef("value")(**TestStructFail));92 testing.expect(!hasDef("value")(**TestStructFail));
92 debug.assert(!hasDef("x")(TestStruct));93 testing.expect(!hasDef("x")(TestStruct));
93 debug.assert(!hasDef("value")(u8));94 testing.expect(!hasDef("value")(u8));
94}95}
9596
96///97///
...@@ -111,9 +112,9 @@ test "std.meta.trait.hasFn" {...@@ -111,9 +112,9 @@ test "std.meta.trait.hasFn" {
111 pub fn useless() void {}112 pub fn useless() void {}
112 };113 };
113114
114 debug.assert(hasFn("useless")(TestStruct));115 testing.expect(hasFn("useless")(TestStruct));
115 debug.assert(!hasFn("append")(TestStruct));116 testing.expect(!hasFn("append")(TestStruct));
116 debug.assert(!hasFn("useless")(u8));117 testing.expect(!hasFn("useless")(u8));
117}118}
118119
119///120///
...@@ -143,11 +144,11 @@ test "std.meta.trait.hasField" {...@@ -143,11 +144,11 @@ test "std.meta.trait.hasField" {
143 value: u32,144 value: u32,
144 };145 };
145146
146 debug.assert(hasField("value")(TestStruct));147 testing.expect(hasField("value")(TestStruct));
147 debug.assert(!hasField("value")(*TestStruct));148 testing.expect(!hasField("value")(*TestStruct));
148 debug.assert(!hasField("x")(TestStruct));149 testing.expect(!hasField("x")(TestStruct));
149 debug.assert(!hasField("x")(**TestStruct));150 testing.expect(!hasField("x")(**TestStruct));
150 debug.assert(!hasField("value")(u8));151 testing.expect(!hasField("value")(u8));
151}152}
152153
153///154///
...@@ -161,11 +162,11 @@ pub fn is(comptime id: builtin.TypeId) TraitFn {...@@ -161,11 +162,11 @@ pub fn is(comptime id: builtin.TypeId) TraitFn {
161}162}
162163
163test "std.meta.trait.is" {164test "std.meta.trait.is" {
164 debug.assert(is(builtin.TypeId.Int)(u8));165 testing.expect(is(builtin.TypeId.Int)(u8));
165 debug.assert(!is(builtin.TypeId.Int)(f32));166 testing.expect(!is(builtin.TypeId.Int)(f32));
166 debug.assert(is(builtin.TypeId.Pointer)(*u8));167 testing.expect(is(builtin.TypeId.Pointer)(*u8));
167 debug.assert(is(builtin.TypeId.Void)(void));168 testing.expect(is(builtin.TypeId.Void)(void));
168 debug.assert(!is(builtin.TypeId.Optional)(anyerror));169 testing.expect(!is(builtin.TypeId.Optional)(anyerror));
169}170}
170171
171///172///
...@@ -180,9 +181,9 @@ pub fn isPtrTo(comptime id: builtin.TypeId) TraitFn {...@@ -180,9 +181,9 @@ pub fn isPtrTo(comptime id: builtin.TypeId) TraitFn {
180}181}
181182
182test "std.meta.trait.isPtrTo" {183test "std.meta.trait.isPtrTo" {
183 debug.assert(!isPtrTo(builtin.TypeId.Struct)(struct {}));184 testing.expect(!isPtrTo(builtin.TypeId.Struct)(struct {}));
184 debug.assert(isPtrTo(builtin.TypeId.Struct)(*struct {}));185 testing.expect(isPtrTo(builtin.TypeId.Struct)(*struct {}));
185 debug.assert(!isPtrTo(builtin.TypeId.Struct)(**struct {}));186 testing.expect(!isPtrTo(builtin.TypeId.Struct)(**struct {}));
186}187}
187188
188///////////Strait trait Fns189///////////Strait trait Fns
...@@ -205,9 +206,9 @@ test "std.meta.trait.isExtern" {...@@ -205,9 +206,9 @@ test "std.meta.trait.isExtern" {
205 const TestExStruct = extern struct {};206 const TestExStruct = extern struct {};
206 const TestStruct = struct {};207 const TestStruct = struct {};
207208
208 debug.assert(isExtern(TestExStruct));209 testing.expect(isExtern(TestExStruct));
209 debug.assert(!isExtern(TestStruct));210 testing.expect(!isExtern(TestStruct));
210 debug.assert(!isExtern(u8));211 testing.expect(!isExtern(u8));
211}212}
212213
213///214///
...@@ -226,9 +227,9 @@ test "std.meta.trait.isPacked" {...@@ -226,9 +227,9 @@ test "std.meta.trait.isPacked" {
226 const TestPStruct = packed struct {};227 const TestPStruct = packed struct {};
227 const TestStruct = struct {};228 const TestStruct = struct {};
228229
229 debug.assert(isPacked(TestPStruct));230 testing.expect(isPacked(TestPStruct));
230 debug.assert(!isPacked(TestStruct));231 testing.expect(!isPacked(TestStruct));
231 debug.assert(!isPacked(u8));232 testing.expect(!isPacked(u8));
232}233}
233234
234///235///
...@@ -240,10 +241,10 @@ pub fn isUnsignedInt(comptime T: type) bool {...@@ -240,10 +241,10 @@ pub fn isUnsignedInt(comptime T: type) bool {
240}241}
241242
242test "isUnsignedInt" {243test "isUnsignedInt" {
243 debug.assert(isUnsignedInt(u32) == true);244 testing.expect(isUnsignedInt(u32) == true);
244 debug.assert(isUnsignedInt(comptime_int) == false);245 testing.expect(isUnsignedInt(comptime_int) == false);
245 debug.assert(isUnsignedInt(i64) == false);246 testing.expect(isUnsignedInt(i64) == false);
246 debug.assert(isUnsignedInt(f64) == false);247 testing.expect(isUnsignedInt(f64) == false);
247}248}
248249
249///250///
...@@ -256,10 +257,10 @@ pub fn isSignedInt(comptime T: type) bool {...@@ -256,10 +257,10 @@ pub fn isSignedInt(comptime T: type) bool {
256}257}
257258
258test "isSignedInt" {259test "isSignedInt" {
259 debug.assert(isSignedInt(u32) == false);260 testing.expect(isSignedInt(u32) == false);
260 debug.assert(isSignedInt(comptime_int) == true);261 testing.expect(isSignedInt(comptime_int) == true);
261 debug.assert(isSignedInt(i64) == true);262 testing.expect(isSignedInt(i64) == true);
262 debug.assert(isSignedInt(f64) == false);263 testing.expect(isSignedInt(f64) == false);
263}264}
264265
265///266///
...@@ -273,9 +274,9 @@ pub fn isSingleItemPtr(comptime T: type) bool {...@@ -273,9 +274,9 @@ pub fn isSingleItemPtr(comptime T: type) bool {
273274
274test "std.meta.trait.isSingleItemPtr" {275test "std.meta.trait.isSingleItemPtr" {
275 const array = []u8{0} ** 10;276 const array = []u8{0} ** 10;
276 debug.assert(isSingleItemPtr(@typeOf(&array[0])));277 testing.expect(isSingleItemPtr(@typeOf(&array[0])));
277 debug.assert(!isSingleItemPtr(@typeOf(array)));278 testing.expect(!isSingleItemPtr(@typeOf(array)));
278 debug.assert(!isSingleItemPtr(@typeOf(array[0..1])));279 testing.expect(!isSingleItemPtr(@typeOf(array[0..1])));
279}280}
280281
281///282///
...@@ -290,9 +291,9 @@ pub fn isManyItemPtr(comptime T: type) bool {...@@ -290,9 +291,9 @@ pub fn isManyItemPtr(comptime T: type) bool {
290test "std.meta.trait.isManyItemPtr" {291test "std.meta.trait.isManyItemPtr" {
291 const array = []u8{0} ** 10;292 const array = []u8{0} ** 10;
292 const mip = @ptrCast([*]const u8, &array[0]);293 const mip = @ptrCast([*]const u8, &array[0]);
293 debug.assert(isManyItemPtr(@typeOf(mip)));294 testing.expect(isManyItemPtr(@typeOf(mip)));
294 debug.assert(!isManyItemPtr(@typeOf(array)));295 testing.expect(!isManyItemPtr(@typeOf(array)));
295 debug.assert(!isManyItemPtr(@typeOf(array[0..1])));296 testing.expect(!isManyItemPtr(@typeOf(array[0..1])));
296}297}
297298
298///299///
...@@ -306,9 +307,9 @@ pub fn isSlice(comptime T: type) bool {...@@ -306,9 +307,9 @@ pub fn isSlice(comptime T: type) bool {
306307
307test "std.meta.trait.isSlice" {308test "std.meta.trait.isSlice" {
308 const array = []u8{0} ** 10;309 const array = []u8{0} ** 10;
309 debug.assert(isSlice(@typeOf(array[0..])));310 testing.expect(isSlice(@typeOf(array[0..])));
310 debug.assert(!isSlice(@typeOf(array)));311 testing.expect(!isSlice(@typeOf(array)));
311 debug.assert(!isSlice(@typeOf(&array[0])));312 testing.expect(!isSlice(@typeOf(&array[0])));
312}313}
313314
314///315///
...@@ -328,10 +329,10 @@ test "std.meta.trait.isIndexable" {...@@ -328,10 +329,10 @@ test "std.meta.trait.isIndexable" {
328 const array = []u8{0} ** 10;329 const array = []u8{0} ** 10;
329 const slice = array[0..];330 const slice = array[0..];
330331
331 debug.assert(isIndexable(@typeOf(array)));332 testing.expect(isIndexable(@typeOf(array)));
332 debug.assert(isIndexable(@typeOf(&array)));333 testing.expect(isIndexable(@typeOf(&array)));
333 debug.assert(isIndexable(@typeOf(slice)));334 testing.expect(isIndexable(@typeOf(slice)));
334 debug.assert(!isIndexable(meta.Child(@typeOf(slice))));335 testing.expect(!isIndexable(meta.Child(@typeOf(slice))));
335}336}
336337
337///338///
...@@ -347,13 +348,13 @@ test "std.meta.trait.isNumber" {...@@ -347,13 +348,13 @@ test "std.meta.trait.isNumber" {
347 number: u8,348 number: u8,
348 };349 };
349350
350 debug.assert(isNumber(u32));351 testing.expect(isNumber(u32));
351 debug.assert(isNumber(f32));352 testing.expect(isNumber(f32));
352 debug.assert(isNumber(u64));353 testing.expect(isNumber(u64));
353 debug.assert(isNumber(@typeOf(102)));354 testing.expect(isNumber(@typeOf(102)));
354 debug.assert(isNumber(@typeOf(102.123)));355 testing.expect(isNumber(@typeOf(102.123)));
355 debug.assert(!isNumber([]u8));356 testing.expect(!isNumber([]u8));
356 debug.assert(!isNumber(NotANumber));357 testing.expect(!isNumber(NotANumber));
357}358}
358359
359///360///
...@@ -366,10 +367,10 @@ pub fn isConstPtr(comptime T: type) bool {...@@ -366,10 +367,10 @@ pub fn isConstPtr(comptime T: type) bool {
366test "std.meta.trait.isConstPtr" {367test "std.meta.trait.isConstPtr" {
367 var t = u8(0);368 var t = u8(0);
368 const c = u8(0);369 const c = u8(0);
369 debug.assert(isConstPtr(*const @typeOf(t)));370 testing.expect(isConstPtr(*const @typeOf(t)));
370 debug.assert(isConstPtr(@typeOf(&c)));371 testing.expect(isConstPtr(@typeOf(&c)));
371 debug.assert(!isConstPtr(*@typeOf(t)));372 testing.expect(!isConstPtr(*@typeOf(t)));
372 debug.assert(!isConstPtr(@typeOf(6)));373 testing.expect(!isConstPtr(@typeOf(6)));
373}374}
374375
375///376///
...@@ -393,8 +394,8 @@ test "std.meta.trait.isContainer" {...@@ -393,8 +394,8 @@ test "std.meta.trait.isContainer" {
393 B,394 B,
394 };395 };
395396
396 debug.assert(isContainer(TestStruct));397 testing.expect(isContainer(TestStruct));
397 debug.assert(isContainer(TestUnion));398 testing.expect(isContainer(TestUnion));
398 debug.assert(isContainer(TestEnum));399 testing.expect(isContainer(TestEnum));
399 debug.assert(!isContainer(u8));400 testing.expect(!isContainer(u8));
400}401}
std/mutex.zig+3-3
...@@ -2,7 +2,7 @@ const std = @import("index.zig");...@@ -2,7 +2,7 @@ const std = @import("index.zig");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const AtomicOrder = builtin.AtomicOrder;3const AtomicOrder = builtin.AtomicOrder;
4const AtomicRmwOp = builtin.AtomicRmwOp;4const AtomicRmwOp = builtin.AtomicRmwOp;
5const assert = std.debug.assert;5const testing = std.testing;
6const SpinLock = std.SpinLock;6const SpinLock = std.SpinLock;
7const linux = std.os.linux;7const linux = std.os.linux;
8const windows = std.os.windows;8const windows = std.os.windows;
...@@ -149,7 +149,7 @@ test "std.Mutex" {...@@ -149,7 +149,7 @@ test "std.Mutex" {
149149
150 if (builtin.single_threaded) {150 if (builtin.single_threaded) {
151 worker(&context);151 worker(&context);
152 std.debug.assertOrPanic(context.data == TestContext.incr_count);152 testing.expect(context.data == TestContext.incr_count);
153 } else {153 } else {
154 const thread_count = 10;154 const thread_count = 10;
155 var threads: [thread_count]*std.os.Thread = undefined;155 var threads: [thread_count]*std.os.Thread = undefined;
...@@ -159,7 +159,7 @@ test "std.Mutex" {...@@ -159,7 +159,7 @@ test "std.Mutex" {
159 for (threads) |t|159 for (threads) |t|
160 t.wait();160 t.wait();
161161
162 std.debug.assertOrPanic(context.data == thread_count * TestContext.incr_count);162 testing.expect(context.data == thread_count * TestContext.incr_count);
163 }163 }
164}164}
165165
std/os/child_process.zig-1
...@@ -7,7 +7,6 @@ const posix = os.posix;...@@ -7,7 +7,6 @@ const posix = os.posix;
7const windows = os.windows;7const windows = os.windows;
8const mem = std.mem;8const mem = std.mem;
9const debug = std.debug;9const debug = std.debug;
10const assert = debug.assert;
11const BufMap = std.BufMap;10const BufMap = std.BufMap;
12const Buffer = std.Buffer;11const Buffer = std.Buffer;
13const builtin = @import("builtin");12const builtin = @import("builtin");
std/os/index.zig+5-4
...@@ -91,6 +91,7 @@ pub const GetAppDataDirError = @import("get_app_data_dir.zig").GetAppDataDirErro...@@ -91,6 +91,7 @@ pub const GetAppDataDirError = @import("get_app_data_dir.zig").GetAppDataDirErro
9191
92const debug = std.debug;92const debug = std.debug;
93const assert = debug.assert;93const assert = debug.assert;
94const testing = std.testing;
9495
95const c = std.c;96const c = std.c;
9697
...@@ -172,7 +173,7 @@ test "os.getRandomBytes" {...@@ -172,7 +173,7 @@ test "os.getRandomBytes" {
172 try getRandomBytes(buf_b[0..]);173 try getRandomBytes(buf_b[0..]);
173174
174 // Check if random (not 100% conclusive)175 // 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));
176}177}
177178
178/// Raises a signal in the current kernel thread, ending its execution.179/// 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...@@ -828,7 +829,7 @@ pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) GetEnvVarOwned
828829
829test "os.getEnvVarOwned" {830test "os.getEnvVarOwned" {
830 var ga = debug.global_allocator;831 var ga = debug.global_allocator;
831 debug.assertError(getEnvVarOwned(ga, "BADENV"), error.EnvironmentVariableNotFound);832 testing.expectError(error.EnvironmentVariableNotFound, getEnvVarOwned(ga, "BADENV"));
832}833}
833834
834/// Caller must free the returned memory.835/// Caller must free the returned memory.
...@@ -2219,9 +2220,9 @@ fn testWindowsCmdLine(input_cmd_line: [*]const u8, expected_args: []const []cons...@@ -2219,9 +2220,9 @@ fn testWindowsCmdLine(input_cmd_line: [*]const u8, expected_args: []const []cons
2219 var it = ArgIteratorWindows.initWithCmdLine(input_cmd_line);2220 var it = ArgIteratorWindows.initWithCmdLine(input_cmd_line);
2220 for (expected_args) |expected_arg| {2221 for (expected_args) |expected_arg| {
2221 const arg = it.next(debug.global_allocator).? catch unreachable;2222 const arg = it.next(debug.global_allocator).? catch unreachable;
2222 assert(mem.eql(u8, arg, expected_arg));2223 testing.expectEqualSlices(u8, expected_arg, arg);
2223 }2224 }
2224 assert(it.next(debug.global_allocator) == null);2225 testing.expect(it.next(debug.global_allocator) == null);
2225}2226}
22262227
2227// TODO make this a build variable that you can set2228// TODO make this a build variable that you can set
std/os/linux/test.zig+6-6
...@@ -1,19 +1,19 @@...@@ -1,19 +1,19 @@
1const std = @import("../../index.zig");1const std = @import("../../index.zig");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const linux = std.os.linux;3const linux = std.os.linux;
4const assert = std.debug.assert;4const expect = std.testing.expect;
55
6test "getpid" {6test "getpid" {
7 assert(linux.getpid() != 0);7 expect(linux.getpid() != 0);
8}8}
99
10test "timer" {10test "timer" {
11 const epoll_fd = linux.epoll_create();11 const epoll_fd = linux.epoll_create();
12 var err = linux.getErrno(epoll_fd);12 var err = linux.getErrno(epoll_fd);
13 assert(err == 0);13 expect(err == 0);
1414
15 const timer_fd = linux.timerfd_create(linux.CLOCK_MONOTONIC, 0);15 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
18 const time_interval = linux.timespec{18 const time_interval = linux.timespec{
19 .tv_sec = 0,19 .tv_sec = 0,
...@@ -26,7 +26,7 @@ test "timer" {...@@ -26,7 +26,7 @@ test "timer" {
26 };26 };
2727
28 err = linux.timerfd_settime(@intCast(i32, timer_fd), 0, &new_time, null);28 err = linux.timerfd_settime(@intCast(i32, timer_fd), 0, &new_time, null);
29 assert(err == 0);29 expect(err == 0);
3030
31 var event = linux.epoll_event{31 var event = linux.epoll_event{
32 .events = linux.EPOLLIN | linux.EPOLLOUT | linux.EPOLLET,32 .events = linux.EPOLLIN | linux.EPOLLOUT | linux.EPOLLET,
...@@ -34,7 +34,7 @@ test "timer" {...@@ -34,7 +34,7 @@ test "timer" {
34 };34 };
3535
36 err = linux.epoll_ctl(@intCast(i32, epoll_fd), linux.EPOLL_CTL_ADD, @intCast(i32, timer_fd), &event);36 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
39 const events_one: linux.epoll_event = undefined;39 const events_one: linux.epoll_event = undefined;
40 var events = []linux.epoll_event{events_one} ** 8;40 var events = []linux.epoll_event{events_one} ** 8;
std/os/path.zig+58-57
...@@ -3,6 +3,7 @@ const builtin = @import("builtin");...@@ -3,6 +3,7 @@ const builtin = @import("builtin");
3const Os = builtin.Os;3const Os = builtin.Os;
4const debug = std.debug;4const debug = std.debug;
5const assert = debug.assert;5const assert = debug.assert;
6const testing = std.testing;
6const mem = std.mem;7const mem = std.mem;
7const fmt = std.fmt;8const fmt = std.fmt;
8const Allocator = mem.Allocator;9const Allocator = mem.Allocator;
...@@ -94,14 +95,14 @@ fn testJoinWindows(paths: []const []const u8, expected: []const u8) void {...@@ -94,14 +95,14 @@ fn testJoinWindows(paths: []const []const u8, expected: []const u8) void {
94 var buf: [1024]u8 = undefined;95 var buf: [1024]u8 = undefined;
95 const a = &std.heap.FixedBufferAllocator.init(&buf).allocator;96 const a = &std.heap.FixedBufferAllocator.init(&buf).allocator;
96 const actual = joinWindows(a, paths) catch @panic("fail");97 const actual = joinWindows(a, paths) catch @panic("fail");
97 debug.assertOrPanic(mem.eql(u8, actual, expected));98 testing.expectEqualSlices(u8, expected, actual);
98}99}
99100
100fn testJoinPosix(paths: []const []const u8, expected: []const u8) void {101fn testJoinPosix(paths: []const []const u8, expected: []const u8) void {
101 var buf: [1024]u8 = undefined;102 var buf: [1024]u8 = undefined;
102 const a = &std.heap.FixedBufferAllocator.init(&buf).allocator;103 const a = &std.heap.FixedBufferAllocator.init(&buf).allocator;
103 const actual = joinPosix(a, paths) catch @panic("fail");104 const actual = joinPosix(a, paths) catch @panic("fail");
104 debug.assertOrPanic(mem.eql(u8, actual, expected));105 testing.expectEqualSlices(u8, expected, actual);
105}106}
106107
107test "os.path.join" {108test "os.path.join" {
...@@ -193,11 +194,11 @@ test "os.path.isAbsolutePosix" {...@@ -193,11 +194,11 @@ test "os.path.isAbsolutePosix" {
193}194}
194195
195fn testIsAbsoluteWindows(path: []const u8, expected_result: bool) void {196fn testIsAbsoluteWindows(path: []const u8, expected_result: bool) void {
196 assert(isAbsoluteWindows(path) == expected_result);197 testing.expectEqual(expected_result, isAbsoluteWindows(path));
197}198}
198199
199fn testIsAbsolutePosix(path: []const u8, expected_result: bool) void {200fn testIsAbsolutePosix(path: []const u8, expected_result: bool) void {
200 assert(isAbsolutePosix(path) == expected_result);201 testing.expectEqual(expected_result, isAbsolutePosix(path));
201}202}
202203
203pub const WindowsPath = struct {204pub const WindowsPath = struct {
...@@ -281,33 +282,33 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {...@@ -281,33 +282,33 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {
281test "os.path.windowsParsePath" {282test "os.path.windowsParsePath" {
282 {283 {
283 const parsed = windowsParsePath("//a/b");284 const parsed = windowsParsePath("//a/b");
284 assert(parsed.is_abs);285 testing.expect(parsed.is_abs);
285 assert(parsed.kind == WindowsPath.Kind.NetworkShare);286 testing.expect(parsed.kind == WindowsPath.Kind.NetworkShare);
286 assert(mem.eql(u8, parsed.disk_designator, "//a/b"));287 testing.expect(mem.eql(u8, parsed.disk_designator, "//a/b"));
287 }288 }
288 {289 {
289 const parsed = windowsParsePath("\\\\a\\b");290 const parsed = windowsParsePath("\\\\a\\b");
290 assert(parsed.is_abs);291 testing.expect(parsed.is_abs);
291 assert(parsed.kind == WindowsPath.Kind.NetworkShare);292 testing.expect(parsed.kind == WindowsPath.Kind.NetworkShare);
292 assert(mem.eql(u8, parsed.disk_designator, "\\\\a\\b"));293 testing.expect(mem.eql(u8, parsed.disk_designator, "\\\\a\\b"));
293 }294 }
294 {295 {
295 const parsed = windowsParsePath("\\\\a\\");296 const parsed = windowsParsePath("\\\\a\\");
296 assert(!parsed.is_abs);297 testing.expect(!parsed.is_abs);
297 assert(parsed.kind == WindowsPath.Kind.None);298 testing.expect(parsed.kind == WindowsPath.Kind.None);
298 assert(mem.eql(u8, parsed.disk_designator, ""));299 testing.expect(mem.eql(u8, parsed.disk_designator, ""));
299 }300 }
300 {301 {
301 const parsed = windowsParsePath("/usr/local");302 const parsed = windowsParsePath("/usr/local");
302 assert(parsed.is_abs);303 testing.expect(parsed.is_abs);
303 assert(parsed.kind == WindowsPath.Kind.None);304 testing.expect(parsed.kind == WindowsPath.Kind.None);
304 assert(mem.eql(u8, parsed.disk_designator, ""));305 testing.expect(mem.eql(u8, parsed.disk_designator, ""));
305 }306 }
306 {307 {
307 const parsed = windowsParsePath("c:../");308 const parsed = windowsParsePath("c:../");
308 assert(!parsed.is_abs);309 testing.expect(!parsed.is_abs);
309 assert(parsed.kind == WindowsPath.Kind.Drive);310 testing.expect(parsed.kind == WindowsPath.Kind.Drive);
310 assert(mem.eql(u8, parsed.disk_designator, "c:"));311 testing.expect(mem.eql(u8, parsed.disk_designator, "c:"));
311 }312 }
312}313}
313314
...@@ -642,10 +643,10 @@ test "os.path.resolve" {...@@ -642,10 +643,10 @@ test "os.path.resolve" {
642 if (windowsParsePath(cwd).kind == WindowsPath.Kind.Drive) {643 if (windowsParsePath(cwd).kind == WindowsPath.Kind.Drive) {
643 cwd[0] = asciiUpper(cwd[0]);644 cwd[0] = asciiUpper(cwd[0]);
644 }645 }
645 assert(mem.eql(u8, testResolveWindows([][]const u8{"."}), cwd));646 testing.expect(mem.eql(u8, testResolveWindows([][]const u8{"."}), cwd));
646 } else {647 } else {
647 assert(mem.eql(u8, testResolvePosix([][]const u8{ "a/b/c/", "../../.." }), cwd));648 testing.expect(mem.eql(u8, testResolvePosix([][]const u8{ "a/b/c/", "../../.." }), cwd));
648 assert(mem.eql(u8, testResolvePosix([][]const u8{"."}), cwd));649 testing.expect(mem.eql(u8, testResolvePosix([][]const u8{"."}), cwd));
649 }650 }
650}651}
651652
...@@ -662,7 +663,7 @@ test "os.path.resolveWindows" {...@@ -662,7 +663,7 @@ test "os.path.resolveWindows" {
662 if (parsed_cwd.kind == WindowsPath.Kind.Drive) {663 if (parsed_cwd.kind == WindowsPath.Kind.Drive) {
663 expected[0] = asciiUpper(parsed_cwd.disk_designator[0]);664 expected[0] = asciiUpper(parsed_cwd.disk_designator[0]);
664 }665 }
665 assert(mem.eql(u8, result, expected));666 testing.expect(mem.eql(u8, result, expected));
666 }667 }
667 {668 {
668 const result = testResolveWindows([][]const u8{ "usr/local", "lib\\zig" });669 const result = testResolveWindows([][]const u8{ "usr/local", "lib\\zig" });
...@@ -673,36 +674,36 @@ test "os.path.resolveWindows" {...@@ -673,36 +674,36 @@ test "os.path.resolveWindows" {
673 if (parsed_cwd.kind == WindowsPath.Kind.Drive) {674 if (parsed_cwd.kind == WindowsPath.Kind.Drive) {
674 expected[0] = asciiUpper(parsed_cwd.disk_designator[0]);675 expected[0] = asciiUpper(parsed_cwd.disk_designator[0]);
675 }676 }
676 assert(mem.eql(u8, result, expected));677 testing.expect(mem.eql(u8, result, expected));
677 }678 }
678 }679 }
679680
680 assert(mem.eql(u8, testResolveWindows([][]const u8{ "c:\\a\\b\\c", "/hi", "ok" }), "C:\\hi\\ok"));681 testing.expect(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 testing.expect(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 testing.expect(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 testing.expect(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 testing.expect(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 testing.expect(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 testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "//server/share", "..", "relative\\" }), "\\\\server\\share\\relative"));
687 assert(mem.eql(u8, testResolveWindows([][]const u8{ "c:/", "//" }), "C:\\"));688 testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "c:/", "//" }), "C:\\"));
688 assert(mem.eql(u8, testResolveWindows([][]const u8{ "c:/", "//dir" }), "C:\\dir"));689 testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "c:/", "//dir" }), "C:\\dir"));
689 assert(mem.eql(u8, testResolveWindows([][]const u8{ "c:/", "//server/share" }), "\\\\server\\share\\"));690 testing.expect(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 testing.expect(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 testing.expect(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"));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"));
693}694}
694695
695test "os.path.resolvePosix" {696test "os.path.resolvePosix" {
696 assert(mem.eql(u8, testResolvePosix([][]const u8{ "/a/b", "c" }), "/a/b/c"));697 testing.expect(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 testing.expect(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 testing.expect(mem.eql(u8, testResolvePosix([][]const u8{ "/a/b/c", "..", "../" }), "/a"));
699 assert(mem.eql(u8, testResolvePosix([][]const u8{ "/", "..", ".." }), "/"));700 testing.expect(mem.eql(u8, testResolvePosix([][]const u8{ "/", "..", ".." }), "/"));
700 assert(mem.eql(u8, testResolvePosix([][]const u8{"/a/b/c/"}), "/a/b/c"));701 testing.expect(mem.eql(u8, testResolvePosix([][]const u8{"/a/b/c/"}), "/a/b/c"));
701702
702 assert(mem.eql(u8, testResolvePosix([][]const u8{ "/var/lib", "../", "file/" }), "/var/file"));703 testing.expect(mem.eql(u8, testResolvePosix([][]const u8{ "/var/lib", "../", "file/" }), "/var/file"));
703 assert(mem.eql(u8, testResolvePosix([][]const u8{ "/var/lib", "/../", "file/" }), "/file"));704 testing.expect(mem.eql(u8, testResolvePosix([][]const u8{ "/var/lib", "/../", "file/" }), "/file"));
704 assert(mem.eql(u8, testResolvePosix([][]const u8{ "/some/dir", ".", "/absolute/" }), "/absolute"));705 testing.expect(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"));706 testing.expect(mem.eql(u8, testResolvePosix([][]const u8{ "/foo/tmp.3/", "../tmp.3/cycles/root.js" }), "/foo/tmp.3/cycles/root.js"));
706}707}
707708
708fn testResolveWindows(paths: []const []const u8) []u8 {709fn testResolveWindows(paths: []const []const u8) []u8 {
...@@ -833,17 +834,17 @@ test "os.path.dirnameWindows" {...@@ -833,17 +834,17 @@ test "os.path.dirnameWindows" {
833834
834fn testDirnamePosix(input: []const u8, expected_output: ?[]const u8) void {835fn testDirnamePosix(input: []const u8, expected_output: ?[]const u8) void {
835 if (dirnamePosix(input)) |output| {836 if (dirnamePosix(input)) |output| {
836 assert(mem.eql(u8, output, expected_output.?));837 testing.expect(mem.eql(u8, output, expected_output.?));
837 } else {838 } else {
838 assert(expected_output == null);839 testing.expect(expected_output == null);
839 }840 }
840}841}
841842
842fn testDirnameWindows(input: []const u8, expected_output: ?[]const u8) void {843fn testDirnameWindows(input: []const u8, expected_output: ?[]const u8) void {
843 if (dirnameWindows(input)) |output| {844 if (dirnameWindows(input)) |output| {
844 assert(mem.eql(u8, output, expected_output.?));845 testing.expect(mem.eql(u8, output, expected_output.?));
845 } else {846 } else {
846 assert(expected_output == null);847 testing.expect(expected_output == null);
847 }848 }
848}849}
849850
...@@ -948,15 +949,15 @@ test "os.path.basename" {...@@ -948,15 +949,15 @@ test "os.path.basename" {
948}949}
949950
950fn testBasename(input: []const u8, expected_output: []const u8) void {951fn 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));
952}953}
953954
954fn testBasenamePosix(input: []const u8, expected_output: []const u8) void {955fn 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));
956}957}
957958
958fn testBasenameWindows(input: []const u8, expected_output: []const u8) void {959fn 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));
960}961}
961962
962/// Returns the relative path from `from` to `to`. If `from` and `to` each963/// Returns the relative path from `from` to `to`. If `from` and `to` each
...@@ -1131,12 +1132,12 @@ test "os.path.relative" {...@@ -1131,12 +1132,12 @@ test "os.path.relative" {
11311132
1132fn testRelativePosix(from: []const u8, to: []const u8, expected_output: []const u8) void {1133fn testRelativePosix(from: []const u8, to: []const u8, expected_output: []const u8) void {
1133 const result = relativePosix(debug.global_allocator, from, to) catch unreachable;1134 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);
1135}1136}
11361137
1137fn testRelativeWindows(from: []const u8, to: []const u8, expected_output: []const u8) void {1138fn testRelativeWindows(from: []const u8, to: []const u8, expected_output: []const u8) void {
1138 const result = relativeWindows(debug.global_allocator, from, to) catch unreachable;1139 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);
1140}1141}
11411142
1142pub const RealError = error{1143pub const RealError = error{
...@@ -1283,5 +1284,5 @@ pub fn realAlloc(allocator: *Allocator, pathname: []const u8) ![]u8 {...@@ -1283,5 +1284,5 @@ pub fn realAlloc(allocator: *Allocator, pathname: []const u8) ![]u8 {
1283test "os.path.real" {1284test "os.path.real" {
1284 // at least call it so it gets compiled1285 // at least call it so it gets compiled
1285 var buf: [os.MAX_PATH_BYTES]u8 = undefined;1286 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"));
1287}1288}
std/os/test.zig+8-8
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const std = @import("../index.zig");1const std = @import("../index.zig");
2const os = std.os;2const os = std.os;
3const assert = std.debug.assert;3const expect = std.testing.expect;
4const io = std.io;4const io = std.io;
5const mem = std.mem;5const mem = std.mem;
66
...@@ -18,7 +18,7 @@ test "makePath, put some files in it, deleteTree" {...@@ -18,7 +18,7 @@ test "makePath, put some files in it, deleteTree" {
18 if (os.Dir.open(a, "os_test_tmp")) |dir| {18 if (os.Dir.open(a, "os_test_tmp")) |dir| {
19 @panic("expected error");19 @panic("expected error");
20 } else |err| {20 } else |err| {
21 assert(err == error.FileNotFound);21 expect(err == error.FileNotFound);
22 }22 }
23}23}
2424
...@@ -27,7 +27,7 @@ test "access file" {...@@ -27,7 +27,7 @@ test "access file" {
27 if (os.File.access("os_test_tmp" ++ os.path.sep_str ++ "file.txt")) |ok| {27 if (os.File.access("os_test_tmp" ++ os.path.sep_str ++ "file.txt")) |ok| {
28 @panic("expected error");28 @panic("expected error");
29 } else |err| {29 } else |err| {
30 assert(err == error.FileNotFound);30 expect(err == error.FileNotFound);
31 }31 }
3232
33 try io.writeFile("os_test_tmp" ++ os.path.sep_str ++ "file.txt", "");33 try io.writeFile("os_test_tmp" ++ os.path.sep_str ++ "file.txt", "");
...@@ -47,9 +47,9 @@ test "std.os.Thread.getCurrentId" {...@@ -47,9 +47,9 @@ test "std.os.Thread.getCurrentId" {
47 const thread_id = thread.handle();47 const thread_id = thread.handle();
48 thread.wait();48 thread.wait();
49 switch (builtin.os) {49 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),
51 else => {51 else => {
52 assert(thread_current_id == thread_id);52 expect(thread_current_id == thread_id);
53 },53 },
54 }54 }
55}55}
...@@ -69,7 +69,7 @@ test "spawn threads" {...@@ -69,7 +69,7 @@ test "spawn threads" {
69 thread3.wait();69 thread3.wait();
70 thread4.wait();70 thread4.wait();
7171
72 assert(shared_ctx == 4);72 expect(shared_ctx == 4);
73}73}
7474
75fn start1(ctx: void) u8 {75fn start1(ctx: void) u8 {
...@@ -83,7 +83,7 @@ fn start2(ctx: *i32) u8 {...@@ -83,7 +83,7 @@ fn start2(ctx: *i32) u8 {
8383
84test "cpu count" {84test "cpu count" {
85 const cpu_count = try std.os.cpuCount(a);85 const cpu_count = try std.os.cpuCount(a);
86 assert(cpu_count >= 1);86 expect(cpu_count >= 1);
87}87}
8888
89test "AtomicFile" {89test "AtomicFile" {
...@@ -101,7 +101,7 @@ test "AtomicFile" {...@@ -101,7 +101,7 @@ test "AtomicFile" {
101 try af.finish();101 try af.finish();
102 }102 }
103 const content = try io.readFileAlloc(allocator, test_out_file);103 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
106 try os.deleteFile(test_out_file);106 try os.deleteFile(test_out_file);
107}107}
std/os/time.zig+5-4
...@@ -2,6 +2,7 @@ const std = @import("../index.zig");...@@ -2,6 +2,7 @@ const std = @import("../index.zig");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const Os = builtin.Os;3const Os = builtin.Os;
4const debug = std.debug;4const debug = std.debug;
5const testing = std.testing;
56
6const windows = std.os.windows;7const windows = std.os.windows;
7const linux = std.os.linux;8const linux = std.os.linux;
...@@ -270,7 +271,7 @@ test "os.time.timestamp" {...@@ -270,7 +271,7 @@ test "os.time.timestamp" {
270 sleep(ns_per_ms);271 sleep(ns_per_ms);
271 const time_1 = milliTimestamp();272 const time_1 = milliTimestamp();
272 const interval = time_1 - time_0;273 const interval = time_1 - time_0;
273 debug.assert(interval > 0 and interval < margin);274 testing.expect(interval > 0 and interval < margin);
274}275}
275276
276test "os.time.Timer" {277test "os.time.Timer" {
...@@ -280,11 +281,11 @@ test "os.time.Timer" {...@@ -280,11 +281,11 @@ test "os.time.Timer" {
280 var timer = try Timer.start();281 var timer = try Timer.start();
281 sleep(10 * ns_per_ms);282 sleep(10 * ns_per_ms);
282 const time_0 = timer.read();283 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
285 const time_1 = timer.lap();286 const time_1 = timer.lap();
286 debug.assert(time_1 >= time_0);287 testing.expect(time_1 >= time_0);
287288
288 timer.reset();289 timer.reset();
289 debug.assert(timer.read() < time_1);290 testing.expect(timer.read() < time_1);
290}291}
std/rand/index.zig+81-80
...@@ -17,6 +17,7 @@...@@ -17,6 +17,7 @@
17const std = @import("../index.zig");17const std = @import("../index.zig");
18const builtin = @import("builtin");18const builtin = @import("builtin");
19const assert = std.debug.assert;19const assert = std.debug.assert;
20const expect = std.testing.expect;
20const mem = std.mem;21const mem = std.mem;
21const math = std.math;22const math = std.math;
22const ziggurat = @import("ziggurat.zig");23const ziggurat = @import("ziggurat.zig");
...@@ -316,43 +317,43 @@ test "Random int" {...@@ -316,43 +317,43 @@ test "Random int" {
316fn testRandomInt() void {317fn testRandomInt() void {
317 var r = SequentialPrng.init();318 var r = SequentialPrng.init();
318319
319 assert(r.random.int(u0) == 0);320 expect(r.random.int(u0) == 0);
320321
321 r.next_value = 0;322 r.next_value = 0;
322 assert(r.random.int(u1) == 0);323 expect(r.random.int(u1) == 0);
323 assert(r.random.int(u1) == 1);324 expect(r.random.int(u1) == 1);
324 assert(r.random.int(u2) == 2);325 expect(r.random.int(u2) == 2);
325 assert(r.random.int(u2) == 3);326 expect(r.random.int(u2) == 3);
326 assert(r.random.int(u2) == 0);327 expect(r.random.int(u2) == 0);
327328
328 r.next_value = 0xff;329 r.next_value = 0xff;
329 assert(r.random.int(u8) == 0xff);330 expect(r.random.int(u8) == 0xff);
330 r.next_value = 0x11;331 r.next_value = 0x11;
331 assert(r.random.int(u8) == 0x11);332 expect(r.random.int(u8) == 0x11);
332333
333 r.next_value = 0xff;334 r.next_value = 0xff;
334 assert(r.random.int(u32) == 0xffffffff);335 expect(r.random.int(u32) == 0xffffffff);
335 r.next_value = 0x11;336 r.next_value = 0x11;
336 assert(r.random.int(u32) == 0x11111111);337 expect(r.random.int(u32) == 0x11111111);
337338
338 r.next_value = 0xff;339 r.next_value = 0xff;
339 assert(r.random.int(i32) == -1);340 expect(r.random.int(i32) == -1);
340 r.next_value = 0x11;341 r.next_value = 0x11;
341 assert(r.random.int(i32) == 0x11111111);342 expect(r.random.int(i32) == 0x11111111);
342343
343 r.next_value = 0xff;344 r.next_value = 0xff;
344 assert(r.random.int(i8) == -1);345 expect(r.random.int(i8) == -1);
345 r.next_value = 0x11;346 r.next_value = 0x11;
346 assert(r.random.int(i8) == 0x11);347 expect(r.random.int(i8) == 0x11);
347348
348 r.next_value = 0xff;349 r.next_value = 0xff;
349 assert(r.random.int(u33) == 0x1ffffffff);350 expect(r.random.int(u33) == 0x1ffffffff);
350 r.next_value = 0xff;351 r.next_value = 0xff;
351 assert(r.random.int(i1) == -1);352 expect(r.random.int(i1) == -1);
352 r.next_value = 0xff;353 r.next_value = 0xff;
353 assert(r.random.int(i2) == -1);354 expect(r.random.int(i2) == -1);
354 r.next_value = 0xff;355 r.next_value = 0xff;
355 assert(r.random.int(i33) == -1);356 expect(r.random.int(i33) == -1);
356}357}
357358
358test "Random boolean" {359test "Random boolean" {
...@@ -361,10 +362,10 @@ test "Random boolean" {...@@ -361,10 +362,10 @@ test "Random boolean" {
361}362}
362fn testRandomBoolean() void {363fn testRandomBoolean() void {
363 var r = SequentialPrng.init();364 var r = SequentialPrng.init();
364 assert(r.random.boolean() == false);365 expect(r.random.boolean() == false);
365 assert(r.random.boolean() == true);366 expect(r.random.boolean() == true);
366 assert(r.random.boolean() == false);367 expect(r.random.boolean() == false);
367 assert(r.random.boolean() == true);368 expect(r.random.boolean() == true);
368}369}
369370
370test "Random intLessThan" {371test "Random intLessThan" {
...@@ -375,36 +376,36 @@ test "Random intLessThan" {...@@ -375,36 +376,36 @@ test "Random intLessThan" {
375fn testRandomIntLessThan() void {376fn testRandomIntLessThan() void {
376 var r = SequentialPrng.init();377 var r = SequentialPrng.init();
377 r.next_value = 0xff;378 r.next_value = 0xff;
378 assert(r.random.uintLessThan(u8, 4) == 3);379 expect(r.random.uintLessThan(u8, 4) == 3);
379 assert(r.next_value == 0);380 expect(r.next_value == 0);
380 assert(r.random.uintLessThan(u8, 4) == 0);381 expect(r.random.uintLessThan(u8, 4) == 0);
381 assert(r.next_value == 1);382 expect(r.next_value == 1);
382383
383 r.next_value = 0;384 r.next_value = 0;
384 assert(r.random.uintLessThan(u64, 32) == 0);385 expect(r.random.uintLessThan(u64, 32) == 0);
385386
386 // trigger the bias rejection code path387 // trigger the bias rejection code path
387 r.next_value = 0;388 r.next_value = 0;
388 assert(r.random.uintLessThan(u8, 3) == 0);389 expect(r.random.uintLessThan(u8, 3) == 0);
389 // verify we incremented twice390 // verify we incremented twice
390 assert(r.next_value == 2);391 expect(r.next_value == 2);
391392
392 r.next_value = 0xff;393 r.next_value = 0xff;
393 assert(r.random.intRangeLessThan(u8, 0, 0x80) == 0x7f);394 expect(r.random.intRangeLessThan(u8, 0, 0x80) == 0x7f);
394 r.next_value = 0xff;395 r.next_value = 0xff;
395 assert(r.random.intRangeLessThan(u8, 0x7f, 0xff) == 0xfe);396 expect(r.random.intRangeLessThan(u8, 0x7f, 0xff) == 0xfe);
396397
397 r.next_value = 0xff;398 r.next_value = 0xff;
398 assert(r.random.intRangeLessThan(i8, 0, 0x40) == 0x3f);399 expect(r.random.intRangeLessThan(i8, 0, 0x40) == 0x3f);
399 r.next_value = 0xff;400 r.next_value = 0xff;
400 assert(r.random.intRangeLessThan(i8, -0x40, 0x40) == 0x3f);401 expect(r.random.intRangeLessThan(i8, -0x40, 0x40) == 0x3f);
401 r.next_value = 0xff;402 r.next_value = 0xff;
402 assert(r.random.intRangeLessThan(i8, -0x80, 0) == -1);403 expect(r.random.intRangeLessThan(i8, -0x80, 0) == -1);
403404
404 r.next_value = 0xff;405 r.next_value = 0xff;
405 assert(r.random.intRangeLessThan(i3, -4, 0) == -1);406 expect(r.random.intRangeLessThan(i3, -4, 0) == -1);
406 r.next_value = 0xff;407 r.next_value = 0xff;
407 assert(r.random.intRangeLessThan(i3, -2, 2) == 1);408 expect(r.random.intRangeLessThan(i3, -2, 2) == 1);
408}409}
409410
410test "Random intAtMost" {411test "Random intAtMost" {
...@@ -415,34 +416,34 @@ test "Random intAtMost" {...@@ -415,34 +416,34 @@ test "Random intAtMost" {
415fn testRandomIntAtMost() void {416fn testRandomIntAtMost() void {
416 var r = SequentialPrng.init();417 var r = SequentialPrng.init();
417 r.next_value = 0xff;418 r.next_value = 0xff;
418 assert(r.random.uintAtMost(u8, 3) == 3);419 expect(r.random.uintAtMost(u8, 3) == 3);
419 assert(r.next_value == 0);420 expect(r.next_value == 0);
420 assert(r.random.uintAtMost(u8, 3) == 0);421 expect(r.random.uintAtMost(u8, 3) == 0);
421422
422 // trigger the bias rejection code path423 // trigger the bias rejection code path
423 r.next_value = 0;424 r.next_value = 0;
424 assert(r.random.uintAtMost(u8, 2) == 0);425 expect(r.random.uintAtMost(u8, 2) == 0);
425 // verify we incremented twice426 // verify we incremented twice
426 assert(r.next_value == 2);427 expect(r.next_value == 2);
427428
428 r.next_value = 0xff;429 r.next_value = 0xff;
429 assert(r.random.intRangeAtMost(u8, 0, 0x7f) == 0x7f);430 expect(r.random.intRangeAtMost(u8, 0, 0x7f) == 0x7f);
430 r.next_value = 0xff;431 r.next_value = 0xff;
431 assert(r.random.intRangeAtMost(u8, 0x7f, 0xfe) == 0xfe);432 expect(r.random.intRangeAtMost(u8, 0x7f, 0xfe) == 0xfe);
432433
433 r.next_value = 0xff;434 r.next_value = 0xff;
434 assert(r.random.intRangeAtMost(i8, 0, 0x3f) == 0x3f);435 expect(r.random.intRangeAtMost(i8, 0, 0x3f) == 0x3f);
435 r.next_value = 0xff;436 r.next_value = 0xff;
436 assert(r.random.intRangeAtMost(i8, -0x40, 0x3f) == 0x3f);437 expect(r.random.intRangeAtMost(i8, -0x40, 0x3f) == 0x3f);
437 r.next_value = 0xff;438 r.next_value = 0xff;
438 assert(r.random.intRangeAtMost(i8, -0x80, -1) == -1);439 expect(r.random.intRangeAtMost(i8, -0x80, -1) == -1);
439440
440 r.next_value = 0xff;441 r.next_value = 0xff;
441 assert(r.random.intRangeAtMost(i3, -4, -1) == -1);442 expect(r.random.intRangeAtMost(i3, -4, -1) == -1);
442 r.next_value = 0xff;443 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);
446}447}
447448
448test "Random Biased" {449test "Random Biased" {
...@@ -450,30 +451,30 @@ test "Random Biased" {...@@ -450,30 +451,30 @@ test "Random Biased" {
450 // Not thoroughly checking the logic here.451 // Not thoroughly checking the logic here.
451 // Just want to execute all the paths with different types.452 // Just want to execute all the paths with different types.
452453
453 assert(r.random.uintLessThanBiased(u1, 1) == 0);454 expect(r.random.uintLessThanBiased(u1, 1) == 0);
454 assert(r.random.uintLessThanBiased(u32, 10) < 10);455 expect(r.random.uintLessThanBiased(u32, 10) < 10);
455 assert(r.random.uintLessThanBiased(u64, 20) < 20);456 expect(r.random.uintLessThanBiased(u64, 20) < 20);
456457
457 assert(r.random.uintAtMostBiased(u0, 0) == 0);458 expect(r.random.uintAtMostBiased(u0, 0) == 0);
458 assert(r.random.uintAtMostBiased(u1, 0) <= 0);459 expect(r.random.uintAtMostBiased(u1, 0) <= 0);
459 assert(r.random.uintAtMostBiased(u32, 10) <= 10);460 expect(r.random.uintAtMostBiased(u32, 10) <= 10);
460 assert(r.random.uintAtMostBiased(u64, 20) <= 20);461 expect(r.random.uintAtMostBiased(u64, 20) <= 20);
461462
462 assert(r.random.intRangeLessThanBiased(u1, 0, 1) == 0);463 expect(r.random.intRangeLessThanBiased(u1, 0, 1) == 0);
463 assert(r.random.intRangeLessThanBiased(i1, -1, 0) == -1);464 expect(r.random.intRangeLessThanBiased(i1, -1, 0) == -1);
464 assert(r.random.intRangeLessThanBiased(u32, 10, 20) >= 10);465 expect(r.random.intRangeLessThanBiased(u32, 10, 20) >= 10);
465 assert(r.random.intRangeLessThanBiased(i32, 10, 20) >= 10);466 expect(r.random.intRangeLessThanBiased(i32, 10, 20) >= 10);
466 assert(r.random.intRangeLessThanBiased(u64, 20, 40) >= 20);467 expect(r.random.intRangeLessThanBiased(u64, 20, 40) >= 20);
467 assert(r.random.intRangeLessThanBiased(i64, 20, 40) >= 20);468 expect(r.random.intRangeLessThanBiased(i64, 20, 40) >= 20);
468469
469 // uncomment for broken module error:470 // uncomment for broken module error:
470 //assert(r.random.intRangeAtMostBiased(u0, 0, 0) == 0);471 //expect(r.random.intRangeAtMostBiased(u0, 0, 0) == 0);
471 assert(r.random.intRangeAtMostBiased(u1, 0, 1) >= 0);472 expect(r.random.intRangeAtMostBiased(u1, 0, 1) >= 0);
472 assert(r.random.intRangeAtMostBiased(i1, -1, 0) >= -1);473 expect(r.random.intRangeAtMostBiased(i1, -1, 0) >= -1);
473 assert(r.random.intRangeAtMostBiased(u32, 10, 20) >= 10);474 expect(r.random.intRangeAtMostBiased(u32, 10, 20) >= 10);
474 assert(r.random.intRangeAtMostBiased(i32, 10, 20) >= 10);475 expect(r.random.intRangeAtMostBiased(i32, 10, 20) >= 10);
475 assert(r.random.intRangeAtMostBiased(u64, 20, 40) >= 20);476 expect(r.random.intRangeAtMostBiased(u64, 20, 40) >= 20);
476 assert(r.random.intRangeAtMostBiased(i64, 20, 40) >= 20);477 expect(r.random.intRangeAtMostBiased(i64, 20, 40) >= 20);
477}478}
478479
479// Generator to extend 64-bit seed values into longer sequences.480// Generator to extend 64-bit seed values into longer sequences.
...@@ -510,7 +511,7 @@ test "splitmix64 sequence" {...@@ -510,7 +511,7 @@ test "splitmix64 sequence" {
510 };511 };
511512
512 for (seq) |s| {513 for (seq) |s| {
513 std.debug.assert(s == r.next());514 expect(s == r.next());
514 }515 }
515}516}
516517
...@@ -603,7 +604,7 @@ test "pcg sequence" {...@@ -603,7 +604,7 @@ test "pcg sequence" {
603 };604 };
604605
605 for (seq) |s| {606 for (seq) |s| {
606 std.debug.assert(s == r.next());607 expect(s == r.next());
607 }608 }
608}609}
609610
...@@ -712,7 +713,7 @@ test "xoroshiro sequence" {...@@ -712,7 +713,7 @@ test "xoroshiro sequence" {
712 };713 };
713714
714 for (seq1) |s| {715 for (seq1) |s| {
715 std.debug.assert(s == r.next());716 expect(s == r.next());
716 }717 }
717718
718 r.jump();719 r.jump();
...@@ -727,7 +728,7 @@ test "xoroshiro sequence" {...@@ -727,7 +728,7 @@ test "xoroshiro sequence" {
727 };728 };
728729
729 for (seq2) |s| {730 for (seq2) |s| {
730 std.debug.assert(s == r.next());731 expect(s == r.next());
731 }732 }
732}733}
733734
...@@ -930,7 +931,7 @@ test "isaac64 sequence" {...@@ -930,7 +931,7 @@ test "isaac64 sequence" {
930 };931 };
931932
932 for (seq) |s| {933 for (seq) |s| {
933 std.debug.assert(s == r.next());934 expect(s == r.next());
934 }935 }
935}936}
936937
...@@ -941,12 +942,12 @@ test "Random float" {...@@ -941,12 +942,12 @@ test "Random float" {
941 var i: usize = 0;942 var i: usize = 0;
942 while (i < 1000) : (i += 1) {943 while (i < 1000) : (i += 1) {
943 const val1 = prng.random.float(f32);944 const val1 = prng.random.float(f32);
944 std.debug.assert(val1 >= 0.0);945 expect(val1 >= 0.0);
945 std.debug.assert(val1 < 1.0);946 expect(val1 < 1.0);
946947
947 const val2 = prng.random.float(f64);948 const val2 = prng.random.float(f64);
948 std.debug.assert(val2 >= 0.0);949 expect(val2 >= 0.0);
949 std.debug.assert(val2 < 1.0);950 expect(val2 < 1.0);
950 }951 }
951}952}
952953
...@@ -960,12 +961,12 @@ test "Random shuffle" {...@@ -960,12 +961,12 @@ test "Random shuffle" {
960 while (i < 1000) : (i += 1) {961 while (i < 1000) : (i += 1) {
961 prng.random.shuffle(u8, seq[0..]);962 prng.random.shuffle(u8, seq[0..]);
962 seen[seq[0]] = true;963 seen[seq[0]] = true;
963 std.debug.assert(sumArray(seq[0..]) == 10);964 expect(sumArray(seq[0..]) == 10);
964 }965 }
965966
966 // we should see every entry at the head at least once967 // we should see every entry at the head at least once
967 for (seen) |e| {968 for (seen) |e| {
968 std.debug.assert(e == true);969 expect(e == true);
969 }970 }
970}971}
971972
std/rb.zig+3-2
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1const std = @import("index.zig");1const std = @import("index.zig");
2const assert = std.debug.assert;2const assert = std.debug.assert;
3const testing = std.testing;
3const mem = std.mem; // For mem.Compare4const mem = std.mem; // For mem.Compare
45
5const Color = enum(u1) {6const Color = enum(u1) {
...@@ -533,13 +534,13 @@ test "rb" {...@@ -533,13 +534,13 @@ test "rb" {
533 _ = tree.insert(&ns[8].node);534 _ = tree.insert(&ns[8].node);
534 _ = tree.insert(&ns[9].node);535 _ = tree.insert(&ns[9].node);
535 tree.remove(&ns[3].node);536 tree.remove(&ns[3].node);
536 assert(tree.insert(&dup.node) == &ns[7].node);537 testing.expect(tree.insert(&dup.node) == &ns[7].node);
537 try tree.replace(&ns[7].node, &dup.node);538 try tree.replace(&ns[7].node, &dup.node);
538539
539 var num: *testNumber = undefined;540 var num: *testNumber = undefined;
540 num = testGetNumber(tree.first().?);541 num = testGetNumber(tree.first().?);
541 while (num.node.next() != null) {542 while (num.node.next() != null) {
542 assert(testGetNumber(num.node.next().?).value > num.value);543 testing.expect(testGetNumber(num.node.next().?).value > num.value);
543 num = testGetNumber(num.node.next().?);544 num = testGetNumber(num.node.next().?);
544 }545 }
545}546}
std/segmented_list.zig+16-15
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1const std = @import("index.zig");1const std = @import("index.zig");
2const assert = std.debug.assert;2const assert = std.debug.assert;
3const testing = std.testing;
3const Allocator = std.mem.Allocator;4const Allocator = std.mem.Allocator;
45
5// Imagine that `fn at(self: *Self, index: usize) &T` is a customer asking for a box6// 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 {...@@ -352,14 +353,14 @@ fn testSegmentedList(comptime prealloc: usize, allocator: *Allocator) !void {
352 var i: usize = 0;353 var i: usize = 0;
353 while (i < 100) : (i += 1) {354 while (i < 100) : (i += 1) {
354 try list.push(@intCast(i32, i + 1));355 try list.push(@intCast(i32, i + 1));
355 assert(list.len == i + 1);356 testing.expect(list.len == i + 1);
356 }357 }
357 }358 }
358359
359 {360 {
360 var i: usize = 0;361 var i: usize = 0;
361 while (i < 100) : (i += 1) {362 while (i < 100) : (i += 1) {
362 assert(list.at(i).* == @intCast(i32, i + 1));363 testing.expect(list.at(i).* == @intCast(i32, i + 1));
363 }364 }
364 }365 }
365366
...@@ -368,35 +369,35 @@ fn testSegmentedList(comptime prealloc: usize, allocator: *Allocator) !void {...@@ -368,35 +369,35 @@ fn testSegmentedList(comptime prealloc: usize, allocator: *Allocator) !void {
368 var x: i32 = 0;369 var x: i32 = 0;
369 while (it.next()) |item| {370 while (it.next()) |item| {
370 x += 1;371 x += 1;
371 assert(item.* == x);372 testing.expect(item.* == x);
372 }373 }
373 assert(x == 100);374 testing.expect(x == 100);
374 while (it.prev()) |item| : (x -= 1) {375 while (it.prev()) |item| : (x -= 1) {
375 assert(item.* == x);376 testing.expect(item.* == x);
376 }377 }
377 assert(x == 0);378 testing.expect(x == 0);
378 }379 }
379380
380 assert(list.pop().? == 100);381 testing.expect(list.pop().? == 100);
381 assert(list.len == 99);382 testing.expect(list.len == 99);
382383
383 try list.pushMany([]i32{384 try list.pushMany([]i32{
384 1,385 1,
385 2,386 2,
386 3,387 3,
387 });388 });
388 assert(list.len == 102);389 testing.expect(list.len == 102);
389 assert(list.pop().? == 3);390 testing.expect(list.pop().? == 3);
390 assert(list.pop().? == 2);391 testing.expect(list.pop().? == 2);
391 assert(list.pop().? == 1);392 testing.expect(list.pop().? == 1);
392 assert(list.len == 99);393 testing.expect(list.len == 99);
393394
394 try list.pushMany([]const i32{});395 try list.pushMany([]const i32{});
395 assert(list.len == 99);396 testing.expect(list.len == 99);
396397
397 var i: i32 = 99;398 var i: i32 = 99;
398 while (list.pop()) |item| : (i -= 1) {399 while (list.pop()) |item| : (i -= 1) {
399 assert(item == i);400 testing.expect(item == i);
400 list.shrinkCapacity(list.len);401 list.shrinkCapacity(list.len);
401 }402 }
402}403}
std/sort.zig+9-8
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1const std = @import("index.zig");1const std = @import("index.zig");
2const assert = std.debug.assert;2const assert = std.debug.assert;
3const testing = std.testing;
3const mem = std.mem;4const mem = std.mem;
4const math = std.math;5const math = std.math;
5const builtin = @import("builtin");6const builtin = @import("builtin");
...@@ -1031,8 +1032,8 @@ fn testStableSort() void {...@@ -1031,8 +1032,8 @@ fn testStableSort() void {
1031 for (cases) |*case| {1032 for (cases) |*case| {
1032 insertionSort(IdAndValue, (case.*)[0..], cmpByValue);1033 insertionSort(IdAndValue, (case.*)[0..], cmpByValue);
1033 for (case.*) |item, i| {1034 for (case.*) |item, i| {
1034 assert(item.id == expected[i].id);1035 testing.expect(item.id == expected[i].id);
1035 assert(item.value == expected[i].value);1036 testing.expect(item.value == expected[i].value);
1036 }1037 }
1037 }1038 }
1038}1039}
...@@ -1077,7 +1078,7 @@ test "std.sort" {...@@ -1077,7 +1078,7 @@ test "std.sort" {
1077 const slice = buf[0..case[0].len];1078 const slice = buf[0..case[0].len];
1078 mem.copy(u8, slice, case[0]);1079 mem.copy(u8, slice, case[0]);
1079 sort(u8, slice, asc(u8));1080 sort(u8, slice, asc(u8));
1080 assert(mem.eql(u8, slice, case[1]));1081 testing.expect(mem.eql(u8, slice, case[1]));
1081 }1082 }
10821083
1083 const i32cases = [][]const []const i32{1084 const i32cases = [][]const []const i32{
...@@ -1112,7 +1113,7 @@ test "std.sort" {...@@ -1112,7 +1113,7 @@ test "std.sort" {
1112 const slice = buf[0..case[0].len];1113 const slice = buf[0..case[0].len];
1113 mem.copy(i32, slice, case[0]);1114 mem.copy(i32, slice, case[0]);
1114 sort(i32, slice, asc(i32));1115 sort(i32, slice, asc(i32));
1115 assert(mem.eql(i32, slice, case[1]));1116 testing.expect(mem.eql(i32, slice, case[1]));
1116 }1117 }
1117}1118}
11181119
...@@ -1149,7 +1150,7 @@ test "std.sort descending" {...@@ -1149,7 +1150,7 @@ test "std.sort descending" {
1149 const slice = buf[0..case[0].len];1150 const slice = buf[0..case[0].len];
1150 mem.copy(i32, slice, case[0]);1151 mem.copy(i32, slice, case[0]);
1151 sort(i32, slice, desc(i32));1152 sort(i32, slice, desc(i32));
1152 assert(mem.eql(i32, slice, case[1]));1153 testing.expect(mem.eql(i32, slice, case[1]));
1153 }1154 }
1154}1155}
11551156
...@@ -1157,7 +1158,7 @@ test "another sort case" {...@@ -1157,7 +1158,7 @@ test "another sort case" {
1157 var arr = []i32{ 5, 3, 1, 2, 4 };1158 var arr = []i32{ 5, 3, 1, 2, 4 };
1158 sort(i32, arr[0..], asc(i32));1159 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 }));
1161}1162}
11621163
1163test "sort fuzz testing" {1164test "sort fuzz testing" {
...@@ -1185,9 +1186,9 @@ fn fuzzTest(rng: *std.rand.Random) void {...@@ -1185,9 +1186,9 @@ fn fuzzTest(rng: *std.rand.Random) void {
1185 var index: usize = 1;1186 var index: usize = 1;
1186 while (index < array.len) : (index += 1) {1187 while (index < array.len) : (index += 1) {
1187 if (array[index].value == array[index - 1].value) {1188 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);
1189 } else {1190 } else {
1190 assert(array[index].value > array[index - 1].value);1191 testing.expect(array[index].value > array[index - 1].value);
1191 }1192 }
1192 }1193 }
1193}1194}
std/special/compiler_rt/divti3_test.zig+2-2
...@@ -1,9 +1,9 @@...@@ -1,9 +1,9 @@
1const __divti3 = @import("divti3.zig").__divti3;1const __divti3 = @import("divti3.zig").__divti3;
2const assert = @import("std").debug.assert;2const testing = @import("std").testing;
33
4fn test__divti3(a: i128, b: i128, expected: i128) void {4fn test__divti3(a: i128, b: i128, expected: i128) void {
5 const x = __divti3(a, b);5 const x = __divti3(a, b);
6 assert(x == expected);6 testing.expect(x == expected);
7}7}
88
9test "divti3" {9test "divti3" {
std/special/compiler_rt/extendXfYf2_test.zig-1
...@@ -1,7 +1,6 @@...@@ -1,7 +1,6 @@
1const __extenddftf2 = @import("extendXfYf2.zig").__extenddftf2;1const __extenddftf2 = @import("extendXfYf2.zig").__extenddftf2;
2const __extendhfsf2 = @import("extendXfYf2.zig").__extendhfsf2;2const __extendhfsf2 = @import("extendXfYf2.zig").__extendhfsf2;
3const __extendsftf2 = @import("extendXfYf2.zig").__extendsftf2;3const __extendsftf2 = @import("extendXfYf2.zig").__extendsftf2;
4const assert = @import("std").debug.assert;
54
6fn test__extenddftf2(a: f64, expectedHi: u64, expectedLo: u64) void {5fn test__extenddftf2(a: f64, expectedHi: u64, expectedLo: u64) void {
7 const x = __extenddftf2(a);6 const x = __extenddftf2(a);
std/special/compiler_rt/fixdfdi_test.zig+2-2
...@@ -1,13 +1,13 @@...@@ -1,13 +1,13 @@
1const __fixdfdi = @import("fixdfdi.zig").__fixdfdi;1const __fixdfdi = @import("fixdfdi.zig").__fixdfdi;
2const std = @import("std");2const std = @import("std");
3const math = std.math;3const math = std.math;
4const assert = std.debug.assert;4const testing = std.testing;
5const warn = std.debug.warn;5const warn = std.debug.warn;
66
7fn test__fixdfdi(a: f64, expected: i64) void {7fn test__fixdfdi(a: f64, expected: i64) void {
8 const x = __fixdfdi(a);8 const x = __fixdfdi(a);
9 //warn("a={}:{x} x={}:{x} expected={}:{x}:u64({x})\n", a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u64, expected));9 //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);
11}11}
1212
13test "fixdfdi" {13test "fixdfdi" {
std/special/compiler_rt/fixdfsi_test.zig+2-2
...@@ -1,13 +1,13 @@...@@ -1,13 +1,13 @@
1const __fixdfsi = @import("fixdfsi.zig").__fixdfsi;1const __fixdfsi = @import("fixdfsi.zig").__fixdfsi;
2const std = @import("std");2const std = @import("std");
3const math = std.math;3const math = std.math;
4const assert = std.debug.assert;4const testing = std.testing;
5const warn = std.debug.warn;5const warn = std.debug.warn;
66
7fn test__fixdfsi(a: f64, expected: i32) void {7fn test__fixdfsi(a: f64, expected: i32) void {
8 const x = __fixdfsi(a);8 const x = __fixdfsi(a);
9 //warn("a={}:{x} x={}:{x} expected={}:{x}:u64({x})\n", a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u32, expected));9 //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);
11}11}
1212
13test "fixdfsi" {13test "fixdfsi" {
std/special/compiler_rt/fixdfti_test.zig+2-2
...@@ -1,13 +1,13 @@...@@ -1,13 +1,13 @@
1const __fixdfti = @import("fixdfti.zig").__fixdfti;1const __fixdfti = @import("fixdfti.zig").__fixdfti;
2const std = @import("std");2const std = @import("std");
3const math = std.math;3const math = std.math;
4const assert = std.debug.assert;4const testing = std.testing;
5const warn = std.debug.warn;5const warn = std.debug.warn;
66
7fn test__fixdfti(a: f64, expected: i128) void {7fn test__fixdfti(a: f64, expected: i128) void {
8 const x = __fixdfti(a);8 const x = __fixdfti(a);
9 //warn("a={}:{x} x={}:{x} expected={}:{x}:u64({x})\n", a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u128, expected));9 //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);
11}11}
1212
13test "fixdfti" {13test "fixdfti" {
std/special/compiler_rt/fixint_test.zig+2-2
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const is_test = @import("builtin").is_test;1const is_test = @import("builtin").is_test;
2const std = @import("std");2const std = @import("std");
3const math = std.math;3const math = std.math;
4const assert = std.debug.assert;4const testing = std.testing;
5const warn = std.debug.warn;5const warn = std.debug.warn;
66
7const fixint = @import("fixint.zig").fixint;7const fixint = @import("fixint.zig").fixint;
...@@ -9,7 +9,7 @@ const fixint = @import("fixint.zig").fixint;...@@ -9,7 +9,7 @@ const fixint = @import("fixint.zig").fixint;
9fn test__fixint(comptime fp_t: type, comptime fixint_t: type, a: fp_t, expected: fixint_t) void {9fn test__fixint(comptime fp_t: type, comptime fixint_t: type, a: fp_t, expected: fixint_t) void {
10 const x = fixint(fp_t, fixint_t, a);10 const x = fixint(fp_t, fixint_t, a);
11 //warn("a={} x={}:{x} expected={}:{x})\n", a, x, x, expected, expected);11 //warn("a={} x={}:{x} expected={}:{x})\n", a, x, x, expected, expected);
12 assert(x == expected);12 testing.expect(x == expected);
13}13}
1414
15test "fixint.i1" {15test "fixint.i1" {
std/special/compiler_rt/fixsfdi_test.zig+2-2
...@@ -1,13 +1,13 @@...@@ -1,13 +1,13 @@
1const __fixsfdi = @import("fixsfdi.zig").__fixsfdi;1const __fixsfdi = @import("fixsfdi.zig").__fixsfdi;
2const std = @import("std");2const std = @import("std");
3const math = std.math;3const math = std.math;
4const assert = std.debug.assert;4const testing = std.testing;
5const warn = std.debug.warn;5const warn = std.debug.warn;
66
7fn test__fixsfdi(a: f32, expected: i64) void {7fn test__fixsfdi(a: f32, expected: i64) void {
8 const x = __fixsfdi(a);8 const x = __fixsfdi(a);
9 //warn("a={}:{x} x={}:{x} expected={}:{x}:u32({x})\n", a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u64, expected));9 //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);
11}11}
1212
13test "fixsfdi" {13test "fixsfdi" {
std/special/compiler_rt/fixsfsi_test.zig+2-2
...@@ -1,13 +1,13 @@...@@ -1,13 +1,13 @@
1const __fixsfsi = @import("fixsfsi.zig").__fixsfsi;1const __fixsfsi = @import("fixsfsi.zig").__fixsfsi;
2const std = @import("std");2const std = @import("std");
3const math = std.math;3const math = std.math;
4const assert = std.debug.assert;4const testing = std.testing;
5const warn = std.debug.warn;5const warn = std.debug.warn;
66
7fn test__fixsfsi(a: f32, expected: i32) void {7fn test__fixsfsi(a: f32, expected: i32) void {
8 const x = __fixsfsi(a);8 const x = __fixsfsi(a);
9 //warn("a={}:{x} x={}:{x} expected={}:{x}:u32({x})\n", a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u32, expected));9 //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);
11}11}
1212
13test "fixsfsi" {13test "fixsfsi" {
std/special/compiler_rt/fixsfti_test.zig+2-2
...@@ -1,13 +1,13 @@...@@ -1,13 +1,13 @@
1const __fixsfti = @import("fixsfti.zig").__fixsfti;1const __fixsfti = @import("fixsfti.zig").__fixsfti;
2const std = @import("std");2const std = @import("std");
3const math = std.math;3const math = std.math;
4const assert = std.debug.assert;4const testing = std.testing;
5const warn = std.debug.warn;5const warn = std.debug.warn;
66
7fn test__fixsfti(a: f32, expected: i128) void {7fn test__fixsfti(a: f32, expected: i128) void {
8 const x = __fixsfti(a);8 const x = __fixsfti(a);
9 //warn("a={}:{x} x={}:{x} expected={}:{x}:u128({x})\n", a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u128, expected));9 //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);
11}11}
1212
13test "fixsfti" {13test "fixsfti" {
std/special/compiler_rt/fixtfdi_test.zig+2-2
...@@ -1,13 +1,13 @@...@@ -1,13 +1,13 @@
1const __fixtfdi = @import("fixtfdi.zig").__fixtfdi;1const __fixtfdi = @import("fixtfdi.zig").__fixtfdi;
2const std = @import("std");2const std = @import("std");
3const math = std.math;3const math = std.math;
4const assert = std.debug.assert;4const testing = std.testing;
5const warn = std.debug.warn;5const warn = std.debug.warn;
66
7fn test__fixtfdi(a: f128, expected: i64) void {7fn test__fixtfdi(a: f128, expected: i64) void {
8 const x = __fixtfdi(a);8 const x = __fixtfdi(a);
9 //warn("a={}:{x} x={}:{x} expected={}:{x}:u64({x})\n", a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u64, expected));9 //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);
11}11}
1212
13test "fixtfdi" {13test "fixtfdi" {
std/special/compiler_rt/fixtfsi_test.zig+2-2
...@@ -1,13 +1,13 @@...@@ -1,13 +1,13 @@
1const __fixtfsi = @import("fixtfsi.zig").__fixtfsi;1const __fixtfsi = @import("fixtfsi.zig").__fixtfsi;
2const std = @import("std");2const std = @import("std");
3const math = std.math;3const math = std.math;
4const assert = std.debug.assert;4const testing = std.testing;
5const warn = std.debug.warn;5const warn = std.debug.warn;
66
7fn test__fixtfsi(a: f128, expected: i32) void {7fn test__fixtfsi(a: f128, expected: i32) void {
8 const x = __fixtfsi(a);8 const x = __fixtfsi(a);
9 //warn("a={}:{x} x={}:{x} expected={}:{x}:u32({x})\n", a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u32, expected));9 //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);
11}11}
1212
13test "fixtfsi" {13test "fixtfsi" {
std/special/compiler_rt/fixtfti_test.zig+2-2
...@@ -1,13 +1,13 @@...@@ -1,13 +1,13 @@
1const __fixtfti = @import("fixtfti.zig").__fixtfti;1const __fixtfti = @import("fixtfti.zig").__fixtfti;
2const std = @import("std");2const std = @import("std");
3const math = std.math;3const math = std.math;
4const assert = std.debug.assert;4const testing = std.testing;
5const warn = std.debug.warn;5const warn = std.debug.warn;
66
7fn test__fixtfti(a: f128, expected: i128) void {7fn test__fixtfti(a: f128, expected: i128) void {
8 const x = __fixtfti(a);8 const x = __fixtfti(a);
9 //warn("a={}:{x} x={}:{x} expected={}:{x}:u128({x})\n", a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u128, expected));9 //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);
11}11}
1212
13test "fixtfti" {13test "fixtfti" {
std/special/compiler_rt/fixunsdfdi_test.zig+2-2
...@@ -1,9 +1,9 @@...@@ -1,9 +1,9 @@
1const __fixunsdfdi = @import("fixunsdfdi.zig").__fixunsdfdi;1const __fixunsdfdi = @import("fixunsdfdi.zig").__fixunsdfdi;
2const assert = @import("std").debug.assert;2const testing = @import("std").testing;
33
4fn test__fixunsdfdi(a: f64, expected: u64) void {4fn test__fixunsdfdi(a: f64, expected: u64) void {
5 const x = __fixunsdfdi(a);5 const x = __fixunsdfdi(a);
6 assert(x == expected);6 testing.expect(x == expected);
7}7}
88
9test "fixunsdfdi" {9test "fixunsdfdi" {
std/special/compiler_rt/fixunsdfsi_test.zig+2-2
...@@ -1,9 +1,9 @@...@@ -1,9 +1,9 @@
1const __fixunsdfsi = @import("fixunsdfsi.zig").__fixunsdfsi;1const __fixunsdfsi = @import("fixunsdfsi.zig").__fixunsdfsi;
2const assert = @import("std").debug.assert;2const testing = @import("std").testing;
33
4fn test__fixunsdfsi(a: f64, expected: u32) void {4fn test__fixunsdfsi(a: f64, expected: u32) void {
5 const x = __fixunsdfsi(a);5 const x = __fixunsdfsi(a);
6 assert(x == expected);6 testing.expect(x == expected);
7}7}
88
9test "fixunsdfsi" {9test "fixunsdfsi" {
std/special/compiler_rt/fixunsdfti_test.zig+2-2
...@@ -1,9 +1,9 @@...@@ -1,9 +1,9 @@
1const __fixunsdfti = @import("fixunsdfti.zig").__fixunsdfti;1const __fixunsdfti = @import("fixunsdfti.zig").__fixunsdfti;
2const assert = @import("std").debug.assert;2const testing = @import("std").testing;
33
4fn test__fixunsdfti(a: f64, expected: u128) void {4fn test__fixunsdfti(a: f64, expected: u128) void {
5 const x = __fixunsdfti(a);5 const x = __fixunsdfti(a);
6 assert(x == expected);6 testing.expect(x == expected);
7}7}
88
9test "fixunsdfti" {9test "fixunsdfti" {
std/special/compiler_rt/fixunssfdi_test.zig+2-2
...@@ -1,9 +1,9 @@...@@ -1,9 +1,9 @@
1const __fixunssfdi = @import("fixunssfdi.zig").__fixunssfdi;1const __fixunssfdi = @import("fixunssfdi.zig").__fixunssfdi;
2const assert = @import("std").debug.assert;2const testing = @import("std").testing;
33
4fn test__fixunssfdi(a: f32, expected: u64) void {4fn test__fixunssfdi(a: f32, expected: u64) void {
5 const x = __fixunssfdi(a);5 const x = __fixunssfdi(a);
6 assert(x == expected);6 testing.expect(x == expected);
7}7}
88
9test "fixunssfdi" {9test "fixunssfdi" {
std/special/compiler_rt/fixunssfsi_test.zig+2-2
...@@ -1,9 +1,9 @@...@@ -1,9 +1,9 @@
1const __fixunssfsi = @import("fixunssfsi.zig").__fixunssfsi;1const __fixunssfsi = @import("fixunssfsi.zig").__fixunssfsi;
2const assert = @import("std").debug.assert;2const testing = @import("std").testing;
33
4fn test__fixunssfsi(a: f32, expected: u32) void {4fn test__fixunssfsi(a: f32, expected: u32) void {
5 const x = __fixunssfsi(a);5 const x = __fixunssfsi(a);
6 assert(x == expected);6 testing.expect(x == expected);
7}7}
88
9test "fixunssfsi" {9test "fixunssfsi" {
std/special/compiler_rt/fixunssfti_test.zig+2-2
...@@ -1,9 +1,9 @@...@@ -1,9 +1,9 @@
1const __fixunssfti = @import("fixunssfti.zig").__fixunssfti;1const __fixunssfti = @import("fixunssfti.zig").__fixunssfti;
2const assert = @import("std").debug.assert;2const testing = @import("std").testing;
33
4fn test__fixunssfti(a: f32, expected: u128) void {4fn test__fixunssfti(a: f32, expected: u128) void {
5 const x = __fixunssfti(a);5 const x = __fixunssfti(a);
6 assert(x == expected);6 testing.expect(x == expected);
7}7}
88
9test "fixunssfti" {9test "fixunssfti" {
std/special/compiler_rt/fixunstfdi_test.zig+2-2
...@@ -1,9 +1,9 @@...@@ -1,9 +1,9 @@
1const __fixunstfdi = @import("fixunstfdi.zig").__fixunstfdi;1const __fixunstfdi = @import("fixunstfdi.zig").__fixunstfdi;
2const assert = @import("std").debug.assert;2const testing = @import("std").testing;
33
4fn test__fixunstfdi(a: f128, expected: u64) void {4fn test__fixunstfdi(a: f128, expected: u64) void {
5 const x = __fixunstfdi(a);5 const x = __fixunstfdi(a);
6 assert(x == expected);6 testing.expect(x == expected);
7}7}
88
9test "fixunstfdi" {9test "fixunstfdi" {
std/special/compiler_rt/fixunstfsi_test.zig+2-2
...@@ -1,9 +1,9 @@...@@ -1,9 +1,9 @@
1const __fixunstfsi = @import("fixunstfsi.zig").__fixunstfsi;1const __fixunstfsi = @import("fixunstfsi.zig").__fixunstfsi;
2const assert = @import("std").debug.assert;2const testing = @import("std").testing;
33
4fn test__fixunstfsi(a: f128, expected: u32) void {4fn test__fixunstfsi(a: f128, expected: u32) void {
5 const x = __fixunstfsi(a);5 const x = __fixunstfsi(a);
6 assert(x == expected);6 testing.expect(x == expected);
7}7}
88
9const inf128 = @bitCast(f128, u128(0x7fff0000000000000000000000000000));9const inf128 = @bitCast(f128, u128(0x7fff0000000000000000000000000000));
std/special/compiler_rt/fixunstfti_test.zig+2-2
...@@ -1,9 +1,9 @@...@@ -1,9 +1,9 @@
1const __fixunstfti = @import("fixunstfti.zig").__fixunstfti;1const __fixunstfti = @import("fixunstfti.zig").__fixunstfti;
2const assert = @import("std").debug.assert;2const testing = @import("std").testing;
33
4fn test__fixunstfti(a: f128, expected: u128) void {4fn test__fixunstfti(a: f128, expected: u128) void {
5 const x = __fixunstfti(a);5 const x = __fixunstfti(a);
6 assert(x == expected);6 testing.expect(x == expected);
7}7}
88
9const inf128 = @bitCast(f128, u128(0x7fff0000000000000000000000000000));9const inf128 = @bitCast(f128, u128(0x7fff0000000000000000000000000000));
std/special/compiler_rt/floattidf_test.zig+2-2
...@@ -1,9 +1,9 @@...@@ -1,9 +1,9 @@
1const __floattidf = @import("floattidf.zig").__floattidf;1const __floattidf = @import("floattidf.zig").__floattidf;
2const assert = @import("std").debug.assert;2const testing = @import("std").testing;
33
4fn test__floattidf(a: i128, expected: f64) void {4fn test__floattidf(a: i128, expected: f64) void {
5 const x = __floattidf(a);5 const x = __floattidf(a);
6 assert(x == expected);6 testing.expect(x == expected);
7}7}
88
9test "floattidf" {9test "floattidf" {
std/special/compiler_rt/floattisf_test.zig+2-2
...@@ -1,9 +1,9 @@...@@ -1,9 +1,9 @@
1const __floattisf = @import("floattisf.zig").__floattisf;1const __floattisf = @import("floattisf.zig").__floattisf;
2const assert = @import("std").debug.assert;2const testing = @import("std").testing;
33
4fn test__floattisf(a: i128, expected: f32) void {4fn test__floattisf(a: i128, expected: f32) void {
5 const x = __floattisf(a);5 const x = __floattisf(a);
6 assert(x == expected);6 testing.expect(x == expected);
7}7}
88
9test "floattisf" {9test "floattisf" {
std/special/compiler_rt/floattitf_test.zig+2-2
...@@ -1,9 +1,9 @@...@@ -1,9 +1,9 @@
1const __floattitf = @import("floattitf.zig").__floattitf;1const __floattitf = @import("floattitf.zig").__floattitf;
2const assert = @import("std").debug.assert;2const testing = @import("std").testing;
33
4fn test__floattitf(a: i128, expected: f128) void {4fn test__floattitf(a: i128, expected: f128) void {
5 const x = __floattitf(a);5 const x = __floattitf(a);
6 assert(x == expected);6 testing.expect(x == expected);
7}7}
88
9test "floattitf" {9test "floattitf" {
std/special/compiler_rt/floatunditf_test.zig-1
...@@ -1,5 +1,4 @@...@@ -1,5 +1,4 @@
1const __floatunditf = @import("floatunditf.zig").__floatunditf;1const __floatunditf = @import("floatunditf.zig").__floatunditf;
2const assert = @import("std").debug.assert;
32
4fn test__floatunditf(a: u128, expected_hi: u64, expected_lo: u64) void {3fn test__floatunditf(a: u128, expected_hi: u64, expected_lo: u64) void {
5 const x = __floatunditf(a);4 const x = __floatunditf(a);
std/special/compiler_rt/floatunsitf_test.zig-1
...@@ -1,5 +1,4 @@...@@ -1,5 +1,4 @@
1const __floatunsitf = @import("floatunsitf.zig").__floatunsitf;1const __floatunsitf = @import("floatunsitf.zig").__floatunsitf;
2const assert = @import("std").debug.assert;
32
4fn test__floatunsitf(a: u64, expected_hi: u64, expected_lo: u64) void {3fn test__floatunsitf(a: u64, expected_hi: u64, expected_lo: u64) void {
5 const x = __floatunsitf(a);4 const x = __floatunsitf(a);
std/special/compiler_rt/floatuntidf_test.zig+2-2
...@@ -1,9 +1,9 @@...@@ -1,9 +1,9 @@
1const __floatuntidf = @import("floatuntidf.zig").__floatuntidf;1const __floatuntidf = @import("floatuntidf.zig").__floatuntidf;
2const assert = @import("std").debug.assert;2const testing = @import("std").testing;
33
4fn test__floatuntidf(a: u128, expected: f64) void {4fn test__floatuntidf(a: u128, expected: f64) void {
5 const x = __floatuntidf(a);5 const x = __floatuntidf(a);
6 assert(x == expected);6 testing.expect(x == expected);
7}7}
88
9test "floatuntidf" {9test "floatuntidf" {
std/special/compiler_rt/floatuntisf_test.zig+2-2
...@@ -1,9 +1,9 @@...@@ -1,9 +1,9 @@
1const __floatuntisf = @import("floatuntisf.zig").__floatuntisf;1const __floatuntisf = @import("floatuntisf.zig").__floatuntisf;
2const assert = @import("std").debug.assert;2const testing = @import("std").testing;
33
4fn test__floatuntisf(a: u128, expected: f32) void {4fn test__floatuntisf(a: u128, expected: f32) void {
5 const x = __floatuntisf(a);5 const x = __floatuntisf(a);
6 assert(x == expected);6 testing.expect(x == expected);
7}7}
88
9test "floatuntisf" {9test "floatuntisf" {
std/special/compiler_rt/floatuntitf_test.zig+2-2
...@@ -1,9 +1,9 @@...@@ -1,9 +1,9 @@
1const __floatuntitf = @import("floatuntitf.zig").__floatuntitf;1const __floatuntitf = @import("floatuntitf.zig").__floatuntitf;
2const assert = @import("std").debug.assert;2const testing = @import("std").testing;
33
4fn test__floatuntitf(a: u128, expected: f128) void {4fn test__floatuntitf(a: u128, expected: f128) void {
5 const x = __floatuntitf(a);5 const x = __floatuntitf(a);
6 assert(x == expected);6 testing.expect(x == expected);
7}7}
88
9test "floatuntitf" {9test "floatuntitf" {
std/special/compiler_rt/index.zig+3-2
...@@ -110,6 +110,7 @@ comptime {...@@ -110,6 +110,7 @@ comptime {
110110
111const std = @import("std");111const std = @import("std");
112const assert = std.debug.assert;112const assert = std.debug.assert;
113const testing = std.testing;
113114
114const __udivmoddi4 = @import("udivmoddi4.zig").__udivmoddi4;115const __udivmoddi4 = @import("udivmoddi4.zig").__udivmoddi4;
115116
...@@ -417,7 +418,7 @@ test "test_umoddi3" {...@@ -417,7 +418,7 @@ test "test_umoddi3" {
417418
418fn test_one_umoddi3(a: u64, b: u64, expected_r: u64) void {419fn test_one_umoddi3(a: u64, b: u64, expected_r: u64) void {
419 const r = __umoddi3(a, b);420 const r = __umoddi3(a, b);
420 assert(r == expected_r);421 testing.expect(r == expected_r);
421}422}
422423
423test "test_udivsi3" {424test "test_udivsi3" {
...@@ -1091,5 +1092,5 @@ test "test_udivsi3" {...@@ -1091,5 +1092,5 @@ test "test_udivsi3" {
10911092
1092fn test_one_udivsi3(a: u32, b: u32, expected_q: u32) void {1093fn test_one_udivsi3(a: u32, b: u32, expected_q: u32) void {
1093 const q: u32 = __udivsi3(a, b);1094 const q: u32 = __udivsi3(a, b);
1094 assert(q == expected_q);1095 testing.expect(q == expected_q);
1095}1096}
std/special/compiler_rt/muloti4_test.zig+2-2
...@@ -1,10 +1,10 @@...@@ -1,10 +1,10 @@
1const __muloti4 = @import("muloti4.zig").__muloti4;1const __muloti4 = @import("muloti4.zig").__muloti4;
2const assert = @import("std").debug.assert;2const testing = @import("std").testing;
33
4fn test__muloti4(a: i128, b: i128, expected: i128, expected_overflow: c_int) void {4fn test__muloti4(a: i128, b: i128, expected: i128, expected_overflow: c_int) void {
5 var overflow: c_int = undefined;5 var overflow: c_int = undefined;
6 const x = __muloti4(a, b, &overflow);6 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));
8}8}
99
10test "muloti4" {10test "muloti4" {
std/special/compiler_rt/multi3_test.zig+2-2
...@@ -1,9 +1,9 @@...@@ -1,9 +1,9 @@
1const __multi3 = @import("multi3.zig").__multi3;1const __multi3 = @import("multi3.zig").__multi3;
2const assert = @import("std").debug.assert;2const testing = @import("std").testing;
33
4fn test__multi3(a: i128, b: i128, expected: i128) void {4fn test__multi3(a: i128, b: i128, expected: i128) void {
5 const x = __multi3(a, b);5 const x = __multi3(a, b);
6 assert(x == expected);6 testing.expect(x == expected);
7}7}
88
9test "multi3" {9test "multi3" {
std/special/compiler_rt/udivmoddi4_test.zig+3-3
...@@ -1,13 +1,13 @@...@@ -1,13 +1,13 @@
1// Disable formatting to avoid unnecessary source repository bloat.1// Disable formatting to avoid unnecessary source repository bloat.
2// zig fmt: off2// zig fmt: off
3const __udivmoddi4 = @import("udivmoddi4.zig").__udivmoddi4;3const __udivmoddi4 = @import("udivmoddi4.zig").__udivmoddi4;
4const assert = @import("std").debug.assert;4const testing = @import("std").testing;
55
6fn test__udivmoddi4(a: u64, b: u64, expected_q: u64, expected_r: u64) void {6fn test__udivmoddi4(a: u64, b: u64, expected_q: u64, expected_r: u64) void {
7 var r: u64 = undefined;7 var r: u64 = undefined;
8 const q = __udivmoddi4(a, b, &r);8 const q = __udivmoddi4(a, b, &r);
9 assert(q == expected_q);9 testing.expect(q == expected_q);
10 assert(r == expected_r);10 testing.expect(r == expected_r);
11}11}
1212
13test "udivmoddi4" {13test "udivmoddi4" {
std/special/compiler_rt/udivmodti4_test.zig+3-3
...@@ -1,13 +1,13 @@...@@ -1,13 +1,13 @@
1// Disable formatting to avoid unnecessary source repository bloat.1// Disable formatting to avoid unnecessary source repository bloat.
2// zig fmt: off2// zig fmt: off
3const __udivmodti4 = @import("udivmodti4.zig").__udivmodti4;3const __udivmodti4 = @import("udivmodti4.zig").__udivmodti4;
4const assert = @import("std").debug.assert;4const testing = @import("std").testing;
55
6fn test__udivmodti4(a: u128, b: u128, expected_q: u128, expected_r: u128) void {6fn test__udivmodti4(a: u128, b: u128, expected_q: u128, expected_r: u128) void {
7 var r: u128 = undefined;7 var r: u128 = undefined;
8 const q = __udivmodti4(a, b, &r);8 const q = __udivmodti4(a, b, &r);
9 assert(q == expected_q);9 testing.expect(q == expected_q);
10 assert(r == expected_r);10 testing.expect(r == expected_r);
11}11}
1212
13test "udivmodti4" {13test "udivmodti4" {
std/special/init-lib/src/main.zig+2-2
...@@ -1,10 +1,10 @@...@@ -1,10 +1,10 @@
1const std = @import("std");1const std = @import("std");
2const assertOrPanic = std.debug.assertOrPanic;2const testing = std.testing;
33
4export fn add(a: i32, b: i32) i32 {4export fn add(a: i32, b: i32) i32 {
5 return a + b;5 return a + b;
6}6}
77
8test "basic add functionality" {8test "basic add functionality" {
9 assertOrPanic(add(3, 7) == 10);9 testing.expect(add(3, 7) == 10);
10}10}
std/statically_initialized_mutex.zig+3-2
...@@ -3,6 +3,7 @@ const builtin = @import("builtin");...@@ -3,6 +3,7 @@ const builtin = @import("builtin");
3const AtomicOrder = builtin.AtomicOrder;3const AtomicOrder = builtin.AtomicOrder;
4const AtomicRmwOp = builtin.AtomicRmwOp;4const AtomicRmwOp = builtin.AtomicRmwOp;
5const assert = std.debug.assert;5const assert = std.debug.assert;
6const expect = std.testing.expect;
6const windows = std.os.windows;7const windows = std.os.windows;
78
8/// Lock may be held only once. If the same thread9/// Lock may be held only once. If the same thread
...@@ -95,7 +96,7 @@ test "std.StaticallyInitializedMutex" {...@@ -95,7 +96,7 @@ test "std.StaticallyInitializedMutex" {
9596
96 if (builtin.single_threaded) {97 if (builtin.single_threaded) {
97 TestContext.worker(&context);98 TestContext.worker(&context);
98 std.debug.assertOrPanic(context.data == TestContext.incr_count);99 expect(context.data == TestContext.incr_count);
99 } else {100 } else {
100 const thread_count = 10;101 const thread_count = 10;
101 var threads: [thread_count]*std.os.Thread = undefined;102 var threads: [thread_count]*std.os.Thread = undefined;
...@@ -105,6 +106,6 @@ test "std.StaticallyInitializedMutex" {...@@ -105,6 +106,6 @@ test "std.StaticallyInitializedMutex" {
105 for (threads) |t|106 for (threads) |t|
106 t.wait();107 t.wait();
107108
108 std.debug.assertOrPanic(context.data == thread_count * TestContext.incr_count);109 expect(context.data == thread_count * TestContext.incr_count);
109 }110 }
110}111}
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 @@...@@ -1,7 +1,7 @@
1const std = @import("./index.zig");1const std = @import("./index.zig");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const debug = std.debug;
4const assert = std.debug.assert;3const assert = std.debug.assert;
4const testing = std.testing;
5const mem = std.mem;5const mem = std.mem;
66
7/// Returns how many bytes the UTF-8 representation would require7/// Returns how many bytes the UTF-8 representation would require
...@@ -32,7 +32,7 @@ pub fn utf8ByteSequenceLength(first_byte: u8) !u3 {...@@ -32,7 +32,7 @@ pub fn utf8ByteSequenceLength(first_byte: u8) !u3 {
32/// Returns: the number of bytes written to out.32/// Returns: the number of bytes written to out.
33pub fn utf8Encode(c: u32, out: []u8) !u3 {33pub fn utf8Encode(c: u32, out: []u8) !u3 {
34 const length = try utf8CodepointSequenceLength(c);34 const length = try utf8CodepointSequenceLength(c);
35 debug.assert(out.len >= length);35 assert(out.len >= length);
36 switch (length) {36 switch (length) {
37 // The pattern for each is the same37 // The pattern for each is the same
38 // - Increasing the initial shift by 6 each time38 // - Increasing the initial shift by 6 each time
...@@ -81,8 +81,8 @@ const Utf8Decode2Error = error{...@@ -81,8 +81,8 @@ const Utf8Decode2Error = error{
81 Utf8OverlongEncoding,81 Utf8OverlongEncoding,
82};82};
83pub fn utf8Decode2(bytes: []const u8) Utf8Decode2Error!u32 {83pub fn utf8Decode2(bytes: []const u8) Utf8Decode2Error!u32 {
84 debug.assert(bytes.len == 2);84 assert(bytes.len == 2);
85 debug.assert(bytes[0] & 0b11100000 == 0b11000000);85 assert(bytes[0] & 0b11100000 == 0b11000000);
86 var value: u32 = bytes[0] & 0b00011111;86 var value: u32 = bytes[0] & 0b00011111;
8787
88 if (bytes[1] & 0b11000000 != 0b10000000) return error.Utf8ExpectedContinuation;88 if (bytes[1] & 0b11000000 != 0b10000000) return error.Utf8ExpectedContinuation;
...@@ -100,8 +100,8 @@ const Utf8Decode3Error = error{...@@ -100,8 +100,8 @@ const Utf8Decode3Error = error{
100 Utf8EncodesSurrogateHalf,100 Utf8EncodesSurrogateHalf,
101};101};
102pub fn utf8Decode3(bytes: []const u8) Utf8Decode3Error!u32 {102pub fn utf8Decode3(bytes: []const u8) Utf8Decode3Error!u32 {
103 debug.assert(bytes.len == 3);103 assert(bytes.len == 3);
104 debug.assert(bytes[0] & 0b11110000 == 0b11100000);104 assert(bytes[0] & 0b11110000 == 0b11100000);
105 var value: u32 = bytes[0] & 0b00001111;105 var value: u32 = bytes[0] & 0b00001111;
106106
107 if (bytes[1] & 0b11000000 != 0b10000000) return error.Utf8ExpectedContinuation;107 if (bytes[1] & 0b11000000 != 0b10000000) return error.Utf8ExpectedContinuation;
...@@ -124,8 +124,8 @@ const Utf8Decode4Error = error{...@@ -124,8 +124,8 @@ const Utf8Decode4Error = error{
124 Utf8CodepointTooLarge,124 Utf8CodepointTooLarge,
125};125};
126pub fn utf8Decode4(bytes: []const u8) Utf8Decode4Error!u32 {126pub fn utf8Decode4(bytes: []const u8) Utf8Decode4Error!u32 {
127 debug.assert(bytes.len == 4);127 assert(bytes.len == 4);
128 debug.assert(bytes[0] & 0b11111000 == 0b11110000);128 assert(bytes[0] & 0b11111000 == 0b11110000);
129 var value: u32 = bytes[0] & 0b00000111;129 var value: u32 = bytes[0] & 0b00000111;
130130
131 if (bytes[1] & 0b11000000 != 0b10000000) return error.Utf8ExpectedContinuation;131 if (bytes[1] & 0b11000000 != 0b10000000) return error.Utf8ExpectedContinuation;
...@@ -274,23 +274,23 @@ test "utf8 encode" {...@@ -274,23 +274,23 @@ test "utf8 encode" {
274fn testUtf8Encode() !void {274fn testUtf8Encode() !void {
275 // A few taken from wikipedia a few taken elsewhere275 // A few taken from wikipedia a few taken elsewhere
276 var array: [4]u8 = undefined;276 var array: [4]u8 = undefined;
277 debug.assert((try utf8Encode(try utf8Decode("€"), array[0..])) == 3);277 testing.expect((try utf8Encode(try utf8Decode("€"), array[0..])) == 3);
278 debug.assert(array[0] == 0b11100010);278 testing.expect(array[0] == 0b11100010);
279 debug.assert(array[1] == 0b10000010);279 testing.expect(array[1] == 0b10000010);
280 debug.assert(array[2] == 0b10101100);280 testing.expect(array[2] == 0b10101100);
281281
282 debug.assert((try utf8Encode(try utf8Decode("$"), array[0..])) == 1);282 testing.expect((try utf8Encode(try utf8Decode("$"), array[0..])) == 1);
283 debug.assert(array[0] == 0b00100100);283 testing.expect(array[0] == 0b00100100);
284284
285 debug.assert((try utf8Encode(try utf8Decode("¢"), array[0..])) == 2);285 testing.expect((try utf8Encode(try utf8Decode("¢"), array[0..])) == 2);
286 debug.assert(array[0] == 0b11000010);286 testing.expect(array[0] == 0b11000010);
287 debug.assert(array[1] == 0b10100010);287 testing.expect(array[1] == 0b10100010);
288288
289 debug.assert((try utf8Encode(try utf8Decode("𐍈"), array[0..])) == 4);289 testing.expect((try utf8Encode(try utf8Decode("𐍈"), array[0..])) == 4);
290 debug.assert(array[0] == 0b11110000);290 testing.expect(array[0] == 0b11110000);
291 debug.assert(array[1] == 0b10010000);291 testing.expect(array[1] == 0b10010000);
292 debug.assert(array[2] == 0b10001101);292 testing.expect(array[2] == 0b10001101);
293 debug.assert(array[3] == 0b10001000);293 testing.expect(array[3] == 0b10001000);
294}294}
295295
296test "utf8 encode error" {296test "utf8 encode error" {
...@@ -306,11 +306,7 @@ fn testUtf8EncodeError() void {...@@ -306,11 +306,7 @@ fn testUtf8EncodeError() void {
306}306}
307307
308fn testErrorEncode(codePoint: u32, array: []u8, expectedErr: anyerror) void {308fn testErrorEncode(codePoint: u32, array: []u8, expectedErr: anyerror) void {
309 if (utf8Encode(codePoint, array)) |_| {309 testing.expectError(expectedErr, utf8Encode(codePoint, array));
310 unreachable;
311 } else |err| {
312 debug.assert(err == expectedErr);
313 }
314}310}
315311
316test "utf8 iterator on ascii" {312test "utf8 iterator on ascii" {
...@@ -321,16 +317,16 @@ fn testUtf8IteratorOnAscii() void {...@@ -321,16 +317,16 @@ fn testUtf8IteratorOnAscii() void {
321 const s = Utf8View.initComptime("abc");317 const s = Utf8View.initComptime("abc");
322318
323 var it1 = s.iterator();319 var it1 = s.iterator();
324 debug.assert(std.mem.eql(u8, "a", it1.nextCodepointSlice().?));320 testing.expect(std.mem.eql(u8, "a", it1.nextCodepointSlice().?));
325 debug.assert(std.mem.eql(u8, "b", it1.nextCodepointSlice().?));321 testing.expect(std.mem.eql(u8, "b", it1.nextCodepointSlice().?));
326 debug.assert(std.mem.eql(u8, "c", it1.nextCodepointSlice().?));322 testing.expect(std.mem.eql(u8, "c", it1.nextCodepointSlice().?));
327 debug.assert(it1.nextCodepointSlice() == null);323 testing.expect(it1.nextCodepointSlice() == null);
328324
329 var it2 = s.iterator();325 var it2 = s.iterator();
330 debug.assert(it2.nextCodepoint().? == 'a');326 testing.expect(it2.nextCodepoint().? == 'a');
331 debug.assert(it2.nextCodepoint().? == 'b');327 testing.expect(it2.nextCodepoint().? == 'b');
332 debug.assert(it2.nextCodepoint().? == 'c');328 testing.expect(it2.nextCodepoint().? == 'c');
333 debug.assert(it2.nextCodepoint() == null);329 testing.expect(it2.nextCodepoint() == null);
334}330}
335331
336test "utf8 view bad" {332test "utf8 view bad" {
...@@ -340,12 +336,7 @@ test "utf8 view bad" {...@@ -340,12 +336,7 @@ test "utf8 view bad" {
340fn testUtf8ViewBad() void {336fn testUtf8ViewBad() void {
341 // Compile-time error.337 // Compile-time error.
342 // const s3 = Utf8View.initComptime("\xfe\xf2");338 // const s3 = Utf8View.initComptime("\xfe\xf2");
343 const s = Utf8View.init("hel\xadlo");339 testing.expectError(error.InvalidUtf8, Utf8View.init("hel\xadlo"));
344 if (s) |_| {
345 unreachable;
346 } else |err| {
347 debug.assert(err == error.InvalidUtf8);
348 }
349}340}
350341
351test "utf8 view ok" {342test "utf8 view ok" {
...@@ -356,16 +347,16 @@ fn testUtf8ViewOk() void {...@@ -356,16 +347,16 @@ fn testUtf8ViewOk() void {
356 const s = Utf8View.initComptime("東京市");347 const s = Utf8View.initComptime("東京市");
357348
358 var it1 = s.iterator();349 var it1 = s.iterator();
359 debug.assert(std.mem.eql(u8, "東", it1.nextCodepointSlice().?));350 testing.expect(std.mem.eql(u8, "東", it1.nextCodepointSlice().?));
360 debug.assert(std.mem.eql(u8, "京", it1.nextCodepointSlice().?));351 testing.expect(std.mem.eql(u8, "京", it1.nextCodepointSlice().?));
361 debug.assert(std.mem.eql(u8, "市", it1.nextCodepointSlice().?));352 testing.expect(std.mem.eql(u8, "市", it1.nextCodepointSlice().?));
362 debug.assert(it1.nextCodepointSlice() == null);353 testing.expect(it1.nextCodepointSlice() == null);
363354
364 var it2 = s.iterator();355 var it2 = s.iterator();
365 debug.assert(it2.nextCodepoint().? == 0x6771);356 testing.expect(it2.nextCodepoint().? == 0x6771);
366 debug.assert(it2.nextCodepoint().? == 0x4eac);357 testing.expect(it2.nextCodepoint().? == 0x4eac);
367 debug.assert(it2.nextCodepoint().? == 0x5e02);358 testing.expect(it2.nextCodepoint().? == 0x5e02);
368 debug.assert(it2.nextCodepoint() == null);359 testing.expect(it2.nextCodepoint() == null);
369}360}
370361
371test "bad utf8 slice" {362test "bad utf8 slice" {
...@@ -373,10 +364,10 @@ test "bad utf8 slice" {...@@ -373,10 +364,10 @@ test "bad utf8 slice" {
373 testBadUtf8Slice();364 testBadUtf8Slice();
374}365}
375fn testBadUtf8Slice() void {366fn testBadUtf8Slice() void {
376 debug.assert(utf8ValidateSlice("abc"));367 testing.expect(utf8ValidateSlice("abc"));
377 debug.assert(!utf8ValidateSlice("abc\xc0"));368 testing.expect(!utf8ValidateSlice("abc\xc0"));
378 debug.assert(!utf8ValidateSlice("abc\xc0abc"));369 testing.expect(!utf8ValidateSlice("abc\xc0abc"));
379 debug.assert(utf8ValidateSlice("abc\xdf\xbf"));370 testing.expect(utf8ValidateSlice("abc\xdf\xbf"));
380}371}
381372
382test "valid utf8" {373test "valid utf8" {
...@@ -459,21 +450,17 @@ fn testMiscInvalidUtf8() void {...@@ -459,21 +450,17 @@ fn testMiscInvalidUtf8() void {
459}450}
460451
461fn testError(bytes: []const u8, expected_err: anyerror) void {452fn testError(bytes: []const u8, expected_err: anyerror) void {
462 if (testDecode(bytes)) |_| {453 testing.expectError(expected_err, testDecode(bytes));
463 unreachable;
464 } else |err| {
465 debug.assert(err == expected_err);
466 }
467}454}
468455
469fn testValid(bytes: []const u8, expected_codepoint: u32) void {456fn 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);
471}458}
472459
473fn testDecode(bytes: []const u8) !u32 {460fn testDecode(bytes: []const u8) !u32 {
474 const length = try utf8ByteSequenceLength(bytes[0]);461 const length = try utf8ByteSequenceLength(bytes[0]);
475 if (bytes.len < length) return error.UnexpectedEof;462 if (bytes.len < length) return error.UnexpectedEof;
476 debug.assert(bytes.len == length);463 testing.expect(bytes.len == length);
477 return utf8Decode(bytes);464 return utf8Decode(bytes);
478}465}
479466
...@@ -513,14 +500,14 @@ test "utf16leToUtf8" {...@@ -513,14 +500,14 @@ test "utf16leToUtf8" {
513 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 'A');500 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 'A');
514 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 'a');501 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 'a');
515 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le);502 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le);
516 assert(mem.eql(u8, utf8, "Aa"));503 testing.expect(mem.eql(u8, utf8, "Aa"));
517 }504 }
518505
519 {506 {
520 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0x80);507 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0x80);
521 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xffff);508 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xffff);
522 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le);509 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"));
524 }511 }
525512
526 {513 {
...@@ -528,7 +515,7 @@ test "utf16leToUtf8" {...@@ -528,7 +515,7 @@ test "utf16leToUtf8" {
528 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xd7ff);515 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xd7ff);
529 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xe000);516 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xe000);
530 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le);517 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"));
532 }519 }
533520
534 {521 {
...@@ -536,7 +523,7 @@ test "utf16leToUtf8" {...@@ -536,7 +523,7 @@ test "utf16leToUtf8" {
536 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xd800);523 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xd800);
537 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdc00);524 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdc00);
538 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le);525 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"));
540 }527 }
541528
542 {529 {
...@@ -544,14 +531,14 @@ test "utf16leToUtf8" {...@@ -544,14 +531,14 @@ test "utf16leToUtf8" {
544 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xdbff);531 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xdbff);
545 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdfff);532 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdfff);
546 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le);533 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"));
548 }535 }
549536
550 {537 {
551 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xdbff);538 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xdbff);
552 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdc00);539 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdc00);
553 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le);540 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"));
555 }542 }
556}543}
557544
std/zig/ast.zig+8-1
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1const std = @import("../index.zig");1const std = @import("../index.zig");
2const assert = std.debug.assert;2const assert = std.debug.assert;
3const testing = std.testing;
3const SegmentedList = std.SegmentedList;4const SegmentedList = std.SegmentedList;
4const mem = std.mem;5const mem = std.mem;
5const Token = std.zig.Token;6const Token = std.zig.Token;
...@@ -109,6 +110,7 @@ pub const Tree = struct {...@@ -109,6 +110,7 @@ pub const Tree = struct {
109pub const Error = union(enum) {110pub const Error = union(enum) {
110 InvalidToken: InvalidToken,111 InvalidToken: InvalidToken,
111 ExpectedVarDeclOrFn: ExpectedVarDeclOrFn,112 ExpectedVarDeclOrFn: ExpectedVarDeclOrFn,
113 ExpectedVarDecl: ExpectedVarDecl,
112 ExpectedAggregateKw: ExpectedAggregateKw,114 ExpectedAggregateKw: ExpectedAggregateKw,
113 UnattachedDocComment: UnattachedDocComment,115 UnattachedDocComment: UnattachedDocComment,
114 ExpectedEqOrSemi: ExpectedEqOrSemi,116 ExpectedEqOrSemi: ExpectedEqOrSemi,
...@@ -132,6 +134,7 @@ pub const Error = union(enum) {...@@ -132,6 +134,7 @@ pub const Error = union(enum) {
132 // TODO https://github.com/ziglang/zig/issues/683134 // TODO https://github.com/ziglang/zig/issues/683
133 @TagType(Error).InvalidToken => |*x| return x.render(tokens, stream),135 @TagType(Error).InvalidToken => |*x| return x.render(tokens, stream),
134 @TagType(Error).ExpectedVarDeclOrFn => |*x| return x.render(tokens, stream),136 @TagType(Error).ExpectedVarDeclOrFn => |*x| return x.render(tokens, stream),
137 @TagType(Error).ExpectedVarDecl => |*x| return x.render(tokens, stream),
135 @TagType(Error).ExpectedAggregateKw => |*x| return x.render(tokens, stream),138 @TagType(Error).ExpectedAggregateKw => |*x| return x.render(tokens, stream),
136 @TagType(Error).UnattachedDocComment => |*x| return x.render(tokens, stream),139 @TagType(Error).UnattachedDocComment => |*x| return x.render(tokens, stream),
137 @TagType(Error).ExpectedEqOrSemi => |*x| return x.render(tokens, stream),140 @TagType(Error).ExpectedEqOrSemi => |*x| return x.render(tokens, stream),
...@@ -157,6 +160,7 @@ pub const Error = union(enum) {...@@ -157,6 +160,7 @@ pub const Error = union(enum) {
157 // TODO https://github.com/ziglang/zig/issues/683160 // TODO https://github.com/ziglang/zig/issues/683
158 @TagType(Error).InvalidToken => |x| return x.token,161 @TagType(Error).InvalidToken => |x| return x.token,
159 @TagType(Error).ExpectedVarDeclOrFn => |x| return x.token,162 @TagType(Error).ExpectedVarDeclOrFn => |x| return x.token,
163 @TagType(Error).ExpectedVarDecl => |x| return x.token,
160 @TagType(Error).ExpectedAggregateKw => |x| return x.token,164 @TagType(Error).ExpectedAggregateKw => |x| return x.token,
161 @TagType(Error).UnattachedDocComment => |x| return x.token,165 @TagType(Error).UnattachedDocComment => |x| return x.token,
162 @TagType(Error).ExpectedEqOrSemi => |x| return x.token,166 @TagType(Error).ExpectedEqOrSemi => |x| return x.token,
...@@ -179,6 +183,7 @@ pub const Error = union(enum) {...@@ -179,6 +183,7 @@ pub const Error = union(enum) {
179183
180 pub const InvalidToken = SingleTokenError("Invalid token {}");184 pub const InvalidToken = SingleTokenError("Invalid token {}");
181 pub const ExpectedVarDeclOrFn = SingleTokenError("Expected variable declaration or function, found {}");185 pub const ExpectedVarDeclOrFn = SingleTokenError("Expected variable declaration or function, found {}");
186 pub const ExpectedVarDecl = SingleTokenError("Expected variable declaration, found {}");
182 pub const ExpectedAggregateKw = SingleTokenError("Expected " ++ @tagName(Token.Id.Keyword_struct) ++ ", " ++ @tagName(Token.Id.Keyword_union) ++ ", or " ++ @tagName(Token.Id.Keyword_enum) ++ ", found {}");187 pub const ExpectedAggregateKw = SingleTokenError("Expected " ++ @tagName(Token.Id.Keyword_struct) ++ ", " ++ @tagName(Token.Id.Keyword_union) ++ ", or " ++ @tagName(Token.Id.Keyword_enum) ++ ", found {}");
183 pub const ExpectedEqOrSemi = SingleTokenError("Expected '=' or ';', found {}");188 pub const ExpectedEqOrSemi = SingleTokenError("Expected '=' or ';', found {}");
184 pub const ExpectedSemiOrLBrace = SingleTokenError("Expected ';' or '{{', found {}");189 pub const ExpectedSemiOrLBrace = SingleTokenError("Expected ';' or '{{', found {}");
...@@ -495,6 +500,7 @@ pub const Node = struct {...@@ -495,6 +500,7 @@ pub const Node = struct {
495 base: Node,500 base: Node,
496 doc_comments: ?*DocComment,501 doc_comments: ?*DocComment,
497 visib_token: ?TokenIndex,502 visib_token: ?TokenIndex,
503 thread_local_token: ?TokenIndex,
498 name_token: TokenIndex,504 name_token: TokenIndex,
499 eq_token: TokenIndex,505 eq_token: TokenIndex,
500 mut_token: TokenIndex,506 mut_token: TokenIndex,
...@@ -535,6 +541,7 @@ pub const Node = struct {...@@ -535,6 +541,7 @@ pub const Node = struct {
535541
536 pub fn firstToken(self: *const VarDecl) TokenIndex {542 pub fn firstToken(self: *const VarDecl) TokenIndex {
537 if (self.visib_token) |visib_token| return visib_token;543 if (self.visib_token) |visib_token| return visib_token;
544 if (self.thread_local_token) |thread_local_token| return thread_local_token;
538 if (self.comptime_token) |comptime_token| return comptime_token;545 if (self.comptime_token) |comptime_token| return comptime_token;
539 if (self.extern_export_token) |extern_export_token| return extern_export_token;546 if (self.extern_export_token) |extern_export_token| return extern_export_token;
540 assert(self.lib_name == null);547 assert(self.lib_name == null);
...@@ -2224,5 +2231,5 @@ test "iterate" {...@@ -2224,5 +2231,5 @@ test "iterate" {
2224 .shebang = null,2231 .shebang = null,
2225 };2232 };
2226 var base = &root.base;2233 var base = &root.base;
2227 assert(base.iterate(0) == null);2234 testing.expect(base.iterate(0) == null);
2228}2235}
std/zig/parse.zig+54
...@@ -229,6 +229,32 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -229,6 +229,32 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
229 }) catch unreachable;229 }) catch unreachable;
230 continue;230 continue;
231 },231 },
232 State.ThreadLocal => |ctx| {
233 const token = nextToken(&tok_it, &tree);
234 const token_index = token.index;
235 const token_ptr = token.ptr;
236 switch (token_ptr.id) {
237 Token.Id.Keyword_var, Token.Id.Keyword_const => {
238 try stack.append(State{
239 .VarDecl = VarDeclCtx{
240 .comments = ctx.comments,
241 .visib_token = ctx.visib_token,
242 .thread_local_token = ctx.thread_local_token,
243 .lib_name = ctx.lib_name,
244 .comptime_token = ctx.comptime_token,
245 .extern_export_token = ctx.extern_export_token,
246 .mut_token = token_index,
247 .list = ctx.list,
248 },
249 });
250 continue;
251 },
252 else => {
253 ((try tree.errors.addOne())).* = Error{ .ExpectedVarDecl = Error.ExpectedVarDecl{ .token = token_index } };
254 return tree;
255 },
256 }
257 },
232 State.TopLevelDecl => |ctx| {258 State.TopLevelDecl => |ctx| {
233 const token = nextToken(&tok_it, &tree);259 const token = nextToken(&tok_it, &tree);
234 const token_index = token.index;260 const token_index = token.index;
...@@ -260,6 +286,28 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -260,6 +286,28 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
260 try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.expr } });286 try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.expr } });
261 continue;287 continue;
262 },288 },
289 Token.Id.Keyword_threadlocal => {
290 if (ctx.extern_export_inline_token) |annotated_token| {
291 if (annotated_token.ptr.id == Token.Id.Keyword_inline) {
292 ((try tree.errors.addOne())).* = Error{ .InvalidToken = Error.InvalidToken{ .token = annotated_token.index } };
293 return tree;
294 }
295 }
296
297 try stack.append(State{
298 .ThreadLocal = VarDeclCtx{
299 .comments = ctx.comments,
300 .visib_token = ctx.visib_token,
301 .thread_local_token = token_index,
302 .lib_name = ctx.lib_name,
303 .comptime_token = null,
304 .extern_export_token = if (ctx.extern_export_inline_token) |at| at.index else null,
305 .mut_token = undefined,
306 .list = ctx.decls,
307 },
308 });
309 continue;
310 },
263 Token.Id.Keyword_var, Token.Id.Keyword_const => {311 Token.Id.Keyword_var, Token.Id.Keyword_const => {
264 if (ctx.extern_export_inline_token) |annotated_token| {312 if (ctx.extern_export_inline_token) |annotated_token| {
265 if (annotated_token.ptr.id == Token.Id.Keyword_inline) {313 if (annotated_token.ptr.id == Token.Id.Keyword_inline) {
...@@ -272,6 +320,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -272,6 +320,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
272 .VarDecl = VarDeclCtx{320 .VarDecl = VarDeclCtx{
273 .comments = ctx.comments,321 .comments = ctx.comments,
274 .visib_token = ctx.visib_token,322 .visib_token = ctx.visib_token,
323 .thread_local_token = null,
275 .lib_name = ctx.lib_name,324 .lib_name = ctx.lib_name,
276 .comptime_token = null,325 .comptime_token = null,
277 .extern_export_token = if (ctx.extern_export_inline_token) |at| at.index else null,326 .extern_export_token = if (ctx.extern_export_inline_token) |at| at.index else null,
...@@ -611,6 +660,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -611,6 +660,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
611 .base = ast.Node{ .id = ast.Node.Id.VarDecl },660 .base = ast.Node{ .id = ast.Node.Id.VarDecl },
612 .doc_comments = ctx.comments,661 .doc_comments = ctx.comments,
613 .visib_token = ctx.visib_token,662 .visib_token = ctx.visib_token,
663 .thread_local_token = ctx.thread_local_token,
614 .mut_token = ctx.mut_token,664 .mut_token = ctx.mut_token,
615 .comptime_token = ctx.comptime_token,665 .comptime_token = ctx.comptime_token,
616 .extern_export_token = ctx.extern_export_token,666 .extern_export_token = ctx.extern_export_token,
...@@ -1094,6 +1144,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -1094,6 +1144,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
1094 .VarDecl = VarDeclCtx{1144 .VarDecl = VarDeclCtx{
1095 .comments = null,1145 .comments = null,
1096 .visib_token = null,1146 .visib_token = null,
1147 .thread_local_token = null,
1097 .comptime_token = null,1148 .comptime_token = null,
1098 .extern_export_token = null,1149 .extern_export_token = null,
1099 .lib_name = null,1150 .lib_name = null,
...@@ -1150,6 +1201,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -1150,6 +1201,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
1150 .VarDecl = VarDeclCtx{1201 .VarDecl = VarDeclCtx{
1151 .comments = null,1202 .comments = null,
1152 .visib_token = null,1203 .visib_token = null,
1204 .thread_local_token = null,
1153 .comptime_token = ctx.comptime_token,1205 .comptime_token = ctx.comptime_token,
1154 .extern_export_token = null,1206 .extern_export_token = null,
1155 .lib_name = null,1207 .lib_name = null,
...@@ -2937,6 +2989,7 @@ const TopLevelDeclCtx = struct {...@@ -2937,6 +2989,7 @@ const TopLevelDeclCtx = struct {
2937const VarDeclCtx = struct {2989const VarDeclCtx = struct {
2938 mut_token: TokenIndex,2990 mut_token: TokenIndex,
2939 visib_token: ?TokenIndex,2991 visib_token: ?TokenIndex,
2992 thread_local_token: ?TokenIndex,
2940 comptime_token: ?TokenIndex,2993 comptime_token: ?TokenIndex,
2941 extern_export_token: ?TokenIndex,2994 extern_export_token: ?TokenIndex,
2942 lib_name: ?*ast.Node,2995 lib_name: ?*ast.Node,
...@@ -3081,6 +3134,7 @@ const State = union(enum) {...@@ -3081,6 +3134,7 @@ const State = union(enum) {
3081 ContainerInitArg: *ast.Node.ContainerDecl,3134 ContainerInitArg: *ast.Node.ContainerDecl,
3082 ContainerDecl: *ast.Node.ContainerDecl,3135 ContainerDecl: *ast.Node.ContainerDecl,
30833136
3137 ThreadLocal: VarDeclCtx,
3084 VarDecl: VarDeclCtx,3138 VarDecl: VarDeclCtx,
3085 VarDeclAlign: *ast.Node.VarDecl,3139 VarDeclAlign: *ast.Node.VarDecl,
3086 VarDeclSection: *ast.Node.VarDecl,3140 VarDeclSection: *ast.Node.VarDecl,
std/zig/parser_test.zig+9-1
...@@ -1,3 +1,10 @@...@@ -1,3 +1,10 @@
1test "zig fmt: threadlocal" {
2 try testCanonical(
3 \\threadlocal var x: i32 = 1234;
4 \\
5 );
6}
7
1test "zig fmt: linksection" {8test "zig fmt: linksection" {
2 try testCanonical(9 try testCanonical(
3 \\export var aoeu: u64 linksection(".text.derp") = 1234;10 \\export var aoeu: u64 linksection(".text.derp") = 1234;
...@@ -5,6 +12,7 @@ test "zig fmt: linksection" {...@@ -5,6 +12,7 @@ test "zig fmt: linksection" {
5 \\12 \\
6 );13 );
7}14}
15
8test "zig fmt: shebang line" {16test "zig fmt: shebang line" {
9 try testCanonical(17 try testCanonical(
10 \\#!/usr/bin/env zig18 \\#!/usr/bin/env zig
...@@ -1940,7 +1948,7 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {...@@ -1940,7 +1948,7 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {
1940 warn("std.zig.render returned {} instead of {}\n", anything_changed, changes_expected);1948 warn("std.zig.render returned {} instead of {}\n", anything_changed, changes_expected);
1941 return error.TestFailed;1949 return error.TestFailed;
1942 }1950 }
1943 std.debug.assert(anything_changed == changes_expected);1951 std.testing.expect(anything_changed == changes_expected);
1944 failing_allocator.allocator.free(result_source);1952 failing_allocator.allocator.free(result_source);
1945 break :x failing_allocator.index;1953 break :x failing_allocator.index;
1946 };1954 };
std/zig/render.zig+3
...@@ -1706,6 +1706,9 @@ fn renderVarDecl(...@@ -1706,6 +1706,9 @@ fn renderVarDecl(
1706 try renderToken(tree, stream, comptime_token, indent, start_col, Space.Space); // comptime1706 try renderToken(tree, stream, comptime_token, indent, start_col, Space.Space); // comptime
1707 }1707 }
17081708
1709 if (var_decl.thread_local_token) |thread_local_token| {
1710 try renderToken(tree, stream, thread_local_token, indent, start_col, Space.Space); // threadlocal
1711 }
1709 try renderToken(tree, stream, var_decl.mut_token, indent, start_col, Space.Space); // var1712 try renderToken(tree, stream, var_decl.mut_token, indent, start_col, Space.Space); // var
17101713
1711 const name_space = if (var_decl.type_node == null and (var_decl.align_node != null or1714 const name_space = if (var_decl.type_node == null and (var_decl.align_node != null or
std/zig/tokenizer.zig+3-1
...@@ -53,6 +53,7 @@ pub const Token = struct {...@@ -53,6 +53,7 @@ pub const Token = struct {
53 Keyword{ .bytes = "switch", .id = Id.Keyword_switch },53 Keyword{ .bytes = "switch", .id = Id.Keyword_switch },
54 Keyword{ .bytes = "test", .id = Id.Keyword_test },54 Keyword{ .bytes = "test", .id = Id.Keyword_test },
55 Keyword{ .bytes = "this", .id = Id.Keyword_this },55 Keyword{ .bytes = "this", .id = Id.Keyword_this },
56 Keyword{ .bytes = "threadlocal", .id = Id.Keyword_threadlocal },
56 Keyword{ .bytes = "true", .id = Id.Keyword_true },57 Keyword{ .bytes = "true", .id = Id.Keyword_true },
57 Keyword{ .bytes = "try", .id = Id.Keyword_try },58 Keyword{ .bytes = "try", .id = Id.Keyword_try },
58 Keyword{ .bytes = "undefined", .id = Id.Keyword_undefined },59 Keyword{ .bytes = "undefined", .id = Id.Keyword_undefined },
...@@ -182,6 +183,7 @@ pub const Token = struct {...@@ -182,6 +183,7 @@ pub const Token = struct {
182 Keyword_switch,183 Keyword_switch,
183 Keyword_test,184 Keyword_test,
184 Keyword_this,185 Keyword_this,
186 Keyword_threadlocal,
185 Keyword_true,187 Keyword_true,
186 Keyword_try,188 Keyword_try,
187 Keyword_undefined,189 Keyword_undefined,
...@@ -1345,5 +1347,5 @@ fn testTokenize(source: []const u8, expected_tokens: []const Token.Id) void {...@@ -1345,5 +1347,5 @@ fn testTokenize(source: []const u8, expected_tokens: []const Token.Id) void {
1345 }1347 }
1346 }1348 }
1347 const last_token = tokenizer.next();1349 const last_token = tokenizer.next();
1348 std.debug.assert(last_token.id == Token.Id.Eof);1350 std.testing.expect(last_token.id == Token.Id.Eof);
1349}1351}
test/cli.zig+6-6
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const os = std.os;3const os = std.os;
4const assertOrPanic = std.debug.assertOrPanic;4const testing = std.testing;
55
6var a: *std.mem.Allocator = undefined;6var a: *std.mem.Allocator = undefined;
77
...@@ -87,13 +87,13 @@ fn exec(cwd: []const u8, argv: []const []const u8) !os.ChildProcess.ExecResult {...@@ -87,13 +87,13 @@ fn exec(cwd: []const u8, argv: []const []const u8) !os.ChildProcess.ExecResult {
87fn testZigInitLib(zig_exe: []const u8, dir_path: []const u8) !void {87fn testZigInitLib(zig_exe: []const u8, dir_path: []const u8) !void {
88 _ = try exec(dir_path, [][]const u8{ zig_exe, "init-lib" });88 _ = try exec(dir_path, [][]const u8{ zig_exe, "init-lib" });
89 const test_result = try exec(dir_path, [][]const u8{ zig_exe, "build", "test" });89 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"));
91}91}
9292
93fn testZigInitExe(zig_exe: []const u8, dir_path: []const u8) !void {93fn testZigInitExe(zig_exe: []const u8, dir_path: []const u8) !void {
94 _ = try exec(dir_path, [][]const u8{ zig_exe, "init-exe" });94 _ = try exec(dir_path, [][]const u8{ zig_exe, "init-exe" });
95 const run_result = try exec(dir_path, [][]const u8{ zig_exe, "build", "run" });95 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"));
97}97}
9898
99fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void {99fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void {
...@@ -126,7 +126,7 @@ fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void {...@@ -126,7 +126,7 @@ fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void {
126 _ = try exec(dir_path, args);126 _ = try exec(dir_path, args);
127127
128 const out_asm = try std.io.readFileAlloc(a, example_s_path);128 const out_asm = try std.io.readFileAlloc(a, example_s_path);
129 assertOrPanic(std.mem.indexOf(u8, out_asm, "square:") != null);129 testing.expect(std.mem.indexOf(u8, out_asm, "square:") != null);
130 assertOrPanic(std.mem.indexOf(u8, out_asm, "mov\teax, edi") != null);130 testing.expect(std.mem.indexOf(u8, out_asm, "mov\teax, edi") != null);
131 assertOrPanic(std.mem.indexOf(u8, out_asm, "imul\teax, edi") != null);131 testing.expect(std.mem.indexOf(u8, out_asm, "imul\teax, edi") != null);
132}132}
test/compile_errors.zig+7
...@@ -1,6 +1,13 @@...@@ -1,6 +1,13 @@
1const tests = @import("tests.zig");1const tests = @import("tests.zig");
22
3pub fn addCases(cases: *tests.CompileErrorContext) void {3pub fn addCases(cases: *tests.CompileErrorContext) void {
4 cases.addTest(
5 "return invalid type from test",
6 \\test "example" { return 1; }
7 ,
8 ".tmp_source.zig:1:25: error: integer value 1 cannot be implicitly casted to type 'void'",
9 );
10
4 cases.add(11 cases.add(
5 "threadlocal qualifier on const",12 "threadlocal qualifier on const",
6 \\threadlocal const x: i32 = 1234;13 \\threadlocal const x: i32 = 1234;
test/runtime_safety.zig+31
...@@ -94,6 +94,20 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -94,6 +94,20 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
94 \\}94 \\}
95 );95 );
9696
97 cases.addRuntimeSafety("vector integer addition overflow",
98 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
99 \\ @import("std").os.exit(126);
100 \\}
101 \\pub fn main() void {
102 \\ var a: @Vector(4, i32) = []i32{ 1, 2, 2147483643, 4 };
103 \\ var b: @Vector(4, i32) = []i32{ 5, 6, 7, 8 };
104 \\ const x = add(a, b);
105 \\}
106 \\fn add(a: @Vector(4, i32), b: @Vector(4, i32)) @Vector(4, i32) {
107 \\ return a + b;
108 \\}
109 );
110
97 cases.addRuntimeSafety("integer subtraction overflow",111 cases.addRuntimeSafety("integer subtraction overflow",
98 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {112 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
99 \\ @import("std").os.exit(126);113 \\ @import("std").os.exit(126);
...@@ -362,6 +376,23 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -362,6 +376,23 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
362 \\}376 \\}
363 );377 );
364378
379 // @intCast a runtime integer to u0 actually results in a comptime-known value,
380 // but we still emit a safety check to ensure the integer was 0 and thus
381 // did not truncate information.
382 cases.addRuntimeSafety("@intCast to u0",
383 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
384 \\ @import("std").os.exit(126);
385 \\}
386 \\
387 \\pub fn main() void {
388 \\ bar(1, 1);
389 \\}
390 \\
391 \\fn bar(one: u1, not_zero: i32) void {
392 \\ var x = one << @intCast(u0, not_zero);
393 \\}
394 );
395
365 // This case makes sure that the code compiles and runs. There is not actually a special396 // This case makes sure that the code compiles and runs. There is not actually a special
366 // runtime safety check having to do specifically with error return traces across suspend points.397 // runtime safety check having to do specifically with error return traces across suspend points.
367 cases.addRuntimeSafety("error return trace across suspend points",398 cases.addRuntimeSafety("error return trace across suspend points",
test/stage1/behavior/align.zig+36-36
...@@ -1,13 +1,13 @@...@@ -1,13 +1,13 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;1const expect = @import("std").testing.expect;
2const builtin = @import("builtin");2const builtin = @import("builtin");
33
4var foo: u8 align(4) = 100;4var foo: u8 align(4) = 100;
55
6test "global variable alignment" {6test "global variable alignment" {
7 assertOrPanic(@typeOf(&foo).alignment == 4);7 expect(@typeOf(&foo).alignment == 4);
8 assertOrPanic(@typeOf(&foo) == *align(4) u8);8 expect(@typeOf(&foo) == *align(4) u8);
9 const slice = (*[1]u8)(&foo)[0..];9 const slice = (*[1]u8)(&foo)[0..];
10 assertOrPanic(@typeOf(slice) == []align(4) u8);10 expect(@typeOf(slice) == []align(4) u8);
11}11}
1212
13fn derp() align(@sizeOf(usize) * 2) i32 {13fn derp() align(@sizeOf(usize) * 2) i32 {
...@@ -17,9 +17,9 @@ fn noop1() align(1) void {}...@@ -17,9 +17,9 @@ fn noop1() align(1) void {}
17fn noop4() align(4) void {}17fn noop4() align(4) void {}
1818
19test "function alignment" {19test "function alignment" {
20 assertOrPanic(derp() == 1234);20 expect(derp() == 1234);
21 assertOrPanic(@typeOf(noop1) == fn () align(1) void);21 expect(@typeOf(noop1) == fn () align(1) void);
22 assertOrPanic(@typeOf(noop4) == fn () align(4) void);22 expect(@typeOf(noop4) == fn () align(4) void);
23 noop1();23 noop1();
24 noop4();24 noop4();
25}25}
...@@ -30,7 +30,7 @@ var baz: packed struct {...@@ -30,7 +30,7 @@ var baz: packed struct {
30} = undefined;30} = undefined;
3131
32test "packed struct alignment" {32test "packed struct alignment" {
33 assertOrPanic(@typeOf(&baz.b) == *align(1) u32);33 expect(@typeOf(&baz.b) == *align(1) u32);
34}34}
3535
36const blah: packed struct {36const blah: packed struct {
...@@ -40,17 +40,17 @@ const blah: packed struct {...@@ -40,17 +40,17 @@ const blah: packed struct {
40} = undefined;40} = undefined;
4141
42test "bit field alignment" {42test "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);
44}44}
4545
46test "default alignment allows unspecified in type syntax" {46test "default alignment allows unspecified in type syntax" {
47 assertOrPanic(*u32 == *align(@alignOf(u32)) u32);47 expect(*u32 == *align(@alignOf(u32)) u32);
48}48}
4949
50test "implicitly decreasing pointer alignment" {50test "implicitly decreasing pointer alignment" {
51 const a: u32 align(4) = 3;51 const a: u32 align(4) = 3;
52 const b: u32 align(8) = 4;52 const b: u32 align(8) = 4;
53 assertOrPanic(addUnaligned(&a, &b) == 7);53 expect(addUnaligned(&a, &b) == 7);
54}54}
5555
56fn addUnaligned(a: *align(1) const u32, b: *align(1) const u32) u32 {56fn 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 {...@@ -60,7 +60,7 @@ fn addUnaligned(a: *align(1) const u32, b: *align(1) const u32) u32 {
60test "implicitly decreasing slice alignment" {60test "implicitly decreasing slice alignment" {
61 const a: u32 align(4) = 3;61 const a: u32 align(4) = 3;
62 const b: u32 align(8) = 4;62 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);
64}64}
65fn addUnalignedSlice(a: []align(1) const u32, b: []align(1) const u32) u32 {65fn addUnalignedSlice(a: []align(1) const u32, b: []align(1) const u32) u32 {
66 return a[0] + b[0];66 return a[0] + b[0];
...@@ -77,7 +77,7 @@ fn testBytesAlign(b: u8) void {...@@ -77,7 +77,7 @@ fn testBytesAlign(b: u8) void {
77 b,77 b,
78 };78 };
79 const ptr = @ptrCast(*u32, &bytes[0]);79 const ptr = @ptrCast(*u32, &bytes[0]);
80 assertOrPanic(ptr.* == 0x33333333);80 expect(ptr.* == 0x33333333);
81}81}
8282
83test "specifying alignment allows slice cast" {83test "specifying alignment allows slice cast" {
...@@ -91,13 +91,13 @@ fn testBytesAlignSlice(b: u8) void {...@@ -91,13 +91,13 @@ fn testBytesAlignSlice(b: u8) void {
91 b,91 b,
92 };92 };
93 const slice: []u32 = @bytesToSlice(u32, bytes[0..]);93 const slice: []u32 = @bytesToSlice(u32, bytes[0..]);
94 assertOrPanic(slice[0] == 0x33333333);94 expect(slice[0] == 0x33333333);
95}95}
9696
97test "@alignCast pointers" {97test "@alignCast pointers" {
98 var x: u32 align(4) = 1;98 var x: u32 align(4) = 1;
99 expectsOnly1(&x);99 expectsOnly1(&x);
100 assertOrPanic(x == 2);100 expect(x == 2);
101}101}
102fn expectsOnly1(x: *align(1) u32) void {102fn expectsOnly1(x: *align(1) u32) void {
103 expects4(@alignCast(4, x));103 expects4(@alignCast(4, x));
...@@ -113,7 +113,7 @@ test "@alignCast slices" {...@@ -113,7 +113,7 @@ test "@alignCast slices" {
113 };113 };
114 const slice = array[0..];114 const slice = array[0..];
115 sliceExpectsOnly1(slice);115 sliceExpectsOnly1(slice);
116 assertOrPanic(slice[0] == 2);116 expect(slice[0] == 2);
117}117}
118fn sliceExpectsOnly1(slice: []align(1) u32) void {118fn sliceExpectsOnly1(slice: []align(1) u32) void {
119 sliceExpects4(@alignCast(4, slice));119 sliceExpects4(@alignCast(4, slice));
...@@ -128,7 +128,7 @@ test "implicitly decreasing fn alignment" {...@@ -128,7 +128,7 @@ test "implicitly decreasing fn alignment" {
128}128}
129129
130fn testImplicitlyDecreaseFnAlign(ptr: fn () align(1) i32, answer: i32) void {130fn testImplicitlyDecreaseFnAlign(ptr: fn () align(1) i32, answer: i32) void {
131 assertOrPanic(ptr() == answer);131 expect(ptr() == answer);
132}132}
133133
134fn alignedSmall() align(8) i32 {134fn alignedSmall() align(8) i32 {
...@@ -139,7 +139,7 @@ fn alignedBig() align(16) i32 {...@@ -139,7 +139,7 @@ fn alignedBig() align(16) i32 {
139}139}
140140
141test "@alignCast functions" {141test "@alignCast functions" {
142 assertOrPanic(fnExpectsOnly1(simple4) == 0x19);142 expect(fnExpectsOnly1(simple4) == 0x19);
143}143}
144fn fnExpectsOnly1(ptr: fn () align(1) i32) i32 {144fn fnExpectsOnly1(ptr: fn () align(1) i32) i32 {
145 return fnExpects4(@alignCast(4, ptr));145 return fnExpects4(@alignCast(4, ptr));
...@@ -152,9 +152,9 @@ fn simple4() align(4) i32 {...@@ -152,9 +152,9 @@ fn simple4() align(4) i32 {
152}152}
153153
154test "generic function with align param" {154test "generic function with align param" {
155 assertOrPanic(whyWouldYouEverDoThis(1) == 0x1);155 expect(whyWouldYouEverDoThis(1) == 0x1);
156 assertOrPanic(whyWouldYouEverDoThis(4) == 0x1);156 expect(whyWouldYouEverDoThis(4) == 0x1);
157 assertOrPanic(whyWouldYouEverDoThis(8) == 0x1);157 expect(whyWouldYouEverDoThis(8) == 0x1);
158}158}
159159
160fn whyWouldYouEverDoThis(comptime align_bytes: u8) align(align_bytes) u8 {160fn whyWouldYouEverDoThis(comptime align_bytes: u8) align(align_bytes) u8 {
...@@ -164,28 +164,28 @@ fn whyWouldYouEverDoThis(comptime align_bytes: u8) align(align_bytes) u8 {...@@ -164,28 +164,28 @@ fn whyWouldYouEverDoThis(comptime align_bytes: u8) align(align_bytes) u8 {
164test "@ptrCast preserves alignment of bigger source" {164test "@ptrCast preserves alignment of bigger source" {
165 var x: u32 align(16) = 1234;165 var x: u32 align(16) = 1234;
166 const ptr = @ptrCast(*u8, &x);166 const ptr = @ptrCast(*u8, &x);
167 assertOrPanic(@typeOf(ptr) == *align(16) u8);167 expect(@typeOf(ptr) == *align(16) u8);
168}168}
169169
170test "runtime known array index has best alignment possible" {170test "runtime known array index has best alignment possible" {
171 // take full advantage of over-alignment171 // take full advantage of over-alignment
172 var array align(4) = []u8{ 1, 2, 3, 4 };172 var array align(4) = []u8{ 1, 2, 3, 4 };
173 assertOrPanic(@typeOf(&array[0]) == *align(4) u8);173 expect(@typeOf(&array[0]) == *align(4) u8);
174 assertOrPanic(@typeOf(&array[1]) == *u8);174 expect(@typeOf(&array[1]) == *u8);
175 assertOrPanic(@typeOf(&array[2]) == *align(2) u8);175 expect(@typeOf(&array[2]) == *align(2) u8);
176 assertOrPanic(@typeOf(&array[3]) == *u8);176 expect(@typeOf(&array[3]) == *u8);
177177
178 // because align is too small but we still figure out to use 2178 // because align is too small but we still figure out to use 2
179 var bigger align(2) = []u64{ 1, 2, 3, 4 };179 var bigger align(2) = []u64{ 1, 2, 3, 4 };
180 assertOrPanic(@typeOf(&bigger[0]) == *align(2) u64);180 expect(@typeOf(&bigger[0]) == *align(2) u64);
181 assertOrPanic(@typeOf(&bigger[1]) == *align(2) u64);181 expect(@typeOf(&bigger[1]) == *align(2) u64);
182 assertOrPanic(@typeOf(&bigger[2]) == *align(2) u64);182 expect(@typeOf(&bigger[2]) == *align(2) u64);
183 assertOrPanic(@typeOf(&bigger[3]) == *align(2) u64);183 expect(@typeOf(&bigger[3]) == *align(2) u64);
184184
185 // because pointer is align 2 and u32 align % 2 == 0 we can assume align 2185 // because pointer is align 2 and u32 align % 2 == 0 we can assume align 2
186 var smaller align(2) = []u32{ 1, 2, 3, 4 };186 var smaller align(2) = []u32{ 1, 2, 3, 4 };
187 comptime assertOrPanic(@typeOf(smaller[0..]) == []align(2) u32);187 comptime expect(@typeOf(smaller[0..]) == []align(2) u32);
188 comptime assertOrPanic(@typeOf(smaller[0..].ptr) == [*]align(2) u32);188 comptime expect(@typeOf(smaller[0..].ptr) == [*]align(2) u32);
189 testIndex(smaller[0..].ptr, 0, *align(2) u32);189 testIndex(smaller[0..].ptr, 0, *align(2) u32);
190 testIndex(smaller[0..].ptr, 1, *align(2) u32);190 testIndex(smaller[0..].ptr, 1, *align(2) u32);
191 testIndex(smaller[0..].ptr, 2, *align(2) u32);191 testIndex(smaller[0..].ptr, 2, *align(2) u32);
...@@ -198,14 +198,14 @@ test "runtime known array index has best alignment possible" {...@@ -198,14 +198,14 @@ test "runtime known array index has best alignment possible" {
198 testIndex2(array[0..].ptr, 3, *u8);198 testIndex2(array[0..].ptr, 3, *u8);
199}199}
200fn testIndex(smaller: [*]align(2) u32, index: usize, comptime T: type) void {200fn 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);
202}202}
203fn testIndex2(ptr: [*]align(4) u8, index: usize, comptime T: type) void {203fn 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);
205}205}
206206
207test "alignstack" {207test "alignstack" {
208 assertOrPanic(fnWithAlignedStack() == 1234);208 expect(fnWithAlignedStack() == 1234);
209}209}
210210
211fn fnWithAlignedStack() i32 {211fn fnWithAlignedStack() i32 {
...@@ -214,7 +214,7 @@ fn fnWithAlignedStack() i32 {...@@ -214,7 +214,7 @@ fn fnWithAlignedStack() i32 {
214}214}
215215
216test "alignment of structs" {216test "alignment of structs" {
217 assertOrPanic(@alignOf(struct {217 expect(@alignOf(struct {
218 a: i32,218 a: i32,
219 b: *i32,219 b: *i32,
220 }) == @alignOf(usize));220 }) == @alignOf(usize));
test/stage1/behavior/alignof.zig+3-3
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const assertOrPanic = std.debug.assertOrPanic;2const expect = std.testing.expect;
3const builtin = @import("builtin");3const builtin = @import("builtin");
4const maxInt = std.math.maxInt;4const maxInt = std.math.maxInt;
55
...@@ -10,9 +10,9 @@ const Foo = struct {...@@ -10,9 +10,9 @@ const Foo = struct {
10};10};
1111
12test "@alignOf(T) before referencing T" {12test "@alignOf(T) before referencing T" {
13 comptime assertOrPanic(@alignOf(Foo) != maxInt(usize));13 comptime expect(@alignOf(Foo) != maxInt(usize));
14 if (builtin.arch == builtin.Arch.x86_64) {14 if (builtin.arch == builtin.Arch.x86_64) {
15 comptime assertOrPanic(@alignOf(Foo) == 4);15 comptime expect(@alignOf(Foo) == 4);
16 }16 }
17}17}
1818
test/stage1/behavior/array.zig+55-55
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;1const expect = @import("std").testing.expect;
2const mem = @import("std").mem;2const mem = @import("std").mem;
33
4test "arrays" {4test "arrays" {
...@@ -18,8 +18,8 @@ test "arrays" {...@@ -18,8 +18,8 @@ test "arrays" {
18 i += 1;18 i += 1;
19 }19 }
2020
21 assertOrPanic(accumulator == 15);21 expect(accumulator == 15);
22 assertOrPanic(getArrayLen(array) == 5);22 expect(getArrayLen(array) == 5);
23}23}
24fn getArrayLen(a: []const u32) usize {24fn getArrayLen(a: []const u32) usize {
25 return a.len;25 return a.len;
...@@ -29,8 +29,8 @@ test "void arrays" {...@@ -29,8 +29,8 @@ test "void arrays" {
29 var array: [4]void = undefined;29 var array: [4]void = undefined;
30 array[0] = void{};30 array[0] = void{};
31 array[1] = array[2];31 array[1] = array[2];
32 assertOrPanic(@sizeOf(@typeOf(array)) == 0);32 expect(@sizeOf(@typeOf(array)) == 0);
33 assertOrPanic(array.len == 4);33 expect(array.len == 4);
34}34}
3535
36test "array literal" {36test "array literal" {
...@@ -41,12 +41,12 @@ test "array literal" {...@@ -41,12 +41,12 @@ test "array literal" {
41 1,41 1,
42 };42 };
4343
44 assertOrPanic(hex_mult.len == 4);44 expect(hex_mult.len == 4);
45 assertOrPanic(hex_mult[1] == 256);45 expect(hex_mult[1] == 256);
46}46}
4747
48test "array dot len const expr" {48test "array dot len const expr" {
49 assertOrPanic(comptime x: {49 expect(comptime x: {
50 break :x some_array.len == 4;50 break :x some_array.len == 4;
51 });51 });
52}52}
...@@ -70,11 +70,11 @@ test "nested arrays" {...@@ -70,11 +70,11 @@ test "nested arrays" {
70 "thing",70 "thing",
71 };71 };
72 for (array_of_strings) |s, i| {72 for (array_of_strings) |s, i| {
73 if (i == 0) assertOrPanic(mem.eql(u8, s, "hello"));73 if (i == 0) expect(mem.eql(u8, s, "hello"));
74 if (i == 1) assertOrPanic(mem.eql(u8, s, "this"));74 if (i == 1) expect(mem.eql(u8, s, "this"));
75 if (i == 2) assertOrPanic(mem.eql(u8, s, "is"));75 if (i == 2) expect(mem.eql(u8, s, "is"));
76 if (i == 3) assertOrPanic(mem.eql(u8, s, "my"));76 if (i == 3) expect(mem.eql(u8, s, "my"));
77 if (i == 4) assertOrPanic(mem.eql(u8, s, "thing"));77 if (i == 4) expect(mem.eql(u8, s, "thing"));
78 }78 }
79}79}
8080
...@@ -92,9 +92,9 @@ test "set global var array via slice embedded in struct" {...@@ -92,9 +92,9 @@ test "set global var array via slice embedded in struct" {
92 s.a[1].b = 2;92 s.a[1].b = 2;
93 s.a[2].b = 3;93 s.a[2].b = 3;
9494
95 assertOrPanic(s_array[0].b == 1);95 expect(s_array[0].b == 1);
96 assertOrPanic(s_array[1].b == 2);96 expect(s_array[1].b == 2);
97 assertOrPanic(s_array[2].b == 3);97 expect(s_array[2].b == 3);
98}98}
9999
100test "array literal with specified size" {100test "array literal with specified size" {
...@@ -102,27 +102,27 @@ test "array literal with specified size" {...@@ -102,27 +102,27 @@ test "array literal with specified size" {
102 1,102 1,
103 2,103 2,
104 };104 };
105 assertOrPanic(array[0] == 1);105 expect(array[0] == 1);
106 assertOrPanic(array[1] == 2);106 expect(array[1] == 2);
107}107}
108108
109test "array child property" {109test "array child property" {
110 var x: [5]i32 = undefined;110 var x: [5]i32 = undefined;
111 assertOrPanic(@typeOf(x).Child == i32);111 expect(@typeOf(x).Child == i32);
112}112}
113113
114test "array len property" {114test "array len property" {
115 var x: [5]i32 = undefined;115 var x: [5]i32 = undefined;
116 assertOrPanic(@typeOf(x).len == 5);116 expect(@typeOf(x).len == 5);
117}117}
118118
119test "array len field" {119test "array len field" {
120 var arr = [4]u8{ 0, 0, 0, 0 };120 var arr = [4]u8{ 0, 0, 0, 0 };
121 var ptr = &arr;121 var ptr = &arr;
122 assertOrPanic(arr.len == 4);122 expect(arr.len == 4);
123 comptime assertOrPanic(arr.len == 4);123 comptime expect(arr.len == 4);
124 assertOrPanic(ptr.len == 4);124 expect(ptr.len == 4);
125 comptime assertOrPanic(ptr.len == 4);125 comptime expect(ptr.len == 4);
126}126}
127127
128test "single-item pointer to array indexing and slicing" {128test "single-item pointer to array indexing and slicing" {
...@@ -133,7 +133,7 @@ test "single-item pointer to array indexing and slicing" {...@@ -133,7 +133,7 @@ test "single-item pointer to array indexing and slicing" {
133fn testSingleItemPtrArrayIndexSlice() void {133fn testSingleItemPtrArrayIndexSlice() void {
134 var array = "aaaa";134 var array = "aaaa";
135 doSomeMangling(&array);135 doSomeMangling(&array);
136 assertOrPanic(mem.eql(u8, "azya", array));136 expect(mem.eql(u8, "azya", array));
137}137}
138138
139fn doSomeMangling(array: *[4]u8) void {139fn doSomeMangling(array: *[4]u8) void {
...@@ -150,7 +150,7 @@ fn testImplicitCastSingleItemPtr() void {...@@ -150,7 +150,7 @@ fn testImplicitCastSingleItemPtr() void {
150 var byte: u8 = 100;150 var byte: u8 = 100;
151 const slice = (*[1]u8)(&byte)[0..];151 const slice = (*[1]u8)(&byte)[0..];
152 slice[0] += 1;152 slice[0] += 1;
153 assertOrPanic(byte == 101);153 expect(byte == 101);
154}154}
155155
156fn testArrayByValAtComptime(b: [2]u8) u8 {156fn testArrayByValAtComptime(b: [2]u8) u8 {
...@@ -165,7 +165,7 @@ test "comptime evalutating function that takes array by value" {...@@ -165,7 +165,7 @@ test "comptime evalutating function that takes array by value" {
165165
166test "implicit comptime in array type size" {166test "implicit comptime in array type size" {
167 var arr: [plusOne(10)]bool = undefined;167 var arr: [plusOne(10)]bool = undefined;
168 assertOrPanic(arr.len == 11);168 expect(arr.len == 11);
169}169}
170170
171fn plusOne(x: u32) u32 {171fn plusOne(x: u32) u32 {
...@@ -197,15 +197,15 @@ test "array literal as argument to function" {...@@ -197,15 +197,15 @@ test "array literal as argument to function" {
197 });197 });
198 }198 }
199 fn foo(x: []const i32) void {199 fn foo(x: []const i32) void {
200 assertOrPanic(x[0] == 1);200 expect(x[0] == 1);
201 assertOrPanic(x[1] == 2);201 expect(x[1] == 2);
202 assertOrPanic(x[2] == 3);202 expect(x[2] == 3);
203 }203 }
204 fn foo2(trash: bool, x: []const i32) void {204 fn foo2(trash: bool, x: []const i32) void {
205 assertOrPanic(trash);205 expect(trash);
206 assertOrPanic(x[0] == 1);206 expect(x[0] == 1);
207 assertOrPanic(x[1] == 2);207 expect(x[1] == 2);
208 assertOrPanic(x[2] == 3);208 expect(x[2] == 3);
209 }209 }
210 };210 };
211 S.entry(2);211 S.entry(2);
...@@ -229,12 +229,12 @@ test "double nested array to const slice cast in array literal" {...@@ -229,12 +229,12 @@ test "double nested array to const slice cast in array literal" {
229 []i32{1},229 []i32{1},
230 []i32{ two, 3 },230 []i32{ two, 3 },
231 };231 };
232 assertOrPanic(cases2.len == 2);232 expect(cases2.len == 2);
233 assertOrPanic(cases2[0].len == 1);233 expect(cases2[0].len == 1);
234 assertOrPanic(cases2[0][0] == 1);234 expect(cases2[0][0] == 1);
235 assertOrPanic(cases2[1].len == 2);235 expect(cases2[1].len == 2);
236 assertOrPanic(cases2[1][0] == 2);236 expect(cases2[1][0] == 2);
237 assertOrPanic(cases2[1][1] == 3);237 expect(cases2[1][1] == 3);
238238
239 const cases3 = [][]const []const i32{239 const cases3 = [][]const []const i32{
240 [][]const i32{[]i32{1}},240 [][]const i32{[]i32{1}},
...@@ -248,21 +248,21 @@ test "double nested array to const slice cast in array literal" {...@@ -248,21 +248,21 @@ test "double nested array to const slice cast in array literal" {
248 }248 }
249249
250 fn check(cases: []const []const []const i32) void {250 fn check(cases: []const []const []const i32) void {
251 assertOrPanic(cases.len == 3);251 expect(cases.len == 3);
252 assertOrPanic(cases[0].len == 1);252 expect(cases[0].len == 1);
253 assertOrPanic(cases[0][0].len == 1);253 expect(cases[0][0].len == 1);
254 assertOrPanic(cases[0][0][0] == 1);254 expect(cases[0][0][0] == 1);
255 assertOrPanic(cases[1].len == 1);255 expect(cases[1].len == 1);
256 assertOrPanic(cases[1][0].len == 2);256 expect(cases[1][0].len == 2);
257 assertOrPanic(cases[1][0][0] == 2);257 expect(cases[1][0][0] == 2);
258 assertOrPanic(cases[1][0][1] == 3);258 expect(cases[1][0][1] == 3);
259 assertOrPanic(cases[2].len == 2);259 expect(cases[2].len == 2);
260 assertOrPanic(cases[2][0].len == 1);260 expect(cases[2][0].len == 1);
261 assertOrPanic(cases[2][0][0] == 4);261 expect(cases[2][0][0] == 4);
262 assertOrPanic(cases[2][1].len == 3);262 expect(cases[2][1].len == 3);
263 assertOrPanic(cases[2][1][0] == 5);263 expect(cases[2][1][0] == 5);
264 assertOrPanic(cases[2][1][1] == 6);264 expect(cases[2][1][1] == 6);
265 assertOrPanic(cases[2][1][2] == 7);265 expect(cases[2][1][2] == 7);
266 }266 }
267 };267 };
268 S.entry(2);268 S.entry(2);
test/stage1/behavior/asm.zig+2-2
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const config = @import("builtin");1const config = @import("builtin");
2const assertOrPanic = @import("std").debug.assertOrPanic;2const expect = @import("std").testing.expect;
33
4comptime {4comptime {
5 if (config.arch == config.Arch.x86_64 and config.os == config.Os.linux) {5 if (config.arch == config.Arch.x86_64 and config.os == config.Os.linux) {
...@@ -13,7 +13,7 @@ comptime {...@@ -13,7 +13,7 @@ comptime {
1313
14test "module level assembly" {14test "module level assembly" {
15 if (config.arch == config.Arch.x86_64 and config.os == config.Os.linux) {15 if (config.arch == config.Arch.x86_64 and config.os == config.Os.linux) {
16 assertOrPanic(aoeu() == 1234);16 expect(aoeu() == 1234);
17 }17 }
18}18}
1919
test/stage1/behavior/atomics.zig+16-16
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const assertOrPanic = std.debug.assertOrPanic;2const expect = std.testing.expect;
3const builtin = @import("builtin");3const builtin = @import("builtin");
4const AtomicRmwOp = builtin.AtomicRmwOp;4const AtomicRmwOp = builtin.AtomicRmwOp;
5const AtomicOrder = builtin.AtomicOrder;5const AtomicOrder = builtin.AtomicOrder;
...@@ -7,18 +7,18 @@ const AtomicOrder = builtin.AtomicOrder;...@@ -7,18 +7,18 @@ const AtomicOrder = builtin.AtomicOrder;
7test "cmpxchg" {7test "cmpxchg" {
8 var x: i32 = 1234;8 var x: i32 = 1234;
9 if (@cmpxchgWeak(i32, &x, 99, 5678, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) |x1| {9 if (@cmpxchgWeak(i32, &x, 99, 5678, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) |x1| {
10 assertOrPanic(x1 == 1234);10 expect(x1 == 1234);
11 } else {11 } else {
12 @panic("cmpxchg should have failed");12 @panic("cmpxchg should have failed");
13 }13 }
1414
15 while (@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) |x1| {15 while (@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) |x1| {
16 assertOrPanic(x1 == 1234);16 expect(x1 == 1234);
17 }17 }
18 assertOrPanic(x == 5678);18 expect(x == 5678);
1919
20 assertOrPanic(@cmpxchgStrong(i32, &x, 5678, 42, AtomicOrder.SeqCst, AtomicOrder.SeqCst) == null);20 expect(@cmpxchgStrong(i32, &x, 5678, 42, AtomicOrder.SeqCst, AtomicOrder.SeqCst) == null);
21 assertOrPanic(x == 42);21 expect(x == 42);
22}22}
2323
24test "fence" {24test "fence" {
...@@ -30,24 +30,24 @@ test "fence" {...@@ -30,24 +30,24 @@ test "fence" {
30test "atomicrmw and atomicload" {30test "atomicrmw and atomicload" {
31 var data: u8 = 200;31 var data: u8 = 200;
32 testAtomicRmw(&data);32 testAtomicRmw(&data);
33 assertOrPanic(data == 42);33 expect(data == 42);
34 testAtomicLoad(&data);34 testAtomicLoad(&data);
35}35}
3636
37fn testAtomicRmw(ptr: *u8) void {37fn testAtomicRmw(ptr: *u8) void {
38 const prev_value = @atomicRmw(u8, ptr, AtomicRmwOp.Xchg, 42, AtomicOrder.SeqCst);38 const prev_value = @atomicRmw(u8, ptr, AtomicRmwOp.Xchg, 42, AtomicOrder.SeqCst);
39 assertOrPanic(prev_value == 200);39 expect(prev_value == 200);
40 comptime {40 comptime {
41 var x: i32 = 1234;41 var x: i32 = 1234;
42 const y: i32 = 12345;42 const y: i32 = 12345;
43 assertOrPanic(@atomicLoad(i32, &x, AtomicOrder.SeqCst) == 1234);43 expect(@atomicLoad(i32, &x, AtomicOrder.SeqCst) == 1234);
44 assertOrPanic(@atomicLoad(i32, &y, AtomicOrder.SeqCst) == 12345);44 expect(@atomicLoad(i32, &y, AtomicOrder.SeqCst) == 12345);
45 }45 }
46}46}
4747
48fn testAtomicLoad(ptr: *u8) void {48fn testAtomicLoad(ptr: *u8) void {
49 const x = @atomicLoad(u8, ptr, AtomicOrder.SeqCst);49 const x = @atomicLoad(u8, ptr, AtomicOrder.SeqCst);
50 assertOrPanic(x == 42);50 expect(x == 42);
51}51}
5252
53test "cmpxchg with ptr" {53test "cmpxchg with ptr" {
...@@ -56,16 +56,16 @@ test "cmpxchg with ptr" {...@@ -56,16 +56,16 @@ test "cmpxchg with ptr" {
56 var data3: i32 = 9101;56 var data3: i32 = 9101;
57 var x: *i32 = &data1;57 var x: *i32 = &data1;
58 if (@cmpxchgWeak(*i32, &x, &data2, &data3, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) |x1| {58 if (@cmpxchgWeak(*i32, &x, &data2, &data3, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) |x1| {
59 assertOrPanic(x1 == &data1);59 expect(x1 == &data1);
60 } else {60 } else {
61 @panic("cmpxchg should have failed");61 @panic("cmpxchg should have failed");
62 }62 }
6363
64 while (@cmpxchgWeak(*i32, &x, &data1, &data3, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) |x1| {64 while (@cmpxchgWeak(*i32, &x, &data1, &data3, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) |x1| {
65 assertOrPanic(x1 == &data1);65 expect(x1 == &data1);
66 }66 }
67 assertOrPanic(x == &data3);67 expect(x == &data3);
6868
69 assertOrPanic(@cmpxchgStrong(*i32, &x, &data3, &data2, AtomicOrder.SeqCst, AtomicOrder.SeqCst) == null);69 expect(@cmpxchgStrong(*i32, &x, &data3, &data2, AtomicOrder.SeqCst, AtomicOrder.SeqCst) == null);
70 assertOrPanic(x == &data2);70 expect(x == &data2);
71}71}
test/stage1/behavior/bit_shifting.zig+5-5
...@@ -1,9 +1,9 @@...@@ -1,9 +1,9 @@
1const std = @import("std");1const std = @import("std");
2const assertOrPanic = std.debug.assertOrPanic;2const expect = std.testing.expect;
33
4fn ShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, comptime V: type) type {4fn ShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, comptime V: type) type {
5 assertOrPanic(Key == @IntType(false, Key.bit_count));5 expect(Key == @IntType(false, Key.bit_count));
6 assertOrPanic(Key.bit_count >= mask_bit_count);6 expect(Key.bit_count >= mask_bit_count);
7 const ShardKey = @IntType(false, mask_bit_count);7 const ShardKey = @IntType(false, mask_bit_count);
8 const shift_amount = Key.bit_count - ShardKey.bit_count;8 const shift_amount = Key.bit_count - ShardKey.bit_count;
9 return struct {9 return struct {
...@@ -77,12 +77,12 @@ fn testShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, c...@@ -77,12 +77,12 @@ fn testShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, c
77 var node_buffer: [node_count]Table.Node = undefined;77 var node_buffer: [node_count]Table.Node = undefined;
78 for (node_buffer) |*node, i| {78 for (node_buffer) |*node, i| {
79 const key = @intCast(Key, i);79 const key = @intCast(Key, i);
80 assertOrPanic(table.get(key) == null);80 expect(table.get(key) == null);
81 node.init(key, {});81 node.init(key, {});
82 table.put(node);82 table.put(node);
83 }83 }
8484
85 for (node_buffer) |*node, i| {85 for (node_buffer) |*node, i| {
86 assertOrPanic(table.get(@intCast(Key, i)) == node);86 expect(table.get(@intCast(Key, i)) == node);
87 }87 }
88}88}
test/stage1/behavior/bitcast.zig+4-4
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const assertOrPanic = std.debug.assertOrPanic;2const expect = std.testing.expect;
3const maxInt = std.math.maxInt;3const maxInt = std.math.maxInt;
44
5test "@bitCast i32 -> u32" {5test "@bitCast i32 -> u32" {
...@@ -8,8 +8,8 @@ test "@bitCast i32 -> u32" {...@@ -8,8 +8,8 @@ test "@bitCast i32 -> u32" {
8}8}
99
10fn testBitCast_i32_u32() void {10fn testBitCast_i32_u32() void {
11 assertOrPanic(conv(-1) == maxInt(u32));11 expect(conv(-1) == maxInt(u32));
12 assertOrPanic(conv2(maxInt(u32)) == -1);12 expect(conv2(maxInt(u32)) == -1);
13}13}
1414
15fn conv(x: i32) u32 {15fn conv(x: i32) u32 {
...@@ -27,7 +27,7 @@ test "@bitCast extern enum to its integer type" {...@@ -27,7 +27,7 @@ test "@bitCast extern enum to its integer type" {
27 fn testBitCastExternEnum() void {27 fn testBitCastExternEnum() void {
28 var SOCK_DGRAM = @This().B;28 var SOCK_DGRAM = @This().B;
29 var sock_dgram = @bitCast(c_int, SOCK_DGRAM);29 var sock_dgram = @bitCast(c_int, SOCK_DGRAM);
30 assertOrPanic(sock_dgram == 1);30 expect(sock_dgram == 1);
31 }31 }
32 };32 };
3333
test/stage1/behavior/bitreverse.zig+43-43
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const assertOrPanic = std.debug.assertOrPanic;2const expect = std.testing.expect;
3const minInt = std.math.minInt;3const minInt = std.math.minInt;
44
5test "@bitreverse" {5test "@bitreverse" {
...@@ -9,73 +9,73 @@ test "@bitreverse" {...@@ -9,73 +9,73 @@ test "@bitreverse" {
99
10fn testBitReverse() void {10fn testBitReverse() void {
11 // using comptime_ints, unsigned11 // using comptime_ints, unsigned
12 assertOrPanic(@bitreverse(u0, 0) == 0);12 expect(@bitreverse(u0, 0) == 0);
13 assertOrPanic(@bitreverse(u5, 0x12) == 0x9);13 expect(@bitreverse(u5, 0x12) == 0x9);
14 assertOrPanic(@bitreverse(u8, 0x12) == 0x48);14 expect(@bitreverse(u8, 0x12) == 0x48);
15 assertOrPanic(@bitreverse(u16, 0x1234) == 0x2c48);15 expect(@bitreverse(u16, 0x1234) == 0x2c48);
16 assertOrPanic(@bitreverse(u24, 0x123456) == 0x6a2c48);16 expect(@bitreverse(u24, 0x123456) == 0x6a2c48);
17 assertOrPanic(@bitreverse(u32, 0x12345678) == 0x1e6a2c48);17 expect(@bitreverse(u32, 0x12345678) == 0x1e6a2c48);
18 assertOrPanic(@bitreverse(u40, 0x123456789a) == 0x591e6a2c48);18 expect(@bitreverse(u40, 0x123456789a) == 0x591e6a2c48);
19 assertOrPanic(@bitreverse(u48, 0x123456789abc) == 0x3d591e6a2c48);19 expect(@bitreverse(u48, 0x123456789abc) == 0x3d591e6a2c48);
20 assertOrPanic(@bitreverse(u56, 0x123456789abcde) == 0x7b3d591e6a2c48);20 expect(@bitreverse(u56, 0x123456789abcde) == 0x7b3d591e6a2c48);
21 assertOrPanic(@bitreverse(u64, 0x123456789abcdef1) == 0x8f7b3d591e6a2c48);21 expect(@bitreverse(u64, 0x123456789abcdef1) == 0x8f7b3d591e6a2c48);
22 assertOrPanic(@bitreverse(u128, 0x123456789abcdef11121314151617181) == 0x818e868a828c84888f7b3d591e6a2c48);22 expect(@bitreverse(u128, 0x123456789abcdef11121314151617181) == 0x818e868a828c84888f7b3d591e6a2c48);
2323
24 // using runtime uints, unsigned24 // using runtime uints, unsigned
25 var num0: u0 = 0;25 var num0: u0 = 0;
26 assertOrPanic(@bitreverse(u0, num0) == 0);26 expect(@bitreverse(u0, num0) == 0);
27 var num5: u5 = 0x12;27 var num5: u5 = 0x12;
28 assertOrPanic(@bitreverse(u5, num5) == 0x9);28 expect(@bitreverse(u5, num5) == 0x9);
29 var num8: u8 = 0x12;29 var num8: u8 = 0x12;
30 assertOrPanic(@bitreverse(u8, num8) == 0x48);30 expect(@bitreverse(u8, num8) == 0x48);
31 var num16: u16 = 0x1234;31 var num16: u16 = 0x1234;
32 assertOrPanic(@bitreverse(u16, num16) == 0x2c48);32 expect(@bitreverse(u16, num16) == 0x2c48);
33 var num24: u24 = 0x123456;33 var num24: u24 = 0x123456;
34 assertOrPanic(@bitreverse(u24, num24) == 0x6a2c48);34 expect(@bitreverse(u24, num24) == 0x6a2c48);
35 var num32: u32 = 0x12345678;35 var num32: u32 = 0x12345678;
36 assertOrPanic(@bitreverse(u32, num32) == 0x1e6a2c48);36 expect(@bitreverse(u32, num32) == 0x1e6a2c48);
37 var num40: u40 = 0x123456789a;37 var num40: u40 = 0x123456789a;
38 assertOrPanic(@bitreverse(u40, num40) == 0x591e6a2c48);38 expect(@bitreverse(u40, num40) == 0x591e6a2c48);
39 var num48: u48 = 0x123456789abc;39 var num48: u48 = 0x123456789abc;
40 assertOrPanic(@bitreverse(u48, num48) == 0x3d591e6a2c48);40 expect(@bitreverse(u48, num48) == 0x3d591e6a2c48);
41 var num56: u56 = 0x123456789abcde;41 var num56: u56 = 0x123456789abcde;
42 assertOrPanic(@bitreverse(u56, num56) == 0x7b3d591e6a2c48);42 expect(@bitreverse(u56, num56) == 0x7b3d591e6a2c48);
43 var num64: u64 = 0x123456789abcdef1;43 var num64: u64 = 0x123456789abcdef1;
44 assertOrPanic(@bitreverse(u64, num64) == 0x8f7b3d591e6a2c48);44 expect(@bitreverse(u64, num64) == 0x8f7b3d591e6a2c48);
45 var num128: u128 = 0x123456789abcdef11121314151617181;45 var num128: u128 = 0x123456789abcdef11121314151617181;
46 assertOrPanic(@bitreverse(u128, num128) == 0x818e868a828c84888f7b3d591e6a2c48);46 expect(@bitreverse(u128, num128) == 0x818e868a828c84888f7b3d591e6a2c48);
4747
48 // using comptime_ints, signed, positive48 // using comptime_ints, signed, positive
49 assertOrPanic(@bitreverse(i0, 0) == 0);49 expect(@bitreverse(i0, 0) == 0);
50 assertOrPanic(@bitreverse(i8, @bitCast(i8, u8(0x92))) == @bitCast(i8, u8(0x49)));50 expect(@bitreverse(i8, @bitCast(i8, u8(0x92))) == @bitCast(i8, u8(0x49)));
51 assertOrPanic(@bitreverse(i16, @bitCast(i16, u16(0x1234))) == @bitCast(i16, u16(0x2c48)));51 expect(@bitreverse(i16, @bitCast(i16, u16(0x1234))) == @bitCast(i16, u16(0x2c48)));
52 assertOrPanic(@bitreverse(i24, @bitCast(i24, u24(0x123456))) == @bitCast(i24, u24(0x6a2c48)));52 expect(@bitreverse(i24, @bitCast(i24, u24(0x123456))) == @bitCast(i24, u24(0x6a2c48)));
53 assertOrPanic(@bitreverse(i32, @bitCast(i32, u32(0x12345678))) == @bitCast(i32, u32(0x1e6a2c48)));53 expect(@bitreverse(i32, @bitCast(i32, u32(0x12345678))) == @bitCast(i32, u32(0x1e6a2c48)));
54 assertOrPanic(@bitreverse(i40, @bitCast(i40, u40(0x123456789a))) == @bitCast(i40, u40(0x591e6a2c48)));54 expect(@bitreverse(i40, @bitCast(i40, u40(0x123456789a))) == @bitCast(i40, u40(0x591e6a2c48)));
55 assertOrPanic(@bitreverse(i48, @bitCast(i48, u48(0x123456789abc))) == @bitCast(i48, u48(0x3d591e6a2c48)));55 expect(@bitreverse(i48, @bitCast(i48, u48(0x123456789abc))) == @bitCast(i48, u48(0x3d591e6a2c48)));
56 assertOrPanic(@bitreverse(i56, @bitCast(i56, u56(0x123456789abcde))) == @bitCast(i56, u56(0x7b3d591e6a2c48)));56 expect(@bitreverse(i56, @bitCast(i56, u56(0x123456789abcde))) == @bitCast(i56, u56(0x7b3d591e6a2c48)));
57 assertOrPanic(@bitreverse(i64, @bitCast(i64, u64(0x123456789abcdef1))) == @bitCast(i64, u64(0x8f7b3d591e6a2c48)));57 expect(@bitreverse(i64, @bitCast(i64, u64(0x123456789abcdef1))) == @bitCast(i64, u64(0x8f7b3d591e6a2c48)));
58 assertOrPanic(@bitreverse(i128, @bitCast(i128, u128(0x123456789abcdef11121314151617181))) == @bitCast(i128, u128(0x818e868a828c84888f7b3d591e6a2c48)));58 expect(@bitreverse(i128, @bitCast(i128, u128(0x123456789abcdef11121314151617181))) == @bitCast(i128, u128(0x818e868a828c84888f7b3d591e6a2c48)));
5959
60 // using comptime_ints, signed, negative. Compare to runtime ints returned from llvm.60 // using comptime_ints, signed, negative. Compare to runtime ints returned from llvm.
61 var neg5: i5 = minInt(i5) + 1;61 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));
63 var neg8: i8 = -18;63 var neg8: i8 = -18;
64 assertOrPanic(@bitreverse(i8, -18) == @bitreverse(i8, neg8));64 expect(@bitreverse(i8, -18) == @bitreverse(i8, neg8));
65 var neg16: i16 = -32694;65 var neg16: i16 = -32694;
66 assertOrPanic(@bitreverse(i16, -32694) == @bitreverse(i16, neg16));66 expect(@bitreverse(i16, -32694) == @bitreverse(i16, neg16));
67 var neg24: i24 = -6773785;67 var neg24: i24 = -6773785;
68 assertOrPanic(@bitreverse(i24, -6773785) == @bitreverse(i24, neg24));68 expect(@bitreverse(i24, -6773785) == @bitreverse(i24, neg24));
69 var neg32: i32 = -16773785;69 var neg32: i32 = -16773785;
70 assertOrPanic(@bitreverse(i32, -16773785) == @bitreverse(i32, neg32));70 expect(@bitreverse(i32, -16773785) == @bitreverse(i32, neg32));
71 var neg40: i40 = minInt(i40) + 12345;71 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));
73 var neg48: i48 = minInt(i48) + 12345;73 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));
75 var neg56: i56 = minInt(i56) + 12345;75 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));
77 var neg64: i64 = minInt(i64) + 12345;77 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));
79 var neg128: i128 = minInt(i128) + 12345;79 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));
81}81}
test/stage1/behavior/bool.zig+10-10
...@@ -1,25 +1,25 @@...@@ -1,25 +1,25 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;1const expect = @import("std").testing.expect;
22
3test "bool literals" {3test "bool literals" {
4 assertOrPanic(true);4 expect(true);
5 assertOrPanic(!false);5 expect(!false);
6}6}
77
8test "cast bool to int" {8test "cast bool to int" {
9 const t = true;9 const t = true;
10 const f = false;10 const f = false;
11 assertOrPanic(@boolToInt(t) == u32(1));11 expect(@boolToInt(t) == u32(1));
12 assertOrPanic(@boolToInt(f) == u32(0));12 expect(@boolToInt(f) == u32(0));
13 nonConstCastBoolToInt(t, f);13 nonConstCastBoolToInt(t, f);
14}14}
1515
16fn nonConstCastBoolToInt(t: bool, f: bool) void {16fn nonConstCastBoolToInt(t: bool, f: bool) void {
17 assertOrPanic(@boolToInt(t) == u32(1));17 expect(@boolToInt(t) == u32(1));
18 assertOrPanic(@boolToInt(f) == u32(0));18 expect(@boolToInt(f) == u32(0));
19}19}
2020
21test "bool cmp" {21test "bool cmp" {
22 assertOrPanic(testBoolCmp(true, false) == false);22 expect(testBoolCmp(true, false) == false);
23}23}
24fn testBoolCmp(a: bool, b: bool) bool {24fn testBoolCmp(a: bool, b: bool) bool {
25 return a == b;25 return a == b;
...@@ -30,6 +30,6 @@ const global_t = true;...@@ -30,6 +30,6 @@ const global_t = true;
30const not_global_f = !global_f;30const not_global_f = !global_f;
31const not_global_t = !global_t;31const not_global_t = !global_t;
32test "compile time bool not" {32test "compile time bool not" {
33 assertOrPanic(not_global_f);33 expect(not_global_f);
34 assertOrPanic(!not_global_t);34 expect(!not_global_t);
35}35}
test/stage1/behavior/bswap.zig+21-21
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const assertOrPanic = std.debug.assertOrPanic;2const expect = std.testing.expect;
33
4test "@bswap" {4test "@bswap" {
5 comptime testByteSwap();5 comptime testByteSwap();
...@@ -7,26 +7,26 @@ test "@bswap" {...@@ -7,26 +7,26 @@ test "@bswap" {
7}7}
88
9fn testByteSwap() void {9fn testByteSwap() void {
10 assertOrPanic(@bswap(u0, 0) == 0);10 expect(@bswap(u0, 0) == 0);
11 assertOrPanic(@bswap(u8, 0x12) == 0x12);11 expect(@bswap(u8, 0x12) == 0x12);
12 assertOrPanic(@bswap(u16, 0x1234) == 0x3412);12 expect(@bswap(u16, 0x1234) == 0x3412);
13 assertOrPanic(@bswap(u24, 0x123456) == 0x563412);13 expect(@bswap(u24, 0x123456) == 0x563412);
14 assertOrPanic(@bswap(u32, 0x12345678) == 0x78563412);14 expect(@bswap(u32, 0x12345678) == 0x78563412);
15 assertOrPanic(@bswap(u40, 0x123456789a) == 0x9a78563412);15 expect(@bswap(u40, 0x123456789a) == 0x9a78563412);
16 assertOrPanic(@bswap(u48, 0x123456789abc) == 0xbc9a78563412);16 expect(@bswap(u48, 0x123456789abc) == 0xbc9a78563412);
17 assertOrPanic(@bswap(u56, 0x123456789abcde) == 0xdebc9a78563412);17 expect(@bswap(u56, 0x123456789abcde) == 0xdebc9a78563412);
18 assertOrPanic(@bswap(u64, 0x123456789abcdef1) == 0xf1debc9a78563412);18 expect(@bswap(u64, 0x123456789abcdef1) == 0xf1debc9a78563412);
19 assertOrPanic(@bswap(u128, 0x123456789abcdef11121314151617181) == 0x8171615141312111f1debc9a78563412);19 expect(@bswap(u128, 0x123456789abcdef11121314151617181) == 0x8171615141312111f1debc9a78563412);
2020
21 assertOrPanic(@bswap(i0, 0) == 0);21 expect(@bswap(i0, 0) == 0);
22 assertOrPanic(@bswap(i8, -50) == -50);22 expect(@bswap(i8, -50) == -50);
23 assertOrPanic(@bswap(i16, @bitCast(i16, u16(0x1234))) == @bitCast(i16, u16(0x3412)));23 expect(@bswap(i16, @bitCast(i16, u16(0x1234))) == @bitCast(i16, u16(0x3412)));
24 assertOrPanic(@bswap(i24, @bitCast(i24, u24(0x123456))) == @bitCast(i24, u24(0x563412)));24 expect(@bswap(i24, @bitCast(i24, u24(0x123456))) == @bitCast(i24, u24(0x563412)));
25 assertOrPanic(@bswap(i32, @bitCast(i32, u32(0x12345678))) == @bitCast(i32, u32(0x78563412)));25 expect(@bswap(i32, @bitCast(i32, u32(0x12345678))) == @bitCast(i32, u32(0x78563412)));
26 assertOrPanic(@bswap(i40, @bitCast(i40, u40(0x123456789a))) == @bitCast(i40, u40(0x9a78563412)));26 expect(@bswap(i40, @bitCast(i40, u40(0x123456789a))) == @bitCast(i40, u40(0x9a78563412)));
27 assertOrPanic(@bswap(i48, @bitCast(i48, u48(0x123456789abc))) == @bitCast(i48, u48(0xbc9a78563412)));27 expect(@bswap(i48, @bitCast(i48, u48(0x123456789abc))) == @bitCast(i48, u48(0xbc9a78563412)));
28 assertOrPanic(@bswap(i56, @bitCast(i56, u56(0x123456789abcde))) == @bitCast(i56, u56(0xdebc9a78563412)));28 expect(@bswap(i56, @bitCast(i56, u56(0x123456789abcde))) == @bitCast(i56, u56(0xdebc9a78563412)));
29 assertOrPanic(@bswap(i64, @bitCast(i64, u64(0x123456789abcdef1))) == @bitCast(i64, u64(0xf1debc9a78563412)));29 expect(@bswap(i64, @bitCast(i64, u64(0x123456789abcdef1))) == @bitCast(i64, u64(0xf1debc9a78563412)));
30 assertOrPanic(@bswap(i128, @bitCast(i128, u128(0x123456789abcdef11121314151617181))) ==30 expect(@bswap(i128, @bitCast(i128, u128(0x123456789abcdef11121314151617181))) ==
31 @bitCast(i128, u128(0x8171615141312111f1debc9a78563412)));31 @bitCast(i128, u128(0x8171615141312111f1debc9a78563412)));
32}32}
test/stage1/behavior/bugs/1076.zig+2-2
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const std = @import("std");1const std = @import("std");
2const mem = std.mem;2const mem = std.mem;
3const assertOrPanic = std.debug.assertOrPanic;3const expect = std.testing.expect;
44
5test "comptime code should not modify constant data" {5test "comptime code should not modify constant data" {
6 testCastPtrOfArrayToSliceAndPtr();6 testCastPtrOfArrayToSliceAndPtr();
...@@ -11,6 +11,6 @@ fn testCastPtrOfArrayToSliceAndPtr() void {...@@ -11,6 +11,6 @@ fn testCastPtrOfArrayToSliceAndPtr() void {
11 var array = "aoeu";11 var array = "aoeu";
12 const x: [*]u8 = &array;12 const x: [*]u8 = &array;
13 x[0] += 1;13 x[0] += 1;
14 assertOrPanic(mem.eql(u8, array[0..], "boeu"));14 expect(mem.eql(u8, array[0..], "boeu"));
15}15}
1616
test/stage1/behavior/bugs/1277.zig+1-1
...@@ -11,5 +11,5 @@ fn f() i32 {...@@ -11,5 +11,5 @@ fn f() i32 {
11}11}
1212
13test "don't emit an LLVM global for a const function when it's in an optional in a struct" {13test "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);
15}15}
test/stage1/behavior/bugs/1322.zig+2-2
...@@ -13,7 +13,7 @@ const C = struct {};...@@ -13,7 +13,7 @@ const C = struct {};
1313
14test "tagged union with all void fields but a meaningful tag" {14test "tagged union with all void fields but a meaningful tag" {
15 var a: A = A{ .b = B{ .c = C{} } };15 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);
17 a = A{ .b = B.None };17 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);
19}19}
test/stage1/behavior/bugs/1381.zig+1-1
...@@ -17,5 +17,5 @@ test "union that needs padding bytes inside an array" {...@@ -17,5 +17,5 @@ test "union that needs padding bytes inside an array" {
17 };17 };
1818
19 const a = as[0].B;19 const a = as[0].B;
20 std.debug.assertOrPanic(a.D == 1);20 std.testing.expect(a.D == 1);
21}21}
test/stage1/behavior/bugs/1421.zig+2-2
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const assertOrPanic = std.debug.assertOrPanic;3const expect = std.testing.expect;
44
5const S = struct {5const S = struct {
6 fn method() builtin.TypeInfo {6 fn method() builtin.TypeInfo {
...@@ -10,5 +10,5 @@ const S = struct {...@@ -10,5 +10,5 @@ const S = struct {
1010
11test "functions with return type required to be comptime are generic" {11test "functions with return type required to be comptime are generic" {
12 const ti = S.method();12 const ti = S.method();
13 assertOrPanic(builtin.TypeId(ti) == builtin.TypeId.Struct);13 expect(builtin.TypeId(ti) == builtin.TypeId.Struct);
14}14}
test/stage1/behavior/bugs/1442.zig+1-1
...@@ -7,5 +7,5 @@ const Union = union(enum) {...@@ -7,5 +7,5 @@ const Union = union(enum) {
77
8test "const error union field alignment" {8test "const error union field alignment" {
9 var union_or_err: anyerror!Union = Union{ .Color = 1234 };9 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);
11}11}
test/stage1/behavior/bugs/1486.zig+3-3
...@@ -1,11 +1,11 @@...@@ -1,11 +1,11 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;1const expect = @import("std").testing.expect;
22
3const ptr = &global;3const ptr = &global;
4var global: u64 = 123;4var global: u64 = 123;
55
6test "constant pointer to global variable causes runtime load" {6test "constant pointer to global variable causes runtime load" {
7 global = 1234;7 global = 1234;
8 assertOrPanic(&global == ptr);8 expect(&global == ptr);
9 assertOrPanic(ptr.* == 1234);9 expect(ptr.* == 1234);
10}10}
1111
test/stage1/behavior/bugs/394.zig+2-2
...@@ -7,12 +7,12 @@ const S = struct {...@@ -7,12 +7,12 @@ const S = struct {
7 y: E,7 y: E,
8};8};
99
10const assertOrPanic = @import("std").debug.assertOrPanic;10const expect = @import("std").testing.expect;
1111
12test "bug 394 fixed" {12test "bug 394 fixed" {
13 const x = S{13 const x = S{
14 .x = 3,14 .x = 3,
15 .y = E{ .B = 1 },15 .y = E{ .B = 1 },
16 };16 };
17 assertOrPanic(x.x == 3);17 expect(x.x == 3);
18}18}
test/stage1/behavior/bugs/655.zig+2-2
...@@ -3,10 +3,10 @@ const other_file = @import("655_other_file.zig");...@@ -3,10 +3,10 @@ const other_file = @import("655_other_file.zig");
33
4test "function with *const parameter with type dereferenced by namespace" {4test "function with *const parameter with type dereferenced by namespace" {
5 const x: other_file.Integer = 1234;5 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);
7 foo(&x);7 foo(&x);
8}8}
99
10fn foo(x: *const other_file.Integer) void {10fn foo(x: *const other_file.Integer) void {
11 std.debug.assertOrPanic(x.* == 1234);11 std.testing.expect(x.* == 1234);
12}12}
test/stage1/behavior/bugs/656.zig+2-2
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;1const expect = @import("std").testing.expect;
22
3const PrefixOp = union(enum) {3const PrefixOp = union(enum) {
4 Return,4 Return,
...@@ -22,7 +22,7 @@ fn foo(a: bool, b: bool) void {...@@ -22,7 +22,7 @@ fn foo(a: bool, b: bool) void {
22 PrefixOp.AddrOf => |addr_of_info| {22 PrefixOp.AddrOf => |addr_of_info| {
23 if (b) {}23 if (b) {}
24 if (addr_of_info.align_expr) |align_expr| {24 if (addr_of_info.align_expr) |align_expr| {
25 assertOrPanic(align_expr == 1234);25 expect(align_expr == 1234);
26 }26 }
27 },27 },
28 PrefixOp.Return => {},28 PrefixOp.Return => {},
test/stage1/behavior/bugs/726.zig+3-3
...@@ -1,9 +1,9 @@...@@ -1,9 +1,9 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;1const expect = @import("std").testing.expect;
22
3test "@ptrCast from const to nullable" {3test "@ptrCast from const to nullable" {
4 const c: u8 = 4;4 const c: u8 = 4;
5 var x: ?*const u8 = @ptrCast(?*const u8, &c);5 var x: ?*const u8 = @ptrCast(?*const u8, &c);
6 assertOrPanic(x.?.* == 4);6 expect(x.?.* == 4);
7}7}
88
9test "@ptrCast from var in empty struct to nullable" {9test "@ptrCast from var in empty struct to nullable" {
...@@ -11,6 +11,6 @@ test "@ptrCast from var in empty struct to nullable" {...@@ -11,6 +11,6 @@ test "@ptrCast from var in empty struct to nullable" {
11 var c: u8 = 4;11 var c: u8 = 4;
12 };12 };
13 var x: ?*const u8 = @ptrCast(?*const u8, &container.c);13 var x: ?*const u8 = @ptrCast(?*const u8, &container.c);
14 assertOrPanic(x.?.* == 4);14 expect(x.?.* == 4);
15}15}
1616
test/stage1/behavior/bugs/920.zig+1-1
...@@ -60,6 +60,6 @@ test "bug 920 fixed" {...@@ -60,6 +60,6 @@ test "bug 920 fixed" {
60 };60 };
6161
62 for (NormalDist1.f) |_, i| {62 for (NormalDist1.f) |_, i| {
63 std.debug.assertOrPanic(NormalDist1.f[i] == NormalDist.f[i]);63 std.testing.expect(NormalDist1.f[i] == NormalDist.f[i]);
64 }64 }
65}65}
test/stage1/behavior/byval_arg_var.zig+1-1
...@@ -6,7 +6,7 @@ test "pass string literal byvalue to a generic var param" {...@@ -6,7 +6,7 @@ test "pass string literal byvalue to a generic var param" {
6 start();6 start();
7 blowUpStack(10);7 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"));
10}10}
1111
12fn start() void {12fn start() void {
test/stage1/behavior/cancel.zig+7-7
...@@ -10,9 +10,9 @@ test "cancel forwards" {...@@ -10,9 +10,9 @@ test "cancel forwards" {
1010
11 const p = async<&da.allocator> f1() catch unreachable;11 const p = async<&da.allocator> f1() catch unreachable;
12 cancel p;12 cancel p;
13 std.debug.assertOrPanic(defer_f1);13 std.testing.expect(defer_f1);
14 std.debug.assertOrPanic(defer_f2);14 std.testing.expect(defer_f2);
15 std.debug.assertOrPanic(defer_f3);15 std.testing.expect(defer_f3);
16}16}
1717
18async fn f1() void {18async fn f1() void {
...@@ -47,10 +47,10 @@ test "cancel backwards" {...@@ -47,10 +47,10 @@ test "cancel backwards" {
4747
48 const p = async<&da.allocator> b1() catch unreachable;48 const p = async<&da.allocator> b1() catch unreachable;
49 cancel p;49 cancel p;
50 std.debug.assertOrPanic(defer_b1);50 std.testing.expect(defer_b1);
51 std.debug.assertOrPanic(defer_b2);51 std.testing.expect(defer_b2);
52 std.debug.assertOrPanic(defer_b3);52 std.testing.expect(defer_b3);
53 std.debug.assertOrPanic(defer_b4);53 std.testing.expect(defer_b4);
54}54}
5555
56async fn b1() void {56async fn b1() void {
test/stage1/behavior/cast.zig+88-77
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const assertOrPanic = std.debug.assertOrPanic;2const expect = std.testing.expect;
3const mem = std.mem;3const mem = std.mem;
4const maxInt = std.math.maxInt;4const maxInt = std.math.maxInt;
55
...@@ -7,12 +7,12 @@ test "int to ptr cast" {...@@ -7,12 +7,12 @@ test "int to ptr cast" {
7 const x = usize(13);7 const x = usize(13);
8 const y = @intToPtr(*u8, x);8 const y = @intToPtr(*u8, x);
9 const z = @ptrToInt(y);9 const z = @ptrToInt(y);
10 assertOrPanic(z == 13);10 expect(z == 13);
11}11}
1212
13test "integer literal to pointer cast" {13test "integer literal to pointer cast" {
14 const vga_mem = @intToPtr(*u16, 0xB8000);14 const vga_mem = @intToPtr(*u16, 0xB8000);
15 assertOrPanic(@ptrToInt(vga_mem) == 0xB8000);15 expect(@ptrToInt(vga_mem) == 0xB8000);
16}16}
1717
18test "pointer reinterpret const float to int" {18test "pointer reinterpret const float to int" {
...@@ -20,7 +20,7 @@ test "pointer reinterpret const float to int" {...@@ -20,7 +20,7 @@ test "pointer reinterpret const float to int" {
20 const float_ptr = &float;20 const float_ptr = &float;
21 const int_ptr = @ptrCast(*const i32, float_ptr);21 const int_ptr = @ptrCast(*const i32, float_ptr);
22 const int_val = int_ptr.*;22 const int_val = int_ptr.*;
23 assertOrPanic(int_val == 858993411);23 expect(int_val == 858993411);
24}24}
2525
26test "implicitly cast indirect pointer to maybe-indirect pointer" {26test "implicitly cast indirect pointer to maybe-indirect pointer" {
...@@ -44,10 +44,10 @@ test "implicitly cast indirect pointer to maybe-indirect pointer" {...@@ -44,10 +44,10 @@ test "implicitly cast indirect pointer to maybe-indirect pointer" {
44 const p = &s;44 const p = &s;
45 const q = &p;45 const q = &p;
46 const r = &q;46 const r = &q;
47 assertOrPanic(42 == S.constConst(q));47 expect(42 == S.constConst(q));
48 assertOrPanic(42 == S.maybeConstConst(q));48 expect(42 == S.maybeConstConst(q));
49 assertOrPanic(42 == S.constConstConst(r));49 expect(42 == S.constConstConst(r));
50 assertOrPanic(42 == S.maybeConstConstConst(r));50 expect(42 == S.maybeConstConstConst(r));
51}51}
5252
53test "explicit cast from integer to error type" {53test "explicit cast from integer to error type" {
...@@ -57,14 +57,14 @@ test "explicit cast from integer to error type" {...@@ -57,14 +57,14 @@ test "explicit cast from integer to error type" {
57fn testCastIntToErr(err: anyerror) void {57fn testCastIntToErr(err: anyerror) void {
58 const x = @errorToInt(err);58 const x = @errorToInt(err);
59 const y = @intToError(x);59 const y = @intToError(x);
60 assertOrPanic(error.ItBroke == y);60 expect(error.ItBroke == y);
61}61}
6262
63test "peer resolve arrays of different size to const slice" {63test "peer resolve arrays of different size to const slice" {
64 assertOrPanic(mem.eql(u8, boolToStr(true), "true"));64 expect(mem.eql(u8, boolToStr(true), "true"));
65 assertOrPanic(mem.eql(u8, boolToStr(false), "false"));65 expect(mem.eql(u8, boolToStr(false), "false"));
66 comptime assertOrPanic(mem.eql(u8, boolToStr(true), "true"));66 comptime expect(mem.eql(u8, boolToStr(true), "true"));
67 comptime assertOrPanic(mem.eql(u8, boolToStr(false), "false"));67 comptime expect(mem.eql(u8, boolToStr(false), "false"));
68}68}
69fn boolToStr(b: bool) []const u8 {69fn boolToStr(b: bool) []const u8 {
70 return if (b) "true" else "false";70 return if (b) "true" else "false";
...@@ -77,8 +77,8 @@ test "peer resolve array and const slice" {...@@ -77,8 +77,8 @@ test "peer resolve array and const slice" {
77fn testPeerResolveArrayConstSlice(b: bool) void {77fn testPeerResolveArrayConstSlice(b: bool) void {
78 const value1 = if (b) "aoeu" else ([]const u8)("zz");78 const value1 = if (b) "aoeu" else ([]const u8)("zz");
79 const value2 = if (b) ([]const u8)("zz") else "aoeu";79 const value2 = if (b) ([]const u8)("zz") else "aoeu";
80 assertOrPanic(mem.eql(u8, value1, "aoeu"));80 expect(mem.eql(u8, value1, "aoeu"));
81 assertOrPanic(mem.eql(u8, value2, "zz"));81 expect(mem.eql(u8, value2, "zz"));
82}82}
8383
84test "implicitly cast from T to anyerror!?T" {84test "implicitly cast from T to anyerror!?T" {
...@@ -92,14 +92,14 @@ const A = struct {...@@ -92,14 +92,14 @@ const A = struct {
92fn castToOptionalTypeError(z: i32) void {92fn castToOptionalTypeError(z: i32) void {
93 const x = i32(1);93 const x = i32(1);
94 const y: anyerror!?i32 = x;94 const y: anyerror!?i32 = x;
95 assertOrPanic((try y).? == 1);95 expect((try y).? == 1);
9696
97 const f = z;97 const f = z;
98 const g: anyerror!?i32 = f;98 const g: anyerror!?i32 = f;
9999
100 const a = A{ .a = z };100 const a = A{ .a = z };
101 const b: anyerror!?A = a;101 const b: anyerror!?A = a;
102 assertOrPanic((b catch unreachable).?.a == 1);102 expect((b catch unreachable).?.a == 1);
103}103}
104104
105test "implicitly cast from int to anyerror!?T" {105test "implicitly cast from int to anyerror!?T" {
...@@ -114,7 +114,7 @@ fn implicitIntLitToOptional() void {...@@ -114,7 +114,7 @@ fn implicitIntLitToOptional() void {
114test "return null from fn() anyerror!?&T" {114test "return null from fn() anyerror!?&T" {
115 const a = returnNullFromOptionalTypeErrorRef();115 const a = returnNullFromOptionalTypeErrorRef();
116 const b = returnNullLitFromOptionalTypeErrorRef();116 const b = returnNullLitFromOptionalTypeErrorRef();
117 assertOrPanic((try a) == null and (try b) == null);117 expect((try a) == null and (try b) == null);
118}118}
119fn returnNullFromOptionalTypeErrorRef() anyerror!?*A {119fn returnNullFromOptionalTypeErrorRef() anyerror!?*A {
120 const a: ?*A = null;120 const a: ?*A = null;
...@@ -125,11 +125,11 @@ fn returnNullLitFromOptionalTypeErrorRef() anyerror!?*A {...@@ -125,11 +125,11 @@ fn returnNullLitFromOptionalTypeErrorRef() anyerror!?*A {
125}125}
126126
127test "peer type resolution: ?T and T" {127test "peer type resolution: ?T and T" {
128 assertOrPanic(peerTypeTAndOptionalT(true, false).? == 0);128 expect(peerTypeTAndOptionalT(true, false).? == 0);
129 assertOrPanic(peerTypeTAndOptionalT(false, false).? == 3);129 expect(peerTypeTAndOptionalT(false, false).? == 3);
130 comptime {130 comptime {
131 assertOrPanic(peerTypeTAndOptionalT(true, false).? == 0);131 expect(peerTypeTAndOptionalT(true, false).? == 0);
132 assertOrPanic(peerTypeTAndOptionalT(false, false).? == 3);132 expect(peerTypeTAndOptionalT(false, false).? == 3);
133 }133 }
134}134}
135fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize {135fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize {
...@@ -141,11 +141,11 @@ fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize {...@@ -141,11 +141,11 @@ fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize {
141}141}
142142
143test "peer type resolution: [0]u8 and []const u8" {143test "peer type resolution: [0]u8 and []const u8" {
144 assertOrPanic(peerTypeEmptyArrayAndSlice(true, "hi").len == 0);144 expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0);
145 assertOrPanic(peerTypeEmptyArrayAndSlice(false, "hi").len == 1);145 expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1);
146 comptime {146 comptime {
147 assertOrPanic(peerTypeEmptyArrayAndSlice(true, "hi").len == 0);147 expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0);
148 assertOrPanic(peerTypeEmptyArrayAndSlice(false, "hi").len == 1);148 expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1);
149 }149 }
150}150}
151fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 {151fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 {
...@@ -157,8 +157,8 @@ fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 {...@@ -157,8 +157,8 @@ fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 {
157}157}
158158
159test "implicitly cast from [N]T to ?[]const T" {159test "implicitly cast from [N]T to ?[]const T" {
160 assertOrPanic(mem.eql(u8, castToOptionalSlice().?, "hi"));160 expect(mem.eql(u8, castToOptionalSlice().?, "hi"));
161 comptime assertOrPanic(mem.eql(u8, castToOptionalSlice().?, "hi"));161 comptime expect(mem.eql(u8, castToOptionalSlice().?, "hi"));
162}162}
163163
164fn castToOptionalSlice() ?[]const u8 {164fn castToOptionalSlice() ?[]const u8 {
...@@ -171,7 +171,7 @@ test "implicitly cast from [0]T to anyerror![]T" {...@@ -171,7 +171,7 @@ test "implicitly cast from [0]T to anyerror![]T" {
171}171}
172172
173fn testCastZeroArrayToErrSliceMut() void {173fn testCastZeroArrayToErrSliceMut() void {
174 assertOrPanic((gimmeErrOrSlice() catch unreachable).len == 0);174 expect((gimmeErrOrSlice() catch unreachable).len == 0);
175}175}
176176
177fn gimmeErrOrSlice() anyerror![]u8 {177fn gimmeErrOrSlice() anyerror![]u8 {
...@@ -182,14 +182,14 @@ test "peer type resolution: [0]u8, []const u8, and anyerror![]u8" {...@@ -182,14 +182,14 @@ test "peer type resolution: [0]u8, []const u8, and anyerror![]u8" {
182 {182 {
183 var data = "hi";183 var data = "hi";
184 const slice = data[0..];184 const slice = data[0..];
185 assertOrPanic((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);185 expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
186 assertOrPanic((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);186 expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
187 }187 }
188 comptime {188 comptime {
189 var data = "hi";189 var data = "hi";
190 const slice = data[0..];190 const slice = data[0..];
191 assertOrPanic((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);191 expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
192 assertOrPanic((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);192 expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
193 }193 }
194}194}
195fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 {195fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 {
...@@ -207,7 +207,7 @@ test "resolve undefined with integer" {...@@ -207,7 +207,7 @@ test "resolve undefined with integer" {
207fn testResolveUndefWithInt(b: bool, x: i32) void {207fn testResolveUndefWithInt(b: bool, x: i32) void {
208 const value = if (b) x else undefined;208 const value = if (b) x else undefined;
209 if (b) {209 if (b) {
210 assertOrPanic(value == x);210 expect(value == x);
211 }211 }
212}212}
213213
...@@ -219,17 +219,17 @@ test "implicit cast from &const [N]T to []const T" {...@@ -219,17 +219,17 @@ test "implicit cast from &const [N]T to []const T" {
219fn testCastConstArrayRefToConstSlice() void {219fn testCastConstArrayRefToConstSlice() void {
220 const blah = "aoeu";220 const blah = "aoeu";
221 const const_array_ref = &blah;221 const const_array_ref = &blah;
222 assertOrPanic(@typeOf(const_array_ref) == *const [4]u8);222 expect(@typeOf(const_array_ref) == *const [4]u8);
223 const slice: []const u8 = const_array_ref;223 const slice: []const u8 = const_array_ref;
224 assertOrPanic(mem.eql(u8, slice, "aoeu"));224 expect(mem.eql(u8, slice, "aoeu"));
225}225}
226226
227test "peer type resolution: error and [N]T" {227test "peer type resolution: error and [N]T" {
228 // TODO: implicit error!T to error!U where T can implicitly cast to U228 // TODO: implicit error!T to error!U where T can implicitly cast to U
229 //assertOrPanic(mem.eql(u8, try testPeerErrorAndArray(0), "OK"));229 //expect(mem.eql(u8, try testPeerErrorAndArray(0), "OK"));
230 //comptime assertOrPanic(mem.eql(u8, try testPeerErrorAndArray(0), "OK"));230 //comptime expect(mem.eql(u8, try testPeerErrorAndArray(0), "OK"));
231 assertOrPanic(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK"));231 expect(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK"));
232 comptime assertOrPanic(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK"));232 comptime expect(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK"));
233}233}
234234
235//fn testPeerErrorAndArray(x: u8) error![]const u8 {235//fn testPeerErrorAndArray(x: u8) error![]const u8 {
...@@ -253,9 +253,9 @@ test "@floatToInt" {...@@ -253,9 +253,9 @@ test "@floatToInt" {
253253
254fn testFloatToInts() void {254fn testFloatToInts() void {
255 const x = i32(1e4);255 const x = i32(1e4);
256 assertOrPanic(x == 10000);256 expect(x == 10000);
257 const y = @floatToInt(i32, f32(1e4));257 const y = @floatToInt(i32, f32(1e4));
258 assertOrPanic(y == 10000);258 expect(y == 10000);
259 expectFloatToInt(f16, 255.1, u8, 255);259 expectFloatToInt(f16, 255.1, u8, 255);
260 expectFloatToInt(f16, 127.2, i8, 127);260 expectFloatToInt(f16, 127.2, i8, 127);
261 expectFloatToInt(f16, -128.2, i8, -128);261 expectFloatToInt(f16, -128.2, i8, -128);
...@@ -266,7 +266,7 @@ fn testFloatToInts() void {...@@ -266,7 +266,7 @@ fn testFloatToInts() void {
266}266}
267267
268fn expectFloatToInt(comptime F: type, f: F, comptime I: type, i: I) void {268fn expectFloatToInt(comptime F: type, f: F, comptime I: type, i: I) void {
269 assertOrPanic(@floatToInt(I, f) == i);269 expect(@floatToInt(I, f) == i);
270}270}
271271
272test "cast u128 to f128 and back" {272test "cast u128 to f128 and back" {
...@@ -275,7 +275,7 @@ test "cast u128 to f128 and back" {...@@ -275,7 +275,7 @@ test "cast u128 to f128 and back" {
275}275}
276276
277fn testCast128() void {277fn testCast128() void {
278 assertOrPanic(cast128Int(cast128Float(0x7fff0000000000000000000000000000)) == 0x7fff0000000000000000000000000000);278 expect(cast128Int(cast128Float(0x7fff0000000000000000000000000000)) == 0x7fff0000000000000000000000000000);
279}279}
280280
281fn cast128Int(x: f128) u128 {281fn cast128Int(x: f128) u128 {
...@@ -295,9 +295,9 @@ test "const slice widen cast" {...@@ -295,9 +295,9 @@ test "const slice widen cast" {
295 };295 };
296296
297 const u32_value = @bytesToSlice(u32, bytes[0..])[0];297 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);
301}301}
302302
303test "single-item pointer of array to slice and to unknown length pointer" {303test "single-item pointer of array to slice and to unknown length pointer" {
...@@ -309,76 +309,76 @@ fn testCastPtrOfArrayToSliceAndPtr() void {...@@ -309,76 +309,76 @@ fn testCastPtrOfArrayToSliceAndPtr() void {
309 var array = "aoeu";309 var array = "aoeu";
310 const x: [*]u8 = &array;310 const x: [*]u8 = &array;
311 x[0] += 1;311 x[0] += 1;
312 assertOrPanic(mem.eql(u8, array[0..], "boeu"));312 expect(mem.eql(u8, array[0..], "boeu"));
313 const y: []u8 = &array;313 const y: []u8 = &array;
314 y[0] += 1;314 y[0] += 1;
315 assertOrPanic(mem.eql(u8, array[0..], "coeu"));315 expect(mem.eql(u8, array[0..], "coeu"));
316}316}
317317
318test "cast *[1][*]const u8 to [*]const ?[*]const u8" {318test "cast *[1][*]const u8 to [*]const ?[*]const u8" {
319 const window_name = [1][*]const u8{c"window name"};319 const window_name = [1][*]const u8{c"window name"};
320 const x: [*]const ?[*]const u8 = &window_name;320 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"));
322}322}
323323
324test "@intCast comptime_int" {324test "@intCast comptime_int" {
325 const result = @intCast(i32, 1234);325 const result = @intCast(i32, 1234);
326 assertOrPanic(@typeOf(result) == i32);326 expect(@typeOf(result) == i32);
327 assertOrPanic(result == 1234);327 expect(result == 1234);
328}328}
329329
330test "@floatCast comptime_int and comptime_float" {330test "@floatCast comptime_int and comptime_float" {
331 {331 {
332 const result = @floatCast(f16, 1234);332 const result = @floatCast(f16, 1234);
333 assertOrPanic(@typeOf(result) == f16);333 expect(@typeOf(result) == f16);
334 assertOrPanic(result == 1234.0);334 expect(result == 1234.0);
335 }335 }
336 {336 {
337 const result = @floatCast(f16, 1234.0);337 const result = @floatCast(f16, 1234.0);
338 assertOrPanic(@typeOf(result) == f16);338 expect(@typeOf(result) == f16);
339 assertOrPanic(result == 1234.0);339 expect(result == 1234.0);
340 }340 }
341 {341 {
342 const result = @floatCast(f32, 1234);342 const result = @floatCast(f32, 1234);
343 assertOrPanic(@typeOf(result) == f32);343 expect(@typeOf(result) == f32);
344 assertOrPanic(result == 1234.0);344 expect(result == 1234.0);
345 }345 }
346 {346 {
347 const result = @floatCast(f32, 1234.0);347 const result = @floatCast(f32, 1234.0);
348 assertOrPanic(@typeOf(result) == f32);348 expect(@typeOf(result) == f32);
349 assertOrPanic(result == 1234.0);349 expect(result == 1234.0);
350 }350 }
351}351}
352352
353test "comptime_int @intToFloat" {353test "comptime_int @intToFloat" {
354 {354 {
355 const result = @intToFloat(f16, 1234);355 const result = @intToFloat(f16, 1234);
356 assertOrPanic(@typeOf(result) == f16);356 expect(@typeOf(result) == f16);
357 assertOrPanic(result == 1234.0);357 expect(result == 1234.0);
358 }358 }
359 {359 {
360 const result = @intToFloat(f32, 1234);360 const result = @intToFloat(f32, 1234);
361 assertOrPanic(@typeOf(result) == f32);361 expect(@typeOf(result) == f32);
362 assertOrPanic(result == 1234.0);362 expect(result == 1234.0);
363 }363 }
364}364}
365365
366test "@bytesToSlice keeps pointer alignment" {366test "@bytesToSlice keeps pointer alignment" {
367 var bytes = []u8{ 0x01, 0x02, 0x03, 0x04 };367 var bytes = []u8{ 0x01, 0x02, 0x03, 0x04 };
368 const numbers = @bytesToSlice(u32, bytes[0..]);368 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);
370}370}
371371
372test "@intCast i32 to u7" {372test "@intCast i32 to u7" {
373 var x: u128 = maxInt(u128);373 var x: u128 = maxInt(u128);
374 var y: i32 = 120;374 var y: i32 = 120;
375 var z = x >> @intCast(u7, y);375 var z = x >> @intCast(u7, y);
376 assertOrPanic(z == 0xff);376 expect(z == 0xff);
377}377}
378378
379test "implicit cast undefined to optional" {379test "implicit cast undefined to optional" {
380 assertOrPanic(MakeType(void).getNull() == null);380 expect(MakeType(void).getNull() == null);
381 assertOrPanic(MakeType(void).getNonNull() != null);381 expect(MakeType(void).getNonNull() != null);
382}382}
383383
384fn MakeType(comptime T: type) type {384fn MakeType(comptime T: type) type {
...@@ -398,16 +398,16 @@ test "implicit cast from *[N]T to ?[*]T" {...@@ -398,16 +398,16 @@ test "implicit cast from *[N]T to ?[*]T" {
398 var y: [4]u16 = [4]u16{ 0, 1, 2, 3 };398 var y: [4]u16 = [4]u16{ 0, 1, 2, 3 };
399399
400 x = &y;400 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]));
402 x.?[0] = 8;402 x.?[0] = 8;
403 y[3] = 6;403 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]));
405}405}
406406
407test "implicit cast from *T to ?*c_void" {407test "implicit cast from *T to ?*c_void" {
408 var a: u8 = 1;408 var a: u8 = 1;
409 incrementVoidPtrValue(&a);409 incrementVoidPtrValue(&a);
410 std.debug.assertOrPanic(a == 2);410 std.testing.expect(a == 2);
411}411}
412412
413fn incrementVoidPtrValue(value: ?*c_void) void {413fn incrementVoidPtrValue(value: ?*c_void) void {
...@@ -417,7 +417,7 @@ fn incrementVoidPtrValue(value: ?*c_void) void {...@@ -417,7 +417,7 @@ fn incrementVoidPtrValue(value: ?*c_void) void {
417test "implicit cast from [*]T to ?*c_void" {417test "implicit cast from [*]T to ?*c_void" {
418 var a = []u8{ 3, 2, 1 };418 var a = []u8{ 3, 2, 1 };
419 incrementVoidPtrArray(a[0..].ptr, 3);419 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 }));
421}421}
422422
423fn incrementVoidPtrArray(array: ?*c_void, len: usize) void {423fn incrementVoidPtrArray(array: ?*c_void, len: usize) void {
...@@ -441,27 +441,27 @@ pub const FUNCTION_CONSTANT = @intToPtr(PFN_void, maxInt(usize));...@@ -441,27 +441,27 @@ pub const FUNCTION_CONSTANT = @intToPtr(PFN_void, maxInt(usize));
441pub const PFN_void = extern fn (*c_void) void;441pub const PFN_void = extern fn (*c_void) void;
442442
443fn foobar(func: PFN_void) void {443fn foobar(func: PFN_void) void {
444 std.debug.assertOrPanic(@ptrToInt(func) == maxInt(usize));444 std.testing.expect(@ptrToInt(func) == maxInt(usize));
445}445}
446446
447test "implicit ptr to *c_void" {447test "implicit ptr to *c_void" {
448 var a: u32 = 1;448 var a: u32 = 1;
449 var ptr: *c_void = &a;449 var ptr: *c_void = &a;
450 var b: *u32 = @ptrCast(*u32, ptr);450 var b: *u32 = @ptrCast(*u32, ptr);
451 assertOrPanic(b.* == 1);451 expect(b.* == 1);
452 var ptr2: ?*c_void = &a;452 var ptr2: ?*c_void = &a;
453 var c: *u32 = @ptrCast(*u32, ptr2.?);453 var c: *u32 = @ptrCast(*u32, ptr2.?);
454 assertOrPanic(c.* == 1);454 expect(c.* == 1);
455}455}
456456
457test "@intCast to comptime_int" {457test "@intCast to comptime_int" {
458 assertOrPanic(@intCast(comptime_int, 0) == 0);458 expect(@intCast(comptime_int, 0) == 0);
459}459}
460460
461test "implicit cast comptime numbers to any type when the value fits" {461test "implicit cast comptime numbers to any type when the value fits" {
462 const a: u64 = 255;462 const a: u64 = 255;
463 var b: u8 = a;463 var b: u8 = a;
464 assertOrPanic(b == 255);464 expect(b == 255);
465}465}
466466
467test "@intToEnum passed a comptime_int to an enum with one item" {467test "@intToEnum passed a comptime_int to an enum with one item" {
...@@ -469,5 +469,16 @@ test "@intToEnum passed a comptime_int to an enum with one item" {...@@ -469,5 +469,16 @@ test "@intToEnum passed a comptime_int to an enum with one item" {
469 A,469 A,
470 };470 };
471 const x = @intToEnum(E, 0);471 const x = @intToEnum(E, 0);
472 assertOrPanic(x == E.A);472 expect(x == E.A);
473}
474
475test "@intCast to u0 and use the result" {
476 const S = struct {
477 fn doTheTest(zero: u1, one: u1, bigzero: i32) void {
478 expect((one << @intCast(u0, bigzero)) == 1);
479 expect((zero << @intCast(u0, bigzero)) == 0);
480 }
481 };
482 S.doTheTest(0, 1, 0);
483 comptime S.doTheTest(0, 1, 0);
473}484}
test/stage1/behavior/const_slice_child.zig+7-6
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1const debug = @import("std").debug;1const std = @import("std");
2const assertOrPanic = debug.assertOrPanic;2const debug = std.debug;
3const expect = std.testing.expect;
34
4var argv: [*]const [*]const u8 = undefined;5var argv: [*]const [*]const u8 = undefined;
56
...@@ -15,10 +16,10 @@ test "const slice child" {...@@ -15,10 +16,10 @@ test "const slice child" {
15}16}
1617
17fn foo(args: [][]const u8) void {18fn foo(args: [][]const u8) void {
18 assertOrPanic(args.len == 3);19 expect(args.len == 3);
19 assertOrPanic(streql(args[0], "one"));20 expect(streql(args[0], "one"));
20 assertOrPanic(streql(args[1], "two"));21 expect(streql(args[1], "two"));
21 assertOrPanic(streql(args[2], "three"));22 expect(streql(args[2], "three"));
22}23}
2324
24fn bar(argc: usize) void {25fn bar(argc: usize) void {
test/stage1/behavior/coroutine_await_struct.zig+3-3
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const assertOrPanic = std.debug.assertOrPanic;3const expect = std.testing.expect;
44
5const Foo = struct {5const Foo = struct {
6 x: i32,6 x: i32,
...@@ -18,8 +18,8 @@ test "coroutine await struct" {...@@ -18,8 +18,8 @@ test "coroutine await struct" {
18 await_seq('f');18 await_seq('f');
19 resume await_a_promise;19 resume await_a_promise;
20 await_seq('i');20 await_seq('i');
21 assertOrPanic(await_final_result.x == 1234);21 expect(await_final_result.x == 1234);
22 assertOrPanic(std.mem.eql(u8, await_points, "abcdefghi"));22 expect(std.mem.eql(u8, await_points, "abcdefghi"));
23}23}
24async fn await_amain() void {24async fn await_amain() void {
25 await_seq('b');25 await_seq('b');
test/stage1/behavior/coroutines.zig+18-18
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const assertOrPanic = std.debug.assertOrPanic;3const expect = std.testing.expect;
44
5var x: i32 = 1;5var x: i32 = 1;
66
...@@ -9,9 +9,9 @@ test "create a coroutine and cancel it" {...@@ -9,9 +9,9 @@ test "create a coroutine and cancel it" {
9 defer da.deinit();9 defer da.deinit();
1010
11 const p = try async<&da.allocator> simpleAsyncFn();11 const p = try async<&da.allocator> simpleAsyncFn();
12 comptime assertOrPanic(@typeOf(p) == promise->void);12 comptime expect(@typeOf(p) == promise->void);
13 cancel p;13 cancel p;
14 assertOrPanic(x == 2);14 expect(x == 2);
15}15}
16async fn simpleAsyncFn() void {16async fn simpleAsyncFn() void {
17 x += 1;17 x += 1;
...@@ -31,7 +31,7 @@ test "coroutine suspend, resume, cancel" {...@@ -31,7 +31,7 @@ test "coroutine suspend, resume, cancel" {
31 cancel p;31 cancel p;
32 seq('g');32 seq('g');
3333
34 assertOrPanic(std.mem.eql(u8, points, "abcdefg"));34 expect(std.mem.eql(u8, points, "abcdefg"));
35}35}
36async fn testAsyncSeq() void {36async fn testAsyncSeq() void {
37 defer seq('e');37 defer seq('e');
...@@ -53,9 +53,9 @@ test "coroutine suspend with block" {...@@ -53,9 +53,9 @@ test "coroutine suspend with block" {
53 defer da.deinit();53 defer da.deinit();
5454
55 const p = try async<&da.allocator> testSuspendBlock();55 const p = try async<&da.allocator> testSuspendBlock();
56 std.debug.assertOrPanic(!result);56 std.testing.expect(!result);
57 resume a_promise;57 resume a_promise;
58 std.debug.assertOrPanic(result);58 std.testing.expect(result);
59 cancel p;59 cancel p;
60}60}
6161
...@@ -63,13 +63,13 @@ var a_promise: promise = undefined;...@@ -63,13 +63,13 @@ var a_promise: promise = undefined;
63var result = false;63var result = false;
64async fn testSuspendBlock() void {64async fn testSuspendBlock() void {
65 suspend {65 suspend {
66 comptime assertOrPanic(@typeOf(@handle()) == promise->void);66 comptime expect(@typeOf(@handle()) == promise->void);
67 a_promise = @handle();67 a_promise = @handle();
68 }68 }
6969
70 //Test to make sure that @handle() works as advertised (issue #1296)70 //Test to make sure that @handle() works as advertised (issue #1296)
71 //var our_handle: promise = @handle();71 //var our_handle: promise = @handle();
72 assertOrPanic(a_promise == @handle());72 expect(a_promise == @handle());
7373
74 result = true;74 result = true;
75}75}
...@@ -86,8 +86,8 @@ test "coroutine await" {...@@ -86,8 +86,8 @@ test "coroutine await" {
86 await_seq('f');86 await_seq('f');
87 resume await_a_promise;87 resume await_a_promise;
88 await_seq('i');88 await_seq('i');
89 assertOrPanic(await_final_result == 1234);89 expect(await_final_result == 1234);
90 assertOrPanic(std.mem.eql(u8, await_points, "abcdefghi"));90 expect(std.mem.eql(u8, await_points, "abcdefghi"));
91}91}
92async fn await_amain() void {92async fn await_amain() void {
93 await_seq('b');93 await_seq('b');
...@@ -123,8 +123,8 @@ test "coroutine await early return" {...@@ -123,8 +123,8 @@ test "coroutine await early return" {
123 early_seq('a');123 early_seq('a');
124 const p = async<&da.allocator> early_amain() catch @panic("out of memory");124 const p = async<&da.allocator> early_amain() catch @panic("out of memory");
125 early_seq('f');125 early_seq('f');
126 assertOrPanic(early_final_result == 1234);126 expect(early_final_result == 1234);
127 assertOrPanic(std.mem.eql(u8, early_points, "abcdef"));127 expect(std.mem.eql(u8, early_points, "abcdef"));
128}128}
129async fn early_amain() void {129async fn early_amain() void {
130 early_seq('b');130 early_seq('b');
...@@ -170,7 +170,7 @@ test "async function with dot syntax" {...@@ -170,7 +170,7 @@ test "async function with dot syntax" {
170 defer da.deinit();170 defer da.deinit();
171 const p = try async<&da.allocator> S.foo();171 const p = try async<&da.allocator> S.foo();
172 cancel p;172 cancel p;
173 assertOrPanic(S.y == 2);173 expect(S.y == 2);
174}174}
175175
176test "async fn pointer in a struct field" {176test "async fn pointer in a struct field" {
...@@ -182,9 +182,9 @@ test "async fn pointer in a struct field" {...@@ -182,9 +182,9 @@ test "async fn pointer in a struct field" {
182 var da = std.heap.DirectAllocator.init();182 var da = std.heap.DirectAllocator.init();
183 defer da.deinit();183 defer da.deinit();
184 const p = (async<&da.allocator> foo.bar(&data)) catch unreachable;184 const p = (async<&da.allocator> foo.bar(&data)) catch unreachable;
185 assertOrPanic(data == 2);185 expect(data == 2);
186 cancel p;186 cancel p;
187 assertOrPanic(data == 4);187 expect(data == 4);
188}188}
189async<*std.mem.Allocator> fn simpleAsyncFn2(y: *i32) void {189async<*std.mem.Allocator> fn simpleAsyncFn2(y: *i32) void {
190 defer y.* += 2;190 defer y.* += 2;
...@@ -230,9 +230,9 @@ async fn suspendThenFail() anyerror!void {...@@ -230,9 +230,9 @@ async fn suspendThenFail() anyerror!void {
230}230}
231async fn printTrace(p: promise->(anyerror!void)) void {231async fn printTrace(p: promise->(anyerror!void)) void {
232 (await p) catch |e| {232 (await p) catch |e| {
233 std.debug.assertOrPanic(e == error.Fail);233 std.testing.expect(e == error.Fail);
234 if (@errorReturnTrace()) |trace| {234 if (@errorReturnTrace()) |trace| {
235 assertOrPanic(trace.index == 1);235 expect(trace.index == 1);
236 } else switch (builtin.mode) {236 } else switch (builtin.mode) {
237 builtin.Mode.Debug, builtin.Mode.ReleaseSafe => @panic("expected return trace"),237 builtin.Mode.Debug, builtin.Mode.ReleaseSafe => @panic("expected return trace"),
238 builtin.Mode.ReleaseFast, builtin.Mode.ReleaseSmall => {},238 builtin.Mode.ReleaseFast, builtin.Mode.ReleaseSmall => {},
...@@ -246,7 +246,7 @@ test "break from suspend" {...@@ -246,7 +246,7 @@ test "break from suspend" {
246 var my_result: i32 = 1;246 var my_result: i32 = 1;
247 const p = try async<a> testBreakFromSuspend(&my_result);247 const p = try async<a> testBreakFromSuspend(&my_result);
248 cancel p;248 cancel p;
249 std.debug.assertOrPanic(my_result == 2);249 std.testing.expect(my_result == 2);
250}250}
251async fn testBreakFromSuspend(my_result: *i32) void {251async fn testBreakFromSuspend(my_result: *i32) void {
252 suspend {252 suspend {
test/stage1/behavior/defer.zig+12-12
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;1const expect = @import("std").testing.expect;
22
3var result: [3]u8 = undefined;3var result: [3]u8 = undefined;
4var index: usize = undefined;4var index: usize = undefined;
...@@ -21,18 +21,18 @@ fn runSomeErrorDefers(x: bool) !bool {...@@ -21,18 +21,18 @@ fn runSomeErrorDefers(x: bool) !bool {
21}21}
2222
23test "mixing normal and error defers" {23test "mixing normal and error defers" {
24 assertOrPanic(runSomeErrorDefers(true) catch unreachable);24 expect(runSomeErrorDefers(true) catch unreachable);
25 assertOrPanic(result[0] == 'c');25 expect(result[0] == 'c');
26 assertOrPanic(result[1] == 'a');26 expect(result[1] == 'a');
2727
28 const ok = runSomeErrorDefers(false) catch |err| x: {28 const ok = runSomeErrorDefers(false) catch |err| x: {
29 assertOrPanic(err == error.FalseNotAllowed);29 expect(err == error.FalseNotAllowed);
30 break :x true;30 break :x true;
31 };31 };
32 assertOrPanic(ok);32 expect(ok);
33 assertOrPanic(result[0] == 'c');33 expect(result[0] == 'c');
34 assertOrPanic(result[1] == 'b');34 expect(result[1] == 'b');
35 assertOrPanic(result[2] == 'a');35 expect(result[2] == 'a');
36}36}
3737
38test "break and continue inside loop inside defer expression" {38test "break and continue inside loop inside defer expression" {
...@@ -47,7 +47,7 @@ fn testBreakContInDefer(x: usize) void {...@@ -47,7 +47,7 @@ fn testBreakContInDefer(x: usize) void {
47 if (i < 5) continue;47 if (i < 5) continue;
48 if (i == 5) break;48 if (i == 5) break;
49 }49 }
50 assertOrPanic(i == 5);50 expect(i == 5);
51 }51 }
52}52}
5353
...@@ -59,11 +59,11 @@ test "defer and labeled break" {...@@ -59,11 +59,11 @@ test "defer and labeled break" {
59 break :blk;59 break :blk;
60 }60 }
6161
62 assertOrPanic(i == 1);62 expect(i == 1);
63}63}
6464
65test "errdefer does not apply to fn inside fn" {65test "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);
67}67}
6868
69fn testNestedFnErrDefer() anyerror!void {69fn testNestedFnErrDefer() anyerror!void {
test/stage1/behavior/enum.zig+37-37
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;1const expect = @import("std").testing.expect;
2const mem = @import("std").mem;2const mem = @import("std").mem;
33
4test "enum type" {4test "enum type" {
...@@ -11,16 +11,16 @@ test "enum type" {...@@ -11,16 +11,16 @@ test "enum type" {
11 };11 };
12 const bar = Bar.B;12 const bar = Bar.B;
1313
14 assertOrPanic(bar == Bar.B);14 expect(bar == Bar.B);
15 assertOrPanic(@memberCount(Foo) == 3);15 expect(@memberCount(Foo) == 3);
16 assertOrPanic(@memberCount(Bar) == 4);16 expect(@memberCount(Bar) == 4);
17 assertOrPanic(@sizeOf(Foo) == @sizeOf(FooNoVoid));17 expect(@sizeOf(Foo) == @sizeOf(FooNoVoid));
18 assertOrPanic(@sizeOf(Bar) == 1);18 expect(@sizeOf(Bar) == 1);
19}19}
2020
21test "enum as return value" {21test "enum as return value" {
22 switch (returnAnInt(13)) {22 switch (returnAnInt(13)) {
23 Foo.One => |value| assertOrPanic(value == 13),23 Foo.One => |value| expect(value == 13),
24 else => unreachable,24 else => unreachable,
25 }25 }
26}26}
...@@ -92,14 +92,14 @@ test "enum to int" {...@@ -92,14 +92,14 @@ test "enum to int" {
92}92}
9393
94fn shouldEqual(n: Number, expected: u3) void {94fn shouldEqual(n: Number, expected: u3) void {
95 assertOrPanic(@enumToInt(n) == expected);95 expect(@enumToInt(n) == expected);
96}96}
9797
98test "int to enum" {98test "int to enum" {
99 testIntToEnumEval(3);99 testIntToEnumEval(3);
100}100}
101fn testIntToEnumEval(x: i32) void {101fn testIntToEnumEval(x: i32) void {
102 assertOrPanic(@intToEnum(IntToEnumNumber, @intCast(u3, x)) == IntToEnumNumber.Three);102 expect(@intToEnum(IntToEnumNumber, @intCast(u3, x)) == IntToEnumNumber.Three);
103}103}
104const IntToEnumNumber = enum {104const IntToEnumNumber = enum {
105 Zero,105 Zero,
...@@ -110,8 +110,8 @@ const IntToEnumNumber = enum {...@@ -110,8 +110,8 @@ const IntToEnumNumber = enum {
110};110};
111111
112test "@tagName" {112test "@tagName" {
113 assertOrPanic(mem.eql(u8, testEnumTagNameBare(BareNumber.Three), "Three"));113 expect(mem.eql(u8, testEnumTagNameBare(BareNumber.Three), "Three"));
114 comptime assertOrPanic(mem.eql(u8, testEnumTagNameBare(BareNumber.Three), "Three"));114 comptime expect(mem.eql(u8, testEnumTagNameBare(BareNumber.Three), "Three"));
115}115}
116116
117fn testEnumTagNameBare(n: BareNumber) []const u8 {117fn testEnumTagNameBare(n: BareNumber) []const u8 {
...@@ -126,8 +126,8 @@ const BareNumber = enum {...@@ -126,8 +126,8 @@ const BareNumber = enum {
126126
127test "enum alignment" {127test "enum alignment" {
128 comptime {128 comptime {
129 assertOrPanic(@alignOf(AlignTestEnum) >= @alignOf([9]u8));129 expect(@alignOf(AlignTestEnum) >= @alignOf([9]u8));
130 assertOrPanic(@alignOf(AlignTestEnum) >= @alignOf(u64));130 expect(@alignOf(AlignTestEnum) >= @alignOf(u64));
131 }131 }
132}132}
133133
...@@ -663,10 +663,10 @@ const ValueCount257 = enum {...@@ -663,10 +663,10 @@ const ValueCount257 = enum {
663663
664test "enum sizes" {664test "enum sizes" {
665 comptime {665 comptime {
666 assertOrPanic(@sizeOf(ValueCount1) == 0);666 expect(@sizeOf(ValueCount1) == 0);
667 assertOrPanic(@sizeOf(ValueCount2) == 1);667 expect(@sizeOf(ValueCount2) == 1);
668 assertOrPanic(@sizeOf(ValueCount256) == 1);668 expect(@sizeOf(ValueCount256) == 1);
669 assertOrPanic(@sizeOf(ValueCount257) == 2);669 expect(@sizeOf(ValueCount257) == 2);
670 }670 }
671}671}
672672
...@@ -685,12 +685,12 @@ test "set enum tag type" {...@@ -685,12 +685,12 @@ test "set enum tag type" {
685 {685 {
686 var x = Small.One;686 var x = Small.One;
687 x = Small.Two;687 x = Small.Two;
688 comptime assertOrPanic(@TagType(Small) == u2);688 comptime expect(@TagType(Small) == u2);
689 }689 }
690 {690 {
691 var x = Small2.One;691 var x = Small2.One;
692 x = Small2.Two;692 x = Small2.Two;
693 comptime assertOrPanic(@TagType(Small2) == u2);693 comptime expect(@TagType(Small2) == u2);
694 }694 }
695}695}
696696
...@@ -737,17 +737,17 @@ const bit_field_1 = BitFieldOfEnums{...@@ -737,17 +737,17 @@ const bit_field_1 = BitFieldOfEnums{
737737
738test "bit field access with enum fields" {738test "bit field access with enum fields" {
739 var data = bit_field_1;739 var data = bit_field_1;
740 assertOrPanic(getA(&data) == A.Two);740 expect(getA(&data) == A.Two);
741 assertOrPanic(getB(&data) == B.Three3);741 expect(getB(&data) == B.Three3);
742 assertOrPanic(getC(&data) == C.Four4);742 expect(getC(&data) == C.Four4);
743 comptime assertOrPanic(@sizeOf(BitFieldOfEnums) == 1);743 comptime expect(@sizeOf(BitFieldOfEnums) == 1);
744744
745 data.b = B.Four3;745 data.b = B.Four3;
746 assertOrPanic(data.b == B.Four3);746 expect(data.b == B.Four3);
747747
748 data.a = A.Three;748 data.a = A.Three;
749 assertOrPanic(data.a == A.Three);749 expect(data.a == A.Three);
750 assertOrPanic(data.b == B.Four3);750 expect(data.b == B.Four3);
751}751}
752752
753fn getA(data: *const BitFieldOfEnums) A {753fn getA(data: *const BitFieldOfEnums) A {
...@@ -768,7 +768,7 @@ test "casting enum to its tag type" {...@@ -768,7 +768,7 @@ test "casting enum to its tag type" {
768}768}
769769
770fn testCastEnumToTagType(value: Small2) void {770fn testCastEnumToTagType(value: Small2) void {
771 assertOrPanic(@enumToInt(value) == 1);771 expect(@enumToInt(value) == 1);
772}772}
773773
774const MultipleChoice = enum(u32) {774const MultipleChoice = enum(u32) {
...@@ -784,8 +784,8 @@ test "enum with specified tag values" {...@@ -784,8 +784,8 @@ test "enum with specified tag values" {
784}784}
785785
786fn testEnumWithSpecifiedTagValues(x: MultipleChoice) void {786fn testEnumWithSpecifiedTagValues(x: MultipleChoice) void {
787 assertOrPanic(@enumToInt(x) == 60);787 expect(@enumToInt(x) == 60);
788 assertOrPanic(1234 == switch (x) {788 expect(1234 == switch (x) {
789 MultipleChoice.A => 1,789 MultipleChoice.A => 1,
790 MultipleChoice.B => 2,790 MultipleChoice.B => 2,
791 MultipleChoice.C => u32(1234),791 MultipleChoice.C => u32(1234),
...@@ -811,8 +811,8 @@ test "enum with specified and unspecified tag values" {...@@ -811,8 +811,8 @@ test "enum with specified and unspecified tag values" {
811}811}
812812
813fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void {813fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void {
814 assertOrPanic(@enumToInt(x) == 1000);814 expect(@enumToInt(x) == 1000);
815 assertOrPanic(1234 == switch (x) {815 expect(1234 == switch (x) {
816 MultipleChoice2.A => 1,816 MultipleChoice2.A => 1,
817 MultipleChoice2.B => 2,817 MultipleChoice2.B => 2,
818 MultipleChoice2.C => 3,818 MultipleChoice2.C => 3,
...@@ -826,8 +826,8 @@ fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void {...@@ -826,8 +826,8 @@ fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void {
826}826}
827827
828test "cast integer literal to enum" {828test "cast integer literal to enum" {
829 assertOrPanic(@intToEnum(MultipleChoice2, 0) == MultipleChoice2.Unspecified1);829 expect(@intToEnum(MultipleChoice2, 0) == MultipleChoice2.Unspecified1);
830 assertOrPanic(@intToEnum(MultipleChoice2, 40) == MultipleChoice2.B);830 expect(@intToEnum(MultipleChoice2, 40) == MultipleChoice2.B);
831}831}
832832
833const EnumWithOneMember = enum {833const EnumWithOneMember = enum {
...@@ -865,14 +865,14 @@ const EnumWithTagValues = enum(u4) {...@@ -865,14 +865,14 @@ const EnumWithTagValues = enum(u4) {
865 D = 1 << 3,865 D = 1 << 3,
866};866};
867test "enum with tag values don't require parens" {867test "enum with tag values don't require parens" {
868 assertOrPanic(@enumToInt(EnumWithTagValues.C) == 0b0100);868 expect(@enumToInt(EnumWithTagValues.C) == 0b0100);
869}869}
870870
871test "enum with 1 field but explicit tag type should still have the tag type" {871test "enum with 1 field but explicit tag type should still have the tag type" {
872 const Enum = enum(u8) {872 const Enum = enum(u8) {
873 B = 2,873 B = 2,
874 };874 };
875 comptime @import("std").debug.assertOrPanic(@sizeOf(Enum) == @sizeOf(u8));875 comptime @import("std").testing.expect(@sizeOf(Enum) == @sizeOf(u8));
876}876}
877877
878test "empty extern enum with members" {878test "empty extern enum with members" {
...@@ -881,7 +881,7 @@ test "empty extern enum with members" {...@@ -881,7 +881,7 @@ test "empty extern enum with members" {
881 B,881 B,
882 C,882 C,
883 };883 };
884 assertOrPanic(@sizeOf(E) == @sizeOf(c_int));884 expect(@sizeOf(E) == @sizeOf(c_int));
885}885}
886886
887test "tag name with assigned enum values" {887test "tag name with assigned enum values" {
...@@ -890,5 +890,5 @@ test "tag name with assigned enum values" {...@@ -890,5 +890,5 @@ test "tag name with assigned enum values" {
890 B = 0,890 B = 0,
891 };891 };
892 var b = LocalFoo.B;892 var b = LocalFoo.B;
893 assertOrPanic(mem.eql(u8, @tagName(b), "B"));893 expect(mem.eql(u8, @tagName(b), "B"));
894}894}
test/stage1/behavior/enum_with_members.zig+5-5
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;1const expect = @import("std").testing.expect;
2const mem = @import("std").mem;2const mem = @import("std").mem;
3const fmt = @import("std").fmt;3const fmt = @import("std").fmt;
44
...@@ -19,9 +19,9 @@ test "enum with members" {...@@ -19,9 +19,9 @@ test "enum with members" {
19 const b = ET{ .UINT = 42 };19 const b = ET{ .UINT = 42 };
20 var buf: [20]u8 = undefined;20 var buf: [20]u8 = undefined;
2121
22 assertOrPanic((a.print(buf[0..]) catch unreachable) == 3);22 expect((a.print(buf[0..]) catch unreachable) == 3);
23 assertOrPanic(mem.eql(u8, buf[0..3], "-42"));23 expect(mem.eql(u8, buf[0..3], "-42"));
2424
25 assertOrPanic((b.print(buf[0..]) catch unreachable) == 2);25 expect((b.print(buf[0..]) catch unreachable) == 2);
26 assertOrPanic(mem.eql(u8, buf[0..2], "42"));26 expect(mem.eql(u8, buf[0..2], "42"));
27}27}
test/stage1/behavior/error.zig+31-31
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const std = @import("std");1const std = @import("std");
2const assertOrPanic = std.debug.assertOrPanic;2const expect = std.testing.expect;
3const assertError = std.debug.assertError;3const expectError = std.testing.expectError;
4const mem = std.mem;4const mem = std.mem;
5const builtin = @import("builtin");5const builtin = @import("builtin");
66
...@@ -19,7 +19,7 @@ pub fn baz() anyerror!i32 {...@@ -19,7 +19,7 @@ pub fn baz() anyerror!i32 {
19}19}
2020
21test "error wrapping" {21test "error wrapping" {
22 assertOrPanic((baz() catch unreachable) == 15);22 expect((baz() catch unreachable) == 15);
23}23}
2424
25fn gimmeItBroke() []const u8 {25fn gimmeItBroke() []const u8 {
...@@ -27,14 +27,14 @@ fn gimmeItBroke() []const u8 {...@@ -27,14 +27,14 @@ fn gimmeItBroke() []const u8 {
27}27}
2828
29test "@errorName" {29test "@errorName" {
30 assertOrPanic(mem.eql(u8, @errorName(error.AnError), "AnError"));30 expect(mem.eql(u8, @errorName(error.AnError), "AnError"));
31 assertOrPanic(mem.eql(u8, @errorName(error.ALongerErrorName), "ALongerErrorName"));31 expect(mem.eql(u8, @errorName(error.ALongerErrorName), "ALongerErrorName"));
32}32}
3333
34test "error values" {34test "error values" {
35 const a = @errorToInt(error.err1);35 const a = @errorToInt(error.err1);
36 const b = @errorToInt(error.err2);36 const b = @errorToInt(error.err2);
37 assertOrPanic(a != b);37 expect(a != b);
38}38}
3939
40test "redefinition of error values allowed" {40test "redefinition of error values allowed" {
...@@ -47,8 +47,8 @@ fn shouldBeNotEqual(a: anyerror, b: anyerror) void {...@@ -47,8 +47,8 @@ fn shouldBeNotEqual(a: anyerror, b: anyerror) void {
47test "error binary operator" {47test "error binary operator" {
48 const a = errBinaryOperatorG(true) catch 3;48 const a = errBinaryOperatorG(true) catch 3;
49 const b = errBinaryOperatorG(false) catch 3;49 const b = errBinaryOperatorG(false) catch 3;
50 assertOrPanic(a == 3);50 expect(a == 3);
51 assertOrPanic(b == 10);51 expect(b == 10);
52}52}
53fn errBinaryOperatorG(x: bool) anyerror!isize {53fn errBinaryOperatorG(x: bool) anyerror!isize {
54 return if (x) error.ItBroke else isize(10);54 return if (x) error.ItBroke else isize(10);
...@@ -56,7 +56,7 @@ fn errBinaryOperatorG(x: bool) anyerror!isize {...@@ -56,7 +56,7 @@ fn errBinaryOperatorG(x: bool) anyerror!isize {
5656
57test "unwrap simple value from error" {57test "unwrap simple value from error" {
58 const i = unwrapSimpleValueFromErrorDo() catch unreachable;58 const i = unwrapSimpleValueFromErrorDo() catch unreachable;
59 assertOrPanic(i == 13);59 expect(i == 13);
60}60}
61fn unwrapSimpleValueFromErrorDo() anyerror!isize {61fn unwrapSimpleValueFromErrorDo() anyerror!isize {
62 return 13;62 return 13;
...@@ -82,10 +82,10 @@ test "error union type " {...@@ -82,10 +82,10 @@ test "error union type " {
8282
83fn testErrorUnionType() void {83fn testErrorUnionType() void {
84 const x: anyerror!i32 = 1234;84 const x: anyerror!i32 = 1234;
85 if (x) |value| assertOrPanic(value == 1234) else |_| unreachable;85 if (x) |value| expect(value == 1234) else |_| unreachable;
86 assertOrPanic(@typeId(@typeOf(x)) == builtin.TypeId.ErrorUnion);86 expect(@typeId(@typeOf(x)) == builtin.TypeId.ErrorUnion);
87 assertOrPanic(@typeId(@typeOf(x).ErrorSet) == builtin.TypeId.ErrorSet);87 expect(@typeId(@typeOf(x).ErrorSet) == builtin.TypeId.ErrorSet);
88 assertOrPanic(@typeOf(x).ErrorSet == anyerror);88 expect(@typeOf(x).ErrorSet == anyerror);
89}89}
9090
91test "error set type" {91test "error set type" {
...@@ -99,12 +99,12 @@ const MyErrSet = error{...@@ -99,12 +99,12 @@ const MyErrSet = error{
99};99};
100100
101fn testErrorSetType() void {101fn testErrorSetType() void {
102 assertOrPanic(@memberCount(MyErrSet) == 2);102 expect(@memberCount(MyErrSet) == 2);
103103
104 const a: MyErrSet!i32 = 5678;104 const a: MyErrSet!i32 = 5678;
105 const b: MyErrSet!i32 = MyErrSet.OutOfMemory;105 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) {
108 error.OutOfMemory => unreachable,108 error.OutOfMemory => unreachable,
109 error.FileNotFound => unreachable,109 error.FileNotFound => unreachable,
110 }110 }
...@@ -127,7 +127,7 @@ const Set2 = error{...@@ -127,7 +127,7 @@ const Set2 = error{
127fn testExplicitErrorSetCast(set1: Set1) void {127fn testExplicitErrorSetCast(set1: Set1) void {
128 var x = @errSetCast(Set2, set1);128 var x = @errSetCast(Set2, set1);
129 var y = @errSetCast(Set1, x);129 var y = @errSetCast(Set1, x);
130 assertOrPanic(y == error.A);130 expect(y == error.A);
131}131}
132132
133test "comptime test error for empty error set" {133test "comptime test error for empty error set" {
...@@ -138,12 +138,12 @@ test "comptime test error for empty error set" {...@@ -138,12 +138,12 @@ test "comptime test error for empty error set" {
138const EmptyErrorSet = error{};138const EmptyErrorSet = error{};
139139
140fn testComptimeTestErrorEmptySet(x: EmptyErrorSet!i32) void {140fn 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");
142}142}
143143
144test "syntax: optional operator in front of error union operator" {144test "syntax: optional operator in front of error union operator" {
145 comptime {145 comptime {
146 assertOrPanic(?(anyerror!i32) == ?(anyerror!i32));146 expect(?(anyerror!i32) == ?(anyerror!i32));
147 }147 }
148}148}
149149
...@@ -173,7 +173,7 @@ fn testErrorUnionPeerTypeResolution(x: i32) void {...@@ -173,7 +173,7 @@ fn testErrorUnionPeerTypeResolution(x: i32) void {
173 if (y) |_| {173 if (y) |_| {
174 @panic("expected error");174 @panic("expected error");
175 } else |e| {175 } else |e| {
176 assertOrPanic(e == error.A);176 expect(e == error.A);
177 }177 }
178}178}
179179
...@@ -282,13 +282,13 @@ test "nested error union function call in optional unwrap" {...@@ -282,13 +282,13 @@ test "nested error union function call in optional unwrap" {
282 return null;282 return null;
283 }283 }
284 };284 };
285 assertOrPanic((try S.errorable()) == 1234);285 expect((try S.errorable()) == 1234);
286 assertError(S.errorable2(), error.Failure);286 expectError(error.Failure, S.errorable2());
287 assertError(S.errorable3(), error.Other);287 expectError(error.Other, S.errorable3());
288 comptime {288 comptime {
289 assertOrPanic((try S.errorable()) == 1234);289 expect((try S.errorable()) == 1234);
290 assertError(S.errorable2(), error.Failure);290 expectError(error.Failure, S.errorable2());
291 assertError(S.errorable3(), error.Other);291 expectError(error.Other, S.errorable3());
292 }292 }
293}293}
294294
...@@ -303,7 +303,7 @@ test "widen cast integer payload of error union function call" {...@@ -303,7 +303,7 @@ test "widen cast integer payload of error union function call" {
303 return 1234;303 return 1234;
304 }304 }
305 };305 };
306 assertOrPanic((try S.errorable()) == 1234);306 expect((try S.errorable()) == 1234);
307}307}
308308
309test "return function call to error set from error union function" {309test "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" {...@@ -316,17 +316,17 @@ test "return function call to error set from error union function" {
316 return error.Failure;316 return error.Failure;
317 }317 }
318 };318 };
319 assertError(S.errorable(), error.Failure);319 expectError(error.Failure, S.errorable());
320 comptime assertError(S.errorable(), error.Failure);320 comptime expectError(error.Failure, S.errorable());
321}321}
322322
323test "optional error set is the same size as error set" {323test "optional error set is the same size as error set" {
324 comptime assertOrPanic(@sizeOf(?anyerror) == @sizeOf(anyerror));324 comptime expect(@sizeOf(?anyerror) == @sizeOf(anyerror));
325 const S = struct {325 const S = struct {
326 fn returnsOptErrSet() ?anyerror {326 fn returnsOptErrSet() ?anyerror {
327 return null;327 return null;
328 }328 }
329 };329 };
330 assertOrPanic(S.returnsOptErrSet() == null);330 expect(S.returnsOptErrSet() == null);
331 comptime assertOrPanic(S.returnsOptErrSet() == null);331 comptime expect(S.returnsOptErrSet() == null);
332}332}
test/stage1/behavior/eval.zig+116-122
...@@ -1,9 +1,9 @@...@@ -1,9 +1,9 @@
1const std = @import("std");1const std = @import("std");
2const assertOrPanic = std.debug.assertOrPanic;2const expect = std.testing.expect;
3const builtin = @import("builtin");3const builtin = @import("builtin");
44
5test "compile time recursion" {5test "compile time recursion" {
6 assertOrPanic(some_data.len == 21);6 expect(some_data.len == 21);
7}7}
8var some_data: [@intCast(usize, fibonacci(7))]u8 = undefined;8var some_data: [@intCast(usize, fibonacci(7))]u8 = undefined;
9fn fibonacci(x: i32) i32 {9fn fibonacci(x: i32) i32 {
...@@ -16,7 +16,7 @@ fn unwrapAndAddOne(blah: ?i32) i32 {...@@ -16,7 +16,7 @@ fn unwrapAndAddOne(blah: ?i32) i32 {
16}16}
17const should_be_1235 = unwrapAndAddOne(1234);17const should_be_1235 = unwrapAndAddOne(1234);
18test "static add one" {18test "static add one" {
19 assertOrPanic(should_be_1235 == 1235);19 expect(should_be_1235 == 1235);
20}20}
2121
22test "inlined loop" {22test "inlined loop" {
...@@ -24,7 +24,7 @@ test "inlined loop" {...@@ -24,7 +24,7 @@ test "inlined loop" {
24 comptime var sum = 0;24 comptime var sum = 0;
25 inline while (i <= 5) : (i += 1)25 inline while (i <= 5) : (i += 1)
26 sum += i;26 sum += i;
27 assertOrPanic(sum == 15);27 expect(sum == 15);
28}28}
2929
30fn gimme1or2(comptime a: bool) i32 {30fn gimme1or2(comptime a: bool) i32 {
...@@ -34,12 +34,12 @@ fn gimme1or2(comptime a: bool) i32 {...@@ -34,12 +34,12 @@ fn gimme1or2(comptime a: bool) i32 {
34 return z;34 return z;
35}35}
36test "inline variable gets result of const if" {36test "inline variable gets result of const if" {
37 assertOrPanic(gimme1or2(true) == 1);37 expect(gimme1or2(true) == 1);
38 assertOrPanic(gimme1or2(false) == 2);38 expect(gimme1or2(false) == 2);
39}39}
4040
41test "static function evaluation" {41test "static function evaluation" {
42 assertOrPanic(statically_added_number == 3);42 expect(statically_added_number == 3);
43}43}
44const statically_added_number = staticAdd(1, 2);44const statically_added_number = staticAdd(1, 2);
45fn staticAdd(a: i32, b: i32) i32 {45fn staticAdd(a: i32, b: i32) i32 {
...@@ -47,8 +47,8 @@ fn staticAdd(a: i32, b: i32) i32 {...@@ -47,8 +47,8 @@ fn staticAdd(a: i32, b: i32) i32 {
47}47}
4848
49test "const expr eval on single expr blocks" {49test "const expr eval on single expr blocks" {
50 assertOrPanic(constExprEvalOnSingleExprBlocksFn(1, true) == 3);50 expect(constExprEvalOnSingleExprBlocksFn(1, true) == 3);
51 comptime assertOrPanic(constExprEvalOnSingleExprBlocksFn(1, true) == 3);51 comptime expect(constExprEvalOnSingleExprBlocksFn(1, true) == 3);
52}52}
5353
54fn constExprEvalOnSingleExprBlocksFn(x: i32, b: bool) i32 {54fn constExprEvalOnSingleExprBlocksFn(x: i32, b: bool) i32 {
...@@ -64,10 +64,10 @@ fn constExprEvalOnSingleExprBlocksFn(x: i32, b: bool) i32 {...@@ -64,10 +64,10 @@ fn constExprEvalOnSingleExprBlocksFn(x: i32, b: bool) i32 {
64}64}
6565
66test "statically initialized list" {66test "statically initialized list" {
67 assertOrPanic(static_point_list[0].x == 1);67 expect(static_point_list[0].x == 1);
68 assertOrPanic(static_point_list[0].y == 2);68 expect(static_point_list[0].y == 2);
69 assertOrPanic(static_point_list[1].x == 3);69 expect(static_point_list[1].x == 3);
70 assertOrPanic(static_point_list[1].y == 4);70 expect(static_point_list[1].y == 4);
71}71}
72const Point = struct {72const Point = struct {
73 x: i32,73 x: i32,
...@@ -85,8 +85,8 @@ fn makePoint(x: i32, y: i32) Point {...@@ -85,8 +85,8 @@ fn makePoint(x: i32, y: i32) Point {
85}85}
8686
87test "static eval list init" {87test "static eval list init" {
88 assertOrPanic(static_vec3.data[2] == 1.0);88 expect(static_vec3.data[2] == 1.0);
89 assertOrPanic(vec3(0.0, 0.0, 3.0).data[2] == 3.0);89 expect(vec3(0.0, 0.0, 3.0).data[2] == 3.0);
90}90}
91const static_vec3 = vec3(0.0, 0.0, 1.0);91const static_vec3 = vec3(0.0, 0.0, 1.0);
92pub const Vec3 = struct {92pub const Vec3 = struct {
...@@ -102,12 +102,12 @@ pub fn vec3(x: f32, y: f32, z: f32) Vec3 {...@@ -102,12 +102,12 @@ pub fn vec3(x: f32, y: f32, z: f32) Vec3 {
102102
103test "constant expressions" {103test "constant expressions" {
104 var array: [array_size]u8 = undefined;104 var array: [array_size]u8 = undefined;
105 assertOrPanic(@sizeOf(@typeOf(array)) == 20);105 expect(@sizeOf(@typeOf(array)) == 20);
106}106}
107const array_size: u8 = 20;107const array_size: u8 = 20;
108108
109test "constant struct with negation" {109test "constant struct with negation" {
110 assertOrPanic(vertices[0].x == -0.6);110 expect(vertices[0].x == -0.6);
111}111}
112const Vertex = struct {112const Vertex = struct {
113 x: f32,113 x: f32,
...@@ -142,7 +142,7 @@ const vertices = []Vertex{...@@ -142,7 +142,7 @@ const vertices = []Vertex{
142142
143test "statically initialized struct" {143test "statically initialized struct" {
144 st_init_str_foo.x += 1;144 st_init_str_foo.x += 1;
145 assertOrPanic(st_init_str_foo.x == 14);145 expect(st_init_str_foo.x == 14);
146}146}
147const StInitStrFoo = struct {147const StInitStrFoo = struct {
148 x: i32,148 x: i32,
...@@ -155,7 +155,7 @@ var st_init_str_foo = StInitStrFoo{...@@ -155,7 +155,7 @@ var st_init_str_foo = StInitStrFoo{
155155
156test "statically initalized array literal" {156test "statically initalized array literal" {
157 const y: [4]u8 = st_init_arr_lit_x;157 const y: [4]u8 = st_init_arr_lit_x;
158 assertOrPanic(y[3] == 4);158 expect(y[3] == 4);
159}159}
160const st_init_arr_lit_x = []u8{160const st_init_arr_lit_x = []u8{
161 1,161 1,
...@@ -167,15 +167,15 @@ const st_init_arr_lit_x = []u8{...@@ -167,15 +167,15 @@ const st_init_arr_lit_x = []u8{
167test "const slice" {167test "const slice" {
168 comptime {168 comptime {
169 const a = "1234567890";169 const a = "1234567890";
170 assertOrPanic(a.len == 10);170 expect(a.len == 10);
171 const b = a[1..2];171 const b = a[1..2];
172 assertOrPanic(b.len == 1);172 expect(b.len == 1);
173 assertOrPanic(b[0] == '2');173 expect(b[0] == '2');
174 }174 }
175}175}
176176
177test "try to trick eval with runtime if" {177test "try to trick eval with runtime if" {
178 assertOrPanic(testTryToTrickEvalWithRuntimeIf(true) == 10);178 expect(testTryToTrickEvalWithRuntimeIf(true) == 10);
179}179}
180180
181fn testTryToTrickEvalWithRuntimeIf(b: bool) usize {181fn testTryToTrickEvalWithRuntimeIf(b: bool) usize {
...@@ -201,16 +201,16 @@ fn letsTryToCompareBools(a: bool, b: bool) bool {...@@ -201,16 +201,16 @@ fn letsTryToCompareBools(a: bool, b: bool) bool {
201 return max(bool, a, b);201 return max(bool, a, b);
202}202}
203test "inlined block and runtime block phi" {203test "inlined block and runtime block phi" {
204 assertOrPanic(letsTryToCompareBools(true, true));204 expect(letsTryToCompareBools(true, true));
205 assertOrPanic(letsTryToCompareBools(true, false));205 expect(letsTryToCompareBools(true, false));
206 assertOrPanic(letsTryToCompareBools(false, true));206 expect(letsTryToCompareBools(false, true));
207 assertOrPanic(!letsTryToCompareBools(false, false));207 expect(!letsTryToCompareBools(false, false));
208208
209 comptime {209 comptime {
210 assertOrPanic(letsTryToCompareBools(true, true));210 expect(letsTryToCompareBools(true, true));
211 assertOrPanic(letsTryToCompareBools(true, false));211 expect(letsTryToCompareBools(true, false));
212 assertOrPanic(letsTryToCompareBools(false, true));212 expect(letsTryToCompareBools(false, true));
213 assertOrPanic(!letsTryToCompareBools(false, false));213 expect(!letsTryToCompareBools(false, false));
214 }214 }
215}215}
216216
...@@ -255,14 +255,14 @@ fn performFn(comptime prefix_char: u8, start_value: i32) i32 {...@@ -255,14 +255,14 @@ fn performFn(comptime prefix_char: u8, start_value: i32) i32 {
255}255}
256256
257test "comptime iterate over fn ptr list" {257test "comptime iterate over fn ptr list" {
258 assertOrPanic(performFn('t', 1) == 6);258 expect(performFn('t', 1) == 6);
259 assertOrPanic(performFn('o', 0) == 1);259 expect(performFn('o', 0) == 1);
260 assertOrPanic(performFn('w', 99) == 99);260 expect(performFn('w', 99) == 99);
261}261}
262262
263test "eval @setRuntimeSafety at compile-time" {263test "eval @setRuntimeSafety at compile-time" {
264 const result = comptime fnWithSetRuntimeSafety();264 const result = comptime fnWithSetRuntimeSafety();
265 assertOrPanic(result == 1234);265 expect(result == 1234);
266}266}
267267
268fn fnWithSetRuntimeSafety() i32 {268fn fnWithSetRuntimeSafety() i32 {
...@@ -272,7 +272,7 @@ fn fnWithSetRuntimeSafety() i32 {...@@ -272,7 +272,7 @@ fn fnWithSetRuntimeSafety() i32 {
272272
273test "eval @setFloatMode at compile-time" {273test "eval @setFloatMode at compile-time" {
274 const result = comptime fnWithFloatMode();274 const result = comptime fnWithFloatMode();
275 assertOrPanic(result == 1234.0);275 expect(result == 1234.0);
276}276}
277277
278fn fnWithFloatMode() f32 {278fn fnWithFloatMode() f32 {
...@@ -293,15 +293,15 @@ var simple_struct = SimpleStruct{ .field = 1234 };...@@ -293,15 +293,15 @@ var simple_struct = SimpleStruct{ .field = 1234 };
293const bound_fn = simple_struct.method;293const bound_fn = simple_struct.method;
294294
295test "call method on bound fn referring to var instance" {295test "call method on bound fn referring to var instance" {
296 assertOrPanic(bound_fn() == 1237);296 expect(bound_fn() == 1237);
297}297}
298298
299test "ptr to local array argument at comptime" {299test "ptr to local array argument at comptime" {
300 comptime {300 comptime {
301 var bytes: [10]u8 = undefined;301 var bytes: [10]u8 = undefined;
302 modifySomeBytes(bytes[0..]);302 modifySomeBytes(bytes[0..]);
303 assertOrPanic(bytes[0] == 'a');303 expect(bytes[0] == 'a');
304 assertOrPanic(bytes[9] == 'b');304 expect(bytes[9] == 'b');
305 }305 }
306}306}
307307
...@@ -329,9 +329,9 @@ fn testCompTimeUIntComparisons(x: u32) void {...@@ -329,9 +329,9 @@ fn testCompTimeUIntComparisons(x: u32) void {
329}329}
330330
331test "const ptr to variable data changes at runtime" {331test "const ptr to variable data changes at runtime" {
332 assertOrPanic(foo_ref.name[0] == 'a');332 expect(foo_ref.name[0] == 'a');
333 foo_ref.name = "b";333 foo_ref.name = "b";
334 assertOrPanic(foo_ref.name[0] == 'b');334 expect(foo_ref.name[0] == 'b');
335}335}
336336
337const Foo = struct {337const Foo = struct {
...@@ -342,8 +342,8 @@ var foo_contents = Foo{ .name = "a" };...@@ -342,8 +342,8 @@ var foo_contents = Foo{ .name = "a" };
342const foo_ref = &foo_contents;342const foo_ref = &foo_contents;
343343
344test "create global array with for loop" {344test "create global array with for loop" {
345 assertOrPanic(global_array[5] == 5 * 5);345 expect(global_array[5] == 5 * 5);
346 assertOrPanic(global_array[9] == 9 * 9);346 expect(global_array[9] == 9 * 9);
347}347}
348348
349const global_array = x: {349const global_array = x: {
...@@ -358,7 +358,7 @@ test "compile-time downcast when the bits fit" {...@@ -358,7 +358,7 @@ test "compile-time downcast when the bits fit" {
358 comptime {358 comptime {
359 const spartan_count: u16 = 255;359 const spartan_count: u16 = 255;
360 const byte = @intCast(u8, spartan_count);360 const byte = @intCast(u8, spartan_count);
361 assertOrPanic(byte == 255);361 expect(byte == 255);
362 }362 }
363}363}
364364
...@@ -366,44 +366,44 @@ const hi1 = "hi";...@@ -366,44 +366,44 @@ const hi1 = "hi";
366const hi2 = hi1;366const hi2 = hi1;
367test "const global shares pointer with other same one" {367test "const global shares pointer with other same one" {
368 assertEqualPtrs(&hi1[0], &hi2[0]);368 assertEqualPtrs(&hi1[0], &hi2[0]);
369 comptime assertOrPanic(&hi1[0] == &hi2[0]);369 comptime expect(&hi1[0] == &hi2[0]);
370}370}
371fn assertEqualPtrs(ptr1: *const u8, ptr2: *const u8) void {371fn assertEqualPtrs(ptr1: *const u8, ptr2: *const u8) void {
372 assertOrPanic(ptr1 == ptr2);372 expect(ptr1 == ptr2);
373}373}
374374
375test "@setEvalBranchQuota" {375test "@setEvalBranchQuota" {
376 comptime {376 comptime {
377 // 1001 for the loop and then 1 more for the assertOrPanic fn call377 // 1001 for the loop and then 1 more for the expect fn call
378 @setEvalBranchQuota(1002);378 @setEvalBranchQuota(1002);
379 var i = 0;379 var i = 0;
380 var sum = 0;380 var sum = 0;
381 while (i < 1001) : (i += 1) {381 while (i < 1001) : (i += 1) {
382 sum += i;382 sum += i;
383 }383 }
384 assertOrPanic(sum == 500500);384 expect(sum == 500500);
385 }385 }
386}386}
387387
388// TODO test "float literal at compile time not lossy" {388// TODO test "float literal at compile time not lossy" {
389// TODO assertOrPanic(16777216.0 + 1.0 == 16777217.0);389// TODO expect(16777216.0 + 1.0 == 16777217.0);
390// TODO assertOrPanic(9007199254740992.0 + 1.0 == 9007199254740993.0);390// TODO expect(9007199254740992.0 + 1.0 == 9007199254740993.0);
391// TODO }391// TODO }
392392
393test "f32 at compile time is lossy" {393test "f32 at compile time is lossy" {
394 assertOrPanic(f32(1 << 24) + 1 == 1 << 24);394 expect(f32(1 << 24) + 1 == 1 << 24);
395}395}
396396
397test "f64 at compile time is lossy" {397test "f64 at compile time is lossy" {
398 assertOrPanic(f64(1 << 53) + 1 == 1 << 53);398 expect(f64(1 << 53) + 1 == 1 << 53);
399}399}
400400
401test "f128 at compile time is lossy" {401test "f128 at compile time is lossy" {
402 assertOrPanic(f128(10384593717069655257060992658440192.0) + 1 == 10384593717069655257060992658440192.0);402 expect(f128(10384593717069655257060992658440192.0) + 1 == 10384593717069655257060992658440192.0);
403}403}
404404
405comptime {405comptime {
406 assertOrPanic(f128(1 << 113) == 10384593717069655257060992658440192);406 expect(f128(1 << 113) == 10384593717069655257060992658440192);
407}407}
408408
409pub fn TypeWithCompTimeSlice(comptime field_name: []const u8) type {409pub fn TypeWithCompTimeSlice(comptime field_name: []const u8) type {
...@@ -415,15 +415,15 @@ pub fn TypeWithCompTimeSlice(comptime field_name: []const u8) type {...@@ -415,15 +415,15 @@ pub fn TypeWithCompTimeSlice(comptime field_name: []const u8) type {
415test "string literal used as comptime slice is memoized" {415test "string literal used as comptime slice is memoized" {
416 const a = "link";416 const a = "link";
417 const b = "link";417 const b = "link";
418 comptime assertOrPanic(TypeWithCompTimeSlice(a).Node == TypeWithCompTimeSlice(b).Node);418 comptime expect(TypeWithCompTimeSlice(a).Node == TypeWithCompTimeSlice(b).Node);
419 comptime assertOrPanic(TypeWithCompTimeSlice("link").Node == TypeWithCompTimeSlice("link").Node);419 comptime expect(TypeWithCompTimeSlice("link").Node == TypeWithCompTimeSlice("link").Node);
420}420}
421421
422test "comptime slice of undefined pointer of length 0" {422test "comptime slice of undefined pointer of length 0" {
423 const slice1 = ([*]i32)(undefined)[0..0];423 const slice1 = ([*]i32)(undefined)[0..0];
424 assertOrPanic(slice1.len == 0);424 expect(slice1.len == 0);
425 const slice2 = ([*]i32)(undefined)[100..100];425 const slice2 = ([*]i32)(undefined)[100..100];
426 assertOrPanic(slice2.len == 0);426 expect(slice2.len == 0);
427}427}
428428
429fn copyWithPartialInline(s: []u32, b: []u8) void {429fn copyWithPartialInline(s: []u32, b: []u8) void {
...@@ -445,16 +445,16 @@ test "binary math operator in partially inlined function" {...@@ -445,16 +445,16 @@ test "binary math operator in partially inlined function" {
445 r.* = @intCast(u8, i + 1);445 r.* = @intCast(u8, i + 1);
446446
447 copyWithPartialInline(s[0..], b[0..]);447 copyWithPartialInline(s[0..], b[0..]);
448 assertOrPanic(s[0] == 0x1020304);448 expect(s[0] == 0x1020304);
449 assertOrPanic(s[1] == 0x5060708);449 expect(s[1] == 0x5060708);
450 assertOrPanic(s[2] == 0x90a0b0c);450 expect(s[2] == 0x90a0b0c);
451 assertOrPanic(s[3] == 0xd0e0f10);451 expect(s[3] == 0xd0e0f10);
452}452}
453453
454test "comptime function with the same args is memoized" {454test "comptime function with the same args is memoized" {
455 comptime {455 comptime {
456 assertOrPanic(MakeType(i32) == MakeType(i32));456 expect(MakeType(i32) == MakeType(i32));
457 assertOrPanic(MakeType(i32) != MakeType(f64));457 expect(MakeType(i32) != MakeType(f64));
458 }458 }
459}459}
460460
...@@ -470,7 +470,7 @@ test "comptime function with mutable pointer is not memoized" {...@@ -470,7 +470,7 @@ test "comptime function with mutable pointer is not memoized" {
470 const ptr = &x;470 const ptr = &x;
471 increment(ptr);471 increment(ptr);
472 increment(ptr);472 increment(ptr);
473 assertOrPanic(x == 3);473 expect(x == 3);
474 }474 }
475}475}
476476
...@@ -496,14 +496,14 @@ fn doesAlotT(comptime T: type, value: usize) T {...@@ -496,14 +496,14 @@ fn doesAlotT(comptime T: type, value: usize) T {
496}496}
497497
498test "@setEvalBranchQuota at same scope as generic function call" {498test "@setEvalBranchQuota at same scope as generic function call" {
499 assertOrPanic(doesAlotT(u32, 2) == 2);499 expect(doesAlotT(u32, 2) == 2);
500}500}
501501
502test "comptime slice of slice preserves comptime var" {502test "comptime slice of slice preserves comptime var" {
503 comptime {503 comptime {
504 var buff: [10]u8 = undefined;504 var buff: [10]u8 = undefined;
505 buff[0..][0..][0] = 1;505 buff[0..][0..][0] = 1;
506 assertOrPanic(buff[0..][0..][0] == 1);506 expect(buff[0..][0..][0] == 1);
507 }507 }
508}508}
509509
...@@ -512,7 +512,7 @@ test "comptime slice of pointer preserves comptime var" {...@@ -512,7 +512,7 @@ test "comptime slice of pointer preserves comptime var" {
512 var buff: [10]u8 = undefined;512 var buff: [10]u8 = undefined;
513 var a = buff[0..].ptr;513 var a = buff[0..].ptr;
514 a[0..1][0] = 1;514 a[0..1][0] = 1;
515 assertOrPanic(buff[0..][0..][0] == 1);515 expect(buff[0..][0..][0] == 1);
516 }516 }
517}517}
518518
...@@ -526,9 +526,9 @@ const SingleFieldStruct = struct {...@@ -526,9 +526,9 @@ const SingleFieldStruct = struct {
526test "const ptr to comptime mutable data is not memoized" {526test "const ptr to comptime mutable data is not memoized" {
527 comptime {527 comptime {
528 var foo = SingleFieldStruct{ .x = 1 };528 var foo = SingleFieldStruct{ .x = 1 };
529 assertOrPanic(foo.read_x() == 1);529 expect(foo.read_x() == 1);
530 foo.x = 2;530 foo.x = 2;
531 assertOrPanic(foo.read_x() == 2);531 expect(foo.read_x() == 2);
532 }532 }
533}533}
534534
...@@ -537,7 +537,7 @@ test "array concat of slices gives slice" {...@@ -537,7 +537,7 @@ test "array concat of slices gives slice" {
537 var a: []const u8 = "aoeu";537 var a: []const u8 = "aoeu";
538 var b: []const u8 = "asdf";538 var b: []const u8 = "asdf";
539 const c = a ++ b;539 const c = a ++ b;
540 assertOrPanic(std.mem.eql(u8, c, "aoeuasdf"));540 expect(std.mem.eql(u8, c, "aoeuasdf"));
541 }541 }
542}542}
543543
...@@ -554,14 +554,14 @@ test "comptime shlWithOverflow" {...@@ -554,14 +554,14 @@ test "comptime shlWithOverflow" {
554 break :amt amt;554 break :amt amt;
555 };555 };
556556
557 assertOrPanic(ct_shifted == rt_shifted);557 expect(ct_shifted == rt_shifted);
558}558}
559559
560test "runtime 128 bit integer division" {560test "runtime 128 bit integer division" {
561 var a: u128 = 152313999999999991610955792383;561 var a: u128 = 152313999999999991610955792383;
562 var b: u128 = 10000000000000000000;562 var b: u128 = 10000000000000000000;
563 var c = a / b;563 var c = a / b;
564 assertOrPanic(c == 15231399999);564 expect(c == 15231399999);
565}565}
566566
567pub const Info = struct {567pub const Info = struct {
...@@ -574,20 +574,20 @@ test "comptime modification of const struct field" {...@@ -574,20 +574,20 @@ test "comptime modification of const struct field" {
574 comptime {574 comptime {
575 var res = diamond_info;575 var res = diamond_info;
576 res.version = 1;576 res.version = 1;
577 assertOrPanic(diamond_info.version == 0);577 expect(diamond_info.version == 0);
578 assertOrPanic(res.version == 1);578 expect(res.version == 1);
579 }579 }
580}580}
581581
582test "pointer to type" {582test "pointer to type" {
583 comptime {583 comptime {
584 var T: type = i32;584 var T: type = i32;
585 assertOrPanic(T == i32);585 expect(T == i32);
586 var ptr = &T;586 var ptr = &T;
587 assertOrPanic(@typeOf(ptr) == *type);587 expect(@typeOf(ptr) == *type);
588 ptr.* = f32;588 ptr.* = f32;
589 assertOrPanic(T == f32);589 expect(T == f32);
590 assertOrPanic(*T == *f32);590 expect(*T == *f32);
591 }591 }
592}592}
593593
...@@ -596,17 +596,17 @@ test "slice of type" {...@@ -596,17 +596,17 @@ test "slice of type" {
596 var types_array = []type{ i32, f64, type };596 var types_array = []type{ i32, f64, type };
597 for (types_array) |T, i| {597 for (types_array) |T, i| {
598 switch (i) {598 switch (i) {
599 0 => assertOrPanic(T == i32),599 0 => expect(T == i32),
600 1 => assertOrPanic(T == f64),600 1 => expect(T == f64),
601 2 => assertOrPanic(T == type),601 2 => expect(T == type),
602 else => unreachable,602 else => unreachable,
603 }603 }
604 }604 }
605 for (types_array[0..]) |T, i| {605 for (types_array[0..]) |T, i| {
606 switch (i) {606 switch (i) {
607 0 => assertOrPanic(T == i32),607 0 => expect(T == i32),
608 1 => assertOrPanic(T == f64),608 1 => expect(T == f64),
609 2 => assertOrPanic(T == type),609 2 => expect(T == type),
610 else => unreachable,610 else => unreachable,
611 }611 }
612 }612 }
...@@ -623,7 +623,7 @@ fn wrap(comptime T: type) Wrapper {...@@ -623,7 +623,7 @@ fn wrap(comptime T: type) Wrapper {
623623
624test "function which returns struct with type field causes implicit comptime" {624test "function which returns struct with type field causes implicit comptime" {
625 const ty = wrap(i32).T;625 const ty = wrap(i32).T;
626 assertOrPanic(ty == i32);626 expect(ty == i32);
627}627}
628628
629test "call method with comptime pass-by-non-copying-value self parameter" {629test "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" {...@@ -637,12 +637,12 @@ test "call method with comptime pass-by-non-copying-value self parameter" {
637637
638 const s = S{ .a = 2 };638 const s = S{ .a = 2 };
639 var b = s.b();639 var b = s.b();
640 assertOrPanic(b == 2);640 expect(b == 2);
641}641}
642642
643test "@tagName of @typeId" {643test "@tagName of @typeId" {
644 const str = @tagName(@typeId(u8));644 const str = @tagName(@typeId(u8));
645 assertOrPanic(std.mem.eql(u8, str, "Int"));645 expect(std.mem.eql(u8, str, "Int"));
646}646}
647647
648test "setting backward branch quota just before a generic fn call" {648test "setting backward branch quota just before a generic fn call" {
...@@ -663,8 +663,8 @@ fn testVarInsideInlineLoop(args: ...) void {...@@ -663,8 +663,8 @@ fn testVarInsideInlineLoop(args: ...) void {
663 comptime var i = 0;663 comptime var i = 0;
664 inline while (i < args.len) : (i += 1) {664 inline while (i < args.len) : (i += 1) {
665 const x = args[i];665 const x = args[i];
666 if (i == 0) assertOrPanic(x);666 if (i == 0) expect(x);
667 if (i == 1) assertOrPanic(x == 42);667 if (i == 1) expect(x == 42);
668 }668 }
669}669}
670670
...@@ -674,7 +674,7 @@ test "inline for with same type but different values" {...@@ -674,7 +674,7 @@ test "inline for with same type but different values" {
674 var a: T = undefined;674 var a: T = undefined;
675 res += a.len;675 res += a.len;
676 }676 }
677 assertOrPanic(res == 5);677 expect(res == 5);
678}678}
679679
680test "refer to the type of a generic function" {680test "refer to the type of a generic function" {
...@@ -688,19 +688,13 @@ fn doNothingWithType(comptime T: type) void {}...@@ -688,19 +688,13 @@ fn doNothingWithType(comptime T: type) void {}
688test "zero extend from u0 to u1" {688test "zero extend from u0 to u1" {
689 var zero_u0: u0 = 0;689 var zero_u0: u0 = 0;
690 var zero_u1: u1 = zero_u0;690 var zero_u1: u1 = zero_u0;
691 assertOrPanic(zero_u1 == 0);691 expect(zero_u1 == 0);
692}692}
693693
694test "bit shift a u1" {694test "bit shift a u1" {
695 var x: u1 = 1;695 var x: u1 = 1;
696 var y = x << 0;696 var y = x << 0;
697 assertOrPanic(y == 1);697 expect(y == 1);
698}
699
700test "@intCast to a u0" {
701 var x: u8 = 0;
702 var y: u0 = @intCast(u0, x);
703 assertOrPanic(y == 0);
704}698}
705699
706test "@bytesToslice on a packed struct" {700test "@bytesToslice on a packed struct" {
...@@ -710,7 +704,7 @@ test "@bytesToslice on a packed struct" {...@@ -710,7 +704,7 @@ test "@bytesToslice on a packed struct" {
710704
711 var b = [1]u8{9};705 var b = [1]u8{9};
712 var f = @bytesToSlice(F, b);706 var f = @bytesToSlice(F, b);
713 assertOrPanic(f[0].a == 9);707 expect(f[0].a == 9);
714}708}
715709
716test "comptime pointer cast array and then slice" {710test "comptime pointer cast array and then slice" {
...@@ -722,8 +716,8 @@ test "comptime pointer cast array and then slice" {...@@ -722,8 +716,8 @@ test "comptime pointer cast array and then slice" {
722 const ptrB: [*]const u8 = &array;716 const ptrB: [*]const u8 = &array;
723 const sliceB: []const u8 = ptrB[0..2];717 const sliceB: []const u8 = ptrB[0..2];
724718
725 assertOrPanic(sliceA[1] == 2);719 expect(sliceA[1] == 2);
726 assertOrPanic(sliceB[1] == 2);720 expect(sliceB[1] == 2);
727}721}
728722
729test "slice bounds in comptime concatenation" {723test "slice bounds in comptime concatenation" {
...@@ -732,47 +726,47 @@ test "slice bounds in comptime concatenation" {...@@ -732,47 +726,47 @@ test "slice bounds in comptime concatenation" {
732 break :blk b[8..9];726 break :blk b[8..9];
733 };727 };
734 const str = "" ++ bs;728 const str = "" ++ bs;
735 assertOrPanic(str.len == 1);729 expect(str.len == 1);
736 assertOrPanic(std.mem.eql(u8, str, "1"));730 expect(std.mem.eql(u8, str, "1"));
737731
738 const str2 = bs ++ "";732 const str2 = bs ++ "";
739 assertOrPanic(str2.len == 1);733 expect(str2.len == 1);
740 assertOrPanic(std.mem.eql(u8, str2, "1"));734 expect(std.mem.eql(u8, str2, "1"));
741}735}
742736
743test "comptime bitwise operators" {737test "comptime bitwise operators" {
744 comptime {738 comptime {
745 assertOrPanic(3 & 1 == 1);739 expect(3 & 1 == 1);
746 assertOrPanic(3 & -1 == 3);740 expect(3 & -1 == 3);
747 assertOrPanic(-3 & -1 == -3);741 expect(-3 & -1 == -3);
748 assertOrPanic(3 | -1 == -1);742 expect(3 | -1 == -1);
749 assertOrPanic(-3 | -1 == -1);743 expect(-3 | -1 == -1);
750 assertOrPanic(3 ^ -1 == -4);744 expect(3 ^ -1 == -4);
751 assertOrPanic(-3 ^ -1 == 2);745 expect(-3 ^ -1 == 2);
752 assertOrPanic(~i8(-1) == 0);746 expect(~i8(-1) == 0);
753 assertOrPanic(~i128(-1) == 0);747 expect(~i128(-1) == 0);
754 assertOrPanic(18446744073709551615 & 18446744073709551611 == 18446744073709551611);748 expect(18446744073709551615 & 18446744073709551611 == 18446744073709551611);
755 assertOrPanic(-18446744073709551615 & -18446744073709551611 == -18446744073709551615);749 expect(-18446744073709551615 & -18446744073709551611 == -18446744073709551615);
756 assertOrPanic(~u128(0) == 0xffffffffffffffffffffffffffffffff);750 expect(~u128(0) == 0xffffffffffffffffffffffffffffffff);
757 }751 }
758}752}
759753
760test "*align(1) u16 is the same as *align(1:0:2) u16" {754test "*align(1) u16 is the same as *align(1:0:2) u16" {
761 comptime {755 comptime {
762 assertOrPanic(*align(1:0:2) u16 == *align(1) u16);756 expect(*align(1:0:2) u16 == *align(1) u16);
763 // TODO add parsing support for this syntax757 // TODO add parsing support for this syntax
764 //assertOrPanic(*align(:0:2) u16 == *u16);758 //expect(*align(:0:2) u16 == *u16);
765 }759 }
766}760}
767761
768test "array concatenation forces comptime" {762test "array concatenation forces comptime" {
769 var a = oneItem(3) ++ oneItem(4);763 var a = oneItem(3) ++ oneItem(4);
770 assertOrPanic(std.mem.eql(i32, a, []i32{ 3, 4 }));764 expect(std.mem.eql(i32, a, []i32{ 3, 4 }));
771}765}
772766
773test "array multiplication forces comptime" {767test "array multiplication forces comptime" {
774 var a = oneItem(3) ** scalar(2);768 var a = oneItem(3) ** scalar(2);
775 assertOrPanic(std.mem.eql(i32, a, []i32{ 3, 3 }));769 expect(std.mem.eql(i32, a, []i32{ 3, 3 }));
776}770}
777771
778fn oneItem(x: i32) [1]i32 {772fn oneItem(x: i32) [1]i32 {
test/stage1/behavior/field_parent_ptr.zig+7-7
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;1const expect = @import("std").testing.expect;
22
3test "@fieldParentPtr non-first field" {3test "@fieldParentPtr non-first field" {
4 testParentFieldPtr(&foo.c);4 testParentFieldPtr(&foo.c);
...@@ -25,17 +25,17 @@ const foo = Foo{...@@ -25,17 +25,17 @@ const foo = Foo{
25};25};
2626
27fn testParentFieldPtr(c: *const i32) void {27fn testParentFieldPtr(c: *const i32) void {
28 assertOrPanic(c == &foo.c);28 expect(c == &foo.c);
2929
30 const base = @fieldParentPtr(Foo, "c", c);30 const base = @fieldParentPtr(Foo, "c", c);
31 assertOrPanic(base == &foo);31 expect(base == &foo);
32 assertOrPanic(&base.c == c);32 expect(&base.c == c);
33}33}
3434
35fn testParentFieldPtrFirst(a: *const bool) void {35fn testParentFieldPtrFirst(a: *const bool) void {
36 assertOrPanic(a == &foo.a);36 expect(a == &foo.a);
3737
38 const base = @fieldParentPtr(Foo, "a", a);38 const base = @fieldParentPtr(Foo, "a", a);
39 assertOrPanic(base == &foo);39 expect(base == &foo);
40 assertOrPanic(&base.a == a);40 expect(&base.a == a);
41}41}
test/stage1/behavior/fn.zig+19-19
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;1const expect = @import("std").testing.expect;
22
3test "params" {3test "params" {
4 assertOrPanic(testParamsAdd(22, 11) == 33);4 expect(testParamsAdd(22, 11) == 33);
5}5}
6fn testParamsAdd(a: i32, b: i32) i32 {6fn testParamsAdd(a: i32, b: i32) i32 {
7 return a + b;7 return a + b;
...@@ -21,32 +21,32 @@ test "void parameters" {...@@ -21,32 +21,32 @@ test "void parameters" {
21fn voidFun(a: i32, b: void, c: i32, d: void) void {21fn voidFun(a: i32, b: void, c: i32, d: void) void {
22 const v = b;22 const v = b;
23 const vv: void = if (a == 1) v else {};23 const vv: void = if (a == 1) v else {};
24 assertOrPanic(a + c == 3);24 expect(a + c == 3);
25 return vv;25 return vv;
26}26}
2727
28test "mutable local variables" {28test "mutable local variables" {
29 var zero: i32 = 0;29 var zero: i32 = 0;
30 assertOrPanic(zero == 0);30 expect(zero == 0);
3131
32 var i = i32(0);32 var i = i32(0);
33 while (i != 3) {33 while (i != 3) {
34 i += 1;34 i += 1;
35 }35 }
36 assertOrPanic(i == 3);36 expect(i == 3);
37}37}
3838
39test "separate block scopes" {39test "separate block scopes" {
40 {40 {
41 const no_conflict: i32 = 5;41 const no_conflict: i32 = 5;
42 assertOrPanic(no_conflict == 5);42 expect(no_conflict == 5);
43 }43 }
4444
45 const c = x: {45 const c = x: {
46 const no_conflict = i32(10);46 const no_conflict = i32(10);
47 break :x no_conflict;47 break :x no_conflict;
48 };48 };
49 assertOrPanic(c == 10);49 expect(c == 10);
50}50}
5151
52test "call function with empty string" {52test "call function with empty string" {
...@@ -59,7 +59,7 @@ fn @"weird function name"() i32 {...@@ -59,7 +59,7 @@ fn @"weird function name"() i32 {
59 return 1234;59 return 1234;
60}60}
61test "weird function name" {61test "weird function name" {
62 assertOrPanic(@"weird function name"() == 1234);62 expect(@"weird function name"() == 1234);
63}63}
6464
65test "implicit cast function unreachable return" {65test "implicit cast function unreachable return" {
...@@ -80,7 +80,7 @@ test "function pointers" {...@@ -80,7 +80,7 @@ test "function pointers" {
80 fn4,80 fn4,
81 };81 };
82 for (fns) |f, i| {82 for (fns) |f, i| {
83 assertOrPanic(f() == @intCast(u32, i) + 5);83 expect(f() == @intCast(u32, i) + 5);
84 }84 }
85}85}
86fn fn1() u32 {86fn fn1() u32 {
...@@ -97,7 +97,7 @@ fn fn4() u32 {...@@ -97,7 +97,7 @@ fn fn4() u32 {
97}97}
9898
99test "inline function call" {99test "inline function call" {
100 assertOrPanic(@inlineCall(add, 3, 9) == 12);100 expect(@inlineCall(add, 3, 9) == 12);
101}101}
102102
103fn add(a: i32, b: i32) i32 {103fn add(a: i32, b: i32) i32 {
...@@ -110,7 +110,7 @@ test "number literal as an argument" {...@@ -110,7 +110,7 @@ test "number literal as an argument" {
110}110}
111111
112fn numberLiteralArg(a: var) void {112fn numberLiteralArg(a: var) void {
113 assertOrPanic(a == 3);113 expect(a == 3);
114}114}
115115
116test "assign inline fn to const variable" {116test "assign inline fn to const variable" {
...@@ -121,7 +121,7 @@ test "assign inline fn to const variable" {...@@ -121,7 +121,7 @@ test "assign inline fn to const variable" {
121inline fn inlineFn() void {}121inline fn inlineFn() void {}
122122
123test "pass by non-copying value" {123test "pass by non-copying value" {
124 assertOrPanic(addPointCoords(Point{ .x = 1, .y = 2 }) == 3);124 expect(addPointCoords(Point{ .x = 1, .y = 2 }) == 3);
125}125}
126126
127const Point = struct {127const Point = struct {
...@@ -134,17 +134,17 @@ fn addPointCoords(pt: Point) i32 {...@@ -134,17 +134,17 @@ fn addPointCoords(pt: Point) i32 {
134}134}
135135
136test "pass by non-copying value through var arg" {136test "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);
138}138}
139139
140fn addPointCoordsVar(pt: var) i32 {140fn addPointCoordsVar(pt: var) i32 {
141 comptime assertOrPanic(@typeOf(pt) == Point);141 comptime expect(@typeOf(pt) == Point);
142 return pt.x + pt.y;142 return pt.x + pt.y;
143}143}
144144
145test "pass by non-copying value as method" {145test "pass by non-copying value as method" {
146 var pt = Point2{ .x = 1, .y = 2 };146 var pt = Point2{ .x = 1, .y = 2 };
147 assertOrPanic(pt.addPointCoords() == 3);147 expect(pt.addPointCoords() == 3);
148}148}
149149
150const Point2 = struct {150const Point2 = struct {
...@@ -158,7 +158,7 @@ const Point2 = struct {...@@ -158,7 +158,7 @@ const Point2 = struct {
158158
159test "pass by non-copying value as method, which is generic" {159test "pass by non-copying value as method, which is generic" {
160 var pt = Point3{ .x = 1, .y = 2 };160 var pt = Point3{ .x = 1, .y = 2 };
161 assertOrPanic(pt.addPointCoords(i32) == 3);161 expect(pt.addPointCoords(i32) == 3);
162}162}
163163
164const Point3 = struct {164const Point3 = struct {
...@@ -173,7 +173,7 @@ const Point3 = struct {...@@ -173,7 +173,7 @@ const Point3 = struct {
173test "pass by non-copying value as method, at comptime" {173test "pass by non-copying value as method, at comptime" {
174 comptime {174 comptime {
175 var pt = Point2{ .x = 1, .y = 2 };175 var pt = Point2{ .x = 1, .y = 2 };
176 assertOrPanic(pt.addPointCoords() == 3);176 expect(pt.addPointCoords() == 3);
177 }177 }
178}178}
179179
...@@ -189,7 +189,7 @@ fn outer(y: u32) fn (u32) u32 {...@@ -189,7 +189,7 @@ fn outer(y: u32) fn (u32) u32 {
189189
190test "return inner function which references comptime variable of outer function" {190test "return inner function which references comptime variable of outer function" {
191 var func = outer(10);191 var func = outer(10);
192 assertOrPanic(func(3) == 7);192 expect(func(3) == 7);
193}193}
194194
195test "extern struct with stdcallcc fn pointer" {195test "extern struct with stdcallcc fn pointer" {
...@@ -203,6 +203,6 @@ test "extern struct with stdcallcc fn pointer" {...@@ -203,6 +203,6 @@ test "extern struct with stdcallcc fn pointer" {
203203
204 var s: S = undefined;204 var s: S = undefined;
205 s.ptr = S.foo;205 s.ptr = S.foo;
206 assertOrPanic(s.ptr() == 1234);206 expect(s.ptr() == 1234);
207}207}
208208
test/stage1/behavior/fn_in_struct_in_comptime.zig+2-2
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;1const expect = @import("std").testing.expect;
22
3fn get_foo() fn (*u8) usize {3fn get_foo() fn (*u8) usize {
4 comptime {4 comptime {
...@@ -13,5 +13,5 @@ fn get_foo() fn (*u8) usize {...@@ -13,5 +13,5 @@ fn get_foo() fn (*u8) usize {
1313
14test "define a function in an anonymous struct in comptime" {14test "define a function in an anonymous struct in comptime" {
15 const foo = get_foo();15 const foo = get_foo();
16 assertOrPanic(foo(@intToPtr(*u8, 12345)) == 12345);16 expect(foo(@intToPtr(*u8, 12345)) == 12345);
17}17}
test/stage1/behavior/for.zig+5-5
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const assertOrPanic = std.debug.assertOrPanic;2const expect = std.testing.expect;
3const mem = std.mem;3const mem = std.mem;
44
5test "continue in for loop" {5test "continue in for loop" {
...@@ -26,7 +26,7 @@ test "for loop with pointer elem var" {...@@ -26,7 +26,7 @@ test "for loop with pointer elem var" {
26 var target: [source.len]u8 = undefined;26 var target: [source.len]u8 = undefined;
27 mem.copy(u8, target[0..], source);27 mem.copy(u8, target[0..], source);
28 mangleString(target[0..]);28 mangleString(target[0..]);
29 assertOrPanic(mem.eql(u8, target, "bcdefgh"));29 expect(mem.eql(u8, target, "bcdefgh"));
30}30}
31fn mangleString(s: []u8) void {31fn mangleString(s: []u8) void {
32 for (s) |*c| {32 for (s) |*c| {
...@@ -68,7 +68,7 @@ test "basic for loop" {...@@ -68,7 +68,7 @@ test "basic for loop" {
68 buf_index += 1;68 buf_index += 1;
69 }69 }
7070
71 assertOrPanic(mem.eql(u8, buffer[0..buf_index], expected_result));71 expect(mem.eql(u8, buffer[0..buf_index], expected_result));
72}72}
7373
74test "break from outer for loop" {74test "break from outer for loop" {
...@@ -85,7 +85,7 @@ fn testBreakOuter() void {...@@ -85,7 +85,7 @@ fn testBreakOuter() void {
85 break :outer;85 break :outer;
86 }86 }
87 }87 }
88 assertOrPanic(count == 1);88 expect(count == 1);
89}89}
9090
91test "continue outer for loop" {91test "continue outer for loop" {
...@@ -102,5 +102,5 @@ fn testContinueOuter() void {...@@ -102,5 +102,5 @@ fn testContinueOuter() void {
102 continue :outer;102 continue :outer;
103 }103 }
104 }104 }
105 assertOrPanic(counter == array.len);105 expect(counter == array.len);
106}106}
test/stage1/behavior/generics.zig+23-23
...@@ -1,9 +1,9 @@...@@ -1,9 +1,9 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;1const expect = @import("std").testing.expect;
22
3test "simple generic fn" {3test "simple generic fn" {
4 assertOrPanic(max(i32, 3, -1) == 3);4 expect(max(i32, 3, -1) == 3);
5 assertOrPanic(max(f32, 0.123, 0.456) == 0.456);5 expect(max(f32, 0.123, 0.456) == 0.456);
6 assertOrPanic(add(2, 3) == 5);6 expect(add(2, 3) == 5);
7}7}
88
9fn max(comptime T: type, a: T, b: T) T {9fn max(comptime T: type, a: T, b: T) T {
...@@ -16,7 +16,7 @@ fn add(comptime a: i32, b: i32) i32 {...@@ -16,7 +16,7 @@ fn add(comptime a: i32, b: i32) i32 {
1616
17const the_max = max(u32, 1234, 5678);17const the_max = max(u32, 1234, 5678);
18test "compile time generic eval" {18test "compile time generic eval" {
19 assertOrPanic(the_max == 5678);19 expect(the_max == 5678);
20}20}
2121
22fn gimmeTheBigOne(a: u32, b: u32) u32 {22fn gimmeTheBigOne(a: u32, b: u32) u32 {
...@@ -32,19 +32,19 @@ fn sameButWithFloats(a: f64, b: f64) f64 {...@@ -32,19 +32,19 @@ fn sameButWithFloats(a: f64, b: f64) f64 {
32}32}
3333
34test "fn with comptime args" {34test "fn with comptime args" {
35 assertOrPanic(gimmeTheBigOne(1234, 5678) == 5678);35 expect(gimmeTheBigOne(1234, 5678) == 5678);
36 assertOrPanic(shouldCallSameInstance(34, 12) == 34);36 expect(shouldCallSameInstance(34, 12) == 34);
37 assertOrPanic(sameButWithFloats(0.43, 0.49) == 0.49);37 expect(sameButWithFloats(0.43, 0.49) == 0.49);
38}38}
3939
40test "var params" {40test "var params" {
41 assertOrPanic(max_i32(12, 34) == 34);41 expect(max_i32(12, 34) == 34);
42 assertOrPanic(max_f64(1.2, 3.4) == 3.4);42 expect(max_f64(1.2, 3.4) == 3.4);
43}43}
4444
45comptime {45comptime {
46 assertOrPanic(max_i32(12, 34) == 34);46 expect(max_i32(12, 34) == 34);
47 assertOrPanic(max_f64(1.2, 3.4) == 3.4);47 expect(max_f64(1.2, 3.4) == 3.4);
48}48}
4949
50fn max_var(a: var, b: var) @typeOf(a + b) {50fn max_var(a: var, b: var) @typeOf(a + b) {
...@@ -76,8 +76,8 @@ test "function with return type type" {...@@ -76,8 +76,8 @@ test "function with return type type" {
76 var list2: List(i32) = undefined;76 var list2: List(i32) = undefined;
77 list.length = 10;77 list.length = 10;
78 list2.length = 10;78 list2.length = 10;
79 assertOrPanic(list.prealloc_items.len == 8);79 expect(list.prealloc_items.len == 8);
80 assertOrPanic(list2.prealloc_items.len == 8);80 expect(list2.prealloc_items.len == 8);
81}81}
8282
83test "generic struct" {83test "generic struct" {
...@@ -89,9 +89,9 @@ test "generic struct" {...@@ -89,9 +89,9 @@ test "generic struct" {
89 .value = true,89 .value = true,
90 .next = null,90 .next = null,
91 };91 };
92 assertOrPanic(a1.value == 13);92 expect(a1.value == 13);
93 assertOrPanic(a1.value == a1.getVal());93 expect(a1.value == a1.getVal());
94 assertOrPanic(b1.getVal());94 expect(b1.getVal());
95}95}
96fn GenNode(comptime T: type) type {96fn GenNode(comptime T: type) type {
97 return struct {97 return struct {
...@@ -104,7 +104,7 @@ fn GenNode(comptime T: type) type {...@@ -104,7 +104,7 @@ fn GenNode(comptime T: type) type {
104}104}
105105
106test "const decls in struct" {106test "const decls in struct" {
107 assertOrPanic(GenericDataThing(3).count_plus_one == 4);107 expect(GenericDataThing(3).count_plus_one == 4);
108}108}
109fn GenericDataThing(comptime count: isize) type {109fn GenericDataThing(comptime count: isize) type {
110 return struct {110 return struct {
...@@ -113,15 +113,15 @@ fn GenericDataThing(comptime count: isize) type {...@@ -113,15 +113,15 @@ fn GenericDataThing(comptime count: isize) type {
113}113}
114114
115test "use generic param in generic param" {115test "use generic param in generic param" {
116 assertOrPanic(aGenericFn(i32, 3, 4) == 7);116 expect(aGenericFn(i32, 3, 4) == 7);
117}117}
118fn aGenericFn(comptime T: type, comptime a: T, b: T) T {118fn aGenericFn(comptime T: type, comptime a: T, b: T) T {
119 return a + b;119 return a + b;
120}120}
121121
122test "generic fn with implicit cast" {122test "generic fn with implicit cast" {
123 assertOrPanic(getFirstByte(u8, []u8{13}) == 13);123 expect(getFirstByte(u8, []u8{13}) == 13);
124 assertOrPanic(getFirstByte(u16, []u16{124 expect(getFirstByte(u16, []u16{
125 0,125 0,
126 13,126 13,
127 }) == 0);127 }) == 0);
...@@ -146,6 +146,6 @@ fn foo2(arg: var) bool {...@@ -146,6 +146,6 @@ fn foo2(arg: var) bool {
146}146}
147147
148test "array of generic fns" {148test "array of generic fns" {
149 assertOrPanic(foos[0](true));149 expect(foos[0](true));
150 assertOrPanic(!foos[1](true));150 expect(!foos[1](true));
151}151}
test/stage1/behavior/if.zig+2-2
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;1const expect = @import("std").testing.expect;
22
3test "if statements" {3test "if statements" {
4 shouldBeEqual(1, 1);4 shouldBeEqual(1, 1);
...@@ -24,7 +24,7 @@ fn firstEqlThird(a: i32, b: i32, c: i32) void {...@@ -24,7 +24,7 @@ fn firstEqlThird(a: i32, b: i32, c: i32) void {
24}24}
2525
26test "else if expression" {26test "else if expression" {
27 assertOrPanic(elseIfExpressionF(1) == 1);27 expect(elseIfExpressionF(1) == 1);
28}28}
29fn elseIfExpressionF(c: u8) u8 {29fn elseIfExpressionF(c: u8) u8 {
30 if (c == 0) {30 if (c == 0) {
test/stage1/behavior/import.zig+3-3
...@@ -1,10 +1,10 @@...@@ -1,10 +1,10 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;1const expect = @import("std").testing.expect;
2const a_namespace = @import("import/a_namespace.zig");2const a_namespace = @import("import/a_namespace.zig");
33
4test "call fn via namespace lookup" {4test "call fn via namespace lookup" {
5 assertOrPanic(a_namespace.foo() == 1234);5 expect(a_namespace.foo() == 1234);
6}6}
77
8test "importing the same thing gives the same import" {8test "importing the same thing gives the same import" {
9 assertOrPanic(@import("std") == @import("std"));9 expect(@import("std") == @import("std"));
10}10}
test/stage1/behavior/incomplete_struct_param_tld.zig+2-2
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;1const expect = @import("std").testing.expect;
22
3const A = struct {3const A = struct {
4 b: B,4 b: B,
...@@ -26,5 +26,5 @@ test "incomplete struct param top level declaration" {...@@ -26,5 +26,5 @@ test "incomplete struct param top level declaration" {
26 .c = C{ .x = 13 },26 .c = C{ .x = 13 },
27 },27 },
28 };28 };
29 assertOrPanic(foo(a) == 13);29 expect(foo(a) == 13);
30}30}
test/stage1/behavior/inttoptr.zig+1-1
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const builtin = @import("builtin");1const builtin = @import("builtin");
2const std = @import("std");2const std = @import("std");
3const assertOrPanic = std.debug.assertOrPanic;3const expect = std.testing.expect;
44
5test "casting random address to function pointer" {5test "casting random address to function pointer" {
6 randomAddressToFunction();6 randomAddressToFunction();
test/stage1/behavior/ir_block_deps.zig+3-3
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;1const expect = @import("std").testing.expect;
22
3fn foo(id: u64) !i32 {3fn foo(id: u64) !i32 {
4 return switch (id) {4 return switch (id) {
...@@ -16,6 +16,6 @@ fn getErrInt() anyerror!i32 {...@@ -16,6 +16,6 @@ fn getErrInt() anyerror!i32 {
16}16}
1717
18test "ir block deps" {18test "ir block deps" {
19 assertOrPanic((foo(1) catch unreachable) == 0);19 expect((foo(1) catch unreachable) == 0);
20 assertOrPanic((foo(2) catch unreachable) == 0);20 expect((foo(2) catch unreachable) == 0);
21}21}
test/stage1/behavior/math.zig+148-131
...@@ -1,5 +1,7 @@...@@ -1,5 +1,7 @@
1const std = @import("std");1const std = @import("std");
2const assertOrPanic = std.debug.assertOrPanic;2const expect = std.testing.expect;
3const expectEqual = std.testing.expectEqual;
4const expectEqualSlices = std.testing.expectEqualSlices;
3const maxInt = std.math.maxInt;5const maxInt = std.math.maxInt;
4const minInt = std.math.minInt;6const minInt = std.math.minInt;
57
...@@ -8,57 +10,57 @@ test "division" {...@@ -8,57 +10,57 @@ test "division" {
8 comptime testDivision();10 comptime testDivision();
9}11}
10fn testDivision() void {12fn testDivision() void {
11 assertOrPanic(div(u32, 13, 3) == 4);13 expect(div(u32, 13, 3) == 4);
12 assertOrPanic(div(f16, 1.0, 2.0) == 0.5);14 expect(div(f16, 1.0, 2.0) == 0.5);
13 assertOrPanic(div(f32, 1.0, 2.0) == 0.5);15 expect(div(f32, 1.0, 2.0) == 0.5);
1416
15 assertOrPanic(divExact(u32, 55, 11) == 5);17 expect(divExact(u32, 55, 11) == 5);
16 assertOrPanic(divExact(i32, -55, 11) == -5);18 expect(divExact(i32, -55, 11) == -5);
17 assertOrPanic(divExact(f16, 55.0, 11.0) == 5.0);19 expect(divExact(f16, 55.0, 11.0) == 5.0);
18 assertOrPanic(divExact(f16, -55.0, 11.0) == -5.0);20 expect(divExact(f16, -55.0, 11.0) == -5.0);
19 assertOrPanic(divExact(f32, 55.0, 11.0) == 5.0);21 expect(divExact(f32, 55.0, 11.0) == 5.0);
20 assertOrPanic(divExact(f32, -55.0, 11.0) == -5.0);22 expect(divExact(f32, -55.0, 11.0) == -5.0);
2123
22 assertOrPanic(divFloor(i32, 5, 3) == 1);24 expect(divFloor(i32, 5, 3) == 1);
23 assertOrPanic(divFloor(i32, -5, 3) == -2);25 expect(divFloor(i32, -5, 3) == -2);
24 assertOrPanic(divFloor(f16, 5.0, 3.0) == 1.0);26 expect(divFloor(f16, 5.0, 3.0) == 1.0);
25 assertOrPanic(divFloor(f16, -5.0, 3.0) == -2.0);27 expect(divFloor(f16, -5.0, 3.0) == -2.0);
26 assertOrPanic(divFloor(f32, 5.0, 3.0) == 1.0);28 expect(divFloor(f32, 5.0, 3.0) == 1.0);
27 assertOrPanic(divFloor(f32, -5.0, 3.0) == -2.0);29 expect(divFloor(f32, -5.0, 3.0) == -2.0);
28 assertOrPanic(divFloor(i32, -0x80000000, -2) == 0x40000000);30 expect(divFloor(i32, -0x80000000, -2) == 0x40000000);
29 assertOrPanic(divFloor(i32, 0, -0x80000000) == 0);31 expect(divFloor(i32, 0, -0x80000000) == 0);
30 assertOrPanic(divFloor(i32, -0x40000001, 0x40000000) == -2);32 expect(divFloor(i32, -0x40000001, 0x40000000) == -2);
31 assertOrPanic(divFloor(i32, -0x80000000, 1) == -0x80000000);33 expect(divFloor(i32, -0x80000000, 1) == -0x80000000);
3234
33 assertOrPanic(divTrunc(i32, 5, 3) == 1);35 expect(divTrunc(i32, 5, 3) == 1);
34 assertOrPanic(divTrunc(i32, -5, 3) == -1);36 expect(divTrunc(i32, -5, 3) == -1);
35 assertOrPanic(divTrunc(f16, 5.0, 3.0) == 1.0);37 expect(divTrunc(f16, 5.0, 3.0) == 1.0);
36 assertOrPanic(divTrunc(f16, -5.0, 3.0) == -1.0);38 expect(divTrunc(f16, -5.0, 3.0) == -1.0);
37 assertOrPanic(divTrunc(f32, 5.0, 3.0) == 1.0);39 expect(divTrunc(f32, 5.0, 3.0) == 1.0);
38 assertOrPanic(divTrunc(f32, -5.0, 3.0) == -1.0);40 expect(divTrunc(f32, -5.0, 3.0) == -1.0);
39 assertOrPanic(divTrunc(f64, 5.0, 3.0) == 1.0);41 expect(divTrunc(f64, 5.0, 3.0) == 1.0);
40 assertOrPanic(divTrunc(f64, -5.0, 3.0) == -1.0);42 expect(divTrunc(f64, -5.0, 3.0) == -1.0);
4143
42 comptime {44 comptime {
43 assertOrPanic(45 expect(
44 1194735857077236777412821811143690633098347576 % 508740759824825164163191790951174292733114988 == 177254337427586449086438229241342047632117600,46 1194735857077236777412821811143690633098347576 % 508740759824825164163191790951174292733114988 == 177254337427586449086438229241342047632117600,
45 );47 );
46 assertOrPanic(48 expect(
47 @rem(-1194735857077236777412821811143690633098347576, 508740759824825164163191790951174292733114988) == -177254337427586449086438229241342047632117600,49 @rem(-1194735857077236777412821811143690633098347576, 508740759824825164163191790951174292733114988) == -177254337427586449086438229241342047632117600,
48 );50 );
49 assertOrPanic(51 expect(
50 1194735857077236777412821811143690633098347576 / 508740759824825164163191790951174292733114988 == 2,52 1194735857077236777412821811143690633098347576 / 508740759824825164163191790951174292733114988 == 2,
51 );53 );
52 assertOrPanic(54 expect(
53 @divTrunc(-1194735857077236777412821811143690633098347576, 508740759824825164163191790951174292733114988) == -2,55 @divTrunc(-1194735857077236777412821811143690633098347576, 508740759824825164163191790951174292733114988) == -2,
54 );56 );
55 assertOrPanic(57 expect(
56 @divTrunc(1194735857077236777412821811143690633098347576, -508740759824825164163191790951174292733114988) == -2,58 @divTrunc(1194735857077236777412821811143690633098347576, -508740759824825164163191790951174292733114988) == -2,
57 );59 );
58 assertOrPanic(60 expect(
59 @divTrunc(-1194735857077236777412821811143690633098347576, -508740759824825164163191790951174292733114988) == 2,61 @divTrunc(-1194735857077236777412821811143690633098347576, -508740759824825164163191790951174292733114988) == 2,
60 );62 );
61 assertOrPanic(63 expect(
62 4126227191251978491697987544882340798050766755606969681711 % 10 == 1,64 4126227191251978491697987544882340798050766755606969681711 % 10 == 1,
63 );65 );
64 }66 }
...@@ -78,9 +80,9 @@ fn divTrunc(comptime T: type, a: T, b: T) T {...@@ -78,9 +80,9 @@ fn divTrunc(comptime T: type, a: T, b: T) T {
7880
79test "@addWithOverflow" {81test "@addWithOverflow" {
80 var result: u8 = undefined;82 var result: u8 = undefined;
81 assertOrPanic(@addWithOverflow(u8, 250, 100, &result));83 expect(@addWithOverflow(u8, 250, 100, &result));
82 assertOrPanic(!@addWithOverflow(u8, 100, 150, &result));84 expect(!@addWithOverflow(u8, 100, 150, &result));
83 assertOrPanic(result == 250);85 expect(result == 250);
84}86}
8587
86// TODO test mulWithOverflow88// TODO test mulWithOverflow
...@@ -88,9 +90,9 @@ test "@addWithOverflow" {...@@ -88,9 +90,9 @@ test "@addWithOverflow" {
8890
89test "@shlWithOverflow" {91test "@shlWithOverflow" {
90 var result: u16 = undefined;92 var result: u16 = undefined;
91 assertOrPanic(@shlWithOverflow(u16, 0b0010111111111111, 3, &result));93 expect(@shlWithOverflow(u16, 0b0010111111111111, 3, &result));
92 assertOrPanic(!@shlWithOverflow(u16, 0b0010111111111111, 2, &result));94 expect(!@shlWithOverflow(u16, 0b0010111111111111, 2, &result));
93 assertOrPanic(result == 0b1011111111111100);95 expect(result == 0b1011111111111100);
94}96}
9597
96test "@clz" {98test "@clz" {
...@@ -99,11 +101,11 @@ test "@clz" {...@@ -99,11 +101,11 @@ test "@clz" {
99}101}
100102
101fn testClz() void {103fn testClz() void {
102 assertOrPanic(clz(u8(0b00001010)) == 4);104 expect(clz(u8(0b00001010)) == 4);
103 assertOrPanic(clz(u8(0b10001010)) == 0);105 expect(clz(u8(0b10001010)) == 0);
104 assertOrPanic(clz(u8(0b00000000)) == 8);106 expect(clz(u8(0b00000000)) == 8);
105 assertOrPanic(clz(u128(0xffffffffffffffff)) == 64);107 expect(clz(u128(0xffffffffffffffff)) == 64);
106 assertOrPanic(clz(u128(0x10000000000000000)) == 63);108 expect(clz(u128(0x10000000000000000)) == 63);
107}109}
108110
109fn clz(x: var) usize {111fn clz(x: var) usize {
...@@ -116,9 +118,9 @@ test "@ctz" {...@@ -116,9 +118,9 @@ test "@ctz" {
116}118}
117119
118fn testCtz() void {120fn testCtz() void {
119 assertOrPanic(ctz(u8(0b10100000)) == 5);121 expect(ctz(u8(0b10100000)) == 5);
120 assertOrPanic(ctz(u8(0b10001010)) == 1);122 expect(ctz(u8(0b10001010)) == 1);
121 assertOrPanic(ctz(u8(0b00000000)) == 8);123 expect(ctz(u8(0b00000000)) == 8);
122}124}
123125
124fn ctz(x: var) usize {126fn ctz(x: var) usize {
...@@ -128,27 +130,27 @@ fn ctz(x: var) usize {...@@ -128,27 +130,27 @@ fn ctz(x: var) usize {
128test "assignment operators" {130test "assignment operators" {
129 var i: u32 = 0;131 var i: u32 = 0;
130 i += 5;132 i += 5;
131 assertOrPanic(i == 5);133 expect(i == 5);
132 i -= 2;134 i -= 2;
133 assertOrPanic(i == 3);135 expect(i == 3);
134 i *= 20;136 i *= 20;
135 assertOrPanic(i == 60);137 expect(i == 60);
136 i /= 3;138 i /= 3;
137 assertOrPanic(i == 20);139 expect(i == 20);
138 i %= 11;140 i %= 11;
139 assertOrPanic(i == 9);141 expect(i == 9);
140 i <<= 1;142 i <<= 1;
141 assertOrPanic(i == 18);143 expect(i == 18);
142 i >>= 2;144 i >>= 2;
143 assertOrPanic(i == 4);145 expect(i == 4);
144 i = 6;146 i = 6;
145 i &= 5;147 i &= 5;
146 assertOrPanic(i == 4);148 expect(i == 4);
147 i ^= 6;149 i ^= 6;
148 assertOrPanic(i == 2);150 expect(i == 2);
149 i = 6;151 i = 6;
150 i |= 3;152 i |= 3;
151 assertOrPanic(i == 7);153 expect(i == 7);
152}154}
153155
154test "three expr in a row" {156test "three expr in a row" {
...@@ -170,14 +172,14 @@ fn testThreeExprInARow(f: bool, t: bool) void {...@@ -170,14 +172,14 @@ fn testThreeExprInARow(f: bool, t: bool) void {
170 assertFalse(i32(7) != --(i32(7)));172 assertFalse(i32(7) != --(i32(7)));
171}173}
172fn assertFalse(b: bool) void {174fn assertFalse(b: bool) void {
173 assertOrPanic(!b);175 expect(!b);
174}176}
175177
176test "const number literal" {178test "const number literal" {
177 const one = 1;179 const one = 1;
178 const eleven = ten + one;180 const eleven = ten + one;
179181
180 assertOrPanic(eleven == 11);182 expect(eleven == 11);
181}183}
182const ten = 10;184const ten = 10;
183185
...@@ -187,9 +189,9 @@ test "unsigned wrapping" {...@@ -187,9 +189,9 @@ test "unsigned wrapping" {
187}189}
188fn testUnsignedWrappingEval(x: u32) void {190fn testUnsignedWrappingEval(x: u32) void {
189 const zero = x +% 1;191 const zero = x +% 1;
190 assertOrPanic(zero == 0);192 expect(zero == 0);
191 const orig = zero -% 1;193 const orig = zero -% 1;
192 assertOrPanic(orig == maxInt(u32));194 expect(orig == maxInt(u32));
193}195}
194196
195test "signed wrapping" {197test "signed wrapping" {
...@@ -198,9 +200,9 @@ test "signed wrapping" {...@@ -198,9 +200,9 @@ test "signed wrapping" {
198}200}
199fn testSignedWrappingEval(x: i32) void {201fn testSignedWrappingEval(x: i32) void {
200 const min_val = x +% 1;202 const min_val = x +% 1;
201 assertOrPanic(min_val == minInt(i32));203 expect(min_val == minInt(i32));
202 const max_val = min_val -% 1;204 const max_val = min_val -% 1;
203 assertOrPanic(max_val == maxInt(i32));205 expect(max_val == maxInt(i32));
204}206}
205207
206test "negation wrapping" {208test "negation wrapping" {
...@@ -208,9 +210,9 @@ test "negation wrapping" {...@@ -208,9 +210,9 @@ test "negation wrapping" {
208 comptime testNegationWrappingEval(minInt(i16));210 comptime testNegationWrappingEval(minInt(i16));
209}211}
210fn testNegationWrappingEval(x: i16) void {212fn testNegationWrappingEval(x: i16) void {
211 assertOrPanic(x == -32768);213 expect(x == -32768);
212 const neg = -%x;214 const neg = -%x;
213 assertOrPanic(neg == -32768);215 expect(neg == -32768);
214}216}
215217
216test "unsigned 64-bit division" {218test "unsigned 64-bit division" {
...@@ -219,8 +221,8 @@ test "unsigned 64-bit division" {...@@ -219,8 +221,8 @@ test "unsigned 64-bit division" {
219}221}
220fn test_u64_div() void {222fn test_u64_div() void {
221 const result = divWithResult(1152921504606846976, 34359738365);223 const result = divWithResult(1152921504606846976, 34359738365);
222 assertOrPanic(result.quotient == 33554432);224 expect(result.quotient == 33554432);
223 assertOrPanic(result.remainder == 100663296);225 expect(result.remainder == 100663296);
224}226}
225fn divWithResult(a: u64, b: u64) DivResult {227fn divWithResult(a: u64, b: u64) DivResult {
226 return DivResult{228 return DivResult{
...@@ -234,36 +236,36 @@ const DivResult = struct {...@@ -234,36 +236,36 @@ const DivResult = struct {
234};236};
235237
236test "binary not" {238test "binary not" {
237 assertOrPanic(comptime x: {239 expect(comptime x: {
238 break :x ~u16(0b1010101010101010) == 0b0101010101010101;240 break :x ~u16(0b1010101010101010) == 0b0101010101010101;
239 });241 });
240 assertOrPanic(comptime x: {242 expect(comptime x: {
241 break :x ~u64(2147483647) == 18446744071562067968;243 break :x ~u64(2147483647) == 18446744071562067968;
242 });244 });
243 testBinaryNot(0b1010101010101010);245 testBinaryNot(0b1010101010101010);
244}246}
245247
246fn testBinaryNot(x: u16) void {248fn testBinaryNot(x: u16) void {
247 assertOrPanic(~x == 0b0101010101010101);249 expect(~x == 0b0101010101010101);
248}250}
249251
250test "small int addition" {252test "small int addition" {
251 var x: @IntType(false, 2) = 0;253 var x: @IntType(false, 2) = 0;
252 assertOrPanic(x == 0);254 expect(x == 0);
253255
254 x += 1;256 x += 1;
255 assertOrPanic(x == 1);257 expect(x == 1);
256258
257 x += 1;259 x += 1;
258 assertOrPanic(x == 2);260 expect(x == 2);
259261
260 x += 1;262 x += 1;
261 assertOrPanic(x == 3);263 expect(x == 3);
262264
263 var result: @typeOf(x) = 3;265 var result: @typeOf(x) = 3;
264 assertOrPanic(@addWithOverflow(@typeOf(x), x, 1, &result));266 expect(@addWithOverflow(@typeOf(x), x, 1, &result));
265267
266 assertOrPanic(result == 0);268 expect(result == 0);
267}269}
268270
269test "float equality" {271test "float equality" {
...@@ -276,20 +278,20 @@ test "float equality" {...@@ -276,20 +278,20 @@ test "float equality" {
276278
277fn testFloatEqualityImpl(x: f64, y: f64) void {279fn testFloatEqualityImpl(x: f64, y: f64) void {
278 const y2 = x + 1.0;280 const y2 = x + 1.0;
279 assertOrPanic(y == y2);281 expect(y == y2);
280}282}
281283
282test "allow signed integer division/remainder when values are comptime known and positive or exact" {284test "allow signed integer division/remainder when values are comptime known and positive or exact" {
283 assertOrPanic(5 / 3 == 1);285 expect(5 / 3 == 1);
284 assertOrPanic(-5 / -3 == 1);286 expect(-5 / -3 == 1);
285 assertOrPanic(-6 / 3 == -2);287 expect(-6 / 3 == -2);
286288
287 assertOrPanic(5 % 3 == 2);289 expect(5 % 3 == 2);
288 assertOrPanic(-6 % 3 == 0);290 expect(-6 % 3 == 0);
289}291}
290292
291test "hex float literal parsing" {293test "hex float literal parsing" {
292 comptime assertOrPanic(0x1.0 == 1.0);294 comptime expect(0x1.0 == 1.0);
293}295}
294296
295test "quad hex float literal parsing in range" {297test "quad hex float literal parsing in range" {
...@@ -304,7 +306,7 @@ test "quad hex float literal parsing accurate" {...@@ -304,7 +306,7 @@ test "quad hex float literal parsing accurate" {
304306
305 // implied 1 is dropped, with an exponent of 0 (0x3fff) after biasing.307 // implied 1 is dropped, with an exponent of 0 (0x3fff) after biasing.
306 const expected: u128 = 0x3fff1111222233334444555566667777;308 const expected: u128 = 0x3fff1111222233334444555566667777;
307 assertOrPanic(@bitCast(u128, a) == expected);309 expect(@bitCast(u128, a) == expected);
308}310}
309311
310test "hex float literal within range" {312test "hex float literal within range" {
...@@ -319,7 +321,7 @@ test "truncating shift left" {...@@ -319,7 +321,7 @@ test "truncating shift left" {
319}321}
320fn testShlTrunc(x: u16) void {322fn testShlTrunc(x: u16) void {
321 const shifted = x << 1;323 const shifted = x << 1;
322 assertOrPanic(shifted == 65534);324 expect(shifted == 65534);
323}325}
324326
325test "truncating shift right" {327test "truncating shift right" {
...@@ -328,7 +330,7 @@ test "truncating shift right" {...@@ -328,7 +330,7 @@ test "truncating shift right" {
328}330}
329fn testShrTrunc(x: u16) void {331fn testShrTrunc(x: u16) void {
330 const shifted = x >> 1;332 const shifted = x >> 1;
331 assertOrPanic(shifted == 32767);333 expect(shifted == 32767);
332}334}
333335
334test "exact shift left" {336test "exact shift left" {
...@@ -337,7 +339,7 @@ test "exact shift left" {...@@ -337,7 +339,7 @@ test "exact shift left" {
337}339}
338fn testShlExact(x: u8) void {340fn testShlExact(x: u8) void {
339 const shifted = @shlExact(x, 2);341 const shifted = @shlExact(x, 2);
340 assertOrPanic(shifted == 0b11010100);342 expect(shifted == 0b11010100);
341}343}
342344
343test "exact shift right" {345test "exact shift right" {
...@@ -346,22 +348,22 @@ test "exact shift right" {...@@ -346,22 +348,22 @@ test "exact shift right" {
346}348}
347fn testShrExact(x: u8) void {349fn testShrExact(x: u8) void {
348 const shifted = @shrExact(x, 2);350 const shifted = @shrExact(x, 2);
349 assertOrPanic(shifted == 0b00101101);351 expect(shifted == 0b00101101);
350}352}
351353
352test "comptime_int addition" {354test "comptime_int addition" {
353 comptime {355 comptime {
354 assertOrPanic(35361831660712422535336160538497375248 + 101752735581729509668353361206450473702 == 137114567242441932203689521744947848950);356 expect(35361831660712422535336160538497375248 + 101752735581729509668353361206450473702 == 137114567242441932203689521744947848950);
355 assertOrPanic(594491908217841670578297176641415611445982232488944558774612 + 390603545391089362063884922208143568023166603618446395589768 == 985095453608931032642182098849559179469148836107390954364380);357 expect(594491908217841670578297176641415611445982232488944558774612 + 390603545391089362063884922208143568023166603618446395589768 == 985095453608931032642182098849559179469148836107390954364380);
356 }358 }
357}359}
358360
359test "comptime_int multiplication" {361test "comptime_int multiplication" {
360 comptime {362 comptime {
361 assertOrPanic(363 expect(
362 45960427431263824329884196484953148229 * 128339149605334697009938835852565949723 == 5898522172026096622534201617172456926982464453350084962781392314016180490567,364 45960427431263824329884196484953148229 * 128339149605334697009938835852565949723 == 5898522172026096622534201617172456926982464453350084962781392314016180490567,
363 );365 );
364 assertOrPanic(366 expect(
365 594491908217841670578297176641415611445982232488944558774612 * 390603545391089362063884922208143568023166603618446395589768 == 232210647056203049913662402532976186578842425262306016094292237500303028346593132411865381225871291702600263463125370016,367 594491908217841670578297176641415611445982232488944558774612 * 390603545391089362063884922208143568023166603618446395589768 == 232210647056203049913662402532976186578842425262306016094292237500303028346593132411865381225871291702600263463125370016,
366 );368 );
367 }369 }
...@@ -369,7 +371,7 @@ test "comptime_int multiplication" {...@@ -369,7 +371,7 @@ test "comptime_int multiplication" {
369371
370test "comptime_int shifting" {372test "comptime_int shifting" {
371 comptime {373 comptime {
372 assertOrPanic((u128(1) << 127) == 0x80000000000000000000000000000000);374 expect((u128(1) << 127) == 0x80000000000000000000000000000000);
373 }375 }
374}376}
375377
...@@ -377,16 +379,16 @@ test "comptime_int multi-limb shift and mask" {...@@ -377,16 +379,16 @@ test "comptime_int multi-limb shift and mask" {
377 comptime {379 comptime {
378 var a = 0xefffffffa0000001eeeeeeefaaaaaaab;380 var a = 0xefffffffa0000001eeeeeeefaaaaaaab;
379381
380 assertOrPanic(u32(a & 0xffffffff) == 0xaaaaaaab);382 expect(u32(a & 0xffffffff) == 0xaaaaaaab);
381 a >>= 32;383 a >>= 32;
382 assertOrPanic(u32(a & 0xffffffff) == 0xeeeeeeef);384 expect(u32(a & 0xffffffff) == 0xeeeeeeef);
383 a >>= 32;385 a >>= 32;
384 assertOrPanic(u32(a & 0xffffffff) == 0xa0000001);386 expect(u32(a & 0xffffffff) == 0xa0000001);
385 a >>= 32;387 a >>= 32;
386 assertOrPanic(u32(a & 0xffffffff) == 0xefffffff);388 expect(u32(a & 0xffffffff) == 0xefffffff);
387 a >>= 32;389 a >>= 32;
388390
389 assertOrPanic(a == 0);391 expect(a == 0);
390 }392 }
391}393}
392394
...@@ -394,7 +396,7 @@ test "comptime_int multi-limb partial shift right" {...@@ -394,7 +396,7 @@ test "comptime_int multi-limb partial shift right" {
394 comptime {396 comptime {
395 var a = 0x1ffffffffeeeeeeee;397 var a = 0x1ffffffffeeeeeeee;
396 a >>= 16;398 a >>= 16;
397 assertOrPanic(a == 0x1ffffffffeeee);399 expect(a == 0x1ffffffffeeee);
398 }400 }
399}401}
400402
...@@ -404,23 +406,23 @@ test "xor" {...@@ -404,23 +406,23 @@ test "xor" {
404}406}
405407
406fn test_xor() void {408fn test_xor() void {
407 assertOrPanic(0xFF ^ 0x00 == 0xFF);409 expect(0xFF ^ 0x00 == 0xFF);
408 assertOrPanic(0xF0 ^ 0x0F == 0xFF);410 expect(0xF0 ^ 0x0F == 0xFF);
409 assertOrPanic(0xFF ^ 0xF0 == 0x0F);411 expect(0xFF ^ 0xF0 == 0x0F);
410 assertOrPanic(0xFF ^ 0x0F == 0xF0);412 expect(0xFF ^ 0x0F == 0xF0);
411 assertOrPanic(0xFF ^ 0xFF == 0x00);413 expect(0xFF ^ 0xFF == 0x00);
412}414}
413415
414test "comptime_int xor" {416test "comptime_int xor" {
415 comptime {417 comptime {
416 assertOrPanic(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ^ 0x00000000000000000000000000000000 == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);418 expect(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ^ 0x00000000000000000000000000000000 == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
417 assertOrPanic(0xFFFFFFFFFFFFFFFF0000000000000000 ^ 0x0000000000000000FFFFFFFFFFFFFFFF == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);419 expect(0xFFFFFFFFFFFFFFFF0000000000000000 ^ 0x0000000000000000FFFFFFFFFFFFFFFF == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
418 assertOrPanic(0xFFFFFFFFFFFFFFFF0000000000000000 ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0x0000000000000000FFFFFFFFFFFFFFFF);420 expect(0xFFFFFFFFFFFFFFFF0000000000000000 ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0x0000000000000000FFFFFFFFFFFFFFFF);
419 assertOrPanic(0x0000000000000000FFFFFFFFFFFFFFFF ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0xFFFFFFFFFFFFFFFF0000000000000000);421 expect(0x0000000000000000FFFFFFFFFFFFFFFF ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0xFFFFFFFFFFFFFFFF0000000000000000);
420 assertOrPanic(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0x00000000000000000000000000000000);422 expect(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0x00000000000000000000000000000000);
421 assertOrPanic(0xFFFFFFFF00000000FFFFFFFF00000000 ^ 0x00000000FFFFFFFF00000000FFFFFFFF == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);423 expect(0xFFFFFFFF00000000FFFFFFFF00000000 ^ 0x00000000FFFFFFFF00000000FFFFFFFF == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
422 assertOrPanic(0xFFFFFFFF00000000FFFFFFFF00000000 ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0x00000000FFFFFFFF00000000FFFFFFFF);424 expect(0xFFFFFFFF00000000FFFFFFFF00000000 ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0x00000000FFFFFFFF00000000FFFFFFFF);
423 assertOrPanic(0x00000000FFFFFFFF00000000FFFFFFFF ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0xFFFFFFFF00000000FFFFFFFF00000000);425 expect(0x00000000FFFFFFFF00000000FFFFFFFF ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0xFFFFFFFF00000000FFFFFFFF00000000);
424 }426 }
425}427}
426428
...@@ -434,23 +436,23 @@ fn make_f128(x: f128) f128 {...@@ -434,23 +436,23 @@ fn make_f128(x: f128) f128 {
434}436}
435437
436fn test_f128() void {438fn test_f128() void {
437 assertOrPanic(@sizeOf(f128) == 16);439 expect(@sizeOf(f128) == 16);
438 assertOrPanic(make_f128(1.0) == 1.0);440 expect(make_f128(1.0) == 1.0);
439 assertOrPanic(make_f128(1.0) != 1.1);441 expect(make_f128(1.0) != 1.1);
440 assertOrPanic(make_f128(1.0) > 0.9);442 expect(make_f128(1.0) > 0.9);
441 assertOrPanic(make_f128(1.0) >= 0.9);443 expect(make_f128(1.0) >= 0.9);
442 assertOrPanic(make_f128(1.0) >= 1.0);444 expect(make_f128(1.0) >= 1.0);
443 should_not_be_zero(1.0);445 should_not_be_zero(1.0);
444}446}
445447
446fn should_not_be_zero(x: f128) void {448fn should_not_be_zero(x: f128) void {
447 assertOrPanic(x != 0.0);449 expect(x != 0.0);
448}450}
449451
450test "comptime float rem int" {452test "comptime float rem int" {
451 comptime {453 comptime {
452 var x = f32(1) % 2;454 var x = f32(1) % 2;
453 assertOrPanic(x == 1.0);455 expect(x == 1.0);
454 }456 }
455}457}
456458
...@@ -465,8 +467,8 @@ test "remainder division" {...@@ -465,8 +467,8 @@ test "remainder division" {
465}467}
466468
467fn remdiv(comptime T: type) void {469fn remdiv(comptime T: type) void {
468 assertOrPanic(T(1) == T(1) % T(2));470 expect(T(1) == T(1) % T(2));
469 assertOrPanic(T(1) == T(7) % T(3));471 expect(T(1) == T(7) % T(3));
470}472}
471473
472test "@sqrt" {474test "@sqrt" {
...@@ -480,21 +482,36 @@ test "@sqrt" {...@@ -480,21 +482,36 @@ test "@sqrt" {
480 const x = 14.0;482 const x = 14.0;
481 const y = x * x;483 const y = x * x;
482 const z = @sqrt(@typeOf(y), y);484 const z = @sqrt(@typeOf(y), y);
483 comptime assertOrPanic(z == x);485 comptime expect(z == x);
484}486}
485487
486fn testSqrt(comptime T: type, x: T) void {488fn testSqrt(comptime T: type, x: T) void {
487 assertOrPanic(@sqrt(T, x * x) == x);489 expect(@sqrt(T, x * x) == x);
488}490}
489491
490test "comptime_int param and return" {492test "comptime_int param and return" {
491 const a = comptimeAdd(35361831660712422535336160538497375248, 101752735581729509668353361206450473702);493 const a = comptimeAdd(35361831660712422535336160538497375248, 101752735581729509668353361206450473702);
492 assertOrPanic(a == 137114567242441932203689521744947848950);494 expect(a == 137114567242441932203689521744947848950);
493495
494 const b = comptimeAdd(594491908217841670578297176641415611445982232488944558774612, 390603545391089362063884922208143568023166603618446395589768);496 const b = comptimeAdd(594491908217841670578297176641415611445982232488944558774612, 390603545391089362063884922208143568023166603618446395589768);
495 assertOrPanic(b == 985095453608931032642182098849559179469148836107390954364380);497 expect(b == 985095453608931032642182098849559179469148836107390954364380);
496}498}
497499
498fn comptimeAdd(comptime a: comptime_int, comptime b: comptime_int) comptime_int {500fn comptimeAdd(comptime a: comptime_int, comptime b: comptime_int) comptime_int {
499 return a + b;501 return a + b;
500}502}
503
504test "vector integer addition" {
505 const S = struct {
506 fn doTheTest() void {
507 var a: @Vector(4, i32) = []i32{ 1, 2, 3, 4 };
508 var b: @Vector(4, i32) = []i32{ 5, 6, 7, 8 };
509 var result = a + b;
510 var result_array: [4]i32 = result;
511 const expected = []i32{ 6, 8, 10, 12 };
512 expectEqualSlices(i32, &expected, &result_array);
513 }
514 };
515 S.doTheTest();
516 comptime S.doTheTest();
517}
test/stage1/behavior/misc.zig+138-138
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const assertOrPanic = std.debug.assertOrPanic;2const expect = std.testing.expect;
3const mem = std.mem;3const mem = std.mem;
4const cstr = std.cstr;4const cstr = std.cstr;
5const builtin = @import("builtin");5const builtin = @import("builtin");
...@@ -26,38 +26,38 @@ test "call disabled extern fn" {...@@ -26,38 +26,38 @@ test "call disabled extern fn" {
26}26}
2727
28test "@IntType builtin" {28test "@IntType builtin" {
29 assertOrPanic(@IntType(true, 8) == i8);29 expect(@IntType(true, 8) == i8);
30 assertOrPanic(@IntType(true, 16) == i16);30 expect(@IntType(true, 16) == i16);
31 assertOrPanic(@IntType(true, 32) == i32);31 expect(@IntType(true, 32) == i32);
32 assertOrPanic(@IntType(true, 64) == i64);32 expect(@IntType(true, 64) == i64);
3333
34 assertOrPanic(@IntType(false, 8) == u8);34 expect(@IntType(false, 8) == u8);
35 assertOrPanic(@IntType(false, 16) == u16);35 expect(@IntType(false, 16) == u16);
36 assertOrPanic(@IntType(false, 32) == u32);36 expect(@IntType(false, 32) == u32);
37 assertOrPanic(@IntType(false, 64) == u64);37 expect(@IntType(false, 64) == u64);
3838
39 assertOrPanic(i8.bit_count == 8);39 expect(i8.bit_count == 8);
40 assertOrPanic(i16.bit_count == 16);40 expect(i16.bit_count == 16);
41 assertOrPanic(i32.bit_count == 32);41 expect(i32.bit_count == 32);
42 assertOrPanic(i64.bit_count == 64);42 expect(i64.bit_count == 64);
4343
44 assertOrPanic(i8.is_signed);44 expect(i8.is_signed);
45 assertOrPanic(i16.is_signed);45 expect(i16.is_signed);
46 assertOrPanic(i32.is_signed);46 expect(i32.is_signed);
47 assertOrPanic(i64.is_signed);47 expect(i64.is_signed);
48 assertOrPanic(isize.is_signed);48 expect(isize.is_signed);
4949
50 assertOrPanic(!u8.is_signed);50 expect(!u8.is_signed);
51 assertOrPanic(!u16.is_signed);51 expect(!u16.is_signed);
52 assertOrPanic(!u32.is_signed);52 expect(!u32.is_signed);
53 assertOrPanic(!u64.is_signed);53 expect(!u64.is_signed);
54 assertOrPanic(!usize.is_signed);54 expect(!usize.is_signed);
55}55}
5656
57test "floating point primitive bit counts" {57test "floating point primitive bit counts" {
58 assertOrPanic(f16.bit_count == 16);58 expect(f16.bit_count == 16);
59 assertOrPanic(f32.bit_count == 32);59 expect(f32.bit_count == 32);
60 assertOrPanic(f64.bit_count == 64);60 expect(f64.bit_count == 64);
61}61}
6262
63test "short circuit" {63test "short circuit" {
...@@ -72,7 +72,7 @@ fn testShortCircuit(f: bool, t: bool) void {...@@ -72,7 +72,7 @@ fn testShortCircuit(f: bool, t: bool) void {
72 var hit_4 = f;72 var hit_4 = f;
7373
74 if (t or x: {74 if (t or x: {
75 assertOrPanic(f);75 expect(f);
76 break :x f;76 break :x f;
77 }) {77 }) {
78 hit_1 = t;78 hit_1 = t;
...@@ -81,31 +81,31 @@ fn testShortCircuit(f: bool, t: bool) void {...@@ -81,31 +81,31 @@ fn testShortCircuit(f: bool, t: bool) void {
81 hit_2 = t;81 hit_2 = t;
82 break :x f;82 break :x f;
83 }) {83 }) {
84 assertOrPanic(f);84 expect(f);
85 }85 }
8686
87 if (t and x: {87 if (t and x: {
88 hit_3 = t;88 hit_3 = t;
89 break :x f;89 break :x f;
90 }) {90 }) {
91 assertOrPanic(f);91 expect(f);
92 }92 }
93 if (f and x: {93 if (f and x: {
94 assertOrPanic(f);94 expect(f);
95 break :x f;95 break :x f;
96 }) {96 }) {
97 assertOrPanic(f);97 expect(f);
98 } else {98 } else {
99 hit_4 = t;99 hit_4 = t;
100 }100 }
101 assertOrPanic(hit_1);101 expect(hit_1);
102 assertOrPanic(hit_2);102 expect(hit_2);
103 assertOrPanic(hit_3);103 expect(hit_3);
104 assertOrPanic(hit_4);104 expect(hit_4);
105}105}
106106
107test "truncate" {107test "truncate" {
108 assertOrPanic(testTruncate(0x10fd) == 0xfd);108 expect(testTruncate(0x10fd) == 0xfd);
109}109}
110fn testTruncate(x: u32) u8 {110fn testTruncate(x: u32) u8 {
111 return @truncate(u8, x);111 return @truncate(u8, x);
...@@ -116,16 +116,16 @@ fn first4KeysOfHomeRow() []const u8 {...@@ -116,16 +116,16 @@ fn first4KeysOfHomeRow() []const u8 {
116}116}
117117
118test "return string from function" {118test "return string from function" {
119 assertOrPanic(mem.eql(u8, first4KeysOfHomeRow(), "aoeu"));119 expect(mem.eql(u8, first4KeysOfHomeRow(), "aoeu"));
120}120}
121121
122const g1: i32 = 1233 + 1;122const g1: i32 = 1233 + 1;
123var g2: i32 = 0;123var g2: i32 = 0;
124124
125test "global variables" {125test "global variables" {
126 assertOrPanic(g2 == 0);126 expect(g2 == 0);
127 g2 = g1;127 g2 = g1;
128 assertOrPanic(g2 == 1234);128 expect(g2 == 1234);
129}129}
130130
131test "memcpy and memset intrinsics" {131test "memcpy and memset intrinsics" {
...@@ -142,7 +142,7 @@ test "builtin static eval" {...@@ -142,7 +142,7 @@ test "builtin static eval" {
142 const x: i32 = comptime x: {142 const x: i32 = comptime x: {
143 break :x 1 + 2 + 3;143 break :x 1 + 2 + 3;
144 };144 };
145 assertOrPanic(x == comptime 6);145 expect(x == comptime 6);
146}146}
147147
148test "slicing" {148test "slicing" {
...@@ -163,7 +163,7 @@ test "slicing" {...@@ -163,7 +163,7 @@ test "slicing" {
163163
164test "constant equal function pointers" {164test "constant equal function pointers" {
165 const alias = emptyFn;165 const alias = emptyFn;
166 assertOrPanic(comptime x: {166 expect(comptime x: {
167 break :x emptyFn == alias;167 break :x emptyFn == alias;
168 });168 });
169}169}
...@@ -171,25 +171,25 @@ test "constant equal function pointers" {...@@ -171,25 +171,25 @@ test "constant equal function pointers" {
171fn emptyFn() void {}171fn emptyFn() void {}
172172
173test "hex escape" {173test "hex escape" {
174 assertOrPanic(mem.eql(u8, "\x68\x65\x6c\x6c\x6f", "hello"));174 expect(mem.eql(u8, "\x68\x65\x6c\x6c\x6f", "hello"));
175}175}
176176
177test "string concatenation" {177test "string concatenation" {
178 assertOrPanic(mem.eql(u8, "OK" ++ " IT " ++ "WORKED", "OK IT WORKED"));178 expect(mem.eql(u8, "OK" ++ " IT " ++ "WORKED", "OK IT WORKED"));
179}179}
180180
181test "array mult operator" {181test "array mult operator" {
182 assertOrPanic(mem.eql(u8, "ab" ** 5, "ababababab"));182 expect(mem.eql(u8, "ab" ** 5, "ababababab"));
183}183}
184184
185test "string escapes" {185test "string escapes" {
186 assertOrPanic(mem.eql(u8, "\"", "\x22"));186 expect(mem.eql(u8, "\"", "\x22"));
187 assertOrPanic(mem.eql(u8, "\'", "\x27"));187 expect(mem.eql(u8, "\'", "\x27"));
188 assertOrPanic(mem.eql(u8, "\n", "\x0a"));188 expect(mem.eql(u8, "\n", "\x0a"));
189 assertOrPanic(mem.eql(u8, "\r", "\x0d"));189 expect(mem.eql(u8, "\r", "\x0d"));
190 assertOrPanic(mem.eql(u8, "\t", "\x09"));190 expect(mem.eql(u8, "\t", "\x09"));
191 assertOrPanic(mem.eql(u8, "\\", "\x5c"));191 expect(mem.eql(u8, "\\", "\x5c"));
192 assertOrPanic(mem.eql(u8, "\u1234\u0069", "\xe1\x88\xb4\x69"));192 expect(mem.eql(u8, "\u1234\u0069", "\xe1\x88\xb4\x69"));
193}193}
194194
195test "multiline string" {195test "multiline string" {
...@@ -199,7 +199,7 @@ test "multiline string" {...@@ -199,7 +199,7 @@ test "multiline string" {
199 \\three199 \\three
200 ;200 ;
201 const s2 = "one\ntwo)\nthree";201 const s2 = "one\ntwo)\nthree";
202 assertOrPanic(mem.eql(u8, s1, s2));202 expect(mem.eql(u8, s1, s2));
203}203}
204204
205test "multiline C string" {205test "multiline C string" {
...@@ -209,11 +209,11 @@ test "multiline C string" {...@@ -209,11 +209,11 @@ test "multiline C string" {
209 c\\three209 c\\three
210 ;210 ;
211 const s2 = c"one\ntwo)\nthree";211 const s2 = c"one\ntwo)\nthree";
212 assertOrPanic(cstr.cmp(s1, s2) == 0);212 expect(cstr.cmp(s1, s2) == 0);
213}213}
214214
215test "type equality" {215test "type equality" {
216 assertOrPanic(*const u8 != *u8);216 expect(*const u8 != *u8);
217}217}
218218
219const global_a: i32 = 1234;219const global_a: i32 = 1234;
...@@ -221,7 +221,7 @@ const global_b: *const i32 = &global_a;...@@ -221,7 +221,7 @@ const global_b: *const i32 = &global_a;
221const global_c: *const f32 = @ptrCast(*const f32, global_b);221const global_c: *const f32 = @ptrCast(*const f32, global_b);
222test "compile time global reinterpret" {222test "compile time global reinterpret" {
223 const d = @ptrCast(*const i32, global_c);223 const d = @ptrCast(*const i32, global_c);
224 assertOrPanic(d.* == 1234);224 expect(d.* == 1234);
225}225}
226226
227test "explicit cast maybe pointers" {227test "explicit cast maybe pointers" {
...@@ -247,8 +247,8 @@ test "cast undefined" {...@@ -247,8 +247,8 @@ test "cast undefined" {
247fn testCastUndefined(x: []const u8) void {}247fn testCastUndefined(x: []const u8) void {}
248248
249test "cast small unsigned to larger signed" {249test "cast small unsigned to larger signed" {
250 assertOrPanic(castSmallUnsignedToLargerSigned1(200) == i16(200));250 expect(castSmallUnsignedToLargerSigned1(200) == i16(200));
251 assertOrPanic(castSmallUnsignedToLargerSigned2(9999) == i64(9999));251 expect(castSmallUnsignedToLargerSigned2(9999) == i64(9999));
252}252}
253fn castSmallUnsignedToLargerSigned1(x: u8) i16 {253fn castSmallUnsignedToLargerSigned1(x: u8) i16 {
254 return x;254 return x;
...@@ -258,7 +258,7 @@ fn castSmallUnsignedToLargerSigned2(x: u16) i64 {...@@ -258,7 +258,7 @@ fn castSmallUnsignedToLargerSigned2(x: u16) i64 {
258}258}
259259
260test "implicit cast after unreachable" {260test "implicit cast after unreachable" {
261 assertOrPanic(outer() == 1234);261 expect(outer() == 1234);
262}262}
263fn inner() i32 {263fn inner() i32 {
264 return 1234;264 return 1234;
...@@ -273,13 +273,13 @@ test "pointer dereferencing" {...@@ -273,13 +273,13 @@ test "pointer dereferencing" {
273273
274 y.* += 1;274 y.* += 1;
275275
276 assertOrPanic(x == 4);276 expect(x == 4);
277 assertOrPanic(y.* == 4);277 expect(y.* == 4);
278}278}
279279
280test "call result of if else expression" {280test "call result of if else expression" {
281 assertOrPanic(mem.eql(u8, f2(true), "a"));281 expect(mem.eql(u8, f2(true), "a"));
282 assertOrPanic(mem.eql(u8, f2(false), "b"));282 expect(mem.eql(u8, f2(false), "b"));
283}283}
284fn f2(x: bool) []const u8 {284fn f2(x: bool) []const u8 {
285 return (if (x) fA else fB)();285 return (if (x) fA else fB)();
...@@ -321,8 +321,8 @@ const test3_bar = Test3Foo{ .Two = 13 };...@@ -321,8 +321,8 @@ const test3_bar = Test3Foo{ .Two = 13 };
321fn test3_1(f: Test3Foo) void {321fn test3_1(f: Test3Foo) void {
322 switch (f) {322 switch (f) {
323 Test3Foo.Three => |pt| {323 Test3Foo.Three => |pt| {
324 assertOrPanic(pt.x == 3);324 expect(pt.x == 3);
325 assertOrPanic(pt.y == 4);325 expect(pt.y == 4);
326 },326 },
327 else => unreachable,327 else => unreachable,
328 }328 }
...@@ -330,14 +330,14 @@ fn test3_1(f: Test3Foo) void {...@@ -330,14 +330,14 @@ fn test3_1(f: Test3Foo) void {
330fn test3_2(f: Test3Foo) void {330fn test3_2(f: Test3Foo) void {
331 switch (f) {331 switch (f) {
332 Test3Foo.Two => |x| {332 Test3Foo.Two => |x| {
333 assertOrPanic(x == 13);333 expect(x == 13);
334 },334 },
335 else => unreachable,335 else => unreachable,
336 }336 }
337}337}
338338
339test "character literals" {339test "character literals" {
340 assertOrPanic('\'' == single_quote);340 expect('\'' == single_quote);
341}341}
342const single_quote = '\'';342const single_quote = '\'';
343343
...@@ -346,13 +346,13 @@ test "take address of parameter" {...@@ -346,13 +346,13 @@ test "take address of parameter" {
346}346}
347fn testTakeAddressOfParameter(f: f32) void {347fn testTakeAddressOfParameter(f: f32) void {
348 const f_ptr = &f;348 const f_ptr = &f;
349 assertOrPanic(f_ptr.* == 12.34);349 expect(f_ptr.* == 12.34);
350}350}
351351
352test "pointer comparison" {352test "pointer comparison" {
353 const a = ([]const u8)("a");353 const a = ([]const u8)("a");
354 const b = &a;354 const b = &a;
355 assertOrPanic(ptrEql(b, b));355 expect(ptrEql(b, b));
356}356}
357fn ptrEql(a: *const []const u8, b: *const []const u8) bool {357fn ptrEql(a: *const []const u8, b: *const []const u8) bool {
358 return a == b;358 return a == b;
...@@ -367,31 +367,31 @@ test "C string concatenation" {...@@ -367,31 +367,31 @@ test "C string concatenation" {
367 {367 {
368 var i: u32 = 0;368 var i: u32 = 0;
369 while (i < len_with_null) : (i += 1) {369 while (i < len_with_null) : (i += 1) {
370 assertOrPanic(a[i] == b[i]);370 expect(a[i] == b[i]);
371 }371 }
372 }372 }
373 assertOrPanic(a[len] == 0);373 expect(a[len] == 0);
374 assertOrPanic(b[len] == 0);374 expect(b[len] == 0);
375}375}
376376
377test "cast slice to u8 slice" {377test "cast slice to u8 slice" {
378 assertOrPanic(@sizeOf(i32) == 4);378 expect(@sizeOf(i32) == 4);
379 var big_thing_array = []i32{ 1, 2, 3, 4 };379 var big_thing_array = []i32{ 1, 2, 3, 4 };
380 const big_thing_slice: []i32 = big_thing_array[0..];380 const big_thing_slice: []i32 = big_thing_array[0..];
381 const bytes = @sliceToBytes(big_thing_slice);381 const bytes = @sliceToBytes(big_thing_slice);
382 assertOrPanic(bytes.len == 4 * 4);382 expect(bytes.len == 4 * 4);
383 bytes[4] = 0;383 bytes[4] = 0;
384 bytes[5] = 0;384 bytes[5] = 0;
385 bytes[6] = 0;385 bytes[6] = 0;
386 bytes[7] = 0;386 bytes[7] = 0;
387 assertOrPanic(big_thing_slice[1] == 0);387 expect(big_thing_slice[1] == 0);
388 const big_thing_again = @bytesToSlice(i32, bytes);388 const big_thing_again = @bytesToSlice(i32, bytes);
389 assertOrPanic(big_thing_again[2] == 3);389 expect(big_thing_again[2] == 3);
390 big_thing_again[2] = -1;390 big_thing_again[2] = -1;
391 assertOrPanic(bytes[8] == maxInt(u8));391 expect(bytes[8] == maxInt(u8));
392 assertOrPanic(bytes[9] == maxInt(u8));392 expect(bytes[9] == maxInt(u8));
393 assertOrPanic(bytes[10] == maxInt(u8));393 expect(bytes[10] == maxInt(u8));
394 assertOrPanic(bytes[11] == maxInt(u8));394 expect(bytes[11] == maxInt(u8));
395}395}
396396
397test "pointer to void return type" {397test "pointer to void return type" {
...@@ -408,7 +408,7 @@ fn testPointerToVoidReturnType2() *const void {...@@ -408,7 +408,7 @@ fn testPointerToVoidReturnType2() *const void {
408408
409test "non const ptr to aliased type" {409test "non const ptr to aliased type" {
410 const int = i32;410 const int = i32;
411 assertOrPanic(?*int == ?*i32);411 expect(?*int == ?*i32);
412}412}
413413
414test "array 2D const double ptr" {414test "array 2D const double ptr" {
...@@ -421,8 +421,8 @@ test "array 2D const double ptr" {...@@ -421,8 +421,8 @@ test "array 2D const double ptr" {
421421
422fn testArray2DConstDoublePtr(ptr: *const f32) void {422fn testArray2DConstDoublePtr(ptr: *const f32) void {
423 const ptr2 = @ptrCast([*]const f32, ptr);423 const ptr2 = @ptrCast([*]const f32, ptr);
424 assertOrPanic(ptr2[0] == 1.0);424 expect(ptr2[0] == 1.0);
425 assertOrPanic(ptr2[1] == 2.0);425 expect(ptr2[1] == 2.0);
426}426}
427427
428const Tid = builtin.TypeId;428const Tid = builtin.TypeId;
...@@ -444,32 +444,32 @@ const AUnion = union {...@@ -444,32 +444,32 @@ const AUnion = union {
444444
445test "@typeId" {445test "@typeId" {
446 comptime {446 comptime {
447 assertOrPanic(@typeId(type) == Tid.Type);447 expect(@typeId(type) == Tid.Type);
448 assertOrPanic(@typeId(void) == Tid.Void);448 expect(@typeId(void) == Tid.Void);
449 assertOrPanic(@typeId(bool) == Tid.Bool);449 expect(@typeId(bool) == Tid.Bool);
450 assertOrPanic(@typeId(noreturn) == Tid.NoReturn);450 expect(@typeId(noreturn) == Tid.NoReturn);
451 assertOrPanic(@typeId(i8) == Tid.Int);451 expect(@typeId(i8) == Tid.Int);
452 assertOrPanic(@typeId(u8) == Tid.Int);452 expect(@typeId(u8) == Tid.Int);
453 assertOrPanic(@typeId(i64) == Tid.Int);453 expect(@typeId(i64) == Tid.Int);
454 assertOrPanic(@typeId(u64) == Tid.Int);454 expect(@typeId(u64) == Tid.Int);
455 assertOrPanic(@typeId(f32) == Tid.Float);455 expect(@typeId(f32) == Tid.Float);
456 assertOrPanic(@typeId(f64) == Tid.Float);456 expect(@typeId(f64) == Tid.Float);
457 assertOrPanic(@typeId(*f32) == Tid.Pointer);457 expect(@typeId(*f32) == Tid.Pointer);
458 assertOrPanic(@typeId([2]u8) == Tid.Array);458 expect(@typeId([2]u8) == Tid.Array);
459 assertOrPanic(@typeId(AStruct) == Tid.Struct);459 expect(@typeId(AStruct) == Tid.Struct);
460 assertOrPanic(@typeId(@typeOf(1)) == Tid.ComptimeInt);460 expect(@typeId(@typeOf(1)) == Tid.ComptimeInt);
461 assertOrPanic(@typeId(@typeOf(1.0)) == Tid.ComptimeFloat);461 expect(@typeId(@typeOf(1.0)) == Tid.ComptimeFloat);
462 assertOrPanic(@typeId(@typeOf(undefined)) == Tid.Undefined);462 expect(@typeId(@typeOf(undefined)) == Tid.Undefined);
463 assertOrPanic(@typeId(@typeOf(null)) == Tid.Null);463 expect(@typeId(@typeOf(null)) == Tid.Null);
464 assertOrPanic(@typeId(?i32) == Tid.Optional);464 expect(@typeId(?i32) == Tid.Optional);
465 assertOrPanic(@typeId(anyerror!i32) == Tid.ErrorUnion);465 expect(@typeId(anyerror!i32) == Tid.ErrorUnion);
466 assertOrPanic(@typeId(anyerror) == Tid.ErrorSet);466 expect(@typeId(anyerror) == Tid.ErrorSet);
467 assertOrPanic(@typeId(AnEnum) == Tid.Enum);467 expect(@typeId(AnEnum) == Tid.Enum);
468 assertOrPanic(@typeId(@typeOf(AUnionEnum.One)) == Tid.Enum);468 expect(@typeId(@typeOf(AUnionEnum.One)) == Tid.Enum);
469 assertOrPanic(@typeId(AUnionEnum) == Tid.Union);469 expect(@typeId(AUnionEnum) == Tid.Union);
470 assertOrPanic(@typeId(AUnion) == Tid.Union);470 expect(@typeId(AUnion) == Tid.Union);
471 assertOrPanic(@typeId(fn () void) == Tid.Fn);471 expect(@typeId(fn () void) == Tid.Fn);
472 assertOrPanic(@typeId(@typeOf(builtin)) == Tid.Namespace);472 expect(@typeId(@typeOf(builtin)) == Tid.Namespace);
473 // TODO bound fn473 // TODO bound fn
474 // TODO arg tuple474 // TODO arg tuple
475 // TODO opaque475 // TODO opaque
...@@ -485,13 +485,13 @@ test "@typeName" {...@@ -485,13 +485,13 @@ test "@typeName" {
485 Unused,485 Unused,
486 };486 };
487 comptime {487 comptime {
488 assertOrPanic(mem.eql(u8, @typeName(i64), "i64"));488 expect(mem.eql(u8, @typeName(i64), "i64"));
489 assertOrPanic(mem.eql(u8, @typeName(*usize), "*usize"));489 expect(mem.eql(u8, @typeName(*usize), "*usize"));
490 // https://github.com/ziglang/zig/issues/675490 // https://github.com/ziglang/zig/issues/675
491 assertOrPanic(mem.eql(u8, @typeName(TypeFromFn(u8)), "TypeFromFn(u8)"));491 expect(mem.eql(u8, @typeName(TypeFromFn(u8)), "TypeFromFn(u8)"));
492 assertOrPanic(mem.eql(u8, @typeName(Struct), "Struct"));492 expect(mem.eql(u8, @typeName(Struct), "Struct"));
493 assertOrPanic(mem.eql(u8, @typeName(Union), "Union"));493 expect(mem.eql(u8, @typeName(Union), "Union"));
494 assertOrPanic(mem.eql(u8, @typeName(Enum), "Enum"));494 expect(mem.eql(u8, @typeName(Enum), "Enum"));
495 }495 }
496}496}
497497
...@@ -501,14 +501,14 @@ fn TypeFromFn(comptime T: type) type {...@@ -501,14 +501,14 @@ fn TypeFromFn(comptime T: type) type {
501501
502test "double implicit cast in same expression" {502test "double implicit cast in same expression" {
503 var x = i32(u16(nine()));503 var x = i32(u16(nine()));
504 assertOrPanic(x == 9);504 expect(x == 9);
505}505}
506fn nine() u8 {506fn nine() u8 {
507 return 9;507 return 9;
508}508}
509509
510test "global variable initialized to global variable array element" {510test "global variable initialized to global variable array element" {
511 assertOrPanic(global_ptr == &gdt[0]);511 expect(global_ptr == &gdt[0]);
512}512}
513const GDTEntry = struct {513const GDTEntry = struct {
514 field: i32,514 field: i32,
...@@ -529,9 +529,9 @@ export fn writeToVRam() void {...@@ -529,9 +529,9 @@ export fn writeToVRam() void {
529const OpaqueA = @OpaqueType();529const OpaqueA = @OpaqueType();
530const OpaqueB = @OpaqueType();530const OpaqueB = @OpaqueType();
531test "@OpaqueType" {531test "@OpaqueType" {
532 assertOrPanic(*OpaqueA != *OpaqueB);532 expect(*OpaqueA != *OpaqueB);
533 assertOrPanic(mem.eql(u8, @typeName(OpaqueA), "OpaqueA"));533 expect(mem.eql(u8, @typeName(OpaqueA), "OpaqueA"));
534 assertOrPanic(mem.eql(u8, @typeName(OpaqueB), "OpaqueB"));534 expect(mem.eql(u8, @typeName(OpaqueB), "OpaqueB"));
535}535}
536536
537test "variable is allowed to be a pointer to an opaque type" {537test "variable is allowed to be a pointer to an opaque type" {
...@@ -571,7 +571,7 @@ fn fnThatClosesOverLocalConst() type {...@@ -571,7 +571,7 @@ fn fnThatClosesOverLocalConst() type {
571571
572test "function closes over local const" {572test "function closes over local const" {
573 const x = fnThatClosesOverLocalConst().g();573 const x = fnThatClosesOverLocalConst().g();
574 assertOrPanic(x == 1);574 expect(x == 1);
575}575}
576576
577test "cold function" {577test "cold function" {
...@@ -608,21 +608,21 @@ export fn testPackedStuff(a: *const PackedStruct, b: *const PackedUnion, c: Pack...@@ -608,21 +608,21 @@ export fn testPackedStuff(a: *const PackedStruct, b: *const PackedUnion, c: Pack
608test "slicing zero length array" {608test "slicing zero length array" {
609 const s1 = ""[0..];609 const s1 = ""[0..];
610 const s2 = ([]u32{})[0..];610 const s2 = ([]u32{})[0..];
611 assertOrPanic(s1.len == 0);611 expect(s1.len == 0);
612 assertOrPanic(s2.len == 0);612 expect(s2.len == 0);
613 assertOrPanic(mem.eql(u8, s1, ""));613 expect(mem.eql(u8, s1, ""));
614 assertOrPanic(mem.eql(u32, s2, []u32{}));614 expect(mem.eql(u32, s2, []u32{}));
615}615}
616616
617const addr1 = @ptrCast(*const u8, emptyFn);617const addr1 = @ptrCast(*const u8, emptyFn);
618test "comptime cast fn to ptr" {618test "comptime cast fn to ptr" {
619 const addr2 = @ptrCast(*const u8, emptyFn);619 const addr2 = @ptrCast(*const u8, emptyFn);
620 comptime assertOrPanic(addr1 == addr2);620 comptime expect(addr1 == addr2);
621}621}
622622
623test "equality compare fn ptrs" {623test "equality compare fn ptrs" {
624 var a = emptyFn;624 var a = emptyFn;
625 assertOrPanic(a == a);625 expect(a == a);
626}626}
627627
628test "self reference through fn ptr field" {628test "self reference through fn ptr field" {
...@@ -637,26 +637,26 @@ test "self reference through fn ptr field" {...@@ -637,26 +637,26 @@ test "self reference through fn ptr field" {
637 };637 };
638 var a: S.A = undefined;638 var a: S.A = undefined;
639 a.f = S.foo;639 a.f = S.foo;
640 assertOrPanic(a.f(a) == 12);640 expect(a.f(a) == 12);
641}641}
642642
643test "volatile load and store" {643test "volatile load and store" {
644 var number: i32 = 1234;644 var number: i32 = 1234;
645 const ptr = (*volatile i32)(&number);645 const ptr = (*volatile i32)(&number);
646 ptr.* += 1;646 ptr.* += 1;
647 assertOrPanic(ptr.* == 1235);647 expect(ptr.* == 1235);
648}648}
649649
650test "slice string literal has type []const u8" {650test "slice string literal has type []const u8" {
651 comptime {651 comptime {
652 assertOrPanic(@typeOf("aoeu"[0..]) == []const u8);652 expect(@typeOf("aoeu"[0..]) == []const u8);
653 const array = []i32{ 1, 2, 3, 4 };653 const array = []i32{ 1, 2, 3, 4 };
654 assertOrPanic(@typeOf(array[0..]) == []const i32);654 expect(@typeOf(array[0..]) == []const i32);
655 }655 }
656}656}
657657
658test "pointer child field" {658test "pointer child field" {
659 assertOrPanic((*u32).Child == u32);659 expect((*u32).Child == u32);
660}660}
661661
662test "struct inside function" {662test "struct inside function" {
...@@ -675,11 +675,11 @@ fn testStructInFn() void {...@@ -675,11 +675,11 @@ fn testStructInFn() void {
675675
676 block.kind += 1;676 block.kind += 1;
677677
678 assertOrPanic(block.kind == 1235);678 expect(block.kind == 1235);
679}679}
680680
681test "fn call returning scalar optional in equality expression" {681test "fn call returning scalar optional in equality expression" {
682 assertOrPanic(getNull() == null);682 expect(getNull() == null);
683}683}
684684
685fn getNull() ?*i32 {685fn getNull() ?*i32 {
...@@ -691,5 +691,5 @@ test "thread local variable" {...@@ -691,5 +691,5 @@ test "thread local variable" {
691 threadlocal var t: i32 = 1234;691 threadlocal var t: i32 = 1234;
692 };692 };
693 S.t += 1;693 S.t += 1;
694 assertOrPanic(S.t == 1235);694 expect(S.t == 1235);
695}695}
test/stage1/behavior/namespace_depends_on_compile_var/index.zig+3-3
...@@ -1,11 +1,11 @@...@@ -1,11 +1,11 @@
1const builtin = @import("builtin");1const builtin = @import("builtin");
2const assertOrPanic = @import("std").debug.assertOrPanic;2const expect = @import("std").testing.expect;
33
4test "namespace depends on compile var" {4test "namespace depends on compile var" {
5 if (some_namespace.a_bool) {5 if (some_namespace.a_bool) {
6 assertOrPanic(some_namespace.a_bool);6 expect(some_namespace.a_bool);
7 } else {7 } else {
8 assertOrPanic(!some_namespace.a_bool);8 expect(!some_namespace.a_bool);
9 }9 }
10}10}
11const some_namespace = switch (builtin.os) {11const some_namespace = switch (builtin.os) {
test/stage1/behavior/new_stack_call.zig+5-5
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const assertOrPanic = std.debug.assertOrPanic;2const expect = std.testing.expect;
33
4var new_stack_bytes: [1024]u8 = undefined;4var new_stack_bytes: [1024]u8 = undefined;
55
...@@ -10,17 +10,17 @@ test "calling a function with a new stack" {...@@ -10,17 +10,17 @@ test "calling a function with a new stack" {
10 const b = @newStackCall(new_stack_bytes[512..], targetFunction, arg);10 const b = @newStackCall(new_stack_bytes[512..], targetFunction, arg);
11 _ = targetFunction(arg);11 _ = targetFunction(arg);
1212
13 assertOrPanic(arg == 1234);13 expect(arg == 1234);
14 assertOrPanic(a < b);14 expect(a < b);
15}15}
1616
17fn targetFunction(x: i32) usize {17fn targetFunction(x: i32) usize {
18 assertOrPanic(x == 1234);18 expect(x == 1234);
1919
20 var local_variable: i32 = 42;20 var local_variable: i32 = 42;
21 const ptr = &local_variable;21 const ptr = &local_variable;
22 ptr.* += 1;22 ptr.* += 1;
2323
24 assertOrPanic(local_variable == 43);24 expect(local_variable == 43);
25 return @ptrToInt(ptr);25 return @ptrToInt(ptr);
26}26}
test/stage1/behavior/null.zig+17-17
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;1const expect = @import("std").testing.expect;
22
3test "optional type" {3test "optional type" {
4 const x: ?bool = true;4 const x: ?bool = true;
...@@ -17,13 +17,13 @@ test "optional type" {...@@ -17,13 +17,13 @@ test "optional type" {
1717
18 const z = next_x orelse 1234;18 const z = next_x orelse 1234;
1919
20 assertOrPanic(z == 1234);20 expect(z == 1234);
2121
22 const final_x: ?i32 = 13;22 const final_x: ?i32 = 13;
2323
24 const num = final_x orelse unreachable;24 const num = final_x orelse unreachable;
2525
26 assertOrPanic(num == 13);26 expect(num == 13);
27}27}
2828
29test "test maybe object and get a pointer to the inner value" {29test "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" {...@@ -33,7 +33,7 @@ test "test maybe object and get a pointer to the inner value" {
33 b.* = false;33 b.* = false;
34 }34 }
3535
36 assertOrPanic(maybe_bool.? == false);36 expect(maybe_bool.? == false);
37}37}
3838
39test "rhs maybe unwrap return" {39test "rhs maybe unwrap return" {
...@@ -47,9 +47,9 @@ test "maybe return" {...@@ -47,9 +47,9 @@ test "maybe return" {
47}47}
4848
49fn maybeReturnImpl() void {49fn maybeReturnImpl() void {
50 assertOrPanic(foo(1235).?);50 expect(foo(1235).?);
51 if (foo(null) != null) unreachable;51 if (foo(null) != null) unreachable;
52 assertOrPanic(!foo(1234).?);52 expect(!foo(1234).?);
53}53}
5454
55fn foo(x: ?i32) ?bool {55fn foo(x: ?i32) ?bool {
...@@ -58,7 +58,7 @@ fn foo(x: ?i32) ?bool {...@@ -58,7 +58,7 @@ fn foo(x: ?i32) ?bool {
58}58}
5959
60test "if var maybe pointer" {60test "if var maybe pointer" {
61 assertOrPanic(shouldBeAPlus1(Particle{61 expect(shouldBeAPlus1(Particle{
62 .a = 14,62 .a = 14,
63 .b = 1,63 .b = 1,
64 .c = 1,64 .c = 1,
...@@ -84,10 +84,10 @@ const Particle = struct {...@@ -84,10 +84,10 @@ const Particle = struct {
8484
85test "null literal outside function" {85test "null literal outside function" {
86 const is_null = here_is_a_null_literal.context == null;86 const is_null = here_is_a_null_literal.context == null;
87 assertOrPanic(is_null);87 expect(is_null);
8888
89 const is_non_null = here_is_a_null_literal.context != null;89 const is_non_null = here_is_a_null_literal.context != null;
90 assertOrPanic(!is_non_null);90 expect(!is_non_null);
91}91}
92const SillyStruct = struct {92const SillyStruct = struct {
93 context: ?i32,93 context: ?i32,
...@@ -98,8 +98,8 @@ test "test null runtime" {...@@ -98,8 +98,8 @@ test "test null runtime" {
98 testTestNullRuntime(null);98 testTestNullRuntime(null);
99}99}
100fn testTestNullRuntime(x: ?i32) void {100fn testTestNullRuntime(x: ?i32) void {
101 assertOrPanic(x == null);101 expect(x == null);
102 assertOrPanic(!(x != null));102 expect(!(x != null));
103}103}
104104
105test "optional void" {105test "optional void" {
...@@ -108,8 +108,8 @@ test "optional void" {...@@ -108,8 +108,8 @@ test "optional void" {
108}108}
109109
110fn optionalVoidImpl() void {110fn optionalVoidImpl() void {
111 assertOrPanic(bar(null) == null);111 expect(bar(null) == null);
112 assertOrPanic(bar({}) != null);112 expect(bar({}) != null);
113}113}
114114
115fn bar(x: ?void) ?void {115fn bar(x: ?void) ?void {
...@@ -133,7 +133,7 @@ test "unwrap optional which is field of global var" {...@@ -133,7 +133,7 @@ test "unwrap optional which is field of global var" {
133 }133 }
134 struct_with_optional.field = 1234;134 struct_with_optional.field = 1234;
135 if (struct_with_optional.field) |payload| {135 if (struct_with_optional.field) |payload| {
136 assertOrPanic(payload == 1234);136 expect(payload == 1234);
137 } else {137 } else {
138 unreachable;138 unreachable;
139 }139 }
...@@ -141,13 +141,13 @@ test "unwrap optional which is field of global var" {...@@ -141,13 +141,13 @@ test "unwrap optional which is field of global var" {
141141
142test "null with default unwrap" {142test "null with default unwrap" {
143 const x: i32 = null orelse 1;143 const x: i32 = null orelse 1;
144 assertOrPanic(x == 1);144 expect(x == 1);
145}145}
146146
147test "optional types" {147test "optional types" {
148 comptime {148 comptime {
149 const opt_type_struct = StructWithOptionalType{ .t = u8 };149 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);
151 }151 }
152}152}
153153
...@@ -158,5 +158,5 @@ const StructWithOptionalType = struct {...@@ -158,5 +158,5 @@ const StructWithOptionalType = struct {
158test "optional pointer to 0 bit type null value at runtime" {158test "optional pointer to 0 bit type null value at runtime" {
159 const EmptyStruct = struct {};159 const EmptyStruct = struct {};
160 var x: ?*EmptyStruct = null;160 var x: ?*EmptyStruct = null;
161 assertOrPanic(x == null);161 expect(x == null);
162}162}
test/stage1/behavior/optional.zig+14-14
...@@ -1,11 +1,11 @@...@@ -1,11 +1,11 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;1const expect = @import("std").testing.expect;
22
3pub const EmptyStruct = struct {};3pub const EmptyStruct = struct {};
44
5test "optional pointer to size zero struct" {5test "optional pointer to size zero struct" {
6 var e = EmptyStruct{};6 var e = EmptyStruct{};
7 var o: ?*EmptyStruct = &e;7 var o: ?*EmptyStruct = &e;
8 assertOrPanic(o != null);8 expect(o != null);
9}9}
1010
11test "equality compare nullable pointers" {11test "equality compare nullable pointers" {
...@@ -18,15 +18,15 @@ fn testNullPtrsEql() void {...@@ -18,15 +18,15 @@ fn testNullPtrsEql() void {
1818
19 var x: ?*i32 = null;19 var x: ?*i32 = null;
20 var y: ?*i32 = null;20 var y: ?*i32 = null;
21 assertOrPanic(x == y);21 expect(x == y);
22 y = &number;22 y = &number;
23 assertOrPanic(x != y);23 expect(x != y);
24 assertOrPanic(x != &number);24 expect(x != &number);
25 assertOrPanic(&number != x);25 expect(&number != x);
26 x = &number;26 x = &number;
27 assertOrPanic(x == y);27 expect(x == y);
28 assertOrPanic(x == &number);28 expect(x == &number);
29 assertOrPanic(&number == x);29 expect(&number == x);
30}30}
3131
32test "address of unwrap optional" {32test "address of unwrap optional" {
...@@ -43,7 +43,7 @@ test "address of unwrap optional" {...@@ -43,7 +43,7 @@ test "address of unwrap optional" {
43 };43 };
44 S.global = S.Foo{ .a = 1234 };44 S.global = S.Foo{ .a = 1234 };
45 const foo = S.getFoo() catch unreachable;45 const foo = S.getFoo() catch unreachable;
46 assertOrPanic(foo.a == 1234);46 expect(foo.a == 1234);
47}47}
4848
49test "passing an optional integer as a parameter" {49test "passing an optional integer as a parameter" {
...@@ -57,15 +57,15 @@ test "passing an optional integer as a parameter" {...@@ -57,15 +57,15 @@ test "passing an optional integer as a parameter" {
57 return x.? == 1234;57 return x.? == 1234;
58 }58 }
59 };59 };
60 assertOrPanic(S.entry());60 expect(S.entry());
61 comptime assertOrPanic(S.entry());61 comptime expect(S.entry());
62}62}
6363
64test "unwrap function call with optional pointer return value" {64test "unwrap function call with optional pointer return value" {
65 const S = struct {65 const S = struct {
66 fn entry() void {66 fn entry() void {
67 assertOrPanic(foo().?.* == 1234);67 expect(foo().?.* == 1234);
68 assertOrPanic(bar() == null);68 expect(bar() == null);
69 }69 }
70 const global: i32 = 1234;70 const global: i32 = 1234;
71 fn foo() ?*const i32 {71 fn foo() ?*const i32 {
test/stage1/behavior/pointers.zig+12-12
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const assertOrPanic = std.debug.assertOrPanic;2const expect = std.testing.expect;
33
4test "dereference pointer" {4test "dereference pointer" {
5 comptime testDerefPtr();5 comptime testDerefPtr();
...@@ -10,33 +10,33 @@ fn testDerefPtr() void {...@@ -10,33 +10,33 @@ fn testDerefPtr() void {
10 var x: i32 = 1234;10 var x: i32 = 1234;
11 var y = &x;11 var y = &x;
12 y.* += 1;12 y.* += 1;
13 assertOrPanic(x == 1235);13 expect(x == 1235);
14}14}
1515
16test "pointer arithmetic" {16test "pointer arithmetic" {
17 var ptr = c"abcd";17 var ptr = c"abcd";
1818
19 assertOrPanic(ptr[0] == 'a');19 expect(ptr[0] == 'a');
20 ptr += 1;20 ptr += 1;
21 assertOrPanic(ptr[0] == 'b');21 expect(ptr[0] == 'b');
22 ptr += 1;22 ptr += 1;
23 assertOrPanic(ptr[0] == 'c');23 expect(ptr[0] == 'c');
24 ptr += 1;24 ptr += 1;
25 assertOrPanic(ptr[0] == 'd');25 expect(ptr[0] == 'd');
26 ptr += 1;26 ptr += 1;
27 assertOrPanic(ptr[0] == 0);27 expect(ptr[0] == 0);
28 ptr -= 1;28 ptr -= 1;
29 assertOrPanic(ptr[0] == 'd');29 expect(ptr[0] == 'd');
30 ptr -= 1;30 ptr -= 1;
31 assertOrPanic(ptr[0] == 'c');31 expect(ptr[0] == 'c');
32 ptr -= 1;32 ptr -= 1;
33 assertOrPanic(ptr[0] == 'b');33 expect(ptr[0] == 'b');
34 ptr -= 1;34 ptr -= 1;
35 assertOrPanic(ptr[0] == 'a');35 expect(ptr[0] == 'a');
36}36}
3737
38test "double pointer parsing" {38test "double pointer parsing" {
39 comptime assertOrPanic(PtrOf(PtrOf(i32)) == **i32);39 comptime expect(PtrOf(PtrOf(i32)) == **i32);
40}40}
4141
42fn PtrOf(comptime T: type) type {42fn PtrOf(comptime T: type) type {
test/stage1/behavior/popcount.zig+5-5
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;1const expect = @import("std").testing.expect;
22
3test "@popCount" {3test "@popCount" {
4 comptime testPopCount();4 comptime testPopCount();
...@@ -8,18 +8,18 @@ test "@popCount" {...@@ -8,18 +8,18 @@ test "@popCount" {
8fn testPopCount() void {8fn testPopCount() void {
9 {9 {
10 var x: u32 = 0xaa;10 var x: u32 = 0xaa;
11 assertOrPanic(@popCount(x) == 4);11 expect(@popCount(x) == 4);
12 }12 }
13 {13 {
14 var x: u32 = 0xaaaaaaaa;14 var x: u32 = 0xaaaaaaaa;
15 assertOrPanic(@popCount(x) == 16);15 expect(@popCount(x) == 16);
16 }16 }
17 {17 {
18 var x: i16 = -1;18 var x: i16 = -1;
19 assertOrPanic(@popCount(x) == 16);19 expect(@popCount(x) == 16);
20 }20 }
21 comptime {21 comptime {
22 assertOrPanic(@popCount(0b11111111000110001100010000100001000011000011100101010001) == 24);22 expect(@popCount(0b11111111000110001100010000100001000011000011100101010001) == 24);
23 }23 }
24}24}
2525
test/stage1/behavior/ptrcast.zig+4-4
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const builtin = @import("builtin");1const builtin = @import("builtin");
2const std = @import("std");2const std = @import("std");
3const assertOrPanic = std.debug.assertOrPanic;3const expect = std.testing.expect;
44
5test "reinterpret bytes as integer with nonzero offset" {5test "reinterpret bytes as integer with nonzero offset" {
6 testReinterpretBytesAsInteger();6 testReinterpretBytesAsInteger();
...@@ -13,7 +13,7 @@ fn testReinterpretBytesAsInteger() void {...@@ -13,7 +13,7 @@ fn testReinterpretBytesAsInteger() void {
13 builtin.Endian.Little => 0xab785634,13 builtin.Endian.Little => 0xab785634,
14 builtin.Endian.Big => 0x345678ab,14 builtin.Endian.Big => 0x345678ab,
15 };15 };
16 assertOrPanic(@ptrCast(*align(1) const u32, bytes[1..5].ptr).* == expected);16 expect(@ptrCast(*align(1) const u32, bytes[1..5].ptr).* == expected);
17}17}
1818
19test "reinterpret bytes of an array into an extern struct" {19test "reinterpret bytes of an array into an extern struct" {
...@@ -32,12 +32,12 @@ fn testReinterpretBytesAsExternStruct() void {...@@ -32,12 +32,12 @@ fn testReinterpretBytesAsExternStruct() void {
3232
33 var ptr = @ptrCast(*const S, &bytes);33 var ptr = @ptrCast(*const S, &bytes);
34 var val = ptr.c;34 var val = ptr.c;
35 assertOrPanic(val == 5);35 expect(val == 5);
36}36}
3737
38test "reinterpret struct field at comptime" {38test "reinterpret struct field at comptime" {
39 const numLittle = comptime Bytes.init(0x12345678);39 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));
41}41}
4242
43const Bytes = struct {43const Bytes = struct {
test/stage1/behavior/pub_enum/index.zig+3-3
...@@ -1,13 +1,13 @@...@@ -1,13 +1,13 @@
1const other = @import("other.zig");1const other = @import("other.zig");
2const assertOrPanic = @import("std").debug.assertOrPanic;2const expect = @import("std").testing.expect;
33
4test "pub enum" {4test "pub enum" {
5 pubEnumTest(other.APubEnum.Two);5 pubEnumTest(other.APubEnum.Two);
6}6}
7fn pubEnumTest(foo: other.APubEnum) void {7fn pubEnumTest(foo: other.APubEnum) void {
8 assertOrPanic(foo == other.APubEnum.Two);8 expect(foo == other.APubEnum.Two);
9}9}
1010
11test "cast with imported symbol" {11test "cast with imported symbol" {
12 assertOrPanic(other.size_t(42) == 42);12 expect(other.size_t(42) == 42);
13}13}
test/stage1/behavior/ref_var_in_if_after_if_2nd_switch_prong.zig+5-5
...@@ -1,14 +1,14 @@...@@ -1,14 +1,14 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;1const expect = @import("std").testing.expect;
2const mem = @import("std").mem;2const mem = @import("std").mem;
33
4var ok: bool = false;4var ok: bool = false;
5test "reference a variable in an if after an if in the 2nd switch prong" {5test "reference a variable in an if after an if in the 2nd switch prong" {
6 foo(true, Num.Two, false, "aoeu");6 foo(true, Num.Two, false, "aoeu");
7 assertOrPanic(!ok);7 expect(!ok);
8 foo(false, Num.One, false, "aoeu");8 foo(false, Num.One, false, "aoeu");
9 assertOrPanic(!ok);9 expect(!ok);
10 foo(true, Num.One, false, "aoeu");10 foo(true, Num.One, false, "aoeu");
11 assertOrPanic(ok);11 expect(ok);
12}12}
1313
14const Num = enum {14const Num = enum {
...@@ -32,6 +32,6 @@ fn foo(c: bool, k: Num, c2: bool, b: []const u8) void {...@@ -32,6 +32,6 @@ fn foo(c: bool, k: Num, c2: bool, b: []const u8) void {
32}32}
3333
34fn a(x: []const u8) void {34fn a(x: []const u8) void {
35 assertOrPanic(mem.eql(u8, x, "aoeu"));35 expect(mem.eql(u8, x, "aoeu"));
36 ok = true;36 ok = true;
37}37}
test/stage1/behavior/reflection.zig+39-39
...@@ -1,25 +1,25 @@...@@ -1,25 +1,25 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;1const expect = @import("std").testing.expect;
2const mem = @import("std").mem;2const mem = @import("std").mem;
3const reflection = @This();3const reflection = @This();
44
5test "reflection: array, pointer, optional, error union type child" {5test "reflection: array, pointer, optional, error union type child" {
6 comptime {6 comptime {
7 assertOrPanic(([10]u8).Child == u8);7 expect(([10]u8).Child == u8);
8 assertOrPanic((*u8).Child == u8);8 expect((*u8).Child == u8);
9 assertOrPanic((anyerror!u8).Payload == u8);9 expect((anyerror!u8).Payload == u8);
10 assertOrPanic((?u8).Child == u8);10 expect((?u8).Child == u8);
11 }11 }
12}12}
1313
14test "reflection: function return type, var args, and param types" {14test "reflection: function return type, var args, and param types" {
15 comptime {15 comptime {
16 assertOrPanic(@typeOf(dummy).ReturnType == i32);16 expect(@typeOf(dummy).ReturnType == i32);
17 assertOrPanic(!@typeOf(dummy).is_var_args);17 expect(!@typeOf(dummy).is_var_args);
18 assertOrPanic(@typeOf(dummy_varargs).is_var_args);18 expect(@typeOf(dummy_varargs).is_var_args);
19 assertOrPanic(@typeOf(dummy).arg_count == 3);19 expect(@typeOf(dummy).arg_count == 3);
20 assertOrPanic(@ArgType(@typeOf(dummy), 0) == bool);20 expect(@ArgType(@typeOf(dummy), 0) == bool);
21 assertOrPanic(@ArgType(@typeOf(dummy), 1) == i32);21 expect(@ArgType(@typeOf(dummy), 1) == i32);
22 assertOrPanic(@ArgType(@typeOf(dummy), 2) == f32);22 expect(@ArgType(@typeOf(dummy), 2) == f32);
23 }23 }
24}24}
2525
...@@ -30,31 +30,31 @@ fn dummy_varargs(args: ...) void {}...@@ -30,31 +30,31 @@ fn dummy_varargs(args: ...) void {}
3030
31test "reflection: struct member types and names" {31test "reflection: struct member types and names" {
32 comptime {32 comptime {
33 assertOrPanic(@memberCount(Foo) == 3);33 expect(@memberCount(Foo) == 3);
3434
35 assertOrPanic(@memberType(Foo, 0) == i32);35 expect(@memberType(Foo, 0) == i32);
36 assertOrPanic(@memberType(Foo, 1) == bool);36 expect(@memberType(Foo, 1) == bool);
37 assertOrPanic(@memberType(Foo, 2) == void);37 expect(@memberType(Foo, 2) == void);
3838
39 assertOrPanic(mem.eql(u8, @memberName(Foo, 0), "one"));39 expect(mem.eql(u8, @memberName(Foo, 0), "one"));
40 assertOrPanic(mem.eql(u8, @memberName(Foo, 1), "two"));40 expect(mem.eql(u8, @memberName(Foo, 1), "two"));
41 assertOrPanic(mem.eql(u8, @memberName(Foo, 2), "three"));41 expect(mem.eql(u8, @memberName(Foo, 2), "three"));
42 }42 }
43}43}
4444
45test "reflection: enum member types and names" {45test "reflection: enum member types and names" {
46 comptime {46 comptime {
47 assertOrPanic(@memberCount(Bar) == 4);47 expect(@memberCount(Bar) == 4);
4848
49 assertOrPanic(@memberType(Bar, 0) == void);49 expect(@memberType(Bar, 0) == void);
50 assertOrPanic(@memberType(Bar, 1) == i32);50 expect(@memberType(Bar, 1) == i32);
51 assertOrPanic(@memberType(Bar, 2) == bool);51 expect(@memberType(Bar, 2) == bool);
52 assertOrPanic(@memberType(Bar, 3) == f64);52 expect(@memberType(Bar, 3) == f64);
5353
54 assertOrPanic(mem.eql(u8, @memberName(Bar, 0), "One"));54 expect(mem.eql(u8, @memberName(Bar, 0), "One"));
55 assertOrPanic(mem.eql(u8, @memberName(Bar, 1), "Two"));55 expect(mem.eql(u8, @memberName(Bar, 1), "Two"));
56 assertOrPanic(mem.eql(u8, @memberName(Bar, 2), "Three"));56 expect(mem.eql(u8, @memberName(Bar, 2), "Three"));
57 assertOrPanic(mem.eql(u8, @memberName(Bar, 3), "Four"));57 expect(mem.eql(u8, @memberName(Bar, 3), "Four"));
58 }58 }
59}59}
6060
...@@ -65,18 +65,18 @@ test "reflection: @field" {...@@ -65,18 +65,18 @@ test "reflection: @field" {
65 .three = void{},65 .three = void{},
66 };66 };
6767
68 assertOrPanic(f.one == f.one);68 expect(f.one == f.one);
69 assertOrPanic(@field(f, "o" ++ "ne") == f.one);69 expect(@field(f, "o" ++ "ne") == f.one);
70 assertOrPanic(@field(f, "t" ++ "wo") == f.two);70 expect(@field(f, "t" ++ "wo") == f.two);
71 assertOrPanic(@field(f, "th" ++ "ree") == f.three);71 expect(@field(f, "th" ++ "ree") == f.three);
72 assertOrPanic(@field(Foo, "const" ++ "ant") == Foo.constant);72 expect(@field(Foo, "const" ++ "ant") == Foo.constant);
73 assertOrPanic(@field(Bar, "O" ++ "ne") == Bar.One);73 expect(@field(Bar, "O" ++ "ne") == Bar.One);
74 assertOrPanic(@field(Bar, "T" ++ "wo") == Bar.Two);74 expect(@field(Bar, "T" ++ "wo") == Bar.Two);
75 assertOrPanic(@field(Bar, "Th" ++ "ree") == Bar.Three);75 expect(@field(Bar, "Th" ++ "ree") == Bar.Three);
76 assertOrPanic(@field(Bar, "F" ++ "our") == Bar.Four);76 expect(@field(Bar, "F" ++ "our") == Bar.Four);
77 assertOrPanic(@field(reflection, "dum" ++ "my")(true, 1, 2) == dummy(true, 1, 2));77 expect(@field(reflection, "dum" ++ "my")(true, 1, 2) == dummy(true, 1, 2));
78 @field(f, "o" ++ "ne") = 4;78 @field(f, "o" ++ "ne") = 4;
79 assertOrPanic(f.one == 4);79 expect(f.one == 4);
80}80}
8181
82const Foo = struct {82const Foo = struct {
test/stage1/behavior/sizeof_and_typeof.zig+30-30
...@@ -1,9 +1,9 @@...@@ -1,9 +1,9 @@
1const builtin = @import("builtin");1const builtin = @import("builtin");
2const assertOrPanic = @import("std").debug.assertOrPanic;2const expect = @import("std").testing.expect;
33
4test "@sizeOf and @typeOf" {4test "@sizeOf and @typeOf" {
5 const y: @typeOf(x) = 120;5 const y: @typeOf(x) = 120;
6 assertOrPanic(@sizeOf(@typeOf(y)) == 2);6 expect(@sizeOf(@typeOf(y)) == 2);
7}7}
8const x: u16 = 13;8const x: u16 = 13;
9const z: @typeOf(x) = 19;9const z: @typeOf(x) = 19;
...@@ -30,40 +30,40 @@ const P = packed struct {...@@ -30,40 +30,40 @@ const P = packed struct {
3030
31test "@byteOffsetOf" {31test "@byteOffsetOf" {
32 // Packed structs have fixed memory layout32 // Packed structs have fixed memory layout
33 assertOrPanic(@byteOffsetOf(P, "a") == 0);33 expect(@byteOffsetOf(P, "a") == 0);
34 assertOrPanic(@byteOffsetOf(P, "b") == 1);34 expect(@byteOffsetOf(P, "b") == 1);
35 assertOrPanic(@byteOffsetOf(P, "c") == 5);35 expect(@byteOffsetOf(P, "c") == 5);
36 assertOrPanic(@byteOffsetOf(P, "d") == 6);36 expect(@byteOffsetOf(P, "d") == 6);
37 assertOrPanic(@byteOffsetOf(P, "e") == 6);37 expect(@byteOffsetOf(P, "e") == 6);
38 assertOrPanic(@byteOffsetOf(P, "f") == 7);38 expect(@byteOffsetOf(P, "f") == 7);
39 assertOrPanic(@byteOffsetOf(P, "g") == 9);39 expect(@byteOffsetOf(P, "g") == 9);
4040
41 // Normal struct fields can be moved/padded41 // Normal struct fields can be moved/padded
42 var a: A = undefined;42 var a: A = undefined;
43 assertOrPanic(@ptrToInt(&a.a) - @ptrToInt(&a) == @byteOffsetOf(A, "a"));43 expect(@ptrToInt(&a.a) - @ptrToInt(&a) == @byteOffsetOf(A, "a"));
44 assertOrPanic(@ptrToInt(&a.b) - @ptrToInt(&a) == @byteOffsetOf(A, "b"));44 expect(@ptrToInt(&a.b) - @ptrToInt(&a) == @byteOffsetOf(A, "b"));
45 assertOrPanic(@ptrToInt(&a.c) - @ptrToInt(&a) == @byteOffsetOf(A, "c"));45 expect(@ptrToInt(&a.c) - @ptrToInt(&a) == @byteOffsetOf(A, "c"));
46 assertOrPanic(@ptrToInt(&a.d) - @ptrToInt(&a) == @byteOffsetOf(A, "d"));46 expect(@ptrToInt(&a.d) - @ptrToInt(&a) == @byteOffsetOf(A, "d"));
47 assertOrPanic(@ptrToInt(&a.e) - @ptrToInt(&a) == @byteOffsetOf(A, "e"));47 expect(@ptrToInt(&a.e) - @ptrToInt(&a) == @byteOffsetOf(A, "e"));
48 assertOrPanic(@ptrToInt(&a.f) - @ptrToInt(&a) == @byteOffsetOf(A, "f"));48 expect(@ptrToInt(&a.f) - @ptrToInt(&a) == @byteOffsetOf(A, "f"));
49 assertOrPanic(@ptrToInt(&a.g) - @ptrToInt(&a) == @byteOffsetOf(A, "g"));49 expect(@ptrToInt(&a.g) - @ptrToInt(&a) == @byteOffsetOf(A, "g"));
50}50}
5151
52test "@bitOffsetOf" {52test "@bitOffsetOf" {
53 // Packed structs have fixed memory layout53 // Packed structs have fixed memory layout
54 assertOrPanic(@bitOffsetOf(P, "a") == 0);54 expect(@bitOffsetOf(P, "a") == 0);
55 assertOrPanic(@bitOffsetOf(P, "b") == 8);55 expect(@bitOffsetOf(P, "b") == 8);
56 assertOrPanic(@bitOffsetOf(P, "c") == 40);56 expect(@bitOffsetOf(P, "c") == 40);
57 assertOrPanic(@bitOffsetOf(P, "d") == 48);57 expect(@bitOffsetOf(P, "d") == 48);
58 assertOrPanic(@bitOffsetOf(P, "e") == 51);58 expect(@bitOffsetOf(P, "e") == 51);
59 assertOrPanic(@bitOffsetOf(P, "f") == 56);59 expect(@bitOffsetOf(P, "f") == 56);
60 assertOrPanic(@bitOffsetOf(P, "g") == 72);60 expect(@bitOffsetOf(P, "g") == 72);
6161
62 assertOrPanic(@byteOffsetOf(A, "a") * 8 == @bitOffsetOf(A, "a"));62 expect(@byteOffsetOf(A, "a") * 8 == @bitOffsetOf(A, "a"));
63 assertOrPanic(@byteOffsetOf(A, "b") * 8 == @bitOffsetOf(A, "b"));63 expect(@byteOffsetOf(A, "b") * 8 == @bitOffsetOf(A, "b"));
64 assertOrPanic(@byteOffsetOf(A, "c") * 8 == @bitOffsetOf(A, "c"));64 expect(@byteOffsetOf(A, "c") * 8 == @bitOffsetOf(A, "c"));
65 assertOrPanic(@byteOffsetOf(A, "d") * 8 == @bitOffsetOf(A, "d"));65 expect(@byteOffsetOf(A, "d") * 8 == @bitOffsetOf(A, "d"));
66 assertOrPanic(@byteOffsetOf(A, "e") * 8 == @bitOffsetOf(A, "e"));66 expect(@byteOffsetOf(A, "e") * 8 == @bitOffsetOf(A, "e"));
67 assertOrPanic(@byteOffsetOf(A, "f") * 8 == @bitOffsetOf(A, "f"));67 expect(@byteOffsetOf(A, "f") * 8 == @bitOffsetOf(A, "f"));
68 assertOrPanic(@byteOffsetOf(A, "g") * 8 == @bitOffsetOf(A, "g"));68 expect(@byteOffsetOf(A, "g") * 8 == @bitOffsetOf(A, "g"));
69}69}
test/stage1/behavior/slice.zig+8-8
...@@ -1,20 +1,20 @@...@@ -1,20 +1,20 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;1const expect = @import("std").testing.expect;
2const mem = @import("std").mem;2const mem = @import("std").mem;
33
4const x = @intToPtr([*]i32, 0x1000)[0..0x500];4const x = @intToPtr([*]i32, 0x1000)[0..0x500];
5const y = x[0x100..];5const y = x[0x100..];
6test "compile time slice of pointer to hard coded address" {6test "compile time slice of pointer to hard coded address" {
7 assertOrPanic(@ptrToInt(x.ptr) == 0x1000);7 expect(@ptrToInt(x.ptr) == 0x1000);
8 assertOrPanic(x.len == 0x500);8 expect(x.len == 0x500);
99
10 assertOrPanic(@ptrToInt(y.ptr) == 0x1100);10 expect(@ptrToInt(y.ptr) == 0x1100);
11 assertOrPanic(y.len == 0x400);11 expect(y.len == 0x400);
12}12}
1313
14test "slice child property" {14test "slice child property" {
15 var array: [5]i32 = undefined;15 var array: [5]i32 = undefined;
16 var slice = array[0..];16 var slice = array[0..];
17 assertOrPanic(@typeOf(slice).Child == i32);17 expect(@typeOf(slice).Child == i32);
18}18}
1919
20test "runtime safety lets us slice from len..len" {20test "runtime safety lets us slice from len..len" {
...@@ -23,7 +23,7 @@ test "runtime safety lets us slice from len..len" {...@@ -23,7 +23,7 @@ test "runtime safety lets us slice from len..len" {
23 2,23 2,
24 3,24 3,
25 };25 };
26 assertOrPanic(mem.eql(u8, sliceFromLenToLen(an_array[0..], 3, 3), ""));26 expect(mem.eql(u8, sliceFromLenToLen(an_array[0..], 3, 3), ""));
27}27}
2828
29fn sliceFromLenToLen(a_slice: []u8, start: usize, end: usize) []u8 {29fn sliceFromLenToLen(a_slice: []u8, start: usize, end: usize) []u8 {
...@@ -36,5 +36,5 @@ test "implicitly cast array of size 0 to slice" {...@@ -36,5 +36,5 @@ test "implicitly cast array of size 0 to slice" {
36}36}
3737
38fn assertLenIsZero(msg: []const u8) void {38fn assertLenIsZero(msg: []const u8) void {
39 assertOrPanic(msg.len == 0);39 expect(msg.len == 0);
40}40}
test/stage1/behavior/struct.zig+92-92
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const assertOrPanic = std.debug.assertOrPanic;2const expect = std.testing.expect;
3const builtin = @import("builtin");3const builtin = @import("builtin");
4const maxInt = std.math.maxInt;4const maxInt = std.math.maxInt;
55
...@@ -12,7 +12,7 @@ const empty_global_instance = StructWithNoFields{};...@@ -12,7 +12,7 @@ const empty_global_instance = StructWithNoFields{};
1212
13test "call struct static method" {13test "call struct static method" {
14 const result = StructWithNoFields.add(3, 4);14 const result = StructWithNoFields.add(3, 4);
15 assertOrPanic(result == 7);15 expect(result == 7);
16}16}
1717
18test "return empty struct instance" {18test "return empty struct instance" {
...@@ -25,7 +25,7 @@ fn returnEmptyStructInstance() StructWithNoFields {...@@ -25,7 +25,7 @@ fn returnEmptyStructInstance() StructWithNoFields {
25const should_be_11 = StructWithNoFields.add(5, 6);25const should_be_11 = StructWithNoFields.add(5, 6);
2626
27test "invoke static method in global scope" {27test "invoke static method in global scope" {
28 assertOrPanic(should_be_11 == 11);28 expect(should_be_11 == 11);
29}29}
3030
31test "void struct fields" {31test "void struct fields" {
...@@ -34,8 +34,8 @@ test "void struct fields" {...@@ -34,8 +34,8 @@ test "void struct fields" {
34 .b = 1,34 .b = 1,
35 .c = void{},35 .c = void{},
36 };36 };
37 assertOrPanic(foo.b == 1);37 expect(foo.b == 1);
38 assertOrPanic(@sizeOf(VoidStructFieldsFoo) == 4);38 expect(@sizeOf(VoidStructFieldsFoo) == 4);
39}39}
40const VoidStructFieldsFoo = struct {40const VoidStructFieldsFoo = struct {
41 a: void,41 a: void,
...@@ -50,7 +50,7 @@ test "structs" {...@@ -50,7 +50,7 @@ test "structs" {
50 foo.b = foo.a == 1;50 foo.b = foo.a == 1;
51 testFoo(foo);51 testFoo(foo);
52 testMutation(&foo);52 testMutation(&foo);
53 assertOrPanic(foo.c == 100);53 expect(foo.c == 100);
54}54}
55const StructFoo = struct {55const StructFoo = struct {
56 a: i32,56 a: i32,
...@@ -58,7 +58,7 @@ const StructFoo = struct {...@@ -58,7 +58,7 @@ const StructFoo = struct {
58 c: f32,58 c: f32,
59};59};
60fn testFoo(foo: StructFoo) void {60fn testFoo(foo: StructFoo) void {
61 assertOrPanic(foo.b);61 expect(foo.b);
62}62}
63fn testMutation(foo: *StructFoo) void {63fn testMutation(foo: *StructFoo) void {
64 foo.c = 100;64 foo.c = 100;
...@@ -83,7 +83,7 @@ test "struct point to self" {...@@ -83,7 +83,7 @@ test "struct point to self" {
8383
84 root.next = &node;84 root.next = &node;
8585
86 assertOrPanic(node.next.next.next.val.x == 1);86 expect(node.next.next.next.val.x == 1);
87}87}
8888
89test "struct byval assign" {89test "struct byval assign" {
...@@ -92,18 +92,18 @@ test "struct byval assign" {...@@ -92,18 +92,18 @@ test "struct byval assign" {
9292
93 foo1.a = 1234;93 foo1.a = 1234;
94 foo2.a = 0;94 foo2.a = 0;
95 assertOrPanic(foo2.a == 0);95 expect(foo2.a == 0);
96 foo2 = foo1;96 foo2 = foo1;
97 assertOrPanic(foo2.a == 1234);97 expect(foo2.a == 1234);
98}98}
9999
100fn structInitializer() void {100fn structInitializer() void {
101 const val = Val{ .x = 42 };101 const val = Val{ .x = 42 };
102 assertOrPanic(val.x == 42);102 expect(val.x == 42);
103}103}
104104
105test "fn call of struct field" {105test "fn call of struct field" {
106 assertOrPanic(callStructField(Foo{ .ptr = aFunc }) == 13);106 expect(callStructField(Foo{ .ptr = aFunc }) == 13);
107}107}
108108
109const Foo = struct {109const Foo = struct {
...@@ -122,7 +122,7 @@ test "store member function in variable" {...@@ -122,7 +122,7 @@ test "store member function in variable" {
122 const instance = MemberFnTestFoo{ .x = 1234 };122 const instance = MemberFnTestFoo{ .x = 1234 };
123 const memberFn = MemberFnTestFoo.member;123 const memberFn = MemberFnTestFoo.member;
124 const result = memberFn(instance);124 const result = memberFn(instance);
125 assertOrPanic(result == 1234);125 expect(result == 1234);
126}126}
127const MemberFnTestFoo = struct {127const MemberFnTestFoo = struct {
128 x: i32,128 x: i32,
...@@ -134,12 +134,12 @@ const MemberFnTestFoo = struct {...@@ -134,12 +134,12 @@ const MemberFnTestFoo = struct {
134test "call member function directly" {134test "call member function directly" {
135 const instance = MemberFnTestFoo{ .x = 1234 };135 const instance = MemberFnTestFoo{ .x = 1234 };
136 const result = MemberFnTestFoo.member(instance);136 const result = MemberFnTestFoo.member(instance);
137 assertOrPanic(result == 1234);137 expect(result == 1234);
138}138}
139139
140test "member functions" {140test "member functions" {
141 const r = MemberFnRand{ .seed = 1234 };141 const r = MemberFnRand{ .seed = 1234 };
142 assertOrPanic(r.getSeed() == 1234);142 expect(r.getSeed() == 1234);
143}143}
144const MemberFnRand = struct {144const MemberFnRand = struct {
145 seed: u32,145 seed: u32,
...@@ -150,7 +150,7 @@ const MemberFnRand = struct {...@@ -150,7 +150,7 @@ const MemberFnRand = struct {
150150
151test "return struct byval from function" {151test "return struct byval from function" {
152 const bar = makeBar(1234, 5678);152 const bar = makeBar(1234, 5678);
153 assertOrPanic(bar.y == 5678);153 expect(bar.y == 5678);
154}154}
155const Bar = struct {155const Bar = struct {
156 x: i32,156 x: i32,
...@@ -165,7 +165,7 @@ fn makeBar(x: i32, y: i32) Bar {...@@ -165,7 +165,7 @@ fn makeBar(x: i32, y: i32) Bar {
165165
166test "empty struct method call" {166test "empty struct method call" {
167 const es = EmptyStruct{};167 const es = EmptyStruct{};
168 assertOrPanic(es.method() == 1234);168 expect(es.method() == 1234);
169}169}
170const EmptyStruct = struct {170const EmptyStruct = struct {
171 fn method(es: *const EmptyStruct) i32 {171 fn method(es: *const EmptyStruct) i32 {
...@@ -182,7 +182,7 @@ fn testReturnEmptyStructFromFn() EmptyStruct2 {...@@ -182,7 +182,7 @@ fn testReturnEmptyStructFromFn() EmptyStruct2 {
182}182}
183183
184test "pass slice of empty struct to fn" {184test "pass slice of empty struct to fn" {
185 assertOrPanic(testPassSliceOfEmptyStructToFn([]EmptyStruct2{EmptyStruct2{}}) == 1);185 expect(testPassSliceOfEmptyStructToFn([]EmptyStruct2{EmptyStruct2{}}) == 1);
186}186}
187fn testPassSliceOfEmptyStructToFn(slice: []const EmptyStruct2) usize {187fn testPassSliceOfEmptyStructToFn(slice: []const EmptyStruct2) usize {
188 return slice.len;188 return slice.len;
...@@ -200,7 +200,7 @@ test "packed struct" {...@@ -200,7 +200,7 @@ test "packed struct" {
200 };200 };
201 foo.y += 1;201 foo.y += 1;
202 const four = foo.x + foo.y;202 const four = foo.x + foo.y;
203 assertOrPanic(four == 4);203 expect(four == 4);
204}204}
205205
206const BitField1 = packed struct {206const BitField1 = packed struct {
...@@ -217,17 +217,17 @@ const bit_field_1 = BitField1{...@@ -217,17 +217,17 @@ const bit_field_1 = BitField1{
217217
218test "bit field access" {218test "bit field access" {
219 var data = bit_field_1;219 var data = bit_field_1;
220 assertOrPanic(getA(&data) == 1);220 expect(getA(&data) == 1);
221 assertOrPanic(getB(&data) == 2);221 expect(getB(&data) == 2);
222 assertOrPanic(getC(&data) == 3);222 expect(getC(&data) == 3);
223 comptime assertOrPanic(@sizeOf(BitField1) == 1);223 comptime expect(@sizeOf(BitField1) == 1);
224224
225 data.b += 1;225 data.b += 1;
226 assertOrPanic(data.b == 3);226 expect(data.b == 3);
227227
228 data.a += 1;228 data.a += 1;
229 assertOrPanic(data.a == 2);229 expect(data.a == 2);
230 assertOrPanic(data.b == 3);230 expect(data.b == 3);
231}231}
232232
233fn getA(data: *const BitField1) u3 {233fn getA(data: *const BitField1) u3 {
...@@ -254,8 +254,8 @@ const Foo96Bits = packed struct {...@@ -254,8 +254,8 @@ const Foo96Bits = packed struct {
254254
255test "packed struct 24bits" {255test "packed struct 24bits" {
256 comptime {256 comptime {
257 assertOrPanic(@sizeOf(Foo24Bits) == 3);257 expect(@sizeOf(Foo24Bits) == 3);
258 assertOrPanic(@sizeOf(Foo96Bits) == 12);258 expect(@sizeOf(Foo96Bits) == 12);
259 }259 }
260260
261 var value = Foo96Bits{261 var value = Foo96Bits{
...@@ -265,28 +265,28 @@ test "packed struct 24bits" {...@@ -265,28 +265,28 @@ test "packed struct 24bits" {
265 .d = 0,265 .d = 0,
266 };266 };
267 value.a += 1;267 value.a += 1;
268 assertOrPanic(value.a == 1);268 expect(value.a == 1);
269 assertOrPanic(value.b == 0);269 expect(value.b == 0);
270 assertOrPanic(value.c == 0);270 expect(value.c == 0);
271 assertOrPanic(value.d == 0);271 expect(value.d == 0);
272272
273 value.b += 1;273 value.b += 1;
274 assertOrPanic(value.a == 1);274 expect(value.a == 1);
275 assertOrPanic(value.b == 1);275 expect(value.b == 1);
276 assertOrPanic(value.c == 0);276 expect(value.c == 0);
277 assertOrPanic(value.d == 0);277 expect(value.d == 0);
278278
279 value.c += 1;279 value.c += 1;
280 assertOrPanic(value.a == 1);280 expect(value.a == 1);
281 assertOrPanic(value.b == 1);281 expect(value.b == 1);
282 assertOrPanic(value.c == 1);282 expect(value.c == 1);
283 assertOrPanic(value.d == 0);283 expect(value.d == 0);
284284
285 value.d += 1;285 value.d += 1;
286 assertOrPanic(value.a == 1);286 expect(value.a == 1);
287 assertOrPanic(value.b == 1);287 expect(value.b == 1);
288 assertOrPanic(value.c == 1);288 expect(value.c == 1);
289 assertOrPanic(value.d == 1);289 expect(value.d == 1);
290}290}
291291
292const FooArray24Bits = packed struct {292const FooArray24Bits = packed struct {
...@@ -297,43 +297,43 @@ const FooArray24Bits = packed struct {...@@ -297,43 +297,43 @@ const FooArray24Bits = packed struct {
297297
298test "packed array 24bits" {298test "packed array 24bits" {
299 comptime {299 comptime {
300 assertOrPanic(@sizeOf([9]Foo24Bits) == 9 * 3);300 expect(@sizeOf([9]Foo24Bits) == 9 * 3);
301 assertOrPanic(@sizeOf(FooArray24Bits) == 2 + 2 * 3 + 2);301 expect(@sizeOf(FooArray24Bits) == 2 + 2 * 3 + 2);
302 }302 }
303303
304 var bytes = []u8{0} ** (@sizeOf(FooArray24Bits) + 1);304 var bytes = []u8{0} ** (@sizeOf(FooArray24Bits) + 1);
305 bytes[bytes.len - 1] = 0xaa;305 bytes[bytes.len - 1] = 0xaa;
306 const ptr = &@bytesToSlice(FooArray24Bits, bytes[0 .. bytes.len - 1])[0];306 const ptr = &@bytesToSlice(FooArray24Bits, bytes[0 .. bytes.len - 1])[0];
307 assertOrPanic(ptr.a == 0);307 expect(ptr.a == 0);
308 assertOrPanic(ptr.b[0].field == 0);308 expect(ptr.b[0].field == 0);
309 assertOrPanic(ptr.b[1].field == 0);309 expect(ptr.b[1].field == 0);
310 assertOrPanic(ptr.c == 0);310 expect(ptr.c == 0);
311311
312 ptr.a = maxInt(u16);312 ptr.a = maxInt(u16);
313 assertOrPanic(ptr.a == maxInt(u16));313 expect(ptr.a == maxInt(u16));
314 assertOrPanic(ptr.b[0].field == 0);314 expect(ptr.b[0].field == 0);
315 assertOrPanic(ptr.b[1].field == 0);315 expect(ptr.b[1].field == 0);
316 assertOrPanic(ptr.c == 0);316 expect(ptr.c == 0);
317317
318 ptr.b[0].field = maxInt(u24);318 ptr.b[0].field = maxInt(u24);
319 assertOrPanic(ptr.a == maxInt(u16));319 expect(ptr.a == maxInt(u16));
320 assertOrPanic(ptr.b[0].field == maxInt(u24));320 expect(ptr.b[0].field == maxInt(u24));
321 assertOrPanic(ptr.b[1].field == 0);321 expect(ptr.b[1].field == 0);
322 assertOrPanic(ptr.c == 0);322 expect(ptr.c == 0);
323323
324 ptr.b[1].field = maxInt(u24);324 ptr.b[1].field = maxInt(u24);
325 assertOrPanic(ptr.a == maxInt(u16));325 expect(ptr.a == maxInt(u16));
326 assertOrPanic(ptr.b[0].field == maxInt(u24));326 expect(ptr.b[0].field == maxInt(u24));
327 assertOrPanic(ptr.b[1].field == maxInt(u24));327 expect(ptr.b[1].field == maxInt(u24));
328 assertOrPanic(ptr.c == 0);328 expect(ptr.c == 0);
329329
330 ptr.c = maxInt(u16);330 ptr.c = maxInt(u16);
331 assertOrPanic(ptr.a == maxInt(u16));331 expect(ptr.a == maxInt(u16));
332 assertOrPanic(ptr.b[0].field == maxInt(u24));332 expect(ptr.b[0].field == maxInt(u24));
333 assertOrPanic(ptr.b[1].field == maxInt(u24));333 expect(ptr.b[1].field == maxInt(u24));
334 assertOrPanic(ptr.c == maxInt(u16));334 expect(ptr.c == maxInt(u16));
335335
336 assertOrPanic(bytes[bytes.len - 1] == 0xaa);336 expect(bytes[bytes.len - 1] == 0xaa);
337}337}
338338
339const FooStructAligned = packed struct {339const FooStructAligned = packed struct {
...@@ -347,17 +347,17 @@ const FooArrayOfAligned = packed struct {...@@ -347,17 +347,17 @@ const FooArrayOfAligned = packed struct {
347347
348test "aligned array of packed struct" {348test "aligned array of packed struct" {
349 comptime {349 comptime {
350 assertOrPanic(@sizeOf(FooStructAligned) == 2);350 expect(@sizeOf(FooStructAligned) == 2);
351 assertOrPanic(@sizeOf(FooArrayOfAligned) == 2 * 2);351 expect(@sizeOf(FooArrayOfAligned) == 2 * 2);
352 }352 }
353353
354 var bytes = []u8{0xbb} ** @sizeOf(FooArrayOfAligned);354 var bytes = []u8{0xbb} ** @sizeOf(FooArrayOfAligned);
355 const ptr = &@bytesToSlice(FooArrayOfAligned, bytes[0..bytes.len])[0];355 const ptr = &@bytesToSlice(FooArrayOfAligned, bytes[0..bytes.len])[0];
356356
357 assertOrPanic(ptr.a[0].a == 0xbb);357 expect(ptr.a[0].a == 0xbb);
358 assertOrPanic(ptr.a[0].b == 0xbb);358 expect(ptr.a[0].b == 0xbb);
359 assertOrPanic(ptr.a[1].a == 0xbb);359 expect(ptr.a[1].a == 0xbb);
360 assertOrPanic(ptr.a[1].b == 0xbb);360 expect(ptr.a[1].b == 0xbb);
361}361}
362362
363test "runtime struct initialization of bitfield" {363test "runtime struct initialization of bitfield" {
...@@ -370,10 +370,10 @@ test "runtime struct initialization of bitfield" {...@@ -370,10 +370,10 @@ test "runtime struct initialization of bitfield" {
370 .y = @intCast(u4, x2),370 .y = @intCast(u4, x2),
371 };371 };
372372
373 assertOrPanic(s1.x == x1);373 expect(s1.x == x1);
374 assertOrPanic(s1.y == x1);374 expect(s1.y == x1);
375 assertOrPanic(s2.x == @intCast(u4, x2));375 expect(s2.x == @intCast(u4, x2));
376 assertOrPanic(s2.y == @intCast(u4, x2));376 expect(s2.y == @intCast(u4, x2));
377}377}
378378
379var x1 = u4(1);379var x1 = u4(1);
...@@ -400,18 +400,18 @@ test "native bit field understands endianness" {...@@ -400,18 +400,18 @@ test "native bit field understands endianness" {
400 @memcpy(bytes[0..].ptr, @ptrCast([*]u8, &all), 8);400 @memcpy(bytes[0..].ptr, @ptrCast([*]u8, &all), 8);
401 var bitfields = @ptrCast(*Bitfields, bytes[0..].ptr).*;401 var bitfields = @ptrCast(*Bitfields, bytes[0..].ptr).*;
402402
403 assertOrPanic(bitfields.f1 == 0x1111);403 expect(bitfields.f1 == 0x1111);
404 assertOrPanic(bitfields.f2 == 0x2222);404 expect(bitfields.f2 == 0x2222);
405 assertOrPanic(bitfields.f3 == 0x33);405 expect(bitfields.f3 == 0x33);
406 assertOrPanic(bitfields.f4 == 0x44);406 expect(bitfields.f4 == 0x44);
407 assertOrPanic(bitfields.f5 == 0x5);407 expect(bitfields.f5 == 0x5);
408 assertOrPanic(bitfields.f6 == 0x6);408 expect(bitfields.f6 == 0x6);
409 assertOrPanic(bitfields.f7 == 0x77);409 expect(bitfields.f7 == 0x77);
410}410}
411411
412test "align 1 field before self referential align 8 field as slice return type" {412test "align 1 field before self referential align 8 field as slice return type" {
413 const result = alloc(Expr);413 const result = alloc(Expr);
414 assertOrPanic(result.len == 0);414 expect(result.len == 0);
415}415}
416416
417const Expr = union(enum) {417const Expr = union(enum) {
...@@ -434,10 +434,10 @@ test "call method with mutable reference to struct with no fields" {...@@ -434,10 +434,10 @@ test "call method with mutable reference to struct with no fields" {
434 };434 };
435435
436 var s = S{};436 var s = S{};
437 assertOrPanic(S.doC(&s));437 expect(S.doC(&s));
438 assertOrPanic(s.doC());438 expect(s.doC());
439 assertOrPanic(S.do(&s));439 expect(S.do(&s));
440 assertOrPanic(s.do());440 expect(s.do());
441}441}
442442
443test "implicit cast packed struct field to const ptr" {443test "implicit cast packed struct field to const ptr" {
...@@ -453,7 +453,7 @@ test "implicit cast packed struct field to const ptr" {...@@ -453,7 +453,7 @@ test "implicit cast packed struct field to const ptr" {
453 var lup: LevelUpMove = undefined;453 var lup: LevelUpMove = undefined;
454 lup.level = 12;454 lup.level = 12;
455 const res = LevelUpMove.toInt(lup.level);455 const res = LevelUpMove.toInt(lup.level);
456 assertOrPanic(res == 12);456 expect(res == 12);
457}457}
458458
459test "pointer to packed struct member in a stack variable" {459test "pointer to packed struct member in a stack variable" {
...@@ -464,7 +464,7 @@ test "pointer to packed struct member in a stack variable" {...@@ -464,7 +464,7 @@ test "pointer to packed struct member in a stack variable" {
464464
465 var s = S{ .a = 2, .b = 0 };465 var s = S{ .a = 2, .b = 0 };
466 var b_ptr = &s.b;466 var b_ptr = &s.b;
467 assertOrPanic(s.b == 0);467 expect(s.b == 0);
468 b_ptr.* = 2;468 b_ptr.* = 2;
469 assertOrPanic(s.b == 2);469 expect(s.b == 2);
470}470}
test/stage1/behavior/struct_contains_null_ptr_itself.zig+2-2
...@@ -1,9 +1,9 @@...@@ -1,9 +1,9 @@
1const std = @import("std");1const std = @import("std");
2const assertOrPanic = std.debug.assertOrPanic;2const expect = std.testing.expect;
33
4test "struct contains null pointer which contains original struct" {4test "struct contains null pointer which contains original struct" {
5 var x: ?*NodeLineComment = null;5 var x: ?*NodeLineComment = null;
6 assertOrPanic(x == null);6 expect(x == null);
7}7}
88
9pub const Node = struct {9pub const Node = struct {
test/stage1/behavior/struct_contains_slice_of_itself.zig+13-13
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;1const expect = @import("std").testing.expect;
22
3const Node = struct {3const Node = struct {
4 payload: i32,4 payload: i32,
...@@ -39,12 +39,12 @@ test "struct contains slice of itself" {...@@ -39,12 +39,12 @@ test "struct contains slice of itself" {
39 .payload = 1234,39 .payload = 1234,
40 .children = nodes[0..],40 .children = nodes[0..],
41 };41 };
42 assertOrPanic(root.payload == 1234);42 expect(root.payload == 1234);
43 assertOrPanic(root.children[0].payload == 1);43 expect(root.children[0].payload == 1);
44 assertOrPanic(root.children[1].payload == 2);44 expect(root.children[1].payload == 2);
45 assertOrPanic(root.children[2].payload == 3);45 expect(root.children[2].payload == 3);
46 assertOrPanic(root.children[2].children[0].payload == 31);46 expect(root.children[2].children[0].payload == 31);
47 assertOrPanic(root.children[2].children[1].payload == 32);47 expect(root.children[2].children[1].payload == 32);
48}48}
4949
50test "struct contains aligned slice of itself" {50test "struct contains aligned slice of itself" {
...@@ -76,10 +76,10 @@ test "struct contains aligned slice of itself" {...@@ -76,10 +76,10 @@ test "struct contains aligned slice of itself" {
76 .payload = 1234,76 .payload = 1234,
77 .children = nodes[0..],77 .children = nodes[0..],
78 };78 };
79 assertOrPanic(root.payload == 1234);79 expect(root.payload == 1234);
80 assertOrPanic(root.children[0].payload == 1);80 expect(root.children[0].payload == 1);
81 assertOrPanic(root.children[1].payload == 2);81 expect(root.children[1].payload == 2);
82 assertOrPanic(root.children[2].payload == 3);82 expect(root.children[2].payload == 3);
83 assertOrPanic(root.children[2].children[0].payload == 31);83 expect(root.children[2].children[0].payload == 31);
84 assertOrPanic(root.children[2].children[1].payload == 32);84 expect(root.children[2].children[1].payload == 32);
85}85}
test/stage1/behavior/switch.zig+33-33
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;1const expect = @import("std").testing.expect;
22
3test "switch with numbers" {3test "switch with numbers" {
4 testSwitchWithNumbers(13);4 testSwitchWithNumbers(13);
...@@ -10,14 +10,14 @@ fn testSwitchWithNumbers(x: u32) void {...@@ -10,14 +10,14 @@ fn testSwitchWithNumbers(x: u32) void {
10 13 => true,10 13 => true,
11 else => false,11 else => false,
12 };12 };
13 assertOrPanic(result);13 expect(result);
14}14}
1515
16test "switch with all ranges" {16test "switch with all ranges" {
17 assertOrPanic(testSwitchWithAllRanges(50, 3) == 1);17 expect(testSwitchWithAllRanges(50, 3) == 1);
18 assertOrPanic(testSwitchWithAllRanges(101, 0) == 2);18 expect(testSwitchWithAllRanges(101, 0) == 2);
19 assertOrPanic(testSwitchWithAllRanges(300, 5) == 3);19 expect(testSwitchWithAllRanges(300, 5) == 3);
20 assertOrPanic(testSwitchWithAllRanges(301, 6) == 6);20 expect(testSwitchWithAllRanges(301, 6) == 6);
21}21}
2222
23fn testSwitchWithAllRanges(x: u32, y: u32) u32 {23fn testSwitchWithAllRanges(x: u32, y: u32) u32 {
...@@ -40,7 +40,7 @@ test "implicit comptime switch" {...@@ -40,7 +40,7 @@ test "implicit comptime switch" {
40 };40 };
4141
42 comptime {42 comptime {
43 assertOrPanic(result + 1 == 14);43 expect(result + 1 == 14);
44 }44 }
45}45}
4646
...@@ -71,7 +71,7 @@ fn nonConstSwitch(foo: SwitchStatmentFoo) void {...@@ -71,7 +71,7 @@ fn nonConstSwitch(foo: SwitchStatmentFoo) void {
71 SwitchStatmentFoo.C => 3,71 SwitchStatmentFoo.C => 3,
72 SwitchStatmentFoo.D => 4,72 SwitchStatmentFoo.D => 4,
73 };73 };
74 assertOrPanic(val == 3);74 expect(val == 3);
75}75}
76const SwitchStatmentFoo = enum {76const SwitchStatmentFoo = enum {
77 A,77 A,
...@@ -93,10 +93,10 @@ const SwitchProngWithVarEnum = union(enum) {...@@ -93,10 +93,10 @@ const SwitchProngWithVarEnum = union(enum) {
93fn switchProngWithVarFn(a: SwitchProngWithVarEnum) void {93fn switchProngWithVarFn(a: SwitchProngWithVarEnum) void {
94 switch (a) {94 switch (a) {
95 SwitchProngWithVarEnum.One => |x| {95 SwitchProngWithVarEnum.One => |x| {
96 assertOrPanic(x == 13);96 expect(x == 13);
97 },97 },
98 SwitchProngWithVarEnum.Two => |x| {98 SwitchProngWithVarEnum.Two => |x| {
99 assertOrPanic(x == 13.0);99 expect(x == 13.0);
100 },100 },
101 SwitchProngWithVarEnum.Meh => |x| {101 SwitchProngWithVarEnum.Meh => |x| {
102 const v: void = x;102 const v: void = x;
...@@ -116,7 +116,7 @@ fn testSwitchEnumPtrCapture() void {...@@ -116,7 +116,7 @@ fn testSwitchEnumPtrCapture() void {
116 else => unreachable,116 else => unreachable,
117 }117 }
118 switch (value) {118 switch (value) {
119 SwitchProngWithVarEnum.One => |x| assertOrPanic(x == 1235),119 SwitchProngWithVarEnum.One => |x| expect(x == 1235),
120 else => unreachable,120 else => unreachable,
121 }121 }
122}122}
...@@ -127,7 +127,7 @@ test "switch with multiple expressions" {...@@ -127,7 +127,7 @@ test "switch with multiple expressions" {
127 4, 5, 6 => 2,127 4, 5, 6 => 2,
128 else => i32(3),128 else => i32(3),
129 };129 };
130 assertOrPanic(x == 2);130 expect(x == 2);
131}131}
132fn returnsFive() i32 {132fn returnsFive() i32 {
133 return 5;133 return 5;
...@@ -149,12 +149,12 @@ fn returnsFalse() bool {...@@ -149,12 +149,12 @@ fn returnsFalse() bool {
149 }149 }
150}150}
151test "switch on const enum with var" {151test "switch on const enum with var" {
152 assertOrPanic(!returnsFalse());152 expect(!returnsFalse());
153}153}
154154
155test "switch on type" {155test "switch on type" {
156 assertOrPanic(trueIfBoolFalseOtherwise(bool));156 expect(trueIfBoolFalseOtherwise(bool));
157 assertOrPanic(!trueIfBoolFalseOtherwise(i32));157 expect(!trueIfBoolFalseOtherwise(i32));
158}158}
159159
160fn trueIfBoolFalseOtherwise(comptime T: type) bool {160fn trueIfBoolFalseOtherwise(comptime T: type) bool {
...@@ -170,16 +170,16 @@ test "switch handles all cases of number" {...@@ -170,16 +170,16 @@ test "switch handles all cases of number" {
170}170}
171171
172fn testSwitchHandleAllCases() void {172fn testSwitchHandleAllCases() void {
173 assertOrPanic(testSwitchHandleAllCasesExhaustive(0) == 3);173 expect(testSwitchHandleAllCasesExhaustive(0) == 3);
174 assertOrPanic(testSwitchHandleAllCasesExhaustive(1) == 2);174 expect(testSwitchHandleAllCasesExhaustive(1) == 2);
175 assertOrPanic(testSwitchHandleAllCasesExhaustive(2) == 1);175 expect(testSwitchHandleAllCasesExhaustive(2) == 1);
176 assertOrPanic(testSwitchHandleAllCasesExhaustive(3) == 0);176 expect(testSwitchHandleAllCasesExhaustive(3) == 0);
177177
178 assertOrPanic(testSwitchHandleAllCasesRange(100) == 0);178 expect(testSwitchHandleAllCasesRange(100) == 0);
179 assertOrPanic(testSwitchHandleAllCasesRange(200) == 1);179 expect(testSwitchHandleAllCasesRange(200) == 1);
180 assertOrPanic(testSwitchHandleAllCasesRange(201) == 2);180 expect(testSwitchHandleAllCasesRange(201) == 2);
181 assertOrPanic(testSwitchHandleAllCasesRange(202) == 4);181 expect(testSwitchHandleAllCasesRange(202) == 4);
182 assertOrPanic(testSwitchHandleAllCasesRange(230) == 3);182 expect(testSwitchHandleAllCasesRange(230) == 3);
183}183}
184184
185fn testSwitchHandleAllCasesExhaustive(x: u2) u2 {185fn testSwitchHandleAllCasesExhaustive(x: u2) u2 {
...@@ -207,8 +207,8 @@ test "switch all prongs unreachable" {...@@ -207,8 +207,8 @@ test "switch all prongs unreachable" {
207}207}
208208
209fn testAllProngsUnreachable() void {209fn testAllProngsUnreachable() void {
210 assertOrPanic(switchWithUnreachable(1) == 2);210 expect(switchWithUnreachable(1) == 2);
211 assertOrPanic(switchWithUnreachable(2) == 10);211 expect(switchWithUnreachable(2) == 10);
212}212}
213213
214fn switchWithUnreachable(x: i32) i32 {214fn switchWithUnreachable(x: i32) i32 {
...@@ -230,7 +230,7 @@ test "capture value of switch with all unreachable prongs" {...@@ -230,7 +230,7 @@ test "capture value of switch with all unreachable prongs" {
230 const x = return_a_number() catch |err| switch (err) {230 const x = return_a_number() catch |err| switch (err) {
231 else => unreachable,231 else => unreachable,
232 };232 };
233 assertOrPanic(x == 1);233 expect(x == 1);
234}234}
235235
236test "switching on booleans" {236test "switching on booleans" {
...@@ -239,14 +239,14 @@ test "switching on booleans" {...@@ -239,14 +239,14 @@ test "switching on booleans" {
239}239}
240240
241fn testSwitchOnBools() void {241fn testSwitchOnBools() void {
242 assertOrPanic(testSwitchOnBoolsTrueAndFalse(true) == false);242 expect(testSwitchOnBoolsTrueAndFalse(true) == false);
243 assertOrPanic(testSwitchOnBoolsTrueAndFalse(false) == true);243 expect(testSwitchOnBoolsTrueAndFalse(false) == true);
244244
245 assertOrPanic(testSwitchOnBoolsTrueWithElse(true) == false);245 expect(testSwitchOnBoolsTrueWithElse(true) == false);
246 assertOrPanic(testSwitchOnBoolsTrueWithElse(false) == true);246 expect(testSwitchOnBoolsTrueWithElse(false) == true);
247247
248 assertOrPanic(testSwitchOnBoolsFalseWithElse(true) == false);248 expect(testSwitchOnBoolsFalseWithElse(true) == false);
249 assertOrPanic(testSwitchOnBoolsFalseWithElse(false) == true);249 expect(testSwitchOnBoolsFalseWithElse(false) == true);
250}250}
251251
252fn testSwitchOnBoolsTrueAndFalse(x: bool) bool {252fn testSwitchOnBoolsTrueAndFalse(x: bool) bool {
test/stage1/behavior/switch_prong_err_enum.zig+3-3
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;1const expect = @import("std").testing.expect;
22
3var read_count: u64 = 0;3var read_count: u64 = 0;
44
...@@ -22,9 +22,9 @@ fn doThing(form_id: u64) anyerror!FormValue {...@@ -22,9 +22,9 @@ fn doThing(form_id: u64) anyerror!FormValue {
22test "switch prong returns error enum" {22test "switch prong returns error enum" {
23 switch (doThing(17) catch unreachable) {23 switch (doThing(17) catch unreachable) {
24 FormValue.Address => |payload| {24 FormValue.Address => |payload| {
25 assertOrPanic(payload == 1);25 expect(payload == 1);
26 },26 },
27 else => unreachable,27 else => unreachable,
28 }28 }
29 assertOrPanic(read_count == 1);29 expect(read_count == 1);
30}30}
test/stage1/behavior/switch_prong_implicit_cast.zig+2-2
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;1const expect = @import("std").testing.expect;
22
3const FormValue = union(enum) {3const FormValue = union(enum) {
4 One: void,4 One: void,
...@@ -18,5 +18,5 @@ test "switch prong implicit cast" {...@@ -18,5 +18,5 @@ test "switch prong implicit cast" {
18 FormValue.One => false,18 FormValue.One => false,
19 FormValue.Two => |x| x,19 FormValue.Two => |x| x,
20 };20 };
21 assertOrPanic(result);21 expect(result);
22}22}
test/stage1/behavior/this.zig+4-4
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;1const expect = @import("std").testing.expect;
22
3const module = @This();3const module = @This();
44
...@@ -20,7 +20,7 @@ fn add(x: i32, y: i32) i32 {...@@ -20,7 +20,7 @@ fn add(x: i32, y: i32) i32 {
20}20}
2121
22test "this refer to module call private fn" {22test "this refer to module call private fn" {
23 assertOrPanic(module.add(1, 2) == 3);23 expect(module.add(1, 2) == 3);
24}24}
2525
26test "this refer to container" {26test "this refer to container" {
...@@ -29,7 +29,7 @@ test "this refer to container" {...@@ -29,7 +29,7 @@ test "this refer to container" {
29 .y = 34,29 .y = 34,
30 };30 };
31 pt.addOne();31 pt.addOne();
32 assertOrPanic(pt.x == 13);32 expect(pt.x == 13);
33 assertOrPanic(pt.y == 35);33 expect(pt.y == 35);
34}34}
3535
test/stage1/behavior/truncate.zig+2-2
...@@ -1,8 +1,8 @@...@@ -1,8 +1,8 @@
1const std = @import("std");1const std = @import("std");
2const assertOrPanic = std.debug.assertOrPanic;2const expect = std.testing.expect;
33
4test "truncate u0 to larger integer allowed and has comptime known result" {4test "truncate u0 to larger integer allowed and has comptime known result" {
5 var x: u0 = 0;5 var x: u0 = 0;
6 const y = @truncate(u8, x);6 const y = @truncate(u8, x);
7 comptime assertOrPanic(y == 0);7 comptime expect(y == 0);
8}8}
test/stage1/behavior/try.zig+5-5
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;1const expect = @import("std").testing.expect;
22
3test "try on error union" {3test "try on error union" {
4 tryOnErrorUnionImpl();4 tryOnErrorUnionImpl();
...@@ -11,7 +11,7 @@ fn tryOnErrorUnionImpl() void {...@@ -11,7 +11,7 @@ fn tryOnErrorUnionImpl() void {
11 error.CrappedOut => i32(2),11 error.CrappedOut => i32(2),
12 else => unreachable,12 else => unreachable,
13 };13 };
14 assertOrPanic(x == 11);14 expect(x == 11);
15}15}
1616
17fn returnsTen() anyerror!i32 {17fn returnsTen() anyerror!i32 {
...@@ -20,10 +20,10 @@ fn returnsTen() anyerror!i32 {...@@ -20,10 +20,10 @@ fn returnsTen() anyerror!i32 {
2020
21test "try without vars" {21test "try without vars" {
22 const result1 = if (failIfTrue(true)) 1 else |_| i32(2);22 const result1 = if (failIfTrue(true)) 1 else |_| i32(2);
23 assertOrPanic(result1 == 2);23 expect(result1 == 2);
2424
25 const result2 = if (failIfTrue(false)) 1 else |_| i32(2);25 const result2 = if (failIfTrue(false)) 1 else |_| i32(2);
26 assertOrPanic(result2 == 1);26 expect(result2 == 1);
27}27}
2828
29fn failIfTrue(ok: bool) anyerror!void {29fn failIfTrue(ok: bool) anyerror!void {
...@@ -38,6 +38,6 @@ test "try then not executed with assignment" {...@@ -38,6 +38,6 @@ test "try then not executed with assignment" {
38 if (failIfTrue(true)) {38 if (failIfTrue(true)) {
39 unreachable;39 unreachable;
40 } else |err| {40 } else |err| {
41 assertOrPanic(err == error.ItBroke);41 expect(err == error.ItBroke);
42 }42 }
43}43}
test/stage1/behavior/type_info.zig+91-91
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;1const expect = @import("std").testing.expect;
2const mem = @import("std").mem;2const mem = @import("std").mem;
3const TypeInfo = @import("builtin").TypeInfo;3const TypeInfo = @import("builtin").TypeInfo;
4const TypeId = @import("builtin").TypeId;4const TypeId = @import("builtin").TypeId;
...@@ -9,10 +9,10 @@ test "type info: tag type, void info" {...@@ -9,10 +9,10 @@ test "type info: tag type, void info" {
9}9}
1010
11fn testBasic() void {11fn testBasic() void {
12 assertOrPanic(@TagType(TypeInfo) == TypeId);12 expect(@TagType(TypeInfo) == TypeId);
13 const void_info = @typeInfo(void);13 const void_info = @typeInfo(void);
14 assertOrPanic(TypeId(void_info) == TypeId.Void);14 expect(TypeId(void_info) == TypeId.Void);
15 assertOrPanic(void_info.Void == {});15 expect(void_info.Void == {});
16}16}
1717
18test "type info: integer, floating point type info" {18test "type info: integer, floating point type info" {
...@@ -22,13 +22,13 @@ test "type info: integer, floating point type info" {...@@ -22,13 +22,13 @@ test "type info: integer, floating point type info" {
2222
23fn testIntFloat() void {23fn testIntFloat() void {
24 const u8_info = @typeInfo(u8);24 const u8_info = @typeInfo(u8);
25 assertOrPanic(TypeId(u8_info) == TypeId.Int);25 expect(TypeId(u8_info) == TypeId.Int);
26 assertOrPanic(!u8_info.Int.is_signed);26 expect(!u8_info.Int.is_signed);
27 assertOrPanic(u8_info.Int.bits == 8);27 expect(u8_info.Int.bits == 8);
2828
29 const f64_info = @typeInfo(f64);29 const f64_info = @typeInfo(f64);
30 assertOrPanic(TypeId(f64_info) == TypeId.Float);30 expect(TypeId(f64_info) == TypeId.Float);
31 assertOrPanic(f64_info.Float.bits == 64);31 expect(f64_info.Float.bits == 64);
32}32}
3333
34test "type info: pointer type info" {34test "type info: pointer type info" {
...@@ -38,12 +38,12 @@ test "type info: pointer type info" {...@@ -38,12 +38,12 @@ test "type info: pointer type info" {
3838
39fn testPointer() void {39fn testPointer() void {
40 const u32_ptr_info = @typeInfo(*u32);40 const u32_ptr_info = @typeInfo(*u32);
41 assertOrPanic(TypeId(u32_ptr_info) == TypeId.Pointer);41 expect(TypeId(u32_ptr_info) == TypeId.Pointer);
42 assertOrPanic(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.One);42 expect(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.One);
43 assertOrPanic(u32_ptr_info.Pointer.is_const == false);43 expect(u32_ptr_info.Pointer.is_const == false);
44 assertOrPanic(u32_ptr_info.Pointer.is_volatile == false);44 expect(u32_ptr_info.Pointer.is_volatile == false);
45 assertOrPanic(u32_ptr_info.Pointer.alignment == @alignOf(u32));45 expect(u32_ptr_info.Pointer.alignment == @alignOf(u32));
46 assertOrPanic(u32_ptr_info.Pointer.child == u32);46 expect(u32_ptr_info.Pointer.child == u32);
47}47}
4848
49test "type info: unknown length pointer type info" {49test "type info: unknown length pointer type info" {
...@@ -53,12 +53,12 @@ test "type info: unknown length pointer type info" {...@@ -53,12 +53,12 @@ test "type info: unknown length pointer type info" {
5353
54fn testUnknownLenPtr() void {54fn testUnknownLenPtr() void {
55 const u32_ptr_info = @typeInfo([*]const volatile f64);55 const u32_ptr_info = @typeInfo([*]const volatile f64);
56 assertOrPanic(TypeId(u32_ptr_info) == TypeId.Pointer);56 expect(TypeId(u32_ptr_info) == TypeId.Pointer);
57 assertOrPanic(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.Many);57 expect(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.Many);
58 assertOrPanic(u32_ptr_info.Pointer.is_const == true);58 expect(u32_ptr_info.Pointer.is_const == true);
59 assertOrPanic(u32_ptr_info.Pointer.is_volatile == true);59 expect(u32_ptr_info.Pointer.is_volatile == true);
60 assertOrPanic(u32_ptr_info.Pointer.alignment == @alignOf(f64));60 expect(u32_ptr_info.Pointer.alignment == @alignOf(f64));
61 assertOrPanic(u32_ptr_info.Pointer.child == f64);61 expect(u32_ptr_info.Pointer.child == f64);
62}62}
6363
64test "type info: slice type info" {64test "type info: slice type info" {
...@@ -68,12 +68,12 @@ test "type info: slice type info" {...@@ -68,12 +68,12 @@ test "type info: slice type info" {
6868
69fn testSlice() void {69fn testSlice() void {
70 const u32_slice_info = @typeInfo([]u32);70 const u32_slice_info = @typeInfo([]u32);
71 assertOrPanic(TypeId(u32_slice_info) == TypeId.Pointer);71 expect(TypeId(u32_slice_info) == TypeId.Pointer);
72 assertOrPanic(u32_slice_info.Pointer.size == TypeInfo.Pointer.Size.Slice);72 expect(u32_slice_info.Pointer.size == TypeInfo.Pointer.Size.Slice);
73 assertOrPanic(u32_slice_info.Pointer.is_const == false);73 expect(u32_slice_info.Pointer.is_const == false);
74 assertOrPanic(u32_slice_info.Pointer.is_volatile == false);74 expect(u32_slice_info.Pointer.is_volatile == false);
75 assertOrPanic(u32_slice_info.Pointer.alignment == 4);75 expect(u32_slice_info.Pointer.alignment == 4);
76 assertOrPanic(u32_slice_info.Pointer.child == u32);76 expect(u32_slice_info.Pointer.child == u32);
77}77}
7878
79test "type info: array type info" {79test "type info: array type info" {
...@@ -83,9 +83,9 @@ test "type info: array type info" {...@@ -83,9 +83,9 @@ test "type info: array type info" {
8383
84fn testArray() void {84fn testArray() void {
85 const arr_info = @typeInfo([42]bool);85 const arr_info = @typeInfo([42]bool);
86 assertOrPanic(TypeId(arr_info) == TypeId.Array);86 expect(TypeId(arr_info) == TypeId.Array);
87 assertOrPanic(arr_info.Array.len == 42);87 expect(arr_info.Array.len == 42);
88 assertOrPanic(arr_info.Array.child == bool);88 expect(arr_info.Array.child == bool);
89}89}
9090
91test "type info: optional type info" {91test "type info: optional type info" {
...@@ -95,8 +95,8 @@ test "type info: optional type info" {...@@ -95,8 +95,8 @@ test "type info: optional type info" {
9595
96fn testOptional() void {96fn testOptional() void {
97 const null_info = @typeInfo(?void);97 const null_info = @typeInfo(?void);
98 assertOrPanic(TypeId(null_info) == TypeId.Optional);98 expect(TypeId(null_info) == TypeId.Optional);
99 assertOrPanic(null_info.Optional.child == void);99 expect(null_info.Optional.child == void);
100}100}
101101
102test "type info: promise info" {102test "type info: promise info" {
...@@ -106,12 +106,12 @@ test "type info: promise info" {...@@ -106,12 +106,12 @@ test "type info: promise info" {
106106
107fn testPromise() void {107fn testPromise() void {
108 const null_promise_info = @typeInfo(promise);108 const null_promise_info = @typeInfo(promise);
109 assertOrPanic(TypeId(null_promise_info) == TypeId.Promise);109 expect(TypeId(null_promise_info) == TypeId.Promise);
110 assertOrPanic(null_promise_info.Promise.child == null);110 expect(null_promise_info.Promise.child == null);
111111
112 const promise_info = @typeInfo(promise->usize);112 const promise_info = @typeInfo(promise->usize);
113 assertOrPanic(TypeId(promise_info) == TypeId.Promise);113 expect(TypeId(promise_info) == TypeId.Promise);
114 assertOrPanic(promise_info.Promise.child.? == usize);114 expect(promise_info.Promise.child.? == usize);
115}115}
116116
117test "type info: error set, error union info" {117test "type info: error set, error union info" {
...@@ -127,15 +127,15 @@ fn testErrorSet() void {...@@ -127,15 +127,15 @@ fn testErrorSet() void {
127 };127 };
128128
129 const error_set_info = @typeInfo(TestErrorSet);129 const error_set_info = @typeInfo(TestErrorSet);
130 assertOrPanic(TypeId(error_set_info) == TypeId.ErrorSet);130 expect(TypeId(error_set_info) == TypeId.ErrorSet);
131 assertOrPanic(error_set_info.ErrorSet.errors.len == 3);131 expect(error_set_info.ErrorSet.errors.len == 3);
132 assertOrPanic(mem.eql(u8, error_set_info.ErrorSet.errors[0].name, "First"));132 expect(mem.eql(u8, error_set_info.ErrorSet.errors[0].name, "First"));
133 assertOrPanic(error_set_info.ErrorSet.errors[2].value == @errorToInt(TestErrorSet.Third));133 expect(error_set_info.ErrorSet.errors[2].value == @errorToInt(TestErrorSet.Third));
134134
135 const error_union_info = @typeInfo(TestErrorSet!usize);135 const error_union_info = @typeInfo(TestErrorSet!usize);
136 assertOrPanic(TypeId(error_union_info) == TypeId.ErrorUnion);136 expect(TypeId(error_union_info) == TypeId.ErrorUnion);
137 assertOrPanic(error_union_info.ErrorUnion.error_set == TestErrorSet);137 expect(error_union_info.ErrorUnion.error_set == TestErrorSet);
138 assertOrPanic(error_union_info.ErrorUnion.payload == usize);138 expect(error_union_info.ErrorUnion.payload == usize);
139}139}
140140
141test "type info: enum info" {141test "type info: enum info" {
...@@ -152,13 +152,13 @@ fn testEnum() void {...@@ -152,13 +152,13 @@ fn testEnum() void {
152 };152 };
153153
154 const os_info = @typeInfo(Os);154 const os_info = @typeInfo(Os);
155 assertOrPanic(TypeId(os_info) == TypeId.Enum);155 expect(TypeId(os_info) == TypeId.Enum);
156 assertOrPanic(os_info.Enum.layout == TypeInfo.ContainerLayout.Auto);156 expect(os_info.Enum.layout == TypeInfo.ContainerLayout.Auto);
157 assertOrPanic(os_info.Enum.fields.len == 4);157 expect(os_info.Enum.fields.len == 4);
158 assertOrPanic(mem.eql(u8, os_info.Enum.fields[1].name, "Macos"));158 expect(mem.eql(u8, os_info.Enum.fields[1].name, "Macos"));
159 assertOrPanic(os_info.Enum.fields[3].value == 3);159 expect(os_info.Enum.fields[3].value == 3);
160 assertOrPanic(os_info.Enum.tag_type == u2);160 expect(os_info.Enum.tag_type == u2);
161 assertOrPanic(os_info.Enum.defs.len == 0);161 expect(os_info.Enum.defs.len == 0);
162}162}
163163
164test "type info: union info" {164test "type info: union info" {
...@@ -168,14 +168,14 @@ test "type info: union info" {...@@ -168,14 +168,14 @@ test "type info: union info" {
168168
169fn testUnion() void {169fn testUnion() void {
170 const typeinfo_info = @typeInfo(TypeInfo);170 const typeinfo_info = @typeInfo(TypeInfo);
171 assertOrPanic(TypeId(typeinfo_info) == TypeId.Union);171 expect(TypeId(typeinfo_info) == TypeId.Union);
172 assertOrPanic(typeinfo_info.Union.layout == TypeInfo.ContainerLayout.Auto);172 expect(typeinfo_info.Union.layout == TypeInfo.ContainerLayout.Auto);
173 assertOrPanic(typeinfo_info.Union.tag_type.? == TypeId);173 expect(typeinfo_info.Union.tag_type.? == TypeId);
174 assertOrPanic(typeinfo_info.Union.fields.len == 25);174 expect(typeinfo_info.Union.fields.len == 25);
175 assertOrPanic(typeinfo_info.Union.fields[4].enum_field != null);175 expect(typeinfo_info.Union.fields[4].enum_field != null);
176 assertOrPanic(typeinfo_info.Union.fields[4].enum_field.?.value == 4);176 expect(typeinfo_info.Union.fields[4].enum_field.?.value == 4);
177 assertOrPanic(typeinfo_info.Union.fields[4].field_type == @typeOf(@typeInfo(u8).Int));177 expect(typeinfo_info.Union.fields[4].field_type == @typeOf(@typeInfo(u8).Int));
178 assertOrPanic(typeinfo_info.Union.defs.len == 21);178 expect(typeinfo_info.Union.defs.len == 21);
179179
180 const TestNoTagUnion = union {180 const TestNoTagUnion = union {
181 Foo: void,181 Foo: void,
...@@ -183,22 +183,22 @@ fn testUnion() void {...@@ -183,22 +183,22 @@ fn testUnion() void {
183 };183 };
184184
185 const notag_union_info = @typeInfo(TestNoTagUnion);185 const notag_union_info = @typeInfo(TestNoTagUnion);
186 assertOrPanic(TypeId(notag_union_info) == TypeId.Union);186 expect(TypeId(notag_union_info) == TypeId.Union);
187 assertOrPanic(notag_union_info.Union.tag_type == null);187 expect(notag_union_info.Union.tag_type == null);
188 assertOrPanic(notag_union_info.Union.layout == TypeInfo.ContainerLayout.Auto);188 expect(notag_union_info.Union.layout == TypeInfo.ContainerLayout.Auto);
189 assertOrPanic(notag_union_info.Union.fields.len == 2);189 expect(notag_union_info.Union.fields.len == 2);
190 assertOrPanic(notag_union_info.Union.fields[0].enum_field == null);190 expect(notag_union_info.Union.fields[0].enum_field == null);
191 assertOrPanic(notag_union_info.Union.fields[1].field_type == u32);191 expect(notag_union_info.Union.fields[1].field_type == u32);
192192
193 const TestExternUnion = extern union {193 const TestExternUnion = extern union {
194 foo: *c_void,194 foo: *c_void,
195 };195 };
196196
197 const extern_union_info = @typeInfo(TestExternUnion);197 const extern_union_info = @typeInfo(TestExternUnion);
198 assertOrPanic(extern_union_info.Union.layout == TypeInfo.ContainerLayout.Extern);198 expect(extern_union_info.Union.layout == TypeInfo.ContainerLayout.Extern);
199 assertOrPanic(extern_union_info.Union.tag_type == null);199 expect(extern_union_info.Union.tag_type == null);
200 assertOrPanic(extern_union_info.Union.fields[0].enum_field == null);200 expect(extern_union_info.Union.fields[0].enum_field == null);
201 assertOrPanic(extern_union_info.Union.fields[0].field_type == *c_void);201 expect(extern_union_info.Union.fields[0].field_type == *c_void);
202}202}
203203
204test "type info: struct info" {204test "type info: struct info" {
...@@ -208,17 +208,17 @@ test "type info: struct info" {...@@ -208,17 +208,17 @@ test "type info: struct info" {
208208
209fn testStruct() void {209fn testStruct() void {
210 const struct_info = @typeInfo(TestStruct);210 const struct_info = @typeInfo(TestStruct);
211 assertOrPanic(TypeId(struct_info) == TypeId.Struct);211 expect(TypeId(struct_info) == TypeId.Struct);
212 assertOrPanic(struct_info.Struct.layout == TypeInfo.ContainerLayout.Packed);212 expect(struct_info.Struct.layout == TypeInfo.ContainerLayout.Packed);
213 assertOrPanic(struct_info.Struct.fields.len == 3);213 expect(struct_info.Struct.fields.len == 3);
214 assertOrPanic(struct_info.Struct.fields[1].offset == null);214 expect(struct_info.Struct.fields[1].offset == null);
215 assertOrPanic(struct_info.Struct.fields[2].field_type == *TestStruct);215 expect(struct_info.Struct.fields[2].field_type == *TestStruct);
216 assertOrPanic(struct_info.Struct.defs.len == 2);216 expect(struct_info.Struct.defs.len == 2);
217 assertOrPanic(struct_info.Struct.defs[0].is_pub);217 expect(struct_info.Struct.defs[0].is_pub);
218 assertOrPanic(!struct_info.Struct.defs[0].data.Fn.is_extern);218 expect(!struct_info.Struct.defs[0].data.Fn.is_extern);
219 assertOrPanic(struct_info.Struct.defs[0].data.Fn.lib_name == null);219 expect(struct_info.Struct.defs[0].data.Fn.lib_name == null);
220 assertOrPanic(struct_info.Struct.defs[0].data.Fn.return_type == void);220 expect(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);221 expect(struct_info.Struct.defs[0].data.Fn.fn_type == fn (*const TestStruct) void);
222}222}
223223
224const TestStruct = packed struct {224const TestStruct = packed struct {
...@@ -238,18 +238,18 @@ test "type info: function type info" {...@@ -238,18 +238,18 @@ test "type info: function type info" {
238238
239fn testFunction() void {239fn testFunction() void {
240 const fn_info = @typeInfo(@typeOf(foo));240 const fn_info = @typeInfo(@typeOf(foo));
241 assertOrPanic(TypeId(fn_info) == TypeId.Fn);241 expect(TypeId(fn_info) == TypeId.Fn);
242 assertOrPanic(fn_info.Fn.calling_convention == TypeInfo.CallingConvention.Unspecified);242 expect(fn_info.Fn.calling_convention == TypeInfo.CallingConvention.Unspecified);
243 assertOrPanic(fn_info.Fn.is_generic);243 expect(fn_info.Fn.is_generic);
244 assertOrPanic(fn_info.Fn.args.len == 2);244 expect(fn_info.Fn.args.len == 2);
245 assertOrPanic(fn_info.Fn.is_var_args);245 expect(fn_info.Fn.is_var_args);
246 assertOrPanic(fn_info.Fn.return_type == null);246 expect(fn_info.Fn.return_type == null);
247 assertOrPanic(fn_info.Fn.async_allocator_type == null);247 expect(fn_info.Fn.async_allocator_type == null);
248248
249 const test_instance: TestStruct = undefined;249 const test_instance: TestStruct = undefined;
250 const bound_fn_info = @typeInfo(@typeOf(test_instance.foo));250 const bound_fn_info = @typeInfo(@typeOf(test_instance.foo));
251 assertOrPanic(TypeId(bound_fn_info) == TypeId.BoundFn);251 expect(TypeId(bound_fn_info) == TypeId.BoundFn);
252 assertOrPanic(bound_fn_info.BoundFn.args[0].arg_type.? == *const TestStruct);252 expect(bound_fn_info.BoundFn.args[0].arg_type.? == *const TestStruct);
253}253}
254254
255fn foo(comptime a: usize, b: bool, args: ...) usize {255fn foo(comptime a: usize, b: bool, args: ...) usize {
...@@ -270,7 +270,7 @@ test "type info: vectors" {...@@ -270,7 +270,7 @@ test "type info: vectors" {
270270
271fn testVector() void {271fn testVector() void {
272 const vec_info = @typeInfo(@Vector(4, i32));272 const vec_info = @typeInfo(@Vector(4, i32));
273 assertOrPanic(TypeId(vec_info) == TypeId.Vector);273 expect(TypeId(vec_info) == TypeId.Vector);
274 assertOrPanic(vec_info.Vector.len == 4);274 expect(vec_info.Vector.len == 4);
275 assertOrPanic(vec_info.Vector.child == i32);275 expect(vec_info.Vector.child == i32);
276}276}
test/stage1/behavior/undefined.zig+14-14
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;1const expect = @import("std").testing.expect;
2const mem = @import("std").mem;2const mem = @import("std").mem;
33
4fn initStaticArray() [10]i32 {4fn initStaticArray() [10]i32 {
...@@ -11,16 +11,16 @@ fn initStaticArray() [10]i32 {...@@ -11,16 +11,16 @@ fn initStaticArray() [10]i32 {
11}11}
12const static_array = initStaticArray();12const static_array = initStaticArray();
13test "init static array to undefined" {13test "init static array to undefined" {
14 assertOrPanic(static_array[0] == 1);14 expect(static_array[0] == 1);
15 assertOrPanic(static_array[4] == 2);15 expect(static_array[4] == 2);
16 assertOrPanic(static_array[7] == 3);16 expect(static_array[7] == 3);
17 assertOrPanic(static_array[9] == 4);17 expect(static_array[9] == 4);
1818
19 comptime {19 comptime {
20 assertOrPanic(static_array[0] == 1);20 expect(static_array[0] == 1);
21 assertOrPanic(static_array[4] == 2);21 expect(static_array[4] == 2);
22 assertOrPanic(static_array[7] == 3);22 expect(static_array[7] == 3);
23 assertOrPanic(static_array[9] == 4);23 expect(static_array[9] == 4);
24 }24 }
25}25}
2626
...@@ -40,12 +40,12 @@ test "assign undefined to struct" {...@@ -40,12 +40,12 @@ test "assign undefined to struct" {
40 comptime {40 comptime {
41 var foo: Foo = undefined;41 var foo: Foo = undefined;
42 setFooX(&foo);42 setFooX(&foo);
43 assertOrPanic(foo.x == 2);43 expect(foo.x == 2);
44 }44 }
45 {45 {
46 var foo: Foo = undefined;46 var foo: Foo = undefined;
47 setFooX(&foo);47 setFooX(&foo);
48 assertOrPanic(foo.x == 2);48 expect(foo.x == 2);
49 }49 }
50}50}
5151
...@@ -53,17 +53,17 @@ test "assign undefined to struct with method" {...@@ -53,17 +53,17 @@ test "assign undefined to struct with method" {
53 comptime {53 comptime {
54 var foo: Foo = undefined;54 var foo: Foo = undefined;
55 foo.setFooXMethod();55 foo.setFooXMethod();
56 assertOrPanic(foo.x == 3);56 expect(foo.x == 3);
57 }57 }
58 {58 {
59 var foo: Foo = undefined;59 var foo: Foo = undefined;
60 foo.setFooXMethod();60 foo.setFooXMethod();
61 assertOrPanic(foo.x == 3);61 expect(foo.x == 3);
62 }62 }
63}63}
6464
65test "type name of undefined" {65test "type name of undefined" {
66 const x = undefined;66 const x = undefined;
67 assertOrPanic(mem.eql(u8, @typeName(@typeOf(x)), "(undefined)"));67 expect(mem.eql(u8, @typeName(@typeOf(x)), "(undefined)"));
68}68}
6969
test/stage1/behavior/underscore.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const assertOrPanic = std.debug.assertOrPanic;2const expect = std.testing.expect;
33
4test "ignore lval with underscore" {4test "ignore lval with underscore" {
5 _ = false;5 _ = false;
test/stage1/behavior/union.zig+38-38
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;1const expect = @import("std").testing.expect;
22
3const Value = union(enum) {3const Value = union(enum) {
4 Int: u64,4 Int: u64,
...@@ -27,11 +27,11 @@ const array = []Value{...@@ -27,11 +27,11 @@ const array = []Value{
2727
28test "unions embedded in aggregate types" {28test "unions embedded in aggregate types" {
29 switch (array[1]) {29 switch (array[1]) {
30 Value.Array => |arr| assertOrPanic(arr[4] == 3),30 Value.Array => |arr| expect(arr[4] == 3),
31 else => unreachable,31 else => unreachable,
32 }32 }
33 switch ((err catch unreachable).val1) {33 switch ((err catch unreachable).val1) {
34 Value.Int => |x| assertOrPanic(x == 1234),34 Value.Int => |x| expect(x == 1234),
35 else => unreachable,35 else => unreachable,
36 }36 }
37}37}
...@@ -43,18 +43,18 @@ const Foo = union {...@@ -43,18 +43,18 @@ const Foo = union {
4343
44test "basic unions" {44test "basic unions" {
45 var foo = Foo{ .int = 1 };45 var foo = Foo{ .int = 1 };
46 assertOrPanic(foo.int == 1);46 expect(foo.int == 1);
47 foo = Foo{ .float = 12.34 };47 foo = Foo{ .float = 12.34 };
48 assertOrPanic(foo.float == 12.34);48 expect(foo.float == 12.34);
49}49}
5050
51test "comptime union field access" {51test "comptime union field access" {
52 comptime {52 comptime {
53 var foo = Foo{ .int = 0 };53 var foo = Foo{ .int = 0 };
54 assertOrPanic(foo.int == 0);54 expect(foo.int == 0);
5555
56 foo = Foo{ .float = 42.42 };56 foo = Foo{ .float = 42.42 };
57 assertOrPanic(foo.float == 42.42);57 expect(foo.float == 42.42);
58 }58 }
59}59}
6060
...@@ -62,10 +62,10 @@ test "init union with runtime value" {...@@ -62,10 +62,10 @@ test "init union with runtime value" {
62 var foo: Foo = undefined;62 var foo: Foo = undefined;
6363
64 setFloat(&foo, 12.34);64 setFloat(&foo, 12.34);
65 assertOrPanic(foo.float == 12.34);65 expect(foo.float == 12.34);
6666
67 setInt(&foo, 42);67 setInt(&foo, 42);
68 assertOrPanic(foo.int == 42);68 expect(foo.int == 42);
69}69}
7070
71fn setFloat(foo: *Foo, x: f64) void {71fn setFloat(foo: *Foo, x: f64) void {
...@@ -83,9 +83,9 @@ const FooExtern = extern union {...@@ -83,9 +83,9 @@ const FooExtern = extern union {
8383
84test "basic extern unions" {84test "basic extern unions" {
85 var foo = FooExtern{ .int = 1 };85 var foo = FooExtern{ .int = 1 };
86 assertOrPanic(foo.int == 1);86 expect(foo.int == 1);
87 foo.float = 12.34;87 foo.float = 12.34;
88 assertOrPanic(foo.float == 12.34);88 expect(foo.float == 12.34);
89}89}
9090
91const Letter = enum {91const Letter = enum {
...@@ -105,11 +105,11 @@ test "union with specified enum tag" {...@@ -105,11 +105,11 @@ test "union with specified enum tag" {
105}105}
106106
107fn doTest() void {107fn doTest() void {
108 assertOrPanic(bar(Payload{ .A = 1234 }) == -10);108 expect(bar(Payload{ .A = 1234 }) == -10);
109}109}
110110
111fn bar(value: Payload) i32 {111fn bar(value: Payload) i32 {
112 assertOrPanic(Letter(value) == Letter.A);112 expect(Letter(value) == Letter.A);
113 return switch (value) {113 return switch (value) {
114 Payload.A => |x| return x - 1244,114 Payload.A => |x| return x - 1244,
115 Payload.B => |x| if (x == 12.34) i32(20) else 21,115 Payload.B => |x| if (x == 12.34) i32(20) else 21,
...@@ -125,8 +125,8 @@ const MultipleChoice = union(enum(u32)) {...@@ -125,8 +125,8 @@ const MultipleChoice = union(enum(u32)) {
125};125};
126test "simple union(enum(u32))" {126test "simple union(enum(u32))" {
127 var x = MultipleChoice.C;127 var x = MultipleChoice.C;
128 assertOrPanic(x == MultipleChoice.C);128 expect(x == MultipleChoice.C);
129 assertOrPanic(@enumToInt(@TagType(MultipleChoice)(x)) == 60);129 expect(@enumToInt(@TagType(MultipleChoice)(x)) == 60);
130}130}
131131
132const MultipleChoice2 = union(enum(u32)) {132const MultipleChoice2 = union(enum(u32)) {
...@@ -142,14 +142,14 @@ const MultipleChoice2 = union(enum(u32)) {...@@ -142,14 +142,14 @@ const MultipleChoice2 = union(enum(u32)) {
142};142};
143143
144test "union(enum(u32)) with specified and unspecified tag values" {144test "union(enum(u32)) with specified and unspecified tag values" {
145 comptime assertOrPanic(@TagType(@TagType(MultipleChoice2)) == u32);145 comptime expect(@TagType(@TagType(MultipleChoice2)) == u32);
146 testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2{ .C = 123 });146 testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2{ .C = 123 });
147 comptime testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2{ .C = 123 });147 comptime testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2{ .C = 123 });
148}148}
149149
150fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void {150fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void {
151 assertOrPanic(@enumToInt(@TagType(MultipleChoice2)(x)) == 60);151 expect(@enumToInt(@TagType(MultipleChoice2)(x)) == 60);
152 assertOrPanic(1123 == switch (x) {152 expect(1123 == switch (x) {
153 MultipleChoice2.A => 1,153 MultipleChoice2.A => 1,
154 MultipleChoice2.B => 2,154 MultipleChoice2.B => 2,
155 MultipleChoice2.C => |v| i32(1000) + v,155 MultipleChoice2.C => |v| i32(1000) + v,
...@@ -167,7 +167,7 @@ const ExternPtrOrInt = extern union {...@@ -167,7 +167,7 @@ const ExternPtrOrInt = extern union {
167 int: u64,167 int: u64,
168};168};
169test "extern union size" {169test "extern union size" {
170 comptime assertOrPanic(@sizeOf(ExternPtrOrInt) == 8);170 comptime expect(@sizeOf(ExternPtrOrInt) == 8);
171}171}
172172
173const PackedPtrOrInt = packed union {173const PackedPtrOrInt = packed union {
...@@ -175,14 +175,14 @@ const PackedPtrOrInt = packed union {...@@ -175,14 +175,14 @@ const PackedPtrOrInt = packed union {
175 int: u64,175 int: u64,
176};176};
177test "extern union size" {177test "extern union size" {
178 comptime assertOrPanic(@sizeOf(PackedPtrOrInt) == 8);178 comptime expect(@sizeOf(PackedPtrOrInt) == 8);
179}179}
180180
181const ZeroBits = union {181const ZeroBits = union {
182 OnlyField: void,182 OnlyField: void,
183};183};
184test "union with only 1 field which is void should be zero bits" {184test "union with only 1 field which is void should be zero bits" {
185 comptime assertOrPanic(@sizeOf(ZeroBits) == 0);185 comptime expect(@sizeOf(ZeroBits) == 0);
186}186}
187187
188const TheTag = enum {188const TheTag = enum {
...@@ -196,9 +196,9 @@ const TheUnion = union(TheTag) {...@@ -196,9 +196,9 @@ const TheUnion = union(TheTag) {
196 C: i32,196 C: i32,
197};197};
198test "union field access gives the enum values" {198test "union field access gives the enum values" {
199 assertOrPanic(TheUnion.A == TheTag.A);199 expect(TheUnion.A == TheTag.A);
200 assertOrPanic(TheUnion.B == TheTag.B);200 expect(TheUnion.B == TheTag.B);
201 assertOrPanic(TheUnion.C == TheTag.C);201 expect(TheUnion.C == TheTag.C);
202}202}
203203
204test "cast union to tag type of union" {204test "cast union to tag type of union" {
...@@ -207,12 +207,12 @@ test "cast union to tag type of union" {...@@ -207,12 +207,12 @@ test "cast union to tag type of union" {
207}207}
208208
209fn testCastUnionToTagType(x: TheUnion) void {209fn testCastUnionToTagType(x: TheUnion) void {
210 assertOrPanic(TheTag(x) == TheTag.B);210 expect(TheTag(x) == TheTag.B);
211}211}
212212
213test "cast tag type of union to union" {213test "cast tag type of union to union" {
214 var x: Value2 = Letter2.B;214 var x: Value2 = Letter2.B;
215 assertOrPanic(Letter2(x) == Letter2.B);215 expect(Letter2(x) == Letter2.B);
216}216}
217const Letter2 = enum {217const Letter2 = enum {
218 A,218 A,
...@@ -227,11 +227,11 @@ const Value2 = union(Letter2) {...@@ -227,11 +227,11 @@ const Value2 = union(Letter2) {
227227
228test "implicit cast union to its tag type" {228test "implicit cast union to its tag type" {
229 var x: Value2 = Letter2.B;229 var x: Value2 = Letter2.B;
230 assertOrPanic(x == Letter2.B);230 expect(x == Letter2.B);
231 giveMeLetterB(x);231 giveMeLetterB(x);
232}232}
233fn giveMeLetterB(x: Letter2) void {233fn giveMeLetterB(x: Letter2) void {
234 assertOrPanic(x == Value2.B);234 expect(x == Value2.B);
235}235}
236236
237pub const PackThis = union(enum) {237pub const PackThis = union(enum) {
...@@ -244,7 +244,7 @@ test "constant packed union" {...@@ -244,7 +244,7 @@ test "constant packed union" {
244}244}
245245
246fn testConstPackedUnion(expected_tokens: []const PackThis) void {246fn testConstPackedUnion(expected_tokens: []const PackThis) void {
247 assertOrPanic(expected_tokens[0].StringLiteral == 1);247 expect(expected_tokens[0].StringLiteral == 1);
248}248}
249249
250test "switch on union with only 1 field" {250test "switch on union with only 1 field" {
...@@ -256,7 +256,7 @@ test "switch on union with only 1 field" {...@@ -256,7 +256,7 @@ test "switch on union with only 1 field" {
256 z = PartialInstWithPayload{ .Compiled = 1234 };256 z = PartialInstWithPayload{ .Compiled = 1234 };
257 switch (z) {257 switch (z) {
258 PartialInstWithPayload.Compiled => |x| {258 PartialInstWithPayload.Compiled => |x| {
259 assertOrPanic(x == 1234);259 expect(x == 1234);
260 return;260 return;
261 },261 },
262 }262 }
...@@ -282,11 +282,11 @@ test "access a member of tagged union with conflicting enum tag name" {...@@ -282,11 +282,11 @@ test "access a member of tagged union with conflicting enum tag name" {
282 const B = void;282 const B = void;
283 };283 };
284284
285 comptime assertOrPanic(Bar.A == u8);285 comptime expect(Bar.A == u8);
286}286}
287287
288test "tagged union initialization with runtime void" {288test "tagged union initialization with runtime void" {
289 assertOrPanic(testTaggedUnionInit({}));289 expect(testTaggedUnionInit({}));
290}290}
291291
292const TaggedUnionWithAVoid = union(enum) {292const TaggedUnionWithAVoid = union(enum) {
...@@ -324,9 +324,9 @@ test "union with only 1 field casted to its enum type" {...@@ -324,9 +324,9 @@ test "union with only 1 field casted to its enum type" {
324324
325 var e = Expr{ .Literal = Literal{ .Bool = true } };325 var e = Expr{ .Literal = Literal{ .Bool = true } };
326 const Tag = @TagType(Expr);326 const Tag = @TagType(Expr);
327 comptime assertOrPanic(@TagType(Tag) == comptime_int);327 comptime expect(@TagType(Tag) == comptime_int);
328 var t = Tag(e);328 var t = Tag(e);
329 assertOrPanic(t == Expr.Literal);329 expect(t == Expr.Literal);
330}330}
331331
332test "union with only 1 field casted to its enum type which has enum value specified" {332test "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...@@ -344,9 +344,9 @@ test "union with only 1 field casted to its enum type which has enum value speci
344 };344 };
345345
346 var e = Expr{ .Literal = Literal{ .Bool = true } };346 var e = Expr{ .Literal = Literal{ .Bool = true } };
347 comptime assertOrPanic(@TagType(Tag) == comptime_int);347 comptime expect(@TagType(Tag) == comptime_int);
348 var t = Tag(e);348 var t = Tag(e);
349 assertOrPanic(t == Expr.Literal);349 expect(t == Expr.Literal);
350 assertOrPanic(@enumToInt(t) == 33);350 expect(@enumToInt(t) == 33);
351 comptime assertOrPanic(@enumToInt(t) == 33);351 comptime expect(@enumToInt(t) == 33);
352}352}
test/stage1/behavior/var_args.zig+17-17
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;1const expect = @import("std").testing.expect;
22
3fn add(args: ...) i32 {3fn add(args: ...) i32 {
4 var sum = i32(0);4 var sum = i32(0);
...@@ -12,9 +12,9 @@ fn add(args: ...) i32 {...@@ -12,9 +12,9 @@ fn add(args: ...) i32 {
12}12}
1313
14test "add arbitrary args" {14test "add arbitrary args" {
15 assertOrPanic(add(i32(1), i32(2), i32(3), i32(4)) == 10);15 expect(add(i32(1), i32(2), i32(3), i32(4)) == 10);
16 assertOrPanic(add(i32(1234)) == 1234);16 expect(add(i32(1234)) == 1234);
17 assertOrPanic(add() == 0);17 expect(add() == 0);
18}18}
1919
20fn readFirstVarArg(args: ...) void {20fn readFirstVarArg(args: ...) void {
...@@ -26,9 +26,9 @@ test "send void arg to var args" {...@@ -26,9 +26,9 @@ test "send void arg to var args" {
26}26}
2727
28test "pass args directly" {28test "pass args directly" {
29 assertOrPanic(addSomeStuff(i32(1), i32(2), i32(3), i32(4)) == 10);29 expect(addSomeStuff(i32(1), i32(2), i32(3), i32(4)) == 10);
30 assertOrPanic(addSomeStuff(i32(1234)) == 1234);30 expect(addSomeStuff(i32(1234)) == 1234);
31 assertOrPanic(addSomeStuff() == 0);31 expect(addSomeStuff() == 0);
32}32}
3333
34fn addSomeStuff(args: ...) i32 {34fn addSomeStuff(args: ...) i32 {
...@@ -36,24 +36,24 @@ fn addSomeStuff(args: ...) i32 {...@@ -36,24 +36,24 @@ fn addSomeStuff(args: ...) i32 {
36}36}
3737
38test "runtime parameter before var args" {38test "runtime parameter before var args" {
39 assertOrPanic(extraFn(10) == 0);39 expect(extraFn(10) == 0);
40 assertOrPanic(extraFn(10, false) == 1);40 expect(extraFn(10, false) == 1);
41 assertOrPanic(extraFn(10, false, true) == 2);41 expect(extraFn(10, false, true) == 2);
4242
43 // TODO issue #31343 // TODO issue #313
44 //comptime {44 //comptime {
45 // assertOrPanic(extraFn(10) == 0);45 // expect(extraFn(10) == 0);
46 // assertOrPanic(extraFn(10, false) == 1);46 // expect(extraFn(10, false) == 1);
47 // assertOrPanic(extraFn(10, false, true) == 2);47 // expect(extraFn(10, false, true) == 2);
48 //}48 //}
49}49}
5050
51fn extraFn(extra: u32, args: ...) usize {51fn extraFn(extra: u32, args: ...) usize {
52 if (args.len >= 1) {52 if (args.len >= 1) {
53 assertOrPanic(args[0] == false);53 expect(args[0] == false);
54 }54 }
55 if (args.len >= 2) {55 if (args.len >= 2) {
56 assertOrPanic(args[1] == true);56 expect(args[1] == true);
57 }57 }
58 return args.len;58 return args.len;
59}59}
...@@ -71,8 +71,8 @@ fn foo2(args: ...) bool {...@@ -71,8 +71,8 @@ fn foo2(args: ...) bool {
71}71}
7272
73test "array of var args functions" {73test "array of var args functions" {
74 assertOrPanic(foos[0]());74 expect(foos[0]());
75 assertOrPanic(!foos[1]());75 expect(!foos[1]());
76}76}
7777
78test "pass zero length array to var args param" {78test "pass zero length array to var args param" {
test/stage1/behavior/vector.zig+4-4
...@@ -1,15 +1,15 @@...@@ -1,15 +1,15 @@
1const std = @import("std");1const std = @import("std");
2const mem = std.mem;2const mem = std.mem;
3const assertOrPanic = std.debug.assertOrPanic;3const expect = std.testing.expect;
44
5test "vector wrap operators" {5test "vector wrap operators" {
6 const S = struct {6 const S = struct {
7 fn doTheTest() void {7 fn doTheTest() void {
8 const v: @Vector(4, i32) = [4]i32{ 10, 20, 30, 40 };8 const v: @Vector(4, i32) = [4]i32{ 10, 20, 30, 40 };
9 const x: @Vector(4, i32) = [4]i32{ 1, 2, 3, 4 };9 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 }));10 expect(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 }));11 expect(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 }));12 expect(mem.eql(i32, ([4]i32)(v *% x), [4]i32{ 10, 40, 90, 160 }));
13 }13 }
14 };14 };
15 S.doTheTest();15 S.doTheTest();
test/stage1/behavior/void.zig+4-4
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;1const expect = @import("std").testing.expect;
22
3const Foo = struct {3const Foo = struct {
4 a: void,4 a: void,
...@@ -13,14 +13,14 @@ test "compare void with void compile time known" {...@@ -13,14 +13,14 @@ test "compare void with void compile time known" {
13 .b = 1,13 .b = 1,
14 .c = {},14 .c = {},
15 };15 };
16 assertOrPanic(foo.a == {});16 expect(foo.a == {});
17 }17 }
18}18}
1919
20test "iterate over a void slice" {20test "iterate over a void slice" {
21 var j: usize = 0;21 var j: usize = 0;
22 for (times(10)) |_, i| {22 for (times(10)) |_, i| {
23 assertOrPanic(i == j);23 expect(i == j);
24 j += 1;24 j += 1;
25 }25 }
26}26}
...@@ -31,5 +31,5 @@ fn times(n: usize) []const void {...@@ -31,5 +31,5 @@ fn times(n: usize) []const void {
3131
32test "void optional" {32test "void optional" {
33 var x: ?void = {};33 var x: ?void = {};
34 assertOrPanic(x != null);34 expect(x != null);
35}35}
test/stage1/behavior/while.zig+22-22
...@@ -1,12 +1,12 @@...@@ -1,12 +1,12 @@
1const assertOrPanic = @import("std").debug.assertOrPanic;1const expect = @import("std").testing.expect;
22
3test "while loop" {3test "while loop" {
4 var i: i32 = 0;4 var i: i32 = 0;
5 while (i < 4) {5 while (i < 4) {
6 i += 1;6 i += 1;
7 }7 }
8 assertOrPanic(i == 4);8 expect(i == 4);
9 assertOrPanic(whileLoop1() == 1);9 expect(whileLoop1() == 1);
10}10}
11fn whileLoop1() i32 {11fn whileLoop1() i32 {
12 return whileLoop2();12 return whileLoop2();
...@@ -18,7 +18,7 @@ fn whileLoop2() i32 {...@@ -18,7 +18,7 @@ fn whileLoop2() i32 {
18}18}
1919
20test "static eval while" {20test "static eval while" {
21 assertOrPanic(static_eval_while_number == 1);21 expect(static_eval_while_number == 1);
22}22}
23const static_eval_while_number = staticWhileLoop1();23const static_eval_while_number = staticWhileLoop1();
24fn staticWhileLoop1() i32 {24fn staticWhileLoop1() i32 {
...@@ -32,7 +32,7 @@ fn staticWhileLoop2() i32 {...@@ -32,7 +32,7 @@ fn staticWhileLoop2() i32 {
3232
33test "continue and break" {33test "continue and break" {
34 runContinueAndBreakTest();34 runContinueAndBreakTest();
35 assertOrPanic(continue_and_break_counter == 8);35 expect(continue_and_break_counter == 8);
36}36}
37var continue_and_break_counter: i32 = 0;37var continue_and_break_counter: i32 = 0;
38fn runContinueAndBreakTest() void {38fn runContinueAndBreakTest() void {
...@@ -45,7 +45,7 @@ fn runContinueAndBreakTest() void {...@@ -45,7 +45,7 @@ fn runContinueAndBreakTest() void {
45 }45 }
46 break;46 break;
47 }47 }
48 assertOrPanic(i == 4);48 expect(i == 4);
49}49}
5050
51test "return with implicit cast from while loop" {51test "return with implicit cast from while loop" {
...@@ -66,7 +66,7 @@ test "while with continue expression" {...@@ -66,7 +66,7 @@ test "while with continue expression" {
66 sum += i;66 sum += i;
67 }67 }
68 }68 }
69 assertOrPanic(sum == 40);69 expect(sum == 40);
70}70}
7171
72test "while with else" {72test "while with else" {
...@@ -78,8 +78,8 @@ test "while with else" {...@@ -78,8 +78,8 @@ test "while with else" {
78 } else {78 } else {
79 got_else += 1;79 got_else += 1;
80 }80 }
81 assertOrPanic(sum == 10);81 expect(sum == 10);
82 assertOrPanic(got_else == 1);82 expect(got_else == 1);
83}83}
8484
85test "while with optional as condition" {85test "while with optional as condition" {
...@@ -88,7 +88,7 @@ test "while with optional as condition" {...@@ -88,7 +88,7 @@ test "while with optional as condition" {
88 while (getNumberOrNull()) |value| {88 while (getNumberOrNull()) |value| {
89 sum += value;89 sum += value;
90 }90 }
91 assertOrPanic(sum == 45);91 expect(sum == 45);
92}92}
9393
94test "while with optional as condition with else" {94test "while with optional as condition with else" {
...@@ -97,12 +97,12 @@ test "while with optional as condition with else" {...@@ -97,12 +97,12 @@ test "while with optional as condition with else" {
97 var got_else: i32 = 0;97 var got_else: i32 = 0;
98 while (getNumberOrNull()) |value| {98 while (getNumberOrNull()) |value| {
99 sum += value;99 sum += value;
100 assertOrPanic(got_else == 0);100 expect(got_else == 0);
101 } else {101 } else {
102 got_else += 1;102 got_else += 1;
103 }103 }
104 assertOrPanic(sum == 45);104 expect(sum == 45);
105 assertOrPanic(got_else == 1);105 expect(got_else == 1);
106}106}
107107
108test "while with error union condition" {108test "while with error union condition" {
...@@ -112,11 +112,11 @@ test "while with error union condition" {...@@ -112,11 +112,11 @@ test "while with error union condition" {
112 while (getNumberOrErr()) |value| {112 while (getNumberOrErr()) |value| {
113 sum += value;113 sum += value;
114 } else |err| {114 } else |err| {
115 assertOrPanic(err == error.OutOfNumbers);115 expect(err == error.OutOfNumbers);
116 got_else += 1;116 got_else += 1;
117 }117 }
118 assertOrPanic(sum == 45);118 expect(sum == 45);
119 assertOrPanic(got_else == 1);119 expect(got_else == 1);
120}120}
121121
122var numbers_left: i32 = undefined;122var numbers_left: i32 = undefined;
...@@ -138,7 +138,7 @@ test "while on optional with else result follow else prong" {...@@ -138,7 +138,7 @@ test "while on optional with else result follow else prong" {
138 break value;138 break value;
139 } else139 } else
140 i32(2);140 i32(2);
141 assertOrPanic(result == 2);141 expect(result == 2);
142}142}
143143
144test "while on optional with else result follow break prong" {144test "while on optional with else result follow break prong" {
...@@ -146,7 +146,7 @@ test "while on optional with else result follow break prong" {...@@ -146,7 +146,7 @@ test "while on optional with else result follow break prong" {
146 break value;146 break value;
147 } else147 } else
148 i32(2);148 i32(2);
149 assertOrPanic(result == 10);149 expect(result == 10);
150}150}
151151
152test "while on error union with else result follow else prong" {152test "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" {...@@ -154,7 +154,7 @@ test "while on error union with else result follow else prong" {
154 break value;154 break value;
155 } else |err|155 } else |err|
156 i32(2);156 i32(2);
157 assertOrPanic(result == 2);157 expect(result == 2);
158}158}
159159
160test "while on error union with else result follow break prong" {160test "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" {...@@ -162,7 +162,7 @@ test "while on error union with else result follow break prong" {
162 break value;162 break value;
163 } else |err|163 } else |err|
164 i32(2);164 i32(2);
165 assertOrPanic(result == 10);165 expect(result == 10);
166}166}
167167
168test "while on bool with else result follow else prong" {168test "while on bool with else result follow else prong" {
...@@ -170,7 +170,7 @@ test "while on bool with else result follow else prong" {...@@ -170,7 +170,7 @@ test "while on bool with else result follow else prong" {
170 break i32(10);170 break i32(10);
171 } else171 } else
172 i32(2);172 i32(2);
173 assertOrPanic(result == 2);173 expect(result == 2);
174}174}
175175
176test "while on bool with else result follow break prong" {176test "while on bool with else result follow break prong" {
...@@ -178,7 +178,7 @@ test "while on bool with else result follow break prong" {...@@ -178,7 +178,7 @@ test "while on bool with else result follow break prong" {
178 break i32(10);178 break i32(10);
179 } else179 } else
180 i32(2);180 i32(2);
181 assertOrPanic(result == 10);181 expect(result == 10);
182}182}
183183
184test "break from outer while loop" {184test "break from outer while loop" {
test/stage1/behavior/widening.zig+4-4
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const assertOrPanic = std.debug.assertOrPanic;2const expect = std.testing.expect;
3const mem = std.mem;3const mem = std.mem;
44
5test "integer widening" {5test "integer widening" {
...@@ -9,13 +9,13 @@ test "integer widening" {...@@ -9,13 +9,13 @@ test "integer widening" {
9 var d: u64 = c;9 var d: u64 = c;
10 var e: u64 = d;10 var e: u64 = d;
11 var f: u128 = e;11 var f: u128 = e;
12 assertOrPanic(f == a);12 expect(f == a);
13}13}
1414
15test "implicit unsigned integer to signed integer" {15test "implicit unsigned integer to signed integer" {
16 var a: u8 = 250;16 var a: u8 = 250;
17 var b: i16 = a;17 var b: i16 = a;
18 assertOrPanic(b == 250);18 expect(b == 250);
19}19}
2020
21test "float widening" {21test "float widening" {
...@@ -23,6 +23,6 @@ test "float widening" {...@@ -23,6 +23,6 @@ test "float widening" {
23 var b: f32 = a;23 var b: f32 = a;
24 var c: f64 = b;24 var c: f64 = b;
25 var d: f128 = c;25 var d: f128 = c;
26 assertOrPanic(d == a);26 expect(d == a);
27}27}
2828
test/stage1/c_abi/main.zig+41-41
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const assertOrPanic = std.debug.assertOrPanic;2const expect = std.testing.expect;
33
4extern fn run_c_tests() void;4extern fn run_c_tests() void;
55
...@@ -33,28 +33,28 @@ test "C ABI integers" {...@@ -33,28 +33,28 @@ test "C ABI integers" {
33}33}
3434
35export fn zig_u8(x: u8) void {35export fn zig_u8(x: u8) void {
36 assertOrPanic(x == 0xff);36 expect(x == 0xff);
37}37}
38export fn zig_u16(x: u16) void {38export fn zig_u16(x: u16) void {
39 assertOrPanic(x == 0xfffe);39 expect(x == 0xfffe);
40}40}
41export fn zig_u32(x: u32) void {41export fn zig_u32(x: u32) void {
42 assertOrPanic(x == 0xfffffffd);42 expect(x == 0xfffffffd);
43}43}
44export fn zig_u64(x: u64) void {44export fn zig_u64(x: u64) void {
45 assertOrPanic(x == 0xfffffffffffffffc);45 expect(x == 0xfffffffffffffffc);
46}46}
47export fn zig_i8(x: i8) void {47export fn zig_i8(x: i8) void {
48 assertOrPanic(x == -1);48 expect(x == -1);
49}49}
50export fn zig_i16(x: i16) void {50export fn zig_i16(x: i16) void {
51 assertOrPanic(x == -2);51 expect(x == -2);
52}52}
53export fn zig_i32(x: i32) void {53export fn zig_i32(x: i32) void {
54 assertOrPanic(x == -3);54 expect(x == -3);
55}55}
56export fn zig_i64(x: i64) void {56export fn zig_i64(x: i64) void {
57 assertOrPanic(x == -4);57 expect(x == -4);
58}58}
5959
60extern fn c_f32(f32) void;60extern fn c_f32(f32) void;
...@@ -66,10 +66,10 @@ test "C ABI floats" {...@@ -66,10 +66,10 @@ test "C ABI floats" {
66}66}
6767
68export fn zig_f32(x: f32) void {68export fn zig_f32(x: f32) void {
69 assertOrPanic(x == 12.34);69 expect(x == 12.34);
70}70}
71export fn zig_f64(x: f64) void {71export fn zig_f64(x: f64) void {
72 assertOrPanic(x == 56.78);72 expect(x == 56.78);
73}73}
7474
75extern fn c_ptr(*c_void) void;75extern fn c_ptr(*c_void) void;
...@@ -79,7 +79,7 @@ test "C ABI pointer" {...@@ -79,7 +79,7 @@ test "C ABI pointer" {
79}79}
8080
81export fn zig_ptr(x: *c_void) void {81export fn zig_ptr(x: *c_void) void {
82 assertOrPanic(@ptrToInt(x) == 0xdeadbeef);82 expect(@ptrToInt(x) == 0xdeadbeef);
83}83}
8484
85extern fn c_bool(bool) void;85extern fn c_bool(bool) void;
...@@ -89,7 +89,7 @@ test "C ABI bool" {...@@ -89,7 +89,7 @@ test "C ABI bool" {
89}89}
9090
91export fn zig_bool(x: bool) void {91export fn zig_bool(x: bool) void {
92 assertOrPanic(x);92 expect(x);
93}93}
9494
95extern fn c_array([10]u8) void;95extern fn c_array([10]u8) void;
...@@ -100,7 +100,7 @@ test "C ABI array" {...@@ -100,7 +100,7 @@ test "C ABI array" {
100}100}
101101
102export fn zig_array(x: [10]u8) void {102export fn zig_array(x: [10]u8) void {
103 assertOrPanic(std.mem.eql(u8, x, "1234567890"));103 expect(std.mem.eql(u8, x, "1234567890"));
104}104}
105105
106const BigStruct = extern struct {106const BigStruct = extern struct {
...@@ -124,11 +124,11 @@ test "C ABI big struct" {...@@ -124,11 +124,11 @@ test "C ABI big struct" {
124}124}
125125
126export fn zig_big_struct(x: BigStruct) void {126export fn zig_big_struct(x: BigStruct) void {
127 assertOrPanic(x.a == 1);127 expect(x.a == 1);
128 assertOrPanic(x.b == 2);128 expect(x.b == 2);
129 assertOrPanic(x.c == 3);129 expect(x.c == 3);
130 assertOrPanic(x.d == 4);130 expect(x.d == 4);
131 assertOrPanic(x.e == 5);131 expect(x.e == 5);
132}132}
133133
134const BigUnion = extern union {134const BigUnion = extern union {
...@@ -150,11 +150,11 @@ test "C ABI big union" {...@@ -150,11 +150,11 @@ test "C ABI big union" {
150}150}
151151
152export fn zig_big_union(x: BigUnion) void {152export fn zig_big_union(x: BigUnion) void {
153 assertOrPanic(x.a.a == 1);153 expect(x.a.a == 1);
154 assertOrPanic(x.a.b == 2);154 expect(x.a.b == 2);
155 assertOrPanic(x.a.c == 3);155 expect(x.a.c == 3);
156 assertOrPanic(x.a.d == 4);156 expect(x.a.d == 4);
157 assertOrPanic(x.a.e == 5);157 expect(x.a.e == 5);
158}158}
159159
160const SmallStructInts = extern struct {160const SmallStructInts = extern struct {
...@@ -176,10 +176,10 @@ test "C ABI small struct of ints" {...@@ -176,10 +176,10 @@ test "C ABI small struct of ints" {
176}176}
177177
178export fn zig_small_struct_ints(x: SmallStructInts) void {178export fn zig_small_struct_ints(x: SmallStructInts) void {
179 assertOrPanic(x.a == 1);179 expect(x.a == 1);
180 assertOrPanic(x.b == 2);180 expect(x.b == 2);
181 assertOrPanic(x.c == 3);181 expect(x.c == 3);
182 assertOrPanic(x.d == 4);182 expect(x.d == 4);
183}183}
184184
185const SplitStructInt = extern struct {185const SplitStructInt = extern struct {
...@@ -199,9 +199,9 @@ test "C ABI split struct of ints" {...@@ -199,9 +199,9 @@ test "C ABI split struct of ints" {
199}199}
200200
201export fn zig_split_struct_ints(x: SplitStructInt) void {201export fn zig_split_struct_ints(x: SplitStructInt) void {
202 assertOrPanic(x.a == 1234);202 expect(x.a == 1234);
203 assertOrPanic(x.b == 100);203 expect(x.b == 100);
204 assertOrPanic(x.c == 1337);204 expect(x.c == 1337);
205}205}
206206
207extern fn c_big_struct_both(BigStruct) BigStruct;207extern fn c_big_struct_both(BigStruct) BigStruct;
...@@ -215,19 +215,19 @@ test "C ABI sret and byval together" {...@@ -215,19 +215,19 @@ test "C ABI sret and byval together" {
215 .e = 5,215 .e = 5,
216 };216 };
217 var y = c_big_struct_both(s);217 var y = c_big_struct_both(s);
218 assertOrPanic(y.a == 10);218 expect(y.a == 10);
219 assertOrPanic(y.b == 11);219 expect(y.b == 11);
220 assertOrPanic(y.c == 12);220 expect(y.c == 12);
221 assertOrPanic(y.d == 13);221 expect(y.d == 13);
222 assertOrPanic(y.e == 14);222 expect(y.e == 14);
223}223}
224224
225export fn zig_big_struct_both(x: BigStruct) BigStruct {225export fn zig_big_struct_both(x: BigStruct) BigStruct {
226 assertOrPanic(x.a == 30);226 expect(x.a == 30);
227 assertOrPanic(x.b == 31);227 expect(x.b == 31);
228 assertOrPanic(x.c == 32);228 expect(x.c == 32);
229 assertOrPanic(x.d == 33);229 expect(x.d == 33);
230 assertOrPanic(x.e == 34);230 expect(x.e == 34);
231 var s = BigStruct{231 var s = BigStruct{
232 .a = 20,232 .a = 20,
233 .b = 21,233 .b = 21,
test/standalone/brace_expansion/main.zig+3-6
...@@ -3,6 +3,7 @@ const io = std.io;...@@ -3,6 +3,7 @@ const io = std.io;
3const mem = std.mem;3const mem = std.mem;
4const debug = std.debug;4const debug = std.debug;
5const assert = debug.assert;5const assert = debug.assert;
6const testing = std.testing;
6const Buffer = std.Buffer;7const Buffer = std.Buffer;
7const ArrayList = std.ArrayList;8const ArrayList = std.ArrayList;
8const maxInt = std.math.maxInt;9const maxInt = std.math.maxInt;
...@@ -220,11 +221,7 @@ fn expectError(test_input: []const u8, expected_err: anyerror) void {...@@ -220,11 +221,7 @@ fn expectError(test_input: []const u8, expected_err: anyerror) void {
220 var output_buf = Buffer.initSize(global_allocator, 0) catch unreachable;221 var output_buf = Buffer.initSize(global_allocator, 0) catch unreachable;
221 defer output_buf.deinit();222 defer output_buf.deinit();
222223
223 if (expandString(test_input, &output_buf)) {224 testing.expectError(expected_err, expandString(test_input, &output_buf));
224 unreachable;
225 } else |err| {
226 assert(expected_err == err);
227 }
228}225}
229226
230test "valid inputs" {227test "valid inputs" {
...@@ -256,5 +253,5 @@ fn expectExpansion(test_input: []const u8, expected_result: []const u8) void {...@@ -256,5 +253,5 @@ fn expectExpansion(test_input: []const u8, expected_result: []const u8) void {
256253
257 expandString(test_input, &result) catch unreachable;254 expandString(test_input, &result) catch unreachable;
258255
259 assert(mem.eql(u8, result.toSlice(), expected_result));256 testing.expectEqualSlices(u8, expected_result, result.toSlice());
260}257}
test/standalone/issue_794/main.zig+2-2
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const c = @cImport(@cInclude("foo.h"));1const c = @cImport(@cInclude("foo.h"));
2const std = @import("std");2const std = @import("std");
3const assert = std.debug.assert;3const testing = std.testing;
44
5test "c import" {5test "c import" {
6 comptime assert(c.NUMBER == 1234);6 comptime testing.expect(c.NUMBER == 1234);
7}7}
test/tests.zig+15-1
...@@ -538,6 +538,7 @@ pub const CompileErrorContext = struct {...@@ -538,6 +538,7 @@ pub const CompileErrorContext = struct {
538 expected_errors: ArrayList([]const u8),538 expected_errors: ArrayList([]const u8),
539 link_libc: bool,539 link_libc: bool,
540 is_exe: bool,540 is_exe: bool,
541 is_test: bool,
541542
542 const SourceFile = struct {543 const SourceFile = struct {
543 filename: []const u8,544 filename: []const u8,
...@@ -596,7 +597,13 @@ pub const CompileErrorContext = struct {...@@ -596,7 +597,13 @@ pub const CompileErrorContext = struct {
596 var zig_args = ArrayList([]const u8).init(b.allocator);597 var zig_args = ArrayList([]const u8).init(b.allocator);
597 zig_args.append(b.zig_exe) catch unreachable;598 zig_args.append(b.zig_exe) catch unreachable;
598599
599 zig_args.append(if (self.case.is_exe) "build-exe" else "build-obj") catch unreachable;600 if (self.case.is_exe) {
601 try zig_args.append("build-exe");
602 } else if (self.case.is_test) {
603 try zig_args.append("test");
604 } else {
605 try zig_args.append("build-obj");
606 }
600 zig_args.append(b.pathFromRoot(root_src)) catch unreachable;607 zig_args.append(b.pathFromRoot(root_src)) catch unreachable;
601608
602 zig_args.append("--name") catch unreachable;609 zig_args.append("--name") catch unreachable;
...@@ -699,6 +706,7 @@ pub const CompileErrorContext = struct {...@@ -699,6 +706,7 @@ pub const CompileErrorContext = struct {
699 .expected_errors = ArrayList([]const u8).init(self.b.allocator),706 .expected_errors = ArrayList([]const u8).init(self.b.allocator),
700 .link_libc = false,707 .link_libc = false,
701 .is_exe = false,708 .is_exe = false,
709 .is_test = false,
702 };710 };
703711
704 tc.addSourceFile(".tmp_source.zig", source);712 tc.addSourceFile(".tmp_source.zig", source);
...@@ -726,6 +734,12 @@ pub const CompileErrorContext = struct {...@@ -726,6 +734,12 @@ pub const CompileErrorContext = struct {
726 self.addCase(tc);734 self.addCase(tc);
727 }735 }
728736
737 pub fn addTest(self: *CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) void {
738 const tc = self.create(name, source, expected_lines);
739 tc.is_test = true;
740 self.addCase(tc);
741 }
742
729 pub fn addCase(self: *CompileErrorContext, case: *const TestCase) void {743 pub fn addCase(self: *CompileErrorContext, case: *const TestCase) void {
730 const b = self.b;744 const b = self.b;
731745