summaryrefslogtreecommitdiff
path: root/src/Normalize.zig
diff options
context:
space:
mode:
authorGravatar Sam Atman2025-04-30 11:58:19 -0400
committerGravatar Sam Atman2025-04-30 11:58:19 -0400
commit1be5e46490e061761b4b97dff5c6acb2181d6fe9 (patch)
tree77a1edcdedd7afae7428e92feba37d2bb1035b22 /src/Normalize.zig
parentAdd general tests step (diff)
downloadzg-1be5e46490e061761b4b97dff5c6acb2181d6fe9.tar.gz
zg-1be5e46490e061761b4b97dff5c6acb2181d6fe9.tar.xz
zg-1be5e46490e061761b4b97dff5c6acb2181d6fe9.zip
Factor out 'Data' for grapheme and DisplayWidth
In the process of refactoring the whole library, so that it doesn't expose anything called "Data" separately from user functionality.
Diffstat (limited to 'src/Normalize.zig')
-rw-r--r--src/Normalize.zig29
1 files changed, 14 insertions, 15 deletions
diff --git a/src/Normalize.zig b/src/Normalize.zig
index a28b708..b738b27 100644
--- a/src/Normalize.zig
+++ b/src/Normalize.zig
@@ -177,7 +177,7 @@ test "decompose" {
177 const allocator = testing.allocator; 177 const allocator = testing.allocator;
178 var data: NormData = undefined; 178 var data: NormData = undefined;
179 try NormData.init(&data, allocator); 179 try NormData.init(&data, allocator);
180 defer data.deinit(); 180 defer data.deinit(allocator);
181 var n = Self{ .norm_data = &data }; 181 var n = Self{ .norm_data = &data };
182 182
183 var buf: [18]u21 = undefined; 183 var buf: [18]u21 = undefined;
@@ -307,11 +307,11 @@ test "nfd ASCII / no-alloc" {
307 const allocator = testing.allocator; 307 const allocator = testing.allocator;
308 var data: NormData = undefined; 308 var data: NormData = undefined;
309 try NormData.init(&data, allocator); 309 try NormData.init(&data, allocator);
310 defer data.deinit(); 310 defer data.deinit(allocator);
311 const n = Self{ .norm_data = &data }; 311 const n = Self{ .norm_data = &data };
312 312
313 const result = try n.nfd(allocator, "Hello World!"); 313 const result = try n.nfd(allocator, "Hello World!");
314 defer result.deinit(); 314 defer result.deinit(allocator);
315 315
316 try testing.expectEqualStrings("Hello World!", result.slice); 316 try testing.expectEqualStrings("Hello World!", result.slice);
317} 317}
@@ -320,11 +320,11 @@ test "nfd !ASCII / alloc" {
320 const allocator = testing.allocator; 320 const allocator = testing.allocator;
321 var data: NormData = undefined; 321 var data: NormData = undefined;
322 try NormData.init(&data, allocator); 322 try NormData.init(&data, allocator);
323 defer data.deinit(); 323 defer data.deinit(allocator);
324 const n = Self{ .norm_data = &data }; 324 const n = Self{ .norm_data = &data };
325 325
326 const result = try n.nfd(allocator, "Héllo World! \u{3d3}"); 326 const result = try n.nfd(allocator, "Héllo World! \u{3d3}");
327 defer result.deinit(); 327 defer result.deinit(allocator);
328 328
329 try testing.expectEqualStrings("He\u{301}llo World! \u{3d2}\u{301}", result.slice); 329 try testing.expectEqualStrings("He\u{301}llo World! \u{3d2}\u{301}", result.slice);
330} 330}
@@ -333,11 +333,11 @@ test "nfkd ASCII / no-alloc" {
333 const allocator = testing.allocator; 333 const allocator = testing.allocator;
334 var data: NormData = undefined; 334 var data: NormData = undefined;
335 try NormData.init(&data, allocator); 335 try NormData.init(&data, allocator);
336 defer data.deinit(); 336 defer data.deinit(allocator);
337 const n = Self{ .norm_data = &data }; 337 const n = Self{ .norm_data = &data };
338 338
339 const result = try n.nfkd(allocator, "Hello World!"); 339 const result = try n.nfkd(allocator, "Hello World!");
340 defer result.deinit(); 340 defer result.deinit(allocator);
341 341
342 try testing.expectEqualStrings("Hello World!", result.slice); 342 try testing.expectEqualStrings("Hello World!", result.slice);
343} 343}
@@ -346,11 +346,11 @@ test "nfkd !ASCII / alloc" {
346 const allocator = testing.allocator; 346 const allocator = testing.allocator;
347 var data: NormData = undefined; 347 var data: NormData = undefined;
348 try NormData.init(&data, allocator); 348 try NormData.init(&data, allocator);
349 defer data.deinit(); 349 defer data.deinit(allocator);
350 const n = Self{ .norm_data = &data }; 350 const n = Self{ .norm_data = &data };
351 351
352 const result = try n.nfkd(allocator, "Héllo World! \u{3d3}"); 352 const result = try n.nfkd(allocator, "Héllo World! \u{3d3}");
353 defer result.deinit(); 353 defer result.deinit(allocator);
354 354
355 try testing.expectEqualStrings("He\u{301}llo World! \u{3a5}\u{301}", result.slice); 355 try testing.expectEqualStrings("He\u{301}llo World! \u{3a5}\u{301}", result.slice);
356} 356}
@@ -546,11 +546,11 @@ test "nfc" {
546 const allocator = testing.allocator; 546 const allocator = testing.allocator;
547 var data: NormData = undefined; 547 var data: NormData = undefined;
548 try NormData.init(&data, allocator); 548 try NormData.init(&data, allocator);
549 defer data.deinit(); 549 defer data.deinit(allocator);
550 const n = Self{ .norm_data = &data }; 550 const n = Self{ .norm_data = &data };
551 551
552 const result = try n.nfc(allocator, "Complex char: \u{3D2}\u{301}"); 552 const result = try n.nfc(allocator, "Complex char: \u{3D2}\u{301}");
553 defer result.deinit(); 553 defer result.deinit(allocator);
554 554
555 try testing.expectEqualStrings("Complex char: \u{3D3}", result.slice); 555 try testing.expectEqualStrings("Complex char: \u{3D3}", result.slice);
556} 556}
@@ -559,11 +559,11 @@ test "nfkc" {
559 const allocator = testing.allocator; 559 const allocator = testing.allocator;
560 var data: NormData = undefined; 560 var data: NormData = undefined;
561 try NormData.init(&data, allocator); 561 try NormData.init(&data, allocator);
562 defer data.deinit(); 562 defer data.deinit(allocator);
563 const n = Self{ .norm_data = &data }; 563 const n = Self{ .norm_data = &data };
564 564
565 const result = try n.nfkc(allocator, "Complex char: \u{03A5}\u{0301}"); 565 const result = try n.nfkc(allocator, "Complex char: \u{03A5}\u{0301}");
566 defer result.deinit(); 566 defer result.deinit(allocator);
567 567
568 try testing.expectEqualStrings("Complex char: \u{038E}", result.slice); 568 try testing.expectEqualStrings("Complex char: \u{038E}", result.slice);
569} 569}
@@ -582,7 +582,7 @@ test "eql" {
582 const allocator = testing.allocator; 582 const allocator = testing.allocator;
583 var data: NormData = undefined; 583 var data: NormData = undefined;
584 try NormData.init(&data, allocator); 584 try NormData.init(&data, allocator);
585 defer data.deinit(); 585 defer data.deinit(allocator);
586 const n = Self{ .norm_data = &data }; 586 const n = Self{ .norm_data = &data };
587 587
588 try testing.expect(try n.eql(allocator, "foé", "foe\u{0301}")); 588 try testing.expect(try n.eql(allocator, "foé", "foe\u{0301}"));
@@ -628,5 +628,4 @@ 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);
632} 631}