summaryrefslogtreecommitdiff
path: root/src/test/strings.zig
blob: 30396159e67f9a0b34c0b4ef20edc38b252c639c (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 = try istr.intern(s1);
    const v1_len: usize = @intCast(fx.unpack(istr.len(v1)));
    try testing.expectEqualStrings(s1, istr.assert(v1).str());
    try testing.expectEqual(s1.len, v1_len);

    const s2 = @embedFile("data/string.txt");
    const v2 = try istr.intern(s2);
    const v2_len: usize = @intCast(fx.unpack(istr.len(v2)));
    try testing.expectEqualStrings(s2, istr.assert(v2).str());
    try testing.expectEqual(s2.len, v2_len);

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

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