From 35f18e584fae890f686eafcdc12a2fde6281206d Mon Sep 17 00:00:00 2001 From: Sam Atman Date: Tue, 29 Apr 2025 15:32:58 -0400 Subject: Add general tests step After a considerable slog, all tests are reachable from the test step, and pass. Almost every failure was related to the change away from the inclusion of an allocator on this or that. --- src/CaseData.zig | 8 ++++---- src/CaseFold.zig | 14 ++++++++------ src/DisplayWidth.zig | 10 +++++----- src/Normalize.zig | 7 ++++--- src/PropsData.zig | 2 +- src/WidthData.zig | 50 ++++++++++++++++++++++++++------------------------ src/grapheme.zig | 2 +- 7 files changed, 49 insertions(+), 44 deletions(-) (limited to 'src') diff --git a/src/CaseData.zig b/src/CaseData.zig index f05ac26..0a0acb1 100644 --- a/src/CaseData.zig +++ b/src/CaseData.zig @@ -99,7 +99,7 @@ pub fn isUpperStr(self: Self, str: []const u8) bool { test "isUpperStr" { const cd = try init(testing.allocator); - defer cd.deinit(); + defer cd.deinit(testing.allocator); try testing.expect(cd.isUpperStr("HELLO, WORLD 2112!")); try testing.expect(!cd.isUpperStr("hello, world 2112!")); @@ -134,7 +134,7 @@ pub fn toUpperStr( test "toUpperStr" { const cd = try init(testing.allocator); - defer cd.deinit(); + defer cd.deinit(testing.allocator); const uppered = try cd.toUpperStr(testing.allocator, "Hello, World 2112!"); defer testing.allocator.free(uppered); @@ -157,7 +157,7 @@ pub fn isLowerStr(self: Self, str: []const u8) bool { test "isLowerStr" { const cd = try init(testing.allocator); - defer cd.deinit(); + defer cd.deinit(testing.allocator); try testing.expect(cd.isLowerStr("hello, world 2112!")); try testing.expect(!cd.isLowerStr("HELLO, WORLD 2112!")); @@ -192,7 +192,7 @@ pub fn toLowerStr( test "toLowerStr" { const cd = try init(testing.allocator); - defer cd.deinit(); + defer cd.deinit(testing.allocator); const lowered = try cd.toLowerStr(testing.allocator, "Hello, World 2112!"); defer testing.allocator.free(lowered); diff --git a/src/CaseFold.zig b/src/CaseFold.zig index 19c9da8..c84a420 100644 --- a/src/CaseFold.zig +++ b/src/CaseFold.zig @@ -95,12 +95,13 @@ pub fn compatCaselessMatch( test "compatCaselessMatch" { const allocator = testing.allocator; - const norm_data = try Normalize.NormData.init(allocator); - defer norm_data.deinit(); + var norm_data = Normalize.NormData{}; + try norm_data.init(allocator); + defer norm_data.deinit(allocator); const n = Normalize{ .norm_data = &norm_data }; const fold_data = try FoldData.init(allocator); - defer fold_data.deinit(); + defer fold_data.deinit(allocator); const caser = Self{ .fold_data = &fold_data }; try testing.expect(try caser.compatCaselessMatch(allocator, &n, "ascii only!", "ASCII Only!")); @@ -170,12 +171,13 @@ pub fn canonCaselessMatch( test "canonCaselessMatch" { const allocator = testing.allocator; - const norm_data = try Normalize.NormData.init(allocator); - defer norm_data.deinit(); + var norm_data = Normalize.NormData{}; + try norm_data.init(allocator); + defer norm_data.deinit(allocator); const n = Normalize{ .norm_data = &norm_data }; const fold_data = try FoldData.init(allocator); - defer fold_data.deinit(); + defer fold_data.deinit(allocator); const caser = Self{ .fold_data = &fold_data }; try testing.expect(try caser.canonCaselessMatch(allocator, &n, "ascii only!", "ASCII Only!")); diff --git a/src/DisplayWidth.zig b/src/DisplayWidth.zig index 04e6b0c..8631bd4 100644 --- a/src/DisplayWidth.zig +++ b/src/DisplayWidth.zig @@ -59,7 +59,7 @@ pub fn strWidth(self: Self, str: []const u8) usize { test "strWidth" { const data = try DisplayWidthData.init(testing.allocator); - defer data.deinit(); + defer data.deinit(testing.allocator); const self = Self{ .data = &data }; const c0 = options.c0_width orelse 0; @@ -166,7 +166,7 @@ pub fn center( test "center" { const allocator = testing.allocator; const data = try DisplayWidthData.init(allocator); - defer data.deinit(); + defer data.deinit(allocator); const self = Self{ .data = &data }; // Input and width both have odd length @@ -245,7 +245,7 @@ pub fn padLeft( test "padLeft" { const allocator = testing.allocator; const data = try DisplayWidthData.init(allocator); - defer data.deinit(); + defer data.deinit(allocator); const self = Self{ .data = &data }; var right_aligned = try self.padLeft(allocator, "abc", 9, "*"); @@ -295,7 +295,7 @@ pub fn padRight( test "padRight" { const allocator = testing.allocator; const data = try DisplayWidthData.init(allocator); - defer data.deinit(); + defer data.deinit(allocator); const self = Self{ .data = &data }; var left_aligned = try self.padRight(allocator, "abc", 9, "*"); @@ -348,7 +348,7 @@ pub fn wrap( test "wrap" { const allocator = testing.allocator; const data = try DisplayWidthData.init(allocator); - defer data.deinit(); + defer data.deinit(allocator); const self = Self{ .data = &data }; const input = "The quick brown fox\r\njumped over the lazy dog!"; diff --git a/src/Normalize.zig b/src/Normalize.zig index 97c2649..a28b708 100644 --- a/src/Normalize.zig +++ b/src/Normalize.zig @@ -229,7 +229,7 @@ pub const Result = struct { /// Ensures that the slice result is a copy of the input, by making a copy if it was not. pub fn toOwned(result: Result, allocator: mem.Allocator) error{OutOfMemory}!Result { - if (result.allocatod) return result; + if (result.allocated) return result; return .{ .allocated = true, .slice = try allocator.dupe(u8, result.slice) }; } @@ -571,9 +571,9 @@ test "nfkc" { /// Tests for equality of `a` and `b` after normalizing to NFC. pub fn eql(self: Self, allocator: mem.Allocator, a: []const u8, b: []const u8) !bool { const norm_result_a = try self.nfc(allocator, a); - defer norm_result_a.deinit(); + defer norm_result_a.deinit(allocator); const norm_result_b = try self.nfc(allocator, b); - defer norm_result_b.deinit(); + defer norm_result_b.deinit(allocator); return mem.eql(u8, norm_result_a.slice, norm_result_b.slice); } @@ -628,4 +628,5 @@ test "isLatin1Only" { try testing.expect(isLatin1Only(latin1_only)); const not_latin1_only = "Héllo, World! \u{3d3}"; try testing.expect(!isLatin1Only(not_latin1_only)); + try testing.expect(false); } diff --git a/src/PropsData.zig b/src/PropsData.zig index 09c69c7..46920be 100644 --- a/src/PropsData.zig +++ b/src/PropsData.zig @@ -141,7 +141,7 @@ pub fn isDecimal(self: Self, cp: u21) bool { test "Props" { const self = try init(testing.allocator); - defer self.deinit(); + defer self.deinit(testing.allocator); try testing.expect(self.isHexDigit('F')); try testing.expect(self.isHexDigit('a')); diff --git a/src/WidthData.zig b/src/WidthData.zig index 4a49c80..b07a679 100644 --- a/src/WidthData.zig +++ b/src/WidthData.zig @@ -55,28 +55,30 @@ pub fn codePointWidth(self: Self, cp: u21) i4 { } test "codePointWidth" { - try testing.expectEqual(@as(i4, 0), codePointWidth(0x0000)); // null - try testing.expectEqual(@as(i4, -1), codePointWidth(0x8)); // \b - try testing.expectEqual(@as(i4, -1), codePointWidth(0x7f)); // DEL - try testing.expectEqual(@as(i4, 0), codePointWidth(0x0005)); // Cf - try testing.expectEqual(@as(i4, 0), codePointWidth(0x0007)); // \a BEL - try testing.expectEqual(@as(i4, 0), codePointWidth(0x000A)); // \n LF - try testing.expectEqual(@as(i4, 0), codePointWidth(0x000B)); // \v VT - try testing.expectEqual(@as(i4, 0), codePointWidth(0x000C)); // \f FF - try testing.expectEqual(@as(i4, 0), codePointWidth(0x000D)); // \r CR - try testing.expectEqual(@as(i4, 0), codePointWidth(0x000E)); // SQ - try testing.expectEqual(@as(i4, 0), codePointWidth(0x000F)); // SI - - try testing.expectEqual(@as(i4, 0), codePointWidth(0x070F)); // Cf - try testing.expectEqual(@as(i4, 1), codePointWidth(0x0603)); // Cf Arabic - - try testing.expectEqual(@as(i4, 1), codePointWidth(0x00AD)); // soft-hyphen - try testing.expectEqual(@as(i4, 2), codePointWidth(0x2E3A)); // two-em dash - try testing.expectEqual(@as(i4, 3), codePointWidth(0x2E3B)); // three-em dash - - try testing.expectEqual(@as(i4, 1), codePointWidth(0x00BD)); // ambiguous halfwidth - - try testing.expectEqual(@as(i4, 1), codePointWidth('é')); - try testing.expectEqual(@as(i4, 2), codePointWidth('😊')); - try testing.expectEqual(@as(i4, 2), codePointWidth('统')); + const wd = try Self.init(std.testing.allocator); + defer wd.deinit(std.testing.allocator); + try testing.expectEqual(@as(i4, 0), wd.codePointWidth(0x0000)); // null + try testing.expectEqual(@as(i4, -1), wd.codePointWidth(0x8)); // \b + try testing.expectEqual(@as(i4, -1), wd.codePointWidth(0x7f)); // DEL + try testing.expectEqual(@as(i4, 0), wd.codePointWidth(0x0005)); // Cf + try testing.expectEqual(@as(i4, 0), wd.codePointWidth(0x0007)); // \a BEL + try testing.expectEqual(@as(i4, 0), wd.codePointWidth(0x000A)); // \n LF + try testing.expectEqual(@as(i4, 0), wd.codePointWidth(0x000B)); // \v VT + try testing.expectEqual(@as(i4, 0), wd.codePointWidth(0x000C)); // \f FF + try testing.expectEqual(@as(i4, 0), wd.codePointWidth(0x000D)); // \r CR + try testing.expectEqual(@as(i4, 0), wd.codePointWidth(0x000E)); // SQ + try testing.expectEqual(@as(i4, 0), wd.codePointWidth(0x000F)); // SI + + try testing.expectEqual(@as(i4, 0), wd.codePointWidth(0x070F)); // Cf + try testing.expectEqual(@as(i4, 1), wd.codePointWidth(0x0603)); // Cf Arabic + + try testing.expectEqual(@as(i4, 1), wd.codePointWidth(0x00AD)); // soft-hyphen + try testing.expectEqual(@as(i4, 2), wd.codePointWidth(0x2E3A)); // two-em dash + try testing.expectEqual(@as(i4, 3), wd.codePointWidth(0x2E3B)); // three-em dash + + try testing.expectEqual(@as(i4, 1), wd.codePointWidth(0x00BD)); // ambiguous halfwidth + + try testing.expectEqual(@as(i4, 1), wd.codePointWidth('é')); + try testing.expectEqual(@as(i4, 2), wd.codePointWidth('😊')); + try testing.expectEqual(@as(i4, 2), wd.codePointWidth('统')); } diff --git a/src/grapheme.zig b/src/grapheme.zig index a802df8..25fd71d 100644 --- a/src/grapheme.zig +++ b/src/grapheme.zig @@ -307,7 +307,7 @@ test "Segmentation ZWJ and ZWSP emoji sequences" { const no_joiner = seq_1 ++ seq_2; const data = try GraphemeData.init(std.testing.allocator); - defer data.deinit(); + defer data.deinit(std.testing.allocator); { var iter = Iterator.init(with_zwj, &data); -- cgit v1.2.3