summaryrefslogtreecommitdiff
path: root/src/test/strings.zig
diff options
context:
space:
mode:
authorTaylan Kammer <taylan.kammer@gmail.com>2026-01-07 03:30:11 +0100
committerTaylan Kammer <taylan.kammer@gmail.com>2026-01-07 03:30:11 +0100
commit344ab30c2155b855a1fcd98027199026d4f467d7 (patch)
treec029d65e5463a8b7f67ac5a932de22e2ffef5d22 /src/test/strings.zig
parentc575aafc23cf20cee76653a179384357cdb918f2 (diff)
Code cleanup.
Diffstat (limited to 'src/test/strings.zig')
-rw-r--r--src/test/strings.zig24
1 files changed, 8 insertions, 16 deletions
diff --git a/src/test/strings.zig b/src/test/strings.zig
index 3a0585e..58a460b 100644
--- a/src/test/strings.zig
+++ b/src/test/strings.zig
@@ -13,27 +13,19 @@ test "istr" {
const s1 = "foo bar baz";
const v1 = istr.intern(s1);
const v1_len: usize = @intCast(fx.unpack(istr.len(v1)));
-
try testing.expectEqualStrings(s1, istr.assert(v1).bytes());
try testing.expectEqual(s1.len, v1_len);
- const path = "src/test/data/string.txt";
- var file = try std.Io.Dir.cwd().openFile(gstIo, path, .{});
- defer file.close(gstIo);
-
- var s2_buf: [4096]u8 = undefined;
- const s2_len = try file.readStreaming(gstIo, &.{&s2_buf});
- var s2: []u8 = s2_buf[0..s2_len];
-
+ const s2 = @embedFile("data/string.txt");
const v2 = istr.intern(s2);
const v2_len: usize = @intCast(fx.unpack(istr.len(v2)));
+ try testing.expectEqualStrings(s2, istr.assert(v2).bytes());
+ try testing.expectEqual(s2.len, v2_len);
- var s2_orig_buf: [4096]u8 = undefined;
- @memcpy(&s2_orig_buf, &s2_buf);
- const s2_orig = s2_orig_buf[0..s2_len];
-
- s2[0] = s2[0] +% 1;
+ // Check that modifying a slice doesn't affect the string.
- try testing.expectEqualStrings(s2_orig, istr.assert(v2).bytes());
- try testing.expectEqual(s2_len, v2_len);
+ var s3 = "test".*;
+ const v3 = istr.intern(&s3);
+ s3[0] = 'x';
+ try testing.expectEqualStrings("test", istr.assert(v3).bytes());
}