blob: 8f640f47bb52bd817e08b245aa4239213b94798a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
const std = @import("std");
const testing = std.testing;
pub const value = @import("../zisp/value.zig");
const istr = value.istr;
const fx = value.fixnum;
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 file = try std.fs.cwd().openFile("src/test/data/string.txt", .{});
defer file.close();
var s2_buf: [4096]u8 = undefined;
const s2_len = try file.readAll(&s2_buf);
var s2: []u8 = s2_buf[0..s2_len];
const v2 = istr.intern(s2);
const v2_len: usize = @intCast(fx.unpack(istr.len(v2)));
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;
try testing.expectEqualStrings(s2_orig, istr.assert(v2).bytes());
try testing.expectEqual(s2_len, v2_len);
}
|