authorgravatar for 69403556+SeanTheGleaming@users.noreply.github.comSean <69403556+SeanTheGleaming@users.noreply.github.com> 2024-04-22 09:25:37-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-04-23 17:57:56-07:00
logf6f7a47aad7da251f1e4ee6f45b6de79ce8bbbd8
tree12d19f1c2a54299725634000d672bea1baab65c8
parent857c1d4ff2513dd29f10ef28a2bfbe61818dc1c4

Update fmt.zig tests

Changed uses of `std.testing.expect` to `std.testing.expectEqual`, `std.testing.expectError`, and `std.testing.expectEqualStrings` where appropriate

1 files changed, 58 insertions(+), 58 deletions(-)

lib/std/fmt.zig+58-58
......@@ -1501,9 +1501,9 @@ pub fn parseInt(comptime T: type, buf: []const u8, base: u8) ParseIntError!T {
15011501}
15021502
15031503test parseInt {
1504 try std.testing.expect((try parseInt(i32, "-10", 10)) == -10);
1505 try std.testing.expect((try parseInt(i32, "+10", 10)) == 10);
1506 try std.testing.expect((try parseInt(u32, "+10", 10)) == 10);
1504 try std.testing.expectEqual(-10, try parseInt(i32, "-10", 10));
1505 try std.testing.expectEqual(10, try parseInt(i32, "+10", 10));
1506 try std.testing.expectEqual(10, try parseInt(u32, "+10", 10));
15071507 try std.testing.expectError(error.Overflow, parseInt(u32, "-10", 10));
15081508 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, " 10", 10));
15091509 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "10 ", 10));
......@@ -1511,17 +1511,17 @@ test parseInt {
15111511 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0x_10_", 10));
15121512 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0x10_", 10));
15131513 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0x_10", 10));
1514 try std.testing.expect((try parseInt(u8, "255", 10)) == 255);
1514 try std.testing.expectEqual(255, try parseInt(u8, "255", 10));
15151515 try std.testing.expectError(error.Overflow, parseInt(u8, "256", 10));
15161516
15171517 // +0 and -0 should work for unsigned
1518 try std.testing.expect((try parseInt(u8, "-0", 10)) == 0);
1519 try std.testing.expect((try parseInt(u8, "+0", 10)) == 0);
1518 try std.testing.expectEqual(0, try parseInt(u8, "-0", 10));
1519 try std.testing.expectEqual(0, try parseInt(u8, "+0", 10));
15201520
15211521 // ensure minInt is parsed correctly
1522 try std.testing.expect((try parseInt(i1, "-1", 10)) == math.minInt(i1));
1523 try std.testing.expect((try parseInt(i8, "-128", 10)) == math.minInt(i8));
1524 try std.testing.expect((try parseInt(i43, "-4398046511104", 10)) == math.minInt(i43));
1522 try std.testing.expectEqual(math.minInt(i1), try parseInt(i1, "-1", 10));
1523 try std.testing.expectEqual(math.minInt(i8), try parseInt(i8, "-128", 10));
1524 try std.testing.expectEqual(math.minInt(i43), try parseInt(i43, "-4398046511104", 10));
15251525
15261526 // empty string or bare +- is invalid
15271527 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "", 10));
......@@ -1532,22 +1532,22 @@ test parseInt {
15321532 try std.testing.expectError(error.InvalidCharacter, parseInt(i32, "-", 10));
15331533
15341534 // autodectect the base
1535 try std.testing.expect((try parseInt(i32, "111", 0)) == 111);
1536 try std.testing.expect((try parseInt(i32, "1_1_1", 0)) == 111);
1537 try std.testing.expect((try parseInt(i32, "1_1_1", 0)) == 111);
1538 try std.testing.expect((try parseInt(i32, "+0b111", 0)) == 7);
1539 try std.testing.expect((try parseInt(i32, "+0B111", 0)) == 7);
1540 try std.testing.expect((try parseInt(i32, "+0b1_11", 0)) == 7);
1541 try std.testing.expect((try parseInt(i32, "+0o111", 0)) == 73);
1542 try std.testing.expect((try parseInt(i32, "+0O111", 0)) == 73);
1543 try std.testing.expect((try parseInt(i32, "+0o11_1", 0)) == 73);
1544 try std.testing.expect((try parseInt(i32, "+0x111", 0)) == 273);
1545 try std.testing.expect((try parseInt(i32, "-0b111", 0)) == -7);
1546 try std.testing.expect((try parseInt(i32, "-0b11_1", 0)) == -7);
1547 try std.testing.expect((try parseInt(i32, "-0o111", 0)) == -73);
1548 try std.testing.expect((try parseInt(i32, "-0x111", 0)) == -273);
1549 try std.testing.expect((try parseInt(i32, "-0X111", 0)) == -273);
1550 try std.testing.expect((try parseInt(i32, "-0x1_11", 0)) == -273);
1535 try std.testing.expectEqual(111, try parseInt(i32, "111", 0));
1536 try std.testing.expectEqual(111, try parseInt(i32, "1_1_1", 0));
1537 try std.testing.expectEqual(111, try parseInt(i32, "1_1_1", 0));
1538 try std.testing.expectEqual(7, try parseInt(i32, "+0b111", 0));
1539 try std.testing.expectEqual(7, try parseInt(i32, "+0B111", 0));
1540 try std.testing.expectEqual(7, try parseInt(i32, "+0b1_11", 0));
1541 try std.testing.expectEqual(73, try parseInt(i32, "+0o111", 0));
1542 try std.testing.expectEqual(73, try parseInt(i32, "+0O111", 0));
1543 try std.testing.expectEqual(73, try parseInt(i32, "+0o11_1", 0));
1544 try std.testing.expectEqual(273, try parseInt(i32, "+0x111", 0));
1545 try std.testing.expectEqual(-7, try parseInt(i32, "-0b111", 0));
1546 try std.testing.expectEqual(-7, try parseInt(i32, "-0b11_1", 0));
1547 try std.testing.expectEqual(-73, try parseInt(i32, "-0o111", 0));
1548 try std.testing.expectEqual(-273, try parseInt(i32, "-0x111", 0));
1549 try std.testing.expectEqual(-273, try parseInt(i32, "-0X111", 0));
1550 try std.testing.expectEqual(-273, try parseInt(i32, "-0x1_11", 0));
15511551
15521552 // bare binary/octal/decimal prefix is invalid
15531553 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0b", 0));
......@@ -1643,31 +1643,31 @@ pub fn parseUnsigned(comptime T: type, buf: []const u8, base: u8) ParseIntError!
16431643}
16441644
16451645test parseUnsigned {
1646 try std.testing.expect((try parseUnsigned(u16, "050124", 10)) == 50124);
1647 try std.testing.expect((try parseUnsigned(u16, "65535", 10)) == 65535);
1648 try std.testing.expect((try parseUnsigned(u16, "65_535", 10)) == 65535);
1646 try std.testing.expectEqual(50124, try parseUnsigned(u16, "050124", 10));
1647 try std.testing.expectEqual(65535, try parseUnsigned(u16, "65535", 10));
1648 try std.testing.expectEqual(65535, try parseUnsigned(u16, "65_535", 10));
16491649 try std.testing.expectError(error.Overflow, parseUnsigned(u16, "65536", 10));
16501650
1651 try std.testing.expect((try parseUnsigned(u64, "0ffffffffffffffff", 16)) == 0xffffffffffffffff);
1652 try std.testing.expect((try parseUnsigned(u64, "0f_fff_fff_fff_fff_fff", 16)) == 0xffffffffffffffff);
1651 try std.testing.expectEqual(0xffffffffffffffff, try parseUnsigned(u64, "0ffffffffffffffff", 16));
1652 try std.testing.expectEqual(0xffffffffffffffff, try parseUnsigned(u64, "0f_fff_fff_fff_fff_fff", 16));
16531653 try std.testing.expectError(error.Overflow, parseUnsigned(u64, "10000000000000000", 16));
16541654
1655 try std.testing.expect((try parseUnsigned(u32, "DeadBeef", 16)) == 0xDEADBEEF);
1655 try std.testing.expectEqual(0xDEADBEEF, try parseUnsigned(u32, "DeadBeef", 16));
16561656
1657 try std.testing.expect((try parseUnsigned(u7, "1", 10)) == 1);
1658 try std.testing.expect((try parseUnsigned(u7, "1000", 2)) == 8);
1657 try std.testing.expectEqual(1, try parseUnsigned(u7, "1", 10));
1658 try std.testing.expectEqual(8, try parseUnsigned(u7, "1000", 2));
16591659
16601660 try std.testing.expectError(error.InvalidCharacter, parseUnsigned(u32, "f", 10));
16611661 try std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "109", 8));
16621662
1663 try std.testing.expect((try parseUnsigned(u32, "NUMBER", 36)) == 1442151747);
1663 try std.testing.expectEqual(1442151747, try parseUnsigned(u32, "NUMBER", 36));
16641664
16651665 // these numbers should fit even though the base itself doesn't fit in the destination type
1666 try std.testing.expect((try parseUnsigned(u1, "0", 10)) == 0);
1667 try std.testing.expect((try parseUnsigned(u1, "1", 10)) == 1);
1666 try std.testing.expectEqual(0, try parseUnsigned(u1, "0", 10));
1667 try std.testing.expectEqual(1, try parseUnsigned(u1, "1", 10));
16681668 try std.testing.expectError(error.Overflow, parseUnsigned(u1, "2", 10));
1669 try std.testing.expect((try parseUnsigned(u1, "001", 16)) == 1);
1670 try std.testing.expect((try parseUnsigned(u2, "3", 16)) == 3);
1669 try std.testing.expectEqual(1, try parseUnsigned(u1, "001", 16));
1670 try std.testing.expectEqual(3, try parseUnsigned(u2, "3", 16));
16711671 try std.testing.expectError(error.Overflow, parseUnsigned(u2, "4", 16));
16721672
16731673 // parseUnsigned does not expect a sign
......@@ -1717,15 +1717,15 @@ pub fn parseIntSizeSuffix(buf: []const u8, digit_base: u8) ParseIntError!usize {
17171717}
17181718
17191719test parseIntSizeSuffix {
1720 try std.testing.expect(try parseIntSizeSuffix("2", 10) == 2);
1721 try std.testing.expect(try parseIntSizeSuffix("2B", 10) == 2);
1722 try std.testing.expect(try parseIntSizeSuffix("2kB", 10) == 2000);
1723 try std.testing.expect(try parseIntSizeSuffix("2k", 10) == 2000);
1724 try std.testing.expect(try parseIntSizeSuffix("2KiB", 10) == 2048);
1725 try std.testing.expect(try parseIntSizeSuffix("2Ki", 10) == 2048);
1726 try std.testing.expect(try parseIntSizeSuffix("aKiB", 16) == 10240);
1727 try std.testing.expect(parseIntSizeSuffix("", 10) == error.InvalidCharacter);
1728 try std.testing.expect(parseIntSizeSuffix("2iB", 10) == error.InvalidCharacter);
1720 try std.testing.expectEqual(2, try parseIntSizeSuffix("2", 10));
1721 try std.testing.expectEqual(2, try parseIntSizeSuffix("2B", 10));
1722 try std.testing.expectEqual(2000, try parseIntSizeSuffix("2kB", 10));
1723 try std.testing.expectEqual(2000, try parseIntSizeSuffix("2k", 10));
1724 try std.testing.expectEqual(2048, try parseIntSizeSuffix("2KiB", 10));
1725 try std.testing.expectEqual(2048, try parseIntSizeSuffix("2Ki", 10));
1726 try std.testing.expectEqual(10240, try parseIntSizeSuffix("aKiB", 16));
1727 try std.testing.expectError(error.InvalidCharacter, parseIntSizeSuffix("", 10));
1728 try std.testing.expectError(error.InvalidCharacter, parseIntSizeSuffix("2iB", 10));
17291729}
17301730
17311731pub const parseFloat = @import("fmt/parse_float.zig").parseFloat;
......@@ -1854,7 +1854,7 @@ test "parse u64 digit too big" {
18541854
18551855test "parse unsigned comptime" {
18561856 comptime {
1857 try std.testing.expect((try parseUnsigned(usize, "2", 10)) == 2);
1857 try std.testing.expectEqual(2, try parseUnsigned(usize, "2", 10));
18581858 }
18591859}
18601860
......@@ -1963,15 +1963,15 @@ test "buffer" {
19631963 var buf1: [32]u8 = undefined;
19641964 var fbs = std.io.fixedBufferStream(&buf1);
19651965 try formatType(1234, "", FormatOptions{}, fbs.writer(), std.options.fmt_max_depth);
1966 try std.testing.expect(mem.eql(u8, fbs.getWritten(), "1234"));
1966 try std.testing.expectEqualStrings("1234", fbs.getWritten());
19671967
19681968 fbs.reset();
19691969 try formatType('a', "c", FormatOptions{}, fbs.writer(), std.options.fmt_max_depth);
1970 try std.testing.expect(mem.eql(u8, fbs.getWritten(), "a"));
1970 try std.testing.expectEqualStrings("a", fbs.getWritten());
19711971
19721972 fbs.reset();
19731973 try formatType(0b1100, "b", FormatOptions{}, fbs.writer(), std.options.fmt_max_depth);
1974 try std.testing.expect(mem.eql(u8, fbs.getWritten(), "1100"));
1974 try std.testing.expectEqualStrings("1100", fbs.getWritten());
19751975 }
19761976}
19771977
......@@ -2372,10 +2372,10 @@ test "union" {
23722372
23732373 var buf: [100]u8 = undefined;
23742374 const uu_result = try bufPrint(buf[0..], "{}", .{uu_inst});
2375 try std.testing.expect(mem.eql(u8, uu_result[0..18], "fmt.test.union.UU@"));
2375 try std.testing.expectEqualStrings("fmt.test.union.UU@", uu_result[0..18]);
23762376
23772377 const eu_result = try bufPrint(buf[0..], "{}", .{eu_inst});
2378 try std.testing.expect(mem.eql(u8, eu_result[0..18], "fmt.test.union.EU@"));
2378 try std.testing.expectEqualStrings("fmt.test.union.EU@", eu_result[0..18]);
23792379}
23802380
23812381test "struct.self-referential" {
......@@ -2476,7 +2476,7 @@ test "formatIntValue with comptime_int" {
24762476 var buf: [20]u8 = undefined;
24772477 var fbs = std.io.fixedBufferStream(&buf);
24782478 try formatIntValue(value, "", FormatOptions{}, fbs.writer());
2479 try std.testing.expect(mem.eql(u8, fbs.getWritten(), "123456789123456789"));
2479 try std.testing.expectEqualStrings("123456789123456789", fbs.getWritten());
24802480}
24812481
24822482test "formatFloatValue with comptime_float" {
......@@ -2542,19 +2542,19 @@ test "formatType max_depth" {
25422542 var buf: [1000]u8 = undefined;
25432543 var fbs = std.io.fixedBufferStream(&buf);
25442544 try formatType(inst, "", FormatOptions{}, fbs.writer(), 0);
2545 try std.testing.expect(mem.eql(u8, fbs.getWritten(), "fmt.test.formatType max_depth.S{ ... }"));
2545 try std.testing.expectEqualStrings("fmt.test.formatType max_depth.S{ ... }", fbs.getWritten());
25462546
25472547 fbs.reset();
25482548 try formatType(inst, "", FormatOptions{}, fbs.writer(), 1);
2549 try std.testing.expect(mem.eql(u8, fbs.getWritten(), "fmt.test.formatType max_depth.S{ .a = fmt.test.formatType max_depth.S{ ... }, .tu = fmt.test.formatType max_depth.TU{ ... }, .e = fmt.test.formatType max_depth.E.Two, .vec = (10.200,2.220) }"));
2549 try std.testing.expectEqualStrings("fmt.test.formatType max_depth.S{ .a = fmt.test.formatType max_depth.S{ ... }, .tu = fmt.test.formatType max_depth.TU{ ... }, .e = fmt.test.formatType max_depth.E.Two, .vec = (10.200,2.220) }", fbs.getWritten());
25502550
25512551 fbs.reset();
25522552 try formatType(inst, "", FormatOptions{}, fbs.writer(), 2);
2553 try std.testing.expect(mem.eql(u8, fbs.getWritten(), "fmt.test.formatType max_depth.S{ .a = fmt.test.formatType max_depth.S{ .a = fmt.test.formatType max_depth.S{ ... }, .tu = fmt.test.formatType max_depth.TU{ ... }, .e = fmt.test.formatType max_depth.E.Two, .vec = (10.200,2.220) }, .tu = fmt.test.formatType max_depth.TU{ .ptr = fmt.test.formatType max_depth.TU{ ... } }, .e = fmt.test.formatType max_depth.E.Two, .vec = (10.200,2.220) }"));
2553 try std.testing.expectEqualStrings("fmt.test.formatType max_depth.S{ .a = fmt.test.formatType max_depth.S{ .a = fmt.test.formatType max_depth.S{ ... }, .tu = fmt.test.formatType max_depth.TU{ ... }, .e = fmt.test.formatType max_depth.E.Two, .vec = (10.200,2.220) }, .tu = fmt.test.formatType max_depth.TU{ .ptr = fmt.test.formatType max_depth.TU{ ... } }, .e = fmt.test.formatType max_depth.E.Two, .vec = (10.200,2.220) }", fbs.getWritten());
25542554
25552555 fbs.reset();
25562556 try formatType(inst, "", FormatOptions{}, fbs.writer(), 3);
2557 try std.testing.expect(mem.eql(u8, fbs.getWritten(), "fmt.test.formatType max_depth.S{ .a = fmt.test.formatType max_depth.S{ .a = fmt.test.formatType max_depth.S{ .a = fmt.test.formatType max_depth.S{ ... }, .tu = fmt.test.formatType max_depth.TU{ ... }, .e = fmt.test.formatType max_depth.E.Two, .vec = (10.200,2.220) }, .tu = fmt.test.formatType max_depth.TU{ .ptr = fmt.test.formatType max_depth.TU{ ... } }, .e = fmt.test.formatType max_depth.E.Two, .vec = (10.200,2.220) }, .tu = fmt.test.formatType max_depth.TU{ .ptr = fmt.test.formatType max_depth.TU{ .ptr = fmt.test.formatType max_depth.TU{ ... } } }, .e = fmt.test.formatType max_depth.E.Two, .vec = (10.200,2.220) }"));
2557 try std.testing.expectEqualStrings("fmt.test.formatType max_depth.S{ .a = fmt.test.formatType max_depth.S{ .a = fmt.test.formatType max_depth.S{ .a = fmt.test.formatType max_depth.S{ ... }, .tu = fmt.test.formatType max_depth.TU{ ... }, .e = fmt.test.formatType max_depth.E.Two, .vec = (10.200,2.220) }, .tu = fmt.test.formatType max_depth.TU{ .ptr = fmt.test.formatType max_depth.TU{ ... } }, .e = fmt.test.formatType max_depth.E.Two, .vec = (10.200,2.220) }, .tu = fmt.test.formatType max_depth.TU{ .ptr = fmt.test.formatType max_depth.TU{ .ptr = fmt.test.formatType max_depth.TU{ ... } } }, .e = fmt.test.formatType max_depth.E.Two, .vec = (10.200,2.220) }", fbs.getWritten());
25582558}
25592559
25602560test "positional" {