summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build.zig155
-rw-r--r--src/CaseData.zig8
-rw-r--r--src/CaseFold.zig14
-rw-r--r--src/DisplayWidth.zig10
-rw-r--r--src/Normalize.zig7
-rw-r--r--src/PropsData.zig2
-rw-r--r--src/WidthData.zig50
-rw-r--r--src/grapheme.zig2
8 files changed, 204 insertions, 44 deletions
diff --git a/build.zig b/build.zig
index ce362ea..b555bd7 100644
--- a/build.zig
+++ b/build.zig
@@ -183,6 +183,14 @@ pub fn build(b: *std.Build) void {
183 .optimize = optimize, 183 .optimize = optimize,
184 }); 184 });
185 185
186 const code_point_t = b.addTest(.{
187 .name = "code_point",
188 .root_module = code_point,
189 .target = target,
190 .optimize = optimize,
191 });
192 const code_point_tr = b.addRunArtifact(code_point_t);
193
186 // Grapheme clusters 194 // Grapheme clusters
187 const grapheme_data = b.createModule(.{ 195 const grapheme_data = b.createModule(.{
188 .root_source_file = b.path("src/GraphemeData.zig"), 196 .root_source_file = b.path("src/GraphemeData.zig"),
@@ -191,6 +199,14 @@ pub fn build(b: *std.Build) void {
191 }); 199 });
192 grapheme_data.addAnonymousImport("gbp", .{ .root_source_file = gbp_gen_out }); 200 grapheme_data.addAnonymousImport("gbp", .{ .root_source_file = gbp_gen_out });
193 201
202 const grapheme_data_t = b.addTest(.{
203 .name = "grapheme_data",
204 .root_module = grapheme_data,
205 .target = target,
206 .optimize = optimize,
207 });
208 const grapheme_data_tr = b.addRunArtifact(grapheme_data_t);
209
194 const grapheme = b.addModule("grapheme", .{ 210 const grapheme = b.addModule("grapheme", .{
195 .root_source_file = b.path("src/grapheme.zig"), 211 .root_source_file = b.path("src/grapheme.zig"),
196 .target = target, 212 .target = target,
@@ -199,6 +215,14 @@ pub fn build(b: *std.Build) void {
199 grapheme.addImport("code_point", code_point); 215 grapheme.addImport("code_point", code_point);
200 grapheme.addImport("GraphemeData", grapheme_data); 216 grapheme.addImport("GraphemeData", grapheme_data);
201 217
218 const grapheme_t = b.addTest(.{
219 .name = "grapheme",
220 .root_module = grapheme,
221 .target = target,
222 .optimize = optimize,
223 });
224 const grapheme_tr = b.addRunArtifact(grapheme_t);
225
202 // ASCII utilities 226 // ASCII utilities
203 const ascii = b.addModule("ascii", .{ 227 const ascii = b.addModule("ascii", .{
204 .root_source_file = b.path("src/ascii.zig"), 228 .root_source_file = b.path("src/ascii.zig"),
@@ -206,6 +230,14 @@ pub fn build(b: *std.Build) void {
206 .optimize = optimize, 230 .optimize = optimize,
207 }); 231 });
208 232
233 const ascii_t = b.addTest(.{
234 .name = "ascii",
235 .root_module = ascii,
236 .target = target,
237 .optimize = optimize,
238 });
239 const ascii_tr = b.addRunArtifact(ascii_t);
240
209 // Fixed pitch font display width 241 // Fixed pitch font display width
210 const width_data = b.createModule(.{ 242 const width_data = b.createModule(.{
211 .root_source_file = b.path("src/WidthData.zig"), 243 .root_source_file = b.path("src/WidthData.zig"),
@@ -215,6 +247,14 @@ pub fn build(b: *std.Build) void {
215 width_data.addAnonymousImport("dwp", .{ .root_source_file = dwp_gen_out }); 247 width_data.addAnonymousImport("dwp", .{ .root_source_file = dwp_gen_out });
216 width_data.addImport("GraphemeData", grapheme_data); 248 width_data.addImport("GraphemeData", grapheme_data);
217 249
250 const width_data_t = b.addTest(.{
251 .name = "width_data",
252 .root_module = width_data,
253 .target = target,
254 .optimize = optimize,
255 });
256 const width_data_tr = b.addRunArtifact(width_data_t);
257
218 const display_width = b.addModule("DisplayWidth", .{ 258 const display_width = b.addModule("DisplayWidth", .{
219 .root_source_file = b.path("src/DisplayWidth.zig"), 259 .root_source_file = b.path("src/DisplayWidth.zig"),
220 .target = target, 260 .target = target,
@@ -226,6 +266,14 @@ pub fn build(b: *std.Build) void {
226 display_width.addImport("DisplayWidthData", width_data); 266 display_width.addImport("DisplayWidthData", width_data);
227 display_width.addOptions("options", options); // For testing 267 display_width.addOptions("options", options); // For testing
228 268
269 const display_width_t = b.addTest(.{
270 .name = "display_width",
271 .root_module = display_width,
272 .target = target,
273 .optimize = optimize,
274 });
275 const display_width_tr = b.addRunArtifact(display_width_t);
276
229 // Normalization 277 // Normalization
230 const ccc_data = b.createModule(.{ 278 const ccc_data = b.createModule(.{
231 .root_source_file = b.path("src/CombiningData.zig"), 279 .root_source_file = b.path("src/CombiningData.zig"),
@@ -234,6 +282,14 @@ pub fn build(b: *std.Build) void {
234 }); 282 });
235 ccc_data.addAnonymousImport("ccc", .{ .root_source_file = ccc_gen_out }); 283 ccc_data.addAnonymousImport("ccc", .{ .root_source_file = ccc_gen_out });
236 284
285 const ccc_data_t = b.addTest(.{
286 .name = "ccc_data",
287 .root_module = ccc_data,
288 .target = target,
289 .optimize = optimize,
290 });
291 const ccc_data_tr = b.addRunArtifact(ccc_data_t);
292
237 const canon_data = b.createModule(.{ 293 const canon_data = b.createModule(.{
238 .root_source_file = b.path("src/CanonData.zig"), 294 .root_source_file = b.path("src/CanonData.zig"),
239 .target = target, 295 .target = target,
@@ -241,6 +297,14 @@ pub fn build(b: *std.Build) void {
241 }); 297 });
242 canon_data.addAnonymousImport("canon", .{ .root_source_file = canon_gen_out }); 298 canon_data.addAnonymousImport("canon", .{ .root_source_file = canon_gen_out });
243 299
300 const canon_data_t = b.addTest(.{
301 .name = "canon_data",
302 .root_module = canon_data,
303 .target = target,
304 .optimize = optimize,
305 });
306 const canon_data_tr = b.addRunArtifact(canon_data_t);
307
244 const compat_data = b.createModule(.{ 308 const compat_data = b.createModule(.{
245 .root_source_file = b.path("src/CompatData.zig"), 309 .root_source_file = b.path("src/CompatData.zig"),
246 .target = target, 310 .target = target,
@@ -248,6 +312,14 @@ pub fn build(b: *std.Build) void {
248 }); 312 });
249 compat_data.addAnonymousImport("compat", .{ .root_source_file = compat_gen_out }); 313 compat_data.addAnonymousImport("compat", .{ .root_source_file = compat_gen_out });
250 314
315 const compat_data_t = b.addTest(.{
316 .name = "compat_data",
317 .root_module = compat_data,
318 .target = target,
319 .optimize = optimize,
320 });
321 const compat_data_tr = b.addRunArtifact(compat_data_t);
322
251 const hangul_data = b.createModule(.{ 323 const hangul_data = b.createModule(.{
252 .root_source_file = b.path("src/HangulData.zig"), 324 .root_source_file = b.path("src/HangulData.zig"),
253 .target = target, 325 .target = target,
@@ -255,6 +327,14 @@ pub fn build(b: *std.Build) void {
255 }); 327 });
256 hangul_data.addAnonymousImport("hangul", .{ .root_source_file = hangul_gen_out }); 328 hangul_data.addAnonymousImport("hangul", .{ .root_source_file = hangul_gen_out });
257 329
330 const hangul_data_t = b.addTest(.{
331 .name = "hangul_data",
332 .root_module = hangul_data,
333 .target = target,
334 .optimize = optimize,
335 });
336 const hangul_data_tr = b.addRunArtifact(hangul_data_t);
337
258 const normp_data = b.createModule(.{ 338 const normp_data = b.createModule(.{
259 .root_source_file = b.path("src/NormPropsData.zig"), 339 .root_source_file = b.path("src/NormPropsData.zig"),
260 .target = target, 340 .target = target,
@@ -262,6 +342,14 @@ pub fn build(b: *std.Build) void {
262 }); 342 });
263 normp_data.addAnonymousImport("normp", .{ .root_source_file = normp_gen_out }); 343 normp_data.addAnonymousImport("normp", .{ .root_source_file = normp_gen_out });
264 344
345 const normp_data_t = b.addTest(.{
346 .name = "normp_data",
347 .root_module = normp_data,
348 .target = target,
349 .optimize = optimize,
350 });
351 const normp_data_tr = b.addRunArtifact(normp_data_t);
352
265 const norm_data = b.createModule(.{ 353 const norm_data = b.createModule(.{
266 .root_source_file = b.path("src/NormData.zig"), 354 .root_source_file = b.path("src/NormData.zig"),
267 .target = target, 355 .target = target,
@@ -282,6 +370,14 @@ pub fn build(b: *std.Build) void {
282 norm.addImport("code_point", code_point); 370 norm.addImport("code_point", code_point);
283 norm.addImport("NormData", norm_data); 371 norm.addImport("NormData", norm_data);
284 372
373 const norm_data_t = b.addTest(.{
374 .name = "norm_data",
375 .root_module = norm_data,
376 .target = target,
377 .optimize = optimize,
378 });
379 const norm_data_tr = b.addRunArtifact(norm_data_t);
380
285 // General Category 381 // General Category
286 const gencat_data = b.addModule("GenCatData", .{ 382 const gencat_data = b.addModule("GenCatData", .{
287 .root_source_file = b.path("src/GenCatData.zig"), 383 .root_source_file = b.path("src/GenCatData.zig"),
@@ -290,6 +386,14 @@ pub fn build(b: *std.Build) void {
290 }); 386 });
291 gencat_data.addAnonymousImport("gencat", .{ .root_source_file = gencat_gen_out }); 387 gencat_data.addAnonymousImport("gencat", .{ .root_source_file = gencat_gen_out });
292 388
389 const gencat_data_t = b.addTest(.{
390 .name = "gencat_data",
391 .root_module = gencat_data,
392 .target = target,
393 .optimize = optimize,
394 });
395 const gencat_data_tr = b.addRunArtifact(gencat_data_t);
396
293 // Case folding 397 // Case folding
294 const fold_data = b.createModule(.{ 398 const fold_data = b.createModule(.{
295 .root_source_file = b.path("src/FoldData.zig"), 399 .root_source_file = b.path("src/FoldData.zig"),
@@ -307,6 +411,14 @@ pub fn build(b: *std.Build) void {
307 case_fold.addImport("FoldData", fold_data); 411 case_fold.addImport("FoldData", fold_data);
308 case_fold.addImport("Normalize", norm); 412 case_fold.addImport("Normalize", norm);
309 413
414 const case_fold_t = b.addTest(.{
415 .name = "case_fold",
416 .root_module = case_fold,
417 .target = target,
418 .optimize = optimize,
419 });
420 const case_fold_tr = b.addRunArtifact(case_fold_t);
421
310 // Letter case 422 // Letter case
311 const case_data = b.addModule("CaseData", .{ 423 const case_data = b.addModule("CaseData", .{
312 .root_source_file = b.path("src/CaseData.zig"), 424 .root_source_file = b.path("src/CaseData.zig"),
@@ -318,6 +430,14 @@ pub fn build(b: *std.Build) void {
318 case_data.addAnonymousImport("upper", .{ .root_source_file = upper_gen_out }); 430 case_data.addAnonymousImport("upper", .{ .root_source_file = upper_gen_out });
319 case_data.addAnonymousImport("lower", .{ .root_source_file = lower_gen_out }); 431 case_data.addAnonymousImport("lower", .{ .root_source_file = lower_gen_out });
320 432
433 const case_data_t = b.addTest(.{
434 .name = "case_data",
435 .root_module = case_data,
436 .target = target,
437 .optimize = optimize,
438 });
439 const case_data_tr = b.addRunArtifact(case_data_t);
440
321 // Scripts 441 // Scripts
322 const scripts_data = b.addModule("ScriptsData", .{ 442 const scripts_data = b.addModule("ScriptsData", .{
323 .root_source_file = b.path("src/ScriptsData.zig"), 443 .root_source_file = b.path("src/ScriptsData.zig"),
@@ -326,6 +446,14 @@ pub fn build(b: *std.Build) void {
326 }); 446 });
327 scripts_data.addAnonymousImport("scripts", .{ .root_source_file = scripts_gen_out }); 447 scripts_data.addAnonymousImport("scripts", .{ .root_source_file = scripts_gen_out });
328 448
449 const scripts_data_t = b.addTest(.{
450 .name = "scripts_data",
451 .root_module = scripts_data,
452 .target = target,
453 .optimize = optimize,
454 });
455 const scripts_data_tr = b.addRunArtifact(scripts_data_t);
456
329 // Properties 457 // Properties
330 const props_data = b.addModule("PropsData", .{ 458 const props_data = b.addModule("PropsData", .{
331 .root_source_file = b.path("src/PropsData.zig"), 459 .root_source_file = b.path("src/PropsData.zig"),
@@ -336,6 +464,14 @@ pub fn build(b: *std.Build) void {
336 props_data.addAnonymousImport("props", .{ .root_source_file = props_gen_out }); 464 props_data.addAnonymousImport("props", .{ .root_source_file = props_gen_out });
337 props_data.addAnonymousImport("numeric", .{ .root_source_file = num_gen_out }); 465 props_data.addAnonymousImport("numeric", .{ .root_source_file = num_gen_out });
338 466
467 const props_data_t = b.addTest(.{
468 .name = "props_data",
469 .root_module = props_data,
470 .target = target,
471 .optimize = optimize,
472 });
473 const props_data_tr = b.addRunArtifact(props_data_t);
474
339 // Unicode Tests 475 // Unicode Tests
340 const unicode_tests = b.addTest(.{ 476 const unicode_tests = b.addTest(.{
341 .root_source_file = b.path("src/unicode_tests.zig"), 477 .root_source_file = b.path("src/unicode_tests.zig"),
@@ -349,4 +485,23 @@ pub fn build(b: *std.Build) void {
349 485
350 const unicode_test_step = b.step("unicode-test", "Run Unicode tests"); 486 const unicode_test_step = b.step("unicode-test", "Run Unicode tests");
351 unicode_test_step.dependOn(&run_unicode_tests.step); 487 unicode_test_step.dependOn(&run_unicode_tests.step);
488
489 const test_step = b.step("test", "Run general tests");
490 test_step.dependOn(&code_point_tr.step);
491 test_step.dependOn(&grapheme_data_tr.step);
492 test_step.dependOn(&width_data_tr.step);
493 test_step.dependOn(&display_width_tr.step);
494 test_step.dependOn(&grapheme_tr.step);
495 test_step.dependOn(&ascii_tr.step);
496 test_step.dependOn(&ccc_data_tr.step);
497 test_step.dependOn(&canon_data_tr.step);
498 test_step.dependOn(&compat_data_tr.step);
499 test_step.dependOn(&hangul_data_tr.step);
500 test_step.dependOn(&normp_data_tr.step);
501 test_step.dependOn(&norm_data_tr.step);
502 test_step.dependOn(&gencat_data_tr.step);
503 test_step.dependOn(&case_fold_tr.step);
504 test_step.dependOn(&case_data_tr.step);
505 test_step.dependOn(&scripts_data_tr.step);
506 test_step.dependOn(&props_data_tr.step);
352} 507}
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
100test "isUpperStr" { 100test "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
135test "toUpperStr" { 135test "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
158test "isLowerStr" { 158test "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
193test "toLowerStr" { 193test "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(
95test "compatCaselessMatch" { 95test "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(
170test "canonCaselessMatch" { 171test "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
60test "strWidth" { 60test "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(
166test "center" { 166test "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(
245test "padLeft" { 245test "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(
295test "padRight" { 295test "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(
348test "wrap" { 348test "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.
572pub fn eql(self: Self, allocator: mem.Allocator, a: []const u8, b: []const u8) !bool { 572pub 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
142test "Props" { 142test "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
57test "codePointWidth" { 57test "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);