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 {...@@ -1501,9 +1501,9 @@ pub fn parseInt(comptime T: type, buf: []const u8, base: u8) ParseIntError!T {
1501}1501}
15021502
1503test parseInt {1503test parseInt {
1504 try std.testing.expect((try parseInt(i32, "-10", 10)) == -10);1504 try std.testing.expectEqual(-10, try parseInt(i32, "-10", 10));
1505 try std.testing.expect((try parseInt(i32, "+10", 10)) == 10);1505 try std.testing.expectEqual(10, try parseInt(i32, "+10", 10));
1506 try std.testing.expect((try parseInt(u32, "+10", 10)) == 10);1506 try std.testing.expectEqual(10, try parseInt(u32, "+10", 10));
1507 try std.testing.expectError(error.Overflow, parseInt(u32, "-10", 10));1507 try std.testing.expectError(error.Overflow, parseInt(u32, "-10", 10));
1508 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, " 10", 10));1508 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, " 10", 10));
1509 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "10 ", 10));1509 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "10 ", 10));
...@@ -1511,17 +1511,17 @@ test parseInt {...@@ -1511,17 +1511,17 @@ test parseInt {
1511 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0x_10_", 10));1511 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0x_10_", 10));
1512 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0x10_", 10));1512 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0x10_", 10));
1513 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0x_10", 10));1513 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));
1515 try std.testing.expectError(error.Overflow, parseInt(u8, "256", 10));1515 try std.testing.expectError(error.Overflow, parseInt(u8, "256", 10));
15161516
1517 // +0 and -0 should work for unsigned1517 // +0 and -0 should work for unsigned
1518 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.expect((try parseInt(u8, "+0", 10)) == 0);1519 try std.testing.expectEqual(0, try parseInt(u8, "+0", 10));
15201520
1521 // ensure minInt is parsed correctly1521 // ensure minInt is parsed correctly
1522 try std.testing.expect((try parseInt(i1, "-1", 10)) == math.minInt(i1));1522 try std.testing.expectEqual(math.minInt(i1), try parseInt(i1, "-1", 10));
1523 try std.testing.expect((try parseInt(i8, "-128", 10)) == math.minInt(i8));1523 try std.testing.expectEqual(math.minInt(i8), try parseInt(i8, "-128", 10));
1524 try std.testing.expect((try parseInt(i43, "-4398046511104", 10)) == math.minInt(i43));1524 try std.testing.expectEqual(math.minInt(i43), try parseInt(i43, "-4398046511104", 10));
15251525
1526 // empty string or bare +- is invalid1526 // empty string or bare +- is invalid
1527 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "", 10));1527 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "", 10));
...@@ -1532,22 +1532,22 @@ test parseInt {...@@ -1532,22 +1532,22 @@ test parseInt {
1532 try std.testing.expectError(error.InvalidCharacter, parseInt(i32, "-", 10));1532 try std.testing.expectError(error.InvalidCharacter, parseInt(i32, "-", 10));
15331533
1534 // autodectect the base1534 // autodectect the base
1535 try std.testing.expect((try parseInt(i32, "111", 0)) == 111);1535 try std.testing.expectEqual(111, try parseInt(i32, "111", 0));
1536 try std.testing.expect((try parseInt(i32, "1_1_1", 0)) == 111);1536 try std.testing.expectEqual(111, try parseInt(i32, "1_1_1", 0));
1537 try std.testing.expect((try parseInt(i32, "1_1_1", 0)) == 111);1537 try std.testing.expectEqual(111, try parseInt(i32, "1_1_1", 0));
1538 try std.testing.expect((try parseInt(i32, "+0b111", 0)) == 7);1538 try std.testing.expectEqual(7, try parseInt(i32, "+0b111", 0));
1539 try std.testing.expect((try parseInt(i32, "+0B111", 0)) == 7);1539 try std.testing.expectEqual(7, try parseInt(i32, "+0B111", 0));
1540 try std.testing.expect((try parseInt(i32, "+0b1_11", 0)) == 7);1540 try std.testing.expectEqual(7, try parseInt(i32, "+0b1_11", 0));
1541 try std.testing.expect((try parseInt(i32, "+0o111", 0)) == 73);1541 try std.testing.expectEqual(73, try parseInt(i32, "+0o111", 0));
1542 try std.testing.expect((try parseInt(i32, "+0O111", 0)) == 73);1542 try std.testing.expectEqual(73, try parseInt(i32, "+0O111", 0));
1543 try std.testing.expect((try parseInt(i32, "+0o11_1", 0)) == 73);1543 try std.testing.expectEqual(73, try parseInt(i32, "+0o11_1", 0));
1544 try std.testing.expect((try parseInt(i32, "+0x111", 0)) == 273);1544 try std.testing.expectEqual(273, try parseInt(i32, "+0x111", 0));
1545 try std.testing.expect((try parseInt(i32, "-0b111", 0)) == -7);1545 try std.testing.expectEqual(-7, try parseInt(i32, "-0b111", 0));
1546 try std.testing.expect((try parseInt(i32, "-0b11_1", 0)) == -7);1546 try std.testing.expectEqual(-7, try parseInt(i32, "-0b11_1", 0));
1547 try std.testing.expect((try parseInt(i32, "-0o111", 0)) == -73);1547 try std.testing.expectEqual(-73, try parseInt(i32, "-0o111", 0));
1548 try std.testing.expect((try parseInt(i32, "-0x111", 0)) == -273);1548 try std.testing.expectEqual(-273, try parseInt(i32, "-0x111", 0));
1549 try std.testing.expect((try parseInt(i32, "-0X111", 0)) == -273);1549 try std.testing.expectEqual(-273, try parseInt(i32, "-0X111", 0));
1550 try std.testing.expect((try parseInt(i32, "-0x1_11", 0)) == -273);1550 try std.testing.expectEqual(-273, try parseInt(i32, "-0x1_11", 0));
15511551
1552 // bare binary/octal/decimal prefix is invalid1552 // bare binary/octal/decimal prefix is invalid
1553 try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0b", 0));1553 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!...@@ -1643,31 +1643,31 @@ pub fn parseUnsigned(comptime T: type, buf: []const u8, base: u8) ParseIntError!
1643}1643}
16441644
1645test parseUnsigned {1645test parseUnsigned {
1646 try std.testing.expect((try parseUnsigned(u16, "050124", 10)) == 50124);1646 try std.testing.expectEqual(50124, try parseUnsigned(u16, "050124", 10));
1647 try std.testing.expect((try parseUnsigned(u16, "65535", 10)) == 65535);1647 try std.testing.expectEqual(65535, try parseUnsigned(u16, "65535", 10));
1648 try std.testing.expect((try parseUnsigned(u16, "65_535", 10)) == 65535);1648 try std.testing.expectEqual(65535, try parseUnsigned(u16, "65_535", 10));
1649 try std.testing.expectError(error.Overflow, parseUnsigned(u16, "65536", 10));1649 try std.testing.expectError(error.Overflow, parseUnsigned(u16, "65536", 10));
16501650
1651 try std.testing.expect((try parseUnsigned(u64, "0ffffffffffffffff", 16)) == 0xffffffffffffffff);1651 try std.testing.expectEqual(0xffffffffffffffff, try parseUnsigned(u64, "0ffffffffffffffff", 16));
1652 try std.testing.expect((try parseUnsigned(u64, "0f_fff_fff_fff_fff_fff", 16)) == 0xffffffffffffffff);1652 try std.testing.expectEqual(0xffffffffffffffff, try parseUnsigned(u64, "0f_fff_fff_fff_fff_fff", 16));
1653 try std.testing.expectError(error.Overflow, parseUnsigned(u64, "10000000000000000", 16));1653 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);1657 try std.testing.expectEqual(1, try parseUnsigned(u7, "1", 10));
1658 try std.testing.expect((try parseUnsigned(u7, "1000", 2)) == 8);1658 try std.testing.expectEqual(8, try parseUnsigned(u7, "1000", 2));
16591659
1660 try std.testing.expectError(error.InvalidCharacter, parseUnsigned(u32, "f", 10));1660 try std.testing.expectError(error.InvalidCharacter, parseUnsigned(u32, "f", 10));
1661 try std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "109", 8));1661 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
1665 // these numbers should fit even though the base itself doesn't fit in the destination type1665 // 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);1666 try std.testing.expectEqual(0, try parseUnsigned(u1, "0", 10));
1667 try std.testing.expect((try parseUnsigned(u1, "1", 10)) == 1);1667 try std.testing.expectEqual(1, try parseUnsigned(u1, "1", 10));
1668 try std.testing.expectError(error.Overflow, parseUnsigned(u1, "2", 10));1668 try std.testing.expectError(error.Overflow, parseUnsigned(u1, "2", 10));
1669 try std.testing.expect((try parseUnsigned(u1, "001", 16)) == 1);1669 try std.testing.expectEqual(1, try parseUnsigned(u1, "001", 16));
1670 try std.testing.expect((try parseUnsigned(u2, "3", 16)) == 3);1670 try std.testing.expectEqual(3, try parseUnsigned(u2, "3", 16));
1671 try std.testing.expectError(error.Overflow, parseUnsigned(u2, "4", 16));1671 try std.testing.expectError(error.Overflow, parseUnsigned(u2, "4", 16));
16721672
1673 // parseUnsigned does not expect a sign1673 // parseUnsigned does not expect a sign
...@@ -1717,15 +1717,15 @@ pub fn parseIntSizeSuffix(buf: []const u8, digit_base: u8) ParseIntError!usize {...@@ -1717,15 +1717,15 @@ pub fn parseIntSizeSuffix(buf: []const u8, digit_base: u8) ParseIntError!usize {
1717}1717}
17181718
1719test parseIntSizeSuffix {1719test parseIntSizeSuffix {
1720 try std.testing.expect(try parseIntSizeSuffix("2", 10) == 2);1720 try std.testing.expectEqual(2, try parseIntSizeSuffix("2", 10));
1721 try std.testing.expect(try parseIntSizeSuffix("2B", 10) == 2);1721 try std.testing.expectEqual(2, try parseIntSizeSuffix("2B", 10));
1722 try std.testing.expect(try parseIntSizeSuffix("2kB", 10) == 2000);1722 try std.testing.expectEqual(2000, try parseIntSizeSuffix("2kB", 10));
1723 try std.testing.expect(try parseIntSizeSuffix("2k", 10) == 2000);1723 try std.testing.expectEqual(2000, try parseIntSizeSuffix("2k", 10));
1724 try std.testing.expect(try parseIntSizeSuffix("2KiB", 10) == 2048);1724 try std.testing.expectEqual(2048, try parseIntSizeSuffix("2KiB", 10));
1725 try std.testing.expect(try parseIntSizeSuffix("2Ki", 10) == 2048);1725 try std.testing.expectEqual(2048, try parseIntSizeSuffix("2Ki", 10));
1726 try std.testing.expect(try parseIntSizeSuffix("aKiB", 16) == 10240);1726 try std.testing.expectEqual(10240, try parseIntSizeSuffix("aKiB", 16));
1727 try std.testing.expect(parseIntSizeSuffix("", 10) == error.InvalidCharacter);1727 try std.testing.expectError(error.InvalidCharacter, parseIntSizeSuffix("", 10));
1728 try std.testing.expect(parseIntSizeSuffix("2iB", 10) == error.InvalidCharacter);1728 try std.testing.expectError(error.InvalidCharacter, parseIntSizeSuffix("2iB", 10));
1729}1729}
17301730
1731pub const parseFloat = @import("fmt/parse_float.zig").parseFloat;1731pub const parseFloat = @import("fmt/parse_float.zig").parseFloat;
...@@ -1854,7 +1854,7 @@ test "parse u64 digit too big" {...@@ -1854,7 +1854,7 @@ test "parse u64 digit too big" {
18541854
1855test "parse unsigned comptime" {1855test "parse unsigned comptime" {
1856 comptime {1856 comptime {
1857 try std.testing.expect((try parseUnsigned(usize, "2", 10)) == 2);1857 try std.testing.expectEqual(2, try parseUnsigned(usize, "2", 10));
1858 }1858 }
1859}1859}
18601860
...@@ -1963,15 +1963,15 @@ test "buffer" {...@@ -1963,15 +1963,15 @@ test "buffer" {
1963 var buf1: [32]u8 = undefined;1963 var buf1: [32]u8 = undefined;
1964 var fbs = std.io.fixedBufferStream(&buf1);1964 var fbs = std.io.fixedBufferStream(&buf1);
1965 try formatType(1234, "", FormatOptions{}, fbs.writer(), std.options.fmt_max_depth);1965 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
1968 fbs.reset();1968 fbs.reset();
1969 try formatType('a', "c", FormatOptions{}, fbs.writer(), std.options.fmt_max_depth);1969 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
1972 fbs.reset();1972 fbs.reset();
1973 try formatType(0b1100, "b", FormatOptions{}, fbs.writer(), std.options.fmt_max_depth);1973 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());
1975 }1975 }
1976}1976}
19771977
...@@ -2372,10 +2372,10 @@ test "union" {...@@ -2372,10 +2372,10 @@ test "union" {
23722372
2373 var buf: [100]u8 = undefined;2373 var buf: [100]u8 = undefined;
2374 const uu_result = try bufPrint(buf[0..], "{}", .{uu_inst});2374 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
2377 const eu_result = try bufPrint(buf[0..], "{}", .{eu_inst});2377 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]);
2379}2379}
23802380
2381test "struct.self-referential" {2381test "struct.self-referential" {
...@@ -2476,7 +2476,7 @@ test "formatIntValue with comptime_int" {...@@ -2476,7 +2476,7 @@ test "formatIntValue with comptime_int" {
2476 var buf: [20]u8 = undefined;2476 var buf: [20]u8 = undefined;
2477 var fbs = std.io.fixedBufferStream(&buf);2477 var fbs = std.io.fixedBufferStream(&buf);
2478 try formatIntValue(value, "", FormatOptions{}, fbs.writer());2478 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());
2480}2480}
24812481
2482test "formatFloatValue with comptime_float" {2482test "formatFloatValue with comptime_float" {
...@@ -2542,19 +2542,19 @@ test "formatType max_depth" {...@@ -2542,19 +2542,19 @@ test "formatType max_depth" {
2542 var buf: [1000]u8 = undefined;2542 var buf: [1000]u8 = undefined;
2543 var fbs = std.io.fixedBufferStream(&buf);2543 var fbs = std.io.fixedBufferStream(&buf);
2544 try formatType(inst, "", FormatOptions{}, fbs.writer(), 0);2544 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
2547 fbs.reset();2547 fbs.reset();
2548 try formatType(inst, "", FormatOptions{}, fbs.writer(), 1);2548 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
2551 fbs.reset();2551 fbs.reset();
2552 try formatType(inst, "", FormatOptions{}, fbs.writer(), 2);2552 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
2555 fbs.reset();2555 fbs.reset();
2556 try formatType(inst, "", FormatOptions{}, fbs.writer(), 3);2556 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());
2558}2558}
25592559
2560test "positional" {2560test "positional" {