diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/CaseData.zig | 8 | ||||
| -rw-r--r-- | src/CaseFold.zig | 14 | ||||
| -rw-r--r-- | src/DisplayWidth.zig | 10 | ||||
| -rw-r--r-- | src/Normalize.zig | 7 | ||||
| -rw-r--r-- | src/PropsData.zig | 2 | ||||
| -rw-r--r-- | src/WidthData.zig | 50 | ||||
| -rw-r--r-- | src/grapheme.zig | 2 |
7 files changed, 49 insertions, 44 deletions
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 { | |||
| 99 | 99 | ||
| 100 | test "isUpperStr" { | 100 | test "isUpperStr" { |
| 101 | const cd = try init(testing.allocator); | 101 | const cd = try init(testing.allocator); |
| 102 | defer cd.deinit(); | 102 | defer cd.deinit(testing.allocator); |
| 103 | 103 | ||
| 104 | try testing.expect(cd.isUpperStr("HELLO, WORLD 2112!")); | 104 | try testing.expect(cd.isUpperStr("HELLO, WORLD 2112!")); |
| 105 | try testing.expect(!cd.isUpperStr("hello, world 2112!")); | 105 | try testing.expect(!cd.isUpperStr("hello, world 2112!")); |
| @@ -134,7 +134,7 @@ pub fn toUpperStr( | |||
| 134 | 134 | ||
| 135 | test "toUpperStr" { | 135 | test "toUpperStr" { |
| 136 | const cd = try init(testing.allocator); | 136 | const cd = try init(testing.allocator); |
| 137 | defer cd.deinit(); | 137 | defer cd.deinit(testing.allocator); |
| 138 | 138 | ||
| 139 | const uppered = try cd.toUpperStr(testing.allocator, "Hello, World 2112!"); | 139 | const uppered = try cd.toUpperStr(testing.allocator, "Hello, World 2112!"); |
| 140 | defer testing.allocator.free(uppered); | 140 | defer testing.allocator.free(uppered); |
| @@ -157,7 +157,7 @@ pub fn isLowerStr(self: Self, str: []const u8) bool { | |||
| 157 | 157 | ||
| 158 | test "isLowerStr" { | 158 | test "isLowerStr" { |
| 159 | const cd = try init(testing.allocator); | 159 | const cd = try init(testing.allocator); |
| 160 | defer cd.deinit(); | 160 | defer cd.deinit(testing.allocator); |
| 161 | 161 | ||
| 162 | try testing.expect(cd.isLowerStr("hello, world 2112!")); | 162 | try testing.expect(cd.isLowerStr("hello, world 2112!")); |
| 163 | try testing.expect(!cd.isLowerStr("HELLO, WORLD 2112!")); | 163 | try testing.expect(!cd.isLowerStr("HELLO, WORLD 2112!")); |
| @@ -192,7 +192,7 @@ pub fn toLowerStr( | |||
| 192 | 192 | ||
| 193 | test "toLowerStr" { | 193 | test "toLowerStr" { |
| 194 | const cd = try init(testing.allocator); | 194 | const cd = try init(testing.allocator); |
| 195 | defer cd.deinit(); | 195 | defer cd.deinit(testing.allocator); |
| 196 | 196 | ||
| 197 | const lowered = try cd.toLowerStr(testing.allocator, "Hello, World 2112!"); | 197 | const lowered = try cd.toLowerStr(testing.allocator, "Hello, World 2112!"); |
| 198 | defer testing.allocator.free(lowered); | 198 | 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( | |||
| 95 | test "compatCaselessMatch" { | 95 | test "compatCaselessMatch" { |
| 96 | const allocator = testing.allocator; | 96 | const allocator = testing.allocator; |
| 97 | 97 | ||
| 98 | const norm_data = try Normalize.NormData.init(allocator); | 98 | var norm_data = Normalize.NormData{}; |
| 99 | defer norm_data.deinit(); | 99 | try norm_data.init(allocator); |
| 100 | defer norm_data.deinit(allocator); | ||
| 100 | const n = Normalize{ .norm_data = &norm_data }; | 101 | const n = Normalize{ .norm_data = &norm_data }; |
| 101 | 102 | ||
| 102 | const fold_data = try FoldData.init(allocator); | 103 | const fold_data = try FoldData.init(allocator); |
| 103 | defer fold_data.deinit(); | 104 | defer fold_data.deinit(allocator); |
| 104 | const caser = Self{ .fold_data = &fold_data }; | 105 | const caser = Self{ .fold_data = &fold_data }; |
| 105 | 106 | ||
| 106 | try testing.expect(try caser.compatCaselessMatch(allocator, &n, "ascii only!", "ASCII Only!")); | 107 | try testing.expect(try caser.compatCaselessMatch(allocator, &n, "ascii only!", "ASCII Only!")); |
| @@ -170,12 +171,13 @@ pub fn canonCaselessMatch( | |||
| 170 | test "canonCaselessMatch" { | 171 | test "canonCaselessMatch" { |
| 171 | const allocator = testing.allocator; | 172 | const allocator = testing.allocator; |
| 172 | 173 | ||
| 173 | const norm_data = try Normalize.NormData.init(allocator); | 174 | var norm_data = Normalize.NormData{}; |
| 174 | defer norm_data.deinit(); | 175 | try norm_data.init(allocator); |
| 176 | defer norm_data.deinit(allocator); | ||
| 175 | const n = Normalize{ .norm_data = &norm_data }; | 177 | const n = Normalize{ .norm_data = &norm_data }; |
| 176 | 178 | ||
| 177 | const fold_data = try FoldData.init(allocator); | 179 | const fold_data = try FoldData.init(allocator); |
| 178 | defer fold_data.deinit(); | 180 | defer fold_data.deinit(allocator); |
| 179 | const caser = Self{ .fold_data = &fold_data }; | 181 | const caser = Self{ .fold_data = &fold_data }; |
| 180 | 182 | ||
| 181 | try testing.expect(try caser.canonCaselessMatch(allocator, &n, "ascii only!", "ASCII Only!")); | 183 | 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 { | |||
| 59 | 59 | ||
| 60 | test "strWidth" { | 60 | test "strWidth" { |
| 61 | const data = try DisplayWidthData.init(testing.allocator); | 61 | const data = try DisplayWidthData.init(testing.allocator); |
| 62 | defer data.deinit(); | 62 | defer data.deinit(testing.allocator); |
| 63 | const self = Self{ .data = &data }; | 63 | const self = Self{ .data = &data }; |
| 64 | const c0 = options.c0_width orelse 0; | 64 | const c0 = options.c0_width orelse 0; |
| 65 | 65 | ||
| @@ -166,7 +166,7 @@ pub fn center( | |||
| 166 | test "center" { | 166 | test "center" { |
| 167 | const allocator = testing.allocator; | 167 | const allocator = testing.allocator; |
| 168 | const data = try DisplayWidthData.init(allocator); | 168 | const data = try DisplayWidthData.init(allocator); |
| 169 | defer data.deinit(); | 169 | defer data.deinit(allocator); |
| 170 | const self = Self{ .data = &data }; | 170 | const self = Self{ .data = &data }; |
| 171 | 171 | ||
| 172 | // Input and width both have odd length | 172 | // Input and width both have odd length |
| @@ -245,7 +245,7 @@ pub fn padLeft( | |||
| 245 | test "padLeft" { | 245 | test "padLeft" { |
| 246 | const allocator = testing.allocator; | 246 | const allocator = testing.allocator; |
| 247 | const data = try DisplayWidthData.init(allocator); | 247 | const data = try DisplayWidthData.init(allocator); |
| 248 | defer data.deinit(); | 248 | defer data.deinit(allocator); |
| 249 | const self = Self{ .data = &data }; | 249 | const self = Self{ .data = &data }; |
| 250 | 250 | ||
| 251 | var right_aligned = try self.padLeft(allocator, "abc", 9, "*"); | 251 | var right_aligned = try self.padLeft(allocator, "abc", 9, "*"); |
| @@ -295,7 +295,7 @@ pub fn padRight( | |||
| 295 | test "padRight" { | 295 | test "padRight" { |
| 296 | const allocator = testing.allocator; | 296 | const allocator = testing.allocator; |
| 297 | const data = try DisplayWidthData.init(allocator); | 297 | const data = try DisplayWidthData.init(allocator); |
| 298 | defer data.deinit(); | 298 | defer data.deinit(allocator); |
| 299 | const self = Self{ .data = &data }; | 299 | const self = Self{ .data = &data }; |
| 300 | 300 | ||
| 301 | var left_aligned = try self.padRight(allocator, "abc", 9, "*"); | 301 | var left_aligned = try self.padRight(allocator, "abc", 9, "*"); |
| @@ -348,7 +348,7 @@ pub fn wrap( | |||
| 348 | test "wrap" { | 348 | test "wrap" { |
| 349 | const allocator = testing.allocator; | 349 | const allocator = testing.allocator; |
| 350 | const data = try DisplayWidthData.init(allocator); | 350 | const data = try DisplayWidthData.init(allocator); |
| 351 | defer data.deinit(); | 351 | defer data.deinit(allocator); |
| 352 | const self = Self{ .data = &data }; | 352 | const self = Self{ .data = &data }; |
| 353 | 353 | ||
| 354 | const input = "The quick brown fox\r\njumped over the lazy dog!"; | 354 | 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 { | |||
| 229 | 229 | ||
| 230 | /// Ensures that the slice result is a copy of the input, by making a copy if it was not. | 230 | /// Ensures that the slice result is a copy of the input, by making a copy if it was not. |
| 231 | pub fn toOwned(result: Result, allocator: mem.Allocator) error{OutOfMemory}!Result { | 231 | pub fn toOwned(result: Result, allocator: mem.Allocator) error{OutOfMemory}!Result { |
| 232 | if (result.allocatod) return result; | 232 | if (result.allocated) return result; |
| 233 | return .{ .allocated = true, .slice = try allocator.dupe(u8, result.slice) }; | 233 | return .{ .allocated = true, .slice = try allocator.dupe(u8, result.slice) }; |
| 234 | } | 234 | } |
| 235 | 235 | ||
| @@ -571,9 +571,9 @@ test "nfkc" { | |||
| 571 | /// Tests for equality of `a` and `b` after normalizing to NFC. | 571 | /// Tests for equality of `a` and `b` after normalizing to NFC. |
| 572 | pub fn eql(self: Self, allocator: mem.Allocator, a: []const u8, b: []const u8) !bool { | 572 | pub fn eql(self: Self, allocator: mem.Allocator, a: []const u8, b: []const u8) !bool { |
| 573 | const norm_result_a = try self.nfc(allocator, a); | 573 | const norm_result_a = try self.nfc(allocator, a); |
| 574 | defer norm_result_a.deinit(); | 574 | defer norm_result_a.deinit(allocator); |
| 575 | const norm_result_b = try self.nfc(allocator, b); | 575 | const norm_result_b = try self.nfc(allocator, b); |
| 576 | defer norm_result_b.deinit(); | 576 | defer norm_result_b.deinit(allocator); |
| 577 | 577 | ||
| 578 | return mem.eql(u8, norm_result_a.slice, norm_result_b.slice); | 578 | return mem.eql(u8, norm_result_a.slice, norm_result_b.slice); |
| 579 | } | 579 | } |
| @@ -628,4 +628,5 @@ test "isLatin1Only" { | |||
| 628 | try testing.expect(isLatin1Only(latin1_only)); | 628 | try testing.expect(isLatin1Only(latin1_only)); |
| 629 | const not_latin1_only = "Héllo, World! \u{3d3}"; | 629 | const not_latin1_only = "Héllo, World! \u{3d3}"; |
| 630 | try testing.expect(!isLatin1Only(not_latin1_only)); | 630 | try testing.expect(!isLatin1Only(not_latin1_only)); |
| 631 | try testing.expect(false); | ||
| 631 | } | 632 | } |
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 { | |||
| 141 | 141 | ||
| 142 | test "Props" { | 142 | test "Props" { |
| 143 | const self = try init(testing.allocator); | 143 | const self = try init(testing.allocator); |
| 144 | defer self.deinit(); | 144 | defer self.deinit(testing.allocator); |
| 145 | 145 | ||
| 146 | try testing.expect(self.isHexDigit('F')); | 146 | try testing.expect(self.isHexDigit('F')); |
| 147 | try testing.expect(self.isHexDigit('a')); | 147 | 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 { | |||
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | test "codePointWidth" { | 57 | test "codePointWidth" { |
| 58 | try testing.expectEqual(@as(i4, 0), codePointWidth(0x0000)); // null | 58 | const wd = try Self.init(std.testing.allocator); |
| 59 | try testing.expectEqual(@as(i4, -1), codePointWidth(0x8)); // \b | 59 | defer wd.deinit(std.testing.allocator); |
| 60 | try testing.expectEqual(@as(i4, -1), codePointWidth(0x7f)); // DEL | 60 | try testing.expectEqual(@as(i4, 0), wd.codePointWidth(0x0000)); // null |
| 61 | try testing.expectEqual(@as(i4, 0), codePointWidth(0x0005)); // Cf | 61 | try testing.expectEqual(@as(i4, -1), wd.codePointWidth(0x8)); // \b |
| 62 | try testing.expectEqual(@as(i4, 0), codePointWidth(0x0007)); // \a BEL | 62 | try testing.expectEqual(@as(i4, -1), wd.codePointWidth(0x7f)); // DEL |
| 63 | try testing.expectEqual(@as(i4, 0), codePointWidth(0x000A)); // \n LF | 63 | try testing.expectEqual(@as(i4, 0), wd.codePointWidth(0x0005)); // Cf |
| 64 | try testing.expectEqual(@as(i4, 0), codePointWidth(0x000B)); // \v VT | 64 | try testing.expectEqual(@as(i4, 0), wd.codePointWidth(0x0007)); // \a BEL |
| 65 | try testing.expectEqual(@as(i4, 0), codePointWidth(0x000C)); // \f FF | 65 | try testing.expectEqual(@as(i4, 0), wd.codePointWidth(0x000A)); // \n LF |
| 66 | try testing.expectEqual(@as(i4, 0), codePointWidth(0x000D)); // \r CR | 66 | try testing.expectEqual(@as(i4, 0), wd.codePointWidth(0x000B)); // \v VT |
| 67 | try testing.expectEqual(@as(i4, 0), codePointWidth(0x000E)); // SQ | 67 | try testing.expectEqual(@as(i4, 0), wd.codePointWidth(0x000C)); // \f FF |
| 68 | try testing.expectEqual(@as(i4, 0), codePointWidth(0x000F)); // SI | 68 | try testing.expectEqual(@as(i4, 0), wd.codePointWidth(0x000D)); // \r CR |
| 69 | 69 | try testing.expectEqual(@as(i4, 0), wd.codePointWidth(0x000E)); // SQ | |
| 70 | try testing.expectEqual(@as(i4, 0), codePointWidth(0x070F)); // Cf | 70 | try testing.expectEqual(@as(i4, 0), wd.codePointWidth(0x000F)); // SI |
| 71 | try testing.expectEqual(@as(i4, 1), codePointWidth(0x0603)); // Cf Arabic | 71 | |
| 72 | 72 | try testing.expectEqual(@as(i4, 0), wd.codePointWidth(0x070F)); // Cf | |
| 73 | try testing.expectEqual(@as(i4, 1), codePointWidth(0x00AD)); // soft-hyphen | 73 | try testing.expectEqual(@as(i4, 1), wd.codePointWidth(0x0603)); // Cf Arabic |
| 74 | try testing.expectEqual(@as(i4, 2), codePointWidth(0x2E3A)); // two-em dash | 74 | |
| 75 | try testing.expectEqual(@as(i4, 3), codePointWidth(0x2E3B)); // three-em dash | 75 | try testing.expectEqual(@as(i4, 1), wd.codePointWidth(0x00AD)); // soft-hyphen |
| 76 | 76 | try testing.expectEqual(@as(i4, 2), wd.codePointWidth(0x2E3A)); // two-em dash | |
| 77 | try testing.expectEqual(@as(i4, 1), codePointWidth(0x00BD)); // ambiguous halfwidth | 77 | try testing.expectEqual(@as(i4, 3), wd.codePointWidth(0x2E3B)); // three-em dash |
| 78 | 78 | ||
| 79 | try testing.expectEqual(@as(i4, 1), codePointWidth('é')); | 79 | try testing.expectEqual(@as(i4, 1), wd.codePointWidth(0x00BD)); // ambiguous halfwidth |
| 80 | try testing.expectEqual(@as(i4, 2), codePointWidth('😊')); | 80 | |
| 81 | try testing.expectEqual(@as(i4, 2), codePointWidth('统')); | 81 | try testing.expectEqual(@as(i4, 1), wd.codePointWidth('é')); |
| 82 | try testing.expectEqual(@as(i4, 2), wd.codePointWidth('😊')); | ||
| 83 | try testing.expectEqual(@as(i4, 2), wd.codePointWidth('统')); | ||
| 82 | } | 84 | } |
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" { | |||
| 307 | const no_joiner = seq_1 ++ seq_2; | 307 | const no_joiner = seq_1 ++ seq_2; |
| 308 | 308 | ||
| 309 | const data = try GraphemeData.init(std.testing.allocator); | 309 | const data = try GraphemeData.init(std.testing.allocator); |
| 310 | defer data.deinit(); | 310 | defer data.deinit(std.testing.allocator); |
| 311 | 311 | ||
| 312 | { | 312 | { |
| 313 | var iter = Iterator.init(with_zwj, &data); | 313 | var iter = Iterator.init(with_zwj, &data); |