summaryrefslogtreecommitdiff
path: root/src/test/strings.zig
blob: 58a460bb6c3356ab08d9d9e958f8149a41d4f242 (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
31
const std = @import("std");

const testing = std.testing;

const gstIo = std.Io.Threaded.global_single_threaded.io();

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 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);

    // Check that modifying a slice doesn't affect the string.

    var s3 = "test".*;
    const v3 = istr.intern(&s3);
    s3[0] = 'x';
    try testing.expectEqualStrings("test", istr.assert(v3).bytes());
}