41 lines
1.3 KiB
Plaintext
41 lines
1.3 KiB
Plaintext
import "@std/mem"
|
|
import "@std/testing"
|
|
|
|
handles_interning test {
|
|
pool := init(mem.c_allocator)
|
|
defer deinit(&pool)
|
|
|
|
input [5]mut u8 := ['h', 'e', 'l', 'l', 'o']
|
|
id :: try intern(&pool, input[..])
|
|
duplicate :: try intern(&pool, "hello")
|
|
input[0] = 'j'
|
|
|
|
same_id :: get_id(&pool, "hello")
|
|
mutated_id :: get_id(&pool, input[..])
|
|
hello_str :: get_str(&pool, id)
|
|
invalid_str :: get_str(&pool, id + 1)
|
|
|
|
try testing.expect_equal(0, id)
|
|
try testing.expect_equal(id, duplicate)
|
|
try testing.expect_equal(id, same_id?)
|
|
try testing.expect_equal(null, mutated_id)
|
|
try testing.expect_equal(null, invalid_str)
|
|
try testing.expect_equal("hello", hello_str?)
|
|
}
|
|
|
|
keeps_independent_pool_ids_local test {
|
|
first := init(mem.c_allocator)
|
|
defer deinit(&first)
|
|
second := init(mem.c_allocator)
|
|
defer deinit(&second)
|
|
hello :: try intern(&first, "hello")
|
|
world :: try intern(&second, "world")
|
|
try testing.expect_equal(hello, world)
|
|
try testing.expect_equal("hello", get_str(&first, hello)?)
|
|
try testing.expect_equal("world", get_str(&second, world)?)
|
|
different :: try intern(&first, "world")
|
|
try testing.expect(different != hello)
|
|
try testing.expect_equal(hello, try intern(&first, "hello"))
|
|
try testing.expect_equal(world, try intern(&second, "world"))
|
|
}
|