minor refactoring
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import "@std/mem"
|
||||
import "@std/arraylist"
|
||||
import "@std/hashmap"
|
||||
import "@std/testing"
|
||||
|
||||
# cross-cutting concern, hence global singleton (owned by main.hon)
|
||||
strings StringPool = undefined
|
||||
@@ -64,25 +63,3 @@ get_str proc(pool @StringPool, id StringId) ?[]u8 {
|
||||
get_id proc(pool @StringPool, str []u8) ?StringId {
|
||||
return hashmap.get(&pool.ids, str)
|
||||
}
|
||||
|
||||
handles_intern test {
|
||||
pool StringPool = 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?)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import "@std/mem"
|
||||
import "@std/testing"
|
||||
|
||||
handles_intern test {
|
||||
pool StringPool = 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?)
|
||||
}
|
||||
Reference in New Issue
Block a user