summaryrefslogtreecommitdiff
path: root/src/unicode_tests.zig
diff options
context:
space:
mode:
authorGravatar Michael Chaten2025-09-14 04:11:09 -0700
committerGravatar Michael Chaten2025-09-14 04:11:09 -0700
commit749197a3f9d25e211615960c02380a3d659b20f9 (patch)
tree9c892349f0a7136edb150f27f549dc182f7699bb /src/unicode_tests.zig
parentUpdate codebase to Zig 0.15.1. (diff)
downloadzg-749197a3f9d25e211615960c02380a3d659b20f9.tar.gz
zg-749197a3f9d25e211615960c02380a3d659b20f9.tar.xz
zg-749197a3f9d25e211615960c02380a3d659b20f9.zip
Embed data files in scripts rather than relying on filesystem access for easier packaging
Diffstat (limited to 'src/unicode_tests.zig')
-rw-r--r--src/unicode_tests.zig23
1 files changed, 6 insertions, 17 deletions
diff --git a/src/unicode_tests.zig b/src/unicode_tests.zig
index ff49b2a..875c5f0 100644
--- a/src/unicode_tests.zig
+++ b/src/unicode_tests.zig
@@ -8,14 +8,10 @@ test "Unicode normalization tests" {
8 const n = try Normalize.init(allocator); 8 const n = try Normalize.init(allocator);
9 defer n.deinit(allocator); 9 defer n.deinit(allocator);
10 10
11 var file = try fs.cwd().openFile("data/unicode/NormalizationTest.txt", .{}); 11 var reader = std.io.Reader.fixed(@embedFile("NormalizationTest.txt"));
12 defer file.close();
13 var buf: [4096]u8 = undefined;
14 var reader = file.reader(&buf);
15
16 var cp_buf: [4]u8 = undefined; 12 var cp_buf: [4]u8 = undefined;
17 13
18 var line_iter: IterRead = .{ .read = &reader.interface }; 14 var line_iter: IterRead = .{ .read = &reader };
19 15
20 while (line_iter.next()) |line| { 16 while (line_iter.next()) |line| {
21 // Iterate over fields. 17 // Iterate over fields.
@@ -120,15 +116,12 @@ test "Unicode normalization tests" {
120 116
121test "Segmentation GraphemeIterator" { 117test "Segmentation GraphemeIterator" {
122 const allocator = std.testing.allocator; 118 const allocator = std.testing.allocator;
123 var file = try std.fs.cwd().openFile("data/unicode/auxiliary/GraphemeBreakTest.txt", .{});
124 defer file.close();
125 var buf: [4096]u8 = undefined;
126 var reader = file.reader(&buf);
127 119
120 var reader = std.io.Reader.fixed(@embedFile("GraphemeBreakTest.txt"));
128 const graph = try Graphemes.init(allocator); 121 const graph = try Graphemes.init(allocator);
129 defer graph.deinit(allocator); 122 defer graph.deinit(allocator);
130 123
131 var line_iter: IterRead = .{ .read = &reader.interface }; 124 var line_iter: IterRead = .{ .read = &reader };
132 125
133 while (line_iter.next()) |raw| { 126 while (line_iter.next()) |raw| {
134 // Clean up. 127 // Clean up.
@@ -263,15 +256,11 @@ test "Segmentation GraphemeIterator" {
263 256
264test "Segmentation Word Iterator" { 257test "Segmentation Word Iterator" {
265 const allocator = std.testing.allocator; 258 const allocator = std.testing.allocator;
266 var file = try std.fs.cwd().openFile("data/unicode/auxiliary/WordBreakTest.txt", .{}); 259 var reader = std.io.Reader.fixed(@embedFile("WordBreakTest.txt"));
267 defer file.close();
268 var buf: [4096]u8 = undefined;
269 var reader = file.reader(&buf);
270
271 const wb = try Words.init(allocator); 260 const wb = try Words.init(allocator);
272 defer wb.deinit(allocator); 261 defer wb.deinit(allocator);
273 262
274 var line_iter: IterRead = .{ .read = &reader.interface }; 263 var line_iter: IterRead = .{ .read = &reader };
275 264
276 while (line_iter.next()) |raw| { 265 while (line_iter.next()) |raw| {
277 // Clean up. 266 // Clean up.