Commit fd77f2cfed
Changed files (252)
lib
std
compress
crypto
pcurves
io
math
complex
net
special
compiler_rt
init-lib
src
valgrind
lib/std/atomic/bool.zig
@@ -47,9 +47,9 @@ pub const Bool = extern struct {
test "std.atomic.Bool" {
var a = Bool.init(false);
- testing.expectEqual(false, a.xchg(false, .SeqCst));
- testing.expectEqual(false, a.load(.SeqCst));
+ try testing.expectEqual(false, a.xchg(false, .SeqCst));
+ try testing.expectEqual(false, a.load(.SeqCst));
a.store(true, .SeqCst);
- testing.expectEqual(true, a.xchg(false, .SeqCst));
- testing.expectEqual(false, a.load(.SeqCst));
+ try testing.expectEqual(true, a.xchg(false, .SeqCst));
+ try testing.expectEqual(false, a.load(.SeqCst));
}
lib/std/atomic/int.zig
@@ -81,12 +81,12 @@ pub fn Int(comptime T: type) type {
test "std.atomic.Int" {
var a = Int(u8).init(0);
- testing.expectEqual(@as(u8, 0), a.incr());
- testing.expectEqual(@as(u8, 1), a.load(.SeqCst));
+ try testing.expectEqual(@as(u8, 0), a.incr());
+ try testing.expectEqual(@as(u8, 1), a.load(.SeqCst));
a.store(42, .SeqCst);
- testing.expectEqual(@as(u8, 42), a.decr());
- testing.expectEqual(@as(u8, 41), a.xchg(100));
- testing.expectEqual(@as(u8, 100), a.fetchAdd(5));
- testing.expectEqual(@as(u8, 105), a.get());
+ try testing.expectEqual(@as(u8, 42), a.decr());
+ try testing.expectEqual(@as(u8, 41), a.xchg(100));
+ try testing.expectEqual(@as(u8, 100), a.fetchAdd(5));
+ try testing.expectEqual(@as(u8, 105), a.get());
a.set(200);
}
lib/std/atomic/queue.zig
@@ -195,24 +195,24 @@ test "std.atomic.Queue" {
};
if (builtin.single_threaded) {
- expect(context.queue.isEmpty());
+ try expect(context.queue.isEmpty());
{
var i: usize = 0;
while (i < put_thread_count) : (i += 1) {
- expect(startPuts(&context) == 0);
+ try expect(startPuts(&context) == 0);
}
}
- expect(!context.queue.isEmpty());
+ try expect(!context.queue.isEmpty());
context.puts_done = true;
{
var i: usize = 0;
while (i < put_thread_count) : (i += 1) {
- expect(startGets(&context) == 0);
+ try expect(startGets(&context) == 0);
}
}
- expect(context.queue.isEmpty());
+ try expect(context.queue.isEmpty());
} else {
- expect(context.queue.isEmpty());
+ try expect(context.queue.isEmpty());
var putters: [put_thread_count]*std.Thread = undefined;
for (putters) |*t| {
@@ -229,7 +229,7 @@ test "std.atomic.Queue" {
for (getters) |t|
t.wait();
- expect(context.queue.isEmpty());
+ try expect(context.queue.isEmpty());
}
if (context.put_sum != context.get_sum) {
@@ -279,7 +279,7 @@ fn startGets(ctx: *Context) u8 {
test "std.atomic.Queue single-threaded" {
var queue = Queue(i32).init();
- expect(queue.isEmpty());
+ try expect(queue.isEmpty());
var node_0 = Queue(i32).Node{
.data = 0,
@@ -287,7 +287,7 @@ test "std.atomic.Queue single-threaded" {
.prev = undefined,
};
queue.put(&node_0);
- expect(!queue.isEmpty());
+ try expect(!queue.isEmpty());
var node_1 = Queue(i32).Node{
.data = 1,
@@ -295,10 +295,10 @@ test "std.atomic.Queue single-threaded" {
.prev = undefined,
};
queue.put(&node_1);
- expect(!queue.isEmpty());
+ try expect(!queue.isEmpty());
- expect(queue.get().?.data == 0);
- expect(!queue.isEmpty());
+ try expect(queue.get().?.data == 0);
+ try expect(!queue.isEmpty());
var node_2 = Queue(i32).Node{
.data = 2,
@@ -306,7 +306,7 @@ test "std.atomic.Queue single-threaded" {
.prev = undefined,
};
queue.put(&node_2);
- expect(!queue.isEmpty());
+ try expect(!queue.isEmpty());
var node_3 = Queue(i32).Node{
.data = 3,
@@ -314,13 +314,13 @@ test "std.atomic.Queue single-threaded" {
.prev = undefined,
};
queue.put(&node_3);
- expect(!queue.isEmpty());
+ try expect(!queue.isEmpty());
- expect(queue.get().?.data == 1);
- expect(!queue.isEmpty());
+ try expect(queue.get().?.data == 1);
+ try expect(!queue.isEmpty());
- expect(queue.get().?.data == 2);
- expect(!queue.isEmpty());
+ try expect(queue.get().?.data == 2);
+ try expect(!queue.isEmpty());
var node_4 = Queue(i32).Node{
.data = 4,
@@ -328,17 +328,17 @@ test "std.atomic.Queue single-threaded" {
.prev = undefined,
};
queue.put(&node_4);
- expect(!queue.isEmpty());
+ try expect(!queue.isEmpty());
- expect(queue.get().?.data == 3);
+ try expect(queue.get().?.data == 3);
node_3.next = null;
- expect(!queue.isEmpty());
+ try expect(!queue.isEmpty());
- expect(queue.get().?.data == 4);
- expect(queue.isEmpty());
+ try expect(queue.get().?.data == 4);
+ try expect(queue.isEmpty());
- expect(queue.get() == null);
- expect(queue.isEmpty());
+ try expect(queue.get() == null);
+ try expect(queue.isEmpty());
}
test "std.atomic.Queue dump" {
@@ -352,7 +352,7 @@ test "std.atomic.Queue dump" {
// Test empty stream
fbs.reset();
try queue.dumpToStream(fbs.writer());
- expect(mem.eql(u8, buffer[0..fbs.pos],
+ try expect(mem.eql(u8, buffer[0..fbs.pos],
\\head: (null)
\\tail: (null)
\\
@@ -376,7 +376,7 @@ test "std.atomic.Queue dump" {
\\ (null)
\\
, .{ @ptrToInt(queue.head), @ptrToInt(queue.tail) });
- expect(mem.eql(u8, buffer[0..fbs.pos], expected));
+ try expect(mem.eql(u8, buffer[0..fbs.pos], expected));
// Test a stream with two elements
var node_1 = Queue(i32).Node{
@@ -397,5 +397,5 @@ test "std.atomic.Queue dump" {
\\ (null)
\\
, .{ @ptrToInt(queue.head), @ptrToInt(queue.head.?.next), @ptrToInt(queue.tail) });
- expect(mem.eql(u8, buffer[0..fbs.pos], expected));
+ try expect(mem.eql(u8, buffer[0..fbs.pos], expected));
}
lib/std/atomic/stack.zig
@@ -110,14 +110,14 @@ test "std.atomic.stack" {
{
var i: usize = 0;
while (i < put_thread_count) : (i += 1) {
- expect(startPuts(&context) == 0);
+ try expect(startPuts(&context) == 0);
}
}
context.puts_done = true;
{
var i: usize = 0;
while (i < put_thread_count) : (i += 1) {
- expect(startGets(&context) == 0);
+ try expect(startGets(&context) == 0);
}
}
} else {
lib/std/c/tokenizer.zig
@@ -1310,7 +1310,7 @@ pub const Tokenizer = struct {
};
test "operators" {
- expectTokens(
+ try expectTokens(
\\ ! != | || |= = ==
\\ ( ) { } [ ] . .. ...
\\ ^ ^= + ++ += - -- -=
@@ -1379,7 +1379,7 @@ test "operators" {
}
test "keywords" {
- expectTokens(
+ try expectTokens(
\\auto break case char const continue default do
\\double else enum extern float for goto if int
\\long register return short signed sizeof static
@@ -1442,7 +1442,7 @@ test "keywords" {
}
test "preprocessor keywords" {
- expectTokens(
+ try expectTokens(
\\#include <test>
\\#define #include <1
\\#ifdef
@@ -1478,7 +1478,7 @@ test "preprocessor keywords" {
}
test "line continuation" {
- expectTokens(
+ try expectTokens(
\\#define foo \
\\ bar
\\"foo\
@@ -1509,7 +1509,7 @@ test "line continuation" {
}
test "string prefix" {
- expectTokens(
+ try expectTokens(
\\"foo"
\\u"foo"
\\u8"foo"
@@ -1543,7 +1543,7 @@ test "string prefix" {
}
test "num suffixes" {
- expectTokens(
+ try expectTokens(
\\ 1.0f 1.0L 1.0 .0 1.
\\ 0l 0lu 0ll 0llu 0
\\ 1u 1ul 1ull 1
@@ -1573,7 +1573,7 @@ test "num suffixes" {
});
}
-fn expectTokens(source: []const u8, expected_tokens: []const Token.Id) void {
+fn expectTokens(source: []const u8, expected_tokens: []const Token.Id) !void {
var tokenizer = Tokenizer{
.buffer = source,
};
@@ -1584,5 +1584,5 @@ fn expectTokens(source: []const u8, expected_tokens: []const Token.Id) void {
}
}
const last_token = tokenizer.next();
- std.testing.expect(last_token.id == .Eof);
+ try std.testing.expect(last_token.id == .Eof);
}
lib/std/compress/deflate.zig
@@ -669,5 +669,5 @@ test "lengths overflow" {
var inflate = inflateStream(reader, &window);
var buf: [1]u8 = undefined;
- std.testing.expectError(error.InvalidLength, inflate.read(&buf));
+ try std.testing.expectError(error.InvalidLength, inflate.read(&buf));
}
lib/std/compress/gzip.zig
@@ -172,17 +172,17 @@ fn testReader(data: []const u8, comptime expected: []const u8) !void {
var hash: [32]u8 = undefined;
std.crypto.hash.sha2.Sha256.hash(buf, hash[0..], .{});
- assertEqual(expected, &hash);
+ try assertEqual(expected, &hash);
}
// Assert `expected` == `input` where `input` is a bytestring.
-pub fn assertEqual(comptime expected: []const u8, input: []const u8) void {
+pub fn assertEqual(comptime expected: []const u8, input: []const u8) !void {
var expected_bytes: [expected.len / 2]u8 = undefined;
for (expected_bytes) |*r, i| {
r.* = std.fmt.parseInt(u8, expected[2 * i .. 2 * i + 2], 16) catch unreachable;
}
- testing.expectEqualSlices(u8, &expected_bytes, input);
+ try testing.expectEqualSlices(u8, &expected_bytes, input);
}
// All the test cases are obtained by compressing the RFC1952 text
@@ -198,12 +198,12 @@ test "compressed data" {
test "sanity checks" {
// Truncated header
- testing.expectError(
+ try testing.expectError(
error.EndOfStream,
testReader(&[_]u8{ 0x1f, 0x8B }, ""),
);
// Wrong CM
- testing.expectError(
+ try testing.expectError(
error.InvalidCompression,
testReader(&[_]u8{
0x1f, 0x8b, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -211,7 +211,7 @@ test "sanity checks" {
}, ""),
);
// Wrong checksum
- testing.expectError(
+ try testing.expectError(
error.WrongChecksum,
testReader(&[_]u8{
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -220,7 +220,7 @@ test "sanity checks" {
}, ""),
);
// Truncated checksum
- testing.expectError(
+ try testing.expectError(
error.EndOfStream,
testReader(&[_]u8{
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -228,7 +228,7 @@ test "sanity checks" {
}, ""),
);
// Wrong initial size
- testing.expectError(
+ try testing.expectError(
error.CorruptedData,
testReader(&[_]u8{
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -237,7 +237,7 @@ test "sanity checks" {
}, ""),
);
// Truncated initial size field
- testing.expectError(
+ try testing.expectError(
error.EndOfStream,
testReader(&[_]u8{
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
lib/std/compress/zlib.zig
@@ -109,17 +109,17 @@ fn testReader(data: []const u8, comptime expected: []const u8) !void {
var hash: [32]u8 = undefined;
std.crypto.hash.sha2.Sha256.hash(buf, hash[0..], .{});
- assertEqual(expected, &hash);
+ try assertEqual(expected, &hash);
}
// Assert `expected` == `input` where `input` is a bytestring.
-pub fn assertEqual(comptime expected: []const u8, input: []const u8) void {
+pub fn assertEqual(comptime expected: []const u8, input: []const u8) !void {
var expected_bytes: [expected.len / 2]u8 = undefined;
for (expected_bytes) |*r, i| {
r.* = std.fmt.parseInt(u8, expected[2 * i .. 2 * i + 2], 16) catch unreachable;
}
- testing.expectEqualSlices(u8, &expected_bytes, input);
+ try testing.expectEqualSlices(u8, &expected_bytes, input);
}
// All the test cases are obtained by compressing the RFC1950 text
@@ -159,32 +159,32 @@ test "don't read past deflate stream's end" {
test "sanity checks" {
// Truncated header
- testing.expectError(
+ try testing.expectError(
error.EndOfStream,
testReader(&[_]u8{0x78}, ""),
);
// Failed FCHECK check
- testing.expectError(
+ try testing.expectError(
error.BadHeader,
testReader(&[_]u8{ 0x78, 0x9D }, ""),
);
// Wrong CM
- testing.expectError(
+ try testing.expectError(
error.InvalidCompression,
testReader(&[_]u8{ 0x79, 0x94 }, ""),
);
// Wrong CINFO
- testing.expectError(
+ try testing.expectError(
error.InvalidWindowSize,
testReader(&[_]u8{ 0x88, 0x98 }, ""),
);
// Wrong checksum
- testing.expectError(
+ try testing.expectError(
error.WrongChecksum,
testReader(&[_]u8{ 0x78, 0xda, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00 }, ""),
);
// Truncated checksum
- testing.expectError(
+ try testing.expectError(
error.EndOfStream,
testReader(&[_]u8{ 0x78, 0xda, 0x03, 0x00, 0x00 }, ""),
);
lib/std/crypto/25519/curve25519.zig
@@ -120,13 +120,13 @@ test "curve25519" {
const p = try Curve25519.basePoint.clampedMul(s);
try p.rejectIdentity();
var buf: [128]u8 = undefined;
- std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&p.toBytes())}), "E6F2A4D1C28EE5C7AD0329268255A468AD407D2672824C0C0EB30EA6EF450145");
+ try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&p.toBytes())}), "E6F2A4D1C28EE5C7AD0329268255A468AD407D2672824C0C0EB30EA6EF450145");
const q = try p.clampedMul(s);
- std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&q.toBytes())}), "3614E119FFE55EC55B87D6B19971A9F4CBC78EFE80BEC55B96392BABCC712537");
+ try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&q.toBytes())}), "3614E119FFE55EC55B87D6B19971A9F4CBC78EFE80BEC55B96392BABCC712537");
try Curve25519.rejectNonCanonical(s);
s[31] |= 0x80;
- std.testing.expectError(error.NonCanonical, Curve25519.rejectNonCanonical(s));
+ try std.testing.expectError(error.NonCanonical, Curve25519.rejectNonCanonical(s));
}
test "curve25519 small order check" {
@@ -155,13 +155,13 @@ test "curve25519 small order check" {
},
};
for (small_order_ss) |small_order_s| {
- std.testing.expectError(error.WeakPublicKey, Curve25519.fromBytes(small_order_s).mul(s));
+ try std.testing.expectError(error.WeakPublicKey, Curve25519.fromBytes(small_order_s).mul(s));
var extra = small_order_s;
extra[31] ^= 0x80;
- std.testing.expectError(error.WeakPublicKey, Curve25519.fromBytes(extra).mul(s));
+ try std.testing.expectError(error.WeakPublicKey, Curve25519.fromBytes(extra).mul(s));
var valid = small_order_s;
valid[31] = 0x40;
s[0] = 0;
- std.testing.expectError(error.IdentityElement, Curve25519.fromBytes(valid).mul(s));
+ try std.testing.expectError(error.IdentityElement, Curve25519.fromBytes(valid).mul(s));
}
}
lib/std/crypto/25519/ed25519.zig
@@ -219,8 +219,8 @@ test "ed25519 key pair creation" {
_ = try fmt.hexToBytes(seed[0..], "8052030376d47112be7f73ed7a019293dd12ad910b654455798b4667d73de166");
const key_pair = try Ed25519.KeyPair.create(seed);
var buf: [256]u8 = undefined;
- std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&key_pair.secret_key)}), "8052030376D47112BE7F73ED7A019293DD12AD910B654455798B4667D73DE1662D6F7455D97B4A3A10D7293909D1A4F2058CB9A370E43FA8154BB280DB839083");
- std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&key_pair.public_key)}), "2D6F7455D97B4A3A10D7293909D1A4F2058CB9A370E43FA8154BB280DB839083");
+ try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&key_pair.secret_key)}), "8052030376D47112BE7F73ED7A019293DD12AD910B654455798B4667D73DE1662D6F7455D97B4A3A10D7293909D1A4F2058CB9A370E43FA8154BB280DB839083");
+ try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&key_pair.public_key)}), "2D6F7455D97B4A3A10D7293909D1A4F2058CB9A370E43FA8154BB280DB839083");
}
test "ed25519 signature" {
@@ -230,9 +230,9 @@ test "ed25519 signature" {
const sig = try Ed25519.sign("test", key_pair, null);
var buf: [128]u8 = undefined;
- std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&sig)}), "10A442B4A80CC4225B154F43BEF28D2472CA80221951262EB8E0DF9091575E2687CC486E77263C3418C757522D54F84B0359236ABBBD4ACD20DC297FDCA66808");
+ try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&sig)}), "10A442B4A80CC4225B154F43BEF28D2472CA80221951262EB8E0DF9091575E2687CC486E77263C3418C757522D54F84B0359236ABBBD4ACD20DC297FDCA66808");
try Ed25519.verify(sig, "test", key_pair.public_key);
- std.testing.expectError(error.SignatureVerificationFailed, Ed25519.verify(sig, "TEST", key_pair.public_key));
+ try std.testing.expectError(error.SignatureVerificationFailed, Ed25519.verify(sig, "TEST", key_pair.public_key));
}
test "ed25519 batch verification" {
@@ -260,7 +260,7 @@ test "ed25519 batch verification" {
try Ed25519.verifyBatch(2, signature_batch);
signature_batch[1].sig = sig1;
- std.testing.expectError(error.SignatureVerificationFailed, Ed25519.verifyBatch(signature_batch.len, signature_batch));
+ try std.testing.expectError(error.SignatureVerificationFailed, Ed25519.verifyBatch(signature_batch.len, signature_batch));
}
}
@@ -354,7 +354,7 @@ test "ed25519 test vectors" {
var sig: [64]u8 = undefined;
_ = try fmt.hexToBytes(&sig, entry.sig_hex);
if (entry.expected) |error_type| {
- std.testing.expectError(error_type, Ed25519.verify(sig, &msg, public_key));
+ try std.testing.expectError(error_type, Ed25519.verify(sig, &msg, public_key));
} else {
try Ed25519.verify(sig, &msg, public_key);
}
lib/std/crypto/25519/edwards25519.zig
@@ -491,7 +491,7 @@ test "edwards25519 packing/unpacking" {
var b = Edwards25519.basePoint;
const pk = try b.mul(s);
var buf: [128]u8 = undefined;
- std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&pk.toBytes())}), "074BC7E0FCBD587FDBC0969444245FADC562809C8F6E97E949AF62484B5B81A6");
+ try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&pk.toBytes())}), "074BC7E0FCBD587FDBC0969444245FADC562809C8F6E97E949AF62484B5B81A6");
const small_order_ss: [7][32]u8 = .{
.{
@@ -518,7 +518,7 @@ test "edwards25519 packing/unpacking" {
};
for (small_order_ss) |small_order_s| {
const small_p = try Edwards25519.fromBytes(small_order_s);
- std.testing.expectError(error.WeakPublicKey, small_p.mul(s));
+ try std.testing.expectError(error.WeakPublicKey, small_p.mul(s));
}
}
@@ -531,26 +531,26 @@ test "edwards25519 point addition/substraction" {
const q = try Edwards25519.basePoint.clampedMul(s2);
const r = p.add(q).add(q).sub(q).sub(q);
try r.rejectIdentity();
- std.testing.expectError(error.IdentityElement, r.sub(p).rejectIdentity());
- std.testing.expectError(error.IdentityElement, p.sub(p).rejectIdentity());
- std.testing.expectError(error.IdentityElement, p.sub(q).add(q).sub(p).rejectIdentity());
+ try std.testing.expectError(error.IdentityElement, r.sub(p).rejectIdentity());
+ try std.testing.expectError(error.IdentityElement, p.sub(p).rejectIdentity());
+ try std.testing.expectError(error.IdentityElement, p.sub(q).add(q).sub(p).rejectIdentity());
}
test "edwards25519 uniform-to-point" {
var r = [32]u8{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 };
var p = Edwards25519.fromUniform(r);
- htest.assertEqual("0691eee3cf70a0056df6bfa03120635636581b5c4ea571dfc680f78c7e0b4137", p.toBytes()[0..]);
+ try htest.assertEqual("0691eee3cf70a0056df6bfa03120635636581b5c4ea571dfc680f78c7e0b4137", p.toBytes()[0..]);
r[31] = 0xff;
p = Edwards25519.fromUniform(r);
- htest.assertEqual("f70718e68ef42d90ca1d936bb2d7e159be6c01d8095d39bd70487c82fe5c973a", p.toBytes()[0..]);
+ try htest.assertEqual("f70718e68ef42d90ca1d936bb2d7e159be6c01d8095d39bd70487c82fe5c973a", p.toBytes()[0..]);
}
// Test vectors from draft-irtf-cfrg-hash-to-curve-10
test "edwards25519 hash-to-curve operation" {
var p = Edwards25519.fromString(true, "QUUX-V01-CS02-with-edwards25519_XMD:SHA-512_ELL2_RO_", "abc");
- htest.assertEqual("31558a26887f23fb8218f143e69d5f0af2e7831130bd5b432ef23883b895831a", p.toBytes()[0..]);
+ try htest.assertEqual("31558a26887f23fb8218f143e69d5f0af2e7831130bd5b432ef23883b895831a", p.toBytes()[0..]);
p = Edwards25519.fromString(false, "QUUX-V01-CS02-with-edwards25519_XMD:SHA-512_ELL2_NU_", "abc");
- htest.assertEqual("42fa27c8f5a1ae0aa38bb59d5938e5145622ba5dedd11d11736fa2f9502d73e7", p.toBytes()[0..]);
+ try htest.assertEqual("42fa27c8f5a1ae0aa38bb59d5938e5145622ba5dedd11d11736fa2f9502d73e7", p.toBytes()[0..]);
}
lib/std/crypto/25519/ristretto255.zig
@@ -175,21 +175,21 @@ pub const Ristretto255 = struct {
test "ristretto255" {
const p = Ristretto255.basePoint;
var buf: [256]u8 = undefined;
- std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&p.toBytes())}), "E2F2AE0A6ABC4E71A884A961C500515F58E30B6AA582DD8DB6A65945E08D2D76");
+ try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&p.toBytes())}), "E2F2AE0A6ABC4E71A884A961C500515F58E30B6AA582DD8DB6A65945E08D2D76");
var r: [Ristretto255.encoded_length]u8 = undefined;
_ = try fmt.hexToBytes(r[0..], "6a493210f7499cd17fecb510ae0cea23a110e8d5b901f8acadd3095c73a3b919");
var q = try Ristretto255.fromBytes(r);
q = q.dbl().add(p);
- std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&q.toBytes())}), "E882B131016B52C1D3337080187CF768423EFCCBB517BB495AB812C4160FF44E");
+ try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&q.toBytes())}), "E882B131016B52C1D3337080187CF768423EFCCBB517BB495AB812C4160FF44E");
const s = [_]u8{15} ++ [_]u8{0} ** 31;
const w = try p.mul(s);
- std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&w.toBytes())}), "E0C418F7C8D9C4CDD7395B93EA124F3AD99021BB681DFC3302A9D99A2E53E64E");
+ try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&w.toBytes())}), "E0C418F7C8D9C4CDD7395B93EA124F3AD99021BB681DFC3302A9D99A2E53E64E");
- std.testing.expect(p.dbl().dbl().dbl().dbl().equivalent(w.add(p)));
+ try std.testing.expect(p.dbl().dbl().dbl().dbl().equivalent(w.add(p)));
const h = [_]u8{69} ** 32 ++ [_]u8{42} ** 32;
const ph = Ristretto255.fromUniform(h);
- std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&ph.toBytes())}), "DCCA54E037A4311EFBEEF413ACD21D35276518970B7A61DC88F8587B493D5E19");
+ try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&ph.toBytes())}), "DCCA54E037A4311EFBEEF413ACD21D35276518970B7A61DC88F8587B493D5E19");
}
lib/std/crypto/25519/scalar.zig
@@ -773,15 +773,15 @@ test "scalar25519" {
var y = x.toBytes();
try rejectNonCanonical(y);
var buf: [128]u8 = undefined;
- std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&y)}), "1E979B917937F3DE71D18077F961F6CEFF01030405060708010203040506070F");
+ try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&y)}), "1E979B917937F3DE71D18077F961F6CEFF01030405060708010203040506070F");
const reduced = reduce(field_size);
- std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&reduced)}), "0000000000000000000000000000000000000000000000000000000000000000");
+ try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&reduced)}), "0000000000000000000000000000000000000000000000000000000000000000");
}
test "non-canonical scalar25519" {
const too_targe: [32]u8 = .{ 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10 };
- std.testing.expectError(error.NonCanonical, rejectNonCanonical(too_targe));
+ try std.testing.expectError(error.NonCanonical, rejectNonCanonical(too_targe));
}
test "mulAdd overflow check" {
@@ -790,5 +790,5 @@ test "mulAdd overflow check" {
const c: [32]u8 = [_]u8{0xff} ** 32;
const x = mulAdd(a, b, c);
var buf: [128]u8 = undefined;
- std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&x)}), "D14DF91389432C25AD60FF9791B9FD1D67BEF517D273ECCE3D9A307C1B419903");
+ try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&x)}), "D14DF91389432C25AD60FF9791B9FD1D67BEF517D273ECCE3D9A307C1B419903");
}
lib/std/crypto/25519/x25519.zig
@@ -92,7 +92,7 @@ test "x25519 public key calculation from secret key" {
_ = try fmt.hexToBytes(sk[0..], "8052030376d47112be7f73ed7a019293dd12ad910b654455798b4667d73de166");
_ = try fmt.hexToBytes(pk_expected[0..], "f1814f0e8ff1043d8a44d25babff3cedcae6c22c3edaa48f857ae70de2baae50");
const pk_calculated = try X25519.recoverPublicKey(sk);
- std.testing.expectEqual(pk_calculated, pk_expected);
+ try std.testing.expectEqual(pk_calculated, pk_expected);
}
test "x25519 rfc7748 vector1" {
@@ -102,7 +102,7 @@ test "x25519 rfc7748 vector1" {
const expected_output = [32]u8{ 0xc3, 0xda, 0x55, 0x37, 0x9d, 0xe9, 0xc6, 0x90, 0x8e, 0x94, 0xea, 0x4d, 0xf2, 0x8d, 0x08, 0x4f, 0x32, 0xec, 0xcf, 0x03, 0x49, 0x1c, 0x71, 0xf7, 0x54, 0xb4, 0x07, 0x55, 0x77, 0xa2, 0x85, 0x52 };
const output = try X25519.scalarmult(secret_key, public_key);
- std.testing.expectEqual(output, expected_output);
+ try std.testing.expectEqual(output, expected_output);
}
test "x25519 rfc7748 vector2" {
@@ -112,7 +112,7 @@ test "x25519 rfc7748 vector2" {
const expected_output = [32]u8{ 0x95, 0xcb, 0xde, 0x94, 0x76, 0xe8, 0x90, 0x7d, 0x7a, 0xad, 0xe4, 0x5c, 0xb4, 0xb8, 0x73, 0xf8, 0x8b, 0x59, 0x5a, 0x68, 0x79, 0x9f, 0xa1, 0x52, 0xe6, 0xf8, 0xf7, 0x64, 0x7a, 0xac, 0x79, 0x57 };
const output = try X25519.scalarmult(secret_key, public_key);
- std.testing.expectEqual(output, expected_output);
+ try std.testing.expectEqual(output, expected_output);
}
test "x25519 rfc7748 one iteration" {
@@ -129,7 +129,7 @@ test "x25519 rfc7748 one iteration" {
mem.copy(u8, k[0..], output[0..]);
}
- std.testing.expectEqual(k, expected_output);
+ try std.testing.expectEqual(k, expected_output);
}
test "x25519 rfc7748 1,000 iterations" {
@@ -151,7 +151,7 @@ test "x25519 rfc7748 1,000 iterations" {
mem.copy(u8, k[0..], output[0..]);
}
- std.testing.expectEqual(k, expected_output);
+ try std.testing.expectEqual(k, expected_output);
}
test "x25519 rfc7748 1,000,000 iterations" {
@@ -172,12 +172,12 @@ test "x25519 rfc7748 1,000,000 iterations" {
mem.copy(u8, k[0..], output[0..]);
}
- std.testing.expectEqual(k[0..], expected_output);
+ try std.testing.expectEqual(k[0..], expected_output);
}
test "edwards25519 -> curve25519 map" {
const ed_kp = try crypto.sign.Ed25519.KeyPair.create([_]u8{0x42} ** 32);
const mont_kp = try X25519.KeyPair.fromEd25519(ed_kp);
- htest.assertEqual("90e7595fc89e52fdfddce9c6a43d74dbf6047025ee0462d2d172e8b6a2841d6e", &mont_kp.secret_key);
- htest.assertEqual("cc4f2cdb695dd766f34118eb67b98652fed1d8bc49c330b119bbfa8a64989378", &mont_kp.public_key);
+ try htest.assertEqual("90e7595fc89e52fdfddce9c6a43d74dbf6047025ee0462d2d172e8b6a2841d6e", &mont_kp.secret_key);
+ try htest.assertEqual("cc4f2cdb695dd766f34118eb67b98652fed1d8bc49c330b119bbfa8a64989378", &mont_kp.public_key);
}
lib/std/crypto/pcurves/tests.zig
@@ -17,7 +17,7 @@ test "p256 ECDH key exchange" {
const dhB = try P256.basePoint.mul(dhb, .Little);
const shareda = try dhA.mul(dhb, .Little);
const sharedb = try dhB.mul(dha, .Little);
- testing.expect(shareda.equivalent(sharedb));
+ try testing.expect(shareda.equivalent(sharedb));
}
test "p256 point from affine coordinates" {
@@ -28,7 +28,7 @@ test "p256 point from affine coordinates" {
var ys: [32]u8 = undefined;
_ = try fmt.hexToBytes(&ys, yh);
var p = try P256.fromSerializedAffineCoordinates(xs, ys, .Big);
- testing.expect(p.equivalent(P256.basePoint));
+ try testing.expect(p.equivalent(P256.basePoint));
}
test "p256 test vectors" {
@@ -50,7 +50,7 @@ test "p256 test vectors" {
p = p.add(P256.basePoint);
var xs: [32]u8 = undefined;
_ = try fmt.hexToBytes(&xs, xh);
- testing.expectEqualSlices(u8, &x.toBytes(.Big), &xs);
+ try testing.expectEqualSlices(u8, &x.toBytes(.Big), &xs);
}
}
@@ -67,7 +67,7 @@ test "p256 test vectors - doubling" {
p = p.dbl();
var xs: [32]u8 = undefined;
_ = try fmt.hexToBytes(&xs, xh);
- testing.expectEqualSlices(u8, &x.toBytes(.Big), &xs);
+ try testing.expectEqualSlices(u8, &x.toBytes(.Big), &xs);
}
}
@@ -75,29 +75,29 @@ test "p256 compressed sec1 encoding/decoding" {
const p = P256.random();
const s = p.toCompressedSec1();
const q = try P256.fromSec1(&s);
- testing.expect(p.equivalent(q));
+ try testing.expect(p.equivalent(q));
}
test "p256 uncompressed sec1 encoding/decoding" {
const p = P256.random();
const s = p.toUncompressedSec1();
const q = try P256.fromSec1(&s);
- testing.expect(p.equivalent(q));
+ try testing.expect(p.equivalent(q));
}
test "p256 public key is the neutral element" {
const n = P256.scalar.Scalar.zero.toBytes(.Little);
const p = P256.random();
- testing.expectError(error.IdentityElement, p.mul(n, .Little));
+ try testing.expectError(error.IdentityElement, p.mul(n, .Little));
}
test "p256 public key is the neutral element (public verification)" {
const n = P256.scalar.Scalar.zero.toBytes(.Little);
const p = P256.random();
- testing.expectError(error.IdentityElement, p.mulPublic(n, .Little));
+ try testing.expectError(error.IdentityElement, p.mulPublic(n, .Little));
}
test "p256 field element non-canonical encoding" {
const s = [_]u8{0xff} ** 32;
- testing.expectError(error.NonCanonical, P256.Fe.fromBytes(s, .Little));
+ try testing.expectError(error.NonCanonical, P256.Fe.fromBytes(s, .Little));
}
lib/std/crypto/aegis.zig
@@ -352,16 +352,16 @@ test "Aegis128L test vector 1" {
Aegis128L.encrypt(&c, &tag, &m, &ad, nonce, key);
try Aegis128L.decrypt(&m2, &c, tag, &ad, nonce, key);
- testing.expectEqualSlices(u8, &m, &m2);
+ try testing.expectEqualSlices(u8, &m, &m2);
- htest.assertEqual("79d94593d8c2119d7e8fd9b8fc77845c5c077a05b2528b6ac54b563aed8efe84", &c);
- htest.assertEqual("cc6f3372f6aa1bb82388d695c3962d9a", &tag);
+ try htest.assertEqual("79d94593d8c2119d7e8fd9b8fc77845c5c077a05b2528b6ac54b563aed8efe84", &c);
+ try htest.assertEqual("cc6f3372f6aa1bb82388d695c3962d9a", &tag);
c[0] +%= 1;
- testing.expectError(error.AuthenticationFailed, Aegis128L.decrypt(&m2, &c, tag, &ad, nonce, key));
+ try testing.expectError(error.AuthenticationFailed, Aegis128L.decrypt(&m2, &c, tag, &ad, nonce, key));
c[0] -%= 1;
tag[0] +%= 1;
- testing.expectError(error.AuthenticationFailed, Aegis128L.decrypt(&m2, &c, tag, &ad, nonce, key));
+ try testing.expectError(error.AuthenticationFailed, Aegis128L.decrypt(&m2, &c, tag, &ad, nonce, key));
}
test "Aegis128L test vector 2" {
@@ -375,10 +375,10 @@ test "Aegis128L test vector 2" {
Aegis128L.encrypt(&c, &tag, &m, &ad, nonce, key);
try Aegis128L.decrypt(&m2, &c, tag, &ad, nonce, key);
- testing.expectEqualSlices(u8, &m, &m2);
+ try testing.expectEqualSlices(u8, &m, &m2);
- htest.assertEqual("41de9000a7b5e40e2d68bb64d99ebb19", &c);
- htest.assertEqual("f4d997cc9b94227ada4fe4165422b1c8", &tag);
+ try htest.assertEqual("41de9000a7b5e40e2d68bb64d99ebb19", &c);
+ try htest.assertEqual("f4d997cc9b94227ada4fe4165422b1c8", &tag);
}
test "Aegis128L test vector 3" {
@@ -392,9 +392,9 @@ test "Aegis128L test vector 3" {
Aegis128L.encrypt(&c, &tag, &m, &ad, nonce, key);
try Aegis128L.decrypt(&m2, &c, tag, &ad, nonce, key);
- testing.expectEqualSlices(u8, &m, &m2);
+ try testing.expectEqualSlices(u8, &m, &m2);
- htest.assertEqual("83cc600dc4e3e7e62d4055826174f149", &tag);
+ try htest.assertEqual("83cc600dc4e3e7e62d4055826174f149", &tag);
}
test "Aegis256 test vector 1" {
@@ -408,16 +408,16 @@ test "Aegis256 test vector 1" {
Aegis256.encrypt(&c, &tag, &m, &ad, nonce, key);
try Aegis256.decrypt(&m2, &c, tag, &ad, nonce, key);
- testing.expectEqualSlices(u8, &m, &m2);
+ try testing.expectEqualSlices(u8, &m, &m2);
- htest.assertEqual("f373079ed84b2709faee373584585d60accd191db310ef5d8b11833df9dec711", &c);
- htest.assertEqual("8d86f91ee606e9ff26a01b64ccbdd91d", &tag);
+ try htest.assertEqual("f373079ed84b2709faee373584585d60accd191db310ef5d8b11833df9dec711", &c);
+ try htest.assertEqual("8d86f91ee606e9ff26a01b64ccbdd91d", &tag);
c[0] +%= 1;
- testing.expectError(error.AuthenticationFailed, Aegis256.decrypt(&m2, &c, tag, &ad, nonce, key));
+ try testing.expectError(error.AuthenticationFailed, Aegis256.decrypt(&m2, &c, tag, &ad, nonce, key));
c[0] -%= 1;
tag[0] +%= 1;
- testing.expectError(error.AuthenticationFailed, Aegis256.decrypt(&m2, &c, tag, &ad, nonce, key));
+ try testing.expectError(error.AuthenticationFailed, Aegis256.decrypt(&m2, &c, tag, &ad, nonce, key));
}
test "Aegis256 test vector 2" {
@@ -431,10 +431,10 @@ test "Aegis256 test vector 2" {
Aegis256.encrypt(&c, &tag, &m, &ad, nonce, key);
try Aegis256.decrypt(&m2, &c, tag, &ad, nonce, key);
- testing.expectEqualSlices(u8, &m, &m2);
+ try testing.expectEqualSlices(u8, &m, &m2);
- htest.assertEqual("b98f03a947807713d75a4fff9fc277a6", &c);
- htest.assertEqual("478f3b50dc478ef7d5cf2d0f7cc13180", &tag);
+ try htest.assertEqual("b98f03a947807713d75a4fff9fc277a6", &c);
+ try htest.assertEqual("478f3b50dc478ef7d5cf2d0f7cc13180", &tag);
}
test "Aegis256 test vector 3" {
@@ -448,7 +448,7 @@ test "Aegis256 test vector 3" {
Aegis256.encrypt(&c, &tag, &m, &ad, nonce, key);
try Aegis256.decrypt(&m2, &c, tag, &ad, nonce, key);
- testing.expectEqualSlices(u8, &m, &m2);
+ try testing.expectEqualSlices(u8, &m, &m2);
- htest.assertEqual("f7a0878f68bd083e8065354071fc27c3", &tag);
+ try htest.assertEqual("f7a0878f68bd083e8065354071fc27c3", &tag);
}
lib/std/crypto/aes.zig
@@ -48,7 +48,7 @@ test "ctr" {
var out: [exp_out.len]u8 = undefined;
var ctx = Aes128.initEnc(key);
ctr(AesEncryptCtx(Aes128), ctx, out[0..], in[0..], iv, builtin.Endian.Big);
- testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
+ try testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
}
test "encrypt" {
@@ -61,7 +61,7 @@ test "encrypt" {
var out: [exp_out.len]u8 = undefined;
var ctx = Aes128.initEnc(key);
ctx.encrypt(out[0..], in[0..]);
- testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
+ try testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
}
// Appendix C.3
@@ -76,7 +76,7 @@ test "encrypt" {
var out: [exp_out.len]u8 = undefined;
var ctx = Aes256.initEnc(key);
ctx.encrypt(out[0..], in[0..]);
- testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
+ try testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
}
}
@@ -90,7 +90,7 @@ test "decrypt" {
var out: [exp_out.len]u8 = undefined;
var ctx = Aes128.initDec(key);
ctx.decrypt(out[0..], in[0..]);
- testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
+ try testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
}
// Appendix C.3
@@ -105,7 +105,7 @@ test "decrypt" {
var out: [exp_out.len]u8 = undefined;
var ctx = Aes256.initDec(key);
ctx.decrypt(out[0..], in[0..]);
- testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
+ try testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
}
}
@@ -123,11 +123,11 @@ test "expand 128-bit key" {
for (enc.key_schedule.round_keys) |round_key, i| {
_ = try std.fmt.hexToBytes(&exp, exp_enc[i]);
- testing.expectEqualSlices(u8, &exp, &round_key.toBytes());
+ try testing.expectEqualSlices(u8, &exp, &round_key.toBytes());
}
for (enc.key_schedule.round_keys) |round_key, i| {
_ = try std.fmt.hexToBytes(&exp, exp_dec[i]);
- testing.expectEqualSlices(u8, &exp, &round_key.toBytes());
+ try testing.expectEqualSlices(u8, &exp, &round_key.toBytes());
}
}
@@ -145,10 +145,10 @@ test "expand 256-bit key" {
for (enc.key_schedule.round_keys) |round_key, i| {
_ = try std.fmt.hexToBytes(&exp, exp_enc[i]);
- testing.expectEqualSlices(u8, &exp, &round_key.toBytes());
+ try testing.expectEqualSlices(u8, &exp, &round_key.toBytes());
}
for (dec.key_schedule.round_keys) |round_key, i| {
_ = try std.fmt.hexToBytes(&exp, exp_dec[i]);
- testing.expectEqualSlices(u8, &exp, &round_key.toBytes());
+ try testing.expectEqualSlices(u8, &exp, &round_key.toBytes());
}
}
lib/std/crypto/aes_gcm.zig
@@ -118,7 +118,7 @@ test "Aes256Gcm - Empty message and no associated data" {
var tag: [Aes256Gcm.tag_length]u8 = undefined;
Aes256Gcm.encrypt(&c, &tag, m, ad, nonce, key);
- htest.assertEqual("6b6ff610a16fa4cd59f1fb7903154e92", &tag);
+ try htest.assertEqual("6b6ff610a16fa4cd59f1fb7903154e92", &tag);
}
test "Aes256Gcm - Associated data only" {
@@ -130,7 +130,7 @@ test "Aes256Gcm - Associated data only" {
var tag: [Aes256Gcm.tag_length]u8 = undefined;
Aes256Gcm.encrypt(&c, &tag, m, ad, nonce, key);
- htest.assertEqual("262ed164c2dfb26e080a9d108dd9dd4c", &tag);
+ try htest.assertEqual("262ed164c2dfb26e080a9d108dd9dd4c", &tag);
}
test "Aes256Gcm - Message only" {
@@ -144,10 +144,10 @@ test "Aes256Gcm - Message only" {
Aes256Gcm.encrypt(&c, &tag, m, ad, nonce, key);
try Aes256Gcm.decrypt(&m2, &c, tag, ad, nonce, key);
- testing.expectEqualSlices(u8, m[0..], m2[0..]);
+ try testing.expectEqualSlices(u8, m[0..], m2[0..]);
- htest.assertEqual("5ca1642d90009fea33d01f78cf6eefaf01d539472f7c", &c);
- htest.assertEqual("07cd7fc9103e2f9e9bf2dfaa319caff4", &tag);
+ try htest.assertEqual("5ca1642d90009fea33d01f78cf6eefaf01d539472f7c", &c);
+ try htest.assertEqual("07cd7fc9103e2f9e9bf2dfaa319caff4", &tag);
}
test "Aes256Gcm - Message and associated data" {
@@ -161,8 +161,8 @@ test "Aes256Gcm - Message and associated data" {
Aes256Gcm.encrypt(&c, &tag, m, ad, nonce, key);
try Aes256Gcm.decrypt(&m2, &c, tag, ad, nonce, key);
- testing.expectEqualSlices(u8, m[0..], m2[0..]);
+ try testing.expectEqualSlices(u8, m[0..], m2[0..]);
- htest.assertEqual("5ca1642d90009fea33d01f78cf6eefaf01", &c);
- htest.assertEqual("64accec679d444e2373bd9f6796c0d2c", &tag);
+ try htest.assertEqual("5ca1642d90009fea33d01f78cf6eefaf01", &c);
+ try htest.assertEqual("64accec679d444e2373bd9f6796c0d2c", &tag);
}
lib/std/crypto/bcrypt.zig
@@ -281,13 +281,13 @@ test "bcrypt codec" {
Codec.encode(salt_str[0..], salt[0..]);
var salt2: [salt_length]u8 = undefined;
try Codec.decode(salt2[0..], salt_str[0..]);
- testing.expectEqualSlices(u8, salt[0..], salt2[0..]);
+ try testing.expectEqualSlices(u8, salt[0..], salt2[0..]);
}
test "bcrypt" {
const s = try strHash("password", 5);
try strVerify(s, "password");
- testing.expectError(error.PasswordVerificationFailed, strVerify(s, "invalid password"));
+ try testing.expectError(error.PasswordVerificationFailed, strVerify(s, "invalid password"));
const long_s = try strHash("password" ** 100, 5);
try strVerify(long_s, "password" ** 100);
lib/std/crypto/blake2.zig
@@ -194,16 +194,16 @@ pub fn Blake2s(comptime out_bits: usize) type {
test "blake2s160 single" {
const h1 = "354c9c33f735962418bdacb9479873429c34916f";
- htest.assertEqualHash(Blake2s160, h1, "");
+ try htest.assertEqualHash(Blake2s160, h1, "");
const h2 = "5ae3b99be29b01834c3b508521ede60438f8de17";
- htest.assertEqualHash(Blake2s160, h2, "abc");
+ try htest.assertEqualHash(Blake2s160, h2, "abc");
const h3 = "5a604fec9713c369e84b0ed68daed7d7504ef240";
- htest.assertEqualHash(Blake2s160, h3, "The quick brown fox jumps over the lazy dog");
+ try htest.assertEqualHash(Blake2s160, h3, "The quick brown fox jumps over the lazy dog");
const h4 = "b60c4dc60e2681e58fbc24e77f07e02c69e72ed0";
- htest.assertEqualHash(Blake2s160, h4, "a" ** 32 ++ "b" ** 32);
+ try htest.assertEqualHash(Blake2s160, h4, "a" ** 32 ++ "b" ** 32);
}
test "blake2s160 streaming" {
@@ -213,21 +213,21 @@ test "blake2s160 streaming" {
const h1 = "354c9c33f735962418bdacb9479873429c34916f";
h.final(out[0..]);
- htest.assertEqual(h1, out[0..]);
+ try htest.assertEqual(h1, out[0..]);
const h2 = "5ae3b99be29b01834c3b508521ede60438f8de17";
h = Blake2s160.init(.{});
h.update("abc");
h.final(out[0..]);
- htest.assertEqual(h2, out[0..]);
+ try htest.assertEqual(h2, out[0..]);
h = Blake2s160.init(.{});
h.update("a");
h.update("b");
h.update("c");
h.final(out[0..]);
- htest.assertEqual(h2, out[0..]);
+ try htest.assertEqual(h2, out[0..]);
const h3 = "b60c4dc60e2681e58fbc24e77f07e02c69e72ed0";
@@ -235,12 +235,12 @@ test "blake2s160 streaming" {
h.update("a" ** 32);
h.update("b" ** 32);
h.final(out[0..]);
- htest.assertEqual(h3, out[0..]);
+ try htest.assertEqual(h3, out[0..]);
h = Blake2s160.init(.{});
h.update("a" ** 32 ++ "b" ** 32);
h.final(out[0..]);
- htest.assertEqual(h3, out[0..]);
+ try htest.assertEqual(h3, out[0..]);
const h4 = "4667fd60791a7fe41f939bca646b4529e296bd68";
@@ -248,12 +248,12 @@ test "blake2s160 streaming" {
h.update("a" ** 32);
h.update("b" ** 32);
h.final(out[0..]);
- htest.assertEqual(h4, out[0..]);
+ try htest.assertEqual(h4, out[0..]);
h = Blake2s160.init(.{ .context = [_]u8{0x69} ** 8, .salt = [_]u8{0x42} ** 8 });
h.update("a" ** 32 ++ "b" ** 32);
h.final(out[0..]);
- htest.assertEqual(h4, out[0..]);
+ try htest.assertEqual(h4, out[0..]);
}
test "comptime blake2s160" {
@@ -265,28 +265,28 @@ test "comptime blake2s160" {
const h1 = "2c56ad9d0b2c8b474aafa93ab307db2f0940105f";
- htest.assertEqualHash(Blake2s160, h1, block[0..]);
+ try htest.assertEqualHash(Blake2s160, h1, block[0..]);
var h = Blake2s160.init(.{});
h.update(&block);
h.final(out[0..]);
- htest.assertEqual(h1, out[0..]);
+ try htest.assertEqual(h1, out[0..]);
}
}
test "blake2s224 single" {
const h1 = "1fa1291e65248b37b3433475b2a0dd63d54a11ecc4e3e034e7bc1ef4";
- htest.assertEqualHash(Blake2s224, h1, "");
+ try htest.assertEqualHash(Blake2s224, h1, "");
const h2 = "0b033fc226df7abde29f67a05d3dc62cf271ef3dfea4d387407fbd55";
- htest.assertEqualHash(Blake2s224, h2, "abc");
+ try htest.assertEqualHash(Blake2s224, h2, "abc");
const h3 = "e4e5cb6c7cae41982b397bf7b7d2d9d1949823ae78435326e8db4912";
- htest.assertEqualHash(Blake2s224, h3, "The quick brown fox jumps over the lazy dog");
+ try htest.assertEqualHash(Blake2s224, h3, "The quick brown fox jumps over the lazy dog");
const h4 = "557381a78facd2b298640f4e32113e58967d61420af1aa939d0cfe01";
- htest.assertEqualHash(Blake2s224, h4, "a" ** 32 ++ "b" ** 32);
+ try htest.assertEqualHash(Blake2s224, h4, "a" ** 32 ++ "b" ** 32);
}
test "blake2s224 streaming" {
@@ -296,21 +296,21 @@ test "blake2s224 streaming" {
const h1 = "1fa1291e65248b37b3433475b2a0dd63d54a11ecc4e3e034e7bc1ef4";
h.final(out[0..]);
- htest.assertEqual(h1, out[0..]);
+ try htest.assertEqual(h1, out[0..]);
const h2 = "0b033fc226df7abde29f67a05d3dc62cf271ef3dfea4d387407fbd55";
h = Blake2s224.init(.{});
h.update("abc");
h.final(out[0..]);
- htest.assertEqual(h2, out[0..]);
+ try htest.assertEqual(h2, out[0..]);
h = Blake2s224.init(.{});
h.update("a");
h.update("b");
h.update("c");
h.final(out[0..]);
- htest.assertEqual(h2, out[0..]);
+ try htest.assertEqual(h2, out[0..]);
const h3 = "557381a78facd2b298640f4e32113e58967d61420af1aa939d0cfe01";
@@ -318,12 +318,12 @@ test "blake2s224 streaming" {
h.update("a" ** 32);
h.update("b" ** 32);
h.final(out[0..]);
- htest.assertEqual(h3, out[0..]);
+ try htest.assertEqual(h3, out[0..]);
h = Blake2s224.init(.{});
h.update("a" ** 32 ++ "b" ** 32);
h.final(out[0..]);
- htest.assertEqual(h3, out[0..]);
+ try htest.assertEqual(h3, out[0..]);
const h4 = "a4d6a9d253441b80e5dfd60a04db169ffab77aec56a2855c402828c3";
@@ -331,12 +331,12 @@ test "blake2s224 streaming" {
h.update("a" ** 32);
h.update("b" ** 32);
h.final(out[0..]);
- htest.assertEqual(h4, out[0..]);
+ try htest.assertEqual(h4, out[0..]);
h = Blake2s224.init(.{ .context = [_]u8{0x69} ** 8, .salt = [_]u8{0x42} ** 8 });
h.update("a" ** 32 ++ "b" ** 32);
h.final(out[0..]);
- htest.assertEqual(h4, out[0..]);
+ try htest.assertEqual(h4, out[0..]);
}
test "comptime blake2s224" {
@@ -347,28 +347,28 @@ test "comptime blake2s224" {
const h1 = "86b7611563293f8c73627df7a6d6ba25ca0548c2a6481f7d116ee576";
- htest.assertEqualHash(Blake2s224, h1, block[0..]);
+ try htest.assertEqualHash(Blake2s224, h1, block[0..]);
var h = Blake2s224.init(.{});
h.update(&block);
h.final(out[0..]);
- htest.assertEqual(h1, out[0..]);
+ try htest.assertEqual(h1, out[0..]);
}
}
test "blake2s256 single" {
const h1 = "69217a3079908094e11121d042354a7c1f55b6482ca1a51e1b250dfd1ed0eef9";
- htest.assertEqualHash(Blake2s256, h1, "");
+ try htest.assertEqualHash(Blake2s256, h1, "");
const h2 = "508c5e8c327c14e2e1a72ba34eeb452f37458b209ed63a294d999b4c86675982";
- htest.assertEqualHash(Blake2s256, h2, "abc");
+ try htest.assertEqualHash(Blake2s256, h2, "abc");
const h3 = "606beeec743ccbeff6cbcdf5d5302aa855c256c29b88c8ed331ea1a6bf3c8812";
- htest.assertEqualHash(Blake2s256, h3, "The quick brown fox jumps over the lazy dog");
+ try htest.assertEqualHash(Blake2s256, h3, "The quick brown fox jumps over the lazy dog");
const h4 = "8d8711dade07a6b92b9a3ea1f40bee9b2c53ff3edd2a273dec170b0163568977";
- htest.assertEqualHash(Blake2s256, h4, "a" ** 32 ++ "b" ** 32);
+ try htest.assertEqualHash(Blake2s256, h4, "a" ** 32 ++ "b" ** 32);
}
test "blake2s256 streaming" {
@@ -378,21 +378,21 @@ test "blake2s256 streaming" {
const h1 = "69217a3079908094e11121d042354a7c1f55b6482ca1a51e1b250dfd1ed0eef9";
h.final(out[0..]);
- htest.assertEqual(h1, out[0..]);
+ try htest.assertEqual(h1, out[0..]);
const h2 = "508c5e8c327c14e2e1a72ba34eeb452f37458b209ed63a294d999b4c86675982";
h = Blake2s256.init(.{});
h.update("abc");
h.final(out[0..]);
- htest.assertEqual(h2, out[0..]);
+ try htest.assertEqual(h2, out[0..]);
h = Blake2s256.init(.{});
h.update("a");
h.update("b");
h.update("c");
h.final(out[0..]);
- htest.assertEqual(h2, out[0..]);
+ try htest.assertEqual(h2, out[0..]);
const h3 = "8d8711dade07a6b92b9a3ea1f40bee9b2c53ff3edd2a273dec170b0163568977";
@@ -400,12 +400,12 @@ test "blake2s256 streaming" {
h.update("a" ** 32);
h.update("b" ** 32);
h.final(out[0..]);
- htest.assertEqual(h3, out[0..]);
+ try htest.assertEqual(h3, out[0..]);
h = Blake2s256.init(.{});
h.update("a" ** 32 ++ "b" ** 32);
h.final(out[0..]);
- htest.assertEqual(h3, out[0..]);
+ try htest.assertEqual(h3, out[0..]);
}
test "blake2s256 keyed" {
@@ -415,20 +415,20 @@ test "blake2s256 keyed" {
const key = "secret_key";
Blake2s256.hash("a" ** 64 ++ "b" ** 64, &out, .{ .key = key });
- htest.assertEqual(h1, out[0..]);
+ try htest.assertEqual(h1, out[0..]);
var h = Blake2s256.init(.{ .key = key });
h.update("a" ** 64 ++ "b" ** 64);
h.final(out[0..]);
- htest.assertEqual(h1, out[0..]);
+ try htest.assertEqual(h1, out[0..]);
h = Blake2s256.init(.{ .key = key });
h.update("a" ** 64);
h.update("b" ** 64);
h.final(out[0..]);
- htest.assertEqual(h1, out[0..]);
+ try htest.assertEqual(h1, out[0..]);
}
test "comptime blake2s256" {
@@ -439,13 +439,13 @@ test "comptime blake2s256" {
const h1 = "ae09db7cd54f42b490ef09b6bc541af688e4959bb8c53f359a6f56e38ab454a3";
- htest.assertEqualHash(Blake2s256, h1, block[0..]);
+ try htest.assertEqualHash(Blake2s256, h1, block[0..]);
var h = Blake2s256.init(.{});
h.update(&block);
h.final(out[0..]);
- htest.assertEqual(h1, out[0..]);
+ try htest.assertEqual(h1, out[0..]);
}
}
@@ -617,16 +617,16 @@ pub fn Blake2b(comptime out_bits: usize) type {
test "blake2b160 single" {
const h1 = "3345524abf6bbe1809449224b5972c41790b6cf2";
- htest.assertEqualHash(Blake2b160, h1, "");
+ try htest.assertEqualHash(Blake2b160, h1, "");
const h2 = "384264f676f39536840523f284921cdc68b6846b";
- htest.assertEqualHash(Blake2b160, h2, "abc");
+ try htest.assertEqualHash(Blake2b160, h2, "abc");
const h3 = "3c523ed102ab45a37d54f5610d5a983162fde84f";
- htest.assertEqualHash(Blake2b160, h3, "The quick brown fox jumps over the lazy dog");
+ try htest.assertEqualHash(Blake2b160, h3, "The quick brown fox jumps over the lazy dog");
const h4 = "43758f5de1740f651f1ae39de92260fe8bd5a11f";
- htest.assertEqualHash(Blake2b160, h4, "a" ** 64 ++ "b" ** 64);
+ try htest.assertEqualHash(Blake2b160, h4, "a" ** 64 ++ "b" ** 64);
}
test "blake2b160 streaming" {
@@ -636,40 +636,40 @@ test "blake2b160 streaming" {
const h1 = "3345524abf6bbe1809449224b5972c41790b6cf2";
h.final(out[0..]);
- htest.assertEqual(h1, out[0..]);
+ try htest.assertEqual(h1, out[0..]);
const h2 = "384264f676f39536840523f284921cdc68b6846b";
h = Blake2b160.init(.{});
h.update("abc");
h.final(out[0..]);
- htest.assertEqual(h2, out[0..]);
+ try htest.assertEqual(h2, out[0..]);
h = Blake2b160.init(.{});
h.update("a");
h.update("b");
h.update("c");
h.final(out[0..]);
- htest.assertEqual(h2, out[0..]);
+ try htest.assertEqual(h2, out[0..]);
const h3 = "43758f5de1740f651f1ae39de92260fe8bd5a11f";
h = Blake2b160.init(.{});
h.update("a" ** 64 ++ "b" ** 64);
h.final(out[0..]);
- htest.assertEqual(h3, out[0..]);
+ try htest.assertEqual(h3, out[0..]);
h = Blake2b160.init(.{});
h.update("a" ** 64);
h.update("b" ** 64);
h.final(out[0..]);
- htest.assertEqual(h3, out[0..]);
+ try htest.assertEqual(h3, out[0..]);
h = Blake2b160.init(.{});
h.update("a" ** 64);
h.update("b" ** 64);
h.final(out[0..]);
- htest.assertEqual(h3, out[0..]);
+ try htest.assertEqual(h3, out[0..]);
const h4 = "72328f8a8200663752fc302d372b5dd9b49dd8dc";
@@ -677,13 +677,13 @@ test "blake2b160 streaming" {
h.update("a" ** 64);
h.update("b" ** 64);
h.final(out[0..]);
- htest.assertEqual(h4, out[0..]);
+ try htest.assertEqual(h4, out[0..]);
h = Blake2b160.init(.{ .context = [_]u8{0x69} ** 16, .salt = [_]u8{0x42} ** 16 });
h.update("a" ** 64);
h.update("b" ** 64);
h.final(out[0..]);
- htest.assertEqual(h4, out[0..]);
+ try htest.assertEqual(h4, out[0..]);
}
test "comptime blake2b160" {
@@ -694,28 +694,28 @@ test "comptime blake2b160" {
const h1 = "8d26f158f564e3293b42f5e3d34263cb173aa9c9";
- htest.assertEqualHash(Blake2b160, h1, block[0..]);
+ try htest.assertEqualHash(Blake2b160, h1, block[0..]);
var h = Blake2b160.init(.{});
h.update(&block);
h.final(out[0..]);
- htest.assertEqual(h1, out[0..]);
+ try htest.assertEqual(h1, out[0..]);
}
}
test "blake2b384 single" {
const h1 = "b32811423377f52d7862286ee1a72ee540524380fda1724a6f25d7978c6fd3244a6caf0498812673c5e05ef583825100";
- htest.assertEqualHash(Blake2b384, h1, "");
+ try htest.assertEqualHash(Blake2b384, h1, "");
const h2 = "6f56a82c8e7ef526dfe182eb5212f7db9df1317e57815dbda46083fc30f54ee6c66ba83be64b302d7cba6ce15bb556f4";
- htest.assertEqualHash(Blake2b384, h2, "abc");
+ try htest.assertEqualHash(Blake2b384, h2, "abc");
const h3 = "b7c81b228b6bd912930e8f0b5387989691c1cee1e65aade4da3b86a3c9f678fc8018f6ed9e2906720c8d2a3aeda9c03d";
- htest.assertEqualHash(Blake2b384, h3, "The quick brown fox jumps over the lazy dog");
+ try htest.assertEqualHash(Blake2b384, h3, "The quick brown fox jumps over the lazy dog");
const h4 = "b7283f0172fecbbd7eca32ce10d8a6c06b453cb3cf675b33eb4246f0da2bb94a6c0bdd6eec0b5fd71ec4fd51be80bf4c";
- htest.assertEqualHash(Blake2b384, h4, "a" ** 64 ++ "b" ** 64);
+ try htest.assertEqualHash(Blake2b384, h4, "a" ** 64 ++ "b" ** 64);
}
test "blake2b384 streaming" {
@@ -725,40 +725,40 @@ test "blake2b384 streaming" {
const h1 = "b32811423377f52d7862286ee1a72ee540524380fda1724a6f25d7978c6fd3244a6caf0498812673c5e05ef583825100";
h.final(out[0..]);
- htest.assertEqual(h1, out[0..]);
+ try htest.assertEqual(h1, out[0..]);
const h2 = "6f56a82c8e7ef526dfe182eb5212f7db9df1317e57815dbda46083fc30f54ee6c66ba83be64b302d7cba6ce15bb556f4";
h = Blake2b384.init(.{});
h.update("abc");
h.final(out[0..]);
- htest.assertEqual(h2, out[0..]);
+ try htest.assertEqual(h2, out[0..]);
h = Blake2b384.init(.{});
h.update("a");
h.update("b");
h.update("c");
h.final(out[0..]);
- htest.assertEqual(h2, out[0..]);
+ try htest.assertEqual(h2, out[0..]);
const h3 = "b7283f0172fecbbd7eca32ce10d8a6c06b453cb3cf675b33eb4246f0da2bb94a6c0bdd6eec0b5fd71ec4fd51be80bf4c";
h = Blake2b384.init(.{});
h.update("a" ** 64 ++ "b" ** 64);
h.final(out[0..]);
- htest.assertEqual(h3, out[0..]);
+ try htest.assertEqual(h3, out[0..]);
h = Blake2b384.init(.{});
h.update("a" ** 64);
h.update("b" ** 64);
h.final(out[0..]);
- htest.assertEqual(h3, out[0..]);
+ try htest.assertEqual(h3, out[0..]);
h = Blake2b384.init(.{});
h.update("a" ** 64);
h.update("b" ** 64);
h.final(out[0..]);
- htest.assertEqual(h3, out[0..]);
+ try htest.assertEqual(h3, out[0..]);
const h4 = "934c48fcb197031c71f583d92f98703510805e72142e0b46f5752d1e971bc86c355d556035613ff7a4154b4de09dac5c";
@@ -766,13 +766,13 @@ test "blake2b384 streaming" {
h.update("a" ** 64);
h.update("b" ** 64);
h.final(out[0..]);
- htest.assertEqual(h4, out[0..]);
+ try htest.assertEqual(h4, out[0..]);
h = Blake2b384.init(.{ .context = [_]u8{0x69} ** 16, .salt = [_]u8{0x42} ** 16 });
h.update("a" ** 64);
h.update("b" ** 64);
h.final(out[0..]);
- htest.assertEqual(h4, out[0..]);
+ try htest.assertEqual(h4, out[0..]);
}
test "comptime blake2b384" {
@@ -783,28 +783,28 @@ test "comptime blake2b384" {
const h1 = "e8aa1931ea0422e4446fecdd25c16cf35c240b10cb4659dd5c776eddcaa4d922397a589404b46eb2e53d78132d05fd7d";
- htest.assertEqualHash(Blake2b384, h1, block[0..]);
+ try htest.assertEqualHash(Blake2b384, h1, block[0..]);
var h = Blake2b384.init(.{});
h.update(&block);
h.final(out[0..]);
- htest.assertEqual(h1, out[0..]);
+ try htest.assertEqual(h1, out[0..]);
}
}
test "blake2b512 single" {
const h1 = "786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce";
- htest.assertEqualHash(Blake2b512, h1, "");
+ try htest.assertEqualHash(Blake2b512, h1, "");
const h2 = "ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923";
- htest.assertEqualHash(Blake2b512, h2, "abc");
+ try htest.assertEqualHash(Blake2b512, h2, "abc");
const h3 = "a8add4bdddfd93e4877d2746e62817b116364a1fa7bc148d95090bc7333b3673f82401cf7aa2e4cb1ecd90296e3f14cb5413f8ed77be73045b13914cdcd6a918";
- htest.assertEqualHash(Blake2b512, h3, "The quick brown fox jumps over the lazy dog");
+ try htest.assertEqualHash(Blake2b512, h3, "The quick brown fox jumps over the lazy dog");
const h4 = "049980af04d6a2cf16b4b49793c3ed7e40732073788806f2c989ebe9547bda0541d63abe298ec8955d08af48ae731f2e8a0bd6d201655a5473b4aa79d211b920";
- htest.assertEqualHash(Blake2b512, h4, "a" ** 64 ++ "b" ** 64);
+ try htest.assertEqualHash(Blake2b512, h4, "a" ** 64 ++ "b" ** 64);
}
test "blake2b512 streaming" {
@@ -814,34 +814,34 @@ test "blake2b512 streaming" {
const h1 = "786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce";
h.final(out[0..]);
- htest.assertEqual(h1, out[0..]);
+ try htest.assertEqual(h1, out[0..]);
const h2 = "ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923";
h = Blake2b512.init(.{});
h.update("abc");
h.final(out[0..]);
- htest.assertEqual(h2, out[0..]);
+ try htest.assertEqual(h2, out[0..]);
h = Blake2b512.init(.{});
h.update("a");
h.update("b");
h.update("c");
h.final(out[0..]);
- htest.assertEqual(h2, out[0..]);
+ try htest.assertEqual(h2, out[0..]);
const h3 = "049980af04d6a2cf16b4b49793c3ed7e40732073788806f2c989ebe9547bda0541d63abe298ec8955d08af48ae731f2e8a0bd6d201655a5473b4aa79d211b920";
h = Blake2b512.init(.{});
h.update("a" ** 64 ++ "b" ** 64);
h.final(out[0..]);
- htest.assertEqual(h3, out[0..]);
+ try htest.assertEqual(h3, out[0..]);
h = Blake2b512.init(.{});
h.update("a" ** 64);
h.update("b" ** 64);
h.final(out[0..]);
- htest.assertEqual(h3, out[0..]);
+ try htest.assertEqual(h3, out[0..]);
}
test "blake2b512 keyed" {
@@ -851,20 +851,20 @@ test "blake2b512 keyed" {
const key = "secret_key";
Blake2b512.hash("a" ** 64 ++ "b" ** 64, &out, .{ .key = key });
- htest.assertEqual(h1, out[0..]);
+ try htest.assertEqual(h1, out[0..]);
var h = Blake2b512.init(.{ .key = key });
h.update("a" ** 64 ++ "b" ** 64);
h.final(out[0..]);
- htest.assertEqual(h1, out[0..]);
+ try htest.assertEqual(h1, out[0..]);
h = Blake2b512.init(.{ .key = key });
h.update("a" ** 64);
h.update("b" ** 64);
h.final(out[0..]);
- htest.assertEqual(h1, out[0..]);
+ try htest.assertEqual(h1, out[0..]);
}
test "comptime blake2b512" {
@@ -875,12 +875,12 @@ test "comptime blake2b512" {
const h1 = "865939e120e6805438478841afb739ae4250cf372653078a065cdcfffca4caf798e6d462b65d658fc165782640eded70963449ae1500fb0f24981d7727e22c41";
- htest.assertEqualHash(Blake2b512, h1, block[0..]);
+ try htest.assertEqualHash(Blake2b512, h1, block[0..]);
var h = Blake2b512.init(.{});
h.update(&block);
h.final(out[0..]);
- htest.assertEqual(h1, out[0..]);
+ try htest.assertEqual(h1, out[0..]);
}
}
lib/std/crypto/blake3.zig
@@ -641,7 +641,7 @@ const reference_test = ReferenceTest{
},
};
-fn testBlake3(hasher: *Blake3, input_len: usize, expected_hex: [262]u8) void {
+fn testBlake3(hasher: *Blake3, input_len: usize, expected_hex: [262]u8) !void {
// Save initial state
const initial_state = hasher.*;
@@ -664,7 +664,7 @@ fn testBlake3(hasher: *Blake3, input_len: usize, expected_hex: [262]u8) void {
// Compare to expected value
var expected_bytes: [expected_hex.len / 2]u8 = undefined;
_ = fmt.hexToBytes(expected_bytes[0..], expected_hex[0..]) catch unreachable;
- testing.expectEqual(actual_bytes, expected_bytes);
+ try testing.expectEqual(actual_bytes, expected_bytes);
// Restore initial state
hasher.* = initial_state;
@@ -676,8 +676,8 @@ test "BLAKE3 reference test cases" {
var derive_key = &Blake3.initKdf(reference_test.context_string, .{});
for (reference_test.cases) |t| {
- testBlake3(hash, t.input_len, t.hash.*);
- testBlake3(keyed_hash, t.input_len, t.keyed_hash.*);
- testBlake3(derive_key, t.input_len, t.derive_key.*);
+ try testBlake3(hash, t.input_len, t.hash.*);
+ try testBlake3(keyed_hash, t.input_len, t.keyed_hash.*);
+ try testBlake3(derive_key, t.input_len, t.derive_key.*);
}
}
lib/std/crypto/chacha20.zig
@@ -604,9 +604,9 @@ test "chacha20 AEAD API" {
aead.encrypt(c[0..], tag[0..], m, ad, nonce, key);
try aead.decrypt(out[0..], c[0..], tag, ad[0..], nonce, key);
- testing.expectEqualSlices(u8, out[0..], m);
+ try testing.expectEqualSlices(u8, out[0..], m);
c[0] += 1;
- testing.expectError(error.AuthenticationFailed, aead.decrypt(out[0..], c[0..], tag, ad[0..], nonce, key));
+ try testing.expectError(error.AuthenticationFailed, aead.decrypt(out[0..], c[0..], tag, ad[0..], nonce, key));
}
}
@@ -644,11 +644,11 @@ test "crypto.chacha20 test vector sunscreen" {
};
ChaCha20IETF.xor(result[0..], m[0..], 1, key, nonce);
- testing.expectEqualSlices(u8, &expected_result, &result);
+ try testing.expectEqualSlices(u8, &expected_result, &result);
var m2: [114]u8 = undefined;
ChaCha20IETF.xor(m2[0..], result[0..], 1, key, nonce);
- testing.expect(mem.order(u8, m, &m2) == .eq);
+ try testing.expect(mem.order(u8, m, &m2) == .eq);
}
// https://tools.ietf.org/html/draft-agl-tls-chacha20poly1305-04#section-7
@@ -683,7 +683,7 @@ test "crypto.chacha20 test vector 1" {
const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0 };
ChaCha20With64BitNonce.xor(result[0..], m[0..], 0, key, nonce);
- testing.expectEqualSlices(u8, &expected_result, &result);
+ try testing.expectEqualSlices(u8, &expected_result, &result);
}
test "crypto.chacha20 test vector 2" {
@@ -717,7 +717,7 @@ test "crypto.chacha20 test vector 2" {
const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0 };
ChaCha20With64BitNonce.xor(result[0..], m[0..], 0, key, nonce);
- testing.expectEqualSlices(u8, &expected_result, &result);
+ try testing.expectEqualSlices(u8, &expected_result, &result);
}
test "crypto.chacha20 test vector 3" {
@@ -751,7 +751,7 @@ test "crypto.chacha20 test vector 3" {
const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 1 };
ChaCha20With64BitNonce.xor(result[0..], m[0..], 0, key, nonce);
- testing.expectEqualSlices(u8, &expected_result, &result);
+ try testing.expectEqualSlices(u8, &expected_result, &result);
}
test "crypto.chacha20 test vector 4" {
@@ -785,7 +785,7 @@ test "crypto.chacha20 test vector 4" {
const nonce = [_]u8{ 1, 0, 0, 0, 0, 0, 0, 0 };
ChaCha20With64BitNonce.xor(result[0..], m[0..], 0, key, nonce);
- testing.expectEqualSlices(u8, &expected_result, &result);
+ try testing.expectEqualSlices(u8, &expected_result, &result);
}
test "crypto.chacha20 test vector 5" {
@@ -857,7 +857,7 @@ test "crypto.chacha20 test vector 5" {
};
ChaCha20With64BitNonce.xor(result[0..], m[0..], 0, key, nonce);
- testing.expectEqualSlices(u8, &expected_result, &result);
+ try testing.expectEqualSlices(u8, &expected_result, &result);
}
test "seal" {
@@ -873,7 +873,7 @@ test "seal" {
var out: [exp_out.len]u8 = undefined;
ChaCha20Poly1305.encrypt(out[0..m.len], out[m.len..], m, ad, nonce, key);
- testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
+ try testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
}
{
const m = [_]u8{
@@ -906,7 +906,7 @@ test "seal" {
var out: [exp_out.len]u8 = undefined;
ChaCha20Poly1305.encrypt(out[0..m.len], out[m.len..], m[0..], ad[0..], nonce, key);
- testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
+ try testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
}
}
@@ -923,7 +923,7 @@ test "open" {
var out: [exp_out.len]u8 = undefined;
try ChaCha20Poly1305.decrypt(out[0..], c[0..exp_out.len], c[exp_out.len..].*, ad[0..], nonce, key);
- testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
+ try testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
}
{
const c = [_]u8{
@@ -956,21 +956,21 @@ test "open" {
var out: [exp_out.len]u8 = undefined;
try ChaCha20Poly1305.decrypt(out[0..], c[0..exp_out.len], c[exp_out.len..].*, ad[0..], nonce, key);
- testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
+ try testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
// corrupting the ciphertext, data, key, or nonce should cause a failure
var bad_c = c;
bad_c[0] ^= 1;
- testing.expectError(error.AuthenticationFailed, ChaCha20Poly1305.decrypt(out[0..], bad_c[0..out.len], bad_c[out.len..].*, ad[0..], nonce, key));
+ try testing.expectError(error.AuthenticationFailed, ChaCha20Poly1305.decrypt(out[0..], bad_c[0..out.len], bad_c[out.len..].*, ad[0..], nonce, key));
var bad_ad = ad;
bad_ad[0] ^= 1;
- testing.expectError(error.AuthenticationFailed, ChaCha20Poly1305.decrypt(out[0..], c[0..out.len], c[out.len..].*, bad_ad[0..], nonce, key));
+ try testing.expectError(error.AuthenticationFailed, ChaCha20Poly1305.decrypt(out[0..], c[0..out.len], c[out.len..].*, bad_ad[0..], nonce, key));
var bad_key = key;
bad_key[0] ^= 1;
- testing.expectError(error.AuthenticationFailed, ChaCha20Poly1305.decrypt(out[0..], c[0..out.len], c[out.len..].*, ad[0..], nonce, bad_key));
+ try testing.expectError(error.AuthenticationFailed, ChaCha20Poly1305.decrypt(out[0..], c[0..out.len], c[out.len..].*, ad[0..], nonce, bad_key));
var bad_nonce = nonce;
bad_nonce[0] ^= 1;
- testing.expectError(error.AuthenticationFailed, ChaCha20Poly1305.decrypt(out[0..], c[0..out.len], c[out.len..].*, ad[0..], bad_nonce, key));
+ try testing.expectError(error.AuthenticationFailed, ChaCha20Poly1305.decrypt(out[0..], c[0..out.len], c[out.len..].*, ad[0..], bad_nonce, key));
}
}
@@ -982,7 +982,7 @@ test "crypto.xchacha20" {
var c: [m.len]u8 = undefined;
XChaCha20IETF.xor(c[0..], m[0..], 0, key, nonce);
var buf: [2 * c.len]u8 = undefined;
- testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&c)}), "E0A1BCF939654AFDBDC1746EC49832647C19D891F0D1A81FC0C1703B4514BDEA584B512F6908C2C5E9DD18D5CBC1805DE5803FE3B9CA5F193FB8359E91FAB0C3BB40309A292EB1CF49685C65C4A3ADF4F11DB0CD2B6B67FBC174BC2E860E8F769FD3565BBFAD1C845E05A0FED9BE167C240D");
+ try testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&c)}), "E0A1BCF939654AFDBDC1746EC49832647C19D891F0D1A81FC0C1703B4514BDEA584B512F6908C2C5E9DD18D5CBC1805DE5803FE3B9CA5F193FB8359E91FAB0C3BB40309A292EB1CF49685C65C4A3ADF4F11DB0CD2B6B67FBC174BC2E860E8F769FD3565BBFAD1C845E05A0FED9BE167C240D");
}
{
const ad = "Additional data";
@@ -991,9 +991,9 @@ test "crypto.xchacha20" {
var out: [m.len]u8 = undefined;
try XChaCha20Poly1305.decrypt(out[0..], c[0..m.len], c[m.len..].*, ad, nonce, key);
var buf: [2 * c.len]u8 = undefined;
- testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&c)}), "994D2DD32333F48E53650C02C7A2ABB8E018B0836D7175AEC779F52E961780768F815C58F1AA52D211498DB89B9216763F569C9433A6BBFCEFB4D4A49387A4C5207FBB3B5A92B5941294DF30588C6740D39DC16FA1F0E634F7246CF7CDCB978E44347D89381B7A74EB7084F754B90BDE9AAF5A94B8F2A85EFD0B50692AE2D425E234");
- testing.expectEqualSlices(u8, out[0..], m);
+ try testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&c)}), "994D2DD32333F48E53650C02C7A2ABB8E018B0836D7175AEC779F52E961780768F815C58F1AA52D211498DB89B9216763F569C9433A6BBFCEFB4D4A49387A4C5207FBB3B5A92B5941294DF30588C6740D39DC16FA1F0E634F7246CF7CDCB978E44347D89381B7A74EB7084F754B90BDE9AAF5A94B8F2A85EFD0B50692AE2D425E234");
+ try testing.expectEqualSlices(u8, out[0..], m);
c[0] += 1;
- testing.expectError(error.AuthenticationFailed, XChaCha20Poly1305.decrypt(out[0..], c[0..m.len], c[m.len..].*, ad, nonce, key));
+ try testing.expectError(error.AuthenticationFailed, XChaCha20Poly1305.decrypt(out[0..], c[0..m.len], c[m.len..].*, ad, nonce, key));
}
}
lib/std/crypto/ghash.zig
@@ -326,11 +326,11 @@ test "ghash" {
st.update(&m);
var out: [16]u8 = undefined;
st.final(&out);
- htest.assertEqual("889295fa746e8b174bf4ec80a65dea41", &out);
+ try htest.assertEqual("889295fa746e8b174bf4ec80a65dea41", &out);
st = Ghash.init(&key);
st.update(m[0..100]);
st.update(m[100..]);
st.final(&out);
- htest.assertEqual("889295fa746e8b174bf4ec80a65dea41", &out);
+ try htest.assertEqual("889295fa746e8b174bf4ec80a65dea41", &out);
}
lib/std/crypto/gimli.zig
@@ -205,7 +205,7 @@ test "permute" {
while (i < 12) : (i += 1) {
mem.writeIntLittle(u32, expected_output[i * 4 ..][0..4], tv_output[i / 4][i % 4]);
}
- testing.expectEqualSlices(u8, state.toSliceConst(), expected_output[0..]);
+ try testing.expectEqualSlices(u8, state.toSliceConst(), expected_output[0..]);
}
pub const Hash = struct {
@@ -274,7 +274,7 @@ test "hash" {
_ = try std.fmt.hexToBytes(&msg, "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C");
var md: [32]u8 = undefined;
hash(&md, &msg, .{});
- htest.assertEqual("1C9A03DC6A5DDC5444CFC6F4B154CFF5CF081633B2CEA4D7D0AE7CCFED5AAA44", &md);
+ try htest.assertEqual("1C9A03DC6A5DDC5444CFC6F4B154CFF5CF081633B2CEA4D7D0AE7CCFED5AAA44", &md);
}
test "hash test vector 17" {
@@ -282,7 +282,7 @@ test "hash test vector 17" {
_ = try std.fmt.hexToBytes(&msg, "000102030405060708090A0B0C0D0E0F");
var md: [32]u8 = undefined;
hash(&md, &msg, .{});
- htest.assertEqual("404C130AF1B9023A7908200919F690FFBB756D5176E056FFDE320016A37C7282", &md);
+ try htest.assertEqual("404C130AF1B9023A7908200919F690FFBB756D5176E056FFDE320016A37C7282", &md);
}
test "hash test vector 33" {
@@ -290,7 +290,7 @@ test "hash test vector 33" {
_ = try std.fmt.hexToBytes(&msg, "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F");
var md: [32]u8 = undefined;
hash(&md, &msg, .{});
- htest.assertEqual("A8F4FA28708BDA7EFB4C1914CA4AFA9E475B82D588D36504F87DBB0ED9AB3C4B", &md);
+ try htest.assertEqual("A8F4FA28708BDA7EFB4C1914CA4AFA9E475B82D588D36504F87DBB0ED9AB3C4B", &md);
}
pub const Aead = struct {
@@ -447,12 +447,12 @@ test "cipher" {
var ct: [pt.len]u8 = undefined;
var tag: [16]u8 = undefined;
Aead.encrypt(&ct, &tag, &pt, &ad, nonce, key);
- htest.assertEqual("", &ct);
- htest.assertEqual("14DA9BB7120BF58B985A8E00FDEBA15B", &tag);
+ try htest.assertEqual("", &ct);
+ try htest.assertEqual("14DA9BB7120BF58B985A8E00FDEBA15B", &tag);
var pt2: [pt.len]u8 = undefined;
try Aead.decrypt(&pt2, &ct, tag, &ad, nonce, key);
- testing.expectEqualSlices(u8, &pt, &pt2);
+ try testing.expectEqualSlices(u8, &pt, &pt2);
}
{ // test vector (34) from NIST KAT submission.
const ad: [0]u8 = undefined;
@@ -462,12 +462,12 @@ test "cipher" {
var ct: [pt.len]u8 = undefined;
var tag: [16]u8 = undefined;
Aead.encrypt(&ct, &tag, &pt, &ad, nonce, key);
- htest.assertEqual("7F", &ct);
- htest.assertEqual("80492C317B1CD58A1EDC3A0D3E9876FC", &tag);
+ try htest.assertEqual("7F", &ct);
+ try htest.assertEqual("80492C317B1CD58A1EDC3A0D3E9876FC", &tag);
var pt2: [pt.len]u8 = undefined;
try Aead.decrypt(&pt2, &ct, tag, &ad, nonce, key);
- testing.expectEqualSlices(u8, &pt, &pt2);
+ try testing.expectEqualSlices(u8, &pt, &pt2);
}
{ // test vector (106) from NIST KAT submission.
var ad: [12 / 2]u8 = undefined;
@@ -478,12 +478,12 @@ test "cipher" {
var ct: [pt.len]u8 = undefined;
var tag: [16]u8 = undefined;
Aead.encrypt(&ct, &tag, &pt, &ad, nonce, key);
- htest.assertEqual("484D35", &ct);
- htest.assertEqual("030BBEA23B61C00CED60A923BDCF9147", &tag);
+ try htest.assertEqual("484D35", &ct);
+ try htest.assertEqual("030BBEA23B61C00CED60A923BDCF9147", &tag);
var pt2: [pt.len]u8 = undefined;
try Aead.decrypt(&pt2, &ct, tag, &ad, nonce, key);
- testing.expectEqualSlices(u8, &pt, &pt2);
+ try testing.expectEqualSlices(u8, &pt, &pt2);
}
{ // test vector (790) from NIST KAT submission.
var ad: [60 / 2]u8 = undefined;
@@ -494,12 +494,12 @@ test "cipher" {
var ct: [pt.len]u8 = undefined;
var tag: [16]u8 = undefined;
Aead.encrypt(&ct, &tag, &pt, &ad, nonce, key);
- htest.assertEqual("6815B4A0ECDAD01596EAD87D9E690697475D234C6A13D1", &ct);
- htest.assertEqual("DFE23F1642508290D68245279558B2FB", &tag);
+ try htest.assertEqual("6815B4A0ECDAD01596EAD87D9E690697475D234C6A13D1", &ct);
+ try htest.assertEqual("DFE23F1642508290D68245279558B2FB", &tag);
var pt2: [pt.len]u8 = undefined;
try Aead.decrypt(&pt2, &ct, tag, &ad, nonce, key);
- testing.expectEqualSlices(u8, &pt, &pt2);
+ try testing.expectEqualSlices(u8, &pt, &pt2);
}
{ // test vector (1057) from NIST KAT submission.
const ad: [0]u8 = undefined;
@@ -509,11 +509,11 @@ test "cipher" {
var ct: [pt.len]u8 = undefined;
var tag: [16]u8 = undefined;
Aead.encrypt(&ct, &tag, &pt, &ad, nonce, key);
- htest.assertEqual("7F8A2CF4F52AA4D6B2E74105C30A2777B9D0C8AEFDD555DE35861BD3011F652F", &ct);
- htest.assertEqual("7256456FA935AC34BBF55AE135F33257", &tag);
+ try htest.assertEqual("7F8A2CF4F52AA4D6B2E74105C30A2777B9D0C8AEFDD555DE35861BD3011F652F", &ct);
+ try htest.assertEqual("7256456FA935AC34BBF55AE135F33257", &tag);
var pt2: [pt.len]u8 = undefined;
try Aead.decrypt(&pt2, &ct, tag, &ad, nonce, key);
- testing.expectEqualSlices(u8, &pt, &pt2);
+ try testing.expectEqualSlices(u8, &pt, &pt2);
}
}
lib/std/crypto/hkdf.zig
@@ -65,8 +65,8 @@ test "Hkdf" {
const context = [_]u8{ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9 };
const kdf = HkdfSha256;
const prk = kdf.extract(&salt, &ikm);
- htest.assertEqual("077709362c2e32df0ddc3f0dc47bba6390b6c73bb50f9c3122ec844ad7c2b3e5", &prk);
+ try htest.assertEqual("077709362c2e32df0ddc3f0dc47bba6390b6c73bb50f9c3122ec844ad7c2b3e5", &prk);
var out: [42]u8 = undefined;
kdf.expand(&out, &context, prk);
- htest.assertEqual("3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865", &out);
+ try htest.assertEqual("3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865", &out);
}
lib/std/crypto/hmac.zig
@@ -84,26 +84,26 @@ const htest = @import("test.zig");
test "hmac md5" {
var out: [HmacMd5.mac_length]u8 = undefined;
HmacMd5.create(out[0..], "", "");
- htest.assertEqual("74e6f7298a9c2d168935f58c001bad88", out[0..]);
+ try htest.assertEqual("74e6f7298a9c2d168935f58c001bad88", out[0..]);
HmacMd5.create(out[0..], "The quick brown fox jumps over the lazy dog", "key");
- htest.assertEqual("80070713463e7749b90c2dc24911e275", out[0..]);
+ try htest.assertEqual("80070713463e7749b90c2dc24911e275", out[0..]);
}
test "hmac sha1" {
var out: [HmacSha1.mac_length]u8 = undefined;
HmacSha1.create(out[0..], "", "");
- htest.assertEqual("fbdb1d1b18aa6c08324b7d64b71fb76370690e1d", out[0..]);
+ try htest.assertEqual("fbdb1d1b18aa6c08324b7d64b71fb76370690e1d", out[0..]);
HmacSha1.create(out[0..], "The quick brown fox jumps over the lazy dog", "key");
- htest.assertEqual("de7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9", out[0..]);
+ try htest.assertEqual("de7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9", out[0..]);
}
test "hmac sha256" {
var out: [sha2.HmacSha256.mac_length]u8 = undefined;
sha2.HmacSha256.create(out[0..], "", "");
- htest.assertEqual("b613679a0814d9ec772f95d778c35fc5ff1697c493715653c6c712144292c5ad", out[0..]);
+ try htest.assertEqual("b613679a0814d9ec772f95d778c35fc5ff1697c493715653c6c712144292c5ad", out[0..]);
sha2.HmacSha256.create(out[0..], "The quick brown fox jumps over the lazy dog", "key");
- htest.assertEqual("f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8", out[0..]);
+ try htest.assertEqual("f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8", out[0..]);
}
lib/std/crypto/isap.zig
@@ -240,8 +240,8 @@ test "ISAP" {
var msg = "test";
var c: [msg.len]u8 = undefined;
IsapA128A.encrypt(c[0..], &tag, msg[0..], ad, n, k);
- testing.expect(mem.eql(u8, &[_]u8{ 0x8f, 0x68, 0x03, 0x8d }, c[0..]));
- testing.expect(mem.eql(u8, &[_]u8{ 0x6c, 0x25, 0xe8, 0xe2, 0xe1, 0x1f, 0x38, 0xe9, 0x80, 0x75, 0xde, 0xd5, 0x2d, 0xb2, 0x31, 0x82 }, tag[0..]));
+ try testing.expect(mem.eql(u8, &[_]u8{ 0x8f, 0x68, 0x03, 0x8d }, c[0..]));
+ try testing.expect(mem.eql(u8, &[_]u8{ 0x6c, 0x25, 0xe8, 0xe2, 0xe1, 0x1f, 0x38, 0xe9, 0x80, 0x75, 0xde, 0xd5, 0x2d, 0xb2, 0x31, 0x82 }, tag[0..]));
try IsapA128A.decrypt(c[0..], c[0..], tag, ad, n, k);
- testing.expect(mem.eql(u8, msg, c[0..]));
+ try testing.expect(mem.eql(u8, msg, c[0..]));
}
lib/std/crypto/md5.zig
@@ -241,13 +241,13 @@ pub const Md5 = struct {
const htest = @import("test.zig");
test "md5 single" {
- htest.assertEqualHash(Md5, "d41d8cd98f00b204e9800998ecf8427e", "");
- htest.assertEqualHash(Md5, "0cc175b9c0f1b6a831c399e269772661", "a");
- htest.assertEqualHash(Md5, "900150983cd24fb0d6963f7d28e17f72", "abc");
- htest.assertEqualHash(Md5, "f96b697d7cb7938d525a2f31aaf161d0", "message digest");
- htest.assertEqualHash(Md5, "c3fcd3d76192e4007dfb496cca67e13b", "abcdefghijklmnopqrstuvwxyz");
- htest.assertEqualHash(Md5, "d174ab98d277d9f5a5611c2c9f419d9f", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
- htest.assertEqualHash(Md5, "57edf4a22be3c955ac49da2e2107b67a", "12345678901234567890123456789012345678901234567890123456789012345678901234567890");
+ try htest.assertEqualHash(Md5, "d41d8cd98f00b204e9800998ecf8427e", "");
+ try htest.assertEqualHash(Md5, "0cc175b9c0f1b6a831c399e269772661", "a");
+ try htest.assertEqualHash(Md5, "900150983cd24fb0d6963f7d28e17f72", "abc");
+ try htest.assertEqualHash(Md5, "f96b697d7cb7938d525a2f31aaf161d0", "message digest");
+ try htest.assertEqualHash(Md5, "c3fcd3d76192e4007dfb496cca67e13b", "abcdefghijklmnopqrstuvwxyz");
+ try htest.assertEqualHash(Md5, "d174ab98d277d9f5a5611c2c9f419d9f", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
+ try htest.assertEqualHash(Md5, "57edf4a22be3c955ac49da2e2107b67a", "12345678901234567890123456789012345678901234567890123456789012345678901234567890");
}
test "md5 streaming" {
@@ -255,12 +255,12 @@ test "md5 streaming" {
var out: [16]u8 = undefined;
h.final(out[0..]);
- htest.assertEqual("d41d8cd98f00b204e9800998ecf8427e", out[0..]);
+ try htest.assertEqual("d41d8cd98f00b204e9800998ecf8427e", out[0..]);
h = Md5.init(.{});
h.update("abc");
h.final(out[0..]);
- htest.assertEqual("900150983cd24fb0d6963f7d28e17f72", out[0..]);
+ try htest.assertEqual("900150983cd24fb0d6963f7d28e17f72", out[0..]);
h = Md5.init(.{});
h.update("a");
@@ -268,7 +268,7 @@ test "md5 streaming" {
h.update("c");
h.final(out[0..]);
- htest.assertEqual("900150983cd24fb0d6963f7d28e17f72", out[0..]);
+ try htest.assertEqual("900150983cd24fb0d6963f7d28e17f72", out[0..]);
}
test "md5 aligned final" {
lib/std/crypto/pbkdf2.zig
@@ -168,7 +168,7 @@ test "RFC 6070 one iteration" {
const expected = "0c60c80f961f0e71f3a9b524af6012062fe037a6";
- htest.assertEqual(expected, dk[0..]);
+ try htest.assertEqual(expected, dk[0..]);
}
test "RFC 6070 two iterations" {
@@ -183,7 +183,7 @@ test "RFC 6070 two iterations" {
const expected = "ea6c014dc72d6f8ccd1ed92ace1d41f0d8de8957";
- htest.assertEqual(expected, dk[0..]);
+ try htest.assertEqual(expected, dk[0..]);
}
test "RFC 6070 4096 iterations" {
@@ -198,7 +198,7 @@ test "RFC 6070 4096 iterations" {
const expected = "4b007901b765489abead49d926f721d065a429c1";
- htest.assertEqual(expected, dk[0..]);
+ try htest.assertEqual(expected, dk[0..]);
}
test "RFC 6070 16,777,216 iterations" {
@@ -218,7 +218,7 @@ test "RFC 6070 16,777,216 iterations" {
const expected = "eefe3d61cd4da4e4e9945b3d6ba2158c2634e984";
- htest.assertEqual(expected, dk[0..]);
+ try htest.assertEqual(expected, dk[0..]);
}
test "RFC 6070 multi-block salt and password" {
@@ -233,7 +233,7 @@ test "RFC 6070 multi-block salt and password" {
const expected = "3d2eec4fe41c849b80c8d83662c0e44a8b291a964cf2f07038";
- htest.assertEqual(expected, dk[0..]);
+ try htest.assertEqual(expected, dk[0..]);
}
test "RFC 6070 embedded NUL" {
@@ -248,7 +248,7 @@ test "RFC 6070 embedded NUL" {
const expected = "56fa6aa75548099dcc37d7f03425e0c3";
- htest.assertEqual(expected, dk[0..]);
+ try htest.assertEqual(expected, dk[0..]);
}
test "Very large dk_len" {
lib/std/crypto/poly1305.zig
@@ -216,5 +216,5 @@ test "poly1305 rfc7439 vector1" {
var mac: [16]u8 = undefined;
Poly1305.create(mac[0..], msg, key);
- std.testing.expectEqualSlices(u8, expected_mac, &mac);
+ try std.testing.expectEqualSlices(u8, expected_mac, &mac);
}
lib/std/crypto/salsa20.zig
@@ -561,11 +561,11 @@ test "(x)salsa20" {
var c: [msg.len]u8 = undefined;
Salsa20.xor(&c, msg[0..], 0, key, nonce);
- htest.assertEqual("30ff9933aa6534ff5207142593cd1fca4b23bdd8", c[0..]);
+ try htest.assertEqual("30ff9933aa6534ff5207142593cd1fca4b23bdd8", c[0..]);
const extended_nonce = [_]u8{0x42} ** 24;
XSalsa20.xor(&c, msg[0..], 0, key, extended_nonce);
- htest.assertEqual("b4ab7d82e750ec07644fa3281bce6cd91d4243f9", c[0..]);
+ try htest.assertEqual("b4ab7d82e750ec07644fa3281bce6cd91d4243f9", c[0..]);
}
test "xsalsa20poly1305" {
@@ -628,5 +628,5 @@ test "secretbox twoblocks" {
const msg = [_]u8{'a'} ** 97;
var ciphertext: [msg.len + SecretBox.tag_length]u8 = undefined;
SecretBox.seal(&ciphertext, &msg, nonce, key);
- htest.assertEqual("b05760e217288ba079caa2fd57fd3701784974ffcfda20fe523b89211ad8af065a6eb37cdb29d51aca5bd75dafdd21d18b044c54bb7c526cf576c94ee8900f911ceab0147e82b667a28c52d58ceb29554ff45471224d37b03256b01c119b89ff6d36855de8138d103386dbc9d971f52261", &ciphertext);
+ try htest.assertEqual("b05760e217288ba079caa2fd57fd3701784974ffcfda20fe523b89211ad8af065a6eb37cdb29d51aca5bd75dafdd21d18b044c54bb7c526cf576c94ee8900f911ceab0147e82b667a28c52d58ceb29554ff45471224d37b03256b01c119b89ff6d36855de8138d103386dbc9d971f52261", &ciphertext);
}
lib/std/crypto/sha1.zig
@@ -265,9 +265,9 @@ pub const Sha1 = struct {
const htest = @import("test.zig");
test "sha1 single" {
- htest.assertEqualHash(Sha1, "da39a3ee5e6b4b0d3255bfef95601890afd80709", "");
- htest.assertEqualHash(Sha1, "a9993e364706816aba3e25717850c26c9cd0d89d", "abc");
- htest.assertEqualHash(Sha1, "a49b2446a02c645bf419f995b67091253a04a259", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
+ try htest.assertEqualHash(Sha1, "da39a3ee5e6b4b0d3255bfef95601890afd80709", "");
+ try htest.assertEqualHash(Sha1, "a9993e364706816aba3e25717850c26c9cd0d89d", "abc");
+ try htest.assertEqualHash(Sha1, "a49b2446a02c645bf419f995b67091253a04a259", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
}
test "sha1 streaming" {
@@ -275,19 +275,19 @@ test "sha1 streaming" {
var out: [20]u8 = undefined;
h.final(&out);
- htest.assertEqual("da39a3ee5e6b4b0d3255bfef95601890afd80709", out[0..]);
+ try htest.assertEqual("da39a3ee5e6b4b0d3255bfef95601890afd80709", out[0..]);
h = Sha1.init(.{});
h.update("abc");
h.final(&out);
- htest.assertEqual("a9993e364706816aba3e25717850c26c9cd0d89d", out[0..]);
+ try htest.assertEqual("a9993e364706816aba3e25717850c26c9cd0d89d", out[0..]);
h = Sha1.init(.{});
h.update("a");
h.update("b");
h.update("c");
h.final(&out);
- htest.assertEqual("a9993e364706816aba3e25717850c26c9cd0d89d", out[0..]);
+ try htest.assertEqual("a9993e364706816aba3e25717850c26c9cd0d89d", out[0..]);
}
test "sha1 aligned final" {
lib/std/crypto/sha2.zig
@@ -285,9 +285,9 @@ fn Sha2x32(comptime params: Sha2Params32) type {
}
test "sha224 single" {
- htest.assertEqualHash(Sha224, "d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f", "");
- htest.assertEqualHash(Sha224, "23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", "abc");
- htest.assertEqualHash(Sha224, "c97ca9a559850ce97a04a96def6d99a9e0e0e2ab14e6b8df265fc0b3", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
+ try htest.assertEqualHash(Sha224, "d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f", "");
+ try htest.assertEqualHash(Sha224, "23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", "abc");
+ try htest.assertEqualHash(Sha224, "c97ca9a559850ce97a04a96def6d99a9e0e0e2ab14e6b8df265fc0b3", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
}
test "sha224 streaming" {
@@ -295,25 +295,25 @@ test "sha224 streaming" {
var out: [28]u8 = undefined;
h.final(out[0..]);
- htest.assertEqual("d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f", out[0..]);
+ try htest.assertEqual("d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f", out[0..]);
h = Sha224.init(.{});
h.update("abc");
h.final(out[0..]);
- htest.assertEqual("23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", out[0..]);
+ try htest.assertEqual("23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", out[0..]);
h = Sha224.init(.{});
h.update("a");
h.update("b");
h.update("c");
h.final(out[0..]);
- htest.assertEqual("23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", out[0..]);
+ try htest.assertEqual("23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", out[0..]);
}
test "sha256 single" {
- htest.assertEqualHash(Sha256, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "");
- htest.assertEqualHash(Sha256, "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", "abc");
- htest.assertEqualHash(Sha256, "cf5b16a778af8380036ce59e7b0492370b249b11e8f07a51afac45037afee9d1", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
+ try htest.assertEqualHash(Sha256, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "");
+ try htest.assertEqualHash(Sha256, "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", "abc");
+ try htest.assertEqualHash(Sha256, "cf5b16a778af8380036ce59e7b0492370b249b11e8f07a51afac45037afee9d1", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
}
test "sha256 streaming" {
@@ -321,19 +321,19 @@ test "sha256 streaming" {
var out: [32]u8 = undefined;
h.final(out[0..]);
- htest.assertEqual("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", out[0..]);
+ try htest.assertEqual("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", out[0..]);
h = Sha256.init(.{});
h.update("abc");
h.final(out[0..]);
- htest.assertEqual("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", out[0..]);
+ try htest.assertEqual("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", out[0..]);
h = Sha256.init(.{});
h.update("a");
h.update("b");
h.update("c");
h.final(out[0..]);
- htest.assertEqual("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", out[0..]);
+ try htest.assertEqual("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", out[0..]);
}
test "sha256 aligned final" {
@@ -675,13 +675,13 @@ fn Sha2x64(comptime params: Sha2Params64) type {
test "sha384 single" {
const h1 = "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b";
- htest.assertEqualHash(Sha384, h1, "");
+ try htest.assertEqualHash(Sha384, h1, "");
const h2 = "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7";
- htest.assertEqualHash(Sha384, h2, "abc");
+ try htest.assertEqualHash(Sha384, h2, "abc");
const h3 = "09330c33f71147e83d192fc782cd1b4753111b173b3b05d22fa08086e3b0f712fcc7c71a557e2db966c3e9fa91746039";
- htest.assertEqualHash(Sha384, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
+ try htest.assertEqualHash(Sha384, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
}
test "sha384 streaming" {
@@ -690,32 +690,32 @@ test "sha384 streaming" {
const h1 = "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b";
h.final(out[0..]);
- htest.assertEqual(h1, out[0..]);
+ try htest.assertEqual(h1, out[0..]);
const h2 = "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7";
h = Sha384.init(.{});
h.update("abc");
h.final(out[0..]);
- htest.assertEqual(h2, out[0..]);
+ try htest.assertEqual(h2, out[0..]);
h = Sha384.init(.{});
h.update("a");
h.update("b");
h.update("c");
h.final(out[0..]);
- htest.assertEqual(h2, out[0..]);
+ try htest.assertEqual(h2, out[0..]);
}
test "sha512 single" {
const h1 = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e";
- htest.assertEqualHash(Sha512, h1, "");
+ try htest.assertEqualHash(Sha512, h1, "");
const h2 = "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f";
- htest.assertEqualHash(Sha512, h2, "abc");
+ try htest.assertEqualHash(Sha512, h2, "abc");
const h3 = "8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018501d289e4900f7e4331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909";
- htest.assertEqualHash(Sha512, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
+ try htest.assertEqualHash(Sha512, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
}
test "sha512 streaming" {
@@ -724,21 +724,21 @@ test "sha512 streaming" {
const h1 = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e";
h.final(out[0..]);
- htest.assertEqual(h1, out[0..]);
+ try htest.assertEqual(h1, out[0..]);
const h2 = "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f";
h = Sha512.init(.{});
h.update("abc");
h.final(out[0..]);
- htest.assertEqual(h2, out[0..]);
+ try htest.assertEqual(h2, out[0..]);
h = Sha512.init(.{});
h.update("a");
h.update("b");
h.update("c");
h.final(out[0..]);
- htest.assertEqual(h2, out[0..]);
+ try htest.assertEqual(h2, out[0..]);
}
test "sha512 aligned final" {
lib/std/crypto/sha3.zig
@@ -169,9 +169,9 @@ fn keccakF(comptime F: usize, d: *[F / 8]u8) void {
}
test "sha3-224 single" {
- htest.assertEqualHash(Sha3_224, "6b4e03423667dbb73b6e15454f0eb1abd4597f9a1b078e3f5b5a6bc7", "");
- htest.assertEqualHash(Sha3_224, "e642824c3f8cf24ad09234ee7d3c766fc9a3a5168d0c94ad73b46fdf", "abc");
- htest.assertEqualHash(Sha3_224, "543e6868e1666c1a643630df77367ae5a62a85070a51c14cbf665cbc", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
+ try htest.assertEqualHash(Sha3_224, "6b4e03423667dbb73b6e15454f0eb1abd4597f9a1b078e3f5b5a6bc7", "");
+ try htest.assertEqualHash(Sha3_224, "e642824c3f8cf24ad09234ee7d3c766fc9a3a5168d0c94ad73b46fdf", "abc");
+ try htest.assertEqualHash(Sha3_224, "543e6868e1666c1a643630df77367ae5a62a85070a51c14cbf665cbc", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
}
test "sha3-224 streaming" {
@@ -179,25 +179,25 @@ test "sha3-224 streaming" {
var out: [28]u8 = undefined;
h.final(out[0..]);
- htest.assertEqual("6b4e03423667dbb73b6e15454f0eb1abd4597f9a1b078e3f5b5a6bc7", out[0..]);
+ try htest.assertEqual("6b4e03423667dbb73b6e15454f0eb1abd4597f9a1b078e3f5b5a6bc7", out[0..]);
h = Sha3_224.init(.{});
h.update("abc");
h.final(out[0..]);
- htest.assertEqual("e642824c3f8cf24ad09234ee7d3c766fc9a3a5168d0c94ad73b46fdf", out[0..]);
+ try htest.assertEqual("e642824c3f8cf24ad09234ee7d3c766fc9a3a5168d0c94ad73b46fdf", out[0..]);
h = Sha3_224.init(.{});
h.update("a");
h.update("b");
h.update("c");
h.final(out[0..]);
- htest.assertEqual("e642824c3f8cf24ad09234ee7d3c766fc9a3a5168d0c94ad73b46fdf", out[0..]);
+ try htest.assertEqual("e642824c3f8cf24ad09234ee7d3c766fc9a3a5168d0c94ad73b46fdf", out[0..]);
}
test "sha3-256 single" {
- htest.assertEqualHash(Sha3_256, "a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a", "");
- htest.assertEqualHash(Sha3_256, "3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532", "abc");
- htest.assertEqualHash(Sha3_256, "916f6061fe879741ca6469b43971dfdb28b1a32dc36cb3254e812be27aad1d18", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
+ try htest.assertEqualHash(Sha3_256, "a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a", "");
+ try htest.assertEqualHash(Sha3_256, "3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532", "abc");
+ try htest.assertEqualHash(Sha3_256, "916f6061fe879741ca6469b43971dfdb28b1a32dc36cb3254e812be27aad1d18", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
}
test "sha3-256 streaming" {
@@ -205,19 +205,19 @@ test "sha3-256 streaming" {
var out: [32]u8 = undefined;
h.final(out[0..]);
- htest.assertEqual("a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a", out[0..]);
+ try htest.assertEqual("a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a", out[0..]);
h = Sha3_256.init(.{});
h.update("abc");
h.final(out[0..]);
- htest.assertEqual("3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532", out[0..]);
+ try htest.assertEqual("3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532", out[0..]);
h = Sha3_256.init(.{});
h.update("a");
h.update("b");
h.update("c");
h.final(out[0..]);
- htest.assertEqual("3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532", out[0..]);
+ try htest.assertEqual("3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532", out[0..]);
}
test "sha3-256 aligned final" {
@@ -231,11 +231,11 @@ test "sha3-256 aligned final" {
test "sha3-384 single" {
const h1 = "0c63a75b845e4f7d01107d852e4c2485c51a50aaaa94fc61995e71bbee983a2ac3713831264adb47fb6bd1e058d5f004";
- htest.assertEqualHash(Sha3_384, h1, "");
+ try htest.assertEqualHash(Sha3_384, h1, "");
const h2 = "ec01498288516fc926459f58e2c6ad8df9b473cb0fc08c2596da7cf0e49be4b298d88cea927ac7f539f1edf228376d25";
- htest.assertEqualHash(Sha3_384, h2, "abc");
+ try htest.assertEqualHash(Sha3_384, h2, "abc");
const h3 = "79407d3b5916b59c3e30b09822974791c313fb9ecc849e406f23592d04f625dc8c709b98b43b3852b337216179aa7fc7";
- htest.assertEqualHash(Sha3_384, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
+ try htest.assertEqualHash(Sha3_384, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
}
test "sha3-384 streaming" {
@@ -244,29 +244,29 @@ test "sha3-384 streaming" {
const h1 = "0c63a75b845e4f7d01107d852e4c2485c51a50aaaa94fc61995e71bbee983a2ac3713831264adb47fb6bd1e058d5f004";
h.final(out[0..]);
- htest.assertEqual(h1, out[0..]);
+ try htest.assertEqual(h1, out[0..]);
const h2 = "ec01498288516fc926459f58e2c6ad8df9b473cb0fc08c2596da7cf0e49be4b298d88cea927ac7f539f1edf228376d25";
h = Sha3_384.init(.{});
h.update("abc");
h.final(out[0..]);
- htest.assertEqual(h2, out[0..]);
+ try htest.assertEqual(h2, out[0..]);
h = Sha3_384.init(.{});
h.update("a");
h.update("b");
h.update("c");
h.final(out[0..]);
- htest.assertEqual(h2, out[0..]);
+ try htest.assertEqual(h2, out[0..]);
}
test "sha3-512 single" {
const h1 = "a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26";
- htest.assertEqualHash(Sha3_512, h1, "");
+ try htest.assertEqualHash(Sha3_512, h1, "");
const h2 = "b751850b1a57168a5693cd924b6b096e08f621827444f70d884f5d0240d2712e10e116e9192af3c91a7ec57647e3934057340b4cf408d5a56592f8274eec53f0";
- htest.assertEqualHash(Sha3_512, h2, "abc");
+ try htest.assertEqualHash(Sha3_512, h2, "abc");
const h3 = "afebb2ef542e6579c50cad06d2e578f9f8dd6881d7dc824d26360feebf18a4fa73e3261122948efcfd492e74e82e2189ed0fb440d187f382270cb455f21dd185";
- htest.assertEqualHash(Sha3_512, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
+ try htest.assertEqualHash(Sha3_512, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
}
test "sha3-512 streaming" {
@@ -275,20 +275,20 @@ test "sha3-512 streaming" {
const h1 = "a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26";
h.final(out[0..]);
- htest.assertEqual(h1, out[0..]);
+ try htest.assertEqual(h1, out[0..]);
const h2 = "b751850b1a57168a5693cd924b6b096e08f621827444f70d884f5d0240d2712e10e116e9192af3c91a7ec57647e3934057340b4cf408d5a56592f8274eec53f0";
h = Sha3_512.init(.{});
h.update("abc");
h.final(out[0..]);
- htest.assertEqual(h2, out[0..]);
+ try htest.assertEqual(h2, out[0..]);
h = Sha3_512.init(.{});
h.update("a");
h.update("b");
h.update("c");
h.final(out[0..]);
- htest.assertEqual(h2, out[0..]);
+ try htest.assertEqual(h2, out[0..]);
}
test "sha3-512 aligned final" {
@@ -301,13 +301,13 @@ test "sha3-512 aligned final" {
}
test "keccak-256 single" {
- htest.assertEqualHash(Keccak_256, "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470", "");
- htest.assertEqualHash(Keccak_256, "4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45", "abc");
- htest.assertEqualHash(Keccak_256, "f519747ed599024f3882238e5ab43960132572b7345fbeb9a90769dafd21ad67", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
+ try htest.assertEqualHash(Keccak_256, "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470", "");
+ try htest.assertEqualHash(Keccak_256, "4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45", "abc");
+ try htest.assertEqualHash(Keccak_256, "f519747ed599024f3882238e5ab43960132572b7345fbeb9a90769dafd21ad67", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
}
test "keccak-512 single" {
- htest.assertEqualHash(Keccak_512, "0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e", "");
- htest.assertEqualHash(Keccak_512, "18587dc2ea106b9a1563e32b3312421ca164c7f1f07bc922a9c83d77cea3a1e5d0c69910739025372dc14ac9642629379540c17e2a65b19d77aa511a9d00bb96", "abc");
- htest.assertEqualHash(Keccak_512, "ac2fb35251825d3aa48468a9948c0a91b8256f6d97d8fa4160faff2dd9dfcc24f3f1db7a983dad13d53439ccac0b37e24037e7b95f80f59f37a2f683c4ba4682", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
+ try htest.assertEqualHash(Keccak_512, "0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e", "");
+ try htest.assertEqualHash(Keccak_512, "18587dc2ea106b9a1563e32b3312421ca164c7f1f07bc922a9c83d77cea3a1e5d0c69910739025372dc14ac9642629379540c17e2a65b19d77aa511a9d00bb96", "abc");
+ try htest.assertEqualHash(Keccak_512, "ac2fb35251825d3aa48468a9948c0a91b8256f6d97d8fa4160faff2dd9dfcc24f3f1db7a983dad13d53439ccac0b37e24037e7b95f80f59f37a2f683c4ba4682", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
}
lib/std/crypto/siphash.zig
@@ -319,7 +319,7 @@ test "siphash64-2-4 sanity" {
var out: [siphash.mac_length]u8 = undefined;
siphash.create(&out, buffer[0..i], test_key);
- testing.expectEqual(out, vector);
+ try testing.expectEqual(out, vector);
}
}
@@ -399,7 +399,7 @@ test "siphash128-2-4 sanity" {
var out: [siphash.mac_length]u8 = undefined;
siphash.create(&out, buffer[0..i], test_key[0..]);
- testing.expectEqual(out, vector);
+ try testing.expectEqual(out, vector);
}
}
@@ -423,6 +423,6 @@ test "iterative non-divisible update" {
}
const iterative_hash = siphash.finalInt();
- std.testing.expectEqual(iterative_hash, non_iterative_hash);
+ try std.testing.expectEqual(iterative_hash, non_iterative_hash);
}
}
lib/std/crypto/test.zig
@@ -8,19 +8,19 @@ const testing = std.testing;
const fmt = std.fmt;
// Hash using the specified hasher `H` asserting `expected == H(input)`.
-pub fn assertEqualHash(comptime Hasher: anytype, comptime expected_hex: *const [Hasher.digest_length * 2:0]u8, input: []const u8) void {
+pub fn assertEqualHash(comptime Hasher: anytype, comptime expected_hex: *const [Hasher.digest_length * 2:0]u8, input: []const u8) !void {
var h: [Hasher.digest_length]u8 = undefined;
Hasher.hash(input, &h, .{});
- assertEqual(expected_hex, &h);
+ try assertEqual(expected_hex, &h);
}
// Assert `expected` == hex(`input`) where `input` is a bytestring
-pub fn assertEqual(comptime expected_hex: [:0]const u8, input: []const u8) void {
+pub fn assertEqual(comptime expected_hex: [:0]const u8, input: []const u8) !void {
var expected_bytes: [expected_hex.len / 2]u8 = undefined;
for (expected_bytes) |*r, i| {
r.* = fmt.parseInt(u8, expected_hex[2 * i .. 2 * i + 2], 16) catch unreachable;
}
- testing.expectEqualSlices(u8, &expected_bytes, input);
+ try testing.expectEqualSlices(u8, &expected_bytes, input);
}
lib/std/crypto/utils.zig
@@ -92,9 +92,9 @@ test "crypto.utils.timingSafeEql" {
var b: [100]u8 = undefined;
std.crypto.random.bytes(a[0..]);
std.crypto.random.bytes(b[0..]);
- testing.expect(!timingSafeEql([100]u8, a, b));
+ try testing.expect(!timingSafeEql([100]u8, a, b));
mem.copy(u8, a[0..], b[0..]);
- testing.expect(timingSafeEql([100]u8, a, b));
+ try testing.expect(timingSafeEql([100]u8, a, b));
}
test "crypto.utils.timingSafeEql (vectors)" {
@@ -104,22 +104,22 @@ test "crypto.utils.timingSafeEql (vectors)" {
std.crypto.random.bytes(b[0..]);
const v1: std.meta.Vector(100, u8) = a;
const v2: std.meta.Vector(100, u8) = b;
- testing.expect(!timingSafeEql(std.meta.Vector(100, u8), v1, v2));
+ try testing.expect(!timingSafeEql(std.meta.Vector(100, u8), v1, v2));
const v3: std.meta.Vector(100, u8) = a;
- testing.expect(timingSafeEql(std.meta.Vector(100, u8), v1, v3));
+ try testing.expect(timingSafeEql(std.meta.Vector(100, u8), v1, v3));
}
test "crypto.utils.timingSafeCompare" {
var a = [_]u8{10} ** 32;
var b = [_]u8{10} ** 32;
- testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .eq);
- testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .eq);
+ try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .eq);
+ try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .eq);
a[31] = 1;
- testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .lt);
- testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .lt);
+ try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .lt);
+ try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .lt);
a[0] = 20;
- testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .gt);
- testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .lt);
+ try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .gt);
+ try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .lt);
}
test "crypto.utils.secureZero" {
@@ -129,5 +129,5 @@ test "crypto.utils.secureZero" {
mem.set(u8, a[0..], 0);
secureZero(u8, b[0..]);
- testing.expectEqualSlices(u8, a[0..], b[0..]);
+ try testing.expectEqualSlices(u8, a[0..], b[0..]);
}
lib/std/event/batch.zig
@@ -119,12 +119,12 @@ test "std.event.Batch" {
batch.add(&async sleepALittle(&count));
batch.add(&async increaseByTen(&count));
batch.wait();
- testing.expect(count == 11);
+ try testing.expect(count == 11);
var another = Batch(anyerror!void, 2, .auto_async).init();
another.add(&async somethingElse());
another.add(&async doSomethingThatFails());
- testing.expectError(error.ItBroke, another.wait());
+ try testing.expectError(error.ItBroke, another.wait());
}
fn sleepALittle(count: *usize) void {
lib/std/event/channel.zig
@@ -310,25 +310,25 @@ test "std.event.Channel wraparound" {
// the buffer wraps around, make sure it doesn't crash.
var result: i32 = undefined;
channel.put(5);
- testing.expectEqual(@as(i32, 5), channel.get());
+ try testing.expectEqual(@as(i32, 5), channel.get());
channel.put(6);
- testing.expectEqual(@as(i32, 6), channel.get());
+ try testing.expectEqual(@as(i32, 6), channel.get());
channel.put(7);
- testing.expectEqual(@as(i32, 7), channel.get());
+ try testing.expectEqual(@as(i32, 7), channel.get());
}
fn testChannelGetter(channel: *Channel(i32)) callconv(.Async) void {
const value1 = channel.get();
- testing.expect(value1 == 1234);
+ try testing.expect(value1 == 1234);
const value2 = channel.get();
- testing.expect(value2 == 4567);
+ try testing.expect(value2 == 4567);
const value3 = channel.getOrNull();
- testing.expect(value3 == null);
+ try testing.expect(value3 == null);
var last_put = async testPut(channel, 4444);
const value4 = channel.getOrNull();
- testing.expect(value4.? == 4444);
+ try testing.expect(value4.? == 4444);
await last_put;
}
fn testChannelPutter(channel: *Channel(i32)) callconv(.Async) void {
lib/std/event/future.zig
@@ -107,7 +107,7 @@ fn testFuture() void {
const result = (await a) + (await b);
- testing.expect(result == 12);
+ try testing.expect(result == 12);
}
fn waitOnFuture(future: *Future(i32)) i32 {
lib/std/event/group.zig
@@ -140,14 +140,14 @@ fn testGroup(allocator: *Allocator) callconv(.Async) void {
var increase_by_ten_frame = async increaseByTen(&count);
group.add(&increase_by_ten_frame) catch @panic("memory");
group.wait();
- testing.expect(count == 11);
+ try testing.expect(count == 11);
var another = Group(anyerror!void).init(allocator);
var something_else_frame = async somethingElse();
another.add(&something_else_frame) catch @panic("memory");
var something_that_fails_frame = async doSomethingThatFails();
another.add(&something_that_fails_frame) catch @panic("memory");
- testing.expectError(error.ItBroke, another.wait());
+ try testing.expectError(error.ItBroke, another.wait());
}
fn sleepALittle(count: *usize) callconv(.Async) void {
std.time.sleep(1 * std.time.ns_per_ms);
lib/std/event/lock.zig
@@ -136,7 +136,7 @@ test "std.event.Lock" {
testLock(&lock);
const expected_result = [1]i32{3 * @intCast(i32, shared_test_data.len)} ** shared_test_data.len;
- testing.expectEqualSlices(i32, &expected_result, &shared_test_data);
+ try testing.expectEqualSlices(i32, &expected_result, &shared_test_data);
}
fn testLock(lock: *Lock) void {
var handle1 = async lockRunner(lock);
lib/std/event/loop.zig
@@ -1655,7 +1655,7 @@ fn testEventLoop() i32 {
fn testEventLoop2(h: anyframe->i32, did_it: *bool) void {
const value = await h;
- testing.expect(value == 1234);
+ try testing.expect(value == 1234);
did_it.* = true;
}
@@ -1682,7 +1682,7 @@ test "std.event.Loop - runDetached" {
// with the previous runDetached.
loop.run();
- testing.expect(testRunDetachedData == 1);
+ try testing.expect(testRunDetachedData == 1);
}
fn testRunDetached() void {
@@ -1705,7 +1705,7 @@ test "std.event.Loop - sleep" {
for (frames) |*frame|
await frame;
- testing.expect(sleep_count == frames.len);
+ try testing.expect(sleep_count == frames.len);
}
fn testSleep(wait_ns: u64, sleep_count: *usize) void {
lib/std/event/rwlock.zig
@@ -228,7 +228,7 @@ test "std.event.RwLock" {
const handle = testLock(std.heap.page_allocator, &lock);
const expected_result = [1]i32{shared_it_count * @intCast(i32, shared_test_data.len)} ** shared_test_data.len;
- testing.expectEqualSlices(i32, expected_result, shared_test_data);
+ try testing.expectEqualSlices(i32, expected_result, shared_test_data);
}
fn testLock(allocator: *Allocator, lock: *RwLock) callconv(.Async) void {
var read_nodes: [100]Loop.NextTickNode = undefined;
@@ -290,7 +290,7 @@ fn readRunner(lock: *RwLock) callconv(.Async) void {
const handle = await lock_promise;
defer handle.release();
- testing.expect(shared_test_index == 0);
- testing.expect(shared_test_data[i] == @intCast(i32, shared_count));
+ try testing.expect(shared_test_index == 0);
+ try testing.expect(shared_test_data[i] == @intCast(i32, shared_count));
}
}
lib/std/fmt/parse_float.zig
@@ -376,44 +376,44 @@ test "fmt.parseFloat" {
inline for ([_]type{ f16, f32, f64, f128 }) |T| {
const Z = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);
- testing.expectError(error.InvalidCharacter, parseFloat(T, ""));
- testing.expectError(error.InvalidCharacter, parseFloat(T, " 1"));
- testing.expectError(error.InvalidCharacter, parseFloat(T, "1abc"));
- testing.expectError(error.InvalidCharacter, parseFloat(T, "+"));
- testing.expectError(error.InvalidCharacter, parseFloat(T, "-"));
+ try testing.expectError(error.InvalidCharacter, parseFloat(T, ""));
+ try testing.expectError(error.InvalidCharacter, parseFloat(T, " 1"));
+ try testing.expectError(error.InvalidCharacter, parseFloat(T, "1abc"));
+ try testing.expectError(error.InvalidCharacter, parseFloat(T, "+"));
+ try testing.expectError(error.InvalidCharacter, parseFloat(T, "-"));
- expectEqual(try parseFloat(T, "0"), 0.0);
- expectEqual(try parseFloat(T, "0"), 0.0);
- expectEqual(try parseFloat(T, "+0"), 0.0);
- expectEqual(try parseFloat(T, "-0"), 0.0);
+ try expectEqual(try parseFloat(T, "0"), 0.0);
+ try expectEqual(try parseFloat(T, "0"), 0.0);
+ try expectEqual(try parseFloat(T, "+0"), 0.0);
+ try expectEqual(try parseFloat(T, "-0"), 0.0);
- expectEqual(try parseFloat(T, "0e0"), 0);
- expectEqual(try parseFloat(T, "2e3"), 2000.0);
- expectEqual(try parseFloat(T, "1e0"), 1.0);
- expectEqual(try parseFloat(T, "-2e3"), -2000.0);
- expectEqual(try parseFloat(T, "-1e0"), -1.0);
- expectEqual(try parseFloat(T, "1.234e3"), 1234);
+ try expectEqual(try parseFloat(T, "0e0"), 0);
+ try expectEqual(try parseFloat(T, "2e3"), 2000.0);
+ try expectEqual(try parseFloat(T, "1e0"), 1.0);
+ try expectEqual(try parseFloat(T, "-2e3"), -2000.0);
+ try expectEqual(try parseFloat(T, "-1e0"), -1.0);
+ try expectEqual(try parseFloat(T, "1.234e3"), 1234);
- expect(approxEqAbs(T, try parseFloat(T, "3.141"), 3.141, epsilon));
- expect(approxEqAbs(T, try parseFloat(T, "-3.141"), -3.141, epsilon));
+ try expect(approxEqAbs(T, try parseFloat(T, "3.141"), 3.141, epsilon));
+ try expect(approxEqAbs(T, try parseFloat(T, "-3.141"), -3.141, epsilon));
- expectEqual(try parseFloat(T, "1e-700"), 0);
- expectEqual(try parseFloat(T, "1e+700"), std.math.inf(T));
+ try expectEqual(try parseFloat(T, "1e-700"), 0);
+ try expectEqual(try parseFloat(T, "1e+700"), std.math.inf(T));
- expectEqual(@bitCast(Z, try parseFloat(T, "nAn")), @bitCast(Z, std.math.nan(T)));
- expectEqual(try parseFloat(T, "inF"), std.math.inf(T));
- expectEqual(try parseFloat(T, "-INF"), -std.math.inf(T));
+ try expectEqual(@bitCast(Z, try parseFloat(T, "nAn")), @bitCast(Z, std.math.nan(T)));
+ try expectEqual(try parseFloat(T, "inF"), std.math.inf(T));
+ try expectEqual(try parseFloat(T, "-INF"), -std.math.inf(T));
- expectEqual(try parseFloat(T, "0.4e0066999999999999999999999999999999999999999999999999999"), std.math.inf(T));
+ try expectEqual(try parseFloat(T, "0.4e0066999999999999999999999999999999999999999999999999999"), std.math.inf(T));
if (T != f16) {
- expect(approxEqAbs(T, try parseFloat(T, "1e-2"), 0.01, epsilon));
- expect(approxEqAbs(T, try parseFloat(T, "1234e-2"), 12.34, epsilon));
+ try expect(approxEqAbs(T, try parseFloat(T, "1e-2"), 0.01, epsilon));
+ try expect(approxEqAbs(T, try parseFloat(T, "1234e-2"), 12.34, epsilon));
- expect(approxEqAbs(T, try parseFloat(T, "123142.1"), 123142.1, epsilon));
- expect(approxEqAbs(T, try parseFloat(T, "-123142.1124"), @as(T, -123142.1124), epsilon));
- expect(approxEqAbs(T, try parseFloat(T, "0.7062146892655368"), @as(T, 0.7062146892655368), epsilon));
- expect(approxEqAbs(T, try parseFloat(T, "2.71828182845904523536"), @as(T, 2.718281828459045), epsilon));
+ try expect(approxEqAbs(T, try parseFloat(T, "123142.1"), 123142.1, epsilon));
+ try expect(approxEqAbs(T, try parseFloat(T, "-123142.1124"), @as(T, -123142.1124), epsilon));
+ try expect(approxEqAbs(T, try parseFloat(T, "0.7062146892655368"), @as(T, 0.7062146892655368), epsilon));
+ try expect(approxEqAbs(T, try parseFloat(T, "2.71828182845904523536"), @as(T, 2.718281828459045), epsilon));
}
}
}
lib/std/fmt/parse_hex_float.zig
@@ -247,17 +247,17 @@ pub fn parseHexFloat(comptime T: type, s: []const u8) !T {
}
test "special" {
- testing.expect(math.isNan(try parseHexFloat(f32, "nAn")));
- testing.expect(math.isPositiveInf(try parseHexFloat(f32, "iNf")));
- testing.expect(math.isPositiveInf(try parseHexFloat(f32, "+Inf")));
- testing.expect(math.isNegativeInf(try parseHexFloat(f32, "-iNf")));
+ try testing.expect(math.isNan(try parseHexFloat(f32, "nAn")));
+ try testing.expect(math.isPositiveInf(try parseHexFloat(f32, "iNf")));
+ try testing.expect(math.isPositiveInf(try parseHexFloat(f32, "+Inf")));
+ try testing.expect(math.isNegativeInf(try parseHexFloat(f32, "-iNf")));
}
test "zero" {
- testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "0x0"));
- testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "-0x0"));
- testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "0x0p42"));
- testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "-0x0.00000p42"));
- testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "0x0.00000p666"));
+ try testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "0x0"));
+ try testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "-0x0"));
+ try testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "0x0p42"));
+ try testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "-0x0.00000p42"));
+ try testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "0x0.00000p666"));
}
test "f16" {
@@ -279,7 +279,7 @@ test "f16" {
};
for (cases) |case| {
- testing.expectEqual(case.v, try parseHexFloat(f16, case.s));
+ try testing.expectEqual(case.v, try parseHexFloat(f16, case.s));
}
}
test "f32" {
@@ -303,7 +303,7 @@ test "f32" {
};
for (cases) |case| {
- testing.expectEqual(case.v, try parseHexFloat(f32, case.s));
+ try testing.expectEqual(case.v, try parseHexFloat(f32, case.s));
}
}
test "f64" {
@@ -325,7 +325,7 @@ test "f64" {
};
for (cases) |case| {
- testing.expectEqual(case.v, try parseHexFloat(f64, case.s));
+ try testing.expectEqual(case.v, try parseHexFloat(f64, case.s));
}
}
test "f128" {
@@ -347,6 +347,6 @@ test "f128" {
};
for (cases) |case| {
- testing.expectEqual(@bitCast(u128, case.v), @bitCast(u128, try parseHexFloat(f128, case.s)));
+ try testing.expectEqual(@bitCast(u128, case.v), @bitCast(u128, try parseHexFloat(f128, case.s)));
}
}
lib/std/fs/path.zig
@@ -96,72 +96,72 @@ pub fn joinZ(allocator: *Allocator, paths: []const []const u8) ![:0]u8 {
return out[0 .. out.len - 1 :0];
}
-fn testJoinMaybeZWindows(paths: []const []const u8, expected: []const u8, zero: bool) void {
+fn testJoinMaybeZWindows(paths: []const []const u8, expected: []const u8, zero: bool) !void {
const windowsIsSep = struct {
fn isSep(byte: u8) bool {
return byte == '/' or byte == '\\';
}
}.isSep;
- const actual = joinSepMaybeZ(testing.allocator, sep_windows, windowsIsSep, paths, zero) catch @panic("fail");
+ const actual = try joinSepMaybeZ(testing.allocator, sep_windows, windowsIsSep, paths, zero);
defer testing.allocator.free(actual);
- testing.expectEqualSlices(u8, expected, if (zero) actual[0 .. actual.len - 1 :0] else actual);
+ try testing.expectEqualSlices(u8, expected, if (zero) actual[0 .. actual.len - 1 :0] else actual);
}
-fn testJoinMaybeZPosix(paths: []const []const u8, expected: []const u8, zero: bool) void {
+fn testJoinMaybeZPosix(paths: []const []const u8, expected: []const u8, zero: bool) !void {
const posixIsSep = struct {
fn isSep(byte: u8) bool {
return byte == '/';
}
}.isSep;
- const actual = joinSepMaybeZ(testing.allocator, sep_posix, posixIsSep, paths, zero) catch @panic("fail");
+ const actual = try joinSepMaybeZ(testing.allocator, sep_posix, posixIsSep, paths, zero);
defer testing.allocator.free(actual);
- testing.expectEqualSlices(u8, expected, if (zero) actual[0 .. actual.len - 1 :0] else actual);
+ try testing.expectEqualSlices(u8, expected, if (zero) actual[0 .. actual.len - 1 :0] else actual);
}
test "join" {
{
const actual: []u8 = try join(testing.allocator, &[_][]const u8{});
defer testing.allocator.free(actual);
- testing.expectEqualSlices(u8, "", actual);
+ try testing.expectEqualSlices(u8, "", actual);
}
{
const actual: [:0]u8 = try joinZ(testing.allocator, &[_][]const u8{});
defer testing.allocator.free(actual);
- testing.expectEqualSlices(u8, "", actual);
+ try testing.expectEqualSlices(u8, "", actual);
}
for (&[_]bool{ false, true }) |zero| {
- testJoinMaybeZWindows(&[_][]const u8{}, "", zero);
- testJoinMaybeZWindows(&[_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c", zero);
- testJoinMaybeZWindows(&[_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c", zero);
- testJoinMaybeZWindows(&[_][]const u8{ "c:\\a\\b\\", "c" }, "c:\\a\\b\\c", zero);
+ try testJoinMaybeZWindows(&[_][]const u8{}, "", zero);
+ try testJoinMaybeZWindows(&[_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c", zero);
+ try testJoinMaybeZWindows(&[_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c", zero);
+ try testJoinMaybeZWindows(&[_][]const u8{ "c:\\a\\b\\", "c" }, "c:\\a\\b\\c", zero);
- testJoinMaybeZWindows(&[_][]const u8{ "c:\\", "a", "b\\", "c" }, "c:\\a\\b\\c", zero);
- testJoinMaybeZWindows(&[_][]const u8{ "c:\\a\\", "b\\", "c" }, "c:\\a\\b\\c", zero);
+ try testJoinMaybeZWindows(&[_][]const u8{ "c:\\", "a", "b\\", "c" }, "c:\\a\\b\\c", zero);
+ try testJoinMaybeZWindows(&[_][]const u8{ "c:\\a\\", "b\\", "c" }, "c:\\a\\b\\c", zero);
- testJoinMaybeZWindows(
+ try testJoinMaybeZWindows(
&[_][]const u8{ "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std", "io.zig" },
"c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std\\io.zig",
zero,
);
- testJoinMaybeZWindows(&[_][]const u8{ "c:\\", "a", "b/", "c" }, "c:\\a\\b/c", zero);
- testJoinMaybeZWindows(&[_][]const u8{ "c:\\a/", "b\\", "/c" }, "c:\\a/b\\c", zero);
+ try testJoinMaybeZWindows(&[_][]const u8{ "c:\\", "a", "b/", "c" }, "c:\\a\\b/c", zero);
+ try testJoinMaybeZWindows(&[_][]const u8{ "c:\\a/", "b\\", "/c" }, "c:\\a/b\\c", zero);
- testJoinMaybeZPosix(&[_][]const u8{}, "", zero);
- testJoinMaybeZPosix(&[_][]const u8{ "/a/b", "c" }, "/a/b/c", zero);
- testJoinMaybeZPosix(&[_][]const u8{ "/a/b/", "c" }, "/a/b/c", zero);
+ try testJoinMaybeZPosix(&[_][]const u8{}, "", zero);
+ try testJoinMaybeZPosix(&[_][]const u8{ "/a/b", "c" }, "/a/b/c", zero);
+ try testJoinMaybeZPosix(&[_][]const u8{ "/a/b/", "c" }, "/a/b/c", zero);
- testJoinMaybeZPosix(&[_][]const u8{ "/", "a", "b/", "c" }, "/a/b/c", zero);
- testJoinMaybeZPosix(&[_][]const u8{ "/a/", "b/", "c" }, "/a/b/c", zero);
+ try testJoinMaybeZPosix(&[_][]const u8{ "/", "a", "b/", "c" }, "/a/b/c", zero);
+ try testJoinMaybeZPosix(&[_][]const u8{ "/a/", "b/", "c" }, "/a/b/c", zero);
- testJoinMaybeZPosix(
+ try testJoinMaybeZPosix(
&[_][]const u8{ "/home/andy/dev/zig/build/lib/zig/std", "io.zig" },
"/home/andy/dev/zig/build/lib/zig/std/io.zig",
zero,
);
- testJoinMaybeZPosix(&[_][]const u8{ "a", "/c" }, "a/c", zero);
- testJoinMaybeZPosix(&[_][]const u8{ "a/", "/c" }, "a/c", zero);
+ try testJoinMaybeZPosix(&[_][]const u8{ "a", "/c" }, "a/c", zero);
+ try testJoinMaybeZPosix(&[_][]const u8{ "a/", "/c" }, "a/c", zero);
}
}
@@ -235,42 +235,42 @@ pub fn isAbsolutePosixZ(path_c: [*:0]const u8) bool {
}
test "isAbsoluteWindows" {
- testIsAbsoluteWindows("", false);
- testIsAbsoluteWindows("/", true);
- testIsAbsoluteWindows("//", true);
- testIsAbsoluteWindows("//server", true);
- testIsAbsoluteWindows("//server/file", true);
- testIsAbsoluteWindows("\\\\server\\file", true);
- testIsAbsoluteWindows("\\\\server", true);
- testIsAbsoluteWindows("\\\\", true);
- testIsAbsoluteWindows("c", false);
- testIsAbsoluteWindows("c:", false);
- testIsAbsoluteWindows("c:\\", true);
- testIsAbsoluteWindows("c:/", true);
- testIsAbsoluteWindows("c://", true);
- testIsAbsoluteWindows("C:/Users/", true);
- testIsAbsoluteWindows("C:\\Users\\", true);
- testIsAbsoluteWindows("C:cwd/another", false);
- testIsAbsoluteWindows("C:cwd\\another", false);
- testIsAbsoluteWindows("directory/directory", false);
- testIsAbsoluteWindows("directory\\directory", false);
- testIsAbsoluteWindows("/usr/local", true);
+ try testIsAbsoluteWindows("", false);
+ try testIsAbsoluteWindows("/", true);
+ try testIsAbsoluteWindows("//", true);
+ try testIsAbsoluteWindows("//server", true);
+ try testIsAbsoluteWindows("//server/file", true);
+ try testIsAbsoluteWindows("\\\\server\\file", true);
+ try testIsAbsoluteWindows("\\\\server", true);
+ try testIsAbsoluteWindows("\\\\", true);
+ try testIsAbsoluteWindows("c", false);
+ try testIsAbsoluteWindows("c:", false);
+ try testIsAbsoluteWindows("c:\\", true);
+ try testIsAbsoluteWindows("c:/", true);
+ try testIsAbsoluteWindows("c://", true);
+ try testIsAbsoluteWindows("C:/Users/", true);
+ try testIsAbsoluteWindows("C:\\Users\\", true);
+ try testIsAbsoluteWindows("C:cwd/another", false);
+ try testIsAbsoluteWindows("C:cwd\\another", false);
+ try testIsAbsoluteWindows("directory/directory", false);
+ try testIsAbsoluteWindows("directory\\directory", false);
+ try testIsAbsoluteWindows("/usr/local", true);
}
test "isAbsolutePosix" {
- testIsAbsolutePosix("", false);
- testIsAbsolutePosix("/home/foo", true);
- testIsAbsolutePosix("/home/foo/..", true);
- testIsAbsolutePosix("bar/", false);
- testIsAbsolutePosix("./baz", false);
+ try testIsAbsolutePosix("", false);
+ try testIsAbsolutePosix("/home/foo", true);
+ try testIsAbsolutePosix("/home/foo/..", true);
+ try testIsAbsolutePosix("bar/", false);
+ try testIsAbsolutePosix("./baz", false);
}
-fn testIsAbsoluteWindows(path: []const u8, expected_result: bool) void {
- testing.expectEqual(expected_result, isAbsoluteWindows(path));
+fn testIsAbsoluteWindows(path: []const u8, expected_result: bool) !void {
+ try testing.expectEqual(expected_result, isAbsoluteWindows(path));
}
-fn testIsAbsolutePosix(path: []const u8, expected_result: bool) void {
- testing.expectEqual(expected_result, isAbsolutePosix(path));
+fn testIsAbsolutePosix(path: []const u8, expected_result: bool) !void {
+ try testing.expectEqual(expected_result, isAbsolutePosix(path));
}
pub const WindowsPath = struct {
@@ -334,33 +334,33 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {
test "windowsParsePath" {
{
const parsed = windowsParsePath("//a/b");
- testing.expect(parsed.is_abs);
- testing.expect(parsed.kind == WindowsPath.Kind.NetworkShare);
- testing.expect(mem.eql(u8, parsed.disk_designator, "//a/b"));
+ try testing.expect(parsed.is_abs);
+ try testing.expect(parsed.kind == WindowsPath.Kind.NetworkShare);
+ try testing.expect(mem.eql(u8, parsed.disk_designator, "//a/b"));
}
{
const parsed = windowsParsePath("\\\\a\\b");
- testing.expect(parsed.is_abs);
- testing.expect(parsed.kind == WindowsPath.Kind.NetworkShare);
- testing.expect(mem.eql(u8, parsed.disk_designator, "\\\\a\\b"));
+ try testing.expect(parsed.is_abs);
+ try testing.expect(parsed.kind == WindowsPath.Kind.NetworkShare);
+ try testing.expect(mem.eql(u8, parsed.disk_designator, "\\\\a\\b"));
}
{
const parsed = windowsParsePath("\\\\a\\");
- testing.expect(!parsed.is_abs);
- testing.expect(parsed.kind == WindowsPath.Kind.None);
- testing.expect(mem.eql(u8, parsed.disk_designator, ""));
+ try testing.expect(!parsed.is_abs);
+ try testing.expect(parsed.kind == WindowsPath.Kind.None);
+ try testing.expect(mem.eql(u8, parsed.disk_designator, ""));
}
{
const parsed = windowsParsePath("/usr/local");
- testing.expect(parsed.is_abs);
- testing.expect(parsed.kind == WindowsPath.Kind.None);
- testing.expect(mem.eql(u8, parsed.disk_designator, ""));
+ try testing.expect(parsed.is_abs);
+ try testing.expect(parsed.kind == WindowsPath.Kind.None);
+ try testing.expect(mem.eql(u8, parsed.disk_designator, ""));
}
{
const parsed = windowsParsePath("c:../");
- testing.expect(!parsed.is_abs);
- testing.expect(parsed.kind == WindowsPath.Kind.Drive);
- testing.expect(mem.eql(u8, parsed.disk_designator, "c:"));
+ try testing.expect(!parsed.is_abs);
+ try testing.expect(parsed.kind == WindowsPath.Kind.Drive);
+ try testing.expect(mem.eql(u8, parsed.disk_designator, "c:"));
}
}
@@ -772,13 +772,13 @@ test "resolvePosix" {
fn testResolveWindows(paths: []const []const u8, expected: []const u8) !void {
const actual = try resolveWindows(testing.allocator, paths);
defer testing.allocator.free(actual);
- return testing.expect(mem.eql(u8, actual, expected));
+ try testing.expect(mem.eql(u8, actual, expected));
}
fn testResolvePosix(paths: []const []const u8, expected: []const u8) !void {
const actual = try resolvePosix(testing.allocator, paths);
defer testing.allocator.free(actual);
- return testing.expect(mem.eql(u8, actual, expected));
+ try testing.expect(mem.eql(u8, actual, expected));
}
/// Strip the last component from a file path.
@@ -856,68 +856,68 @@ pub fn dirnamePosix(path: []const u8) ?[]const u8 {
}
test "dirnamePosix" {
- testDirnamePosix("/a/b/c", "/a/b");
- testDirnamePosix("/a/b/c///", "/a/b");
- testDirnamePosix("/a", "/");
- testDirnamePosix("/", null);
- testDirnamePosix("//", null);
- testDirnamePosix("///", null);
- testDirnamePosix("////", null);
- testDirnamePosix("", null);
- testDirnamePosix("a", null);
- testDirnamePosix("a/", null);
- testDirnamePosix("a//", null);
+ try testDirnamePosix("/a/b/c", "/a/b");
+ try testDirnamePosix("/a/b/c///", "/a/b");
+ try testDirnamePosix("/a", "/");
+ try testDirnamePosix("/", null);
+ try testDirnamePosix("//", null);
+ try testDirnamePosix("///", null);
+ try testDirnamePosix("////", null);
+ try testDirnamePosix("", null);
+ try testDirnamePosix("a", null);
+ try testDirnamePosix("a/", null);
+ try testDirnamePosix("a//", null);
}
test "dirnameWindows" {
- testDirnameWindows("c:\\", null);
- testDirnameWindows("c:\\foo", "c:\\");
- testDirnameWindows("c:\\foo\\", "c:\\");
- testDirnameWindows("c:\\foo\\bar", "c:\\foo");
- testDirnameWindows("c:\\foo\\bar\\", "c:\\foo");
- testDirnameWindows("c:\\foo\\bar\\baz", "c:\\foo\\bar");
- testDirnameWindows("\\", null);
- testDirnameWindows("\\foo", "\\");
- testDirnameWindows("\\foo\\", "\\");
- testDirnameWindows("\\foo\\bar", "\\foo");
- testDirnameWindows("\\foo\\bar\\", "\\foo");
- testDirnameWindows("\\foo\\bar\\baz", "\\foo\\bar");
- testDirnameWindows("c:", null);
- testDirnameWindows("c:foo", null);
- testDirnameWindows("c:foo\\", null);
- testDirnameWindows("c:foo\\bar", "c:foo");
- testDirnameWindows("c:foo\\bar\\", "c:foo");
- testDirnameWindows("c:foo\\bar\\baz", "c:foo\\bar");
- testDirnameWindows("file:stream", null);
- testDirnameWindows("dir\\file:stream", "dir");
- testDirnameWindows("\\\\unc\\share", null);
- testDirnameWindows("\\\\unc\\share\\foo", "\\\\unc\\share\\");
- testDirnameWindows("\\\\unc\\share\\foo\\", "\\\\unc\\share\\");
- testDirnameWindows("\\\\unc\\share\\foo\\bar", "\\\\unc\\share\\foo");
- testDirnameWindows("\\\\unc\\share\\foo\\bar\\", "\\\\unc\\share\\foo");
- testDirnameWindows("\\\\unc\\share\\foo\\bar\\baz", "\\\\unc\\share\\foo\\bar");
- testDirnameWindows("/a/b/", "/a");
- testDirnameWindows("/a/b", "/a");
- testDirnameWindows("/a", "/");
- testDirnameWindows("", null);
- testDirnameWindows("/", null);
- testDirnameWindows("////", null);
- testDirnameWindows("foo", null);
+ try testDirnameWindows("c:\\", null);
+ try testDirnameWindows("c:\\foo", "c:\\");
+ try testDirnameWindows("c:\\foo\\", "c:\\");
+ try testDirnameWindows("c:\\foo\\bar", "c:\\foo");
+ try testDirnameWindows("c:\\foo\\bar\\", "c:\\foo");
+ try testDirnameWindows("c:\\foo\\bar\\baz", "c:\\foo\\bar");
+ try testDirnameWindows("\\", null);
+ try testDirnameWindows("\\foo", "\\");
+ try testDirnameWindows("\\foo\\", "\\");
+ try testDirnameWindows("\\foo\\bar", "\\foo");
+ try testDirnameWindows("\\foo\\bar\\", "\\foo");
+ try testDirnameWindows("\\foo\\bar\\baz", "\\foo\\bar");
+ try testDirnameWindows("c:", null);
+ try testDirnameWindows("c:foo", null);
+ try testDirnameWindows("c:foo\\", null);
+ try testDirnameWindows("c:foo\\bar", "c:foo");
+ try testDirnameWindows("c:foo\\bar\\", "c:foo");
+ try testDirnameWindows("c:foo\\bar\\baz", "c:foo\\bar");
+ try testDirnameWindows("file:stream", null);
+ try testDirnameWindows("dir\\file:stream", "dir");
+ try testDirnameWindows("\\\\unc\\share", null);
+ try testDirnameWindows("\\\\unc\\share\\foo", "\\\\unc\\share\\");
+ try testDirnameWindows("\\\\unc\\share\\foo\\", "\\\\unc\\share\\");
+ try testDirnameWindows("\\\\unc\\share\\foo\\bar", "\\\\unc\\share\\foo");
+ try testDirnameWindows("\\\\unc\\share\\foo\\bar\\", "\\\\unc\\share\\foo");
+ try testDirnameWindows("\\\\unc\\share\\foo\\bar\\baz", "\\\\unc\\share\\foo\\bar");
+ try testDirnameWindows("/a/b/", "/a");
+ try testDirnameWindows("/a/b", "/a");
+ try testDirnameWindows("/a", "/");
+ try testDirnameWindows("", null);
+ try testDirnameWindows("/", null);
+ try testDirnameWindows("////", null);
+ try testDirnameWindows("foo", null);
}
-fn testDirnamePosix(input: []const u8, expected_output: ?[]const u8) void {
+fn testDirnamePosix(input: []const u8, expected_output: ?[]const u8) !void {
if (dirnamePosix(input)) |output| {
- testing.expect(mem.eql(u8, output, expected_output.?));
+ try testing.expect(mem.eql(u8, output, expected_output.?));
} else {
- testing.expect(expected_output == null);
+ try testing.expect(expected_output == null);
}
}
-fn testDirnameWindows(input: []const u8, expected_output: ?[]const u8) void {
+fn testDirnameWindows(input: []const u8, expected_output: ?[]const u8) !void {
if (dirnameWindows(input)) |output| {
- testing.expect(mem.eql(u8, output, expected_output.?));
+ try testing.expect(mem.eql(u8, output, expected_output.?));
} else {
- testing.expect(expected_output == null);
+ try testing.expect(expected_output == null);
}
}
@@ -983,54 +983,54 @@ pub fn basenameWindows(path: []const u8) []const u8 {
}
test "basename" {
- testBasename("", "");
- testBasename("/", "");
- testBasename("/dir/basename.ext", "basename.ext");
- testBasename("/basename.ext", "basename.ext");
- testBasename("basename.ext", "basename.ext");
- testBasename("basename.ext/", "basename.ext");
- testBasename("basename.ext//", "basename.ext");
- testBasename("/aaa/bbb", "bbb");
- testBasename("/aaa/", "aaa");
- testBasename("/aaa/b", "b");
- testBasename("/a/b", "b");
- testBasename("//a", "a");
-
- testBasenamePosix("\\dir\\basename.ext", "\\dir\\basename.ext");
- testBasenamePosix("\\basename.ext", "\\basename.ext");
- testBasenamePosix("basename.ext", "basename.ext");
- testBasenamePosix("basename.ext\\", "basename.ext\\");
- testBasenamePosix("basename.ext\\\\", "basename.ext\\\\");
- testBasenamePosix("foo", "foo");
-
- testBasenameWindows("\\dir\\basename.ext", "basename.ext");
- testBasenameWindows("\\basename.ext", "basename.ext");
- testBasenameWindows("basename.ext", "basename.ext");
- testBasenameWindows("basename.ext\\", "basename.ext");
- testBasenameWindows("basename.ext\\\\", "basename.ext");
- testBasenameWindows("foo", "foo");
- testBasenameWindows("C:", "");
- testBasenameWindows("C:.", ".");
- testBasenameWindows("C:\\", "");
- testBasenameWindows("C:\\dir\\base.ext", "base.ext");
- testBasenameWindows("C:\\basename.ext", "basename.ext");
- testBasenameWindows("C:basename.ext", "basename.ext");
- testBasenameWindows("C:basename.ext\\", "basename.ext");
- testBasenameWindows("C:basename.ext\\\\", "basename.ext");
- testBasenameWindows("C:foo", "foo");
- testBasenameWindows("file:stream", "file:stream");
+ try testBasename("", "");
+ try testBasename("/", "");
+ try testBasename("/dir/basename.ext", "basename.ext");
+ try testBasename("/basename.ext", "basename.ext");
+ try testBasename("basename.ext", "basename.ext");
+ try testBasename("basename.ext/", "basename.ext");
+ try testBasename("basename.ext//", "basename.ext");
+ try testBasename("/aaa/bbb", "bbb");
+ try testBasename("/aaa/", "aaa");
+ try testBasename("/aaa/b", "b");
+ try testBasename("/a/b", "b");
+ try testBasename("//a", "a");
+
+ try testBasenamePosix("\\dir\\basename.ext", "\\dir\\basename.ext");
+ try testBasenamePosix("\\basename.ext", "\\basename.ext");
+ try testBasenamePosix("basename.ext", "basename.ext");
+ try testBasenamePosix("basename.ext\\", "basename.ext\\");
+ try testBasenamePosix("basename.ext\\\\", "basename.ext\\\\");
+ try testBasenamePosix("foo", "foo");
+
+ try testBasenameWindows("\\dir\\basename.ext", "basename.ext");
+ try testBasenameWindows("\\basename.ext", "basename.ext");
+ try testBasenameWindows("basename.ext", "basename.ext");
+ try testBasenameWindows("basename.ext\\", "basename.ext");
+ try testBasenameWindows("basename.ext\\\\", "basename.ext");
+ try testBasenameWindows("foo", "foo");
+ try testBasenameWindows("C:", "");
+ try testBasenameWindows("C:.", ".");
+ try testBasenameWindows("C:\\", "");
+ try testBasenameWindows("C:\\dir\\base.ext", "base.ext");
+ try testBasenameWindows("C:\\basename.ext", "basename.ext");
+ try testBasenameWindows("C:basename.ext", "basename.ext");
+ try testBasenameWindows("C:basename.ext\\", "basename.ext");
+ try testBasenameWindows("C:basename.ext\\\\", "basename.ext");
+ try testBasenameWindows("C:foo", "foo");
+ try testBasenameWindows("file:stream", "file:stream");
}
-fn testBasename(input: []const u8, expected_output: []const u8) void {
- testing.expectEqualSlices(u8, expected_output, basename(input));
+fn testBasename(input: []const u8, expected_output: []const u8) !void {
+ try testing.expectEqualSlices(u8, expected_output, basename(input));
}
-fn testBasenamePosix(input: []const u8, expected_output: []const u8) void {
- testing.expectEqualSlices(u8, expected_output, basenamePosix(input));
+fn testBasenamePosix(input: []const u8, expected_output: []const u8) !void {
+ try testing.expectEqualSlices(u8, expected_output, basenamePosix(input));
}
-fn testBasenameWindows(input: []const u8, expected_output: []const u8) void {
- testing.expectEqualSlices(u8, expected_output, basenameWindows(input));
+fn testBasenameWindows(input: []const u8, expected_output: []const u8) !void {
+ try testing.expectEqualSlices(u8, expected_output, basenameWindows(input));
}
/// Returns the relative path from `from` to `to`. If `from` and `to` each
@@ -1212,13 +1212,13 @@ test "relative" {
fn testRelativePosix(from: []const u8, to: []const u8, expected_output: []const u8) !void {
const result = try relativePosix(testing.allocator, from, to);
defer testing.allocator.free(result);
- testing.expectEqualSlices(u8, expected_output, result);
+ try testing.expectEqualSlices(u8, expected_output, result);
}
fn testRelativeWindows(from: []const u8, to: []const u8, expected_output: []const u8) !void {
const result = try relativeWindows(testing.allocator, from, to);
defer testing.allocator.free(result);
- testing.expectEqualSlices(u8, expected_output, result);
+ try testing.expectEqualSlices(u8, expected_output, result);
}
/// Returns the extension of the file name (if any).
@@ -1241,47 +1241,47 @@ pub fn extension(path: []const u8) []const u8 {
return filename[index..];
}
-fn testExtension(path: []const u8, expected: []const u8) void {
- std.testing.expectEqualStrings(expected, extension(path));
+fn testExtension(path: []const u8, expected: []const u8) !void {
+ try std.testing.expectEqualStrings(expected, extension(path));
}
test "extension" {
- testExtension("", "");
- testExtension(".", "");
- testExtension("a.", ".");
- testExtension("abc.", ".");
- testExtension(".a", "");
- testExtension(".file", "");
- testExtension(".gitignore", "");
- testExtension("file.ext", ".ext");
- testExtension("file.ext.", ".");
- testExtension("very-long-file.bruh", ".bruh");
- testExtension("a.b.c", ".c");
- testExtension("a.b.c/", ".c");
-
- testExtension("/", "");
- testExtension("/.", "");
- testExtension("/a.", ".");
- testExtension("/abc.", ".");
- testExtension("/.a", "");
- testExtension("/.file", "");
- testExtension("/.gitignore", "");
- testExtension("/file.ext", ".ext");
- testExtension("/file.ext.", ".");
- testExtension("/very-long-file.bruh", ".bruh");
- testExtension("/a.b.c", ".c");
- testExtension("/a.b.c/", ".c");
-
- testExtension("/foo/bar/bam/", "");
- testExtension("/foo/bar/bam/.", "");
- testExtension("/foo/bar/bam/a.", ".");
- testExtension("/foo/bar/bam/abc.", ".");
- testExtension("/foo/bar/bam/.a", "");
- testExtension("/foo/bar/bam/.file", "");
- testExtension("/foo/bar/bam/.gitignore", "");
- testExtension("/foo/bar/bam/file.ext", ".ext");
- testExtension("/foo/bar/bam/file.ext.", ".");
- testExtension("/foo/bar/bam/very-long-file.bruh", ".bruh");
- testExtension("/foo/bar/bam/a.b.c", ".c");
- testExtension("/foo/bar/bam/a.b.c/", ".c");
+ try testExtension("", "");
+ try testExtension(".", "");
+ try testExtension("a.", ".");
+ try testExtension("abc.", ".");
+ try testExtension(".a", "");
+ try testExtension(".file", "");
+ try testExtension(".gitignore", "");
+ try testExtension("file.ext", ".ext");
+ try testExtension("file.ext.", ".");
+ try testExtension("very-long-file.bruh", ".bruh");
+ try testExtension("a.b.c", ".c");
+ try testExtension("a.b.c/", ".c");
+
+ try testExtension("/", "");
+ try testExtension("/.", "");
+ try testExtension("/a.", ".");
+ try testExtension("/abc.", ".");
+ try testExtension("/.a", "");
+ try testExtension("/.file", "");
+ try testExtension("/.gitignore", "");
+ try testExtension("/file.ext", ".ext");
+ try testExtension("/file.ext.", ".");
+ try testExtension("/very-long-file.bruh", ".bruh");
+ try testExtension("/a.b.c", ".c");
+ try testExtension("/a.b.c/", ".c");
+
+ try testExtension("/foo/bar/bam/", "");
+ try testExtension("/foo/bar/bam/.", "");
+ try testExtension("/foo/bar/bam/a.", ".");
+ try testExtension("/foo/bar/bam/abc.", ".");
+ try testExtension("/foo/bar/bam/.a", "");
+ try testExtension("/foo/bar/bam/.file", "");
+ try testExtension("/foo/bar/bam/.gitignore", "");
+ try testExtension("/foo/bar/bam/file.ext", ".ext");
+ try testExtension("/foo/bar/bam/file.ext.", ".");
+ try testExtension("/foo/bar/bam/very-long-file.bruh", ".bruh");
+ try testExtension("/foo/bar/bam/a.b.c", ".c");
+ try testExtension("/foo/bar/bam/a.b.c/", ".c");
}
lib/std/fs/test.zig
@@ -46,7 +46,7 @@ test "Dir.readLink" {
fn testReadLink(dir: Dir, target_path: []const u8, symlink_path: []const u8) !void {
var buffer: [fs.MAX_PATH_BYTES]u8 = undefined;
const given = try dir.readLink(symlink_path, buffer[0..]);
- testing.expect(mem.eql(u8, target_path, given));
+ try testing.expect(mem.eql(u8, target_path, given));
}
test "accessAbsolute" {
@@ -132,7 +132,7 @@ test "readLinkAbsolute" {
fn testReadLinkAbsolute(target_path: []const u8, symlink_path: []const u8) !void {
var buffer: [fs.MAX_PATH_BYTES]u8 = undefined;
const given = try fs.readLinkAbsolute(symlink_path, buffer[0..]);
- testing.expect(mem.eql(u8, target_path, given));
+ try testing.expect(mem.eql(u8, target_path, given));
}
test "Dir.Iterator" {
@@ -159,9 +159,9 @@ test "Dir.Iterator" {
try entries.append(Dir.Entry{ .name = name, .kind = entry.kind });
}
- testing.expect(entries.items.len == 2); // note that the Iterator skips '.' and '..'
- testing.expect(contains(&entries, Dir.Entry{ .name = "some_file", .kind = Dir.Entry.Kind.File }));
- testing.expect(contains(&entries, Dir.Entry{ .name = "some_dir", .kind = Dir.Entry.Kind.Directory }));
+ try testing.expect(entries.items.len == 2); // note that the Iterator skips '.' and '..'
+ try testing.expect(contains(&entries, Dir.Entry{ .name = "some_file", .kind = Dir.Entry.Kind.File }));
+ try testing.expect(contains(&entries, Dir.Entry{ .name = "some_dir", .kind = Dir.Entry.Kind.Directory }));
}
fn entryEql(lhs: Dir.Entry, rhs: Dir.Entry) bool {
@@ -203,7 +203,7 @@ test "Dir.realpath smoke test" {
const file_path = try tmp_dir.dir.realpath("test_file", buf1[0..]);
const expected_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "test_file" });
- testing.expect(mem.eql(u8, file_path, expected_path));
+ try testing.expect(mem.eql(u8, file_path, expected_path));
}
// Next, test alloc version
@@ -211,7 +211,7 @@ test "Dir.realpath smoke test" {
const file_path = try tmp_dir.dir.realpathAlloc(&arena.allocator, "test_file");
const expected_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "test_file" });
- testing.expect(mem.eql(u8, file_path, expected_path));
+ try testing.expect(mem.eql(u8, file_path, expected_path));
}
}
@@ -224,7 +224,7 @@ test "readAllAlloc" {
const buf1 = try file.readToEndAlloc(testing.allocator, 1024);
defer testing.allocator.free(buf1);
- testing.expect(buf1.len == 0);
+ try testing.expect(buf1.len == 0);
const write_buf: []const u8 = "this is a test.\nthis is a test.\nthis is a test.\nthis is a test.\n";
try file.writeAll(write_buf);
@@ -233,19 +233,19 @@ test "readAllAlloc" {
// max_bytes > file_size
const buf2 = try file.readToEndAlloc(testing.allocator, 1024);
defer testing.allocator.free(buf2);
- testing.expectEqual(write_buf.len, buf2.len);
- testing.expect(std.mem.eql(u8, write_buf, buf2));
+ try testing.expectEqual(write_buf.len, buf2.len);
+ try testing.expect(std.mem.eql(u8, write_buf, buf2));
try file.seekTo(0);
// max_bytes == file_size
const buf3 = try file.readToEndAlloc(testing.allocator, write_buf.len);
defer testing.allocator.free(buf3);
- testing.expectEqual(write_buf.len, buf3.len);
- testing.expect(std.mem.eql(u8, write_buf, buf3));
+ try testing.expectEqual(write_buf.len, buf3.len);
+ try testing.expect(std.mem.eql(u8, write_buf, buf3));
try file.seekTo(0);
// max_bytes < file_size
- testing.expectError(error.FileTooBig, file.readToEndAlloc(testing.allocator, write_buf.len - 1));
+ try testing.expectError(error.FileTooBig, file.readToEndAlloc(testing.allocator, write_buf.len - 1));
}
test "directory operations on files" {
@@ -257,22 +257,22 @@ test "directory operations on files" {
var file = try tmp_dir.dir.createFile(test_file_name, .{ .read = true });
file.close();
- testing.expectError(error.PathAlreadyExists, tmp_dir.dir.makeDir(test_file_name));
- testing.expectError(error.NotDir, tmp_dir.dir.openDir(test_file_name, .{}));
- testing.expectError(error.NotDir, tmp_dir.dir.deleteDir(test_file_name));
+ try testing.expectError(error.PathAlreadyExists, tmp_dir.dir.makeDir(test_file_name));
+ try testing.expectError(error.NotDir, tmp_dir.dir.openDir(test_file_name, .{}));
+ try testing.expectError(error.NotDir, tmp_dir.dir.deleteDir(test_file_name));
if (builtin.os.tag != .wasi and builtin.os.tag != .freebsd and builtin.os.tag != .openbsd) {
const absolute_path = try tmp_dir.dir.realpathAlloc(testing.allocator, test_file_name);
defer testing.allocator.free(absolute_path);
- testing.expectError(error.PathAlreadyExists, fs.makeDirAbsolute(absolute_path));
- testing.expectError(error.NotDir, fs.deleteDirAbsolute(absolute_path));
+ try testing.expectError(error.PathAlreadyExists, fs.makeDirAbsolute(absolute_path));
+ try testing.expectError(error.NotDir, fs.deleteDirAbsolute(absolute_path));
}
// ensure the file still exists and is a file as a sanity check
file = try tmp_dir.dir.openFile(test_file_name, .{});
const stat = try file.stat();
- testing.expect(stat.kind == .File);
+ try testing.expect(stat.kind == .File);
file.close();
}
@@ -287,23 +287,23 @@ test "file operations on directories" {
try tmp_dir.dir.makeDir(test_dir_name);
- testing.expectError(error.IsDir, tmp_dir.dir.createFile(test_dir_name, .{}));
- testing.expectError(error.IsDir, tmp_dir.dir.deleteFile(test_dir_name));
+ try testing.expectError(error.IsDir, tmp_dir.dir.createFile(test_dir_name, .{}));
+ try testing.expectError(error.IsDir, tmp_dir.dir.deleteFile(test_dir_name));
// Currently, WASI will return error.Unexpected (via ENOTCAPABLE) when attempting fd_read on a directory handle.
// TODO: Re-enable on WASI once https://github.com/bytecodealliance/wasmtime/issues/1935 is resolved.
if (builtin.os.tag != .wasi) {
- testing.expectError(error.IsDir, tmp_dir.dir.readFileAlloc(testing.allocator, test_dir_name, std.math.maxInt(usize)));
+ try testing.expectError(error.IsDir, tmp_dir.dir.readFileAlloc(testing.allocator, test_dir_name, std.math.maxInt(usize)));
}
// Note: The `.write = true` is necessary to ensure the error occurs on all platforms.
// TODO: Add a read-only test as well, see https://github.com/ziglang/zig/issues/5732
- testing.expectError(error.IsDir, tmp_dir.dir.openFile(test_dir_name, .{ .write = true }));
+ try testing.expectError(error.IsDir, tmp_dir.dir.openFile(test_dir_name, .{ .write = true }));
if (builtin.os.tag != .wasi and builtin.os.tag != .freebsd and builtin.os.tag != .openbsd) {
const absolute_path = try tmp_dir.dir.realpathAlloc(testing.allocator, test_dir_name);
defer testing.allocator.free(absolute_path);
- testing.expectError(error.IsDir, fs.createFileAbsolute(absolute_path, .{}));
- testing.expectError(error.IsDir, fs.deleteFileAbsolute(absolute_path));
+ try testing.expectError(error.IsDir, fs.createFileAbsolute(absolute_path, .{}));
+ try testing.expectError(error.IsDir, fs.deleteFileAbsolute(absolute_path));
}
// ensure the directory still exists as a sanity check
@@ -316,7 +316,7 @@ test "deleteDir" {
defer tmp_dir.cleanup();
// deleting a non-existent directory
- testing.expectError(error.FileNotFound, tmp_dir.dir.deleteDir("test_dir"));
+ try testing.expectError(error.FileNotFound, tmp_dir.dir.deleteDir("test_dir"));
var dir = try tmp_dir.dir.makeOpenPath("test_dir", .{});
var file = try dir.createFile("test_file", .{});
@@ -326,7 +326,7 @@ test "deleteDir" {
// deleting a non-empty directory
// TODO: Re-enable this check on Windows, see https://github.com/ziglang/zig/issues/5537
if (builtin.os.tag != .windows) {
- testing.expectError(error.DirNotEmpty, tmp_dir.dir.deleteDir("test_dir"));
+ try testing.expectError(error.DirNotEmpty, tmp_dir.dir.deleteDir("test_dir"));
}
dir = try tmp_dir.dir.openDir("test_dir", .{});
@@ -341,7 +341,7 @@ test "Dir.rename files" {
var tmp_dir = tmpDir(.{});
defer tmp_dir.cleanup();
- testing.expectError(error.FileNotFound, tmp_dir.dir.rename("missing_file_name", "something_else"));
+ try testing.expectError(error.FileNotFound, tmp_dir.dir.rename("missing_file_name", "something_else"));
// Renaming files
const test_file_name = "test_file";
@@ -351,7 +351,7 @@ test "Dir.rename files" {
try tmp_dir.dir.rename(test_file_name, renamed_test_file_name);
// Ensure the file was renamed
- testing.expectError(error.FileNotFound, tmp_dir.dir.openFile(test_file_name, .{}));
+ try testing.expectError(error.FileNotFound, tmp_dir.dir.openFile(test_file_name, .{}));
file = try tmp_dir.dir.openFile(renamed_test_file_name, .{});
file.close();
@@ -363,7 +363,7 @@ test "Dir.rename files" {
existing_file.close();
try tmp_dir.dir.rename(renamed_test_file_name, "existing_file");
- testing.expectError(error.FileNotFound, tmp_dir.dir.openFile(renamed_test_file_name, .{}));
+ try testing.expectError(error.FileNotFound, tmp_dir.dir.openFile(renamed_test_file_name, .{}));
file = try tmp_dir.dir.openFile("existing_file", .{});
file.close();
}
@@ -380,7 +380,7 @@ test "Dir.rename directories" {
try tmp_dir.dir.rename("test_dir", "test_dir_renamed");
// Ensure the directory was renamed
- testing.expectError(error.FileNotFound, tmp_dir.dir.openDir("test_dir", .{}));
+ try testing.expectError(error.FileNotFound, tmp_dir.dir.openDir("test_dir", .{}));
var dir = try tmp_dir.dir.openDir("test_dir_renamed", .{});
// Put a file in the directory
@@ -391,7 +391,7 @@ test "Dir.rename directories" {
try tmp_dir.dir.rename("test_dir_renamed", "test_dir_renamed_again");
// Ensure the directory was renamed and the file still exists in it
- testing.expectError(error.FileNotFound, tmp_dir.dir.openDir("test_dir_renamed", .{}));
+ try testing.expectError(error.FileNotFound, tmp_dir.dir.openDir("test_dir_renamed", .{}));
dir = try tmp_dir.dir.openDir("test_dir_renamed_again", .{});
file = try dir.openFile("test_file", .{});
file.close();
@@ -402,7 +402,7 @@ test "Dir.rename directories" {
file = try target_dir.createFile("filler", .{ .read = true });
file.close();
- testing.expectError(error.PathAlreadyExists, tmp_dir.dir.rename("test_dir_renamed_again", "non_empty_target_dir"));
+ try testing.expectError(error.PathAlreadyExists, tmp_dir.dir.rename("test_dir_renamed_again", "non_empty_target_dir"));
// Ensure the directory was not renamed
dir = try tmp_dir.dir.openDir("test_dir_renamed_again", .{});
@@ -421,8 +421,8 @@ test "Dir.rename file <-> dir" {
var file = try tmp_dir.dir.createFile("test_file", .{ .read = true });
file.close();
try tmp_dir.dir.makeDir("test_dir");
- testing.expectError(error.IsDir, tmp_dir.dir.rename("test_file", "test_dir"));
- testing.expectError(error.NotDir, tmp_dir.dir.rename("test_dir", "test_file"));
+ try testing.expectError(error.IsDir, tmp_dir.dir.rename("test_file", "test_dir"));
+ try testing.expectError(error.NotDir, tmp_dir.dir.rename("test_dir", "test_file"));
}
test "rename" {
@@ -440,7 +440,7 @@ test "rename" {
try fs.rename(tmp_dir1.dir, test_file_name, tmp_dir2.dir, renamed_test_file_name);
// ensure the file was renamed
- testing.expectError(error.FileNotFound, tmp_dir1.dir.openFile(test_file_name, .{}));
+ try testing.expectError(error.FileNotFound, tmp_dir1.dir.openFile(test_file_name, .{}));
file = try tmp_dir2.dir.openFile(renamed_test_file_name, .{});
file.close();
}
@@ -461,7 +461,7 @@ test "renameAbsolute" {
break :blk try fs.realpathAlloc(&arena.allocator, relative_path);
};
- testing.expectError(error.FileNotFound, fs.renameAbsolute(
+ try testing.expectError(error.FileNotFound, fs.renameAbsolute(
try fs.path.join(allocator, &[_][]const u8{ base_path, "missing_file_name" }),
try fs.path.join(allocator, &[_][]const u8{ base_path, "something_else" }),
));
@@ -477,10 +477,10 @@ test "renameAbsolute" {
);
// ensure the file was renamed
- testing.expectError(error.FileNotFound, tmp_dir.dir.openFile(test_file_name, .{}));
+ try testing.expectError(error.FileNotFound, tmp_dir.dir.openFile(test_file_name, .{}));
file = try tmp_dir.dir.openFile(renamed_test_file_name, .{});
const stat = try file.stat();
- testing.expect(stat.kind == .File);
+ try testing.expect(stat.kind == .File);
file.close();
// Renaming directories
@@ -493,7 +493,7 @@ test "renameAbsolute" {
);
// ensure the directory was renamed
- testing.expectError(error.FileNotFound, tmp_dir.dir.openDir(test_dir_name, .{}));
+ try testing.expectError(error.FileNotFound, tmp_dir.dir.openDir(test_dir_name, .{}));
var dir = try tmp_dir.dir.openDir(renamed_test_dir_name, .{});
dir.close();
}
@@ -516,7 +516,7 @@ test "makePath, put some files in it, deleteTree" {
if (tmp.dir.openDir("os_test_tmp", .{})) |dir| {
@panic("expected error");
} else |err| {
- testing.expect(err == error.FileNotFound);
+ try testing.expect(err == error.FileNotFound);
}
}
@@ -530,7 +530,7 @@ test "access file" {
if (tmp.dir.access("os_test_tmp" ++ fs.path.sep_str ++ "file.txt", .{})) |ok| {
@panic("expected error");
} else |err| {
- testing.expect(err == error.FileNotFound);
+ try testing.expect(err == error.FileNotFound);
}
try tmp.dir.writeFile("os_test_tmp" ++ fs.path.sep_str ++ "file.txt", "");
@@ -600,7 +600,7 @@ test "sendfile" {
.header_count = 2,
});
const amt = try dest_file.preadAll(&written_buf, 0);
- testing.expect(mem.eql(u8, written_buf[0..amt], "header1\nsecond header\nine1\nsecontrailer1\nsecond trailer\n"));
+ try testing.expect(mem.eql(u8, written_buf[0..amt], "header1\nsecond header\nine1\nsecontrailer1\nsecond trailer\n"));
}
test "copyRangeAll" {
@@ -626,7 +626,7 @@ test "copyRangeAll" {
_ = try src_file.copyRangeAll(0, dest_file, 0, data.len);
const amt = try dest_file.preadAll(&written_buf, 0);
- testing.expect(mem.eql(u8, written_buf[0..amt], data));
+ try testing.expect(mem.eql(u8, written_buf[0..amt], data));
}
test "fs.copyFile" {
@@ -655,7 +655,7 @@ fn expectFileContents(dir: Dir, file_path: []const u8, data: []const u8) !void {
const contents = try dir.readFileAlloc(testing.allocator, file_path, 1000);
defer testing.allocator.free(contents);
- testing.expectEqualSlices(u8, data, contents);
+ try testing.expectEqualSlices(u8, data, contents);
}
test "AtomicFile" {
@@ -676,7 +676,7 @@ test "AtomicFile" {
}
const content = try tmp.dir.readFileAlloc(testing.allocator, test_out_file, 9999);
defer testing.allocator.free(content);
- testing.expect(mem.eql(u8, content, test_content));
+ try testing.expect(mem.eql(u8, content, test_content));
try tmp.dir.deleteFile(test_out_file);
}
@@ -685,7 +685,7 @@ test "realpath" {
if (builtin.os.tag == .wasi) return error.SkipZigTest;
var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
- testing.expectError(error.FileNotFound, fs.realpath("definitely_bogus_does_not_exist1234", &buf));
+ try testing.expectError(error.FileNotFound, fs.realpath("definitely_bogus_does_not_exist1234", &buf));
}
test "open file with exclusive nonblocking lock twice" {
@@ -700,7 +700,7 @@ test "open file with exclusive nonblocking lock twice" {
defer file1.close();
const file2 = tmp.dir.createFile(filename, .{ .lock = .Exclusive, .lock_nonblocking = true });
- testing.expectError(error.WouldBlock, file2);
+ try testing.expectError(error.WouldBlock, file2);
}
test "open file with shared and exclusive nonblocking lock" {
@@ -715,7 +715,7 @@ test "open file with shared and exclusive nonblocking lock" {
defer file1.close();
const file2 = tmp.dir.createFile(filename, .{ .lock = .Exclusive, .lock_nonblocking = true });
- testing.expectError(error.WouldBlock, file2);
+ try testing.expectError(error.WouldBlock, file2);
}
test "open file with exclusive and shared nonblocking lock" {
@@ -730,7 +730,7 @@ test "open file with exclusive and shared nonblocking lock" {
defer file1.close();
const file2 = tmp.dir.createFile(filename, .{ .lock = .Shared, .lock_nonblocking = true });
- testing.expectError(error.WouldBlock, file2);
+ try testing.expectError(error.WouldBlock, file2);
}
test "open file with exclusive lock twice, make sure it waits" {
@@ -790,7 +790,7 @@ test "open file with exclusive nonblocking lock twice (absolute paths)" {
const file2 = fs.createFileAbsolute(filename, .{ .lock = .Exclusive, .lock_nonblocking = true });
file1.close();
- testing.expectError(error.WouldBlock, file2);
+ try testing.expectError(error.WouldBlock, file2);
try fs.deleteFileAbsolute(filename);
}
@@ -830,6 +830,6 @@ test "walker" {
try fs.path.join(allocator, &[_][]const u8{ expected_dir_name, name });
var entry = (try walker.next()).?;
- testing.expectEqualStrings(expected_dir_name, try fs.path.relative(allocator, tmp_path, entry.path));
+ try testing.expectEqualStrings(expected_dir_name, try fs.path.relative(allocator, tmp_path, entry.path));
}
}
lib/std/fs/wasi.zig
@@ -174,8 +174,8 @@ test "extracting WASI preopens" {
try preopens.populate();
- std.testing.expectEqual(@as(usize, 1), preopens.asSlice().len);
+ try std.testing.expectEqual(@as(usize, 1), preopens.asSlice().len);
const preopen = preopens.find(PreopenType{ .Dir = "." }) orelse unreachable;
- std.testing.expect(preopen.@"type".eql(PreopenType{ .Dir = "." }));
- std.testing.expectEqual(@as(usize, 3), preopen.fd);
+ try std.testing.expect(preopen.@"type".eql(PreopenType{ .Dir = "." }));
+ try std.testing.expectEqual(@as(usize, 3), preopen.fd);
}
lib/std/fs/watch.zig
@@ -662,13 +662,13 @@ fn testWriteWatchWriteDelete(allocator: *Allocator) !void {
const read_contents = try std.fs.cwd().readFileAlloc(allocator, file_path, 1024 * 1024);
defer allocator.free(read_contents);
- testing.expectEqualSlices(u8, contents, read_contents);
+ try testing.expectEqualSlices(u8, contents, read_contents);
// now watch the file
var watch = try Watch(void).init(allocator, 0);
defer watch.deinit();
- testing.expect((try watch.addFile(file_path, {})) == null);
+ try testing.expect((try watch.addFile(file_path, {})) == null);
var ev = async watch.channel.get();
var ev_consumed = false;
@@ -698,7 +698,7 @@ fn testWriteWatchWriteDelete(allocator: *Allocator) !void {
const contents_updated = try std.fs.cwd().readFileAlloc(allocator, file_path, 1024 * 1024);
defer allocator.free(contents_updated);
- testing.expectEqualSlices(u8,
+ try testing.expectEqualSlices(u8,
\\line 1
\\lorem ipsum
, contents_updated);
lib/std/hash/adler.zig
@@ -99,21 +99,21 @@ pub const Adler32 = struct {
};
test "adler32 sanity" {
- testing.expectEqual(@as(u32, 0x620062), Adler32.hash("a"));
- testing.expectEqual(@as(u32, 0xbc002ed), Adler32.hash("example"));
+ try testing.expectEqual(@as(u32, 0x620062), Adler32.hash("a"));
+ try testing.expectEqual(@as(u32, 0xbc002ed), Adler32.hash("example"));
}
test "adler32 long" {
const long1 = [_]u8{1} ** 1024;
- testing.expectEqual(@as(u32, 0x06780401), Adler32.hash(long1[0..]));
+ try testing.expectEqual(@as(u32, 0x06780401), Adler32.hash(long1[0..]));
const long2 = [_]u8{1} ** 1025;
- testing.expectEqual(@as(u32, 0x0a7a0402), Adler32.hash(long2[0..]));
+ try testing.expectEqual(@as(u32, 0x0a7a0402), Adler32.hash(long2[0..]));
}
test "adler32 very long" {
const long = [_]u8{1} ** 5553;
- testing.expectEqual(@as(u32, 0x707f15b2), Adler32.hash(long[0..]));
+ try testing.expectEqual(@as(u32, 0x707f15b2), Adler32.hash(long[0..]));
}
test "adler32 very long with variation" {
@@ -129,5 +129,5 @@ test "adler32 very long with variation" {
break :blk result;
};
- testing.expectEqual(@as(u32, 0x5af38d6e), std.hash.Adler32.hash(long[0..]));
+ try testing.expectEqual(@as(u32, 0x5af38d6e), std.hash.Adler32.hash(long[0..]));
}
lib/std/hash/auto_hash.zig
@@ -239,18 +239,18 @@ fn testHashDeepRecursive(key: anytype) u64 {
test "typeContainsSlice" {
comptime {
- testing.expect(!typeContainsSlice(meta.Tag(std.builtin.TypeInfo)));
+ try testing.expect(!typeContainsSlice(meta.Tag(std.builtin.TypeInfo)));
- testing.expect(typeContainsSlice([]const u8));
- testing.expect(!typeContainsSlice(u8));
+ try testing.expect(typeContainsSlice([]const u8));
+ try testing.expect(!typeContainsSlice(u8));
const A = struct { x: []const u8 };
const B = struct { a: A };
const C = struct { b: B };
const D = struct { x: u8 };
- testing.expect(typeContainsSlice(A));
- testing.expect(typeContainsSlice(B));
- testing.expect(typeContainsSlice(C));
- testing.expect(!typeContainsSlice(D));
+ try testing.expect(typeContainsSlice(A));
+ try testing.expect(typeContainsSlice(B));
+ try testing.expect(typeContainsSlice(C));
+ try testing.expect(!typeContainsSlice(D));
}
}
@@ -261,17 +261,17 @@ test "hash pointer" {
const c = &array[2];
const d = a;
- testing.expect(testHashShallow(a) == testHashShallow(d));
- testing.expect(testHashShallow(a) != testHashShallow(c));
- testing.expect(testHashShallow(a) != testHashShallow(b));
+ try testing.expect(testHashShallow(a) == testHashShallow(d));
+ try testing.expect(testHashShallow(a) != testHashShallow(c));
+ try testing.expect(testHashShallow(a) != testHashShallow(b));
- testing.expect(testHashDeep(a) == testHashDeep(a));
- testing.expect(testHashDeep(a) == testHashDeep(c));
- testing.expect(testHashDeep(a) == testHashDeep(b));
+ try testing.expect(testHashDeep(a) == testHashDeep(a));
+ try testing.expect(testHashDeep(a) == testHashDeep(c));
+ try testing.expect(testHashDeep(a) == testHashDeep(b));
- testing.expect(testHashDeepRecursive(a) == testHashDeepRecursive(a));
- testing.expect(testHashDeepRecursive(a) == testHashDeepRecursive(c));
- testing.expect(testHashDeepRecursive(a) == testHashDeepRecursive(b));
+ try testing.expect(testHashDeepRecursive(a) == testHashDeepRecursive(a));
+ try testing.expect(testHashDeepRecursive(a) == testHashDeepRecursive(c));
+ try testing.expect(testHashDeepRecursive(a) == testHashDeepRecursive(b));
}
test "hash slice shallow" {
@@ -286,10 +286,10 @@ test "hash slice shallow" {
const a = array1[runtime_zero..];
const b = array2[runtime_zero..];
const c = array1[runtime_zero..3];
- testing.expect(testHashShallow(a) == testHashShallow(a));
- testing.expect(testHashShallow(a) != testHashShallow(array1));
- testing.expect(testHashShallow(a) != testHashShallow(b));
- testing.expect(testHashShallow(a) != testHashShallow(c));
+ try testing.expect(testHashShallow(a) == testHashShallow(a));
+ try testing.expect(testHashShallow(a) != testHashShallow(array1));
+ try testing.expect(testHashShallow(a) != testHashShallow(b));
+ try testing.expect(testHashShallow(a) != testHashShallow(c));
}
test "hash slice deep" {
@@ -302,10 +302,10 @@ test "hash slice deep" {
const a = array1[0..];
const b = array2[0..];
const c = array1[0..3];
- testing.expect(testHashDeep(a) == testHashDeep(a));
- testing.expect(testHashDeep(a) == testHashDeep(array1));
- testing.expect(testHashDeep(a) == testHashDeep(b));
- testing.expect(testHashDeep(a) != testHashDeep(c));
+ try testing.expect(testHashDeep(a) == testHashDeep(a));
+ try testing.expect(testHashDeep(a) == testHashDeep(array1));
+ try testing.expect(testHashDeep(a) == testHashDeep(b));
+ try testing.expect(testHashDeep(a) != testHashDeep(c));
}
test "hash struct deep" {
@@ -331,28 +331,28 @@ test "hash struct deep" {
defer allocator.destroy(bar.c);
defer allocator.destroy(baz.c);
- testing.expect(testHashDeep(foo) == testHashDeep(bar));
- testing.expect(testHashDeep(foo) != testHashDeep(baz));
- testing.expect(testHashDeep(bar) != testHashDeep(baz));
+ try testing.expect(testHashDeep(foo) == testHashDeep(bar));
+ try testing.expect(testHashDeep(foo) != testHashDeep(baz));
+ try testing.expect(testHashDeep(bar) != testHashDeep(baz));
var hasher = Wyhash.init(0);
const h = testHashDeep(foo);
autoHash(&hasher, foo.a);
autoHash(&hasher, foo.b);
autoHash(&hasher, foo.c.*);
- testing.expectEqual(h, hasher.final());
+ try testing.expectEqual(h, hasher.final());
const h2 = testHashDeepRecursive(&foo);
- testing.expect(h2 != testHashDeep(&foo));
- testing.expect(h2 == testHashDeep(foo));
+ try testing.expect(h2 != testHashDeep(&foo));
+ try testing.expect(h2 == testHashDeep(foo));
}
test "testHash optional" {
const a: ?u32 = 123;
const b: ?u32 = null;
- testing.expectEqual(testHash(a), testHash(@as(u32, 123)));
- testing.expect(testHash(a) != testHash(b));
- testing.expectEqual(testHash(b), 0);
+ try testing.expectEqual(testHash(a), testHash(@as(u32, 123)));
+ try testing.expect(testHash(a) != testHash(b));
+ try testing.expectEqual(testHash(b), 0);
}
test "testHash array" {
@@ -362,7 +362,7 @@ test "testHash array" {
autoHash(&hasher, @as(u32, 1));
autoHash(&hasher, @as(u32, 2));
autoHash(&hasher, @as(u32, 3));
- testing.expectEqual(h, hasher.final());
+ try testing.expectEqual(h, hasher.final());
}
test "testHash struct" {
@@ -377,7 +377,7 @@ test "testHash struct" {
autoHash(&hasher, @as(u32, 1));
autoHash(&hasher, @as(u32, 2));
autoHash(&hasher, @as(u32, 3));
- testing.expectEqual(h, hasher.final());
+ try testing.expectEqual(h, hasher.final());
}
test "testHash union" {
@@ -390,12 +390,12 @@ test "testHash union" {
const a = Foo{ .A = 18 };
var b = Foo{ .B = true };
const c = Foo{ .C = 18 };
- testing.expect(testHash(a) == testHash(a));
- testing.expect(testHash(a) != testHash(b));
- testing.expect(testHash(a) != testHash(c));
+ try testing.expect(testHash(a) == testHash(a));
+ try testing.expect(testHash(a) != testHash(b));
+ try testing.expect(testHash(a) != testHash(c));
b = Foo{ .A = 18 };
- testing.expect(testHash(a) == testHash(b));
+ try testing.expect(testHash(a) == testHash(b));
}
test "testHash vector" {
@@ -404,13 +404,13 @@ test "testHash vector" {
const a: meta.Vector(4, u32) = [_]u32{ 1, 2, 3, 4 };
const b: meta.Vector(4, u32) = [_]u32{ 1, 2, 3, 5 };
- testing.expect(testHash(a) == testHash(a));
- testing.expect(testHash(a) != testHash(b));
+ try testing.expect(testHash(a) == testHash(a));
+ try testing.expect(testHash(a) != testHash(b));
const c: meta.Vector(4, u31) = [_]u31{ 1, 2, 3, 4 };
const d: meta.Vector(4, u31) = [_]u31{ 1, 2, 3, 5 };
- testing.expect(testHash(c) == testHash(c));
- testing.expect(testHash(c) != testHash(d));
+ try testing.expect(testHash(c) == testHash(c));
+ try testing.expect(testHash(c) != testHash(d));
}
test "testHash error union" {
@@ -422,7 +422,7 @@ test "testHash error union" {
};
const f = Foo{};
const g: Errors!Foo = Errors.Test;
- testing.expect(testHash(f) != testHash(g));
- testing.expect(testHash(f) == testHash(Foo{}));
- testing.expect(testHash(g) == testHash(Errors.Test));
+ try testing.expect(testHash(f) != testHash(g));
+ try testing.expect(testHash(f) == testHash(Foo{}));
+ try testing.expect(testHash(g) == testHash(Errors.Test));
}
lib/std/hash/cityhash.zig
@@ -381,14 +381,14 @@ fn CityHash32hashIgnoreSeed(str: []const u8, seed: u32) u32 {
test "cityhash32" {
const Test = struct {
- fn doTest() void {
+ fn doTest() !void {
// Note: SMHasher doesn't provide a 32bit version of the algorithm.
// Note: The implementation was verified against the Google Abseil version.
- std.testing.expectEqual(SMHasherTest(CityHash32hashIgnoreSeed), 0x68254F81);
- std.testing.expectEqual(SMHasherTest(CityHash32hashIgnoreSeed), 0x68254F81);
+ try std.testing.expectEqual(SMHasherTest(CityHash32hashIgnoreSeed), 0x68254F81);
+ try std.testing.expectEqual(SMHasherTest(CityHash32hashIgnoreSeed), 0x68254F81);
}
};
- Test.doTest();
+ try Test.doTest();
// TODO This is uncommented to prevent OOM on the CI server. Re-enable this test
// case once we ship stage2.
//@setEvalBranchQuota(50000);
@@ -397,13 +397,13 @@ test "cityhash32" {
test "cityhash64" {
const Test = struct {
- fn doTest() void {
+ fn doTest() !void {
// Note: This is not compliant with the SMHasher implementation of CityHash64!
// Note: The implementation was verified against the Google Abseil version.
- std.testing.expectEqual(SMHasherTest(CityHash64.hashWithSeed), 0x5FABC5C5);
+ try std.testing.expectEqual(SMHasherTest(CityHash64.hashWithSeed), 0x5FABC5C5);
}
};
- Test.doTest();
+ try Test.doTest();
// TODO This is uncommented to prevent OOM on the CI server. Re-enable this test
// case once we ship stage2.
//@setEvalBranchQuota(50000);
lib/std/hash/crc.zig
@@ -109,9 +109,9 @@ test "crc32 ieee" {
const Crc32Ieee = Crc32WithPoly(.IEEE);
- testing.expect(Crc32Ieee.hash("") == 0x00000000);
- testing.expect(Crc32Ieee.hash("a") == 0xe8b7be43);
- testing.expect(Crc32Ieee.hash("abc") == 0x352441c2);
+ try testing.expect(Crc32Ieee.hash("") == 0x00000000);
+ try testing.expect(Crc32Ieee.hash("a") == 0xe8b7be43);
+ try testing.expect(Crc32Ieee.hash("abc") == 0x352441c2);
}
test "crc32 castagnoli" {
@@ -119,9 +119,9 @@ test "crc32 castagnoli" {
const Crc32Castagnoli = Crc32WithPoly(.Castagnoli);
- testing.expect(Crc32Castagnoli.hash("") == 0x00000000);
- testing.expect(Crc32Castagnoli.hash("a") == 0xc1d04330);
- testing.expect(Crc32Castagnoli.hash("abc") == 0x364b3fb7);
+ try testing.expect(Crc32Castagnoli.hash("") == 0x00000000);
+ try testing.expect(Crc32Castagnoli.hash("a") == 0xc1d04330);
+ try testing.expect(Crc32Castagnoli.hash("abc") == 0x364b3fb7);
}
// half-byte lookup table implementation.
@@ -177,9 +177,9 @@ test "small crc32 ieee" {
const Crc32Ieee = Crc32SmallWithPoly(.IEEE);
- testing.expect(Crc32Ieee.hash("") == 0x00000000);
- testing.expect(Crc32Ieee.hash("a") == 0xe8b7be43);
- testing.expect(Crc32Ieee.hash("abc") == 0x352441c2);
+ try testing.expect(Crc32Ieee.hash("") == 0x00000000);
+ try testing.expect(Crc32Ieee.hash("a") == 0xe8b7be43);
+ try testing.expect(Crc32Ieee.hash("abc") == 0x352441c2);
}
test "small crc32 castagnoli" {
@@ -187,7 +187,7 @@ test "small crc32 castagnoli" {
const Crc32Castagnoli = Crc32SmallWithPoly(.Castagnoli);
- testing.expect(Crc32Castagnoli.hash("") == 0x00000000);
- testing.expect(Crc32Castagnoli.hash("a") == 0xc1d04330);
- testing.expect(Crc32Castagnoli.hash("abc") == 0x364b3fb7);
+ try testing.expect(Crc32Castagnoli.hash("") == 0x00000000);
+ try testing.expect(Crc32Castagnoli.hash("a") == 0xc1d04330);
+ try testing.expect(Crc32Castagnoli.hash("abc") == 0x364b3fb7);
}
lib/std/hash/fnv.zig
@@ -46,18 +46,18 @@ fn Fnv1a(comptime T: type, comptime prime: T, comptime offset: T) type {
}
test "fnv1a-32" {
- testing.expect(Fnv1a_32.hash("") == 0x811c9dc5);
- testing.expect(Fnv1a_32.hash("a") == 0xe40c292c);
- testing.expect(Fnv1a_32.hash("foobar") == 0xbf9cf968);
+ try testing.expect(Fnv1a_32.hash("") == 0x811c9dc5);
+ try testing.expect(Fnv1a_32.hash("a") == 0xe40c292c);
+ try testing.expect(Fnv1a_32.hash("foobar") == 0xbf9cf968);
}
test "fnv1a-64" {
- testing.expect(Fnv1a_64.hash("") == 0xcbf29ce484222325);
- testing.expect(Fnv1a_64.hash("a") == 0xaf63dc4c8601ec8c);
- testing.expect(Fnv1a_64.hash("foobar") == 0x85944171f73967e8);
+ try testing.expect(Fnv1a_64.hash("") == 0xcbf29ce484222325);
+ try testing.expect(Fnv1a_64.hash("a") == 0xaf63dc4c8601ec8c);
+ try testing.expect(Fnv1a_64.hash("foobar") == 0x85944171f73967e8);
}
test "fnv1a-128" {
- testing.expect(Fnv1a_128.hash("") == 0x6c62272e07bb014262b821756295c58d);
- testing.expect(Fnv1a_128.hash("a") == 0xd228cb696f1a8caf78912b704e4a8964);
+ try testing.expect(Fnv1a_128.hash("") == 0x6c62272e07bb014262b821756295c58d);
+ try testing.expect(Fnv1a_128.hash("a") == 0xd228cb696f1a8caf78912b704e4a8964);
}
lib/std/hash/murmur.zig
@@ -308,7 +308,7 @@ fn SMHasherTest(comptime hash_fn: anytype, comptime hashbits: u32) u32 {
}
test "murmur2_32" {
- testing.expectEqual(SMHasherTest(Murmur2_32.hashWithSeed, 32), 0x27864C1E);
+ try testing.expectEqual(SMHasherTest(Murmur2_32.hashWithSeed, 32), 0x27864C1E);
var v0: u32 = 0x12345678;
var v1: u64 = 0x1234567812345678;
var v0le: u32 = v0;
@@ -317,12 +317,12 @@ test "murmur2_32" {
v0le = @byteSwap(u32, v0le);
v1le = @byteSwap(u64, v1le);
}
- testing.expectEqual(Murmur2_32.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur2_32.hashUint32(v0));
- testing.expectEqual(Murmur2_32.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur2_32.hashUint64(v1));
+ try testing.expectEqual(Murmur2_32.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur2_32.hashUint32(v0));
+ try testing.expectEqual(Murmur2_32.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur2_32.hashUint64(v1));
}
test "murmur2_64" {
- std.testing.expectEqual(SMHasherTest(Murmur2_64.hashWithSeed, 64), 0x1F0D3804);
+ try std.testing.expectEqual(SMHasherTest(Murmur2_64.hashWithSeed, 64), 0x1F0D3804);
var v0: u32 = 0x12345678;
var v1: u64 = 0x1234567812345678;
var v0le: u32 = v0;
@@ -331,12 +331,12 @@ test "murmur2_64" {
v0le = @byteSwap(u32, v0le);
v1le = @byteSwap(u64, v1le);
}
- testing.expectEqual(Murmur2_64.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur2_64.hashUint32(v0));
- testing.expectEqual(Murmur2_64.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur2_64.hashUint64(v1));
+ try testing.expectEqual(Murmur2_64.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur2_64.hashUint32(v0));
+ try testing.expectEqual(Murmur2_64.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur2_64.hashUint64(v1));
}
test "murmur3_32" {
- std.testing.expectEqual(SMHasherTest(Murmur3_32.hashWithSeed, 32), 0xB0F57EE3);
+ try std.testing.expectEqual(SMHasherTest(Murmur3_32.hashWithSeed, 32), 0xB0F57EE3);
var v0: u32 = 0x12345678;
var v1: u64 = 0x1234567812345678;
var v0le: u32 = v0;
@@ -345,6 +345,6 @@ test "murmur3_32" {
v0le = @byteSwap(u32, v0le);
v1le = @byteSwap(u64, v1le);
}
- testing.expectEqual(Murmur3_32.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur3_32.hashUint32(v0));
- testing.expectEqual(Murmur3_32.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur3_32.hashUint64(v1));
+ try testing.expectEqual(Murmur3_32.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur3_32.hashUint32(v0));
+ try testing.expectEqual(Murmur3_32.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur3_32.hashUint64(v1));
}
lib/std/hash/wyhash.zig
@@ -183,13 +183,13 @@ const expectEqual = std.testing.expectEqual;
test "test vectors" {
const hash = Wyhash.hash;
- expectEqual(hash(0, ""), 0x0);
- expectEqual(hash(1, "a"), 0xbed235177f41d328);
- expectEqual(hash(2, "abc"), 0xbe348debe59b27c3);
- expectEqual(hash(3, "message digest"), 0x37320f657213a290);
- expectEqual(hash(4, "abcdefghijklmnopqrstuvwxyz"), 0xd0b270e1d8a7019c);
- expectEqual(hash(5, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"), 0x602a1894d3bbfe7f);
- expectEqual(hash(6, "12345678901234567890123456789012345678901234567890123456789012345678901234567890"), 0x829e9c148b75970e);
+ try expectEqual(hash(0, ""), 0x0);
+ try expectEqual(hash(1, "a"), 0xbed235177f41d328);
+ try expectEqual(hash(2, "abc"), 0xbe348debe59b27c3);
+ try expectEqual(hash(3, "message digest"), 0x37320f657213a290);
+ try expectEqual(hash(4, "abcdefghijklmnopqrstuvwxyz"), 0xd0b270e1d8a7019c);
+ try expectEqual(hash(5, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"), 0x602a1894d3bbfe7f);
+ try expectEqual(hash(6, "12345678901234567890123456789012345678901234567890123456789012345678901234567890"), 0x829e9c148b75970e);
}
test "test vectors streaming" {
@@ -197,19 +197,19 @@ test "test vectors streaming" {
for ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") |e| {
wh.update(mem.asBytes(&e));
}
- expectEqual(wh.final(), 0x602a1894d3bbfe7f);
+ try expectEqual(wh.final(), 0x602a1894d3bbfe7f);
const pattern = "1234567890";
const count = 8;
const result = 0x829e9c148b75970e;
- expectEqual(Wyhash.hash(6, pattern ** 8), result);
+ try expectEqual(Wyhash.hash(6, pattern ** 8), result);
wh = Wyhash.init(6);
var i: u32 = 0;
while (i < count) : (i += 1) {
wh.update(pattern);
}
- expectEqual(wh.final(), result);
+ try expectEqual(wh.final(), result);
}
test "iterative non-divisible update" {
@@ -231,6 +231,6 @@ test "iterative non-divisible update" {
}
const iterative_hash = wy.final();
- std.testing.expectEqual(iterative_hash, non_iterative_hash);
+ try std.testing.expectEqual(iterative_hash, non_iterative_hash);
}
}
lib/std/heap/general_purpose_allocator.zig
@@ -692,7 +692,7 @@ const test_config = Config{};
test "small allocations - free in same order" {
var gpa = GeneralPurposeAllocator(test_config){};
- defer std.testing.expect(!gpa.deinit());
+ defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
const allocator = &gpa.allocator;
var list = std.ArrayList(*u64).init(std.testing.allocator);
@@ -711,7 +711,7 @@ test "small allocations - free in same order" {
test "small allocations - free in reverse order" {
var gpa = GeneralPurposeAllocator(test_config){};
- defer std.testing.expect(!gpa.deinit());
+ defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
const allocator = &gpa.allocator;
var list = std.ArrayList(*u64).init(std.testing.allocator);
@@ -730,7 +730,7 @@ test "small allocations - free in reverse order" {
test "large allocations" {
var gpa = GeneralPurposeAllocator(test_config){};
- defer std.testing.expect(!gpa.deinit());
+ defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
const allocator = &gpa.allocator;
const ptr1 = try allocator.alloc(u64, 42768);
@@ -743,7 +743,7 @@ test "large allocations" {
test "realloc" {
var gpa = GeneralPurposeAllocator(test_config){};
- defer std.testing.expect(!gpa.deinit());
+ defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
const allocator = &gpa.allocator;
var slice = try allocator.alignedAlloc(u8, @alignOf(u32), 1);
@@ -753,19 +753,19 @@ test "realloc" {
// This reallocation should keep its pointer address.
const old_slice = slice;
slice = try allocator.realloc(slice, 2);
- std.testing.expect(old_slice.ptr == slice.ptr);
- std.testing.expect(slice[0] == 0x12);
+ try std.testing.expect(old_slice.ptr == slice.ptr);
+ try std.testing.expect(slice[0] == 0x12);
slice[1] = 0x34;
// This requires upgrading to a larger size class
slice = try allocator.realloc(slice, 17);
- std.testing.expect(slice[0] == 0x12);
- std.testing.expect(slice[1] == 0x34);
+ try std.testing.expect(slice[0] == 0x12);
+ try std.testing.expect(slice[1] == 0x34);
}
test "shrink" {
var gpa = GeneralPurposeAllocator(test_config){};
- defer std.testing.expect(!gpa.deinit());
+ defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
const allocator = &gpa.allocator;
var slice = try allocator.alloc(u8, 20);
@@ -776,19 +776,19 @@ test "shrink" {
slice = allocator.shrink(slice, 17);
for (slice) |b| {
- std.testing.expect(b == 0x11);
+ try std.testing.expect(b == 0x11);
}
slice = allocator.shrink(slice, 16);
for (slice) |b| {
- std.testing.expect(b == 0x11);
+ try std.testing.expect(b == 0x11);
}
}
test "large object - grow" {
var gpa = GeneralPurposeAllocator(test_config){};
- defer std.testing.expect(!gpa.deinit());
+ defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
const allocator = &gpa.allocator;
var slice1 = try allocator.alloc(u8, page_size * 2 - 20);
@@ -796,17 +796,17 @@ test "large object - grow" {
const old = slice1;
slice1 = try allocator.realloc(slice1, page_size * 2 - 10);
- std.testing.expect(slice1.ptr == old.ptr);
+ try std.testing.expect(slice1.ptr == old.ptr);
slice1 = try allocator.realloc(slice1, page_size * 2);
- std.testing.expect(slice1.ptr == old.ptr);
+ try std.testing.expect(slice1.ptr == old.ptr);
slice1 = try allocator.realloc(slice1, page_size * 2 + 1);
}
test "realloc small object to large object" {
var gpa = GeneralPurposeAllocator(test_config){};
- defer std.testing.expect(!gpa.deinit());
+ defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
const allocator = &gpa.allocator;
var slice = try allocator.alloc(u8, 70);
@@ -817,13 +817,13 @@ test "realloc small object to large object" {
// This requires upgrading to a large object
const large_object_size = page_size * 2 + 50;
slice = try allocator.realloc(slice, large_object_size);
- std.testing.expect(slice[0] == 0x12);
- std.testing.expect(slice[60] == 0x34);
+ try std.testing.expect(slice[0] == 0x12);
+ try std.testing.expect(slice[60] == 0x34);
}
test "shrink large object to large object" {
var gpa = GeneralPurposeAllocator(test_config){};
- defer std.testing.expect(!gpa.deinit());
+ defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
const allocator = &gpa.allocator;
var slice = try allocator.alloc(u8, page_size * 2 + 50);
@@ -832,21 +832,21 @@ test "shrink large object to large object" {
slice[60] = 0x34;
slice = try allocator.resize(slice, page_size * 2 + 1);
- std.testing.expect(slice[0] == 0x12);
- std.testing.expect(slice[60] == 0x34);
+ try std.testing.expect(slice[0] == 0x12);
+ try std.testing.expect(slice[60] == 0x34);
slice = allocator.shrink(slice, page_size * 2 + 1);
- std.testing.expect(slice[0] == 0x12);
- std.testing.expect(slice[60] == 0x34);
+ try std.testing.expect(slice[0] == 0x12);
+ try std.testing.expect(slice[60] == 0x34);
slice = try allocator.realloc(slice, page_size * 2);
- std.testing.expect(slice[0] == 0x12);
- std.testing.expect(slice[60] == 0x34);
+ try std.testing.expect(slice[0] == 0x12);
+ try std.testing.expect(slice[60] == 0x34);
}
test "shrink large object to large object with larger alignment" {
var gpa = GeneralPurposeAllocator(test_config){};
- defer std.testing.expect(!gpa.deinit());
+ defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
const allocator = &gpa.allocator;
var debug_buffer: [1000]u8 = undefined;
@@ -875,13 +875,13 @@ test "shrink large object to large object with larger alignment" {
slice[60] = 0x34;
slice = try allocator.reallocAdvanced(slice, big_alignment, alloc_size / 2, .exact);
- std.testing.expect(slice[0] == 0x12);
- std.testing.expect(slice[60] == 0x34);
+ try std.testing.expect(slice[0] == 0x12);
+ try std.testing.expect(slice[60] == 0x34);
}
test "realloc large object to small object" {
var gpa = GeneralPurposeAllocator(test_config){};
- defer std.testing.expect(!gpa.deinit());
+ defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
const allocator = &gpa.allocator;
var slice = try allocator.alloc(u8, page_size * 2 + 50);
@@ -890,8 +890,8 @@ test "realloc large object to small object" {
slice[16] = 0x34;
slice = try allocator.realloc(slice, 19);
- std.testing.expect(slice[0] == 0x12);
- std.testing.expect(slice[16] == 0x34);
+ try std.testing.expect(slice[0] == 0x12);
+ try std.testing.expect(slice[16] == 0x34);
}
test "overrideable mutexes" {
@@ -899,7 +899,7 @@ test "overrideable mutexes" {
.backing_allocator = std.testing.allocator,
.mutex = std.Thread.Mutex{},
};
- defer std.testing.expect(!gpa.deinit());
+ defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
const allocator = &gpa.allocator;
const ptr = try allocator.create(i32);
@@ -908,7 +908,7 @@ test "overrideable mutexes" {
test "non-page-allocator backing allocator" {
var gpa = GeneralPurposeAllocator(.{}){ .backing_allocator = std.testing.allocator };
- defer std.testing.expect(!gpa.deinit());
+ defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
const allocator = &gpa.allocator;
const ptr = try allocator.create(i32);
@@ -917,7 +917,7 @@ test "non-page-allocator backing allocator" {
test "realloc large object to larger alignment" {
var gpa = GeneralPurposeAllocator(test_config){};
- defer std.testing.expect(!gpa.deinit());
+ defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
const allocator = &gpa.allocator;
var debug_buffer: [1000]u8 = undefined;
@@ -943,22 +943,22 @@ test "realloc large object to larger alignment" {
slice[16] = 0x34;
slice = try allocator.reallocAdvanced(slice, 32, page_size * 2 + 100, .exact);
- std.testing.expect(slice[0] == 0x12);
- std.testing.expect(slice[16] == 0x34);
+ try std.testing.expect(slice[0] == 0x12);
+ try std.testing.expect(slice[16] == 0x34);
slice = try allocator.reallocAdvanced(slice, 32, page_size * 2 + 25, .exact);
- std.testing.expect(slice[0] == 0x12);
- std.testing.expect(slice[16] == 0x34);
+ try std.testing.expect(slice[0] == 0x12);
+ try std.testing.expect(slice[16] == 0x34);
slice = try allocator.reallocAdvanced(slice, big_alignment, page_size * 2 + 100, .exact);
- std.testing.expect(slice[0] == 0x12);
- std.testing.expect(slice[16] == 0x34);
+ try std.testing.expect(slice[0] == 0x12);
+ try std.testing.expect(slice[16] == 0x34);
}
test "large object shrinks to small but allocation fails during shrink" {
var failing_allocator = std.testing.FailingAllocator.init(std.heap.page_allocator, 3);
var gpa = GeneralPurposeAllocator(.{}){ .backing_allocator = &failing_allocator.allocator };
- defer std.testing.expect(!gpa.deinit());
+ defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
const allocator = &gpa.allocator;
var slice = try allocator.alloc(u8, page_size * 2 + 50);
@@ -969,13 +969,13 @@ test "large object shrinks to small but allocation fails during shrink" {
// Next allocation will fail in the backing allocator of the GeneralPurposeAllocator
slice = allocator.shrink(slice, 4);
- std.testing.expect(slice[0] == 0x12);
- std.testing.expect(slice[3] == 0x34);
+ try std.testing.expect(slice[0] == 0x12);
+ try std.testing.expect(slice[3] == 0x34);
}
test "objects of size 1024 and 2048" {
var gpa = GeneralPurposeAllocator(test_config){};
- defer std.testing.expect(!gpa.deinit());
+ defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
const allocator = &gpa.allocator;
const slice = try allocator.alloc(u8, 1025);
@@ -987,26 +987,26 @@ test "objects of size 1024 and 2048" {
test "setting a memory cap" {
var gpa = GeneralPurposeAllocator(.{ .enable_memory_limit = true }){};
- defer std.testing.expect(!gpa.deinit());
+ defer std.testing.expect(!gpa.deinit()) catch @panic("leak");
const allocator = &gpa.allocator;
gpa.setRequestedMemoryLimit(1010);
const small = try allocator.create(i32);
- std.testing.expect(gpa.total_requested_bytes == 4);
+ try std.testing.expect(gpa.total_requested_bytes == 4);
const big = try allocator.alloc(u8, 1000);
- std.testing.expect(gpa.total_requested_bytes == 1004);
+ try std.testing.expect(gpa.total_requested_bytes == 1004);
- std.testing.expectError(error.OutOfMemory, allocator.create(u64));
+ try std.testing.expectError(error.OutOfMemory, allocator.create(u64));
allocator.destroy(small);
- std.testing.expect(gpa.total_requested_bytes == 1000);
+ try std.testing.expect(gpa.total_requested_bytes == 1000);
allocator.free(big);
- std.testing.expect(gpa.total_requested_bytes == 0);
+ try std.testing.expect(gpa.total_requested_bytes == 0);
const exact = try allocator.alloc(u8, 1010);
- std.testing.expect(gpa.total_requested_bytes == 1010);
+ try std.testing.expect(gpa.total_requested_bytes == 1010);
allocator.free(exact);
}
lib/std/heap/logging_allocator.zig
@@ -93,11 +93,11 @@ test "LoggingAllocator" {
var a = try allocator.alloc(u8, 10);
a = allocator.shrink(a, 5);
- std.testing.expect(a.len == 5);
- std.testing.expectError(error.OutOfMemory, allocator.resize(a, 20));
+ try std.testing.expect(a.len == 5);
+ try std.testing.expectError(error.OutOfMemory, allocator.resize(a, 20));
allocator.free(a);
- std.testing.expectEqualSlices(u8,
+ try std.testing.expectEqualSlices(u8,
\\alloc : 10 success!
\\shrink: 10 to 5
\\expand: 5 to 20 failure!
lib/std/io/bit_reader.zig
@@ -185,64 +185,64 @@ test "api coverage" {
const expect = testing.expect;
const expectError = testing.expectError;
- expect(1 == try bit_stream_be.readBits(u2, 1, &out_bits));
- expect(out_bits == 1);
- expect(2 == try bit_stream_be.readBits(u5, 2, &out_bits));
- expect(out_bits == 2);
- expect(3 == try bit_stream_be.readBits(u128, 3, &out_bits));
- expect(out_bits == 3);
- expect(4 == try bit_stream_be.readBits(u8, 4, &out_bits));
- expect(out_bits == 4);
- expect(5 == try bit_stream_be.readBits(u9, 5, &out_bits));
- expect(out_bits == 5);
- expect(1 == try bit_stream_be.readBits(u1, 1, &out_bits));
- expect(out_bits == 1);
+ try expect(1 == try bit_stream_be.readBits(u2, 1, &out_bits));
+ try expect(out_bits == 1);
+ try expect(2 == try bit_stream_be.readBits(u5, 2, &out_bits));
+ try expect(out_bits == 2);
+ try expect(3 == try bit_stream_be.readBits(u128, 3, &out_bits));
+ try expect(out_bits == 3);
+ try expect(4 == try bit_stream_be.readBits(u8, 4, &out_bits));
+ try expect(out_bits == 4);
+ try expect(5 == try bit_stream_be.readBits(u9, 5, &out_bits));
+ try expect(out_bits == 5);
+ try expect(1 == try bit_stream_be.readBits(u1, 1, &out_bits));
+ try expect(out_bits == 1);
mem_in_be.pos = 0;
bit_stream_be.bit_count = 0;
- expect(0b110011010000101 == try bit_stream_be.readBits(u15, 15, &out_bits));
- expect(out_bits == 15);
+ try expect(0b110011010000101 == try bit_stream_be.readBits(u15, 15, &out_bits));
+ try expect(out_bits == 15);
mem_in_be.pos = 0;
bit_stream_be.bit_count = 0;
- expect(0b1100110100001011 == try bit_stream_be.readBits(u16, 16, &out_bits));
- expect(out_bits == 16);
+ try expect(0b1100110100001011 == try bit_stream_be.readBits(u16, 16, &out_bits));
+ try expect(out_bits == 16);
_ = try bit_stream_be.readBits(u0, 0, &out_bits);
- expect(0 == try bit_stream_be.readBits(u1, 1, &out_bits));
- expect(out_bits == 0);
- expectError(error.EndOfStream, bit_stream_be.readBitsNoEof(u1, 1));
+ try expect(0 == try bit_stream_be.readBits(u1, 1, &out_bits));
+ try expect(out_bits == 0);
+ try expectError(error.EndOfStream, bit_stream_be.readBitsNoEof(u1, 1));
var mem_in_le = io.fixedBufferStream(&mem_le);
var bit_stream_le = bitReader(.Little, mem_in_le.reader());
- expect(1 == try bit_stream_le.readBits(u2, 1, &out_bits));
- expect(out_bits == 1);
- expect(2 == try bit_stream_le.readBits(u5, 2, &out_bits));
- expect(out_bits == 2);
- expect(3 == try bit_stream_le.readBits(u128, 3, &out_bits));
- expect(out_bits == 3);
- expect(4 == try bit_stream_le.readBits(u8, 4, &out_bits));
- expect(out_bits == 4);
- expect(5 == try bit_stream_le.readBits(u9, 5, &out_bits));
- expect(out_bits == 5);
- expect(1 == try bit_stream_le.readBits(u1, 1, &out_bits));
- expect(out_bits == 1);
+ try expect(1 == try bit_stream_le.readBits(u2, 1, &out_bits));
+ try expect(out_bits == 1);
+ try expect(2 == try bit_stream_le.readBits(u5, 2, &out_bits));
+ try expect(out_bits == 2);
+ try expect(3 == try bit_stream_le.readBits(u128, 3, &out_bits));
+ try expect(out_bits == 3);
+ try expect(4 == try bit_stream_le.readBits(u8, 4, &out_bits));
+ try expect(out_bits == 4);
+ try expect(5 == try bit_stream_le.readBits(u9, 5, &out_bits));
+ try expect(out_bits == 5);
+ try expect(1 == try bit_stream_le.readBits(u1, 1, &out_bits));
+ try expect(out_bits == 1);
mem_in_le.pos = 0;
bit_stream_le.bit_count = 0;
- expect(0b001010100011101 == try bit_stream_le.readBits(u15, 15, &out_bits));
- expect(out_bits == 15);
+ try expect(0b001010100011101 == try bit_stream_le.readBits(u15, 15, &out_bits));
+ try expect(out_bits == 15);
mem_in_le.pos = 0;
bit_stream_le.bit_count = 0;
- expect(0b1001010100011101 == try bit_stream_le.readBits(u16, 16, &out_bits));
- expect(out_bits == 16);
+ try expect(0b1001010100011101 == try bit_stream_le.readBits(u16, 16, &out_bits));
+ try expect(out_bits == 16);
_ = try bit_stream_le.readBits(u0, 0, &out_bits);
- expect(0 == try bit_stream_le.readBits(u1, 1, &out_bits));
- expect(out_bits == 0);
- expectError(error.EndOfStream, bit_stream_le.readBitsNoEof(u1, 1));
+ try expect(0 == try bit_stream_le.readBits(u1, 1, &out_bits));
+ try expect(out_bits == 0);
+ try expectError(error.EndOfStream, bit_stream_le.readBitsNoEof(u1, 1));
}
lib/std/io/bit_writer.zig
@@ -163,17 +163,17 @@ test "api coverage" {
try bit_stream_be.writeBits(@as(u9, 5), 5);
try bit_stream_be.writeBits(@as(u1, 1), 1);
- testing.expect(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001011);
+ try testing.expect(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001011);
mem_out_be.pos = 0;
try bit_stream_be.writeBits(@as(u15, 0b110011010000101), 15);
try bit_stream_be.flushBits();
- testing.expect(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001010);
+ try testing.expect(mem_be[0] == 0b11001101 and mem_be[1] == 0b00001010);
mem_out_be.pos = 0;
try bit_stream_be.writeBits(@as(u32, 0b110011010000101), 16);
- testing.expect(mem_be[0] == 0b01100110 and mem_be[1] == 0b10000101);
+ try testing.expect(mem_be[0] == 0b01100110 and mem_be[1] == 0b10000101);
try bit_stream_be.writeBits(@as(u0, 0), 0);
@@ -187,16 +187,16 @@ test "api coverage" {
try bit_stream_le.writeBits(@as(u9, 5), 5);
try bit_stream_le.writeBits(@as(u1, 1), 1);
- testing.expect(mem_le[0] == 0b00011101 and mem_le[1] == 0b10010101);
+ try testing.expect(mem_le[0] == 0b00011101 and mem_le[1] == 0b10010101);
mem_out_le.pos = 0;
try bit_stream_le.writeBits(@as(u15, 0b110011010000101), 15);
try bit_stream_le.flushBits();
- testing.expect(mem_le[0] == 0b10000101 and mem_le[1] == 0b01100110);
+ try testing.expect(mem_le[0] == 0b10000101 and mem_le[1] == 0b01100110);
mem_out_le.pos = 0;
try bit_stream_le.writeBits(@as(u32, 0b1100110100001011), 16);
- testing.expect(mem_le[0] == 0b00001011 and mem_le[1] == 0b11001101);
+ try testing.expect(mem_le[0] == 0b00001011 and mem_le[1] == 0b11001101);
try bit_stream_le.writeBits(@as(u0, 0), 0);
}
lib/std/io/buffered_reader.zig
@@ -87,5 +87,5 @@ test "io.BufferedReader" {
const res = try stream.readAllAlloc(testing.allocator, str.len + 1);
defer testing.allocator.free(res);
- testing.expectEqualSlices(u8, str, res);
+ try testing.expectEqualSlices(u8, str, res);
}
lib/std/io/counting_reader.zig
@@ -41,8 +41,8 @@ test "io.CountingReader" {
//read and discard all bytes
while (stream.readByte()) |_| {} else |err| {
- testing.expect(err == error.EndOfStream);
+ try testing.expect(err == error.EndOfStream);
}
- testing.expect(counting_stream.bytes_read == bytes.len);
+ try testing.expect(counting_stream.bytes_read == bytes.len);
}
lib/std/io/counting_writer.zig
@@ -40,5 +40,5 @@ test "io.CountingWriter" {
const bytes = "yay" ** 100;
stream.writeAll(bytes) catch unreachable;
- testing.expect(counting_stream.bytes_written == bytes.len);
+ try testing.expect(counting_stream.bytes_written == bytes.len);
}
lib/std/io/fixed_buffer_stream.zig
@@ -134,7 +134,7 @@ test "FixedBufferStream output" {
const stream = fbs.writer();
try stream.print("{s}{s}!", .{ "Hello", "World" });
- testing.expectEqualSlices(u8, "HelloWorld!", fbs.getWritten());
+ try testing.expectEqualSlices(u8, "HelloWorld!", fbs.getWritten());
}
test "FixedBufferStream output 2" {
@@ -142,19 +142,19 @@ test "FixedBufferStream output 2" {
var fbs = fixedBufferStream(&buffer);
try fbs.writer().writeAll("Hello");
- testing.expect(mem.eql(u8, fbs.getWritten(), "Hello"));
+ try testing.expect(mem.eql(u8, fbs.getWritten(), "Hello"));
try fbs.writer().writeAll("world");
- testing.expect(mem.eql(u8, fbs.getWritten(), "Helloworld"));
+ try testing.expect(mem.eql(u8, fbs.getWritten(), "Helloworld"));
- testing.expectError(error.NoSpaceLeft, fbs.writer().writeAll("!"));
- testing.expect(mem.eql(u8, fbs.getWritten(), "Helloworld"));
+ try testing.expectError(error.NoSpaceLeft, fbs.writer().writeAll("!"));
+ try testing.expect(mem.eql(u8, fbs.getWritten(), "Helloworld"));
fbs.reset();
- testing.expect(fbs.getWritten().len == 0);
+ try testing.expect(fbs.getWritten().len == 0);
- testing.expectError(error.NoSpaceLeft, fbs.writer().writeAll("Hello world!"));
- testing.expect(mem.eql(u8, fbs.getWritten(), "Hello worl"));
+ try testing.expectError(error.NoSpaceLeft, fbs.writer().writeAll("Hello world!"));
+ try testing.expect(mem.eql(u8, fbs.getWritten(), "Hello worl"));
}
test "FixedBufferStream input" {
@@ -164,13 +164,13 @@ test "FixedBufferStream input" {
var dest: [4]u8 = undefined;
var read = try fbs.reader().read(dest[0..4]);
- testing.expect(read == 4);
- testing.expect(mem.eql(u8, dest[0..4], bytes[0..4]));
+ try testing.expect(read == 4);
+ try testing.expect(mem.eql(u8, dest[0..4], bytes[0..4]));
read = try fbs.reader().read(dest[0..4]);
- testing.expect(read == 3);
- testing.expect(mem.eql(u8, dest[0..3], bytes[4..7]));
+ try testing.expect(read == 3);
+ try testing.expect(mem.eql(u8, dest[0..3], bytes[4..7]));
read = try fbs.reader().read(dest[0..4]);
- testing.expect(read == 0);
+ try testing.expect(read == 0);
}
lib/std/io/limited_reader.zig
@@ -43,8 +43,8 @@ test "basic usage" {
var early_stream = limitedReader(fbs.reader(), 3);
var buf: [5]u8 = undefined;
- testing.expectEqual(@as(usize, 3), try early_stream.reader().read(&buf));
- testing.expectEqualSlices(u8, data[0..3], buf[0..3]);
- testing.expectEqual(@as(usize, 0), try early_stream.reader().read(&buf));
- testing.expectError(error.EndOfStream, early_stream.reader().skipBytes(10, .{}));
+ try testing.expectEqual(@as(usize, 3), try early_stream.reader().read(&buf));
+ try testing.expectEqualSlices(u8, data[0..3], buf[0..3]);
+ try testing.expectEqual(@as(usize, 0), try early_stream.reader().read(&buf));
+ try testing.expectError(error.EndOfStream, early_stream.reader().skipBytes(10, .{}));
}
lib/std/io/multi_writer.zig
@@ -52,6 +52,6 @@ test "MultiWriter" {
var fbs2 = io.fixedBufferStream(&buf2);
var stream = multiWriter(.{ fbs1.writer(), fbs2.writer() });
try stream.writer().print("HI", .{});
- testing.expectEqualSlices(u8, "HI", fbs1.getWritten());
- testing.expectEqualSlices(u8, "HI", fbs2.getWritten());
+ try testing.expectEqualSlices(u8, "HI", fbs1.getWritten());
+ try testing.expectEqualSlices(u8, "HI", fbs2.getWritten());
}
lib/std/io/peek_stream.zig
@@ -94,24 +94,24 @@ test "PeekStream" {
try ps.putBackByte(10);
var read = try ps.reader().read(dest[0..4]);
- testing.expect(read == 4);
- testing.expect(dest[0] == 10);
- testing.expect(dest[1] == 9);
- testing.expect(mem.eql(u8, dest[2..4], bytes[0..2]));
+ try testing.expect(read == 4);
+ try testing.expect(dest[0] == 10);
+ try testing.expect(dest[1] == 9);
+ try testing.expect(mem.eql(u8, dest[2..4], bytes[0..2]));
read = try ps.reader().read(dest[0..4]);
- testing.expect(read == 4);
- testing.expect(mem.eql(u8, dest[0..4], bytes[2..6]));
+ try testing.expect(read == 4);
+ try testing.expect(mem.eql(u8, dest[0..4], bytes[2..6]));
read = try ps.reader().read(dest[0..4]);
- testing.expect(read == 2);
- testing.expect(mem.eql(u8, dest[0..2], bytes[6..8]));
+ try testing.expect(read == 2);
+ try testing.expect(mem.eql(u8, dest[0..2], bytes[6..8]));
try ps.putBackByte(11);
try ps.putBackByte(12);
read = try ps.reader().read(dest[0..4]);
- testing.expect(read == 2);
- testing.expect(dest[0] == 12);
- testing.expect(dest[1] == 11);
+ try testing.expect(read == 2);
+ try testing.expect(dest[0] == 12);
+ try testing.expect(dest[1] == 11);
}
lib/std/io/reader.zig
@@ -329,26 +329,26 @@ pub fn Reader(
test "Reader" {
var buf = "a\x02".*;
const reader = std.io.fixedBufferStream(&buf).reader();
- testing.expect((try reader.readByte()) == 'a');
- testing.expect((try reader.readEnum(enum(u8) {
+ try testing.expect((try reader.readByte()) == 'a');
+ try testing.expect((try reader.readEnum(enum(u8) {
a = 0,
b = 99,
c = 2,
d = 3,
}, undefined)) == .c);
- testing.expectError(error.EndOfStream, reader.readByte());
+ try testing.expectError(error.EndOfStream, reader.readByte());
}
test "Reader.isBytes" {
const reader = std.io.fixedBufferStream("foobar").reader();
- testing.expectEqual(true, try reader.isBytes("foo"));
- testing.expectEqual(false, try reader.isBytes("qux"));
+ try testing.expectEqual(true, try reader.isBytes("foo"));
+ try testing.expectEqual(false, try reader.isBytes("qux"));
}
test "Reader.skipBytes" {
const reader = std.io.fixedBufferStream("foobar").reader();
try reader.skipBytes(3, .{});
- testing.expect(try reader.isBytes("bar"));
+ try testing.expect(try reader.isBytes("bar"));
try reader.skipBytes(0, .{});
- testing.expectError(error.EndOfStream, reader.skipBytes(1, .{}));
+ try testing.expectError(error.EndOfStream, reader.skipBytes(1, .{}));
}
lib/std/io/test.zig
@@ -40,7 +40,7 @@ test "write a file, read it, then delete it" {
{
// Make sure the exclusive flag is honored.
- expectError(File.OpenError.PathAlreadyExists, tmp.dir.createFile(tmp_file_name, .{ .exclusive = true }));
+ try expectError(File.OpenError.PathAlreadyExists, tmp.dir.createFile(tmp_file_name, .{ .exclusive = true }));
}
{
@@ -49,16 +49,16 @@ test "write a file, read it, then delete it" {
const file_size = try file.getEndPos();
const expected_file_size: u64 = "begin".len + data.len + "end".len;
- expectEqual(expected_file_size, file_size);
+ try expectEqual(expected_file_size, file_size);
var buf_stream = io.bufferedReader(file.reader());
const st = buf_stream.reader();
const contents = try st.readAllAlloc(std.testing.allocator, 2 * 1024);
defer std.testing.allocator.free(contents);
- expect(mem.eql(u8, contents[0.."begin".len], "begin"));
- expect(mem.eql(u8, contents["begin".len .. contents.len - "end".len], &data));
- expect(mem.eql(u8, contents[contents.len - "end".len ..], "end"));
+ try expect(mem.eql(u8, contents[0.."begin".len], "begin"));
+ try expect(mem.eql(u8, contents["begin".len .. contents.len - "end".len], &data));
+ try expect(mem.eql(u8, contents[contents.len - "end".len ..], "end"));
}
try tmp.dir.deleteFile(tmp_file_name);
}
@@ -90,20 +90,20 @@ test "BitStreams with File Stream" {
var out_bits: usize = undefined;
- expect(1 == try bit_stream.readBits(u2, 1, &out_bits));
- expect(out_bits == 1);
- expect(2 == try bit_stream.readBits(u5, 2, &out_bits));
- expect(out_bits == 2);
- expect(3 == try bit_stream.readBits(u128, 3, &out_bits));
- expect(out_bits == 3);
- expect(4 == try bit_stream.readBits(u8, 4, &out_bits));
- expect(out_bits == 4);
- expect(5 == try bit_stream.readBits(u9, 5, &out_bits));
- expect(out_bits == 5);
- expect(1 == try bit_stream.readBits(u1, 1, &out_bits));
- expect(out_bits == 1);
-
- expectError(error.EndOfStream, bit_stream.readBitsNoEof(u1, 1));
+ try expect(1 == try bit_stream.readBits(u2, 1, &out_bits));
+ try expect(out_bits == 1);
+ try expect(2 == try bit_stream.readBits(u5, 2, &out_bits));
+ try expect(out_bits == 2);
+ try expect(3 == try bit_stream.readBits(u128, 3, &out_bits));
+ try expect(out_bits == 3);
+ try expect(4 == try bit_stream.readBits(u8, 4, &out_bits));
+ try expect(out_bits == 4);
+ try expect(5 == try bit_stream.readBits(u9, 5, &out_bits));
+ try expect(out_bits == 5);
+ try expect(1 == try bit_stream.readBits(u1, 1, &out_bits));
+ try expect(out_bits == 1);
+
+ try expectError(error.EndOfStream, bit_stream.readBitsNoEof(u1, 1));
}
try tmp.dir.deleteFile(tmp_file_name);
}
@@ -123,16 +123,16 @@ test "File seek ops" {
// Seek to the end
try file.seekFromEnd(0);
- expect((try file.getPos()) == try file.getEndPos());
+ try expect((try file.getPos()) == try file.getEndPos());
// Negative delta
try file.seekBy(-4096);
- expect((try file.getPos()) == 4096);
+ try expect((try file.getPos()) == 4096);
// Positive delta
try file.seekBy(10);
- expect((try file.getPos()) == 4106);
+ try expect((try file.getPos()) == 4106);
// Absolute position
try file.seekTo(1234);
- expect((try file.getPos()) == 1234);
+ try expect((try file.getPos()) == 1234);
}
test "setEndPos" {
@@ -147,18 +147,18 @@ test "setEndPos" {
}
// Verify that the file size changes and the file offset is not moved
- std.testing.expect((try file.getEndPos()) == 0);
- std.testing.expect((try file.getPos()) == 0);
+ try std.testing.expect((try file.getEndPos()) == 0);
+ try std.testing.expect((try file.getPos()) == 0);
try file.setEndPos(8192);
- std.testing.expect((try file.getEndPos()) == 8192);
- std.testing.expect((try file.getPos()) == 0);
+ try std.testing.expect((try file.getEndPos()) == 8192);
+ try std.testing.expect((try file.getPos()) == 0);
try file.seekTo(100);
try file.setEndPos(4096);
- std.testing.expect((try file.getEndPos()) == 4096);
- std.testing.expect((try file.getPos()) == 100);
+ try std.testing.expect((try file.getEndPos()) == 4096);
+ try std.testing.expect((try file.getPos()) == 100);
try file.setEndPos(0);
- std.testing.expect((try file.getEndPos()) == 0);
- std.testing.expect((try file.getPos()) == 100);
+ try std.testing.expect((try file.getEndPos()) == 0);
+ try std.testing.expect((try file.getPos()) == 100);
}
test "updateTimes" {
@@ -178,6 +178,6 @@ test "updateTimes" {
stat_old.mtime - 5 * std.time.ns_per_s,
);
var stat_new = try file.stat();
- expect(stat_new.atime < stat_old.atime);
- expect(stat_new.mtime < stat_old.mtime);
+ try expect(stat_new.atime < stat_old.atime);
+ try expect(stat_new.mtime < stat_old.mtime);
}
lib/std/json/test.zig
@@ -21,37 +21,37 @@ fn testNonStreaming(s: []const u8) !void {
}
fn ok(s: []const u8) !void {
- testing.expect(json.validate(s));
+ try testing.expect(json.validate(s));
try testNonStreaming(s);
}
-fn err(s: []const u8) void {
- testing.expect(!json.validate(s));
+fn err(s: []const u8) !void {
+ try testing.expect(!json.validate(s));
- testing.expect(std.meta.isError(testNonStreaming(s)));
+ try testing.expect(std.meta.isError(testNonStreaming(s)));
}
-fn utf8Error(s: []const u8) void {
- testing.expect(!json.validate(s));
+fn utf8Error(s: []const u8) !void {
+ try testing.expect(!json.validate(s));
- testing.expectError(error.InvalidUtf8Byte, testNonStreaming(s));
+ try testing.expectError(error.InvalidUtf8Byte, testNonStreaming(s));
}
-fn any(s: []const u8) void {
+fn any(s: []const u8) !void {
_ = json.validate(s);
testNonStreaming(s) catch {};
}
-fn anyStreamingErrNonStreaming(s: []const u8) void {
+fn anyStreamingErrNonStreaming(s: []const u8) !void {
_ = json.validate(s);
- testing.expect(std.meta.isError(testNonStreaming(s)));
+ try testing.expect(std.meta.isError(testNonStreaming(s)));
}
fn roundTrip(s: []const u8) !void {
- testing.expect(json.validate(s));
+ try testing.expect(json.validate(s));
var p = json.Parser.init(testing.allocator, false);
defer p.deinit();
@@ -63,7 +63,7 @@ fn roundTrip(s: []const u8) !void {
var fbs = std.io.fixedBufferStream(&buf);
try tree.root.jsonStringify(.{}, fbs.writer());
- testing.expectEqualStrings(s, fbs.getWritten());
+ try testing.expectEqualStrings(s, fbs.getWritten());
}
////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -642,109 +642,109 @@ test "y_structure_whitespace_array" {
////////////////////////////////////////////////////////////////////////////////////////////////////
test "n_array_1_true_without_comma" {
- err(
+ try err(
\\[1 true]
);
}
test "n_array_a_invalid_utf8" {
- err(
+ try err(
\\[aå]
);
}
test "n_array_colon_instead_of_comma" {
- err(
+ try err(
\\["": 1]
);
}
test "n_array_comma_after_close" {
- err(
+ try err(
\\[""],
);
}
test "n_array_comma_and_number" {
- err(
+ try err(
\\[,1]
);
}
test "n_array_double_comma" {
- err(
+ try err(
\\[1,,2]
);
}
test "n_array_double_extra_comma" {
- err(
+ try err(
\\["x",,]
);
}
test "n_array_extra_close" {
- err(
+ try err(
\\["x"]]
);
}
test "n_array_extra_comma" {
- err(
+ try err(
\\["",]
);
}
test "n_array_incomplete_invalid_value" {
- err(
+ try err(
\\[x
);
}
test "n_array_incomplete" {
- err(
+ try err(
\\["x"
);
}
test "n_array_inner_array_no_comma" {
- err(
+ try err(
\\[3[4]]
);
}
test "n_array_invalid_utf8" {
- err(
+ try err(
\\[ÿ]
);
}
test "n_array_items_separated_by_semicolon" {
- err(
+ try err(
\\[1:2]
);
}
test "n_array_just_comma" {
- err(
+ try err(
\\[,]
);
}
test "n_array_just_minus" {
- err(
+ try err(
\\[-]
);
}
test "n_array_missing_value" {
- err(
+ try err(
\\[ , ""]
);
}
test "n_array_newlines_unclosed" {
- err(
+ try err(
\\["a",
\\4
\\,1,
@@ -752,41 +752,41 @@ test "n_array_newlines_unclosed" {
}
test "n_array_number_and_comma" {
- err(
+ try err(
\\[1,]
);
}
test "n_array_number_and_several_commas" {
- err(
+ try err(
\\[1,,]
);
}
test "n_array_spaces_vertical_tab_formfeed" {
- err("[\"\x0aa\"\\f]");
+ try err("[\"\x0aa\"\\f]");
}
test "n_array_star_inside" {
- err(
+ try err(
\\[*]
);
}
test "n_array_unclosed" {
- err(
+ try err(
\\[""
);
}
test "n_array_unclosed_trailing_comma" {
- err(
+ try err(
\\[1,
);
}
test "n_array_unclosed_with_new_lines" {
- err(
+ try err(
\\[1,
\\1
\\,1
@@ -794,956 +794,956 @@ test "n_array_unclosed_with_new_lines" {
}
test "n_array_unclosed_with_object_inside" {
- err(
+ try err(
\\[{}
);
}
test "n_incomplete_false" {
- err(
+ try err(
\\[fals]
);
}
test "n_incomplete_null" {
- err(
+ try err(
\\[nul]
);
}
test "n_incomplete_true" {
- err(
+ try err(
\\[tru]
);
}
test "n_multidigit_number_then_00" {
- err("123\x00");
+ try err("123\x00");
}
test "n_number_0.1.2" {
- err(
+ try err(
\\[0.1.2]
);
}
test "n_number_-01" {
- err(
+ try err(
\\[-01]
);
}
test "n_number_0.3e" {
- err(
+ try err(
\\[0.3e]
);
}
test "n_number_0.3e+" {
- err(
+ try err(
\\[0.3e+]
);
}
test "n_number_0_capital_E" {
- err(
+ try err(
\\[0E]
);
}
test "n_number_0_capital_E+" {
- err(
+ try err(
\\[0E+]
);
}
test "n_number_0.e1" {
- err(
+ try err(
\\[0.e1]
);
}
test "n_number_0e" {
- err(
+ try err(
\\[0e]
);
}
test "n_number_0e+" {
- err(
+ try err(
\\[0e+]
);
}
test "n_number_1_000" {
- err(
+ try err(
\\[1 000.0]
);
}
test "n_number_1.0e-" {
- err(
+ try err(
\\[1.0e-]
);
}
test "n_number_1.0e" {
- err(
+ try err(
\\[1.0e]
);
}
test "n_number_1.0e+" {
- err(
+ try err(
\\[1.0e+]
);
}
test "n_number_-1.0." {
- err(
+ try err(
\\[-1.0.]
);
}
test "n_number_1eE2" {
- err(
+ try err(
\\[1eE2]
);
}
test "n_number_.-1" {
- err(
+ try err(
\\[.-1]
);
}
test "n_number_+1" {
- err(
+ try err(
\\[+1]
);
}
test "n_number_.2e-3" {
- err(
+ try err(
\\[.2e-3]
);
}
test "n_number_2.e-3" {
- err(
+ try err(
\\[2.e-3]
);
}
test "n_number_2.e+3" {
- err(
+ try err(
\\[2.e+3]
);
}
test "n_number_2.e3" {
- err(
+ try err(
\\[2.e3]
);
}
test "n_number_-2." {
- err(
+ try err(
\\[-2.]
);
}
test "n_number_9.e+" {
- err(
+ try err(
\\[9.e+]
);
}
test "n_number_expression" {
- err(
+ try err(
\\[1+2]
);
}
test "n_number_hex_1_digit" {
- err(
+ try err(
\\[0x1]
);
}
test "n_number_hex_2_digits" {
- err(
+ try err(
\\[0x42]
);
}
test "n_number_infinity" {
- err(
+ try err(
\\[Infinity]
);
}
test "n_number_+Inf" {
- err(
+ try err(
\\[+Inf]
);
}
test "n_number_Inf" {
- err(
+ try err(
\\[Inf]
);
}
test "n_number_invalid+-" {
- err(
+ try err(
\\[0e+-1]
);
}
test "n_number_invalid-negative-real" {
- err(
+ try err(
\\[-123.123foo]
);
}
test "n_number_invalid-utf-8-in-bigger-int" {
- err(
+ try err(
\\[123å]
);
}
test "n_number_invalid-utf-8-in-exponent" {
- err(
+ try err(
\\[1e1å]
);
}
test "n_number_invalid-utf-8-in-int" {
- err(
+ try err(
\\[0å]
);
}
test "n_number_++" {
- err(
+ try err(
\\[++1234]
);
}
test "n_number_minus_infinity" {
- err(
+ try err(
\\[-Infinity]
);
}
test "n_number_minus_sign_with_trailing_garbage" {
- err(
+ try err(
\\[-foo]
);
}
test "n_number_minus_space_1" {
- err(
+ try err(
\\[- 1]
);
}
test "n_number_-NaN" {
- err(
+ try err(
\\[-NaN]
);
}
test "n_number_NaN" {
- err(
+ try err(
\\[NaN]
);
}
test "n_number_neg_int_starting_with_zero" {
- err(
+ try err(
\\[-012]
);
}
test "n_number_neg_real_without_int_part" {
- err(
+ try err(
\\[-.123]
);
}
test "n_number_neg_with_garbage_at_end" {
- err(
+ try err(
\\[-1x]
);
}
test "n_number_real_garbage_after_e" {
- err(
+ try err(
\\[1ea]
);
}
test "n_number_real_with_invalid_utf8_after_e" {
- err(
+ try err(
\\[1eå]
);
}
test "n_number_real_without_fractional_part" {
- err(
+ try err(
\\[1.]
);
}
test "n_number_starting_with_dot" {
- err(
+ try err(
\\[.123]
);
}
test "n_number_U+FF11_fullwidth_digit_one" {
- err(
+ try err(
\\[ï¼]
);
}
test "n_number_with_alpha_char" {
- err(
+ try err(
\\[1.8011670033376514H-308]
);
}
test "n_number_with_alpha" {
- err(
+ try err(
\\[1.2a-3]
);
}
test "n_number_with_leading_zero" {
- err(
+ try err(
\\[012]
);
}
test "n_object_bad_value" {
- err(
+ try err(
\\["x", truth]
);
}
test "n_object_bracket_key" {
- err(
+ try err(
\\{[: "x"}
);
}
test "n_object_comma_instead_of_colon" {
- err(
+ try err(
\\{"x", null}
);
}
test "n_object_double_colon" {
- err(
+ try err(
\\{"x"::"b"}
);
}
test "n_object_emoji" {
- err(
+ try err(
\\{ð¨ð}
);
}
test "n_object_garbage_at_end" {
- err(
+ try err(
\\{"a":"a" 123}
);
}
test "n_object_key_with_single_quotes" {
- err(
+ try err(
\\{key: 'value'}
);
}
test "n_object_lone_continuation_byte_in_key_and_trailing_comma" {
- err(
+ try err(
\\{"¹":"0",}
);
}
test "n_object_missing_colon" {
- err(
+ try err(
\\{"a" b}
);
}
test "n_object_missing_key" {
- err(
+ try err(
\\{:"b"}
);
}
test "n_object_missing_semicolon" {
- err(
+ try err(
\\{"a" "b"}
);
}
test "n_object_missing_value" {
- err(
+ try err(
\\{"a":
);
}
test "n_object_no-colon" {
- err(
+ try err(
\\{"a"
);
}
test "n_object_non_string_key_but_huge_number_instead" {
- err(
+ try err(
\\{9999E9999:1}
);
}
test "n_object_non_string_key" {
- err(
+ try err(
\\{1:1}
);
}
test "n_object_repeated_null_null" {
- err(
+ try err(
\\{null:null,null:null}
);
}
test "n_object_several_trailing_commas" {
- err(
+ try err(
\\{"id":0,,,,,}
);
}
test "n_object_single_quote" {
- err(
+ try err(
\\{'a':0}
);
}
test "n_object_trailing_comma" {
- err(
+ try err(
\\{"id":0,}
);
}
test "n_object_trailing_comment" {
- err(
+ try err(
\\{"a":"b"}/**/
);
}
test "n_object_trailing_comment_open" {
- err(
+ try err(
\\{"a":"b"}/**//
);
}
test "n_object_trailing_comment_slash_open_incomplete" {
- err(
+ try err(
\\{"a":"b"}/
);
}
test "n_object_trailing_comment_slash_open" {
- err(
+ try err(
\\{"a":"b"}//
);
}
test "n_object_two_commas_in_a_row" {
- err(
+ try err(
\\{"a":"b",,"c":"d"}
);
}
test "n_object_unquoted_key" {
- err(
+ try err(
\\{a: "b"}
);
}
test "n_object_unterminated-value" {
- err(
+ try err(
\\{"a":"a
);
}
test "n_object_with_single_string" {
- err(
+ try err(
\\{ "foo" : "bar", "a" }
);
}
test "n_object_with_trailing_garbage" {
- err(
+ try err(
\\{"a":"b"}#
);
}
test "n_single_space" {
- err(" ");
+ try err(" ");
}
test "n_string_1_surrogate_then_escape" {
- err(
+ try err(
\\["\uD800\"]
);
}
test "n_string_1_surrogate_then_escape_u1" {
- err(
+ try err(
\\["\uD800\u1"]
);
}
test "n_string_1_surrogate_then_escape_u1x" {
- err(
+ try err(
\\["\uD800\u1x"]
);
}
test "n_string_1_surrogate_then_escape_u" {
- err(
+ try err(
\\["\uD800\u"]
);
}
test "n_string_accentuated_char_no_quotes" {
- err(
+ try err(
\\[é]
);
}
test "n_string_backslash_00" {
- err("[\"\x00\"]");
+ try err("[\"\x00\"]");
}
test "n_string_escaped_backslash_bad" {
- err(
+ try err(
\\["\\\"]
);
}
test "n_string_escaped_ctrl_char_tab" {
- err("\x5b\x22\x5c\x09\x22\x5d");
+ try err("\x5b\x22\x5c\x09\x22\x5d");
}
test "n_string_escaped_emoji" {
- err("[\"\x5c\xc3\xb0\xc2\x9f\xc2\x8c\xc2\x80\"]");
+ try err("[\"\x5c\xc3\xb0\xc2\x9f\xc2\x8c\xc2\x80\"]");
}
test "n_string_escape_x" {
- err(
+ try err(
\\["\x00"]
);
}
test "n_string_incomplete_escaped_character" {
- err(
+ try err(
\\["\u00A"]
);
}
test "n_string_incomplete_escape" {
- err(
+ try err(
\\["\"]
);
}
test "n_string_incomplete_surrogate_escape_invalid" {
- err(
+ try err(
\\["\uD800\uD800\x"]
);
}
test "n_string_incomplete_surrogate" {
- err(
+ try err(
\\["\uD834\uDd"]
);
}
test "n_string_invalid_backslash_esc" {
- err(
+ try err(
\\["\a"]
);
}
test "n_string_invalid_unicode_escape" {
- err(
+ try err(
\\["\uqqqq"]
);
}
test "n_string_invalid_utf8_after_escape" {
- err("[\"\\\x75\xc3\xa5\"]");
+ try err("[\"\\\x75\xc3\xa5\"]");
}
test "n_string_invalid-utf-8-in-escape" {
- err(
+ try err(
\\["\uå"]
);
}
test "n_string_leading_uescaped_thinspace" {
- err(
+ try err(
\\[\u0020"asd"]
);
}
test "n_string_no_quotes_with_bad_escape" {
- err(
+ try err(
\\[\n]
);
}
test "n_string_single_doublequote" {
- err(
+ try err(
\\"
);
}
test "n_string_single_quote" {
- err(
+ try err(
\\['single quote']
);
}
test "n_string_single_string_no_double_quotes" {
- err(
+ try err(
\\abc
);
}
test "n_string_start_escape_unclosed" {
- err(
+ try err(
\\["\
);
}
test "n_string_unescaped_crtl_char" {
- err("[\"a\x00a\"]");
+ try err("[\"a\x00a\"]");
}
test "n_string_unescaped_newline" {
- err(
+ try err(
\\["new
\\line"]
);
}
test "n_string_unescaped_tab" {
- err("[\"\t\"]");
+ try err("[\"\t\"]");
}
test "n_string_unicode_CapitalU" {
- err(
+ try err(
\\"\UA66D"
);
}
test "n_string_with_trailing_garbage" {
- err(
+ try err(
\\""x
);
}
test "n_structure_100000_opening_arrays" {
- err("[" ** 100000);
+ try err("[" ** 100000);
}
test "n_structure_angle_bracket_." {
- err(
+ try err(
\\<.>
);
}
test "n_structure_angle_bracket_null" {
- err(
+ try err(
\\[<null>]
);
}
test "n_structure_array_trailing_garbage" {
- err(
+ try err(
\\[1]x
);
}
test "n_structure_array_with_extra_array_close" {
- err(
+ try err(
\\[1]]
);
}
test "n_structure_array_with_unclosed_string" {
- err(
+ try err(
\\["asd]
);
}
test "n_structure_ascii-unicode-identifier" {
- err(
+ try err(
\\aå
);
}
test "n_structure_capitalized_True" {
- err(
+ try err(
\\[True]
);
}
test "n_structure_close_unopened_array" {
- err(
+ try err(
\\1]
);
}
test "n_structure_comma_instead_of_closing_brace" {
- err(
+ try err(
\\{"x": true,
);
}
test "n_structure_double_array" {
- err(
+ try err(
\\[][]
);
}
test "n_structure_end_array" {
- err(
+ try err(
\\]
);
}
test "n_structure_incomplete_UTF8_BOM" {
- err(
+ try err(
\\ï»{}
);
}
test "n_structure_lone-invalid-utf-8" {
- err(
+ try err(
\\å
);
}
test "n_structure_lone-open-bracket" {
- err(
+ try err(
\\[
);
}
test "n_structure_no_data" {
- err(
+ try err(
\\
);
}
test "n_structure_null-byte-outside-string" {
- err("[\x00]");
+ try err("[\x00]");
}
test "n_structure_number_with_trailing_garbage" {
- err(
+ try err(
\\2@
);
}
test "n_structure_object_followed_by_closing_object" {
- err(
+ try err(
\\{}}
);
}
test "n_structure_object_unclosed_no_value" {
- err(
+ try err(
\\{"":
);
}
test "n_structure_object_with_comment" {
- err(
+ try err(
\\{"a":/*comment*/"b"}
);
}
test "n_structure_object_with_trailing_garbage" {
- err(
+ try err(
\\{"a": true} "x"
);
}
test "n_structure_open_array_apostrophe" {
- err(
+ try err(
\\['
);
}
test "n_structure_open_array_comma" {
- err(
+ try err(
\\[,
);
}
test "n_structure_open_array_object" {
- err("[{\"\":" ** 50000);
+ try err("[{\"\":" ** 50000);
}
test "n_structure_open_array_open_object" {
- err(
+ try err(
\\[{
);
}
test "n_structure_open_array_open_string" {
- err(
+ try err(
\\["a
);
}
test "n_structure_open_array_string" {
- err(
+ try err(
\\["a"
);
}
test "n_structure_open_object_close_array" {
- err(
+ try err(
\\{]
);
}
test "n_structure_open_object_comma" {
- err(
+ try err(
\\{,
);
}
test "n_structure_open_object" {
- err(
+ try err(
\\{
);
}
test "n_structure_open_object_open_array" {
- err(
+ try err(
\\{[
);
}
test "n_structure_open_object_open_string" {
- err(
+ try err(
\\{"a
);
}
test "n_structure_open_object_string_with_apostrophes" {
- err(
+ try err(
\\{'a'
);
}
test "n_structure_open_open" {
- err(
+ try err(
\\["\{["\{["\{["\{
);
}
test "n_structure_single_eacute" {
- err(
+ try err(
\\é
);
}
test "n_structure_single_star" {
- err(
+ try err(
\\*
);
}
test "n_structure_trailing_#" {
- err(
+ try err(
\\{"a":"b"}#{}
);
}
test "n_structure_U+2060_word_joined" {
- err(
+ try err(
\\[â ]
);
}
test "n_structure_uescaped_LF_before_string" {
- err(
+ try err(
\\[\u000A""]
);
}
test "n_structure_unclosed_array" {
- err(
+ try err(
\\[1
);
}
test "n_structure_unclosed_array_partial_null" {
- err(
+ try err(
\\[ false, nul
);
}
test "n_structure_unclosed_array_unfinished_false" {
- err(
+ try err(
\\[ true, fals
);
}
test "n_structure_unclosed_array_unfinished_true" {
- err(
+ try err(
\\[ false, tru
);
}
test "n_structure_unclosed_object" {
- err(
+ try err(
\\{"asd":"asd"
);
}
test "n_structure_unicode-identifier" {
- err(
+ try err(
\\Ã¥
);
}
test "n_structure_UTF8_BOM_no_data" {
- err(
+ try err(
\\
);
}
test "n_structure_whitespace_formfeed" {
- err("[\x0c]");
+ try err("[\x0c]");
}
test "n_structure_whitespace_U+2060_word_joiner" {
- err(
+ try err(
\\[â ]
);
}
@@ -1751,255 +1751,255 @@ test "n_structure_whitespace_U+2060_word_joiner" {
////////////////////////////////////////////////////////////////////////////////////////////////////
test "i_number_double_huge_neg_exp" {
- any(
+ try any(
\\[123.456e-789]
);
}
test "i_number_huge_exp" {
- any(
+ try any(
\\[0.4e00669999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999969999999006]
);
}
test "i_number_neg_int_huge_exp" {
- any(
+ try any(
\\[-1e+9999]
);
}
test "i_number_pos_double_huge_exp" {
- any(
+ try any(
\\[1.5e+9999]
);
}
test "i_number_real_neg_overflow" {
- any(
+ try any(
\\[-123123e100000]
);
}
test "i_number_real_pos_overflow" {
- any(
+ try any(
\\[123123e100000]
);
}
test "i_number_real_underflow" {
- any(
+ try any(
\\[123e-10000000]
);
}
test "i_number_too_big_neg_int" {
- any(
+ try any(
\\[-123123123123123123123123123123]
);
}
test "i_number_too_big_pos_int" {
- any(
+ try any(
\\[100000000000000000000]
);
}
test "i_number_very_big_negative_int" {
- any(
+ try any(
\\[-237462374673276894279832749832423479823246327846]
);
}
test "i_object_key_lone_2nd_surrogate" {
- anyStreamingErrNonStreaming(
+ try anyStreamingErrNonStreaming(
\\{"\uDFAA":0}
);
}
test "i_string_1st_surrogate_but_2nd_missing" {
- anyStreamingErrNonStreaming(
+ try anyStreamingErrNonStreaming(
\\["\uDADA"]
);
}
test "i_string_1st_valid_surrogate_2nd_invalid" {
- anyStreamingErrNonStreaming(
+ try anyStreamingErrNonStreaming(
\\["\uD888\u1234"]
);
}
test "i_string_incomplete_surrogate_and_escape_valid" {
- anyStreamingErrNonStreaming(
+ try anyStreamingErrNonStreaming(
\\["\uD800\n"]
);
}
test "i_string_incomplete_surrogate_pair" {
- anyStreamingErrNonStreaming(
+ try anyStreamingErrNonStreaming(
\\["\uDd1ea"]
);
}
test "i_string_incomplete_surrogates_escape_valid" {
- anyStreamingErrNonStreaming(
+ try anyStreamingErrNonStreaming(
\\["\uD800\uD800\n"]
);
}
test "i_string_invalid_lonely_surrogate" {
- anyStreamingErrNonStreaming(
+ try anyStreamingErrNonStreaming(
\\["\ud800"]
);
}
test "i_string_invalid_surrogate" {
- anyStreamingErrNonStreaming(
+ try anyStreamingErrNonStreaming(
\\["\ud800abc"]
);
}
test "i_string_invalid_utf-8" {
- any(
+ try any(
\\["ÿ"]
);
}
test "i_string_inverted_surrogates_U+1D11E" {
- anyStreamingErrNonStreaming(
+ try anyStreamingErrNonStreaming(
\\["\uDd1e\uD834"]
);
}
test "i_string_iso_latin_1" {
- any(
+ try any(
\\["é"]
);
}
test "i_string_lone_second_surrogate" {
- anyStreamingErrNonStreaming(
+ try anyStreamingErrNonStreaming(
\\["\uDFAA"]
);
}
test "i_string_lone_utf8_continuation_byte" {
- any(
+ try any(
\\[""]
);
}
test "i_string_not_in_unicode_range" {
- any(
+ try any(
\\["ô¿¿¿"]
);
}
test "i_string_overlong_sequence_2_bytes" {
- any(
+ try any(
\\["À¯"]
);
}
test "i_string_overlong_sequence_6_bytes" {
- any(
+ try any(
\\["ü¿¿¿¿"]
);
}
test "i_string_overlong_sequence_6_bytes_null" {
- any(
+ try any(
\\["ü"]
);
}
test "i_string_truncated-utf-8" {
- any(
+ try any(
\\["àÿ"]
);
}
test "i_string_utf16BE_no_BOM" {
- any("\x00\x5b\x00\x22\x00\xc3\xa9\x00\x22\x00\x5d");
+ try any("\x00\x5b\x00\x22\x00\xc3\xa9\x00\x22\x00\x5d");
}
test "i_string_utf16LE_no_BOM" {
- any("\x5b\x00\x22\x00\xc3\xa9\x00\x22\x00\x5d\x00");
+ try any("\x5b\x00\x22\x00\xc3\xa9\x00\x22\x00\x5d\x00");
}
test "i_string_UTF-16LE_with_BOM" {
- any("\xc3\xbf\xc3\xbe\x5b\x00\x22\x00\xc3\xa9\x00\x22\x00\x5d\x00");
+ try any("\xc3\xbf\xc3\xbe\x5b\x00\x22\x00\xc3\xa9\x00\x22\x00\x5d\x00");
}
test "i_string_UTF-8_invalid_sequence" {
- any(
+ try any(
\\["æ¥Ñú"]
);
}
test "i_string_UTF8_surrogate_U+D800" {
- any(
+ try any(
\\["í "]
);
}
test "i_structure_500_nested_arrays" {
- any(("[" ** 500) ++ ("]" ** 500));
+ try any(("[" ** 500) ++ ("]" ** 500));
}
test "i_structure_UTF-8_BOM_empty_object" {
- any(
+ try any(
\\{}
);
}
test "truncated UTF-8 sequence" {
- utf8Error("\"\xc2\"");
- utf8Error("\"\xdf\"");
- utf8Error("\"\xed\xa0\"");
- utf8Error("\"\xf0\x80\"");
- utf8Error("\"\xf0\x80\x80\"");
+ try utf8Error("\"\xc2\"");
+ try utf8Error("\"\xdf\"");
+ try utf8Error("\"\xed\xa0\"");
+ try utf8Error("\"\xf0\x80\"");
+ try utf8Error("\"\xf0\x80\x80\"");
}
test "invalid continuation byte" {
- utf8Error("\"\xc2\x00\"");
- utf8Error("\"\xc2\x7f\"");
- utf8Error("\"\xc2\xc0\"");
- utf8Error("\"\xc3\xc1\"");
- utf8Error("\"\xc4\xf5\"");
- utf8Error("\"\xc5\xff\"");
- utf8Error("\"\xe4\x80\x00\"");
- utf8Error("\"\xe5\x80\x10\"");
- utf8Error("\"\xe6\x80\xc0\"");
- utf8Error("\"\xe7\x80\xf5\"");
- utf8Error("\"\xe8\x00\x80\"");
- utf8Error("\"\xf2\x00\x80\x80\"");
- utf8Error("\"\xf0\x80\x00\x80\"");
- utf8Error("\"\xf1\x80\xc0\x80\"");
- utf8Error("\"\xf2\x80\x80\x00\"");
- utf8Error("\"\xf3\x80\x80\xc0\"");
- utf8Error("\"\xf4\x80\x80\xf5\"");
+ try utf8Error("\"\xc2\x00\"");
+ try utf8Error("\"\xc2\x7f\"");
+ try utf8Error("\"\xc2\xc0\"");
+ try utf8Error("\"\xc3\xc1\"");
+ try utf8Error("\"\xc4\xf5\"");
+ try utf8Error("\"\xc5\xff\"");
+ try utf8Error("\"\xe4\x80\x00\"");
+ try utf8Error("\"\xe5\x80\x10\"");
+ try utf8Error("\"\xe6\x80\xc0\"");
+ try utf8Error("\"\xe7\x80\xf5\"");
+ try utf8Error("\"\xe8\x00\x80\"");
+ try utf8Error("\"\xf2\x00\x80\x80\"");
+ try utf8Error("\"\xf0\x80\x00\x80\"");
+ try utf8Error("\"\xf1\x80\xc0\x80\"");
+ try utf8Error("\"\xf2\x80\x80\x00\"");
+ try utf8Error("\"\xf3\x80\x80\xc0\"");
+ try utf8Error("\"\xf4\x80\x80\xf5\"");
}
test "disallowed overlong form" {
- utf8Error("\"\xc0\x80\"");
- utf8Error("\"\xc0\x90\"");
- utf8Error("\"\xc1\x80\"");
- utf8Error("\"\xc1\x90\"");
- utf8Error("\"\xe0\x80\x80\"");
- utf8Error("\"\xf0\x80\x80\x80\"");
+ try utf8Error("\"\xc0\x80\"");
+ try utf8Error("\"\xc0\x90\"");
+ try utf8Error("\"\xc1\x80\"");
+ try utf8Error("\"\xc1\x90\"");
+ try utf8Error("\"\xe0\x80\x80\"");
+ try utf8Error("\"\xf0\x80\x80\x80\"");
}
test "out of UTF-16 range" {
- utf8Error("\"\xf4\x90\x80\x80\"");
- utf8Error("\"\xf5\x80\x80\x80\"");
- utf8Error("\"\xf6\x80\x80\x80\"");
- utf8Error("\"\xf7\x80\x80\x80\"");
- utf8Error("\"\xf8\x80\x80\x80\"");
- utf8Error("\"\xf9\x80\x80\x80\"");
- utf8Error("\"\xfa\x80\x80\x80\"");
- utf8Error("\"\xfb\x80\x80\x80\"");
- utf8Error("\"\xfc\x80\x80\x80\"");
- utf8Error("\"\xfd\x80\x80\x80\"");
- utf8Error("\"\xfe\x80\x80\x80\"");
- utf8Error("\"\xff\x80\x80\x80\"");
+ try utf8Error("\"\xf4\x90\x80\x80\"");
+ try utf8Error("\"\xf5\x80\x80\x80\"");
+ try utf8Error("\"\xf6\x80\x80\x80\"");
+ try utf8Error("\"\xf7\x80\x80\x80\"");
+ try utf8Error("\"\xf8\x80\x80\x80\"");
+ try utf8Error("\"\xf9\x80\x80\x80\"");
+ try utf8Error("\"\xfa\x80\x80\x80\"");
+ try utf8Error("\"\xfb\x80\x80\x80\"");
+ try utf8Error("\"\xfc\x80\x80\x80\"");
+ try utf8Error("\"\xfd\x80\x80\x80\"");
+ try utf8Error("\"\xfe\x80\x80\x80\"");
+ try utf8Error("\"\xff\x80\x80\x80\"");
}
lib/std/json/write_stream.zig
@@ -288,7 +288,7 @@ test "json write stream" {
\\ "float": 3.5e+00
\\}
;
- std.testing.expect(std.mem.eql(u8, expected, result));
+ try std.testing.expect(std.mem.eql(u8, expected, result));
}
fn getJsonObject(allocator: *std.mem.Allocator) !std.json.Value {
lib/std/math/big/int_test.zig
@@ -30,7 +30,7 @@ test "big.int comptime_int set" {
const result = @as(Limb, s & maxInt(Limb));
s >>= @typeInfo(Limb).Int.bits / 2;
s >>= @typeInfo(Limb).Int.bits / 2;
- testing.expect(a.limbs[i] == result);
+ try testing.expect(a.limbs[i] == result);
}
}
@@ -38,37 +38,37 @@ test "big.int comptime_int set negative" {
var a = try Managed.initSet(testing.allocator, -10);
defer a.deinit();
- testing.expect(a.limbs[0] == 10);
- testing.expect(a.isPositive() == false);
+ try testing.expect(a.limbs[0] == 10);
+ try testing.expect(a.isPositive() == false);
}
test "big.int int set unaligned small" {
var a = try Managed.initSet(testing.allocator, @as(u7, 45));
defer a.deinit();
- testing.expect(a.limbs[0] == 45);
- testing.expect(a.isPositive() == true);
+ try testing.expect(a.limbs[0] == 45);
+ try testing.expect(a.isPositive() == true);
}
test "big.int comptime_int to" {
var a = try Managed.initSet(testing.allocator, 0xefffffff00000001eeeeeeefaaaaaaab);
defer a.deinit();
- testing.expect((try a.to(u128)) == 0xefffffff00000001eeeeeeefaaaaaaab);
+ try testing.expect((try a.to(u128)) == 0xefffffff00000001eeeeeeefaaaaaaab);
}
test "big.int sub-limb to" {
var a = try Managed.initSet(testing.allocator, 10);
defer a.deinit();
- testing.expect((try a.to(u8)) == 10);
+ try testing.expect((try a.to(u8)) == 10);
}
test "big.int to target too small error" {
var a = try Managed.initSet(testing.allocator, 0xffffffff);
defer a.deinit();
- testing.expectError(error.TargetTooSmall, a.to(u8));
+ try testing.expectError(error.TargetTooSmall, a.to(u8));
}
test "big.int normalize" {
@@ -81,22 +81,22 @@ test "big.int normalize" {
a.limbs[2] = 3;
a.limbs[3] = 0;
a.normalize(4);
- testing.expect(a.len() == 3);
+ try testing.expect(a.len() == 3);
a.limbs[0] = 1;
a.limbs[1] = 2;
a.limbs[2] = 3;
a.normalize(3);
- testing.expect(a.len() == 3);
+ try testing.expect(a.len() == 3);
a.limbs[0] = 0;
a.limbs[1] = 0;
a.normalize(2);
- testing.expect(a.len() == 1);
+ try testing.expect(a.len() == 1);
a.limbs[0] = 0;
a.normalize(1);
- testing.expect(a.len() == 1);
+ try testing.expect(a.len() == 1);
}
test "big.int normalize multi" {
@@ -109,24 +109,24 @@ test "big.int normalize multi" {
a.limbs[2] = 0;
a.limbs[3] = 0;
a.normalize(4);
- testing.expect(a.len() == 2);
+ try testing.expect(a.len() == 2);
a.limbs[0] = 1;
a.limbs[1] = 2;
a.limbs[2] = 3;
a.normalize(3);
- testing.expect(a.len() == 3);
+ try testing.expect(a.len() == 3);
a.limbs[0] = 0;
a.limbs[1] = 0;
a.limbs[2] = 0;
a.limbs[3] = 0;
a.normalize(4);
- testing.expect(a.len() == 1);
+ try testing.expect(a.len() == 1);
a.limbs[0] = 0;
a.normalize(1);
- testing.expect(a.len() == 1);
+ try testing.expect(a.len() == 1);
}
test "big.int parity" {
@@ -134,12 +134,12 @@ test "big.int parity" {
defer a.deinit();
try a.set(0);
- testing.expect(a.isEven());
- testing.expect(!a.isOdd());
+ try testing.expect(a.isEven());
+ try testing.expect(!a.isOdd());
try a.set(7);
- testing.expect(!a.isEven());
- testing.expect(a.isOdd());
+ try testing.expect(!a.isEven());
+ try testing.expect(a.isOdd());
}
test "big.int bitcount + sizeInBaseUpperBound" {
@@ -147,27 +147,27 @@ test "big.int bitcount + sizeInBaseUpperBound" {
defer a.deinit();
try a.set(0b100);
- testing.expect(a.bitCountAbs() == 3);
- testing.expect(a.sizeInBaseUpperBound(2) >= 3);
- testing.expect(a.sizeInBaseUpperBound(10) >= 1);
+ try testing.expect(a.bitCountAbs() == 3);
+ try testing.expect(a.sizeInBaseUpperBound(2) >= 3);
+ try testing.expect(a.sizeInBaseUpperBound(10) >= 1);
a.negate();
- testing.expect(a.bitCountAbs() == 3);
- testing.expect(a.sizeInBaseUpperBound(2) >= 4);
- testing.expect(a.sizeInBaseUpperBound(10) >= 2);
+ try testing.expect(a.bitCountAbs() == 3);
+ try testing.expect(a.sizeInBaseUpperBound(2) >= 4);
+ try testing.expect(a.sizeInBaseUpperBound(10) >= 2);
try a.set(0xffffffff);
- testing.expect(a.bitCountAbs() == 32);
- testing.expect(a.sizeInBaseUpperBound(2) >= 32);
- testing.expect(a.sizeInBaseUpperBound(10) >= 10);
+ try testing.expect(a.bitCountAbs() == 32);
+ try testing.expect(a.sizeInBaseUpperBound(2) >= 32);
+ try testing.expect(a.sizeInBaseUpperBound(10) >= 10);
try a.shiftLeft(a, 5000);
- testing.expect(a.bitCountAbs() == 5032);
- testing.expect(a.sizeInBaseUpperBound(2) >= 5032);
+ try testing.expect(a.bitCountAbs() == 5032);
+ try testing.expect(a.sizeInBaseUpperBound(2) >= 5032);
a.setSign(false);
- testing.expect(a.bitCountAbs() == 5032);
- testing.expect(a.sizeInBaseUpperBound(2) >= 5033);
+ try testing.expect(a.bitCountAbs() == 5032);
+ try testing.expect(a.sizeInBaseUpperBound(2) >= 5033);
}
test "big.int bitcount/to" {
@@ -175,30 +175,30 @@ test "big.int bitcount/to" {
defer a.deinit();
try a.set(0);
- testing.expect(a.bitCountTwosComp() == 0);
+ try testing.expect(a.bitCountTwosComp() == 0);
- testing.expect((try a.to(u0)) == 0);
- testing.expect((try a.to(i0)) == 0);
+ try testing.expect((try a.to(u0)) == 0);
+ try testing.expect((try a.to(i0)) == 0);
try a.set(-1);
- testing.expect(a.bitCountTwosComp() == 1);
- testing.expect((try a.to(i1)) == -1);
+ try testing.expect(a.bitCountTwosComp() == 1);
+ try testing.expect((try a.to(i1)) == -1);
try a.set(-8);
- testing.expect(a.bitCountTwosComp() == 4);
- testing.expect((try a.to(i4)) == -8);
+ try testing.expect(a.bitCountTwosComp() == 4);
+ try testing.expect((try a.to(i4)) == -8);
try a.set(127);
- testing.expect(a.bitCountTwosComp() == 7);
- testing.expect((try a.to(u7)) == 127);
+ try testing.expect(a.bitCountTwosComp() == 7);
+ try testing.expect((try a.to(u7)) == 127);
try a.set(-128);
- testing.expect(a.bitCountTwosComp() == 8);
- testing.expect((try a.to(i8)) == -128);
+ try testing.expect(a.bitCountTwosComp() == 8);
+ try testing.expect((try a.to(i8)) == -128);
try a.set(-129);
- testing.expect(a.bitCountTwosComp() == 9);
- testing.expect((try a.to(i9)) == -129);
+ try testing.expect(a.bitCountTwosComp() == 9);
+ try testing.expect((try a.to(i9)) == -129);
}
test "big.int fits" {
@@ -206,27 +206,27 @@ test "big.int fits" {
defer a.deinit();
try a.set(0);
- testing.expect(a.fits(u0));
- testing.expect(a.fits(i0));
+ try testing.expect(a.fits(u0));
+ try testing.expect(a.fits(i0));
try a.set(255);
- testing.expect(!a.fits(u0));
- testing.expect(!a.fits(u1));
- testing.expect(!a.fits(i8));
- testing.expect(a.fits(u8));
- testing.expect(a.fits(u9));
- testing.expect(a.fits(i9));
+ try testing.expect(!a.fits(u0));
+ try testing.expect(!a.fits(u1));
+ try testing.expect(!a.fits(i8));
+ try testing.expect(a.fits(u8));
+ try testing.expect(a.fits(u9));
+ try testing.expect(a.fits(i9));
try a.set(-128);
- testing.expect(!a.fits(i7));
- testing.expect(a.fits(i8));
- testing.expect(a.fits(i9));
- testing.expect(!a.fits(u9));
+ try testing.expect(!a.fits(i7));
+ try testing.expect(a.fits(i8));
+ try testing.expect(a.fits(i9));
+ try testing.expect(!a.fits(u9));
try a.set(0x1ffffffffeeeeeeee);
- testing.expect(!a.fits(u32));
- testing.expect(!a.fits(u64));
- testing.expect(a.fits(u65));
+ try testing.expect(!a.fits(u32));
+ try testing.expect(!a.fits(u64));
+ try testing.expect(a.fits(u65));
}
test "big.int string set" {
@@ -234,7 +234,7 @@ test "big.int string set" {
defer a.deinit();
try a.setString(10, "120317241209124781241290847124");
- testing.expect((try a.to(u128)) == 120317241209124781241290847124);
+ try testing.expect((try a.to(u128)) == 120317241209124781241290847124);
}
test "big.int string negative" {
@@ -242,7 +242,7 @@ test "big.int string negative" {
defer a.deinit();
try a.setString(10, "-1023");
- testing.expect((try a.to(i32)) == -1023);
+ try testing.expect((try a.to(i32)) == -1023);
}
test "big.int string set number with underscores" {
@@ -250,7 +250,7 @@ test "big.int string set number with underscores" {
defer a.deinit();
try a.setString(10, "__1_2_0_3_1_7_2_4_1_2_0_____9_1__2__4_7_8_1_2_4_1_2_9_0_8_4_7_1_2_4___");
- testing.expect((try a.to(u128)) == 120317241209124781241290847124);
+ try testing.expect((try a.to(u128)) == 120317241209124781241290847124);
}
test "big.int string set case insensitive number" {
@@ -258,19 +258,19 @@ test "big.int string set case insensitive number" {
defer a.deinit();
try a.setString(16, "aB_cD_eF");
- testing.expect((try a.to(u32)) == 0xabcdef);
+ try testing.expect((try a.to(u32)) == 0xabcdef);
}
test "big.int string set bad char error" {
var a = try Managed.init(testing.allocator);
defer a.deinit();
- testing.expectError(error.InvalidCharacter, a.setString(10, "x"));
+ try testing.expectError(error.InvalidCharacter, a.setString(10, "x"));
}
test "big.int string set bad base error" {
var a = try Managed.init(testing.allocator);
defer a.deinit();
- testing.expectError(error.InvalidBase, a.setString(45, "10"));
+ try testing.expectError(error.InvalidBase, a.setString(45, "10"));
}
test "big.int string to" {
@@ -281,14 +281,14 @@ test "big.int string to" {
defer testing.allocator.free(as);
const es = "120317241209124781241290847124";
- testing.expect(mem.eql(u8, as, es));
+ try testing.expect(mem.eql(u8, as, es));
}
test "big.int string to base base error" {
var a = try Managed.initSet(testing.allocator, 0xffffffff);
defer a.deinit();
- testing.expectError(error.InvalidBase, a.toString(testing.allocator, 45, false));
+ try testing.expectError(error.InvalidBase, a.toString(testing.allocator, 45, false));
}
test "big.int string to base 2" {
@@ -299,7 +299,7 @@ test "big.int string to base 2" {
defer testing.allocator.free(as);
const es = "-1011";
- testing.expect(mem.eql(u8, as, es));
+ try testing.expect(mem.eql(u8, as, es));
}
test "big.int string to base 16" {
@@ -310,7 +310,7 @@ test "big.int string to base 16" {
defer testing.allocator.free(as);
const es = "efffffff00000001eeeeeeefaaaaaaab";
- testing.expect(mem.eql(u8, as, es));
+ try testing.expect(mem.eql(u8, as, es));
}
test "big.int neg string to" {
@@ -321,7 +321,7 @@ test "big.int neg string to" {
defer testing.allocator.free(as);
const es = "-123907434";
- testing.expect(mem.eql(u8, as, es));
+ try testing.expect(mem.eql(u8, as, es));
}
test "big.int zero string to" {
@@ -332,7 +332,7 @@ test "big.int zero string to" {
defer testing.allocator.free(as);
const es = "0";
- testing.expect(mem.eql(u8, as, es));
+ try testing.expect(mem.eql(u8, as, es));
}
test "big.int clone" {
@@ -341,12 +341,12 @@ test "big.int clone" {
var b = try a.clone();
defer b.deinit();
- testing.expect((try a.to(u32)) == 1234);
- testing.expect((try b.to(u32)) == 1234);
+ try testing.expect((try a.to(u32)) == 1234);
+ try testing.expect((try b.to(u32)) == 1234);
try a.set(77);
- testing.expect((try a.to(u32)) == 77);
- testing.expect((try b.to(u32)) == 1234);
+ try testing.expect((try a.to(u32)) == 77);
+ try testing.expect((try b.to(u32)) == 1234);
}
test "big.int swap" {
@@ -355,20 +355,20 @@ test "big.int swap" {
var b = try Managed.initSet(testing.allocator, 5678);
defer b.deinit();
- testing.expect((try a.to(u32)) == 1234);
- testing.expect((try b.to(u32)) == 5678);
+ try testing.expect((try a.to(u32)) == 1234);
+ try testing.expect((try b.to(u32)) == 5678);
a.swap(&b);
- testing.expect((try a.to(u32)) == 5678);
- testing.expect((try b.to(u32)) == 1234);
+ try testing.expect((try a.to(u32)) == 5678);
+ try testing.expect((try b.to(u32)) == 1234);
}
test "big.int to negative" {
var a = try Managed.initSet(testing.allocator, -10);
defer a.deinit();
- testing.expect((try a.to(i32)) == -10);
+ try testing.expect((try a.to(i32)) == -10);
}
test "big.int compare" {
@@ -377,8 +377,8 @@ test "big.int compare" {
var b = try Managed.initSet(testing.allocator, 10);
defer b.deinit();
- testing.expect(a.orderAbs(b) == .gt);
- testing.expect(a.order(b) == .lt);
+ try testing.expect(a.orderAbs(b) == .gt);
+ try testing.expect(a.order(b) == .lt);
}
test "big.int compare similar" {
@@ -387,8 +387,8 @@ test "big.int compare similar" {
var b = try Managed.initSet(testing.allocator, 0xffffffffeeeeeeeeffffffffeeeeeeef);
defer b.deinit();
- testing.expect(a.orderAbs(b) == .lt);
- testing.expect(b.orderAbs(a) == .gt);
+ try testing.expect(a.orderAbs(b) == .lt);
+ try testing.expect(b.orderAbs(a) == .gt);
}
test "big.int compare different limb size" {
@@ -397,8 +397,8 @@ test "big.int compare different limb size" {
var b = try Managed.initSet(testing.allocator, 1);
defer b.deinit();
- testing.expect(a.orderAbs(b) == .gt);
- testing.expect(b.orderAbs(a) == .lt);
+ try testing.expect(a.orderAbs(b) == .gt);
+ try testing.expect(b.orderAbs(a) == .lt);
}
test "big.int compare multi-limb" {
@@ -407,8 +407,8 @@ test "big.int compare multi-limb" {
var b = try Managed.initSet(testing.allocator, 0x7777777799999999ffffeeeeffffeeeeffffeeeee);
defer b.deinit();
- testing.expect(a.orderAbs(b) == .gt);
- testing.expect(a.order(b) == .lt);
+ try testing.expect(a.orderAbs(b) == .gt);
+ try testing.expect(a.order(b) == .lt);
}
test "big.int equality" {
@@ -417,8 +417,8 @@ test "big.int equality" {
var b = try Managed.initSet(testing.allocator, -0xffffffff1);
defer b.deinit();
- testing.expect(a.eqAbs(b));
- testing.expect(!a.eq(b));
+ try testing.expect(a.eqAbs(b));
+ try testing.expect(!a.eq(b));
}
test "big.int abs" {
@@ -426,10 +426,10 @@ test "big.int abs" {
defer a.deinit();
a.abs();
- testing.expect((try a.to(u32)) == 5);
+ try testing.expect((try a.to(u32)) == 5);
a.abs();
- testing.expect((try a.to(u32)) == 5);
+ try testing.expect((try a.to(u32)) == 5);
}
test "big.int negate" {
@@ -437,10 +437,10 @@ test "big.int negate" {
defer a.deinit();
a.negate();
- testing.expect((try a.to(i32)) == -5);
+ try testing.expect((try a.to(i32)) == -5);
a.negate();
- testing.expect((try a.to(i32)) == 5);
+ try testing.expect((try a.to(i32)) == 5);
}
test "big.int add single-single" {
@@ -453,7 +453,7 @@ test "big.int add single-single" {
defer c.deinit();
try c.add(a.toConst(), b.toConst());
- testing.expect((try c.to(u32)) == 55);
+ try testing.expect((try c.to(u32)) == 55);
}
test "big.int add multi-single" {
@@ -466,10 +466,10 @@ test "big.int add multi-single" {
defer c.deinit();
try c.add(a.toConst(), b.toConst());
- testing.expect((try c.to(DoubleLimb)) == maxInt(Limb) + 2);
+ try testing.expect((try c.to(DoubleLimb)) == maxInt(Limb) + 2);
try c.add(b.toConst(), a.toConst());
- testing.expect((try c.to(DoubleLimb)) == maxInt(Limb) + 2);
+ try testing.expect((try c.to(DoubleLimb)) == maxInt(Limb) + 2);
}
test "big.int add multi-multi" {
@@ -484,7 +484,7 @@ test "big.int add multi-multi" {
defer c.deinit();
try c.add(a.toConst(), b.toConst());
- testing.expect((try c.to(u128)) == op1 + op2);
+ try testing.expect((try c.to(u128)) == op1 + op2);
}
test "big.int add zero-zero" {
@@ -497,7 +497,7 @@ test "big.int add zero-zero" {
defer c.deinit();
try c.add(a.toConst(), b.toConst());
- testing.expect((try c.to(u32)) == 0);
+ try testing.expect((try c.to(u32)) == 0);
}
test "big.int add alias multi-limb nonzero-zero" {
@@ -509,7 +509,7 @@ test "big.int add alias multi-limb nonzero-zero" {
try a.add(a.toConst(), b.toConst());
- testing.expect((try a.to(u128)) == op1);
+ try testing.expect((try a.to(u128)) == op1);
}
test "big.int add sign" {
@@ -526,16 +526,16 @@ test "big.int add sign" {
defer neg_two.deinit();
try a.add(one.toConst(), two.toConst());
- testing.expect((try a.to(i32)) == 3);
+ try testing.expect((try a.to(i32)) == 3);
try a.add(neg_one.toConst(), two.toConst());
- testing.expect((try a.to(i32)) == 1);
+ try testing.expect((try a.to(i32)) == 1);
try a.add(one.toConst(), neg_two.toConst());
- testing.expect((try a.to(i32)) == -1);
+ try testing.expect((try a.to(i32)) == -1);
try a.add(neg_one.toConst(), neg_two.toConst());
- testing.expect((try a.to(i32)) == -3);
+ try testing.expect((try a.to(i32)) == -3);
}
test "big.int sub single-single" {
@@ -548,7 +548,7 @@ test "big.int sub single-single" {
defer c.deinit();
try c.sub(a.toConst(), b.toConst());
- testing.expect((try c.to(u32)) == 45);
+ try testing.expect((try c.to(u32)) == 45);
}
test "big.int sub multi-single" {
@@ -561,7 +561,7 @@ test "big.int sub multi-single" {
defer c.deinit();
try c.sub(a.toConst(), b.toConst());
- testing.expect((try c.to(Limb)) == maxInt(Limb));
+ try testing.expect((try c.to(Limb)) == maxInt(Limb));
}
test "big.int sub multi-multi" {
@@ -577,7 +577,7 @@ test "big.int sub multi-multi" {
defer c.deinit();
try c.sub(a.toConst(), b.toConst());
- testing.expect((try c.to(u128)) == op1 - op2);
+ try testing.expect((try c.to(u128)) == op1 - op2);
}
test "big.int sub equal" {
@@ -590,7 +590,7 @@ test "big.int sub equal" {
defer c.deinit();
try c.sub(a.toConst(), b.toConst());
- testing.expect((try c.to(u32)) == 0);
+ try testing.expect((try c.to(u32)) == 0);
}
test "big.int sub sign" {
@@ -607,19 +607,19 @@ test "big.int sub sign" {
defer neg_two.deinit();
try a.sub(one.toConst(), two.toConst());
- testing.expect((try a.to(i32)) == -1);
+ try testing.expect((try a.to(i32)) == -1);
try a.sub(neg_one.toConst(), two.toConst());
- testing.expect((try a.to(i32)) == -3);
+ try testing.expect((try a.to(i32)) == -3);
try a.sub(one.toConst(), neg_two.toConst());
- testing.expect((try a.to(i32)) == 3);
+ try testing.expect((try a.to(i32)) == 3);
try a.sub(neg_one.toConst(), neg_two.toConst());
- testing.expect((try a.to(i32)) == 1);
+ try testing.expect((try a.to(i32)) == 1);
try a.sub(neg_two.toConst(), neg_one.toConst());
- testing.expect((try a.to(i32)) == -1);
+ try testing.expect((try a.to(i32)) == -1);
}
test "big.int mul single-single" {
@@ -632,7 +632,7 @@ test "big.int mul single-single" {
defer c.deinit();
try c.mul(a.toConst(), b.toConst());
- testing.expect((try c.to(u64)) == 250);
+ try testing.expect((try c.to(u64)) == 250);
}
test "big.int mul multi-single" {
@@ -645,7 +645,7 @@ test "big.int mul multi-single" {
defer c.deinit();
try c.mul(a.toConst(), b.toConst());
- testing.expect((try c.to(DoubleLimb)) == 2 * maxInt(Limb));
+ try testing.expect((try c.to(DoubleLimb)) == 2 * maxInt(Limb));
}
test "big.int mul multi-multi" {
@@ -660,7 +660,7 @@ test "big.int mul multi-multi" {
defer c.deinit();
try c.mul(a.toConst(), b.toConst());
- testing.expect((try c.to(u256)) == op1 * op2);
+ try testing.expect((try c.to(u256)) == op1 * op2);
}
test "big.int mul alias r with a" {
@@ -671,7 +671,7 @@ test "big.int mul alias r with a" {
try a.mul(a.toConst(), b.toConst());
- testing.expect((try a.to(DoubleLimb)) == 2 * maxInt(Limb));
+ try testing.expect((try a.to(DoubleLimb)) == 2 * maxInt(Limb));
}
test "big.int mul alias r with b" {
@@ -682,7 +682,7 @@ test "big.int mul alias r with b" {
try a.mul(b.toConst(), a.toConst());
- testing.expect((try a.to(DoubleLimb)) == 2 * maxInt(Limb));
+ try testing.expect((try a.to(DoubleLimb)) == 2 * maxInt(Limb));
}
test "big.int mul alias r with a and b" {
@@ -691,7 +691,7 @@ test "big.int mul alias r with a and b" {
try a.mul(a.toConst(), a.toConst());
- testing.expect((try a.to(DoubleLimb)) == maxInt(Limb) * maxInt(Limb));
+ try testing.expect((try a.to(DoubleLimb)) == maxInt(Limb) * maxInt(Limb));
}
test "big.int mul a*0" {
@@ -704,7 +704,7 @@ test "big.int mul a*0" {
defer c.deinit();
try c.mul(a.toConst(), b.toConst());
- testing.expect((try c.to(u32)) == 0);
+ try testing.expect((try c.to(u32)) == 0);
}
test "big.int mul 0*0" {
@@ -717,7 +717,7 @@ test "big.int mul 0*0" {
defer c.deinit();
try c.mul(a.toConst(), b.toConst());
- testing.expect((try c.to(u32)) == 0);
+ try testing.expect((try c.to(u32)) == 0);
}
test "big.int mul large" {
@@ -738,7 +738,7 @@ test "big.int mul large" {
try b.mul(a.toConst(), a.toConst());
try c.sqr(a.toConst());
- testing.expect(b.eq(c));
+ try testing.expect(b.eq(c));
}
test "big.int div single-single no rem" {
@@ -753,8 +753,8 @@ test "big.int div single-single no rem" {
defer r.deinit();
try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
- testing.expect((try q.to(u32)) == 10);
- testing.expect((try r.to(u32)) == 0);
+ try testing.expect((try q.to(u32)) == 10);
+ try testing.expect((try r.to(u32)) == 0);
}
test "big.int div single-single with rem" {
@@ -769,8 +769,8 @@ test "big.int div single-single with rem" {
defer r.deinit();
try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
- testing.expect((try q.to(u32)) == 9);
- testing.expect((try r.to(u32)) == 4);
+ try testing.expect((try q.to(u32)) == 9);
+ try testing.expect((try r.to(u32)) == 4);
}
test "big.int div multi-single no rem" {
@@ -788,8 +788,8 @@ test "big.int div multi-single no rem" {
defer r.deinit();
try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
- testing.expect((try q.to(u64)) == op1 / op2);
- testing.expect((try r.to(u64)) == 0);
+ try testing.expect((try q.to(u64)) == op1 / op2);
+ try testing.expect((try r.to(u64)) == 0);
}
test "big.int div multi-single with rem" {
@@ -807,8 +807,8 @@ test "big.int div multi-single with rem" {
defer r.deinit();
try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
- testing.expect((try q.to(u64)) == op1 / op2);
- testing.expect((try r.to(u64)) == 3);
+ try testing.expect((try q.to(u64)) == op1 / op2);
+ try testing.expect((try r.to(u64)) == 3);
}
test "big.int div multi>2-single" {
@@ -826,8 +826,8 @@ test "big.int div multi>2-single" {
defer r.deinit();
try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
- testing.expect((try q.to(u128)) == op1 / op2);
- testing.expect((try r.to(u32)) == 0x3e4e);
+ try testing.expect((try q.to(u128)) == op1 / op2);
+ try testing.expect((try r.to(u32)) == 0x3e4e);
}
test "big.int div single-single q < r" {
@@ -842,8 +842,8 @@ test "big.int div single-single q < r" {
defer r.deinit();
try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
- testing.expect((try q.to(u64)) == 0);
- testing.expect((try r.to(u64)) == 0x0078f432);
+ try testing.expect((try q.to(u64)) == 0);
+ try testing.expect((try r.to(u64)) == 0x0078f432);
}
test "big.int div single-single q == r" {
@@ -858,8 +858,8 @@ test "big.int div single-single q == r" {
defer r.deinit();
try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
- testing.expect((try q.to(u64)) == 1);
- testing.expect((try r.to(u64)) == 0);
+ try testing.expect((try q.to(u64)) == 1);
+ try testing.expect((try r.to(u64)) == 0);
}
test "big.int div q=0 alias" {
@@ -870,8 +870,8 @@ test "big.int div q=0 alias" {
try Managed.divTrunc(&a, &b, a.toConst(), b.toConst());
- testing.expect((try a.to(u64)) == 0);
- testing.expect((try b.to(u64)) == 3);
+ try testing.expect((try a.to(u64)) == 0);
+ try testing.expect((try b.to(u64)) == 3);
}
test "big.int div multi-multi q < r" {
@@ -888,8 +888,8 @@ test "big.int div multi-multi q < r" {
defer r.deinit();
try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
- testing.expect((try q.to(u128)) == 0);
- testing.expect((try r.to(u128)) == op1);
+ try testing.expect((try q.to(u128)) == 0);
+ try testing.expect((try r.to(u128)) == op1);
}
test "big.int div trunc single-single +/+" {
@@ -912,8 +912,8 @@ test "big.int div trunc single-single +/+" {
const eq = @divTrunc(u, v);
const er = @mod(u, v);
- testing.expect((try q.to(i32)) == eq);
- testing.expect((try r.to(i32)) == er);
+ try testing.expect((try q.to(i32)) == eq);
+ try testing.expect((try r.to(i32)) == er);
}
test "big.int div trunc single-single -/+" {
@@ -936,8 +936,8 @@ test "big.int div trunc single-single -/+" {
const eq = -1;
const er = -2;
- testing.expect((try q.to(i32)) == eq);
- testing.expect((try r.to(i32)) == er);
+ try testing.expect((try q.to(i32)) == eq);
+ try testing.expect((try r.to(i32)) == er);
}
test "big.int div trunc single-single +/-" {
@@ -960,8 +960,8 @@ test "big.int div trunc single-single +/-" {
const eq = -1;
const er = 2;
- testing.expect((try q.to(i32)) == eq);
- testing.expect((try r.to(i32)) == er);
+ try testing.expect((try q.to(i32)) == eq);
+ try testing.expect((try r.to(i32)) == er);
}
test "big.int div trunc single-single -/-" {
@@ -984,8 +984,8 @@ test "big.int div trunc single-single -/-" {
const eq = 1;
const er = -2;
- testing.expect((try q.to(i32)) == eq);
- testing.expect((try r.to(i32)) == er);
+ try testing.expect((try q.to(i32)) == eq);
+ try testing.expect((try r.to(i32)) == er);
}
test "big.int div floor single-single +/+" {
@@ -1008,8 +1008,8 @@ test "big.int div floor single-single +/+" {
const eq = 1;
const er = 2;
- testing.expect((try q.to(i32)) == eq);
- testing.expect((try r.to(i32)) == er);
+ try testing.expect((try q.to(i32)) == eq);
+ try testing.expect((try r.to(i32)) == er);
}
test "big.int div floor single-single -/+" {
@@ -1032,8 +1032,8 @@ test "big.int div floor single-single -/+" {
const eq = -2;
const er = 1;
- testing.expect((try q.to(i32)) == eq);
- testing.expect((try r.to(i32)) == er);
+ try testing.expect((try q.to(i32)) == eq);
+ try testing.expect((try r.to(i32)) == er);
}
test "big.int div floor single-single +/-" {
@@ -1056,8 +1056,8 @@ test "big.int div floor single-single +/-" {
const eq = -2;
const er = -1;
- testing.expect((try q.to(i32)) == eq);
- testing.expect((try r.to(i32)) == er);
+ try testing.expect((try q.to(i32)) == eq);
+ try testing.expect((try r.to(i32)) == er);
}
test "big.int div floor single-single -/-" {
@@ -1080,8 +1080,8 @@ test "big.int div floor single-single -/-" {
const eq = 1;
const er = -2;
- testing.expect((try q.to(i32)) == eq);
- testing.expect((try r.to(i32)) == er);
+ try testing.expect((try q.to(i32)) == eq);
+ try testing.expect((try r.to(i32)) == er);
}
test "big.int div multi-multi with rem" {
@@ -1096,8 +1096,8 @@ test "big.int div multi-multi with rem" {
defer r.deinit();
try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
- testing.expect((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b);
- testing.expect((try r.to(u128)) == 0x28de0acacd806823638);
+ try testing.expect((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b);
+ try testing.expect((try r.to(u128)) == 0x28de0acacd806823638);
}
test "big.int div multi-multi no rem" {
@@ -1112,8 +1112,8 @@ test "big.int div multi-multi no rem" {
defer r.deinit();
try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
- testing.expect((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b);
- testing.expect((try r.to(u128)) == 0);
+ try testing.expect((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b);
+ try testing.expect((try r.to(u128)) == 0);
}
test "big.int div multi-multi (2 branch)" {
@@ -1128,8 +1128,8 @@ test "big.int div multi-multi (2 branch)" {
defer r.deinit();
try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
- testing.expect((try q.to(u128)) == 0x10000000000000000);
- testing.expect((try r.to(u128)) == 0x44444443444444431111111111111111);
+ try testing.expect((try q.to(u128)) == 0x10000000000000000);
+ try testing.expect((try r.to(u128)) == 0x44444443444444431111111111111111);
}
test "big.int div multi-multi (3.1/3.3 branch)" {
@@ -1144,8 +1144,8 @@ test "big.int div multi-multi (3.1/3.3 branch)" {
defer r.deinit();
try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
- testing.expect((try q.to(u128)) == 0xfffffffffffffffffff);
- testing.expect((try r.to(u256)) == 0x1111111111111111111110b12222222222222222282);
+ try testing.expect((try q.to(u128)) == 0xfffffffffffffffffff);
+ try testing.expect((try r.to(u256)) == 0x1111111111111111111110b12222222222222222282);
}
test "big.int div multi-single zero-limb trailing" {
@@ -1162,8 +1162,8 @@ test "big.int div multi-single zero-limb trailing" {
var expected = try Managed.initSet(testing.allocator, 0x6000000000000000000000000000000000000000000000000);
defer expected.deinit();
- testing.expect(q.eq(expected));
- testing.expect(r.eqZero());
+ try testing.expect(q.eq(expected));
+ try testing.expect(r.eqZero());
}
test "big.int div multi-multi zero-limb trailing (with rem)" {
@@ -1178,11 +1178,11 @@ test "big.int div multi-multi zero-limb trailing (with rem)" {
defer r.deinit();
try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
- testing.expect((try q.to(u128)) == 0x10000000000000000);
+ try testing.expect((try q.to(u128)) == 0x10000000000000000);
const rs = try r.toString(testing.allocator, 16, false);
defer testing.allocator.free(rs);
- testing.expect(std.mem.eql(u8, rs, "4444444344444443111111111111111100000000000000000000000000000000"));
+ try testing.expect(std.mem.eql(u8, rs, "4444444344444443111111111111111100000000000000000000000000000000"));
}
test "big.int div multi-multi zero-limb trailing (with rem) and dividend zero-limb count > divisor zero-limb count" {
@@ -1197,11 +1197,11 @@ test "big.int div multi-multi zero-limb trailing (with rem) and dividend zero-li
defer r.deinit();
try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
- testing.expect((try q.to(u128)) == 0x1);
+ try testing.expect((try q.to(u128)) == 0x1);
const rs = try r.toString(testing.allocator, 16, false);
defer testing.allocator.free(rs);
- testing.expect(std.mem.eql(u8, rs, "444444434444444311111111111111110000000000000000"));
+ try testing.expect(std.mem.eql(u8, rs, "444444434444444311111111111111110000000000000000"));
}
test "big.int div multi-multi zero-limb trailing (with rem) and dividend zero-limb count < divisor zero-limb count" {
@@ -1218,11 +1218,11 @@ test "big.int div multi-multi zero-limb trailing (with rem) and dividend zero-li
const qs = try q.toString(testing.allocator, 16, false);
defer testing.allocator.free(qs);
- testing.expect(std.mem.eql(u8, qs, "10000000000000000820820803105186f"));
+ try testing.expect(std.mem.eql(u8, qs, "10000000000000000820820803105186f"));
const rs = try r.toString(testing.allocator, 16, false);
defer testing.allocator.free(rs);
- testing.expect(std.mem.eql(u8, rs, "4e11f2baa5896a321d463b543d0104e30000000000000000"));
+ try testing.expect(std.mem.eql(u8, rs, "4e11f2baa5896a321d463b543d0104e30000000000000000"));
}
test "big.int div multi-multi fuzz case #1" {
@@ -1242,11 +1242,11 @@ test "big.int div multi-multi fuzz case #1" {
const qs = try q.toString(testing.allocator, 16, false);
defer testing.allocator.free(qs);
- testing.expect(std.mem.eql(u8, qs, "3ffffffffffffffffffffffffffff0000000000000000000000000000000000001ffffffffffffffffffffffffffff7fffffffe000000000000000000000000000180000000000000000000003fffffbfffffffdfffffffffffffeffff800000100101000000100000000020003fffffdfbfffffe3ffffffffffffeffff7fffc00800a100000017ffe000002000400007efbfff7fe9f00000037ffff3fff7fffa004006100000009ffe00000190038200bf7d2ff7fefe80400060000f7d7f8fbf9401fe38e0403ffc0bdffffa51102c300d7be5ef9df4e5060007b0127ad3fa69f97d0f820b6605ff617ddf7f32ad7a05c0d03f2e7bc78a6000e087a8bbcdc59e07a5a079128a7861f553ddebed7e8e56701756f9ead39b48cd1b0831889ea6ec1fddf643d0565b075ff07e6caea4e2854ec9227fd635ed60a2f5eef2893052ffd54718fa08604acbf6a15e78a467c4a3c53c0278af06c4416573f925491b195e8fd79302cb1aaf7caf4ecfc9aec1254cc969786363ac729f914c6ddcc26738d6b0facd54eba026580aba2eb6482a088b0d224a8852420b91ec1"));
+ try testing.expect(std.mem.eql(u8, qs, "3ffffffffffffffffffffffffffff0000000000000000000000000000000000001ffffffffffffffffffffffffffff7fffffffe000000000000000000000000000180000000000000000000003fffffbfffffffdfffffffffffffeffff800000100101000000100000000020003fffffdfbfffffe3ffffffffffffeffff7fffc00800a100000017ffe000002000400007efbfff7fe9f00000037ffff3fff7fffa004006100000009ffe00000190038200bf7d2ff7fefe80400060000f7d7f8fbf9401fe38e0403ffc0bdffffa51102c300d7be5ef9df4e5060007b0127ad3fa69f97d0f820b6605ff617ddf7f32ad7a05c0d03f2e7bc78a6000e087a8bbcdc59e07a5a079128a7861f553ddebed7e8e56701756f9ead39b48cd1b0831889ea6ec1fddf643d0565b075ff07e6caea4e2854ec9227fd635ed60a2f5eef2893052ffd54718fa08604acbf6a15e78a467c4a3c53c0278af06c4416573f925491b195e8fd79302cb1aaf7caf4ecfc9aec1254cc969786363ac729f914c6ddcc26738d6b0facd54eba026580aba2eb6482a088b0d224a8852420b91ec1"));
const rs = try r.toString(testing.allocator, 16, false);
defer testing.allocator.free(rs);
- testing.expect(std.mem.eql(u8, rs, "310d1d4c414426b4836c2635bad1df3a424e50cbdd167ffccb4dfff57d36b4aae0d6ca0910698220171a0f3373c1060a046c2812f0027e321f72979daa5e7973214170d49e885de0c0ecc167837d44502430674a82522e5df6a0759548052420b91ec1"));
+ try testing.expect(std.mem.eql(u8, rs, "310d1d4c414426b4836c2635bad1df3a424e50cbdd167ffccb4dfff57d36b4aae0d6ca0910698220171a0f3373c1060a046c2812f0027e321f72979daa5e7973214170d49e885de0c0ecc167837d44502430674a82522e5df6a0759548052420b91ec1"));
}
test "big.int div multi-multi fuzz case #2" {
@@ -1266,11 +1266,11 @@ test "big.int div multi-multi fuzz case #2" {
const qs = try q.toString(testing.allocator, 16, false);
defer testing.allocator.free(qs);
- testing.expect(std.mem.eql(u8, qs, "40100400fe3f8fe3f8fe3f8fe3f8fe3f8fe4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f91e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4992649926499264991e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4792e4b92e4b92e4b92e4b92a4a92a4a92a4"));
+ try testing.expect(std.mem.eql(u8, qs, "40100400fe3f8fe3f8fe3f8fe3f8fe3f8fe4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f91e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4992649926499264991e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4792e4b92e4b92e4b92e4b92a4a92a4a92a4"));
const rs = try r.toString(testing.allocator, 16, false);
defer testing.allocator.free(rs);
- testing.expect(std.mem.eql(u8, rs, "a900000000000000000000000000000000000000000000000000"));
+ try testing.expect(std.mem.eql(u8, rs, "a900000000000000000000000000000000000000000000000000"));
}
test "big.int shift-right single" {
@@ -1278,7 +1278,7 @@ test "big.int shift-right single" {
defer a.deinit();
try a.shiftRight(a, 16);
- testing.expect((try a.to(u32)) == 0xffff);
+ try testing.expect((try a.to(u32)) == 0xffff);
}
test "big.int shift-right multi" {
@@ -1286,13 +1286,13 @@ test "big.int shift-right multi" {
defer a.deinit();
try a.shiftRight(a, 67);
- testing.expect((try a.to(u64)) == 0x1fffe0001dddc222);
+ try testing.expect((try a.to(u64)) == 0x1fffe0001dddc222);
try a.set(0xffff0000eeee1111dddd2222cccc3333);
try a.shiftRight(a, 63);
try a.shiftRight(a, 63);
try a.shiftRight(a, 2);
- testing.expect(a.eqZero());
+ try testing.expect(a.eqZero());
}
test "big.int shift-left single" {
@@ -1300,7 +1300,7 @@ test "big.int shift-left single" {
defer a.deinit();
try a.shiftLeft(a, 16);
- testing.expect((try a.to(u64)) == 0xffff0000);
+ try testing.expect((try a.to(u64)) == 0xffff0000);
}
test "big.int shift-left multi" {
@@ -1308,7 +1308,7 @@ test "big.int shift-left multi" {
defer a.deinit();
try a.shiftLeft(a, 67);
- testing.expect((try a.to(u128)) == 0xffff0000eeee11100000000000000000);
+ try testing.expect((try a.to(u128)) == 0xffff0000eeee11100000000000000000);
}
test "big.int shift-right negative" {
@@ -1318,12 +1318,12 @@ test "big.int shift-right negative" {
var arg = try Managed.initSet(testing.allocator, -20);
defer arg.deinit();
try a.shiftRight(arg, 2);
- testing.expect((try a.to(i32)) == -20 >> 2);
+ try testing.expect((try a.to(i32)) == -20 >> 2);
var arg2 = try Managed.initSet(testing.allocator, -5);
defer arg2.deinit();
try a.shiftRight(arg2, 10);
- testing.expect((try a.to(i32)) == -5 >> 10);
+ try testing.expect((try a.to(i32)) == -5 >> 10);
}
test "big.int shift-left negative" {
@@ -1333,7 +1333,7 @@ test "big.int shift-left negative" {
var arg = try Managed.initSet(testing.allocator, -10);
defer arg.deinit();
try a.shiftRight(arg, 1232);
- testing.expect((try a.to(i32)) == -10 >> 1232);
+ try testing.expect((try a.to(i32)) == -10 >> 1232);
}
test "big.int bitwise and simple" {
@@ -1344,7 +1344,7 @@ test "big.int bitwise and simple" {
try a.bitAnd(a, b);
- testing.expect((try a.to(u64)) == 0xeeeeeeee00000000);
+ try testing.expect((try a.to(u64)) == 0xeeeeeeee00000000);
}
test "big.int bitwise and multi-limb" {
@@ -1355,7 +1355,7 @@ test "big.int bitwise and multi-limb" {
try a.bitAnd(a, b);
- testing.expect((try a.to(u128)) == 0);
+ try testing.expect((try a.to(u128)) == 0);
}
test "big.int bitwise xor simple" {
@@ -1366,7 +1366,7 @@ test "big.int bitwise xor simple" {
try a.bitXor(a, b);
- testing.expect((try a.to(u64)) == 0x1111111133333333);
+ try testing.expect((try a.to(u64)) == 0x1111111133333333);
}
test "big.int bitwise xor multi-limb" {
@@ -1377,7 +1377,7 @@ test "big.int bitwise xor multi-limb" {
try a.bitXor(a, b);
- testing.expect((try a.to(DoubleLimb)) == (maxInt(Limb) + 1) ^ maxInt(Limb));
+ try testing.expect((try a.to(DoubleLimb)) == (maxInt(Limb) + 1) ^ maxInt(Limb));
}
test "big.int bitwise or simple" {
@@ -1388,7 +1388,7 @@ test "big.int bitwise or simple" {
try a.bitOr(a, b);
- testing.expect((try a.to(u64)) == 0xffffffff33333333);
+ try testing.expect((try a.to(u64)) == 0xffffffff33333333);
}
test "big.int bitwise or multi-limb" {
@@ -1400,7 +1400,7 @@ test "big.int bitwise or multi-limb" {
try a.bitOr(a, b);
// TODO: big.int.cpp or is wrong on multi-limb.
- testing.expect((try a.to(DoubleLimb)) == (maxInt(Limb) + 1) + maxInt(Limb));
+ try testing.expect((try a.to(DoubleLimb)) == (maxInt(Limb) + 1) + maxInt(Limb));
}
test "big.int var args" {
@@ -1410,15 +1410,15 @@ test "big.int var args" {
var b = try Managed.initSet(testing.allocator, 6);
defer b.deinit();
try a.add(a.toConst(), b.toConst());
- testing.expect((try a.to(u64)) == 11);
+ try testing.expect((try a.to(u64)) == 11);
var c = try Managed.initSet(testing.allocator, 11);
defer c.deinit();
- testing.expect(a.order(c) == .eq);
+ try testing.expect(a.order(c) == .eq);
var d = try Managed.initSet(testing.allocator, 14);
defer d.deinit();
- testing.expect(a.order(d) != .gt);
+ try testing.expect(a.order(d) != .gt);
}
test "big.int gcd non-one small" {
@@ -1431,7 +1431,7 @@ test "big.int gcd non-one small" {
try r.gcd(a, b);
- testing.expect((try r.to(u32)) == 1);
+ try testing.expect((try r.to(u32)) == 1);
}
test "big.int gcd non-one small" {
@@ -1444,7 +1444,7 @@ test "big.int gcd non-one small" {
try r.gcd(a, b);
- testing.expect((try r.to(u32)) == 38);
+ try testing.expect((try r.to(u32)) == 38);
}
test "big.int gcd non-one large" {
@@ -1457,7 +1457,7 @@ test "big.int gcd non-one large" {
try r.gcd(a, b);
- testing.expect((try r.to(u32)) == 4369);
+ try testing.expect((try r.to(u32)) == 4369);
}
test "big.int gcd large multi-limb result" {
@@ -1471,7 +1471,7 @@ test "big.int gcd large multi-limb result" {
try r.gcd(a, b);
const answer = (try r.to(u256));
- testing.expect(answer == 0xf000000ff00000fff0000ffff000fffff00ffffff1);
+ try testing.expect(answer == 0xf000000ff00000fff0000ffff000fffff00ffffff1);
}
test "big.int gcd one large" {
@@ -1484,7 +1484,7 @@ test "big.int gcd one large" {
try r.gcd(a, b);
- testing.expect((try r.to(u64)) == 1);
+ try testing.expect((try r.to(u64)) == 1);
}
test "big.int mutable to managed" {
@@ -1495,7 +1495,7 @@ test "big.int mutable to managed" {
var a = Mutable.init(limbs_buf, 0xdeadbeef);
var a_managed = a.toManaged(allocator);
- testing.expect(a.toConst().eq(a_managed.toConst()));
+ try testing.expect(a.toConst().eq(a_managed.toConst()));
}
test "big.int const to managed" {
@@ -1505,7 +1505,7 @@ test "big.int const to managed" {
var b = try a.toConst().toManaged(testing.allocator);
defer b.deinit();
- testing.expect(a.toConst().eq(b.toConst()));
+ try testing.expect(a.toConst().eq(b.toConst()));
}
test "big.int pow" {
@@ -1514,10 +1514,10 @@ test "big.int pow" {
defer a.deinit();
try a.pow(a.toConst(), 3);
- testing.expectEqual(@as(i32, -27), try a.to(i32));
+ try testing.expectEqual(@as(i32, -27), try a.to(i32));
try a.pow(a.toConst(), 4);
- testing.expectEqual(@as(i32, 531441), try a.to(i32));
+ try testing.expectEqual(@as(i32, 531441), try a.to(i32));
}
{
var a = try Managed.initSet(testing.allocator, 10);
@@ -1531,11 +1531,11 @@ test "big.int pow" {
// y and a are aliased
try a.pow(a.toConst(), 123);
- testing.expect(a.eq(y));
+ try testing.expect(a.eq(y));
const ys = try y.toString(testing.allocator, 16, false);
defer testing.allocator.free(ys);
- testing.expectEqualSlices(
+ try testing.expectEqualSlices(
u8,
"183425a5f872f126e00a5ad62c839075cd6846c6fb0230887c7ad7a9dc530fcb" ++
"4933f60e8000000000000000000000000000000",
@@ -1548,17 +1548,17 @@ test "big.int pow" {
defer a.deinit();
try a.pow(a.toConst(), 100);
- testing.expectEqual(@as(i32, 0), try a.to(i32));
+ try testing.expectEqual(@as(i32, 0), try a.to(i32));
try a.set(1);
try a.pow(a.toConst(), 0);
- testing.expectEqual(@as(i32, 1), try a.to(i32));
+ try testing.expectEqual(@as(i32, 1), try a.to(i32));
try a.pow(a.toConst(), 100);
- testing.expectEqual(@as(i32, 1), try a.to(i32));
+ try testing.expectEqual(@as(i32, 1), try a.to(i32));
try a.set(-1);
try a.pow(a.toConst(), 15);
- testing.expectEqual(@as(i32, -1), try a.to(i32));
+ try testing.expectEqual(@as(i32, -1), try a.to(i32));
try a.pow(a.toConst(), 16);
- testing.expectEqual(@as(i32, 1), try a.to(i32));
+ try testing.expectEqual(@as(i32, 1), try a.to(i32));
}
}
lib/std/math/big/rational.zig
@@ -473,7 +473,7 @@ pub const Rational = struct {
};
fn extractLowBits(a: Int, comptime T: type) T {
- testing.expect(@typeInfo(T) == .Int);
+ debug.assert(@typeInfo(T) == .Int);
const t_bits = @typeInfo(T).Int.bits;
const limb_bits = @typeInfo(Limb).Int.bits;
@@ -498,19 +498,19 @@ test "big.rational extractLowBits" {
defer a.deinit();
const a1 = extractLowBits(a, u8);
- testing.expect(a1 == 0x21);
+ try testing.expect(a1 == 0x21);
const a2 = extractLowBits(a, u16);
- testing.expect(a2 == 0x4321);
+ try testing.expect(a2 == 0x4321);
const a3 = extractLowBits(a, u32);
- testing.expect(a3 == 0x87654321);
+ try testing.expect(a3 == 0x87654321);
const a4 = extractLowBits(a, u64);
- testing.expect(a4 == 0x1234567887654321);
+ try testing.expect(a4 == 0x1234567887654321);
const a5 = extractLowBits(a, u128);
- testing.expect(a5 == 0x11112222333344441234567887654321);
+ try testing.expect(a5 == 0x11112222333344441234567887654321);
}
test "big.rational set" {
@@ -518,28 +518,28 @@ test "big.rational set" {
defer a.deinit();
try a.setInt(5);
- testing.expect((try a.p.to(u32)) == 5);
- testing.expect((try a.q.to(u32)) == 1);
+ try testing.expect((try a.p.to(u32)) == 5);
+ try testing.expect((try a.q.to(u32)) == 1);
try a.setRatio(7, 3);
- testing.expect((try a.p.to(u32)) == 7);
- testing.expect((try a.q.to(u32)) == 3);
+ try testing.expect((try a.p.to(u32)) == 7);
+ try testing.expect((try a.q.to(u32)) == 3);
try a.setRatio(9, 3);
- testing.expect((try a.p.to(i32)) == 3);
- testing.expect((try a.q.to(i32)) == 1);
+ try testing.expect((try a.p.to(i32)) == 3);
+ try testing.expect((try a.q.to(i32)) == 1);
try a.setRatio(-9, 3);
- testing.expect((try a.p.to(i32)) == -3);
- testing.expect((try a.q.to(i32)) == 1);
+ try testing.expect((try a.p.to(i32)) == -3);
+ try testing.expect((try a.q.to(i32)) == 1);
try a.setRatio(9, -3);
- testing.expect((try a.p.to(i32)) == -3);
- testing.expect((try a.q.to(i32)) == 1);
+ try testing.expect((try a.p.to(i32)) == -3);
+ try testing.expect((try a.q.to(i32)) == 1);
try a.setRatio(-9, -3);
- testing.expect((try a.p.to(i32)) == 3);
- testing.expect((try a.q.to(i32)) == 1);
+ try testing.expect((try a.p.to(i32)) == 3);
+ try testing.expect((try a.q.to(i32)) == 1);
}
test "big.rational setFloat" {
@@ -547,24 +547,24 @@ test "big.rational setFloat" {
defer a.deinit();
try a.setFloat(f64, 2.5);
- testing.expect((try a.p.to(i32)) == 5);
- testing.expect((try a.q.to(i32)) == 2);
+ try testing.expect((try a.p.to(i32)) == 5);
+ try testing.expect((try a.q.to(i32)) == 2);
try a.setFloat(f32, -2.5);
- testing.expect((try a.p.to(i32)) == -5);
- testing.expect((try a.q.to(i32)) == 2);
+ try testing.expect((try a.p.to(i32)) == -5);
+ try testing.expect((try a.q.to(i32)) == 2);
try a.setFloat(f32, 3.141593);
// = 3.14159297943115234375
- testing.expect((try a.p.to(u32)) == 3294199);
- testing.expect((try a.q.to(u32)) == 1048576);
+ try testing.expect((try a.p.to(u32)) == 3294199);
+ try testing.expect((try a.q.to(u32)) == 1048576);
try a.setFloat(f64, 72.141593120712409172417410926841290461290467124);
// = 72.1415931207124145885245525278151035308837890625
- testing.expect((try a.p.to(u128)) == 5076513310880537);
- testing.expect((try a.q.to(u128)) == 70368744177664);
+ try testing.expect((try a.p.to(u128)) == 5076513310880537);
+ try testing.expect((try a.q.to(u128)) == 70368744177664);
}
test "big.rational setFloatString" {
@@ -574,8 +574,8 @@ test "big.rational setFloatString" {
try a.setFloatString("72.14159312071241458852455252781510353");
// = 72.1415931207124145885245525278151035308837890625
- testing.expect((try a.p.to(u128)) == 7214159312071241458852455252781510353);
- testing.expect((try a.q.to(u128)) == 100000000000000000000000000000000000);
+ try testing.expect((try a.p.to(u128)) == 7214159312071241458852455252781510353);
+ try testing.expect((try a.q.to(u128)) == 100000000000000000000000000000000000);
}
test "big.rational toFloat" {
@@ -584,11 +584,11 @@ test "big.rational toFloat" {
// = 3.14159297943115234375
try a.setRatio(3294199, 1048576);
- testing.expect((try a.toFloat(f64)) == 3.14159297943115234375);
+ try testing.expect((try a.toFloat(f64)) == 3.14159297943115234375);
// = 72.1415931207124145885245525278151035308837890625
try a.setRatio(5076513310880537, 70368744177664);
- testing.expect((try a.toFloat(f64)) == 72.141593120712409172417410926841290461290467124);
+ try testing.expect((try a.toFloat(f64)) == 72.141593120712409172417410926841290461290467124);
}
test "big.rational set/to Float round-trip" {
@@ -599,7 +599,7 @@ test "big.rational set/to Float round-trip" {
while (i < 512) : (i += 1) {
const r = prng.random.float(f64);
try a.setFloat(f64, r);
- testing.expect((try a.toFloat(f64)) == r);
+ try testing.expect((try a.toFloat(f64)) == r);
}
}
@@ -611,8 +611,8 @@ test "big.rational copy" {
defer b.deinit();
try a.copyInt(b);
- testing.expect((try a.p.to(u32)) == 5);
- testing.expect((try a.q.to(u32)) == 1);
+ try testing.expect((try a.p.to(u32)) == 5);
+ try testing.expect((try a.q.to(u32)) == 1);
var c = try Int.initSet(testing.allocator, 7);
defer c.deinit();
@@ -620,8 +620,8 @@ test "big.rational copy" {
defer d.deinit();
try a.copyRatio(c, d);
- testing.expect((try a.p.to(u32)) == 7);
- testing.expect((try a.q.to(u32)) == 3);
+ try testing.expect((try a.p.to(u32)) == 7);
+ try testing.expect((try a.q.to(u32)) == 3);
var e = try Int.initSet(testing.allocator, 9);
defer e.deinit();
@@ -629,8 +629,8 @@ test "big.rational copy" {
defer f.deinit();
try a.copyRatio(e, f);
- testing.expect((try a.p.to(u32)) == 3);
- testing.expect((try a.q.to(u32)) == 1);
+ try testing.expect((try a.p.to(u32)) == 3);
+ try testing.expect((try a.q.to(u32)) == 1);
}
test "big.rational negate" {
@@ -638,16 +638,16 @@ test "big.rational negate" {
defer a.deinit();
try a.setInt(-50);
- testing.expect((try a.p.to(i32)) == -50);
- testing.expect((try a.q.to(i32)) == 1);
+ try testing.expect((try a.p.to(i32)) == -50);
+ try testing.expect((try a.q.to(i32)) == 1);
a.negate();
- testing.expect((try a.p.to(i32)) == 50);
- testing.expect((try a.q.to(i32)) == 1);
+ try testing.expect((try a.p.to(i32)) == 50);
+ try testing.expect((try a.q.to(i32)) == 1);
a.negate();
- testing.expect((try a.p.to(i32)) == -50);
- testing.expect((try a.q.to(i32)) == 1);
+ try testing.expect((try a.p.to(i32)) == -50);
+ try testing.expect((try a.q.to(i32)) == 1);
}
test "big.rational abs" {
@@ -655,16 +655,16 @@ test "big.rational abs" {
defer a.deinit();
try a.setInt(-50);
- testing.expect((try a.p.to(i32)) == -50);
- testing.expect((try a.q.to(i32)) == 1);
+ try testing.expect((try a.p.to(i32)) == -50);
+ try testing.expect((try a.q.to(i32)) == 1);
a.abs();
- testing.expect((try a.p.to(i32)) == 50);
- testing.expect((try a.q.to(i32)) == 1);
+ try testing.expect((try a.p.to(i32)) == 50);
+ try testing.expect((try a.q.to(i32)) == 1);
a.abs();
- testing.expect((try a.p.to(i32)) == 50);
- testing.expect((try a.q.to(i32)) == 1);
+ try testing.expect((try a.p.to(i32)) == 50);
+ try testing.expect((try a.q.to(i32)) == 1);
}
test "big.rational swap" {
@@ -676,19 +676,19 @@ test "big.rational swap" {
try a.setRatio(50, 23);
try b.setRatio(17, 3);
- testing.expect((try a.p.to(u32)) == 50);
- testing.expect((try a.q.to(u32)) == 23);
+ try testing.expect((try a.p.to(u32)) == 50);
+ try testing.expect((try a.q.to(u32)) == 23);
- testing.expect((try b.p.to(u32)) == 17);
- testing.expect((try b.q.to(u32)) == 3);
+ try testing.expect((try b.p.to(u32)) == 17);
+ try testing.expect((try b.q.to(u32)) == 3);
a.swap(&b);
- testing.expect((try a.p.to(u32)) == 17);
- testing.expect((try a.q.to(u32)) == 3);
+ try testing.expect((try a.p.to(u32)) == 17);
+ try testing.expect((try a.q.to(u32)) == 3);
- testing.expect((try b.p.to(u32)) == 50);
- testing.expect((try b.q.to(u32)) == 23);
+ try testing.expect((try b.p.to(u32)) == 50);
+ try testing.expect((try b.q.to(u32)) == 23);
}
test "big.rational order" {
@@ -699,11 +699,11 @@ test "big.rational order" {
try a.setRatio(500, 231);
try b.setRatio(18903, 8584);
- testing.expect((try a.order(b)) == .lt);
+ try testing.expect((try a.order(b)) == .lt);
try a.setRatio(890, 10);
try b.setRatio(89, 1);
- testing.expect((try a.order(b)) == .eq);
+ try testing.expect((try a.order(b)) == .eq);
}
test "big.rational add single-limb" {
@@ -714,11 +714,11 @@ test "big.rational add single-limb" {
try a.setRatio(500, 231);
try b.setRatio(18903, 8584);
- testing.expect((try a.order(b)) == .lt);
+ try testing.expect((try a.order(b)) == .lt);
try a.setRatio(890, 10);
try b.setRatio(89, 1);
- testing.expect((try a.order(b)) == .eq);
+ try testing.expect((try a.order(b)) == .eq);
}
test "big.rational add" {
@@ -734,7 +734,7 @@ test "big.rational add" {
try a.add(a, b);
try r.setRatio(984786924199, 290395044174);
- testing.expect((try a.order(r)) == .eq);
+ try testing.expect((try a.order(r)) == .eq);
}
test "big.rational sub" {
@@ -750,7 +750,7 @@ test "big.rational sub" {
try a.sub(a, b);
try r.setRatio(979040510045, 290395044174);
- testing.expect((try a.order(r)) == .eq);
+ try testing.expect((try a.order(r)) == .eq);
}
test "big.rational mul" {
@@ -766,7 +766,7 @@ test "big.rational mul" {
try a.mul(a, b);
try r.setRatio(571481443, 17082061422);
- testing.expect((try a.order(r)) == .eq);
+ try testing.expect((try a.order(r)) == .eq);
}
test "big.rational div" {
@@ -782,7 +782,7 @@ test "big.rational div" {
try a.div(a, b);
try r.setRatio(75531824394, 221015929);
- testing.expect((try a.order(r)) == .eq);
+ try testing.expect((try a.order(r)) == .eq);
}
test "big.rational div" {
@@ -795,11 +795,11 @@ test "big.rational div" {
a.invert();
try r.setRatio(23341, 78923);
- testing.expect((try a.order(r)) == .eq);
+ try testing.expect((try a.order(r)) == .eq);
try a.setRatio(-78923, 23341);
a.invert();
try r.setRatio(-23341, 78923);
- testing.expect((try a.order(r)) == .eq);
+ try testing.expect((try a.order(r)) == .eq);
}
lib/std/math/complex/abs.zig
@@ -20,5 +20,5 @@ const epsilon = 0.0001;
test "complex.cabs" {
const a = Complex(f32).new(5, 3);
const c = abs(a);
- testing.expect(math.approxEqAbs(f32, c, 5.83095, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c, 5.83095, epsilon));
}
lib/std/math/complex/acos.zig
@@ -22,6 +22,6 @@ test "complex.cacos" {
const a = Complex(f32).new(5, 3);
const c = acos(a);
- testing.expect(math.approxEqAbs(f32, c.re, 0.546975, epsilon));
- testing.expect(math.approxEqAbs(f32, c.im, -2.452914, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.re, 0.546975, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.im, -2.452914, epsilon));
}
lib/std/math/complex/acosh.zig
@@ -22,6 +22,6 @@ test "complex.cacosh" {
const a = Complex(f32).new(5, 3);
const c = acosh(a);
- testing.expect(math.approxEqAbs(f32, c.re, 2.452914, epsilon));
- testing.expect(math.approxEqAbs(f32, c.im, 0.546975, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.re, 2.452914, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.im, 0.546975, epsilon));
}
lib/std/math/complex/arg.zig
@@ -20,5 +20,5 @@ const epsilon = 0.0001;
test "complex.carg" {
const a = Complex(f32).new(5, 3);
const c = arg(a);
- testing.expect(math.approxEqAbs(f32, c, 0.540420, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c, 0.540420, epsilon));
}
lib/std/math/complex/asin.zig
@@ -28,6 +28,6 @@ test "complex.casin" {
const a = Complex(f32).new(5, 3);
const c = asin(a);
- testing.expect(math.approxEqAbs(f32, c.re, 1.023822, epsilon));
- testing.expect(math.approxEqAbs(f32, c.im, 2.452914, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.re, 1.023822, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.im, 2.452914, epsilon));
}
lib/std/math/complex/asinh.zig
@@ -23,6 +23,6 @@ test "complex.casinh" {
const a = Complex(f32).new(5, 3);
const c = asinh(a);
- testing.expect(math.approxEqAbs(f32, c.re, 2.459831, epsilon));
- testing.expect(math.approxEqAbs(f32, c.im, 0.533999, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.re, 2.459831, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.im, 0.533999, epsilon));
}
lib/std/math/complex/atan.zig
@@ -130,14 +130,14 @@ test "complex.catan32" {
const a = Complex(f32).new(5, 3);
const c = atan(a);
- testing.expect(math.approxEqAbs(f32, c.re, 1.423679, epsilon));
- testing.expect(math.approxEqAbs(f32, c.im, 0.086569, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.re, 1.423679, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.im, 0.086569, epsilon));
}
test "complex.catan64" {
const a = Complex(f64).new(5, 3);
const c = atan(a);
- testing.expect(math.approxEqAbs(f64, c.re, 1.423679, epsilon));
- testing.expect(math.approxEqAbs(f64, c.im, 0.086569, epsilon));
+ try testing.expect(math.approxEqAbs(f64, c.re, 1.423679, epsilon));
+ try testing.expect(math.approxEqAbs(f64, c.im, 0.086569, epsilon));
}
lib/std/math/complex/atanh.zig
@@ -23,6 +23,6 @@ test "complex.catanh" {
const a = Complex(f32).new(5, 3);
const c = atanh(a);
- testing.expect(math.approxEqAbs(f32, c.re, 0.146947, epsilon));
- testing.expect(math.approxEqAbs(f32, c.im, 1.480870, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.re, 0.146947, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.im, 1.480870, epsilon));
}
lib/std/math/complex/conj.zig
@@ -19,5 +19,5 @@ test "complex.conj" {
const a = Complex(f32).new(5, 3);
const c = a.conjugate();
- testing.expect(c.re == 5 and c.im == -3);
+ try testing.expect(c.re == 5 and c.im == -3);
}
lib/std/math/complex/cos.zig
@@ -22,6 +22,6 @@ test "complex.ccos" {
const a = Complex(f32).new(5, 3);
const c = cos(a);
- testing.expect(math.approxEqAbs(f32, c.re, 2.855815, epsilon));
- testing.expect(math.approxEqAbs(f32, c.im, 9.606383, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.re, 2.855815, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.im, 9.606383, epsilon));
}
lib/std/math/complex/cosh.zig
@@ -165,14 +165,14 @@ test "complex.ccosh32" {
const a = Complex(f32).new(5, 3);
const c = cosh(a);
- testing.expect(math.approxEqAbs(f32, c.re, -73.467300, epsilon));
- testing.expect(math.approxEqAbs(f32, c.im, 10.471557, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.re, -73.467300, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.im, 10.471557, epsilon));
}
test "complex.ccosh64" {
const a = Complex(f64).new(5, 3);
const c = cosh(a);
- testing.expect(math.approxEqAbs(f64, c.re, -73.467300, epsilon));
- testing.expect(math.approxEqAbs(f64, c.im, 10.471557, epsilon));
+ try testing.expect(math.approxEqAbs(f64, c.re, -73.467300, epsilon));
+ try testing.expect(math.approxEqAbs(f64, c.im, 10.471557, epsilon));
}
lib/std/math/complex/exp.zig
@@ -131,14 +131,14 @@ test "complex.cexp32" {
const a = Complex(f32).new(5, 3);
const c = exp(a);
- testing.expect(math.approxEqAbs(f32, c.re, -146.927917, epsilon));
- testing.expect(math.approxEqAbs(f32, c.im, 20.944065, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.re, -146.927917, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.im, 20.944065, epsilon));
}
test "complex.cexp64" {
const a = Complex(f64).new(5, 3);
const c = exp(a);
- testing.expect(math.approxEqAbs(f64, c.re, -146.927917, epsilon));
- testing.expect(math.approxEqAbs(f64, c.im, 20.944065, epsilon));
+ try testing.expect(math.approxEqAbs(f64, c.re, -146.927917, epsilon));
+ try testing.expect(math.approxEqAbs(f64, c.im, 20.944065, epsilon));
}
lib/std/math/complex/log.zig
@@ -24,6 +24,6 @@ test "complex.clog" {
const a = Complex(f32).new(5, 3);
const c = log(a);
- testing.expect(math.approxEqAbs(f32, c.re, 1.763180, epsilon));
- testing.expect(math.approxEqAbs(f32, c.im, 0.540419, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.re, 1.763180, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.im, 0.540419, epsilon));
}
lib/std/math/complex/pow.zig
@@ -23,6 +23,6 @@ test "complex.cpow" {
const b = Complex(f32).new(2.3, -1.3);
const c = pow(Complex(f32), a, b);
- testing.expect(math.approxEqAbs(f32, c.re, 58.049110, epsilon));
- testing.expect(math.approxEqAbs(f32, c.im, -101.003433, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.re, 58.049110, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.im, -101.003433, epsilon));
}
lib/std/math/complex/proj.zig
@@ -26,5 +26,5 @@ test "complex.cproj" {
const a = Complex(f32).new(5, 3);
const c = proj(a);
- testing.expect(c.re == 5 and c.im == 3);
+ try testing.expect(c.re == 5 and c.im == 3);
}
lib/std/math/complex/sin.zig
@@ -23,6 +23,6 @@ test "complex.csin" {
const a = Complex(f32).new(5, 3);
const c = sin(a);
- testing.expect(math.approxEqAbs(f32, c.re, -9.654126, epsilon));
- testing.expect(math.approxEqAbs(f32, c.im, 2.841692, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.re, -9.654126, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.im, 2.841692, epsilon));
}
lib/std/math/complex/sinh.zig
@@ -164,14 +164,14 @@ test "complex.csinh32" {
const a = Complex(f32).new(5, 3);
const c = sinh(a);
- testing.expect(math.approxEqAbs(f32, c.re, -73.460617, epsilon));
- testing.expect(math.approxEqAbs(f32, c.im, 10.472508, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.re, -73.460617, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.im, 10.472508, epsilon));
}
test "complex.csinh64" {
const a = Complex(f64).new(5, 3);
const c = sinh(a);
- testing.expect(math.approxEqAbs(f64, c.re, -73.460617, epsilon));
- testing.expect(math.approxEqAbs(f64, c.im, 10.472508, epsilon));
+ try testing.expect(math.approxEqAbs(f64, c.re, -73.460617, epsilon));
+ try testing.expect(math.approxEqAbs(f64, c.im, 10.472508, epsilon));
}
lib/std/math/complex/sqrt.zig
@@ -138,14 +138,14 @@ test "complex.csqrt32" {
const a = Complex(f32).new(5, 3);
const c = sqrt(a);
- testing.expect(math.approxEqAbs(f32, c.re, 2.327117, epsilon));
- testing.expect(math.approxEqAbs(f32, c.im, 0.644574, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.re, 2.327117, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.im, 0.644574, epsilon));
}
test "complex.csqrt64" {
const a = Complex(f64).new(5, 3);
const c = sqrt(a);
- testing.expect(math.approxEqAbs(f64, c.re, 2.3271175190399496, epsilon));
- testing.expect(math.approxEqAbs(f64, c.im, 0.6445742373246469, epsilon));
+ try testing.expect(math.approxEqAbs(f64, c.re, 2.3271175190399496, epsilon));
+ try testing.expect(math.approxEqAbs(f64, c.im, 0.6445742373246469, epsilon));
}
lib/std/math/complex/tan.zig
@@ -23,6 +23,6 @@ test "complex.ctan" {
const a = Complex(f32).new(5, 3);
const c = tan(a);
- testing.expect(math.approxEqAbs(f32, c.re, -0.002708233, epsilon));
- testing.expect(math.approxEqAbs(f32, c.im, 1.004165, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.re, -0.002708233, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.im, 1.004165, epsilon));
}
lib/std/math/complex/tanh.zig
@@ -113,14 +113,14 @@ test "complex.ctanh32" {
const a = Complex(f32).new(5, 3);
const c = tanh(a);
- testing.expect(math.approxEqAbs(f32, c.re, 0.999913, epsilon));
- testing.expect(math.approxEqAbs(f32, c.im, -0.000025, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.re, 0.999913, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c.im, -0.000025, epsilon));
}
test "complex.ctanh64" {
const a = Complex(f64).new(5, 3);
const c = tanh(a);
- testing.expect(math.approxEqAbs(f64, c.re, 0.999913, epsilon));
- testing.expect(math.approxEqAbs(f64, c.im, -0.000025, epsilon));
+ try testing.expect(math.approxEqAbs(f64, c.re, 0.999913, epsilon));
+ try testing.expect(math.approxEqAbs(f64, c.im, -0.000025, epsilon));
}
lib/std/math/acos.zig
@@ -154,38 +154,38 @@ fn acos64(x: f64) f64 {
}
test "math.acos" {
- expect(acos(@as(f32, 0.0)) == acos32(0.0));
- expect(acos(@as(f64, 0.0)) == acos64(0.0));
+ try expect(acos(@as(f32, 0.0)) == acos32(0.0));
+ try expect(acos(@as(f64, 0.0)) == acos64(0.0));
}
test "math.acos32" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f32, acos32(0.0), 1.570796, epsilon));
- expect(math.approxEqAbs(f32, acos32(0.2), 1.369438, epsilon));
- expect(math.approxEqAbs(f32, acos32(0.3434), 1.220262, epsilon));
- expect(math.approxEqAbs(f32, acos32(0.5), 1.047198, epsilon));
- expect(math.approxEqAbs(f32, acos32(0.8923), 0.468382, epsilon));
- expect(math.approxEqAbs(f32, acos32(-0.2), 1.772154, epsilon));
+ try expect(math.approxEqAbs(f32, acos32(0.0), 1.570796, epsilon));
+ try expect(math.approxEqAbs(f32, acos32(0.2), 1.369438, epsilon));
+ try expect(math.approxEqAbs(f32, acos32(0.3434), 1.220262, epsilon));
+ try expect(math.approxEqAbs(f32, acos32(0.5), 1.047198, epsilon));
+ try expect(math.approxEqAbs(f32, acos32(0.8923), 0.468382, epsilon));
+ try expect(math.approxEqAbs(f32, acos32(-0.2), 1.772154, epsilon));
}
test "math.acos64" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f64, acos64(0.0), 1.570796, epsilon));
- expect(math.approxEqAbs(f64, acos64(0.2), 1.369438, epsilon));
- expect(math.approxEqAbs(f64, acos64(0.3434), 1.220262, epsilon));
- expect(math.approxEqAbs(f64, acos64(0.5), 1.047198, epsilon));
- expect(math.approxEqAbs(f64, acos64(0.8923), 0.468382, epsilon));
- expect(math.approxEqAbs(f64, acos64(-0.2), 1.772154, epsilon));
+ try expect(math.approxEqAbs(f64, acos64(0.0), 1.570796, epsilon));
+ try expect(math.approxEqAbs(f64, acos64(0.2), 1.369438, epsilon));
+ try expect(math.approxEqAbs(f64, acos64(0.3434), 1.220262, epsilon));
+ try expect(math.approxEqAbs(f64, acos64(0.5), 1.047198, epsilon));
+ try expect(math.approxEqAbs(f64, acos64(0.8923), 0.468382, epsilon));
+ try expect(math.approxEqAbs(f64, acos64(-0.2), 1.772154, epsilon));
}
test "math.acos32.special" {
- expect(math.isNan(acos32(-2)));
- expect(math.isNan(acos32(1.5)));
+ try expect(math.isNan(acos32(-2)));
+ try expect(math.isNan(acos32(1.5)));
}
test "math.acos64.special" {
- expect(math.isNan(acos64(-2)));
- expect(math.isNan(acos64(1.5)));
+ try expect(math.isNan(acos64(-2)));
+ try expect(math.isNan(acos64(1.5)));
}
lib/std/math/acosh.zig
@@ -66,34 +66,34 @@ fn acosh64(x: f64) f64 {
}
test "math.acosh" {
- expect(acosh(@as(f32, 1.5)) == acosh32(1.5));
- expect(acosh(@as(f64, 1.5)) == acosh64(1.5));
+ try expect(acosh(@as(f32, 1.5)) == acosh32(1.5));
+ try expect(acosh(@as(f64, 1.5)) == acosh64(1.5));
}
test "math.acosh32" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f32, acosh32(1.5), 0.962424, epsilon));
- expect(math.approxEqAbs(f32, acosh32(37.45), 4.315976, epsilon));
- expect(math.approxEqAbs(f32, acosh32(89.123), 5.183133, epsilon));
- expect(math.approxEqAbs(f32, acosh32(123123.234375), 12.414088, epsilon));
+ try expect(math.approxEqAbs(f32, acosh32(1.5), 0.962424, epsilon));
+ try expect(math.approxEqAbs(f32, acosh32(37.45), 4.315976, epsilon));
+ try expect(math.approxEqAbs(f32, acosh32(89.123), 5.183133, epsilon));
+ try expect(math.approxEqAbs(f32, acosh32(123123.234375), 12.414088, epsilon));
}
test "math.acosh64" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f64, acosh64(1.5), 0.962424, epsilon));
- expect(math.approxEqAbs(f64, acosh64(37.45), 4.315976, epsilon));
- expect(math.approxEqAbs(f64, acosh64(89.123), 5.183133, epsilon));
- expect(math.approxEqAbs(f64, acosh64(123123.234375), 12.414088, epsilon));
+ try expect(math.approxEqAbs(f64, acosh64(1.5), 0.962424, epsilon));
+ try expect(math.approxEqAbs(f64, acosh64(37.45), 4.315976, epsilon));
+ try expect(math.approxEqAbs(f64, acosh64(89.123), 5.183133, epsilon));
+ try expect(math.approxEqAbs(f64, acosh64(123123.234375), 12.414088, epsilon));
}
test "math.acosh32.special" {
- expect(math.isNan(acosh32(math.nan(f32))));
- expect(math.isSignalNan(acosh32(0.5)));
+ try expect(math.isNan(acosh32(math.nan(f32))));
+ try expect(math.isSignalNan(acosh32(0.5)));
}
test "math.acosh64.special" {
- expect(math.isNan(acosh64(math.nan(f64))));
- expect(math.isSignalNan(acosh64(0.5)));
+ try expect(math.isNan(acosh64(math.nan(f64))));
+ try expect(math.isSignalNan(acosh64(0.5)));
}
lib/std/math/asin.zig
@@ -147,42 +147,42 @@ fn asin64(x: f64) f64 {
}
test "math.asin" {
- expect(asin(@as(f32, 0.0)) == asin32(0.0));
- expect(asin(@as(f64, 0.0)) == asin64(0.0));
+ try expect(asin(@as(f32, 0.0)) == asin32(0.0));
+ try expect(asin(@as(f64, 0.0)) == asin64(0.0));
}
test "math.asin32" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f32, asin32(0.0), 0.0, epsilon));
- expect(math.approxEqAbs(f32, asin32(0.2), 0.201358, epsilon));
- expect(math.approxEqAbs(f32, asin32(-0.2), -0.201358, epsilon));
- expect(math.approxEqAbs(f32, asin32(0.3434), 0.350535, epsilon));
- expect(math.approxEqAbs(f32, asin32(0.5), 0.523599, epsilon));
- expect(math.approxEqAbs(f32, asin32(0.8923), 1.102415, epsilon));
+ try expect(math.approxEqAbs(f32, asin32(0.0), 0.0, epsilon));
+ try expect(math.approxEqAbs(f32, asin32(0.2), 0.201358, epsilon));
+ try expect(math.approxEqAbs(f32, asin32(-0.2), -0.201358, epsilon));
+ try expect(math.approxEqAbs(f32, asin32(0.3434), 0.350535, epsilon));
+ try expect(math.approxEqAbs(f32, asin32(0.5), 0.523599, epsilon));
+ try expect(math.approxEqAbs(f32, asin32(0.8923), 1.102415, epsilon));
}
test "math.asin64" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f64, asin64(0.0), 0.0, epsilon));
- expect(math.approxEqAbs(f64, asin64(0.2), 0.201358, epsilon));
- expect(math.approxEqAbs(f64, asin64(-0.2), -0.201358, epsilon));
- expect(math.approxEqAbs(f64, asin64(0.3434), 0.350535, epsilon));
- expect(math.approxEqAbs(f64, asin64(0.5), 0.523599, epsilon));
- expect(math.approxEqAbs(f64, asin64(0.8923), 1.102415, epsilon));
+ try expect(math.approxEqAbs(f64, asin64(0.0), 0.0, epsilon));
+ try expect(math.approxEqAbs(f64, asin64(0.2), 0.201358, epsilon));
+ try expect(math.approxEqAbs(f64, asin64(-0.2), -0.201358, epsilon));
+ try expect(math.approxEqAbs(f64, asin64(0.3434), 0.350535, epsilon));
+ try expect(math.approxEqAbs(f64, asin64(0.5), 0.523599, epsilon));
+ try expect(math.approxEqAbs(f64, asin64(0.8923), 1.102415, epsilon));
}
test "math.asin32.special" {
- expect(asin32(0.0) == 0.0);
- expect(asin32(-0.0) == -0.0);
- expect(math.isNan(asin32(-2)));
- expect(math.isNan(asin32(1.5)));
+ try expect(asin32(0.0) == 0.0);
+ try expect(asin32(-0.0) == -0.0);
+ try expect(math.isNan(asin32(-2)));
+ try expect(math.isNan(asin32(1.5)));
}
test "math.asin64.special" {
- expect(asin64(0.0) == 0.0);
- expect(asin64(-0.0) == -0.0);
- expect(math.isNan(asin64(-2)));
- expect(math.isNan(asin64(1.5)));
+ try expect(asin64(0.0) == 0.0);
+ try expect(asin64(-0.0) == -0.0);
+ try expect(math.isNan(asin64(-2)));
+ try expect(math.isNan(asin64(1.5)));
}
lib/std/math/asinh.zig
@@ -94,46 +94,46 @@ fn asinh64(x: f64) f64 {
}
test "math.asinh" {
- expect(asinh(@as(f32, 0.0)) == asinh32(0.0));
- expect(asinh(@as(f64, 0.0)) == asinh64(0.0));
+ try expect(asinh(@as(f32, 0.0)) == asinh32(0.0));
+ try expect(asinh(@as(f64, 0.0)) == asinh64(0.0));
}
test "math.asinh32" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f32, asinh32(0.0), 0.0, epsilon));
- expect(math.approxEqAbs(f32, asinh32(0.2), 0.198690, epsilon));
- expect(math.approxEqAbs(f32, asinh32(0.8923), 0.803133, epsilon));
- expect(math.approxEqAbs(f32, asinh32(1.5), 1.194763, epsilon));
- expect(math.approxEqAbs(f32, asinh32(37.45), 4.316332, epsilon));
- expect(math.approxEqAbs(f32, asinh32(89.123), 5.183196, epsilon));
- expect(math.approxEqAbs(f32, asinh32(123123.234375), 12.414088, epsilon));
+ try expect(math.approxEqAbs(f32, asinh32(0.0), 0.0, epsilon));
+ try expect(math.approxEqAbs(f32, asinh32(0.2), 0.198690, epsilon));
+ try expect(math.approxEqAbs(f32, asinh32(0.8923), 0.803133, epsilon));
+ try expect(math.approxEqAbs(f32, asinh32(1.5), 1.194763, epsilon));
+ try expect(math.approxEqAbs(f32, asinh32(37.45), 4.316332, epsilon));
+ try expect(math.approxEqAbs(f32, asinh32(89.123), 5.183196, epsilon));
+ try expect(math.approxEqAbs(f32, asinh32(123123.234375), 12.414088, epsilon));
}
test "math.asinh64" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f64, asinh64(0.0), 0.0, epsilon));
- expect(math.approxEqAbs(f64, asinh64(0.2), 0.198690, epsilon));
- expect(math.approxEqAbs(f64, asinh64(0.8923), 0.803133, epsilon));
- expect(math.approxEqAbs(f64, asinh64(1.5), 1.194763, epsilon));
- expect(math.approxEqAbs(f64, asinh64(37.45), 4.316332, epsilon));
- expect(math.approxEqAbs(f64, asinh64(89.123), 5.183196, epsilon));
- expect(math.approxEqAbs(f64, asinh64(123123.234375), 12.414088, epsilon));
+ try expect(math.approxEqAbs(f64, asinh64(0.0), 0.0, epsilon));
+ try expect(math.approxEqAbs(f64, asinh64(0.2), 0.198690, epsilon));
+ try expect(math.approxEqAbs(f64, asinh64(0.8923), 0.803133, epsilon));
+ try expect(math.approxEqAbs(f64, asinh64(1.5), 1.194763, epsilon));
+ try expect(math.approxEqAbs(f64, asinh64(37.45), 4.316332, epsilon));
+ try expect(math.approxEqAbs(f64, asinh64(89.123), 5.183196, epsilon));
+ try expect(math.approxEqAbs(f64, asinh64(123123.234375), 12.414088, epsilon));
}
test "math.asinh32.special" {
- expect(asinh32(0.0) == 0.0);
- expect(asinh32(-0.0) == -0.0);
- expect(math.isPositiveInf(asinh32(math.inf(f32))));
- expect(math.isNegativeInf(asinh32(-math.inf(f32))));
- expect(math.isNan(asinh32(math.nan(f32))));
+ try expect(asinh32(0.0) == 0.0);
+ try expect(asinh32(-0.0) == -0.0);
+ try expect(math.isPositiveInf(asinh32(math.inf(f32))));
+ try expect(math.isNegativeInf(asinh32(-math.inf(f32))));
+ try expect(math.isNan(asinh32(math.nan(f32))));
}
test "math.asinh64.special" {
- expect(asinh64(0.0) == 0.0);
- expect(asinh64(-0.0) == -0.0);
- expect(math.isPositiveInf(asinh64(math.inf(f64))));
- expect(math.isNegativeInf(asinh64(-math.inf(f64))));
- expect(math.isNan(asinh64(math.nan(f64))));
+ try expect(asinh64(0.0) == 0.0);
+ try expect(asinh64(-0.0) == -0.0);
+ try expect(math.isPositiveInf(asinh64(math.inf(f64))));
+ try expect(math.isNegativeInf(asinh64(-math.inf(f64))));
+ try expect(math.isNan(asinh64(math.nan(f64))));
}
lib/std/math/atan.zig
@@ -217,44 +217,44 @@ fn atan64(x_: f64) f64 {
}
test "math.atan" {
- expect(@bitCast(u32, atan(@as(f32, 0.2))) == @bitCast(u32, atan32(0.2)));
- expect(atan(@as(f64, 0.2)) == atan64(0.2));
+ try expect(@bitCast(u32, atan(@as(f32, 0.2))) == @bitCast(u32, atan32(0.2)));
+ try expect(atan(@as(f64, 0.2)) == atan64(0.2));
}
test "math.atan32" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f32, atan32(0.2), 0.197396, epsilon));
- expect(math.approxEqAbs(f32, atan32(-0.2), -0.197396, epsilon));
- expect(math.approxEqAbs(f32, atan32(0.3434), 0.330783, epsilon));
- expect(math.approxEqAbs(f32, atan32(0.8923), 0.728545, epsilon));
- expect(math.approxEqAbs(f32, atan32(1.5), 0.982794, epsilon));
+ try expect(math.approxEqAbs(f32, atan32(0.2), 0.197396, epsilon));
+ try expect(math.approxEqAbs(f32, atan32(-0.2), -0.197396, epsilon));
+ try expect(math.approxEqAbs(f32, atan32(0.3434), 0.330783, epsilon));
+ try expect(math.approxEqAbs(f32, atan32(0.8923), 0.728545, epsilon));
+ try expect(math.approxEqAbs(f32, atan32(1.5), 0.982794, epsilon));
}
test "math.atan64" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f64, atan64(0.2), 0.197396, epsilon));
- expect(math.approxEqAbs(f64, atan64(-0.2), -0.197396, epsilon));
- expect(math.approxEqAbs(f64, atan64(0.3434), 0.330783, epsilon));
- expect(math.approxEqAbs(f64, atan64(0.8923), 0.728545, epsilon));
- expect(math.approxEqAbs(f64, atan64(1.5), 0.982794, epsilon));
+ try expect(math.approxEqAbs(f64, atan64(0.2), 0.197396, epsilon));
+ try expect(math.approxEqAbs(f64, atan64(-0.2), -0.197396, epsilon));
+ try expect(math.approxEqAbs(f64, atan64(0.3434), 0.330783, epsilon));
+ try expect(math.approxEqAbs(f64, atan64(0.8923), 0.728545, epsilon));
+ try expect(math.approxEqAbs(f64, atan64(1.5), 0.982794, epsilon));
}
test "math.atan32.special" {
const epsilon = 0.000001;
- expect(atan32(0.0) == 0.0);
- expect(atan32(-0.0) == -0.0);
- expect(math.approxEqAbs(f32, atan32(math.inf(f32)), math.pi / 2.0, epsilon));
- expect(math.approxEqAbs(f32, atan32(-math.inf(f32)), -math.pi / 2.0, epsilon));
+ try expect(atan32(0.0) == 0.0);
+ try expect(atan32(-0.0) == -0.0);
+ try expect(math.approxEqAbs(f32, atan32(math.inf(f32)), math.pi / 2.0, epsilon));
+ try expect(math.approxEqAbs(f32, atan32(-math.inf(f32)), -math.pi / 2.0, epsilon));
}
test "math.atan64.special" {
const epsilon = 0.000001;
- expect(atan64(0.0) == 0.0);
- expect(atan64(-0.0) == -0.0);
- expect(math.approxEqAbs(f64, atan64(math.inf(f64)), math.pi / 2.0, epsilon));
- expect(math.approxEqAbs(f64, atan64(-math.inf(f64)), -math.pi / 2.0, epsilon));
+ try expect(atan64(0.0) == 0.0);
+ try expect(atan64(-0.0) == -0.0);
+ try expect(math.approxEqAbs(f64, atan64(math.inf(f64)), math.pi / 2.0, epsilon));
+ try expect(math.approxEqAbs(f64, atan64(-math.inf(f64)), -math.pi / 2.0, epsilon));
}
lib/std/math/atan2.zig
@@ -217,78 +217,78 @@ fn atan2_64(y: f64, x: f64) f64 {
}
test "math.atan2" {
- expect(atan2(f32, 0.2, 0.21) == atan2_32(0.2, 0.21));
- expect(atan2(f64, 0.2, 0.21) == atan2_64(0.2, 0.21));
+ try expect(atan2(f32, 0.2, 0.21) == atan2_32(0.2, 0.21));
+ try expect(atan2(f64, 0.2, 0.21) == atan2_64(0.2, 0.21));
}
test "math.atan2_32" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f32, atan2_32(0.0, 0.0), 0.0, epsilon));
- expect(math.approxEqAbs(f32, atan2_32(0.2, 0.2), 0.785398, epsilon));
- expect(math.approxEqAbs(f32, atan2_32(-0.2, 0.2), -0.785398, epsilon));
- expect(math.approxEqAbs(f32, atan2_32(0.2, -0.2), 2.356194, epsilon));
- expect(math.approxEqAbs(f32, atan2_32(-0.2, -0.2), -2.356194, epsilon));
- expect(math.approxEqAbs(f32, atan2_32(0.34, -0.4), 2.437099, epsilon));
- expect(math.approxEqAbs(f32, atan2_32(0.34, 1.243), 0.267001, epsilon));
+ try expect(math.approxEqAbs(f32, atan2_32(0.0, 0.0), 0.0, epsilon));
+ try expect(math.approxEqAbs(f32, atan2_32(0.2, 0.2), 0.785398, epsilon));
+ try expect(math.approxEqAbs(f32, atan2_32(-0.2, 0.2), -0.785398, epsilon));
+ try expect(math.approxEqAbs(f32, atan2_32(0.2, -0.2), 2.356194, epsilon));
+ try expect(math.approxEqAbs(f32, atan2_32(-0.2, -0.2), -2.356194, epsilon));
+ try expect(math.approxEqAbs(f32, atan2_32(0.34, -0.4), 2.437099, epsilon));
+ try expect(math.approxEqAbs(f32, atan2_32(0.34, 1.243), 0.267001, epsilon));
}
test "math.atan2_64" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f64, atan2_64(0.0, 0.0), 0.0, epsilon));
- expect(math.approxEqAbs(f64, atan2_64(0.2, 0.2), 0.785398, epsilon));
- expect(math.approxEqAbs(f64, atan2_64(-0.2, 0.2), -0.785398, epsilon));
- expect(math.approxEqAbs(f64, atan2_64(0.2, -0.2), 2.356194, epsilon));
- expect(math.approxEqAbs(f64, atan2_64(-0.2, -0.2), -2.356194, epsilon));
- expect(math.approxEqAbs(f64, atan2_64(0.34, -0.4), 2.437099, epsilon));
- expect(math.approxEqAbs(f64, atan2_64(0.34, 1.243), 0.267001, epsilon));
+ try expect(math.approxEqAbs(f64, atan2_64(0.0, 0.0), 0.0, epsilon));
+ try expect(math.approxEqAbs(f64, atan2_64(0.2, 0.2), 0.785398, epsilon));
+ try expect(math.approxEqAbs(f64, atan2_64(-0.2, 0.2), -0.785398, epsilon));
+ try expect(math.approxEqAbs(f64, atan2_64(0.2, -0.2), 2.356194, epsilon));
+ try expect(math.approxEqAbs(f64, atan2_64(-0.2, -0.2), -2.356194, epsilon));
+ try expect(math.approxEqAbs(f64, atan2_64(0.34, -0.4), 2.437099, epsilon));
+ try expect(math.approxEqAbs(f64, atan2_64(0.34, 1.243), 0.267001, epsilon));
}
test "math.atan2_32.special" {
const epsilon = 0.000001;
- expect(math.isNan(atan2_32(1.0, math.nan(f32))));
- expect(math.isNan(atan2_32(math.nan(f32), 1.0)));
- expect(atan2_32(0.0, 5.0) == 0.0);
- expect(atan2_32(-0.0, 5.0) == -0.0);
- expect(math.approxEqAbs(f32, atan2_32(0.0, -5.0), math.pi, epsilon));
+ try expect(math.isNan(atan2_32(1.0, math.nan(f32))));
+ try expect(math.isNan(atan2_32(math.nan(f32), 1.0)));
+ try expect(atan2_32(0.0, 5.0) == 0.0);
+ try expect(atan2_32(-0.0, 5.0) == -0.0);
+ try expect(math.approxEqAbs(f32, atan2_32(0.0, -5.0), math.pi, epsilon));
//expect(math.approxEqAbs(f32, atan2_32(-0.0, -5.0), -math.pi, .{.rel=0,.abs=epsilon})); TODO support negative zero?
- expect(math.approxEqAbs(f32, atan2_32(1.0, 0.0), math.pi / 2.0, epsilon));
- expect(math.approxEqAbs(f32, atan2_32(1.0, -0.0), math.pi / 2.0, epsilon));
- expect(math.approxEqAbs(f32, atan2_32(-1.0, 0.0), -math.pi / 2.0, epsilon));
- expect(math.approxEqAbs(f32, atan2_32(-1.0, -0.0), -math.pi / 2.0, epsilon));
- expect(math.approxEqAbs(f32, atan2_32(math.inf(f32), math.inf(f32)), math.pi / 4.0, epsilon));
- expect(math.approxEqAbs(f32, atan2_32(-math.inf(f32), math.inf(f32)), -math.pi / 4.0, epsilon));
- expect(math.approxEqAbs(f32, atan2_32(math.inf(f32), -math.inf(f32)), 3.0 * math.pi / 4.0, epsilon));
- expect(math.approxEqAbs(f32, atan2_32(-math.inf(f32), -math.inf(f32)), -3.0 * math.pi / 4.0, epsilon));
- expect(atan2_32(1.0, math.inf(f32)) == 0.0);
- expect(math.approxEqAbs(f32, atan2_32(1.0, -math.inf(f32)), math.pi, epsilon));
- expect(math.approxEqAbs(f32, atan2_32(-1.0, -math.inf(f32)), -math.pi, epsilon));
- expect(math.approxEqAbs(f32, atan2_32(math.inf(f32), 1.0), math.pi / 2.0, epsilon));
- expect(math.approxEqAbs(f32, atan2_32(-math.inf(f32), 1.0), -math.pi / 2.0, epsilon));
+ try expect(math.approxEqAbs(f32, atan2_32(1.0, 0.0), math.pi / 2.0, epsilon));
+ try expect(math.approxEqAbs(f32, atan2_32(1.0, -0.0), math.pi / 2.0, epsilon));
+ try expect(math.approxEqAbs(f32, atan2_32(-1.0, 0.0), -math.pi / 2.0, epsilon));
+ try expect(math.approxEqAbs(f32, atan2_32(-1.0, -0.0), -math.pi / 2.0, epsilon));
+ try expect(math.approxEqAbs(f32, atan2_32(math.inf(f32), math.inf(f32)), math.pi / 4.0, epsilon));
+ try expect(math.approxEqAbs(f32, atan2_32(-math.inf(f32), math.inf(f32)), -math.pi / 4.0, epsilon));
+ try expect(math.approxEqAbs(f32, atan2_32(math.inf(f32), -math.inf(f32)), 3.0 * math.pi / 4.0, epsilon));
+ try expect(math.approxEqAbs(f32, atan2_32(-math.inf(f32), -math.inf(f32)), -3.0 * math.pi / 4.0, epsilon));
+ try expect(atan2_32(1.0, math.inf(f32)) == 0.0);
+ try expect(math.approxEqAbs(f32, atan2_32(1.0, -math.inf(f32)), math.pi, epsilon));
+ try expect(math.approxEqAbs(f32, atan2_32(-1.0, -math.inf(f32)), -math.pi, epsilon));
+ try expect(math.approxEqAbs(f32, atan2_32(math.inf(f32), 1.0), math.pi / 2.0, epsilon));
+ try expect(math.approxEqAbs(f32, atan2_32(-math.inf(f32), 1.0), -math.pi / 2.0, epsilon));
}
test "math.atan2_64.special" {
const epsilon = 0.000001;
- expect(math.isNan(atan2_64(1.0, math.nan(f64))));
- expect(math.isNan(atan2_64(math.nan(f64), 1.0)));
- expect(atan2_64(0.0, 5.0) == 0.0);
- expect(atan2_64(-0.0, 5.0) == -0.0);
- expect(math.approxEqAbs(f64, atan2_64(0.0, -5.0), math.pi, epsilon));
+ try expect(math.isNan(atan2_64(1.0, math.nan(f64))));
+ try expect(math.isNan(atan2_64(math.nan(f64), 1.0)));
+ try expect(atan2_64(0.0, 5.0) == 0.0);
+ try expect(atan2_64(-0.0, 5.0) == -0.0);
+ try expect(math.approxEqAbs(f64, atan2_64(0.0, -5.0), math.pi, epsilon));
//expect(math.approxEqAbs(f64, atan2_64(-0.0, -5.0), -math.pi, .{.rel=0,.abs=epsilon})); TODO support negative zero?
- expect(math.approxEqAbs(f64, atan2_64(1.0, 0.0), math.pi / 2.0, epsilon));
- expect(math.approxEqAbs(f64, atan2_64(1.0, -0.0), math.pi / 2.0, epsilon));
- expect(math.approxEqAbs(f64, atan2_64(-1.0, 0.0), -math.pi / 2.0, epsilon));
- expect(math.approxEqAbs(f64, atan2_64(-1.0, -0.0), -math.pi / 2.0, epsilon));
- expect(math.approxEqAbs(f64, atan2_64(math.inf(f64), math.inf(f64)), math.pi / 4.0, epsilon));
- expect(math.approxEqAbs(f64, atan2_64(-math.inf(f64), math.inf(f64)), -math.pi / 4.0, epsilon));
- expect(math.approxEqAbs(f64, atan2_64(math.inf(f64), -math.inf(f64)), 3.0 * math.pi / 4.0, epsilon));
- expect(math.approxEqAbs(f64, atan2_64(-math.inf(f64), -math.inf(f64)), -3.0 * math.pi / 4.0, epsilon));
- expect(atan2_64(1.0, math.inf(f64)) == 0.0);
- expect(math.approxEqAbs(f64, atan2_64(1.0, -math.inf(f64)), math.pi, epsilon));
- expect(math.approxEqAbs(f64, atan2_64(-1.0, -math.inf(f64)), -math.pi, epsilon));
- expect(math.approxEqAbs(f64, atan2_64(math.inf(f64), 1.0), math.pi / 2.0, epsilon));
- expect(math.approxEqAbs(f64, atan2_64(-math.inf(f64), 1.0), -math.pi / 2.0, epsilon));
+ try expect(math.approxEqAbs(f64, atan2_64(1.0, 0.0), math.pi / 2.0, epsilon));
+ try expect(math.approxEqAbs(f64, atan2_64(1.0, -0.0), math.pi / 2.0, epsilon));
+ try expect(math.approxEqAbs(f64, atan2_64(-1.0, 0.0), -math.pi / 2.0, epsilon));
+ try expect(math.approxEqAbs(f64, atan2_64(-1.0, -0.0), -math.pi / 2.0, epsilon));
+ try expect(math.approxEqAbs(f64, atan2_64(math.inf(f64), math.inf(f64)), math.pi / 4.0, epsilon));
+ try expect(math.approxEqAbs(f64, atan2_64(-math.inf(f64), math.inf(f64)), -math.pi / 4.0, epsilon));
+ try expect(math.approxEqAbs(f64, atan2_64(math.inf(f64), -math.inf(f64)), 3.0 * math.pi / 4.0, epsilon));
+ try expect(math.approxEqAbs(f64, atan2_64(-math.inf(f64), -math.inf(f64)), -3.0 * math.pi / 4.0, epsilon));
+ try expect(atan2_64(1.0, math.inf(f64)) == 0.0);
+ try expect(math.approxEqAbs(f64, atan2_64(1.0, -math.inf(f64)), math.pi, epsilon));
+ try expect(math.approxEqAbs(f64, atan2_64(-1.0, -math.inf(f64)), -math.pi, epsilon));
+ try expect(math.approxEqAbs(f64, atan2_64(math.inf(f64), 1.0), math.pi / 2.0, epsilon));
+ try expect(math.approxEqAbs(f64, atan2_64(-math.inf(f64), 1.0), -math.pi / 2.0, epsilon));
}
lib/std/math/atanh.zig
@@ -89,38 +89,38 @@ fn atanh_64(x: f64) f64 {
}
test "math.atanh" {
- expect(atanh(@as(f32, 0.0)) == atanh_32(0.0));
- expect(atanh(@as(f64, 0.0)) == atanh_64(0.0));
+ try expect(atanh(@as(f32, 0.0)) == atanh_32(0.0));
+ try expect(atanh(@as(f64, 0.0)) == atanh_64(0.0));
}
test "math.atanh_32" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f32, atanh_32(0.0), 0.0, epsilon));
- expect(math.approxEqAbs(f32, atanh_32(0.2), 0.202733, epsilon));
- expect(math.approxEqAbs(f32, atanh_32(0.8923), 1.433099, epsilon));
+ try expect(math.approxEqAbs(f32, atanh_32(0.0), 0.0, epsilon));
+ try expect(math.approxEqAbs(f32, atanh_32(0.2), 0.202733, epsilon));
+ try expect(math.approxEqAbs(f32, atanh_32(0.8923), 1.433099, epsilon));
}
test "math.atanh_64" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f64, atanh_64(0.0), 0.0, epsilon));
- expect(math.approxEqAbs(f64, atanh_64(0.2), 0.202733, epsilon));
- expect(math.approxEqAbs(f64, atanh_64(0.8923), 1.433099, epsilon));
+ try expect(math.approxEqAbs(f64, atanh_64(0.0), 0.0, epsilon));
+ try expect(math.approxEqAbs(f64, atanh_64(0.2), 0.202733, epsilon));
+ try expect(math.approxEqAbs(f64, atanh_64(0.8923), 1.433099, epsilon));
}
test "math.atanh32.special" {
- expect(math.isPositiveInf(atanh_32(1)));
- expect(math.isNegativeInf(atanh_32(-1)));
- expect(math.isSignalNan(atanh_32(1.5)));
- expect(math.isSignalNan(atanh_32(-1.5)));
- expect(math.isNan(atanh_32(math.nan(f32))));
+ try expect(math.isPositiveInf(atanh_32(1)));
+ try expect(math.isNegativeInf(atanh_32(-1)));
+ try expect(math.isSignalNan(atanh_32(1.5)));
+ try expect(math.isSignalNan(atanh_32(-1.5)));
+ try expect(math.isNan(atanh_32(math.nan(f32))));
}
test "math.atanh64.special" {
- expect(math.isPositiveInf(atanh_64(1)));
- expect(math.isNegativeInf(atanh_64(-1)));
- expect(math.isSignalNan(atanh_64(1.5)));
- expect(math.isSignalNan(atanh_64(-1.5)));
- expect(math.isNan(atanh_64(math.nan(f64))));
+ try expect(math.isPositiveInf(atanh_64(1)));
+ try expect(math.isNegativeInf(atanh_64(-1)));
+ try expect(math.isSignalNan(atanh_64(1.5)));
+ try expect(math.isSignalNan(atanh_64(-1.5)));
+ try expect(math.isNan(atanh_64(math.nan(f64))));
}
lib/std/math/cbrt.zig
@@ -125,44 +125,44 @@ fn cbrt64(x: f64) f64 {
}
test "math.cbrt" {
- expect(cbrt(@as(f32, 0.0)) == cbrt32(0.0));
- expect(cbrt(@as(f64, 0.0)) == cbrt64(0.0));
+ try expect(cbrt(@as(f32, 0.0)) == cbrt32(0.0));
+ try expect(cbrt(@as(f64, 0.0)) == cbrt64(0.0));
}
test "math.cbrt32" {
const epsilon = 0.000001;
- expect(cbrt32(0.0) == 0.0);
- expect(math.approxEqAbs(f32, cbrt32(0.2), 0.584804, epsilon));
- expect(math.approxEqAbs(f32, cbrt32(0.8923), 0.962728, epsilon));
- expect(math.approxEqAbs(f32, cbrt32(1.5), 1.144714, epsilon));
- expect(math.approxEqAbs(f32, cbrt32(37.45), 3.345676, epsilon));
- expect(math.approxEqAbs(f32, cbrt32(123123.234375), 49.748501, epsilon));
+ try expect(cbrt32(0.0) == 0.0);
+ try expect(math.approxEqAbs(f32, cbrt32(0.2), 0.584804, epsilon));
+ try expect(math.approxEqAbs(f32, cbrt32(0.8923), 0.962728, epsilon));
+ try expect(math.approxEqAbs(f32, cbrt32(1.5), 1.144714, epsilon));
+ try expect(math.approxEqAbs(f32, cbrt32(37.45), 3.345676, epsilon));
+ try expect(math.approxEqAbs(f32, cbrt32(123123.234375), 49.748501, epsilon));
}
test "math.cbrt64" {
const epsilon = 0.000001;
- expect(cbrt64(0.0) == 0.0);
- expect(math.approxEqAbs(f64, cbrt64(0.2), 0.584804, epsilon));
- expect(math.approxEqAbs(f64, cbrt64(0.8923), 0.962728, epsilon));
- expect(math.approxEqAbs(f64, cbrt64(1.5), 1.144714, epsilon));
- expect(math.approxEqAbs(f64, cbrt64(37.45), 3.345676, epsilon));
- expect(math.approxEqAbs(f64, cbrt64(123123.234375), 49.748501, epsilon));
+ try expect(cbrt64(0.0) == 0.0);
+ try expect(math.approxEqAbs(f64, cbrt64(0.2), 0.584804, epsilon));
+ try expect(math.approxEqAbs(f64, cbrt64(0.8923), 0.962728, epsilon));
+ try expect(math.approxEqAbs(f64, cbrt64(1.5), 1.144714, epsilon));
+ try expect(math.approxEqAbs(f64, cbrt64(37.45), 3.345676, epsilon));
+ try expect(math.approxEqAbs(f64, cbrt64(123123.234375), 49.748501, epsilon));
}
test "math.cbrt.special" {
- expect(cbrt32(0.0) == 0.0);
- expect(cbrt32(-0.0) == -0.0);
- expect(math.isPositiveInf(cbrt32(math.inf(f32))));
- expect(math.isNegativeInf(cbrt32(-math.inf(f32))));
- expect(math.isNan(cbrt32(math.nan(f32))));
+ try expect(cbrt32(0.0) == 0.0);
+ try expect(cbrt32(-0.0) == -0.0);
+ try expect(math.isPositiveInf(cbrt32(math.inf(f32))));
+ try expect(math.isNegativeInf(cbrt32(-math.inf(f32))));
+ try expect(math.isNan(cbrt32(math.nan(f32))));
}
test "math.cbrt64.special" {
- expect(cbrt64(0.0) == 0.0);
- expect(cbrt64(-0.0) == -0.0);
- expect(math.isPositiveInf(cbrt64(math.inf(f64))));
- expect(math.isNegativeInf(cbrt64(-math.inf(f64))));
- expect(math.isNan(cbrt64(math.nan(f64))));
+ try expect(cbrt64(0.0) == 0.0);
+ try expect(cbrt64(-0.0) == -0.0);
+ try expect(math.isPositiveInf(cbrt64(math.inf(f64))));
+ try expect(math.isNegativeInf(cbrt64(-math.inf(f64))));
+ try expect(math.isNan(cbrt64(math.nan(f64))));
}
lib/std/math/ceil.zig
@@ -120,49 +120,49 @@ fn ceil128(x: f128) f128 {
}
test "math.ceil" {
- expect(ceil(@as(f32, 0.0)) == ceil32(0.0));
- expect(ceil(@as(f64, 0.0)) == ceil64(0.0));
- expect(ceil(@as(f128, 0.0)) == ceil128(0.0));
+ try expect(ceil(@as(f32, 0.0)) == ceil32(0.0));
+ try expect(ceil(@as(f64, 0.0)) == ceil64(0.0));
+ try expect(ceil(@as(f128, 0.0)) == ceil128(0.0));
}
test "math.ceil32" {
- expect(ceil32(1.3) == 2.0);
- expect(ceil32(-1.3) == -1.0);
- expect(ceil32(0.2) == 1.0);
+ try expect(ceil32(1.3) == 2.0);
+ try expect(ceil32(-1.3) == -1.0);
+ try expect(ceil32(0.2) == 1.0);
}
test "math.ceil64" {
- expect(ceil64(1.3) == 2.0);
- expect(ceil64(-1.3) == -1.0);
- expect(ceil64(0.2) == 1.0);
+ try expect(ceil64(1.3) == 2.0);
+ try expect(ceil64(-1.3) == -1.0);
+ try expect(ceil64(0.2) == 1.0);
}
test "math.ceil128" {
- expect(ceil128(1.3) == 2.0);
- expect(ceil128(-1.3) == -1.0);
- expect(ceil128(0.2) == 1.0);
+ try expect(ceil128(1.3) == 2.0);
+ try expect(ceil128(-1.3) == -1.0);
+ try expect(ceil128(0.2) == 1.0);
}
test "math.ceil32.special" {
- expect(ceil32(0.0) == 0.0);
- expect(ceil32(-0.0) == -0.0);
- expect(math.isPositiveInf(ceil32(math.inf(f32))));
- expect(math.isNegativeInf(ceil32(-math.inf(f32))));
- expect(math.isNan(ceil32(math.nan(f32))));
+ try expect(ceil32(0.0) == 0.0);
+ try expect(ceil32(-0.0) == -0.0);
+ try expect(math.isPositiveInf(ceil32(math.inf(f32))));
+ try expect(math.isNegativeInf(ceil32(-math.inf(f32))));
+ try expect(math.isNan(ceil32(math.nan(f32))));
}
test "math.ceil64.special" {
- expect(ceil64(0.0) == 0.0);
- expect(ceil64(-0.0) == -0.0);
- expect(math.isPositiveInf(ceil64(math.inf(f64))));
- expect(math.isNegativeInf(ceil64(-math.inf(f64))));
- expect(math.isNan(ceil64(math.nan(f64))));
+ try expect(ceil64(0.0) == 0.0);
+ try expect(ceil64(-0.0) == -0.0);
+ try expect(math.isPositiveInf(ceil64(math.inf(f64))));
+ try expect(math.isNegativeInf(ceil64(-math.inf(f64))));
+ try expect(math.isNan(ceil64(math.nan(f64))));
}
test "math.ceil128.special" {
- expect(ceil128(0.0) == 0.0);
- expect(ceil128(-0.0) == -0.0);
- expect(math.isPositiveInf(ceil128(math.inf(f128))));
- expect(math.isNegativeInf(ceil128(-math.inf(f128))));
- expect(math.isNan(ceil128(math.nan(f128))));
+ try expect(ceil128(0.0) == 0.0);
+ try expect(ceil128(-0.0) == -0.0);
+ try expect(math.isPositiveInf(ceil128(math.inf(f128))));
+ try expect(math.isNegativeInf(ceil128(-math.inf(f128))));
+ try expect(math.isNan(ceil128(math.nan(f128))));
}
lib/std/math/complex.zig
@@ -114,7 +114,7 @@ test "complex.add" {
const b = Complex(f32).new(2, 7);
const c = a.add(b);
- testing.expect(c.re == 7 and c.im == 10);
+ try testing.expect(c.re == 7 and c.im == 10);
}
test "complex.sub" {
@@ -122,7 +122,7 @@ test "complex.sub" {
const b = Complex(f32).new(2, 7);
const c = a.sub(b);
- testing.expect(c.re == 3 and c.im == -4);
+ try testing.expect(c.re == 3 and c.im == -4);
}
test "complex.mul" {
@@ -130,7 +130,7 @@ test "complex.mul" {
const b = Complex(f32).new(2, 7);
const c = a.mul(b);
- testing.expect(c.re == -11 and c.im == 41);
+ try testing.expect(c.re == -11 and c.im == 41);
}
test "complex.div" {
@@ -138,7 +138,7 @@ test "complex.div" {
const b = Complex(f32).new(2, 7);
const c = a.div(b);
- testing.expect(math.approxEqAbs(f32, c.re, @as(f32, 31) / 53, epsilon) and
+ try testing.expect(math.approxEqAbs(f32, c.re, @as(f32, 31) / 53, epsilon) and
math.approxEqAbs(f32, c.im, @as(f32, -29) / 53, epsilon));
}
@@ -146,14 +146,14 @@ test "complex.conjugate" {
const a = Complex(f32).new(5, 3);
const c = a.conjugate();
- testing.expect(c.re == 5 and c.im == -3);
+ try testing.expect(c.re == 5 and c.im == -3);
}
test "complex.reciprocal" {
const a = Complex(f32).new(5, 3);
const c = a.reciprocal();
- testing.expect(math.approxEqAbs(f32, c.re, @as(f32, 5) / 34, epsilon) and
+ try testing.expect(math.approxEqAbs(f32, c.re, @as(f32, 5) / 34, epsilon) and
math.approxEqAbs(f32, c.im, @as(f32, -3) / 34, epsilon));
}
@@ -161,7 +161,7 @@ test "complex.magnitude" {
const a = Complex(f32).new(5, 3);
const c = a.magnitude();
- testing.expect(math.approxEqAbs(f32, c, 5.83095, epsilon));
+ try testing.expect(math.approxEqAbs(f32, c, 5.83095, epsilon));
}
test "complex.cmath" {
lib/std/math/copysign.zig
@@ -62,36 +62,36 @@ fn copysign128(x: f128, y: f128) f128 {
}
test "math.copysign" {
- expect(copysign(f16, 1.0, 1.0) == copysign16(1.0, 1.0));
- expect(copysign(f32, 1.0, 1.0) == copysign32(1.0, 1.0));
- expect(copysign(f64, 1.0, 1.0) == copysign64(1.0, 1.0));
- expect(copysign(f128, 1.0, 1.0) == copysign128(1.0, 1.0));
+ try expect(copysign(f16, 1.0, 1.0) == copysign16(1.0, 1.0));
+ try expect(copysign(f32, 1.0, 1.0) == copysign32(1.0, 1.0));
+ try expect(copysign(f64, 1.0, 1.0) == copysign64(1.0, 1.0));
+ try expect(copysign(f128, 1.0, 1.0) == copysign128(1.0, 1.0));
}
test "math.copysign16" {
- expect(copysign16(5.0, 1.0) == 5.0);
- expect(copysign16(5.0, -1.0) == -5.0);
- expect(copysign16(-5.0, -1.0) == -5.0);
- expect(copysign16(-5.0, 1.0) == 5.0);
+ try expect(copysign16(5.0, 1.0) == 5.0);
+ try expect(copysign16(5.0, -1.0) == -5.0);
+ try expect(copysign16(-5.0, -1.0) == -5.0);
+ try expect(copysign16(-5.0, 1.0) == 5.0);
}
test "math.copysign32" {
- expect(copysign32(5.0, 1.0) == 5.0);
- expect(copysign32(5.0, -1.0) == -5.0);
- expect(copysign32(-5.0, -1.0) == -5.0);
- expect(copysign32(-5.0, 1.0) == 5.0);
+ try expect(copysign32(5.0, 1.0) == 5.0);
+ try expect(copysign32(5.0, -1.0) == -5.0);
+ try expect(copysign32(-5.0, -1.0) == -5.0);
+ try expect(copysign32(-5.0, 1.0) == 5.0);
}
test "math.copysign64" {
- expect(copysign64(5.0, 1.0) == 5.0);
- expect(copysign64(5.0, -1.0) == -5.0);
- expect(copysign64(-5.0, -1.0) == -5.0);
- expect(copysign64(-5.0, 1.0) == 5.0);
+ try expect(copysign64(5.0, 1.0) == 5.0);
+ try expect(copysign64(5.0, -1.0) == -5.0);
+ try expect(copysign64(-5.0, -1.0) == -5.0);
+ try expect(copysign64(-5.0, 1.0) == 5.0);
}
test "math.copysign128" {
- expect(copysign128(5.0, 1.0) == 5.0);
- expect(copysign128(5.0, -1.0) == -5.0);
- expect(copysign128(-5.0, -1.0) == -5.0);
- expect(copysign128(-5.0, 1.0) == 5.0);
+ try expect(copysign128(5.0, 1.0) == 5.0);
+ try expect(copysign128(5.0, -1.0) == -5.0);
+ try expect(copysign128(-5.0, -1.0) == -5.0);
+ try expect(copysign128(-5.0, 1.0) == 5.0);
}
lib/std/math/cos.zig
@@ -88,42 +88,42 @@ fn cos_(comptime T: type, x_: T) T {
}
test "math.cos" {
- expect(cos(@as(f32, 0.0)) == cos_(f32, 0.0));
- expect(cos(@as(f64, 0.0)) == cos_(f64, 0.0));
+ try expect(cos(@as(f32, 0.0)) == cos_(f32, 0.0));
+ try expect(cos(@as(f64, 0.0)) == cos_(f64, 0.0));
}
test "math.cos32" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f32, cos_(f32, 0.0), 1.0, epsilon));
- expect(math.approxEqAbs(f32, cos_(f32, 0.2), 0.980067, epsilon));
- expect(math.approxEqAbs(f32, cos_(f32, 0.8923), 0.627623, epsilon));
- expect(math.approxEqAbs(f32, cos_(f32, 1.5), 0.070737, epsilon));
- expect(math.approxEqAbs(f32, cos_(f32, -1.5), 0.070737, epsilon));
- expect(math.approxEqAbs(f32, cos_(f32, 37.45), 0.969132, epsilon));
- expect(math.approxEqAbs(f32, cos_(f32, 89.123), 0.400798, epsilon));
+ try expect(math.approxEqAbs(f32, cos_(f32, 0.0), 1.0, epsilon));
+ try expect(math.approxEqAbs(f32, cos_(f32, 0.2), 0.980067, epsilon));
+ try expect(math.approxEqAbs(f32, cos_(f32, 0.8923), 0.627623, epsilon));
+ try expect(math.approxEqAbs(f32, cos_(f32, 1.5), 0.070737, epsilon));
+ try expect(math.approxEqAbs(f32, cos_(f32, -1.5), 0.070737, epsilon));
+ try expect(math.approxEqAbs(f32, cos_(f32, 37.45), 0.969132, epsilon));
+ try expect(math.approxEqAbs(f32, cos_(f32, 89.123), 0.400798, epsilon));
}
test "math.cos64" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f64, cos_(f64, 0.0), 1.0, epsilon));
- expect(math.approxEqAbs(f64, cos_(f64, 0.2), 0.980067, epsilon));
- expect(math.approxEqAbs(f64, cos_(f64, 0.8923), 0.627623, epsilon));
- expect(math.approxEqAbs(f64, cos_(f64, 1.5), 0.070737, epsilon));
- expect(math.approxEqAbs(f64, cos_(f64, -1.5), 0.070737, epsilon));
- expect(math.approxEqAbs(f64, cos_(f64, 37.45), 0.969132, epsilon));
- expect(math.approxEqAbs(f64, cos_(f64, 89.123), 0.40080, epsilon));
+ try expect(math.approxEqAbs(f64, cos_(f64, 0.0), 1.0, epsilon));
+ try expect(math.approxEqAbs(f64, cos_(f64, 0.2), 0.980067, epsilon));
+ try expect(math.approxEqAbs(f64, cos_(f64, 0.8923), 0.627623, epsilon));
+ try expect(math.approxEqAbs(f64, cos_(f64, 1.5), 0.070737, epsilon));
+ try expect(math.approxEqAbs(f64, cos_(f64, -1.5), 0.070737, epsilon));
+ try expect(math.approxEqAbs(f64, cos_(f64, 37.45), 0.969132, epsilon));
+ try expect(math.approxEqAbs(f64, cos_(f64, 89.123), 0.40080, epsilon));
}
test "math.cos32.special" {
- expect(math.isNan(cos_(f32, math.inf(f32))));
- expect(math.isNan(cos_(f32, -math.inf(f32))));
- expect(math.isNan(cos_(f32, math.nan(f32))));
+ try expect(math.isNan(cos_(f32, math.inf(f32))));
+ try expect(math.isNan(cos_(f32, -math.inf(f32))));
+ try expect(math.isNan(cos_(f32, math.nan(f32))));
}
test "math.cos64.special" {
- expect(math.isNan(cos_(f64, math.inf(f64))));
- expect(math.isNan(cos_(f64, -math.inf(f64))));
- expect(math.isNan(cos_(f64, math.nan(f64))));
+ try expect(math.isNan(cos_(f64, math.inf(f64))));
+ try expect(math.isNan(cos_(f64, -math.inf(f64))));
+ try expect(math.isNan(cos_(f64, math.nan(f64))));
}
lib/std/math/cosh.zig
@@ -93,48 +93,48 @@ fn cosh64(x: f64) f64 {
}
test "math.cosh" {
- expect(cosh(@as(f32, 1.5)) == cosh32(1.5));
- expect(cosh(@as(f64, 1.5)) == cosh64(1.5));
+ try expect(cosh(@as(f32, 1.5)) == cosh32(1.5));
+ try expect(cosh(@as(f64, 1.5)) == cosh64(1.5));
}
test "math.cosh32" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f32, cosh32(0.0), 1.0, epsilon));
- expect(math.approxEqAbs(f32, cosh32(0.2), 1.020067, epsilon));
- expect(math.approxEqAbs(f32, cosh32(0.8923), 1.425225, epsilon));
- expect(math.approxEqAbs(f32, cosh32(1.5), 2.352410, epsilon));
- expect(math.approxEqAbs(f32, cosh32(-0.0), 1.0, epsilon));
- expect(math.approxEqAbs(f32, cosh32(-0.2), 1.020067, epsilon));
- expect(math.approxEqAbs(f32, cosh32(-0.8923), 1.425225, epsilon));
- expect(math.approxEqAbs(f32, cosh32(-1.5), 2.352410, epsilon));
+ try expect(math.approxEqAbs(f32, cosh32(0.0), 1.0, epsilon));
+ try expect(math.approxEqAbs(f32, cosh32(0.2), 1.020067, epsilon));
+ try expect(math.approxEqAbs(f32, cosh32(0.8923), 1.425225, epsilon));
+ try expect(math.approxEqAbs(f32, cosh32(1.5), 2.352410, epsilon));
+ try expect(math.approxEqAbs(f32, cosh32(-0.0), 1.0, epsilon));
+ try expect(math.approxEqAbs(f32, cosh32(-0.2), 1.020067, epsilon));
+ try expect(math.approxEqAbs(f32, cosh32(-0.8923), 1.425225, epsilon));
+ try expect(math.approxEqAbs(f32, cosh32(-1.5), 2.352410, epsilon));
}
test "math.cosh64" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f64, cosh64(0.0), 1.0, epsilon));
- expect(math.approxEqAbs(f64, cosh64(0.2), 1.020067, epsilon));
- expect(math.approxEqAbs(f64, cosh64(0.8923), 1.425225, epsilon));
- expect(math.approxEqAbs(f64, cosh64(1.5), 2.352410, epsilon));
- expect(math.approxEqAbs(f64, cosh64(-0.0), 1.0, epsilon));
- expect(math.approxEqAbs(f64, cosh64(-0.2), 1.020067, epsilon));
- expect(math.approxEqAbs(f64, cosh64(-0.8923), 1.425225, epsilon));
- expect(math.approxEqAbs(f64, cosh64(-1.5), 2.352410, epsilon));
+ try expect(math.approxEqAbs(f64, cosh64(0.0), 1.0, epsilon));
+ try expect(math.approxEqAbs(f64, cosh64(0.2), 1.020067, epsilon));
+ try expect(math.approxEqAbs(f64, cosh64(0.8923), 1.425225, epsilon));
+ try expect(math.approxEqAbs(f64, cosh64(1.5), 2.352410, epsilon));
+ try expect(math.approxEqAbs(f64, cosh64(-0.0), 1.0, epsilon));
+ try expect(math.approxEqAbs(f64, cosh64(-0.2), 1.020067, epsilon));
+ try expect(math.approxEqAbs(f64, cosh64(-0.8923), 1.425225, epsilon));
+ try expect(math.approxEqAbs(f64, cosh64(-1.5), 2.352410, epsilon));
}
test "math.cosh32.special" {
- expect(cosh32(0.0) == 1.0);
- expect(cosh32(-0.0) == 1.0);
- expect(math.isPositiveInf(cosh32(math.inf(f32))));
- expect(math.isPositiveInf(cosh32(-math.inf(f32))));
- expect(math.isNan(cosh32(math.nan(f32))));
+ try expect(cosh32(0.0) == 1.0);
+ try expect(cosh32(-0.0) == 1.0);
+ try expect(math.isPositiveInf(cosh32(math.inf(f32))));
+ try expect(math.isPositiveInf(cosh32(-math.inf(f32))));
+ try expect(math.isNan(cosh32(math.nan(f32))));
}
test "math.cosh64.special" {
- expect(cosh64(0.0) == 1.0);
- expect(cosh64(-0.0) == 1.0);
- expect(math.isPositiveInf(cosh64(math.inf(f64))));
- expect(math.isPositiveInf(cosh64(-math.inf(f64))));
- expect(math.isNan(cosh64(math.nan(f64))));
+ try expect(cosh64(0.0) == 1.0);
+ try expect(cosh64(-0.0) == 1.0);
+ try expect(math.isPositiveInf(cosh64(math.inf(f64))));
+ try expect(math.isPositiveInf(cosh64(-math.inf(f64))));
+ try expect(math.isNan(cosh64(math.nan(f64))));
}
lib/std/math/exp.zig
@@ -187,36 +187,36 @@ fn exp64(x_: f64) f64 {
}
test "math.exp" {
- expect(exp(@as(f32, 0.0)) == exp32(0.0));
- expect(exp(@as(f64, 0.0)) == exp64(0.0));
+ try expect(exp(@as(f32, 0.0)) == exp32(0.0));
+ try expect(exp(@as(f64, 0.0)) == exp64(0.0));
}
test "math.exp32" {
const epsilon = 0.000001;
- expect(exp32(0.0) == 1.0);
- expect(math.approxEqAbs(f32, exp32(0.0), 1.0, epsilon));
- expect(math.approxEqAbs(f32, exp32(0.2), 1.221403, epsilon));
- expect(math.approxEqAbs(f32, exp32(0.8923), 2.440737, epsilon));
- expect(math.approxEqAbs(f32, exp32(1.5), 4.481689, epsilon));
+ try expect(exp32(0.0) == 1.0);
+ try expect(math.approxEqAbs(f32, exp32(0.0), 1.0, epsilon));
+ try expect(math.approxEqAbs(f32, exp32(0.2), 1.221403, epsilon));
+ try expect(math.approxEqAbs(f32, exp32(0.8923), 2.440737, epsilon));
+ try expect(math.approxEqAbs(f32, exp32(1.5), 4.481689, epsilon));
}
test "math.exp64" {
const epsilon = 0.000001;
- expect(exp64(0.0) == 1.0);
- expect(math.approxEqAbs(f64, exp64(0.0), 1.0, epsilon));
- expect(math.approxEqAbs(f64, exp64(0.2), 1.221403, epsilon));
- expect(math.approxEqAbs(f64, exp64(0.8923), 2.440737, epsilon));
- expect(math.approxEqAbs(f64, exp64(1.5), 4.481689, epsilon));
+ try expect(exp64(0.0) == 1.0);
+ try expect(math.approxEqAbs(f64, exp64(0.0), 1.0, epsilon));
+ try expect(math.approxEqAbs(f64, exp64(0.2), 1.221403, epsilon));
+ try expect(math.approxEqAbs(f64, exp64(0.8923), 2.440737, epsilon));
+ try expect(math.approxEqAbs(f64, exp64(1.5), 4.481689, epsilon));
}
test "math.exp32.special" {
- expect(math.isPositiveInf(exp32(math.inf(f32))));
- expect(math.isNan(exp32(math.nan(f32))));
+ try expect(math.isPositiveInf(exp32(math.inf(f32))));
+ try expect(math.isNan(exp32(math.nan(f32))));
}
test "math.exp64.special" {
- expect(math.isPositiveInf(exp64(math.inf(f64))));
- expect(math.isNan(exp64(math.nan(f64))));
+ try expect(math.isPositiveInf(exp64(math.inf(f64))));
+ try expect(math.isNan(exp64(math.nan(f64))));
}
lib/std/math/exp2.zig
@@ -426,35 +426,35 @@ fn exp2_64(x: f64) f64 {
}
test "math.exp2" {
- expect(exp2(@as(f32, 0.8923)) == exp2_32(0.8923));
- expect(exp2(@as(f64, 0.8923)) == exp2_64(0.8923));
+ try expect(exp2(@as(f32, 0.8923)) == exp2_32(0.8923));
+ try expect(exp2(@as(f64, 0.8923)) == exp2_64(0.8923));
}
test "math.exp2_32" {
const epsilon = 0.000001;
- expect(exp2_32(0.0) == 1.0);
- expect(math.approxEqAbs(f32, exp2_32(0.2), 1.148698, epsilon));
- expect(math.approxEqAbs(f32, exp2_32(0.8923), 1.856133, epsilon));
- expect(math.approxEqAbs(f32, exp2_32(1.5), 2.828427, epsilon));
- expect(math.approxEqAbs(f32, exp2_32(37.45), 187747237888, epsilon));
+ try expect(exp2_32(0.0) == 1.0);
+ try expect(math.approxEqAbs(f32, exp2_32(0.2), 1.148698, epsilon));
+ try expect(math.approxEqAbs(f32, exp2_32(0.8923), 1.856133, epsilon));
+ try expect(math.approxEqAbs(f32, exp2_32(1.5), 2.828427, epsilon));
+ try expect(math.approxEqAbs(f32, exp2_32(37.45), 187747237888, epsilon));
}
test "math.exp2_64" {
const epsilon = 0.000001;
- expect(exp2_64(0.0) == 1.0);
- expect(math.approxEqAbs(f64, exp2_64(0.2), 1.148698, epsilon));
- expect(math.approxEqAbs(f64, exp2_64(0.8923), 1.856133, epsilon));
- expect(math.approxEqAbs(f64, exp2_64(1.5), 2.828427, epsilon));
+ try expect(exp2_64(0.0) == 1.0);
+ try expect(math.approxEqAbs(f64, exp2_64(0.2), 1.148698, epsilon));
+ try expect(math.approxEqAbs(f64, exp2_64(0.8923), 1.856133, epsilon));
+ try expect(math.approxEqAbs(f64, exp2_64(1.5), 2.828427, epsilon));
}
test "math.exp2_32.special" {
- expect(math.isPositiveInf(exp2_32(math.inf(f32))));
- expect(math.isNan(exp2_32(math.nan(f32))));
+ try expect(math.isPositiveInf(exp2_32(math.inf(f32))));
+ try expect(math.isNan(exp2_32(math.nan(f32))));
}
test "math.exp2_64.special" {
- expect(math.isPositiveInf(exp2_64(math.inf(f64))));
- expect(math.isNan(exp2_64(math.nan(f64))));
+ try expect(math.isPositiveInf(exp2_64(math.inf(f64))));
+ try expect(math.isNan(exp2_64(math.nan(f64))));
}
lib/std/math/expm1.zig
@@ -292,42 +292,42 @@ fn expm1_64(x_: f64) f64 {
}
test "math.exp1m" {
- expect(expm1(@as(f32, 0.0)) == expm1_32(0.0));
- expect(expm1(@as(f64, 0.0)) == expm1_64(0.0));
+ try expect(expm1(@as(f32, 0.0)) == expm1_32(0.0));
+ try expect(expm1(@as(f64, 0.0)) == expm1_64(0.0));
}
test "math.expm1_32" {
const epsilon = 0.000001;
- expect(expm1_32(0.0) == 0.0);
- expect(math.approxEqAbs(f32, expm1_32(0.0), 0.0, epsilon));
- expect(math.approxEqAbs(f32, expm1_32(0.2), 0.221403, epsilon));
- expect(math.approxEqAbs(f32, expm1_32(0.8923), 1.440737, epsilon));
- expect(math.approxEqAbs(f32, expm1_32(1.5), 3.481689, epsilon));
+ try expect(expm1_32(0.0) == 0.0);
+ try expect(math.approxEqAbs(f32, expm1_32(0.0), 0.0, epsilon));
+ try expect(math.approxEqAbs(f32, expm1_32(0.2), 0.221403, epsilon));
+ try expect(math.approxEqAbs(f32, expm1_32(0.8923), 1.440737, epsilon));
+ try expect(math.approxEqAbs(f32, expm1_32(1.5), 3.481689, epsilon));
}
test "math.expm1_64" {
const epsilon = 0.000001;
- expect(expm1_64(0.0) == 0.0);
- expect(math.approxEqAbs(f64, expm1_64(0.0), 0.0, epsilon));
- expect(math.approxEqAbs(f64, expm1_64(0.2), 0.221403, epsilon));
- expect(math.approxEqAbs(f64, expm1_64(0.8923), 1.440737, epsilon));
- expect(math.approxEqAbs(f64, expm1_64(1.5), 3.481689, epsilon));
+ try expect(expm1_64(0.0) == 0.0);
+ try expect(math.approxEqAbs(f64, expm1_64(0.0), 0.0, epsilon));
+ try expect(math.approxEqAbs(f64, expm1_64(0.2), 0.221403, epsilon));
+ try expect(math.approxEqAbs(f64, expm1_64(0.8923), 1.440737, epsilon));
+ try expect(math.approxEqAbs(f64, expm1_64(1.5), 3.481689, epsilon));
}
test "math.expm1_32.special" {
const epsilon = 0.000001;
- expect(math.isPositiveInf(expm1_32(math.inf(f32))));
- expect(expm1_32(-math.inf(f32)) == -1.0);
- expect(math.isNan(expm1_32(math.nan(f32))));
+ try expect(math.isPositiveInf(expm1_32(math.inf(f32))));
+ try expect(expm1_32(-math.inf(f32)) == -1.0);
+ try expect(math.isNan(expm1_32(math.nan(f32))));
}
test "math.expm1_64.special" {
const epsilon = 0.000001;
- expect(math.isPositiveInf(expm1_64(math.inf(f64))));
- expect(expm1_64(-math.inf(f64)) == -1.0);
- expect(math.isNan(expm1_64(math.nan(f64))));
+ try expect(math.isPositiveInf(expm1_64(math.inf(f64))));
+ try expect(expm1_64(-math.inf(f64)) == -1.0);
+ try expect(math.isNan(expm1_64(math.nan(f64))));
}
lib/std/math/fabs.zig
@@ -55,52 +55,52 @@ fn fabs128(x: f128) f128 {
}
test "math.fabs" {
- expect(fabs(@as(f16, 1.0)) == fabs16(1.0));
- expect(fabs(@as(f32, 1.0)) == fabs32(1.0));
- expect(fabs(@as(f64, 1.0)) == fabs64(1.0));
- expect(fabs(@as(f128, 1.0)) == fabs128(1.0));
+ try expect(fabs(@as(f16, 1.0)) == fabs16(1.0));
+ try expect(fabs(@as(f32, 1.0)) == fabs32(1.0));
+ try expect(fabs(@as(f64, 1.0)) == fabs64(1.0));
+ try expect(fabs(@as(f128, 1.0)) == fabs128(1.0));
}
test "math.fabs16" {
- expect(fabs16(1.0) == 1.0);
- expect(fabs16(-1.0) == 1.0);
+ try expect(fabs16(1.0) == 1.0);
+ try expect(fabs16(-1.0) == 1.0);
}
test "math.fabs32" {
- expect(fabs32(1.0) == 1.0);
- expect(fabs32(-1.0) == 1.0);
+ try expect(fabs32(1.0) == 1.0);
+ try expect(fabs32(-1.0) == 1.0);
}
test "math.fabs64" {
- expect(fabs64(1.0) == 1.0);
- expect(fabs64(-1.0) == 1.0);
+ try expect(fabs64(1.0) == 1.0);
+ try expect(fabs64(-1.0) == 1.0);
}
test "math.fabs128" {
- expect(fabs128(1.0) == 1.0);
- expect(fabs128(-1.0) == 1.0);
+ try expect(fabs128(1.0) == 1.0);
+ try expect(fabs128(-1.0) == 1.0);
}
test "math.fabs16.special" {
- expect(math.isPositiveInf(fabs(math.inf(f16))));
- expect(math.isPositiveInf(fabs(-math.inf(f16))));
- expect(math.isNan(fabs(math.nan(f16))));
+ try expect(math.isPositiveInf(fabs(math.inf(f16))));
+ try expect(math.isPositiveInf(fabs(-math.inf(f16))));
+ try expect(math.isNan(fabs(math.nan(f16))));
}
test "math.fabs32.special" {
- expect(math.isPositiveInf(fabs(math.inf(f32))));
- expect(math.isPositiveInf(fabs(-math.inf(f32))));
- expect(math.isNan(fabs(math.nan(f32))));
+ try expect(math.isPositiveInf(fabs(math.inf(f32))));
+ try expect(math.isPositiveInf(fabs(-math.inf(f32))));
+ try expect(math.isNan(fabs(math.nan(f32))));
}
test "math.fabs64.special" {
- expect(math.isPositiveInf(fabs(math.inf(f64))));
- expect(math.isPositiveInf(fabs(-math.inf(f64))));
- expect(math.isNan(fabs(math.nan(f64))));
+ try expect(math.isPositiveInf(fabs(math.inf(f64))));
+ try expect(math.isPositiveInf(fabs(-math.inf(f64))));
+ try expect(math.isNan(fabs(math.nan(f64))));
}
test "math.fabs128.special" {
- expect(math.isPositiveInf(fabs(math.inf(f128))));
- expect(math.isPositiveInf(fabs(-math.inf(f128))));
- expect(math.isNan(fabs(math.nan(f128))));
+ try expect(math.isPositiveInf(fabs(math.inf(f128))));
+ try expect(math.isPositiveInf(fabs(-math.inf(f128))));
+ try expect(math.isNan(fabs(math.nan(f128))));
}
lib/std/math/floor.zig
@@ -156,64 +156,64 @@ fn floor128(x: f128) f128 {
}
test "math.floor" {
- expect(floor(@as(f16, 1.3)) == floor16(1.3));
- expect(floor(@as(f32, 1.3)) == floor32(1.3));
- expect(floor(@as(f64, 1.3)) == floor64(1.3));
- expect(floor(@as(f128, 1.3)) == floor128(1.3));
+ try expect(floor(@as(f16, 1.3)) == floor16(1.3));
+ try expect(floor(@as(f32, 1.3)) == floor32(1.3));
+ try expect(floor(@as(f64, 1.3)) == floor64(1.3));
+ try expect(floor(@as(f128, 1.3)) == floor128(1.3));
}
test "math.floor16" {
- expect(floor16(1.3) == 1.0);
- expect(floor16(-1.3) == -2.0);
- expect(floor16(0.2) == 0.0);
+ try expect(floor16(1.3) == 1.0);
+ try expect(floor16(-1.3) == -2.0);
+ try expect(floor16(0.2) == 0.0);
}
test "math.floor32" {
- expect(floor32(1.3) == 1.0);
- expect(floor32(-1.3) == -2.0);
- expect(floor32(0.2) == 0.0);
+ try expect(floor32(1.3) == 1.0);
+ try expect(floor32(-1.3) == -2.0);
+ try expect(floor32(0.2) == 0.0);
}
test "math.floor64" {
- expect(floor64(1.3) == 1.0);
- expect(floor64(-1.3) == -2.0);
- expect(floor64(0.2) == 0.0);
+ try expect(floor64(1.3) == 1.0);
+ try expect(floor64(-1.3) == -2.0);
+ try expect(floor64(0.2) == 0.0);
}
test "math.floor128" {
- expect(floor128(1.3) == 1.0);
- expect(floor128(-1.3) == -2.0);
- expect(floor128(0.2) == 0.0);
+ try expect(floor128(1.3) == 1.0);
+ try expect(floor128(-1.3) == -2.0);
+ try expect(floor128(0.2) == 0.0);
}
test "math.floor16.special" {
- expect(floor16(0.0) == 0.0);
- expect(floor16(-0.0) == -0.0);
- expect(math.isPositiveInf(floor16(math.inf(f16))));
- expect(math.isNegativeInf(floor16(-math.inf(f16))));
- expect(math.isNan(floor16(math.nan(f16))));
+ try expect(floor16(0.0) == 0.0);
+ try expect(floor16(-0.0) == -0.0);
+ try expect(math.isPositiveInf(floor16(math.inf(f16))));
+ try expect(math.isNegativeInf(floor16(-math.inf(f16))));
+ try expect(math.isNan(floor16(math.nan(f16))));
}
test "math.floor32.special" {
- expect(floor32(0.0) == 0.0);
- expect(floor32(-0.0) == -0.0);
- expect(math.isPositiveInf(floor32(math.inf(f32))));
- expect(math.isNegativeInf(floor32(-math.inf(f32))));
- expect(math.isNan(floor32(math.nan(f32))));
+ try expect(floor32(0.0) == 0.0);
+ try expect(floor32(-0.0) == -0.0);
+ try expect(math.isPositiveInf(floor32(math.inf(f32))));
+ try expect(math.isNegativeInf(floor32(-math.inf(f32))));
+ try expect(math.isNan(floor32(math.nan(f32))));
}
test "math.floor64.special" {
- expect(floor64(0.0) == 0.0);
- expect(floor64(-0.0) == -0.0);
- expect(math.isPositiveInf(floor64(math.inf(f64))));
- expect(math.isNegativeInf(floor64(-math.inf(f64))));
- expect(math.isNan(floor64(math.nan(f64))));
+ try expect(floor64(0.0) == 0.0);
+ try expect(floor64(-0.0) == -0.0);
+ try expect(math.isPositiveInf(floor64(math.inf(f64))));
+ try expect(math.isNegativeInf(floor64(-math.inf(f64))));
+ try expect(math.isNan(floor64(math.nan(f64))));
}
test "math.floor128.special" {
- expect(floor128(0.0) == 0.0);
- expect(floor128(-0.0) == -0.0);
- expect(math.isPositiveInf(floor128(math.inf(f128))));
- expect(math.isNegativeInf(floor128(-math.inf(f128))));
- expect(math.isNan(floor128(math.nan(f128))));
+ try expect(floor128(0.0) == 0.0);
+ try expect(floor128(-0.0) == -0.0);
+ try expect(math.isPositiveInf(floor128(math.inf(f128))));
+ try expect(math.isNegativeInf(floor128(-math.inf(f128))));
+ try expect(math.isNan(floor128(math.nan(f128))));
}
lib/std/math/fma.zig
@@ -148,30 +148,30 @@ fn add_and_denorm(a: f64, b: f64, scale: i32) f64 {
}
test "math.fma" {
- expect(fma(f32, 0.0, 1.0, 1.0) == fma32(0.0, 1.0, 1.0));
- expect(fma(f64, 0.0, 1.0, 1.0) == fma64(0.0, 1.0, 1.0));
+ try expect(fma(f32, 0.0, 1.0, 1.0) == fma32(0.0, 1.0, 1.0));
+ try expect(fma(f64, 0.0, 1.0, 1.0) == fma64(0.0, 1.0, 1.0));
}
test "math.fma32" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f32, fma32(0.0, 5.0, 9.124), 9.124, epsilon));
- expect(math.approxEqAbs(f32, fma32(0.2, 5.0, 9.124), 10.124, epsilon));
- expect(math.approxEqAbs(f32, fma32(0.8923, 5.0, 9.124), 13.5855, epsilon));
- expect(math.approxEqAbs(f32, fma32(1.5, 5.0, 9.124), 16.624, epsilon));
- expect(math.approxEqAbs(f32, fma32(37.45, 5.0, 9.124), 196.374004, epsilon));
- expect(math.approxEqAbs(f32, fma32(89.123, 5.0, 9.124), 454.739005, epsilon));
- expect(math.approxEqAbs(f32, fma32(123123.234375, 5.0, 9.124), 615625.295875, epsilon));
+ try expect(math.approxEqAbs(f32, fma32(0.0, 5.0, 9.124), 9.124, epsilon));
+ try expect(math.approxEqAbs(f32, fma32(0.2, 5.0, 9.124), 10.124, epsilon));
+ try expect(math.approxEqAbs(f32, fma32(0.8923, 5.0, 9.124), 13.5855, epsilon));
+ try expect(math.approxEqAbs(f32, fma32(1.5, 5.0, 9.124), 16.624, epsilon));
+ try expect(math.approxEqAbs(f32, fma32(37.45, 5.0, 9.124), 196.374004, epsilon));
+ try expect(math.approxEqAbs(f32, fma32(89.123, 5.0, 9.124), 454.739005, epsilon));
+ try expect(math.approxEqAbs(f32, fma32(123123.234375, 5.0, 9.124), 615625.295875, epsilon));
}
test "math.fma64" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f64, fma64(0.0, 5.0, 9.124), 9.124, epsilon));
- expect(math.approxEqAbs(f64, fma64(0.2, 5.0, 9.124), 10.124, epsilon));
- expect(math.approxEqAbs(f64, fma64(0.8923, 5.0, 9.124), 13.5855, epsilon));
- expect(math.approxEqAbs(f64, fma64(1.5, 5.0, 9.124), 16.624, epsilon));
- expect(math.approxEqAbs(f64, fma64(37.45, 5.0, 9.124), 196.374, epsilon));
- expect(math.approxEqAbs(f64, fma64(89.123, 5.0, 9.124), 454.739, epsilon));
- expect(math.approxEqAbs(f64, fma64(123123.234375, 5.0, 9.124), 615625.295875, epsilon));
+ try expect(math.approxEqAbs(f64, fma64(0.0, 5.0, 9.124), 9.124, epsilon));
+ try expect(math.approxEqAbs(f64, fma64(0.2, 5.0, 9.124), 10.124, epsilon));
+ try expect(math.approxEqAbs(f64, fma64(0.8923, 5.0, 9.124), 13.5855, epsilon));
+ try expect(math.approxEqAbs(f64, fma64(1.5, 5.0, 9.124), 16.624, epsilon));
+ try expect(math.approxEqAbs(f64, fma64(37.45, 5.0, 9.124), 196.374, epsilon));
+ try expect(math.approxEqAbs(f64, fma64(89.123, 5.0, 9.124), 454.739, epsilon));
+ try expect(math.approxEqAbs(f64, fma64(123123.234375, 5.0, 9.124), 615625.295875, epsilon));
}
lib/std/math/frexp.zig
@@ -115,11 +115,11 @@ fn frexp64(x: f64) frexp64_result {
test "math.frexp" {
const a = frexp(@as(f32, 1.3));
const b = frexp32(1.3);
- expect(a.significand == b.significand and a.exponent == b.exponent);
+ try expect(a.significand == b.significand and a.exponent == b.exponent);
const c = frexp(@as(f64, 1.3));
const d = frexp64(1.3);
- expect(c.significand == d.significand and c.exponent == d.exponent);
+ try expect(c.significand == d.significand and c.exponent == d.exponent);
}
test "math.frexp32" {
@@ -127,10 +127,10 @@ test "math.frexp32" {
var r: frexp32_result = undefined;
r = frexp32(1.3);
- expect(math.approxEqAbs(f32, r.significand, 0.65, epsilon) and r.exponent == 1);
+ try expect(math.approxEqAbs(f32, r.significand, 0.65, epsilon) and r.exponent == 1);
r = frexp32(78.0234);
- expect(math.approxEqAbs(f32, r.significand, 0.609558, epsilon) and r.exponent == 7);
+ try expect(math.approxEqAbs(f32, r.significand, 0.609558, epsilon) and r.exponent == 7);
}
test "math.frexp64" {
@@ -138,46 +138,46 @@ test "math.frexp64" {
var r: frexp64_result = undefined;
r = frexp64(1.3);
- expect(math.approxEqAbs(f64, r.significand, 0.65, epsilon) and r.exponent == 1);
+ try expect(math.approxEqAbs(f64, r.significand, 0.65, epsilon) and r.exponent == 1);
r = frexp64(78.0234);
- expect(math.approxEqAbs(f64, r.significand, 0.609558, epsilon) and r.exponent == 7);
+ try expect(math.approxEqAbs(f64, r.significand, 0.609558, epsilon) and r.exponent == 7);
}
test "math.frexp32.special" {
var r: frexp32_result = undefined;
r = frexp32(0.0);
- expect(r.significand == 0.0 and r.exponent == 0);
+ try expect(r.significand == 0.0 and r.exponent == 0);
r = frexp32(-0.0);
- expect(r.significand == -0.0 and r.exponent == 0);
+ try expect(r.significand == -0.0 and r.exponent == 0);
r = frexp32(math.inf(f32));
- expect(math.isPositiveInf(r.significand) and r.exponent == 0);
+ try expect(math.isPositiveInf(r.significand) and r.exponent == 0);
r = frexp32(-math.inf(f32));
- expect(math.isNegativeInf(r.significand) and r.exponent == 0);
+ try expect(math.isNegativeInf(r.significand) and r.exponent == 0);
r = frexp32(math.nan(f32));
- expect(math.isNan(r.significand));
+ try expect(math.isNan(r.significand));
}
test "math.frexp64.special" {
var r: frexp64_result = undefined;
r = frexp64(0.0);
- expect(r.significand == 0.0 and r.exponent == 0);
+ try expect(r.significand == 0.0 and r.exponent == 0);
r = frexp64(-0.0);
- expect(r.significand == -0.0 and r.exponent == 0);
+ try expect(r.significand == -0.0 and r.exponent == 0);
r = frexp64(math.inf(f64));
- expect(math.isPositiveInf(r.significand) and r.exponent == 0);
+ try expect(math.isPositiveInf(r.significand) and r.exponent == 0);
r = frexp64(-math.inf(f64));
- expect(math.isNegativeInf(r.significand) and r.exponent == 0);
+ try expect(math.isNegativeInf(r.significand) and r.exponent == 0);
r = frexp64(math.nan(f64));
- expect(math.isNan(r.significand));
+ try expect(math.isNan(r.significand));
}
lib/std/math/hypot.zig
@@ -126,48 +126,48 @@ fn hypot64(x: f64, y: f64) f64 {
}
test "math.hypot" {
- expect(hypot(f32, 0.0, -1.2) == hypot32(0.0, -1.2));
- expect(hypot(f64, 0.0, -1.2) == hypot64(0.0, -1.2));
+ try expect(hypot(f32, 0.0, -1.2) == hypot32(0.0, -1.2));
+ try expect(hypot(f64, 0.0, -1.2) == hypot64(0.0, -1.2));
}
test "math.hypot32" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f32, hypot32(0.0, -1.2), 1.2, epsilon));
- expect(math.approxEqAbs(f32, hypot32(0.2, -0.34), 0.394462, epsilon));
- expect(math.approxEqAbs(f32, hypot32(0.8923, 2.636890), 2.783772, epsilon));
- expect(math.approxEqAbs(f32, hypot32(1.5, 5.25), 5.460083, epsilon));
- expect(math.approxEqAbs(f32, hypot32(37.45, 159.835), 164.163742, epsilon));
- expect(math.approxEqAbs(f32, hypot32(89.123, 382.028905), 392.286865, epsilon));
- expect(math.approxEqAbs(f32, hypot32(123123.234375, 529428.707813), 543556.875, epsilon));
+ try expect(math.approxEqAbs(f32, hypot32(0.0, -1.2), 1.2, epsilon));
+ try expect(math.approxEqAbs(f32, hypot32(0.2, -0.34), 0.394462, epsilon));
+ try expect(math.approxEqAbs(f32, hypot32(0.8923, 2.636890), 2.783772, epsilon));
+ try expect(math.approxEqAbs(f32, hypot32(1.5, 5.25), 5.460083, epsilon));
+ try expect(math.approxEqAbs(f32, hypot32(37.45, 159.835), 164.163742, epsilon));
+ try expect(math.approxEqAbs(f32, hypot32(89.123, 382.028905), 392.286865, epsilon));
+ try expect(math.approxEqAbs(f32, hypot32(123123.234375, 529428.707813), 543556.875, epsilon));
}
test "math.hypot64" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f64, hypot64(0.0, -1.2), 1.2, epsilon));
- expect(math.approxEqAbs(f64, hypot64(0.2, -0.34), 0.394462, epsilon));
- expect(math.approxEqAbs(f64, hypot64(0.8923, 2.636890), 2.783772, epsilon));
- expect(math.approxEqAbs(f64, hypot64(1.5, 5.25), 5.460082, epsilon));
- expect(math.approxEqAbs(f64, hypot64(37.45, 159.835), 164.163728, epsilon));
- expect(math.approxEqAbs(f64, hypot64(89.123, 382.028905), 392.286876, epsilon));
- expect(math.approxEqAbs(f64, hypot64(123123.234375, 529428.707813), 543556.885247, epsilon));
+ try expect(math.approxEqAbs(f64, hypot64(0.0, -1.2), 1.2, epsilon));
+ try expect(math.approxEqAbs(f64, hypot64(0.2, -0.34), 0.394462, epsilon));
+ try expect(math.approxEqAbs(f64, hypot64(0.8923, 2.636890), 2.783772, epsilon));
+ try expect(math.approxEqAbs(f64, hypot64(1.5, 5.25), 5.460082, epsilon));
+ try expect(math.approxEqAbs(f64, hypot64(37.45, 159.835), 164.163728, epsilon));
+ try expect(math.approxEqAbs(f64, hypot64(89.123, 382.028905), 392.286876, epsilon));
+ try expect(math.approxEqAbs(f64, hypot64(123123.234375, 529428.707813), 543556.885247, epsilon));
}
test "math.hypot32.special" {
- expect(math.isPositiveInf(hypot32(math.inf(f32), 0.0)));
- expect(math.isPositiveInf(hypot32(-math.inf(f32), 0.0)));
- expect(math.isPositiveInf(hypot32(0.0, math.inf(f32))));
- expect(math.isPositiveInf(hypot32(0.0, -math.inf(f32))));
- expect(math.isNan(hypot32(math.nan(f32), 0.0)));
- expect(math.isNan(hypot32(0.0, math.nan(f32))));
+ try expect(math.isPositiveInf(hypot32(math.inf(f32), 0.0)));
+ try expect(math.isPositiveInf(hypot32(-math.inf(f32), 0.0)));
+ try expect(math.isPositiveInf(hypot32(0.0, math.inf(f32))));
+ try expect(math.isPositiveInf(hypot32(0.0, -math.inf(f32))));
+ try expect(math.isNan(hypot32(math.nan(f32), 0.0)));
+ try expect(math.isNan(hypot32(0.0, math.nan(f32))));
}
test "math.hypot64.special" {
- expect(math.isPositiveInf(hypot64(math.inf(f64), 0.0)));
- expect(math.isPositiveInf(hypot64(-math.inf(f64), 0.0)));
- expect(math.isPositiveInf(hypot64(0.0, math.inf(f64))));
- expect(math.isPositiveInf(hypot64(0.0, -math.inf(f64))));
- expect(math.isNan(hypot64(math.nan(f64), 0.0)));
- expect(math.isNan(hypot64(0.0, math.nan(f64))));
+ try expect(math.isPositiveInf(hypot64(math.inf(f64), 0.0)));
+ try expect(math.isPositiveInf(hypot64(-math.inf(f64), 0.0)));
+ try expect(math.isPositiveInf(hypot64(0.0, math.inf(f64))));
+ try expect(math.isPositiveInf(hypot64(0.0, -math.inf(f64))));
+ try expect(math.isNan(hypot64(math.nan(f64), 0.0)));
+ try expect(math.isNan(hypot64(0.0, math.nan(f64))));
}
lib/std/math/ilogb.zig
@@ -106,38 +106,38 @@ fn ilogb64(x: f64) i32 {
}
test "math.ilogb" {
- expect(ilogb(@as(f32, 0.2)) == ilogb32(0.2));
- expect(ilogb(@as(f64, 0.2)) == ilogb64(0.2));
+ try expect(ilogb(@as(f32, 0.2)) == ilogb32(0.2));
+ try expect(ilogb(@as(f64, 0.2)) == ilogb64(0.2));
}
test "math.ilogb32" {
- expect(ilogb32(0.0) == fp_ilogb0);
- expect(ilogb32(0.5) == -1);
- expect(ilogb32(0.8923) == -1);
- expect(ilogb32(10.0) == 3);
- expect(ilogb32(-123984) == 16);
- expect(ilogb32(2398.23) == 11);
+ try expect(ilogb32(0.0) == fp_ilogb0);
+ try expect(ilogb32(0.5) == -1);
+ try expect(ilogb32(0.8923) == -1);
+ try expect(ilogb32(10.0) == 3);
+ try expect(ilogb32(-123984) == 16);
+ try expect(ilogb32(2398.23) == 11);
}
test "math.ilogb64" {
- expect(ilogb64(0.0) == fp_ilogb0);
- expect(ilogb64(0.5) == -1);
- expect(ilogb64(0.8923) == -1);
- expect(ilogb64(10.0) == 3);
- expect(ilogb64(-123984) == 16);
- expect(ilogb64(2398.23) == 11);
+ try expect(ilogb64(0.0) == fp_ilogb0);
+ try expect(ilogb64(0.5) == -1);
+ try expect(ilogb64(0.8923) == -1);
+ try expect(ilogb64(10.0) == 3);
+ try expect(ilogb64(-123984) == 16);
+ try expect(ilogb64(2398.23) == 11);
}
test "math.ilogb32.special" {
- expect(ilogb32(math.inf(f32)) == maxInt(i32));
- expect(ilogb32(-math.inf(f32)) == maxInt(i32));
- expect(ilogb32(0.0) == minInt(i32));
- expect(ilogb32(math.nan(f32)) == maxInt(i32));
+ try expect(ilogb32(math.inf(f32)) == maxInt(i32));
+ try expect(ilogb32(-math.inf(f32)) == maxInt(i32));
+ try expect(ilogb32(0.0) == minInt(i32));
+ try expect(ilogb32(math.nan(f32)) == maxInt(i32));
}
test "math.ilogb64.special" {
- expect(ilogb64(math.inf(f64)) == maxInt(i32));
- expect(ilogb64(-math.inf(f64)) == maxInt(i32));
- expect(ilogb64(0.0) == minInt(i32));
- expect(ilogb64(math.nan(f64)) == maxInt(i32));
+ try expect(ilogb64(math.inf(f64)) == maxInt(i32));
+ try expect(ilogb64(-math.inf(f64)) == maxInt(i32));
+ try expect(ilogb64(0.0) == minInt(i32));
+ try expect(ilogb64(math.nan(f64)) == maxInt(i32));
}
lib/std/math/isfinite.zig
@@ -35,30 +35,30 @@ pub fn isFinite(x: anytype) bool {
}
test "math.isFinite" {
- expect(isFinite(@as(f16, 0.0)));
- expect(isFinite(@as(f16, -0.0)));
- expect(isFinite(@as(f32, 0.0)));
- expect(isFinite(@as(f32, -0.0)));
- expect(isFinite(@as(f64, 0.0)));
- expect(isFinite(@as(f64, -0.0)));
- expect(isFinite(@as(f128, 0.0)));
- expect(isFinite(@as(f128, -0.0)));
+ try expect(isFinite(@as(f16, 0.0)));
+ try expect(isFinite(@as(f16, -0.0)));
+ try expect(isFinite(@as(f32, 0.0)));
+ try expect(isFinite(@as(f32, -0.0)));
+ try expect(isFinite(@as(f64, 0.0)));
+ try expect(isFinite(@as(f64, -0.0)));
+ try expect(isFinite(@as(f128, 0.0)));
+ try expect(isFinite(@as(f128, -0.0)));
- expect(!isFinite(math.inf(f16)));
- expect(!isFinite(-math.inf(f16)));
- expect(!isFinite(math.inf(f32)));
- expect(!isFinite(-math.inf(f32)));
- expect(!isFinite(math.inf(f64)));
- expect(!isFinite(-math.inf(f64)));
- expect(!isFinite(math.inf(f128)));
- expect(!isFinite(-math.inf(f128)));
+ try expect(!isFinite(math.inf(f16)));
+ try expect(!isFinite(-math.inf(f16)));
+ try expect(!isFinite(math.inf(f32)));
+ try expect(!isFinite(-math.inf(f32)));
+ try expect(!isFinite(math.inf(f64)));
+ try expect(!isFinite(-math.inf(f64)));
+ try expect(!isFinite(math.inf(f128)));
+ try expect(!isFinite(-math.inf(f128)));
- expect(!isFinite(math.nan(f16)));
- expect(!isFinite(-math.nan(f16)));
- expect(!isFinite(math.nan(f32)));
- expect(!isFinite(-math.nan(f32)));
- expect(!isFinite(math.nan(f64)));
- expect(!isFinite(-math.nan(f64)));
- expect(!isFinite(math.nan(f128)));
- expect(!isFinite(-math.nan(f128)));
+ try expect(!isFinite(math.nan(f16)));
+ try expect(!isFinite(-math.nan(f16)));
+ try expect(!isFinite(math.nan(f32)));
+ try expect(!isFinite(-math.nan(f32)));
+ try expect(!isFinite(math.nan(f64)));
+ try expect(!isFinite(-math.nan(f64)));
+ try expect(!isFinite(math.nan(f128)));
+ try expect(!isFinite(-math.nan(f128)));
}
lib/std/math/isinf.zig
@@ -79,58 +79,58 @@ pub fn isNegativeInf(x: anytype) bool {
}
test "math.isInf" {
- expect(!isInf(@as(f16, 0.0)));
- expect(!isInf(@as(f16, -0.0)));
- expect(!isInf(@as(f32, 0.0)));
- expect(!isInf(@as(f32, -0.0)));
- expect(!isInf(@as(f64, 0.0)));
- expect(!isInf(@as(f64, -0.0)));
- expect(!isInf(@as(f128, 0.0)));
- expect(!isInf(@as(f128, -0.0)));
- expect(isInf(math.inf(f16)));
- expect(isInf(-math.inf(f16)));
- expect(isInf(math.inf(f32)));
- expect(isInf(-math.inf(f32)));
- expect(isInf(math.inf(f64)));
- expect(isInf(-math.inf(f64)));
- expect(isInf(math.inf(f128)));
- expect(isInf(-math.inf(f128)));
+ try expect(!isInf(@as(f16, 0.0)));
+ try expect(!isInf(@as(f16, -0.0)));
+ try expect(!isInf(@as(f32, 0.0)));
+ try expect(!isInf(@as(f32, -0.0)));
+ try expect(!isInf(@as(f64, 0.0)));
+ try expect(!isInf(@as(f64, -0.0)));
+ try expect(!isInf(@as(f128, 0.0)));
+ try expect(!isInf(@as(f128, -0.0)));
+ try expect(isInf(math.inf(f16)));
+ try expect(isInf(-math.inf(f16)));
+ try expect(isInf(math.inf(f32)));
+ try expect(isInf(-math.inf(f32)));
+ try expect(isInf(math.inf(f64)));
+ try expect(isInf(-math.inf(f64)));
+ try expect(isInf(math.inf(f128)));
+ try expect(isInf(-math.inf(f128)));
}
test "math.isPositiveInf" {
- expect(!isPositiveInf(@as(f16, 0.0)));
- expect(!isPositiveInf(@as(f16, -0.0)));
- expect(!isPositiveInf(@as(f32, 0.0)));
- expect(!isPositiveInf(@as(f32, -0.0)));
- expect(!isPositiveInf(@as(f64, 0.0)));
- expect(!isPositiveInf(@as(f64, -0.0)));
- expect(!isPositiveInf(@as(f128, 0.0)));
- expect(!isPositiveInf(@as(f128, -0.0)));
- expect(isPositiveInf(math.inf(f16)));
- expect(!isPositiveInf(-math.inf(f16)));
- expect(isPositiveInf(math.inf(f32)));
- expect(!isPositiveInf(-math.inf(f32)));
- expect(isPositiveInf(math.inf(f64)));
- expect(!isPositiveInf(-math.inf(f64)));
- expect(isPositiveInf(math.inf(f128)));
- expect(!isPositiveInf(-math.inf(f128)));
+ try expect(!isPositiveInf(@as(f16, 0.0)));
+ try expect(!isPositiveInf(@as(f16, -0.0)));
+ try expect(!isPositiveInf(@as(f32, 0.0)));
+ try expect(!isPositiveInf(@as(f32, -0.0)));
+ try expect(!isPositiveInf(@as(f64, 0.0)));
+ try expect(!isPositiveInf(@as(f64, -0.0)));
+ try expect(!isPositiveInf(@as(f128, 0.0)));
+ try expect(!isPositiveInf(@as(f128, -0.0)));
+ try expect(isPositiveInf(math.inf(f16)));
+ try expect(!isPositiveInf(-math.inf(f16)));
+ try expect(isPositiveInf(math.inf(f32)));
+ try expect(!isPositiveInf(-math.inf(f32)));
+ try expect(isPositiveInf(math.inf(f64)));
+ try expect(!isPositiveInf(-math.inf(f64)));
+ try expect(isPositiveInf(math.inf(f128)));
+ try expect(!isPositiveInf(-math.inf(f128)));
}
test "math.isNegativeInf" {
- expect(!isNegativeInf(@as(f16, 0.0)));
- expect(!isNegativeInf(@as(f16, -0.0)));
- expect(!isNegativeInf(@as(f32, 0.0)));
- expect(!isNegativeInf(@as(f32, -0.0)));
- expect(!isNegativeInf(@as(f64, 0.0)));
- expect(!isNegativeInf(@as(f64, -0.0)));
- expect(!isNegativeInf(@as(f128, 0.0)));
- expect(!isNegativeInf(@as(f128, -0.0)));
- expect(!isNegativeInf(math.inf(f16)));
- expect(isNegativeInf(-math.inf(f16)));
- expect(!isNegativeInf(math.inf(f32)));
- expect(isNegativeInf(-math.inf(f32)));
- expect(!isNegativeInf(math.inf(f64)));
- expect(isNegativeInf(-math.inf(f64)));
- expect(!isNegativeInf(math.inf(f128)));
- expect(isNegativeInf(-math.inf(f128)));
+ try expect(!isNegativeInf(@as(f16, 0.0)));
+ try expect(!isNegativeInf(@as(f16, -0.0)));
+ try expect(!isNegativeInf(@as(f32, 0.0)));
+ try expect(!isNegativeInf(@as(f32, -0.0)));
+ try expect(!isNegativeInf(@as(f64, 0.0)));
+ try expect(!isNegativeInf(@as(f64, -0.0)));
+ try expect(!isNegativeInf(@as(f128, 0.0)));
+ try expect(!isNegativeInf(@as(f128, -0.0)));
+ try expect(!isNegativeInf(math.inf(f16)));
+ try expect(isNegativeInf(-math.inf(f16)));
+ try expect(!isNegativeInf(math.inf(f32)));
+ try expect(isNegativeInf(-math.inf(f32)));
+ try expect(!isNegativeInf(math.inf(f64)));
+ try expect(isNegativeInf(-math.inf(f64)));
+ try expect(!isNegativeInf(math.inf(f128)));
+ try expect(isNegativeInf(-math.inf(f128)));
}
lib/std/math/isnan.zig
@@ -21,12 +21,12 @@ pub fn isSignalNan(x: anytype) bool {
}
test "math.isNan" {
- expect(isNan(math.nan(f16)));
- expect(isNan(math.nan(f32)));
- expect(isNan(math.nan(f64)));
- expect(isNan(math.nan(f128)));
- expect(!isNan(@as(f16, 1.0)));
- expect(!isNan(@as(f32, 1.0)));
- expect(!isNan(@as(f64, 1.0)));
- expect(!isNan(@as(f128, 1.0)));
+ try expect(isNan(math.nan(f16)));
+ try expect(isNan(math.nan(f32)));
+ try expect(isNan(math.nan(f64)));
+ try expect(isNan(math.nan(f128)));
+ try expect(!isNan(@as(f16, 1.0)));
+ try expect(!isNan(@as(f32, 1.0)));
+ try expect(!isNan(@as(f64, 1.0)));
+ try expect(!isNan(@as(f128, 1.0)));
}
lib/std/math/isnormal.zig
@@ -31,13 +31,13 @@ pub fn isNormal(x: anytype) bool {
}
test "math.isNormal" {
- expect(!isNormal(math.nan(f16)));
- expect(!isNormal(math.nan(f32)));
- expect(!isNormal(math.nan(f64)));
- expect(!isNormal(@as(f16, 0)));
- expect(!isNormal(@as(f32, 0)));
- expect(!isNormal(@as(f64, 0)));
- expect(isNormal(@as(f16, 1.0)));
- expect(isNormal(@as(f32, 1.0)));
- expect(isNormal(@as(f64, 1.0)));
+ try expect(!isNormal(math.nan(f16)));
+ try expect(!isNormal(math.nan(f32)));
+ try expect(!isNormal(math.nan(f64)));
+ try expect(!isNormal(@as(f16, 0)));
+ try expect(!isNormal(@as(f32, 0)));
+ try expect(!isNormal(@as(f64, 0)));
+ try expect(isNormal(@as(f16, 1.0)));
+ try expect(isNormal(@as(f32, 1.0)));
+ try expect(isNormal(@as(f64, 1.0)));
}
lib/std/math/ln.zig
@@ -153,42 +153,42 @@ pub fn ln_64(x_: f64) f64 {
}
test "math.ln" {
- expect(ln(@as(f32, 0.2)) == ln_32(0.2));
- expect(ln(@as(f64, 0.2)) == ln_64(0.2));
+ try expect(ln(@as(f32, 0.2)) == ln_32(0.2));
+ try expect(ln(@as(f64, 0.2)) == ln_64(0.2));
}
test "math.ln32" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f32, ln_32(0.2), -1.609438, epsilon));
- expect(math.approxEqAbs(f32, ln_32(0.8923), -0.113953, epsilon));
- expect(math.approxEqAbs(f32, ln_32(1.5), 0.405465, epsilon));
- expect(math.approxEqAbs(f32, ln_32(37.45), 3.623007, epsilon));
- expect(math.approxEqAbs(f32, ln_32(89.123), 4.490017, epsilon));
- expect(math.approxEqAbs(f32, ln_32(123123.234375), 11.720941, epsilon));
+ try expect(math.approxEqAbs(f32, ln_32(0.2), -1.609438, epsilon));
+ try expect(math.approxEqAbs(f32, ln_32(0.8923), -0.113953, epsilon));
+ try expect(math.approxEqAbs(f32, ln_32(1.5), 0.405465, epsilon));
+ try expect(math.approxEqAbs(f32, ln_32(37.45), 3.623007, epsilon));
+ try expect(math.approxEqAbs(f32, ln_32(89.123), 4.490017, epsilon));
+ try expect(math.approxEqAbs(f32, ln_32(123123.234375), 11.720941, epsilon));
}
test "math.ln64" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f64, ln_64(0.2), -1.609438, epsilon));
- expect(math.approxEqAbs(f64, ln_64(0.8923), -0.113953, epsilon));
- expect(math.approxEqAbs(f64, ln_64(1.5), 0.405465, epsilon));
- expect(math.approxEqAbs(f64, ln_64(37.45), 3.623007, epsilon));
- expect(math.approxEqAbs(f64, ln_64(89.123), 4.490017, epsilon));
- expect(math.approxEqAbs(f64, ln_64(123123.234375), 11.720941, epsilon));
+ try expect(math.approxEqAbs(f64, ln_64(0.2), -1.609438, epsilon));
+ try expect(math.approxEqAbs(f64, ln_64(0.8923), -0.113953, epsilon));
+ try expect(math.approxEqAbs(f64, ln_64(1.5), 0.405465, epsilon));
+ try expect(math.approxEqAbs(f64, ln_64(37.45), 3.623007, epsilon));
+ try expect(math.approxEqAbs(f64, ln_64(89.123), 4.490017, epsilon));
+ try expect(math.approxEqAbs(f64, ln_64(123123.234375), 11.720941, epsilon));
}
test "math.ln32.special" {
- expect(math.isPositiveInf(ln_32(math.inf(f32))));
- expect(math.isNegativeInf(ln_32(0.0)));
- expect(math.isNan(ln_32(-1.0)));
- expect(math.isNan(ln_32(math.nan(f32))));
+ try expect(math.isPositiveInf(ln_32(math.inf(f32))));
+ try expect(math.isNegativeInf(ln_32(0.0)));
+ try expect(math.isNan(ln_32(-1.0)));
+ try expect(math.isNan(ln_32(math.nan(f32))));
}
test "math.ln64.special" {
- expect(math.isPositiveInf(ln_64(math.inf(f64))));
- expect(math.isNegativeInf(ln_64(0.0)));
- expect(math.isNan(ln_64(-1.0)));
- expect(math.isNan(ln_64(math.nan(f64))));
+ try expect(math.isPositiveInf(ln_64(math.inf(f64))));
+ try expect(math.isNegativeInf(ln_64(0.0)));
+ try expect(math.isNan(ln_64(-1.0)));
+ try expect(math.isNan(ln_64(math.nan(f64))));
}
lib/std/math/log.zig
@@ -53,25 +53,25 @@ pub fn log(comptime T: type, base: T, x: T) T {
}
test "math.log integer" {
- expect(log(u8, 2, 0x1) == 0);
- expect(log(u8, 2, 0x2) == 1);
- expect(log(u16, 2, 0x72) == 6);
- expect(log(u32, 2, 0xFFFFFF) == 23);
- expect(log(u64, 2, 0x7FF0123456789ABC) == 62);
+ try expect(log(u8, 2, 0x1) == 0);
+ try expect(log(u8, 2, 0x2) == 1);
+ try expect(log(u16, 2, 0x72) == 6);
+ try expect(log(u32, 2, 0xFFFFFF) == 23);
+ try expect(log(u64, 2, 0x7FF0123456789ABC) == 62);
}
test "math.log float" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f32, log(f32, 6, 0.23947), -0.797723, epsilon));
- expect(math.approxEqAbs(f32, log(f32, 89, 0.23947), -0.318432, epsilon));
- expect(math.approxEqAbs(f64, log(f64, 123897, 12389216414), 1.981724596, epsilon));
+ try expect(math.approxEqAbs(f32, log(f32, 6, 0.23947), -0.797723, epsilon));
+ try expect(math.approxEqAbs(f32, log(f32, 89, 0.23947), -0.318432, epsilon));
+ try expect(math.approxEqAbs(f64, log(f64, 123897, 12389216414), 1.981724596, epsilon));
}
test "math.log float_special" {
- expect(log(f32, 2, 0.2301974) == math.log2(@as(f32, 0.2301974)));
- expect(log(f32, 10, 0.2301974) == math.log10(@as(f32, 0.2301974)));
+ try expect(log(f32, 2, 0.2301974) == math.log2(@as(f32, 0.2301974)));
+ try expect(log(f32, 10, 0.2301974) == math.log10(@as(f32, 0.2301974)));
- expect(log(f64, 2, 213.23019799993) == math.log2(@as(f64, 213.23019799993)));
- expect(log(f64, 10, 213.23019799993) == math.log10(@as(f64, 213.23019799993)));
+ try expect(log(f64, 2, 213.23019799993) == math.log2(@as(f64, 213.23019799993)));
+ try expect(log(f64, 10, 213.23019799993) == math.log10(@as(f64, 213.23019799993)));
}
lib/std/math/log10.zig
@@ -181,42 +181,42 @@ pub fn log10_64(x_: f64) f64 {
}
test "math.log10" {
- testing.expect(log10(@as(f32, 0.2)) == log10_32(0.2));
- testing.expect(log10(@as(f64, 0.2)) == log10_64(0.2));
+ try testing.expect(log10(@as(f32, 0.2)) == log10_32(0.2));
+ try testing.expect(log10(@as(f64, 0.2)) == log10_64(0.2));
}
test "math.log10_32" {
const epsilon = 0.000001;
- testing.expect(math.approxEqAbs(f32, log10_32(0.2), -0.698970, epsilon));
- testing.expect(math.approxEqAbs(f32, log10_32(0.8923), -0.049489, epsilon));
- testing.expect(math.approxEqAbs(f32, log10_32(1.5), 0.176091, epsilon));
- testing.expect(math.approxEqAbs(f32, log10_32(37.45), 1.573452, epsilon));
- testing.expect(math.approxEqAbs(f32, log10_32(89.123), 1.94999, epsilon));
- testing.expect(math.approxEqAbs(f32, log10_32(123123.234375), 5.09034, epsilon));
+ try testing.expect(math.approxEqAbs(f32, log10_32(0.2), -0.698970, epsilon));
+ try testing.expect(math.approxEqAbs(f32, log10_32(0.8923), -0.049489, epsilon));
+ try testing.expect(math.approxEqAbs(f32, log10_32(1.5), 0.176091, epsilon));
+ try testing.expect(math.approxEqAbs(f32, log10_32(37.45), 1.573452, epsilon));
+ try testing.expect(math.approxEqAbs(f32, log10_32(89.123), 1.94999, epsilon));
+ try testing.expect(math.approxEqAbs(f32, log10_32(123123.234375), 5.09034, epsilon));
}
test "math.log10_64" {
const epsilon = 0.000001;
- testing.expect(math.approxEqAbs(f64, log10_64(0.2), -0.698970, epsilon));
- testing.expect(math.approxEqAbs(f64, log10_64(0.8923), -0.049489, epsilon));
- testing.expect(math.approxEqAbs(f64, log10_64(1.5), 0.176091, epsilon));
- testing.expect(math.approxEqAbs(f64, log10_64(37.45), 1.573452, epsilon));
- testing.expect(math.approxEqAbs(f64, log10_64(89.123), 1.94999, epsilon));
- testing.expect(math.approxEqAbs(f64, log10_64(123123.234375), 5.09034, epsilon));
+ try testing.expect(math.approxEqAbs(f64, log10_64(0.2), -0.698970, epsilon));
+ try testing.expect(math.approxEqAbs(f64, log10_64(0.8923), -0.049489, epsilon));
+ try testing.expect(math.approxEqAbs(f64, log10_64(1.5), 0.176091, epsilon));
+ try testing.expect(math.approxEqAbs(f64, log10_64(37.45), 1.573452, epsilon));
+ try testing.expect(math.approxEqAbs(f64, log10_64(89.123), 1.94999, epsilon));
+ try testing.expect(math.approxEqAbs(f64, log10_64(123123.234375), 5.09034, epsilon));
}
test "math.log10_32.special" {
- testing.expect(math.isPositiveInf(log10_32(math.inf(f32))));
- testing.expect(math.isNegativeInf(log10_32(0.0)));
- testing.expect(math.isNan(log10_32(-1.0)));
- testing.expect(math.isNan(log10_32(math.nan(f32))));
+ try testing.expect(math.isPositiveInf(log10_32(math.inf(f32))));
+ try testing.expect(math.isNegativeInf(log10_32(0.0)));
+ try testing.expect(math.isNan(log10_32(-1.0)));
+ try testing.expect(math.isNan(log10_32(math.nan(f32))));
}
test "math.log10_64.special" {
- testing.expect(math.isPositiveInf(log10_64(math.inf(f64))));
- testing.expect(math.isNegativeInf(log10_64(0.0)));
- testing.expect(math.isNan(log10_64(-1.0)));
- testing.expect(math.isNan(log10_64(math.nan(f64))));
+ try testing.expect(math.isPositiveInf(log10_64(math.inf(f64))));
+ try testing.expect(math.isNegativeInf(log10_64(0.0)));
+ try testing.expect(math.isNan(log10_64(-1.0)));
+ try testing.expect(math.isNan(log10_64(math.nan(f64))));
}
lib/std/math/log1p.zig
@@ -188,48 +188,48 @@ fn log1p_64(x: f64) f64 {
}
test "math.log1p" {
- expect(log1p(@as(f32, 0.0)) == log1p_32(0.0));
- expect(log1p(@as(f64, 0.0)) == log1p_64(0.0));
+ try expect(log1p(@as(f32, 0.0)) == log1p_32(0.0));
+ try expect(log1p(@as(f64, 0.0)) == log1p_64(0.0));
}
test "math.log1p_32" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f32, log1p_32(0.0), 0.0, epsilon));
- expect(math.approxEqAbs(f32, log1p_32(0.2), 0.182322, epsilon));
- expect(math.approxEqAbs(f32, log1p_32(0.8923), 0.637793, epsilon));
- expect(math.approxEqAbs(f32, log1p_32(1.5), 0.916291, epsilon));
- expect(math.approxEqAbs(f32, log1p_32(37.45), 3.649359, epsilon));
- expect(math.approxEqAbs(f32, log1p_32(89.123), 4.501175, epsilon));
- expect(math.approxEqAbs(f32, log1p_32(123123.234375), 11.720949, epsilon));
+ try expect(math.approxEqAbs(f32, log1p_32(0.0), 0.0, epsilon));
+ try expect(math.approxEqAbs(f32, log1p_32(0.2), 0.182322, epsilon));
+ try expect(math.approxEqAbs(f32, log1p_32(0.8923), 0.637793, epsilon));
+ try expect(math.approxEqAbs(f32, log1p_32(1.5), 0.916291, epsilon));
+ try expect(math.approxEqAbs(f32, log1p_32(37.45), 3.649359, epsilon));
+ try expect(math.approxEqAbs(f32, log1p_32(89.123), 4.501175, epsilon));
+ try expect(math.approxEqAbs(f32, log1p_32(123123.234375), 11.720949, epsilon));
}
test "math.log1p_64" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f64, log1p_64(0.0), 0.0, epsilon));
- expect(math.approxEqAbs(f64, log1p_64(0.2), 0.182322, epsilon));
- expect(math.approxEqAbs(f64, log1p_64(0.8923), 0.637793, epsilon));
- expect(math.approxEqAbs(f64, log1p_64(1.5), 0.916291, epsilon));
- expect(math.approxEqAbs(f64, log1p_64(37.45), 3.649359, epsilon));
- expect(math.approxEqAbs(f64, log1p_64(89.123), 4.501175, epsilon));
- expect(math.approxEqAbs(f64, log1p_64(123123.234375), 11.720949, epsilon));
+ try expect(math.approxEqAbs(f64, log1p_64(0.0), 0.0, epsilon));
+ try expect(math.approxEqAbs(f64, log1p_64(0.2), 0.182322, epsilon));
+ try expect(math.approxEqAbs(f64, log1p_64(0.8923), 0.637793, epsilon));
+ try expect(math.approxEqAbs(f64, log1p_64(1.5), 0.916291, epsilon));
+ try expect(math.approxEqAbs(f64, log1p_64(37.45), 3.649359, epsilon));
+ try expect(math.approxEqAbs(f64, log1p_64(89.123), 4.501175, epsilon));
+ try expect(math.approxEqAbs(f64, log1p_64(123123.234375), 11.720949, epsilon));
}
test "math.log1p_32.special" {
- expect(math.isPositiveInf(log1p_32(math.inf(f32))));
- expect(log1p_32(0.0) == 0.0);
- expect(log1p_32(-0.0) == -0.0);
- expect(math.isNegativeInf(log1p_32(-1.0)));
- expect(math.isNan(log1p_32(-2.0)));
- expect(math.isNan(log1p_32(math.nan(f32))));
+ try expect(math.isPositiveInf(log1p_32(math.inf(f32))));
+ try expect(log1p_32(0.0) == 0.0);
+ try expect(log1p_32(-0.0) == -0.0);
+ try expect(math.isNegativeInf(log1p_32(-1.0)));
+ try expect(math.isNan(log1p_32(-2.0)));
+ try expect(math.isNan(log1p_32(math.nan(f32))));
}
test "math.log1p_64.special" {
- expect(math.isPositiveInf(log1p_64(math.inf(f64))));
- expect(log1p_64(0.0) == 0.0);
- expect(log1p_64(-0.0) == -0.0);
- expect(math.isNegativeInf(log1p_64(-1.0)));
- expect(math.isNan(log1p_64(-2.0)));
- expect(math.isNan(log1p_64(math.nan(f64))));
+ try expect(math.isPositiveInf(log1p_64(math.inf(f64))));
+ try expect(log1p_64(0.0) == 0.0);
+ try expect(log1p_64(-0.0) == -0.0);
+ try expect(math.isNegativeInf(log1p_64(-1.0)));
+ try expect(math.isNan(log1p_64(-2.0)));
+ try expect(math.isNan(log1p_64(math.nan(f64))));
}
lib/std/math/log2.zig
@@ -179,40 +179,40 @@ pub fn log2_64(x_: f64) f64 {
}
test "math.log2" {
- expect(log2(@as(f32, 0.2)) == log2_32(0.2));
- expect(log2(@as(f64, 0.2)) == log2_64(0.2));
+ try expect(log2(@as(f32, 0.2)) == log2_32(0.2));
+ try expect(log2(@as(f64, 0.2)) == log2_64(0.2));
}
test "math.log2_32" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f32, log2_32(0.2), -2.321928, epsilon));
- expect(math.approxEqAbs(f32, log2_32(0.8923), -0.164399, epsilon));
- expect(math.approxEqAbs(f32, log2_32(1.5), 0.584962, epsilon));
- expect(math.approxEqAbs(f32, log2_32(37.45), 5.226894, epsilon));
- expect(math.approxEqAbs(f32, log2_32(123123.234375), 16.909744, epsilon));
+ try expect(math.approxEqAbs(f32, log2_32(0.2), -2.321928, epsilon));
+ try expect(math.approxEqAbs(f32, log2_32(0.8923), -0.164399, epsilon));
+ try expect(math.approxEqAbs(f32, log2_32(1.5), 0.584962, epsilon));
+ try expect(math.approxEqAbs(f32, log2_32(37.45), 5.226894, epsilon));
+ try expect(math.approxEqAbs(f32, log2_32(123123.234375), 16.909744, epsilon));
}
test "math.log2_64" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f64, log2_64(0.2), -2.321928, epsilon));
- expect(math.approxEqAbs(f64, log2_64(0.8923), -0.164399, epsilon));
- expect(math.approxEqAbs(f64, log2_64(1.5), 0.584962, epsilon));
- expect(math.approxEqAbs(f64, log2_64(37.45), 5.226894, epsilon));
- expect(math.approxEqAbs(f64, log2_64(123123.234375), 16.909744, epsilon));
+ try expect(math.approxEqAbs(f64, log2_64(0.2), -2.321928, epsilon));
+ try expect(math.approxEqAbs(f64, log2_64(0.8923), -0.164399, epsilon));
+ try expect(math.approxEqAbs(f64, log2_64(1.5), 0.584962, epsilon));
+ try expect(math.approxEqAbs(f64, log2_64(37.45), 5.226894, epsilon));
+ try expect(math.approxEqAbs(f64, log2_64(123123.234375), 16.909744, epsilon));
}
test "math.log2_32.special" {
- expect(math.isPositiveInf(log2_32(math.inf(f32))));
- expect(math.isNegativeInf(log2_32(0.0)));
- expect(math.isNan(log2_32(-1.0)));
- expect(math.isNan(log2_32(math.nan(f32))));
+ try expect(math.isPositiveInf(log2_32(math.inf(f32))));
+ try expect(math.isNegativeInf(log2_32(0.0)));
+ try expect(math.isNan(log2_32(-1.0)));
+ try expect(math.isNan(log2_32(math.nan(f32))));
}
test "math.log2_64.special" {
- expect(math.isPositiveInf(log2_64(math.inf(f64))));
- expect(math.isNegativeInf(log2_64(0.0)));
- expect(math.isNan(log2_64(-1.0)));
- expect(math.isNan(log2_64(math.nan(f64))));
+ try expect(math.isPositiveInf(log2_64(math.inf(f64))));
+ try expect(math.isNegativeInf(log2_64(0.0)));
+ try expect(math.isNan(log2_64(-1.0)));
+ try expect(math.isNan(log2_64(math.nan(f64))));
}
lib/std/math/modf.zig
@@ -131,11 +131,11 @@ test "math.modf" {
const a = modf(@as(f32, 1.0));
const b = modf32(1.0);
// NOTE: No struct comparison on generic return type function? non-named, makes sense, but still.
- expect(a.ipart == b.ipart and a.fpart == b.fpart);
+ try expect(a.ipart == b.ipart and a.fpart == b.fpart);
const c = modf(@as(f64, 1.0));
const d = modf64(1.0);
- expect(a.ipart == b.ipart and a.fpart == b.fpart);
+ try expect(a.ipart == b.ipart and a.fpart == b.fpart);
}
test "math.modf32" {
@@ -143,24 +143,24 @@ test "math.modf32" {
var r: modf32_result = undefined;
r = modf32(1.0);
- expect(math.approxEqAbs(f32, r.ipart, 1.0, epsilon));
- expect(math.approxEqAbs(f32, r.fpart, 0.0, epsilon));
+ try expect(math.approxEqAbs(f32, r.ipart, 1.0, epsilon));
+ try expect(math.approxEqAbs(f32, r.fpart, 0.0, epsilon));
r = modf32(2.545);
- expect(math.approxEqAbs(f32, r.ipart, 2.0, epsilon));
- expect(math.approxEqAbs(f32, r.fpart, 0.545, epsilon));
+ try expect(math.approxEqAbs(f32, r.ipart, 2.0, epsilon));
+ try expect(math.approxEqAbs(f32, r.fpart, 0.545, epsilon));
r = modf32(3.978123);
- expect(math.approxEqAbs(f32, r.ipart, 3.0, epsilon));
- expect(math.approxEqAbs(f32, r.fpart, 0.978123, epsilon));
+ try expect(math.approxEqAbs(f32, r.ipart, 3.0, epsilon));
+ try expect(math.approxEqAbs(f32, r.fpart, 0.978123, epsilon));
r = modf32(43874.3);
- expect(math.approxEqAbs(f32, r.ipart, 43874, epsilon));
- expect(math.approxEqAbs(f32, r.fpart, 0.300781, epsilon));
+ try expect(math.approxEqAbs(f32, r.ipart, 43874, epsilon));
+ try expect(math.approxEqAbs(f32, r.fpart, 0.300781, epsilon));
r = modf32(1234.340780);
- expect(math.approxEqAbs(f32, r.ipart, 1234, epsilon));
- expect(math.approxEqAbs(f32, r.fpart, 0.340820, epsilon));
+ try expect(math.approxEqAbs(f32, r.ipart, 1234, epsilon));
+ try expect(math.approxEqAbs(f32, r.fpart, 0.340820, epsilon));
}
test "math.modf64" {
@@ -168,48 +168,48 @@ test "math.modf64" {
var r: modf64_result = undefined;
r = modf64(1.0);
- expect(math.approxEqAbs(f64, r.ipart, 1.0, epsilon));
- expect(math.approxEqAbs(f64, r.fpart, 0.0, epsilon));
+ try expect(math.approxEqAbs(f64, r.ipart, 1.0, epsilon));
+ try expect(math.approxEqAbs(f64, r.fpart, 0.0, epsilon));
r = modf64(2.545);
- expect(math.approxEqAbs(f64, r.ipart, 2.0, epsilon));
- expect(math.approxEqAbs(f64, r.fpart, 0.545, epsilon));
+ try expect(math.approxEqAbs(f64, r.ipart, 2.0, epsilon));
+ try expect(math.approxEqAbs(f64, r.fpart, 0.545, epsilon));
r = modf64(3.978123);
- expect(math.approxEqAbs(f64, r.ipart, 3.0, epsilon));
- expect(math.approxEqAbs(f64, r.fpart, 0.978123, epsilon));
+ try expect(math.approxEqAbs(f64, r.ipart, 3.0, epsilon));
+ try expect(math.approxEqAbs(f64, r.fpart, 0.978123, epsilon));
r = modf64(43874.3);
- expect(math.approxEqAbs(f64, r.ipart, 43874, epsilon));
- expect(math.approxEqAbs(f64, r.fpart, 0.3, epsilon));
+ try expect(math.approxEqAbs(f64, r.ipart, 43874, epsilon));
+ try expect(math.approxEqAbs(f64, r.fpart, 0.3, epsilon));
r = modf64(1234.340780);
- expect(math.approxEqAbs(f64, r.ipart, 1234, epsilon));
- expect(math.approxEqAbs(f64, r.fpart, 0.340780, epsilon));
+ try expect(math.approxEqAbs(f64, r.ipart, 1234, epsilon));
+ try expect(math.approxEqAbs(f64, r.fpart, 0.340780, epsilon));
}
test "math.modf32.special" {
var r: modf32_result = undefined;
r = modf32(math.inf(f32));
- expect(math.isPositiveInf(r.ipart) and math.isNan(r.fpart));
+ try expect(math.isPositiveInf(r.ipart) and math.isNan(r.fpart));
r = modf32(-math.inf(f32));
- expect(math.isNegativeInf(r.ipart) and math.isNan(r.fpart));
+ try expect(math.isNegativeInf(r.ipart) and math.isNan(r.fpart));
r = modf32(math.nan(f32));
- expect(math.isNan(r.ipart) and math.isNan(r.fpart));
+ try expect(math.isNan(r.ipart) and math.isNan(r.fpart));
}
test "math.modf64.special" {
var r: modf64_result = undefined;
r = modf64(math.inf(f64));
- expect(math.isPositiveInf(r.ipart) and math.isNan(r.fpart));
+ try expect(math.isPositiveInf(r.ipart) and math.isNan(r.fpart));
r = modf64(-math.inf(f64));
- expect(math.isNegativeInf(r.ipart) and math.isNan(r.fpart));
+ try expect(math.isNegativeInf(r.ipart) and math.isNan(r.fpart));
r = modf64(math.nan(f64));
- expect(math.isNan(r.ipart) and math.isNan(r.fpart));
+ try expect(math.isNan(r.ipart) and math.isNan(r.fpart));
}
lib/std/math/pow.zig
@@ -191,67 +191,67 @@ fn isOddInteger(x: f64) bool {
test "math.pow" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f32, pow(f32, 0.0, 3.3), 0.0, epsilon));
- expect(math.approxEqAbs(f32, pow(f32, 0.8923, 3.3), 0.686572, epsilon));
- expect(math.approxEqAbs(f32, pow(f32, 0.2, 3.3), 0.004936, epsilon));
- expect(math.approxEqAbs(f32, pow(f32, 1.5, 3.3), 3.811546, epsilon));
- expect(math.approxEqAbs(f32, pow(f32, 37.45, 3.3), 155736.703125, epsilon));
- expect(math.approxEqAbs(f32, pow(f32, 89.123, 3.3), 2722489.5, epsilon));
+ try expect(math.approxEqAbs(f32, pow(f32, 0.0, 3.3), 0.0, epsilon));
+ try expect(math.approxEqAbs(f32, pow(f32, 0.8923, 3.3), 0.686572, epsilon));
+ try expect(math.approxEqAbs(f32, pow(f32, 0.2, 3.3), 0.004936, epsilon));
+ try expect(math.approxEqAbs(f32, pow(f32, 1.5, 3.3), 3.811546, epsilon));
+ try expect(math.approxEqAbs(f32, pow(f32, 37.45, 3.3), 155736.703125, epsilon));
+ try expect(math.approxEqAbs(f32, pow(f32, 89.123, 3.3), 2722489.5, epsilon));
- expect(math.approxEqAbs(f64, pow(f64, 0.0, 3.3), 0.0, epsilon));
- expect(math.approxEqAbs(f64, pow(f64, 0.8923, 3.3), 0.686572, epsilon));
- expect(math.approxEqAbs(f64, pow(f64, 0.2, 3.3), 0.004936, epsilon));
- expect(math.approxEqAbs(f64, pow(f64, 1.5, 3.3), 3.811546, epsilon));
- expect(math.approxEqAbs(f64, pow(f64, 37.45, 3.3), 155736.7160616, epsilon));
- expect(math.approxEqAbs(f64, pow(f64, 89.123, 3.3), 2722490.231436, epsilon));
+ try expect(math.approxEqAbs(f64, pow(f64, 0.0, 3.3), 0.0, epsilon));
+ try expect(math.approxEqAbs(f64, pow(f64, 0.8923, 3.3), 0.686572, epsilon));
+ try expect(math.approxEqAbs(f64, pow(f64, 0.2, 3.3), 0.004936, epsilon));
+ try expect(math.approxEqAbs(f64, pow(f64, 1.5, 3.3), 3.811546, epsilon));
+ try expect(math.approxEqAbs(f64, pow(f64, 37.45, 3.3), 155736.7160616, epsilon));
+ try expect(math.approxEqAbs(f64, pow(f64, 89.123, 3.3), 2722490.231436, epsilon));
}
test "math.pow.special" {
const epsilon = 0.000001;
- expect(pow(f32, 4, 0.0) == 1.0);
- expect(pow(f32, 7, -0.0) == 1.0);
- expect(pow(f32, 45, 1.0) == 45);
- expect(pow(f32, -45, 1.0) == -45);
- expect(math.isNan(pow(f32, math.nan(f32), 5.0)));
- expect(math.isPositiveInf(pow(f32, -math.inf(f32), 0.5)));
- expect(math.isPositiveInf(pow(f32, -0, -0.5)));
- expect(pow(f32, -0, 0.5) == 0);
- expect(math.isNan(pow(f32, 5.0, math.nan(f32))));
- expect(math.isPositiveInf(pow(f32, 0.0, -1.0)));
+ try expect(pow(f32, 4, 0.0) == 1.0);
+ try expect(pow(f32, 7, -0.0) == 1.0);
+ try expect(pow(f32, 45, 1.0) == 45);
+ try expect(pow(f32, -45, 1.0) == -45);
+ try expect(math.isNan(pow(f32, math.nan(f32), 5.0)));
+ try expect(math.isPositiveInf(pow(f32, -math.inf(f32), 0.5)));
+ try expect(math.isPositiveInf(pow(f32, -0, -0.5)));
+ try expect(pow(f32, -0, 0.5) == 0);
+ try expect(math.isNan(pow(f32, 5.0, math.nan(f32))));
+ try expect(math.isPositiveInf(pow(f32, 0.0, -1.0)));
//expect(math.isNegativeInf(pow(f32, -0.0, -3.0))); TODO is this required?
- expect(math.isPositiveInf(pow(f32, 0.0, -math.inf(f32))));
- expect(math.isPositiveInf(pow(f32, -0.0, -math.inf(f32))));
- expect(pow(f32, 0.0, math.inf(f32)) == 0.0);
- expect(pow(f32, -0.0, math.inf(f32)) == 0.0);
- expect(math.isPositiveInf(pow(f32, 0.0, -2.0)));
- expect(math.isPositiveInf(pow(f32, -0.0, -2.0)));
- expect(pow(f32, 0.0, 1.0) == 0.0);
- expect(pow(f32, -0.0, 1.0) == -0.0);
- expect(pow(f32, 0.0, 2.0) == 0.0);
- expect(pow(f32, -0.0, 2.0) == 0.0);
- expect(math.approxEqAbs(f32, pow(f32, -1.0, math.inf(f32)), 1.0, epsilon));
- expect(math.approxEqAbs(f32, pow(f32, -1.0, -math.inf(f32)), 1.0, epsilon));
- expect(math.isPositiveInf(pow(f32, 1.2, math.inf(f32))));
- expect(math.isPositiveInf(pow(f32, -1.2, math.inf(f32))));
- expect(pow(f32, 1.2, -math.inf(f32)) == 0.0);
- expect(pow(f32, -1.2, -math.inf(f32)) == 0.0);
- expect(pow(f32, 0.2, math.inf(f32)) == 0.0);
- expect(pow(f32, -0.2, math.inf(f32)) == 0.0);
- expect(math.isPositiveInf(pow(f32, 0.2, -math.inf(f32))));
- expect(math.isPositiveInf(pow(f32, -0.2, -math.inf(f32))));
- expect(math.isPositiveInf(pow(f32, math.inf(f32), 1.0)));
- expect(pow(f32, math.inf(f32), -1.0) == 0.0);
+ try expect(math.isPositiveInf(pow(f32, 0.0, -math.inf(f32))));
+ try expect(math.isPositiveInf(pow(f32, -0.0, -math.inf(f32))));
+ try expect(pow(f32, 0.0, math.inf(f32)) == 0.0);
+ try expect(pow(f32, -0.0, math.inf(f32)) == 0.0);
+ try expect(math.isPositiveInf(pow(f32, 0.0, -2.0)));
+ try expect(math.isPositiveInf(pow(f32, -0.0, -2.0)));
+ try expect(pow(f32, 0.0, 1.0) == 0.0);
+ try expect(pow(f32, -0.0, 1.0) == -0.0);
+ try expect(pow(f32, 0.0, 2.0) == 0.0);
+ try expect(pow(f32, -0.0, 2.0) == 0.0);
+ try expect(math.approxEqAbs(f32, pow(f32, -1.0, math.inf(f32)), 1.0, epsilon));
+ try expect(math.approxEqAbs(f32, pow(f32, -1.0, -math.inf(f32)), 1.0, epsilon));
+ try expect(math.isPositiveInf(pow(f32, 1.2, math.inf(f32))));
+ try expect(math.isPositiveInf(pow(f32, -1.2, math.inf(f32))));
+ try expect(pow(f32, 1.2, -math.inf(f32)) == 0.0);
+ try expect(pow(f32, -1.2, -math.inf(f32)) == 0.0);
+ try expect(pow(f32, 0.2, math.inf(f32)) == 0.0);
+ try expect(pow(f32, -0.2, math.inf(f32)) == 0.0);
+ try expect(math.isPositiveInf(pow(f32, 0.2, -math.inf(f32))));
+ try expect(math.isPositiveInf(pow(f32, -0.2, -math.inf(f32))));
+ try expect(math.isPositiveInf(pow(f32, math.inf(f32), 1.0)));
+ try expect(pow(f32, math.inf(f32), -1.0) == 0.0);
//expect(pow(f32, -math.inf(f32), 5.0) == pow(f32, -0.0, -5.0)); TODO support negative 0?
- expect(pow(f32, -math.inf(f32), -5.2) == pow(f32, -0.0, 5.2));
- expect(math.isNan(pow(f32, -1.0, 1.2)));
- expect(math.isNan(pow(f32, -12.4, 78.5)));
+ try expect(pow(f32, -math.inf(f32), -5.2) == pow(f32, -0.0, 5.2));
+ try expect(math.isNan(pow(f32, -1.0, 1.2)));
+ try expect(math.isNan(pow(f32, -12.4, 78.5)));
}
test "math.pow.overflow" {
- expect(math.isPositiveInf(pow(f64, 2, 1 << 32)));
- expect(pow(f64, 2, -(1 << 32)) == 0);
- expect(math.isNegativeInf(pow(f64, -2, (1 << 32) + 1)));
- expect(pow(f64, 0.5, 1 << 45) == 0);
- expect(math.isPositiveInf(pow(f64, 0.5, -(1 << 45))));
+ try expect(math.isPositiveInf(pow(f64, 2, 1 << 32)));
+ try expect(pow(f64, 2, -(1 << 32)) == 0);
+ try expect(math.isNegativeInf(pow(f64, -2, (1 << 32) + 1)));
+ try expect(pow(f64, 0.5, 1 << 45) == 0);
+ try expect(math.isPositiveInf(pow(f64, 0.5, -(1 << 45))));
}
lib/std/math/powi.zig
@@ -112,82 +112,82 @@ pub fn powi(comptime T: type, x: T, y: T) (error{
}
test "math.powi" {
- testing.expectError(error.Underflow, powi(i8, -66, 6));
- testing.expectError(error.Underflow, powi(i16, -13, 13));
- testing.expectError(error.Underflow, powi(i32, -32, 21));
- testing.expectError(error.Underflow, powi(i64, -24, 61));
- testing.expectError(error.Underflow, powi(i17, -15, 15));
- testing.expectError(error.Underflow, powi(i42, -6, 40));
-
- testing.expect((try powi(i8, -5, 3)) == -125);
- testing.expect((try powi(i16, -16, 3)) == -4096);
- testing.expect((try powi(i32, -91, 3)) == -753571);
- testing.expect((try powi(i64, -36, 6)) == 2176782336);
- testing.expect((try powi(i17, -2, 15)) == -32768);
- testing.expect((try powi(i42, -5, 7)) == -78125);
-
- testing.expect((try powi(u8, 6, 2)) == 36);
- testing.expect((try powi(u16, 5, 4)) == 625);
- testing.expect((try powi(u32, 12, 6)) == 2985984);
- testing.expect((try powi(u64, 34, 2)) == 1156);
- testing.expect((try powi(u17, 16, 3)) == 4096);
- testing.expect((try powi(u42, 34, 6)) == 1544804416);
-
- testing.expectError(error.Overflow, powi(i8, 120, 7));
- testing.expectError(error.Overflow, powi(i16, 73, 15));
- testing.expectError(error.Overflow, powi(i32, 23, 31));
- testing.expectError(error.Overflow, powi(i64, 68, 61));
- testing.expectError(error.Overflow, powi(i17, 15, 15));
- testing.expectError(error.Overflow, powi(i42, 121312, 41));
-
- testing.expectError(error.Overflow, powi(u8, 123, 7));
- testing.expectError(error.Overflow, powi(u16, 2313, 15));
- testing.expectError(error.Overflow, powi(u32, 8968, 31));
- testing.expectError(error.Overflow, powi(u64, 2342, 63));
- testing.expectError(error.Overflow, powi(u17, 2723, 16));
- testing.expectError(error.Overflow, powi(u42, 8234, 41));
+ try testing.expectError(error.Underflow, powi(i8, -66, 6));
+ try testing.expectError(error.Underflow, powi(i16, -13, 13));
+ try testing.expectError(error.Underflow, powi(i32, -32, 21));
+ try testing.expectError(error.Underflow, powi(i64, -24, 61));
+ try testing.expectError(error.Underflow, powi(i17, -15, 15));
+ try testing.expectError(error.Underflow, powi(i42, -6, 40));
+
+ try testing.expect((try powi(i8, -5, 3)) == -125);
+ try testing.expect((try powi(i16, -16, 3)) == -4096);
+ try testing.expect((try powi(i32, -91, 3)) == -753571);
+ try testing.expect((try powi(i64, -36, 6)) == 2176782336);
+ try testing.expect((try powi(i17, -2, 15)) == -32768);
+ try testing.expect((try powi(i42, -5, 7)) == -78125);
+
+ try testing.expect((try powi(u8, 6, 2)) == 36);
+ try testing.expect((try powi(u16, 5, 4)) == 625);
+ try testing.expect((try powi(u32, 12, 6)) == 2985984);
+ try testing.expect((try powi(u64, 34, 2)) == 1156);
+ try testing.expect((try powi(u17, 16, 3)) == 4096);
+ try testing.expect((try powi(u42, 34, 6)) == 1544804416);
+
+ try testing.expectError(error.Overflow, powi(i8, 120, 7));
+ try testing.expectError(error.Overflow, powi(i16, 73, 15));
+ try testing.expectError(error.Overflow, powi(i32, 23, 31));
+ try testing.expectError(error.Overflow, powi(i64, 68, 61));
+ try testing.expectError(error.Overflow, powi(i17, 15, 15));
+ try testing.expectError(error.Overflow, powi(i42, 121312, 41));
+
+ try testing.expectError(error.Overflow, powi(u8, 123, 7));
+ try testing.expectError(error.Overflow, powi(u16, 2313, 15));
+ try testing.expectError(error.Overflow, powi(u32, 8968, 31));
+ try testing.expectError(error.Overflow, powi(u64, 2342, 63));
+ try testing.expectError(error.Overflow, powi(u17, 2723, 16));
+ try testing.expectError(error.Overflow, powi(u42, 8234, 41));
}
test "math.powi.special" {
- testing.expectError(error.Underflow, powi(i8, -2, 8));
- testing.expectError(error.Underflow, powi(i16, -2, 16));
- testing.expectError(error.Underflow, powi(i32, -2, 32));
- testing.expectError(error.Underflow, powi(i64, -2, 64));
- testing.expectError(error.Underflow, powi(i17, -2, 17));
- testing.expectError(error.Underflow, powi(i42, -2, 42));
-
- testing.expect((try powi(i8, -1, 3)) == -1);
- testing.expect((try powi(i16, -1, 2)) == 1);
- testing.expect((try powi(i32, -1, 16)) == 1);
- testing.expect((try powi(i64, -1, 6)) == 1);
- testing.expect((try powi(i17, -1, 15)) == -1);
- testing.expect((try powi(i42, -1, 7)) == -1);
-
- testing.expect((try powi(u8, 1, 2)) == 1);
- testing.expect((try powi(u16, 1, 4)) == 1);
- testing.expect((try powi(u32, 1, 6)) == 1);
- testing.expect((try powi(u64, 1, 2)) == 1);
- testing.expect((try powi(u17, 1, 3)) == 1);
- testing.expect((try powi(u42, 1, 6)) == 1);
-
- testing.expectError(error.Overflow, powi(i8, 2, 7));
- testing.expectError(error.Overflow, powi(i16, 2, 15));
- testing.expectError(error.Overflow, powi(i32, 2, 31));
- testing.expectError(error.Overflow, powi(i64, 2, 63));
- testing.expectError(error.Overflow, powi(i17, 2, 16));
- testing.expectError(error.Overflow, powi(i42, 2, 41));
-
- testing.expectError(error.Overflow, powi(u8, 2, 8));
- testing.expectError(error.Overflow, powi(u16, 2, 16));
- testing.expectError(error.Overflow, powi(u32, 2, 32));
- testing.expectError(error.Overflow, powi(u64, 2, 64));
- testing.expectError(error.Overflow, powi(u17, 2, 17));
- testing.expectError(error.Overflow, powi(u42, 2, 42));
-
- testing.expect((try powi(u8, 6, 0)) == 1);
- testing.expect((try powi(u16, 5, 0)) == 1);
- testing.expect((try powi(u32, 12, 0)) == 1);
- testing.expect((try powi(u64, 34, 0)) == 1);
- testing.expect((try powi(u17, 16, 0)) == 1);
- testing.expect((try powi(u42, 34, 0)) == 1);
+ try testing.expectError(error.Underflow, powi(i8, -2, 8));
+ try testing.expectError(error.Underflow, powi(i16, -2, 16));
+ try testing.expectError(error.Underflow, powi(i32, -2, 32));
+ try testing.expectError(error.Underflow, powi(i64, -2, 64));
+ try testing.expectError(error.Underflow, powi(i17, -2, 17));
+ try testing.expectError(error.Underflow, powi(i42, -2, 42));
+
+ try testing.expect((try powi(i8, -1, 3)) == -1);
+ try testing.expect((try powi(i16, -1, 2)) == 1);
+ try testing.expect((try powi(i32, -1, 16)) == 1);
+ try testing.expect((try powi(i64, -1, 6)) == 1);
+ try testing.expect((try powi(i17, -1, 15)) == -1);
+ try testing.expect((try powi(i42, -1, 7)) == -1);
+
+ try testing.expect((try powi(u8, 1, 2)) == 1);
+ try testing.expect((try powi(u16, 1, 4)) == 1);
+ try testing.expect((try powi(u32, 1, 6)) == 1);
+ try testing.expect((try powi(u64, 1, 2)) == 1);
+ try testing.expect((try powi(u17, 1, 3)) == 1);
+ try testing.expect((try powi(u42, 1, 6)) == 1);
+
+ try testing.expectError(error.Overflow, powi(i8, 2, 7));
+ try testing.expectError(error.Overflow, powi(i16, 2, 15));
+ try testing.expectError(error.Overflow, powi(i32, 2, 31));
+ try testing.expectError(error.Overflow, powi(i64, 2, 63));
+ try testing.expectError(error.Overflow, powi(i17, 2, 16));
+ try testing.expectError(error.Overflow, powi(i42, 2, 41));
+
+ try testing.expectError(error.Overflow, powi(u8, 2, 8));
+ try testing.expectError(error.Overflow, powi(u16, 2, 16));
+ try testing.expectError(error.Overflow, powi(u32, 2, 32));
+ try testing.expectError(error.Overflow, powi(u64, 2, 64));
+ try testing.expectError(error.Overflow, powi(u17, 2, 17));
+ try testing.expectError(error.Overflow, powi(u42, 2, 42));
+
+ try testing.expect((try powi(u8, 6, 0)) == 1);
+ try testing.expect((try powi(u16, 5, 0)) == 1);
+ try testing.expect((try powi(u32, 12, 0)) == 1);
+ try testing.expect((try powi(u64, 34, 0)) == 1);
+ try testing.expect((try powi(u17, 16, 0)) == 1);
+ try testing.expect((try powi(u42, 34, 0)) == 1);
}
lib/std/math/round.zig
@@ -130,52 +130,52 @@ fn round128(x_: f128) f128 {
}
test "math.round" {
- expect(round(@as(f32, 1.3)) == round32(1.3));
- expect(round(@as(f64, 1.3)) == round64(1.3));
- expect(round(@as(f128, 1.3)) == round128(1.3));
+ try expect(round(@as(f32, 1.3)) == round32(1.3));
+ try expect(round(@as(f64, 1.3)) == round64(1.3));
+ try expect(round(@as(f128, 1.3)) == round128(1.3));
}
test "math.round32" {
- expect(round32(1.3) == 1.0);
- expect(round32(-1.3) == -1.0);
- expect(round32(0.2) == 0.0);
- expect(round32(1.8) == 2.0);
+ try expect(round32(1.3) == 1.0);
+ try expect(round32(-1.3) == -1.0);
+ try expect(round32(0.2) == 0.0);
+ try expect(round32(1.8) == 2.0);
}
test "math.round64" {
- expect(round64(1.3) == 1.0);
- expect(round64(-1.3) == -1.0);
- expect(round64(0.2) == 0.0);
- expect(round64(1.8) == 2.0);
+ try expect(round64(1.3) == 1.0);
+ try expect(round64(-1.3) == -1.0);
+ try expect(round64(0.2) == 0.0);
+ try expect(round64(1.8) == 2.0);
}
test "math.round128" {
- expect(round128(1.3) == 1.0);
- expect(round128(-1.3) == -1.0);
- expect(round128(0.2) == 0.0);
- expect(round128(1.8) == 2.0);
+ try expect(round128(1.3) == 1.0);
+ try expect(round128(-1.3) == -1.0);
+ try expect(round128(0.2) == 0.0);
+ try expect(round128(1.8) == 2.0);
}
test "math.round32.special" {
- expect(round32(0.0) == 0.0);
- expect(round32(-0.0) == -0.0);
- expect(math.isPositiveInf(round32(math.inf(f32))));
- expect(math.isNegativeInf(round32(-math.inf(f32))));
- expect(math.isNan(round32(math.nan(f32))));
+ try expect(round32(0.0) == 0.0);
+ try expect(round32(-0.0) == -0.0);
+ try expect(math.isPositiveInf(round32(math.inf(f32))));
+ try expect(math.isNegativeInf(round32(-math.inf(f32))));
+ try expect(math.isNan(round32(math.nan(f32))));
}
test "math.round64.special" {
- expect(round64(0.0) == 0.0);
- expect(round64(-0.0) == -0.0);
- expect(math.isPositiveInf(round64(math.inf(f64))));
- expect(math.isNegativeInf(round64(-math.inf(f64))));
- expect(math.isNan(round64(math.nan(f64))));
+ try expect(round64(0.0) == 0.0);
+ try expect(round64(-0.0) == -0.0);
+ try expect(math.isPositiveInf(round64(math.inf(f64))));
+ try expect(math.isNegativeInf(round64(-math.inf(f64))));
+ try expect(math.isNan(round64(math.nan(f64))));
}
test "math.round128.special" {
- expect(round128(0.0) == 0.0);
- expect(round128(-0.0) == -0.0);
- expect(math.isPositiveInf(round128(math.inf(f128))));
- expect(math.isNegativeInf(round128(-math.inf(f128))));
- expect(math.isNan(round128(math.nan(f128))));
+ try expect(round128(0.0) == 0.0);
+ try expect(round128(-0.0) == -0.0);
+ try expect(math.isPositiveInf(round128(math.inf(f128))));
+ try expect(math.isNegativeInf(round128(-math.inf(f128))));
+ try expect(math.isNan(round128(math.nan(f128))));
}
lib/std/math/scalbn.zig
@@ -84,14 +84,14 @@ fn scalbn64(x: f64, n_: i32) f64 {
}
test "math.scalbn" {
- expect(scalbn(@as(f32, 1.5), 4) == scalbn32(1.5, 4));
- expect(scalbn(@as(f64, 1.5), 4) == scalbn64(1.5, 4));
+ try expect(scalbn(@as(f32, 1.5), 4) == scalbn32(1.5, 4));
+ try expect(scalbn(@as(f64, 1.5), 4) == scalbn64(1.5, 4));
}
test "math.scalbn32" {
- expect(scalbn32(1.5, 4) == 24.0);
+ try expect(scalbn32(1.5, 4) == 24.0);
}
test "math.scalbn64" {
- expect(scalbn64(1.5, 4) == 24.0);
+ try expect(scalbn64(1.5, 4) == 24.0);
}
lib/std/math/signbit.zig
@@ -40,28 +40,28 @@ fn signbit128(x: f128) bool {
}
test "math.signbit" {
- expect(signbit(@as(f16, 4.0)) == signbit16(4.0));
- expect(signbit(@as(f32, 4.0)) == signbit32(4.0));
- expect(signbit(@as(f64, 4.0)) == signbit64(4.0));
- expect(signbit(@as(f128, 4.0)) == signbit128(4.0));
+ try expect(signbit(@as(f16, 4.0)) == signbit16(4.0));
+ try expect(signbit(@as(f32, 4.0)) == signbit32(4.0));
+ try expect(signbit(@as(f64, 4.0)) == signbit64(4.0));
+ try expect(signbit(@as(f128, 4.0)) == signbit128(4.0));
}
test "math.signbit16" {
- expect(!signbit16(4.0));
- expect(signbit16(-3.0));
+ try expect(!signbit16(4.0));
+ try expect(signbit16(-3.0));
}
test "math.signbit32" {
- expect(!signbit32(4.0));
- expect(signbit32(-3.0));
+ try expect(!signbit32(4.0));
+ try expect(signbit32(-3.0));
}
test "math.signbit64" {
- expect(!signbit64(4.0));
- expect(signbit64(-3.0));
+ try expect(!signbit64(4.0));
+ try expect(signbit64(-3.0));
}
test "math.signbit128" {
- expect(!signbit128(4.0));
- expect(signbit128(-3.0));
+ try expect(!signbit128(4.0));
+ try expect(signbit128(-3.0));
}
lib/std/math/sin.zig
@@ -89,47 +89,47 @@ fn sin_(comptime T: type, x_: T) T {
}
test "math.sin" {
- expect(sin(@as(f32, 0.0)) == sin_(f32, 0.0));
- expect(sin(@as(f64, 0.0)) == sin_(f64, 0.0));
- expect(comptime (math.sin(@as(f64, 2))) == math.sin(@as(f64, 2)));
+ try expect(sin(@as(f32, 0.0)) == sin_(f32, 0.0));
+ try expect(sin(@as(f64, 0.0)) == sin_(f64, 0.0));
+ try expect(comptime (math.sin(@as(f64, 2))) == math.sin(@as(f64, 2)));
}
test "math.sin32" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f32, sin_(f32, 0.0), 0.0, epsilon));
- expect(math.approxEqAbs(f32, sin_(f32, 0.2), 0.198669, epsilon));
- expect(math.approxEqAbs(f32, sin_(f32, 0.8923), 0.778517, epsilon));
- expect(math.approxEqAbs(f32, sin_(f32, 1.5), 0.997495, epsilon));
- expect(math.approxEqAbs(f32, sin_(f32, -1.5), -0.997495, epsilon));
- expect(math.approxEqAbs(f32, sin_(f32, 37.45), -0.246544, epsilon));
- expect(math.approxEqAbs(f32, sin_(f32, 89.123), 0.916166, epsilon));
+ try expect(math.approxEqAbs(f32, sin_(f32, 0.0), 0.0, epsilon));
+ try expect(math.approxEqAbs(f32, sin_(f32, 0.2), 0.198669, epsilon));
+ try expect(math.approxEqAbs(f32, sin_(f32, 0.8923), 0.778517, epsilon));
+ try expect(math.approxEqAbs(f32, sin_(f32, 1.5), 0.997495, epsilon));
+ try expect(math.approxEqAbs(f32, sin_(f32, -1.5), -0.997495, epsilon));
+ try expect(math.approxEqAbs(f32, sin_(f32, 37.45), -0.246544, epsilon));
+ try expect(math.approxEqAbs(f32, sin_(f32, 89.123), 0.916166, epsilon));
}
test "math.sin64" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f64, sin_(f64, 0.0), 0.0, epsilon));
- expect(math.approxEqAbs(f64, sin_(f64, 0.2), 0.198669, epsilon));
- expect(math.approxEqAbs(f64, sin_(f64, 0.8923), 0.778517, epsilon));
- expect(math.approxEqAbs(f64, sin_(f64, 1.5), 0.997495, epsilon));
- expect(math.approxEqAbs(f64, sin_(f64, -1.5), -0.997495, epsilon));
- expect(math.approxEqAbs(f64, sin_(f64, 37.45), -0.246543, epsilon));
- expect(math.approxEqAbs(f64, sin_(f64, 89.123), 0.916166, epsilon));
+ try expect(math.approxEqAbs(f64, sin_(f64, 0.0), 0.0, epsilon));
+ try expect(math.approxEqAbs(f64, sin_(f64, 0.2), 0.198669, epsilon));
+ try expect(math.approxEqAbs(f64, sin_(f64, 0.8923), 0.778517, epsilon));
+ try expect(math.approxEqAbs(f64, sin_(f64, 1.5), 0.997495, epsilon));
+ try expect(math.approxEqAbs(f64, sin_(f64, -1.5), -0.997495, epsilon));
+ try expect(math.approxEqAbs(f64, sin_(f64, 37.45), -0.246543, epsilon));
+ try expect(math.approxEqAbs(f64, sin_(f64, 89.123), 0.916166, epsilon));
}
test "math.sin32.special" {
- expect(sin_(f32, 0.0) == 0.0);
- expect(sin_(f32, -0.0) == -0.0);
- expect(math.isNan(sin_(f32, math.inf(f32))));
- expect(math.isNan(sin_(f32, -math.inf(f32))));
- expect(math.isNan(sin_(f32, math.nan(f32))));
+ try expect(sin_(f32, 0.0) == 0.0);
+ try expect(sin_(f32, -0.0) == -0.0);
+ try expect(math.isNan(sin_(f32, math.inf(f32))));
+ try expect(math.isNan(sin_(f32, -math.inf(f32))));
+ try expect(math.isNan(sin_(f32, math.nan(f32))));
}
test "math.sin64.special" {
- expect(sin_(f64, 0.0) == 0.0);
- expect(sin_(f64, -0.0) == -0.0);
- expect(math.isNan(sin_(f64, math.inf(f64))));
- expect(math.isNan(sin_(f64, -math.inf(f64))));
- expect(math.isNan(sin_(f64, math.nan(f64))));
+ try expect(sin_(f64, 0.0) == 0.0);
+ try expect(sin_(f64, -0.0) == -0.0);
+ try expect(math.isNan(sin_(f64, math.inf(f64))));
+ try expect(math.isNan(sin_(f64, -math.inf(f64))));
+ try expect(math.isNan(sin_(f64, math.nan(f64))));
}
lib/std/math/sinh.zig
@@ -98,48 +98,48 @@ fn sinh64(x: f64) f64 {
}
test "math.sinh" {
- expect(sinh(@as(f32, 1.5)) == sinh32(1.5));
- expect(sinh(@as(f64, 1.5)) == sinh64(1.5));
+ try expect(sinh(@as(f32, 1.5)) == sinh32(1.5));
+ try expect(sinh(@as(f64, 1.5)) == sinh64(1.5));
}
test "math.sinh32" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f32, sinh32(0.0), 0.0, epsilon));
- expect(math.approxEqAbs(f32, sinh32(0.2), 0.201336, epsilon));
- expect(math.approxEqAbs(f32, sinh32(0.8923), 1.015512, epsilon));
- expect(math.approxEqAbs(f32, sinh32(1.5), 2.129279, epsilon));
- expect(math.approxEqAbs(f32, sinh32(-0.0), -0.0, epsilon));
- expect(math.approxEqAbs(f32, sinh32(-0.2), -0.201336, epsilon));
- expect(math.approxEqAbs(f32, sinh32(-0.8923), -1.015512, epsilon));
- expect(math.approxEqAbs(f32, sinh32(-1.5), -2.129279, epsilon));
+ try expect(math.approxEqAbs(f32, sinh32(0.0), 0.0, epsilon));
+ try expect(math.approxEqAbs(f32, sinh32(0.2), 0.201336, epsilon));
+ try expect(math.approxEqAbs(f32, sinh32(0.8923), 1.015512, epsilon));
+ try expect(math.approxEqAbs(f32, sinh32(1.5), 2.129279, epsilon));
+ try expect(math.approxEqAbs(f32, sinh32(-0.0), -0.0, epsilon));
+ try expect(math.approxEqAbs(f32, sinh32(-0.2), -0.201336, epsilon));
+ try expect(math.approxEqAbs(f32, sinh32(-0.8923), -1.015512, epsilon));
+ try expect(math.approxEqAbs(f32, sinh32(-1.5), -2.129279, epsilon));
}
test "math.sinh64" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f64, sinh64(0.0), 0.0, epsilon));
- expect(math.approxEqAbs(f64, sinh64(0.2), 0.201336, epsilon));
- expect(math.approxEqAbs(f64, sinh64(0.8923), 1.015512, epsilon));
- expect(math.approxEqAbs(f64, sinh64(1.5), 2.129279, epsilon));
- expect(math.approxEqAbs(f64, sinh64(-0.0), -0.0, epsilon));
- expect(math.approxEqAbs(f64, sinh64(-0.2), -0.201336, epsilon));
- expect(math.approxEqAbs(f64, sinh64(-0.8923), -1.015512, epsilon));
- expect(math.approxEqAbs(f64, sinh64(-1.5), -2.129279, epsilon));
+ try expect(math.approxEqAbs(f64, sinh64(0.0), 0.0, epsilon));
+ try expect(math.approxEqAbs(f64, sinh64(0.2), 0.201336, epsilon));
+ try expect(math.approxEqAbs(f64, sinh64(0.8923), 1.015512, epsilon));
+ try expect(math.approxEqAbs(f64, sinh64(1.5), 2.129279, epsilon));
+ try expect(math.approxEqAbs(f64, sinh64(-0.0), -0.0, epsilon));
+ try expect(math.approxEqAbs(f64, sinh64(-0.2), -0.201336, epsilon));
+ try expect(math.approxEqAbs(f64, sinh64(-0.8923), -1.015512, epsilon));
+ try expect(math.approxEqAbs(f64, sinh64(-1.5), -2.129279, epsilon));
}
test "math.sinh32.special" {
- expect(sinh32(0.0) == 0.0);
- expect(sinh32(-0.0) == -0.0);
- expect(math.isPositiveInf(sinh32(math.inf(f32))));
- expect(math.isNegativeInf(sinh32(-math.inf(f32))));
- expect(math.isNan(sinh32(math.nan(f32))));
+ try expect(sinh32(0.0) == 0.0);
+ try expect(sinh32(-0.0) == -0.0);
+ try expect(math.isPositiveInf(sinh32(math.inf(f32))));
+ try expect(math.isNegativeInf(sinh32(-math.inf(f32))));
+ try expect(math.isNan(sinh32(math.nan(f32))));
}
test "math.sinh64.special" {
- expect(sinh64(0.0) == 0.0);
- expect(sinh64(-0.0) == -0.0);
- expect(math.isPositiveInf(sinh64(math.inf(f64))));
- expect(math.isNegativeInf(sinh64(-math.inf(f64))));
- expect(math.isNan(sinh64(math.nan(f64))));
+ try expect(sinh64(0.0) == 0.0);
+ try expect(sinh64(-0.0) == -0.0);
+ try expect(math.isPositiveInf(sinh64(math.inf(f64))));
+ try expect(math.isNegativeInf(sinh64(-math.inf(f64))));
+ try expect(math.isNan(sinh64(math.nan(f64))));
}
lib/std/math/sqrt.zig
@@ -69,14 +69,14 @@ fn sqrt_int(comptime T: type, value: T) Sqrt(T) {
}
test "math.sqrt_int" {
- expect(sqrt_int(u0, 0) == 0);
- expect(sqrt_int(u1, 1) == 1);
- expect(sqrt_int(u32, 3) == 1);
- expect(sqrt_int(u32, 4) == 2);
- expect(sqrt_int(u32, 5) == 2);
- expect(sqrt_int(u32, 8) == 2);
- expect(sqrt_int(u32, 9) == 3);
- expect(sqrt_int(u32, 10) == 3);
+ try expect(sqrt_int(u0, 0) == 0);
+ try expect(sqrt_int(u1, 1) == 1);
+ try expect(sqrt_int(u32, 3) == 1);
+ try expect(sqrt_int(u32, 4) == 2);
+ try expect(sqrt_int(u32, 5) == 2);
+ try expect(sqrt_int(u32, 8) == 2);
+ try expect(sqrt_int(u32, 9) == 3);
+ try expect(sqrt_int(u32, 10) == 3);
}
/// Returns the return type `sqrt` will return given an operand of type `T`.
lib/std/math/tan.zig
@@ -80,44 +80,44 @@ fn tan_(comptime T: type, x_: T) T {
}
test "math.tan" {
- expect(tan(@as(f32, 0.0)) == tan_(f32, 0.0));
- expect(tan(@as(f64, 0.0)) == tan_(f64, 0.0));
+ try expect(tan(@as(f32, 0.0)) == tan_(f32, 0.0));
+ try expect(tan(@as(f64, 0.0)) == tan_(f64, 0.0));
}
test "math.tan32" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f32, tan_(f32, 0.0), 0.0, epsilon));
- expect(math.approxEqAbs(f32, tan_(f32, 0.2), 0.202710, epsilon));
- expect(math.approxEqAbs(f32, tan_(f32, 0.8923), 1.240422, epsilon));
- expect(math.approxEqAbs(f32, tan_(f32, 1.5), 14.101420, epsilon));
- expect(math.approxEqAbs(f32, tan_(f32, 37.45), -0.254397, epsilon));
- expect(math.approxEqAbs(f32, tan_(f32, 89.123), 2.285852, epsilon));
+ try expect(math.approxEqAbs(f32, tan_(f32, 0.0), 0.0, epsilon));
+ try expect(math.approxEqAbs(f32, tan_(f32, 0.2), 0.202710, epsilon));
+ try expect(math.approxEqAbs(f32, tan_(f32, 0.8923), 1.240422, epsilon));
+ try expect(math.approxEqAbs(f32, tan_(f32, 1.5), 14.101420, epsilon));
+ try expect(math.approxEqAbs(f32, tan_(f32, 37.45), -0.254397, epsilon));
+ try expect(math.approxEqAbs(f32, tan_(f32, 89.123), 2.285852, epsilon));
}
test "math.tan64" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f64, tan_(f64, 0.0), 0.0, epsilon));
- expect(math.approxEqAbs(f64, tan_(f64, 0.2), 0.202710, epsilon));
- expect(math.approxEqAbs(f64, tan_(f64, 0.8923), 1.240422, epsilon));
- expect(math.approxEqAbs(f64, tan_(f64, 1.5), 14.101420, epsilon));
- expect(math.approxEqAbs(f64, tan_(f64, 37.45), -0.254397, epsilon));
- expect(math.approxEqAbs(f64, tan_(f64, 89.123), 2.2858376, epsilon));
+ try expect(math.approxEqAbs(f64, tan_(f64, 0.0), 0.0, epsilon));
+ try expect(math.approxEqAbs(f64, tan_(f64, 0.2), 0.202710, epsilon));
+ try expect(math.approxEqAbs(f64, tan_(f64, 0.8923), 1.240422, epsilon));
+ try expect(math.approxEqAbs(f64, tan_(f64, 1.5), 14.101420, epsilon));
+ try expect(math.approxEqAbs(f64, tan_(f64, 37.45), -0.254397, epsilon));
+ try expect(math.approxEqAbs(f64, tan_(f64, 89.123), 2.2858376, epsilon));
}
test "math.tan32.special" {
- expect(tan_(f32, 0.0) == 0.0);
- expect(tan_(f32, -0.0) == -0.0);
- expect(math.isNan(tan_(f32, math.inf(f32))));
- expect(math.isNan(tan_(f32, -math.inf(f32))));
- expect(math.isNan(tan_(f32, math.nan(f32))));
+ try expect(tan_(f32, 0.0) == 0.0);
+ try expect(tan_(f32, -0.0) == -0.0);
+ try expect(math.isNan(tan_(f32, math.inf(f32))));
+ try expect(math.isNan(tan_(f32, -math.inf(f32))));
+ try expect(math.isNan(tan_(f32, math.nan(f32))));
}
test "math.tan64.special" {
- expect(tan_(f64, 0.0) == 0.0);
- expect(tan_(f64, -0.0) == -0.0);
- expect(math.isNan(tan_(f64, math.inf(f64))));
- expect(math.isNan(tan_(f64, -math.inf(f64))));
- expect(math.isNan(tan_(f64, math.nan(f64))));
+ try expect(tan_(f64, 0.0) == 0.0);
+ try expect(tan_(f64, -0.0) == -0.0);
+ try expect(math.isNan(tan_(f64, math.inf(f64))));
+ try expect(math.isNan(tan_(f64, -math.inf(f64))));
+ try expect(math.isNan(tan_(f64, math.nan(f64))));
}
lib/std/math/tanh.zig
@@ -124,42 +124,42 @@ fn tanh64(x: f64) f64 {
}
test "math.tanh" {
- expect(tanh(@as(f32, 1.5)) == tanh32(1.5));
- expect(tanh(@as(f64, 1.5)) == tanh64(1.5));
+ try expect(tanh(@as(f32, 1.5)) == tanh32(1.5));
+ try expect(tanh(@as(f64, 1.5)) == tanh64(1.5));
}
test "math.tanh32" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f32, tanh32(0.0), 0.0, epsilon));
- expect(math.approxEqAbs(f32, tanh32(0.2), 0.197375, epsilon));
- expect(math.approxEqAbs(f32, tanh32(0.8923), 0.712528, epsilon));
- expect(math.approxEqAbs(f32, tanh32(1.5), 0.905148, epsilon));
- expect(math.approxEqAbs(f32, tanh32(37.45), 1.0, epsilon));
+ try expect(math.approxEqAbs(f32, tanh32(0.0), 0.0, epsilon));
+ try expect(math.approxEqAbs(f32, tanh32(0.2), 0.197375, epsilon));
+ try expect(math.approxEqAbs(f32, tanh32(0.8923), 0.712528, epsilon));
+ try expect(math.approxEqAbs(f32, tanh32(1.5), 0.905148, epsilon));
+ try expect(math.approxEqAbs(f32, tanh32(37.45), 1.0, epsilon));
}
test "math.tanh64" {
const epsilon = 0.000001;
- expect(math.approxEqAbs(f64, tanh64(0.0), 0.0, epsilon));
- expect(math.approxEqAbs(f64, tanh64(0.2), 0.197375, epsilon));
- expect(math.approxEqAbs(f64, tanh64(0.8923), 0.712528, epsilon));
- expect(math.approxEqAbs(f64, tanh64(1.5), 0.905148, epsilon));
- expect(math.approxEqAbs(f64, tanh64(37.45), 1.0, epsilon));
+ try expect(math.approxEqAbs(f64, tanh64(0.0), 0.0, epsilon));
+ try expect(math.approxEqAbs(f64, tanh64(0.2), 0.197375, epsilon));
+ try expect(math.approxEqAbs(f64, tanh64(0.8923), 0.712528, epsilon));
+ try expect(math.approxEqAbs(f64, tanh64(1.5), 0.905148, epsilon));
+ try expect(math.approxEqAbs(f64, tanh64(37.45), 1.0, epsilon));
}
test "math.tanh32.special" {
- expect(tanh32(0.0) == 0.0);
- expect(tanh32(-0.0) == -0.0);
- expect(tanh32(math.inf(f32)) == 1.0);
- expect(tanh32(-math.inf(f32)) == -1.0);
- expect(math.isNan(tanh32(math.nan(f32))));
+ try expect(tanh32(0.0) == 0.0);
+ try expect(tanh32(-0.0) == -0.0);
+ try expect(tanh32(math.inf(f32)) == 1.0);
+ try expect(tanh32(-math.inf(f32)) == -1.0);
+ try expect(math.isNan(tanh32(math.nan(f32))));
}
test "math.tanh64.special" {
- expect(tanh64(0.0) == 0.0);
- expect(tanh64(-0.0) == -0.0);
- expect(tanh64(math.inf(f64)) == 1.0);
- expect(tanh64(-math.inf(f64)) == -1.0);
- expect(math.isNan(tanh64(math.nan(f64))));
+ try expect(tanh64(0.0) == 0.0);
+ try expect(tanh64(-0.0) == -0.0);
+ try expect(tanh64(math.inf(f64)) == 1.0);
+ try expect(tanh64(-math.inf(f64)) == -1.0);
+ try expect(math.isNan(tanh64(math.nan(f64))));
}
lib/std/math/trunc.zig
@@ -94,49 +94,49 @@ fn trunc128(x: f128) f128 {
}
test "math.trunc" {
- expect(trunc(@as(f32, 1.3)) == trunc32(1.3));
- expect(trunc(@as(f64, 1.3)) == trunc64(1.3));
- expect(trunc(@as(f128, 1.3)) == trunc128(1.3));
+ try expect(trunc(@as(f32, 1.3)) == trunc32(1.3));
+ try expect(trunc(@as(f64, 1.3)) == trunc64(1.3));
+ try expect(trunc(@as(f128, 1.3)) == trunc128(1.3));
}
test "math.trunc32" {
- expect(trunc32(1.3) == 1.0);
- expect(trunc32(-1.3) == -1.0);
- expect(trunc32(0.2) == 0.0);
+ try expect(trunc32(1.3) == 1.0);
+ try expect(trunc32(-1.3) == -1.0);
+ try expect(trunc32(0.2) == 0.0);
}
test "math.trunc64" {
- expect(trunc64(1.3) == 1.0);
- expect(trunc64(-1.3) == -1.0);
- expect(trunc64(0.2) == 0.0);
+ try expect(trunc64(1.3) == 1.0);
+ try expect(trunc64(-1.3) == -1.0);
+ try expect(trunc64(0.2) == 0.0);
}
test "math.trunc128" {
- expect(trunc128(1.3) == 1.0);
- expect(trunc128(-1.3) == -1.0);
- expect(trunc128(0.2) == 0.0);
+ try expect(trunc128(1.3) == 1.0);
+ try expect(trunc128(-1.3) == -1.0);
+ try expect(trunc128(0.2) == 0.0);
}
test "math.trunc32.special" {
- expect(trunc32(0.0) == 0.0); // 0x3F800000
- expect(trunc32(-0.0) == -0.0);
- expect(math.isPositiveInf(trunc32(math.inf(f32))));
- expect(math.isNegativeInf(trunc32(-math.inf(f32))));
- expect(math.isNan(trunc32(math.nan(f32))));
+ try expect(trunc32(0.0) == 0.0); // 0x3F800000
+ try expect(trunc32(-0.0) == -0.0);
+ try expect(math.isPositiveInf(trunc32(math.inf(f32))));
+ try expect(math.isNegativeInf(trunc32(-math.inf(f32))));
+ try expect(math.isNan(trunc32(math.nan(f32))));
}
test "math.trunc64.special" {
- expect(trunc64(0.0) == 0.0);
- expect(trunc64(-0.0) == -0.0);
- expect(math.isPositiveInf(trunc64(math.inf(f64))));
- expect(math.isNegativeInf(trunc64(-math.inf(f64))));
- expect(math.isNan(trunc64(math.nan(f64))));
+ try expect(trunc64(0.0) == 0.0);
+ try expect(trunc64(-0.0) == -0.0);
+ try expect(math.isPositiveInf(trunc64(math.inf(f64))));
+ try expect(math.isNegativeInf(trunc64(-math.inf(f64))));
+ try expect(math.isNan(trunc64(math.nan(f64))));
}
test "math.trunc128.special" {
- expect(trunc128(0.0) == 0.0);
- expect(trunc128(-0.0) == -0.0);
- expect(math.isPositiveInf(trunc128(math.inf(f128))));
- expect(math.isNegativeInf(trunc128(-math.inf(f128))));
- expect(math.isNan(trunc128(math.nan(f128))));
+ try expect(trunc128(0.0) == 0.0);
+ try expect(trunc128(-0.0) == -0.0);
+ try expect(math.isPositiveInf(trunc128(math.inf(f128))));
+ try expect(math.isNegativeInf(trunc128(-math.inf(f128))));
+ try expect(math.isNan(trunc128(math.nan(f128))));
}
lib/std/meta/trailer_flags.zig
@@ -146,7 +146,7 @@ test "TrailerFlags" {
b: bool,
c: u64,
});
- testing.expectEqual(u2, meta.Tag(Flags.FieldEnum));
+ try testing.expectEqual(u2, meta.Tag(Flags.FieldEnum));
var flags = Flags.init(.{
.b = true,
@@ -158,16 +158,16 @@ test "TrailerFlags" {
flags.set(slice.ptr, .b, false);
flags.set(slice.ptr, .c, 12345678);
- testing.expect(flags.get(slice.ptr, .a) == null);
- testing.expect(!flags.get(slice.ptr, .b).?);
- testing.expect(flags.get(slice.ptr, .c).? == 12345678);
+ try testing.expect(flags.get(slice.ptr, .a) == null);
+ try testing.expect(!flags.get(slice.ptr, .b).?);
+ try testing.expect(flags.get(slice.ptr, .c).? == 12345678);
flags.setMany(slice.ptr, .{
.b = true,
.c = 5678,
});
- testing.expect(flags.get(slice.ptr, .a) == null);
- testing.expect(flags.get(slice.ptr, .b).?);
- testing.expect(flags.get(slice.ptr, .c).? == 5678);
+ try testing.expect(flags.get(slice.ptr, .a) == null);
+ try testing.expect(flags.get(slice.ptr, .b).?);
+ try testing.expect(flags.get(slice.ptr, .c).? == 5678);
}
lib/std/meta/trait.zig
@@ -45,8 +45,8 @@ test "std.meta.trait.multiTrait" {
hasField("x"),
hasField("y"),
});
- testing.expect(isVector(Vector2));
- testing.expect(!isVector(u8));
+ try testing.expect(isVector(Vector2));
+ try testing.expect(!isVector(u8));
}
pub fn hasFn(comptime name: []const u8) TraitFn {
@@ -66,9 +66,9 @@ test "std.meta.trait.hasFn" {
pub fn useless() void {}
};
- testing.expect(hasFn("useless")(TestStruct));
- testing.expect(!hasFn("append")(TestStruct));
- testing.expect(!hasFn("useless")(u8));
+ try testing.expect(hasFn("useless")(TestStruct));
+ try testing.expect(!hasFn("append")(TestStruct));
+ try testing.expect(!hasFn("useless")(u8));
}
pub fn hasField(comptime name: []const u8) TraitFn {
@@ -96,11 +96,11 @@ test "std.meta.trait.hasField" {
value: u32,
};
- testing.expect(hasField("value")(TestStruct));
- testing.expect(!hasField("value")(*TestStruct));
- testing.expect(!hasField("x")(TestStruct));
- testing.expect(!hasField("x")(**TestStruct));
- testing.expect(!hasField("value")(u8));
+ try testing.expect(hasField("value")(TestStruct));
+ try testing.expect(!hasField("value")(*TestStruct));
+ try testing.expect(!hasField("x")(TestStruct));
+ try testing.expect(!hasField("x")(**TestStruct));
+ try testing.expect(!hasField("value")(u8));
}
pub fn is(comptime id: builtin.TypeId) TraitFn {
@@ -113,11 +113,11 @@ pub fn is(comptime id: builtin.TypeId) TraitFn {
}
test "std.meta.trait.is" {
- testing.expect(is(.Int)(u8));
- testing.expect(!is(.Int)(f32));
- testing.expect(is(.Pointer)(*u8));
- testing.expect(is(.Void)(void));
- testing.expect(!is(.Optional)(anyerror));
+ try testing.expect(is(.Int)(u8));
+ try testing.expect(!is(.Int)(f32));
+ try testing.expect(is(.Pointer)(*u8));
+ try testing.expect(is(.Void)(void));
+ try testing.expect(!is(.Optional)(anyerror));
}
pub fn isPtrTo(comptime id: builtin.TypeId) TraitFn {
@@ -131,9 +131,9 @@ pub fn isPtrTo(comptime id: builtin.TypeId) TraitFn {
}
test "std.meta.trait.isPtrTo" {
- testing.expect(!isPtrTo(.Struct)(struct {}));
- testing.expect(isPtrTo(.Struct)(*struct {}));
- testing.expect(!isPtrTo(.Struct)(**struct {}));
+ try testing.expect(!isPtrTo(.Struct)(struct {}));
+ try testing.expect(isPtrTo(.Struct)(*struct {}));
+ try testing.expect(!isPtrTo(.Struct)(**struct {}));
}
pub fn isSliceOf(comptime id: builtin.TypeId) TraitFn {
@@ -147,9 +147,9 @@ pub fn isSliceOf(comptime id: builtin.TypeId) TraitFn {
}
test "std.meta.trait.isSliceOf" {
- testing.expect(!isSliceOf(.Struct)(struct {}));
- testing.expect(isSliceOf(.Struct)([]struct {}));
- testing.expect(!isSliceOf(.Struct)([][]struct {}));
+ try testing.expect(!isSliceOf(.Struct)(struct {}));
+ try testing.expect(isSliceOf(.Struct)([]struct {}));
+ try testing.expect(!isSliceOf(.Struct)([][]struct {}));
}
///////////Strait trait Fns
@@ -170,9 +170,9 @@ test "std.meta.trait.isExtern" {
const TestExStruct = extern struct {};
const TestStruct = struct {};
- testing.expect(isExtern(TestExStruct));
- testing.expect(!isExtern(TestStruct));
- testing.expect(!isExtern(u8));
+ try testing.expect(isExtern(TestExStruct));
+ try testing.expect(!isExtern(TestStruct));
+ try testing.expect(!isExtern(u8));
}
pub fn isPacked(comptime T: type) bool {
@@ -188,9 +188,9 @@ test "std.meta.trait.isPacked" {
const TestPStruct = packed struct {};
const TestStruct = struct {};
- testing.expect(isPacked(TestPStruct));
- testing.expect(!isPacked(TestStruct));
- testing.expect(!isPacked(u8));
+ try testing.expect(isPacked(TestPStruct));
+ try testing.expect(!isPacked(TestStruct));
+ try testing.expect(!isPacked(u8));
}
pub fn isUnsignedInt(comptime T: type) bool {
@@ -201,10 +201,10 @@ pub fn isUnsignedInt(comptime T: type) bool {
}
test "isUnsignedInt" {
- testing.expect(isUnsignedInt(u32) == true);
- testing.expect(isUnsignedInt(comptime_int) == false);
- testing.expect(isUnsignedInt(i64) == false);
- testing.expect(isUnsignedInt(f64) == false);
+ try testing.expect(isUnsignedInt(u32) == true);
+ try testing.expect(isUnsignedInt(comptime_int) == false);
+ try testing.expect(isUnsignedInt(i64) == false);
+ try testing.expect(isUnsignedInt(f64) == false);
}
pub fn isSignedInt(comptime T: type) bool {
@@ -216,10 +216,10 @@ pub fn isSignedInt(comptime T: type) bool {
}
test "isSignedInt" {
- testing.expect(isSignedInt(u32) == false);
- testing.expect(isSignedInt(comptime_int) == true);
- testing.expect(isSignedInt(i64) == true);
- testing.expect(isSignedInt(f64) == false);
+ try testing.expect(isSignedInt(u32) == false);
+ try testing.expect(isSignedInt(comptime_int) == true);
+ try testing.expect(isSignedInt(i64) == true);
+ try testing.expect(isSignedInt(f64) == false);
}
pub fn isSingleItemPtr(comptime T: type) bool {
@@ -231,10 +231,10 @@ pub fn isSingleItemPtr(comptime T: type) bool {
test "std.meta.trait.isSingleItemPtr" {
const array = [_]u8{0} ** 10;
- comptime testing.expect(isSingleItemPtr(@TypeOf(&array[0])));
- comptime testing.expect(!isSingleItemPtr(@TypeOf(array)));
+ comptime try testing.expect(isSingleItemPtr(@TypeOf(&array[0])));
+ comptime try testing.expect(!isSingleItemPtr(@TypeOf(array)));
var runtime_zero: usize = 0;
- testing.expect(!isSingleItemPtr(@TypeOf(array[runtime_zero..1])));
+ try testing.expect(!isSingleItemPtr(@TypeOf(array[runtime_zero..1])));
}
pub fn isManyItemPtr(comptime T: type) bool {
@@ -247,9 +247,9 @@ pub fn isManyItemPtr(comptime T: type) bool {
test "std.meta.trait.isManyItemPtr" {
const array = [_]u8{0} ** 10;
const mip = @ptrCast([*]const u8, &array[0]);
- testing.expect(isManyItemPtr(@TypeOf(mip)));
- testing.expect(!isManyItemPtr(@TypeOf(array)));
- testing.expect(!isManyItemPtr(@TypeOf(array[0..1])));
+ try testing.expect(isManyItemPtr(@TypeOf(mip)));
+ try testing.expect(!isManyItemPtr(@TypeOf(array)));
+ try testing.expect(!isManyItemPtr(@TypeOf(array[0..1])));
}
pub fn isSlice(comptime T: type) bool {
@@ -262,9 +262,9 @@ pub fn isSlice(comptime T: type) bool {
test "std.meta.trait.isSlice" {
const array = [_]u8{0} ** 10;
var runtime_zero: usize = 0;
- testing.expect(isSlice(@TypeOf(array[runtime_zero..])));
- testing.expect(!isSlice(@TypeOf(array)));
- testing.expect(!isSlice(@TypeOf(&array[0])));
+ try testing.expect(isSlice(@TypeOf(array[runtime_zero..])));
+ try testing.expect(!isSlice(@TypeOf(array)));
+ try testing.expect(!isSlice(@TypeOf(&array[0])));
}
pub fn isIndexable(comptime T: type) bool {
@@ -283,12 +283,12 @@ test "std.meta.trait.isIndexable" {
const vector: meta.Vector(2, u32) = [_]u32{0} ** 2;
const tuple = .{ 1, 2, 3 };
- testing.expect(isIndexable(@TypeOf(array)));
- testing.expect(isIndexable(@TypeOf(&array)));
- testing.expect(isIndexable(@TypeOf(slice)));
- testing.expect(!isIndexable(meta.Child(@TypeOf(slice))));
- testing.expect(isIndexable(@TypeOf(vector)));
- testing.expect(isIndexable(@TypeOf(tuple)));
+ try testing.expect(isIndexable(@TypeOf(array)));
+ try testing.expect(isIndexable(@TypeOf(&array)));
+ try testing.expect(isIndexable(@TypeOf(slice)));
+ try testing.expect(!isIndexable(meta.Child(@TypeOf(slice))));
+ try testing.expect(isIndexable(@TypeOf(vector)));
+ try testing.expect(isIndexable(@TypeOf(tuple)));
}
pub fn isNumber(comptime T: type) bool {
@@ -317,13 +317,13 @@ test "std.meta.trait.isNumber" {
number: u8,
};
- testing.expect(isNumber(u32));
- testing.expect(isNumber(f32));
- testing.expect(isNumber(u64));
- testing.expect(isNumber(@TypeOf(102)));
- testing.expect(isNumber(@TypeOf(102.123)));
- testing.expect(!isNumber([]u8));
- testing.expect(!isNumber(NotANumber));
+ try testing.expect(isNumber(u32));
+ try testing.expect(isNumber(f32));
+ try testing.expect(isNumber(u64));
+ try testing.expect(isNumber(@TypeOf(102)));
+ try testing.expect(isNumber(@TypeOf(102.123)));
+ try testing.expect(!isNumber([]u8));
+ try testing.expect(!isNumber(NotANumber));
}
pub fn isIntegral(comptime T: type) bool {
@@ -334,12 +334,12 @@ pub fn isIntegral(comptime T: type) bool {
}
test "isIntegral" {
- testing.expect(isIntegral(u32));
- testing.expect(!isIntegral(f32));
- testing.expect(isIntegral(@TypeOf(102)));
- testing.expect(!isIntegral(@TypeOf(102.123)));
- testing.expect(!isIntegral(*u8));
- testing.expect(!isIntegral([]u8));
+ try testing.expect(isIntegral(u32));
+ try testing.expect(!isIntegral(f32));
+ try testing.expect(isIntegral(@TypeOf(102)));
+ try testing.expect(!isIntegral(@TypeOf(102.123)));
+ try testing.expect(!isIntegral(*u8));
+ try testing.expect(!isIntegral([]u8));
}
pub fn isFloat(comptime T: type) bool {
@@ -350,12 +350,12 @@ pub fn isFloat(comptime T: type) bool {
}
test "isFloat" {
- testing.expect(!isFloat(u32));
- testing.expect(isFloat(f32));
- testing.expect(!isFloat(@TypeOf(102)));
- testing.expect(isFloat(@TypeOf(102.123)));
- testing.expect(!isFloat(*f64));
- testing.expect(!isFloat([]f32));
+ try testing.expect(!isFloat(u32));
+ try testing.expect(isFloat(f32));
+ try testing.expect(!isFloat(@TypeOf(102)));
+ try testing.expect(isFloat(@TypeOf(102.123)));
+ try testing.expect(!isFloat(*f64));
+ try testing.expect(!isFloat([]f32));
}
pub fn isConstPtr(comptime T: type) bool {
@@ -366,10 +366,10 @@ pub fn isConstPtr(comptime T: type) bool {
test "std.meta.trait.isConstPtr" {
var t = @as(u8, 0);
const c = @as(u8, 0);
- testing.expect(isConstPtr(*const @TypeOf(t)));
- testing.expect(isConstPtr(@TypeOf(&c)));
- testing.expect(!isConstPtr(*@TypeOf(t)));
- testing.expect(!isConstPtr(@TypeOf(6)));
+ try testing.expect(isConstPtr(*const @TypeOf(t)));
+ try testing.expect(isConstPtr(@TypeOf(&c)));
+ try testing.expect(!isConstPtr(*@TypeOf(t)));
+ try testing.expect(!isConstPtr(@TypeOf(6)));
}
pub fn isContainer(comptime T: type) bool {
@@ -389,10 +389,10 @@ test "std.meta.trait.isContainer" {
B,
};
- testing.expect(isContainer(TestStruct));
- testing.expect(isContainer(TestUnion));
- testing.expect(isContainer(TestEnum));
- testing.expect(!isContainer(u8));
+ try testing.expect(isContainer(TestStruct));
+ try testing.expect(isContainer(TestUnion));
+ try testing.expect(isContainer(TestEnum));
+ try testing.expect(!isContainer(u8));
}
pub fn isTuple(comptime T: type) bool {
@@ -403,9 +403,9 @@ test "std.meta.trait.isTuple" {
const t1 = struct {};
const t2 = .{ .a = 0 };
const t3 = .{ 1, 2, 3 };
- testing.expect(!isTuple(t1));
- testing.expect(!isTuple(@TypeOf(t2)));
- testing.expect(isTuple(@TypeOf(t3)));
+ try testing.expect(!isTuple(t1));
+ try testing.expect(!isTuple(@TypeOf(t2)));
+ try testing.expect(isTuple(@TypeOf(t3)));
}
/// Returns true if the passed type will coerce to []const u8.
@@ -449,41 +449,41 @@ pub fn isZigString(comptime T: type) bool {
}
test "std.meta.trait.isZigString" {
- testing.expect(isZigString([]const u8));
- testing.expect(isZigString([]u8));
- testing.expect(isZigString([:0]const u8));
- testing.expect(isZigString([:0]u8));
- testing.expect(isZigString([:5]const u8));
- testing.expect(isZigString([:5]u8));
- testing.expect(isZigString(*const [0]u8));
- testing.expect(isZigString(*[0]u8));
- testing.expect(isZigString(*const [0:0]u8));
- testing.expect(isZigString(*[0:0]u8));
- testing.expect(isZigString(*const [0:5]u8));
- testing.expect(isZigString(*[0:5]u8));
- testing.expect(isZigString(*const [10]u8));
- testing.expect(isZigString(*[10]u8));
- testing.expect(isZigString(*const [10:0]u8));
- testing.expect(isZigString(*[10:0]u8));
- testing.expect(isZigString(*const [10:5]u8));
- testing.expect(isZigString(*[10:5]u8));
-
- testing.expect(!isZigString(u8));
- testing.expect(!isZigString([4]u8));
- testing.expect(!isZigString([4:0]u8));
- testing.expect(!isZigString([*]const u8));
- testing.expect(!isZigString([*]const [4]u8));
- testing.expect(!isZigString([*c]const u8));
- testing.expect(!isZigString([*c]const [4]u8));
- testing.expect(!isZigString([*:0]const u8));
- testing.expect(!isZigString([*:0]const u8));
- testing.expect(!isZigString(*[]const u8));
- testing.expect(!isZigString(?[]const u8));
- testing.expect(!isZigString(?*const [4]u8));
- testing.expect(!isZigString([]allowzero u8));
- testing.expect(!isZigString([]volatile u8));
- testing.expect(!isZigString(*allowzero [4]u8));
- testing.expect(!isZigString(*volatile [4]u8));
+ try testing.expect(isZigString([]const u8));
+ try testing.expect(isZigString([]u8));
+ try testing.expect(isZigString([:0]const u8));
+ try testing.expect(isZigString([:0]u8));
+ try testing.expect(isZigString([:5]const u8));
+ try testing.expect(isZigString([:5]u8));
+ try testing.expect(isZigString(*const [0]u8));
+ try testing.expect(isZigString(*[0]u8));
+ try testing.expect(isZigString(*const [0:0]u8));
+ try testing.expect(isZigString(*[0:0]u8));
+ try testing.expect(isZigString(*const [0:5]u8));
+ try testing.expect(isZigString(*[0:5]u8));
+ try testing.expect(isZigString(*const [10]u8));
+ try testing.expect(isZigString(*[10]u8));
+ try testing.expect(isZigString(*const [10:0]u8));
+ try testing.expect(isZigString(*[10:0]u8));
+ try testing.expect(isZigString(*const [10:5]u8));
+ try testing.expect(isZigString(*[10:5]u8));
+
+ try testing.expect(!isZigString(u8));
+ try testing.expect(!isZigString([4]u8));
+ try testing.expect(!isZigString([4:0]u8));
+ try testing.expect(!isZigString([*]const u8));
+ try testing.expect(!isZigString([*]const [4]u8));
+ try testing.expect(!isZigString([*c]const u8));
+ try testing.expect(!isZigString([*c]const [4]u8));
+ try testing.expect(!isZigString([*:0]const u8));
+ try testing.expect(!isZigString([*:0]const u8));
+ try testing.expect(!isZigString(*[]const u8));
+ try testing.expect(!isZigString(?[]const u8));
+ try testing.expect(!isZigString(?*const [4]u8));
+ try testing.expect(!isZigString([]allowzero u8));
+ try testing.expect(!isZigString([]volatile u8));
+ try testing.expect(!isZigString(*allowzero [4]u8));
+ try testing.expect(!isZigString(*volatile [4]u8));
}
pub fn hasDecls(comptime T: type, comptime names: anytype) bool {
@@ -505,11 +505,11 @@ test "std.meta.trait.hasDecls" {
const tuple = .{ "a", "b", "c" };
- testing.expect(!hasDecls(TestStruct1, .{"a"}));
- testing.expect(hasDecls(TestStruct2, .{ "a", "b" }));
- testing.expect(hasDecls(TestStruct2, .{ "a", "b", "useless" }));
- testing.expect(!hasDecls(TestStruct2, .{ "a", "b", "c" }));
- testing.expect(!hasDecls(TestStruct2, tuple));
+ try testing.expect(!hasDecls(TestStruct1, .{"a"}));
+ try testing.expect(hasDecls(TestStruct2, .{ "a", "b" }));
+ try testing.expect(hasDecls(TestStruct2, .{ "a", "b", "useless" }));
+ try testing.expect(!hasDecls(TestStruct2, .{ "a", "b", "c" }));
+ try testing.expect(!hasDecls(TestStruct2, tuple));
}
pub fn hasFields(comptime T: type, comptime names: anytype) bool {
@@ -531,11 +531,11 @@ test "std.meta.trait.hasFields" {
const tuple = .{ "a", "b", "c" };
- testing.expect(!hasFields(TestStruct1, .{"a"}));
- testing.expect(hasFields(TestStruct2, .{ "a", "b" }));
- testing.expect(hasFields(TestStruct2, .{ "a", "b", "c" }));
- testing.expect(hasFields(TestStruct2, tuple));
- testing.expect(!hasFields(TestStruct2, .{ "a", "b", "useless" }));
+ try testing.expect(!hasFields(TestStruct1, .{"a"}));
+ try testing.expect(hasFields(TestStruct2, .{ "a", "b" }));
+ try testing.expect(hasFields(TestStruct2, .{ "a", "b", "c" }));
+ try testing.expect(hasFields(TestStruct2, tuple));
+ try testing.expect(!hasFields(TestStruct2, .{ "a", "b", "useless" }));
}
pub fn hasFunctions(comptime T: type, comptime names: anytype) bool {
@@ -555,10 +555,10 @@ test "std.meta.trait.hasFunctions" {
const tuple = .{ "a", "b", "c" };
- testing.expect(!hasFunctions(TestStruct1, .{"a"}));
- testing.expect(hasFunctions(TestStruct2, .{ "a", "b" }));
- testing.expect(!hasFunctions(TestStruct2, .{ "a", "b", "c" }));
- testing.expect(!hasFunctions(TestStruct2, tuple));
+ try testing.expect(!hasFunctions(TestStruct1, .{"a"}));
+ try testing.expect(hasFunctions(TestStruct2, .{ "a", "b" }));
+ try testing.expect(!hasFunctions(TestStruct2, .{ "a", "b", "c" }));
+ try testing.expect(!hasFunctions(TestStruct2, tuple));
}
/// True if every value of the type `T` has a unique bit pattern representing it.
@@ -606,65 +606,65 @@ test "std.meta.trait.hasUniqueRepresentation" {
b: u32,
};
- testing.expect(hasUniqueRepresentation(TestStruct1));
+ try testing.expect(hasUniqueRepresentation(TestStruct1));
const TestStruct2 = struct {
a: u32,
b: u16,
};
- testing.expect(!hasUniqueRepresentation(TestStruct2));
+ try testing.expect(!hasUniqueRepresentation(TestStruct2));
const TestStruct3 = struct {
a: u32,
b: u32,
};
- testing.expect(hasUniqueRepresentation(TestStruct3));
+ try testing.expect(hasUniqueRepresentation(TestStruct3));
const TestStruct4 = struct { a: []const u8 };
- testing.expect(!hasUniqueRepresentation(TestStruct4));
+ try testing.expect(!hasUniqueRepresentation(TestStruct4));
const TestStruct5 = struct { a: TestStruct4 };
- testing.expect(!hasUniqueRepresentation(TestStruct5));
+ try testing.expect(!hasUniqueRepresentation(TestStruct5));
const TestUnion1 = packed union {
a: u32,
b: u16,
};
- testing.expect(!hasUniqueRepresentation(TestUnion1));
+ try testing.expect(!hasUniqueRepresentation(TestUnion1));
const TestUnion2 = extern union {
a: u32,
b: u16,
};
- testing.expect(!hasUniqueRepresentation(TestUnion2));
+ try testing.expect(!hasUniqueRepresentation(TestUnion2));
const TestUnion3 = union {
a: u32,
b: u16,
};
- testing.expect(!hasUniqueRepresentation(TestUnion3));
+ try testing.expect(!hasUniqueRepresentation(TestUnion3));
const TestUnion4 = union(enum) {
a: u32,
b: u16,
};
- testing.expect(!hasUniqueRepresentation(TestUnion4));
+ try testing.expect(!hasUniqueRepresentation(TestUnion4));
inline for ([_]type{ i0, u8, i16, u32, i64 }) |T| {
- testing.expect(hasUniqueRepresentation(T));
+ try testing.expect(hasUniqueRepresentation(T));
}
inline for ([_]type{ i1, u9, i17, u33, i24 }) |T| {
- testing.expect(!hasUniqueRepresentation(T));
+ try testing.expect(!hasUniqueRepresentation(T));
}
- testing.expect(!hasUniqueRepresentation([]u8));
- testing.expect(!hasUniqueRepresentation([]const u8));
+ try testing.expect(!hasUniqueRepresentation([]u8));
+ try testing.expect(!hasUniqueRepresentation([]const u8));
}
lib/std/net/test.zig
@@ -38,26 +38,26 @@ test "parse and render IPv6 addresses" {
for (ips) |ip, i| {
var addr = net.Address.parseIp6(ip, 0) catch unreachable;
var newIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr}) catch unreachable;
- std.testing.expect(std.mem.eql(u8, printed[i], newIp[1 .. newIp.len - 3]));
+ try std.testing.expect(std.mem.eql(u8, printed[i], newIp[1 .. newIp.len - 3]));
if (std.builtin.os.tag == .linux) {
var addr_via_resolve = net.Address.resolveIp6(ip, 0) catch unreachable;
var newResolvedIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr_via_resolve}) catch unreachable;
- std.testing.expect(std.mem.eql(u8, printed[i], newResolvedIp[1 .. newResolvedIp.len - 3]));
+ try std.testing.expect(std.mem.eql(u8, printed[i], newResolvedIp[1 .. newResolvedIp.len - 3]));
}
}
- testing.expectError(error.InvalidCharacter, net.Address.parseIp6(":::", 0));
- testing.expectError(error.Overflow, net.Address.parseIp6("FF001::FB", 0));
- testing.expectError(error.InvalidCharacter, net.Address.parseIp6("FF01::Fb:zig", 0));
- testing.expectError(error.InvalidEnd, net.Address.parseIp6("FF01:0:0:0:0:0:0:FB:", 0));
- testing.expectError(error.Incomplete, net.Address.parseIp6("FF01:", 0));
- testing.expectError(error.InvalidIpv4Mapping, net.Address.parseIp6("::123.123.123.123", 0));
+ try testing.expectError(error.InvalidCharacter, net.Address.parseIp6(":::", 0));
+ try testing.expectError(error.Overflow, net.Address.parseIp6("FF001::FB", 0));
+ try testing.expectError(error.InvalidCharacter, net.Address.parseIp6("FF01::Fb:zig", 0));
+ try testing.expectError(error.InvalidEnd, net.Address.parseIp6("FF01:0:0:0:0:0:0:FB:", 0));
+ try testing.expectError(error.Incomplete, net.Address.parseIp6("FF01:", 0));
+ try testing.expectError(error.InvalidIpv4Mapping, net.Address.parseIp6("::123.123.123.123", 0));
// TODO Make this test pass on other operating systems.
if (std.builtin.os.tag == .linux) {
- testing.expectError(error.Incomplete, net.Address.resolveIp6("ff01::fb%", 0));
- testing.expectError(error.Overflow, net.Address.resolveIp6("ff01::fb%wlp3s0s0s0s0s0s0s0s0", 0));
- testing.expectError(error.Overflow, net.Address.resolveIp6("ff01::fb%12345678901234", 0));
+ try testing.expectError(error.Incomplete, net.Address.resolveIp6("ff01::fb%", 0));
+ try testing.expectError(error.Overflow, net.Address.resolveIp6("ff01::fb%wlp3s0s0s0s0s0s0s0s0", 0));
+ try testing.expectError(error.Overflow, net.Address.resolveIp6("ff01::fb%12345678901234", 0));
}
}
@@ -68,7 +68,7 @@ test "invalid but parseable IPv6 scope ids" {
return error.SkipZigTest;
}
- testing.expectError(error.InterfaceNotFound, net.Address.resolveIp6("ff01::fb%123s45678901234", 0));
+ try testing.expectError(error.InterfaceNotFound, net.Address.resolveIp6("ff01::fb%123s45678901234", 0));
}
test "parse and render IPv4 addresses" {
@@ -84,14 +84,14 @@ test "parse and render IPv4 addresses" {
}) |ip| {
var addr = net.Address.parseIp4(ip, 0) catch unreachable;
var newIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr}) catch unreachable;
- std.testing.expect(std.mem.eql(u8, ip, newIp[0 .. newIp.len - 2]));
+ try std.testing.expect(std.mem.eql(u8, ip, newIp[0 .. newIp.len - 2]));
}
- testing.expectError(error.Overflow, net.Address.parseIp4("256.0.0.1", 0));
- testing.expectError(error.InvalidCharacter, net.Address.parseIp4("x.0.0.1", 0));
- testing.expectError(error.InvalidEnd, net.Address.parseIp4("127.0.0.1.1", 0));
- testing.expectError(error.Incomplete, net.Address.parseIp4("127.0.0.", 0));
- testing.expectError(error.InvalidCharacter, net.Address.parseIp4("100..0.1", 0));
+ try testing.expectError(error.Overflow, net.Address.parseIp4("256.0.0.1", 0));
+ try testing.expectError(error.InvalidCharacter, net.Address.parseIp4("x.0.0.1", 0));
+ try testing.expectError(error.InvalidEnd, net.Address.parseIp4("127.0.0.1.1", 0));
+ try testing.expectError(error.Incomplete, net.Address.parseIp4("127.0.0.", 0));
+ try testing.expectError(error.InvalidCharacter, net.Address.parseIp4("100..0.1", 0));
}
test "resolve DNS" {
@@ -169,8 +169,8 @@ test "listen on a port, send bytes, receive bytes" {
var buf: [16]u8 = undefined;
const n = try client.stream.reader().read(&buf);
- testing.expectEqual(@as(usize, 12), n);
- testing.expectEqualSlices(u8, "Hello world!", buf[0..n]);
+ try testing.expectEqual(@as(usize, 12), n);
+ try testing.expectEqualSlices(u8, "Hello world!", buf[0..n]);
}
test "listen on a port, send bytes, receive bytes" {
@@ -230,7 +230,7 @@ fn testClientToHost(allocator: *mem.Allocator, name: []const u8, port: u16) anye
var buf: [100]u8 = undefined;
const len = try connection.read(&buf);
const msg = buf[0..len];
- testing.expect(mem.eql(u8, msg, "hello from server\n"));
+ try testing.expect(mem.eql(u8, msg, "hello from server\n"));
}
fn testClient(addr: net.Address) anyerror!void {
@@ -242,7 +242,7 @@ fn testClient(addr: net.Address) anyerror!void {
var buf: [100]u8 = undefined;
const len = try socket_file.read(&buf);
const msg = buf[0..len];
- testing.expect(mem.eql(u8, msg, "hello from server\n"));
+ try testing.expect(mem.eql(u8, msg, "hello from server\n"));
}
fn testServer(server: *net.StreamServer) anyerror!void {
@@ -293,6 +293,6 @@ test "listen on a unix socket, send bytes, receive bytes" {
var buf: [16]u8 = undefined;
const n = try client.stream.reader().read(&buf);
- testing.expectEqual(@as(usize, 12), n);
- testing.expectEqualSlices(u8, "Hello world!", buf[0..n]);
+ try testing.expectEqual(@as(usize, 12), n);
+ try testing.expectEqualSlices(u8, "Hello world!", buf[0..n]);
}
lib/std/os/linux/bpf/btf.zig
@@ -92,7 +92,7 @@ pub const IntInfo = packed struct {
};
test "IntInfo is 32 bits" {
- std.testing.expectEqual(@bitSizeOf(IntInfo), 32);
+ try std.testing.expectEqual(@bitSizeOf(IntInfo), 32);
}
/// Enum kind is followed by this struct
lib/std/os/linux/bpf.zig
@@ -737,11 +737,11 @@ pub const Insn = packed struct {
};
test "insn bitsize" {
- expectEqual(@bitSizeOf(Insn), 64);
+ try expectEqual(@bitSizeOf(Insn), 64);
}
-fn expect_opcode(code: u8, insn: Insn) void {
- expectEqual(code, insn.code);
+fn expect_opcode(code: u8, insn: Insn) !void {
+ try expectEqual(code, insn.code);
}
// The opcodes were grabbed from https://github.com/iovisor/bpf-docs/blob/master/eBPF.md
@@ -750,108 +750,108 @@ test "opcodes" {
// loading 64-bit immediates (imm is only 32 bits wide)
// alu instructions
- expect_opcode(0x07, Insn.add(.r1, 0));
- expect_opcode(0x0f, Insn.add(.r1, .r2));
- expect_opcode(0x17, Insn.sub(.r1, 0));
- expect_opcode(0x1f, Insn.sub(.r1, .r2));
- expect_opcode(0x27, Insn.mul(.r1, 0));
- expect_opcode(0x2f, Insn.mul(.r1, .r2));
- expect_opcode(0x37, Insn.div(.r1, 0));
- expect_opcode(0x3f, Insn.div(.r1, .r2));
- expect_opcode(0x47, Insn.alu_or(.r1, 0));
- expect_opcode(0x4f, Insn.alu_or(.r1, .r2));
- expect_opcode(0x57, Insn.alu_and(.r1, 0));
- expect_opcode(0x5f, Insn.alu_and(.r1, .r2));
- expect_opcode(0x67, Insn.lsh(.r1, 0));
- expect_opcode(0x6f, Insn.lsh(.r1, .r2));
- expect_opcode(0x77, Insn.rsh(.r1, 0));
- expect_opcode(0x7f, Insn.rsh(.r1, .r2));
- expect_opcode(0x87, Insn.neg(.r1));
- expect_opcode(0x97, Insn.mod(.r1, 0));
- expect_opcode(0x9f, Insn.mod(.r1, .r2));
- expect_opcode(0xa7, Insn.xor(.r1, 0));
- expect_opcode(0xaf, Insn.xor(.r1, .r2));
- expect_opcode(0xb7, Insn.mov(.r1, 0));
- expect_opcode(0xbf, Insn.mov(.r1, .r2));
- expect_opcode(0xc7, Insn.arsh(.r1, 0));
- expect_opcode(0xcf, Insn.arsh(.r1, .r2));
+ try expect_opcode(0x07, Insn.add(.r1, 0));
+ try expect_opcode(0x0f, Insn.add(.r1, .r2));
+ try expect_opcode(0x17, Insn.sub(.r1, 0));
+ try expect_opcode(0x1f, Insn.sub(.r1, .r2));
+ try expect_opcode(0x27, Insn.mul(.r1, 0));
+ try expect_opcode(0x2f, Insn.mul(.r1, .r2));
+ try expect_opcode(0x37, Insn.div(.r1, 0));
+ try expect_opcode(0x3f, Insn.div(.r1, .r2));
+ try expect_opcode(0x47, Insn.alu_or(.r1, 0));
+ try expect_opcode(0x4f, Insn.alu_or(.r1, .r2));
+ try expect_opcode(0x57, Insn.alu_and(.r1, 0));
+ try expect_opcode(0x5f, Insn.alu_and(.r1, .r2));
+ try expect_opcode(0x67, Insn.lsh(.r1, 0));
+ try expect_opcode(0x6f, Insn.lsh(.r1, .r2));
+ try expect_opcode(0x77, Insn.rsh(.r1, 0));
+ try expect_opcode(0x7f, Insn.rsh(.r1, .r2));
+ try expect_opcode(0x87, Insn.neg(.r1));
+ try expect_opcode(0x97, Insn.mod(.r1, 0));
+ try expect_opcode(0x9f, Insn.mod(.r1, .r2));
+ try expect_opcode(0xa7, Insn.xor(.r1, 0));
+ try expect_opcode(0xaf, Insn.xor(.r1, .r2));
+ try expect_opcode(0xb7, Insn.mov(.r1, 0));
+ try expect_opcode(0xbf, Insn.mov(.r1, .r2));
+ try expect_opcode(0xc7, Insn.arsh(.r1, 0));
+ try expect_opcode(0xcf, Insn.arsh(.r1, .r2));
// atomic instructions: might be more of these not documented in the wild
- expect_opcode(0xdb, Insn.xadd(.r1, .r2));
+ try expect_opcode(0xdb, Insn.xadd(.r1, .r2));
// TODO: byteswap instructions
- expect_opcode(0xd4, Insn.le(.half_word, .r1));
- expectEqual(@intCast(i32, 16), Insn.le(.half_word, .r1).imm);
- expect_opcode(0xd4, Insn.le(.word, .r1));
- expectEqual(@intCast(i32, 32), Insn.le(.word, .r1).imm);
- expect_opcode(0xd4, Insn.le(.double_word, .r1));
- expectEqual(@intCast(i32, 64), Insn.le(.double_word, .r1).imm);
- expect_opcode(0xdc, Insn.be(.half_word, .r1));
- expectEqual(@intCast(i32, 16), Insn.be(.half_word, .r1).imm);
- expect_opcode(0xdc, Insn.be(.word, .r1));
- expectEqual(@intCast(i32, 32), Insn.be(.word, .r1).imm);
- expect_opcode(0xdc, Insn.be(.double_word, .r1));
- expectEqual(@intCast(i32, 64), Insn.be(.double_word, .r1).imm);
+ try expect_opcode(0xd4, Insn.le(.half_word, .r1));
+ try expectEqual(@intCast(i32, 16), Insn.le(.half_word, .r1).imm);
+ try expect_opcode(0xd4, Insn.le(.word, .r1));
+ try expectEqual(@intCast(i32, 32), Insn.le(.word, .r1).imm);
+ try expect_opcode(0xd4, Insn.le(.double_word, .r1));
+ try expectEqual(@intCast(i32, 64), Insn.le(.double_word, .r1).imm);
+ try expect_opcode(0xdc, Insn.be(.half_word, .r1));
+ try expectEqual(@intCast(i32, 16), Insn.be(.half_word, .r1).imm);
+ try expect_opcode(0xdc, Insn.be(.word, .r1));
+ try expectEqual(@intCast(i32, 32), Insn.be(.word, .r1).imm);
+ try expect_opcode(0xdc, Insn.be(.double_word, .r1));
+ try expectEqual(@intCast(i32, 64), Insn.be(.double_word, .r1).imm);
// memory instructions
- expect_opcode(0x18, Insn.ld_dw1(.r1, 0));
- expect_opcode(0x00, Insn.ld_dw2(0));
+ try expect_opcode(0x18, Insn.ld_dw1(.r1, 0));
+ try expect_opcode(0x00, Insn.ld_dw2(0));
// loading a map fd
- expect_opcode(0x18, Insn.ld_map_fd1(.r1, 0));
- expectEqual(@intCast(u4, PSEUDO_MAP_FD), Insn.ld_map_fd1(.r1, 0).src);
- expect_opcode(0x00, Insn.ld_map_fd2(0));
-
- expect_opcode(0x38, Insn.ld_abs(.double_word, .r1, .r2, 0));
- expect_opcode(0x20, Insn.ld_abs(.word, .r1, .r2, 0));
- expect_opcode(0x28, Insn.ld_abs(.half_word, .r1, .r2, 0));
- expect_opcode(0x30, Insn.ld_abs(.byte, .r1, .r2, 0));
-
- expect_opcode(0x58, Insn.ld_ind(.double_word, .r1, .r2, 0));
- expect_opcode(0x40, Insn.ld_ind(.word, .r1, .r2, 0));
- expect_opcode(0x48, Insn.ld_ind(.half_word, .r1, .r2, 0));
- expect_opcode(0x50, Insn.ld_ind(.byte, .r1, .r2, 0));
-
- expect_opcode(0x79, Insn.ldx(.double_word, .r1, .r2, 0));
- expect_opcode(0x61, Insn.ldx(.word, .r1, .r2, 0));
- expect_opcode(0x69, Insn.ldx(.half_word, .r1, .r2, 0));
- expect_opcode(0x71, Insn.ldx(.byte, .r1, .r2, 0));
-
- expect_opcode(0x62, Insn.st(.word, .r1, 0, 0));
- expect_opcode(0x6a, Insn.st(.half_word, .r1, 0, 0));
- expect_opcode(0x72, Insn.st(.byte, .r1, 0, 0));
-
- expect_opcode(0x63, Insn.stx(.word, .r1, 0, .r2));
- expect_opcode(0x6b, Insn.stx(.half_word, .r1, 0, .r2));
- expect_opcode(0x73, Insn.stx(.byte, .r1, 0, .r2));
- expect_opcode(0x7b, Insn.stx(.double_word, .r1, 0, .r2));
+ try expect_opcode(0x18, Insn.ld_map_fd1(.r1, 0));
+ try expectEqual(@intCast(u4, PSEUDO_MAP_FD), Insn.ld_map_fd1(.r1, 0).src);
+ try expect_opcode(0x00, Insn.ld_map_fd2(0));
+
+ try expect_opcode(0x38, Insn.ld_abs(.double_word, .r1, .r2, 0));
+ try expect_opcode(0x20, Insn.ld_abs(.word, .r1, .r2, 0));
+ try expect_opcode(0x28, Insn.ld_abs(.half_word, .r1, .r2, 0));
+ try expect_opcode(0x30, Insn.ld_abs(.byte, .r1, .r2, 0));
+
+ try expect_opcode(0x58, Insn.ld_ind(.double_word, .r1, .r2, 0));
+ try expect_opcode(0x40, Insn.ld_ind(.word, .r1, .r2, 0));
+ try expect_opcode(0x48, Insn.ld_ind(.half_word, .r1, .r2, 0));
+ try expect_opcode(0x50, Insn.ld_ind(.byte, .r1, .r2, 0));
+
+ try expect_opcode(0x79, Insn.ldx(.double_word, .r1, .r2, 0));
+ try expect_opcode(0x61, Insn.ldx(.word, .r1, .r2, 0));
+ try expect_opcode(0x69, Insn.ldx(.half_word, .r1, .r2, 0));
+ try expect_opcode(0x71, Insn.ldx(.byte, .r1, .r2, 0));
+
+ try expect_opcode(0x62, Insn.st(.word, .r1, 0, 0));
+ try expect_opcode(0x6a, Insn.st(.half_word, .r1, 0, 0));
+ try expect_opcode(0x72, Insn.st(.byte, .r1, 0, 0));
+
+ try expect_opcode(0x63, Insn.stx(.word, .r1, 0, .r2));
+ try expect_opcode(0x6b, Insn.stx(.half_word, .r1, 0, .r2));
+ try expect_opcode(0x73, Insn.stx(.byte, .r1, 0, .r2));
+ try expect_opcode(0x7b, Insn.stx(.double_word, .r1, 0, .r2));
// branch instructions
- expect_opcode(0x05, Insn.ja(0));
- expect_opcode(0x15, Insn.jeq(.r1, 0, 0));
- expect_opcode(0x1d, Insn.jeq(.r1, .r2, 0));
- expect_opcode(0x25, Insn.jgt(.r1, 0, 0));
- expect_opcode(0x2d, Insn.jgt(.r1, .r2, 0));
- expect_opcode(0x35, Insn.jge(.r1, 0, 0));
- expect_opcode(0x3d, Insn.jge(.r1, .r2, 0));
- expect_opcode(0xa5, Insn.jlt(.r1, 0, 0));
- expect_opcode(0xad, Insn.jlt(.r1, .r2, 0));
- expect_opcode(0xb5, Insn.jle(.r1, 0, 0));
- expect_opcode(0xbd, Insn.jle(.r1, .r2, 0));
- expect_opcode(0x45, Insn.jset(.r1, 0, 0));
- expect_opcode(0x4d, Insn.jset(.r1, .r2, 0));
- expect_opcode(0x55, Insn.jne(.r1, 0, 0));
- expect_opcode(0x5d, Insn.jne(.r1, .r2, 0));
- expect_opcode(0x65, Insn.jsgt(.r1, 0, 0));
- expect_opcode(0x6d, Insn.jsgt(.r1, .r2, 0));
- expect_opcode(0x75, Insn.jsge(.r1, 0, 0));
- expect_opcode(0x7d, Insn.jsge(.r1, .r2, 0));
- expect_opcode(0xc5, Insn.jslt(.r1, 0, 0));
- expect_opcode(0xcd, Insn.jslt(.r1, .r2, 0));
- expect_opcode(0xd5, Insn.jsle(.r1, 0, 0));
- expect_opcode(0xdd, Insn.jsle(.r1, .r2, 0));
- expect_opcode(0x85, Insn.call(.unspec));
- expect_opcode(0x95, Insn.exit());
+ try expect_opcode(0x05, Insn.ja(0));
+ try expect_opcode(0x15, Insn.jeq(.r1, 0, 0));
+ try expect_opcode(0x1d, Insn.jeq(.r1, .r2, 0));
+ try expect_opcode(0x25, Insn.jgt(.r1, 0, 0));
+ try expect_opcode(0x2d, Insn.jgt(.r1, .r2, 0));
+ try expect_opcode(0x35, Insn.jge(.r1, 0, 0));
+ try expect_opcode(0x3d, Insn.jge(.r1, .r2, 0));
+ try expect_opcode(0xa5, Insn.jlt(.r1, 0, 0));
+ try expect_opcode(0xad, Insn.jlt(.r1, .r2, 0));
+ try expect_opcode(0xb5, Insn.jle(.r1, 0, 0));
+ try expect_opcode(0xbd, Insn.jle(.r1, .r2, 0));
+ try expect_opcode(0x45, Insn.jset(.r1, 0, 0));
+ try expect_opcode(0x4d, Insn.jset(.r1, .r2, 0));
+ try expect_opcode(0x55, Insn.jne(.r1, 0, 0));
+ try expect_opcode(0x5d, Insn.jne(.r1, .r2, 0));
+ try expect_opcode(0x65, Insn.jsgt(.r1, 0, 0));
+ try expect_opcode(0x6d, Insn.jsgt(.r1, .r2, 0));
+ try expect_opcode(0x75, Insn.jsge(.r1, 0, 0));
+ try expect_opcode(0x7d, Insn.jsge(.r1, .r2, 0));
+ try expect_opcode(0xc5, Insn.jslt(.r1, 0, 0));
+ try expect_opcode(0xcd, Insn.jslt(.r1, .r2, 0));
+ try expect_opcode(0xd5, Insn.jsle(.r1, 0, 0));
+ try expect_opcode(0xdd, Insn.jsle(.r1, .r2, 0));
+ try expect_opcode(0x85, Insn.call(.unspec));
+ try expect_opcode(0x95, Insn.exit());
}
pub const Cmd = extern enum(usize) {
@@ -1596,7 +1596,7 @@ test "map lookup, update, and delete" {
var value = std.mem.zeroes([value_size]u8);
// fails looking up value that doesn't exist
- expectError(error.NotFound, map_lookup_elem(map, &key, &value));
+ try expectError(error.NotFound, map_lookup_elem(map, &key, &value));
// succeed at updating and looking up element
try map_update_elem(map, &key, &value, 0);
@@ -1604,14 +1604,14 @@ test "map lookup, update, and delete" {
// fails inserting more than max entries
const second_key = [key_size]u8{ 0, 0, 0, 1 };
- expectError(error.ReachedMaxEntries, map_update_elem(map, &second_key, &value, 0));
+ try expectError(error.ReachedMaxEntries, map_update_elem(map, &second_key, &value, 0));
// succeed at deleting an existing elem
try map_delete_elem(map, &key);
- expectError(error.NotFound, map_lookup_elem(map, &key, &value));
+ try expectError(error.NotFound, map_lookup_elem(map, &key, &value));
// fail at deleting a non-existing elem
- expectError(error.NotFound, map_delete_elem(map, &key));
+ try expectError(error.NotFound, map_delete_elem(map, &key));
}
pub fn prog_load(
@@ -1662,5 +1662,5 @@ test "prog_load" {
const prog = try prog_load(.socket_filter, &good_prog, null, "MIT", 0);
defer std.os.close(prog);
- expectError(error.UnsafeProgram, prog_load(.socket_filter, &bad_prog, null, "MIT", 0));
+ try expectError(error.UnsafeProgram, prog_load(.socket_filter, &bad_prog, null, "MIT", 0));
}
lib/std/os/linux/io_uring.zig
@@ -937,16 +937,16 @@ pub fn io_uring_prep_fallocate(
test "structs/offsets/entries" {
if (builtin.os.tag != .linux) return error.SkipZigTest;
- testing.expectEqual(@as(usize, 120), @sizeOf(io_uring_params));
- testing.expectEqual(@as(usize, 64), @sizeOf(io_uring_sqe));
- testing.expectEqual(@as(usize, 16), @sizeOf(io_uring_cqe));
+ try testing.expectEqual(@as(usize, 120), @sizeOf(io_uring_params));
+ try testing.expectEqual(@as(usize, 64), @sizeOf(io_uring_sqe));
+ try testing.expectEqual(@as(usize, 16), @sizeOf(io_uring_cqe));
- testing.expectEqual(0, linux.IORING_OFF_SQ_RING);
- testing.expectEqual(0x8000000, linux.IORING_OFF_CQ_RING);
- testing.expectEqual(0x10000000, linux.IORING_OFF_SQES);
+ try testing.expectEqual(0, linux.IORING_OFF_SQ_RING);
+ try testing.expectEqual(0x8000000, linux.IORING_OFF_CQ_RING);
+ try testing.expectEqual(0x10000000, linux.IORING_OFF_SQES);
- testing.expectError(error.EntriesZero, IO_Uring.init(0, 0));
- testing.expectError(error.EntriesNotPowerOfTwo, IO_Uring.init(3, 0));
+ try testing.expectError(error.EntriesZero, IO_Uring.init(0, 0));
+ try testing.expectError(error.EntriesNotPowerOfTwo, IO_Uring.init(3, 0));
}
test "nop" {
@@ -959,11 +959,11 @@ test "nop" {
};
defer {
ring.deinit();
- testing.expectEqual(@as(os.fd_t, -1), ring.fd);
+ testing.expectEqual(@as(os.fd_t, -1), ring.fd) catch @panic("test failed");
}
const sqe = try ring.nop(0xaaaaaaaa);
- testing.expectEqual(io_uring_sqe{
+ try testing.expectEqual(io_uring_sqe{
.opcode = .NOP,
.flags = 0,
.ioprio = 0,
@@ -979,40 +979,40 @@ test "nop" {
.__pad2 = [2]u64{ 0, 0 },
}, sqe.*);
- testing.expectEqual(@as(u32, 0), ring.sq.sqe_head);
- testing.expectEqual(@as(u32, 1), ring.sq.sqe_tail);
- testing.expectEqual(@as(u32, 0), ring.sq.tail.*);
- testing.expectEqual(@as(u32, 0), ring.cq.head.*);
- testing.expectEqual(@as(u32, 1), ring.sq_ready());
- testing.expectEqual(@as(u32, 0), ring.cq_ready());
-
- testing.expectEqual(@as(u32, 1), try ring.submit());
- testing.expectEqual(@as(u32, 1), ring.sq.sqe_head);
- testing.expectEqual(@as(u32, 1), ring.sq.sqe_tail);
- testing.expectEqual(@as(u32, 1), ring.sq.tail.*);
- testing.expectEqual(@as(u32, 0), ring.cq.head.*);
- testing.expectEqual(@as(u32, 0), ring.sq_ready());
-
- testing.expectEqual(io_uring_cqe{
+ try testing.expectEqual(@as(u32, 0), ring.sq.sqe_head);
+ try testing.expectEqual(@as(u32, 1), ring.sq.sqe_tail);
+ try testing.expectEqual(@as(u32, 0), ring.sq.tail.*);
+ try testing.expectEqual(@as(u32, 0), ring.cq.head.*);
+ try testing.expectEqual(@as(u32, 1), ring.sq_ready());
+ try testing.expectEqual(@as(u32, 0), ring.cq_ready());
+
+ try testing.expectEqual(@as(u32, 1), try ring.submit());
+ try testing.expectEqual(@as(u32, 1), ring.sq.sqe_head);
+ try testing.expectEqual(@as(u32, 1), ring.sq.sqe_tail);
+ try testing.expectEqual(@as(u32, 1), ring.sq.tail.*);
+ try testing.expectEqual(@as(u32, 0), ring.cq.head.*);
+ try testing.expectEqual(@as(u32, 0), ring.sq_ready());
+
+ try testing.expectEqual(io_uring_cqe{
.user_data = 0xaaaaaaaa,
.res = 0,
.flags = 0,
}, try ring.copy_cqe());
- testing.expectEqual(@as(u32, 1), ring.cq.head.*);
- testing.expectEqual(@as(u32, 0), ring.cq_ready());
+ try testing.expectEqual(@as(u32, 1), ring.cq.head.*);
+ try testing.expectEqual(@as(u32, 0), ring.cq_ready());
const sqe_barrier = try ring.nop(0xbbbbbbbb);
sqe_barrier.flags |= linux.IOSQE_IO_DRAIN;
- testing.expectEqual(@as(u32, 1), try ring.submit());
- testing.expectEqual(io_uring_cqe{
+ try testing.expectEqual(@as(u32, 1), try ring.submit());
+ try testing.expectEqual(io_uring_cqe{
.user_data = 0xbbbbbbbb,
.res = 0,
.flags = 0,
}, try ring.copy_cqe());
- testing.expectEqual(@as(u32, 2), ring.sq.sqe_head);
- testing.expectEqual(@as(u32, 2), ring.sq.sqe_tail);
- testing.expectEqual(@as(u32, 2), ring.sq.tail.*);
- testing.expectEqual(@as(u32, 2), ring.cq.head.*);
+ try testing.expectEqual(@as(u32, 2), ring.sq.sqe_head);
+ try testing.expectEqual(@as(u32, 2), ring.sq.sqe_tail);
+ try testing.expectEqual(@as(u32, 2), ring.sq.tail.*);
+ try testing.expectEqual(@as(u32, 2), ring.cq.head.*);
}
test "readv" {
@@ -1042,17 +1042,17 @@ test "readv" {
var buffer = [_]u8{42} ** 128;
var iovecs = [_]os.iovec{os.iovec{ .iov_base = &buffer, .iov_len = buffer.len }};
const sqe = try ring.readv(0xcccccccc, fd_index, iovecs[0..], 0);
- testing.expectEqual(linux.IORING_OP.READV, sqe.opcode);
+ try testing.expectEqual(linux.IORING_OP.READV, sqe.opcode);
sqe.flags |= linux.IOSQE_FIXED_FILE;
- testing.expectError(error.SubmissionQueueFull, ring.nop(0));
- testing.expectEqual(@as(u32, 1), try ring.submit());
- testing.expectEqual(linux.io_uring_cqe{
+ try testing.expectError(error.SubmissionQueueFull, ring.nop(0));
+ try testing.expectEqual(@as(u32, 1), try ring.submit());
+ try testing.expectEqual(linux.io_uring_cqe{
.user_data = 0xcccccccc,
.res = buffer.len,
.flags = 0,
}, try ring.copy_cqe());
- testing.expectEqualSlices(u8, &([_]u8{0} ** buffer.len), buffer[0..]);
+ try testing.expectEqualSlices(u8, &([_]u8{0} ** buffer.len), buffer[0..]);
try ring.unregister_files();
}
@@ -1083,46 +1083,46 @@ test "writev/fsync/readv" {
};
const sqe_writev = try ring.writev(0xdddddddd, fd, iovecs_write[0..], 17);
- testing.expectEqual(linux.IORING_OP.WRITEV, sqe_writev.opcode);
- testing.expectEqual(@as(u64, 17), sqe_writev.off);
+ try testing.expectEqual(linux.IORING_OP.WRITEV, sqe_writev.opcode);
+ try testing.expectEqual(@as(u64, 17), sqe_writev.off);
sqe_writev.flags |= linux.IOSQE_IO_LINK;
const sqe_fsync = try ring.fsync(0xeeeeeeee, fd, 0);
- testing.expectEqual(linux.IORING_OP.FSYNC, sqe_fsync.opcode);
- testing.expectEqual(fd, sqe_fsync.fd);
+ try testing.expectEqual(linux.IORING_OP.FSYNC, sqe_fsync.opcode);
+ try testing.expectEqual(fd, sqe_fsync.fd);
sqe_fsync.flags |= linux.IOSQE_IO_LINK;
const sqe_readv = try ring.readv(0xffffffff, fd, iovecs_read[0..], 17);
- testing.expectEqual(linux.IORING_OP.READV, sqe_readv.opcode);
- testing.expectEqual(@as(u64, 17), sqe_readv.off);
+ try testing.expectEqual(linux.IORING_OP.READV, sqe_readv.opcode);
+ try testing.expectEqual(@as(u64, 17), sqe_readv.off);
- testing.expectEqual(@as(u32, 3), ring.sq_ready());
- testing.expectEqual(@as(u32, 3), try ring.submit_and_wait(3));
- testing.expectEqual(@as(u32, 0), ring.sq_ready());
- testing.expectEqual(@as(u32, 3), ring.cq_ready());
+ try testing.expectEqual(@as(u32, 3), ring.sq_ready());
+ try testing.expectEqual(@as(u32, 3), try ring.submit_and_wait(3));
+ try testing.expectEqual(@as(u32, 0), ring.sq_ready());
+ try testing.expectEqual(@as(u32, 3), ring.cq_ready());
- testing.expectEqual(linux.io_uring_cqe{
+ try testing.expectEqual(linux.io_uring_cqe{
.user_data = 0xdddddddd,
.res = buffer_write.len,
.flags = 0,
}, try ring.copy_cqe());
- testing.expectEqual(@as(u32, 2), ring.cq_ready());
+ try testing.expectEqual(@as(u32, 2), ring.cq_ready());
- testing.expectEqual(linux.io_uring_cqe{
+ try testing.expectEqual(linux.io_uring_cqe{
.user_data = 0xeeeeeeee,
.res = 0,
.flags = 0,
}, try ring.copy_cqe());
- testing.expectEqual(@as(u32, 1), ring.cq_ready());
+ try testing.expectEqual(@as(u32, 1), ring.cq_ready());
- testing.expectEqual(linux.io_uring_cqe{
+ try testing.expectEqual(linux.io_uring_cqe{
.user_data = 0xffffffff,
.res = buffer_read.len,
.flags = 0,
}, try ring.copy_cqe());
- testing.expectEqual(@as(u32, 0), ring.cq_ready());
+ try testing.expectEqual(@as(u32, 0), ring.cq_ready());
- testing.expectEqualSlices(u8, buffer_write[0..], buffer_read[0..]);
+ try testing.expectEqualSlices(u8, buffer_write[0..], buffer_read[0..]);
}
test "write/read" {
@@ -1144,13 +1144,13 @@ test "write/read" {
const buffer_write = [_]u8{97} ** 20;
var buffer_read = [_]u8{98} ** 20;
const sqe_write = try ring.write(0x11111111, fd, buffer_write[0..], 10);
- testing.expectEqual(linux.IORING_OP.WRITE, sqe_write.opcode);
- testing.expectEqual(@as(u64, 10), sqe_write.off);
+ try testing.expectEqual(linux.IORING_OP.WRITE, sqe_write.opcode);
+ try testing.expectEqual(@as(u64, 10), sqe_write.off);
sqe_write.flags |= linux.IOSQE_IO_LINK;
const sqe_read = try ring.read(0x22222222, fd, buffer_read[0..], 10);
- testing.expectEqual(linux.IORING_OP.READ, sqe_read.opcode);
- testing.expectEqual(@as(u64, 10), sqe_read.off);
- testing.expectEqual(@as(u32, 2), try ring.submit());
+ try testing.expectEqual(linux.IORING_OP.READ, sqe_read.opcode);
+ try testing.expectEqual(@as(u64, 10), sqe_read.off);
+ try testing.expectEqual(@as(u32, 2), try ring.submit());
const cqe_write = try ring.copy_cqe();
const cqe_read = try ring.copy_cqe();
@@ -1158,17 +1158,17 @@ test "write/read" {
// https://lwn.net/Articles/809820/
if (cqe_write.res == -linux.EINVAL) return error.SkipZigTest;
if (cqe_read.res == -linux.EINVAL) return error.SkipZigTest;
- testing.expectEqual(linux.io_uring_cqe{
+ try testing.expectEqual(linux.io_uring_cqe{
.user_data = 0x11111111,
.res = buffer_write.len,
.flags = 0,
}, cqe_write);
- testing.expectEqual(linux.io_uring_cqe{
+ try testing.expectEqual(linux.io_uring_cqe{
.user_data = 0x22222222,
.res = buffer_read.len,
.flags = 0,
}, cqe_read);
- testing.expectEqualSlices(u8, buffer_write[0..], buffer_read[0..]);
+ try testing.expectEqualSlices(u8, buffer_write[0..], buffer_read[0..]);
}
test "openat" {
@@ -1187,7 +1187,7 @@ test "openat" {
const flags: u32 = os.O_CLOEXEC | os.O_RDWR | os.O_CREAT;
const mode: os.mode_t = 0o666;
const sqe_openat = try ring.openat(0x33333333, linux.AT_FDCWD, path, flags, mode);
- testing.expectEqual(io_uring_sqe{
+ try testing.expectEqual(io_uring_sqe{
.opcode = .OPENAT,
.flags = 0,
.ioprio = 0,
@@ -1202,10 +1202,10 @@ test "openat" {
.splice_fd_in = 0,
.__pad2 = [2]u64{ 0, 0 },
}, sqe_openat.*);
- testing.expectEqual(@as(u32, 1), try ring.submit());
+ try testing.expectEqual(@as(u32, 1), try ring.submit());
const cqe_openat = try ring.copy_cqe();
- testing.expectEqual(@as(u64, 0x33333333), cqe_openat.user_data);
+ try testing.expectEqual(@as(u64, 0x33333333), cqe_openat.user_data);
if (cqe_openat.res == -linux.EINVAL) return error.SkipZigTest;
// AT_FDCWD is not fully supported before kernel 5.6:
// See https://lore.kernel.org/io-uring/20200207155039.12819-1-axboe@kernel.dk/T/
@@ -1214,8 +1214,8 @@ test "openat" {
return error.SkipZigTest;
}
if (cqe_openat.res <= 0) std.debug.print("\ncqe_openat.res={}\n", .{cqe_openat.res});
- testing.expect(cqe_openat.res > 0);
- testing.expectEqual(@as(u32, 0), cqe_openat.flags);
+ try testing.expect(cqe_openat.res > 0);
+ try testing.expectEqual(@as(u32, 0), cqe_openat.flags);
os.close(cqe_openat.res);
}
@@ -1236,13 +1236,13 @@ test "close" {
defer std.fs.cwd().deleteFile(path) catch {};
const sqe_close = try ring.close(0x44444444, file.handle);
- testing.expectEqual(linux.IORING_OP.CLOSE, sqe_close.opcode);
- testing.expectEqual(file.handle, sqe_close.fd);
- testing.expectEqual(@as(u32, 1), try ring.submit());
+ try testing.expectEqual(linux.IORING_OP.CLOSE, sqe_close.opcode);
+ try testing.expectEqual(file.handle, sqe_close.fd);
+ try testing.expectEqual(@as(u32, 1), try ring.submit());
const cqe_close = try ring.copy_cqe();
if (cqe_close.res == -linux.EINVAL) return error.SkipZigTest;
- testing.expectEqual(linux.io_uring_cqe{
+ try testing.expectEqual(linux.io_uring_cqe{
.user_data = 0x44444444,
.res = 0,
.flags = 0,
@@ -1273,12 +1273,12 @@ test "accept/connect/send/recv" {
var accept_addr: os.sockaddr = undefined;
var accept_addr_len: os.socklen_t = @sizeOf(@TypeOf(accept_addr));
const accept = try ring.accept(0xaaaaaaaa, server, &accept_addr, &accept_addr_len, 0);
- testing.expectEqual(@as(u32, 1), try ring.submit());
+ try testing.expectEqual(@as(u32, 1), try ring.submit());
const client = try os.socket(address.any.family, os.SOCK_STREAM | os.SOCK_CLOEXEC, 0);
defer os.close(client);
const connect = try ring.connect(0xcccccccc, client, &address.any, address.getOsSockLen());
- testing.expectEqual(@as(u32, 1), try ring.submit());
+ try testing.expectEqual(@as(u32, 1), try ring.submit());
var cqe_accept = try ring.copy_cqe();
if (cqe_accept.res == -linux.EINVAL) return error.SkipZigTest;
@@ -1293,11 +1293,11 @@ test "accept/connect/send/recv" {
cqe_connect = a;
}
- testing.expectEqual(@as(u64, 0xaaaaaaaa), cqe_accept.user_data);
+ try testing.expectEqual(@as(u64, 0xaaaaaaaa), cqe_accept.user_data);
if (cqe_accept.res <= 0) std.debug.print("\ncqe_accept.res={}\n", .{cqe_accept.res});
- testing.expect(cqe_accept.res > 0);
- testing.expectEqual(@as(u32, 0), cqe_accept.flags);
- testing.expectEqual(linux.io_uring_cqe{
+ try testing.expect(cqe_accept.res > 0);
+ try testing.expectEqual(@as(u32, 0), cqe_accept.flags);
+ try testing.expectEqual(linux.io_uring_cqe{
.user_data = 0xcccccccc,
.res = 0,
.flags = 0,
@@ -1306,11 +1306,11 @@ test "accept/connect/send/recv" {
const send = try ring.send(0xeeeeeeee, client, buffer_send[0..], 0);
send.flags |= linux.IOSQE_IO_LINK;
const recv = try ring.recv(0xffffffff, cqe_accept.res, buffer_recv[0..], 0);
- testing.expectEqual(@as(u32, 2), try ring.submit());
+ try testing.expectEqual(@as(u32, 2), try ring.submit());
const cqe_send = try ring.copy_cqe();
if (cqe_send.res == -linux.EINVAL) return error.SkipZigTest;
- testing.expectEqual(linux.io_uring_cqe{
+ try testing.expectEqual(linux.io_uring_cqe{
.user_data = 0xeeeeeeee,
.res = buffer_send.len,
.flags = 0,
@@ -1318,13 +1318,13 @@ test "accept/connect/send/recv" {
const cqe_recv = try ring.copy_cqe();
if (cqe_recv.res == -linux.EINVAL) return error.SkipZigTest;
- testing.expectEqual(linux.io_uring_cqe{
+ try testing.expectEqual(linux.io_uring_cqe{
.user_data = 0xffffffff,
.res = buffer_recv.len,
.flags = 0,
}, cqe_recv);
- testing.expectEqualSlices(u8, buffer_send[0..buffer_recv.len], buffer_recv[0..]);
+ try testing.expectEqualSlices(u8, buffer_send[0..buffer_recv.len], buffer_recv[0..]);
}
test "timeout (after a relative time)" {
@@ -1343,12 +1343,12 @@ test "timeout (after a relative time)" {
const started = std.time.milliTimestamp();
const sqe = try ring.timeout(0x55555555, &ts, 0, 0);
- testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe.opcode);
- testing.expectEqual(@as(u32, 1), try ring.submit());
+ try testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe.opcode);
+ try testing.expectEqual(@as(u32, 1), try ring.submit());
const cqe = try ring.copy_cqe();
const stopped = std.time.milliTimestamp();
- testing.expectEqual(linux.io_uring_cqe{
+ try testing.expectEqual(linux.io_uring_cqe{
.user_data = 0x55555555,
.res = -linux.ETIME,
.flags = 0,
@@ -1371,20 +1371,20 @@ test "timeout (after a number of completions)" {
const ts = os.__kernel_timespec{ .tv_sec = 3, .tv_nsec = 0 };
const count_completions: u64 = 1;
const sqe_timeout = try ring.timeout(0x66666666, &ts, count_completions, 0);
- testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe_timeout.opcode);
- testing.expectEqual(count_completions, sqe_timeout.off);
+ try testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe_timeout.opcode);
+ try testing.expectEqual(count_completions, sqe_timeout.off);
_ = try ring.nop(0x77777777);
- testing.expectEqual(@as(u32, 2), try ring.submit());
+ try testing.expectEqual(@as(u32, 2), try ring.submit());
const cqe_nop = try ring.copy_cqe();
- testing.expectEqual(linux.io_uring_cqe{
+ try testing.expectEqual(linux.io_uring_cqe{
.user_data = 0x77777777,
.res = 0,
.flags = 0,
}, cqe_nop);
const cqe_timeout = try ring.copy_cqe();
- testing.expectEqual(linux.io_uring_cqe{
+ try testing.expectEqual(linux.io_uring_cqe{
.user_data = 0x66666666,
.res = 0,
.flags = 0,
@@ -1403,15 +1403,15 @@ test "timeout_remove" {
const ts = os.__kernel_timespec{ .tv_sec = 3, .tv_nsec = 0 };
const sqe_timeout = try ring.timeout(0x88888888, &ts, 0, 0);
- testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe_timeout.opcode);
- testing.expectEqual(@as(u64, 0x88888888), sqe_timeout.user_data);
+ try testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe_timeout.opcode);
+ try testing.expectEqual(@as(u64, 0x88888888), sqe_timeout.user_data);
const sqe_timeout_remove = try ring.timeout_remove(0x99999999, 0x88888888, 0);
- testing.expectEqual(linux.IORING_OP.TIMEOUT_REMOVE, sqe_timeout_remove.opcode);
- testing.expectEqual(@as(u64, 0x88888888), sqe_timeout_remove.addr);
- testing.expectEqual(@as(u64, 0x99999999), sqe_timeout_remove.user_data);
+ try testing.expectEqual(linux.IORING_OP.TIMEOUT_REMOVE, sqe_timeout_remove.opcode);
+ try testing.expectEqual(@as(u64, 0x88888888), sqe_timeout_remove.addr);
+ try testing.expectEqual(@as(u64, 0x99999999), sqe_timeout_remove.user_data);
- testing.expectEqual(@as(u32, 2), try ring.submit());
+ try testing.expectEqual(@as(u32, 2), try ring.submit());
const cqe_timeout = try ring.copy_cqe();
// IORING_OP_TIMEOUT_REMOVE is not supported by this kernel version:
@@ -1424,14 +1424,14 @@ test "timeout_remove" {
{
return error.SkipZigTest;
}
- testing.expectEqual(linux.io_uring_cqe{
+ try testing.expectEqual(linux.io_uring_cqe{
.user_data = 0x88888888,
.res = -linux.ECANCELED,
.flags = 0,
}, cqe_timeout);
const cqe_timeout_remove = try ring.copy_cqe();
- testing.expectEqual(linux.io_uring_cqe{
+ try testing.expectEqual(linux.io_uring_cqe{
.user_data = 0x99999999,
.res = 0,
.flags = 0,
@@ -1453,13 +1453,13 @@ test "fallocate" {
defer file.close();
defer std.fs.cwd().deleteFile(path) catch {};
- testing.expectEqual(@as(u64, 0), (try file.stat()).size);
+ try testing.expectEqual(@as(u64, 0), (try file.stat()).size);
const len: u64 = 65536;
const sqe = try ring.fallocate(0xaaaaaaaa, file.handle, 0, 0, len);
- testing.expectEqual(linux.IORING_OP.FALLOCATE, sqe.opcode);
- testing.expectEqual(file.handle, sqe.fd);
- testing.expectEqual(@as(u32, 1), try ring.submit());
+ try testing.expectEqual(linux.IORING_OP.FALLOCATE, sqe.opcode);
+ try testing.expectEqual(file.handle, sqe.fd);
+ try testing.expectEqual(@as(u32, 1), try ring.submit());
const cqe = try ring.copy_cqe();
switch (-cqe.res) {
@@ -1473,11 +1473,11 @@ test "fallocate" {
linux.EOPNOTSUPP => return error.SkipZigTest,
else => |errno| std.debug.panic("unhandled errno: {}", .{errno}),
}
- testing.expectEqual(linux.io_uring_cqe{
+ try testing.expectEqual(linux.io_uring_cqe{
.user_data = 0xaaaaaaaa,
.res = 0,
.flags = 0,
}, cqe);
- testing.expectEqual(len, (try file.stat()).size);
+ try testing.expectEqual(len, (try file.stat()).size);
}
lib/std/os/linux/test.zig
@@ -18,7 +18,7 @@ test "fallocate" {
defer file.close();
defer fs.cwd().deleteFile(path) catch {};
- expect((try file.stat()).size == 0);
+ try expect((try file.stat()).size == 0);
const len: u64 = 65536;
switch (linux.getErrno(linux.fallocate(file.handle, 0, 0, len))) {
@@ -28,20 +28,20 @@ test "fallocate" {
else => |errno| std.debug.panic("unhandled errno: {}", .{errno}),
}
- expect((try file.stat()).size == len);
+ try expect((try file.stat()).size == len);
}
test "getpid" {
- expect(linux.getpid() != 0);
+ try expect(linux.getpid() != 0);
}
test "timer" {
const epoll_fd = linux.epoll_create();
var err: usize = linux.getErrno(epoll_fd);
- expect(err == 0);
+ try expect(err == 0);
const timer_fd = linux.timerfd_create(linux.CLOCK_MONOTONIC, 0);
- expect(linux.getErrno(timer_fd) == 0);
+ try expect(linux.getErrno(timer_fd) == 0);
const time_interval = linux.timespec{
.tv_sec = 0,
@@ -54,7 +54,7 @@ test "timer" {
};
err = linux.timerfd_settime(@intCast(i32, timer_fd), 0, &new_time, null);
- expect(err == 0);
+ try expect(err == 0);
var event = linux.epoll_event{
.events = linux.EPOLLIN | linux.EPOLLOUT | linux.EPOLLET,
@@ -62,7 +62,7 @@ test "timer" {
};
err = linux.epoll_ctl(@intCast(i32, epoll_fd), linux.EPOLL_CTL_ADD, @intCast(i32, timer_fd), &event);
- expect(err == 0);
+ try expect(err == 0);
const events_one: linux.epoll_event = undefined;
var events = [_]linux.epoll_event{events_one} ** 8;
@@ -93,18 +93,18 @@ test "statx" {
else => unreachable,
}
- expect(stat_buf.mode == statx_buf.mode);
- expect(@bitCast(u32, stat_buf.uid) == statx_buf.uid);
- expect(@bitCast(u32, stat_buf.gid) == statx_buf.gid);
- expect(@bitCast(u64, @as(i64, stat_buf.size)) == statx_buf.size);
- expect(@bitCast(u64, @as(i64, stat_buf.blksize)) == statx_buf.blksize);
- expect(@bitCast(u64, @as(i64, stat_buf.blocks)) == statx_buf.blocks);
+ try expect(stat_buf.mode == statx_buf.mode);
+ try expect(@bitCast(u32, stat_buf.uid) == statx_buf.uid);
+ try expect(@bitCast(u32, stat_buf.gid) == statx_buf.gid);
+ try expect(@bitCast(u64, @as(i64, stat_buf.size)) == statx_buf.size);
+ try expect(@bitCast(u64, @as(i64, stat_buf.blksize)) == statx_buf.blksize);
+ try expect(@bitCast(u64, @as(i64, stat_buf.blocks)) == statx_buf.blocks);
}
test "user and group ids" {
if (builtin.link_libc) return error.SkipZigTest;
- expectEqual(linux.getauxval(elf.AT_UID), linux.getuid());
- expectEqual(linux.getauxval(elf.AT_GID), linux.getgid());
- expectEqual(linux.getauxval(elf.AT_EUID), linux.geteuid());
- expectEqual(linux.getauxval(elf.AT_EGID), linux.getegid());
+ try expectEqual(linux.getauxval(elf.AT_UID), linux.getuid());
+ try expectEqual(linux.getauxval(elf.AT_GID), linux.getgid());
+ try expectEqual(linux.getauxval(elf.AT_EUID), linux.geteuid());
+ try expectEqual(linux.getauxval(elf.AT_EGID), linux.getegid());
}
lib/std/os/test.zig
@@ -37,7 +37,7 @@ test "chdir smoke test" {
try os.chdir(old_cwd);
var new_cwd_buf: [fs.MAX_PATH_BYTES]u8 = undefined;
const new_cwd = try os.getcwd(new_cwd_buf[0..]);
- expect(mem.eql(u8, old_cwd, new_cwd));
+ try expect(mem.eql(u8, old_cwd, new_cwd));
}
{
// Next, change current working directory to one level above
@@ -45,7 +45,7 @@ test "chdir smoke test" {
try os.chdir(parent);
var new_cwd_buf: [fs.MAX_PATH_BYTES]u8 = undefined;
const new_cwd = try os.getcwd(new_cwd_buf[0..]);
- expect(mem.eql(u8, parent, new_cwd));
+ try expect(mem.eql(u8, parent, new_cwd));
}
}
@@ -77,7 +77,7 @@ test "open smoke test" {
// Try this again with the same flags. This op should fail with error.PathAlreadyExists.
file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_file" });
- expectError(error.PathAlreadyExists, os.open(file_path, os.O_RDWR | os.O_CREAT | os.O_EXCL, mode));
+ try expectError(error.PathAlreadyExists, os.open(file_path, os.O_RDWR | os.O_CREAT | os.O_EXCL, mode));
// Try opening without `O_EXCL` flag.
file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_file" });
@@ -86,7 +86,7 @@ test "open smoke test" {
// Try opening as a directory which should fail.
file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_file" });
- expectError(error.NotDir, os.open(file_path, os.O_RDWR | os.O_DIRECTORY, mode));
+ try expectError(error.NotDir, os.open(file_path, os.O_RDWR | os.O_DIRECTORY, mode));
// Create some directory
file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_dir" });
@@ -99,7 +99,7 @@ test "open smoke test" {
// Try opening as file which should fail.
file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_dir" });
- expectError(error.IsDir, os.open(file_path, os.O_RDWR, mode));
+ try expectError(error.IsDir, os.open(file_path, os.O_RDWR, mode));
}
test "openat smoke test" {
@@ -118,14 +118,14 @@ test "openat smoke test" {
os.close(fd);
// Try this again with the same flags. This op should fail with error.PathAlreadyExists.
- expectError(error.PathAlreadyExists, os.openat(tmp.dir.fd, "some_file", os.O_RDWR | os.O_CREAT | os.O_EXCL, mode));
+ try expectError(error.PathAlreadyExists, os.openat(tmp.dir.fd, "some_file", os.O_RDWR | os.O_CREAT | os.O_EXCL, mode));
// Try opening without `O_EXCL` flag.
fd = try os.openat(tmp.dir.fd, "some_file", os.O_RDWR | os.O_CREAT, mode);
os.close(fd);
// Try opening as a directory which should fail.
- expectError(error.NotDir, os.openat(tmp.dir.fd, "some_file", os.O_RDWR | os.O_DIRECTORY, mode));
+ try expectError(error.NotDir, os.openat(tmp.dir.fd, "some_file", os.O_RDWR | os.O_DIRECTORY, mode));
// Create some directory
try os.mkdirat(tmp.dir.fd, "some_dir", mode);
@@ -135,7 +135,7 @@ test "openat smoke test" {
os.close(fd);
// Try opening as file which should fail.
- expectError(error.IsDir, os.openat(tmp.dir.fd, "some_dir", os.O_RDWR, mode));
+ try expectError(error.IsDir, os.openat(tmp.dir.fd, "some_dir", os.O_RDWR, mode));
}
test "symlink with relative paths" {
@@ -169,7 +169,7 @@ test "symlink with relative paths" {
var buffer: [fs.MAX_PATH_BYTES]u8 = undefined;
const given = try os.readlink("symlinked", buffer[0..]);
- expect(mem.eql(u8, "file.txt", given));
+ try expect(mem.eql(u8, "file.txt", given));
try cwd.deleteFile("file.txt");
try cwd.deleteFile("symlinked");
@@ -186,7 +186,7 @@ test "readlink on Windows" {
fn testReadlink(target_path: []const u8, symlink_path: []const u8) !void {
var buffer: [fs.MAX_PATH_BYTES]u8 = undefined;
const given = try os.readlink(symlink_path, buffer[0..]);
- expect(mem.eql(u8, target_path, given));
+ try expect(mem.eql(u8, target_path, given));
}
test "link with relative paths" {
@@ -209,15 +209,15 @@ test "link with relative paths" {
const estat = try os.fstat(efd.handle);
const nstat = try os.fstat(nfd.handle);
- testing.expectEqual(estat.ino, nstat.ino);
- testing.expectEqual(@as(usize, 2), nstat.nlink);
+ try testing.expectEqual(estat.ino, nstat.ino);
+ try testing.expectEqual(@as(usize, 2), nstat.nlink);
}
try os.unlink("new.txt");
{
const estat = try os.fstat(efd.handle);
- testing.expectEqual(@as(usize, 1), estat.nlink);
+ try testing.expectEqual(@as(usize, 1), estat.nlink);
}
try cwd.deleteFile("example.txt");
@@ -244,15 +244,15 @@ test "linkat with different directories" {
const estat = try os.fstat(efd.handle);
const nstat = try os.fstat(nfd.handle);
- testing.expectEqual(estat.ino, nstat.ino);
- testing.expectEqual(@as(usize, 2), nstat.nlink);
+ try testing.expectEqual(estat.ino, nstat.ino);
+ try testing.expectEqual(@as(usize, 2), nstat.nlink);
}
try os.unlinkat(tmp.dir.fd, "new.txt", 0);
{
const estat = try os.fstat(efd.handle);
- testing.expectEqual(@as(usize, 1), estat.nlink);
+ try testing.expectEqual(@as(usize, 1), estat.nlink);
}
try cwd.deleteFile("example.txt");
@@ -281,7 +281,7 @@ test "fstatat" {
// now repeat but using `fstatat` instead
const flags = if (builtin.os.tag == .wasi) 0x0 else os.AT_SYMLINK_NOFOLLOW;
const statat = try os.fstatat(tmp.dir.fd, "file.txt", flags);
- expectEqual(stat, statat);
+ try expectEqual(stat, statat);
}
test "readlinkat" {
@@ -310,7 +310,7 @@ test "readlinkat" {
// read the link
var buffer: [fs.MAX_PATH_BYTES]u8 = undefined;
const read_link = try os.readlinkat(tmp.dir.fd, "link", buffer[0..]);
- expect(mem.eql(u8, "file.txt", read_link));
+ try expect(mem.eql(u8, "file.txt", read_link));
}
fn testThreadIdFn(thread_id: *Thread.Id) void {
@@ -325,13 +325,13 @@ test "std.Thread.getCurrentId" {
const thread_id = thread.handle();
thread.wait();
if (Thread.use_pthreads) {
- expect(thread_current_id == thread_id);
+ try expect(thread_current_id == thread_id);
} else if (builtin.os.tag == .windows) {
- expect(Thread.getCurrentId() != thread_current_id);
+ try expect(Thread.getCurrentId() != thread_current_id);
} else {
// If the thread completes very quickly, then thread_id can be 0. See the
// documentation comments for `std.Thread.handle`.
- expect(thread_id == 0 or thread_current_id == thread_id);
+ try expect(thread_id == 0 or thread_current_id == thread_id);
}
}
@@ -350,7 +350,7 @@ test "spawn threads" {
thread3.wait();
thread4.wait();
- expect(shared_ctx == 4);
+ try expect(shared_ctx == 4);
}
fn start1(ctx: void) u8 {
@@ -366,23 +366,23 @@ test "cpu count" {
if (builtin.os.tag == .wasi) return error.SkipZigTest;
const cpu_count = try Thread.cpuCount();
- expect(cpu_count >= 1);
+ try expect(cpu_count >= 1);
}
test "thread local storage" {
if (builtin.single_threaded) return error.SkipZigTest;
const thread1 = try Thread.spawn(testTls, {});
const thread2 = try Thread.spawn(testTls, {});
- testTls({});
+ try testTls({});
thread1.wait();
thread2.wait();
}
threadlocal var x: i32 = 1234;
-fn testTls(context: void) void {
- if (x != 1234) @panic("bad start value");
+fn testTls(context: void) !void {
+ if (x != 1234) return error.TlsBadStartValue;
x += 1;
- if (x != 1235) @panic("bad end value");
+ if (x != 1235) return error.TlsBadEndValue;
}
test "getrandom" {
@@ -392,7 +392,7 @@ test "getrandom" {
try os.getrandom(&buf_b);
// If this test fails the chance is significantly higher that there is a bug than
// that two sets of 50 bytes were equal.
- expect(!mem.eql(u8, &buf_a, &buf_b));
+ try expect(!mem.eql(u8, &buf_a, &buf_b));
}
test "getcwd" {
@@ -411,7 +411,7 @@ test "sigaltstack" {
// Setting a stack size less than MINSIGSTKSZ returns ENOMEM
st.ss_flags = 0;
st.ss_size = 1;
- testing.expectError(error.SizeTooSmall, os.sigaltstack(&st, null));
+ try testing.expectError(error.SizeTooSmall, os.sigaltstack(&st, null));
}
// If the type is not available use void to avoid erroring out when `iter_fn` is
@@ -462,7 +462,7 @@ test "dl_iterate_phdr" {
var counter: usize = 0;
try os.dl_iterate_phdr(&counter, IterFnError, iter_fn);
- expect(counter != 0);
+ try expect(counter != 0);
}
test "gethostname" {
@@ -471,7 +471,7 @@ test "gethostname" {
var buf: [os.HOST_NAME_MAX]u8 = undefined;
const hostname = try os.gethostname(&buf);
- expect(hostname.len != 0);
+ try expect(hostname.len != 0);
}
test "pipe" {
@@ -479,10 +479,10 @@ test "pipe" {
return error.SkipZigTest;
var fds = try os.pipe();
- expect((try os.write(fds[1], "hello")) == 5);
+ try expect((try os.write(fds[1], "hello")) == 5);
var buf: [16]u8 = undefined;
- expect((try os.read(fds[0], buf[0..])) == 5);
- testing.expectEqualSlices(u8, buf[0..5], "hello");
+ try expect((try os.read(fds[0], buf[0..])) == 5);
+ try testing.expectEqualSlices(u8, buf[0..5], "hello");
os.close(fds[1]);
os.close(fds[0]);
}
@@ -501,13 +501,13 @@ test "memfd_create" {
else => |e| return e,
};
defer std.os.close(fd);
- expect((try std.os.write(fd, "test")) == 4);
+ try expect((try std.os.write(fd, "test")) == 4);
try std.os.lseek_SET(fd, 0);
var buf: [10]u8 = undefined;
const bytes_read = try std.os.read(fd, &buf);
- expect(bytes_read == 4);
- expect(mem.eql(u8, buf[0..4], "test"));
+ try expect(bytes_read == 4);
+ try expect(mem.eql(u8, buf[0..4], "test"));
}
test "mmap" {
@@ -529,14 +529,14 @@ test "mmap" {
);
defer os.munmap(data);
- testing.expectEqual(@as(usize, 1234), data.len);
+ try testing.expectEqual(@as(usize, 1234), data.len);
// By definition the data returned by mmap is zero-filled
- testing.expect(mem.eql(u8, data, &[_]u8{0x00} ** 1234));
+ try testing.expect(mem.eql(u8, data, &[_]u8{0x00} ** 1234));
// Make sure the memory is writeable as requested
std.mem.set(u8, data, 0x55);
- testing.expect(mem.eql(u8, data, &[_]u8{0x55} ** 1234));
+ try testing.expect(mem.eql(u8, data, &[_]u8{0x55} ** 1234));
}
const test_out_file = "os_tmp_test";
@@ -576,7 +576,7 @@ test "mmap" {
var i: u32 = 0;
while (i < alloc_size / @sizeOf(u32)) : (i += 1) {
- testing.expectEqual(i, try stream.readIntNative(u32));
+ try testing.expectEqual(i, try stream.readIntNative(u32));
}
}
@@ -600,7 +600,7 @@ test "mmap" {
var i: u32 = alloc_size / 2 / @sizeOf(u32);
while (i < alloc_size / @sizeOf(u32)) : (i += 1) {
- testing.expectEqual(i, try stream.readIntNative(u32));
+ try testing.expectEqual(i, try stream.readIntNative(u32));
}
}
@@ -609,9 +609,9 @@ test "mmap" {
test "getenv" {
if (builtin.os.tag == .windows) {
- expect(os.getenvW(&[_:0]u16{ 'B', 'O', 'G', 'U', 'S', 0x11, 0x22, 0x33, 0x44, 0x55 }) == null);
+ try expect(os.getenvW(&[_:0]u16{ 'B', 'O', 'G', 'U', 'S', 0x11, 0x22, 0x33, 0x44, 0x55 }) == null);
} else {
- expect(os.getenvZ("BOGUSDOESNOTEXISTENVVAR") == null);
+ try expect(os.getenvZ("BOGUSDOESNOTEXISTENVVAR") == null);
}
}
@@ -633,17 +633,17 @@ test "fcntl" {
// Note: The test assumes createFile opens the file with O_CLOEXEC
{
const flags = try os.fcntl(file.handle, os.F_GETFD, 0);
- expect((flags & os.FD_CLOEXEC) != 0);
+ try expect((flags & os.FD_CLOEXEC) != 0);
}
{
_ = try os.fcntl(file.handle, os.F_SETFD, 0);
const flags = try os.fcntl(file.handle, os.F_GETFD, 0);
- expect((flags & os.FD_CLOEXEC) == 0);
+ try expect((flags & os.FD_CLOEXEC) == 0);
}
{
_ = try os.fcntl(file.handle, os.F_SETFD, os.FD_CLOEXEC);
const flags = try os.fcntl(file.handle, os.F_GETFD, 0);
- expect((flags & os.FD_CLOEXEC) != 0);
+ try expect((flags & os.FD_CLOEXEC) != 0);
}
}
@@ -748,12 +748,12 @@ test "sigaction" {
os.sigaction(os.SIGUSR1, &sa, null);
// Check that we can read it back correctly.
os.sigaction(os.SIGUSR1, null, &old_sa);
- testing.expectEqual(S.handler, old_sa.handler.sigaction.?);
- testing.expect((old_sa.flags & os.SA_SIGINFO) != 0);
+ try testing.expectEqual(S.handler, old_sa.handler.sigaction.?);
+ try testing.expect((old_sa.flags & os.SA_SIGINFO) != 0);
// Invoke the handler.
try os.raise(os.SIGUSR1);
- testing.expect(signal_test_failed == false);
+ try testing.expect(signal_test_failed == false);
// Check if the handler has been correctly reset to SIG_DFL
os.sigaction(os.SIGUSR1, null, &old_sa);
- testing.expectEqual(os.SIG_DFL, old_sa.handler.sigaction);
+ try testing.expectEqual(os.SIG_DFL, old_sa.handler.sigaction);
}
lib/std/os/windows.zig
@@ -997,7 +997,7 @@ test "QueryObjectName" {
var result_path = try QueryObjectName(handle, &out_buffer);
const required_len_in_u16 = result_path.len + @divExact(@ptrToInt(result_path.ptr) - @ptrToInt(&out_buffer), 2) + 1;
//insufficient size
- std.testing.expectError(error.NameTooLong, QueryObjectName(handle, out_buffer[0 .. required_len_in_u16 - 1]));
+ try std.testing.expectError(error.NameTooLong, QueryObjectName(handle, out_buffer[0 .. required_len_in_u16 - 1]));
//exactly-sufficient size
_ = try QueryObjectName(handle, out_buffer[0..required_len_in_u16]);
}
@@ -1155,8 +1155,8 @@ test "GetFinalPathNameByHandle" {
const required_len_in_u16 = nt_path.len + @divExact(@ptrToInt(nt_path.ptr) - @ptrToInt(&buffer), 2) + 1;
//check with insufficient size
- std.testing.expectError(error.NameTooLong, GetFinalPathNameByHandle(handle, .{ .volume_name = .Nt }, buffer[0 .. required_len_in_u16 - 1]));
- std.testing.expectError(error.NameTooLong, GetFinalPathNameByHandle(handle, .{ .volume_name = .Dos }, buffer[0 .. required_len_in_u16 - 1]));
+ try std.testing.expectError(error.NameTooLong, GetFinalPathNameByHandle(handle, .{ .volume_name = .Nt }, buffer[0 .. required_len_in_u16 - 1]));
+ try std.testing.expectError(error.NameTooLong, GetFinalPathNameByHandle(handle, .{ .volume_name = .Dos }, buffer[0 .. required_len_in_u16 - 1]));
//check with exactly-sufficient size
_ = try GetFinalPathNameByHandle(handle, .{ .volume_name = .Nt }, buffer[0..required_len_in_u16]);
lib/std/rand/Isaac64.zig
@@ -205,7 +205,7 @@ test "isaac64 sequence" {
};
for (seq) |s| {
- std.testing.expect(s == r.next());
+ try std.testing.expect(s == r.next());
}
}
@@ -237,6 +237,6 @@ test "isaac64 fill" {
var buf1: [7]u8 = undefined;
std.mem.writeIntLittle(u64, &buf0, s);
Isaac64.fill(&r.random, &buf1);
- std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..]));
+ try std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..]));
}
}
lib/std/rand/Pcg.zig
@@ -96,7 +96,7 @@ test "pcg sequence" {
};
for (seq) |s| {
- std.testing.expect(s == r.next());
+ try std.testing.expect(s == r.next());
}
}
@@ -120,6 +120,6 @@ test "pcg fill" {
var buf1: [3]u8 = undefined;
std.mem.writeIntLittle(u32, &buf0, s);
Pcg.fill(&r.random, &buf1);
- std.testing.expect(std.mem.eql(u8, buf0[0..3], buf1[0..]));
+ try std.testing.expect(std.mem.eql(u8, buf0[0..3], buf1[0..]));
}
}
lib/std/rand/Sfc64.zig
@@ -103,7 +103,7 @@ test "Sfc64 sequence" {
};
for (seq) |s| {
- std.testing.expectEqual(s, r.next());
+ try std.testing.expectEqual(s, r.next());
}
}
@@ -135,6 +135,6 @@ test "Sfc64 fill" {
var buf1: [7]u8 = undefined;
std.mem.writeIntLittle(u64, &buf0, s);
Sfc64.fill(&r.random, &buf1);
- std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..]));
+ try std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..]));
}
}
lib/std/rand/Xoroshiro128.zig
@@ -113,7 +113,7 @@ test "xoroshiro sequence" {
};
for (seq1) |s| {
- std.testing.expect(s == r.next());
+ try std.testing.expect(s == r.next());
}
r.jump();
@@ -128,7 +128,7 @@ test "xoroshiro sequence" {
};
for (seq2) |s| {
- std.testing.expect(s == r.next());
+ try std.testing.expect(s == r.next());
}
}
@@ -151,6 +151,6 @@ test "xoroshiro fill" {
var buf1: [7]u8 = undefined;
std.mem.writeIntLittle(u64, &buf0, s);
Xoroshiro128.fill(&r.random, &buf1);
- std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..]));
+ try std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..]));
}
}
lib/std/special/compiler_rt/comparedf2_test.zig
@@ -101,6 +101,6 @@ const test_vectors = init: {
test "compare f64" {
for (test_vectors) |vector, i| {
- std.testing.expect(test__cmpdf2(vector));
+ try std.testing.expect(test__cmpdf2(vector));
}
}
lib/std/special/compiler_rt/comparesf2_test.zig
@@ -101,6 +101,6 @@ const test_vectors = init: {
test "compare f32" {
for (test_vectors) |vector, i| {
- std.testing.expect(test__cmpsf2(vector));
+ try std.testing.expect(test__cmpsf2(vector));
}
}
lib/std/special/compiler_rt/divdf3_test.zig
@@ -30,7 +30,7 @@ fn compareResultD(result: f64, expected: u64) bool {
fn test__divdf3(a: f64, b: f64, expected: u64) void {
const x = __divdf3(a, b);
const ret = compareResultD(x, expected);
- testing.expect(ret == true);
+ try testing.expect(ret == true);
}
test "divdf3" {
lib/std/special/compiler_rt/divsf3_test.zig
@@ -30,7 +30,7 @@ fn compareResultF(result: f32, expected: u32) bool {
fn test__divsf3(a: f32, b: f32, expected: u32) void {
const x = __divsf3(a, b);
const ret = compareResultF(x, expected);
- testing.expect(ret == true);
+ try testing.expect(ret == true);
}
test "divsf3" {
lib/std/special/compiler_rt/divtf3_test.zig
@@ -31,7 +31,7 @@ fn compareResultLD(result: f128, expectedHi: u64, expectedLo: u64) bool {
fn test__divtf3(a: f128, b: f128, expectedHi: u64, expectedLo: u64) void {
const x = __divtf3(a, b);
const ret = compareResultLD(x, expectedHi, expectedLo);
- testing.expect(ret == true);
+ try testing.expect(ret == true);
}
test "divtf3" {
lib/std/special/compiler_rt/divti3_test.zig
@@ -8,7 +8,7 @@ const testing = @import("std").testing;
fn test__divti3(a: i128, b: i128, expected: i128) void {
const x = __divti3(a, b);
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "divti3" {
lib/std/special/compiler_rt/emutls.zig
@@ -339,12 +339,12 @@ test "simple_allocator" {
test "__emutls_get_address zeroed" {
var ctl = emutls_control.init(usize, null);
- expect(ctl.object.index == 0);
+ try expect(ctl.object.index == 0);
// retrieve a variable from ctl
var x = @ptrCast(*usize, @alignCast(@alignOf(usize), __emutls_get_address(&ctl)));
- expect(ctl.object.index != 0); // index has been allocated for this ctl
- expect(x.* == 0); // storage has been zeroed
+ try expect(ctl.object.index != 0); // index has been allocated for this ctl
+ try expect(x.* == 0); // storage has been zeroed
// modify the storage
x.* = 1234;
@@ -352,26 +352,26 @@ test "__emutls_get_address zeroed" {
// retrieve a variable from ctl (same ctl)
var y = @ptrCast(*usize, @alignCast(@alignOf(usize), __emutls_get_address(&ctl)));
- expect(y.* == 1234); // same content that x.*
- expect(x == y); // same pointer
+ try expect(y.* == 1234); // same content that x.*
+ try expect(x == y); // same pointer
}
test "__emutls_get_address with default_value" {
var value: usize = 5678; // default value
var ctl = emutls_control.init(usize, &value);
- expect(ctl.object.index == 0);
+ try expect(ctl.object.index == 0);
var x: *usize = @ptrCast(*usize, @alignCast(@alignOf(usize), __emutls_get_address(&ctl)));
- expect(ctl.object.index != 0);
- expect(x.* == 5678); // storage initialized with default value
+ try expect(ctl.object.index != 0);
+ try expect(x.* == 5678); // storage initialized with default value
// modify the storage
x.* = 9012;
- expect(value == 5678); // the default value didn't change
+ try expect(value == 5678); // the default value didn't change
var y = @ptrCast(*usize, @alignCast(@alignOf(usize), __emutls_get_address(&ctl)));
- expect(y.* == 9012); // the modified storage persists
+ try expect(y.* == 9012); // the modified storage persists
}
test "test default_value with differents sizes" {
@@ -380,7 +380,7 @@ test "test default_value with differents sizes" {
var def: T = value;
var ctl = emutls_control.init(T, &def);
var x = ctl.get_typed_pointer(T);
- expect(x.* == value);
+ try expect(x.* == value);
}
}._testType;
lib/std/special/compiler_rt/fixdfdi_test.zig
@@ -12,7 +12,7 @@ const warn = std.debug.warn;
fn test__fixdfdi(a: f64, expected: i64) void {
const x = __fixdfdi(a);
//warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", .{a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u64, expected)});
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "fixdfdi" {
lib/std/special/compiler_rt/fixdfsi_test.zig
@@ -12,7 +12,7 @@ const warn = std.debug.warn;
fn test__fixdfsi(a: f64, expected: i32) void {
const x = __fixdfsi(a);
//warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", .{a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u32, expected)});
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "fixdfsi" {
lib/std/special/compiler_rt/fixdfti_test.zig
@@ -12,7 +12,7 @@ const warn = std.debug.warn;
fn test__fixdfti(a: f64, expected: i128) void {
const x = __fixdfti(a);
//warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", .{a, @bitCast(u64, a), x, x, expected, expected, @bitCast(u128, expected)});
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "fixdfti" {
lib/std/special/compiler_rt/fixint_test.zig
@@ -14,7 +14,7 @@ const fixint = @import("fixint.zig").fixint;
fn test__fixint(comptime fp_t: type, comptime fixint_t: type, a: fp_t, expected: fixint_t) void {
const x = fixint(fp_t, fixint_t, a);
//warn("a={} x={}:{x} expected={}:{x})\n", .{a, x, x, expected, expected});
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "fixint.i1" {
lib/std/special/compiler_rt/fixsfdi_test.zig
@@ -12,7 +12,7 @@ const warn = std.debug.warn;
fn test__fixsfdi(a: f32, expected: i64) void {
const x = __fixsfdi(a);
//warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u32, {x})\n", .{a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u64, expected)});
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "fixsfdi" {
lib/std/special/compiler_rt/fixsfsi_test.zig
@@ -12,7 +12,7 @@ const warn = std.debug.warn;
fn test__fixsfsi(a: f32, expected: i32) void {
const x = __fixsfsi(a);
//warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u32, {x})\n", .{a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u32, expected)});
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "fixsfsi" {
lib/std/special/compiler_rt/fixsfti_test.zig
@@ -12,7 +12,7 @@ const warn = std.debug.warn;
fn test__fixsfti(a: f32, expected: i128) void {
const x = __fixsfti(a);
//warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u128, {x})\n", .{a, @bitCast(u32, a), x, x, expected, expected, @bitCast(u128, expected)});
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "fixsfti" {
lib/std/special/compiler_rt/fixtfdi_test.zig
@@ -12,7 +12,7 @@ const warn = std.debug.warn;
fn test__fixtfdi(a: f128, expected: i64) void {
const x = __fixtfdi(a);
//warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u64, {x})\n", .{a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u64, expected)});
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "fixtfdi" {
lib/std/special/compiler_rt/fixtfsi_test.zig
@@ -12,7 +12,7 @@ const warn = std.debug.warn;
fn test__fixtfsi(a: f128, expected: i32) void {
const x = __fixtfsi(a);
//warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u32, {x})\n", .{a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u32, expected)});
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "fixtfsi" {
lib/std/special/compiler_rt/fixtfti_test.zig
@@ -12,7 +12,7 @@ const warn = std.debug.warn;
fn test__fixtfti(a: f128, expected: i128) void {
const x = __fixtfti(a);
//warn("a={}:{x} x={}:{x} expected={}:{x}:@as(u128, {x})\n", .{a, @bitCast(u128, a), x, x, expected, expected, @bitCast(u128, expected)});
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "fixtfti" {
lib/std/special/compiler_rt/fixunsdfdi_test.zig
@@ -8,7 +8,7 @@ const testing = @import("std").testing;
fn test__fixunsdfdi(a: f64, expected: u64) void {
const x = __fixunsdfdi(a);
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "fixunsdfdi" {
lib/std/special/compiler_rt/fixunsdfsi_test.zig
@@ -8,7 +8,7 @@ const testing = @import("std").testing;
fn test__fixunsdfsi(a: f64, expected: u32) void {
const x = __fixunsdfsi(a);
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "fixunsdfsi" {
lib/std/special/compiler_rt/fixunsdfti_test.zig
@@ -8,7 +8,7 @@ const testing = @import("std").testing;
fn test__fixunsdfti(a: f64, expected: u128) void {
const x = __fixunsdfti(a);
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "fixunsdfti" {
lib/std/special/compiler_rt/fixunssfdi_test.zig
@@ -8,7 +8,7 @@ const testing = @import("std").testing;
fn test__fixunssfdi(a: f32, expected: u64) void {
const x = __fixunssfdi(a);
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "fixunssfdi" {
lib/std/special/compiler_rt/fixunssfsi_test.zig
@@ -8,7 +8,7 @@ const testing = @import("std").testing;
fn test__fixunssfsi(a: f32, expected: u32) void {
const x = __fixunssfsi(a);
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "fixunssfsi" {
lib/std/special/compiler_rt/fixunssfti_test.zig
@@ -8,7 +8,7 @@ const testing = @import("std").testing;
fn test__fixunssfti(a: f32, expected: u128) void {
const x = __fixunssfti(a);
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "fixunssfti" {
lib/std/special/compiler_rt/fixunstfdi_test.zig
@@ -8,7 +8,7 @@ const testing = @import("std").testing;
fn test__fixunstfdi(a: f128, expected: u64) void {
const x = __fixunstfdi(a);
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "fixunstfdi" {
lib/std/special/compiler_rt/fixunstfsi_test.zig
@@ -8,7 +8,7 @@ const testing = @import("std").testing;
fn test__fixunstfsi(a: f128, expected: u32) void {
const x = __fixunstfsi(a);
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
const inf128 = @bitCast(f128, @as(u128, 0x7fff0000000000000000000000000000));
lib/std/special/compiler_rt/fixunstfti_test.zig
@@ -8,7 +8,7 @@ const testing = @import("std").testing;
fn test__fixunstfti(a: f128, expected: u128) void {
const x = __fixunstfti(a);
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
const inf128 = @bitCast(f128, @as(u128, 0x7fff0000000000000000000000000000));
lib/std/special/compiler_rt/floatdidf_test.zig
@@ -8,7 +8,7 @@ const testing = @import("std").testing;
fn test__floatdidf(a: i64, expected: f64) void {
const r = __floatdidf(a);
- testing.expect(r == expected);
+ try testing.expect(r == expected);
}
test "floatdidf" {
lib/std/special/compiler_rt/floatdisf_test.zig
@@ -8,7 +8,7 @@ const testing = @import("std").testing;
fn test__floatdisf(a: i64, expected: f32) void {
const x = __floatdisf(a);
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "floatdisf" {
lib/std/special/compiler_rt/floatditf_test.zig
@@ -8,7 +8,7 @@ const testing = @import("std").testing;
fn test__floatditf(a: i64, expected: f128) void {
const x = __floatditf(a);
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "floatditf" {
lib/std/special/compiler_rt/floatsiXf.zig
@@ -86,17 +86,17 @@ pub fn __aeabi_i2f(arg: i32) callconv(.AAPCS) f32 {
fn test_one_floatsitf(a: i32, expected: u128) void {
const r = __floatsitf(a);
- std.testing.expect(@bitCast(u128, r) == expected);
+ try std.testing.expect(@bitCast(u128, r) == expected);
}
fn test_one_floatsidf(a: i32, expected: u64) void {
const r = __floatsidf(a);
- std.testing.expect(@bitCast(u64, r) == expected);
+ try std.testing.expect(@bitCast(u64, r) == expected);
}
fn test_one_floatsisf(a: i32, expected: u32) void {
const r = __floatsisf(a);
- std.testing.expect(@bitCast(u32, r) == expected);
+ try std.testing.expect(@bitCast(u32, r) == expected);
}
test "floatsidf" {
lib/std/special/compiler_rt/floattidf_test.zig
@@ -8,7 +8,7 @@ const testing = @import("std").testing;
fn test__floattidf(a: i128, expected: f64) void {
const x = __floattidf(a);
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "floattidf" {
lib/std/special/compiler_rt/floattisf_test.zig
@@ -8,7 +8,7 @@ const testing = @import("std").testing;
fn test__floattisf(a: i128, expected: f32) void {
const x = __floattisf(a);
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "floattisf" {
lib/std/special/compiler_rt/floattitf_test.zig
@@ -8,7 +8,7 @@ const testing = @import("std").testing;
fn test__floattitf(a: i128, expected: f128) void {
const x = __floattitf(a);
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "floattitf" {
lib/std/special/compiler_rt/floatundidf_test.zig
@@ -8,7 +8,7 @@ const testing = @import("std").testing;
fn test__floatundidf(a: u64, expected: f64) void {
const r = __floatundidf(a);
- testing.expect(r == expected);
+ try testing.expect(r == expected);
}
test "floatundidf" {
lib/std/special/compiler_rt/floatunsidf.zig
@@ -30,7 +30,7 @@ pub fn __aeabi_ui2d(arg: u32) callconv(.AAPCS) f64 {
fn test_one_floatunsidf(a: u32, expected: u64) void {
const r = __floatunsidf(a);
- std.testing.expect(@bitCast(u64, r) == expected);
+ try std.testing.expect(@bitCast(u64, r) == expected);
}
test "floatsidf" {
lib/std/special/compiler_rt/floatunsisf.zig
@@ -50,7 +50,7 @@ pub fn __aeabi_ui2f(arg: u32) callconv(.AAPCS) f32 {
fn test_one_floatunsisf(a: u32, expected: u32) void {
const r = __floatunsisf(a);
- std.testing.expect(@bitCast(u32, r) == expected);
+ try std.testing.expect(@bitCast(u32, r) == expected);
}
test "floatunsisf" {
lib/std/special/compiler_rt/floatuntidf_test.zig
@@ -8,7 +8,7 @@ const testing = @import("std").testing;
fn test__floatuntidf(a: u128, expected: f64) void {
const x = __floatuntidf(a);
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "floatuntidf" {
lib/std/special/compiler_rt/floatuntisf_test.zig
@@ -8,7 +8,7 @@ const testing = @import("std").testing;
fn test__floatuntisf(a: u128, expected: f32) void {
const x = __floatuntisf(a);
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "floatuntisf" {
lib/std/special/compiler_rt/floatuntitf_test.zig
@@ -8,7 +8,7 @@ const testing = @import("std").testing;
fn test__floatuntitf(a: u128, expected: f128) void {
const x = __floatuntitf(a);
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "floatuntitf" {
lib/std/special/compiler_rt/int.zig
@@ -64,7 +64,7 @@ test "test_divdi3" {
fn test_one_divdi3(a: i64, b: i64, expected_q: i64) void {
const q: i64 = __divdi3(a, b);
- testing.expect(q == expected_q);
+ try testing.expect(q == expected_q);
}
pub fn __moddi3(a: i64, b: i64) callconv(.C) i64 {
@@ -104,7 +104,7 @@ test "test_moddi3" {
fn test_one_moddi3(a: i64, b: i64, expected_r: i64) void {
const r: i64 = __moddi3(a, b);
- testing.expect(r == expected_r);
+ try testing.expect(r == expected_r);
}
pub fn __udivdi3(a: u64, b: u64) callconv(.C) u64 {
@@ -130,7 +130,7 @@ test "test_umoddi3" {
fn test_one_umoddi3(a: u64, b: u64, expected_r: u64) void {
const r = __umoddi3(a, b);
- testing.expect(r == expected_r);
+ try testing.expect(r == expected_r);
}
pub fn __divmodsi4(a: i32, b: i32, rem: *i32) callconv(.C) i32 {
@@ -166,7 +166,7 @@ test "test_divmodsi4" {
fn test_one_divmodsi4(a: i32, b: i32, expected_q: i32, expected_r: i32) void {
var r: i32 = undefined;
const q: i32 = __divmodsi4(a, b, &r);
- testing.expect(q == expected_q and r == expected_r);
+ try testing.expect(q == expected_q and r == expected_r);
}
pub fn __udivmodsi4(a: u32, b: u32, rem: *u32) callconv(.C) u32 {
@@ -213,7 +213,7 @@ test "test_divsi3" {
fn test_one_divsi3(a: i32, b: i32, expected_q: i32) void {
const q: i32 = __divsi3(a, b);
- testing.expect(q == expected_q);
+ try testing.expect(q == expected_q);
}
pub fn __udivsi3(n: u32, d: u32) callconv(.C) u32 {
@@ -400,7 +400,7 @@ test "test_udivsi3" {
fn test_one_udivsi3(a: u32, b: u32, expected_q: u32) void {
const q: u32 = __udivsi3(a, b);
- testing.expect(q == expected_q);
+ try testing.expect(q == expected_q);
}
pub fn __modsi3(n: i32, d: i32) callconv(.C) i32 {
@@ -431,7 +431,7 @@ test "test_modsi3" {
fn test_one_modsi3(a: i32, b: i32, expected_r: i32) void {
const r: i32 = __modsi3(a, b);
- testing.expect(r == expected_r);
+ try testing.expect(r == expected_r);
}
pub fn __umodsi3(n: u32, d: u32) callconv(.C) u32 {
@@ -583,7 +583,7 @@ test "test_umodsi3" {
fn test_one_umodsi3(a: u32, b: u32, expected_r: u32) void {
const r: u32 = __umodsi3(a, b);
- testing.expect(r == expected_r);
+ try testing.expect(r == expected_r);
}
pub fn __mulsi3(a: i32, b: i32) callconv(.C) i32 {
lib/std/special/compiler_rt/modti3_test.zig
@@ -8,7 +8,7 @@ const testing = @import("std").testing;
fn test__modti3(a: i128, b: i128, expected: i128) void {
const x = __modti3(a, b);
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "modti3" {
lib/std/special/compiler_rt/muldi3_test.zig
@@ -8,7 +8,7 @@ const testing = @import("std").testing;
fn test__muldi3(a: i64, b: i64, expected: i64) void {
const x = __muldi3(a, b);
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "muldi3" {
lib/std/special/compiler_rt/mulodi4_test.zig
@@ -9,7 +9,7 @@ const testing = @import("std").testing;
fn test__mulodi4(a: i64, b: i64, expected: i64, expected_overflow: c_int) void {
var overflow: c_int = undefined;
const x = __mulodi4(a, b, &overflow);
- testing.expect(overflow == expected_overflow and (expected_overflow != 0 or x == expected));
+ try testing.expect(overflow == expected_overflow and (expected_overflow != 0 or x == expected));
}
test "mulodi4" {
lib/std/special/compiler_rt/muloti4_test.zig
@@ -9,7 +9,7 @@ const testing = @import("std").testing;
fn test__muloti4(a: i128, b: i128, expected: i128, expected_overflow: c_int) void {
var overflow: c_int = undefined;
const x = __muloti4(a, b, &overflow);
- testing.expect(overflow == expected_overflow and (expected_overflow != 0 or x == expected));
+ try testing.expect(overflow == expected_overflow and (expected_overflow != 0 or x == expected));
}
test "muloti4" {
lib/std/special/compiler_rt/multi3_test.zig
@@ -8,7 +8,7 @@ const testing = @import("std").testing;
fn test__multi3(a: i128, b: i128, expected: i128) void {
const x = __multi3(a, b);
- testing.expect(x == expected);
+ try testing.expect(x == expected);
}
test "multi3" {
lib/std/special/compiler_rt/popcountdi2_test.zig
@@ -18,7 +18,7 @@ fn naive_popcount(a_param: i64) i32 {
fn test__popcountdi2(a: i64) void {
const x = __popcountdi2(a);
const expected = naive_popcount(a);
- testing.expect(expected == x);
+ try testing.expect(expected == x);
}
test "popcountdi2" {
lib/std/special/compiler_rt/udivmoddi4_test.zig
@@ -11,8 +11,8 @@ const testing = @import("std").testing;
fn test__udivmoddi4(a: u64, b: u64, expected_q: u64, expected_r: u64) void {
var r: u64 = undefined;
const q = __udivmoddi4(a, b, &r);
- testing.expect(q == expected_q);
- testing.expect(r == expected_r);
+ try testing.expect(q == expected_q);
+ try testing.expect(r == expected_r);
}
test "udivmoddi4" {
lib/std/special/compiler_rt/udivmodti4_test.zig
@@ -11,8 +11,8 @@ const testing = @import("std").testing;
fn test__udivmodti4(a: u128, b: u128, expected_q: u128, expected_r: u128) void {
var r: u128 = undefined;
const q = __udivmodti4(a, b, &r);
- testing.expect(q == expected_q);
- testing.expect(r == expected_r);
+ try testing.expect(q == expected_q);
+ try testing.expect(r == expected_r);
}
test "udivmodti4" {
lib/std/special/init-lib/src/main.zig
@@ -6,5 +6,5 @@ export fn add(a: i32, b: i32) i32 {
}
test "basic add functionality" {
- testing.expect(add(3, 7) == 10);
+ try testing.expect(add(3, 7) == 10);
}
lib/std/special/c.zig
@@ -161,10 +161,10 @@ fn strerror(errnum: c_int) callconv(.C) [*:0]const u8 {
}
test "strncmp" {
- std.testing.expect(strncmp("a", "b", 1) == -1);
- std.testing.expect(strncmp("a", "c", 1) == -2);
- std.testing.expect(strncmp("b", "a", 1) == 1);
- std.testing.expect(strncmp("\xff", "\x02", 1) == 253);
+ try std.testing.expect(strncmp("a", "b", 1) == -1);
+ try std.testing.expect(strncmp("a", "c", 1) == -2);
+ try std.testing.expect(strncmp("b", "a", 1) == 1);
+ try std.testing.expect(strncmp("\xff", "\x02", 1) == 253);
}
// Avoid dragging in the runtime safety mechanisms into this .o file,
@@ -245,9 +245,9 @@ test "memcmp" {
const arr2 = &[_]u8{ 1, 0, 1 };
const arr3 = &[_]u8{ 1, 2, 1 };
- std.testing.expect(memcmp(base_arr[0..], arr1[0..], base_arr.len) == 0);
- std.testing.expect(memcmp(base_arr[0..], arr2[0..], base_arr.len) > 0);
- std.testing.expect(memcmp(base_arr[0..], arr3[0..], base_arr.len) < 0);
+ try std.testing.expect(memcmp(base_arr[0..], arr1[0..], base_arr.len) == 0);
+ try std.testing.expect(memcmp(base_arr[0..], arr2[0..], base_arr.len) > 0);
+ try std.testing.expect(memcmp(base_arr[0..], arr3[0..], base_arr.len) < 0);
}
export fn bcmp(vl: [*]allowzero const u8, vr: [*]allowzero const u8, n: usize) callconv(.C) isize {
@@ -269,9 +269,9 @@ test "bcmp" {
const arr2 = &[_]u8{ 1, 0, 1 };
const arr3 = &[_]u8{ 1, 2, 1 };
- std.testing.expect(bcmp(base_arr[0..], arr1[0..], base_arr.len) == 0);
- std.testing.expect(bcmp(base_arr[0..], arr2[0..], base_arr.len) != 0);
- std.testing.expect(bcmp(base_arr[0..], arr3[0..], base_arr.len) != 0);
+ try std.testing.expect(bcmp(base_arr[0..], arr1[0..], base_arr.len) == 0);
+ try std.testing.expect(bcmp(base_arr[0..], arr2[0..], base_arr.len) != 0);
+ try std.testing.expect(bcmp(base_arr[0..], arr3[0..], base_arr.len) != 0);
}
comptime {
@@ -865,11 +865,11 @@ test "fmod, fmodf" {
const nan_val = math.nan(T);
const inf_val = math.inf(T);
- std.testing.expect(isNan(generic_fmod(T, nan_val, 1.0)));
- std.testing.expect(isNan(generic_fmod(T, 1.0, nan_val)));
- std.testing.expect(isNan(generic_fmod(T, inf_val, 1.0)));
- std.testing.expect(isNan(generic_fmod(T, 0.0, 0.0)));
- std.testing.expect(isNan(generic_fmod(T, 1.0, 0.0)));
+ try std.testing.expect(isNan(generic_fmod(T, nan_val, 1.0)));
+ try std.testing.expect(isNan(generic_fmod(T, 1.0, nan_val)));
+ try std.testing.expect(isNan(generic_fmod(T, inf_val, 1.0)));
+ try std.testing.expect(isNan(generic_fmod(T, 0.0, 0.0)));
+ try std.testing.expect(isNan(generic_fmod(T, 1.0, 0.0)));
std.testing.expectEqual(@as(T, 0.0), generic_fmod(T, 0.0, 2.0));
std.testing.expectEqual(@as(T, -0.0), generic_fmod(T, -0.0, 2.0));
@@ -901,7 +901,7 @@ test "fmin, fminf" {
inline for ([_]type{ f32, f64 }) |T| {
const nan_val = math.nan(T);
- std.testing.expect(isNan(generic_fmin(T, nan_val, nan_val)));
+ try std.testing.expect(isNan(generic_fmin(T, nan_val, nan_val)));
std.testing.expectEqual(@as(T, 1.0), generic_fmin(T, nan_val, 1.0));
std.testing.expectEqual(@as(T, 1.0), generic_fmin(T, 1.0, nan_val));
@@ -930,7 +930,7 @@ test "fmax, fmaxf" {
inline for ([_]type{ f32, f64 }) |T| {
const nan_val = math.nan(T);
- std.testing.expect(isNan(generic_fmax(T, nan_val, nan_val)));
+ try std.testing.expect(isNan(generic_fmax(T, nan_val, nan_val)));
std.testing.expectEqual(@as(T, 1.0), generic_fmax(T, nan_val, 1.0));
std.testing.expectEqual(@as(T, 1.0), generic_fmax(T, 1.0, nan_val));
@@ -1094,11 +1094,11 @@ test "sqrt" {
}
test "sqrt special" {
- std.testing.expect(std.math.isPositiveInf(sqrt(std.math.inf(f64))));
- std.testing.expect(sqrt(0.0) == 0.0);
- std.testing.expect(sqrt(-0.0) == -0.0);
- std.testing.expect(isNan(sqrt(-1.0)));
- std.testing.expect(isNan(sqrt(std.math.nan(f64))));
+ try std.testing.expect(std.math.isPositiveInf(sqrt(std.math.inf(f64))));
+ try std.testing.expect(sqrt(0.0) == 0.0);
+ try std.testing.expect(sqrt(-0.0) == -0.0);
+ try std.testing.expect(isNan(sqrt(-1.0)));
+ try std.testing.expect(isNan(sqrt(std.math.nan(f64))));
}
export fn sqrtf(x: f32) f32 {
@@ -1199,9 +1199,9 @@ test "sqrtf" {
}
test "sqrtf special" {
- std.testing.expect(std.math.isPositiveInf(sqrtf(std.math.inf(f32))));
- std.testing.expect(sqrtf(0.0) == 0.0);
- std.testing.expect(sqrtf(-0.0) == -0.0);
- std.testing.expect(isNan(sqrtf(-1.0)));
- std.testing.expect(isNan(sqrtf(std.math.nan(f32))));
+ try std.testing.expect(std.math.isPositiveInf(sqrtf(std.math.inf(f32))));
+ try std.testing.expect(sqrtf(0.0) == 0.0);
+ try std.testing.expect(sqrtf(-0.0) == -0.0);
+ try std.testing.expect(isNan(sqrtf(-1.0)));
+ try std.testing.expect(isNan(sqrtf(std.math.nan(f32))));
}
lib/std/Thread/AutoResetEvent.zig
@@ -176,7 +176,7 @@ test "basic usage" {
// test local code paths
{
var event = AutoResetEvent{};
- testing.expectError(error.TimedOut, event.timedWait(1));
+ try testing.expectError(error.TimedOut, event.timedWait(1));
event.set();
event.wait();
}
@@ -192,28 +192,28 @@ test "basic usage" {
const Self = @This();
- fn sender(self: *Self) void {
- testing.expect(self.value == 0);
+ fn sender(self: *Self) !void {
+ try testing.expect(self.value == 0);
self.value = 1;
self.out.set();
self.in.wait();
- testing.expect(self.value == 2);
+ try testing.expect(self.value == 2);
self.value = 3;
self.out.set();
self.in.wait();
- testing.expect(self.value == 4);
+ try testing.expect(self.value == 4);
}
- fn receiver(self: *Self) void {
+ fn receiver(self: *Self) !void {
self.out.wait();
- testing.expect(self.value == 1);
+ try testing.expect(self.value == 1);
self.value = 2;
self.in.set();
self.out.wait();
- testing.expect(self.value == 3);
+ try testing.expect(self.value == 3);
self.value = 4;
self.in.set();
}
lib/std/Thread/Mutex.zig
@@ -294,7 +294,7 @@ test "basic usage" {
if (builtin.single_threaded) {
worker(&context);
- testing.expect(context.data == TestContext.incr_count);
+ try testing.expect(context.data == TestContext.incr_count);
} else {
const thread_count = 10;
var threads: [thread_count]*std.Thread = undefined;
@@ -304,7 +304,7 @@ test "basic usage" {
for (threads) |t|
t.wait();
- testing.expect(context.data == thread_count * TestContext.incr_count);
+ try testing.expect(context.data == thread_count * TestContext.incr_count);
}
}
lib/std/Thread/ResetEvent.zig
@@ -204,7 +204,7 @@ test "basic usage" {
event.reset();
event.set();
- testing.expectEqual(TimedWaitResult.event_set, event.timedWait(1));
+ try testing.expectEqual(TimedWaitResult.event_set, event.timedWait(1));
// test cross-thread signaling
if (builtin.single_threaded)
@@ -233,25 +233,25 @@ test "basic usage" {
self.* = undefined;
}
- fn sender(self: *Self) void {
+ fn sender(self: *Self) !void {
// update value and signal input
- testing.expect(self.value == 0);
+ try testing.expect(self.value == 0);
self.value = 1;
self.in.set();
// wait for receiver to update value and signal output
self.out.wait();
- testing.expect(self.value == 2);
+ try testing.expect(self.value == 2);
// update value and signal final input
self.value = 3;
self.in.set();
}
- fn receiver(self: *Self) void {
+ fn receiver(self: *Self) !void {
// wait for sender to update value and signal input
self.in.wait();
- assert(self.value == 1);
+ try testing.expect(self.value == 1);
// update value and signal output
self.in.reset();
@@ -260,7 +260,7 @@ test "basic usage" {
// wait for sender to update value and signal final input
self.in.wait();
- assert(self.value == 3);
+ try testing.expect(self.value == 3);
}
fn sleeper(self: *Self) void {
@@ -272,9 +272,9 @@ test "basic usage" {
fn timedWaiter(self: *Self) !void {
self.in.wait();
- testing.expectEqual(TimedWaitResult.timed_out, self.out.timedWait(time.ns_per_us));
+ try testing.expectEqual(TimedWaitResult.timed_out, self.out.timedWait(time.ns_per_us));
try self.out.timedWait(time.ns_per_ms * 100);
- testing.expect(self.value == 5);
+ try testing.expect(self.value == 5);
}
};
@@ -283,7 +283,7 @@ test "basic usage" {
defer context.deinit();
const receiver = try std.Thread.spawn(Context.receiver, &context);
defer receiver.wait();
- context.sender();
+ try context.sender();
if (false) {
// I have now observed this fail on macOS, Windows, and Linux.
lib/std/Thread/StaticResetEvent.zig
@@ -320,7 +320,7 @@ test "basic usage" {
event.reset();
event.set();
- testing.expectEqual(TimedWaitResult.event_set, event.timedWait(1));
+ try testing.expectEqual(TimedWaitResult.event_set, event.timedWait(1));
// test cross-thread signaling
if (std.builtin.single_threaded)
@@ -333,25 +333,25 @@ test "basic usage" {
in: StaticResetEvent = .{},
out: StaticResetEvent = .{},
- fn sender(self: *Self) void {
+ fn sender(self: *Self) !void {
// update value and signal input
- testing.expect(self.value == 0);
+ try testing.expect(self.value == 0);
self.value = 1;
self.in.set();
// wait for receiver to update value and signal output
self.out.wait();
- testing.expect(self.value == 2);
+ try testing.expect(self.value == 2);
// update value and signal final input
self.value = 3;
self.in.set();
}
- fn receiver(self: *Self) void {
+ fn receiver(self: *Self) !void {
// wait for sender to update value and signal input
self.in.wait();
- assert(self.value == 1);
+ try testing.expect(self.value == 1);
// update value and signal output
self.in.reset();
@@ -360,7 +360,7 @@ test "basic usage" {
// wait for sender to update value and signal final input
self.in.wait();
- assert(self.value == 3);
+ try testing.expect(self.value == 3);
}
fn sleeper(self: *Self) void {
@@ -372,16 +372,16 @@ test "basic usage" {
fn timedWaiter(self: *Self) !void {
self.in.wait();
- testing.expectEqual(TimedWaitResult.timed_out, self.out.timedWait(time.ns_per_us));
+ try testing.expectEqual(TimedWaitResult.timed_out, self.out.timedWait(time.ns_per_us));
try self.out.timedWait(time.ns_per_ms * 100);
- testing.expect(self.value == 5);
+ try testing.expect(self.value == 5);
}
};
var context = Context{};
const receiver = try std.Thread.spawn(Context.receiver, &context);
defer receiver.wait();
- context.sender();
+ try context.sender();
if (false) {
// I have now observed this fail on macOS, Windows, and Linux.
lib/std/valgrind/memcheck.zig
@@ -149,7 +149,7 @@ pub fn countLeaks() CountResult {
}
test "countLeaks" {
- testing.expectEqual(
+ try testing.expectEqual(
@as(CountResult, .{
.leaked = 0,
.dubious = 0,
@@ -179,7 +179,7 @@ pub fn countLeakBlocks() CountResult {
}
test "countLeakBlocks" {
- testing.expectEqual(
+ try testing.expectEqual(
@as(CountResult, .{
.leaked = 0,
.dubious = 0,
lib/std/x/net/tcp.zig
@@ -322,7 +322,7 @@ test "tcp/client: set read timeout of 1 millisecond on blocking client" {
defer conn.deinit();
var buf: [1]u8 = undefined;
- testing.expectError(error.WouldBlock, client.read(&buf));
+ try testing.expectError(error.WouldBlock, client.read(&buf));
}
test "tcp/listener: bind to unspecified ipv4 address" {
@@ -335,7 +335,7 @@ test "tcp/listener: bind to unspecified ipv4 address" {
try listener.listen(128);
const address = try listener.getLocalAddress();
- testing.expect(address == .ipv4);
+ try testing.expect(address == .ipv4);
}
test "tcp/listener: bind to unspecified ipv6 address" {
@@ -348,5 +348,5 @@ test "tcp/listener: bind to unspecified ipv6 address" {
try listener.listen(128);
const address = try listener.getLocalAddress();
- testing.expect(address == .ipv6);
+ try testing.expect(address == .ipv6);
}
lib/std/x/os/net.zig
@@ -499,12 +499,12 @@ test {
test "ip: convert to and from ipv6" {
try testing.expectFmt("::7f00:1", "{}", .{IPv4.localhost.toIPv6()});
- testing.expect(!IPv4.localhost.toIPv6().mapsToIPv4());
+ try testing.expect(!IPv4.localhost.toIPv6().mapsToIPv4());
try testing.expectFmt("::ffff:127.0.0.1", "{}", .{IPv4.localhost.mapToIPv6()});
- testing.expect(IPv4.localhost.mapToIPv6().mapsToIPv4());
+ try testing.expect(IPv4.localhost.mapToIPv6().mapsToIPv4());
- testing.expect(IPv4.localhost.toIPv6().toIPv4() == null);
+ try testing.expect(IPv4.localhost.toIPv6().toIPv4() == null);
try testing.expectFmt("127.0.0.1", "{}", .{IPv4.localhost.mapToIPv6().toIPv4()});
}
lib/std/zig/system/linux.zig
@@ -414,8 +414,8 @@ fn testParser(
) !void {
var fbs = io.fixedBufferStream(input);
const result = try parser.parse(arch, fbs.reader());
- testing.expectEqual(expected_model, result.?.model);
- testing.expect(expected_model.features.eql(result.?.features));
+ try testing.expectEqual(expected_model, result.?.model);
+ try testing.expect(expected_model.features.eql(result.?.features));
}
// The generic implementation of a /proc/cpuinfo parser.
lib/std/zig/system/macos.zig
@@ -402,7 +402,7 @@ fn testVersionEquality(expected: std.builtin.Version, got: std.builtin.Version)
var b_got: [64]u8 = undefined;
const s_got: []const u8 = try std.fmt.bufPrint(b_got[0..], "{}", .{got});
- testing.expectEqualStrings(s_expected, s_got);
+ try testing.expectEqualStrings(s_expected, s_got);
}
/// Detect SDK path on Darwin.
lib/std/zig/cross_target.zig
@@ -800,7 +800,7 @@ test "CrossTarget.parse" {
.{@tagName(std.Target.current.abi)},
) catch unreachable;
- std.testing.expectEqualSlices(u8, triple, text);
+ try std.testing.expectEqualSlices(u8, triple, text);
}
{
const cross_target = try CrossTarget.parse(.{
@@ -808,18 +808,18 @@ test "CrossTarget.parse" {
.cpu_features = "native",
});
- std.testing.expect(cross_target.cpu_arch.? == .aarch64);
- std.testing.expect(cross_target.cpu_model == .native);
+ try std.testing.expect(cross_target.cpu_arch.? == .aarch64);
+ try std.testing.expect(cross_target.cpu_model == .native);
}
{
const cross_target = try CrossTarget.parse(.{ .arch_os_abi = "native" });
- std.testing.expect(cross_target.cpu_arch == null);
- std.testing.expect(cross_target.isNative());
+ try std.testing.expect(cross_target.cpu_arch == null);
+ try std.testing.expect(cross_target.isNative());
const text = try cross_target.zigTriple(std.testing.allocator);
defer std.testing.allocator.free(text);
- std.testing.expectEqualSlices(u8, "native", text);
+ try std.testing.expectEqualSlices(u8, "native", text);
}
{
const cross_target = try CrossTarget.parse(.{
@@ -828,23 +828,23 @@ test "CrossTarget.parse" {
});
const target = cross_target.toTarget();
- std.testing.expect(target.os.tag == .linux);
- std.testing.expect(target.abi == .gnu);
- std.testing.expect(target.cpu.arch == .x86_64);
- std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .sse));
- std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .avx));
- std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .cx8));
- std.testing.expect(Target.x86.featureSetHas(target.cpu.features, .cmov));
- std.testing.expect(Target.x86.featureSetHas(target.cpu.features, .fxsr));
+ try std.testing.expect(target.os.tag == .linux);
+ try std.testing.expect(target.abi == .gnu);
+ try std.testing.expect(target.cpu.arch == .x86_64);
+ try std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .sse));
+ try std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .avx));
+ try std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .cx8));
+ try std.testing.expect(Target.x86.featureSetHas(target.cpu.features, .cmov));
+ try std.testing.expect(Target.x86.featureSetHas(target.cpu.features, .fxsr));
- std.testing.expect(Target.x86.featureSetHasAny(target.cpu.features, .{ .sse, .avx, .cmov }));
- std.testing.expect(!Target.x86.featureSetHasAny(target.cpu.features, .{ .sse, .avx }));
- std.testing.expect(Target.x86.featureSetHasAll(target.cpu.features, .{ .mmx, .x87 }));
- std.testing.expect(!Target.x86.featureSetHasAll(target.cpu.features, .{ .mmx, .x87, .sse }));
+ try std.testing.expect(Target.x86.featureSetHasAny(target.cpu.features, .{ .sse, .avx, .cmov }));
+ try std.testing.expect(!Target.x86.featureSetHasAny(target.cpu.features, .{ .sse, .avx }));
+ try std.testing.expect(Target.x86.featureSetHasAll(target.cpu.features, .{ .mmx, .x87 }));
+ try std.testing.expect(!Target.x86.featureSetHasAll(target.cpu.features, .{ .mmx, .x87, .sse }));
const text = try cross_target.zigTriple(std.testing.allocator);
defer std.testing.allocator.free(text);
- std.testing.expectEqualSlices(u8, "x86_64-linux-gnu", text);
+ try std.testing.expectEqualSlices(u8, "x86_64-linux-gnu", text);
}
{
const cross_target = try CrossTarget.parse(.{
@@ -853,15 +853,15 @@ test "CrossTarget.parse" {
});
const target = cross_target.toTarget();
- std.testing.expect(target.os.tag == .linux);
- std.testing.expect(target.abi == .musleabihf);
- std.testing.expect(target.cpu.arch == .arm);
- std.testing.expect(target.cpu.model == &Target.arm.cpu.generic);
- std.testing.expect(Target.arm.featureSetHas(target.cpu.features, .v8a));
+ try std.testing.expect(target.os.tag == .linux);
+ try std.testing.expect(target.abi == .musleabihf);
+ try std.testing.expect(target.cpu.arch == .arm);
+ try std.testing.expect(target.cpu.model == &Target.arm.cpu.generic);
+ try std.testing.expect(Target.arm.featureSetHas(target.cpu.features, .v8a));
const text = try cross_target.zigTriple(std.testing.allocator);
defer std.testing.allocator.free(text);
- std.testing.expectEqualSlices(u8, "arm-linux-musleabihf", text);
+ try std.testing.expectEqualSlices(u8, "arm-linux-musleabihf", text);
}
{
const cross_target = try CrossTarget.parse(.{
@@ -870,21 +870,21 @@ test "CrossTarget.parse" {
});
const target = cross_target.toTarget();
- std.testing.expect(target.cpu.arch == .aarch64);
- std.testing.expect(target.os.tag == .linux);
- std.testing.expect(target.os.version_range.linux.range.min.major == 3);
- std.testing.expect(target.os.version_range.linux.range.min.minor == 10);
- std.testing.expect(target.os.version_range.linux.range.min.patch == 0);
- std.testing.expect(target.os.version_range.linux.range.max.major == 4);
- std.testing.expect(target.os.version_range.linux.range.max.minor == 4);
- std.testing.expect(target.os.version_range.linux.range.max.patch == 1);
- std.testing.expect(target.os.version_range.linux.glibc.major == 2);
- std.testing.expect(target.os.version_range.linux.glibc.minor == 27);
- std.testing.expect(target.os.version_range.linux.glibc.patch == 0);
- std.testing.expect(target.abi == .gnu);
+ try std.testing.expect(target.cpu.arch == .aarch64);
+ try std.testing.expect(target.os.tag == .linux);
+ try std.testing.expect(target.os.version_range.linux.range.min.major == 3);
+ try std.testing.expect(target.os.version_range.linux.range.min.minor == 10);
+ try std.testing.expect(target.os.version_range.linux.range.min.patch == 0);
+ try std.testing.expect(target.os.version_range.linux.range.max.major == 4);
+ try std.testing.expect(target.os.version_range.linux.range.max.minor == 4);
+ try std.testing.expect(target.os.version_range.linux.range.max.patch == 1);
+ try std.testing.expect(target.os.version_range.linux.glibc.major == 2);
+ try std.testing.expect(target.os.version_range.linux.glibc.minor == 27);
+ try std.testing.expect(target.os.version_range.linux.glibc.patch == 0);
+ try std.testing.expect(target.abi == .gnu);
const text = try cross_target.zigTriple(std.testing.allocator);
defer std.testing.allocator.free(text);
- std.testing.expectEqualSlices(u8, "aarch64-linux.3.10...4.4.1-gnu.2.27", text);
+ try std.testing.expectEqualSlices(u8, "aarch64-linux.3.10...4.4.1-gnu.2.27", text);
}
}
lib/std/zig/parser_test.zig
@@ -988,7 +988,7 @@ test "zig fmt: while else err prong with no block" {
\\ const result = while (returnError()) |value| {
\\ break value;
\\ } else |err| @as(i32, 2);
- \\ expect(result == 2);
+ \\ try expect(result == 2);
\\}
\\
);
@@ -5135,7 +5135,7 @@ test "recovery: missing while rbrace" {
const std = @import("std");
const mem = std.mem;
-const warn = std.debug.warn;
+const print = std.debug.print;
const io = std.io;
const maxInt = std.math.maxInt;
@@ -5177,13 +5177,13 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {
var failing_allocator = std.testing.FailingAllocator.init(&fixed_allocator.allocator, maxInt(usize));
var anything_changed: bool = undefined;
const result_source = try testParse(source, &failing_allocator.allocator, &anything_changed);
- std.testing.expectEqualStrings(expected_source, result_source);
+ try std.testing.expectEqualStrings(expected_source, result_source);
const changes_expected = source.ptr != expected_source.ptr;
if (anything_changed != changes_expected) {
- warn("std.zig.render returned {} instead of {}\n", .{ anything_changed, changes_expected });
+ print("std.zig.render returned {} instead of {}\n", .{ anything_changed, changes_expected });
return error.TestFailed;
}
- std.testing.expect(anything_changed == changes_expected);
+ try std.testing.expect(anything_changed == changes_expected);
failing_allocator.allocator.free(result_source);
break :x failing_allocator.index;
};
@@ -5198,7 +5198,7 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {
} else |err| switch (err) {
error.OutOfMemory => {
if (failing_allocator.allocated_bytes != failing_allocator.freed_bytes) {
- warn(
+ print(
"\nfail_index: {d}/{d}\nallocated bytes: {d}\nfreed bytes: {d}\nallocations: {d}\ndeallocations: {d}\n",
.{
fail_index,
@@ -5212,8 +5212,7 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {
return error.MemoryLeakDetected;
}
},
- error.ParseError => @panic("test failed"),
- else => @panic("test failed"),
+ else => return err,
}
}
}
@@ -5227,8 +5226,8 @@ fn testError(source: []const u8, expected_errors: []const Error) !void {
var tree = try std.zig.parse(std.testing.allocator, source);
defer tree.deinit(std.testing.allocator);
- std.testing.expectEqual(expected_errors.len, tree.errors.len);
+ try std.testing.expectEqual(expected_errors.len, tree.errors.len);
for (expected_errors) |expected, i| {
- std.testing.expectEqual(expected, tree.errors[i].tag);
+ try std.testing.expectEqual(expected, tree.errors[i].tag);
}
}
lib/std/zig/string_literal.zig
@@ -153,7 +153,7 @@ test "parse" {
var fixed_buf_alloc = std.heap.FixedBufferAllocator.init(fixed_buf_mem[0..]);
var alloc = &fixed_buf_alloc.allocator;
- expect(eql(u8, "foo", try parseAlloc(alloc, "\"foo\"")));
- expect(eql(u8, "foo", try parseAlloc(alloc, "\"f\x6f\x6f\"")));
- expect(eql(u8, "f💯", try parseAlloc(alloc, "\"f\u{1f4af}\"")));
+ try expect(eql(u8, "foo", try parseAlloc(alloc, "\"foo\"")));
+ try expect(eql(u8, "foo", try parseAlloc(alloc, "\"f\x6f\x6f\"")));
+ try expect(eql(u8, "f💯", try parseAlloc(alloc, "\"f\u{1f4af}\"")));
}
lib/std/zig/tokenizer.zig
@@ -1503,11 +1503,11 @@ pub const Tokenizer = struct {
};
test "tokenizer" {
- testTokenize("test", &.{.keyword_test});
+ try testTokenize("test", &.{.keyword_test});
}
test "line comment followed by top-level comptime" {
- testTokenize(
+ try testTokenize(
\\// line comment
\\comptime {}
\\
@@ -1519,7 +1519,7 @@ test "line comment followed by top-level comptime" {
}
test "tokenizer - unknown length pointer and then c pointer" {
- testTokenize(
+ try testTokenize(
\\[*]u8
\\[*c]u8
, &.{
@@ -1536,72 +1536,72 @@ test "tokenizer - unknown length pointer and then c pointer" {
}
test "tokenizer - code point literal with hex escape" {
- testTokenize(
+ try testTokenize(
\\'\x1b'
, &.{.char_literal});
- testTokenize(
+ try testTokenize(
\\'\x1'
, &.{ .invalid, .invalid });
}
test "tokenizer - code point literal with unicode escapes" {
// Valid unicode escapes
- testTokenize(
+ try testTokenize(
\\'\u{3}'
, &.{.char_literal});
- testTokenize(
+ try testTokenize(
\\'\u{01}'
, &.{.char_literal});
- testTokenize(
+ try testTokenize(
\\'\u{2a}'
, &.{.char_literal});
- testTokenize(
+ try testTokenize(
\\'\u{3f9}'
, &.{.char_literal});
- testTokenize(
+ try testTokenize(
\\'\u{6E09aBc1523}'
, &.{.char_literal});
- testTokenize(
+ try testTokenize(
\\"\u{440}"
, &.{.string_literal});
// Invalid unicode escapes
- testTokenize(
+ try testTokenize(
\\'\u'
, &.{.invalid});
- testTokenize(
+ try testTokenize(
\\'\u{{'
, &.{ .invalid, .invalid });
- testTokenize(
+ try testTokenize(
\\'\u{}'
, &.{ .invalid, .invalid });
- testTokenize(
+ try testTokenize(
\\'\u{s}'
, &.{ .invalid, .invalid });
- testTokenize(
+ try testTokenize(
\\'\u{2z}'
, &.{ .invalid, .invalid });
- testTokenize(
+ try testTokenize(
\\'\u{4a'
, &.{.invalid});
// Test old-style unicode literals
- testTokenize(
+ try testTokenize(
\\'\u0333'
, &.{ .invalid, .invalid });
- testTokenize(
+ try testTokenize(
\\'\U0333'
, &.{ .invalid, .integer_literal, .invalid });
}
test "tokenizer - code point literal with unicode code point" {
- testTokenize(
+ try testTokenize(
\\'💩'
, &.{.char_literal});
}
test "tokenizer - float literal e exponent" {
- testTokenize("a = 4.94065645841246544177e-324;\n", &.{
+ try testTokenize("a = 4.94065645841246544177e-324;\n", &.{
.identifier,
.equal,
.float_literal,
@@ -1610,7 +1610,7 @@ test "tokenizer - float literal e exponent" {
}
test "tokenizer - float literal p exponent" {
- testTokenize("a = 0x1.a827999fcef32p+1022;\n", &.{
+ try testTokenize("a = 0x1.a827999fcef32p+1022;\n", &.{
.identifier,
.equal,
.float_literal,
@@ -1619,84 +1619,84 @@ test "tokenizer - float literal p exponent" {
}
test "tokenizer - chars" {
- testTokenize("'c'", &.{.char_literal});
+ try testTokenize("'c'", &.{.char_literal});
}
test "tokenizer - invalid token characters" {
- testTokenize("#", &.{.invalid});
- testTokenize("`", &.{.invalid});
- testTokenize("'c", &.{.invalid});
- testTokenize("'", &.{.invalid});
- testTokenize("''", &.{ .invalid, .invalid });
+ try testTokenize("#", &.{.invalid});
+ try testTokenize("`", &.{.invalid});
+ try testTokenize("'c", &.{.invalid});
+ try testTokenize("'", &.{.invalid});
+ try testTokenize("''", &.{ .invalid, .invalid });
}
test "tokenizer - invalid literal/comment characters" {
- testTokenize("\"\x00\"", &.{
+ try testTokenize("\"\x00\"", &.{
.string_literal,
.invalid,
});
- testTokenize("//\x00", &.{
+ try testTokenize("//\x00", &.{
.invalid,
});
- testTokenize("//\x1f", &.{
+ try testTokenize("//\x1f", &.{
.invalid,
});
- testTokenize("//\x7f", &.{
+ try testTokenize("//\x7f", &.{
.invalid,
});
}
test "tokenizer - utf8" {
- testTokenize("//\xc2\x80", &.{});
- testTokenize("//\xf4\x8f\xbf\xbf", &.{});
+ try testTokenize("//\xc2\x80", &.{});
+ try testTokenize("//\xf4\x8f\xbf\xbf", &.{});
}
test "tokenizer - invalid utf8" {
- testTokenize("//\x80", &.{
+ try testTokenize("//\x80", &.{
.invalid,
});
- testTokenize("//\xbf", &.{
+ try testTokenize("//\xbf", &.{
.invalid,
});
- testTokenize("//\xf8", &.{
+ try testTokenize("//\xf8", &.{
.invalid,
});
- testTokenize("//\xff", &.{
+ try testTokenize("//\xff", &.{
.invalid,
});
- testTokenize("//\xc2\xc0", &.{
+ try testTokenize("//\xc2\xc0", &.{
.invalid,
});
- testTokenize("//\xe0", &.{
+ try testTokenize("//\xe0", &.{
.invalid,
});
- testTokenize("//\xf0", &.{
+ try testTokenize("//\xf0", &.{
.invalid,
});
- testTokenize("//\xf0\x90\x80\xc0", &.{
+ try testTokenize("//\xf0\x90\x80\xc0", &.{
.invalid,
});
}
test "tokenizer - illegal unicode codepoints" {
// unicode newline characters.U+0085, U+2028, U+2029
- testTokenize("//\xc2\x84", &.{});
- testTokenize("//\xc2\x85", &.{
+ try testTokenize("//\xc2\x84", &.{});
+ try testTokenize("//\xc2\x85", &.{
.invalid,
});
- testTokenize("//\xc2\x86", &.{});
- testTokenize("//\xe2\x80\xa7", &.{});
- testTokenize("//\xe2\x80\xa8", &.{
+ try testTokenize("//\xc2\x86", &.{});
+ try testTokenize("//\xe2\x80\xa7", &.{});
+ try testTokenize("//\xe2\x80\xa8", &.{
.invalid,
});
- testTokenize("//\xe2\x80\xa9", &.{
+ try testTokenize("//\xe2\x80\xa9", &.{
.invalid,
});
- testTokenize("//\xe2\x80\xaa", &.{});
+ try testTokenize("//\xe2\x80\xaa", &.{});
}
test "tokenizer - string identifier and builtin fns" {
- testTokenize(
+ try testTokenize(
\\const @"if" = @import("std");
, &.{
.keyword_const,
@@ -1711,7 +1711,7 @@ test "tokenizer - string identifier and builtin fns" {
}
test "tokenizer - multiline string literal with literal tab" {
- testTokenize(
+ try testTokenize(
\\\\foo bar
, &.{
.multiline_string_literal_line,
@@ -1719,7 +1719,7 @@ test "tokenizer - multiline string literal with literal tab" {
}
test "tokenizer - comments with literal tab" {
- testTokenize(
+ try testTokenize(
\\//foo bar
\\//!foo bar
\\///foo bar
@@ -1735,25 +1735,25 @@ test "tokenizer - comments with literal tab" {
}
test "tokenizer - pipe and then invalid" {
- testTokenize("||=", &.{
+ try testTokenize("||=", &.{
.pipe_pipe,
.equal,
});
}
test "tokenizer - line comment and doc comment" {
- testTokenize("//", &.{});
- testTokenize("// a / b", &.{});
- testTokenize("// /", &.{});
- testTokenize("/// a", &.{.doc_comment});
- testTokenize("///", &.{.doc_comment});
- testTokenize("////", &.{});
- testTokenize("//!", &.{.container_doc_comment});
- testTokenize("//!!", &.{.container_doc_comment});
+ try testTokenize("//", &.{});
+ try testTokenize("// a / b", &.{});
+ try testTokenize("// /", &.{});
+ try testTokenize("/// a", &.{.doc_comment});
+ try testTokenize("///", &.{.doc_comment});
+ try testTokenize("////", &.{});
+ try testTokenize("//!", &.{.container_doc_comment});
+ try testTokenize("//!!", &.{.container_doc_comment});
}
test "tokenizer - line comment followed by identifier" {
- testTokenize(
+ try testTokenize(
\\ Unexpected,
\\ // another
\\ Another,
@@ -1766,14 +1766,14 @@ test "tokenizer - line comment followed by identifier" {
}
test "tokenizer - UTF-8 BOM is recognized and skipped" {
- testTokenize("\xEF\xBB\xBFa;\n", &.{
+ try testTokenize("\xEF\xBB\xBFa;\n", &.{
.identifier,
.semicolon,
});
}
test "correctly parse pointer assignment" {
- testTokenize("b.*=3;\n", &.{
+ try testTokenize("b.*=3;\n", &.{
.identifier,
.period_asterisk,
.equal,
@@ -1783,14 +1783,14 @@ test "correctly parse pointer assignment" {
}
test "correctly parse pointer dereference followed by asterisk" {
- testTokenize("\"b\".* ** 10", &.{
+ try testTokenize("\"b\".* ** 10", &.{
.string_literal,
.period_asterisk,
.asterisk_asterisk,
.integer_literal,
});
- testTokenize("(\"b\".*)** 10", &.{
+ try testTokenize("(\"b\".*)** 10", &.{
.l_paren,
.string_literal,
.period_asterisk,
@@ -1799,7 +1799,7 @@ test "correctly parse pointer dereference followed by asterisk" {
.integer_literal,
});
- testTokenize("\"b\".*** 10", &.{
+ try testTokenize("\"b\".*** 10", &.{
.string_literal,
.invalid_periodasterisks,
.asterisk_asterisk,
@@ -1808,245 +1808,245 @@ test "correctly parse pointer dereference followed by asterisk" {
}
test "tokenizer - range literals" {
- testTokenize("0...9", &.{ .integer_literal, .ellipsis3, .integer_literal });
- testTokenize("'0'...'9'", &.{ .char_literal, .ellipsis3, .char_literal });
- testTokenize("0x00...0x09", &.{ .integer_literal, .ellipsis3, .integer_literal });
- testTokenize("0b00...0b11", &.{ .integer_literal, .ellipsis3, .integer_literal });
- testTokenize("0o00...0o11", &.{ .integer_literal, .ellipsis3, .integer_literal });
+ try testTokenize("0...9", &.{ .integer_literal, .ellipsis3, .integer_literal });
+ try testTokenize("'0'...'9'", &.{ .char_literal, .ellipsis3, .char_literal });
+ try testTokenize("0x00...0x09", &.{ .integer_literal, .ellipsis3, .integer_literal });
+ try testTokenize("0b00...0b11", &.{ .integer_literal, .ellipsis3, .integer_literal });
+ try testTokenize("0o00...0o11", &.{ .integer_literal, .ellipsis3, .integer_literal });
}
test "tokenizer - number literals decimal" {
- testTokenize("0", &.{.integer_literal});
- testTokenize("1", &.{.integer_literal});
- testTokenize("2", &.{.integer_literal});
- testTokenize("3", &.{.integer_literal});
- testTokenize("4", &.{.integer_literal});
- testTokenize("5", &.{.integer_literal});
- testTokenize("6", &.{.integer_literal});
- testTokenize("7", &.{.integer_literal});
- testTokenize("8", &.{.integer_literal});
- testTokenize("9", &.{.integer_literal});
- testTokenize("1..", &.{ .integer_literal, .ellipsis2 });
- testTokenize("0a", &.{ .invalid, .identifier });
- testTokenize("9b", &.{ .invalid, .identifier });
- testTokenize("1z", &.{ .invalid, .identifier });
- testTokenize("1z_1", &.{ .invalid, .identifier });
- testTokenize("9z3", &.{ .invalid, .identifier });
-
- testTokenize("0_0", &.{.integer_literal});
- testTokenize("0001", &.{.integer_literal});
- testTokenize("01234567890", &.{.integer_literal});
- testTokenize("012_345_6789_0", &.{.integer_literal});
- testTokenize("0_1_2_3_4_5_6_7_8_9_0", &.{.integer_literal});
-
- testTokenize("00_", &.{.invalid});
- testTokenize("0_0_", &.{.invalid});
- testTokenize("0__0", &.{ .invalid, .identifier });
- testTokenize("0_0f", &.{ .invalid, .identifier });
- testTokenize("0_0_f", &.{ .invalid, .identifier });
- testTokenize("0_0_f_00", &.{ .invalid, .identifier });
- testTokenize("1_,", &.{ .invalid, .comma });
-
- testTokenize("1.", &.{.float_literal});
- testTokenize("0.0", &.{.float_literal});
- testTokenize("1.0", &.{.float_literal});
- testTokenize("10.0", &.{.float_literal});
- testTokenize("0e0", &.{.float_literal});
- testTokenize("1e0", &.{.float_literal});
- testTokenize("1e100", &.{.float_literal});
- testTokenize("1.e100", &.{.float_literal});
- testTokenize("1.0e100", &.{.float_literal});
- testTokenize("1.0e+100", &.{.float_literal});
- testTokenize("1.0e-100", &.{.float_literal});
- testTokenize("1_0_0_0.0_0_0_0_0_1e1_0_0_0", &.{.float_literal});
- testTokenize("1.+", &.{ .float_literal, .plus });
-
- testTokenize("1e", &.{.invalid});
- testTokenize("1.0e1f0", &.{ .invalid, .identifier });
- testTokenize("1.0p100", &.{ .invalid, .identifier });
- testTokenize("1.0p-100", &.{ .invalid, .identifier, .minus, .integer_literal });
- testTokenize("1.0p1f0", &.{ .invalid, .identifier });
- testTokenize("1.0_,", &.{ .invalid, .comma });
- testTokenize("1_.0", &.{ .invalid, .period, .integer_literal });
- testTokenize("1._", &.{ .invalid, .identifier });
- testTokenize("1.a", &.{ .invalid, .identifier });
- testTokenize("1.z", &.{ .invalid, .identifier });
- testTokenize("1._0", &.{ .invalid, .identifier });
- testTokenize("1._+", &.{ .invalid, .identifier, .plus });
- testTokenize("1._e", &.{ .invalid, .identifier });
- testTokenize("1.0e", &.{.invalid});
- testTokenize("1.0e,", &.{ .invalid, .comma });
- testTokenize("1.0e_", &.{ .invalid, .identifier });
- testTokenize("1.0e+_", &.{ .invalid, .identifier });
- testTokenize("1.0e-_", &.{ .invalid, .identifier });
- testTokenize("1.0e0_+", &.{ .invalid, .plus });
+ try testTokenize("0", &.{.integer_literal});
+ try testTokenize("1", &.{.integer_literal});
+ try testTokenize("2", &.{.integer_literal});
+ try testTokenize("3", &.{.integer_literal});
+ try testTokenize("4", &.{.integer_literal});
+ try testTokenize("5", &.{.integer_literal});
+ try testTokenize("6", &.{.integer_literal});
+ try testTokenize("7", &.{.integer_literal});
+ try testTokenize("8", &.{.integer_literal});
+ try testTokenize("9", &.{.integer_literal});
+ try testTokenize("1..", &.{ .integer_literal, .ellipsis2 });
+ try testTokenize("0a", &.{ .invalid, .identifier });
+ try testTokenize("9b", &.{ .invalid, .identifier });
+ try testTokenize("1z", &.{ .invalid, .identifier });
+ try testTokenize("1z_1", &.{ .invalid, .identifier });
+ try testTokenize("9z3", &.{ .invalid, .identifier });
+
+ try testTokenize("0_0", &.{.integer_literal});
+ try testTokenize("0001", &.{.integer_literal});
+ try testTokenize("01234567890", &.{.integer_literal});
+ try testTokenize("012_345_6789_0", &.{.integer_literal});
+ try testTokenize("0_1_2_3_4_5_6_7_8_9_0", &.{.integer_literal});
+
+ try testTokenize("00_", &.{.invalid});
+ try testTokenize("0_0_", &.{.invalid});
+ try testTokenize("0__0", &.{ .invalid, .identifier });
+ try testTokenize("0_0f", &.{ .invalid, .identifier });
+ try testTokenize("0_0_f", &.{ .invalid, .identifier });
+ try testTokenize("0_0_f_00", &.{ .invalid, .identifier });
+ try testTokenize("1_,", &.{ .invalid, .comma });
+
+ try testTokenize("1.", &.{.float_literal});
+ try testTokenize("0.0", &.{.float_literal});
+ try testTokenize("1.0", &.{.float_literal});
+ try testTokenize("10.0", &.{.float_literal});
+ try testTokenize("0e0", &.{.float_literal});
+ try testTokenize("1e0", &.{.float_literal});
+ try testTokenize("1e100", &.{.float_literal});
+ try testTokenize("1.e100", &.{.float_literal});
+ try testTokenize("1.0e100", &.{.float_literal});
+ try testTokenize("1.0e+100", &.{.float_literal});
+ try testTokenize("1.0e-100", &.{.float_literal});
+ try testTokenize("1_0_0_0.0_0_0_0_0_1e1_0_0_0", &.{.float_literal});
+ try testTokenize("1.+", &.{ .float_literal, .plus });
+
+ try testTokenize("1e", &.{.invalid});
+ try testTokenize("1.0e1f0", &.{ .invalid, .identifier });
+ try testTokenize("1.0p100", &.{ .invalid, .identifier });
+ try testTokenize("1.0p-100", &.{ .invalid, .identifier, .minus, .integer_literal });
+ try testTokenize("1.0p1f0", &.{ .invalid, .identifier });
+ try testTokenize("1.0_,", &.{ .invalid, .comma });
+ try testTokenize("1_.0", &.{ .invalid, .period, .integer_literal });
+ try testTokenize("1._", &.{ .invalid, .identifier });
+ try testTokenize("1.a", &.{ .invalid, .identifier });
+ try testTokenize("1.z", &.{ .invalid, .identifier });
+ try testTokenize("1._0", &.{ .invalid, .identifier });
+ try testTokenize("1._+", &.{ .invalid, .identifier, .plus });
+ try testTokenize("1._e", &.{ .invalid, .identifier });
+ try testTokenize("1.0e", &.{.invalid});
+ try testTokenize("1.0e,", &.{ .invalid, .comma });
+ try testTokenize("1.0e_", &.{ .invalid, .identifier });
+ try testTokenize("1.0e+_", &.{ .invalid, .identifier });
+ try testTokenize("1.0e-_", &.{ .invalid, .identifier });
+ try testTokenize("1.0e0_+", &.{ .invalid, .plus });
}
test "tokenizer - number literals binary" {
- testTokenize("0b0", &.{.integer_literal});
- testTokenize("0b1", &.{.integer_literal});
- testTokenize("0b2", &.{ .invalid, .integer_literal });
- testTokenize("0b3", &.{ .invalid, .integer_literal });
- testTokenize("0b4", &.{ .invalid, .integer_literal });
- testTokenize("0b5", &.{ .invalid, .integer_literal });
- testTokenize("0b6", &.{ .invalid, .integer_literal });
- testTokenize("0b7", &.{ .invalid, .integer_literal });
- testTokenize("0b8", &.{ .invalid, .integer_literal });
- testTokenize("0b9", &.{ .invalid, .integer_literal });
- testTokenize("0ba", &.{ .invalid, .identifier });
- testTokenize("0bb", &.{ .invalid, .identifier });
- testTokenize("0bc", &.{ .invalid, .identifier });
- testTokenize("0bd", &.{ .invalid, .identifier });
- testTokenize("0be", &.{ .invalid, .identifier });
- testTokenize("0bf", &.{ .invalid, .identifier });
- testTokenize("0bz", &.{ .invalid, .identifier });
-
- testTokenize("0b0000_0000", &.{.integer_literal});
- testTokenize("0b1111_1111", &.{.integer_literal});
- testTokenize("0b10_10_10_10", &.{.integer_literal});
- testTokenize("0b0_1_0_1_0_1_0_1", &.{.integer_literal});
- testTokenize("0b1.", &.{ .integer_literal, .period });
- testTokenize("0b1.0", &.{ .integer_literal, .period, .integer_literal });
-
- testTokenize("0B0", &.{ .invalid, .identifier });
- testTokenize("0b_", &.{ .invalid, .identifier });
- testTokenize("0b_0", &.{ .invalid, .identifier });
- testTokenize("0b1_", &.{.invalid});
- testTokenize("0b0__1", &.{ .invalid, .identifier });
- testTokenize("0b0_1_", &.{.invalid});
- testTokenize("0b1e", &.{ .invalid, .identifier });
- testTokenize("0b1p", &.{ .invalid, .identifier });
- testTokenize("0b1e0", &.{ .invalid, .identifier });
- testTokenize("0b1p0", &.{ .invalid, .identifier });
- testTokenize("0b1_,", &.{ .invalid, .comma });
+ try testTokenize("0b0", &.{.integer_literal});
+ try testTokenize("0b1", &.{.integer_literal});
+ try testTokenize("0b2", &.{ .invalid, .integer_literal });
+ try testTokenize("0b3", &.{ .invalid, .integer_literal });
+ try testTokenize("0b4", &.{ .invalid, .integer_literal });
+ try testTokenize("0b5", &.{ .invalid, .integer_literal });
+ try testTokenize("0b6", &.{ .invalid, .integer_literal });
+ try testTokenize("0b7", &.{ .invalid, .integer_literal });
+ try testTokenize("0b8", &.{ .invalid, .integer_literal });
+ try testTokenize("0b9", &.{ .invalid, .integer_literal });
+ try testTokenize("0ba", &.{ .invalid, .identifier });
+ try testTokenize("0bb", &.{ .invalid, .identifier });
+ try testTokenize("0bc", &.{ .invalid, .identifier });
+ try testTokenize("0bd", &.{ .invalid, .identifier });
+ try testTokenize("0be", &.{ .invalid, .identifier });
+ try testTokenize("0bf", &.{ .invalid, .identifier });
+ try testTokenize("0bz", &.{ .invalid, .identifier });
+
+ try testTokenize("0b0000_0000", &.{.integer_literal});
+ try testTokenize("0b1111_1111", &.{.integer_literal});
+ try testTokenize("0b10_10_10_10", &.{.integer_literal});
+ try testTokenize("0b0_1_0_1_0_1_0_1", &.{.integer_literal});
+ try testTokenize("0b1.", &.{ .integer_literal, .period });
+ try testTokenize("0b1.0", &.{ .integer_literal, .period, .integer_literal });
+
+ try testTokenize("0B0", &.{ .invalid, .identifier });
+ try testTokenize("0b_", &.{ .invalid, .identifier });
+ try testTokenize("0b_0", &.{ .invalid, .identifier });
+ try testTokenize("0b1_", &.{.invalid});
+ try testTokenize("0b0__1", &.{ .invalid, .identifier });
+ try testTokenize("0b0_1_", &.{.invalid});
+ try testTokenize("0b1e", &.{ .invalid, .identifier });
+ try testTokenize("0b1p", &.{ .invalid, .identifier });
+ try testTokenize("0b1e0", &.{ .invalid, .identifier });
+ try testTokenize("0b1p0", &.{ .invalid, .identifier });
+ try testTokenize("0b1_,", &.{ .invalid, .comma });
}
test "tokenizer - number literals octal" {
- testTokenize("0o0", &.{.integer_literal});
- testTokenize("0o1", &.{.integer_literal});
- testTokenize("0o2", &.{.integer_literal});
- testTokenize("0o3", &.{.integer_literal});
- testTokenize("0o4", &.{.integer_literal});
- testTokenize("0o5", &.{.integer_literal});
- testTokenize("0o6", &.{.integer_literal});
- testTokenize("0o7", &.{.integer_literal});
- testTokenize("0o8", &.{ .invalid, .integer_literal });
- testTokenize("0o9", &.{ .invalid, .integer_literal });
- testTokenize("0oa", &.{ .invalid, .identifier });
- testTokenize("0ob", &.{ .invalid, .identifier });
- testTokenize("0oc", &.{ .invalid, .identifier });
- testTokenize("0od", &.{ .invalid, .identifier });
- testTokenize("0oe", &.{ .invalid, .identifier });
- testTokenize("0of", &.{ .invalid, .identifier });
- testTokenize("0oz", &.{ .invalid, .identifier });
-
- testTokenize("0o01234567", &.{.integer_literal});
- testTokenize("0o0123_4567", &.{.integer_literal});
- testTokenize("0o01_23_45_67", &.{.integer_literal});
- testTokenize("0o0_1_2_3_4_5_6_7", &.{.integer_literal});
- testTokenize("0o7.", &.{ .integer_literal, .period });
- testTokenize("0o7.0", &.{ .integer_literal, .period, .integer_literal });
-
- testTokenize("0O0", &.{ .invalid, .identifier });
- testTokenize("0o_", &.{ .invalid, .identifier });
- testTokenize("0o_0", &.{ .invalid, .identifier });
- testTokenize("0o1_", &.{.invalid});
- testTokenize("0o0__1", &.{ .invalid, .identifier });
- testTokenize("0o0_1_", &.{.invalid});
- testTokenize("0o1e", &.{ .invalid, .identifier });
- testTokenize("0o1p", &.{ .invalid, .identifier });
- testTokenize("0o1e0", &.{ .invalid, .identifier });
- testTokenize("0o1p0", &.{ .invalid, .identifier });
- testTokenize("0o_,", &.{ .invalid, .identifier, .comma });
+ try testTokenize("0o0", &.{.integer_literal});
+ try testTokenize("0o1", &.{.integer_literal});
+ try testTokenize("0o2", &.{.integer_literal});
+ try testTokenize("0o3", &.{.integer_literal});
+ try testTokenize("0o4", &.{.integer_literal});
+ try testTokenize("0o5", &.{.integer_literal});
+ try testTokenize("0o6", &.{.integer_literal});
+ try testTokenize("0o7", &.{.integer_literal});
+ try testTokenize("0o8", &.{ .invalid, .integer_literal });
+ try testTokenize("0o9", &.{ .invalid, .integer_literal });
+ try testTokenize("0oa", &.{ .invalid, .identifier });
+ try testTokenize("0ob", &.{ .invalid, .identifier });
+ try testTokenize("0oc", &.{ .invalid, .identifier });
+ try testTokenize("0od", &.{ .invalid, .identifier });
+ try testTokenize("0oe", &.{ .invalid, .identifier });
+ try testTokenize("0of", &.{ .invalid, .identifier });
+ try testTokenize("0oz", &.{ .invalid, .identifier });
+
+ try testTokenize("0o01234567", &.{.integer_literal});
+ try testTokenize("0o0123_4567", &.{.integer_literal});
+ try testTokenize("0o01_23_45_67", &.{.integer_literal});
+ try testTokenize("0o0_1_2_3_4_5_6_7", &.{.integer_literal});
+ try testTokenize("0o7.", &.{ .integer_literal, .period });
+ try testTokenize("0o7.0", &.{ .integer_literal, .period, .integer_literal });
+
+ try testTokenize("0O0", &.{ .invalid, .identifier });
+ try testTokenize("0o_", &.{ .invalid, .identifier });
+ try testTokenize("0o_0", &.{ .invalid, .identifier });
+ try testTokenize("0o1_", &.{.invalid});
+ try testTokenize("0o0__1", &.{ .invalid, .identifier });
+ try testTokenize("0o0_1_", &.{.invalid});
+ try testTokenize("0o1e", &.{ .invalid, .identifier });
+ try testTokenize("0o1p", &.{ .invalid, .identifier });
+ try testTokenize("0o1e0", &.{ .invalid, .identifier });
+ try testTokenize("0o1p0", &.{ .invalid, .identifier });
+ try testTokenize("0o_,", &.{ .invalid, .identifier, .comma });
}
test "tokenizer - number literals hexadeciaml" {
- testTokenize("0x0", &.{.integer_literal});
- testTokenize("0x1", &.{.integer_literal});
- testTokenize("0x2", &.{.integer_literal});
- testTokenize("0x3", &.{.integer_literal});
- testTokenize("0x4", &.{.integer_literal});
- testTokenize("0x5", &.{.integer_literal});
- testTokenize("0x6", &.{.integer_literal});
- testTokenize("0x7", &.{.integer_literal});
- testTokenize("0x8", &.{.integer_literal});
- testTokenize("0x9", &.{.integer_literal});
- testTokenize("0xa", &.{.integer_literal});
- testTokenize("0xb", &.{.integer_literal});
- testTokenize("0xc", &.{.integer_literal});
- testTokenize("0xd", &.{.integer_literal});
- testTokenize("0xe", &.{.integer_literal});
- testTokenize("0xf", &.{.integer_literal});
- testTokenize("0xA", &.{.integer_literal});
- testTokenize("0xB", &.{.integer_literal});
- testTokenize("0xC", &.{.integer_literal});
- testTokenize("0xD", &.{.integer_literal});
- testTokenize("0xE", &.{.integer_literal});
- testTokenize("0xF", &.{.integer_literal});
- testTokenize("0x0z", &.{ .invalid, .identifier });
- testTokenize("0xz", &.{ .invalid, .identifier });
-
- testTokenize("0x0123456789ABCDEF", &.{.integer_literal});
- testTokenize("0x0123_4567_89AB_CDEF", &.{.integer_literal});
- testTokenize("0x01_23_45_67_89AB_CDE_F", &.{.integer_literal});
- testTokenize("0x0_1_2_3_4_5_6_7_8_9_A_B_C_D_E_F", &.{.integer_literal});
-
- testTokenize("0X0", &.{ .invalid, .identifier });
- testTokenize("0x_", &.{ .invalid, .identifier });
- testTokenize("0x_1", &.{ .invalid, .identifier });
- testTokenize("0x1_", &.{.invalid});
- testTokenize("0x0__1", &.{ .invalid, .identifier });
- testTokenize("0x0_1_", &.{.invalid});
- testTokenize("0x_,", &.{ .invalid, .identifier, .comma });
-
- testTokenize("0x1.", &.{.float_literal});
- testTokenize("0x1.0", &.{.float_literal});
- testTokenize("0xF.", &.{.float_literal});
- testTokenize("0xF.0", &.{.float_literal});
- testTokenize("0xF.F", &.{.float_literal});
- testTokenize("0xF.Fp0", &.{.float_literal});
- testTokenize("0xF.FP0", &.{.float_literal});
- testTokenize("0x1p0", &.{.float_literal});
- testTokenize("0xfp0", &.{.float_literal});
- testTokenize("0x1.+0xF.", &.{ .float_literal, .plus, .float_literal });
-
- testTokenize("0x0123456.789ABCDEF", &.{.float_literal});
- testTokenize("0x0_123_456.789_ABC_DEF", &.{.float_literal});
- testTokenize("0x0_1_2_3_4_5_6.7_8_9_A_B_C_D_E_F", &.{.float_literal});
- testTokenize("0x0p0", &.{.float_literal});
- testTokenize("0x0.0p0", &.{.float_literal});
- testTokenize("0xff.ffp10", &.{.float_literal});
- testTokenize("0xff.ffP10", &.{.float_literal});
- testTokenize("0xff.p10", &.{.float_literal});
- testTokenize("0xffp10", &.{.float_literal});
- testTokenize("0xff_ff.ff_ffp1_0_0_0", &.{.float_literal});
- testTokenize("0xf_f_f_f.f_f_f_fp+1_000", &.{.float_literal});
- testTokenize("0xf_f_f_f.f_f_f_fp-1_00_0", &.{.float_literal});
-
- testTokenize("0x1e", &.{.integer_literal});
- testTokenize("0x1e0", &.{.integer_literal});
- testTokenize("0x1p", &.{.invalid});
- testTokenize("0xfp0z1", &.{ .invalid, .identifier });
- testTokenize("0xff.ffpff", &.{ .invalid, .identifier });
- testTokenize("0x0.p", &.{.invalid});
- testTokenize("0x0.z", &.{ .invalid, .identifier });
- testTokenize("0x0._", &.{ .invalid, .identifier });
- testTokenize("0x0_.0", &.{ .invalid, .period, .integer_literal });
- testTokenize("0x0_.0.0", &.{ .invalid, .period, .float_literal });
- testTokenize("0x0._0", &.{ .invalid, .identifier });
- testTokenize("0x0.0_", &.{.invalid});
- testTokenize("0x0_p0", &.{ .invalid, .identifier });
- testTokenize("0x0_.p0", &.{ .invalid, .period, .identifier });
- testTokenize("0x0._p0", &.{ .invalid, .identifier });
- testTokenize("0x0.0_p0", &.{ .invalid, .identifier });
- testTokenize("0x0._0p0", &.{ .invalid, .identifier });
- testTokenize("0x0.0p_0", &.{ .invalid, .identifier });
- testTokenize("0x0.0p+_0", &.{ .invalid, .identifier });
- testTokenize("0x0.0p-_0", &.{ .invalid, .identifier });
- testTokenize("0x0.0p0_", &.{ .invalid, .eof });
+ try testTokenize("0x0", &.{.integer_literal});
+ try testTokenize("0x1", &.{.integer_literal});
+ try testTokenize("0x2", &.{.integer_literal});
+ try testTokenize("0x3", &.{.integer_literal});
+ try testTokenize("0x4", &.{.integer_literal});
+ try testTokenize("0x5", &.{.integer_literal});
+ try testTokenize("0x6", &.{.integer_literal});
+ try testTokenize("0x7", &.{.integer_literal});
+ try testTokenize("0x8", &.{.integer_literal});
+ try testTokenize("0x9", &.{.integer_literal});
+ try testTokenize("0xa", &.{.integer_literal});
+ try testTokenize("0xb", &.{.integer_literal});
+ try testTokenize("0xc", &.{.integer_literal});
+ try testTokenize("0xd", &.{.integer_literal});
+ try testTokenize("0xe", &.{.integer_literal});
+ try testTokenize("0xf", &.{.integer_literal});
+ try testTokenize("0xA", &.{.integer_literal});
+ try testTokenize("0xB", &.{.integer_literal});
+ try testTokenize("0xC", &.{.integer_literal});
+ try testTokenize("0xD", &.{.integer_literal});
+ try testTokenize("0xE", &.{.integer_literal});
+ try testTokenize("0xF", &.{.integer_literal});
+ try testTokenize("0x0z", &.{ .invalid, .identifier });
+ try testTokenize("0xz", &.{ .invalid, .identifier });
+
+ try testTokenize("0x0123456789ABCDEF", &.{.integer_literal});
+ try testTokenize("0x0123_4567_89AB_CDEF", &.{.integer_literal});
+ try testTokenize("0x01_23_45_67_89AB_CDE_F", &.{.integer_literal});
+ try testTokenize("0x0_1_2_3_4_5_6_7_8_9_A_B_C_D_E_F", &.{.integer_literal});
+
+ try testTokenize("0X0", &.{ .invalid, .identifier });
+ try testTokenize("0x_", &.{ .invalid, .identifier });
+ try testTokenize("0x_1", &.{ .invalid, .identifier });
+ try testTokenize("0x1_", &.{.invalid});
+ try testTokenize("0x0__1", &.{ .invalid, .identifier });
+ try testTokenize("0x0_1_", &.{.invalid});
+ try testTokenize("0x_,", &.{ .invalid, .identifier, .comma });
+
+ try testTokenize("0x1.", &.{.float_literal});
+ try testTokenize("0x1.0", &.{.float_literal});
+ try testTokenize("0xF.", &.{.float_literal});
+ try testTokenize("0xF.0", &.{.float_literal});
+ try testTokenize("0xF.F", &.{.float_literal});
+ try testTokenize("0xF.Fp0", &.{.float_literal});
+ try testTokenize("0xF.FP0", &.{.float_literal});
+ try testTokenize("0x1p0", &.{.float_literal});
+ try testTokenize("0xfp0", &.{.float_literal});
+ try testTokenize("0x1.+0xF.", &.{ .float_literal, .plus, .float_literal });
+
+ try testTokenize("0x0123456.789ABCDEF", &.{.float_literal});
+ try testTokenize("0x0_123_456.789_ABC_DEF", &.{.float_literal});
+ try testTokenize("0x0_1_2_3_4_5_6.7_8_9_A_B_C_D_E_F", &.{.float_literal});
+ try testTokenize("0x0p0", &.{.float_literal});
+ try testTokenize("0x0.0p0", &.{.float_literal});
+ try testTokenize("0xff.ffp10", &.{.float_literal});
+ try testTokenize("0xff.ffP10", &.{.float_literal});
+ try testTokenize("0xff.p10", &.{.float_literal});
+ try testTokenize("0xffp10", &.{.float_literal});
+ try testTokenize("0xff_ff.ff_ffp1_0_0_0", &.{.float_literal});
+ try testTokenize("0xf_f_f_f.f_f_f_fp+1_000", &.{.float_literal});
+ try testTokenize("0xf_f_f_f.f_f_f_fp-1_00_0", &.{.float_literal});
+
+ try testTokenize("0x1e", &.{.integer_literal});
+ try testTokenize("0x1e0", &.{.integer_literal});
+ try testTokenize("0x1p", &.{.invalid});
+ try testTokenize("0xfp0z1", &.{ .invalid, .identifier });
+ try testTokenize("0xff.ffpff", &.{ .invalid, .identifier });
+ try testTokenize("0x0.p", &.{.invalid});
+ try testTokenize("0x0.z", &.{ .invalid, .identifier });
+ try testTokenize("0x0._", &.{ .invalid, .identifier });
+ try testTokenize("0x0_.0", &.{ .invalid, .period, .integer_literal });
+ try testTokenize("0x0_.0.0", &.{ .invalid, .period, .float_literal });
+ try testTokenize("0x0._0", &.{ .invalid, .identifier });
+ try testTokenize("0x0.0_", &.{.invalid});
+ try testTokenize("0x0_p0", &.{ .invalid, .identifier });
+ try testTokenize("0x0_.p0", &.{ .invalid, .period, .identifier });
+ try testTokenize("0x0._p0", &.{ .invalid, .identifier });
+ try testTokenize("0x0.0_p0", &.{ .invalid, .identifier });
+ try testTokenize("0x0._0p0", &.{ .invalid, .identifier });
+ try testTokenize("0x0.0p_0", &.{ .invalid, .identifier });
+ try testTokenize("0x0.0p+_0", &.{ .invalid, .identifier });
+ try testTokenize("0x0.0p-_0", &.{ .invalid, .identifier });
+ try testTokenize("0x0.0p0_", &.{ .invalid, .eof });
}
-fn testTokenize(source: []const u8, expected_tokens: []const Token.Tag) void {
+fn testTokenize(source: []const u8, expected_tokens: []const Token.Tag) !void {
var tokenizer = Tokenizer.init(source);
for (expected_tokens) |expected_token_id| {
const token = tokenizer.next();
@@ -2055,6 +2055,6 @@ fn testTokenize(source: []const u8, expected_tokens: []const Token.Tag) void {
}
}
const last_token = tokenizer.next();
- std.testing.expect(last_token.tag == .eof);
- std.testing.expect(last_token.loc.start == source.len);
+ try std.testing.expect(last_token.tag == .eof);
+ try std.testing.expect(last_token.loc.start == source.len);
}
lib/std/array_hash_map.zig
@@ -1064,63 +1064,63 @@ test "basic hash map usage" {
var map = AutoArrayHashMap(i32, i32).init(std.testing.allocator);
defer map.deinit();
- testing.expect((try map.fetchPut(1, 11)) == null);
- testing.expect((try map.fetchPut(2, 22)) == null);
- testing.expect((try map.fetchPut(3, 33)) == null);
- testing.expect((try map.fetchPut(4, 44)) == null);
+ try testing.expect((try map.fetchPut(1, 11)) == null);
+ try testing.expect((try map.fetchPut(2, 22)) == null);
+ try testing.expect((try map.fetchPut(3, 33)) == null);
+ try testing.expect((try map.fetchPut(4, 44)) == null);
try map.putNoClobber(5, 55);
- testing.expect((try map.fetchPut(5, 66)).?.value == 55);
- testing.expect((try map.fetchPut(5, 55)).?.value == 66);
+ try testing.expect((try map.fetchPut(5, 66)).?.value == 55);
+ try testing.expect((try map.fetchPut(5, 55)).?.value == 66);
const gop1 = try map.getOrPut(5);
- testing.expect(gop1.found_existing == true);
- testing.expect(gop1.entry.value == 55);
- testing.expect(gop1.index == 4);
+ try testing.expect(gop1.found_existing == true);
+ try testing.expect(gop1.entry.value == 55);
+ try testing.expect(gop1.index == 4);
gop1.entry.value = 77;
- testing.expect(map.getEntry(5).?.value == 77);
+ try testing.expect(map.getEntry(5).?.value == 77);
const gop2 = try map.getOrPut(99);
- testing.expect(gop2.found_existing == false);
- testing.expect(gop2.index == 5);
+ try testing.expect(gop2.found_existing == false);
+ try testing.expect(gop2.index == 5);
gop2.entry.value = 42;
- testing.expect(map.getEntry(99).?.value == 42);
+ try testing.expect(map.getEntry(99).?.value == 42);
const gop3 = try map.getOrPutValue(5, 5);
- testing.expect(gop3.value == 77);
+ try testing.expect(gop3.value == 77);
const gop4 = try map.getOrPutValue(100, 41);
- testing.expect(gop4.value == 41);
+ try testing.expect(gop4.value == 41);
- testing.expect(map.contains(2));
- testing.expect(map.getEntry(2).?.value == 22);
- testing.expect(map.get(2).? == 22);
+ try testing.expect(map.contains(2));
+ try testing.expect(map.getEntry(2).?.value == 22);
+ try testing.expect(map.get(2).? == 22);
const rmv1 = map.swapRemove(2);
- testing.expect(rmv1.?.key == 2);
- testing.expect(rmv1.?.value == 22);
- testing.expect(map.swapRemove(2) == null);
- testing.expect(map.getEntry(2) == null);
- testing.expect(map.get(2) == null);
+ try testing.expect(rmv1.?.key == 2);
+ try testing.expect(rmv1.?.value == 22);
+ try testing.expect(map.swapRemove(2) == null);
+ try testing.expect(map.getEntry(2) == null);
+ try testing.expect(map.get(2) == null);
// Since we've used `swapRemove` above, the index of this entry should remain unchanged.
- testing.expect(map.getIndex(100).? == 1);
+ try testing.expect(map.getIndex(100).? == 1);
const gop5 = try map.getOrPut(5);
- testing.expect(gop5.found_existing == true);
- testing.expect(gop5.entry.value == 77);
- testing.expect(gop5.index == 4);
+ try testing.expect(gop5.found_existing == true);
+ try testing.expect(gop5.entry.value == 77);
+ try testing.expect(gop5.index == 4);
// Whereas, if we do an `orderedRemove`, it should move the index forward one spot.
const rmv2 = map.orderedRemove(100);
- testing.expect(rmv2.?.key == 100);
- testing.expect(rmv2.?.value == 41);
- testing.expect(map.orderedRemove(100) == null);
- testing.expect(map.getEntry(100) == null);
- testing.expect(map.get(100) == null);
+ try testing.expect(rmv2.?.key == 100);
+ try testing.expect(rmv2.?.value == 41);
+ try testing.expect(map.orderedRemove(100) == null);
+ try testing.expect(map.getEntry(100) == null);
+ try testing.expect(map.get(100) == null);
const gop6 = try map.getOrPut(5);
- testing.expect(gop6.found_existing == true);
- testing.expect(gop6.entry.value == 77);
- testing.expect(gop6.index == 3);
+ try testing.expect(gop6.found_existing == true);
+ try testing.expect(gop6.entry.value == 77);
+ try testing.expect(gop6.index == 3);
map.removeAssertDiscard(3);
}
@@ -1156,11 +1156,11 @@ test "iterator hash map" {
while (it.next()) |entry| : (count += 1) {
buffer[@intCast(usize, entry.key)] = entry.value;
}
- testing.expect(count == 3);
- testing.expect(it.next() == null);
+ try testing.expect(count == 3);
+ try testing.expect(it.next() == null);
for (buffer) |v, i| {
- testing.expect(buffer[@intCast(usize, keys[i])] == values[i]);
+ try testing.expect(buffer[@intCast(usize, keys[i])] == values[i]);
}
it.reset();
@@ -1172,13 +1172,13 @@ test "iterator hash map" {
}
for (buffer[0..2]) |v, i| {
- testing.expect(buffer[@intCast(usize, keys[i])] == values[i]);
+ try testing.expect(buffer[@intCast(usize, keys[i])] == values[i]);
}
it.reset();
var entry = it.next().?;
- testing.expect(entry.key == first_entry.key);
- testing.expect(entry.value == first_entry.value);
+ try testing.expect(entry.key == first_entry.key);
+ try testing.expect(entry.value == first_entry.value);
}
test "ensure capacity" {
@@ -1187,13 +1187,13 @@ test "ensure capacity" {
try map.ensureCapacity(20);
const initial_capacity = map.capacity();
- testing.expect(initial_capacity >= 20);
+ try testing.expect(initial_capacity >= 20);
var i: i32 = 0;
while (i < 20) : (i += 1) {
- testing.expect(map.fetchPutAssumeCapacity(i, i + 10) == null);
+ try testing.expect(map.fetchPutAssumeCapacity(i, i + 10) == null);
}
// shouldn't resize from putAssumeCapacity
- testing.expect(initial_capacity == map.capacity());
+ try testing.expect(initial_capacity == map.capacity());
}
test "clone" {
@@ -1211,7 +1211,7 @@ test "clone" {
i = 0;
while (i < 10) : (i += 1) {
- testing.expect(copy.get(i).? == i * 10);
+ try testing.expect(copy.get(i).? == i * 10);
}
}
@@ -1223,35 +1223,35 @@ test "shrink" {
const num_entries = 20;
var i: i32 = 0;
while (i < num_entries) : (i += 1)
- testing.expect((try map.fetchPut(i, i * 10)) == null);
+ try testing.expect((try map.fetchPut(i, i * 10)) == null);
- testing.expect(map.unmanaged.index_header != null);
- testing.expect(map.count() == num_entries);
+ try testing.expect(map.unmanaged.index_header != null);
+ try testing.expect(map.count() == num_entries);
// Test `shrinkRetainingCapacity`.
map.shrinkRetainingCapacity(17);
- testing.expect(map.count() == 17);
- testing.expect(map.capacity() == 20);
+ try testing.expect(map.count() == 17);
+ try testing.expect(map.capacity() == 20);
i = 0;
while (i < num_entries) : (i += 1) {
const gop = try map.getOrPut(i);
if (i < 17) {
- testing.expect(gop.found_existing == true);
- testing.expect(gop.entry.value == i * 10);
- } else testing.expect(gop.found_existing == false);
+ try testing.expect(gop.found_existing == true);
+ try testing.expect(gop.entry.value == i * 10);
+ } else try testing.expect(gop.found_existing == false);
}
// Test `shrinkAndFree`.
map.shrinkAndFree(15);
- testing.expect(map.count() == 15);
- testing.expect(map.capacity() == 15);
+ try testing.expect(map.count() == 15);
+ try testing.expect(map.capacity() == 15);
i = 0;
while (i < num_entries) : (i += 1) {
const gop = try map.getOrPut(i);
if (i < 15) {
- testing.expect(gop.found_existing == true);
- testing.expect(gop.entry.value == i * 10);
- } else testing.expect(gop.found_existing == false);
+ try testing.expect(gop.found_existing == true);
+ try testing.expect(gop.entry.value == i * 10);
+ } else try testing.expect(gop.found_existing == false);
}
}
@@ -1264,12 +1264,12 @@ test "pop" {
var i: i32 = 0;
while (i < 9) : (i += 1) {
- testing.expect((try map.fetchPut(i, i)) == null);
+ try testing.expect((try map.fetchPut(i, i)) == null);
}
while (i > 0) : (i -= 1) {
const pop = map.pop();
- testing.expect(pop.key == i - 1 and pop.value == i - 1);
+ try testing.expect(pop.key == i - 1 and pop.value == i - 1);
}
}
@@ -1281,10 +1281,10 @@ test "reIndex" {
const num_indexed_entries = 20;
var i: i32 = 0;
while (i < num_indexed_entries) : (i += 1)
- testing.expect((try map.fetchPut(i, i * 10)) == null);
+ try testing.expect((try map.fetchPut(i, i * 10)) == null);
// Make sure we allocated an index header.
- testing.expect(map.unmanaged.index_header != null);
+ try testing.expect(map.unmanaged.index_header != null);
// Now write to the underlying array list directly.
const num_unindexed_entries = 20;
@@ -1303,9 +1303,9 @@ test "reIndex" {
i = 0;
while (i < num_indexed_entries + num_unindexed_entries) : (i += 1) {
const gop = try map.getOrPut(i);
- testing.expect(gop.found_existing == true);
- testing.expect(gop.entry.value == i * 10);
- testing.expect(gop.index == i);
+ try testing.expect(gop.found_existing == true);
+ try testing.expect(gop.entry.value == i * 10);
+ try testing.expect(gop.index == i);
}
}
@@ -1332,9 +1332,9 @@ test "fromOwnedArrayList" {
i = 0;
while (i < num_entries) : (i += 1) {
const gop = try map.getOrPut(i);
- testing.expect(gop.found_existing == true);
- testing.expect(gop.entry.value == i * 10);
- testing.expect(gop.index == i);
+ try testing.expect(gop.found_existing == true);
+ try testing.expect(gop.entry.value == i * 10);
+ try testing.expect(gop.index == i);
}
}
lib/std/array_list.zig
@@ -695,15 +695,15 @@ test "std.ArrayList/ArrayListUnmanaged.init" {
var list = ArrayList(i32).init(testing.allocator);
defer list.deinit();
- testing.expect(list.items.len == 0);
- testing.expect(list.capacity == 0);
+ try testing.expect(list.items.len == 0);
+ try testing.expect(list.capacity == 0);
}
{
var list = ArrayListUnmanaged(i32){};
- testing.expect(list.items.len == 0);
- testing.expect(list.capacity == 0);
+ try testing.expect(list.items.len == 0);
+ try testing.expect(list.capacity == 0);
}
}
@@ -712,14 +712,14 @@ test "std.ArrayList/ArrayListUnmanaged.initCapacity" {
{
var list = try ArrayList(i8).initCapacity(a, 200);
defer list.deinit();
- testing.expect(list.items.len == 0);
- testing.expect(list.capacity >= 200);
+ try testing.expect(list.items.len == 0);
+ try testing.expect(list.capacity >= 200);
}
{
var list = try ArrayListUnmanaged(i8).initCapacity(a, 200);
defer list.deinit(a);
- testing.expect(list.items.len == 0);
- testing.expect(list.capacity >= 200);
+ try testing.expect(list.items.len == 0);
+ try testing.expect(list.capacity >= 200);
}
}
@@ -739,33 +739,33 @@ test "std.ArrayList/ArrayListUnmanaged.basic" {
{
var i: usize = 0;
while (i < 10) : (i += 1) {
- testing.expect(list.items[i] == @intCast(i32, i + 1));
+ try testing.expect(list.items[i] == @intCast(i32, i + 1));
}
}
for (list.items) |v, i| {
- testing.expect(v == @intCast(i32, i + 1));
+ try testing.expect(v == @intCast(i32, i + 1));
}
- testing.expect(list.pop() == 10);
- testing.expect(list.items.len == 9);
+ try testing.expect(list.pop() == 10);
+ try testing.expect(list.items.len == 9);
list.appendSlice(&[_]i32{ 1, 2, 3 }) catch unreachable;
- testing.expect(list.items.len == 12);
- testing.expect(list.pop() == 3);
- testing.expect(list.pop() == 2);
- testing.expect(list.pop() == 1);
- testing.expect(list.items.len == 9);
+ try testing.expect(list.items.len == 12);
+ try testing.expect(list.pop() == 3);
+ try testing.expect(list.pop() == 2);
+ try testing.expect(list.pop() == 1);
+ try testing.expect(list.items.len == 9);
list.appendSlice(&[_]i32{}) catch unreachable;
- testing.expect(list.items.len == 9);
+ try testing.expect(list.items.len == 9);
// can only set on indices < self.items.len
list.items[7] = 33;
list.items[8] = 42;
- testing.expect(list.pop() == 42);
- testing.expect(list.pop() == 33);
+ try testing.expect(list.pop() == 42);
+ try testing.expect(list.pop() == 33);
}
{
var list = ArrayListUnmanaged(i32){};
@@ -781,33 +781,33 @@ test "std.ArrayList/ArrayListUnmanaged.basic" {
{
var i: usize = 0;
while (i < 10) : (i += 1) {
- testing.expect(list.items[i] == @intCast(i32, i + 1));
+ try testing.expect(list.items[i] == @intCast(i32, i + 1));
}
}
for (list.items) |v, i| {
- testing.expect(v == @intCast(i32, i + 1));
+ try testing.expect(v == @intCast(i32, i + 1));
}
- testing.expect(list.pop() == 10);
- testing.expect(list.items.len == 9);
+ try testing.expect(list.pop() == 10);
+ try testing.expect(list.items.len == 9);
list.appendSlice(a, &[_]i32{ 1, 2, 3 }) catch unreachable;
- testing.expect(list.items.len == 12);
- testing.expect(list.pop() == 3);
- testing.expect(list.pop() == 2);
- testing.expect(list.pop() == 1);
- testing.expect(list.items.len == 9);
+ try testing.expect(list.items.len == 12);
+ try testing.expect(list.pop() == 3);
+ try testing.expect(list.pop() == 2);
+ try testing.expect(list.pop() == 1);
+ try testing.expect(list.items.len == 9);
list.appendSlice(a, &[_]i32{}) catch unreachable;
- testing.expect(list.items.len == 9);
+ try testing.expect(list.items.len == 9);
// can only set on indices < self.items.len
list.items[7] = 33;
list.items[8] = 42;
- testing.expect(list.pop() == 42);
- testing.expect(list.pop() == 33);
+ try testing.expect(list.pop() == 42);
+ try testing.expect(list.pop() == 33);
}
}
@@ -818,9 +818,9 @@ test "std.ArrayList/ArrayListUnmanaged.appendNTimes" {
defer list.deinit();
try list.appendNTimes(2, 10);
- testing.expectEqual(@as(usize, 10), list.items.len);
+ try testing.expectEqual(@as(usize, 10), list.items.len);
for (list.items) |element| {
- testing.expectEqual(@as(i32, 2), element);
+ try testing.expectEqual(@as(i32, 2), element);
}
}
{
@@ -828,9 +828,9 @@ test "std.ArrayList/ArrayListUnmanaged.appendNTimes" {
defer list.deinit(a);
try list.appendNTimes(a, 2, 10);
- testing.expectEqual(@as(usize, 10), list.items.len);
+ try testing.expectEqual(@as(usize, 10), list.items.len);
for (list.items) |element| {
- testing.expectEqual(@as(i32, 2), element);
+ try testing.expectEqual(@as(i32, 2), element);
}
}
}
@@ -840,12 +840,12 @@ test "std.ArrayList/ArrayListUnmanaged.appendNTimes with failing allocator" {
{
var list = ArrayList(i32).init(a);
defer list.deinit();
- testing.expectError(error.OutOfMemory, list.appendNTimes(2, 10));
+ try testing.expectError(error.OutOfMemory, list.appendNTimes(2, 10));
}
{
var list = ArrayListUnmanaged(i32){};
defer list.deinit(a);
- testing.expectError(error.OutOfMemory, list.appendNTimes(a, 2, 10));
+ try testing.expectError(error.OutOfMemory, list.appendNTimes(a, 2, 10));
}
}
@@ -864,18 +864,18 @@ test "std.ArrayList/ArrayListUnmanaged.orderedRemove" {
try list.append(7);
//remove from middle
- testing.expectEqual(@as(i32, 4), list.orderedRemove(3));
- testing.expectEqual(@as(i32, 5), list.items[3]);
- testing.expectEqual(@as(usize, 6), list.items.len);
+ try testing.expectEqual(@as(i32, 4), list.orderedRemove(3));
+ try testing.expectEqual(@as(i32, 5), list.items[3]);
+ try testing.expectEqual(@as(usize, 6), list.items.len);
//remove from end
- testing.expectEqual(@as(i32, 7), list.orderedRemove(5));
- testing.expectEqual(@as(usize, 5), list.items.len);
+ try testing.expectEqual(@as(i32, 7), list.orderedRemove(5));
+ try testing.expectEqual(@as(usize, 5), list.items.len);
//remove from front
- testing.expectEqual(@as(i32, 1), list.orderedRemove(0));
- testing.expectEqual(@as(i32, 2), list.items[0]);
- testing.expectEqual(@as(usize, 4), list.items.len);
+ try testing.expectEqual(@as(i32, 1), list.orderedRemove(0));
+ try testing.expectEqual(@as(i32, 2), list.items[0]);
+ try testing.expectEqual(@as(usize, 4), list.items.len);
}
{
var list = ArrayListUnmanaged(i32){};
@@ -890,18 +890,18 @@ test "std.ArrayList/ArrayListUnmanaged.orderedRemove" {
try list.append(a, 7);
//remove from middle
- testing.expectEqual(@as(i32, 4), list.orderedRemove(3));
- testing.expectEqual(@as(i32, 5), list.items[3]);
- testing.expectEqual(@as(usize, 6), list.items.len);
+ try testing.expectEqual(@as(i32, 4), list.orderedRemove(3));
+ try testing.expectEqual(@as(i32, 5), list.items[3]);
+ try testing.expectEqual(@as(usize, 6), list.items.len);
//remove from end
- testing.expectEqual(@as(i32, 7), list.orderedRemove(5));
- testing.expectEqual(@as(usize, 5), list.items.len);
+ try testing.expectEqual(@as(i32, 7), list.orderedRemove(5));
+ try testing.expectEqual(@as(usize, 5), list.items.len);
//remove from front
- testing.expectEqual(@as(i32, 1), list.orderedRemove(0));
- testing.expectEqual(@as(i32, 2), list.items[0]);
- testing.expectEqual(@as(usize, 4), list.items.len);
+ try testing.expectEqual(@as(i32, 1), list.orderedRemove(0));
+ try testing.expectEqual(@as(i32, 2), list.items[0]);
+ try testing.expectEqual(@as(usize, 4), list.items.len);
}
}
@@ -920,18 +920,18 @@ test "std.ArrayList/ArrayListUnmanaged.swapRemove" {
try list.append(7);
//remove from middle
- testing.expect(list.swapRemove(3) == 4);
- testing.expect(list.items[3] == 7);
- testing.expect(list.items.len == 6);
+ try testing.expect(list.swapRemove(3) == 4);
+ try testing.expect(list.items[3] == 7);
+ try testing.expect(list.items.len == 6);
//remove from end
- testing.expect(list.swapRemove(5) == 6);
- testing.expect(list.items.len == 5);
+ try testing.expect(list.swapRemove(5) == 6);
+ try testing.expect(list.items.len == 5);
//remove from front
- testing.expect(list.swapRemove(0) == 1);
- testing.expect(list.items[0] == 5);
- testing.expect(list.items.len == 4);
+ try testing.expect(list.swapRemove(0) == 1);
+ try testing.expect(list.items[0] == 5);
+ try testing.expect(list.items.len == 4);
}
{
var list = ArrayListUnmanaged(i32){};
@@ -946,18 +946,18 @@ test "std.ArrayList/ArrayListUnmanaged.swapRemove" {
try list.append(a, 7);
//remove from middle
- testing.expect(list.swapRemove(3) == 4);
- testing.expect(list.items[3] == 7);
- testing.expect(list.items.len == 6);
+ try testing.expect(list.swapRemove(3) == 4);
+ try testing.expect(list.items[3] == 7);
+ try testing.expect(list.items.len == 6);
//remove from end
- testing.expect(list.swapRemove(5) == 6);
- testing.expect(list.items.len == 5);
+ try testing.expect(list.swapRemove(5) == 6);
+ try testing.expect(list.items.len == 5);
//remove from front
- testing.expect(list.swapRemove(0) == 1);
- testing.expect(list.items[0] == 5);
- testing.expect(list.items.len == 4);
+ try testing.expect(list.swapRemove(0) == 1);
+ try testing.expect(list.items[0] == 5);
+ try testing.expect(list.items.len == 4);
}
}
@@ -971,10 +971,10 @@ test "std.ArrayList/ArrayListUnmanaged.insert" {
try list.append(2);
try list.append(3);
try list.insert(0, 5);
- testing.expect(list.items[0] == 5);
- testing.expect(list.items[1] == 1);
- testing.expect(list.items[2] == 2);
- testing.expect(list.items[3] == 3);
+ try testing.expect(list.items[0] == 5);
+ try testing.expect(list.items[1] == 1);
+ try testing.expect(list.items[2] == 2);
+ try testing.expect(list.items[3] == 3);
}
{
var list = ArrayListUnmanaged(i32){};
@@ -984,10 +984,10 @@ test "std.ArrayList/ArrayListUnmanaged.insert" {
try list.append(a, 2);
try list.append(a, 3);
try list.insert(a, 0, 5);
- testing.expect(list.items[0] == 5);
- testing.expect(list.items[1] == 1);
- testing.expect(list.items[2] == 2);
- testing.expect(list.items[3] == 3);
+ try testing.expect(list.items[0] == 5);
+ try testing.expect(list.items[1] == 1);
+ try testing.expect(list.items[2] == 2);
+ try testing.expect(list.items[3] == 3);
}
}
@@ -1002,17 +1002,17 @@ test "std.ArrayList/ArrayListUnmanaged.insertSlice" {
try list.append(3);
try list.append(4);
try list.insertSlice(1, &[_]i32{ 9, 8 });
- testing.expect(list.items[0] == 1);
- testing.expect(list.items[1] == 9);
- testing.expect(list.items[2] == 8);
- testing.expect(list.items[3] == 2);
- testing.expect(list.items[4] == 3);
- testing.expect(list.items[5] == 4);
+ try testing.expect(list.items[0] == 1);
+ try testing.expect(list.items[1] == 9);
+ try testing.expect(list.items[2] == 8);
+ try testing.expect(list.items[3] == 2);
+ try testing.expect(list.items[4] == 3);
+ try testing.expect(list.items[5] == 4);
const items = [_]i32{1};
try list.insertSlice(0, items[0..0]);
- testing.expect(list.items.len == 6);
- testing.expect(list.items[0] == 1);
+ try testing.expect(list.items.len == 6);
+ try testing.expect(list.items[0] == 1);
}
{
var list = ArrayListUnmanaged(i32){};
@@ -1023,17 +1023,17 @@ test "std.ArrayList/ArrayListUnmanaged.insertSlice" {
try list.append(a, 3);
try list.append(a, 4);
try list.insertSlice(a, 1, &[_]i32{ 9, 8 });
- testing.expect(list.items[0] == 1);
- testing.expect(list.items[1] == 9);
- testing.expect(list.items[2] == 8);
- testing.expect(list.items[3] == 2);
- testing.expect(list.items[4] == 3);
- testing.expect(list.items[5] == 4);
+ try testing.expect(list.items[0] == 1);
+ try testing.expect(list.items[1] == 9);
+ try testing.expect(list.items[2] == 8);
+ try testing.expect(list.items[3] == 2);
+ try testing.expect(list.items[4] == 3);
+ try testing.expect(list.items[5] == 4);
const items = [_]i32{1};
try list.insertSlice(a, 0, items[0..0]);
- testing.expect(list.items.len == 6);
- testing.expect(list.items[0] == 1);
+ try testing.expect(list.items.len == 6);
+ try testing.expect(list.items[0] == 1);
}
}
@@ -1066,13 +1066,13 @@ test "std.ArrayList/ArrayListUnmanaged.replaceRange" {
try list_lt.replaceRange(1, 2, &new);
// after_range > new_items.len in function body
- testing.expect(1 + 4 > new.len);
+ try testing.expect(1 + 4 > new.len);
try list_gt.replaceRange(1, 4, &new);
- testing.expectEqualSlices(i32, list_zero.items, &result_zero);
- testing.expectEqualSlices(i32, list_eq.items, &result_eq);
- testing.expectEqualSlices(i32, list_lt.items, &result_le);
- testing.expectEqualSlices(i32, list_gt.items, &result_gt);
+ try testing.expectEqualSlices(i32, list_zero.items, &result_zero);
+ try testing.expectEqualSlices(i32, list_eq.items, &result_eq);
+ try testing.expectEqualSlices(i32, list_lt.items, &result_le);
+ try testing.expectEqualSlices(i32, list_gt.items, &result_gt);
}
{
var list_zero = ArrayListUnmanaged(i32){};
@@ -1090,13 +1090,13 @@ test "std.ArrayList/ArrayListUnmanaged.replaceRange" {
try list_lt.replaceRange(a, 1, 2, &new);
// after_range > new_items.len in function body
- testing.expect(1 + 4 > new.len);
+ try testing.expect(1 + 4 > new.len);
try list_gt.replaceRange(a, 1, 4, &new);
- testing.expectEqualSlices(i32, list_zero.items, &result_zero);
- testing.expectEqualSlices(i32, list_eq.items, &result_eq);
- testing.expectEqualSlices(i32, list_lt.items, &result_le);
- testing.expectEqualSlices(i32, list_gt.items, &result_gt);
+ try testing.expectEqualSlices(i32, list_zero.items, &result_zero);
+ try testing.expectEqualSlices(i32, list_eq.items, &result_eq);
+ try testing.expectEqualSlices(i32, list_lt.items, &result_le);
+ try testing.expectEqualSlices(i32, list_gt.items, &result_gt);
}
}
@@ -1116,13 +1116,13 @@ test "std.ArrayList/ArrayListUnmanaged: ArrayList(T) of struct T" {
var root = Item{ .integer = 1, .sub_items = ArrayList(Item).init(a) };
defer root.sub_items.deinit();
try root.sub_items.append(Item{ .integer = 42, .sub_items = ArrayList(Item).init(a) });
- testing.expect(root.sub_items.items[0].integer == 42);
+ try testing.expect(root.sub_items.items[0].integer == 42);
}
{
var root = ItemUnmanaged{ .integer = 1, .sub_items = ArrayListUnmanaged(ItemUnmanaged){} };
defer root.sub_items.deinit(a);
try root.sub_items.append(a, ItemUnmanaged{ .integer = 42, .sub_items = ArrayListUnmanaged(ItemUnmanaged){} });
- testing.expect(root.sub_items.items[0].integer == 42);
+ try testing.expect(root.sub_items.items[0].integer == 42);
}
}
@@ -1137,7 +1137,7 @@ test "std.ArrayList(u8)/ArrayListAligned implements writer" {
const y: i32 = 1234;
try buffer.writer().print("x: {}\ny: {}\n", .{ x, y });
- testing.expectEqualSlices(u8, "x: 42\ny: 1234\n", buffer.items);
+ try testing.expectEqualSlices(u8, "x: 42\ny: 1234\n", buffer.items);
}
{
var list = ArrayListAligned(u8, 2).init(a);
@@ -1149,7 +1149,7 @@ test "std.ArrayList(u8)/ArrayListAligned implements writer" {
try writer.writeAll("d");
try writer.writeAll("efg");
- testing.expectEqualSlices(u8, list.items, "abcdefg");
+ try testing.expectEqualSlices(u8, list.items, "abcdefg");
}
}
@@ -1167,7 +1167,7 @@ test "std.ArrayList/ArrayListUnmanaged.shrink still sets length on error.OutOfMe
try list.append(3);
list.shrinkAndFree(1);
- testing.expect(list.items.len == 1);
+ try testing.expect(list.items.len == 1);
}
{
var list = ArrayListUnmanaged(i32){};
@@ -1177,7 +1177,7 @@ test "std.ArrayList/ArrayListUnmanaged.shrink still sets length on error.OutOfMe
try list.append(a, 3);
list.shrinkAndFree(a, 1);
- testing.expect(list.items.len == 1);
+ try testing.expect(list.items.len == 1);
}
}
@@ -1191,7 +1191,7 @@ test "std.ArrayList/ArrayListUnmanaged.addManyAsArray" {
try list.ensureCapacity(8);
list.addManyAsArrayAssumeCapacity(4).* = "asdf".*;
- testing.expectEqualSlices(u8, list.items, "aoeuasdf");
+ try testing.expectEqualSlices(u8, list.items, "aoeuasdf");
}
{
var list = ArrayListUnmanaged(u8){};
@@ -1201,7 +1201,7 @@ test "std.ArrayList/ArrayListUnmanaged.addManyAsArray" {
try list.ensureCapacity(a, 8);
list.addManyAsArrayAssumeCapacity(4).* = "asdf".*;
- testing.expectEqualSlices(u8, list.items, "aoeuasdf");
+ try testing.expectEqualSlices(u8, list.items, "aoeuasdf");
}
}
@@ -1215,7 +1215,7 @@ test "std.ArrayList/ArrayListUnmanaged.toOwnedSliceSentinel" {
const result = try list.toOwnedSliceSentinel(0);
defer a.free(result);
- testing.expectEqualStrings(result, mem.spanZ(result.ptr));
+ try testing.expectEqualStrings(result, mem.spanZ(result.ptr));
}
{
var list = ArrayListUnmanaged(u8){};
@@ -1225,7 +1225,7 @@ test "std.ArrayList/ArrayListUnmanaged.toOwnedSliceSentinel" {
const result = try list.toOwnedSliceSentinel(a, 0);
defer a.free(result);
- testing.expectEqualStrings(result, mem.spanZ(result.ptr));
+ try testing.expectEqualStrings(result, mem.spanZ(result.ptr));
}
}
@@ -1239,7 +1239,7 @@ test "ArrayListAligned/ArrayListAlignedUnmanaged accepts unaligned slices" {
try list.insertSlice(2, &.{ 4, 5, 6, 7 });
try list.replaceRange(1, 3, &.{ 8, 9 });
- testing.expectEqualSlices(u8, list.items, &.{ 0, 8, 9, 6, 7, 2, 3 });
+ try testing.expectEqualSlices(u8, list.items, &.{ 0, 8, 9, 6, 7, 2, 3 });
}
{
var list = std.ArrayListAlignedUnmanaged(u8, 8){};
@@ -1249,6 +1249,6 @@ test "ArrayListAligned/ArrayListAlignedUnmanaged accepts unaligned slices" {
try list.insertSlice(a, 2, &.{ 4, 5, 6, 7 });
try list.replaceRange(a, 1, 3, &.{ 8, 9 });
- testing.expectEqualSlices(u8, list.items, &.{ 0, 8, 9, 6, 7, 2, 3 });
+ try testing.expectEqualSlices(u8, list.items, &.{ 0, 8, 9, 6, 7, 2, 3 });
}
}
lib/std/ascii.zig
@@ -236,11 +236,11 @@ pub const spaces = [_]u8{ ' ', '\t', '\n', '\r', control_code.VT, control_code.F
test "spaces" {
const testing = std.testing;
- for (spaces) |space| testing.expect(isSpace(space));
+ for (spaces) |space| try testing.expect(isSpace(space));
var i: u8 = 0;
while (isASCII(i)) : (i += 1) {
- if (isSpace(i)) testing.expect(std.mem.indexOfScalar(u8, &spaces, i) != null);
+ if (isSpace(i)) try testing.expect(std.mem.indexOfScalar(u8, &spaces, i) != null);
}
}
@@ -279,13 +279,13 @@ pub fn toLower(c: u8) u8 {
test "ascii character classes" {
const testing = std.testing;
- testing.expect('C' == toUpper('c'));
- testing.expect(':' == toUpper(':'));
- testing.expect('\xab' == toUpper('\xab'));
- testing.expect('c' == toLower('C'));
- testing.expect(isAlpha('c'));
- testing.expect(!isAlpha('5'));
- testing.expect(isSpace(' '));
+ try testing.expect('C' == toUpper('c'));
+ try testing.expect(':' == toUpper(':'));
+ try testing.expect('\xab' == toUpper('\xab'));
+ try testing.expect('c' == toLower('C'));
+ try testing.expect(isAlpha('c'));
+ try testing.expect(!isAlpha('5'));
+ try testing.expect(isSpace(' '));
}
/// Allocates a lower case copy of `ascii_string`.
@@ -301,7 +301,7 @@ pub fn allocLowerString(allocator: *std.mem.Allocator, ascii_string: []const u8)
test "allocLowerString" {
const result = try allocLowerString(std.testing.allocator, "aBcDeFgHiJkLmNOPqrst0234+💩!");
defer std.testing.allocator.free(result);
- std.testing.expect(std.mem.eql(u8, "abcdefghijklmnopqrst0234+💩!", result));
+ try std.testing.expect(std.mem.eql(u8, "abcdefghijklmnopqrst0234+💩!", result));
}
/// Allocates an upper case copy of `ascii_string`.
@@ -317,7 +317,7 @@ pub fn allocUpperString(allocator: *std.mem.Allocator, ascii_string: []const u8)
test "allocUpperString" {
const result = try allocUpperString(std.testing.allocator, "aBcDeFgHiJkLmNOPqrst0234+💩!");
defer std.testing.allocator.free(result);
- std.testing.expect(std.mem.eql(u8, "ABCDEFGHIJKLMNOPQRST0234+💩!", result));
+ try std.testing.expect(std.mem.eql(u8, "ABCDEFGHIJKLMNOPQRST0234+💩!", result));
}
/// Compares strings `a` and `b` case insensitively and returns whether they are equal.
@@ -330,9 +330,9 @@ pub fn eqlIgnoreCase(a: []const u8, b: []const u8) bool {
}
test "eqlIgnoreCase" {
- std.testing.expect(eqlIgnoreCase("HEl💩Lo!", "hel💩lo!"));
- std.testing.expect(!eqlIgnoreCase("hElLo!", "hello! "));
- std.testing.expect(!eqlIgnoreCase("hElLo!", "helro!"));
+ try std.testing.expect(eqlIgnoreCase("HEl💩Lo!", "hel💩lo!"));
+ try std.testing.expect(!eqlIgnoreCase("hElLo!", "hello! "));
+ try std.testing.expect(!eqlIgnoreCase("hElLo!", "helro!"));
}
pub fn startsWithIgnoreCase(haystack: []const u8, needle: []const u8) bool {
@@ -340,8 +340,8 @@ pub fn startsWithIgnoreCase(haystack: []const u8, needle: []const u8) bool {
}
test "ascii.startsWithIgnoreCase" {
- std.testing.expect(startsWithIgnoreCase("boB", "Bo"));
- std.testing.expect(!startsWithIgnoreCase("Needle in hAyStAcK", "haystack"));
+ try std.testing.expect(startsWithIgnoreCase("boB", "Bo"));
+ try std.testing.expect(!startsWithIgnoreCase("Needle in hAyStAcK", "haystack"));
}
pub fn endsWithIgnoreCase(haystack: []const u8, needle: []const u8) bool {
@@ -349,8 +349,8 @@ pub fn endsWithIgnoreCase(haystack: []const u8, needle: []const u8) bool {
}
test "ascii.endsWithIgnoreCase" {
- std.testing.expect(endsWithIgnoreCase("Needle in HaYsTaCk", "haystack"));
- std.testing.expect(!endsWithIgnoreCase("BoB", "Bo"));
+ try std.testing.expect(endsWithIgnoreCase("Needle in HaYsTaCk", "haystack"));
+ try std.testing.expect(!endsWithIgnoreCase("BoB", "Bo"));
}
/// Finds `substr` in `container`, ignoring case, starting at `start_index`.
@@ -372,12 +372,12 @@ pub fn indexOfIgnoreCase(container: []const u8, substr: []const u8) ?usize {
}
test "indexOfIgnoreCase" {
- std.testing.expect(indexOfIgnoreCase("one Two Three Four", "foUr").? == 14);
- std.testing.expect(indexOfIgnoreCase("one two three FouR", "gOur") == null);
- std.testing.expect(indexOfIgnoreCase("foO", "Foo").? == 0);
- std.testing.expect(indexOfIgnoreCase("foo", "fool") == null);
+ try std.testing.expect(indexOfIgnoreCase("one Two Three Four", "foUr").? == 14);
+ try std.testing.expect(indexOfIgnoreCase("one two three FouR", "gOur") == null);
+ try std.testing.expect(indexOfIgnoreCase("foO", "Foo").? == 0);
+ try std.testing.expect(indexOfIgnoreCase("foo", "fool") == null);
- std.testing.expect(indexOfIgnoreCase("FOO foo", "fOo").? == 0);
+ try std.testing.expect(indexOfIgnoreCase("FOO foo", "fOo").? == 0);
}
/// Compares two slices of numbers lexicographically. O(n).
lib/std/base64.zig
@@ -318,14 +318,14 @@ pub const Base64DecoderWithIgnore = struct {
test "base64" {
@setEvalBranchQuota(8000);
- testBase64() catch unreachable;
- comptime testAllApis(standard, "comptime", "Y29tcHRpbWU=") catch unreachable;
+ try testBase64();
+ comptime try testAllApis(standard, "comptime", "Y29tcHRpbWU=");
}
test "base64 url_safe_no_pad" {
@setEvalBranchQuota(8000);
- testBase64UrlSafeNoPad() catch unreachable;
- comptime testAllApis(url_safe_no_pad, "comptime", "Y29tcHRpbWU") catch unreachable;
+ try testBase64UrlSafeNoPad();
+ comptime try testAllApis(url_safe_no_pad, "comptime", "Y29tcHRpbWU");
}
fn testBase64() !void {
@@ -404,7 +404,7 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [
{
var buffer: [0x100]u8 = undefined;
const encoded = codecs.Encoder.encode(&buffer, expected_decoded);
- testing.expectEqualSlices(u8, expected_encoded, encoded);
+ try testing.expectEqualSlices(u8, expected_encoded, encoded);
}
// Base64Decoder
@@ -412,7 +412,7 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [
var buffer: [0x100]u8 = undefined;
var decoded = buffer[0..try codecs.Decoder.calcSizeForSlice(expected_encoded)];
try codecs.Decoder.decode(decoded, expected_encoded);
- testing.expectEqualSlices(u8, expected_decoded, decoded);
+ try testing.expectEqualSlices(u8, expected_decoded, decoded);
}
// Base64DecoderWithIgnore
@@ -421,8 +421,8 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [
var buffer: [0x100]u8 = undefined;
var decoded = buffer[0..try decoder_ignore_nothing.calcSizeUpperBound(expected_encoded.len)];
var written = try decoder_ignore_nothing.decode(decoded, expected_encoded);
- testing.expect(written <= decoded.len);
- testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]);
+ try testing.expect(written <= decoded.len);
+ try testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]);
}
}
@@ -431,7 +431,7 @@ fn testDecodeIgnoreSpace(codecs: Codecs, expected_decoded: []const u8, encoded:
var buffer: [0x100]u8 = undefined;
var decoded = buffer[0..try decoder_ignore_space.calcSizeUpperBound(encoded.len)];
var written = try decoder_ignore_space.decode(decoded, encoded);
- testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]);
+ try testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]);
}
fn testError(codecs: Codecs, encoded: []const u8, expected_err: anyerror) !void {
lib/std/bit_set.zig
@@ -998,9 +998,9 @@ fn BitSetIterator(comptime MaskInt: type, comptime options: IteratorOptions) typ
const testing = std.testing;
-fn testBitSet(a: anytype, b: anytype, len: usize) void {
- testing.expectEqual(len, a.capacity());
- testing.expectEqual(len, b.capacity());
+fn testBitSet(a: anytype, b: anytype, len: usize) !void {
+ try testing.expectEqual(len, a.capacity());
+ try testing.expectEqual(len, b.capacity());
{
var i: usize = 0;
@@ -1010,50 +1010,50 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void {
}
}
- testing.expectEqual((len + 1) / 2, a.count());
- testing.expectEqual((len + 3) / 4 + (len + 2) / 4, b.count());
+ try testing.expectEqual((len + 1) / 2, a.count());
+ try testing.expectEqual((len + 3) / 4 + (len + 2) / 4, b.count());
{
var iter = a.iterator(.{});
var i: usize = 0;
while (i < len) : (i += 2) {
- testing.expectEqual(@as(?usize, i), iter.next());
+ try testing.expectEqual(@as(?usize, i), iter.next());
}
- testing.expectEqual(@as(?usize, null), iter.next());
- testing.expectEqual(@as(?usize, null), iter.next());
- testing.expectEqual(@as(?usize, null), iter.next());
+ try testing.expectEqual(@as(?usize, null), iter.next());
+ try testing.expectEqual(@as(?usize, null), iter.next());
+ try testing.expectEqual(@as(?usize, null), iter.next());
}
a.toggleAll();
{
var iter = a.iterator(.{});
var i: usize = 1;
while (i < len) : (i += 2) {
- testing.expectEqual(@as(?usize, i), iter.next());
+ try testing.expectEqual(@as(?usize, i), iter.next());
}
- testing.expectEqual(@as(?usize, null), iter.next());
- testing.expectEqual(@as(?usize, null), iter.next());
- testing.expectEqual(@as(?usize, null), iter.next());
+ try testing.expectEqual(@as(?usize, null), iter.next());
+ try testing.expectEqual(@as(?usize, null), iter.next());
+ try testing.expectEqual(@as(?usize, null), iter.next());
}
{
var iter = b.iterator(.{ .kind = .unset });
var i: usize = 2;
while (i < len) : (i += 4) {
- testing.expectEqual(@as(?usize, i), iter.next());
+ try testing.expectEqual(@as(?usize, i), iter.next());
if (i + 1 < len) {
- testing.expectEqual(@as(?usize, i + 1), iter.next());
+ try testing.expectEqual(@as(?usize, i + 1), iter.next());
}
}
- testing.expectEqual(@as(?usize, null), iter.next());
- testing.expectEqual(@as(?usize, null), iter.next());
- testing.expectEqual(@as(?usize, null), iter.next());
+ try testing.expectEqual(@as(?usize, null), iter.next());
+ try testing.expectEqual(@as(?usize, null), iter.next());
+ try testing.expectEqual(@as(?usize, null), iter.next());
}
{
var i: usize = 0;
while (i < len) : (i += 1) {
- testing.expectEqual(i & 1 != 0, a.isSet(i));
- testing.expectEqual(i & 2 == 0, b.isSet(i));
+ try testing.expectEqual(i & 1 != 0, a.isSet(i));
+ try testing.expectEqual(i & 2 == 0, b.isSet(i));
}
}
@@ -1061,8 +1061,8 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void {
{
var i: usize = 0;
while (i < len) : (i += 1) {
- testing.expectEqual(i & 1 != 0 or i & 2 == 0, a.isSet(i));
- testing.expectEqual(i & 2 == 0, b.isSet(i));
+ try testing.expectEqual(i & 1 != 0 or i & 2 == 0, a.isSet(i));
+ try testing.expectEqual(i & 2 == 0, b.isSet(i));
}
i = len;
@@ -1071,27 +1071,27 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void {
while (i > 0) {
i -= 1;
if (i & 1 != 0 or i & 2 == 0) {
- testing.expectEqual(@as(?usize, i), set.next());
+ try testing.expectEqual(@as(?usize, i), set.next());
} else {
- testing.expectEqual(@as(?usize, i), unset.next());
+ try testing.expectEqual(@as(?usize, i), unset.next());
}
}
- testing.expectEqual(@as(?usize, null), set.next());
- testing.expectEqual(@as(?usize, null), set.next());
- testing.expectEqual(@as(?usize, null), set.next());
- testing.expectEqual(@as(?usize, null), unset.next());
- testing.expectEqual(@as(?usize, null), unset.next());
- testing.expectEqual(@as(?usize, null), unset.next());
+ try testing.expectEqual(@as(?usize, null), set.next());
+ try testing.expectEqual(@as(?usize, null), set.next());
+ try testing.expectEqual(@as(?usize, null), set.next());
+ try testing.expectEqual(@as(?usize, null), unset.next());
+ try testing.expectEqual(@as(?usize, null), unset.next());
+ try testing.expectEqual(@as(?usize, null), unset.next());
}
a.toggleSet(b.*);
{
- testing.expectEqual(len / 4, a.count());
+ try testing.expectEqual(len / 4, a.count());
var i: usize = 0;
while (i < len) : (i += 1) {
- testing.expectEqual(i & 1 != 0 and i & 2 != 0, a.isSet(i));
- testing.expectEqual(i & 2 == 0, b.isSet(i));
+ try testing.expectEqual(i & 1 != 0 and i & 2 != 0, a.isSet(i));
+ try testing.expectEqual(i & 2 == 0, b.isSet(i));
if (i & 1 == 0) {
a.set(i);
} else {
@@ -1102,29 +1102,29 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void {
a.setIntersection(b.*);
{
- testing.expectEqual((len + 3) / 4, a.count());
+ try testing.expectEqual((len + 3) / 4, a.count());
var i: usize = 0;
while (i < len) : (i += 1) {
- testing.expectEqual(i & 1 == 0 and i & 2 == 0, a.isSet(i));
- testing.expectEqual(i & 2 == 0, b.isSet(i));
+ try testing.expectEqual(i & 1 == 0 and i & 2 == 0, a.isSet(i));
+ try testing.expectEqual(i & 2 == 0, b.isSet(i));
}
}
a.toggleSet(a.*);
{
var iter = a.iterator(.{});
- testing.expectEqual(@as(?usize, null), iter.next());
- testing.expectEqual(@as(?usize, null), iter.next());
- testing.expectEqual(@as(?usize, null), iter.next());
- testing.expectEqual(@as(usize, 0), a.count());
+ try testing.expectEqual(@as(?usize, null), iter.next());
+ try testing.expectEqual(@as(?usize, null), iter.next());
+ try testing.expectEqual(@as(?usize, null), iter.next());
+ try testing.expectEqual(@as(usize, 0), a.count());
}
{
var iter = a.iterator(.{ .direction = .reverse });
- testing.expectEqual(@as(?usize, null), iter.next());
- testing.expectEqual(@as(?usize, null), iter.next());
- testing.expectEqual(@as(?usize, null), iter.next());
- testing.expectEqual(@as(usize, 0), a.count());
+ try testing.expectEqual(@as(?usize, null), iter.next());
+ try testing.expectEqual(@as(?usize, null), iter.next());
+ try testing.expectEqual(@as(?usize, null), iter.next());
+ try testing.expectEqual(@as(usize, 0), a.count());
}
const test_bits = [_]usize{
@@ -1139,51 +1139,51 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void {
for (test_bits) |i| {
if (i < a.capacity()) {
- testing.expectEqual(@as(?usize, i), a.findFirstSet());
- testing.expectEqual(@as(?usize, i), a.toggleFirstSet());
+ try testing.expectEqual(@as(?usize, i), a.findFirstSet());
+ try testing.expectEqual(@as(?usize, i), a.toggleFirstSet());
}
}
- testing.expectEqual(@as(?usize, null), a.findFirstSet());
- testing.expectEqual(@as(?usize, null), a.toggleFirstSet());
- testing.expectEqual(@as(?usize, null), a.findFirstSet());
- testing.expectEqual(@as(?usize, null), a.toggleFirstSet());
- testing.expectEqual(@as(usize, 0), a.count());
+ try testing.expectEqual(@as(?usize, null), a.findFirstSet());
+ try testing.expectEqual(@as(?usize, null), a.toggleFirstSet());
+ try testing.expectEqual(@as(?usize, null), a.findFirstSet());
+ try testing.expectEqual(@as(?usize, null), a.toggleFirstSet());
+ try testing.expectEqual(@as(usize, 0), a.count());
}
-fn testStaticBitSet(comptime Set: type) void {
+fn testStaticBitSet(comptime Set: type) !void {
var a = Set.initEmpty();
var b = Set.initFull();
- testing.expectEqual(@as(usize, 0), a.count());
- testing.expectEqual(@as(usize, Set.bit_length), b.count());
+ try testing.expectEqual(@as(usize, 0), a.count());
+ try testing.expectEqual(@as(usize, Set.bit_length), b.count());
- testBitSet(&a, &b, Set.bit_length);
+ try testBitSet(&a, &b, Set.bit_length);
}
test "IntegerBitSet" {
- testStaticBitSet(IntegerBitSet(0));
- testStaticBitSet(IntegerBitSet(1));
- testStaticBitSet(IntegerBitSet(2));
- testStaticBitSet(IntegerBitSet(5));
- testStaticBitSet(IntegerBitSet(8));
- testStaticBitSet(IntegerBitSet(32));
- testStaticBitSet(IntegerBitSet(64));
- testStaticBitSet(IntegerBitSet(127));
+ try testStaticBitSet(IntegerBitSet(0));
+ try testStaticBitSet(IntegerBitSet(1));
+ try testStaticBitSet(IntegerBitSet(2));
+ try testStaticBitSet(IntegerBitSet(5));
+ try testStaticBitSet(IntegerBitSet(8));
+ try testStaticBitSet(IntegerBitSet(32));
+ try testStaticBitSet(IntegerBitSet(64));
+ try testStaticBitSet(IntegerBitSet(127));
}
test "ArrayBitSet" {
inline for (.{ 0, 1, 2, 31, 32, 33, 63, 64, 65, 254, 500, 3000 }) |size| {
- testStaticBitSet(ArrayBitSet(u8, size));
- testStaticBitSet(ArrayBitSet(u16, size));
- testStaticBitSet(ArrayBitSet(u32, size));
- testStaticBitSet(ArrayBitSet(u64, size));
- testStaticBitSet(ArrayBitSet(u128, size));
+ try testStaticBitSet(ArrayBitSet(u8, size));
+ try testStaticBitSet(ArrayBitSet(u16, size));
+ try testStaticBitSet(ArrayBitSet(u32, size));
+ try testStaticBitSet(ArrayBitSet(u64, size));
+ try testStaticBitSet(ArrayBitSet(u128, size));
}
}
test "DynamicBitSetUnmanaged" {
const allocator = std.testing.allocator;
var a = try DynamicBitSetUnmanaged.initEmpty(300, allocator);
- testing.expectEqual(@as(usize, 0), a.count());
+ try testing.expectEqual(@as(usize, 0), a.count());
a.deinit(allocator);
a = try DynamicBitSetUnmanaged.initEmpty(0, allocator);
@@ -1193,10 +1193,10 @@ test "DynamicBitSetUnmanaged" {
var tmp = try a.clone(allocator);
defer tmp.deinit(allocator);
- testing.expectEqual(old_len, tmp.capacity());
+ try testing.expectEqual(old_len, tmp.capacity());
var i: usize = 0;
while (i < old_len) : (i += 1) {
- testing.expectEqual(a.isSet(i), tmp.isSet(i));
+ try testing.expectEqual(a.isSet(i), tmp.isSet(i));
}
a.toggleSet(a); // zero a
@@ -1206,24 +1206,24 @@ test "DynamicBitSetUnmanaged" {
try tmp.resize(size, false, allocator);
if (size > old_len) {
- testing.expectEqual(size - old_len, a.count());
+ try testing.expectEqual(size - old_len, a.count());
} else {
- testing.expectEqual(@as(usize, 0), a.count());
+ try testing.expectEqual(@as(usize, 0), a.count());
}
- testing.expectEqual(@as(usize, 0), tmp.count());
+ try testing.expectEqual(@as(usize, 0), tmp.count());
var b = try DynamicBitSetUnmanaged.initFull(size, allocator);
defer b.deinit(allocator);
- testing.expectEqual(@as(usize, size), b.count());
+ try testing.expectEqual(@as(usize, size), b.count());
- testBitSet(&a, &b, size);
+ try testBitSet(&a, &b, size);
}
}
test "DynamicBitSet" {
const allocator = std.testing.allocator;
var a = try DynamicBitSet.initEmpty(300, allocator);
- testing.expectEqual(@as(usize, 0), a.count());
+ try testing.expectEqual(@as(usize, 0), a.count());
a.deinit();
a = try DynamicBitSet.initEmpty(0, allocator);
@@ -1233,10 +1233,10 @@ test "DynamicBitSet" {
var tmp = try a.clone(allocator);
defer tmp.deinit();
- testing.expectEqual(old_len, tmp.capacity());
+ try testing.expectEqual(old_len, tmp.capacity());
var i: usize = 0;
while (i < old_len) : (i += 1) {
- testing.expectEqual(a.isSet(i), tmp.isSet(i));
+ try testing.expectEqual(a.isSet(i), tmp.isSet(i));
}
a.toggleSet(a); // zero a
@@ -1246,24 +1246,24 @@ test "DynamicBitSet" {
try tmp.resize(size, false);
if (size > old_len) {
- testing.expectEqual(size - old_len, a.count());
+ try testing.expectEqual(size - old_len, a.count());
} else {
- testing.expectEqual(@as(usize, 0), a.count());
+ try testing.expectEqual(@as(usize, 0), a.count());
}
- testing.expectEqual(@as(usize, 0), tmp.count());
+ try testing.expectEqual(@as(usize, 0), tmp.count());
var b = try DynamicBitSet.initFull(size, allocator);
defer b.deinit();
- testing.expectEqual(@as(usize, size), b.count());
+ try testing.expectEqual(@as(usize, size), b.count());
- testBitSet(&a, &b, size);
+ try testBitSet(&a, &b, size);
}
}
test "StaticBitSet" {
- testing.expectEqual(IntegerBitSet(0), StaticBitSet(0));
- testing.expectEqual(IntegerBitSet(5), StaticBitSet(5));
- testing.expectEqual(IntegerBitSet(@bitSizeOf(usize)), StaticBitSet(@bitSizeOf(usize)));
- testing.expectEqual(ArrayBitSet(usize, @bitSizeOf(usize) + 1), StaticBitSet(@bitSizeOf(usize) + 1));
- testing.expectEqual(ArrayBitSet(usize, 500), StaticBitSet(500));
+ try testing.expectEqual(IntegerBitSet(0), StaticBitSet(0));
+ try testing.expectEqual(IntegerBitSet(5), StaticBitSet(5));
+ try testing.expectEqual(IntegerBitSet(@bitSizeOf(usize)), StaticBitSet(@bitSizeOf(usize)));
+ try testing.expectEqual(ArrayBitSet(usize, @bitSizeOf(usize) + 1), StaticBitSet(@bitSizeOf(usize) + 1));
+ try testing.expectEqual(ArrayBitSet(usize, 500), StaticBitSet(500));
}
lib/std/buf_map.zig
@@ -94,19 +94,19 @@ test "BufMap" {
defer bufmap.deinit();
try bufmap.set("x", "1");
- testing.expect(mem.eql(u8, bufmap.get("x").?, "1"));
- testing.expect(1 == bufmap.count());
+ try testing.expect(mem.eql(u8, bufmap.get("x").?, "1"));
+ try testing.expect(1 == bufmap.count());
try bufmap.set("x", "2");
- testing.expect(mem.eql(u8, bufmap.get("x").?, "2"));
- testing.expect(1 == bufmap.count());
+ try testing.expect(mem.eql(u8, bufmap.get("x").?, "2"));
+ try testing.expect(1 == bufmap.count());
try bufmap.set("x", "3");
- testing.expect(mem.eql(u8, bufmap.get("x").?, "3"));
- testing.expect(1 == bufmap.count());
+ try testing.expect(mem.eql(u8, bufmap.get("x").?, "3"));
+ try testing.expect(1 == bufmap.count());
bufmap.delete("x");
- testing.expect(0 == bufmap.count());
+ try testing.expect(0 == bufmap.count());
try bufmap.setMove(try allocator.dupe(u8, "k"), try allocator.dupe(u8, "v1"));
try bufmap.setMove(try allocator.dupe(u8, "k"), try allocator.dupe(u8, "v2"));
lib/std/buf_set.zig
@@ -73,9 +73,9 @@ test "BufSet" {
defer bufset.deinit();
try bufset.put("x");
- testing.expect(bufset.count() == 1);
+ try testing.expect(bufset.count() == 1);
bufset.delete("x");
- testing.expect(bufset.count() == 0);
+ try testing.expect(bufset.count() == 0);
try bufset.put("x");
try bufset.put("y");
lib/std/build.zig
@@ -3060,19 +3060,19 @@ test "Builder.dupePkg()" {
const dupe_deps = dupe.dependencies.?;
// probably the same top level package details
- std.testing.expectEqualStrings(pkg_top.name, dupe.name);
+ try std.testing.expectEqualStrings(pkg_top.name, dupe.name);
// probably the same dependencies
- std.testing.expectEqual(original_deps.len, dupe_deps.len);
- std.testing.expectEqual(original_deps[0].name, pkg_dep.name);
+ try std.testing.expectEqual(original_deps.len, dupe_deps.len);
+ try std.testing.expectEqual(original_deps[0].name, pkg_dep.name);
// could segfault otherwise if pointers in duplicated package's fields are
// the same as those in stack allocated package's fields
- std.testing.expect(dupe_deps.ptr != original_deps.ptr);
- std.testing.expect(dupe.name.ptr != pkg_top.name.ptr);
- std.testing.expect(dupe.path.ptr != pkg_top.path.ptr);
- std.testing.expect(dupe_deps[0].name.ptr != pkg_dep.name.ptr);
- std.testing.expect(dupe_deps[0].path.ptr != pkg_dep.path.ptr);
+ try std.testing.expect(dupe_deps.ptr != original_deps.ptr);
+ try std.testing.expect(dupe.name.ptr != pkg_top.name.ptr);
+ try std.testing.expect(dupe.path.ptr != pkg_top.path.ptr);
+ try std.testing.expect(dupe_deps[0].name.ptr != pkg_dep.name.ptr);
+ try std.testing.expect(dupe_deps[0].path.ptr != pkg_dep.path.ptr);
}
test "LibExeObjStep.addBuildOption" {
@@ -3096,7 +3096,7 @@ test "LibExeObjStep.addBuildOption" {
exe.addBuildOption(?[]const u8, "optional_string", null);
exe.addBuildOption(std.SemanticVersion, "semantic_version", try std.SemanticVersion.parse("0.1.2-foo+bar"));
- std.testing.expectEqualStrings(
+ try std.testing.expectEqualStrings(
\\pub const option1: usize = 1;
\\pub const option2: ?usize = null;
\\pub const string: []const u8 = "zigisthebest";
@@ -3140,10 +3140,10 @@ test "LibExeObjStep.addPackage" {
var exe = builder.addExecutable("not_an_executable", "/not/an/executable.zig");
exe.addPackage(pkg_top);
- std.testing.expectEqual(@as(usize, 1), exe.packages.items.len);
+ try std.testing.expectEqual(@as(usize, 1), exe.packages.items.len);
const dupe = exe.packages.items[0];
- std.testing.expectEqualStrings(pkg_top.name, dupe.name);
+ try std.testing.expectEqualStrings(pkg_top.name, dupe.name);
}
test {
lib/std/builtin.zig
@@ -546,7 +546,7 @@ pub fn testVersionParse() !void {
const f = struct {
fn eql(text: []const u8, v1: u32, v2: u32, v3: u32) !void {
const v = try Version.parse(text);
- std.testing.expect(v.major == v1 and v.minor == v2 and v.patch == v3);
+ try std.testing.expect(v.major == v1 and v.minor == v2 and v.patch == v3);
}
fn err(text: []const u8, expected_err: anyerror) !void {
lib/std/child_process.zig
@@ -1005,7 +1005,7 @@ test "createNullDelimitedEnvMap" {
defer arena.deinit();
const environ = try createNullDelimitedEnvMap(&arena.allocator, &envmap);
- testing.expectEqual(@as(usize, 5), environ.len);
+ try testing.expectEqual(@as(usize, 5), environ.len);
inline for (.{
"HOME=/home/ifreund",
@@ -1017,7 +1017,7 @@ test "createNullDelimitedEnvMap" {
for (environ) |variable| {
if (mem.eql(u8, mem.span(variable orelse continue), target)) break;
} else {
- testing.expect(false); // Environment variable not found
+ try testing.expect(false); // Environment variable not found
}
}
}
lib/std/comptime_string_map.zig
@@ -95,7 +95,7 @@ test "ComptimeStringMap list literal of list literals" {
.{ "samelen", .E },
});
- testMap(map);
+ try testMap(map);
}
test "ComptimeStringMap array of structs" {
@@ -111,7 +111,7 @@ test "ComptimeStringMap array of structs" {
.{ .@"0" = "samelen", .@"1" = .E },
});
- testMap(map);
+ try testMap(map);
}
test "ComptimeStringMap slice of structs" {
@@ -128,18 +128,18 @@ test "ComptimeStringMap slice of structs" {
};
const map = ComptimeStringMap(TestEnum, slice);
- testMap(map);
+ try testMap(map);
}
-fn testMap(comptime map: anytype) void {
- std.testing.expectEqual(TestEnum.A, map.get("have").?);
- std.testing.expectEqual(TestEnum.B, map.get("nothing").?);
- std.testing.expect(null == map.get("missing"));
- std.testing.expectEqual(TestEnum.D, map.get("these").?);
- std.testing.expectEqual(TestEnum.E, map.get("samelen").?);
+fn testMap(comptime map: anytype) !void {
+ try std.testing.expectEqual(TestEnum.A, map.get("have").?);
+ try std.testing.expectEqual(TestEnum.B, map.get("nothing").?);
+ try std.testing.expect(null == map.get("missing"));
+ try std.testing.expectEqual(TestEnum.D, map.get("these").?);
+ try std.testing.expectEqual(TestEnum.E, map.get("samelen").?);
- std.testing.expect(!map.has("missing"));
- std.testing.expect(map.has("these"));
+ try std.testing.expect(!map.has("missing"));
+ try std.testing.expect(map.has("these"));
}
test "ComptimeStringMap void value type, slice of structs" {
@@ -155,7 +155,7 @@ test "ComptimeStringMap void value type, slice of structs" {
};
const map = ComptimeStringMap(void, slice);
- testSet(map);
+ try testSet(map);
}
test "ComptimeStringMap void value type, list literal of list literals" {
@@ -167,16 +167,16 @@ test "ComptimeStringMap void value type, list literal of list literals" {
.{"samelen"},
});
- testSet(map);
+ try testSet(map);
}
-fn testSet(comptime map: anytype) void {
- std.testing.expectEqual({}, map.get("have").?);
- std.testing.expectEqual({}, map.get("nothing").?);
- std.testing.expect(null == map.get("missing"));
- std.testing.expectEqual({}, map.get("these").?);
- std.testing.expectEqual({}, map.get("samelen").?);
+fn testSet(comptime map: anytype) !void {
+ try std.testing.expectEqual({}, map.get("have").?);
+ try std.testing.expectEqual({}, map.get("nothing").?);
+ try std.testing.expect(null == map.get("missing"));
+ try std.testing.expectEqual({}, map.get("these").?);
+ try std.testing.expectEqual({}, map.get("samelen").?);
- std.testing.expect(!map.has("missing"));
- std.testing.expect(map.has("these"));
+ try std.testing.expect(!map.has("missing"));
+ try std.testing.expect(map.has("these"));
}
lib/std/crypto.zig
@@ -188,7 +188,7 @@ test "CSPRNG" {
const a = random.int(u64);
const b = random.int(u64);
const c = random.int(u64);
- std.testing.expect(a ^ b ^ c != 0);
+ try std.testing.expect(a ^ b ^ c != 0);
}
test "issue #4532: no index out of bounds" {
@@ -226,6 +226,6 @@ test "issue #4532: no index out of bounds" {
h.update(block[1..]);
h.final(&out2);
- std.testing.expectEqual(out1, out2);
+ try std.testing.expectEqual(out1, out2);
}
}
lib/std/cstr.zig
@@ -27,13 +27,13 @@ pub fn cmp(a: [*:0]const u8, b: [*:0]const u8) i8 {
}
test "cstr fns" {
- comptime testCStrFnsImpl();
- testCStrFnsImpl();
+ comptime try testCStrFnsImpl();
+ try testCStrFnsImpl();
}
-fn testCStrFnsImpl() void {
- testing.expect(cmp("aoeu", "aoez") == -1);
- testing.expect(mem.len("123456789") == 9);
+fn testCStrFnsImpl() !void {
+ try testing.expect(cmp("aoeu", "aoez") == -1);
+ try testing.expect(mem.len("123456789") == 9);
}
/// Returns a mutable, null-terminated slice with the same length as `slice`.
@@ -48,8 +48,8 @@ pub fn addNullByte(allocator: *mem.Allocator, slice: []const u8) ![:0]u8 {
test "addNullByte" {
const slice = try addNullByte(std.testing.allocator, "hello"[0..4]);
defer std.testing.allocator.free(slice);
- testing.expect(slice.len == 4);
- testing.expect(slice[4] == 0);
+ try testing.expect(slice.len == 4);
+ try testing.expect(slice[4] == 0);
}
pub const NullTerminated2DArray = struct {
lib/std/dynamic_library.zig
@@ -408,7 +408,7 @@ test "dynamic_library" {
};
const dynlib = DynLib.open(libname) catch |err| {
- testing.expect(err == error.FileNotFound);
+ try testing.expect(err == error.FileNotFound);
return;
};
}
lib/std/elf.zig
@@ -565,7 +565,7 @@ test "bswapAllFields" {
.ch_addralign = 0x12124242,
};
bswapAllFields(Elf32_Chdr, &s);
- std.testing.expectEqual(Elf32_Chdr{
+ try std.testing.expectEqual(Elf32_Chdr{
.ch_type = 0x34123412,
.ch_size = 0x78567856,
.ch_addralign = 0x42421212,
lib/std/enums.zig
@@ -56,10 +56,10 @@ test "std.enums.valuesFromFields" {
.{ .name = "a", .value = undefined },
.{ .name = "d", .value = undefined },
});
- testing.expectEqual(E.b, fields[0]);
- testing.expectEqual(E.a, fields[1]);
- testing.expectEqual(E.d, fields[2]); // a == d
- testing.expectEqual(E.d, fields[3]);
+ try testing.expectEqual(E.b, fields[0]);
+ try testing.expectEqual(E.a, fields[1]);
+ try testing.expectEqual(E.d, fields[2]); // a == d
+ try testing.expectEqual(E.d, fields[3]);
}
/// Returns the set of all named values in the given enum, in
@@ -70,7 +70,7 @@ pub fn values(comptime E: type) []const E {
test "std.enum.values" {
const E = extern enum { a, b, c, d = 0 };
- testing.expectEqualSlices(E, &.{ .a, .b, .c, .d }, values(E));
+ try testing.expectEqualSlices(E, &.{ .a, .b, .c, .d }, values(E));
}
/// Returns the set of all unique named values in the given enum, in
@@ -82,10 +82,10 @@ pub fn uniqueValues(comptime E: type) []const E {
test "std.enum.uniqueValues" {
const E = extern enum { a, b, c, d = 0, e, f = 3 };
- testing.expectEqualSlices(E, &.{ .a, .b, .c, .f }, uniqueValues(E));
+ try testing.expectEqualSlices(E, &.{ .a, .b, .c, .f }, uniqueValues(E));
const F = enum { a, b, c };
- testing.expectEqualSlices(F, &.{ .a, .b, .c }, uniqueValues(F));
+ try testing.expectEqualSlices(F, &.{ .a, .b, .c }, uniqueValues(F));
}
/// Returns the set of all unique field values in the given enum, in
@@ -179,10 +179,10 @@ test "std.enums.directEnumArray" {
.c = true,
});
- testing.expectEqual([7]bool, @TypeOf(array));
- testing.expectEqual(true, array[4]);
- testing.expectEqual(false, array[6]);
- testing.expectEqual(true, array[2]);
+ try testing.expectEqual([7]bool, @TypeOf(array));
+ try testing.expectEqual(true, array[4]);
+ try testing.expectEqual(false, array[6]);
+ try testing.expectEqual(true, array[2]);
}
/// Initializes an array of Data which can be indexed by
@@ -220,10 +220,10 @@ test "std.enums.directEnumArrayDefault" {
.b = runtime_false,
});
- testing.expectEqual([7]bool, @TypeOf(array));
- testing.expectEqual(true, array[4]);
- testing.expectEqual(false, array[6]);
- testing.expectEqual(false, array[2]);
+ try testing.expectEqual([7]bool, @TypeOf(array));
+ try testing.expectEqual(true, array[4]);
+ try testing.expectEqual(false, array[6]);
+ try testing.expectEqual(false, array[2]);
}
/// Cast an enum literal, value, or string to the enum value of type E
@@ -250,23 +250,23 @@ pub fn nameCast(comptime E: type, comptime value: anytype) E {
test "std.enums.nameCast" {
const A = enum { a = 0, b = 1 };
const B = enum { a = 1, b = 0 };
- testing.expectEqual(A.a, nameCast(A, .a));
- testing.expectEqual(A.a, nameCast(A, A.a));
- testing.expectEqual(A.a, nameCast(A, B.a));
- testing.expectEqual(A.a, nameCast(A, "a"));
- testing.expectEqual(A.a, nameCast(A, @as(*const [1]u8, "a")));
- testing.expectEqual(A.a, nameCast(A, @as([:0]const u8, "a")));
- testing.expectEqual(A.a, nameCast(A, @as([]const u8, "a")));
-
- testing.expectEqual(B.a, nameCast(B, .a));
- testing.expectEqual(B.a, nameCast(B, A.a));
- testing.expectEqual(B.a, nameCast(B, B.a));
- testing.expectEqual(B.a, nameCast(B, "a"));
-
- testing.expectEqual(B.b, nameCast(B, .b));
- testing.expectEqual(B.b, nameCast(B, A.b));
- testing.expectEqual(B.b, nameCast(B, B.b));
- testing.expectEqual(B.b, nameCast(B, "b"));
+ try testing.expectEqual(A.a, nameCast(A, .a));
+ try testing.expectEqual(A.a, nameCast(A, A.a));
+ try testing.expectEqual(A.a, nameCast(A, B.a));
+ try testing.expectEqual(A.a, nameCast(A, "a"));
+ try testing.expectEqual(A.a, nameCast(A, @as(*const [1]u8, "a")));
+ try testing.expectEqual(A.a, nameCast(A, @as([:0]const u8, "a")));
+ try testing.expectEqual(A.a, nameCast(A, @as([]const u8, "a")));
+
+ try testing.expectEqual(B.a, nameCast(B, .a));
+ try testing.expectEqual(B.a, nameCast(B, A.a));
+ try testing.expectEqual(B.a, nameCast(B, B.a));
+ try testing.expectEqual(B.a, nameCast(B, "a"));
+
+ try testing.expectEqual(B.b, nameCast(B, .b));
+ try testing.expectEqual(B.b, nameCast(B, A.b));
+ try testing.expectEqual(B.b, nameCast(B, B.b));
+ try testing.expectEqual(B.b, nameCast(B, "b"));
}
/// A set of enum elements, backed by a bitfield. If the enum
@@ -851,202 +851,202 @@ test "std.enums.EnumIndexer dense zeroed" {
const E = enum { b = 1, a = 0, c = 2 };
const Indexer = EnumIndexer(E);
ensureIndexer(Indexer);
- testing.expectEqual(E, Indexer.Key);
- testing.expectEqual(@as(usize, 3), Indexer.count);
+ try testing.expectEqual(E, Indexer.Key);
+ try testing.expectEqual(@as(usize, 3), Indexer.count);
- testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
- testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
- testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
+ try testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
+ try testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
+ try testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
- testing.expectEqual(E.a, Indexer.keyForIndex(0));
- testing.expectEqual(E.b, Indexer.keyForIndex(1));
- testing.expectEqual(E.c, Indexer.keyForIndex(2));
+ try testing.expectEqual(E.a, Indexer.keyForIndex(0));
+ try testing.expectEqual(E.b, Indexer.keyForIndex(1));
+ try testing.expectEqual(E.c, Indexer.keyForIndex(2));
}
test "std.enums.EnumIndexer dense positive" {
const E = enum(u4) { c = 6, a = 4, b = 5 };
const Indexer = EnumIndexer(E);
ensureIndexer(Indexer);
- testing.expectEqual(E, Indexer.Key);
- testing.expectEqual(@as(usize, 3), Indexer.count);
+ try testing.expectEqual(E, Indexer.Key);
+ try testing.expectEqual(@as(usize, 3), Indexer.count);
- testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
- testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
- testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
+ try testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
+ try testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
+ try testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
- testing.expectEqual(E.a, Indexer.keyForIndex(0));
- testing.expectEqual(E.b, Indexer.keyForIndex(1));
- testing.expectEqual(E.c, Indexer.keyForIndex(2));
+ try testing.expectEqual(E.a, Indexer.keyForIndex(0));
+ try testing.expectEqual(E.b, Indexer.keyForIndex(1));
+ try testing.expectEqual(E.c, Indexer.keyForIndex(2));
}
test "std.enums.EnumIndexer dense negative" {
const E = enum(i4) { a = -6, c = -4, b = -5 };
const Indexer = EnumIndexer(E);
ensureIndexer(Indexer);
- testing.expectEqual(E, Indexer.Key);
- testing.expectEqual(@as(usize, 3), Indexer.count);
+ try testing.expectEqual(E, Indexer.Key);
+ try testing.expectEqual(@as(usize, 3), Indexer.count);
- testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
- testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
- testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
+ try testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
+ try testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
+ try testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
- testing.expectEqual(E.a, Indexer.keyForIndex(0));
- testing.expectEqual(E.b, Indexer.keyForIndex(1));
- testing.expectEqual(E.c, Indexer.keyForIndex(2));
+ try testing.expectEqual(E.a, Indexer.keyForIndex(0));
+ try testing.expectEqual(E.b, Indexer.keyForIndex(1));
+ try testing.expectEqual(E.c, Indexer.keyForIndex(2));
}
test "std.enums.EnumIndexer sparse" {
const E = enum(i4) { a = -2, c = 6, b = 4 };
const Indexer = EnumIndexer(E);
ensureIndexer(Indexer);
- testing.expectEqual(E, Indexer.Key);
- testing.expectEqual(@as(usize, 3), Indexer.count);
+ try testing.expectEqual(E, Indexer.Key);
+ try testing.expectEqual(@as(usize, 3), Indexer.count);
- testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
- testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
- testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
+ try testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
+ try testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
+ try testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
- testing.expectEqual(E.a, Indexer.keyForIndex(0));
- testing.expectEqual(E.b, Indexer.keyForIndex(1));
- testing.expectEqual(E.c, Indexer.keyForIndex(2));
+ try testing.expectEqual(E.a, Indexer.keyForIndex(0));
+ try testing.expectEqual(E.b, Indexer.keyForIndex(1));
+ try testing.expectEqual(E.c, Indexer.keyForIndex(2));
}
test "std.enums.EnumIndexer repeats" {
const E = extern enum { a = -2, c = 6, b = 4, b2 = 4 };
const Indexer = EnumIndexer(E);
ensureIndexer(Indexer);
- testing.expectEqual(E, Indexer.Key);
- testing.expectEqual(@as(usize, 3), Indexer.count);
+ try testing.expectEqual(E, Indexer.Key);
+ try testing.expectEqual(@as(usize, 3), Indexer.count);
- testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
- testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
- testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
+ try testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a));
+ try testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b));
+ try testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c));
- testing.expectEqual(E.a, Indexer.keyForIndex(0));
- testing.expectEqual(E.b, Indexer.keyForIndex(1));
- testing.expectEqual(E.c, Indexer.keyForIndex(2));
+ try testing.expectEqual(E.a, Indexer.keyForIndex(0));
+ try testing.expectEqual(E.b, Indexer.keyForIndex(1));
+ try testing.expectEqual(E.c, Indexer.keyForIndex(2));
}
test "std.enums.EnumSet" {
const E = extern enum { a, b, c, d, e = 0 };
const Set = EnumSet(E);
- testing.expectEqual(E, Set.Key);
- testing.expectEqual(EnumIndexer(E), Set.Indexer);
- testing.expectEqual(@as(usize, 4), Set.len);
+ try testing.expectEqual(E, Set.Key);
+ try testing.expectEqual(EnumIndexer(E), Set.Indexer);
+ try testing.expectEqual(@as(usize, 4), Set.len);
// Empty sets
const empty = Set{};
- comptime testing.expect(empty.count() == 0);
+ comptime try testing.expect(empty.count() == 0);
var empty_b = Set.init(.{});
- testing.expect(empty_b.count() == 0);
+ try testing.expect(empty_b.count() == 0);
const empty_c = comptime Set.init(.{});
- comptime testing.expect(empty_c.count() == 0);
+ comptime try testing.expect(empty_c.count() == 0);
const full = Set.initFull();
- testing.expect(full.count() == Set.len);
+ try testing.expect(full.count() == Set.len);
const full_b = comptime Set.initFull();
- comptime testing.expect(full_b.count() == Set.len);
+ comptime try testing.expect(full_b.count() == Set.len);
- testing.expectEqual(false, empty.contains(.a));
- testing.expectEqual(false, empty.contains(.b));
- testing.expectEqual(false, empty.contains(.c));
- testing.expectEqual(false, empty.contains(.d));
- testing.expectEqual(false, empty.contains(.e));
+ try testing.expectEqual(false, empty.contains(.a));
+ try testing.expectEqual(false, empty.contains(.b));
+ try testing.expectEqual(false, empty.contains(.c));
+ try testing.expectEqual(false, empty.contains(.d));
+ try testing.expectEqual(false, empty.contains(.e));
{
var iter = empty_b.iterator();
- testing.expectEqual(@as(?E, null), iter.next());
+ try testing.expectEqual(@as(?E, null), iter.next());
}
var mut = Set.init(.{
.a = true,
.c = true,
});
- testing.expectEqual(@as(usize, 2), mut.count());
- testing.expectEqual(true, mut.contains(.a));
- testing.expectEqual(false, mut.contains(.b));
- testing.expectEqual(true, mut.contains(.c));
- testing.expectEqual(false, mut.contains(.d));
- testing.expectEqual(true, mut.contains(.e)); // aliases a
+ try testing.expectEqual(@as(usize, 2), mut.count());
+ try testing.expectEqual(true, mut.contains(.a));
+ try testing.expectEqual(false, mut.contains(.b));
+ try testing.expectEqual(true, mut.contains(.c));
+ try testing.expectEqual(false, mut.contains(.d));
+ try testing.expectEqual(true, mut.contains(.e)); // aliases a
{
var it = mut.iterator();
- testing.expectEqual(@as(?E, .a), it.next());
- testing.expectEqual(@as(?E, .c), it.next());
- testing.expectEqual(@as(?E, null), it.next());
+ try testing.expectEqual(@as(?E, .a), it.next());
+ try testing.expectEqual(@as(?E, .c), it.next());
+ try testing.expectEqual(@as(?E, null), it.next());
}
mut.toggleAll();
- testing.expectEqual(@as(usize, 2), mut.count());
- testing.expectEqual(false, mut.contains(.a));
- testing.expectEqual(true, mut.contains(.b));
- testing.expectEqual(false, mut.contains(.c));
- testing.expectEqual(true, mut.contains(.d));
- testing.expectEqual(false, mut.contains(.e)); // aliases a
+ try testing.expectEqual(@as(usize, 2), mut.count());
+ try testing.expectEqual(false, mut.contains(.a));
+ try testing.expectEqual(true, mut.contains(.b));
+ try testing.expectEqual(false, mut.contains(.c));
+ try testing.expectEqual(true, mut.contains(.d));
+ try testing.expectEqual(false, mut.contains(.e)); // aliases a
{
var it = mut.iterator();
- testing.expectEqual(@as(?E, .b), it.next());
- testing.expectEqual(@as(?E, .d), it.next());
- testing.expectEqual(@as(?E, null), it.next());
+ try testing.expectEqual(@as(?E, .b), it.next());
+ try testing.expectEqual(@as(?E, .d), it.next());
+ try testing.expectEqual(@as(?E, null), it.next());
}
mut.toggleSet(Set.init(.{ .a = true, .b = true }));
- testing.expectEqual(@as(usize, 2), mut.count());
- testing.expectEqual(true, mut.contains(.a));
- testing.expectEqual(false, mut.contains(.b));
- testing.expectEqual(false, mut.contains(.c));
- testing.expectEqual(true, mut.contains(.d));
- testing.expectEqual(true, mut.contains(.e)); // aliases a
+ try testing.expectEqual(@as(usize, 2), mut.count());
+ try testing.expectEqual(true, mut.contains(.a));
+ try testing.expectEqual(false, mut.contains(.b));
+ try testing.expectEqual(false, mut.contains(.c));
+ try testing.expectEqual(true, mut.contains(.d));
+ try testing.expectEqual(true, mut.contains(.e)); // aliases a
mut.setUnion(Set.init(.{ .a = true, .b = true }));
- testing.expectEqual(@as(usize, 3), mut.count());
- testing.expectEqual(true, mut.contains(.a));
- testing.expectEqual(true, mut.contains(.b));
- testing.expectEqual(false, mut.contains(.c));
- testing.expectEqual(true, mut.contains(.d));
+ try testing.expectEqual(@as(usize, 3), mut.count());
+ try testing.expectEqual(true, mut.contains(.a));
+ try testing.expectEqual(true, mut.contains(.b));
+ try testing.expectEqual(false, mut.contains(.c));
+ try testing.expectEqual(true, mut.contains(.d));
mut.remove(.c);
mut.remove(.b);
- testing.expectEqual(@as(usize, 2), mut.count());
- testing.expectEqual(true, mut.contains(.a));
- testing.expectEqual(false, mut.contains(.b));
- testing.expectEqual(false, mut.contains(.c));
- testing.expectEqual(true, mut.contains(.d));
+ try testing.expectEqual(@as(usize, 2), mut.count());
+ try testing.expectEqual(true, mut.contains(.a));
+ try testing.expectEqual(false, mut.contains(.b));
+ try testing.expectEqual(false, mut.contains(.c));
+ try testing.expectEqual(true, mut.contains(.d));
mut.setIntersection(Set.init(.{ .a = true, .b = true }));
- testing.expectEqual(@as(usize, 1), mut.count());
- testing.expectEqual(true, mut.contains(.a));
- testing.expectEqual(false, mut.contains(.b));
- testing.expectEqual(false, mut.contains(.c));
- testing.expectEqual(false, mut.contains(.d));
+ try testing.expectEqual(@as(usize, 1), mut.count());
+ try testing.expectEqual(true, mut.contains(.a));
+ try testing.expectEqual(false, mut.contains(.b));
+ try testing.expectEqual(false, mut.contains(.c));
+ try testing.expectEqual(false, mut.contains(.d));
mut.insert(.a);
mut.insert(.b);
- testing.expectEqual(@as(usize, 2), mut.count());
- testing.expectEqual(true, mut.contains(.a));
- testing.expectEqual(true, mut.contains(.b));
- testing.expectEqual(false, mut.contains(.c));
- testing.expectEqual(false, mut.contains(.d));
+ try testing.expectEqual(@as(usize, 2), mut.count());
+ try testing.expectEqual(true, mut.contains(.a));
+ try testing.expectEqual(true, mut.contains(.b));
+ try testing.expectEqual(false, mut.contains(.c));
+ try testing.expectEqual(false, mut.contains(.d));
mut.setPresent(.a, false);
mut.toggle(.b);
mut.toggle(.c);
mut.setPresent(.d, true);
- testing.expectEqual(@as(usize, 2), mut.count());
- testing.expectEqual(false, mut.contains(.a));
- testing.expectEqual(false, mut.contains(.b));
- testing.expectEqual(true, mut.contains(.c));
- testing.expectEqual(true, mut.contains(.d));
+ try testing.expectEqual(@as(usize, 2), mut.count());
+ try testing.expectEqual(false, mut.contains(.a));
+ try testing.expectEqual(false, mut.contains(.b));
+ try testing.expectEqual(true, mut.contains(.c));
+ try testing.expectEqual(true, mut.contains(.d));
}
test "std.enums.EnumArray void" {
const E = extern enum { a, b, c, d, e = 0 };
const ArrayVoid = EnumArray(E, void);
- testing.expectEqual(E, ArrayVoid.Key);
- testing.expectEqual(EnumIndexer(E), ArrayVoid.Indexer);
- testing.expectEqual(void, ArrayVoid.Value);
- testing.expectEqual(@as(usize, 4), ArrayVoid.len);
+ try testing.expectEqual(E, ArrayVoid.Key);
+ try testing.expectEqual(EnumIndexer(E), ArrayVoid.Indexer);
+ try testing.expectEqual(void, ArrayVoid.Value);
+ try testing.expectEqual(@as(usize, 4), ArrayVoid.len);
const undef = ArrayVoid.initUndefined();
var inst = ArrayVoid.initFill({});
@@ -1059,113 +1059,113 @@ test "std.enums.EnumArray void" {
inst.set(.a, {});
var it = inst.iterator();
- testing.expectEqual(E.a, it.next().?.key);
- testing.expectEqual(E.b, it.next().?.key);
- testing.expectEqual(E.c, it.next().?.key);
- testing.expectEqual(E.d, it.next().?.key);
- testing.expect(it.next() == null);
+ try testing.expectEqual(E.a, it.next().?.key);
+ try testing.expectEqual(E.b, it.next().?.key);
+ try testing.expectEqual(E.c, it.next().?.key);
+ try testing.expectEqual(E.d, it.next().?.key);
+ try testing.expect(it.next() == null);
}
test "std.enums.EnumArray sized" {
const E = extern enum { a, b, c, d, e = 0 };
const Array = EnumArray(E, usize);
- testing.expectEqual(E, Array.Key);
- testing.expectEqual(EnumIndexer(E), Array.Indexer);
- testing.expectEqual(usize, Array.Value);
- testing.expectEqual(@as(usize, 4), Array.len);
+ try testing.expectEqual(E, Array.Key);
+ try testing.expectEqual(EnumIndexer(E), Array.Indexer);
+ try testing.expectEqual(usize, Array.Value);
+ try testing.expectEqual(@as(usize, 4), Array.len);
const undef = Array.initUndefined();
var inst = Array.initFill(5);
const inst2 = Array.init(.{ .a = 1, .b = 2, .c = 3, .d = 4 });
const inst3 = Array.initDefault(6, .{ .b = 4, .c = 2 });
- testing.expectEqual(@as(usize, 5), inst.get(.a));
- testing.expectEqual(@as(usize, 5), inst.get(.b));
- testing.expectEqual(@as(usize, 5), inst.get(.c));
- testing.expectEqual(@as(usize, 5), inst.get(.d));
+ try testing.expectEqual(@as(usize, 5), inst.get(.a));
+ try testing.expectEqual(@as(usize, 5), inst.get(.b));
+ try testing.expectEqual(@as(usize, 5), inst.get(.c));
+ try testing.expectEqual(@as(usize, 5), inst.get(.d));
- testing.expectEqual(@as(usize, 1), inst2.get(.a));
- testing.expectEqual(@as(usize, 2), inst2.get(.b));
- testing.expectEqual(@as(usize, 3), inst2.get(.c));
- testing.expectEqual(@as(usize, 4), inst2.get(.d));
+ try testing.expectEqual(@as(usize, 1), inst2.get(.a));
+ try testing.expectEqual(@as(usize, 2), inst2.get(.b));
+ try testing.expectEqual(@as(usize, 3), inst2.get(.c));
+ try testing.expectEqual(@as(usize, 4), inst2.get(.d));
- testing.expectEqual(@as(usize, 6), inst3.get(.a));
- testing.expectEqual(@as(usize, 4), inst3.get(.b));
- testing.expectEqual(@as(usize, 2), inst3.get(.c));
- testing.expectEqual(@as(usize, 6), inst3.get(.d));
+ try testing.expectEqual(@as(usize, 6), inst3.get(.a));
+ try testing.expectEqual(@as(usize, 4), inst3.get(.b));
+ try testing.expectEqual(@as(usize, 2), inst3.get(.c));
+ try testing.expectEqual(@as(usize, 6), inst3.get(.d));
- testing.expectEqual(&inst.values[0], inst.getPtr(.a));
- testing.expectEqual(&inst.values[1], inst.getPtr(.b));
- testing.expectEqual(&inst.values[2], inst.getPtr(.c));
- testing.expectEqual(&inst.values[3], inst.getPtr(.d));
+ try testing.expectEqual(&inst.values[0], inst.getPtr(.a));
+ try testing.expectEqual(&inst.values[1], inst.getPtr(.b));
+ try testing.expectEqual(&inst.values[2], inst.getPtr(.c));
+ try testing.expectEqual(&inst.values[3], inst.getPtr(.d));
- testing.expectEqual(@as(*const usize, &inst.values[0]), inst.getPtrConst(.a));
- testing.expectEqual(@as(*const usize, &inst.values[1]), inst.getPtrConst(.b));
- testing.expectEqual(@as(*const usize, &inst.values[2]), inst.getPtrConst(.c));
- testing.expectEqual(@as(*const usize, &inst.values[3]), inst.getPtrConst(.d));
+ try testing.expectEqual(@as(*const usize, &inst.values[0]), inst.getPtrConst(.a));
+ try testing.expectEqual(@as(*const usize, &inst.values[1]), inst.getPtrConst(.b));
+ try testing.expectEqual(@as(*const usize, &inst.values[2]), inst.getPtrConst(.c));
+ try testing.expectEqual(@as(*const usize, &inst.values[3]), inst.getPtrConst(.d));
inst.set(.c, 8);
- testing.expectEqual(@as(usize, 5), inst.get(.a));
- testing.expectEqual(@as(usize, 5), inst.get(.b));
- testing.expectEqual(@as(usize, 8), inst.get(.c));
- testing.expectEqual(@as(usize, 5), inst.get(.d));
+ try testing.expectEqual(@as(usize, 5), inst.get(.a));
+ try testing.expectEqual(@as(usize, 5), inst.get(.b));
+ try testing.expectEqual(@as(usize, 8), inst.get(.c));
+ try testing.expectEqual(@as(usize, 5), inst.get(.d));
var it = inst.iterator();
const Entry = Array.Entry;
- testing.expectEqual(@as(?Entry, Entry{
+ try testing.expectEqual(@as(?Entry, Entry{
.key = .a,
.value = &inst.values[0],
}), it.next());
- testing.expectEqual(@as(?Entry, Entry{
+ try testing.expectEqual(@as(?Entry, Entry{
.key = .b,
.value = &inst.values[1],
}), it.next());
- testing.expectEqual(@as(?Entry, Entry{
+ try testing.expectEqual(@as(?Entry, Entry{
.key = .c,
.value = &inst.values[2],
}), it.next());
- testing.expectEqual(@as(?Entry, Entry{
+ try testing.expectEqual(@as(?Entry, Entry{
.key = .d,
.value = &inst.values[3],
}), it.next());
- testing.expectEqual(@as(?Entry, null), it.next());
+ try testing.expectEqual(@as(?Entry, null), it.next());
}
test "std.enums.EnumMap void" {
const E = extern enum { a, b, c, d, e = 0 };
const Map = EnumMap(E, void);
- testing.expectEqual(E, Map.Key);
- testing.expectEqual(EnumIndexer(E), Map.Indexer);
- testing.expectEqual(void, Map.Value);
- testing.expectEqual(@as(usize, 4), Map.len);
+ try testing.expectEqual(E, Map.Key);
+ try testing.expectEqual(EnumIndexer(E), Map.Indexer);
+ try testing.expectEqual(void, Map.Value);
+ try testing.expectEqual(@as(usize, 4), Map.len);
const b = Map.initFull({});
- testing.expectEqual(@as(usize, 4), b.count());
+ try testing.expectEqual(@as(usize, 4), b.count());
const c = Map.initFullWith(.{ .a = {}, .b = {}, .c = {}, .d = {} });
- testing.expectEqual(@as(usize, 4), c.count());
+ try testing.expectEqual(@as(usize, 4), c.count());
const d = Map.initFullWithDefault({}, .{ .b = {} });
- testing.expectEqual(@as(usize, 4), d.count());
+ try testing.expectEqual(@as(usize, 4), d.count());
var a = Map.init(.{ .b = {}, .d = {} });
- testing.expectEqual(@as(usize, 2), a.count());
- testing.expectEqual(false, a.contains(.a));
- testing.expectEqual(true, a.contains(.b));
- testing.expectEqual(false, a.contains(.c));
- testing.expectEqual(true, a.contains(.d));
- testing.expect(a.get(.a) == null);
- testing.expect(a.get(.b) != null);
- testing.expect(a.get(.c) == null);
- testing.expect(a.get(.d) != null);
- testing.expect(a.getPtr(.a) == null);
- testing.expect(a.getPtr(.b) != null);
- testing.expect(a.getPtr(.c) == null);
- testing.expect(a.getPtr(.d) != null);
- testing.expect(a.getPtrConst(.a) == null);
- testing.expect(a.getPtrConst(.b) != null);
- testing.expect(a.getPtrConst(.c) == null);
- testing.expect(a.getPtrConst(.d) != null);
+ try testing.expectEqual(@as(usize, 2), a.count());
+ try testing.expectEqual(false, a.contains(.a));
+ try testing.expectEqual(true, a.contains(.b));
+ try testing.expectEqual(false, a.contains(.c));
+ try testing.expectEqual(true, a.contains(.d));
+ try testing.expect(a.get(.a) == null);
+ try testing.expect(a.get(.b) != null);
+ try testing.expect(a.get(.c) == null);
+ try testing.expect(a.get(.d) != null);
+ try testing.expect(a.getPtr(.a) == null);
+ try testing.expect(a.getPtr(.b) != null);
+ try testing.expect(a.getPtr(.c) == null);
+ try testing.expect(a.getPtr(.d) != null);
+ try testing.expect(a.getPtrConst(.a) == null);
+ try testing.expect(a.getPtrConst(.b) != null);
+ try testing.expect(a.getPtrConst(.c) == null);
+ try testing.expect(a.getPtrConst(.d) != null);
_ = a.getPtrAssertContains(.b);
_ = a.getAssertContains(.d);
@@ -1174,115 +1174,115 @@ test "std.enums.EnumMap void" {
a.putUninitialized(.c).* = {};
a.putUninitialized(.c).* = {};
- testing.expectEqual(@as(usize, 4), a.count());
- testing.expect(a.get(.a) != null);
- testing.expect(a.get(.b) != null);
- testing.expect(a.get(.c) != null);
- testing.expect(a.get(.d) != null);
+ try testing.expectEqual(@as(usize, 4), a.count());
+ try testing.expect(a.get(.a) != null);
+ try testing.expect(a.get(.b) != null);
+ try testing.expect(a.get(.c) != null);
+ try testing.expect(a.get(.d) != null);
a.remove(.a);
_ = a.fetchRemove(.c);
var iter = a.iterator();
const Entry = Map.Entry;
- testing.expectEqual(E.b, iter.next().?.key);
- testing.expectEqual(E.d, iter.next().?.key);
- testing.expect(iter.next() == null);
+ try testing.expectEqual(E.b, iter.next().?.key);
+ try testing.expectEqual(E.d, iter.next().?.key);
+ try testing.expect(iter.next() == null);
}
test "std.enums.EnumMap sized" {
const E = extern enum { a, b, c, d, e = 0 };
const Map = EnumMap(E, usize);
- testing.expectEqual(E, Map.Key);
- testing.expectEqual(EnumIndexer(E), Map.Indexer);
- testing.expectEqual(usize, Map.Value);
- testing.expectEqual(@as(usize, 4), Map.len);
+ try testing.expectEqual(E, Map.Key);
+ try testing.expectEqual(EnumIndexer(E), Map.Indexer);
+ try testing.expectEqual(usize, Map.Value);
+ try testing.expectEqual(@as(usize, 4), Map.len);
const b = Map.initFull(5);
- testing.expectEqual(@as(usize, 4), b.count());
- testing.expect(b.contains(.a));
- testing.expect(b.contains(.b));
- testing.expect(b.contains(.c));
- testing.expect(b.contains(.d));
- testing.expectEqual(@as(?usize, 5), b.get(.a));
- testing.expectEqual(@as(?usize, 5), b.get(.b));
- testing.expectEqual(@as(?usize, 5), b.get(.c));
- testing.expectEqual(@as(?usize, 5), b.get(.d));
+ try testing.expectEqual(@as(usize, 4), b.count());
+ try testing.expect(b.contains(.a));
+ try testing.expect(b.contains(.b));
+ try testing.expect(b.contains(.c));
+ try testing.expect(b.contains(.d));
+ try testing.expectEqual(@as(?usize, 5), b.get(.a));
+ try testing.expectEqual(@as(?usize, 5), b.get(.b));
+ try testing.expectEqual(@as(?usize, 5), b.get(.c));
+ try testing.expectEqual(@as(?usize, 5), b.get(.d));
const c = Map.initFullWith(.{ .a = 1, .b = 2, .c = 3, .d = 4 });
- testing.expectEqual(@as(usize, 4), c.count());
- testing.expect(c.contains(.a));
- testing.expect(c.contains(.b));
- testing.expect(c.contains(.c));
- testing.expect(c.contains(.d));
- testing.expectEqual(@as(?usize, 1), c.get(.a));
- testing.expectEqual(@as(?usize, 2), c.get(.b));
- testing.expectEqual(@as(?usize, 3), c.get(.c));
- testing.expectEqual(@as(?usize, 4), c.get(.d));
+ try testing.expectEqual(@as(usize, 4), c.count());
+ try testing.expect(c.contains(.a));
+ try testing.expect(c.contains(.b));
+ try testing.expect(c.contains(.c));
+ try testing.expect(c.contains(.d));
+ try testing.expectEqual(@as(?usize, 1), c.get(.a));
+ try testing.expectEqual(@as(?usize, 2), c.get(.b));
+ try testing.expectEqual(@as(?usize, 3), c.get(.c));
+ try testing.expectEqual(@as(?usize, 4), c.get(.d));
const d = Map.initFullWithDefault(6, .{ .b = 2, .c = 4 });
- testing.expectEqual(@as(usize, 4), d.count());
- testing.expect(d.contains(.a));
- testing.expect(d.contains(.b));
- testing.expect(d.contains(.c));
- testing.expect(d.contains(.d));
- testing.expectEqual(@as(?usize, 6), d.get(.a));
- testing.expectEqual(@as(?usize, 2), d.get(.b));
- testing.expectEqual(@as(?usize, 4), d.get(.c));
- testing.expectEqual(@as(?usize, 6), d.get(.d));
+ try testing.expectEqual(@as(usize, 4), d.count());
+ try testing.expect(d.contains(.a));
+ try testing.expect(d.contains(.b));
+ try testing.expect(d.contains(.c));
+ try testing.expect(d.contains(.d));
+ try testing.expectEqual(@as(?usize, 6), d.get(.a));
+ try testing.expectEqual(@as(?usize, 2), d.get(.b));
+ try testing.expectEqual(@as(?usize, 4), d.get(.c));
+ try testing.expectEqual(@as(?usize, 6), d.get(.d));
var a = Map.init(.{ .b = 2, .d = 4 });
- testing.expectEqual(@as(usize, 2), a.count());
- testing.expectEqual(false, a.contains(.a));
- testing.expectEqual(true, a.contains(.b));
- testing.expectEqual(false, a.contains(.c));
- testing.expectEqual(true, a.contains(.d));
-
- testing.expectEqual(@as(?usize, null), a.get(.a));
- testing.expectEqual(@as(?usize, 2), a.get(.b));
- testing.expectEqual(@as(?usize, null), a.get(.c));
- testing.expectEqual(@as(?usize, 4), a.get(.d));
-
- testing.expectEqual(@as(?*usize, null), a.getPtr(.a));
- testing.expectEqual(@as(?*usize, &a.values[1]), a.getPtr(.b));
- testing.expectEqual(@as(?*usize, null), a.getPtr(.c));
- testing.expectEqual(@as(?*usize, &a.values[3]), a.getPtr(.d));
-
- testing.expectEqual(@as(?*const usize, null), a.getPtrConst(.a));
- testing.expectEqual(@as(?*const usize, &a.values[1]), a.getPtrConst(.b));
- testing.expectEqual(@as(?*const usize, null), a.getPtrConst(.c));
- testing.expectEqual(@as(?*const usize, &a.values[3]), a.getPtrConst(.d));
-
- testing.expectEqual(@as(*const usize, &a.values[1]), a.getPtrAssertContains(.b));
- testing.expectEqual(@as(*const usize, &a.values[3]), a.getPtrAssertContains(.d));
- testing.expectEqual(@as(usize, 2), a.getAssertContains(.b));
- testing.expectEqual(@as(usize, 4), a.getAssertContains(.d));
+ try testing.expectEqual(@as(usize, 2), a.count());
+ try testing.expectEqual(false, a.contains(.a));
+ try testing.expectEqual(true, a.contains(.b));
+ try testing.expectEqual(false, a.contains(.c));
+ try testing.expectEqual(true, a.contains(.d));
+
+ try testing.expectEqual(@as(?usize, null), a.get(.a));
+ try testing.expectEqual(@as(?usize, 2), a.get(.b));
+ try testing.expectEqual(@as(?usize, null), a.get(.c));
+ try testing.expectEqual(@as(?usize, 4), a.get(.d));
+
+ try testing.expectEqual(@as(?*usize, null), a.getPtr(.a));
+ try testing.expectEqual(@as(?*usize, &a.values[1]), a.getPtr(.b));
+ try testing.expectEqual(@as(?*usize, null), a.getPtr(.c));
+ try testing.expectEqual(@as(?*usize, &a.values[3]), a.getPtr(.d));
+
+ try testing.expectEqual(@as(?*const usize, null), a.getPtrConst(.a));
+ try testing.expectEqual(@as(?*const usize, &a.values[1]), a.getPtrConst(.b));
+ try testing.expectEqual(@as(?*const usize, null), a.getPtrConst(.c));
+ try testing.expectEqual(@as(?*const usize, &a.values[3]), a.getPtrConst(.d));
+
+ try testing.expectEqual(@as(*const usize, &a.values[1]), a.getPtrAssertContains(.b));
+ try testing.expectEqual(@as(*const usize, &a.values[3]), a.getPtrAssertContains(.d));
+ try testing.expectEqual(@as(usize, 2), a.getAssertContains(.b));
+ try testing.expectEqual(@as(usize, 4), a.getAssertContains(.d));
a.put(.a, 3);
a.put(.a, 5);
a.putUninitialized(.c).* = 7;
a.putUninitialized(.c).* = 9;
- testing.expectEqual(@as(usize, 4), a.count());
- testing.expectEqual(@as(?usize, 5), a.get(.a));
- testing.expectEqual(@as(?usize, 2), a.get(.b));
- testing.expectEqual(@as(?usize, 9), a.get(.c));
- testing.expectEqual(@as(?usize, 4), a.get(.d));
+ try testing.expectEqual(@as(usize, 4), a.count());
+ try testing.expectEqual(@as(?usize, 5), a.get(.a));
+ try testing.expectEqual(@as(?usize, 2), a.get(.b));
+ try testing.expectEqual(@as(?usize, 9), a.get(.c));
+ try testing.expectEqual(@as(?usize, 4), a.get(.d));
a.remove(.a);
- testing.expectEqual(@as(?usize, null), a.fetchRemove(.a));
- testing.expectEqual(@as(?usize, 9), a.fetchRemove(.c));
+ try testing.expectEqual(@as(?usize, null), a.fetchRemove(.a));
+ try testing.expectEqual(@as(?usize, 9), a.fetchRemove(.c));
a.remove(.c);
var iter = a.iterator();
const Entry = Map.Entry;
- testing.expectEqual(@as(?Entry, Entry{
+ try testing.expectEqual(@as(?Entry, Entry{
.key = .b,
.value = &a.values[1],
}), iter.next());
- testing.expectEqual(@as(?Entry, Entry{
+ try testing.expectEqual(@as(?Entry, Entry{
.key = .d,
.value = &a.values[3],
}), iter.next());
- testing.expectEqual(@as(?Entry, null), iter.next());
+ try testing.expectEqual(@as(?Entry, null), iter.next());
}
lib/std/fifo.zig
@@ -402,59 +402,59 @@ test "LinearFifo(u8, .Dynamic)" {
defer fifo.deinit();
try fifo.write("HELLO");
- testing.expectEqual(@as(usize, 5), fifo.readableLength());
- testing.expectEqualSlices(u8, "HELLO", fifo.readableSlice(0));
+ try testing.expectEqual(@as(usize, 5), fifo.readableLength());
+ try testing.expectEqualSlices(u8, "HELLO", fifo.readableSlice(0));
{
var i: usize = 0;
while (i < 5) : (i += 1) {
try fifo.write(&[_]u8{fifo.peekItem(i)});
}
- testing.expectEqual(@as(usize, 10), fifo.readableLength());
- testing.expectEqualSlices(u8, "HELLOHELLO", fifo.readableSlice(0));
+ try testing.expectEqual(@as(usize, 10), fifo.readableLength());
+ try testing.expectEqualSlices(u8, "HELLOHELLO", fifo.readableSlice(0));
}
{
- testing.expectEqual(@as(u8, 'H'), fifo.readItem().?);
- testing.expectEqual(@as(u8, 'E'), fifo.readItem().?);
- testing.expectEqual(@as(u8, 'L'), fifo.readItem().?);
- testing.expectEqual(@as(u8, 'L'), fifo.readItem().?);
- testing.expectEqual(@as(u8, 'O'), fifo.readItem().?);
+ try testing.expectEqual(@as(u8, 'H'), fifo.readItem().?);
+ try testing.expectEqual(@as(u8, 'E'), fifo.readItem().?);
+ try testing.expectEqual(@as(u8, 'L'), fifo.readItem().?);
+ try testing.expectEqual(@as(u8, 'L'), fifo.readItem().?);
+ try testing.expectEqual(@as(u8, 'O'), fifo.readItem().?);
}
- testing.expectEqual(@as(usize, 5), fifo.readableLength());
+ try testing.expectEqual(@as(usize, 5), fifo.readableLength());
{ // Writes that wrap around
- testing.expectEqual(@as(usize, 11), fifo.writableLength());
- testing.expectEqual(@as(usize, 6), fifo.writableSlice(0).len);
+ try testing.expectEqual(@as(usize, 11), fifo.writableLength());
+ try testing.expectEqual(@as(usize, 6), fifo.writableSlice(0).len);
fifo.writeAssumeCapacity("6<chars<11");
- testing.expectEqualSlices(u8, "HELLO6<char", fifo.readableSlice(0));
- testing.expectEqualSlices(u8, "s<11", fifo.readableSlice(11));
- testing.expectEqualSlices(u8, "11", fifo.readableSlice(13));
- testing.expectEqualSlices(u8, "", fifo.readableSlice(15));
+ try testing.expectEqualSlices(u8, "HELLO6<char", fifo.readableSlice(0));
+ try testing.expectEqualSlices(u8, "s<11", fifo.readableSlice(11));
+ try testing.expectEqualSlices(u8, "11", fifo.readableSlice(13));
+ try testing.expectEqualSlices(u8, "", fifo.readableSlice(15));
fifo.discard(11);
- testing.expectEqualSlices(u8, "s<11", fifo.readableSlice(0));
+ try testing.expectEqualSlices(u8, "s<11", fifo.readableSlice(0));
fifo.discard(4);
- testing.expectEqual(@as(usize, 0), fifo.readableLength());
+ try testing.expectEqual(@as(usize, 0), fifo.readableLength());
}
{
const buf = try fifo.writableWithSize(12);
- testing.expectEqual(@as(usize, 12), buf.len);
+ try testing.expectEqual(@as(usize, 12), buf.len);
var i: u8 = 0;
while (i < 10) : (i += 1) {
buf[i] = i + 'a';
}
fifo.update(10);
- testing.expectEqualSlices(u8, "abcdefghij", fifo.readableSlice(0));
+ try testing.expectEqualSlices(u8, "abcdefghij", fifo.readableSlice(0));
}
{
try fifo.unget("prependedstring");
var result: [30]u8 = undefined;
- testing.expectEqualSlices(u8, "prependedstringabcdefghij", result[0..fifo.read(&result)]);
+ try testing.expectEqualSlices(u8, "prependedstringabcdefghij", result[0..fifo.read(&result)]);
try fifo.unget("b");
try fifo.unget("a");
- testing.expectEqualSlices(u8, "ab", result[0..fifo.read(&result)]);
+ try testing.expectEqualSlices(u8, "ab", result[0..fifo.read(&result)]);
}
fifo.shrink(0);
@@ -462,17 +462,17 @@ test "LinearFifo(u8, .Dynamic)" {
{
try fifo.writer().print("{s}, {s}!", .{ "Hello", "World" });
var result: [30]u8 = undefined;
- testing.expectEqualSlices(u8, "Hello, World!", result[0..fifo.read(&result)]);
- testing.expectEqual(@as(usize, 0), fifo.readableLength());
+ try testing.expectEqualSlices(u8, "Hello, World!", result[0..fifo.read(&result)]);
+ try testing.expectEqual(@as(usize, 0), fifo.readableLength());
}
{
try fifo.writer().writeAll("This is a test");
var result: [30]u8 = undefined;
- testing.expectEqualSlices(u8, "This", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?);
- testing.expectEqualSlices(u8, "is", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?);
- testing.expectEqualSlices(u8, "a", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?);
- testing.expectEqualSlices(u8, "test", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?);
+ try testing.expectEqualSlices(u8, "This", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?);
+ try testing.expectEqualSlices(u8, "is", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?);
+ try testing.expectEqualSlices(u8, "a", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?);
+ try testing.expectEqualSlices(u8, "test", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?);
}
{
@@ -481,7 +481,7 @@ test "LinearFifo(u8, .Dynamic)" {
var out_buf: [50]u8 = undefined;
var out_fbs = std.io.fixedBufferStream(&out_buf);
try fifo.pump(in_fbs.reader(), out_fbs.writer());
- testing.expectEqualSlices(u8, in_fbs.buffer, out_fbs.getWritten());
+ try testing.expectEqualSlices(u8, in_fbs.buffer, out_fbs.getWritten());
}
}
@@ -498,28 +498,28 @@ test "LinearFifo" {
defer fifo.deinit();
try fifo.write(&[_]T{ 0, 1, 1, 0, 1 });
- testing.expectEqual(@as(usize, 5), fifo.readableLength());
+ try testing.expectEqual(@as(usize, 5), fifo.readableLength());
{
- testing.expectEqual(@as(T, 0), fifo.readItem().?);
- testing.expectEqual(@as(T, 1), fifo.readItem().?);
- testing.expectEqual(@as(T, 1), fifo.readItem().?);
- testing.expectEqual(@as(T, 0), fifo.readItem().?);
- testing.expectEqual(@as(T, 1), fifo.readItem().?);
- testing.expectEqual(@as(usize, 0), fifo.readableLength());
+ try testing.expectEqual(@as(T, 0), fifo.readItem().?);
+ try testing.expectEqual(@as(T, 1), fifo.readItem().?);
+ try testing.expectEqual(@as(T, 1), fifo.readItem().?);
+ try testing.expectEqual(@as(T, 0), fifo.readItem().?);
+ try testing.expectEqual(@as(T, 1), fifo.readItem().?);
+ try testing.expectEqual(@as(usize, 0), fifo.readableLength());
}
{
try fifo.writeItem(1);
try fifo.writeItem(1);
try fifo.writeItem(1);
- testing.expectEqual(@as(usize, 3), fifo.readableLength());
+ try testing.expectEqual(@as(usize, 3), fifo.readableLength());
}
{
var readBuf: [3]T = undefined;
const n = fifo.read(&readBuf);
- testing.expectEqual(@as(usize, 3), n); // NOTE: It should be the number of items.
+ try testing.expectEqual(@as(usize, 3), n); // NOTE: It should be the number of items.
}
}
}
lib/std/fmt.zig
@@ -1422,7 +1422,7 @@ test "fmtDuration" {
.{ .s = "1y1m999ns", .d = 365 * std.time.ns_per_day + std.time.ns_per_min + 999 },
}) |tc| {
const slice = try bufPrint(&buf, "{}", .{fmtDuration(tc.d)});
- std.testing.expectEqualStrings(tc.s, slice);
+ try std.testing.expectEqualStrings(tc.s, slice);
}
}
@@ -1478,44 +1478,44 @@ pub fn parseInt(comptime T: type, buf: []const u8, radix: u8) ParseIntError!T {
}
test "parseInt" {
- std.testing.expect((try parseInt(i32, "-10", 10)) == -10);
- std.testing.expect((try parseInt(i32, "+10", 10)) == 10);
- std.testing.expect((try parseInt(u32, "+10", 10)) == 10);
- std.testing.expectError(error.Overflow, parseInt(u32, "-10", 10));
- std.testing.expectError(error.InvalidCharacter, parseInt(u32, " 10", 10));
- std.testing.expectError(error.InvalidCharacter, parseInt(u32, "10 ", 10));
- std.testing.expect((try parseInt(u8, "255", 10)) == 255);
- std.testing.expectError(error.Overflow, parseInt(u8, "256", 10));
+ try std.testing.expect((try parseInt(i32, "-10", 10)) == -10);
+ try std.testing.expect((try parseInt(i32, "+10", 10)) == 10);
+ try std.testing.expect((try parseInt(u32, "+10", 10)) == 10);
+ try std.testing.expectError(error.Overflow, parseInt(u32, "-10", 10));
+ try std.testing.expectError(error.InvalidCharacter, parseInt(u32, " 10", 10));
+ try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "10 ", 10));
+ try std.testing.expect((try parseInt(u8, "255", 10)) == 255);
+ try std.testing.expectError(error.Overflow, parseInt(u8, "256", 10));
// +0 and -0 should work for unsigned
- std.testing.expect((try parseInt(u8, "-0", 10)) == 0);
- std.testing.expect((try parseInt(u8, "+0", 10)) == 0);
+ try std.testing.expect((try parseInt(u8, "-0", 10)) == 0);
+ try std.testing.expect((try parseInt(u8, "+0", 10)) == 0);
// ensure minInt is parsed correctly
- std.testing.expect((try parseInt(i8, "-128", 10)) == math.minInt(i8));
- std.testing.expect((try parseInt(i43, "-4398046511104", 10)) == math.minInt(i43));
+ try std.testing.expect((try parseInt(i8, "-128", 10)) == math.minInt(i8));
+ try std.testing.expect((try parseInt(i43, "-4398046511104", 10)) == math.minInt(i43));
// empty string or bare +- is invalid
- std.testing.expectError(error.InvalidCharacter, parseInt(u32, "", 10));
- std.testing.expectError(error.InvalidCharacter, parseInt(i32, "", 10));
- std.testing.expectError(error.InvalidCharacter, parseInt(u32, "+", 10));
- std.testing.expectError(error.InvalidCharacter, parseInt(i32, "+", 10));
- std.testing.expectError(error.InvalidCharacter, parseInt(u32, "-", 10));
- std.testing.expectError(error.InvalidCharacter, parseInt(i32, "-", 10));
+ try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "", 10));
+ try std.testing.expectError(error.InvalidCharacter, parseInt(i32, "", 10));
+ try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "+", 10));
+ try std.testing.expectError(error.InvalidCharacter, parseInt(i32, "+", 10));
+ try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "-", 10));
+ try std.testing.expectError(error.InvalidCharacter, parseInt(i32, "-", 10));
// autodectect the radix
- std.testing.expect((try parseInt(i32, "111", 0)) == 111);
- std.testing.expect((try parseInt(i32, "+0b111", 0)) == 7);
- std.testing.expect((try parseInt(i32, "+0o111", 0)) == 73);
- std.testing.expect((try parseInt(i32, "+0x111", 0)) == 273);
- std.testing.expect((try parseInt(i32, "-0b111", 0)) == -7);
- std.testing.expect((try parseInt(i32, "-0o111", 0)) == -73);
- std.testing.expect((try parseInt(i32, "-0x111", 0)) == -273);
+ try std.testing.expect((try parseInt(i32, "111", 0)) == 111);
+ try std.testing.expect((try parseInt(i32, "+0b111", 0)) == 7);
+ try std.testing.expect((try parseInt(i32, "+0o111", 0)) == 73);
+ try std.testing.expect((try parseInt(i32, "+0x111", 0)) == 273);
+ try std.testing.expect((try parseInt(i32, "-0b111", 0)) == -7);
+ try std.testing.expect((try parseInt(i32, "-0o111", 0)) == -73);
+ try std.testing.expect((try parseInt(i32, "-0x111", 0)) == -273);
// bare binary/octal/decimal prefix is invalid
- std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0b", 0));
- std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0o", 0));
- std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0x", 0));
+ try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0b", 0));
+ try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0o", 0));
+ try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0x", 0));
}
fn parseWithSign(
@@ -1583,37 +1583,37 @@ pub fn parseUnsigned(comptime T: type, buf: []const u8, radix: u8) ParseIntError
}
test "parseUnsigned" {
- std.testing.expect((try parseUnsigned(u16, "050124", 10)) == 50124);
- std.testing.expect((try parseUnsigned(u16, "65535", 10)) == 65535);
- std.testing.expectError(error.Overflow, parseUnsigned(u16, "65536", 10));
+ try std.testing.expect((try parseUnsigned(u16, "050124", 10)) == 50124);
+ try std.testing.expect((try parseUnsigned(u16, "65535", 10)) == 65535);
+ try std.testing.expectError(error.Overflow, parseUnsigned(u16, "65536", 10));
- std.testing.expect((try parseUnsigned(u64, "0ffffffffffffffff", 16)) == 0xffffffffffffffff);
- std.testing.expectError(error.Overflow, parseUnsigned(u64, "10000000000000000", 16));
+ try std.testing.expect((try parseUnsigned(u64, "0ffffffffffffffff", 16)) == 0xffffffffffffffff);
+ try std.testing.expectError(error.Overflow, parseUnsigned(u64, "10000000000000000", 16));
- std.testing.expect((try parseUnsigned(u32, "DeadBeef", 16)) == 0xDEADBEEF);
+ try std.testing.expect((try parseUnsigned(u32, "DeadBeef", 16)) == 0xDEADBEEF);
- std.testing.expect((try parseUnsigned(u7, "1", 10)) == 1);
- std.testing.expect((try parseUnsigned(u7, "1000", 2)) == 8);
+ try std.testing.expect((try parseUnsigned(u7, "1", 10)) == 1);
+ try std.testing.expect((try parseUnsigned(u7, "1000", 2)) == 8);
- std.testing.expectError(error.InvalidCharacter, parseUnsigned(u32, "f", 10));
- std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "109", 8));
+ try std.testing.expectError(error.InvalidCharacter, parseUnsigned(u32, "f", 10));
+ try std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "109", 8));
- std.testing.expect((try parseUnsigned(u32, "NUMBER", 36)) == 1442151747);
+ try std.testing.expect((try parseUnsigned(u32, "NUMBER", 36)) == 1442151747);
// these numbers should fit even though the radix itself doesn't fit in the destination type
- std.testing.expect((try parseUnsigned(u1, "0", 10)) == 0);
- std.testing.expect((try parseUnsigned(u1, "1", 10)) == 1);
- std.testing.expectError(error.Overflow, parseUnsigned(u1, "2", 10));
- std.testing.expect((try parseUnsigned(u1, "001", 16)) == 1);
- std.testing.expect((try parseUnsigned(u2, "3", 16)) == 3);
- std.testing.expectError(error.Overflow, parseUnsigned(u2, "4", 16));
+ try std.testing.expect((try parseUnsigned(u1, "0", 10)) == 0);
+ try std.testing.expect((try parseUnsigned(u1, "1", 10)) == 1);
+ try std.testing.expectError(error.Overflow, parseUnsigned(u1, "2", 10));
+ try std.testing.expect((try parseUnsigned(u1, "001", 16)) == 1);
+ try std.testing.expect((try parseUnsigned(u2, "3", 16)) == 3);
+ try std.testing.expectError(error.Overflow, parseUnsigned(u2, "4", 16));
// parseUnsigned does not expect a sign
- std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "+0", 10));
- std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "-0", 10));
+ try std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "+0", 10));
+ try std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "-0", 10));
// test empty string error
- std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "", 10));
+ try std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "", 10));
}
pub const parseFloat = @import("fmt/parse_float.zig").parseFloat;
@@ -1692,21 +1692,21 @@ test "bufPrintInt" {
var buffer: [100]u8 = undefined;
const buf = buffer[0..];
- std.testing.expectEqualSlices(u8, "-1", bufPrintIntToSlice(buf, @as(i1, -1), 10, false, FormatOptions{}));
+ try std.testing.expectEqualSlices(u8, "-1", bufPrintIntToSlice(buf, @as(i1, -1), 10, false, FormatOptions{}));
- std.testing.expectEqualSlices(u8, "-101111000110000101001110", bufPrintIntToSlice(buf, @as(i32, -12345678), 2, false, FormatOptions{}));
- std.testing.expectEqualSlices(u8, "-12345678", bufPrintIntToSlice(buf, @as(i32, -12345678), 10, false, FormatOptions{}));
- std.testing.expectEqualSlices(u8, "-bc614e", bufPrintIntToSlice(buf, @as(i32, -12345678), 16, false, FormatOptions{}));
- std.testing.expectEqualSlices(u8, "-BC614E", bufPrintIntToSlice(buf, @as(i32, -12345678), 16, true, FormatOptions{}));
+ try std.testing.expectEqualSlices(u8, "-101111000110000101001110", bufPrintIntToSlice(buf, @as(i32, -12345678), 2, false, FormatOptions{}));
+ try std.testing.expectEqualSlices(u8, "-12345678", bufPrintIntToSlice(buf, @as(i32, -12345678), 10, false, FormatOptions{}));
+ try std.testing.expectEqualSlices(u8, "-bc614e", bufPrintIntToSlice(buf, @as(i32, -12345678), 16, false, FormatOptions{}));
+ try std.testing.expectEqualSlices(u8, "-BC614E", bufPrintIntToSlice(buf, @as(i32, -12345678), 16, true, FormatOptions{}));
- std.testing.expectEqualSlices(u8, "12345678", bufPrintIntToSlice(buf, @as(u32, 12345678), 10, true, FormatOptions{}));
+ try std.testing.expectEqualSlices(u8, "12345678", bufPrintIntToSlice(buf, @as(u32, 12345678), 10, true, FormatOptions{}));
- std.testing.expectEqualSlices(u8, " 666", bufPrintIntToSlice(buf, @as(u32, 666), 10, false, FormatOptions{ .width = 6 }));
- std.testing.expectEqualSlices(u8, " 1234", bufPrintIntToSlice(buf, @as(u32, 0x1234), 16, false, FormatOptions{ .width = 6 }));
- std.testing.expectEqualSlices(u8, "1234", bufPrintIntToSlice(buf, @as(u32, 0x1234), 16, false, FormatOptions{ .width = 1 }));
+ try std.testing.expectEqualSlices(u8, " 666", bufPrintIntToSlice(buf, @as(u32, 666), 10, false, FormatOptions{ .width = 6 }));
+ try std.testing.expectEqualSlices(u8, " 1234", bufPrintIntToSlice(buf, @as(u32, 0x1234), 16, false, FormatOptions{ .width = 6 }));
+ try std.testing.expectEqualSlices(u8, "1234", bufPrintIntToSlice(buf, @as(u32, 0x1234), 16, false, FormatOptions{ .width = 1 }));
- std.testing.expectEqualSlices(u8, "+42", bufPrintIntToSlice(buf, @as(i32, 42), 10, false, FormatOptions{ .width = 3 }));
- std.testing.expectEqualSlices(u8, "-42", bufPrintIntToSlice(buf, @as(i32, -42), 10, false, FormatOptions{ .width = 3 }));
+ try std.testing.expectEqualSlices(u8, "+42", bufPrintIntToSlice(buf, @as(i32, 42), 10, false, FormatOptions{ .width = 3 }));
+ try std.testing.expectEqualSlices(u8, "-42", bufPrintIntToSlice(buf, @as(i32, -42), 10, false, FormatOptions{ .width = 3 }));
}
pub fn bufPrintIntToSlice(buf: []u8, value: anytype, base: u8, uppercase: bool, options: FormatOptions) []u8 {
@@ -1724,8 +1724,8 @@ pub fn comptimePrint(comptime fmt: []const u8, args: anytype) *const [count(fmt,
test "comptimePrint" {
@setEvalBranchQuota(2000);
- std.testing.expectEqual(*const [3:0]u8, @TypeOf(comptime comptimePrint("{}", .{100})));
- std.testing.expectEqualSlices(u8, "100", comptime comptimePrint("{}", .{100}));
+ try std.testing.expectEqual(*const [3:0]u8, @TypeOf(comptime comptimePrint("{}", .{100})));
+ try std.testing.expectEqualSlices(u8, "100", comptime comptimePrint("{}", .{100}));
}
test "parse u64 digit too big" {
@@ -1738,7 +1738,7 @@ test "parse u64 digit too big" {
test "parse unsigned comptime" {
comptime {
- std.testing.expect((try parseUnsigned(usize, "2", 10)) == 2);
+ try std.testing.expect((try parseUnsigned(usize, "2", 10)) == 2);
}
}
@@ -1835,15 +1835,15 @@ test "buffer" {
var buf1: [32]u8 = undefined;
var fbs = std.io.fixedBufferStream(&buf1);
try formatType(1234, "", FormatOptions{}, fbs.writer(), default_max_depth);
- std.testing.expect(mem.eql(u8, fbs.getWritten(), "1234"));
+ try std.testing.expect(mem.eql(u8, fbs.getWritten(), "1234"));
fbs.reset();
try formatType('a', "c", FormatOptions{}, fbs.writer(), default_max_depth);
- std.testing.expect(mem.eql(u8, fbs.getWritten(), "a"));
+ try std.testing.expect(mem.eql(u8, fbs.getWritten(), "a"));
fbs.reset();
try formatType(0b1100, "b", FormatOptions{}, fbs.writer(), default_max_depth);
- std.testing.expect(mem.eql(u8, fbs.getWritten(), "1100"));
+ try std.testing.expect(mem.eql(u8, fbs.getWritten(), "1100"));
}
}
@@ -2170,10 +2170,10 @@ test "union" {
var buf: [100]u8 = undefined;
const uu_result = try bufPrint(buf[0..], "{}", .{uu_inst});
- std.testing.expect(mem.eql(u8, uu_result[0..3], "UU@"));
+ try std.testing.expect(mem.eql(u8, uu_result[0..3], "UU@"));
const eu_result = try bufPrint(buf[0..], "{}", .{eu_inst});
- std.testing.expect(mem.eql(u8, uu_result[0..3], "EU@"));
+ try std.testing.expect(mem.eql(u8, uu_result[0..3], "EU@"));
}
test "enum" {
@@ -2256,9 +2256,9 @@ test "hexToBytes" {
try expectFmt("90" ** 32, "{s}", .{fmtSliceHexUpper(try hexToBytes(&buf, "90" ** 32))});
try expectFmt("ABCD", "{s}", .{fmtSliceHexUpper(try hexToBytes(&buf, "ABCD"))});
try expectFmt("", "{s}", .{fmtSliceHexUpper(try hexToBytes(&buf, ""))});
- std.testing.expectError(error.InvalidCharacter, hexToBytes(&buf, "012Z"));
- std.testing.expectError(error.InvalidLength, hexToBytes(&buf, "AAA"));
- std.testing.expectError(error.NoSpaceLeft, hexToBytes(buf[0..1], "ABAB"));
+ try std.testing.expectError(error.InvalidCharacter, hexToBytes(&buf, "012Z"));
+ try std.testing.expectError(error.InvalidLength, hexToBytes(&buf, "AAA"));
+ try std.testing.expectError(error.NoSpaceLeft, hexToBytes(buf[0..1], "ABAB"));
}
test "formatIntValue with comptime_int" {
@@ -2267,7 +2267,7 @@ test "formatIntValue with comptime_int" {
var buf: [20]u8 = undefined;
var fbs = std.io.fixedBufferStream(&buf);
try formatIntValue(value, "", FormatOptions{}, fbs.writer());
- std.testing.expect(mem.eql(u8, fbs.getWritten(), "123456789123456789"));
+ try std.testing.expect(mem.eql(u8, fbs.getWritten(), "123456789123456789"));
}
test "formatFloatValue with comptime_float" {
@@ -2276,7 +2276,7 @@ test "formatFloatValue with comptime_float" {
var buf: [20]u8 = undefined;
var fbs = std.io.fixedBufferStream(&buf);
try formatFloatValue(value, "", FormatOptions{}, fbs.writer());
- std.testing.expect(mem.eql(u8, fbs.getWritten(), "1.0e+00"));
+ try std.testing.expect(mem.eql(u8, fbs.getWritten(), "1.0e+00"));
try expectFmt("1.0e+00", "{}", .{value});
try expectFmt("1.0e+00", "{}", .{1.0});
@@ -2332,19 +2332,19 @@ test "formatType max_depth" {
var buf: [1000]u8 = undefined;
var fbs = std.io.fixedBufferStream(&buf);
try formatType(inst, "", FormatOptions{}, fbs.writer(), 0);
- std.testing.expect(mem.eql(u8, fbs.getWritten(), "S{ ... }"));
+ try std.testing.expect(mem.eql(u8, fbs.getWritten(), "S{ ... }"));
fbs.reset();
try formatType(inst, "", FormatOptions{}, fbs.writer(), 1);
- std.testing.expect(mem.eql(u8, fbs.getWritten(), "S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }"));
+ try std.testing.expect(mem.eql(u8, fbs.getWritten(), "S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }"));
fbs.reset();
try formatType(inst, "", FormatOptions{}, fbs.writer(), 2);
- std.testing.expect(mem.eql(u8, fbs.getWritten(), "S{ .a = S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }, .tu = TU{ .ptr = TU{ ... } }, .e = E.Two, .vec = (10.200,2.220) }"));
+ try std.testing.expect(mem.eql(u8, fbs.getWritten(), "S{ .a = S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }, .tu = TU{ .ptr = TU{ ... } }, .e = E.Two, .vec = (10.200,2.220) }"));
fbs.reset();
try formatType(inst, "", FormatOptions{}, fbs.writer(), 3);
- std.testing.expect(mem.eql(u8, fbs.getWritten(), "S{ .a = S{ .a = S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }, .tu = TU{ .ptr = TU{ ... } }, .e = E.Two, .vec = (10.200,2.220) }, .tu = TU{ .ptr = TU{ .ptr = TU{ ... } } }, .e = E.Two, .vec = (10.200,2.220) }"));
+ try std.testing.expect(mem.eql(u8, fbs.getWritten(), "S{ .a = S{ .a = S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }, .tu = TU{ .ptr = TU{ ... } }, .e = E.Two, .vec = (10.200,2.220) }, .tu = TU{ .ptr = TU{ .ptr = TU{ ... } } }, .e = E.Two, .vec = (10.200,2.220) }"));
}
test "positional" {
lib/std/hash_map.zig
@@ -824,15 +824,15 @@ test "std.hash_map basic usage" {
while (it.next()) |kv| {
sum += kv.key;
}
- expect(sum == total);
+ try expect(sum == total);
i = 0;
sum = 0;
while (i < count) : (i += 1) {
- expectEqual(map.get(i).?, i);
+ try expectEqual(map.get(i).?, i);
sum += map.get(i).?;
}
- expectEqual(total, sum);
+ try expectEqual(total, sum);
}
test "std.hash_map ensureCapacity" {
@@ -841,13 +841,13 @@ test "std.hash_map ensureCapacity" {
try map.ensureCapacity(20);
const initial_capacity = map.capacity();
- testing.expect(initial_capacity >= 20);
+ try testing.expect(initial_capacity >= 20);
var i: i32 = 0;
while (i < 20) : (i += 1) {
- testing.expect(map.fetchPutAssumeCapacity(i, i + 10) == null);
+ try testing.expect(map.fetchPutAssumeCapacity(i, i + 10) == null);
}
// shouldn't resize from putAssumeCapacity
- testing.expect(initial_capacity == map.capacity());
+ try testing.expect(initial_capacity == map.capacity());
}
test "std.hash_map ensureCapacity with tombstones" {
@@ -870,22 +870,22 @@ test "std.hash_map clearRetainingCapacity" {
map.clearRetainingCapacity();
try map.put(1, 1);
- expectEqual(map.get(1).?, 1);
- expectEqual(map.count(), 1);
+ try expectEqual(map.get(1).?, 1);
+ try expectEqual(map.count(), 1);
map.clearRetainingCapacity();
map.putAssumeCapacity(1, 1);
- expectEqual(map.get(1).?, 1);
- expectEqual(map.count(), 1);
+ try expectEqual(map.get(1).?, 1);
+ try expectEqual(map.count(), 1);
const cap = map.capacity();
- expect(cap > 0);
+ try expect(cap > 0);
map.clearRetainingCapacity();
map.clearRetainingCapacity();
- expectEqual(map.count(), 0);
- expectEqual(map.capacity(), cap);
- expect(!map.contains(1));
+ try expectEqual(map.count(), 0);
+ try expectEqual(map.capacity(), cap);
+ try expect(!map.contains(1));
}
test "std.hash_map grow" {
@@ -898,19 +898,19 @@ test "std.hash_map grow" {
while (i < growTo) : (i += 1) {
try map.put(i, i);
}
- expectEqual(map.count(), growTo);
+ try expectEqual(map.count(), growTo);
i = 0;
var it = map.iterator();
while (it.next()) |kv| {
- expectEqual(kv.key, kv.value);
+ try expectEqual(kv.key, kv.value);
i += 1;
}
- expectEqual(i, growTo);
+ try expectEqual(i, growTo);
i = 0;
while (i < growTo) : (i += 1) {
- expectEqual(map.get(i).?, i);
+ try expectEqual(map.get(i).?, i);
}
}
@@ -921,7 +921,7 @@ test "std.hash_map clone" {
var a = try map.clone();
defer a.deinit();
- expectEqual(a.count(), 0);
+ try expectEqual(a.count(), 0);
try a.put(1, 1);
try a.put(2, 2);
@@ -930,10 +930,10 @@ test "std.hash_map clone" {
var b = try a.clone();
defer b.deinit();
- expectEqual(b.count(), 3);
- expectEqual(b.get(1), 1);
- expectEqual(b.get(2), 2);
- expectEqual(b.get(3), 3);
+ try expectEqual(b.count(), 3);
+ try expectEqual(b.get(1), 1);
+ try expectEqual(b.get(2), 2);
+ try expectEqual(b.get(3), 3);
}
test "std.hash_map ensureCapacity with existing elements" {
@@ -941,12 +941,12 @@ test "std.hash_map ensureCapacity with existing elements" {
defer map.deinit();
try map.put(0, 0);
- expectEqual(map.count(), 1);
- expectEqual(map.capacity(), @TypeOf(map).Unmanaged.minimal_capacity);
+ try expectEqual(map.count(), 1);
+ try expectEqual(map.capacity(), @TypeOf(map).Unmanaged.minimal_capacity);
try map.ensureCapacity(65);
- expectEqual(map.count(), 1);
- expectEqual(map.capacity(), 128);
+ try expectEqual(map.count(), 1);
+ try expectEqual(map.capacity(), 128);
}
test "std.hash_map ensureCapacity satisfies max load factor" {
@@ -954,7 +954,7 @@ test "std.hash_map ensureCapacity satisfies max load factor" {
defer map.deinit();
try map.ensureCapacity(127);
- expectEqual(map.capacity(), 256);
+ try expectEqual(map.capacity(), 256);
}
test "std.hash_map remove" {
@@ -972,19 +972,19 @@ test "std.hash_map remove" {
_ = map.remove(i);
}
}
- expectEqual(map.count(), 10);
+ try expectEqual(map.count(), 10);
var it = map.iterator();
while (it.next()) |kv| {
- expectEqual(kv.key, kv.value);
- expect(kv.key % 3 != 0);
+ try expectEqual(kv.key, kv.value);
+ try expect(kv.key % 3 != 0);
}
i = 0;
while (i < 16) : (i += 1) {
if (i % 3 == 0) {
- expect(!map.contains(i));
+ try expect(!map.contains(i));
} else {
- expectEqual(map.get(i).?, i);
+ try expectEqual(map.get(i).?, i);
}
}
}
@@ -1001,14 +1001,14 @@ test "std.hash_map reverse removes" {
i = 16;
while (i > 0) : (i -= 1) {
_ = map.remove(i - 1);
- expect(!map.contains(i - 1));
+ try expect(!map.contains(i - 1));
var j: u32 = 0;
while (j < i - 1) : (j += 1) {
- expectEqual(map.get(j).?, j);
+ try expectEqual(map.get(j).?, j);
}
}
- expectEqual(map.count(), 0);
+ try expectEqual(map.count(), 0);
}
test "std.hash_map multiple removes on same metadata" {
@@ -1024,17 +1024,17 @@ test "std.hash_map multiple removes on same metadata" {
_ = map.remove(15);
_ = map.remove(14);
_ = map.remove(13);
- expect(!map.contains(7));
- expect(!map.contains(15));
- expect(!map.contains(14));
- expect(!map.contains(13));
+ try expect(!map.contains(7));
+ try expect(!map.contains(15));
+ try expect(!map.contains(14));
+ try expect(!map.contains(13));
i = 0;
while (i < 13) : (i += 1) {
if (i == 7) {
- expect(!map.contains(i));
+ try expect(!map.contains(i));
} else {
- expectEqual(map.get(i).?, i);
+ try expectEqual(map.get(i).?, i);
}
}
@@ -1044,7 +1044,7 @@ test "std.hash_map multiple removes on same metadata" {
try map.put(7, 7);
i = 0;
while (i < 16) : (i += 1) {
- expectEqual(map.get(i).?, i);
+ try expectEqual(map.get(i).?, i);
}
}
@@ -1070,12 +1070,12 @@ test "std.hash_map put and remove loop in random order" {
for (keys.items) |key| {
try map.put(key, key);
}
- expectEqual(map.count(), size);
+ try expectEqual(map.count(), size);
for (keys.items) |key| {
_ = map.remove(key);
}
- expectEqual(map.count(), 0);
+ try expectEqual(map.count(), 0);
}
}
@@ -1119,7 +1119,7 @@ test "std.hash_map put" {
i = 0;
while (i < 16) : (i += 1) {
- expectEqual(map.get(i).?, i);
+ try expectEqual(map.get(i).?, i);
}
i = 0;
@@ -1129,7 +1129,7 @@ test "std.hash_map put" {
i = 0;
while (i < 16) : (i += 1) {
- expectEqual(map.get(i).?, i * 16 + 1);
+ try expectEqual(map.get(i).?, i * 16 + 1);
}
}
@@ -1148,7 +1148,7 @@ test "std.hash_map putAssumeCapacity" {
while (i < 20) : (i += 1) {
sum += map.get(i).?;
}
- expectEqual(sum, 190);
+ try expectEqual(sum, 190);
i = 0;
while (i < 20) : (i += 1) {
@@ -1160,7 +1160,7 @@ test "std.hash_map putAssumeCapacity" {
while (i < 20) : (i += 1) {
sum += map.get(i).?;
}
- expectEqual(sum, 20);
+ try expectEqual(sum, 20);
}
test "std.hash_map getOrPut" {
@@ -1183,49 +1183,49 @@ test "std.hash_map getOrPut" {
sum += map.get(i).?;
}
- expectEqual(sum, 30);
+ try expectEqual(sum, 30);
}
test "std.hash_map basic hash map usage" {
var map = AutoHashMap(i32, i32).init(std.testing.allocator);
defer map.deinit();
- testing.expect((try map.fetchPut(1, 11)) == null);
- testing.expect((try map.fetchPut(2, 22)) == null);
- testing.expect((try map.fetchPut(3, 33)) == null);
- testing.expect((try map.fetchPut(4, 44)) == null);
+ try testing.expect((try map.fetchPut(1, 11)) == null);
+ try testing.expect((try map.fetchPut(2, 22)) == null);
+ try testing.expect((try map.fetchPut(3, 33)) == null);
+ try testing.expect((try map.fetchPut(4, 44)) == null);
try map.putNoClobber(5, 55);
- testing.expect((try map.fetchPut(5, 66)).?.value == 55);
- testing.expect((try map.fetchPut(5, 55)).?.value == 66);
+ try testing.expect((try map.fetchPut(5, 66)).?.value == 55);
+ try testing.expect((try map.fetchPut(5, 55)).?.value == 66);
const gop1 = try map.getOrPut(5);
- testing.expect(gop1.found_existing == true);
- testing.expect(gop1.entry.value == 55);
+ try testing.expect(gop1.found_existing == true);
+ try testing.expect(gop1.entry.value == 55);
gop1.entry.value = 77;
- testing.expect(map.getEntry(5).?.value == 77);
+ try testing.expect(map.getEntry(5).?.value == 77);
const gop2 = try map.getOrPut(99);
- testing.expect(gop2.found_existing == false);
+ try testing.expect(gop2.found_existing == false);
gop2.entry.value = 42;
- testing.expect(map.getEntry(99).?.value == 42);
+ try testing.expect(map.getEntry(99).?.value == 42);
const gop3 = try map.getOrPutValue(5, 5);
- testing.expect(gop3.value == 77);
+ try testing.expect(gop3.value == 77);
const gop4 = try map.getOrPutValue(100, 41);
- testing.expect(gop4.value == 41);
+ try testing.expect(gop4.value == 41);
- testing.expect(map.contains(2));
- testing.expect(map.getEntry(2).?.value == 22);
- testing.expect(map.get(2).? == 22);
+ try testing.expect(map.contains(2));
+ try testing.expect(map.getEntry(2).?.value == 22);
+ try testing.expect(map.get(2).? == 22);
const rmv1 = map.remove(2);
- testing.expect(rmv1.?.key == 2);
- testing.expect(rmv1.?.value == 22);
- testing.expect(map.remove(2) == null);
- testing.expect(map.getEntry(2) == null);
- testing.expect(map.get(2) == null);
+ try testing.expect(rmv1.?.key == 2);
+ try testing.expect(rmv1.?.value == 22);
+ try testing.expect(map.remove(2) == null);
+ try testing.expect(map.getEntry(2) == null);
+ try testing.expect(map.get(2) == null);
map.removeAssertDiscard(3);
}
@@ -1244,6 +1244,6 @@ test "std.hash_map clone" {
i = 0;
while (i < 10) : (i += 1) {
- testing.expect(copy.get(i).? == i * 10);
+ try testing.expect(copy.get(i).? == i * 10);
}
}
lib/std/heap.zig
@@ -858,16 +858,16 @@ test "WasmPageAllocator internals" {
if (comptime std.Target.current.isWasm()) {
const conventional_memsize = WasmPageAllocator.conventional.totalPages() * mem.page_size;
const initial = try page_allocator.alloc(u8, mem.page_size);
- testing.expect(@ptrToInt(initial.ptr) < conventional_memsize); // If this isn't conventional, the rest of these tests don't make sense. Also we have a serious memory leak in the test suite.
+ try testing.expect(@ptrToInt(initial.ptr) < conventional_memsize); // If this isn't conventional, the rest of these tests don't make sense. Also we have a serious memory leak in the test suite.
var inplace = try page_allocator.realloc(initial, 1);
- testing.expectEqual(initial.ptr, inplace.ptr);
+ try testing.expectEqual(initial.ptr, inplace.ptr);
inplace = try page_allocator.realloc(inplace, 4);
- testing.expectEqual(initial.ptr, inplace.ptr);
+ try testing.expectEqual(initial.ptr, inplace.ptr);
page_allocator.free(inplace);
const reuse = try page_allocator.alloc(u8, 1);
- testing.expectEqual(initial.ptr, reuse.ptr);
+ try testing.expectEqual(initial.ptr, reuse.ptr);
page_allocator.free(reuse);
// This segment may span conventional and extended which has really complex rules so we're just ignoring it for now.
@@ -875,18 +875,18 @@ test "WasmPageAllocator internals" {
page_allocator.free(padding);
const extended = try page_allocator.alloc(u8, conventional_memsize);
- testing.expect(@ptrToInt(extended.ptr) >= conventional_memsize);
+ try testing.expect(@ptrToInt(extended.ptr) >= conventional_memsize);
const use_small = try page_allocator.alloc(u8, 1);
- testing.expectEqual(initial.ptr, use_small.ptr);
+ try testing.expectEqual(initial.ptr, use_small.ptr);
page_allocator.free(use_small);
inplace = try page_allocator.realloc(extended, 1);
- testing.expectEqual(extended.ptr, inplace.ptr);
+ try testing.expectEqual(extended.ptr, inplace.ptr);
page_allocator.free(inplace);
const reuse_extended = try page_allocator.alloc(u8, conventional_memsize);
- testing.expectEqual(extended.ptr, reuse_extended.ptr);
+ try testing.expectEqual(extended.ptr, reuse_extended.ptr);
page_allocator.free(reuse_extended);
}
}
@@ -959,15 +959,15 @@ test "FixedBufferAllocator.reset" {
var x = try fba.allocator.create(u64);
x.* = X;
- testing.expectError(error.OutOfMemory, fba.allocator.create(u64));
+ try testing.expectError(error.OutOfMemory, fba.allocator.create(u64));
fba.reset();
var y = try fba.allocator.create(u64);
y.* = Y;
// we expect Y to have overwritten X.
- testing.expect(x.* == y.*);
- testing.expect(y.* == Y);
+ try testing.expect(x.* == y.*);
+ try testing.expect(y.* == Y);
}
test "StackFallbackAllocator" {
@@ -987,11 +987,11 @@ test "FixedBufferAllocator Reuse memory on realloc" {
var fixed_buffer_allocator = FixedBufferAllocator.init(small_fixed_buffer[0..]);
var slice0 = try fixed_buffer_allocator.allocator.alloc(u8, 5);
- testing.expect(slice0.len == 5);
+ try testing.expect(slice0.len == 5);
var slice1 = try fixed_buffer_allocator.allocator.realloc(slice0, 10);
- testing.expect(slice1.ptr == slice0.ptr);
- testing.expect(slice1.len == 10);
- testing.expectError(error.OutOfMemory, fixed_buffer_allocator.allocator.realloc(slice1, 11));
+ try testing.expect(slice1.ptr == slice0.ptr);
+ try testing.expect(slice1.len == 10);
+ try testing.expectError(error.OutOfMemory, fixed_buffer_allocator.allocator.realloc(slice1, 11));
}
// check that we don't re-use the memory if it's not the most recent block
{
@@ -1002,10 +1002,10 @@ test "FixedBufferAllocator Reuse memory on realloc" {
slice0[1] = 2;
var slice1 = try fixed_buffer_allocator.allocator.alloc(u8, 2);
var slice2 = try fixed_buffer_allocator.allocator.realloc(slice0, 4);
- testing.expect(slice0.ptr != slice2.ptr);
- testing.expect(slice1.ptr != slice2.ptr);
- testing.expect(slice2[0] == 1);
- testing.expect(slice2[1] == 2);
+ try testing.expect(slice0.ptr != slice2.ptr);
+ try testing.expect(slice1.ptr != slice2.ptr);
+ try testing.expect(slice2[0] == 1);
+ try testing.expect(slice2[1] == 2);
}
}
@@ -1024,28 +1024,28 @@ pub fn testAllocator(base_allocator: *mem.Allocator) !void {
const allocator = &validationAllocator.allocator;
var slice = try allocator.alloc(*i32, 100);
- testing.expect(slice.len == 100);
+ try testing.expect(slice.len == 100);
for (slice) |*item, i| {
item.* = try allocator.create(i32);
item.*.* = @intCast(i32, i);
}
slice = try allocator.realloc(slice, 20000);
- testing.expect(slice.len == 20000);
+ try testing.expect(slice.len == 20000);
for (slice[0..100]) |item, i| {
- testing.expect(item.* == @intCast(i32, i));
+ try testing.expect(item.* == @intCast(i32, i));
allocator.destroy(item);
}
slice = allocator.shrink(slice, 50);
- testing.expect(slice.len == 50);
+ try testing.expect(slice.len == 50);
slice = allocator.shrink(slice, 25);
- testing.expect(slice.len == 25);
+ try testing.expect(slice.len == 25);
slice = allocator.shrink(slice, 0);
- testing.expect(slice.len == 0);
+ try testing.expect(slice.len == 0);
slice = try allocator.realloc(slice, 10);
- testing.expect(slice.len == 10);
+ try testing.expect(slice.len == 10);
allocator.free(slice);
@@ -1058,7 +1058,7 @@ pub fn testAllocator(base_allocator: *mem.Allocator) !void {
allocator.destroy(zero_bit_ptr);
const oversize = try allocator.allocAdvanced(u32, null, 5, .at_least);
- testing.expect(oversize.len >= 5);
+ try testing.expect(oversize.len >= 5);
for (oversize) |*item| {
item.* = 0xDEADBEEF;
}
@@ -1073,29 +1073,29 @@ pub fn testAllocatorAligned(base_allocator: *mem.Allocator) !void {
inline for ([_]u29{ 1, 2, 4, 8, 16, 32, 64 }) |alignment| {
// initial
var slice = try allocator.alignedAlloc(u8, alignment, 10);
- testing.expect(slice.len == 10);
+ try testing.expect(slice.len == 10);
// grow
slice = try allocator.realloc(slice, 100);
- testing.expect(slice.len == 100);
+ try testing.expect(slice.len == 100);
// shrink
slice = allocator.shrink(slice, 10);
- testing.expect(slice.len == 10);
+ try testing.expect(slice.len == 10);
// go to zero
slice = allocator.shrink(slice, 0);
- testing.expect(slice.len == 0);
+ try testing.expect(slice.len == 0);
// realloc from zero
slice = try allocator.realloc(slice, 100);
- testing.expect(slice.len == 100);
+ try testing.expect(slice.len == 100);
// shrink with shrink
slice = allocator.shrink(slice, 10);
- testing.expect(slice.len == 10);
+ try testing.expect(slice.len == 10);
// shrink to zero
slice = allocator.shrink(slice, 0);
- testing.expect(slice.len == 0);
+ try testing.expect(slice.len == 0);
}
}
-pub fn testAllocatorLargeAlignment(base_allocator: *mem.Allocator) mem.Allocator.Error!void {
+pub fn testAllocatorLargeAlignment(base_allocator: *mem.Allocator) !void {
var validationAllocator = mem.validationWrap(base_allocator);
const allocator = &validationAllocator.allocator;
@@ -1110,24 +1110,24 @@ pub fn testAllocatorLargeAlignment(base_allocator: *mem.Allocator) mem.Allocator
_ = @shlWithOverflow(usize, ~@as(usize, 0), @as(USizeShift, @ctz(u29, large_align)), &align_mask);
var slice = try allocator.alignedAlloc(u8, large_align, 500);
- testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
+ try testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
slice = allocator.shrink(slice, 100);
- testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
+ try testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
slice = try allocator.realloc(slice, 5000);
- testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
+ try testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
slice = allocator.shrink(slice, 10);
- testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
+ try testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
slice = try allocator.realloc(slice, 20000);
- testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
+ try testing.expect(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
allocator.free(slice);
}
-pub fn testAllocatorAlignedShrink(base_allocator: *mem.Allocator) mem.Allocator.Error!void {
+pub fn testAllocatorAlignedShrink(base_allocator: *mem.Allocator) !void {
var validationAllocator = mem.validationWrap(base_allocator);
const allocator = &validationAllocator.allocator;
@@ -1155,8 +1155,8 @@ pub fn testAllocatorAlignedShrink(base_allocator: *mem.Allocator) mem.Allocator.
// realloc to a smaller size but with a larger alignment
slice = try allocator.reallocAdvanced(slice, mem.page_size * 32, alloc_size / 2, .exact);
- testing.expect(slice[0] == 0x12);
- testing.expect(slice[60] == 0x34);
+ try testing.expect(slice[0] == 0x12);
+ try testing.expect(slice[60] == 0x34);
}
test "heap" {
lib/std/json.zig
@@ -79,18 +79,18 @@ fn encodesTo(decoded: []const u8, encoded: []const u8) bool {
test "encodesTo" {
// same
- testing.expectEqual(true, encodesTo("false", "false"));
+ try testing.expectEqual(true, encodesTo("false", "false"));
// totally different
- testing.expectEqual(false, encodesTo("false", "true"));
+ try testing.expectEqual(false, encodesTo("false", "true"));
// different lengths
- testing.expectEqual(false, encodesTo("false", "other"));
+ try testing.expectEqual(false, encodesTo("false", "other"));
// with escape
- testing.expectEqual(true, encodesTo("\\", "\\\\"));
- testing.expectEqual(true, encodesTo("with\nescape", "with\\nescape"));
+ try testing.expectEqual(true, encodesTo("\\", "\\\\"));
+ try testing.expectEqual(true, encodesTo("with\nescape", "with\\nescape"));
// with unicode
- testing.expectEqual(true, encodesTo("ą", "\\u0105"));
- testing.expectEqual(true, encodesTo("😂", "\\ud83d\\ude02"));
- testing.expectEqual(true, encodesTo("withąunicode😂", "with\\u0105unicode\\ud83d\\ude02"));
+ try testing.expectEqual(true, encodesTo("ą", "\\u0105"));
+ try testing.expectEqual(true, encodesTo("😂", "\\ud83d\\ude02"));
+ try testing.expectEqual(true, encodesTo("withąunicode😂", "with\\u0105unicode\\ud83d\\ude02"));
}
/// A single token slice into the parent string.
@@ -1138,9 +1138,9 @@ pub const TokenStream = struct {
}
};
-fn checkNext(p: *TokenStream, id: std.meta.Tag(Token)) void {
+fn checkNext(p: *TokenStream, id: std.meta.Tag(Token)) !void {
const token = (p.next() catch unreachable).?;
- debug.assert(std.meta.activeTag(token) == id);
+ try testing.expect(std.meta.activeTag(token) == id);
}
test "json.token" {
@@ -1163,46 +1163,46 @@ test "json.token" {
var p = TokenStream.init(s);
- checkNext(&p, .ObjectBegin);
- checkNext(&p, .String); // Image
- checkNext(&p, .ObjectBegin);
- checkNext(&p, .String); // Width
- checkNext(&p, .Number);
- checkNext(&p, .String); // Height
- checkNext(&p, .Number);
- checkNext(&p, .String); // Title
- checkNext(&p, .String);
- checkNext(&p, .String); // Thumbnail
- checkNext(&p, .ObjectBegin);
- checkNext(&p, .String); // Url
- checkNext(&p, .String);
- checkNext(&p, .String); // Height
- checkNext(&p, .Number);
- checkNext(&p, .String); // Width
- checkNext(&p, .Number);
- checkNext(&p, .ObjectEnd);
- checkNext(&p, .String); // Animated
- checkNext(&p, .False);
- checkNext(&p, .String); // IDs
- checkNext(&p, .ArrayBegin);
- checkNext(&p, .Number);
- checkNext(&p, .Number);
- checkNext(&p, .Number);
- checkNext(&p, .Number);
- checkNext(&p, .ArrayEnd);
- checkNext(&p, .ObjectEnd);
- checkNext(&p, .ObjectEnd);
-
- testing.expect((try p.next()) == null);
+ try checkNext(&p, .ObjectBegin);
+ try checkNext(&p, .String); // Image
+ try checkNext(&p, .ObjectBegin);
+ try checkNext(&p, .String); // Width
+ try checkNext(&p, .Number);
+ try checkNext(&p, .String); // Height
+ try checkNext(&p, .Number);
+ try checkNext(&p, .String); // Title
+ try checkNext(&p, .String);
+ try checkNext(&p, .String); // Thumbnail
+ try checkNext(&p, .ObjectBegin);
+ try checkNext(&p, .String); // Url
+ try checkNext(&p, .String);
+ try checkNext(&p, .String); // Height
+ try checkNext(&p, .Number);
+ try checkNext(&p, .String); // Width
+ try checkNext(&p, .Number);
+ try checkNext(&p, .ObjectEnd);
+ try checkNext(&p, .String); // Animated
+ try checkNext(&p, .False);
+ try checkNext(&p, .String); // IDs
+ try checkNext(&p, .ArrayBegin);
+ try checkNext(&p, .Number);
+ try checkNext(&p, .Number);
+ try checkNext(&p, .Number);
+ try checkNext(&p, .Number);
+ try checkNext(&p, .ArrayEnd);
+ try checkNext(&p, .ObjectEnd);
+ try checkNext(&p, .ObjectEnd);
+
+ try testing.expect((try p.next()) == null);
}
test "json.token mismatched close" {
var p = TokenStream.init("[102, 111, 111 }");
- checkNext(&p, .ArrayBegin);
- checkNext(&p, .Number);
- checkNext(&p, .Number);
- checkNext(&p, .Number);
- testing.expectError(error.UnexpectedClosingBrace, p.next());
+ try checkNext(&p, .ArrayBegin);
+ try checkNext(&p, .Number);
+ try checkNext(&p, .Number);
+ try checkNext(&p, .Number);
+ try testing.expectError(error.UnexpectedClosingBrace, p.next());
}
/// Validate a JSON string. This does not limit number precision so a decoder may not necessarily
@@ -1223,12 +1223,12 @@ pub fn validate(s: []const u8) bool {
}
test "json.validate" {
- testing.expectEqual(true, validate("{}"));
- testing.expectEqual(true, validate("[]"));
- testing.expectEqual(true, validate("[{[[[[{}]]]]}]"));
- testing.expectEqual(false, validate("{]"));
- testing.expectEqual(false, validate("[}"));
- testing.expectEqual(false, validate("{{{{[]}}}]"));
+ try testing.expectEqual(true, validate("{}"));
+ try testing.expectEqual(true, validate("[]"));
+ try testing.expectEqual(true, validate("[{[[[[{}]]]]}]"));
+ try testing.expectEqual(false, validate("{]"));
+ try testing.expectEqual(false, validate("[}"));
+ try testing.expectEqual(false, validate("{{{{[]}}}]"));
}
const Allocator = std.mem.Allocator;
@@ -1326,37 +1326,37 @@ test "Value.jsonStringify" {
var buffer: [10]u8 = undefined;
var fbs = std.io.fixedBufferStream(&buffer);
try @as(Value, .Null).jsonStringify(.{}, fbs.writer());
- testing.expectEqualSlices(u8, fbs.getWritten(), "null");
+ try testing.expectEqualSlices(u8, fbs.getWritten(), "null");
}
{
var buffer: [10]u8 = undefined;
var fbs = std.io.fixedBufferStream(&buffer);
try (Value{ .Bool = true }).jsonStringify(.{}, fbs.writer());
- testing.expectEqualSlices(u8, fbs.getWritten(), "true");
+ try testing.expectEqualSlices(u8, fbs.getWritten(), "true");
}
{
var buffer: [10]u8 = undefined;
var fbs = std.io.fixedBufferStream(&buffer);
try (Value{ .Integer = 42 }).jsonStringify(.{}, fbs.writer());
- testing.expectEqualSlices(u8, fbs.getWritten(), "42");
+ try testing.expectEqualSlices(u8, fbs.getWritten(), "42");
}
{
var buffer: [10]u8 = undefined;
var fbs = std.io.fixedBufferStream(&buffer);
try (Value{ .NumberString = "43" }).jsonStringify(.{}, fbs.writer());
- testing.expectEqualSlices(u8, fbs.getWritten(), "43");
+ try testing.expectEqualSlices(u8, fbs.getWritten(), "43");
}
{
var buffer: [10]u8 = undefined;
var fbs = std.io.fixedBufferStream(&buffer);
try (Value{ .Float = 42 }).jsonStringify(.{}, fbs.writer());
- testing.expectEqualSlices(u8, fbs.getWritten(), "4.2e+01");
+ try testing.expectEqualSlices(u8, fbs.getWritten(), "4.2e+01");
}
{
var buffer: [10]u8 = undefined;
var fbs = std.io.fixedBufferStream(&buffer);
try (Value{ .String = "weeee" }).jsonStringify(.{}, fbs.writer());
- testing.expectEqualSlices(u8, fbs.getWritten(), "\"weeee\"");
+ try testing.expectEqualSlices(u8, fbs.getWritten(), "\"weeee\"");
}
{
var buffer: [10]u8 = undefined;
@@ -1369,7 +1369,7 @@ test "Value.jsonStringify" {
try (Value{
.Array = Array.fromOwnedSlice(undefined, &vals),
}).jsonStringify(.{}, fbs.writer());
- testing.expectEqualSlices(u8, fbs.getWritten(), "[1,2,3]");
+ try testing.expectEqualSlices(u8, fbs.getWritten(), "[1,2,3]");
}
{
var buffer: [10]u8 = undefined;
@@ -1378,7 +1378,7 @@ test "Value.jsonStringify" {
defer obj.deinit();
try obj.putNoClobber("a", .{ .String = "b" });
try (Value{ .Object = obj }).jsonStringify(.{}, fbs.writer());
- testing.expectEqualSlices(u8, fbs.getWritten(), "{\"a\":\"b\"}");
+ try testing.expectEqualSlices(u8, fbs.getWritten(), "{\"a\":\"b\"}");
}
}
@@ -1751,17 +1751,17 @@ pub fn parseFree(comptime T: type, value: T, options: ParseOptions) void {
}
test "parse" {
- testing.expectEqual(false, try parse(bool, &TokenStream.init("false"), ParseOptions{}));
- testing.expectEqual(true, try parse(bool, &TokenStream.init("true"), ParseOptions{}));
- testing.expectEqual(@as(u1, 1), try parse(u1, &TokenStream.init("1"), ParseOptions{}));
- testing.expectError(error.Overflow, parse(u1, &TokenStream.init("50"), ParseOptions{}));
- testing.expectEqual(@as(u64, 42), try parse(u64, &TokenStream.init("42"), ParseOptions{}));
- testing.expectEqual(@as(f64, 42), try parse(f64, &TokenStream.init("42.0"), ParseOptions{}));
- testing.expectEqual(@as(?bool, null), try parse(?bool, &TokenStream.init("null"), ParseOptions{}));
- testing.expectEqual(@as(?bool, true), try parse(?bool, &TokenStream.init("true"), ParseOptions{}));
-
- testing.expectEqual(@as([3]u8, "foo".*), try parse([3]u8, &TokenStream.init("\"foo\""), ParseOptions{}));
- testing.expectEqual(@as([3]u8, "foo".*), try parse([3]u8, &TokenStream.init("[102, 111, 111]"), ParseOptions{}));
+ try testing.expectEqual(false, try parse(bool, &TokenStream.init("false"), ParseOptions{}));
+ try testing.expectEqual(true, try parse(bool, &TokenStream.init("true"), ParseOptions{}));
+ try testing.expectEqual(@as(u1, 1), try parse(u1, &TokenStream.init("1"), ParseOptions{}));
+ try testing.expectError(error.Overflow, parse(u1, &TokenStream.init("50"), ParseOptions{}));
+ try testing.expectEqual(@as(u64, 42), try parse(u64, &TokenStream.init("42"), ParseOptions{}));
+ try testing.expectEqual(@as(f64, 42), try parse(f64, &TokenStream.init("42.0"), ParseOptions{}));
+ try testing.expectEqual(@as(?bool, null), try parse(?bool, &TokenStream.init("null"), ParseOptions{}));
+ try testing.expectEqual(@as(?bool, true), try parse(?bool, &TokenStream.init("true"), ParseOptions{}));
+
+ try testing.expectEqual(@as([3]u8, "foo".*), try parse([3]u8, &TokenStream.init("\"foo\""), ParseOptions{}));
+ try testing.expectEqual(@as([3]u8, "foo".*), try parse([3]u8, &TokenStream.init("[102, 111, 111]"), ParseOptions{}));
}
test "parse into enum" {
@@ -1770,31 +1770,31 @@ test "parse into enum" {
Bar,
@"with\\escape",
};
- testing.expectEqual(@as(T, .Foo), try parse(T, &TokenStream.init("\"Foo\""), ParseOptions{}));
- testing.expectEqual(@as(T, .Foo), try parse(T, &TokenStream.init("42"), ParseOptions{}));
- testing.expectEqual(@as(T, .@"with\\escape"), try parse(T, &TokenStream.init("\"with\\\\escape\""), ParseOptions{}));
- testing.expectError(error.InvalidEnumTag, parse(T, &TokenStream.init("5"), ParseOptions{}));
- testing.expectError(error.InvalidEnumTag, parse(T, &TokenStream.init("\"Qux\""), ParseOptions{}));
+ try testing.expectEqual(@as(T, .Foo), try parse(T, &TokenStream.init("\"Foo\""), ParseOptions{}));
+ try testing.expectEqual(@as(T, .Foo), try parse(T, &TokenStream.init("42"), ParseOptions{}));
+ try testing.expectEqual(@as(T, .@"with\\escape"), try parse(T, &TokenStream.init("\"with\\\\escape\""), ParseOptions{}));
+ try testing.expectError(error.InvalidEnumTag, parse(T, &TokenStream.init("5"), ParseOptions{}));
+ try testing.expectError(error.InvalidEnumTag, parse(T, &TokenStream.init("\"Qux\""), ParseOptions{}));
}
test "parse into that allocates a slice" {
- testing.expectError(error.AllocatorRequired, parse([]u8, &TokenStream.init("\"foo\""), ParseOptions{}));
+ try testing.expectError(error.AllocatorRequired, parse([]u8, &TokenStream.init("\"foo\""), ParseOptions{}));
const options = ParseOptions{ .allocator = testing.allocator };
{
const r = try parse([]u8, &TokenStream.init("\"foo\""), options);
defer parseFree([]u8, r, options);
- testing.expectEqualSlices(u8, "foo", r);
+ try testing.expectEqualSlices(u8, "foo", r);
}
{
const r = try parse([]u8, &TokenStream.init("[102, 111, 111]"), options);
defer parseFree([]u8, r, options);
- testing.expectEqualSlices(u8, "foo", r);
+ try testing.expectEqualSlices(u8, "foo", r);
}
{
const r = try parse([]u8, &TokenStream.init("\"with\\\\escape\""), options);
defer parseFree([]u8, r, options);
- testing.expectEqualSlices(u8, "with\\escape", r);
+ try testing.expectEqualSlices(u8, "with\\escape", r);
}
}
@@ -1805,7 +1805,7 @@ test "parse into tagged union" {
float: f64,
string: []const u8,
};
- testing.expectEqual(T{ .float = 1.5 }, try parse(T, &TokenStream.init("1.5"), ParseOptions{}));
+ try testing.expectEqual(T{ .float = 1.5 }, try parse(T, &TokenStream.init("1.5"), ParseOptions{}));
}
{ // failing allocations should be bubbled up instantly without trying next member
@@ -1816,7 +1816,7 @@ test "parse into tagged union" {
string: []const u8,
array: [3]u8,
};
- testing.expectError(error.OutOfMemory, parse(T, &TokenStream.init("[1,2,3]"), options));
+ try testing.expectError(error.OutOfMemory, parse(T, &TokenStream.init("[1,2,3]"), options));
}
{
@@ -1825,7 +1825,7 @@ test "parse into tagged union" {
x: u8,
y: u8,
};
- testing.expectEqual(T{ .x = 42 }, try parse(T, &TokenStream.init("42"), ParseOptions{}));
+ try testing.expectEqual(T{ .x = 42 }, try parse(T, &TokenStream.init("42"), ParseOptions{}));
}
{ // needs to back out when first union member doesn't match
@@ -1833,7 +1833,7 @@ test "parse into tagged union" {
A: struct { x: u32 },
B: struct { y: u32 },
};
- testing.expectEqual(T{ .B = .{ .y = 42 } }, try parse(T, &TokenStream.init("{\"y\":42}"), ParseOptions{}));
+ try testing.expectEqual(T{ .B = .{ .y = 42 } }, try parse(T, &TokenStream.init("{\"y\":42}"), ParseOptions{}));
}
}
@@ -1843,7 +1843,7 @@ test "parse union bubbles up AllocatorRequired" {
string: []const u8,
int: i32,
};
- testing.expectError(error.AllocatorRequired, parse(T, &TokenStream.init("42"), ParseOptions{}));
+ try testing.expectError(error.AllocatorRequired, parse(T, &TokenStream.init("42"), ParseOptions{}));
}
{ // string member not first in union (and matching)
@@ -1852,7 +1852,7 @@ test "parse union bubbles up AllocatorRequired" {
float: f64,
string: []const u8,
};
- testing.expectError(error.AllocatorRequired, parse(T, &TokenStream.init("\"foo\""), ParseOptions{}));
+ try testing.expectError(error.AllocatorRequired, parse(T, &TokenStream.init("\"foo\""), ParseOptions{}));
}
}
@@ -1866,11 +1866,11 @@ test "parseFree descends into tagged union" {
};
// use a string with unicode escape so we know result can't be a reference to global constant
const r = try parse(T, &TokenStream.init("\"with\\u0105unicode\""), options);
- testing.expectEqual(std.meta.Tag(T).string, @as(std.meta.Tag(T), r));
- testing.expectEqualSlices(u8, "withąunicode", r.string);
- testing.expectEqual(@as(usize, 0), fail_alloc.deallocations);
+ try testing.expectEqual(std.meta.Tag(T).string, @as(std.meta.Tag(T), r));
+ try testing.expectEqualSlices(u8, "withąunicode", r.string);
+ try testing.expectEqual(@as(usize, 0), fail_alloc.deallocations);
parseFree(T, r, options);
- testing.expectEqual(@as(usize, 1), fail_alloc.deallocations);
+ try testing.expectEqual(@as(usize, 1), fail_alloc.deallocations);
}
test "parse with comptime field" {
@@ -1879,7 +1879,7 @@ test "parse with comptime field" {
comptime a: i32 = 0,
b: bool,
};
- testing.expectEqual(T{ .a = 0, .b = true }, try parse(T, &TokenStream.init(
+ try testing.expectEqual(T{ .a = 0, .b = true }, try parse(T, &TokenStream.init(
\\{
\\ "a": 0,
\\ "b": true
@@ -1912,7 +1912,7 @@ test "parse with comptime field" {
test "parse into struct with no fields" {
const T = struct {};
- testing.expectEqual(T{}, try parse(T, &TokenStream.init("{}"), ParseOptions{}));
+ try testing.expectEqual(T{}, try parse(T, &TokenStream.init("{}"), ParseOptions{}));
}
test "parse into struct with misc fields" {
@@ -1968,24 +1968,24 @@ test "parse into struct with misc fields" {
\\}
), options);
defer parseFree(T, r, options);
- testing.expectEqual(@as(i64, 420), r.int);
- testing.expectEqual(@as(f64, 3.14), r.float);
- testing.expectEqual(true, r.@"with\\escape");
- testing.expectEqual(false, r.@"withąunicode😂");
- testing.expectEqualSlices(u8, "zig", r.language);
- testing.expectEqual(@as(?bool, null), r.optional);
- testing.expectEqual(@as(i32, 42), r.default_field);
- testing.expectEqual(@as(f64, 66.6), r.static_array[0]);
- testing.expectEqual(@as(f64, 420.420), r.static_array[1]);
- testing.expectEqual(@as(f64, 69.69), r.static_array[2]);
- testing.expectEqual(@as(usize, 3), r.dynamic_array.len);
- testing.expectEqual(@as(f64, 66.6), r.dynamic_array[0]);
- testing.expectEqual(@as(f64, 420.420), r.dynamic_array[1]);
- testing.expectEqual(@as(f64, 69.69), r.dynamic_array[2]);
- testing.expectEqualSlices(u8, r.complex.nested, "zig");
- testing.expectEqualSlices(u8, "zig", r.veryComplex[0].foo);
- testing.expectEqualSlices(u8, "rocks", r.veryComplex[1].foo);
- testing.expectEqual(T.Union{ .float = 100000 }, r.a_union);
+ try testing.expectEqual(@as(i64, 420), r.int);
+ try testing.expectEqual(@as(f64, 3.14), r.float);
+ try testing.expectEqual(true, r.@"with\\escape");
+ try testing.expectEqual(false, r.@"withąunicode😂");
+ try testing.expectEqualSlices(u8, "zig", r.language);
+ try testing.expectEqual(@as(?bool, null), r.optional);
+ try testing.expectEqual(@as(i32, 42), r.default_field);
+ try testing.expectEqual(@as(f64, 66.6), r.static_array[0]);
+ try testing.expectEqual(@as(f64, 420.420), r.static_array[1]);
+ try testing.expectEqual(@as(f64, 69.69), r.static_array[2]);
+ try testing.expectEqual(@as(usize, 3), r.dynamic_array.len);
+ try testing.expectEqual(@as(f64, 66.6), r.dynamic_array[0]);
+ try testing.expectEqual(@as(f64, 420.420), r.dynamic_array[1]);
+ try testing.expectEqual(@as(f64, 69.69), r.dynamic_array[2]);
+ try testing.expectEqualSlices(u8, r.complex.nested, "zig");
+ try testing.expectEqualSlices(u8, "zig", r.veryComplex[0].foo);
+ try testing.expectEqualSlices(u8, "rocks", r.veryComplex[1].foo);
+ try testing.expectEqual(T.Union{ .float = 100000 }, r.a_union);
}
/// A non-stream JSON parser which constructs a tree of Value's.
@@ -2320,28 +2320,28 @@ test "json.parser.dynamic" {
var image = root.Object.get("Image").?;
const width = image.Object.get("Width").?;
- testing.expect(width.Integer == 800);
+ try testing.expect(width.Integer == 800);
const height = image.Object.get("Height").?;
- testing.expect(height.Integer == 600);
+ try testing.expect(height.Integer == 600);
const title = image.Object.get("Title").?;
- testing.expect(mem.eql(u8, title.String, "View from 15th Floor"));
+ try testing.expect(mem.eql(u8, title.String, "View from 15th Floor"));
const animated = image.Object.get("Animated").?;
- testing.expect(animated.Bool == false);
+ try testing.expect(animated.Bool == false);
const array_of_object = image.Object.get("ArrayOfObject").?;
- testing.expect(array_of_object.Array.items.len == 1);
+ try testing.expect(array_of_object.Array.items.len == 1);
const obj0 = array_of_object.Array.items[0].Object.get("n").?;
- testing.expect(mem.eql(u8, obj0.String, "m"));
+ try testing.expect(mem.eql(u8, obj0.String, "m"));
const double = image.Object.get("double").?;
- testing.expect(double.Float == 1.3412);
+ try testing.expect(double.Float == 1.3412);
const large_int = image.Object.get("LargeInt").?;
- testing.expect(mem.eql(u8, large_int.NumberString, "18446744073709551615"));
+ try testing.expect(mem.eql(u8, large_int.NumberString, "18446744073709551615"));
}
test "import more json tests" {
@@ -2388,12 +2388,12 @@ test "write json then parse it" {
var tree = try parser.parse(fixed_buffer_stream.getWritten());
defer tree.deinit();
- testing.expect(tree.root.Object.get("f").?.Bool == false);
- testing.expect(tree.root.Object.get("t").?.Bool == true);
- testing.expect(tree.root.Object.get("int").?.Integer == 1234);
- testing.expect(tree.root.Object.get("array").?.Array.items[0].Null == {});
- testing.expect(tree.root.Object.get("array").?.Array.items[1].Float == 12.34);
- testing.expect(mem.eql(u8, tree.root.Object.get("str").?.String, "hello"));
+ try testing.expect(tree.root.Object.get("f").?.Bool == false);
+ try testing.expect(tree.root.Object.get("t").?.Bool == true);
+ try testing.expect(tree.root.Object.get("int").?.Integer == 1234);
+ try testing.expect(tree.root.Object.get("array").?.Array.items[0].Null == {});
+ try testing.expect(tree.root.Object.get("array").?.Array.items[1].Float == 12.34);
+ try testing.expect(mem.eql(u8, tree.root.Object.get("str").?.String, "hello"));
}
fn test_parse(arena_allocator: *std.mem.Allocator, json_str: []const u8) !Value {
@@ -2404,7 +2404,7 @@ fn test_parse(arena_allocator: *std.mem.Allocator, json_str: []const u8) !Value
test "parsing empty string gives appropriate error" {
var arena_allocator = std.heap.ArenaAllocator.init(std.testing.allocator);
defer arena_allocator.deinit();
- testing.expectError(error.UnexpectedEndOfJson, test_parse(&arena_allocator.allocator, ""));
+ try testing.expectError(error.UnexpectedEndOfJson, test_parse(&arena_allocator.allocator, ""));
}
test "integer after float has proper type" {
@@ -2416,7 +2416,7 @@ test "integer after float has proper type" {
\\ "ints": [1, 2, 3]
\\}
);
- std.testing.expect(json.Object.get("ints").?.Array.items[0] == .Integer);
+ try std.testing.expect(json.Object.get("ints").?.Array.items[0] == .Integer);
}
test "escaped characters" {
@@ -2439,16 +2439,16 @@ test "escaped characters" {
const obj = (try test_parse(&arena_allocator.allocator, input)).Object;
- testing.expectEqualSlices(u8, obj.get("backslash").?.String, "\\");
- testing.expectEqualSlices(u8, obj.get("forwardslash").?.String, "/");
- testing.expectEqualSlices(u8, obj.get("newline").?.String, "\n");
- testing.expectEqualSlices(u8, obj.get("carriagereturn").?.String, "\r");
- testing.expectEqualSlices(u8, obj.get("tab").?.String, "\t");
- testing.expectEqualSlices(u8, obj.get("formfeed").?.String, "\x0C");
- testing.expectEqualSlices(u8, obj.get("backspace").?.String, "\x08");
- testing.expectEqualSlices(u8, obj.get("doublequote").?.String, "\"");
- testing.expectEqualSlices(u8, obj.get("unicode").?.String, "ą");
- testing.expectEqualSlices(u8, obj.get("surrogatepair").?.String, "😂");
+ try testing.expectEqualSlices(u8, obj.get("backslash").?.String, "\\");
+ try testing.expectEqualSlices(u8, obj.get("forwardslash").?.String, "/");
+ try testing.expectEqualSlices(u8, obj.get("newline").?.String, "\n");
+ try testing.expectEqualSlices(u8, obj.get("carriagereturn").?.String, "\r");
+ try testing.expectEqualSlices(u8, obj.get("tab").?.String, "\t");
+ try testing.expectEqualSlices(u8, obj.get("formfeed").?.String, "\x0C");
+ try testing.expectEqualSlices(u8, obj.get("backspace").?.String, "\x08");
+ try testing.expectEqualSlices(u8, obj.get("doublequote").?.String, "\"");
+ try testing.expectEqualSlices(u8, obj.get("unicode").?.String, "ą");
+ try testing.expectEqualSlices(u8, obj.get("surrogatepair").?.String, "😂");
}
test "string copy option" {
@@ -2471,7 +2471,7 @@ test "string copy option" {
const obj_copy = tree_copy.root.Object;
for ([_][]const u8{ "noescape", "simple", "unicode", "surrogatepair" }) |field_name| {
- testing.expectEqualSlices(u8, obj_nocopy.get(field_name).?.String, obj_copy.get(field_name).?.String);
+ try testing.expectEqualSlices(u8, obj_nocopy.get(field_name).?.String, obj_copy.get(field_name).?.String);
}
const nocopy_addr = &obj_nocopy.get("noescape").?.String[0];
@@ -2479,12 +2479,12 @@ test "string copy option" {
var found_nocopy = false;
for (input) |_, index| {
- testing.expect(copy_addr != &input[index]);
+ try testing.expect(copy_addr != &input[index]);
if (nocopy_addr == &input[index]) {
found_nocopy = true;
}
}
- testing.expect(found_nocopy);
+ try testing.expect(found_nocopy);
}
pub const StringifyOptions = struct {
lib/std/leb128.zig
@@ -152,22 +152,22 @@ test "writeUnsignedFixed" {
{
var buf: [4]u8 = undefined;
writeUnsignedFixed(4, &buf, 0);
- testing.expect((try test_read_uleb128(u64, &buf)) == 0);
+ try testing.expect((try test_read_uleb128(u64, &buf)) == 0);
}
{
var buf: [4]u8 = undefined;
writeUnsignedFixed(4, &buf, 1);
- testing.expect((try test_read_uleb128(u64, &buf)) == 1);
+ try testing.expect((try test_read_uleb128(u64, &buf)) == 1);
}
{
var buf: [4]u8 = undefined;
writeUnsignedFixed(4, &buf, 1000);
- testing.expect((try test_read_uleb128(u64, &buf)) == 1000);
+ try testing.expect((try test_read_uleb128(u64, &buf)) == 1000);
}
{
var buf: [4]u8 = undefined;
writeUnsignedFixed(4, &buf, 10000000);
- testing.expect((try test_read_uleb128(u64, &buf)) == 10000000);
+ try testing.expect((try test_read_uleb128(u64, &buf)) == 10000000);
}
}
@@ -212,44 +212,44 @@ fn test_read_uleb128_seq(comptime T: type, comptime N: usize, encoded: []const u
test "deserialize signed LEB128" {
// Truncated
- testing.expectError(error.EndOfStream, test_read_stream_ileb128(i64, "\x80"));
+ try testing.expectError(error.EndOfStream, test_read_stream_ileb128(i64, "\x80"));
// Overflow
- testing.expectError(error.Overflow, test_read_ileb128(i8, "\x80\x80\x40"));
- testing.expectError(error.Overflow, test_read_ileb128(i16, "\x80\x80\x80\x40"));
- testing.expectError(error.Overflow, test_read_ileb128(i32, "\x80\x80\x80\x80\x40"));
- testing.expectError(error.Overflow, test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x40"));
- testing.expectError(error.Overflow, test_read_ileb128(i8, "\xff\x7e"));
+ try testing.expectError(error.Overflow, test_read_ileb128(i8, "\x80\x80\x40"));
+ try testing.expectError(error.Overflow, test_read_ileb128(i16, "\x80\x80\x80\x40"));
+ try testing.expectError(error.Overflow, test_read_ileb128(i32, "\x80\x80\x80\x80\x40"));
+ try testing.expectError(error.Overflow, test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x40"));
+ try testing.expectError(error.Overflow, test_read_ileb128(i8, "\xff\x7e"));
// Decode SLEB128
- testing.expect((try test_read_ileb128(i64, "\x00")) == 0);
- testing.expect((try test_read_ileb128(i64, "\x01")) == 1);
- testing.expect((try test_read_ileb128(i64, "\x3f")) == 63);
- testing.expect((try test_read_ileb128(i64, "\x40")) == -64);
- testing.expect((try test_read_ileb128(i64, "\x41")) == -63);
- testing.expect((try test_read_ileb128(i64, "\x7f")) == -1);
- testing.expect((try test_read_ileb128(i64, "\x80\x01")) == 128);
- testing.expect((try test_read_ileb128(i64, "\x81\x01")) == 129);
- testing.expect((try test_read_ileb128(i64, "\xff\x7e")) == -129);
- testing.expect((try test_read_ileb128(i64, "\x80\x7f")) == -128);
- testing.expect((try test_read_ileb128(i64, "\x81\x7f")) == -127);
- testing.expect((try test_read_ileb128(i64, "\xc0\x00")) == 64);
- testing.expect((try test_read_ileb128(i64, "\xc7\x9f\x7f")) == -12345);
- testing.expect((try test_read_ileb128(i8, "\xff\x7f")) == -1);
- testing.expect((try test_read_ileb128(i16, "\xff\xff\x7f")) == -1);
- testing.expect((try test_read_ileb128(i32, "\xff\xff\xff\xff\x7f")) == -1);
- testing.expect((try test_read_ileb128(i32, "\x80\x80\x80\x80\x08")) == -0x80000000);
- testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01")) == @bitCast(i64, @intCast(u64, 0x8000000000000000)));
- testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x40")) == -0x4000000000000000);
- testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x7f")) == -0x8000000000000000);
+ try testing.expect((try test_read_ileb128(i64, "\x00")) == 0);
+ try testing.expect((try test_read_ileb128(i64, "\x01")) == 1);
+ try testing.expect((try test_read_ileb128(i64, "\x3f")) == 63);
+ try testing.expect((try test_read_ileb128(i64, "\x40")) == -64);
+ try testing.expect((try test_read_ileb128(i64, "\x41")) == -63);
+ try testing.expect((try test_read_ileb128(i64, "\x7f")) == -1);
+ try testing.expect((try test_read_ileb128(i64, "\x80\x01")) == 128);
+ try testing.expect((try test_read_ileb128(i64, "\x81\x01")) == 129);
+ try testing.expect((try test_read_ileb128(i64, "\xff\x7e")) == -129);
+ try testing.expect((try test_read_ileb128(i64, "\x80\x7f")) == -128);
+ try testing.expect((try test_read_ileb128(i64, "\x81\x7f")) == -127);
+ try testing.expect((try test_read_ileb128(i64, "\xc0\x00")) == 64);
+ try testing.expect((try test_read_ileb128(i64, "\xc7\x9f\x7f")) == -12345);
+ try testing.expect((try test_read_ileb128(i8, "\xff\x7f")) == -1);
+ try testing.expect((try test_read_ileb128(i16, "\xff\xff\x7f")) == -1);
+ try testing.expect((try test_read_ileb128(i32, "\xff\xff\xff\xff\x7f")) == -1);
+ try testing.expect((try test_read_ileb128(i32, "\x80\x80\x80\x80\x08")) == -0x80000000);
+ try testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01")) == @bitCast(i64, @intCast(u64, 0x8000000000000000)));
+ try testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x40")) == -0x4000000000000000);
+ try testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x7f")) == -0x8000000000000000);
// Decode unnormalized SLEB128 with extra padding bytes.
- testing.expect((try test_read_ileb128(i64, "\x80\x00")) == 0);
- testing.expect((try test_read_ileb128(i64, "\x80\x80\x00")) == 0);
- testing.expect((try test_read_ileb128(i64, "\xff\x00")) == 0x7f);
- testing.expect((try test_read_ileb128(i64, "\xff\x80\x00")) == 0x7f);
- testing.expect((try test_read_ileb128(i64, "\x80\x81\x00")) == 0x80);
- testing.expect((try test_read_ileb128(i64, "\x80\x81\x80\x00")) == 0x80);
+ try testing.expect((try test_read_ileb128(i64, "\x80\x00")) == 0);
+ try testing.expect((try test_read_ileb128(i64, "\x80\x80\x00")) == 0);
+ try testing.expect((try test_read_ileb128(i64, "\xff\x00")) == 0x7f);
+ try testing.expect((try test_read_ileb128(i64, "\xff\x80\x00")) == 0x7f);
+ try testing.expect((try test_read_ileb128(i64, "\x80\x81\x00")) == 0x80);
+ try testing.expect((try test_read_ileb128(i64, "\x80\x81\x80\x00")) == 0x80);
// Decode sequence of SLEB128 values
try test_read_ileb128_seq(i64, 4, "\x81\x01\x3f\x80\x7f\x80\x80\x80\x00");
@@ -257,39 +257,39 @@ test "deserialize signed LEB128" {
test "deserialize unsigned LEB128" {
// Truncated
- testing.expectError(error.EndOfStream, test_read_stream_uleb128(u64, "\x80"));
+ try testing.expectError(error.EndOfStream, test_read_stream_uleb128(u64, "\x80"));
// Overflow
- testing.expectError(error.Overflow, test_read_uleb128(u8, "\x80\x02"));
- testing.expectError(error.Overflow, test_read_uleb128(u8, "\x80\x80\x40"));
- testing.expectError(error.Overflow, test_read_uleb128(u16, "\x80\x80\x84"));
- testing.expectError(error.Overflow, test_read_uleb128(u16, "\x80\x80\x80\x40"));
- testing.expectError(error.Overflow, test_read_uleb128(u32, "\x80\x80\x80\x80\x90"));
- testing.expectError(error.Overflow, test_read_uleb128(u32, "\x80\x80\x80\x80\x40"));
- testing.expectError(error.Overflow, test_read_uleb128(u64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x40"));
+ try testing.expectError(error.Overflow, test_read_uleb128(u8, "\x80\x02"));
+ try testing.expectError(error.Overflow, test_read_uleb128(u8, "\x80\x80\x40"));
+ try testing.expectError(error.Overflow, test_read_uleb128(u16, "\x80\x80\x84"));
+ try testing.expectError(error.Overflow, test_read_uleb128(u16, "\x80\x80\x80\x40"));
+ try testing.expectError(error.Overflow, test_read_uleb128(u32, "\x80\x80\x80\x80\x90"));
+ try testing.expectError(error.Overflow, test_read_uleb128(u32, "\x80\x80\x80\x80\x40"));
+ try testing.expectError(error.Overflow, test_read_uleb128(u64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x40"));
// Decode ULEB128
- testing.expect((try test_read_uleb128(u64, "\x00")) == 0);
- testing.expect((try test_read_uleb128(u64, "\x01")) == 1);
- testing.expect((try test_read_uleb128(u64, "\x3f")) == 63);
- testing.expect((try test_read_uleb128(u64, "\x40")) == 64);
- testing.expect((try test_read_uleb128(u64, "\x7f")) == 0x7f);
- testing.expect((try test_read_uleb128(u64, "\x80\x01")) == 0x80);
- testing.expect((try test_read_uleb128(u64, "\x81\x01")) == 0x81);
- testing.expect((try test_read_uleb128(u64, "\x90\x01")) == 0x90);
- testing.expect((try test_read_uleb128(u64, "\xff\x01")) == 0xff);
- testing.expect((try test_read_uleb128(u64, "\x80\x02")) == 0x100);
- testing.expect((try test_read_uleb128(u64, "\x81\x02")) == 0x101);
- testing.expect((try test_read_uleb128(u64, "\x80\xc1\x80\x80\x10")) == 4294975616);
- testing.expect((try test_read_uleb128(u64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01")) == 0x8000000000000000);
+ try testing.expect((try test_read_uleb128(u64, "\x00")) == 0);
+ try testing.expect((try test_read_uleb128(u64, "\x01")) == 1);
+ try testing.expect((try test_read_uleb128(u64, "\x3f")) == 63);
+ try testing.expect((try test_read_uleb128(u64, "\x40")) == 64);
+ try testing.expect((try test_read_uleb128(u64, "\x7f")) == 0x7f);
+ try testing.expect((try test_read_uleb128(u64, "\x80\x01")) == 0x80);
+ try testing.expect((try test_read_uleb128(u64, "\x81\x01")) == 0x81);
+ try testing.expect((try test_read_uleb128(u64, "\x90\x01")) == 0x90);
+ try testing.expect((try test_read_uleb128(u64, "\xff\x01")) == 0xff);
+ try testing.expect((try test_read_uleb128(u64, "\x80\x02")) == 0x100);
+ try testing.expect((try test_read_uleb128(u64, "\x81\x02")) == 0x101);
+ try testing.expect((try test_read_uleb128(u64, "\x80\xc1\x80\x80\x10")) == 4294975616);
+ try testing.expect((try test_read_uleb128(u64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01")) == 0x8000000000000000);
// Decode ULEB128 with extra padding bytes
- testing.expect((try test_read_uleb128(u64, "\x80\x00")) == 0);
- testing.expect((try test_read_uleb128(u64, "\x80\x80\x00")) == 0);
- testing.expect((try test_read_uleb128(u64, "\xff\x00")) == 0x7f);
- testing.expect((try test_read_uleb128(u64, "\xff\x80\x00")) == 0x7f);
- testing.expect((try test_read_uleb128(u64, "\x80\x81\x00")) == 0x80);
- testing.expect((try test_read_uleb128(u64, "\x80\x81\x80\x00")) == 0x80);
+ try testing.expect((try test_read_uleb128(u64, "\x80\x00")) == 0);
+ try testing.expect((try test_read_uleb128(u64, "\x80\x80\x00")) == 0);
+ try testing.expect((try test_read_uleb128(u64, "\xff\x00")) == 0x7f);
+ try testing.expect((try test_read_uleb128(u64, "\xff\x80\x00")) == 0x7f);
+ try testing.expect((try test_read_uleb128(u64, "\x80\x81\x00")) == 0x80);
+ try testing.expect((try test_read_uleb128(u64, "\x80\x81\x80\x00")) == 0x80);
// Decode sequence of ULEB128 values
try test_read_uleb128_seq(u64, 4, "\x81\x01\x3f\x80\x7f\x80\x80\x80\x00");
@@ -326,19 +326,19 @@ fn test_write_leb128(value: anytype) !void {
// stream write
try writeStream(fbs.writer(), value);
const w1_pos = fbs.pos;
- testing.expect(w1_pos == bytes_needed);
+ try testing.expect(w1_pos == bytes_needed);
// stream read
fbs.pos = 0;
const sr = try readStream(T, fbs.reader());
- testing.expect(fbs.pos == w1_pos);
- testing.expect(sr == value);
+ try testing.expect(fbs.pos == w1_pos);
+ try testing.expect(sr == value);
// bigger type stream read
fbs.pos = 0;
const bsr = try readStream(B, fbs.reader());
- testing.expect(fbs.pos == w1_pos);
- testing.expect(bsr == value);
+ try testing.expect(fbs.pos == w1_pos);
+ try testing.expect(bsr == value);
}
test "serialize unsigned LEB128" {
lib/std/linked_list.zig
@@ -123,7 +123,7 @@ test "basic SinglyLinkedList test" {
const L = SinglyLinkedList(u32);
var list = L{};
- testing.expect(list.len() == 0);
+ try testing.expect(list.len() == 0);
var one = L.Node{ .data = 1 };
var two = L.Node{ .data = 2 };
@@ -137,14 +137,14 @@ test "basic SinglyLinkedList test" {
two.insertAfter(&three); // {1, 2, 3, 5}
three.insertAfter(&four); // {1, 2, 3, 4, 5}
- testing.expect(list.len() == 5);
+ try testing.expect(list.len() == 5);
// Traverse forwards.
{
var it = list.first;
var index: u32 = 1;
while (it) |node| : (it = node.next) {
- testing.expect(node.data == index);
+ try testing.expect(node.data == index);
index += 1;
}
}
@@ -153,9 +153,9 @@ test "basic SinglyLinkedList test" {
_ = list.remove(&five); // {2, 3, 4}
_ = two.removeNext(); // {2, 4}
- testing.expect(list.first.?.data == 2);
- testing.expect(list.first.?.next.?.data == 4);
- testing.expect(list.first.?.next.?.next == null);
+ try testing.expect(list.first.?.data == 2);
+ try testing.expect(list.first.?.next.?.data == 4);
+ try testing.expect(list.first.?.next.?.next == null);
}
/// A tail queue is headed by a pair of pointers, one to the head of the
@@ -344,7 +344,7 @@ test "basic TailQueue test" {
var it = list.first;
var index: u32 = 1;
while (it) |node| : (it = node.next) {
- testing.expect(node.data == index);
+ try testing.expect(node.data == index);
index += 1;
}
}
@@ -354,7 +354,7 @@ test "basic TailQueue test" {
var it = list.last;
var index: u32 = 1;
while (it) |node| : (it = node.prev) {
- testing.expect(node.data == (6 - index));
+ try testing.expect(node.data == (6 - index));
index += 1;
}
}
@@ -363,9 +363,9 @@ test "basic TailQueue test" {
var last = list.pop(); // {2, 3, 4}
list.remove(&three); // {2, 4}
- testing.expect(list.first.?.data == 2);
- testing.expect(list.last.?.data == 4);
- testing.expect(list.len == 2);
+ try testing.expect(list.first.?.data == 2);
+ try testing.expect(list.last.?.data == 4);
+ try testing.expect(list.len == 2);
}
test "TailQueue concatenation" {
@@ -387,18 +387,18 @@ test "TailQueue concatenation" {
list1.concatByMoving(&list2);
- testing.expect(list1.last == &five);
- testing.expect(list1.len == 5);
- testing.expect(list2.first == null);
- testing.expect(list2.last == null);
- testing.expect(list2.len == 0);
+ try testing.expect(list1.last == &five);
+ try testing.expect(list1.len == 5);
+ try testing.expect(list2.first == null);
+ try testing.expect(list2.last == null);
+ try testing.expect(list2.len == 0);
// Traverse forwards.
{
var it = list1.first;
var index: u32 = 1;
while (it) |node| : (it = node.next) {
- testing.expect(node.data == index);
+ try testing.expect(node.data == index);
index += 1;
}
}
@@ -408,7 +408,7 @@ test "TailQueue concatenation" {
var it = list1.last;
var index: u32 = 1;
while (it) |node| : (it = node.prev) {
- testing.expect(node.data == (6 - index));
+ try testing.expect(node.data == (6 - index));
index += 1;
}
}
@@ -421,7 +421,7 @@ test "TailQueue concatenation" {
var it = list2.first;
var index: u32 = 1;
while (it) |node| : (it = node.next) {
- testing.expect(node.data == index);
+ try testing.expect(node.data == index);
index += 1;
}
}
@@ -431,7 +431,7 @@ test "TailQueue concatenation" {
var it = list2.last;
var index: u32 = 1;
while (it) |node| : (it = node.prev) {
- testing.expect(node.data == (6 - index));
+ try testing.expect(node.data == (6 - index));
index += 1;
}
}
lib/std/math.zig
@@ -177,20 +177,20 @@ test "approxEqAbs and approxEqRel" {
else => unreachable,
};
- testing.expect(approxEqAbs(T, 0.0, 0.0, eps_value));
- testing.expect(approxEqAbs(T, -0.0, -0.0, eps_value));
- testing.expect(approxEqAbs(T, 0.0, -0.0, eps_value));
- testing.expect(approxEqRel(T, 1.0, 1.0, sqrt_eps_value));
- testing.expect(!approxEqRel(T, 1.0, 0.0, sqrt_eps_value));
- testing.expect(!approxEqAbs(T, 1.0 + 2 * epsilon(T), 1.0, eps_value));
- testing.expect(approxEqAbs(T, 1.0 + 1 * epsilon(T), 1.0, eps_value));
- testing.expect(!approxEqRel(T, 1.0, nan_value, sqrt_eps_value));
- testing.expect(!approxEqRel(T, nan_value, nan_value, sqrt_eps_value));
- testing.expect(approxEqRel(T, inf_value, inf_value, sqrt_eps_value));
- testing.expect(approxEqRel(T, min_value, min_value, sqrt_eps_value));
- testing.expect(approxEqRel(T, -min_value, -min_value, sqrt_eps_value));
- testing.expect(approxEqAbs(T, min_value, 0.0, eps_value * 2));
- testing.expect(approxEqAbs(T, -min_value, 0.0, eps_value * 2));
+ try testing.expect(approxEqAbs(T, 0.0, 0.0, eps_value));
+ try testing.expect(approxEqAbs(T, -0.0, -0.0, eps_value));
+ try testing.expect(approxEqAbs(T, 0.0, -0.0, eps_value));
+ try testing.expect(approxEqRel(T, 1.0, 1.0, sqrt_eps_value));
+ try testing.expect(!approxEqRel(T, 1.0, 0.0, sqrt_eps_value));
+ try testing.expect(!approxEqAbs(T, 1.0 + 2 * epsilon(T), 1.0, eps_value));
+ try testing.expect(approxEqAbs(T, 1.0 + 1 * epsilon(T), 1.0, eps_value));
+ try testing.expect(!approxEqRel(T, 1.0, nan_value, sqrt_eps_value));
+ try testing.expect(!approxEqRel(T, nan_value, nan_value, sqrt_eps_value));
+ try testing.expect(approxEqRel(T, inf_value, inf_value, sqrt_eps_value));
+ try testing.expect(approxEqRel(T, min_value, min_value, sqrt_eps_value));
+ try testing.expect(approxEqRel(T, -min_value, -min_value, sqrt_eps_value));
+ try testing.expect(approxEqAbs(T, min_value, 0.0, eps_value * 2));
+ try testing.expect(approxEqAbs(T, -min_value, 0.0, eps_value * 2));
}
}
@@ -349,34 +349,34 @@ pub fn min(x: anytype, y: anytype) Min(@TypeOf(x), @TypeOf(y)) {
}
test "math.min" {
- testing.expect(min(@as(i32, -1), @as(i32, 2)) == -1);
+ try testing.expect(min(@as(i32, -1), @as(i32, 2)) == -1);
{
var a: u16 = 999;
var b: u32 = 10;
var result = min(a, b);
- testing.expect(@TypeOf(result) == u16);
- testing.expect(result == 10);
+ try testing.expect(@TypeOf(result) == u16);
+ try testing.expect(result == 10);
}
{
var a: f64 = 10.34;
var b: f32 = 999.12;
var result = min(a, b);
- testing.expect(@TypeOf(result) == f64);
- testing.expect(result == 10.34);
+ try testing.expect(@TypeOf(result) == f64);
+ try testing.expect(result == 10.34);
}
{
var a: i8 = -127;
var b: i16 = -200;
var result = min(a, b);
- testing.expect(@TypeOf(result) == i16);
- testing.expect(result == -200);
+ try testing.expect(@TypeOf(result) == i16);
+ try testing.expect(result == -200);
}
{
const a = 10.34;
var b: f32 = 999.12;
var result = min(a, b);
- testing.expect(@TypeOf(result) == f32);
- testing.expect(result == 10.34);
+ try testing.expect(@TypeOf(result) == f32);
+ try testing.expect(result == 10.34);
}
}
@@ -385,7 +385,7 @@ pub fn max(x: anytype, y: anytype) @TypeOf(x, y) {
}
test "math.max" {
- testing.expect(max(@as(i32, -1), @as(i32, 2)) == 2);
+ try testing.expect(max(@as(i32, -1), @as(i32, 2)) == 2);
}
pub fn clamp(val: anytype, lower: anytype, upper: anytype) @TypeOf(val, lower, upper) {
@@ -394,19 +394,19 @@ pub fn clamp(val: anytype, lower: anytype, upper: anytype) @TypeOf(val, lower, u
}
test "math.clamp" {
// Within range
- testing.expect(std.math.clamp(@as(i32, -1), @as(i32, -4), @as(i32, 7)) == -1);
+ try testing.expect(std.math.clamp(@as(i32, -1), @as(i32, -4), @as(i32, 7)) == -1);
// Below
- testing.expect(std.math.clamp(@as(i32, -5), @as(i32, -4), @as(i32, 7)) == -4);
+ try testing.expect(std.math.clamp(@as(i32, -5), @as(i32, -4), @as(i32, 7)) == -4);
// Above
- testing.expect(std.math.clamp(@as(i32, 8), @as(i32, -4), @as(i32, 7)) == 7);
+ try testing.expect(std.math.clamp(@as(i32, 8), @as(i32, -4), @as(i32, 7)) == 7);
// Floating point
- testing.expect(std.math.clamp(@as(f32, 1.1), @as(f32, 0.0), @as(f32, 1.0)) == 1.0);
- testing.expect(std.math.clamp(@as(f32, -127.5), @as(f32, -200), @as(f32, -100)) == -127.5);
+ try testing.expect(std.math.clamp(@as(f32, 1.1), @as(f32, 0.0), @as(f32, 1.0)) == 1.0);
+ try testing.expect(std.math.clamp(@as(f32, -127.5), @as(f32, -200), @as(f32, -100)) == -127.5);
// Mix of comptime and non-comptime
var i: i32 = 1;
- testing.expect(std.math.clamp(i, 0, 1) == 1);
+ try testing.expect(std.math.clamp(i, 0, 1) == 1);
}
pub fn mul(comptime T: type, a: T, b: T) (error{Overflow}!T) {
@@ -461,17 +461,17 @@ pub fn shl(comptime T: type, a: T, shift_amt: anytype) T {
}
test "math.shl" {
- testing.expect(shl(u8, 0b11111111, @as(usize, 3)) == 0b11111000);
- testing.expect(shl(u8, 0b11111111, @as(usize, 8)) == 0);
- testing.expect(shl(u8, 0b11111111, @as(usize, 9)) == 0);
- testing.expect(shl(u8, 0b11111111, @as(isize, -2)) == 0b00111111);
- testing.expect(shl(u8, 0b11111111, 3) == 0b11111000);
- testing.expect(shl(u8, 0b11111111, 8) == 0);
- testing.expect(shl(u8, 0b11111111, 9) == 0);
- testing.expect(shl(u8, 0b11111111, -2) == 0b00111111);
- testing.expect(shl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, @as(usize, 1))[0] == @as(u32, 42) << 1);
- testing.expect(shl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, @as(isize, -1))[0] == @as(u32, 42) >> 1);
- testing.expect(shl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, 33)[0] == 0);
+ try testing.expect(shl(u8, 0b11111111, @as(usize, 3)) == 0b11111000);
+ try testing.expect(shl(u8, 0b11111111, @as(usize, 8)) == 0);
+ try testing.expect(shl(u8, 0b11111111, @as(usize, 9)) == 0);
+ try testing.expect(shl(u8, 0b11111111, @as(isize, -2)) == 0b00111111);
+ try testing.expect(shl(u8, 0b11111111, 3) == 0b11111000);
+ try testing.expect(shl(u8, 0b11111111, 8) == 0);
+ try testing.expect(shl(u8, 0b11111111, 9) == 0);
+ try testing.expect(shl(u8, 0b11111111, -2) == 0b00111111);
+ try testing.expect(shl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, @as(usize, 1))[0] == @as(u32, 42) << 1);
+ try testing.expect(shl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, @as(isize, -1))[0] == @as(u32, 42) >> 1);
+ try testing.expect(shl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, 33)[0] == 0);
}
/// Shifts right. Overflowed bits are truncated.
@@ -501,17 +501,17 @@ pub fn shr(comptime T: type, a: T, shift_amt: anytype) T {
}
test "math.shr" {
- testing.expect(shr(u8, 0b11111111, @as(usize, 3)) == 0b00011111);
- testing.expect(shr(u8, 0b11111111, @as(usize, 8)) == 0);
- testing.expect(shr(u8, 0b11111111, @as(usize, 9)) == 0);
- testing.expect(shr(u8, 0b11111111, @as(isize, -2)) == 0b11111100);
- testing.expect(shr(u8, 0b11111111, 3) == 0b00011111);
- testing.expect(shr(u8, 0b11111111, 8) == 0);
- testing.expect(shr(u8, 0b11111111, 9) == 0);
- testing.expect(shr(u8, 0b11111111, -2) == 0b11111100);
- testing.expect(shr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, @as(usize, 1))[0] == @as(u32, 42) >> 1);
- testing.expect(shr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, @as(isize, -1))[0] == @as(u32, 42) << 1);
- testing.expect(shr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, 33)[0] == 0);
+ try testing.expect(shr(u8, 0b11111111, @as(usize, 3)) == 0b00011111);
+ try testing.expect(shr(u8, 0b11111111, @as(usize, 8)) == 0);
+ try testing.expect(shr(u8, 0b11111111, @as(usize, 9)) == 0);
+ try testing.expect(shr(u8, 0b11111111, @as(isize, -2)) == 0b11111100);
+ try testing.expect(shr(u8, 0b11111111, 3) == 0b00011111);
+ try testing.expect(shr(u8, 0b11111111, 8) == 0);
+ try testing.expect(shr(u8, 0b11111111, 9) == 0);
+ try testing.expect(shr(u8, 0b11111111, -2) == 0b11111100);
+ try testing.expect(shr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, @as(usize, 1))[0] == @as(u32, 42) >> 1);
+ try testing.expect(shr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, @as(isize, -1))[0] == @as(u32, 42) << 1);
+ try testing.expect(shr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, 33)[0] == 0);
}
/// Rotates right. Only unsigned values can be rotated.
@@ -533,13 +533,13 @@ pub fn rotr(comptime T: type, x: T, r: anytype) T {
}
test "math.rotr" {
- testing.expect(rotr(u8, 0b00000001, @as(usize, 0)) == 0b00000001);
- testing.expect(rotr(u8, 0b00000001, @as(usize, 9)) == 0b10000000);
- testing.expect(rotr(u8, 0b00000001, @as(usize, 8)) == 0b00000001);
- testing.expect(rotr(u8, 0b00000001, @as(usize, 4)) == 0b00010000);
- testing.expect(rotr(u8, 0b00000001, @as(isize, -1)) == 0b00000010);
- testing.expect(rotr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){1}, @as(usize, 1))[0] == @as(u32, 1) << 31);
- testing.expect(rotr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){1}, @as(isize, -1))[0] == @as(u32, 1) << 1);
+ try testing.expect(rotr(u8, 0b00000001, @as(usize, 0)) == 0b00000001);
+ try testing.expect(rotr(u8, 0b00000001, @as(usize, 9)) == 0b10000000);
+ try testing.expect(rotr(u8, 0b00000001, @as(usize, 8)) == 0b00000001);
+ try testing.expect(rotr(u8, 0b00000001, @as(usize, 4)) == 0b00010000);
+ try testing.expect(rotr(u8, 0b00000001, @as(isize, -1)) == 0b00000010);
+ try testing.expect(rotr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){1}, @as(usize, 1))[0] == @as(u32, 1) << 31);
+ try testing.expect(rotr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){1}, @as(isize, -1))[0] == @as(u32, 1) << 1);
}
/// Rotates left. Only unsigned values can be rotated.
@@ -561,13 +561,13 @@ pub fn rotl(comptime T: type, x: T, r: anytype) T {
}
test "math.rotl" {
- testing.expect(rotl(u8, 0b00000001, @as(usize, 0)) == 0b00000001);
- testing.expect(rotl(u8, 0b00000001, @as(usize, 9)) == 0b00000010);
- testing.expect(rotl(u8, 0b00000001, @as(usize, 8)) == 0b00000001);
- testing.expect(rotl(u8, 0b00000001, @as(usize, 4)) == 0b00010000);
- testing.expect(rotl(u8, 0b00000001, @as(isize, -1)) == 0b10000000);
- testing.expect(rotl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){1 << 31}, @as(usize, 1))[0] == 1);
- testing.expect(rotl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){1 << 31}, @as(isize, -1))[0] == @as(u32, 1) << 30);
+ try testing.expect(rotl(u8, 0b00000001, @as(usize, 0)) == 0b00000001);
+ try testing.expect(rotl(u8, 0b00000001, @as(usize, 9)) == 0b00000010);
+ try testing.expect(rotl(u8, 0b00000001, @as(usize, 8)) == 0b00000001);
+ try testing.expect(rotl(u8, 0b00000001, @as(usize, 4)) == 0b00010000);
+ try testing.expect(rotl(u8, 0b00000001, @as(isize, -1)) == 0b10000000);
+ try testing.expect(rotl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){1 << 31}, @as(usize, 1))[0] == 1);
+ try testing.expect(rotl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){1 << 31}, @as(isize, -1))[0] == @as(u32, 1) << 30);
}
pub fn Log2Int(comptime T: type) type {
@@ -598,62 +598,62 @@ pub fn IntFittingRange(comptime from: comptime_int, comptime to: comptime_int) t
}
test "math.IntFittingRange" {
- testing.expect(IntFittingRange(0, 0) == u0);
- testing.expect(IntFittingRange(0, 1) == u1);
- testing.expect(IntFittingRange(0, 2) == u2);
- testing.expect(IntFittingRange(0, 3) == u2);
- testing.expect(IntFittingRange(0, 4) == u3);
- testing.expect(IntFittingRange(0, 7) == u3);
- testing.expect(IntFittingRange(0, 8) == u4);
- testing.expect(IntFittingRange(0, 9) == u4);
- testing.expect(IntFittingRange(0, 15) == u4);
- testing.expect(IntFittingRange(0, 16) == u5);
- testing.expect(IntFittingRange(0, 17) == u5);
- testing.expect(IntFittingRange(0, 4095) == u12);
- testing.expect(IntFittingRange(2000, 4095) == u12);
- testing.expect(IntFittingRange(0, 4096) == u13);
- testing.expect(IntFittingRange(2000, 4096) == u13);
- testing.expect(IntFittingRange(0, 4097) == u13);
- testing.expect(IntFittingRange(2000, 4097) == u13);
- testing.expect(IntFittingRange(0, 123456789123456798123456789) == u87);
- testing.expect(IntFittingRange(0, 123456789123456798123456789123456789123456798123456789) == u177);
-
- testing.expect(IntFittingRange(-1, -1) == i1);
- testing.expect(IntFittingRange(-1, 0) == i1);
- testing.expect(IntFittingRange(-1, 1) == i2);
- testing.expect(IntFittingRange(-2, -2) == i2);
- testing.expect(IntFittingRange(-2, -1) == i2);
- testing.expect(IntFittingRange(-2, 0) == i2);
- testing.expect(IntFittingRange(-2, 1) == i2);
- testing.expect(IntFittingRange(-2, 2) == i3);
- testing.expect(IntFittingRange(-1, 2) == i3);
- testing.expect(IntFittingRange(-1, 3) == i3);
- testing.expect(IntFittingRange(-1, 4) == i4);
- testing.expect(IntFittingRange(-1, 7) == i4);
- testing.expect(IntFittingRange(-1, 8) == i5);
- testing.expect(IntFittingRange(-1, 9) == i5);
- testing.expect(IntFittingRange(-1, 15) == i5);
- testing.expect(IntFittingRange(-1, 16) == i6);
- testing.expect(IntFittingRange(-1, 17) == i6);
- testing.expect(IntFittingRange(-1, 4095) == i13);
- testing.expect(IntFittingRange(-4096, 4095) == i13);
- testing.expect(IntFittingRange(-1, 4096) == i14);
- testing.expect(IntFittingRange(-4097, 4095) == i14);
- testing.expect(IntFittingRange(-1, 4097) == i14);
- testing.expect(IntFittingRange(-1, 123456789123456798123456789) == i88);
- testing.expect(IntFittingRange(-1, 123456789123456798123456789123456789123456798123456789) == i178);
+ try testing.expect(IntFittingRange(0, 0) == u0);
+ try testing.expect(IntFittingRange(0, 1) == u1);
+ try testing.expect(IntFittingRange(0, 2) == u2);
+ try testing.expect(IntFittingRange(0, 3) == u2);
+ try testing.expect(IntFittingRange(0, 4) == u3);
+ try testing.expect(IntFittingRange(0, 7) == u3);
+ try testing.expect(IntFittingRange(0, 8) == u4);
+ try testing.expect(IntFittingRange(0, 9) == u4);
+ try testing.expect(IntFittingRange(0, 15) == u4);
+ try testing.expect(IntFittingRange(0, 16) == u5);
+ try testing.expect(IntFittingRange(0, 17) == u5);
+ try testing.expect(IntFittingRange(0, 4095) == u12);
+ try testing.expect(IntFittingRange(2000, 4095) == u12);
+ try testing.expect(IntFittingRange(0, 4096) == u13);
+ try testing.expect(IntFittingRange(2000, 4096) == u13);
+ try testing.expect(IntFittingRange(0, 4097) == u13);
+ try testing.expect(IntFittingRange(2000, 4097) == u13);
+ try testing.expect(IntFittingRange(0, 123456789123456798123456789) == u87);
+ try testing.expect(IntFittingRange(0, 123456789123456798123456789123456789123456798123456789) == u177);
+
+ try testing.expect(IntFittingRange(-1, -1) == i1);
+ try testing.expect(IntFittingRange(-1, 0) == i1);
+ try testing.expect(IntFittingRange(-1, 1) == i2);
+ try testing.expect(IntFittingRange(-2, -2) == i2);
+ try testing.expect(IntFittingRange(-2, -1) == i2);
+ try testing.expect(IntFittingRange(-2, 0) == i2);
+ try testing.expect(IntFittingRange(-2, 1) == i2);
+ try testing.expect(IntFittingRange(-2, 2) == i3);
+ try testing.expect(IntFittingRange(-1, 2) == i3);
+ try testing.expect(IntFittingRange(-1, 3) == i3);
+ try testing.expect(IntFittingRange(-1, 4) == i4);
+ try testing.expect(IntFittingRange(-1, 7) == i4);
+ try testing.expect(IntFittingRange(-1, 8) == i5);
+ try testing.expect(IntFittingRange(-1, 9) == i5);
+ try testing.expect(IntFittingRange(-1, 15) == i5);
+ try testing.expect(IntFittingRange(-1, 16) == i6);
+ try testing.expect(IntFittingRange(-1, 17) == i6);
+ try testing.expect(IntFittingRange(-1, 4095) == i13);
+ try testing.expect(IntFittingRange(-4096, 4095) == i13);
+ try testing.expect(IntFittingRange(-1, 4096) == i14);
+ try testing.expect(IntFittingRange(-4097, 4095) == i14);
+ try testing.expect(IntFittingRange(-1, 4097) == i14);
+ try testing.expect(IntFittingRange(-1, 123456789123456798123456789) == i88);
+ try testing.expect(IntFittingRange(-1, 123456789123456798123456789123456789123456798123456789) == i178);
}
test "math overflow functions" {
- testOverflow();
- comptime testOverflow();
+ try testOverflow();
+ comptime try testOverflow();
}
-fn testOverflow() void {
- testing.expect((mul(i32, 3, 4) catch unreachable) == 12);
- testing.expect((add(i32, 3, 4) catch unreachable) == 7);
- testing.expect((sub(i32, 3, 4) catch unreachable) == -1);
- testing.expect((shlExact(i32, 0b11, 4) catch unreachable) == 0b110000);
+fn testOverflow() !void {
+ try testing.expect((mul(i32, 3, 4) catch unreachable) == 12);
+ try testing.expect((add(i32, 3, 4) catch unreachable) == 7);
+ try testing.expect((sub(i32, 3, 4) catch unreachable) == -1);
+ try testing.expect((shlExact(i32, 0b11, 4) catch unreachable) == 0b110000);
}
pub fn absInt(x: anytype) !@TypeOf(x) {
@@ -670,23 +670,23 @@ pub fn absInt(x: anytype) !@TypeOf(x) {
}
test "math.absInt" {
- testAbsInt();
- comptime testAbsInt();
+ try testAbsInt();
+ comptime try testAbsInt();
}
-fn testAbsInt() void {
- testing.expect((absInt(@as(i32, -10)) catch unreachable) == 10);
- testing.expect((absInt(@as(i32, 10)) catch unreachable) == 10);
+fn testAbsInt() !void {
+ try testing.expect((absInt(@as(i32, -10)) catch unreachable) == 10);
+ try testing.expect((absInt(@as(i32, 10)) catch unreachable) == 10);
}
pub const absFloat = fabs;
test "math.absFloat" {
- testAbsFloat();
- comptime testAbsFloat();
+ try testAbsFloat();
+ comptime try testAbsFloat();
}
-fn testAbsFloat() void {
- testing.expect(absFloat(@as(f32, -10.05)) == 10.05);
- testing.expect(absFloat(@as(f32, 10.05)) == 10.05);
+fn testAbsFloat() !void {
+ try testing.expect(absFloat(@as(f32, -10.05)) == 10.05);
+ try testing.expect(absFloat(@as(f32, 10.05)) == 10.05);
}
pub fn divTrunc(comptime T: type, numerator: T, denominator: T) !T {
@@ -697,17 +697,17 @@ pub fn divTrunc(comptime T: type, numerator: T, denominator: T) !T {
}
test "math.divTrunc" {
- testDivTrunc();
- comptime testDivTrunc();
+ try testDivTrunc();
+ comptime try testDivTrunc();
}
-fn testDivTrunc() void {
- testing.expect((divTrunc(i32, 5, 3) catch unreachable) == 1);
- testing.expect((divTrunc(i32, -5, 3) catch unreachable) == -1);
- testing.expectError(error.DivisionByZero, divTrunc(i8, -5, 0));
- testing.expectError(error.Overflow, divTrunc(i8, -128, -1));
+fn testDivTrunc() !void {
+ try testing.expect((divTrunc(i32, 5, 3) catch unreachable) == 1);
+ try testing.expect((divTrunc(i32, -5, 3) catch unreachable) == -1);
+ try testing.expectError(error.DivisionByZero, divTrunc(i8, -5, 0));
+ try testing.expectError(error.Overflow, divTrunc(i8, -128, -1));
- testing.expect((divTrunc(f32, 5.0, 3.0) catch unreachable) == 1.0);
- testing.expect((divTrunc(f32, -5.0, 3.0) catch unreachable) == -1.0);
+ try testing.expect((divTrunc(f32, 5.0, 3.0) catch unreachable) == 1.0);
+ try testing.expect((divTrunc(f32, -5.0, 3.0) catch unreachable) == -1.0);
}
pub fn divFloor(comptime T: type, numerator: T, denominator: T) !T {
@@ -718,17 +718,17 @@ pub fn divFloor(comptime T: type, numerator: T, denominator: T) !T {
}
test "math.divFloor" {
- testDivFloor();
- comptime testDivFloor();
+ try testDivFloor();
+ comptime try testDivFloor();
}
-fn testDivFloor() void {
- testing.expect((divFloor(i32, 5, 3) catch unreachable) == 1);
- testing.expect((divFloor(i32, -5, 3) catch unreachable) == -2);
- testing.expectError(error.DivisionByZero, divFloor(i8, -5, 0));
- testing.expectError(error.Overflow, divFloor(i8, -128, -1));
+fn testDivFloor() !void {
+ try testing.expect((divFloor(i32, 5, 3) catch unreachable) == 1);
+ try testing.expect((divFloor(i32, -5, 3) catch unreachable) == -2);
+ try testing.expectError(error.DivisionByZero, divFloor(i8, -5, 0));
+ try testing.expectError(error.Overflow, divFloor(i8, -128, -1));
- testing.expect((divFloor(f32, 5.0, 3.0) catch unreachable) == 1.0);
- testing.expect((divFloor(f32, -5.0, 3.0) catch unreachable) == -2.0);
+ try testing.expect((divFloor(f32, 5.0, 3.0) catch unreachable) == 1.0);
+ try testing.expect((divFloor(f32, -5.0, 3.0) catch unreachable) == -2.0);
}
pub fn divCeil(comptime T: type, numerator: T, denominator: T) !T {
@@ -752,36 +752,36 @@ pub fn divCeil(comptime T: type, numerator: T, denominator: T) !T {
}
test "math.divCeil" {
- testDivCeil();
- comptime testDivCeil();
-}
-fn testDivCeil() void {
- testing.expectEqual(@as(i32, 2), divCeil(i32, 5, 3) catch unreachable);
- testing.expectEqual(@as(i32, -1), divCeil(i32, -5, 3) catch unreachable);
- testing.expectEqual(@as(i32, -1), divCeil(i32, 5, -3) catch unreachable);
- testing.expectEqual(@as(i32, 2), divCeil(i32, -5, -3) catch unreachable);
- testing.expectEqual(@as(i32, 0), divCeil(i32, 0, 5) catch unreachable);
- testing.expectEqual(@as(u32, 0), divCeil(u32, 0, 5) catch unreachable);
- testing.expectError(error.DivisionByZero, divCeil(i8, -5, 0));
- testing.expectError(error.Overflow, divCeil(i8, -128, -1));
-
- testing.expectEqual(@as(f32, 0.0), divCeil(f32, 0.0, 5.0) catch unreachable);
- testing.expectEqual(@as(f32, 2.0), divCeil(f32, 5.0, 3.0) catch unreachable);
- testing.expectEqual(@as(f32, -1.0), divCeil(f32, -5.0, 3.0) catch unreachable);
- testing.expectEqual(@as(f32, -1.0), divCeil(f32, 5.0, -3.0) catch unreachable);
- testing.expectEqual(@as(f32, 2.0), divCeil(f32, -5.0, -3.0) catch unreachable);
-
- testing.expectEqual(6, divCeil(comptime_int, 23, 4) catch unreachable);
- testing.expectEqual(-5, divCeil(comptime_int, -23, 4) catch unreachable);
- testing.expectEqual(-5, divCeil(comptime_int, 23, -4) catch unreachable);
- testing.expectEqual(6, divCeil(comptime_int, -23, -4) catch unreachable);
- testing.expectError(error.DivisionByZero, divCeil(comptime_int, 23, 0));
-
- testing.expectEqual(6.0, divCeil(comptime_float, 23.0, 4.0) catch unreachable);
- testing.expectEqual(-5.0, divCeil(comptime_float, -23.0, 4.0) catch unreachable);
- testing.expectEqual(-5.0, divCeil(comptime_float, 23.0, -4.0) catch unreachable);
- testing.expectEqual(6.0, divCeil(comptime_float, -23.0, -4.0) catch unreachable);
- testing.expectError(error.DivisionByZero, divCeil(comptime_float, 23.0, 0.0));
+ try testDivCeil();
+ comptime try testDivCeil();
+}
+fn testDivCeil() !void {
+ try testing.expectEqual(@as(i32, 2), divCeil(i32, 5, 3) catch unreachable);
+ try testing.expectEqual(@as(i32, -1), divCeil(i32, -5, 3) catch unreachable);
+ try testing.expectEqual(@as(i32, -1), divCeil(i32, 5, -3) catch unreachable);
+ try testing.expectEqual(@as(i32, 2), divCeil(i32, -5, -3) catch unreachable);
+ try testing.expectEqual(@as(i32, 0), divCeil(i32, 0, 5) catch unreachable);
+ try testing.expectEqual(@as(u32, 0), divCeil(u32, 0, 5) catch unreachable);
+ try testing.expectError(error.DivisionByZero, divCeil(i8, -5, 0));
+ try testing.expectError(error.Overflow, divCeil(i8, -128, -1));
+
+ try testing.expectEqual(@as(f32, 0.0), divCeil(f32, 0.0, 5.0) catch unreachable);
+ try testing.expectEqual(@as(f32, 2.0), divCeil(f32, 5.0, 3.0) catch unreachable);
+ try testing.expectEqual(@as(f32, -1.0), divCeil(f32, -5.0, 3.0) catch unreachable);
+ try testing.expectEqual(@as(f32, -1.0), divCeil(f32, 5.0, -3.0) catch unreachable);
+ try testing.expectEqual(@as(f32, 2.0), divCeil(f32, -5.0, -3.0) catch unreachable);
+
+ try testing.expectEqual(6, divCeil(comptime_int, 23, 4) catch unreachable);
+ try testing.expectEqual(-5, divCeil(comptime_int, -23, 4) catch unreachable);
+ try testing.expectEqual(-5, divCeil(comptime_int, 23, -4) catch unreachable);
+ try testing.expectEqual(6, divCeil(comptime_int, -23, -4) catch unreachable);
+ try testing.expectError(error.DivisionByZero, divCeil(comptime_int, 23, 0));
+
+ try testing.expectEqual(6.0, divCeil(comptime_float, 23.0, 4.0) catch unreachable);
+ try testing.expectEqual(-5.0, divCeil(comptime_float, -23.0, 4.0) catch unreachable);
+ try testing.expectEqual(-5.0, divCeil(comptime_float, 23.0, -4.0) catch unreachable);
+ try testing.expectEqual(6.0, divCeil(comptime_float, -23.0, -4.0) catch unreachable);
+ try testing.expectError(error.DivisionByZero, divCeil(comptime_float, 23.0, 0.0));
}
pub fn divExact(comptime T: type, numerator: T, denominator: T) !T {
@@ -794,19 +794,19 @@ pub fn divExact(comptime T: type, numerator: T, denominator: T) !T {
}
test "math.divExact" {
- testDivExact();
- comptime testDivExact();
+ try testDivExact();
+ comptime try testDivExact();
}
-fn testDivExact() void {
- testing.expect((divExact(i32, 10, 5) catch unreachable) == 2);
- testing.expect((divExact(i32, -10, 5) catch unreachable) == -2);
- testing.expectError(error.DivisionByZero, divExact(i8, -5, 0));
- testing.expectError(error.Overflow, divExact(i8, -128, -1));
- testing.expectError(error.UnexpectedRemainder, divExact(i32, 5, 2));
+fn testDivExact() !void {
+ try testing.expect((divExact(i32, 10, 5) catch unreachable) == 2);
+ try testing.expect((divExact(i32, -10, 5) catch unreachable) == -2);
+ try testing.expectError(error.DivisionByZero, divExact(i8, -5, 0));
+ try testing.expectError(error.Overflow, divExact(i8, -128, -1));
+ try testing.expectError(error.UnexpectedRemainder, divExact(i32, 5, 2));
- testing.expect((divExact(f32, 10.0, 5.0) catch unreachable) == 2.0);
- testing.expect((divExact(f32, -10.0, 5.0) catch unreachable) == -2.0);
- testing.expectError(error.UnexpectedRemainder, divExact(f32, 5.0, 2.0));
+ try testing.expect((divExact(f32, 10.0, 5.0) catch unreachable) == 2.0);
+ try testing.expect((divExact(f32, -10.0, 5.0) catch unreachable) == -2.0);
+ try testing.expectError(error.UnexpectedRemainder, divExact(f32, 5.0, 2.0));
}
pub fn mod(comptime T: type, numerator: T, denominator: T) !T {
@@ -817,19 +817,19 @@ pub fn mod(comptime T: type, numerator: T, denominator: T) !T {
}
test "math.mod" {
- testMod();
- comptime testMod();
+ try testMod();
+ comptime try testMod();
}
-fn testMod() void {
- testing.expect((mod(i32, -5, 3) catch unreachable) == 1);
- testing.expect((mod(i32, 5, 3) catch unreachable) == 2);
- testing.expectError(error.NegativeDenominator, mod(i32, 10, -1));
- testing.expectError(error.DivisionByZero, mod(i32, 10, 0));
+fn testMod() !void {
+ try testing.expect((mod(i32, -5, 3) catch unreachable) == 1);
+ try testing.expect((mod(i32, 5, 3) catch unreachable) == 2);
+ try testing.expectError(error.NegativeDenominator, mod(i32, 10, -1));
+ try testing.expectError(error.DivisionByZero, mod(i32, 10, 0));
- testing.expect((mod(f32, -5, 3) catch unreachable) == 1);
- testing.expect((mod(f32, 5, 3) catch unreachable) == 2);
- testing.expectError(error.NegativeDenominator, mod(f32, 10, -1));
- testing.expectError(error.DivisionByZero, mod(f32, 10, 0));
+ try testing.expect((mod(f32, -5, 3) catch unreachable) == 1);
+ try testing.expect((mod(f32, 5, 3) catch unreachable) == 2);
+ try testing.expectError(error.NegativeDenominator, mod(f32, 10, -1));
+ try testing.expectError(error.DivisionByZero, mod(f32, 10, 0));
}
pub fn rem(comptime T: type, numerator: T, denominator: T) !T {
@@ -840,19 +840,19 @@ pub fn rem(comptime T: type, numerator: T, denominator: T) !T {
}
test "math.rem" {
- testRem();
- comptime testRem();
+ try testRem();
+ comptime try testRem();
}
-fn testRem() void {
- testing.expect((rem(i32, -5, 3) catch unreachable) == -2);
- testing.expect((rem(i32, 5, 3) catch unreachable) == 2);
- testing.expectError(error.NegativeDenominator, rem(i32, 10, -1));
- testing.expectError(error.DivisionByZero, rem(i32, 10, 0));
+fn testRem() !void {
+ try testing.expect((rem(i32, -5, 3) catch unreachable) == -2);
+ try testing.expect((rem(i32, 5, 3) catch unreachable) == 2);
+ try testing.expectError(error.NegativeDenominator, rem(i32, 10, -1));
+ try testing.expectError(error.DivisionByZero, rem(i32, 10, 0));
- testing.expect((rem(f32, -5, 3) catch unreachable) == -2);
- testing.expect((rem(f32, 5, 3) catch unreachable) == 2);
- testing.expectError(error.NegativeDenominator, rem(f32, 10, -1));
- testing.expectError(error.DivisionByZero, rem(f32, 10, 0));
+ try testing.expect((rem(f32, -5, 3) catch unreachable) == -2);
+ try testing.expect((rem(f32, 5, 3) catch unreachable) == 2);
+ try testing.expectError(error.NegativeDenominator, rem(f32, 10, -1));
+ try testing.expectError(error.DivisionByZero, rem(f32, 10, 0));
}
/// Returns the absolute value of the integer parameter.
@@ -883,11 +883,11 @@ pub fn absCast(x: anytype) switch (@typeInfo(@TypeOf(x))) {
}
test "math.absCast" {
- testing.expectEqual(@as(u1, 1), absCast(@as(i1, -1)));
- testing.expectEqual(@as(u32, 999), absCast(@as(i32, -999)));
- testing.expectEqual(@as(u32, 999), absCast(@as(i32, 999)));
- testing.expectEqual(@as(u32, -minInt(i32)), absCast(@as(i32, minInt(i32))));
- testing.expectEqual(999, absCast(-999));
+ try testing.expectEqual(@as(u1, 1), absCast(@as(i1, -1)));
+ try testing.expectEqual(@as(u32, 999), absCast(@as(i32, -999)));
+ try testing.expectEqual(@as(u32, 999), absCast(@as(i32, 999)));
+ try testing.expectEqual(@as(u32, -minInt(i32)), absCast(@as(i32, minInt(i32))));
+ try testing.expectEqual(999, absCast(-999));
}
/// Returns the negation of the integer parameter.
@@ -904,13 +904,13 @@ pub fn negateCast(x: anytype) !std.meta.Int(.signed, std.meta.bitCount(@TypeOf(x
}
test "math.negateCast" {
- testing.expect((negateCast(@as(u32, 999)) catch unreachable) == -999);
- testing.expect(@TypeOf(negateCast(@as(u32, 999)) catch unreachable) == i32);
+ try testing.expect((negateCast(@as(u32, 999)) catch unreachable) == -999);
+ try testing.expect(@TypeOf(negateCast(@as(u32, 999)) catch unreachable) == i32);
- testing.expect((negateCast(@as(u32, -minInt(i32))) catch unreachable) == minInt(i32));
- testing.expect(@TypeOf(negateCast(@as(u32, -minInt(i32))) catch unreachable) == i32);
+ try testing.expect((negateCast(@as(u32, -minInt(i32))) catch unreachable) == minInt(i32));
+ try testing.expect(@TypeOf(negateCast(@as(u32, -minInt(i32))) catch unreachable) == i32);
- testing.expectError(error.Overflow, negateCast(@as(u32, maxInt(i32) + 10)));
+ try testing.expectError(error.Overflow, negateCast(@as(u32, maxInt(i32) + 10)));
}
/// Cast an integer to a different integer type. If the value doesn't fit,
@@ -929,13 +929,13 @@ pub fn cast(comptime T: type, x: anytype) (error{Overflow}!T) {
}
test "math.cast" {
- testing.expectError(error.Overflow, cast(u8, @as(u32, 300)));
- testing.expectError(error.Overflow, cast(i8, @as(i32, -200)));
- testing.expectError(error.Overflow, cast(u8, @as(i8, -1)));
- testing.expectError(error.Overflow, cast(u64, @as(i8, -1)));
+ try testing.expectError(error.Overflow, cast(u8, @as(u32, 300)));
+ try testing.expectError(error.Overflow, cast(i8, @as(i32, -200)));
+ try testing.expectError(error.Overflow, cast(u8, @as(i8, -1)));
+ try testing.expectError(error.Overflow, cast(u64, @as(i8, -1)));
- testing.expect((try cast(u8, @as(u32, 255))) == @as(u8, 255));
- testing.expect(@TypeOf(try cast(u8, @as(u32, 255))) == u8);
+ try testing.expect((try cast(u8, @as(u32, 255))) == @as(u8, 255));
+ try testing.expect(@TypeOf(try cast(u8, @as(u32, 255))) == u8);
}
pub const AlignCastError = error{UnalignedMemory};
@@ -966,17 +966,17 @@ pub fn floorPowerOfTwo(comptime T: type, value: T) T {
}
test "math.floorPowerOfTwo" {
- testFloorPowerOfTwo();
- comptime testFloorPowerOfTwo();
+ try testFloorPowerOfTwo();
+ comptime try testFloorPowerOfTwo();
}
-fn testFloorPowerOfTwo() void {
- testing.expect(floorPowerOfTwo(u32, 63) == 32);
- testing.expect(floorPowerOfTwo(u32, 64) == 64);
- testing.expect(floorPowerOfTwo(u32, 65) == 64);
- testing.expect(floorPowerOfTwo(u4, 7) == 4);
- testing.expect(floorPowerOfTwo(u4, 8) == 8);
- testing.expect(floorPowerOfTwo(u4, 9) == 8);
+fn testFloorPowerOfTwo() !void {
+ try testing.expect(floorPowerOfTwo(u32, 63) == 32);
+ try testing.expect(floorPowerOfTwo(u32, 64) == 64);
+ try testing.expect(floorPowerOfTwo(u32, 65) == 64);
+ try testing.expect(floorPowerOfTwo(u4, 7) == 4);
+ try testing.expect(floorPowerOfTwo(u4, 8) == 8);
+ try testing.expect(floorPowerOfTwo(u4, 9) == 8);
}
/// Returns the next power of two (if the value is not already a power of two).
@@ -1012,20 +1012,20 @@ pub fn ceilPowerOfTwoAssert(comptime T: type, value: T) T {
}
test "math.ceilPowerOfTwoPromote" {
- testCeilPowerOfTwoPromote();
- comptime testCeilPowerOfTwoPromote();
+ try testCeilPowerOfTwoPromote();
+ comptime try testCeilPowerOfTwoPromote();
}
-fn testCeilPowerOfTwoPromote() void {
- testing.expectEqual(@as(u33, 1), ceilPowerOfTwoPromote(u32, 1));
- testing.expectEqual(@as(u33, 2), ceilPowerOfTwoPromote(u32, 2));
- testing.expectEqual(@as(u33, 64), ceilPowerOfTwoPromote(u32, 63));
- testing.expectEqual(@as(u33, 64), ceilPowerOfTwoPromote(u32, 64));
- testing.expectEqual(@as(u33, 128), ceilPowerOfTwoPromote(u32, 65));
- testing.expectEqual(@as(u6, 8), ceilPowerOfTwoPromote(u5, 7));
- testing.expectEqual(@as(u6, 8), ceilPowerOfTwoPromote(u5, 8));
- testing.expectEqual(@as(u6, 16), ceilPowerOfTwoPromote(u5, 9));
- testing.expectEqual(@as(u5, 16), ceilPowerOfTwoPromote(u4, 9));
+fn testCeilPowerOfTwoPromote() !void {
+ try testing.expectEqual(@as(u33, 1), ceilPowerOfTwoPromote(u32, 1));
+ try testing.expectEqual(@as(u33, 2), ceilPowerOfTwoPromote(u32, 2));
+ try testing.expectEqual(@as(u33, 64), ceilPowerOfTwoPromote(u32, 63));
+ try testing.expectEqual(@as(u33, 64), ceilPowerOfTwoPromote(u32, 64));
+ try testing.expectEqual(@as(u33, 128), ceilPowerOfTwoPromote(u32, 65));
+ try testing.expectEqual(@as(u6, 8), ceilPowerOfTwoPromote(u5, 7));
+ try testing.expectEqual(@as(u6, 8), ceilPowerOfTwoPromote(u5, 8));
+ try testing.expectEqual(@as(u6, 16), ceilPowerOfTwoPromote(u5, 9));
+ try testing.expectEqual(@as(u5, 16), ceilPowerOfTwoPromote(u4, 9));
}
test "math.ceilPowerOfTwo" {
@@ -1034,15 +1034,15 @@ test "math.ceilPowerOfTwo" {
}
fn testCeilPowerOfTwo() !void {
- testing.expectEqual(@as(u32, 1), try ceilPowerOfTwo(u32, 1));
- testing.expectEqual(@as(u32, 2), try ceilPowerOfTwo(u32, 2));
- testing.expectEqual(@as(u32, 64), try ceilPowerOfTwo(u32, 63));
- testing.expectEqual(@as(u32, 64), try ceilPowerOfTwo(u32, 64));
- testing.expectEqual(@as(u32, 128), try ceilPowerOfTwo(u32, 65));
- testing.expectEqual(@as(u5, 8), try ceilPowerOfTwo(u5, 7));
- testing.expectEqual(@as(u5, 8), try ceilPowerOfTwo(u5, 8));
- testing.expectEqual(@as(u5, 16), try ceilPowerOfTwo(u5, 9));
- testing.expectError(error.Overflow, ceilPowerOfTwo(u4, 9));
+ try testing.expectEqual(@as(u32, 1), try ceilPowerOfTwo(u32, 1));
+ try testing.expectEqual(@as(u32, 2), try ceilPowerOfTwo(u32, 2));
+ try testing.expectEqual(@as(u32, 64), try ceilPowerOfTwo(u32, 63));
+ try testing.expectEqual(@as(u32, 64), try ceilPowerOfTwo(u32, 64));
+ try testing.expectEqual(@as(u32, 128), try ceilPowerOfTwo(u32, 65));
+ try testing.expectEqual(@as(u5, 8), try ceilPowerOfTwo(u5, 7));
+ try testing.expectEqual(@as(u5, 8), try ceilPowerOfTwo(u5, 8));
+ try testing.expectEqual(@as(u5, 16), try ceilPowerOfTwo(u5, 9));
+ try testing.expectError(error.Overflow, ceilPowerOfTwo(u4, 9));
}
pub fn log2_int(comptime T: type, x: T) Log2Int(T) {
@@ -1059,16 +1059,16 @@ pub fn log2_int_ceil(comptime T: type, x: T) Log2Int(T) {
}
test "std.math.log2_int_ceil" {
- testing.expect(log2_int_ceil(u32, 1) == 0);
- testing.expect(log2_int_ceil(u32, 2) == 1);
- testing.expect(log2_int_ceil(u32, 3) == 2);
- testing.expect(log2_int_ceil(u32, 4) == 2);
- testing.expect(log2_int_ceil(u32, 5) == 3);
- testing.expect(log2_int_ceil(u32, 6) == 3);
- testing.expect(log2_int_ceil(u32, 7) == 3);
- testing.expect(log2_int_ceil(u32, 8) == 3);
- testing.expect(log2_int_ceil(u32, 9) == 4);
- testing.expect(log2_int_ceil(u32, 10) == 4);
+ try testing.expect(log2_int_ceil(u32, 1) == 0);
+ try testing.expect(log2_int_ceil(u32, 2) == 1);
+ try testing.expect(log2_int_ceil(u32, 3) == 2);
+ try testing.expect(log2_int_ceil(u32, 4) == 2);
+ try testing.expect(log2_int_ceil(u32, 5) == 3);
+ try testing.expect(log2_int_ceil(u32, 6) == 3);
+ try testing.expect(log2_int_ceil(u32, 7) == 3);
+ try testing.expect(log2_int_ceil(u32, 8) == 3);
+ try testing.expect(log2_int_ceil(u32, 9) == 4);
+ try testing.expect(log2_int_ceil(u32, 10) == 4);
}
///Cast a value to a different type. If the value doesn't fit in, or can't be perfectly represented by,
@@ -1112,15 +1112,15 @@ pub fn lossyCast(comptime T: type, value: anytype) T {
}
test "math.lossyCast" {
- testing.expect(lossyCast(i16, 70000.0) == @as(i16, 32767));
- testing.expect(lossyCast(u32, @as(i16, -255)) == @as(u32, 0));
- testing.expect(lossyCast(i9, @as(u32, 200)) == @as(i9, 200));
+ try testing.expect(lossyCast(i16, 70000.0) == @as(i16, 32767));
+ try testing.expect(lossyCast(u32, @as(i16, -255)) == @as(u32, 0));
+ try testing.expect(lossyCast(i9, @as(u32, 200)) == @as(i9, 200));
}
test "math.f64_min" {
const f64_min_u64 = 0x0010000000000000;
const fmin: f64 = f64_min;
- testing.expect(@bitCast(u64, fmin) == f64_min_u64);
+ try testing.expect(@bitCast(u64, fmin) == f64_min_u64);
}
pub fn maxInt(comptime T: type) comptime_int {
@@ -1139,45 +1139,45 @@ pub fn minInt(comptime T: type) comptime_int {
}
test "minInt and maxInt" {
- testing.expect(maxInt(u0) == 0);
- testing.expect(maxInt(u1) == 1);
- testing.expect(maxInt(u8) == 255);
- testing.expect(maxInt(u16) == 65535);
- testing.expect(maxInt(u32) == 4294967295);
- testing.expect(maxInt(u64) == 18446744073709551615);
- testing.expect(maxInt(u128) == 340282366920938463463374607431768211455);
-
- testing.expect(maxInt(i0) == 0);
- testing.expect(maxInt(i1) == 0);
- testing.expect(maxInt(i8) == 127);
- testing.expect(maxInt(i16) == 32767);
- testing.expect(maxInt(i32) == 2147483647);
- testing.expect(maxInt(i63) == 4611686018427387903);
- testing.expect(maxInt(i64) == 9223372036854775807);
- testing.expect(maxInt(i128) == 170141183460469231731687303715884105727);
-
- testing.expect(minInt(u0) == 0);
- testing.expect(minInt(u1) == 0);
- testing.expect(minInt(u8) == 0);
- testing.expect(minInt(u16) == 0);
- testing.expect(minInt(u32) == 0);
- testing.expect(minInt(u63) == 0);
- testing.expect(minInt(u64) == 0);
- testing.expect(minInt(u128) == 0);
-
- testing.expect(minInt(i0) == 0);
- testing.expect(minInt(i1) == -1);
- testing.expect(minInt(i8) == -128);
- testing.expect(minInt(i16) == -32768);
- testing.expect(minInt(i32) == -2147483648);
- testing.expect(minInt(i63) == -4611686018427387904);
- testing.expect(minInt(i64) == -9223372036854775808);
- testing.expect(minInt(i128) == -170141183460469231731687303715884105728);
+ try testing.expect(maxInt(u0) == 0);
+ try testing.expect(maxInt(u1) == 1);
+ try testing.expect(maxInt(u8) == 255);
+ try testing.expect(maxInt(u16) == 65535);
+ try testing.expect(maxInt(u32) == 4294967295);
+ try testing.expect(maxInt(u64) == 18446744073709551615);
+ try testing.expect(maxInt(u128) == 340282366920938463463374607431768211455);
+
+ try testing.expect(maxInt(i0) == 0);
+ try testing.expect(maxInt(i1) == 0);
+ try testing.expect(maxInt(i8) == 127);
+ try testing.expect(maxInt(i16) == 32767);
+ try testing.expect(maxInt(i32) == 2147483647);
+ try testing.expect(maxInt(i63) == 4611686018427387903);
+ try testing.expect(maxInt(i64) == 9223372036854775807);
+ try testing.expect(maxInt(i128) == 170141183460469231731687303715884105727);
+
+ try testing.expect(minInt(u0) == 0);
+ try testing.expect(minInt(u1) == 0);
+ try testing.expect(minInt(u8) == 0);
+ try testing.expect(minInt(u16) == 0);
+ try testing.expect(minInt(u32) == 0);
+ try testing.expect(minInt(u63) == 0);
+ try testing.expect(minInt(u64) == 0);
+ try testing.expect(minInt(u128) == 0);
+
+ try testing.expect(minInt(i0) == 0);
+ try testing.expect(minInt(i1) == -1);
+ try testing.expect(minInt(i8) == -128);
+ try testing.expect(minInt(i16) == -32768);
+ try testing.expect(minInt(i32) == -2147483648);
+ try testing.expect(minInt(i63) == -4611686018427387904);
+ try testing.expect(minInt(i64) == -9223372036854775808);
+ try testing.expect(minInt(i128) == -170141183460469231731687303715884105728);
}
test "max value type" {
const x: u32 = maxInt(i32);
- testing.expect(x == 2147483647);
+ try testing.expect(x == 2147483647);
}
pub fn mulWide(comptime T: type, a: T, b: T) std.meta.Int(@typeInfo(T).Int.signedness, @typeInfo(T).Int.bits * 2) {
@@ -1186,9 +1186,9 @@ pub fn mulWide(comptime T: type, a: T, b: T) std.meta.Int(@typeInfo(T).Int.signe
}
test "math.mulWide" {
- testing.expect(mulWide(u8, 5, 5) == 25);
- testing.expect(mulWide(i8, 5, -5) == -25);
- testing.expect(mulWide(u8, 100, 100) == 10000);
+ try testing.expect(mulWide(u8, 5, 5) == 25);
+ try testing.expect(mulWide(i8, 5, -5) == -25);
+ try testing.expect(mulWide(u8, 100, 100) == 10000);
}
/// See also `CompareOperator`.
@@ -1284,51 +1284,51 @@ pub fn compare(a: anytype, op: CompareOperator, b: anytype) bool {
}
test "compare between signed and unsigned" {
- testing.expect(compare(@as(i8, -1), .lt, @as(u8, 255)));
- testing.expect(compare(@as(i8, 2), .gt, @as(u8, 1)));
- testing.expect(!compare(@as(i8, -1), .gte, @as(u8, 255)));
- testing.expect(compare(@as(u8, 255), .gt, @as(i8, -1)));
- testing.expect(!compare(@as(u8, 255), .lte, @as(i8, -1)));
- testing.expect(compare(@as(i8, -1), .lt, @as(u9, 255)));
- testing.expect(!compare(@as(i8, -1), .gte, @as(u9, 255)));
- testing.expect(compare(@as(u9, 255), .gt, @as(i8, -1)));
- testing.expect(!compare(@as(u9, 255), .lte, @as(i8, -1)));
- testing.expect(compare(@as(i9, -1), .lt, @as(u8, 255)));
- testing.expect(!compare(@as(i9, -1), .gte, @as(u8, 255)));
- testing.expect(compare(@as(u8, 255), .gt, @as(i9, -1)));
- testing.expect(!compare(@as(u8, 255), .lte, @as(i9, -1)));
- testing.expect(compare(@as(u8, 1), .lt, @as(u8, 2)));
- testing.expect(@bitCast(u8, @as(i8, -1)) == @as(u8, 255));
- testing.expect(!compare(@as(u8, 255), .eq, @as(i8, -1)));
- testing.expect(compare(@as(u8, 1), .eq, @as(u8, 1)));
+ try testing.expect(compare(@as(i8, -1), .lt, @as(u8, 255)));
+ try testing.expect(compare(@as(i8, 2), .gt, @as(u8, 1)));
+ try testing.expect(!compare(@as(i8, -1), .gte, @as(u8, 255)));
+ try testing.expect(compare(@as(u8, 255), .gt, @as(i8, -1)));
+ try testing.expect(!compare(@as(u8, 255), .lte, @as(i8, -1)));
+ try testing.expect(compare(@as(i8, -1), .lt, @as(u9, 255)));
+ try testing.expect(!compare(@as(i8, -1), .gte, @as(u9, 255)));
+ try testing.expect(compare(@as(u9, 255), .gt, @as(i8, -1)));
+ try testing.expect(!compare(@as(u9, 255), .lte, @as(i8, -1)));
+ try testing.expect(compare(@as(i9, -1), .lt, @as(u8, 255)));
+ try testing.expect(!compare(@as(i9, -1), .gte, @as(u8, 255)));
+ try testing.expect(compare(@as(u8, 255), .gt, @as(i9, -1)));
+ try testing.expect(!compare(@as(u8, 255), .lte, @as(i9, -1)));
+ try testing.expect(compare(@as(u8, 1), .lt, @as(u8, 2)));
+ try testing.expect(@bitCast(u8, @as(i8, -1)) == @as(u8, 255));
+ try testing.expect(!compare(@as(u8, 255), .eq, @as(i8, -1)));
+ try testing.expect(compare(@as(u8, 1), .eq, @as(u8, 1)));
}
test "order" {
- testing.expect(order(0, 0) == .eq);
- testing.expect(order(1, 0) == .gt);
- testing.expect(order(-1, 0) == .lt);
+ try testing.expect(order(0, 0) == .eq);
+ try testing.expect(order(1, 0) == .gt);
+ try testing.expect(order(-1, 0) == .lt);
}
test "order.invert" {
- testing.expect(Order.invert(order(0, 0)) == .eq);
- testing.expect(Order.invert(order(1, 0)) == .lt);
- testing.expect(Order.invert(order(-1, 0)) == .gt);
+ try testing.expect(Order.invert(order(0, 0)) == .eq);
+ try testing.expect(Order.invert(order(1, 0)) == .lt);
+ try testing.expect(Order.invert(order(-1, 0)) == .gt);
}
test "order.compare" {
- testing.expect(order(-1, 0).compare(.lt));
- testing.expect(order(-1, 0).compare(.lte));
- testing.expect(order(0, 0).compare(.lte));
- testing.expect(order(0, 0).compare(.eq));
- testing.expect(order(0, 0).compare(.gte));
- testing.expect(order(1, 0).compare(.gte));
- testing.expect(order(1, 0).compare(.gt));
- testing.expect(order(1, 0).compare(.neq));
+ try testing.expect(order(-1, 0).compare(.lt));
+ try testing.expect(order(-1, 0).compare(.lte));
+ try testing.expect(order(0, 0).compare(.lte));
+ try testing.expect(order(0, 0).compare(.eq));
+ try testing.expect(order(0, 0).compare(.gte));
+ try testing.expect(order(1, 0).compare(.gte));
+ try testing.expect(order(1, 0).compare(.gt));
+ try testing.expect(order(1, 0).compare(.neq));
}
test "math.comptime" {
comptime const v = sin(@as(f32, 1)) + ln(@as(f32, 5));
- testing.expect(v == sin(@as(f32, 1)) + ln(@as(f32, 5)));
+ try testing.expect(v == sin(@as(f32, 1)) + ln(@as(f32, 5)));
}
/// Returns a mask of all ones if value is true,
@@ -1354,26 +1354,26 @@ pub fn boolMask(comptime MaskInt: type, value: bool) callconv(.Inline) MaskInt {
test "boolMask" {
const runTest = struct {
- fn runTest() void {
- testing.expectEqual(@as(u1, 0), boolMask(u1, false));
- testing.expectEqual(@as(u1, 1), boolMask(u1, true));
+ fn runTest() !void {
+ try testing.expectEqual(@as(u1, 0), boolMask(u1, false));
+ try testing.expectEqual(@as(u1, 1), boolMask(u1, true));
- testing.expectEqual(@as(i1, 0), boolMask(i1, false));
- testing.expectEqual(@as(i1, -1), boolMask(i1, true));
+ try testing.expectEqual(@as(i1, 0), boolMask(i1, false));
+ try testing.expectEqual(@as(i1, -1), boolMask(i1, true));
- testing.expectEqual(@as(u13, 0), boolMask(u13, false));
- testing.expectEqual(@as(u13, 0x1FFF), boolMask(u13, true));
+ try testing.expectEqual(@as(u13, 0), boolMask(u13, false));
+ try testing.expectEqual(@as(u13, 0x1FFF), boolMask(u13, true));
- testing.expectEqual(@as(i13, 0), boolMask(i13, false));
- testing.expectEqual(@as(i13, -1), boolMask(i13, true));
+ try testing.expectEqual(@as(i13, 0), boolMask(i13, false));
+ try testing.expectEqual(@as(i13, -1), boolMask(i13, true));
- testing.expectEqual(@as(u32, 0), boolMask(u32, false));
- testing.expectEqual(@as(u32, 0xFFFF_FFFF), boolMask(u32, true));
+ try testing.expectEqual(@as(u32, 0), boolMask(u32, false));
+ try testing.expectEqual(@as(u32, 0xFFFF_FFFF), boolMask(u32, true));
- testing.expectEqual(@as(i32, 0), boolMask(i32, false));
- testing.expectEqual(@as(i32, -1), boolMask(i32, true));
+ try testing.expectEqual(@as(i32, 0), boolMask(i32, false));
+ try testing.expectEqual(@as(i32, -1), boolMask(i32, true));
}
}.runTest;
- runTest();
- comptime runTest();
+ try runTest();
+ comptime try runTest();
}
lib/std/mem.zig
@@ -142,8 +142,8 @@ fn failAllocatorAlloc(self: *Allocator, n: usize, alignment: u29, len_align: u29
}
test "mem.Allocator basics" {
- testing.expectError(error.OutOfMemory, failAllocator.alloc(u8, 1));
- testing.expectError(error.OutOfMemory, failAllocator.allocSentinel(u8, 1, 0));
+ try testing.expectError(error.OutOfMemory, failAllocator.alloc(u8, 1));
+ try testing.expectError(error.OutOfMemory, failAllocator.allocSentinel(u8, 1, 0));
}
/// Copy all of source into dest at position 0.
@@ -276,8 +276,8 @@ test "mem.zeroes" {
var a = zeroes(C_struct);
a.y += 10;
- testing.expect(a.x == 0);
- testing.expect(a.y == 10);
+ try testing.expect(a.x == 0);
+ try testing.expect(a.y == 10);
const ZigStruct = struct {
integral_types: struct {
@@ -314,32 +314,32 @@ test "mem.zeroes" {
};
const b = zeroes(ZigStruct);
- testing.expectEqual(@as(i8, 0), b.integral_types.integer_0);
- testing.expectEqual(@as(i8, 0), b.integral_types.integer_8);
- testing.expectEqual(@as(i16, 0), b.integral_types.integer_16);
- testing.expectEqual(@as(i32, 0), b.integral_types.integer_32);
- testing.expectEqual(@as(i64, 0), b.integral_types.integer_64);
- testing.expectEqual(@as(i128, 0), b.integral_types.integer_128);
- testing.expectEqual(@as(u8, 0), b.integral_types.unsigned_0);
- testing.expectEqual(@as(u8, 0), b.integral_types.unsigned_8);
- testing.expectEqual(@as(u16, 0), b.integral_types.unsigned_16);
- testing.expectEqual(@as(u32, 0), b.integral_types.unsigned_32);
- testing.expectEqual(@as(u64, 0), b.integral_types.unsigned_64);
- testing.expectEqual(@as(u128, 0), b.integral_types.unsigned_128);
- testing.expectEqual(@as(f32, 0), b.integral_types.float_32);
- testing.expectEqual(@as(f64, 0), b.integral_types.float_64);
- testing.expectEqual(@as(?*u8, null), b.pointers.optional);
- testing.expectEqual(@as([*c]u8, null), b.pointers.c_pointer);
- testing.expectEqual(@as([]u8, &[_]u8{}), b.pointers.slice);
+ try testing.expectEqual(@as(i8, 0), b.integral_types.integer_0);
+ try testing.expectEqual(@as(i8, 0), b.integral_types.integer_8);
+ try testing.expectEqual(@as(i16, 0), b.integral_types.integer_16);
+ try testing.expectEqual(@as(i32, 0), b.integral_types.integer_32);
+ try testing.expectEqual(@as(i64, 0), b.integral_types.integer_64);
+ try testing.expectEqual(@as(i128, 0), b.integral_types.integer_128);
+ try testing.expectEqual(@as(u8, 0), b.integral_types.unsigned_0);
+ try testing.expectEqual(@as(u8, 0), b.integral_types.unsigned_8);
+ try testing.expectEqual(@as(u16, 0), b.integral_types.unsigned_16);
+ try testing.expectEqual(@as(u32, 0), b.integral_types.unsigned_32);
+ try testing.expectEqual(@as(u64, 0), b.integral_types.unsigned_64);
+ try testing.expectEqual(@as(u128, 0), b.integral_types.unsigned_128);
+ try testing.expectEqual(@as(f32, 0), b.integral_types.float_32);
+ try testing.expectEqual(@as(f64, 0), b.integral_types.float_64);
+ try testing.expectEqual(@as(?*u8, null), b.pointers.optional);
+ try testing.expectEqual(@as([*c]u8, null), b.pointers.c_pointer);
+ try testing.expectEqual(@as([]u8, &[_]u8{}), b.pointers.slice);
for (b.array) |e| {
- testing.expectEqual(@as(u32, 0), e);
+ try testing.expectEqual(@as(u32, 0), e);
}
- testing.expectEqual(@splat(2, @as(u32, 0)), b.vector_u32);
- testing.expectEqual(@splat(2, @as(f32, 0.0)), b.vector_f32);
- testing.expectEqual(@splat(2, @as(bool, false)), b.vector_bool);
- testing.expectEqual(@as(?u8, null), b.optional_int);
+ try testing.expectEqual(@splat(2, @as(u32, 0)), b.vector_u32);
+ try testing.expectEqual(@splat(2, @as(f32, 0.0)), b.vector_f32);
+ try testing.expectEqual(@splat(2, @as(bool, false)), b.vector_bool);
+ try testing.expectEqual(@as(?u8, null), b.optional_int);
for (b.sentinel) |e| {
- testing.expectEqual(@as(u8, 0), e);
+ try testing.expectEqual(@as(u8, 0), e);
}
const C_union = extern union {
@@ -348,7 +348,7 @@ test "mem.zeroes" {
};
var c = zeroes(C_union);
- testing.expectEqual(@as(u8, 0), c.a);
+ try testing.expectEqual(@as(u8, 0), c.a);
}
/// Initializes all fields of the struct with their default value, or zero values if no default value is present.
@@ -421,7 +421,7 @@ test "zeroInit" {
.a = 42,
});
- testing.expectEqual(S{
+ try testing.expectEqual(S{
.a = 42,
.b = null,
.c = .{
@@ -439,7 +439,7 @@ test "zeroInit" {
};
const c = zeroInit(Color, .{ 255, 255 });
- testing.expectEqual(Color{
+ try testing.expectEqual(Color{
.r = 255,
.g = 255,
.b = 0,
@@ -462,11 +462,11 @@ pub fn order(comptime T: type, lhs: []const T, rhs: []const T) math.Order {
}
test "order" {
- testing.expect(order(u8, "abcd", "bee") == .lt);
- testing.expect(order(u8, "abc", "abc") == .eq);
- testing.expect(order(u8, "abc", "abc0") == .lt);
- testing.expect(order(u8, "", "") == .eq);
- testing.expect(order(u8, "", "a") == .lt);
+ try testing.expect(order(u8, "abcd", "bee") == .lt);
+ try testing.expect(order(u8, "abc", "abc") == .eq);
+ try testing.expect(order(u8, "abc", "abc0") == .lt);
+ try testing.expect(order(u8, "", "") == .eq);
+ try testing.expect(order(u8, "", "a") == .lt);
}
/// Returns true if lhs < rhs, false otherwise
@@ -475,11 +475,11 @@ pub fn lessThan(comptime T: type, lhs: []const T, rhs: []const T) bool {
}
test "mem.lessThan" {
- testing.expect(lessThan(u8, "abcd", "bee"));
- testing.expect(!lessThan(u8, "abc", "abc"));
- testing.expect(lessThan(u8, "abc", "abc0"));
- testing.expect(!lessThan(u8, "", ""));
- testing.expect(lessThan(u8, "", "a"));
+ try testing.expect(lessThan(u8, "abcd", "bee"));
+ try testing.expect(!lessThan(u8, "abc", "abc"));
+ try testing.expect(lessThan(u8, "abc", "abc0"));
+ try testing.expect(!lessThan(u8, "", ""));
+ try testing.expect(lessThan(u8, "", "a"));
}
/// Compares two slices and returns whether they are equal.
@@ -504,11 +504,11 @@ pub fn indexOfDiff(comptime T: type, a: []const T, b: []const T) ?usize {
}
test "indexOfDiff" {
- testing.expectEqual(indexOfDiff(u8, "one", "one"), null);
- testing.expectEqual(indexOfDiff(u8, "one two", "one"), 3);
- testing.expectEqual(indexOfDiff(u8, "one", "one two"), 3);
- testing.expectEqual(indexOfDiff(u8, "one twx", "one two"), 6);
- testing.expectEqual(indexOfDiff(u8, "xne", "one"), 0);
+ try testing.expectEqual(indexOfDiff(u8, "one", "one"), null);
+ try testing.expectEqual(indexOfDiff(u8, "one two", "one"), 3);
+ try testing.expectEqual(indexOfDiff(u8, "one", "one two"), 3);
+ try testing.expectEqual(indexOfDiff(u8, "one twx", "one two"), 6);
+ try testing.expectEqual(indexOfDiff(u8, "xne", "one"), 0);
}
pub const toSliceConst = @compileError("deprecated; use std.mem.spanZ");
@@ -548,26 +548,26 @@ pub fn Span(comptime T: type) type {
}
test "Span" {
- testing.expect(Span(*[5]u16) == []u16);
- testing.expect(Span(?*[5]u16) == ?[]u16);
- testing.expect(Span(*const [5]u16) == []const u16);
- testing.expect(Span(?*const [5]u16) == ?[]const u16);
- testing.expect(Span([]u16) == []u16);
- testing.expect(Span(?[]u16) == ?[]u16);
- testing.expect(Span([]const u8) == []const u8);
- testing.expect(Span(?[]const u8) == ?[]const u8);
- testing.expect(Span([:1]u16) == [:1]u16);
- testing.expect(Span(?[:1]u16) == ?[:1]u16);
- testing.expect(Span([:1]const u8) == [:1]const u8);
- testing.expect(Span(?[:1]const u8) == ?[:1]const u8);
- testing.expect(Span([*:1]u16) == [:1]u16);
- testing.expect(Span(?[*:1]u16) == ?[:1]u16);
- testing.expect(Span([*:1]const u8) == [:1]const u8);
- testing.expect(Span(?[*:1]const u8) == ?[:1]const u8);
- testing.expect(Span([*c]u16) == [:0]u16);
- testing.expect(Span(?[*c]u16) == ?[:0]u16);
- testing.expect(Span([*c]const u8) == [:0]const u8);
- testing.expect(Span(?[*c]const u8) == ?[:0]const u8);
+ try testing.expect(Span(*[5]u16) == []u16);
+ try testing.expect(Span(?*[5]u16) == ?[]u16);
+ try testing.expect(Span(*const [5]u16) == []const u16);
+ try testing.expect(Span(?*const [5]u16) == ?[]const u16);
+ try testing.expect(Span([]u16) == []u16);
+ try testing.expect(Span(?[]u16) == ?[]u16);
+ try testing.expect(Span([]const u8) == []const u8);
+ try testing.expect(Span(?[]const u8) == ?[]const u8);
+ try testing.expect(Span([:1]u16) == [:1]u16);
+ try testing.expect(Span(?[:1]u16) == ?[:1]u16);
+ try testing.expect(Span([:1]const u8) == [:1]const u8);
+ try testing.expect(Span(?[:1]const u8) == ?[:1]const u8);
+ try testing.expect(Span([*:1]u16) == [:1]u16);
+ try testing.expect(Span(?[*:1]u16) == ?[:1]u16);
+ try testing.expect(Span([*:1]const u8) == [:1]const u8);
+ try testing.expect(Span(?[*:1]const u8) == ?[:1]const u8);
+ try testing.expect(Span([*c]u16) == [:0]u16);
+ try testing.expect(Span(?[*c]u16) == ?[:0]u16);
+ try testing.expect(Span([*c]const u8) == [:0]const u8);
+ try testing.expect(Span(?[*c]const u8) == ?[:0]const u8);
}
/// Takes a pointer to an array, a sentinel-terminated pointer, or a slice, and
@@ -597,9 +597,9 @@ pub fn span(ptr: anytype) Span(@TypeOf(ptr)) {
test "span" {
var array: [5]u16 = [_]u16{ 1, 2, 3, 4, 5 };
const ptr = @as([*:3]u16, array[0..2 :3]);
- testing.expect(eql(u16, span(ptr), &[_]u16{ 1, 2 }));
- testing.expect(eql(u16, span(&array), &[_]u16{ 1, 2, 3, 4, 5 }));
- testing.expectEqual(@as(?[:0]u16, null), span(@as(?[*:0]u16, null)));
+ try testing.expect(eql(u16, span(ptr), &[_]u16{ 1, 2 }));
+ try testing.expect(eql(u16, span(&array), &[_]u16{ 1, 2, 3, 4, 5 }));
+ try testing.expectEqual(@as(?[:0]u16, null), span(@as(?[*:0]u16, null)));
}
/// Same as `span`, except when there is both a sentinel and an array
@@ -625,9 +625,9 @@ pub fn spanZ(ptr: anytype) Span(@TypeOf(ptr)) {
test "spanZ" {
var array: [5]u16 = [_]u16{ 1, 2, 3, 4, 5 };
const ptr = @as([*:3]u16, array[0..2 :3]);
- testing.expect(eql(u16, spanZ(ptr), &[_]u16{ 1, 2 }));
- testing.expect(eql(u16, spanZ(&array), &[_]u16{ 1, 2, 3, 4, 5 }));
- testing.expectEqual(@as(?[:0]u16, null), spanZ(@as(?[*:0]u16, null)));
+ try testing.expect(eql(u16, spanZ(ptr), &[_]u16{ 1, 2 }));
+ try testing.expect(eql(u16, spanZ(&array), &[_]u16{ 1, 2, 3, 4, 5 }));
+ try testing.expectEqual(@as(?[:0]u16, null), spanZ(@as(?[*:0]u16, null)));
}
/// Takes a pointer to an array, an array, a vector, a sentinel-terminated pointer,
@@ -661,30 +661,30 @@ pub fn len(value: anytype) usize {
}
test "len" {
- testing.expect(len("aoeu") == 4);
+ try testing.expect(len("aoeu") == 4);
{
var array: [5]u16 = [_]u16{ 1, 2, 3, 4, 5 };
- testing.expect(len(&array) == 5);
- testing.expect(len(array[0..3]) == 3);
+ try testing.expect(len(&array) == 5);
+ try testing.expect(len(array[0..3]) == 3);
array[2] = 0;
const ptr = @as([*:0]u16, array[0..2 :0]);
- testing.expect(len(ptr) == 2);
+ try testing.expect(len(ptr) == 2);
}
{
var array: [5:0]u16 = [_:0]u16{ 1, 2, 3, 4, 5 };
- testing.expect(len(&array) == 5);
+ try testing.expect(len(&array) == 5);
array[2] = 0;
- testing.expect(len(&array) == 5);
+ try testing.expect(len(&array) == 5);
}
{
const vector: meta.Vector(2, u32) = [2]u32{ 1, 2 };
- testing.expect(len(vector) == 2);
+ try testing.expect(len(vector) == 2);
}
{
const tuple = .{ 1, 2 };
- testing.expect(len(tuple) == 2);
- testing.expect(tuple[0] == 1);
+ try testing.expect(len(tuple) == 2);
+ try testing.expect(tuple[0] == 1);
}
}
@@ -725,21 +725,21 @@ pub fn lenZ(ptr: anytype) usize {
}
test "lenZ" {
- testing.expect(lenZ("aoeu") == 4);
+ try testing.expect(lenZ("aoeu") == 4);
{
var array: [5]u16 = [_]u16{ 1, 2, 3, 4, 5 };
- testing.expect(lenZ(&array) == 5);
- testing.expect(lenZ(array[0..3]) == 3);
+ try testing.expect(lenZ(&array) == 5);
+ try testing.expect(lenZ(array[0..3]) == 3);
array[2] = 0;
const ptr = @as([*:0]u16, array[0..2 :0]);
- testing.expect(lenZ(ptr) == 2);
+ try testing.expect(lenZ(ptr) == 2);
}
{
var array: [5:0]u16 = [_:0]u16{ 1, 2, 3, 4, 5 };
- testing.expect(lenZ(&array) == 5);
+ try testing.expect(lenZ(&array) == 5);
array[2] = 0;
- testing.expect(lenZ(&array) == 2);
+ try testing.expect(lenZ(&array) == 2);
}
}
@@ -793,10 +793,10 @@ pub fn trim(comptime T: type, slice: []const T, values_to_strip: []const T) []co
}
test "mem.trim" {
- testing.expectEqualSlices(u8, "foo\n ", trimLeft(u8, " foo\n ", " \n"));
- testing.expectEqualSlices(u8, " foo", trimRight(u8, " foo\n ", " \n"));
- testing.expectEqualSlices(u8, "foo", trim(u8, " foo\n ", " \n"));
- testing.expectEqualSlices(u8, "foo", trim(u8, "foo", " \n"));
+ try testing.expectEqualSlices(u8, "foo\n ", trimLeft(u8, " foo\n ", " \n"));
+ try testing.expectEqualSlices(u8, " foo", trimRight(u8, " foo\n ", " \n"));
+ try testing.expectEqualSlices(u8, "foo", trim(u8, " foo\n ", " \n"));
+ try testing.expectEqualSlices(u8, "foo", trim(u8, "foo", " \n"));
}
/// Linear search for the index of a scalar value inside a slice.
@@ -951,28 +951,28 @@ pub fn indexOfPos(comptime T: type, haystack: []const T, start_index: usize, nee
}
test "mem.indexOf" {
- testing.expect(indexOf(u8, "one two three four five six seven eight nine ten eleven", "three four").? == 8);
- testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten eleven", "three four").? == 8);
- testing.expect(indexOf(u8, "one two three four five six seven eight nine ten eleven", "two two") == null);
- testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten eleven", "two two") == null);
-
- testing.expect(indexOf(u8, "one two three four five six seven eight nine ten", "").? == 0);
- testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten", "").? == 48);
-
- testing.expect(indexOf(u8, "one two three four", "four").? == 14);
- testing.expect(lastIndexOf(u8, "one two three two four", "two").? == 14);
- testing.expect(indexOf(u8, "one two three four", "gour") == null);
- testing.expect(lastIndexOf(u8, "one two three four", "gour") == null);
- testing.expect(indexOf(u8, "foo", "foo").? == 0);
- testing.expect(lastIndexOf(u8, "foo", "foo").? == 0);
- testing.expect(indexOf(u8, "foo", "fool") == null);
- testing.expect(lastIndexOf(u8, "foo", "lfoo") == null);
- testing.expect(lastIndexOf(u8, "foo", "fool") == null);
-
- testing.expect(indexOf(u8, "foo foo", "foo").? == 0);
- testing.expect(lastIndexOf(u8, "foo foo", "foo").? == 4);
- testing.expect(lastIndexOfAny(u8, "boo, cat", "abo").? == 6);
- testing.expect(lastIndexOfScalar(u8, "boo", 'o').? == 2);
+ try testing.expect(indexOf(u8, "one two three four five six seven eight nine ten eleven", "three four").? == 8);
+ try testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten eleven", "three four").? == 8);
+ try testing.expect(indexOf(u8, "one two three four five six seven eight nine ten eleven", "two two") == null);
+ try testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten eleven", "two two") == null);
+
+ try testing.expect(indexOf(u8, "one two three four five six seven eight nine ten", "").? == 0);
+ try testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten", "").? == 48);
+
+ try testing.expect(indexOf(u8, "one two three four", "four").? == 14);
+ try testing.expect(lastIndexOf(u8, "one two three two four", "two").? == 14);
+ try testing.expect(indexOf(u8, "one two three four", "gour") == null);
+ try testing.expect(lastIndexOf(u8, "one two three four", "gour") == null);
+ try testing.expect(indexOf(u8, "foo", "foo").? == 0);
+ try testing.expect(lastIndexOf(u8, "foo", "foo").? == 0);
+ try testing.expect(indexOf(u8, "foo", "fool") == null);
+ try testing.expect(lastIndexOf(u8, "foo", "lfoo") == null);
+ try testing.expect(lastIndexOf(u8, "foo", "fool") == null);
+
+ try testing.expect(indexOf(u8, "foo foo", "foo").? == 0);
+ try testing.expect(lastIndexOf(u8, "foo foo", "foo").? == 4);
+ try testing.expect(lastIndexOfAny(u8, "boo, cat", "abo").? == 6);
+ try testing.expect(lastIndexOfScalar(u8, "boo", 'o').? == 2);
}
/// Returns the number of needles inside the haystack
@@ -992,17 +992,17 @@ pub fn count(comptime T: type, haystack: []const T, needle: []const T) usize {
}
test "mem.count" {
- testing.expect(count(u8, "", "h") == 0);
- testing.expect(count(u8, "h", "h") == 1);
- testing.expect(count(u8, "hh", "h") == 2);
- testing.expect(count(u8, "world!", "hello") == 0);
- testing.expect(count(u8, "hello world!", "hello") == 1);
- testing.expect(count(u8, " abcabc abc", "abc") == 3);
- testing.expect(count(u8, "udexdcbvbruhasdrw", "bruh") == 1);
- testing.expect(count(u8, "foo bar", "o bar") == 1);
- testing.expect(count(u8, "foofoofoo", "foo") == 3);
- testing.expect(count(u8, "fffffff", "ff") == 3);
- testing.expect(count(u8, "owowowu", "owowu") == 1);
+ try testing.expect(count(u8, "", "h") == 0);
+ try testing.expect(count(u8, "h", "h") == 1);
+ try testing.expect(count(u8, "hh", "h") == 2);
+ try testing.expect(count(u8, "world!", "hello") == 0);
+ try testing.expect(count(u8, "hello world!", "hello") == 1);
+ try testing.expect(count(u8, " abcabc abc", "abc") == 3);
+ try testing.expect(count(u8, "udexdcbvbruhasdrw", "bruh") == 1);
+ try testing.expect(count(u8, "foo bar", "o bar") == 1);
+ try testing.expect(count(u8, "foofoofoo", "foo") == 3);
+ try testing.expect(count(u8, "fffffff", "ff") == 3);
+ try testing.expect(count(u8, "owowowu", "owowu") == 1);
}
/// Returns true if the haystack contains expected_count or more needles
@@ -1024,19 +1024,19 @@ pub fn containsAtLeast(comptime T: type, haystack: []const T, expected_count: us
}
test "mem.containsAtLeast" {
- testing.expect(containsAtLeast(u8, "aa", 0, "a"));
- testing.expect(containsAtLeast(u8, "aa", 1, "a"));
- testing.expect(containsAtLeast(u8, "aa", 2, "a"));
- testing.expect(!containsAtLeast(u8, "aa", 3, "a"));
+ try testing.expect(containsAtLeast(u8, "aa", 0, "a"));
+ try testing.expect(containsAtLeast(u8, "aa", 1, "a"));
+ try testing.expect(containsAtLeast(u8, "aa", 2, "a"));
+ try testing.expect(!containsAtLeast(u8, "aa", 3, "a"));
- testing.expect(containsAtLeast(u8, "radaradar", 1, "radar"));
- testing.expect(!containsAtLeast(u8, "radaradar", 2, "radar"));
+ try testing.expect(containsAtLeast(u8, "radaradar", 1, "radar"));
+ try testing.expect(!containsAtLeast(u8, "radaradar", 2, "radar"));
- testing.expect(containsAtLeast(u8, "radarradaradarradar", 3, "radar"));
- testing.expect(!containsAtLeast(u8, "radarradaradarradar", 4, "radar"));
+ try testing.expect(containsAtLeast(u8, "radarradaradarradar", 3, "radar"));
+ try testing.expect(!containsAtLeast(u8, "radarradaradarradar", 4, "radar"));
- testing.expect(containsAtLeast(u8, " radar radar ", 2, "radar"));
- testing.expect(!containsAtLeast(u8, " radar radar ", 3, "radar"));
+ try testing.expect(containsAtLeast(u8, " radar radar ", 2, "radar"));
+ try testing.expect(!containsAtLeast(u8, " radar radar ", 3, "radar"));
}
/// Reads an integer from memory with size equal to bytes.len.
@@ -1141,34 +1141,34 @@ test "comptime read/write int" {
var bytes: [2]u8 = undefined;
writeIntLittle(u16, &bytes, 0x1234);
const result = readIntBig(u16, &bytes);
- testing.expect(result == 0x3412);
+ try testing.expect(result == 0x3412);
}
comptime {
var bytes: [2]u8 = undefined;
writeIntBig(u16, &bytes, 0x1234);
const result = readIntLittle(u16, &bytes);
- testing.expect(result == 0x3412);
+ try testing.expect(result == 0x3412);
}
}
test "readIntBig and readIntLittle" {
- testing.expect(readIntSliceBig(u0, &[_]u8{}) == 0x0);
- testing.expect(readIntSliceLittle(u0, &[_]u8{}) == 0x0);
+ try testing.expect(readIntSliceBig(u0, &[_]u8{}) == 0x0);
+ try testing.expect(readIntSliceLittle(u0, &[_]u8{}) == 0x0);
- testing.expect(readIntSliceBig(u8, &[_]u8{0x32}) == 0x32);
- testing.expect(readIntSliceLittle(u8, &[_]u8{0x12}) == 0x12);
+ try testing.expect(readIntSliceBig(u8, &[_]u8{0x32}) == 0x32);
+ try testing.expect(readIntSliceLittle(u8, &[_]u8{0x12}) == 0x12);
- testing.expect(readIntSliceBig(u16, &[_]u8{ 0x12, 0x34 }) == 0x1234);
- testing.expect(readIntSliceLittle(u16, &[_]u8{ 0x12, 0x34 }) == 0x3412);
+ try testing.expect(readIntSliceBig(u16, &[_]u8{ 0x12, 0x34 }) == 0x1234);
+ try testing.expect(readIntSliceLittle(u16, &[_]u8{ 0x12, 0x34 }) == 0x3412);
- testing.expect(readIntSliceBig(u72, &[_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }) == 0x123456789abcdef024);
- testing.expect(readIntSliceLittle(u72, &[_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }) == 0xfedcba9876543210ec);
+ try testing.expect(readIntSliceBig(u72, &[_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }) == 0x123456789abcdef024);
+ try testing.expect(readIntSliceLittle(u72, &[_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }) == 0xfedcba9876543210ec);
- testing.expect(readIntSliceBig(i8, &[_]u8{0xff}) == -1);
- testing.expect(readIntSliceLittle(i8, &[_]u8{0xfe}) == -2);
+ try testing.expect(readIntSliceBig(i8, &[_]u8{0xff}) == -1);
+ try testing.expect(readIntSliceLittle(i8, &[_]u8{0xfe}) == -2);
- testing.expect(readIntSliceBig(i16, &[_]u8{ 0xff, 0xfd }) == -3);
- testing.expect(readIntSliceLittle(i16, &[_]u8{ 0xfc, 0xff }) == -4);
+ try testing.expect(readIntSliceBig(i16, &[_]u8{ 0xff, 0xfd }) == -3);
+ try testing.expect(readIntSliceLittle(i16, &[_]u8{ 0xfc, 0xff }) == -4);
}
/// Writes an integer to memory, storing it in twos-complement.
@@ -1283,34 +1283,34 @@ test "writeIntBig and writeIntLittle" {
var buf9: [9]u8 = undefined;
writeIntBig(u0, &buf0, 0x0);
- testing.expect(eql(u8, buf0[0..], &[_]u8{}));
+ try testing.expect(eql(u8, buf0[0..], &[_]u8{}));
writeIntLittle(u0, &buf0, 0x0);
- testing.expect(eql(u8, buf0[0..], &[_]u8{}));
+ try testing.expect(eql(u8, buf0[0..], &[_]u8{}));
writeIntBig(u8, &buf1, 0x12);
- testing.expect(eql(u8, buf1[0..], &[_]u8{0x12}));
+ try testing.expect(eql(u8, buf1[0..], &[_]u8{0x12}));
writeIntLittle(u8, &buf1, 0x34);
- testing.expect(eql(u8, buf1[0..], &[_]u8{0x34}));
+ try testing.expect(eql(u8, buf1[0..], &[_]u8{0x34}));
writeIntBig(u16, &buf2, 0x1234);
- testing.expect(eql(u8, buf2[0..], &[_]u8{ 0x12, 0x34 }));
+ try testing.expect(eql(u8, buf2[0..], &[_]u8{ 0x12, 0x34 }));
writeIntLittle(u16, &buf2, 0x5678);
- testing.expect(eql(u8, buf2[0..], &[_]u8{ 0x78, 0x56 }));
+ try testing.expect(eql(u8, buf2[0..], &[_]u8{ 0x78, 0x56 }));
writeIntBig(u72, &buf9, 0x123456789abcdef024);
- testing.expect(eql(u8, buf9[0..], &[_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }));
+ try testing.expect(eql(u8, buf9[0..], &[_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }));
writeIntLittle(u72, &buf9, 0xfedcba9876543210ec);
- testing.expect(eql(u8, buf9[0..], &[_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }));
+ try testing.expect(eql(u8, buf9[0..], &[_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }));
writeIntBig(i8, &buf1, -1);
- testing.expect(eql(u8, buf1[0..], &[_]u8{0xff}));
+ try testing.expect(eql(u8, buf1[0..], &[_]u8{0xff}));
writeIntLittle(i8, &buf1, -2);
- testing.expect(eql(u8, buf1[0..], &[_]u8{0xfe}));
+ try testing.expect(eql(u8, buf1[0..], &[_]u8{0xfe}));
writeIntBig(i16, &buf2, -3);
- testing.expect(eql(u8, buf2[0..], &[_]u8{ 0xff, 0xfd }));
+ try testing.expect(eql(u8, buf2[0..], &[_]u8{ 0xff, 0xfd }));
writeIntLittle(i16, &buf2, -4);
- testing.expect(eql(u8, buf2[0..], &[_]u8{ 0xfc, 0xff }));
+ try testing.expect(eql(u8, buf2[0..], &[_]u8{ 0xfc, 0xff }));
}
/// Returns an iterator that iterates over the slices of `buffer` that are not
@@ -1331,60 +1331,60 @@ pub fn tokenize(buffer: []const u8, delimiter_bytes: []const u8) TokenIterator {
test "mem.tokenize" {
var it = tokenize(" abc def ghi ", " ");
- testing.expect(eql(u8, it.next().?, "abc"));
- testing.expect(eql(u8, it.next().?, "def"));
- testing.expect(eql(u8, it.next().?, "ghi"));
- testing.expect(it.next() == null);
+ try testing.expect(eql(u8, it.next().?, "abc"));
+ try testing.expect(eql(u8, it.next().?, "def"));
+ try testing.expect(eql(u8, it.next().?, "ghi"));
+ try testing.expect(it.next() == null);
it = tokenize("..\\bob", "\\");
- testing.expect(eql(u8, it.next().?, ".."));
- testing.expect(eql(u8, "..", "..\\bob"[0..it.index]));
- testing.expect(eql(u8, it.next().?, "bob"));
- testing.expect(it.next() == null);
+ try testing.expect(eql(u8, it.next().?, ".."));
+ try testing.expect(eql(u8, "..", "..\\bob"[0..it.index]));
+ try testing.expect(eql(u8, it.next().?, "bob"));
+ try testing.expect(it.next() == null);
it = tokenize("//a/b", "/");
- testing.expect(eql(u8, it.next().?, "a"));
- testing.expect(eql(u8, it.next().?, "b"));
- testing.expect(eql(u8, "//a/b", "//a/b"[0..it.index]));
- testing.expect(it.next() == null);
+ try testing.expect(eql(u8, it.next().?, "a"));
+ try testing.expect(eql(u8, it.next().?, "b"));
+ try testing.expect(eql(u8, "//a/b", "//a/b"[0..it.index]));
+ try testing.expect(it.next() == null);
it = tokenize("|", "|");
- testing.expect(it.next() == null);
+ try testing.expect(it.next() == null);
it = tokenize("", "|");
- testing.expect(it.next() == null);
+ try testing.expect(it.next() == null);
it = tokenize("hello", "");
- testing.expect(eql(u8, it.next().?, "hello"));
- testing.expect(it.next() == null);
+ try testing.expect(eql(u8, it.next().?, "hello"));
+ try testing.expect(it.next() == null);
it = tokenize("hello", " ");
- testing.expect(eql(u8, it.next().?, "hello"));
- testing.expect(it.next() == null);
+ try testing.expect(eql(u8, it.next().?, "hello"));
+ try testing.expect(it.next() == null);
}
test "mem.tokenize (multibyte)" {
var it = tokenize("a|b,c/d e", " /,|");
- testing.expect(eql(u8, it.next().?, "a"));
- testing.expect(eql(u8, it.next().?, "b"));
- testing.expect(eql(u8, it.next().?, "c"));
- testing.expect(eql(u8, it.next().?, "d"));
- testing.expect(eql(u8, it.next().?, "e"));
- testing.expect(it.next() == null);
+ try testing.expect(eql(u8, it.next().?, "a"));
+ try testing.expect(eql(u8, it.next().?, "b"));
+ try testing.expect(eql(u8, it.next().?, "c"));
+ try testing.expect(eql(u8, it.next().?, "d"));
+ try testing.expect(eql(u8, it.next().?, "e"));
+ try testing.expect(it.next() == null);
}
test "mem.tokenize (reset)" {
var it = tokenize(" abc def ghi ", " ");
- testing.expect(eql(u8, it.next().?, "abc"));
- testing.expect(eql(u8, it.next().?, "def"));
- testing.expect(eql(u8, it.next().?, "ghi"));
+ try testing.expect(eql(u8, it.next().?, "abc"));
+ try testing.expect(eql(u8, it.next().?, "def"));
+ try testing.expect(eql(u8, it.next().?, "ghi"));
it.reset();
- testing.expect(eql(u8, it.next().?, "abc"));
- testing.expect(eql(u8, it.next().?, "def"));
- testing.expect(eql(u8, it.next().?, "ghi"));
- testing.expect(it.next() == null);
+ try testing.expect(eql(u8, it.next().?, "abc"));
+ try testing.expect(eql(u8, it.next().?, "def"));
+ try testing.expect(eql(u8, it.next().?, "ghi"));
+ try testing.expect(it.next() == null);
}
/// Returns an iterator that iterates over the slices of `buffer` that
@@ -1408,34 +1408,34 @@ pub const separate = @compileError("deprecated: renamed to split (behavior remai
test "mem.split" {
var it = split("abc|def||ghi", "|");
- testing.expect(eql(u8, it.next().?, "abc"));
- testing.expect(eql(u8, it.next().?, "def"));
- testing.expect(eql(u8, it.next().?, ""));
- testing.expect(eql(u8, it.next().?, "ghi"));
- testing.expect(it.next() == null);
+ try testing.expect(eql(u8, it.next().?, "abc"));
+ try testing.expect(eql(u8, it.next().?, "def"));
+ try testing.expect(eql(u8, it.next().?, ""));
+ try testing.expect(eql(u8, it.next().?, "ghi"));
+ try testing.expect(it.next() == null);
it = split("", "|");
- testing.expect(eql(u8, it.next().?, ""));
- testing.expect(it.next() == null);
+ try testing.expect(eql(u8, it.next().?, ""));
+ try testing.expect(it.next() == null);
it = split("|", "|");
- testing.expect(eql(u8, it.next().?, ""));
- testing.expect(eql(u8, it.next().?, ""));
- testing.expect(it.next() == null);
+ try testing.expect(eql(u8, it.next().?, ""));
+ try testing.expect(eql(u8, it.next().?, ""));
+ try testing.expect(it.next() == null);
it = split("hello", " ");
- testing.expect(eql(u8, it.next().?, "hello"));
- testing.expect(it.next() == null);
+ try testing.expect(eql(u8, it.next().?, "hello"));
+ try testing.expect(it.next() == null);
}
test "mem.split (multibyte)" {
var it = split("a, b ,, c, d, e", ", ");
- testing.expect(eql(u8, it.next().?, "a"));
- testing.expect(eql(u8, it.next().?, "b ,"));
- testing.expect(eql(u8, it.next().?, "c"));
- testing.expect(eql(u8, it.next().?, "d"));
- testing.expect(eql(u8, it.next().?, "e"));
- testing.expect(it.next() == null);
+ try testing.expect(eql(u8, it.next().?, "a"));
+ try testing.expect(eql(u8, it.next().?, "b ,"));
+ try testing.expect(eql(u8, it.next().?, "c"));
+ try testing.expect(eql(u8, it.next().?, "d"));
+ try testing.expect(eql(u8, it.next().?, "e"));
+ try testing.expect(it.next() == null);
}
pub fn startsWith(comptime T: type, haystack: []const T, needle: []const T) bool {
@@ -1443,8 +1443,8 @@ pub fn startsWith(comptime T: type, haystack: []const T, needle: []const T) bool
}
test "mem.startsWith" {
- testing.expect(startsWith(u8, "Bob", "Bo"));
- testing.expect(!startsWith(u8, "Needle in haystack", "haystack"));
+ try testing.expect(startsWith(u8, "Bob", "Bo"));
+ try testing.expect(!startsWith(u8, "Needle in haystack", "haystack"));
}
pub fn endsWith(comptime T: type, haystack: []const T, needle: []const T) bool {
@@ -1452,8 +1452,8 @@ pub fn endsWith(comptime T: type, haystack: []const T, needle: []const T) bool {
}
test "mem.endsWith" {
- testing.expect(endsWith(u8, "Needle in haystack", "haystack"));
- testing.expect(!endsWith(u8, "Bob", "Bo"));
+ try testing.expect(endsWith(u8, "Needle in haystack", "haystack"));
+ try testing.expect(!endsWith(u8, "Bob", "Bo"));
}
pub const TokenIterator = struct {
@@ -1571,22 +1571,22 @@ test "mem.join" {
{
const str = try join(testing.allocator, ",", &[_][]const u8{});
defer testing.allocator.free(str);
- testing.expect(eql(u8, str, ""));
+ try testing.expect(eql(u8, str, ""));
}
{
const str = try join(testing.allocator, ",", &[_][]const u8{ "a", "b", "c" });
defer testing.allocator.free(str);
- testing.expect(eql(u8, str, "a,b,c"));
+ try testing.expect(eql(u8, str, "a,b,c"));
}
{
const str = try join(testing.allocator, ",", &[_][]const u8{"a"});
defer testing.allocator.free(str);
- testing.expect(eql(u8, str, "a"));
+ try testing.expect(eql(u8, str, "a"));
}
{
const str = try join(testing.allocator, ",", &[_][]const u8{ "a", "", "b", "", "c" });
defer testing.allocator.free(str);
- testing.expect(eql(u8, str, "a,,b,,c"));
+ try testing.expect(eql(u8, str, "a,,b,,c"));
}
}
@@ -1594,26 +1594,26 @@ test "mem.joinZ" {
{
const str = try joinZ(testing.allocator, ",", &[_][]const u8{});
defer testing.allocator.free(str);
- testing.expect(eql(u8, str, ""));
- testing.expectEqual(str[str.len], 0);
+ try testing.expect(eql(u8, str, ""));
+ try testing.expectEqual(str[str.len], 0);
}
{
const str = try joinZ(testing.allocator, ",", &[_][]const u8{ "a", "b", "c" });
defer testing.allocator.free(str);
- testing.expect(eql(u8, str, "a,b,c"));
- testing.expectEqual(str[str.len], 0);
+ try testing.expect(eql(u8, str, "a,b,c"));
+ try testing.expectEqual(str[str.len], 0);
}
{
const str = try joinZ(testing.allocator, ",", &[_][]const u8{"a"});
defer testing.allocator.free(str);
- testing.expect(eql(u8, str, "a"));
- testing.expectEqual(str[str.len], 0);
+ try testing.expect(eql(u8, str, "a"));
+ try testing.expectEqual(str[str.len], 0);
}
{
const str = try joinZ(testing.allocator, ",", &[_][]const u8{ "a", "", "b", "", "c" });
defer testing.allocator.free(str);
- testing.expect(eql(u8, str, "a,,b,,c"));
- testing.expectEqual(str[str.len], 0);
+ try testing.expect(eql(u8, str, "a,,b,,c"));
+ try testing.expectEqual(str[str.len], 0);
}
}
@@ -1646,7 +1646,7 @@ test "concat" {
{
const str = try concat(testing.allocator, u8, &[_][]const u8{ "abc", "def", "ghi" });
defer testing.allocator.free(str);
- testing.expect(eql(u8, str, "abcdefghi"));
+ try testing.expect(eql(u8, str, "abcdefghi"));
}
{
const str = try concat(testing.allocator, u32, &[_][]const u32{
@@ -1656,21 +1656,21 @@ test "concat" {
&[_]u32{5},
});
defer testing.allocator.free(str);
- testing.expect(eql(u32, str, &[_]u32{ 0, 1, 2, 3, 4, 5 }));
+ try testing.expect(eql(u32, str, &[_]u32{ 0, 1, 2, 3, 4, 5 }));
}
}
test "testStringEquality" {
- testing.expect(eql(u8, "abcd", "abcd"));
- testing.expect(!eql(u8, "abcdef", "abZdef"));
- testing.expect(!eql(u8, "abcdefg", "abcdef"));
+ try testing.expect(eql(u8, "abcd", "abcd"));
+ try testing.expect(!eql(u8, "abcdef", "abZdef"));
+ try testing.expect(!eql(u8, "abcdefg", "abcdef"));
}
test "testReadInt" {
- testReadIntImpl();
- comptime testReadIntImpl();
+ try testReadIntImpl();
+ comptime try testReadIntImpl();
}
-fn testReadIntImpl() void {
+fn testReadIntImpl() !void {
{
const bytes = [_]u8{
0x12,
@@ -1678,12 +1678,12 @@ fn testReadIntImpl() void {
0x56,
0x78,
};
- testing.expect(readInt(u32, &bytes, builtin.Endian.Big) == 0x12345678);
- testing.expect(readIntBig(u32, &bytes) == 0x12345678);
- testing.expect(readIntBig(i32, &bytes) == 0x12345678);
- testing.expect(readInt(u32, &bytes, builtin.Endian.Little) == 0x78563412);
- testing.expect(readIntLittle(u32, &bytes) == 0x78563412);
- testing.expect(readIntLittle(i32, &bytes) == 0x78563412);
+ try testing.expect(readInt(u32, &bytes, builtin.Endian.Big) == 0x12345678);
+ try testing.expect(readIntBig(u32, &bytes) == 0x12345678);
+ try testing.expect(readIntBig(i32, &bytes) == 0x12345678);
+ try testing.expect(readInt(u32, &bytes, builtin.Endian.Little) == 0x78563412);
+ try testing.expect(readIntLittle(u32, &bytes) == 0x78563412);
+ try testing.expect(readIntLittle(i32, &bytes) == 0x78563412);
}
{
const buf = [_]u8{
@@ -1693,7 +1693,7 @@ fn testReadIntImpl() void {
0x34,
};
const answer = readInt(u32, &buf, builtin.Endian.Big);
- testing.expect(answer == 0x00001234);
+ try testing.expect(answer == 0x00001234);
}
{
const buf = [_]u8{
@@ -1703,41 +1703,41 @@ fn testReadIntImpl() void {
0x00,
};
const answer = readInt(u32, &buf, builtin.Endian.Little);
- testing.expect(answer == 0x00003412);
+ try testing.expect(answer == 0x00003412);
}
{
const bytes = [_]u8{
0xff,
0xfe,
};
- testing.expect(readIntBig(u16, &bytes) == 0xfffe);
- testing.expect(readIntBig(i16, &bytes) == -0x0002);
- testing.expect(readIntLittle(u16, &bytes) == 0xfeff);
- testing.expect(readIntLittle(i16, &bytes) == -0x0101);
+ try testing.expect(readIntBig(u16, &bytes) == 0xfffe);
+ try testing.expect(readIntBig(i16, &bytes) == -0x0002);
+ try testing.expect(readIntLittle(u16, &bytes) == 0xfeff);
+ try testing.expect(readIntLittle(i16, &bytes) == -0x0101);
}
}
test "writeIntSlice" {
- testWriteIntImpl();
- comptime testWriteIntImpl();
+ try testWriteIntImpl();
+ comptime try testWriteIntImpl();
}
-fn testWriteIntImpl() void {
+fn testWriteIntImpl() !void {
var bytes: [8]u8 = undefined;
writeIntSlice(u0, bytes[0..], 0, builtin.Endian.Big);
- testing.expect(eql(u8, &bytes, &[_]u8{
+ try testing.expect(eql(u8, &bytes, &[_]u8{
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
}));
writeIntSlice(u0, bytes[0..], 0, builtin.Endian.Little);
- testing.expect(eql(u8, &bytes, &[_]u8{
+ try testing.expect(eql(u8, &bytes, &[_]u8{
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
}));
writeIntSlice(u64, bytes[0..], 0x12345678CAFEBABE, builtin.Endian.Big);
- testing.expect(eql(u8, &bytes, &[_]u8{
+ try testing.expect(eql(u8, &bytes, &[_]u8{
0x12,
0x34,
0x56,
@@ -1749,7 +1749,7 @@ fn testWriteIntImpl() void {
}));
writeIntSlice(u64, bytes[0..], 0xBEBAFECA78563412, builtin.Endian.Little);
- testing.expect(eql(u8, &bytes, &[_]u8{
+ try testing.expect(eql(u8, &bytes, &[_]u8{
0x12,
0x34,
0x56,
@@ -1761,7 +1761,7 @@ fn testWriteIntImpl() void {
}));
writeIntSlice(u32, bytes[0..], 0x12345678, builtin.Endian.Big);
- testing.expect(eql(u8, &bytes, &[_]u8{
+ try testing.expect(eql(u8, &bytes, &[_]u8{
0x00,
0x00,
0x00,
@@ -1773,7 +1773,7 @@ fn testWriteIntImpl() void {
}));
writeIntSlice(u32, bytes[0..], 0x78563412, builtin.Endian.Little);
- testing.expect(eql(u8, &bytes, &[_]u8{
+ try testing.expect(eql(u8, &bytes, &[_]u8{
0x12,
0x34,
0x56,
@@ -1785,7 +1785,7 @@ fn testWriteIntImpl() void {
}));
writeIntSlice(u16, bytes[0..], 0x1234, builtin.Endian.Big);
- testing.expect(eql(u8, &bytes, &[_]u8{
+ try testing.expect(eql(u8, &bytes, &[_]u8{
0x00,
0x00,
0x00,
@@ -1797,7 +1797,7 @@ fn testWriteIntImpl() void {
}));
writeIntSlice(u16, bytes[0..], 0x1234, builtin.Endian.Little);
- testing.expect(eql(u8, &bytes, &[_]u8{
+ try testing.expect(eql(u8, &bytes, &[_]u8{
0x34,
0x12,
0x00,
@@ -1820,7 +1820,7 @@ pub fn min(comptime T: type, slice: []const T) T {
}
test "mem.min" {
- testing.expect(min(u8, "abcdefg") == 'a');
+ try testing.expect(min(u8, "abcdefg") == 'a');
}
/// Returns the largest number in a slice. O(n).
@@ -1834,7 +1834,7 @@ pub fn max(comptime T: type, slice: []const T) T {
}
test "mem.max" {
- testing.expect(max(u8, "abcdefg") == 'g');
+ try testing.expect(max(u8, "abcdefg") == 'g');
}
pub fn swap(comptime T: type, a: *T, b: *T) void {
@@ -1856,7 +1856,7 @@ test "reverse" {
var arr = [_]i32{ 5, 3, 1, 2, 4 };
reverse(i32, arr[0..]);
- testing.expect(eql(i32, &arr, &[_]i32{ 4, 2, 1, 3, 5 }));
+ try testing.expect(eql(i32, &arr, &[_]i32{ 4, 2, 1, 3, 5 }));
}
/// In-place rotation of the values in an array ([0 1 2 3] becomes [1 2 3 0] if we rotate by 1)
@@ -1871,7 +1871,7 @@ test "rotate" {
var arr = [_]i32{ 5, 3, 1, 2, 4 };
rotate(i32, arr[0..], 2);
- testing.expect(eql(i32, &arr, &[_]i32{ 1, 2, 4, 5, 3 }));
+ try testing.expect(eql(i32, &arr, &[_]i32{ 1, 2, 4, 5, 3 }));
}
/// Replace needle with replacement as many times as possible, writing to an output buffer which is assumed to be of
@@ -1904,31 +1904,31 @@ test "replace" {
var output: [29]u8 = undefined;
var replacements = replace(u8, "All your base are belong to us", "base", "Zig", output[0..]);
var expected: []const u8 = "All your Zig are belong to us";
- testing.expect(replacements == 1);
- testing.expectEqualStrings(expected, output[0..expected.len]);
+ try testing.expect(replacements == 1);
+ try testing.expectEqualStrings(expected, output[0..expected.len]);
replacements = replace(u8, "Favor reading code over writing code.", "code", "", output[0..]);
expected = "Favor reading over writing .";
- testing.expect(replacements == 2);
- testing.expectEqualStrings(expected, output[0..expected.len]);
+ try testing.expect(replacements == 2);
+ try testing.expectEqualStrings(expected, output[0..expected.len]);
// Empty needle is not allowed but input may be empty.
replacements = replace(u8, "", "x", "y", output[0..0]);
expected = "";
- testing.expect(replacements == 0);
- testing.expectEqualStrings(expected, output[0..expected.len]);
+ try testing.expect(replacements == 0);
+ try testing.expectEqualStrings(expected, output[0..expected.len]);
// Adjacent replacements.
replacements = replace(u8, "\\n\\n", "\\n", "\n", output[0..]);
expected = "\n\n";
- testing.expect(replacements == 2);
- testing.expectEqualStrings(expected, output[0..expected.len]);
+ try testing.expect(replacements == 2);
+ try testing.expectEqualStrings(expected, output[0..expected.len]);
replacements = replace(u8, "abbba", "b", "cd", output[0..]);
expected = "acdcdcda";
- testing.expect(replacements == 3);
- testing.expectEqualStrings(expected, output[0..expected.len]);
+ try testing.expect(replacements == 3);
+ try testing.expectEqualStrings(expected, output[0..expected.len]);
}
/// Calculate the size needed in an output buffer to perform a replacement.
@@ -1952,16 +1952,16 @@ pub fn replacementSize(comptime T: type, input: []const T, needle: []const T, re
}
test "replacementSize" {
- testing.expect(replacementSize(u8, "All your base are belong to us", "base", "Zig") == 29);
- testing.expect(replacementSize(u8, "Favor reading code over writing code.", "code", "") == 29);
- testing.expect(replacementSize(u8, "Only one obvious way to do things.", "things.", "things in Zig.") == 41);
+ try testing.expect(replacementSize(u8, "All your base are belong to us", "base", "Zig") == 29);
+ try testing.expect(replacementSize(u8, "Favor reading code over writing code.", "code", "") == 29);
+ try testing.expect(replacementSize(u8, "Only one obvious way to do things.", "things.", "things in Zig.") == 41);
// Empty needle is not allowed but input may be empty.
- testing.expect(replacementSize(u8, "", "x", "y") == 0);
+ try testing.expect(replacementSize(u8, "", "x", "y") == 0);
// Adjacent replacements.
- testing.expect(replacementSize(u8, "\\n\\n", "\\n", "\n") == 2);
- testing.expect(replacementSize(u8, "abbba", "b", "cd") == 8);
+ try testing.expect(replacementSize(u8, "\\n\\n", "\\n", "\n") == 2);
+ try testing.expect(replacementSize(u8, "abbba", "b", "cd") == 8);
}
/// Perform a replacement on an allocated buffer of pre-determined size. Caller must free returned memory.
@@ -1976,11 +1976,11 @@ test "replaceOwned" {
const base_replace = replaceOwned(u8, allocator, "All your base are belong to us", "base", "Zig") catch unreachable;
defer allocator.free(base_replace);
- testing.expect(eql(u8, base_replace, "All your Zig are belong to us"));
+ try testing.expect(eql(u8, base_replace, "All your Zig are belong to us"));
const zen_replace = replaceOwned(u8, allocator, "Favor reading code over writing code.", " code", "") catch unreachable;
defer allocator.free(zen_replace);
- testing.expect(eql(u8, zen_replace, "Favor reading over writing."));
+ try testing.expect(eql(u8, zen_replace, "Favor reading over writing."));
}
/// Converts a little-endian integer to host endianness.
@@ -2068,12 +2068,12 @@ test "asBytes" {
.Little => "\xEF\xBE\xAD\xDE",
};
- testing.expect(eql(u8, asBytes(&deadbeef), deadbeef_bytes));
+ try testing.expect(eql(u8, asBytes(&deadbeef), deadbeef_bytes));
var codeface = @as(u32, 0xC0DEFACE);
for (asBytes(&codeface).*) |*b|
b.* = 0;
- testing.expect(codeface == 0);
+ try testing.expect(codeface == 0);
const S = packed struct {
a: u8,
@@ -2088,11 +2088,11 @@ test "asBytes" {
.c = 0xDE,
.d = 0xA1,
};
- testing.expect(eql(u8, asBytes(&inst), "\xBE\xEF\xDE\xA1"));
+ try testing.expect(eql(u8, asBytes(&inst), "\xBE\xEF\xDE\xA1"));
const ZST = struct {};
const zero = ZST{};
- testing.expect(eql(u8, asBytes(&zero), ""));
+ try testing.expect(eql(u8, asBytes(&zero), ""));
}
test "asBytes preserves pointer attributes" {
@@ -2103,10 +2103,10 @@ test "asBytes preserves pointer attributes" {
const in = @typeInfo(@TypeOf(inPtr)).Pointer;
const out = @typeInfo(@TypeOf(outSlice)).Pointer;
- testing.expectEqual(in.is_const, out.is_const);
- testing.expectEqual(in.is_volatile, out.is_volatile);
- testing.expectEqual(in.is_allowzero, out.is_allowzero);
- testing.expectEqual(in.alignment, out.alignment);
+ try testing.expectEqual(in.is_const, out.is_const);
+ try testing.expectEqual(in.is_volatile, out.is_volatile);
+ try testing.expectEqual(in.is_allowzero, out.is_allowzero);
+ try testing.expectEqual(in.alignment, out.alignment);
}
/// Given any value, returns a copy of its bytes in an array.
@@ -2117,14 +2117,14 @@ pub fn toBytes(value: anytype) [@sizeOf(@TypeOf(value))]u8 {
test "toBytes" {
var my_bytes = toBytes(@as(u32, 0x12345678));
switch (builtin.endian) {
- .Big => testing.expect(eql(u8, &my_bytes, "\x12\x34\x56\x78")),
- .Little => testing.expect(eql(u8, &my_bytes, "\x78\x56\x34\x12")),
+ .Big => try testing.expect(eql(u8, &my_bytes, "\x12\x34\x56\x78")),
+ .Little => try testing.expect(eql(u8, &my_bytes, "\x78\x56\x34\x12")),
}
my_bytes[0] = '\x99';
switch (builtin.endian) {
- .Big => testing.expect(eql(u8, &my_bytes, "\x99\x34\x56\x78")),
- .Little => testing.expect(eql(u8, &my_bytes, "\x99\x56\x34\x12")),
+ .Big => try testing.expect(eql(u8, &my_bytes, "\x99\x34\x56\x78")),
+ .Little => try testing.expect(eql(u8, &my_bytes, "\x99\x56\x34\x12")),
}
}
@@ -2154,17 +2154,17 @@ test "bytesAsValue" {
.Little => "\xEF\xBE\xAD\xDE",
};
- testing.expect(deadbeef == bytesAsValue(u32, deadbeef_bytes).*);
+ try testing.expect(deadbeef == bytesAsValue(u32, deadbeef_bytes).*);
var codeface_bytes: [4]u8 = switch (builtin.endian) {
.Big => "\xC0\xDE\xFA\xCE",
.Little => "\xCE\xFA\xDE\xC0",
}.*;
var codeface = bytesAsValue(u32, &codeface_bytes);
- testing.expect(codeface.* == 0xC0DEFACE);
+ try testing.expect(codeface.* == 0xC0DEFACE);
codeface.* = 0;
for (codeface_bytes) |b|
- testing.expect(b == 0);
+ try testing.expect(b == 0);
const S = packed struct {
a: u8,
@@ -2181,7 +2181,7 @@ test "bytesAsValue" {
};
const inst_bytes = "\xBE\xEF\xDE\xA1";
const inst2 = bytesAsValue(S, inst_bytes);
- testing.expect(meta.eql(inst, inst2.*));
+ try testing.expect(meta.eql(inst, inst2.*));
}
test "bytesAsValue preserves pointer attributes" {
@@ -2192,10 +2192,10 @@ test "bytesAsValue preserves pointer attributes" {
const in = @typeInfo(@TypeOf(inSlice)).Pointer;
const out = @typeInfo(@TypeOf(outPtr)).Pointer;
- testing.expectEqual(in.is_const, out.is_const);
- testing.expectEqual(in.is_volatile, out.is_volatile);
- testing.expectEqual(in.is_allowzero, out.is_allowzero);
- testing.expectEqual(in.alignment, out.alignment);
+ try testing.expectEqual(in.is_const, out.is_const);
+ try testing.expectEqual(in.is_volatile, out.is_volatile);
+ try testing.expectEqual(in.is_allowzero, out.is_allowzero);
+ try testing.expectEqual(in.alignment, out.alignment);
}
/// Given a pointer to an array of bytes, returns a value of the specified type backed by a
@@ -2210,7 +2210,7 @@ test "bytesToValue" {
};
const deadbeef = bytesToValue(u32, deadbeef_bytes);
- testing.expect(deadbeef == @as(u32, 0xDEADBEEF));
+ try testing.expect(deadbeef == @as(u32, 0xDEADBEEF));
}
fn BytesAsSliceReturnType(comptime T: type, comptime bytesType: type) type {
@@ -2243,17 +2243,17 @@ test "bytesAsSlice" {
{
const bytes = [_]u8{ 0xDE, 0xAD, 0xBE, 0xEF };
const slice = bytesAsSlice(u16, bytes[0..]);
- testing.expect(slice.len == 2);
- testing.expect(bigToNative(u16, slice[0]) == 0xDEAD);
- testing.expect(bigToNative(u16, slice[1]) == 0xBEEF);
+ try testing.expect(slice.len == 2);
+ try testing.expect(bigToNative(u16, slice[0]) == 0xDEAD);
+ try testing.expect(bigToNative(u16, slice[1]) == 0xBEEF);
}
{
const bytes = [_]u8{ 0xDE, 0xAD, 0xBE, 0xEF };
var runtime_zero: usize = 0;
const slice = bytesAsSlice(u16, bytes[runtime_zero..]);
- testing.expect(slice.len == 2);
- testing.expect(bigToNative(u16, slice[0]) == 0xDEAD);
- testing.expect(bigToNative(u16, slice[1]) == 0xBEEF);
+ try testing.expect(slice.len == 2);
+ try testing.expect(bigToNative(u16, slice[0]) == 0xDEAD);
+ try testing.expect(bigToNative(u16, slice[1]) == 0xBEEF);
}
}
@@ -2261,13 +2261,13 @@ test "bytesAsSlice keeps pointer alignment" {
{
var bytes = [_]u8{ 0x01, 0x02, 0x03, 0x04 };
const numbers = bytesAsSlice(u32, bytes[0..]);
- comptime testing.expect(@TypeOf(numbers) == []align(@alignOf(@TypeOf(bytes))) u32);
+ comptime try testing.expect(@TypeOf(numbers) == []align(@alignOf(@TypeOf(bytes))) u32);
}
{
var bytes = [_]u8{ 0x01, 0x02, 0x03, 0x04 };
var runtime_zero: usize = 0;
const numbers = bytesAsSlice(u32, bytes[runtime_zero..]);
- comptime testing.expect(@TypeOf(numbers) == []align(@alignOf(@TypeOf(bytes))) u32);
+ comptime try testing.expect(@TypeOf(numbers) == []align(@alignOf(@TypeOf(bytes))) u32);
}
}
@@ -2278,7 +2278,7 @@ test "bytesAsSlice on a packed struct" {
var b = [1]u8{9};
var f = bytesAsSlice(F, &b);
- testing.expect(f[0].a == 9);
+ try testing.expect(f[0].a == 9);
}
test "bytesAsSlice with specified alignment" {
@@ -2289,7 +2289,7 @@ test "bytesAsSlice with specified alignment" {
0x33,
};
const slice: []u32 = std.mem.bytesAsSlice(u32, bytes[0..]);
- testing.expect(slice[0] == 0x33333333);
+ try testing.expect(slice[0] == 0x33333333);
}
test "bytesAsSlice preserves pointer attributes" {
@@ -2300,10 +2300,10 @@ test "bytesAsSlice preserves pointer attributes" {
const in = @typeInfo(@TypeOf(inSlice)).Pointer;
const out = @typeInfo(@TypeOf(outSlice)).Pointer;
- testing.expectEqual(in.is_const, out.is_const);
- testing.expectEqual(in.is_volatile, out.is_volatile);
- testing.expectEqual(in.is_allowzero, out.is_allowzero);
- testing.expectEqual(in.alignment, out.alignment);
+ try testing.expectEqual(in.is_const, out.is_const);
+ try testing.expectEqual(in.is_volatile, out.is_volatile);
+ try testing.expectEqual(in.is_allowzero, out.is_allowzero);
+ try testing.expectEqual(in.alignment, out.alignment);
}
fn SliceAsBytesReturnType(comptime sliceType: type) type {
@@ -2332,8 +2332,8 @@ pub fn sliceAsBytes(slice: anytype) SliceAsBytesReturnType(@TypeOf(slice)) {
test "sliceAsBytes" {
const bytes = [_]u16{ 0xDEAD, 0xBEEF };
const slice = sliceAsBytes(bytes[0..]);
- testing.expect(slice.len == 4);
- testing.expect(eql(u8, slice, switch (builtin.endian) {
+ try testing.expect(slice.len == 4);
+ try testing.expect(eql(u8, slice, switch (builtin.endian) {
.Big => "\xDE\xAD\xBE\xEF",
.Little => "\xAD\xDE\xEF\xBE",
}));
@@ -2342,7 +2342,7 @@ test "sliceAsBytes" {
test "sliceAsBytes with sentinel slice" {
const empty_string: [:0]const u8 = "";
const bytes = sliceAsBytes(empty_string);
- testing.expect(bytes.len == 0);
+ try testing.expect(bytes.len == 0);
}
test "sliceAsBytes packed struct at runtime and comptime" {
@@ -2351,49 +2351,49 @@ test "sliceAsBytes packed struct at runtime and comptime" {
b: u4,
};
const S = struct {
- fn doTheTest() void {
+ fn doTheTest() !void {
var foo: Foo = undefined;
var slice = sliceAsBytes(@as(*[1]Foo, &foo)[0..1]);
slice[0] = 0x13;
switch (builtin.endian) {
.Big => {
- testing.expect(foo.a == 0x1);
- testing.expect(foo.b == 0x3);
+ try testing.expect(foo.a == 0x1);
+ try testing.expect(foo.b == 0x3);
},
.Little => {
- testing.expect(foo.a == 0x3);
- testing.expect(foo.b == 0x1);
+ try testing.expect(foo.a == 0x3);
+ try testing.expect(foo.b == 0x1);
},
}
}
};
- S.doTheTest();
- comptime S.doTheTest();
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "sliceAsBytes and bytesAsSlice back" {
- testing.expect(@sizeOf(i32) == 4);
+ try testing.expect(@sizeOf(i32) == 4);
var big_thing_array = [_]i32{ 1, 2, 3, 4 };
const big_thing_slice: []i32 = big_thing_array[0..];
const bytes = sliceAsBytes(big_thing_slice);
- testing.expect(bytes.len == 4 * 4);
+ try testing.expect(bytes.len == 4 * 4);
bytes[4] = 0;
bytes[5] = 0;
bytes[6] = 0;
bytes[7] = 0;
- testing.expect(big_thing_slice[1] == 0);
+ try testing.expect(big_thing_slice[1] == 0);
const big_thing_again = bytesAsSlice(i32, bytes);
- testing.expect(big_thing_again[2] == 3);
+ try testing.expect(big_thing_again[2] == 3);
big_thing_again[2] = -1;
- testing.expect(bytes[8] == math.maxInt(u8));
- testing.expect(bytes[9] == math.maxInt(u8));
- testing.expect(bytes[10] == math.maxInt(u8));
- testing.expect(bytes[11] == math.maxInt(u8));
+ try testing.expect(bytes[8] == math.maxInt(u8));
+ try testing.expect(bytes[9] == math.maxInt(u8));
+ try testing.expect(bytes[10] == math.maxInt(u8));
+ try testing.expect(bytes[11] == math.maxInt(u8));
}
test "sliceAsBytes preserves pointer attributes" {
@@ -2404,10 +2404,10 @@ test "sliceAsBytes preserves pointer attributes" {
const in = @typeInfo(@TypeOf(inSlice)).Pointer;
const out = @typeInfo(@TypeOf(outSlice)).Pointer;
- testing.expectEqual(in.is_const, out.is_const);
- testing.expectEqual(in.is_volatile, out.is_volatile);
- testing.expectEqual(in.is_allowzero, out.is_allowzero);
- testing.expectEqual(in.alignment, out.alignment);
+ try testing.expectEqual(in.is_const, out.is_const);
+ try testing.expectEqual(in.is_volatile, out.is_volatile);
+ try testing.expectEqual(in.is_allowzero, out.is_allowzero);
+ try testing.expectEqual(in.alignment, out.alignment);
}
/// Round an address up to the nearest aligned address
@@ -2434,18 +2434,18 @@ pub fn doNotOptimizeAway(val: anytype) void {
}
test "alignForward" {
- testing.expect(alignForward(1, 1) == 1);
- testing.expect(alignForward(2, 1) == 2);
- testing.expect(alignForward(1, 2) == 2);
- testing.expect(alignForward(2, 2) == 2);
- testing.expect(alignForward(3, 2) == 4);
- testing.expect(alignForward(4, 2) == 4);
- testing.expect(alignForward(7, 8) == 8);
- testing.expect(alignForward(8, 8) == 8);
- testing.expect(alignForward(9, 8) == 16);
- testing.expect(alignForward(15, 8) == 16);
- testing.expect(alignForward(16, 8) == 16);
- testing.expect(alignForward(17, 8) == 24);
+ try testing.expect(alignForward(1, 1) == 1);
+ try testing.expect(alignForward(2, 1) == 2);
+ try testing.expect(alignForward(1, 2) == 2);
+ try testing.expect(alignForward(2, 2) == 2);
+ try testing.expect(alignForward(3, 2) == 4);
+ try testing.expect(alignForward(4, 2) == 4);
+ try testing.expect(alignForward(7, 8) == 8);
+ try testing.expect(alignForward(8, 8) == 8);
+ try testing.expect(alignForward(9, 8) == 16);
+ try testing.expect(alignForward(15, 8) == 16);
+ try testing.expect(alignForward(16, 8) == 16);
+ try testing.expect(alignForward(17, 8) == 24);
}
/// Round an address up to the previous aligned address
@@ -2497,19 +2497,19 @@ pub fn isAlignedGeneric(comptime T: type, addr: T, alignment: T) bool {
}
test "isAligned" {
- testing.expect(isAligned(0, 4));
- testing.expect(isAligned(1, 1));
- testing.expect(isAligned(2, 1));
- testing.expect(isAligned(2, 2));
- testing.expect(!isAligned(2, 4));
- testing.expect(isAligned(3, 1));
- testing.expect(!isAligned(3, 2));
- testing.expect(!isAligned(3, 4));
- testing.expect(isAligned(4, 4));
- testing.expect(isAligned(4, 2));
- testing.expect(isAligned(4, 1));
- testing.expect(!isAligned(4, 8));
- testing.expect(!isAligned(4, 16));
+ try testing.expect(isAligned(0, 4));
+ try testing.expect(isAligned(1, 1));
+ try testing.expect(isAligned(2, 1));
+ try testing.expect(isAligned(2, 2));
+ try testing.expect(!isAligned(2, 4));
+ try testing.expect(isAligned(3, 1));
+ try testing.expect(!isAligned(3, 2));
+ try testing.expect(!isAligned(3, 4));
+ try testing.expect(isAligned(4, 4));
+ try testing.expect(isAligned(4, 2));
+ try testing.expect(isAligned(4, 1));
+ try testing.expect(!isAligned(4, 8));
+ try testing.expect(!isAligned(4, 16));
}
test "freeing empty string with null-terminated sentinel" {
lib/std/meta.zig
@@ -47,16 +47,16 @@ test "std.meta.tagName" {
var u2a = U2{ .C = 0 };
var u2b = U2{ .D = 0 };
- testing.expect(mem.eql(u8, tagName(E1.A), "A"));
- testing.expect(mem.eql(u8, tagName(E1.B), "B"));
- testing.expect(mem.eql(u8, tagName(E2.C), "C"));
- testing.expect(mem.eql(u8, tagName(E2.D), "D"));
- testing.expect(mem.eql(u8, tagName(error.E), "E"));
- testing.expect(mem.eql(u8, tagName(error.F), "F"));
- testing.expect(mem.eql(u8, tagName(u1g), "G"));
- testing.expect(mem.eql(u8, tagName(u1h), "H"));
- testing.expect(mem.eql(u8, tagName(u2a), "C"));
- testing.expect(mem.eql(u8, tagName(u2b), "D"));
+ try testing.expect(mem.eql(u8, tagName(E1.A), "A"));
+ try testing.expect(mem.eql(u8, tagName(E1.B), "B"));
+ try testing.expect(mem.eql(u8, tagName(E2.C), "C"));
+ try testing.expect(mem.eql(u8, tagName(E2.D), "D"));
+ try testing.expect(mem.eql(u8, tagName(error.E), "E"));
+ try testing.expect(mem.eql(u8, tagName(error.F), "F"));
+ try testing.expect(mem.eql(u8, tagName(u1g), "G"));
+ try testing.expect(mem.eql(u8, tagName(u1h), "H"));
+ try testing.expect(mem.eql(u8, tagName(u2a), "C"));
+ try testing.expect(mem.eql(u8, tagName(u2b), "D"));
}
pub fn stringToEnum(comptime T: type, str: []const u8) ?T {
@@ -98,9 +98,9 @@ test "std.meta.stringToEnum" {
A,
B,
};
- testing.expect(E1.A == stringToEnum(E1, "A").?);
- testing.expect(E1.B == stringToEnum(E1, "B").?);
- testing.expect(null == stringToEnum(E1, "C"));
+ try testing.expect(E1.A == stringToEnum(E1, "A").?);
+ try testing.expect(E1.B == stringToEnum(E1, "B").?);
+ try testing.expect(null == stringToEnum(E1, "C"));
}
pub fn bitCount(comptime T: type) comptime_int {
@@ -113,8 +113,8 @@ pub fn bitCount(comptime T: type) comptime_int {
}
test "std.meta.bitCount" {
- testing.expect(bitCount(u8) == 8);
- testing.expect(bitCount(f32) == 32);
+ try testing.expect(bitCount(u8) == 8);
+ try testing.expect(bitCount(f32) == 32);
}
/// Returns the alignment of type T.
@@ -135,13 +135,13 @@ pub fn alignment(comptime T: type) comptime_int {
}
test "std.meta.alignment" {
- testing.expect(alignment(u8) == 1);
- testing.expect(alignment(*align(1) u8) == 1);
- testing.expect(alignment(*align(2) u8) == 2);
- testing.expect(alignment([]align(1) u8) == 1);
- testing.expect(alignment([]align(2) u8) == 2);
- testing.expect(alignment(fn () void) > 0);
- testing.expect(alignment(fn () align(128) void) == 128);
+ try testing.expect(alignment(u8) == 1);
+ try testing.expect(alignment(*align(1) u8) == 1);
+ try testing.expect(alignment(*align(2) u8) == 2);
+ try testing.expect(alignment([]align(1) u8) == 1);
+ try testing.expect(alignment([]align(2) u8) == 2);
+ try testing.expect(alignment(fn () void) > 0);
+ try testing.expect(alignment(fn () align(128) void) == 128);
}
pub fn Child(comptime T: type) type {
@@ -155,11 +155,11 @@ pub fn Child(comptime T: type) type {
}
test "std.meta.Child" {
- testing.expect(Child([1]u8) == u8);
- testing.expect(Child(*u8) == u8);
- testing.expect(Child([]u8) == u8);
- testing.expect(Child(?u8) == u8);
- testing.expect(Child(Vector(2, u8)) == u8);
+ try testing.expect(Child([1]u8) == u8);
+ try testing.expect(Child(*u8) == u8);
+ try testing.expect(Child([]u8) == u8);
+ try testing.expect(Child(?u8) == u8);
+ try testing.expect(Child(Vector(2, u8)) == u8);
}
/// Given a "memory span" type, returns the "element type".
@@ -188,13 +188,13 @@ pub fn Elem(comptime T: type) type {
}
test "std.meta.Elem" {
- testing.expect(Elem([1]u8) == u8);
- testing.expect(Elem([*]u8) == u8);
- testing.expect(Elem([]u8) == u8);
- testing.expect(Elem(*[10]u8) == u8);
- testing.expect(Elem(Vector(2, u8)) == u8);
- testing.expect(Elem(*Vector(2, u8)) == u8);
- testing.expect(Elem(?[*]u8) == u8);
+ try testing.expect(Elem([1]u8) == u8);
+ try testing.expect(Elem([*]u8) == u8);
+ try testing.expect(Elem([]u8) == u8);
+ try testing.expect(Elem(*[10]u8) == u8);
+ try testing.expect(Elem(Vector(2, u8)) == u8);
+ try testing.expect(Elem(*Vector(2, u8)) == u8);
+ try testing.expect(Elem(?[*]u8) == u8);
}
/// Given a type which can have a sentinel e.g. `[:0]u8`, returns the sentinel value,
@@ -219,20 +219,20 @@ pub fn sentinel(comptime T: type) ?Elem(T) {
}
test "std.meta.sentinel" {
- testSentinel();
- comptime testSentinel();
+ try testSentinel();
+ comptime try testSentinel();
}
-fn testSentinel() void {
- testing.expectEqual(@as(u8, 0), sentinel([:0]u8).?);
- testing.expectEqual(@as(u8, 0), sentinel([*:0]u8).?);
- testing.expectEqual(@as(u8, 0), sentinel([5:0]u8).?);
- testing.expectEqual(@as(u8, 0), sentinel(*const [5:0]u8).?);
+fn testSentinel() !void {
+ try testing.expectEqual(@as(u8, 0), sentinel([:0]u8).?);
+ try testing.expectEqual(@as(u8, 0), sentinel([*:0]u8).?);
+ try testing.expectEqual(@as(u8, 0), sentinel([5:0]u8).?);
+ try testing.expectEqual(@as(u8, 0), sentinel(*const [5:0]u8).?);
- testing.expect(sentinel([]u8) == null);
- testing.expect(sentinel([*]u8) == null);
- testing.expect(sentinel([5]u8) == null);
- testing.expect(sentinel(*const [5]u8) == null);
+ try testing.expect(sentinel([]u8) == null);
+ try testing.expect(sentinel([*]u8) == null);
+ try testing.expect(sentinel([5]u8) == null);
+ try testing.expect(sentinel(*const [5]u8) == null);
}
/// Given a "memory span" type, returns the same type except with the given sentinel value.
@@ -322,17 +322,17 @@ pub fn assumeSentinel(p: anytype, comptime sentinel_val: Elem(@TypeOf(p))) Senti
}
test "std.meta.assumeSentinel" {
- testing.expect([*:0]u8 == @TypeOf(assumeSentinel(@as([*]u8, undefined), 0)));
- testing.expect([:0]u8 == @TypeOf(assumeSentinel(@as([]u8, undefined), 0)));
- testing.expect([*:0]const u8 == @TypeOf(assumeSentinel(@as([*]const u8, undefined), 0)));
- testing.expect([:0]const u8 == @TypeOf(assumeSentinel(@as([]const u8, undefined), 0)));
- testing.expect([*:0]u16 == @TypeOf(assumeSentinel(@as([*]u16, undefined), 0)));
- testing.expect([:0]const u16 == @TypeOf(assumeSentinel(@as([]const u16, undefined), 0)));
- testing.expect([*:3]u8 == @TypeOf(assumeSentinel(@as([*:1]u8, undefined), 3)));
- testing.expect([:null]?[*]u8 == @TypeOf(assumeSentinel(@as([]?[*]u8, undefined), null)));
- testing.expect([*:null]?[*]u8 == @TypeOf(assumeSentinel(@as([*]?[*]u8, undefined), null)));
- testing.expect(*[10:0]u8 == @TypeOf(assumeSentinel(@as(*[10]u8, undefined), 0)));
- testing.expect(?[*:0]u8 == @TypeOf(assumeSentinel(@as(?[*]u8, undefined), 0)));
+ try testing.expect([*:0]u8 == @TypeOf(assumeSentinel(@as([*]u8, undefined), 0)));
+ try testing.expect([:0]u8 == @TypeOf(assumeSentinel(@as([]u8, undefined), 0)));
+ try testing.expect([*:0]const u8 == @TypeOf(assumeSentinel(@as([*]const u8, undefined), 0)));
+ try testing.expect([:0]const u8 == @TypeOf(assumeSentinel(@as([]const u8, undefined), 0)));
+ try testing.expect([*:0]u16 == @TypeOf(assumeSentinel(@as([*]u16, undefined), 0)));
+ try testing.expect([:0]const u16 == @TypeOf(assumeSentinel(@as([]const u16, undefined), 0)));
+ try testing.expect([*:3]u8 == @TypeOf(assumeSentinel(@as([*:1]u8, undefined), 3)));
+ try testing.expect([:null]?[*]u8 == @TypeOf(assumeSentinel(@as([]?[*]u8, undefined), null)));
+ try testing.expect([*:null]?[*]u8 == @TypeOf(assumeSentinel(@as([*]?[*]u8, undefined), null)));
+ try testing.expect(*[10:0]u8 == @TypeOf(assumeSentinel(@as(*[10]u8, undefined), 0)));
+ try testing.expect(?[*:0]u8 == @TypeOf(assumeSentinel(@as(?[*]u8, undefined), 0)));
}
pub fn containerLayout(comptime T: type) TypeInfo.ContainerLayout {
@@ -367,15 +367,15 @@ test "std.meta.containerLayout" {
a: u8,
};
- testing.expect(containerLayout(E1) == .Auto);
- testing.expect(containerLayout(E2) == .Packed);
- testing.expect(containerLayout(E3) == .Extern);
- testing.expect(containerLayout(S1) == .Auto);
- testing.expect(containerLayout(S2) == .Packed);
- testing.expect(containerLayout(S3) == .Extern);
- testing.expect(containerLayout(U1) == .Auto);
- testing.expect(containerLayout(U2) == .Packed);
- testing.expect(containerLayout(U3) == .Extern);
+ try testing.expect(containerLayout(E1) == .Auto);
+ try testing.expect(containerLayout(E2) == .Packed);
+ try testing.expect(containerLayout(E3) == .Extern);
+ try testing.expect(containerLayout(S1) == .Auto);
+ try testing.expect(containerLayout(S2) == .Packed);
+ try testing.expect(containerLayout(S3) == .Extern);
+ try testing.expect(containerLayout(U1) == .Auto);
+ try testing.expect(containerLayout(U2) == .Packed);
+ try testing.expect(containerLayout(U3) == .Extern);
}
pub fn declarations(comptime T: type) []const TypeInfo.Declaration {
@@ -414,8 +414,8 @@ test "std.meta.declarations" {
};
inline for (decls) |decl| {
- testing.expect(decl.len == 1);
- testing.expect(comptime mem.eql(u8, decl[0].name, "a"));
+ try testing.expect(decl.len == 1);
+ try testing.expect(comptime mem.eql(u8, decl[0].name, "a"));
}
}
@@ -450,8 +450,8 @@ test "std.meta.declarationInfo" {
};
inline for (infos) |info| {
- testing.expect(comptime mem.eql(u8, info.name, "a"));
- testing.expect(!info.is_pub);
+ try testing.expect(comptime mem.eql(u8, info.name, "a"));
+ try testing.expect(!info.is_pub);
}
}
@@ -488,16 +488,16 @@ test "std.meta.fields" {
const sf = comptime fields(S1);
const uf = comptime fields(U1);
- testing.expect(e1f.len == 1);
- testing.expect(e2f.len == 1);
- testing.expect(sf.len == 1);
- testing.expect(uf.len == 1);
- testing.expect(mem.eql(u8, e1f[0].name, "A"));
- testing.expect(mem.eql(u8, e2f[0].name, "A"));
- testing.expect(mem.eql(u8, sf[0].name, "a"));
- testing.expect(mem.eql(u8, uf[0].name, "a"));
- testing.expect(comptime sf[0].field_type == u8);
- testing.expect(comptime uf[0].field_type == u8);
+ try testing.expect(e1f.len == 1);
+ try testing.expect(e2f.len == 1);
+ try testing.expect(sf.len == 1);
+ try testing.expect(uf.len == 1);
+ try testing.expect(mem.eql(u8, e1f[0].name, "A"));
+ try testing.expect(mem.eql(u8, e2f[0].name, "A"));
+ try testing.expect(mem.eql(u8, sf[0].name, "a"));
+ try testing.expect(mem.eql(u8, uf[0].name, "a"));
+ try testing.expect(comptime sf[0].field_type == u8);
+ try testing.expect(comptime uf[0].field_type == u8);
}
pub fn fieldInfo(comptime T: type, comptime field: FieldEnum(T)) switch (@typeInfo(T)) {
@@ -527,12 +527,12 @@ test "std.meta.fieldInfo" {
const sf = fieldInfo(S1, .a);
const uf = fieldInfo(U1, .a);
- testing.expect(mem.eql(u8, e1f.name, "A"));
- testing.expect(mem.eql(u8, e2f.name, "A"));
- testing.expect(mem.eql(u8, sf.name, "a"));
- testing.expect(mem.eql(u8, uf.name, "a"));
- testing.expect(comptime sf.field_type == u8);
- testing.expect(comptime uf.field_type == u8);
+ try testing.expect(mem.eql(u8, e1f.name, "A"));
+ try testing.expect(mem.eql(u8, e2f.name, "A"));
+ try testing.expect(mem.eql(u8, sf.name, "a"));
+ try testing.expect(mem.eql(u8, uf.name, "a"));
+ try testing.expect(comptime sf.field_type == u8);
+ try testing.expect(comptime uf.field_type == u8);
}
pub fn fieldNames(comptime T: type) *const [fields(T).len][]const u8 {
@@ -562,16 +562,16 @@ test "std.meta.fieldNames" {
const s1names = fieldNames(S1);
const u1names = fieldNames(U1);
- testing.expect(e1names.len == 2);
- testing.expectEqualSlices(u8, e1names[0], "A");
- testing.expectEqualSlices(u8, e1names[1], "B");
- testing.expect(e2names.len == 1);
- testing.expectEqualSlices(u8, e2names[0], "A");
- testing.expect(s1names.len == 1);
- testing.expectEqualSlices(u8, s1names[0], "a");
- testing.expect(u1names.len == 2);
- testing.expectEqualSlices(u8, u1names[0], "a");
- testing.expectEqualSlices(u8, u1names[1], "b");
+ try testing.expect(e1names.len == 2);
+ try testing.expectEqualSlices(u8, e1names[0], "A");
+ try testing.expectEqualSlices(u8, e1names[1], "B");
+ try testing.expect(e2names.len == 1);
+ try testing.expectEqualSlices(u8, e2names[0], "A");
+ try testing.expect(s1names.len == 1);
+ try testing.expectEqualSlices(u8, s1names[0], "a");
+ try testing.expect(u1names.len == 2);
+ try testing.expectEqualSlices(u8, u1names[0], "a");
+ try testing.expectEqualSlices(u8, u1names[1], "b");
}
pub fn FieldEnum(comptime T: type) type {
@@ -595,20 +595,20 @@ pub fn FieldEnum(comptime T: type) type {
});
}
-fn expectEqualEnum(expected: anytype, actual: @TypeOf(expected)) void {
+fn expectEqualEnum(expected: anytype, actual: @TypeOf(expected)) !void {
// TODO: https://github.com/ziglang/zig/issues/7419
// testing.expectEqual(@typeInfo(expected).Enum, @typeInfo(actual).Enum);
- testing.expectEqual(@typeInfo(expected).Enum.layout, @typeInfo(actual).Enum.layout);
- testing.expectEqual(@typeInfo(expected).Enum.tag_type, @typeInfo(actual).Enum.tag_type);
- comptime testing.expectEqualSlices(std.builtin.TypeInfo.EnumField, @typeInfo(expected).Enum.fields, @typeInfo(actual).Enum.fields);
- comptime testing.expectEqualSlices(std.builtin.TypeInfo.Declaration, @typeInfo(expected).Enum.decls, @typeInfo(actual).Enum.decls);
- testing.expectEqual(@typeInfo(expected).Enum.is_exhaustive, @typeInfo(actual).Enum.is_exhaustive);
+ try testing.expectEqual(@typeInfo(expected).Enum.layout, @typeInfo(actual).Enum.layout);
+ try testing.expectEqual(@typeInfo(expected).Enum.tag_type, @typeInfo(actual).Enum.tag_type);
+ comptime try testing.expectEqualSlices(std.builtin.TypeInfo.EnumField, @typeInfo(expected).Enum.fields, @typeInfo(actual).Enum.fields);
+ comptime try testing.expectEqualSlices(std.builtin.TypeInfo.Declaration, @typeInfo(expected).Enum.decls, @typeInfo(actual).Enum.decls);
+ try testing.expectEqual(@typeInfo(expected).Enum.is_exhaustive, @typeInfo(actual).Enum.is_exhaustive);
}
test "std.meta.FieldEnum" {
- expectEqualEnum(enum { a }, FieldEnum(struct { a: u8 }));
- expectEqualEnum(enum { a, b, c }, FieldEnum(struct { a: u8, b: void, c: f32 }));
- expectEqualEnum(enum { a, b, c }, FieldEnum(union { a: u8, b: void, c: f32 }));
+ try expectEqualEnum(enum { a }, FieldEnum(struct { a: u8 }));
+ try expectEqualEnum(enum { a, b, c }, FieldEnum(struct { a: u8, b: void, c: f32 }));
+ try expectEqualEnum(enum { a, b, c }, FieldEnum(union { a: u8, b: void, c: f32 }));
}
// Deprecated: use Tag
@@ -632,8 +632,8 @@ test "std.meta.Tag" {
D: u16,
};
- testing.expect(Tag(E) == u8);
- testing.expect(Tag(U) == E);
+ try testing.expect(Tag(E) == u8);
+ try testing.expect(Tag(U) == E);
}
///Returns the active tag of a tagged union
@@ -654,10 +654,10 @@ test "std.meta.activeTag" {
};
var u = U{ .Int = 32 };
- testing.expect(activeTag(u) == UE.Int);
+ try testing.expect(activeTag(u) == UE.Int);
u = U{ .Float = 112.9876 };
- testing.expect(activeTag(u) == UE.Float);
+ try testing.expect(activeTag(u) == UE.Float);
}
const TagPayloadType = TagPayload;
@@ -665,7 +665,7 @@ const TagPayloadType = TagPayload;
///Given a tagged union type, and an enum, return the type of the union
/// field corresponding to the enum tag.
pub fn TagPayload(comptime U: type, tag: Tag(U)) type {
- testing.expect(trait.is(.Union)(U));
+ try testing.expect(trait.is(.Union)(U));
const info = @typeInfo(U).Union;
const tag_info = @typeInfo(Tag(U)).Enum;
@@ -687,7 +687,7 @@ test "std.meta.TagPayload" {
};
const MovedEvent = TagPayload(Event, Event.Moved);
var e: Event = undefined;
- testing.expect(MovedEvent == @TypeOf(e.Moved));
+ try testing.expect(MovedEvent == @TypeOf(e.Moved));
}
/// Compares two of any type for equality. Containers are compared on a field-by-field basis,
@@ -787,19 +787,19 @@ test "std.meta.eql" {
const u_2 = U{ .s = s_1 };
const u_3 = U{ .f = 24 };
- testing.expect(eql(s_1, s_3));
- testing.expect(eql(&s_1, &s_1));
- testing.expect(!eql(&s_1, &s_3));
- testing.expect(eql(u_1, u_3));
- testing.expect(!eql(u_1, u_2));
+ try testing.expect(eql(s_1, s_3));
+ try testing.expect(eql(&s_1, &s_1));
+ try testing.expect(!eql(&s_1, &s_3));
+ try testing.expect(eql(u_1, u_3));
+ try testing.expect(!eql(u_1, u_2));
var a1 = "abcdef".*;
var a2 = "abcdef".*;
var a3 = "ghijkl".*;
- testing.expect(eql(a1, a2));
- testing.expect(!eql(a1, a3));
- testing.expect(!eql(a1[0..], a2[0..]));
+ try testing.expect(eql(a1, a2));
+ try testing.expect(!eql(a1, a3));
+ try testing.expect(!eql(a1[0..], a2[0..]));
const EU = struct {
fn tst(err: bool) !u8 {
@@ -808,16 +808,16 @@ test "std.meta.eql" {
}
};
- testing.expect(eql(EU.tst(true), EU.tst(true)));
- testing.expect(eql(EU.tst(false), EU.tst(false)));
- testing.expect(!eql(EU.tst(false), EU.tst(true)));
+ try testing.expect(eql(EU.tst(true), EU.tst(true)));
+ try testing.expect(eql(EU.tst(false), EU.tst(false)));
+ try testing.expect(!eql(EU.tst(false), EU.tst(true)));
var v1 = @splat(4, @as(u32, 1));
var v2 = @splat(4, @as(u32, 1));
var v3 = @splat(4, @as(u32, 2));
- testing.expect(eql(v1, v2));
- testing.expect(!eql(v1, v3));
+ try testing.expect(eql(v1, v2));
+ try testing.expect(!eql(v1, v3));
}
test "intToEnum with error return" {
@@ -831,9 +831,9 @@ test "intToEnum with error return" {
var zero: u8 = 0;
var one: u16 = 1;
- testing.expect(intToEnum(E1, zero) catch unreachable == E1.A);
- testing.expect(intToEnum(E2, one) catch unreachable == E2.B);
- testing.expectError(error.InvalidEnumTag, intToEnum(E1, one));
+ try testing.expect(intToEnum(E1, zero) catch unreachable == E1.A);
+ try testing.expect(intToEnum(E2, one) catch unreachable == E2.B);
+ try testing.expectError(error.InvalidEnumTag, intToEnum(E1, one));
}
pub const IntToEnumError = error{InvalidEnumTag};
@@ -1008,27 +1008,27 @@ test "std.meta.cast" {
var i = @as(i64, 10);
- testing.expect(cast(*u8, 16) == @intToPtr(*u8, 16));
- testing.expect(cast(*u64, &i).* == @as(u64, 10));
- testing.expect(cast(*i64, @as(?*align(1) i64, &i)) == &i);
+ try testing.expect(cast(*u8, 16) == @intToPtr(*u8, 16));
+ try testing.expect(cast(*u64, &i).* == @as(u64, 10));
+ try testing.expect(cast(*i64, @as(?*align(1) i64, &i)) == &i);
- testing.expect(cast(?*u8, 2) == @intToPtr(*u8, 2));
- testing.expect(cast(?*i64, @as(*align(1) i64, &i)) == &i);
- testing.expect(cast(?*i64, @as(?*align(1) i64, &i)) == &i);
+ try testing.expect(cast(?*u8, 2) == @intToPtr(*u8, 2));
+ try testing.expect(cast(?*i64, @as(*align(1) i64, &i)) == &i);
+ try testing.expect(cast(?*i64, @as(?*align(1) i64, &i)) == &i);
- testing.expect(cast(E, 1) == .One);
+ try testing.expect(cast(E, 1) == .One);
- testing.expectEqual(@as(u32, 4), cast(u32, @intToPtr(*u32, 4)));
- testing.expectEqual(@as(u32, 4), cast(u32, @intToPtr(?*u32, 4)));
- testing.expectEqual(@as(u32, 10), cast(u32, @as(u64, 10)));
- testing.expectEqual(@as(u8, 2), cast(u8, E.Two));
+ try testing.expectEqual(@as(u32, 4), cast(u32, @intToPtr(*u32, 4)));
+ try testing.expectEqual(@as(u32, 4), cast(u32, @intToPtr(?*u32, 4)));
+ try testing.expectEqual(@as(u32, 10), cast(u32, @as(u64, 10)));
+ try testing.expectEqual(@as(u8, 2), cast(u8, E.Two));
- testing.expectEqual(@bitCast(i32, @as(u32, 0x8000_0000)), cast(i32, @as(u32, 0x8000_0000)));
+ try testing.expectEqual(@bitCast(i32, @as(u32, 0x8000_0000)), cast(i32, @as(u32, 0x8000_0000)));
- testing.expectEqual(@intToPtr(*u8, 2), cast(*u8, @intToPtr(*const u8, 2)));
- testing.expectEqual(@intToPtr(*u8, 2), cast(*u8, @intToPtr(*volatile u8, 2)));
+ try testing.expectEqual(@intToPtr(*u8, 2), cast(*u8, @intToPtr(*const u8, 2)));
+ try testing.expectEqual(@intToPtr(*u8, 2), cast(*u8, @intToPtr(*volatile u8, 2)));
- testing.expectEqual(@intToPtr(?*c_void, 2), cast(?*c_void, @intToPtr(*u8, 2)));
+ try testing.expectEqual(@intToPtr(?*c_void, 2), cast(?*c_void, @intToPtr(*u8, 2)));
const C_ENUM = extern enum(c_int) {
A = 0,
@@ -1036,10 +1036,10 @@ test "std.meta.cast" {
C,
_,
};
- testing.expectEqual(cast(C_ENUM, @as(i64, -1)), @intToEnum(C_ENUM, -1));
- testing.expectEqual(cast(C_ENUM, @as(i8, 1)), .B);
- testing.expectEqual(cast(C_ENUM, @as(u64, 1)), .B);
- testing.expectEqual(cast(C_ENUM, @as(u64, 42)), @intToEnum(C_ENUM, 42));
+ try testing.expectEqual(cast(C_ENUM, @as(i64, -1)), @intToEnum(C_ENUM, -1));
+ try testing.expectEqual(cast(C_ENUM, @as(i8, 1)), .B);
+ try testing.expectEqual(cast(C_ENUM, @as(u64, 1)), .B);
+ try testing.expectEqual(cast(C_ENUM, @as(u64, 42)), @intToEnum(C_ENUM, 42));
}
/// Given a value returns its size as C's sizeof operator would.
@@ -1118,43 +1118,43 @@ test "sizeof" {
const ptr_size = @sizeOf(*c_void);
- testing.expect(sizeof(u32) == 4);
- testing.expect(sizeof(@as(u32, 2)) == 4);
- testing.expect(sizeof(2) == @sizeOf(c_int));
+ try testing.expect(sizeof(u32) == 4);
+ try testing.expect(sizeof(@as(u32, 2)) == 4);
+ try testing.expect(sizeof(2) == @sizeOf(c_int));
- testing.expect(sizeof(2.0) == @sizeOf(f64));
+ try testing.expect(sizeof(2.0) == @sizeOf(f64));
- testing.expect(sizeof(E) == @sizeOf(c_int));
- testing.expect(sizeof(E.One) == @sizeOf(c_int));
+ try testing.expect(sizeof(E) == @sizeOf(c_int));
+ try testing.expect(sizeof(E.One) == @sizeOf(c_int));
- testing.expect(sizeof(S) == 4);
+ try testing.expect(sizeof(S) == 4);
- testing.expect(sizeof([_]u32{ 4, 5, 6 }) == 12);
- testing.expect(sizeof([3]u32) == 12);
- testing.expect(sizeof([3:0]u32) == 16);
- testing.expect(sizeof(&[_]u32{ 4, 5, 6 }) == ptr_size);
+ try testing.expect(sizeof([_]u32{ 4, 5, 6 }) == 12);
+ try testing.expect(sizeof([3]u32) == 12);
+ try testing.expect(sizeof([3:0]u32) == 16);
+ try testing.expect(sizeof(&[_]u32{ 4, 5, 6 }) == ptr_size);
- testing.expect(sizeof(*u32) == ptr_size);
- testing.expect(sizeof([*]u32) == ptr_size);
- testing.expect(sizeof([*c]u32) == ptr_size);
- testing.expect(sizeof(?*u32) == ptr_size);
- testing.expect(sizeof(?[*]u32) == ptr_size);
- testing.expect(sizeof(*c_void) == ptr_size);
- testing.expect(sizeof(*void) == ptr_size);
- testing.expect(sizeof(null) == ptr_size);
+ try testing.expect(sizeof(*u32) == ptr_size);
+ try testing.expect(sizeof([*]u32) == ptr_size);
+ try testing.expect(sizeof([*c]u32) == ptr_size);
+ try testing.expect(sizeof(?*u32) == ptr_size);
+ try testing.expect(sizeof(?[*]u32) == ptr_size);
+ try testing.expect(sizeof(*c_void) == ptr_size);
+ try testing.expect(sizeof(*void) == ptr_size);
+ try testing.expect(sizeof(null) == ptr_size);
- testing.expect(sizeof("foobar") == 7);
- testing.expect(sizeof(&[_:0]u16{ 'f', 'o', 'o', 'b', 'a', 'r' }) == 14);
- testing.expect(sizeof(*const [4:0]u8) == 5);
- testing.expect(sizeof(*[4:0]u8) == ptr_size);
- testing.expect(sizeof([*]const [4:0]u8) == ptr_size);
- testing.expect(sizeof(*const *const [4:0]u8) == ptr_size);
- testing.expect(sizeof(*const [4]u8) == ptr_size);
+ try testing.expect(sizeof("foobar") == 7);
+ try testing.expect(sizeof(&[_:0]u16{ 'f', 'o', 'o', 'b', 'a', 'r' }) == 14);
+ try testing.expect(sizeof(*const [4:0]u8) == 5);
+ try testing.expect(sizeof(*[4:0]u8) == ptr_size);
+ try testing.expect(sizeof([*]const [4:0]u8) == ptr_size);
+ try testing.expect(sizeof(*const *const [4:0]u8) == ptr_size);
+ try testing.expect(sizeof(*const [4]u8) == ptr_size);
- testing.expect(sizeof(sizeof) == @sizeOf(@TypeOf(sizeof)));
+ try testing.expect(sizeof(sizeof) == @sizeOf(@TypeOf(sizeof)));
- testing.expect(sizeof(void) == 1);
- testing.expect(sizeof(c_void) == 1);
+ try testing.expect(sizeof(void) == 1);
+ try testing.expect(sizeof(c_void) == 1);
}
pub const CIntLiteralRadix = enum { decimal, octal, hexadecimal };
@@ -1193,7 +1193,7 @@ pub fn promoteIntLiteral(
test "promoteIntLiteral" {
const signed_hex = promoteIntLiteral(c_int, math.maxInt(c_int) + 1, .hexadecimal);
- testing.expectEqual(c_uint, @TypeOf(signed_hex));
+ try testing.expectEqual(c_uint, @TypeOf(signed_hex));
if (math.maxInt(c_longlong) == math.maxInt(c_int)) return;
@@ -1201,11 +1201,11 @@ test "promoteIntLiteral" {
const unsigned = promoteIntLiteral(c_uint, math.maxInt(c_uint) + 1, .hexadecimal);
if (math.maxInt(c_long) > math.maxInt(c_int)) {
- testing.expectEqual(c_long, @TypeOf(signed_decimal));
- testing.expectEqual(c_ulong, @TypeOf(unsigned));
+ try testing.expectEqual(c_long, @TypeOf(signed_decimal));
+ try testing.expectEqual(c_ulong, @TypeOf(unsigned));
} else {
- testing.expectEqual(c_longlong, @TypeOf(signed_decimal));
- testing.expectEqual(c_ulonglong, @TypeOf(unsigned));
+ try testing.expectEqual(c_longlong, @TypeOf(signed_decimal));
+ try testing.expectEqual(c_ulonglong, @TypeOf(unsigned));
}
}
@@ -1347,17 +1347,17 @@ pub fn shuffleVectorIndex(comptime this_index: c_int, comptime source_vector_len
test "shuffleVectorIndex" {
const vector_len: usize = 4;
- testing.expect(shuffleVectorIndex(-1, vector_len) == 0);
+ try testing.expect(shuffleVectorIndex(-1, vector_len) == 0);
- testing.expect(shuffleVectorIndex(0, vector_len) == 0);
- testing.expect(shuffleVectorIndex(1, vector_len) == 1);
- testing.expect(shuffleVectorIndex(2, vector_len) == 2);
- testing.expect(shuffleVectorIndex(3, vector_len) == 3);
+ try testing.expect(shuffleVectorIndex(0, vector_len) == 0);
+ try testing.expect(shuffleVectorIndex(1, vector_len) == 1);
+ try testing.expect(shuffleVectorIndex(2, vector_len) == 2);
+ try testing.expect(shuffleVectorIndex(3, vector_len) == 3);
- testing.expect(shuffleVectorIndex(4, vector_len) == -1);
- testing.expect(shuffleVectorIndex(5, vector_len) == -2);
- testing.expect(shuffleVectorIndex(6, vector_len) == -3);
- testing.expect(shuffleVectorIndex(7, vector_len) == -4);
+ try testing.expect(shuffleVectorIndex(4, vector_len) == -1);
+ try testing.expect(shuffleVectorIndex(5, vector_len) == -2);
+ try testing.expect(shuffleVectorIndex(6, vector_len) == -3);
+ try testing.expect(shuffleVectorIndex(7, vector_len) == -4);
}
/// Returns whether `error_union` contains an error.
@@ -1366,6 +1366,6 @@ pub fn isError(error_union: anytype) bool {
}
test "isError" {
- std.testing.expect(isError(math.absInt(@as(i8, -128))));
- std.testing.expect(!isError(math.absInt(@as(i8, -127))));
+ try std.testing.expect(isError(math.absInt(@as(i8, -128))));
+ try std.testing.expect(!isError(math.absInt(@as(i8, -127))));
}
lib/std/multi_array_list.zig
@@ -303,7 +303,7 @@ test "basic usage" {
var list = MultiArrayList(Foo){};
defer list.deinit(ally);
- testing.expectEqual(@as(usize, 0), list.items(.a).len);
+ try testing.expectEqual(@as(usize, 0), list.items(.a).len);
try list.ensureCapacity(ally, 2);
@@ -319,12 +319,12 @@ test "basic usage" {
.c = 'b',
});
- testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 1, 2 });
- testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'a', 'b' });
+ try testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 1, 2 });
+ try testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'a', 'b' });
- testing.expectEqual(@as(usize, 2), list.items(.b).len);
- testing.expectEqualStrings("foobar", list.items(.b)[0]);
- testing.expectEqualStrings("zigzag", list.items(.b)[1]);
+ try testing.expectEqual(@as(usize, 2), list.items(.b).len);
+ try testing.expectEqualStrings("foobar", list.items(.b)[0]);
+ try testing.expectEqualStrings("zigzag", list.items(.b)[1]);
try list.append(ally, .{
.a = 3,
@@ -332,13 +332,13 @@ test "basic usage" {
.c = 'c',
});
- testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 1, 2, 3 });
- testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'a', 'b', 'c' });
+ try testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 1, 2, 3 });
+ try testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'a', 'b', 'c' });
- testing.expectEqual(@as(usize, 3), list.items(.b).len);
- testing.expectEqualStrings("foobar", list.items(.b)[0]);
- testing.expectEqualStrings("zigzag", list.items(.b)[1]);
- testing.expectEqualStrings("fizzbuzz", list.items(.b)[2]);
+ try testing.expectEqual(@as(usize, 3), list.items(.b).len);
+ try testing.expectEqualStrings("foobar", list.items(.b)[0]);
+ try testing.expectEqualStrings("zigzag", list.items(.b)[1]);
+ try testing.expectEqualStrings("fizzbuzz", list.items(.b)[2]);
// Add 6 more things to force a capacity increase.
var i: usize = 0;
@@ -350,12 +350,12 @@ test "basic usage" {
});
}
- testing.expectEqualSlices(
+ try testing.expectEqualSlices(
u32,
&[_]u32{ 1, 2, 3, 4, 5, 6, 7, 8, 9 },
list.items(.a),
);
- testing.expectEqualSlices(
+ try testing.expectEqualSlices(
u8,
&[_]u8{ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i' },
list.items(.c),
@@ -363,13 +363,13 @@ test "basic usage" {
list.shrinkAndFree(ally, 3);
- testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 1, 2, 3 });
- testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'a', 'b', 'c' });
+ try testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 1, 2, 3 });
+ try testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'a', 'b', 'c' });
- testing.expectEqual(@as(usize, 3), list.items(.b).len);
- testing.expectEqualStrings("foobar", list.items(.b)[0]);
- testing.expectEqualStrings("zigzag", list.items(.b)[1]);
- testing.expectEqualStrings("fizzbuzz", list.items(.b)[2]);
+ try testing.expectEqual(@as(usize, 3), list.items(.b).len);
+ try testing.expectEqualStrings("foobar", list.items(.b)[0]);
+ try testing.expectEqualStrings("zigzag", list.items(.b)[1]);
+ try testing.expectEqualStrings("fizzbuzz", list.items(.b)[2]);
}
// This was observed to fail on aarch64 with LLVM 11, when the capacityInBytes
@@ -418,37 +418,37 @@ test "regression test for @reduce bug" {
try list.append(ally, .{ .tag = .eof, .start = 123 });
const tags = list.items(.tag);
- testing.expectEqual(tags[1], .identifier);
- testing.expectEqual(tags[2], .equal);
- testing.expectEqual(tags[3], .builtin);
- testing.expectEqual(tags[4], .l_paren);
- testing.expectEqual(tags[5], .string_literal);
- testing.expectEqual(tags[6], .r_paren);
- testing.expectEqual(tags[7], .semicolon);
- testing.expectEqual(tags[8], .keyword_pub);
- testing.expectEqual(tags[9], .keyword_fn);
- testing.expectEqual(tags[10], .identifier);
- testing.expectEqual(tags[11], .l_paren);
- testing.expectEqual(tags[12], .r_paren);
- testing.expectEqual(tags[13], .identifier);
- testing.expectEqual(tags[14], .bang);
- testing.expectEqual(tags[15], .identifier);
- testing.expectEqual(tags[16], .l_brace);
- testing.expectEqual(tags[17], .identifier);
- testing.expectEqual(tags[18], .period);
- testing.expectEqual(tags[19], .identifier);
- testing.expectEqual(tags[20], .period);
- testing.expectEqual(tags[21], .identifier);
- testing.expectEqual(tags[22], .l_paren);
- testing.expectEqual(tags[23], .string_literal);
- testing.expectEqual(tags[24], .comma);
- testing.expectEqual(tags[25], .period);
- testing.expectEqual(tags[26], .l_brace);
- testing.expectEqual(tags[27], .r_brace);
- testing.expectEqual(tags[28], .r_paren);
- testing.expectEqual(tags[29], .semicolon);
- testing.expectEqual(tags[30], .r_brace);
- testing.expectEqual(tags[31], .eof);
+ try testing.expectEqual(tags[1], .identifier);
+ try testing.expectEqual(tags[2], .equal);
+ try testing.expectEqual(tags[3], .builtin);
+ try testing.expectEqual(tags[4], .l_paren);
+ try testing.expectEqual(tags[5], .string_literal);
+ try testing.expectEqual(tags[6], .r_paren);
+ try testing.expectEqual(tags[7], .semicolon);
+ try testing.expectEqual(tags[8], .keyword_pub);
+ try testing.expectEqual(tags[9], .keyword_fn);
+ try testing.expectEqual(tags[10], .identifier);
+ try testing.expectEqual(tags[11], .l_paren);
+ try testing.expectEqual(tags[12], .r_paren);
+ try testing.expectEqual(tags[13], .identifier);
+ try testing.expectEqual(tags[14], .bang);
+ try testing.expectEqual(tags[15], .identifier);
+ try testing.expectEqual(tags[16], .l_brace);
+ try testing.expectEqual(tags[17], .identifier);
+ try testing.expectEqual(tags[18], .period);
+ try testing.expectEqual(tags[19], .identifier);
+ try testing.expectEqual(tags[20], .period);
+ try testing.expectEqual(tags[21], .identifier);
+ try testing.expectEqual(tags[22], .l_paren);
+ try testing.expectEqual(tags[23], .string_literal);
+ try testing.expectEqual(tags[24], .comma);
+ try testing.expectEqual(tags[25], .period);
+ try testing.expectEqual(tags[26], .l_brace);
+ try testing.expectEqual(tags[27], .r_brace);
+ try testing.expectEqual(tags[28], .r_paren);
+ try testing.expectEqual(tags[29], .semicolon);
+ try testing.expectEqual(tags[30], .r_brace);
+ try testing.expectEqual(tags[31], .eof);
}
test "ensure capacity on empty list" {
@@ -466,15 +466,15 @@ test "ensure capacity on empty list" {
list.appendAssumeCapacity(.{ .a = 1, .b = 2 });
list.appendAssumeCapacity(.{ .a = 3, .b = 4 });
- testing.expectEqualSlices(u32, &[_]u32{ 1, 3 }, list.items(.a));
- testing.expectEqualSlices(u8, &[_]u8{ 2, 4 }, list.items(.b));
+ try testing.expectEqualSlices(u32, &[_]u32{ 1, 3 }, list.items(.a));
+ try testing.expectEqualSlices(u8, &[_]u8{ 2, 4 }, list.items(.b));
list.len = 0;
list.appendAssumeCapacity(.{ .a = 5, .b = 6 });
list.appendAssumeCapacity(.{ .a = 7, .b = 8 });
- testing.expectEqualSlices(u32, &[_]u32{ 5, 7 }, list.items(.a));
- testing.expectEqualSlices(u8, &[_]u8{ 6, 8 }, list.items(.b));
+ try testing.expectEqualSlices(u32, &[_]u32{ 5, 7 }, list.items(.a));
+ try testing.expectEqualSlices(u8, &[_]u8{ 6, 8 }, list.items(.b));
list.len = 0;
try list.ensureCapacity(ally, 16);
@@ -482,6 +482,6 @@ test "ensure capacity on empty list" {
list.appendAssumeCapacity(.{ .a = 9, .b = 10 });
list.appendAssumeCapacity(.{ .a = 11, .b = 12 });
- testing.expectEqualSlices(u32, &[_]u32{ 9, 11 }, list.items(.a));
- testing.expectEqualSlices(u8, &[_]u8{ 10, 12 }, list.items(.b));
+ try testing.expectEqualSlices(u32, &[_]u32{ 9, 11 }, list.items(.a));
+ try testing.expectEqualSlices(u8, &[_]u8{ 10, 12 }, list.items(.b));
}
lib/std/once.zig
@@ -67,5 +67,5 @@ test "Once executes its function just once" {
}
}
- testing.expectEqual(@as(i32, 1), global_number);
+ try testing.expectEqual(@as(i32, 1), global_number);
}
lib/std/packed_int_array.zig
@@ -353,7 +353,7 @@ test "PackedIntArray" {
const PackedArray = PackedIntArray(I, int_count);
const expected_bytes = ((bits * int_count) + 7) / 8;
- testing.expect(@sizeOf(PackedArray) == expected_bytes);
+ try testing.expect(@sizeOf(PackedArray) == expected_bytes);
var data = @as(PackedArray, undefined);
@@ -370,7 +370,7 @@ test "PackedIntArray" {
count = 0;
while (i < data.len()) : (i += 1) {
const val = data.get(i);
- testing.expect(val == count);
+ try testing.expect(val == count);
if (bits > 0) count +%= 1;
}
}
@@ -427,7 +427,7 @@ test "PackedIntSlice" {
count = 0;
while (i < data.len()) : (i += 1) {
const val = data.get(i);
- testing.expect(val == count);
+ try testing.expect(val == count);
if (bits > 0) count +%= 1;
}
}
@@ -454,48 +454,48 @@ test "PackedIntSlice of PackedInt(Array/Slice)" {
//slice of array
var packed_slice = packed_array.slice(2, 5);
- testing.expect(packed_slice.len() == 3);
+ try testing.expect(packed_slice.len() == 3);
const ps_bit_count = (bits * packed_slice.len()) + packed_slice.bit_offset;
const ps_expected_bytes = (ps_bit_count + 7) / 8;
- testing.expect(packed_slice.bytes.len == ps_expected_bytes);
- testing.expect(packed_slice.get(0) == 2 % limit);
- testing.expect(packed_slice.get(1) == 3 % limit);
- testing.expect(packed_slice.get(2) == 4 % limit);
+ try testing.expect(packed_slice.bytes.len == ps_expected_bytes);
+ try testing.expect(packed_slice.get(0) == 2 % limit);
+ try testing.expect(packed_slice.get(1) == 3 % limit);
+ try testing.expect(packed_slice.get(2) == 4 % limit);
packed_slice.set(1, 7 % limit);
- testing.expect(packed_slice.get(1) == 7 % limit);
+ try testing.expect(packed_slice.get(1) == 7 % limit);
//write through slice
- testing.expect(packed_array.get(3) == 7 % limit);
+ try testing.expect(packed_array.get(3) == 7 % limit);
//slice of a slice
const packed_slice_two = packed_slice.slice(0, 3);
- testing.expect(packed_slice_two.len() == 3);
+ try testing.expect(packed_slice_two.len() == 3);
const ps2_bit_count = (bits * packed_slice_two.len()) + packed_slice_two.bit_offset;
const ps2_expected_bytes = (ps2_bit_count + 7) / 8;
- testing.expect(packed_slice_two.bytes.len == ps2_expected_bytes);
- testing.expect(packed_slice_two.get(1) == 7 % limit);
- testing.expect(packed_slice_two.get(2) == 4 % limit);
+ try testing.expect(packed_slice_two.bytes.len == ps2_expected_bytes);
+ try testing.expect(packed_slice_two.get(1) == 7 % limit);
+ try testing.expect(packed_slice_two.get(2) == 4 % limit);
//size one case
const packed_slice_three = packed_slice_two.slice(1, 2);
- testing.expect(packed_slice_three.len() == 1);
+ try testing.expect(packed_slice_three.len() == 1);
const ps3_bit_count = (bits * packed_slice_three.len()) + packed_slice_three.bit_offset;
const ps3_expected_bytes = (ps3_bit_count + 7) / 8;
- testing.expect(packed_slice_three.bytes.len == ps3_expected_bytes);
- testing.expect(packed_slice_three.get(0) == 7 % limit);
+ try testing.expect(packed_slice_three.bytes.len == ps3_expected_bytes);
+ try testing.expect(packed_slice_three.get(0) == 7 % limit);
//empty slice case
const packed_slice_empty = packed_slice.slice(0, 0);
- testing.expect(packed_slice_empty.len() == 0);
- testing.expect(packed_slice_empty.bytes.len == 0);
+ try testing.expect(packed_slice_empty.len() == 0);
+ try testing.expect(packed_slice_empty.bytes.len == 0);
//slicing at byte boundaries
const packed_slice_edge = packed_array.slice(8, 16);
- testing.expect(packed_slice_edge.len() == 8);
+ try testing.expect(packed_slice_edge.len() == 8);
const pse_bit_count = (bits * packed_slice_edge.len()) + packed_slice_edge.bit_offset;
const pse_expected_bytes = (pse_bit_count + 7) / 8;
- testing.expect(packed_slice_edge.bytes.len == pse_expected_bytes);
- testing.expect(packed_slice_edge.bit_offset == 0);
+ try testing.expect(packed_slice_edge.bytes.len == pse_expected_bytes);
+ try testing.expect(packed_slice_edge.bit_offset == 0);
}
}
@@ -543,7 +543,7 @@ test "PackedInt(Array/Slice) sliceCast" {
.Big => 0b01,
.Little => 0b10,
};
- testing.expect(packed_slice_cast_2.get(i) == val);
+ try testing.expect(packed_slice_cast_2.get(i) == val);
}
i = 0;
while (i < packed_slice_cast_4.len()) : (i += 1) {
@@ -551,12 +551,12 @@ test "PackedInt(Array/Slice) sliceCast" {
.Big => 0b0101,
.Little => 0b1010,
};
- testing.expect(packed_slice_cast_4.get(i) == val);
+ try testing.expect(packed_slice_cast_4.get(i) == val);
}
i = 0;
while (i < packed_slice_cast_9.len()) : (i += 1) {
const val = 0b010101010;
- testing.expect(packed_slice_cast_9.get(i) == val);
+ try testing.expect(packed_slice_cast_9.get(i) == val);
packed_slice_cast_9.set(i, 0b111000111);
}
i = 0;
@@ -565,7 +565,7 @@ test "PackedInt(Array/Slice) sliceCast" {
.Big => if (i % 2 == 0) @as(u3, 0b111) else @as(u3, 0b000),
.Little => if (i % 2 == 0) @as(u3, 0b111) else @as(u3, 0b000),
};
- testing.expect(packed_slice_cast_3.get(i) == val);
+ try testing.expect(packed_slice_cast_3.get(i) == val);
}
}
@@ -575,58 +575,58 @@ test "PackedInt(Array/Slice)Endian" {
{
const PackedArrayBe = PackedIntArrayEndian(u4, .Big, 8);
var packed_array_be = PackedArrayBe.init([_]u4{ 0, 1, 2, 3, 4, 5, 6, 7 });
- testing.expect(packed_array_be.bytes[0] == 0b00000001);
- testing.expect(packed_array_be.bytes[1] == 0b00100011);
+ try testing.expect(packed_array_be.bytes[0] == 0b00000001);
+ try testing.expect(packed_array_be.bytes[1] == 0b00100011);
var i = @as(usize, 0);
while (i < packed_array_be.len()) : (i += 1) {
- testing.expect(packed_array_be.get(i) == i);
+ try testing.expect(packed_array_be.get(i) == i);
}
var packed_slice_le = packed_array_be.sliceCastEndian(u4, .Little);
i = 0;
while (i < packed_slice_le.len()) : (i += 1) {
const val = if (i % 2 == 0) i + 1 else i - 1;
- testing.expect(packed_slice_le.get(i) == val);
+ try testing.expect(packed_slice_le.get(i) == val);
}
var packed_slice_le_shift = packed_array_be.slice(1, 5).sliceCastEndian(u4, .Little);
i = 0;
while (i < packed_slice_le_shift.len()) : (i += 1) {
const val = if (i % 2 == 0) i else i + 2;
- testing.expect(packed_slice_le_shift.get(i) == val);
+ try testing.expect(packed_slice_le_shift.get(i) == val);
}
}
{
const PackedArrayBe = PackedIntArrayEndian(u11, .Big, 8);
var packed_array_be = PackedArrayBe.init([_]u11{ 0, 1, 2, 3, 4, 5, 6, 7 });
- testing.expect(packed_array_be.bytes[0] == 0b00000000);
- testing.expect(packed_array_be.bytes[1] == 0b00000000);
- testing.expect(packed_array_be.bytes[2] == 0b00000100);
- testing.expect(packed_array_be.bytes[3] == 0b00000001);
- testing.expect(packed_array_be.bytes[4] == 0b00000000);
+ try testing.expect(packed_array_be.bytes[0] == 0b00000000);
+ try testing.expect(packed_array_be.bytes[1] == 0b00000000);
+ try testing.expect(packed_array_be.bytes[2] == 0b00000100);
+ try testing.expect(packed_array_be.bytes[3] == 0b00000001);
+ try testing.expect(packed_array_be.bytes[4] == 0b00000000);
var i = @as(usize, 0);
while (i < packed_array_be.len()) : (i += 1) {
- testing.expect(packed_array_be.get(i) == i);
+ try testing.expect(packed_array_be.get(i) == i);
}
var packed_slice_le = packed_array_be.sliceCastEndian(u11, .Little);
- testing.expect(packed_slice_le.get(0) == 0b00000000000);
- testing.expect(packed_slice_le.get(1) == 0b00010000000);
- testing.expect(packed_slice_le.get(2) == 0b00000000100);
- testing.expect(packed_slice_le.get(3) == 0b00000000000);
- testing.expect(packed_slice_le.get(4) == 0b00010000011);
- testing.expect(packed_slice_le.get(5) == 0b00000000010);
- testing.expect(packed_slice_le.get(6) == 0b10000010000);
- testing.expect(packed_slice_le.get(7) == 0b00000111001);
+ try testing.expect(packed_slice_le.get(0) == 0b00000000000);
+ try testing.expect(packed_slice_le.get(1) == 0b00010000000);
+ try testing.expect(packed_slice_le.get(2) == 0b00000000100);
+ try testing.expect(packed_slice_le.get(3) == 0b00000000000);
+ try testing.expect(packed_slice_le.get(4) == 0b00010000011);
+ try testing.expect(packed_slice_le.get(5) == 0b00000000010);
+ try testing.expect(packed_slice_le.get(6) == 0b10000010000);
+ try testing.expect(packed_slice_le.get(7) == 0b00000111001);
var packed_slice_le_shift = packed_array_be.slice(1, 5).sliceCastEndian(u11, .Little);
- testing.expect(packed_slice_le_shift.get(0) == 0b00010000000);
- testing.expect(packed_slice_le_shift.get(1) == 0b00000000100);
- testing.expect(packed_slice_le_shift.get(2) == 0b00000000000);
- testing.expect(packed_slice_le_shift.get(3) == 0b00010000011);
+ try testing.expect(packed_slice_le_shift.get(0) == 0b00010000000);
+ try testing.expect(packed_slice_le_shift.get(1) == 0b00000000100);
+ try testing.expect(packed_slice_le_shift.get(2) == 0b00000000000);
+ try testing.expect(packed_slice_le_shift.get(3) == 0b00010000011);
}
}
lib/std/priority_dequeue.zig
@@ -482,12 +482,12 @@ test "std.PriorityDequeue: add and remove min" {
try queue.add(25);
try queue.add(13);
- expectEqual(@as(u32, 7), queue.removeMin());
- expectEqual(@as(u32, 12), queue.removeMin());
- expectEqual(@as(u32, 13), queue.removeMin());
- expectEqual(@as(u32, 23), queue.removeMin());
- expectEqual(@as(u32, 25), queue.removeMin());
- expectEqual(@as(u32, 54), queue.removeMin());
+ try expectEqual(@as(u32, 7), queue.removeMin());
+ try expectEqual(@as(u32, 12), queue.removeMin());
+ try expectEqual(@as(u32, 13), queue.removeMin());
+ try expectEqual(@as(u32, 23), queue.removeMin());
+ try expectEqual(@as(u32, 25), queue.removeMin());
+ try expectEqual(@as(u32, 54), queue.removeMin());
}
test "std.PriorityDequeue: add and remove min structs" {
@@ -508,12 +508,12 @@ test "std.PriorityDequeue: add and remove min structs" {
try queue.add(.{ .size = 25 });
try queue.add(.{ .size = 13 });
- expectEqual(@as(u32, 7), queue.removeMin().size);
- expectEqual(@as(u32, 12), queue.removeMin().size);
- expectEqual(@as(u32, 13), queue.removeMin().size);
- expectEqual(@as(u32, 23), queue.removeMin().size);
- expectEqual(@as(u32, 25), queue.removeMin().size);
- expectEqual(@as(u32, 54), queue.removeMin().size);
+ try expectEqual(@as(u32, 7), queue.removeMin().size);
+ try expectEqual(@as(u32, 12), queue.removeMin().size);
+ try expectEqual(@as(u32, 13), queue.removeMin().size);
+ try expectEqual(@as(u32, 23), queue.removeMin().size);
+ try expectEqual(@as(u32, 25), queue.removeMin().size);
+ try expectEqual(@as(u32, 54), queue.removeMin().size);
}
test "std.PriorityDequeue: add and remove max" {
@@ -527,12 +527,12 @@ test "std.PriorityDequeue: add and remove max" {
try queue.add(25);
try queue.add(13);
- expectEqual(@as(u32, 54), queue.removeMax());
- expectEqual(@as(u32, 25), queue.removeMax());
- expectEqual(@as(u32, 23), queue.removeMax());
- expectEqual(@as(u32, 13), queue.removeMax());
- expectEqual(@as(u32, 12), queue.removeMax());
- expectEqual(@as(u32, 7), queue.removeMax());
+ try expectEqual(@as(u32, 54), queue.removeMax());
+ try expectEqual(@as(u32, 25), queue.removeMax());
+ try expectEqual(@as(u32, 23), queue.removeMax());
+ try expectEqual(@as(u32, 13), queue.removeMax());
+ try expectEqual(@as(u32, 12), queue.removeMax());
+ try expectEqual(@as(u32, 7), queue.removeMax());
}
test "std.PriorityDequeue: add and remove same min" {
@@ -546,12 +546,12 @@ test "std.PriorityDequeue: add and remove same min" {
try queue.add(1);
try queue.add(1);
- expectEqual(@as(u32, 1), queue.removeMin());
- expectEqual(@as(u32, 1), queue.removeMin());
- expectEqual(@as(u32, 1), queue.removeMin());
- expectEqual(@as(u32, 1), queue.removeMin());
- expectEqual(@as(u32, 2), queue.removeMin());
- expectEqual(@as(u32, 2), queue.removeMin());
+ try expectEqual(@as(u32, 1), queue.removeMin());
+ try expectEqual(@as(u32, 1), queue.removeMin());
+ try expectEqual(@as(u32, 1), queue.removeMin());
+ try expectEqual(@as(u32, 1), queue.removeMin());
+ try expectEqual(@as(u32, 2), queue.removeMin());
+ try expectEqual(@as(u32, 2), queue.removeMin());
}
test "std.PriorityDequeue: add and remove same max" {
@@ -565,20 +565,20 @@ test "std.PriorityDequeue: add and remove same max" {
try queue.add(1);
try queue.add(1);
- expectEqual(@as(u32, 2), queue.removeMax());
- expectEqual(@as(u32, 2), queue.removeMax());
- expectEqual(@as(u32, 1), queue.removeMax());
- expectEqual(@as(u32, 1), queue.removeMax());
- expectEqual(@as(u32, 1), queue.removeMax());
- expectEqual(@as(u32, 1), queue.removeMax());
+ try expectEqual(@as(u32, 2), queue.removeMax());
+ try expectEqual(@as(u32, 2), queue.removeMax());
+ try expectEqual(@as(u32, 1), queue.removeMax());
+ try expectEqual(@as(u32, 1), queue.removeMax());
+ try expectEqual(@as(u32, 1), queue.removeMax());
+ try expectEqual(@as(u32, 1), queue.removeMax());
}
test "std.PriorityDequeue: removeOrNull empty" {
var queue = PDQ.init(testing.allocator, lessThanComparison);
defer queue.deinit();
- expect(queue.removeMinOrNull() == null);
- expect(queue.removeMaxOrNull() == null);
+ try expect(queue.removeMinOrNull() == null);
+ try expect(queue.removeMaxOrNull() == null);
}
test "std.PriorityDequeue: edge case 3 elements" {
@@ -589,9 +589,9 @@ test "std.PriorityDequeue: edge case 3 elements" {
try queue.add(3);
try queue.add(2);
- expectEqual(@as(u32, 2), queue.removeMin());
- expectEqual(@as(u32, 3), queue.removeMin());
- expectEqual(@as(u32, 9), queue.removeMin());
+ try expectEqual(@as(u32, 2), queue.removeMin());
+ try expectEqual(@as(u32, 3), queue.removeMin());
+ try expectEqual(@as(u32, 9), queue.removeMin());
}
test "std.PriorityDequeue: edge case 3 elements max" {
@@ -602,37 +602,37 @@ test "std.PriorityDequeue: edge case 3 elements max" {
try queue.add(3);
try queue.add(2);
- expectEqual(@as(u32, 9), queue.removeMax());
- expectEqual(@as(u32, 3), queue.removeMax());
- expectEqual(@as(u32, 2), queue.removeMax());
+ try expectEqual(@as(u32, 9), queue.removeMax());
+ try expectEqual(@as(u32, 3), queue.removeMax());
+ try expectEqual(@as(u32, 2), queue.removeMax());
}
test "std.PriorityDequeue: peekMin" {
var queue = PDQ.init(testing.allocator, lessThanComparison);
defer queue.deinit();
- expect(queue.peekMin() == null);
+ try expect(queue.peekMin() == null);
try queue.add(9);
try queue.add(3);
try queue.add(2);
- expect(queue.peekMin().? == 2);
- expect(queue.peekMin().? == 2);
+ try expect(queue.peekMin().? == 2);
+ try expect(queue.peekMin().? == 2);
}
test "std.PriorityDequeue: peekMax" {
var queue = PDQ.init(testing.allocator, lessThanComparison);
defer queue.deinit();
- expect(queue.peekMin() == null);
+ try expect(queue.peekMin() == null);
try queue.add(9);
try queue.add(3);
try queue.add(2);
- expect(queue.peekMax().? == 9);
- expect(queue.peekMax().? == 9);
+ try expect(queue.peekMax().? == 9);
+ try expect(queue.peekMax().? == 9);
}
test "std.PriorityDequeue: sift up with odd indices" {
@@ -645,7 +645,7 @@ test "std.PriorityDequeue: sift up with odd indices" {
const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
for (sorted_items) |e| {
- expectEqual(e, queue.removeMin());
+ try expectEqual(e, queue.removeMin());
}
}
@@ -659,7 +659,7 @@ test "std.PriorityDequeue: sift up with odd indices" {
const sorted_items = [_]u32{ 25, 24, 24, 22, 21, 16, 15, 15, 14, 13, 12, 11, 7, 7, 6, 5, 2, 1 };
for (sorted_items) |e| {
- expectEqual(e, queue.removeMax());
+ try expectEqual(e, queue.removeMax());
}
}
@@ -671,7 +671,7 @@ test "std.PriorityDequeue: addSlice min" {
const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
for (sorted_items) |e| {
- expectEqual(e, queue.removeMin());
+ try expectEqual(e, queue.removeMin());
}
}
@@ -683,7 +683,7 @@ test "std.PriorityDequeue: addSlice max" {
const sorted_items = [_]u32{ 25, 24, 24, 22, 21, 16, 15, 15, 14, 13, 12, 11, 7, 7, 6, 5, 2, 1 };
for (sorted_items) |e| {
- expectEqual(e, queue.removeMax());
+ try expectEqual(e, queue.removeMax());
}
}
@@ -692,8 +692,8 @@ test "std.PriorityDequeue: fromOwnedSlice trivial case 0" {
const queue_items = try testing.allocator.dupe(u32, &items);
var queue = PDQ.fromOwnedSlice(testing.allocator, lessThanComparison, queue_items[0..]);
defer queue.deinit();
- expectEqual(@as(usize, 0), queue.len);
- expect(queue.removeMinOrNull() == null);
+ try expectEqual(@as(usize, 0), queue.len);
+ try expect(queue.removeMinOrNull() == null);
}
test "std.PriorityDequeue: fromOwnedSlice trivial case 1" {
@@ -702,9 +702,9 @@ test "std.PriorityDequeue: fromOwnedSlice trivial case 1" {
var queue = PDQ.fromOwnedSlice(testing.allocator, lessThanComparison, queue_items[0..]);
defer queue.deinit();
- expectEqual(@as(usize, 1), queue.len);
- expectEqual(items[0], queue.removeMin());
- expect(queue.removeMinOrNull() == null);
+ try expectEqual(@as(usize, 1), queue.len);
+ try expectEqual(items[0], queue.removeMin());
+ try expect(queue.removeMinOrNull() == null);
}
test "std.PriorityDequeue: fromOwnedSlice" {
@@ -715,7 +715,7 @@ test "std.PriorityDequeue: fromOwnedSlice" {
const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
for (sorted_items) |e| {
- expectEqual(e, queue.removeMin());
+ try expectEqual(e, queue.removeMin());
}
}
@@ -729,9 +729,9 @@ test "std.PriorityDequeue: update min queue" {
try queue.update(55, 5);
try queue.update(44, 4);
try queue.update(11, 1);
- expectEqual(@as(u32, 1), queue.removeMin());
- expectEqual(@as(u32, 4), queue.removeMin());
- expectEqual(@as(u32, 5), queue.removeMin());
+ try expectEqual(@as(u32, 1), queue.removeMin());
+ try expectEqual(@as(u32, 4), queue.removeMin());
+ try expectEqual(@as(u32, 5), queue.removeMin());
}
test "std.PriorityDequeue: update same min queue" {
@@ -744,10 +744,10 @@ test "std.PriorityDequeue: update same min queue" {
try queue.add(2);
try queue.update(1, 5);
try queue.update(2, 4);
- expectEqual(@as(u32, 1), queue.removeMin());
- expectEqual(@as(u32, 2), queue.removeMin());
- expectEqual(@as(u32, 4), queue.removeMin());
- expectEqual(@as(u32, 5), queue.removeMin());
+ try expectEqual(@as(u32, 1), queue.removeMin());
+ try expectEqual(@as(u32, 2), queue.removeMin());
+ try expectEqual(@as(u32, 4), queue.removeMin());
+ try expectEqual(@as(u32, 5), queue.removeMin());
}
test "std.PriorityDequeue: update max queue" {
@@ -761,9 +761,9 @@ test "std.PriorityDequeue: update max queue" {
try queue.update(44, 1);
try queue.update(11, 4);
- expectEqual(@as(u32, 5), queue.removeMax());
- expectEqual(@as(u32, 4), queue.removeMax());
- expectEqual(@as(u32, 1), queue.removeMax());
+ try expectEqual(@as(u32, 5), queue.removeMax());
+ try expectEqual(@as(u32, 4), queue.removeMax());
+ try expectEqual(@as(u32, 1), queue.removeMax());
}
test "std.PriorityDequeue: update same max queue" {
@@ -776,10 +776,10 @@ test "std.PriorityDequeue: update same max queue" {
try queue.add(2);
try queue.update(1, 5);
try queue.update(2, 4);
- expectEqual(@as(u32, 5), queue.removeMax());
- expectEqual(@as(u32, 4), queue.removeMax());
- expectEqual(@as(u32, 2), queue.removeMax());
- expectEqual(@as(u32, 1), queue.removeMax());
+ try expectEqual(@as(u32, 5), queue.removeMax());
+ try expectEqual(@as(u32, 4), queue.removeMax());
+ try expectEqual(@as(u32, 2), queue.removeMax());
+ try expectEqual(@as(u32, 1), queue.removeMax());
}
test "std.PriorityDequeue: iterator" {
@@ -801,7 +801,7 @@ test "std.PriorityDequeue: iterator" {
_ = map.remove(e);
}
- expectEqual(@as(usize, 0), map.count());
+ try expectEqual(@as(usize, 0), map.count());
}
test "std.PriorityDequeue: remove at index" {
@@ -821,10 +821,10 @@ test "std.PriorityDequeue: remove at index" {
idx += 1;
} else unreachable;
- expectEqual(queue.removeIndex(two_idx), 2);
- expectEqual(queue.removeMin(), 1);
- expectEqual(queue.removeMin(), 3);
- expectEqual(queue.removeMinOrNull(), null);
+ try expectEqual(queue.removeIndex(two_idx), 2);
+ try expectEqual(queue.removeMin(), 1);
+ try expectEqual(queue.removeMin(), 3);
+ try expectEqual(queue.removeMinOrNull(), null);
}
test "std.PriorityDequeue: iterator while empty" {
@@ -833,7 +833,7 @@ test "std.PriorityDequeue: iterator while empty" {
var it = queue.iterator();
- expectEqual(it.next(), null);
+ try expectEqual(it.next(), null);
}
test "std.PriorityDequeue: shrinkRetainingCapacity and shrinkAndFree" {
@@ -841,26 +841,26 @@ test "std.PriorityDequeue: shrinkRetainingCapacity and shrinkAndFree" {
defer queue.deinit();
try queue.ensureCapacity(4);
- expect(queue.capacity() >= 4);
+ try expect(queue.capacity() >= 4);
try queue.add(1);
try queue.add(2);
try queue.add(3);
- expect(queue.capacity() >= 4);
- expectEqual(@as(usize, 3), queue.len);
+ try expect(queue.capacity() >= 4);
+ try expectEqual(@as(usize, 3), queue.len);
queue.shrinkRetainingCapacity(3);
- expect(queue.capacity() >= 4);
- expectEqual(@as(usize, 3), queue.len);
+ try expect(queue.capacity() >= 4);
+ try expectEqual(@as(usize, 3), queue.len);
queue.shrinkAndFree(3);
- expectEqual(@as(usize, 3), queue.capacity());
- expectEqual(@as(usize, 3), queue.len);
+ try expectEqual(@as(usize, 3), queue.capacity());
+ try expectEqual(@as(usize, 3), queue.len);
- expectEqual(@as(u32, 3), queue.removeMax());
- expectEqual(@as(u32, 2), queue.removeMax());
- expectEqual(@as(u32, 1), queue.removeMax());
- expect(queue.removeMaxOrNull() == null);
+ try expectEqual(@as(u32, 3), queue.removeMax());
+ try expectEqual(@as(u32, 2), queue.removeMax());
+ try expectEqual(@as(u32, 1), queue.removeMax());
+ try expect(queue.removeMaxOrNull() == null);
}
test "std.PriorityDequeue: fuzz testing min" {
@@ -885,7 +885,7 @@ fn fuzzTestMin(rng: *std.rand.Random, comptime queue_size: usize) !void {
var last_removed: ?u32 = null;
while (queue.removeMinOrNull()) |next| {
if (last_removed) |last| {
- expect(last <= next);
+ try expect(last <= next);
}
last_removed = next;
}
@@ -913,7 +913,7 @@ fn fuzzTestMax(rng: *std.rand.Random, queue_size: usize) !void {
var last_removed: ?u32 = null;
while (queue.removeMaxOrNull()) |next| {
if (last_removed) |last| {
- expect(last >= next);
+ try expect(last >= next);
}
last_removed = next;
}
@@ -945,13 +945,13 @@ fn fuzzTestMinMax(rng: *std.rand.Random, queue_size: usize) !void {
if (i % 2 == 0) {
const next = queue.removeMin();
if (last_min) |last| {
- expect(last <= next);
+ try expect(last <= next);
}
last_min = next;
} else {
const next = queue.removeMax();
if (last_max) |last| {
- expect(last >= next);
+ try expect(last >= next);
}
last_max = next;
}
lib/std/priority_queue.zig
@@ -290,12 +290,12 @@ test "std.PriorityQueue: add and remove min heap" {
try queue.add(23);
try queue.add(25);
try queue.add(13);
- expectEqual(@as(u32, 7), queue.remove());
- expectEqual(@as(u32, 12), queue.remove());
- expectEqual(@as(u32, 13), queue.remove());
- expectEqual(@as(u32, 23), queue.remove());
- expectEqual(@as(u32, 25), queue.remove());
- expectEqual(@as(u32, 54), queue.remove());
+ try expectEqual(@as(u32, 7), queue.remove());
+ try expectEqual(@as(u32, 12), queue.remove());
+ try expectEqual(@as(u32, 13), queue.remove());
+ try expectEqual(@as(u32, 23), queue.remove());
+ try expectEqual(@as(u32, 25), queue.remove());
+ try expectEqual(@as(u32, 54), queue.remove());
}
test "std.PriorityQueue: add and remove same min heap" {
@@ -308,19 +308,19 @@ test "std.PriorityQueue: add and remove same min heap" {
try queue.add(2);
try queue.add(1);
try queue.add(1);
- expectEqual(@as(u32, 1), queue.remove());
- expectEqual(@as(u32, 1), queue.remove());
- expectEqual(@as(u32, 1), queue.remove());
- expectEqual(@as(u32, 1), queue.remove());
- expectEqual(@as(u32, 2), queue.remove());
- expectEqual(@as(u32, 2), queue.remove());
+ try expectEqual(@as(u32, 1), queue.remove());
+ try expectEqual(@as(u32, 1), queue.remove());
+ try expectEqual(@as(u32, 1), queue.remove());
+ try expectEqual(@as(u32, 1), queue.remove());
+ try expectEqual(@as(u32, 2), queue.remove());
+ try expectEqual(@as(u32, 2), queue.remove());
}
test "std.PriorityQueue: removeOrNull on empty" {
var queue = PQ.init(testing.allocator, lessThan);
defer queue.deinit();
- expect(queue.removeOrNull() == null);
+ try expect(queue.removeOrNull() == null);
}
test "std.PriorityQueue: edge case 3 elements" {
@@ -330,21 +330,21 @@ test "std.PriorityQueue: edge case 3 elements" {
try queue.add(9);
try queue.add(3);
try queue.add(2);
- expectEqual(@as(u32, 2), queue.remove());
- expectEqual(@as(u32, 3), queue.remove());
- expectEqual(@as(u32, 9), queue.remove());
+ try expectEqual(@as(u32, 2), queue.remove());
+ try expectEqual(@as(u32, 3), queue.remove());
+ try expectEqual(@as(u32, 9), queue.remove());
}
test "std.PriorityQueue: peek" {
var queue = PQ.init(testing.allocator, lessThan);
defer queue.deinit();
- expect(queue.peek() == null);
+ try expect(queue.peek() == null);
try queue.add(9);
try queue.add(3);
try queue.add(2);
- expectEqual(@as(u32, 2), queue.peek().?);
- expectEqual(@as(u32, 2), queue.peek().?);
+ try expectEqual(@as(u32, 2), queue.peek().?);
+ try expectEqual(@as(u32, 2), queue.peek().?);
}
test "std.PriorityQueue: sift up with odd indices" {
@@ -357,7 +357,7 @@ test "std.PriorityQueue: sift up with odd indices" {
const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
for (sorted_items) |e| {
- expectEqual(e, queue.remove());
+ try expectEqual(e, queue.remove());
}
}
@@ -369,7 +369,7 @@ test "std.PriorityQueue: addSlice" {
const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
for (sorted_items) |e| {
- expectEqual(e, queue.remove());
+ try expectEqual(e, queue.remove());
}
}
@@ -378,8 +378,8 @@ test "std.PriorityQueue: fromOwnedSlice trivial case 0" {
const queue_items = try testing.allocator.dupe(u32, &items);
var queue = PQ.fromOwnedSlice(testing.allocator, lessThan, queue_items[0..]);
defer queue.deinit();
- expectEqual(@as(usize, 0), queue.len);
- expect(queue.removeOrNull() == null);
+ try expectEqual(@as(usize, 0), queue.len);
+ try expect(queue.removeOrNull() == null);
}
test "std.PriorityQueue: fromOwnedSlice trivial case 1" {
@@ -388,9 +388,9 @@ test "std.PriorityQueue: fromOwnedSlice trivial case 1" {
var queue = PQ.fromOwnedSlice(testing.allocator, lessThan, queue_items[0..]);
defer queue.deinit();
- expectEqual(@as(usize, 1), queue.len);
- expectEqual(items[0], queue.remove());
- expect(queue.removeOrNull() == null);
+ try expectEqual(@as(usize, 1), queue.len);
+ try expectEqual(items[0], queue.remove());
+ try expect(queue.removeOrNull() == null);
}
test "std.PriorityQueue: fromOwnedSlice" {
@@ -401,7 +401,7 @@ test "std.PriorityQueue: fromOwnedSlice" {
const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
for (sorted_items) |e| {
- expectEqual(e, queue.remove());
+ try expectEqual(e, queue.remove());
}
}
@@ -415,12 +415,12 @@ test "std.PriorityQueue: add and remove max heap" {
try queue.add(23);
try queue.add(25);
try queue.add(13);
- expectEqual(@as(u32, 54), queue.remove());
- expectEqual(@as(u32, 25), queue.remove());
- expectEqual(@as(u32, 23), queue.remove());
- expectEqual(@as(u32, 13), queue.remove());
- expectEqual(@as(u32, 12), queue.remove());
- expectEqual(@as(u32, 7), queue.remove());
+ try expectEqual(@as(u32, 54), queue.remove());
+ try expectEqual(@as(u32, 25), queue.remove());
+ try expectEqual(@as(u32, 23), queue.remove());
+ try expectEqual(@as(u32, 13), queue.remove());
+ try expectEqual(@as(u32, 12), queue.remove());
+ try expectEqual(@as(u32, 7), queue.remove());
}
test "std.PriorityQueue: add and remove same max heap" {
@@ -433,12 +433,12 @@ test "std.PriorityQueue: add and remove same max heap" {
try queue.add(2);
try queue.add(1);
try queue.add(1);
- expectEqual(@as(u32, 2), queue.remove());
- expectEqual(@as(u32, 2), queue.remove());
- expectEqual(@as(u32, 1), queue.remove());
- expectEqual(@as(u32, 1), queue.remove());
- expectEqual(@as(u32, 1), queue.remove());
- expectEqual(@as(u32, 1), queue.remove());
+ try expectEqual(@as(u32, 2), queue.remove());
+ try expectEqual(@as(u32, 2), queue.remove());
+ try expectEqual(@as(u32, 1), queue.remove());
+ try expectEqual(@as(u32, 1), queue.remove());
+ try expectEqual(@as(u32, 1), queue.remove());
+ try expectEqual(@as(u32, 1), queue.remove());
}
test "std.PriorityQueue: iterator" {
@@ -460,7 +460,7 @@ test "std.PriorityQueue: iterator" {
_ = map.remove(e);
}
- expectEqual(@as(usize, 0), map.count());
+ try expectEqual(@as(usize, 0), map.count());
}
test "std.PriorityQueue: remove at index" {
@@ -480,10 +480,10 @@ test "std.PriorityQueue: remove at index" {
idx += 1;
} else unreachable;
- expectEqual(queue.removeIndex(two_idx), 2);
- expectEqual(queue.remove(), 1);
- expectEqual(queue.remove(), 3);
- expectEqual(queue.removeOrNull(), null);
+ try expectEqual(queue.removeIndex(two_idx), 2);
+ try expectEqual(queue.remove(), 1);
+ try expectEqual(queue.remove(), 3);
+ try expectEqual(queue.removeOrNull(), null);
}
test "std.PriorityQueue: iterator while empty" {
@@ -492,7 +492,7 @@ test "std.PriorityQueue: iterator while empty" {
var it = queue.iterator();
- expectEqual(it.next(), null);
+ try expectEqual(it.next(), null);
}
test "std.PriorityQueue: shrinkRetainingCapacity and shrinkAndFree" {
@@ -500,26 +500,26 @@ test "std.PriorityQueue: shrinkRetainingCapacity and shrinkAndFree" {
defer queue.deinit();
try queue.ensureCapacity(4);
- expect(queue.capacity() >= 4);
+ try expect(queue.capacity() >= 4);
try queue.add(1);
try queue.add(2);
try queue.add(3);
- expect(queue.capacity() >= 4);
- expectEqual(@as(usize, 3), queue.len);
+ try expect(queue.capacity() >= 4);
+ try expectEqual(@as(usize, 3), queue.len);
queue.shrinkRetainingCapacity(3);
- expect(queue.capacity() >= 4);
- expectEqual(@as(usize, 3), queue.len);
+ try expect(queue.capacity() >= 4);
+ try expectEqual(@as(usize, 3), queue.len);
queue.shrinkAndFree(3);
- expectEqual(@as(usize, 3), queue.capacity());
- expectEqual(@as(usize, 3), queue.len);
+ try expectEqual(@as(usize, 3), queue.capacity());
+ try expectEqual(@as(usize, 3), queue.len);
- expectEqual(@as(u32, 1), queue.remove());
- expectEqual(@as(u32, 2), queue.remove());
- expectEqual(@as(u32, 3), queue.remove());
- expect(queue.removeOrNull() == null);
+ try expectEqual(@as(u32, 1), queue.remove());
+ try expectEqual(@as(u32, 2), queue.remove());
+ try expectEqual(@as(u32, 3), queue.remove());
+ try expect(queue.removeOrNull() == null);
}
test "std.PriorityQueue: update min heap" {
@@ -532,9 +532,9 @@ test "std.PriorityQueue: update min heap" {
try queue.update(55, 5);
try queue.update(44, 4);
try queue.update(11, 1);
- expectEqual(@as(u32, 1), queue.remove());
- expectEqual(@as(u32, 4), queue.remove());
- expectEqual(@as(u32, 5), queue.remove());
+ try expectEqual(@as(u32, 1), queue.remove());
+ try expectEqual(@as(u32, 4), queue.remove());
+ try expectEqual(@as(u32, 5), queue.remove());
}
test "std.PriorityQueue: update same min heap" {
@@ -547,10 +547,10 @@ test "std.PriorityQueue: update same min heap" {
try queue.add(2);
try queue.update(1, 5);
try queue.update(2, 4);
- expectEqual(@as(u32, 1), queue.remove());
- expectEqual(@as(u32, 2), queue.remove());
- expectEqual(@as(u32, 4), queue.remove());
- expectEqual(@as(u32, 5), queue.remove());
+ try expectEqual(@as(u32, 1), queue.remove());
+ try expectEqual(@as(u32, 2), queue.remove());
+ try expectEqual(@as(u32, 4), queue.remove());
+ try expectEqual(@as(u32, 5), queue.remove());
}
test "std.PriorityQueue: update max heap" {
@@ -563,9 +563,9 @@ test "std.PriorityQueue: update max heap" {
try queue.update(55, 5);
try queue.update(44, 1);
try queue.update(11, 4);
- expectEqual(@as(u32, 5), queue.remove());
- expectEqual(@as(u32, 4), queue.remove());
- expectEqual(@as(u32, 1), queue.remove());
+ try expectEqual(@as(u32, 5), queue.remove());
+ try expectEqual(@as(u32, 4), queue.remove());
+ try expectEqual(@as(u32, 1), queue.remove());
}
test "std.PriorityQueue: update same max heap" {
@@ -578,8 +578,8 @@ test "std.PriorityQueue: update same max heap" {
try queue.add(2);
try queue.update(1, 5);
try queue.update(2, 4);
- expectEqual(@as(u32, 5), queue.remove());
- expectEqual(@as(u32, 4), queue.remove());
- expectEqual(@as(u32, 2), queue.remove());
- expectEqual(@as(u32, 1), queue.remove());
+ try expectEqual(@as(u32, 5), queue.remove());
+ try expectEqual(@as(u32, 4), queue.remove());
+ try expectEqual(@as(u32, 2), queue.remove());
+ try expectEqual(@as(u32, 1), queue.remove());
}
lib/std/process.zig
@@ -181,7 +181,7 @@ pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) GetEnvVarOwned
test "os.getEnvVarOwned" {
var ga = std.testing.allocator;
- testing.expectError(error.EnvironmentVariableNotFound, getEnvVarOwned(ga, "BADENV"));
+ try testing.expectError(error.EnvironmentVariableNotFound, getEnvVarOwned(ga, "BADENV"));
}
pub const ArgIteratorPosix = struct {
@@ -516,10 +516,10 @@ test "args iterator" {
};
const given_suffix = std.fs.path.basename(prog_name);
- testing.expect(mem.eql(u8, expected_suffix, given_suffix));
- testing.expect(it.skip()); // Skip over zig_exe_path, passed to the test runner
- testing.expect(it.next(ga) == null);
- testing.expect(!it.skip());
+ try testing.expect(mem.eql(u8, expected_suffix, given_suffix));
+ try testing.expect(it.skip()); // Skip over zig_exe_path, passed to the test runner
+ try testing.expect(it.next(ga) == null);
+ try testing.expect(!it.skip());
}
/// Caller must call argsFree on result.
@@ -575,14 +575,14 @@ pub fn argsFree(allocator: *mem.Allocator, args_alloc: []const [:0]u8) void {
test "windows arg parsing" {
const utf16Literal = std.unicode.utf8ToUtf16LeStringLiteral;
- testWindowsCmdLine(utf16Literal("a b\tc d"), &[_][]const u8{ "a", "b", "c", "d" });
- testWindowsCmdLine(utf16Literal("\"abc\" d e"), &[_][]const u8{ "abc", "d", "e" });
- testWindowsCmdLine(utf16Literal("a\\\\\\b d\"e f\"g h"), &[_][]const u8{ "a\\\\\\b", "de fg", "h" });
- testWindowsCmdLine(utf16Literal("a\\\\\\\"b c d"), &[_][]const u8{ "a\\\"b", "c", "d" });
- testWindowsCmdLine(utf16Literal("a\\\\\\\\\"b c\" d e"), &[_][]const u8{ "a\\\\b c", "d", "e" });
- testWindowsCmdLine(utf16Literal("a b\tc \"d f"), &[_][]const u8{ "a", "b", "c", "d f" });
-
- testWindowsCmdLine(utf16Literal("\".\\..\\zig-cache\\build\" \"bin\\zig.exe\" \".\\..\" \".\\..\\zig-cache\" \"--help\""), &[_][]const u8{
+ try testWindowsCmdLine(utf16Literal("a b\tc d"), &[_][]const u8{ "a", "b", "c", "d" });
+ try testWindowsCmdLine(utf16Literal("\"abc\" d e"), &[_][]const u8{ "abc", "d", "e" });
+ try testWindowsCmdLine(utf16Literal("a\\\\\\b d\"e f\"g h"), &[_][]const u8{ "a\\\\\\b", "de fg", "h" });
+ try testWindowsCmdLine(utf16Literal("a\\\\\\\"b c d"), &[_][]const u8{ "a\\\"b", "c", "d" });
+ try testWindowsCmdLine(utf16Literal("a\\\\\\\\\"b c\" d e"), &[_][]const u8{ "a\\\\b c", "d", "e" });
+ try testWindowsCmdLine(utf16Literal("a b\tc \"d f"), &[_][]const u8{ "a", "b", "c", "d f" });
+
+ try testWindowsCmdLine(utf16Literal("\".\\..\\zig-cache\\build\" \"bin\\zig.exe\" \".\\..\" \".\\..\\zig-cache\" \"--help\""), &[_][]const u8{
".\\..\\zig-cache\\build",
"bin\\zig.exe",
".\\..",
@@ -591,14 +591,14 @@ test "windows arg parsing" {
});
}
-fn testWindowsCmdLine(input_cmd_line: [*]const u16, expected_args: []const []const u8) void {
+fn testWindowsCmdLine(input_cmd_line: [*]const u16, expected_args: []const []const u8) !void {
var it = ArgIteratorWindows.initWithCmdLine(input_cmd_line);
for (expected_args) |expected_arg| {
const arg = it.next(std.testing.allocator).? catch unreachable;
defer std.testing.allocator.free(arg);
- testing.expectEqualStrings(expected_arg, arg);
+ try testing.expectEqualStrings(expected_arg, arg);
}
- testing.expect(it.next(std.testing.allocator) == null);
+ try testing.expect(it.next(std.testing.allocator) == null);
}
pub const UserInfo = struct {
lib/std/rand.zig
@@ -319,139 +319,139 @@ const SequentialPrng = struct {
};
test "Random int" {
- testRandomInt();
- comptime testRandomInt();
+ try testRandomInt();
+ comptime try testRandomInt();
}
-fn testRandomInt() void {
+fn testRandomInt() !void {
var r = SequentialPrng.init();
- expect(r.random.int(u0) == 0);
+ try expect(r.random.int(u0) == 0);
r.next_value = 0;
- expect(r.random.int(u1) == 0);
- expect(r.random.int(u1) == 1);
- expect(r.random.int(u2) == 2);
- expect(r.random.int(u2) == 3);
- expect(r.random.int(u2) == 0);
+ try expect(r.random.int(u1) == 0);
+ try expect(r.random.int(u1) == 1);
+ try expect(r.random.int(u2) == 2);
+ try expect(r.random.int(u2) == 3);
+ try expect(r.random.int(u2) == 0);
r.next_value = 0xff;
- expect(r.random.int(u8) == 0xff);
+ try expect(r.random.int(u8) == 0xff);
r.next_value = 0x11;
- expect(r.random.int(u8) == 0x11);
+ try expect(r.random.int(u8) == 0x11);
r.next_value = 0xff;
- expect(r.random.int(u32) == 0xffffffff);
+ try expect(r.random.int(u32) == 0xffffffff);
r.next_value = 0x11;
- expect(r.random.int(u32) == 0x11111111);
+ try expect(r.random.int(u32) == 0x11111111);
r.next_value = 0xff;
- expect(r.random.int(i32) == -1);
+ try expect(r.random.int(i32) == -1);
r.next_value = 0x11;
- expect(r.random.int(i32) == 0x11111111);
+ try expect(r.random.int(i32) == 0x11111111);
r.next_value = 0xff;
- expect(r.random.int(i8) == -1);
+ try expect(r.random.int(i8) == -1);
r.next_value = 0x11;
- expect(r.random.int(i8) == 0x11);
+ try expect(r.random.int(i8) == 0x11);
r.next_value = 0xff;
- expect(r.random.int(u33) == 0x1ffffffff);
+ try expect(r.random.int(u33) == 0x1ffffffff);
r.next_value = 0xff;
- expect(r.random.int(i1) == -1);
+ try expect(r.random.int(i1) == -1);
r.next_value = 0xff;
- expect(r.random.int(i2) == -1);
+ try expect(r.random.int(i2) == -1);
r.next_value = 0xff;
- expect(r.random.int(i33) == -1);
+ try expect(r.random.int(i33) == -1);
}
test "Random boolean" {
- testRandomBoolean();
- comptime testRandomBoolean();
+ try testRandomBoolean();
+ comptime try testRandomBoolean();
}
-fn testRandomBoolean() void {
+fn testRandomBoolean() !void {
var r = SequentialPrng.init();
- expect(r.random.boolean() == false);
- expect(r.random.boolean() == true);
- expect(r.random.boolean() == false);
- expect(r.random.boolean() == true);
+ try expect(r.random.boolean() == false);
+ try expect(r.random.boolean() == true);
+ try expect(r.random.boolean() == false);
+ try expect(r.random.boolean() == true);
}
test "Random intLessThan" {
@setEvalBranchQuota(10000);
- testRandomIntLessThan();
- comptime testRandomIntLessThan();
+ try testRandomIntLessThan();
+ comptime try testRandomIntLessThan();
}
-fn testRandomIntLessThan() void {
+fn testRandomIntLessThan() !void {
var r = SequentialPrng.init();
r.next_value = 0xff;
- expect(r.random.uintLessThan(u8, 4) == 3);
- expect(r.next_value == 0);
- expect(r.random.uintLessThan(u8, 4) == 0);
- expect(r.next_value == 1);
+ try expect(r.random.uintLessThan(u8, 4) == 3);
+ try expect(r.next_value == 0);
+ try expect(r.random.uintLessThan(u8, 4) == 0);
+ try expect(r.next_value == 1);
r.next_value = 0;
- expect(r.random.uintLessThan(u64, 32) == 0);
+ try expect(r.random.uintLessThan(u64, 32) == 0);
// trigger the bias rejection code path
r.next_value = 0;
- expect(r.random.uintLessThan(u8, 3) == 0);
+ try expect(r.random.uintLessThan(u8, 3) == 0);
// verify we incremented twice
- expect(r.next_value == 2);
+ try expect(r.next_value == 2);
r.next_value = 0xff;
- expect(r.random.intRangeLessThan(u8, 0, 0x80) == 0x7f);
+ try expect(r.random.intRangeLessThan(u8, 0, 0x80) == 0x7f);
r.next_value = 0xff;
- expect(r.random.intRangeLessThan(u8, 0x7f, 0xff) == 0xfe);
+ try expect(r.random.intRangeLessThan(u8, 0x7f, 0xff) == 0xfe);
r.next_value = 0xff;
- expect(r.random.intRangeLessThan(i8, 0, 0x40) == 0x3f);
+ try expect(r.random.intRangeLessThan(i8, 0, 0x40) == 0x3f);
r.next_value = 0xff;
- expect(r.random.intRangeLessThan(i8, -0x40, 0x40) == 0x3f);
+ try expect(r.random.intRangeLessThan(i8, -0x40, 0x40) == 0x3f);
r.next_value = 0xff;
- expect(r.random.intRangeLessThan(i8, -0x80, 0) == -1);
+ try expect(r.random.intRangeLessThan(i8, -0x80, 0) == -1);
r.next_value = 0xff;
- expect(r.random.intRangeLessThan(i3, -4, 0) == -1);
+ try expect(r.random.intRangeLessThan(i3, -4, 0) == -1);
r.next_value = 0xff;
- expect(r.random.intRangeLessThan(i3, -2, 2) == 1);
+ try expect(r.random.intRangeLessThan(i3, -2, 2) == 1);
}
test "Random intAtMost" {
@setEvalBranchQuota(10000);
- testRandomIntAtMost();
- comptime testRandomIntAtMost();
+ try testRandomIntAtMost();
+ comptime try testRandomIntAtMost();
}
-fn testRandomIntAtMost() void {
+fn testRandomIntAtMost() !void {
var r = SequentialPrng.init();
r.next_value = 0xff;
- expect(r.random.uintAtMost(u8, 3) == 3);
- expect(r.next_value == 0);
- expect(r.random.uintAtMost(u8, 3) == 0);
+ try expect(r.random.uintAtMost(u8, 3) == 3);
+ try expect(r.next_value == 0);
+ try expect(r.random.uintAtMost(u8, 3) == 0);
// trigger the bias rejection code path
r.next_value = 0;
- expect(r.random.uintAtMost(u8, 2) == 0);
+ try expect(r.random.uintAtMost(u8, 2) == 0);
// verify we incremented twice
- expect(r.next_value == 2);
+ try expect(r.next_value == 2);
r.next_value = 0xff;
- expect(r.random.intRangeAtMost(u8, 0, 0x7f) == 0x7f);
+ try expect(r.random.intRangeAtMost(u8, 0, 0x7f) == 0x7f);
r.next_value = 0xff;
- expect(r.random.intRangeAtMost(u8, 0x7f, 0xfe) == 0xfe);
+ try expect(r.random.intRangeAtMost(u8, 0x7f, 0xfe) == 0xfe);
r.next_value = 0xff;
- expect(r.random.intRangeAtMost(i8, 0, 0x3f) == 0x3f);
+ try expect(r.random.intRangeAtMost(i8, 0, 0x3f) == 0x3f);
r.next_value = 0xff;
- expect(r.random.intRangeAtMost(i8, -0x40, 0x3f) == 0x3f);
+ try expect(r.random.intRangeAtMost(i8, -0x40, 0x3f) == 0x3f);
r.next_value = 0xff;
- expect(r.random.intRangeAtMost(i8, -0x80, -1) == -1);
+ try expect(r.random.intRangeAtMost(i8, -0x80, -1) == -1);
r.next_value = 0xff;
- expect(r.random.intRangeAtMost(i3, -4, -1) == -1);
+ try expect(r.random.intRangeAtMost(i3, -4, -1) == -1);
r.next_value = 0xff;
- expect(r.random.intRangeAtMost(i3, -2, 1) == 1);
+ try expect(r.random.intRangeAtMost(i3, -2, 1) == 1);
- expect(r.random.uintAtMost(u0, 0) == 0);
+ try expect(r.random.uintAtMost(u0, 0) == 0);
}
test "Random Biased" {
@@ -459,30 +459,30 @@ test "Random Biased" {
// Not thoroughly checking the logic here.
// Just want to execute all the paths with different types.
- expect(r.random.uintLessThanBiased(u1, 1) == 0);
- expect(r.random.uintLessThanBiased(u32, 10) < 10);
- expect(r.random.uintLessThanBiased(u64, 20) < 20);
+ try expect(r.random.uintLessThanBiased(u1, 1) == 0);
+ try expect(r.random.uintLessThanBiased(u32, 10) < 10);
+ try expect(r.random.uintLessThanBiased(u64, 20) < 20);
- expect(r.random.uintAtMostBiased(u0, 0) == 0);
- expect(r.random.uintAtMostBiased(u1, 0) <= 0);
- expect(r.random.uintAtMostBiased(u32, 10) <= 10);
- expect(r.random.uintAtMostBiased(u64, 20) <= 20);
+ try expect(r.random.uintAtMostBiased(u0, 0) == 0);
+ try expect(r.random.uintAtMostBiased(u1, 0) <= 0);
+ try expect(r.random.uintAtMostBiased(u32, 10) <= 10);
+ try expect(r.random.uintAtMostBiased(u64, 20) <= 20);
- expect(r.random.intRangeLessThanBiased(u1, 0, 1) == 0);
- expect(r.random.intRangeLessThanBiased(i1, -1, 0) == -1);
- expect(r.random.intRangeLessThanBiased(u32, 10, 20) >= 10);
- expect(r.random.intRangeLessThanBiased(i32, 10, 20) >= 10);
- expect(r.random.intRangeLessThanBiased(u64, 20, 40) >= 20);
- expect(r.random.intRangeLessThanBiased(i64, 20, 40) >= 20);
+ try expect(r.random.intRangeLessThanBiased(u1, 0, 1) == 0);
+ try expect(r.random.intRangeLessThanBiased(i1, -1, 0) == -1);
+ try expect(r.random.intRangeLessThanBiased(u32, 10, 20) >= 10);
+ try expect(r.random.intRangeLessThanBiased(i32, 10, 20) >= 10);
+ try expect(r.random.intRangeLessThanBiased(u64, 20, 40) >= 20);
+ try expect(r.random.intRangeLessThanBiased(i64, 20, 40) >= 20);
// uncomment for broken module error:
//expect(r.random.intRangeAtMostBiased(u0, 0, 0) == 0);
- expect(r.random.intRangeAtMostBiased(u1, 0, 1) >= 0);
- expect(r.random.intRangeAtMostBiased(i1, -1, 0) >= -1);
- expect(r.random.intRangeAtMostBiased(u32, 10, 20) >= 10);
- expect(r.random.intRangeAtMostBiased(i32, 10, 20) >= 10);
- expect(r.random.intRangeAtMostBiased(u64, 20, 40) >= 20);
- expect(r.random.intRangeAtMostBiased(i64, 20, 40) >= 20);
+ try expect(r.random.intRangeAtMostBiased(u1, 0, 1) >= 0);
+ try expect(r.random.intRangeAtMostBiased(i1, -1, 0) >= -1);
+ try expect(r.random.intRangeAtMostBiased(u32, 10, 20) >= 10);
+ try expect(r.random.intRangeAtMostBiased(i32, 10, 20) >= 10);
+ try expect(r.random.intRangeAtMostBiased(u64, 20, 40) >= 20);
+ try expect(r.random.intRangeAtMostBiased(i64, 20, 40) >= 20);
}
// Generator to extend 64-bit seed values into longer sequences.
@@ -519,7 +519,7 @@ test "splitmix64 sequence" {
};
for (seq) |s| {
- expect(s == r.next());
+ try expect(s == r.next());
}
}
@@ -530,12 +530,12 @@ test "Random float" {
var i: usize = 0;
while (i < 1000) : (i += 1) {
const val1 = prng.random.float(f32);
- expect(val1 >= 0.0);
- expect(val1 < 1.0);
+ try expect(val1 >= 0.0);
+ try expect(val1 < 1.0);
const val2 = prng.random.float(f64);
- expect(val2 >= 0.0);
- expect(val2 < 1.0);
+ try expect(val2 >= 0.0);
+ try expect(val2 < 1.0);
}
}
@@ -549,12 +549,12 @@ test "Random shuffle" {
while (i < 1000) : (i += 1) {
prng.random.shuffle(u8, seq[0..]);
seen[seq[0]] = true;
- expect(sumArray(seq[0..]) == 10);
+ try expect(sumArray(seq[0..]) == 10);
}
// we should see every entry at the head at least once
for (seen) |e| {
- expect(e == true);
+ try expect(e == true);
}
}
@@ -567,17 +567,17 @@ fn sumArray(s: []const u8) u32 {
test "Random range" {
var prng = DefaultPrng.init(0);
- testRange(&prng.random, -4, 3);
- testRange(&prng.random, -4, -1);
- testRange(&prng.random, 10, 14);
- testRange(&prng.random, -0x80, 0x7f);
+ try testRange(&prng.random, -4, 3);
+ try testRange(&prng.random, -4, -1);
+ try testRange(&prng.random, 10, 14);
+ try testRange(&prng.random, -0x80, 0x7f);
}
-fn testRange(r: *Random, start: i8, end: i8) void {
- testRangeBias(r, start, end, true);
- testRangeBias(r, start, end, false);
+fn testRange(r: *Random, start: i8, end: i8) !void {
+ try testRangeBias(r, start, end, true);
+ try testRangeBias(r, start, end, false);
}
-fn testRangeBias(r: *Random, start: i8, end: i8, biased: bool) void {
+fn testRangeBias(r: *Random, start: i8, end: i8, biased: bool) !void {
const count = @intCast(usize, @as(i32, end) - @as(i32, start));
var values_buffer = [_]bool{false} ** 0x100;
const values = values_buffer[0..count];
@@ -599,7 +599,7 @@ test "CSPRNG" {
const a = csprng.random.int(u64);
const b = csprng.random.int(u64);
const c = csprng.random.int(u64);
- expect(a ^ b ^ c != 0);
+ try expect(a ^ b ^ c != 0);
}
test {
lib/std/SemanticVersion.zig
@@ -249,13 +249,13 @@ test "SemanticVersion format" {
"+justmeta",
"9.8.7+meta+meta",
"9.8.7-whatever+meta+meta",
- }) |invalid| expectError(error.InvalidVersion, parse(invalid));
+ }) |invalid| try expectError(error.InvalidVersion, parse(invalid));
// Valid version string that may overflow.
const big_valid = "99999999999999999999999.999999999999999999.99999999999999999";
if (parse(big_valid)) |ver| {
try std.testing.expectFmt(big_valid, "{}", .{ver});
- } else |err| expect(err == error.Overflow);
+ } else |err| try expect(err == error.Overflow);
// Invalid version string that may overflow.
const big_invalid = "99999999999999999999999.999999999999999999.99999999999999999----RC-SNAPSHOT.12.09.1--------------------------------..12";
@@ -264,22 +264,22 @@ test "SemanticVersion format" {
test "SemanticVersion precedence" {
// SemVer 2 spec 11.2 example: 1.0.0 < 2.0.0 < 2.1.0 < 2.1.1.
- expect(order(try parse("1.0.0"), try parse("2.0.0")) == .lt);
- expect(order(try parse("2.0.0"), try parse("2.1.0")) == .lt);
- expect(order(try parse("2.1.0"), try parse("2.1.1")) == .lt);
+ try expect(order(try parse("1.0.0"), try parse("2.0.0")) == .lt);
+ try expect(order(try parse("2.0.0"), try parse("2.1.0")) == .lt);
+ try expect(order(try parse("2.1.0"), try parse("2.1.1")) == .lt);
// SemVer 2 spec 11.3 example: 1.0.0-alpha < 1.0.0.
- expect(order(try parse("1.0.0-alpha"), try parse("1.0.0")) == .lt);
+ try expect(order(try parse("1.0.0-alpha"), try parse("1.0.0")) == .lt);
// SemVer 2 spec 11.4 example: 1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta < 1.0.0-beta <
// 1.0.0-beta.2 < 1.0.0-beta.11 < 1.0.0-rc.1 < 1.0.0.
- expect(order(try parse("1.0.0-alpha"), try parse("1.0.0-alpha.1")) == .lt);
- expect(order(try parse("1.0.0-alpha.1"), try parse("1.0.0-alpha.beta")) == .lt);
- expect(order(try parse("1.0.0-alpha.beta"), try parse("1.0.0-beta")) == .lt);
- expect(order(try parse("1.0.0-beta"), try parse("1.0.0-beta.2")) == .lt);
- expect(order(try parse("1.0.0-beta.2"), try parse("1.0.0-beta.11")) == .lt);
- expect(order(try parse("1.0.0-beta.11"), try parse("1.0.0-rc.1")) == .lt);
- expect(order(try parse("1.0.0-rc.1"), try parse("1.0.0")) == .lt);
+ try expect(order(try parse("1.0.0-alpha"), try parse("1.0.0-alpha.1")) == .lt);
+ try expect(order(try parse("1.0.0-alpha.1"), try parse("1.0.0-alpha.beta")) == .lt);
+ try expect(order(try parse("1.0.0-alpha.beta"), try parse("1.0.0-beta")) == .lt);
+ try expect(order(try parse("1.0.0-beta"), try parse("1.0.0-beta.2")) == .lt);
+ try expect(order(try parse("1.0.0-beta.2"), try parse("1.0.0-beta.11")) == .lt);
+ try expect(order(try parse("1.0.0-beta.11"), try parse("1.0.0-rc.1")) == .lt);
+ try expect(order(try parse("1.0.0-rc.1"), try parse("1.0.0")) == .lt);
}
test "zig_version" {
lib/std/sort.zig
@@ -43,35 +43,35 @@ test "binarySearch" {
return math.order(lhs, rhs);
}
};
- testing.expectEqual(
+ try testing.expectEqual(
@as(?usize, null),
binarySearch(u32, 1, &[_]u32{}, {}, S.order_u32),
);
- testing.expectEqual(
+ try testing.expectEqual(
@as(?usize, 0),
binarySearch(u32, 1, &[_]u32{1}, {}, S.order_u32),
);
- testing.expectEqual(
+ try testing.expectEqual(
@as(?usize, null),
binarySearch(u32, 1, &[_]u32{0}, {}, S.order_u32),
);
- testing.expectEqual(
+ try testing.expectEqual(
@as(?usize, null),
binarySearch(u32, 0, &[_]u32{1}, {}, S.order_u32),
);
- testing.expectEqual(
+ try testing.expectEqual(
@as(?usize, 4),
binarySearch(u32, 5, &[_]u32{ 1, 2, 3, 4, 5 }, {}, S.order_u32),
);
- testing.expectEqual(
+ try testing.expectEqual(
@as(?usize, 0),
binarySearch(u32, 2, &[_]u32{ 2, 4, 8, 16, 32, 64 }, {}, S.order_u32),
);
- testing.expectEqual(
+ try testing.expectEqual(
@as(?usize, 1),
binarySearch(i32, -4, &[_]i32{ -7, -4, 0, 9, 10 }, {}, S.order_i32),
);
- testing.expectEqual(
+ try testing.expectEqual(
@as(?usize, 3),
binarySearch(i32, 98, &[_]i32{ -100, -25, 2, 98, 99, 100 }, {}, S.order_i32),
);
@@ -1152,10 +1152,10 @@ pub fn desc(comptime T: type) fn (void, T, T) bool {
}
test "stable sort" {
- testStableSort();
- comptime testStableSort();
+ try testStableSort();
+ comptime try testStableSort();
}
-fn testStableSort() void {
+fn testStableSort() !void {
var expected = [_]IdAndValue{
IdAndValue{ .id = 0, .value = 0 },
IdAndValue{ .id = 1, .value = 0 },
@@ -1194,8 +1194,8 @@ fn testStableSort() void {
for (cases) |*case| {
insertionSort(IdAndValue, (case.*)[0..], {}, cmpByValue);
for (case.*) |item, i| {
- testing.expect(item.id == expected[i].id);
- testing.expect(item.value == expected[i].value);
+ try testing.expect(item.id == expected[i].id);
+ try testing.expect(item.value == expected[i].value);
}
}
}
@@ -1245,7 +1245,7 @@ test "sort" {
const slice = buf[0..case[0].len];
mem.copy(u8, slice, case[0]);
sort(u8, slice, {}, asc_u8);
- testing.expect(mem.eql(u8, slice, case[1]));
+ try testing.expect(mem.eql(u8, slice, case[1]));
}
const i32cases = [_][]const []const i32{
@@ -1280,7 +1280,7 @@ test "sort" {
const slice = buf[0..case[0].len];
mem.copy(i32, slice, case[0]);
sort(i32, slice, {}, asc_i32);
- testing.expect(mem.eql(i32, slice, case[1]));
+ try testing.expect(mem.eql(i32, slice, case[1]));
}
}
@@ -1317,7 +1317,7 @@ test "sort descending" {
const slice = buf[0..case[0].len];
mem.copy(i32, slice, case[0]);
sort(i32, slice, {}, desc_i32);
- testing.expect(mem.eql(i32, slice, case[1]));
+ try testing.expect(mem.eql(i32, slice, case[1]));
}
}
@@ -1325,7 +1325,7 @@ test "another sort case" {
var arr = [_]i32{ 5, 3, 1, 2, 4 };
sort(i32, arr[0..], {}, asc_i32);
- testing.expect(mem.eql(i32, &arr, &[_]i32{ 1, 2, 3, 4, 5 }));
+ try testing.expect(mem.eql(i32, &arr, &[_]i32{ 1, 2, 3, 4, 5 }));
}
test "sort fuzz testing" {
@@ -1353,9 +1353,9 @@ fn fuzzTest(rng: *std.rand.Random) !void {
var index: usize = 1;
while (index < array.len) : (index += 1) {
if (array[index].value == array[index - 1].value) {
- testing.expect(array[index].id > array[index - 1].id);
+ try testing.expect(array[index].id > array[index - 1].id);
} else {
- testing.expect(array[index].value > array[index - 1].value);
+ try testing.expect(array[index].value > array[index - 1].value);
}
}
}
@@ -1383,13 +1383,13 @@ pub fn argMin(
}
test "argMin" {
- testing.expectEqual(@as(?usize, null), argMin(i32, &[_]i32{}, {}, asc_i32));
- testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{1}, {}, asc_i32));
- testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));
- testing.expectEqual(@as(?usize, 3), argMin(i32, &[_]i32{ 9, 3, 8, 2, 5 }, {}, asc_i32));
- testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32));
- testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{ -10, 1, 10 }, {}, asc_i32));
- testing.expectEqual(@as(?usize, 3), argMin(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32));
+ try testing.expectEqual(@as(?usize, null), argMin(i32, &[_]i32{}, {}, asc_i32));
+ try testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{1}, {}, asc_i32));
+ try testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));
+ try testing.expectEqual(@as(?usize, 3), argMin(i32, &[_]i32{ 9, 3, 8, 2, 5 }, {}, asc_i32));
+ try testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32));
+ try testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{ -10, 1, 10 }, {}, asc_i32));
+ try testing.expectEqual(@as(?usize, 3), argMin(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32));
}
pub fn min(
@@ -1403,13 +1403,13 @@ pub fn min(
}
test "min" {
- testing.expectEqual(@as(?i32, null), min(i32, &[_]i32{}, {}, asc_i32));
- testing.expectEqual(@as(?i32, 1), min(i32, &[_]i32{1}, {}, asc_i32));
- testing.expectEqual(@as(?i32, 1), min(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));
- testing.expectEqual(@as(?i32, 2), min(i32, &[_]i32{ 9, 3, 8, 2, 5 }, {}, asc_i32));
- testing.expectEqual(@as(?i32, 1), min(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32));
- testing.expectEqual(@as(?i32, -10), min(i32, &[_]i32{ -10, 1, 10 }, {}, asc_i32));
- testing.expectEqual(@as(?i32, 7), min(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32));
+ try testing.expectEqual(@as(?i32, null), min(i32, &[_]i32{}, {}, asc_i32));
+ try testing.expectEqual(@as(?i32, 1), min(i32, &[_]i32{1}, {}, asc_i32));
+ try testing.expectEqual(@as(?i32, 1), min(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));
+ try testing.expectEqual(@as(?i32, 2), min(i32, &[_]i32{ 9, 3, 8, 2, 5 }, {}, asc_i32));
+ try testing.expectEqual(@as(?i32, 1), min(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32));
+ try testing.expectEqual(@as(?i32, -10), min(i32, &[_]i32{ -10, 1, 10 }, {}, asc_i32));
+ try testing.expectEqual(@as(?i32, 7), min(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32));
}
pub fn argMax(
@@ -1435,13 +1435,13 @@ pub fn argMax(
}
test "argMax" {
- testing.expectEqual(@as(?usize, null), argMax(i32, &[_]i32{}, {}, asc_i32));
- testing.expectEqual(@as(?usize, 0), argMax(i32, &[_]i32{1}, {}, asc_i32));
- testing.expectEqual(@as(?usize, 4), argMax(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));
- testing.expectEqual(@as(?usize, 0), argMax(i32, &[_]i32{ 9, 3, 8, 2, 5 }, {}, asc_i32));
- testing.expectEqual(@as(?usize, 0), argMax(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32));
- testing.expectEqual(@as(?usize, 2), argMax(i32, &[_]i32{ -10, 1, 10 }, {}, asc_i32));
- testing.expectEqual(@as(?usize, 1), argMax(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32));
+ try testing.expectEqual(@as(?usize, null), argMax(i32, &[_]i32{}, {}, asc_i32));
+ try testing.expectEqual(@as(?usize, 0), argMax(i32, &[_]i32{1}, {}, asc_i32));
+ try testing.expectEqual(@as(?usize, 4), argMax(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));
+ try testing.expectEqual(@as(?usize, 0), argMax(i32, &[_]i32{ 9, 3, 8, 2, 5 }, {}, asc_i32));
+ try testing.expectEqual(@as(?usize, 0), argMax(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32));
+ try testing.expectEqual(@as(?usize, 2), argMax(i32, &[_]i32{ -10, 1, 10 }, {}, asc_i32));
+ try testing.expectEqual(@as(?usize, 1), argMax(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32));
}
pub fn max(
@@ -1455,13 +1455,13 @@ pub fn max(
}
test "max" {
- testing.expectEqual(@as(?i32, null), max(i32, &[_]i32{}, {}, asc_i32));
- testing.expectEqual(@as(?i32, 1), max(i32, &[_]i32{1}, {}, asc_i32));
- testing.expectEqual(@as(?i32, 5), max(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));
- testing.expectEqual(@as(?i32, 9), max(i32, &[_]i32{ 9, 3, 8, 2, 5 }, {}, asc_i32));
- testing.expectEqual(@as(?i32, 1), max(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32));
- testing.expectEqual(@as(?i32, 10), max(i32, &[_]i32{ -10, 1, 10 }, {}, asc_i32));
- testing.expectEqual(@as(?i32, 3), max(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32));
+ try testing.expectEqual(@as(?i32, null), max(i32, &[_]i32{}, {}, asc_i32));
+ try testing.expectEqual(@as(?i32, 1), max(i32, &[_]i32{1}, {}, asc_i32));
+ try testing.expectEqual(@as(?i32, 5), max(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));
+ try testing.expectEqual(@as(?i32, 9), max(i32, &[_]i32{ 9, 3, 8, 2, 5 }, {}, asc_i32));
+ try testing.expectEqual(@as(?i32, 1), max(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32));
+ try testing.expectEqual(@as(?i32, 10), max(i32, &[_]i32{ -10, 1, 10 }, {}, asc_i32));
+ try testing.expectEqual(@as(?i32, 3), max(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32));
}
pub fn isSorted(
@@ -1481,28 +1481,28 @@ pub fn isSorted(
}
test "isSorted" {
- testing.expect(isSorted(i32, &[_]i32{}, {}, asc_i32));
- testing.expect(isSorted(i32, &[_]i32{10}, {}, asc_i32));
- testing.expect(isSorted(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));
- testing.expect(isSorted(i32, &[_]i32{ -10, 1, 1, 1, 10 }, {}, asc_i32));
+ try testing.expect(isSorted(i32, &[_]i32{}, {}, asc_i32));
+ try testing.expect(isSorted(i32, &[_]i32{10}, {}, asc_i32));
+ try testing.expect(isSorted(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));
+ try testing.expect(isSorted(i32, &[_]i32{ -10, 1, 1, 1, 10 }, {}, asc_i32));
- testing.expect(isSorted(i32, &[_]i32{}, {}, desc_i32));
- testing.expect(isSorted(i32, &[_]i32{-20}, {}, desc_i32));
- testing.expect(isSorted(i32, &[_]i32{ 3, 2, 1, 0, -1 }, {}, desc_i32));
- testing.expect(isSorted(i32, &[_]i32{ 10, -10 }, {}, desc_i32));
+ try testing.expect(isSorted(i32, &[_]i32{}, {}, desc_i32));
+ try testing.expect(isSorted(i32, &[_]i32{-20}, {}, desc_i32));
+ try testing.expect(isSorted(i32, &[_]i32{ 3, 2, 1, 0, -1 }, {}, desc_i32));
+ try testing.expect(isSorted(i32, &[_]i32{ 10, -10 }, {}, desc_i32));
- testing.expect(isSorted(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32));
- testing.expect(isSorted(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, desc_i32));
+ try testing.expect(isSorted(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32));
+ try testing.expect(isSorted(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, desc_i32));
- testing.expectEqual(false, isSorted(i32, &[_]i32{ 5, 4, 3, 2, 1 }, {}, asc_i32));
- testing.expectEqual(false, isSorted(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, desc_i32));
+ try testing.expectEqual(false, isSorted(i32, &[_]i32{ 5, 4, 3, 2, 1 }, {}, asc_i32));
+ try testing.expectEqual(false, isSorted(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, desc_i32));
- testing.expect(isSorted(u8, "abcd", {}, asc_u8));
- testing.expect(isSorted(u8, "zyxw", {}, desc_u8));
+ try testing.expect(isSorted(u8, "abcd", {}, asc_u8));
+ try testing.expect(isSorted(u8, "zyxw", {}, desc_u8));
- testing.expectEqual(false, isSorted(u8, "abcd", {}, desc_u8));
- testing.expectEqual(false, isSorted(u8, "zyxw", {}, asc_u8));
+ try testing.expectEqual(false, isSorted(u8, "abcd", {}, desc_u8));
+ try testing.expectEqual(false, isSorted(u8, "zyxw", {}, asc_u8));
- testing.expect(isSorted(u8, "ffff", {}, asc_u8));
- testing.expect(isSorted(u8, "ffff", {}, desc_u8));
+ try testing.expect(isSorted(u8, "ffff", {}, asc_u8));
+ try testing.expect(isSorted(u8, "ffff", {}, desc_u8));
}
lib/std/time.zig
@@ -271,7 +271,7 @@ test "timestamp" {
sleep(ns_per_ms);
const time_1 = milliTimestamp();
const interval = time_1 - time_0;
- testing.expect(interval > 0);
+ try testing.expect(interval > 0);
// Tests should not depend on timings: skip test if outside margin.
if (!(interval < margin)) return error.SkipZigTest;
}
@@ -282,13 +282,13 @@ test "Timer" {
var timer = try Timer.start();
sleep(10 * ns_per_ms);
const time_0 = timer.read();
- testing.expect(time_0 > 0);
+ try testing.expect(time_0 > 0);
// Tests should not depend on timings: skip test if outside margin.
if (!(time_0 < margin)) return error.SkipZigTest;
const time_1 = timer.lap();
- testing.expect(time_1 >= time_0);
+ try testing.expect(time_1 >= time_0);
timer.reset();
- testing.expect(timer.read() < time_1);
+ try testing.expect(timer.read() < time_1);
}
lib/std/unicode.zig
@@ -336,224 +336,224 @@ pub const Utf16LeIterator = struct {
};
test "utf8 encode" {
- comptime testUtf8Encode() catch unreachable;
+ comptime try testUtf8Encode();
try testUtf8Encode();
}
fn testUtf8Encode() !void {
// A few taken from wikipedia a few taken elsewhere
var array: [4]u8 = undefined;
- testing.expect((try utf8Encode(try utf8Decode("€"), array[0..])) == 3);
- testing.expect(array[0] == 0b11100010);
- testing.expect(array[1] == 0b10000010);
- testing.expect(array[2] == 0b10101100);
+ try testing.expect((try utf8Encode(try utf8Decode("€"), array[0..])) == 3);
+ try testing.expect(array[0] == 0b11100010);
+ try testing.expect(array[1] == 0b10000010);
+ try testing.expect(array[2] == 0b10101100);
- testing.expect((try utf8Encode(try utf8Decode("$"), array[0..])) == 1);
- testing.expect(array[0] == 0b00100100);
+ try testing.expect((try utf8Encode(try utf8Decode("$"), array[0..])) == 1);
+ try testing.expect(array[0] == 0b00100100);
- testing.expect((try utf8Encode(try utf8Decode("¢"), array[0..])) == 2);
- testing.expect(array[0] == 0b11000010);
- testing.expect(array[1] == 0b10100010);
+ try testing.expect((try utf8Encode(try utf8Decode("¢"), array[0..])) == 2);
+ try testing.expect(array[0] == 0b11000010);
+ try testing.expect(array[1] == 0b10100010);
- testing.expect((try utf8Encode(try utf8Decode("𐍈"), array[0..])) == 4);
- testing.expect(array[0] == 0b11110000);
- testing.expect(array[1] == 0b10010000);
- testing.expect(array[2] == 0b10001101);
- testing.expect(array[3] == 0b10001000);
+ try testing.expect((try utf8Encode(try utf8Decode("𐍈"), array[0..])) == 4);
+ try testing.expect(array[0] == 0b11110000);
+ try testing.expect(array[1] == 0b10010000);
+ try testing.expect(array[2] == 0b10001101);
+ try testing.expect(array[3] == 0b10001000);
}
test "utf8 encode error" {
- comptime testUtf8EncodeError();
- testUtf8EncodeError();
+ comptime try testUtf8EncodeError();
+ try testUtf8EncodeError();
}
-fn testUtf8EncodeError() void {
+fn testUtf8EncodeError() !void {
var array: [4]u8 = undefined;
- testErrorEncode(0xd800, array[0..], error.Utf8CannotEncodeSurrogateHalf);
- testErrorEncode(0xdfff, array[0..], error.Utf8CannotEncodeSurrogateHalf);
- testErrorEncode(0x110000, array[0..], error.CodepointTooLarge);
- testErrorEncode(0x1fffff, array[0..], error.CodepointTooLarge);
+ try testErrorEncode(0xd800, array[0..], error.Utf8CannotEncodeSurrogateHalf);
+ try testErrorEncode(0xdfff, array[0..], error.Utf8CannotEncodeSurrogateHalf);
+ try testErrorEncode(0x110000, array[0..], error.CodepointTooLarge);
+ try testErrorEncode(0x1fffff, array[0..], error.CodepointTooLarge);
}
-fn testErrorEncode(codePoint: u21, array: []u8, expectedErr: anyerror) void {
- testing.expectError(expectedErr, utf8Encode(codePoint, array));
+fn testErrorEncode(codePoint: u21, array: []u8, expectedErr: anyerror) !void {
+ try testing.expectError(expectedErr, utf8Encode(codePoint, array));
}
test "utf8 iterator on ascii" {
- comptime testUtf8IteratorOnAscii();
- testUtf8IteratorOnAscii();
+ comptime try testUtf8IteratorOnAscii();
+ try testUtf8IteratorOnAscii();
}
-fn testUtf8IteratorOnAscii() void {
+fn testUtf8IteratorOnAscii() !void {
const s = Utf8View.initComptime("abc");
var it1 = s.iterator();
- testing.expect(std.mem.eql(u8, "a", it1.nextCodepointSlice().?));
- testing.expect(std.mem.eql(u8, "b", it1.nextCodepointSlice().?));
- testing.expect(std.mem.eql(u8, "c", it1.nextCodepointSlice().?));
- testing.expect(it1.nextCodepointSlice() == null);
+ try testing.expect(std.mem.eql(u8, "a", it1.nextCodepointSlice().?));
+ try testing.expect(std.mem.eql(u8, "b", it1.nextCodepointSlice().?));
+ try testing.expect(std.mem.eql(u8, "c", it1.nextCodepointSlice().?));
+ try testing.expect(it1.nextCodepointSlice() == null);
var it2 = s.iterator();
- testing.expect(it2.nextCodepoint().? == 'a');
- testing.expect(it2.nextCodepoint().? == 'b');
- testing.expect(it2.nextCodepoint().? == 'c');
- testing.expect(it2.nextCodepoint() == null);
+ try testing.expect(it2.nextCodepoint().? == 'a');
+ try testing.expect(it2.nextCodepoint().? == 'b');
+ try testing.expect(it2.nextCodepoint().? == 'c');
+ try testing.expect(it2.nextCodepoint() == null);
}
test "utf8 view bad" {
- comptime testUtf8ViewBad();
- testUtf8ViewBad();
+ comptime try testUtf8ViewBad();
+ try testUtf8ViewBad();
}
-fn testUtf8ViewBad() void {
+fn testUtf8ViewBad() !void {
// Compile-time error.
// const s3 = Utf8View.initComptime("\xfe\xf2");
- testing.expectError(error.InvalidUtf8, Utf8View.init("hel\xadlo"));
+ try testing.expectError(error.InvalidUtf8, Utf8View.init("hel\xadlo"));
}
test "utf8 view ok" {
- comptime testUtf8ViewOk();
- testUtf8ViewOk();
+ comptime try testUtf8ViewOk();
+ try testUtf8ViewOk();
}
-fn testUtf8ViewOk() void {
+fn testUtf8ViewOk() !void {
const s = Utf8View.initComptime("東京市");
var it1 = s.iterator();
- testing.expect(std.mem.eql(u8, "東", it1.nextCodepointSlice().?));
- testing.expect(std.mem.eql(u8, "京", it1.nextCodepointSlice().?));
- testing.expect(std.mem.eql(u8, "市", it1.nextCodepointSlice().?));
- testing.expect(it1.nextCodepointSlice() == null);
+ try testing.expect(std.mem.eql(u8, "東", it1.nextCodepointSlice().?));
+ try testing.expect(std.mem.eql(u8, "京", it1.nextCodepointSlice().?));
+ try testing.expect(std.mem.eql(u8, "市", it1.nextCodepointSlice().?));
+ try testing.expect(it1.nextCodepointSlice() == null);
var it2 = s.iterator();
- testing.expect(it2.nextCodepoint().? == 0x6771);
- testing.expect(it2.nextCodepoint().? == 0x4eac);
- testing.expect(it2.nextCodepoint().? == 0x5e02);
- testing.expect(it2.nextCodepoint() == null);
+ try testing.expect(it2.nextCodepoint().? == 0x6771);
+ try testing.expect(it2.nextCodepoint().? == 0x4eac);
+ try testing.expect(it2.nextCodepoint().? == 0x5e02);
+ try testing.expect(it2.nextCodepoint() == null);
}
test "bad utf8 slice" {
- comptime testBadUtf8Slice();
- testBadUtf8Slice();
+ comptime try testBadUtf8Slice();
+ try testBadUtf8Slice();
}
-fn testBadUtf8Slice() void {
- testing.expect(utf8ValidateSlice("abc"));
- testing.expect(!utf8ValidateSlice("abc\xc0"));
- testing.expect(!utf8ValidateSlice("abc\xc0abc"));
- testing.expect(utf8ValidateSlice("abc\xdf\xbf"));
+fn testBadUtf8Slice() !void {
+ try testing.expect(utf8ValidateSlice("abc"));
+ try testing.expect(!utf8ValidateSlice("abc\xc0"));
+ try testing.expect(!utf8ValidateSlice("abc\xc0abc"));
+ try testing.expect(utf8ValidateSlice("abc\xdf\xbf"));
}
test "valid utf8" {
- comptime testValidUtf8();
- testValidUtf8();
-}
-fn testValidUtf8() void {
- testValid("\x00", 0x0);
- testValid("\x20", 0x20);
- testValid("\x7f", 0x7f);
- testValid("\xc2\x80", 0x80);
- testValid("\xdf\xbf", 0x7ff);
- testValid("\xe0\xa0\x80", 0x800);
- testValid("\xe1\x80\x80", 0x1000);
- testValid("\xef\xbf\xbf", 0xffff);
- testValid("\xf0\x90\x80\x80", 0x10000);
- testValid("\xf1\x80\x80\x80", 0x40000);
- testValid("\xf3\xbf\xbf\xbf", 0xfffff);
- testValid("\xf4\x8f\xbf\xbf", 0x10ffff);
+ comptime try testValidUtf8();
+ try testValidUtf8();
+}
+fn testValidUtf8() !void {
+ try testValid("\x00", 0x0);
+ try testValid("\x20", 0x20);
+ try testValid("\x7f", 0x7f);
+ try testValid("\xc2\x80", 0x80);
+ try testValid("\xdf\xbf", 0x7ff);
+ try testValid("\xe0\xa0\x80", 0x800);
+ try testValid("\xe1\x80\x80", 0x1000);
+ try testValid("\xef\xbf\xbf", 0xffff);
+ try testValid("\xf0\x90\x80\x80", 0x10000);
+ try testValid("\xf1\x80\x80\x80", 0x40000);
+ try testValid("\xf3\xbf\xbf\xbf", 0xfffff);
+ try testValid("\xf4\x8f\xbf\xbf", 0x10ffff);
}
test "invalid utf8 continuation bytes" {
- comptime testInvalidUtf8ContinuationBytes();
- testInvalidUtf8ContinuationBytes();
+ comptime try testInvalidUtf8ContinuationBytes();
+ try testInvalidUtf8ContinuationBytes();
}
-fn testInvalidUtf8ContinuationBytes() void {
+fn testInvalidUtf8ContinuationBytes() !void {
// unexpected continuation
- testError("\x80", error.Utf8InvalidStartByte);
- testError("\xbf", error.Utf8InvalidStartByte);
+ try testError("\x80", error.Utf8InvalidStartByte);
+ try testError("\xbf", error.Utf8InvalidStartByte);
// too many leading 1's
- testError("\xf8", error.Utf8InvalidStartByte);
- testError("\xff", error.Utf8InvalidStartByte);
+ try testError("\xf8", error.Utf8InvalidStartByte);
+ try testError("\xff", error.Utf8InvalidStartByte);
// expected continuation for 2 byte sequences
- testError("\xc2", error.UnexpectedEof);
- testError("\xc2\x00", error.Utf8ExpectedContinuation);
- testError("\xc2\xc0", error.Utf8ExpectedContinuation);
+ try testError("\xc2", error.UnexpectedEof);
+ try testError("\xc2\x00", error.Utf8ExpectedContinuation);
+ try testError("\xc2\xc0", error.Utf8ExpectedContinuation);
// expected continuation for 3 byte sequences
- testError("\xe0", error.UnexpectedEof);
- testError("\xe0\x00", error.UnexpectedEof);
- testError("\xe0\xc0", error.UnexpectedEof);
- testError("\xe0\xa0", error.UnexpectedEof);
- testError("\xe0\xa0\x00", error.Utf8ExpectedContinuation);
- testError("\xe0\xa0\xc0", error.Utf8ExpectedContinuation);
+ try testError("\xe0", error.UnexpectedEof);
+ try testError("\xe0\x00", error.UnexpectedEof);
+ try testError("\xe0\xc0", error.UnexpectedEof);
+ try testError("\xe0\xa0", error.UnexpectedEof);
+ try testError("\xe0\xa0\x00", error.Utf8ExpectedContinuation);
+ try testError("\xe0\xa0\xc0", error.Utf8ExpectedContinuation);
// expected continuation for 4 byte sequences
- testError("\xf0", error.UnexpectedEof);
- testError("\xf0\x00", error.UnexpectedEof);
- testError("\xf0\xc0", error.UnexpectedEof);
- testError("\xf0\x90\x00", error.UnexpectedEof);
- testError("\xf0\x90\xc0", error.UnexpectedEof);
- testError("\xf0\x90\x80\x00", error.Utf8ExpectedContinuation);
- testError("\xf0\x90\x80\xc0", error.Utf8ExpectedContinuation);
+ try testError("\xf0", error.UnexpectedEof);
+ try testError("\xf0\x00", error.UnexpectedEof);
+ try testError("\xf0\xc0", error.UnexpectedEof);
+ try testError("\xf0\x90\x00", error.UnexpectedEof);
+ try testError("\xf0\x90\xc0", error.UnexpectedEof);
+ try testError("\xf0\x90\x80\x00", error.Utf8ExpectedContinuation);
+ try testError("\xf0\x90\x80\xc0", error.Utf8ExpectedContinuation);
}
test "overlong utf8 codepoint" {
- comptime testOverlongUtf8Codepoint();
- testOverlongUtf8Codepoint();
+ comptime try testOverlongUtf8Codepoint();
+ try testOverlongUtf8Codepoint();
}
-fn testOverlongUtf8Codepoint() void {
- testError("\xc0\x80", error.Utf8OverlongEncoding);
- testError("\xc1\xbf", error.Utf8OverlongEncoding);
- testError("\xe0\x80\x80", error.Utf8OverlongEncoding);
- testError("\xe0\x9f\xbf", error.Utf8OverlongEncoding);
- testError("\xf0\x80\x80\x80", error.Utf8OverlongEncoding);
- testError("\xf0\x8f\xbf\xbf", error.Utf8OverlongEncoding);
+fn testOverlongUtf8Codepoint() !void {
+ try testError("\xc0\x80", error.Utf8OverlongEncoding);
+ try testError("\xc1\xbf", error.Utf8OverlongEncoding);
+ try testError("\xe0\x80\x80", error.Utf8OverlongEncoding);
+ try testError("\xe0\x9f\xbf", error.Utf8OverlongEncoding);
+ try testError("\xf0\x80\x80\x80", error.Utf8OverlongEncoding);
+ try testError("\xf0\x8f\xbf\xbf", error.Utf8OverlongEncoding);
}
test "misc invalid utf8" {
- comptime testMiscInvalidUtf8();
- testMiscInvalidUtf8();
+ comptime try testMiscInvalidUtf8();
+ try testMiscInvalidUtf8();
}
-fn testMiscInvalidUtf8() void {
+fn testMiscInvalidUtf8() !void {
// codepoint out of bounds
- testError("\xf4\x90\x80\x80", error.Utf8CodepointTooLarge);
- testError("\xf7\xbf\xbf\xbf", error.Utf8CodepointTooLarge);
+ try testError("\xf4\x90\x80\x80", error.Utf8CodepointTooLarge);
+ try testError("\xf7\xbf\xbf\xbf", error.Utf8CodepointTooLarge);
// surrogate halves
- testValid("\xed\x9f\xbf", 0xd7ff);
- testError("\xed\xa0\x80", error.Utf8EncodesSurrogateHalf);
- testError("\xed\xbf\xbf", error.Utf8EncodesSurrogateHalf);
- testValid("\xee\x80\x80", 0xe000);
+ try testValid("\xed\x9f\xbf", 0xd7ff);
+ try testError("\xed\xa0\x80", error.Utf8EncodesSurrogateHalf);
+ try testError("\xed\xbf\xbf", error.Utf8EncodesSurrogateHalf);
+ try testValid("\xee\x80\x80", 0xe000);
}
test "utf8 iterator peeking" {
- comptime testUtf8Peeking();
- testUtf8Peeking();
+ comptime try testUtf8Peeking();
+ try testUtf8Peeking();
}
-fn testUtf8Peeking() void {
+fn testUtf8Peeking() !void {
const s = Utf8View.initComptime("noël");
var it = s.iterator();
- testing.expect(std.mem.eql(u8, "n", it.nextCodepointSlice().?));
+ try testing.expect(std.mem.eql(u8, "n", it.nextCodepointSlice().?));
- testing.expect(std.mem.eql(u8, "o", it.peek(1)));
- testing.expect(std.mem.eql(u8, "oë", it.peek(2)));
- testing.expect(std.mem.eql(u8, "oël", it.peek(3)));
- testing.expect(std.mem.eql(u8, "oël", it.peek(4)));
- testing.expect(std.mem.eql(u8, "oël", it.peek(10)));
+ try testing.expect(std.mem.eql(u8, "o", it.peek(1)));
+ try testing.expect(std.mem.eql(u8, "oë", it.peek(2)));
+ try testing.expect(std.mem.eql(u8, "oël", it.peek(3)));
+ try testing.expect(std.mem.eql(u8, "oël", it.peek(4)));
+ try testing.expect(std.mem.eql(u8, "oël", it.peek(10)));
- testing.expect(std.mem.eql(u8, "o", it.nextCodepointSlice().?));
- testing.expect(std.mem.eql(u8, "ë", it.nextCodepointSlice().?));
- testing.expect(std.mem.eql(u8, "l", it.nextCodepointSlice().?));
- testing.expect(it.nextCodepointSlice() == null);
+ try testing.expect(std.mem.eql(u8, "o", it.nextCodepointSlice().?));
+ try testing.expect(std.mem.eql(u8, "ë", it.nextCodepointSlice().?));
+ try testing.expect(std.mem.eql(u8, "l", it.nextCodepointSlice().?));
+ try testing.expect(it.nextCodepointSlice() == null);
- testing.expect(std.mem.eql(u8, &[_]u8{}, it.peek(1)));
+ try testing.expect(std.mem.eql(u8, &[_]u8{}, it.peek(1)));
}
-fn testError(bytes: []const u8, expected_err: anyerror) void {
- testing.expectError(expected_err, testDecode(bytes));
+fn testError(bytes: []const u8, expected_err: anyerror) !void {
+ try testing.expectError(expected_err, testDecode(bytes));
}
-fn testValid(bytes: []const u8, expected_codepoint: u21) void {
- testing.expect((testDecode(bytes) catch unreachable) == expected_codepoint);
+fn testValid(bytes: []const u8, expected_codepoint: u21) !void {
+ try testing.expect((testDecode(bytes) catch unreachable) == expected_codepoint);
}
fn testDecode(bytes: []const u8) !u21 {
const length = try utf8ByteSequenceLength(bytes[0]);
if (bytes.len < length) return error.UnexpectedEof;
- testing.expect(bytes.len == length);
+ try testing.expect(bytes.len == length);
return utf8Decode(bytes);
}
@@ -615,7 +615,7 @@ test "utf16leToUtf8" {
mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 'a');
const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);
defer std.testing.allocator.free(utf8);
- testing.expect(mem.eql(u8, utf8, "Aa"));
+ try testing.expect(mem.eql(u8, utf8, "Aa"));
}
{
@@ -623,7 +623,7 @@ test "utf16leToUtf8" {
mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xffff);
const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);
defer std.testing.allocator.free(utf8);
- testing.expect(mem.eql(u8, utf8, "\xc2\x80" ++ "\xef\xbf\xbf"));
+ try testing.expect(mem.eql(u8, utf8, "\xc2\x80" ++ "\xef\xbf\xbf"));
}
{
@@ -632,7 +632,7 @@ test "utf16leToUtf8" {
mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xe000);
const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);
defer std.testing.allocator.free(utf8);
- testing.expect(mem.eql(u8, utf8, "\xed\x9f\xbf" ++ "\xee\x80\x80"));
+ try testing.expect(mem.eql(u8, utf8, "\xed\x9f\xbf" ++ "\xee\x80\x80"));
}
{
@@ -641,7 +641,7 @@ test "utf16leToUtf8" {
mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdc00);
const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);
defer std.testing.allocator.free(utf8);
- testing.expect(mem.eql(u8, utf8, "\xf0\x90\x80\x80"));
+ try testing.expect(mem.eql(u8, utf8, "\xf0\x90\x80\x80"));
}
{
@@ -650,7 +650,7 @@ test "utf16leToUtf8" {
mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdfff);
const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);
defer std.testing.allocator.free(utf8);
- testing.expect(mem.eql(u8, utf8, "\xf4\x8f\xbf\xbf"));
+ try testing.expect(mem.eql(u8, utf8, "\xf4\x8f\xbf\xbf"));
}
{
@@ -658,7 +658,7 @@ test "utf16leToUtf8" {
mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdc00);
const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);
defer std.testing.allocator.free(utf8);
- testing.expect(mem.eql(u8, utf8, "\xf4\x8f\xb0\x80"));
+ try testing.expect(mem.eql(u8, utf8, "\xf4\x8f\xb0\x80"));
}
}
@@ -717,13 +717,13 @@ test "utf8ToUtf16Le" {
var utf16le: [2]u16 = [_]u16{0} ** 2;
{
const length = try utf8ToUtf16Le(utf16le[0..], "𐐷");
- testing.expectEqual(@as(usize, 2), length);
- testing.expectEqualSlices(u8, "\x01\xd8\x37\xdc", mem.sliceAsBytes(utf16le[0..]));
+ try testing.expectEqual(@as(usize, 2), length);
+ try testing.expectEqualSlices(u8, "\x01\xd8\x37\xdc", mem.sliceAsBytes(utf16le[0..]));
}
{
const length = try utf8ToUtf16Le(utf16le[0..], "\u{10FFFF}");
- testing.expectEqual(@as(usize, 2), length);
- testing.expectEqualSlices(u8, "\xff\xdb\xff\xdf", mem.sliceAsBytes(utf16le[0..]));
+ try testing.expectEqual(@as(usize, 2), length);
+ try testing.expectEqualSlices(u8, "\xff\xdb\xff\xdf", mem.sliceAsBytes(utf16le[0..]));
}
}
@@ -731,14 +731,14 @@ test "utf8ToUtf16LeWithNull" {
{
const utf16 = try utf8ToUtf16LeWithNull(testing.allocator, "𐐷");
defer testing.allocator.free(utf16);
- testing.expectEqualSlices(u8, "\x01\xd8\x37\xdc", mem.sliceAsBytes(utf16[0..]));
- testing.expect(utf16[2] == 0);
+ try testing.expectEqualSlices(u8, "\x01\xd8\x37\xdc", mem.sliceAsBytes(utf16[0..]));
+ try testing.expect(utf16[2] == 0);
}
{
const utf16 = try utf8ToUtf16LeWithNull(testing.allocator, "\u{10FFFF}");
defer testing.allocator.free(utf16);
- testing.expectEqualSlices(u8, "\xff\xdb\xff\xdf", mem.sliceAsBytes(utf16[0..]));
- testing.expect(utf16[2] == 0);
+ try testing.expectEqualSlices(u8, "\xff\xdb\xff\xdf", mem.sliceAsBytes(utf16[0..]));
+ try testing.expect(utf16[2] == 0);
}
}
@@ -776,8 +776,8 @@ test "utf8ToUtf16LeStringLiteral" {
mem.nativeToLittle(u16, 0x41),
};
const utf16 = utf8ToUtf16LeStringLiteral("A");
- testing.expectEqualSlices(u16, &bytes, utf16);
- testing.expect(utf16[1] == 0);
+ try testing.expectEqualSlices(u16, &bytes, utf16);
+ try testing.expect(utf16[1] == 0);
}
{
const bytes = [_:0]u16{
@@ -785,32 +785,32 @@ test "utf8ToUtf16LeStringLiteral" {
mem.nativeToLittle(u16, 0xDC37),
};
const utf16 = utf8ToUtf16LeStringLiteral("𐐷");
- testing.expectEqualSlices(u16, &bytes, utf16);
- testing.expect(utf16[2] == 0);
+ try testing.expectEqualSlices(u16, &bytes, utf16);
+ try testing.expect(utf16[2] == 0);
}
{
const bytes = [_:0]u16{
mem.nativeToLittle(u16, 0x02FF),
};
const utf16 = utf8ToUtf16LeStringLiteral("\u{02FF}");
- testing.expectEqualSlices(u16, &bytes, utf16);
- testing.expect(utf16[1] == 0);
+ try testing.expectEqualSlices(u16, &bytes, utf16);
+ try testing.expect(utf16[1] == 0);
}
{
const bytes = [_:0]u16{
mem.nativeToLittle(u16, 0x7FF),
};
const utf16 = utf8ToUtf16LeStringLiteral("\u{7FF}");
- testing.expectEqualSlices(u16, &bytes, utf16);
- testing.expect(utf16[1] == 0);
+ try testing.expectEqualSlices(u16, &bytes, utf16);
+ try testing.expect(utf16[1] == 0);
}
{
const bytes = [_:0]u16{
mem.nativeToLittle(u16, 0x801),
};
const utf16 = utf8ToUtf16LeStringLiteral("\u{801}");
- testing.expectEqualSlices(u16, &bytes, utf16);
- testing.expect(utf16[1] == 0);
+ try testing.expectEqualSlices(u16, &bytes, utf16);
+ try testing.expect(utf16[1] == 0);
}
{
const bytes = [_:0]u16{
@@ -818,35 +818,35 @@ test "utf8ToUtf16LeStringLiteral" {
mem.nativeToLittle(u16, 0xDFFF),
};
const utf16 = utf8ToUtf16LeStringLiteral("\u{10FFFF}");
- testing.expectEqualSlices(u16, &bytes, utf16);
- testing.expect(utf16[2] == 0);
+ try testing.expectEqualSlices(u16, &bytes, utf16);
+ try testing.expect(utf16[2] == 0);
}
}
fn testUtf8CountCodepoints() !void {
- testing.expectEqual(@as(usize, 10), try utf8CountCodepoints("abcdefghij"));
- testing.expectEqual(@as(usize, 10), try utf8CountCodepoints("äåéëþüúíóö"));
- testing.expectEqual(@as(usize, 5), try utf8CountCodepoints("こんにちは"));
+ try testing.expectEqual(@as(usize, 10), try utf8CountCodepoints("abcdefghij"));
+ try testing.expectEqual(@as(usize, 10), try utf8CountCodepoints("äåéëþüúíóö"));
+ try testing.expectEqual(@as(usize, 5), try utf8CountCodepoints("こんにちは"));
// testing.expectError(error.Utf8EncodesSurrogateHalf, utf8CountCodepoints("\xED\xA0\x80"));
}
test "utf8 count codepoints" {
try testUtf8CountCodepoints();
- comptime testUtf8CountCodepoints() catch unreachable;
+ comptime try testUtf8CountCodepoints();
}
fn testUtf8ValidCodepoint() !void {
- testing.expect(utf8ValidCodepoint('e'));
- testing.expect(utf8ValidCodepoint('ë'));
- testing.expect(utf8ValidCodepoint('は'));
- testing.expect(utf8ValidCodepoint(0xe000));
- testing.expect(utf8ValidCodepoint(0x10ffff));
- testing.expect(!utf8ValidCodepoint(0xd800));
- testing.expect(!utf8ValidCodepoint(0xdfff));
- testing.expect(!utf8ValidCodepoint(0x110000));
+ try testing.expect(utf8ValidCodepoint('e'));
+ try testing.expect(utf8ValidCodepoint('ë'));
+ try testing.expect(utf8ValidCodepoint('は'));
+ try testing.expect(utf8ValidCodepoint(0xe000));
+ try testing.expect(utf8ValidCodepoint(0x10ffff));
+ try testing.expect(!utf8ValidCodepoint(0xd800));
+ try testing.expect(!utf8ValidCodepoint(0xdfff));
+ try testing.expect(!utf8ValidCodepoint(0x110000));
}
test "utf8 valid codepoint" {
try testUtf8ValidCodepoint();
- comptime testUtf8ValidCodepoint() catch unreachable;
+ comptime try testUtf8ValidCodepoint();
}
lib/std/wasm.zig
@@ -200,11 +200,11 @@ test "Wasm - opcodes" {
const local_get = opcode(.local_get);
const i64_extend32_s = opcode(.i64_extend32_s);
- testing.expectEqual(@as(u16, 0x41), i32_const);
- testing.expectEqual(@as(u16, 0x0B), end);
- testing.expectEqual(@as(u16, 0x1A), drop);
- testing.expectEqual(@as(u16, 0x20), local_get);
- testing.expectEqual(@as(u16, 0xC4), i64_extend32_s);
+ try testing.expectEqual(@as(u16, 0x41), i32_const);
+ try testing.expectEqual(@as(u16, 0x0B), end);
+ try testing.expectEqual(@as(u16, 0x1A), drop);
+ try testing.expectEqual(@as(u16, 0x20), local_get);
+ try testing.expectEqual(@as(u16, 0xC4), i64_extend32_s);
}
/// Enum representing all Wasm value types as per spec:
@@ -227,10 +227,10 @@ test "Wasm - valtypes" {
const _f32 = valtype(.f32);
const _f64 = valtype(.f64);
- testing.expectEqual(@as(u8, 0x7F), _i32);
- testing.expectEqual(@as(u8, 0x7E), _i64);
- testing.expectEqual(@as(u8, 0x7D), _f32);
- testing.expectEqual(@as(u8, 0x7C), _f64);
+ try testing.expectEqual(@as(u8, 0x7F), _i32);
+ try testing.expectEqual(@as(u8, 0x7E), _i64);
+ try testing.expectEqual(@as(u8, 0x7D), _f32);
+ try testing.expectEqual(@as(u8, 0x7C), _f64);
}
/// Wasm module sections as per spec:
lib/std/zig.zig
@@ -253,26 +253,26 @@ pub fn parseCharLiteral(
test "parseCharLiteral" {
var bad_index: usize = undefined;
- std.testing.expectEqual(try parseCharLiteral("'a'", &bad_index), 'a');
- std.testing.expectEqual(try parseCharLiteral("'ä'", &bad_index), 'ä');
- std.testing.expectEqual(try parseCharLiteral("'\\x00'", &bad_index), 0);
- std.testing.expectEqual(try parseCharLiteral("'\\x4f'", &bad_index), 0x4f);
- std.testing.expectEqual(try parseCharLiteral("'\\x4F'", &bad_index), 0x4f);
- std.testing.expectEqual(try parseCharLiteral("'ぁ'", &bad_index), 0x3041);
- std.testing.expectEqual(try parseCharLiteral("'\\u{0}'", &bad_index), 0);
- std.testing.expectEqual(try parseCharLiteral("'\\u{3041}'", &bad_index), 0x3041);
- std.testing.expectEqual(try parseCharLiteral("'\\u{7f}'", &bad_index), 0x7f);
- std.testing.expectEqual(try parseCharLiteral("'\\u{7FFF}'", &bad_index), 0x7FFF);
+ try std.testing.expectEqual(try parseCharLiteral("'a'", &bad_index), 'a');
+ try std.testing.expectEqual(try parseCharLiteral("'ä'", &bad_index), 'ä');
+ try std.testing.expectEqual(try parseCharLiteral("'\\x00'", &bad_index), 0);
+ try std.testing.expectEqual(try parseCharLiteral("'\\x4f'", &bad_index), 0x4f);
+ try std.testing.expectEqual(try parseCharLiteral("'\\x4F'", &bad_index), 0x4f);
+ try std.testing.expectEqual(try parseCharLiteral("'ぁ'", &bad_index), 0x3041);
+ try std.testing.expectEqual(try parseCharLiteral("'\\u{0}'", &bad_index), 0);
+ try std.testing.expectEqual(try parseCharLiteral("'\\u{3041}'", &bad_index), 0x3041);
+ try std.testing.expectEqual(try parseCharLiteral("'\\u{7f}'", &bad_index), 0x7f);
+ try std.testing.expectEqual(try parseCharLiteral("'\\u{7FFF}'", &bad_index), 0x7FFF);
- std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\x0'", &bad_index));
- std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\x000'", &bad_index));
- std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\y'", &bad_index));
- std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u'", &bad_index));
- std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\uFFFF'", &bad_index));
- std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{}'", &bad_index));
- std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{FFFFFF}'", &bad_index));
- std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{FFFF'", &bad_index));
- std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{FFFF}x'", &bad_index));
+ try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\x0'", &bad_index));
+ try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\x000'", &bad_index));
+ try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\y'", &bad_index));
+ try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u'", &bad_index));
+ try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\uFFFF'", &bad_index));
+ try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{}'", &bad_index));
+ try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{FFFFFF}'", &bad_index));
+ try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{FFFF'", &bad_index));
+ try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{FFFF}x'", &bad_index));
}
test {