vile / lexer / spelling_test.v
26 lines · 24 sloc · 696 bytes · 76646891b77a3d5c6af4a1e42b122cd61dc1654b
Raw
1module lexer
2
3fn test_single_byte_spellings_are_exact_terminated_and_source_independent() {
4 for byte in 0 .. 256 {
5 source := [u8(byte)].bytestr()
6 span := TokenSpan{.identifier, 0, 1, 1, 1}
7 text := span.text(source)
8 unsafe { source.free() }
9 gc_collect()
10 assert text.len == 1
11 assert text[0] == u8(byte)
12 assert unsafe { text.str[1] } == 0
13 unsafe { text.free() }
14 }
15}
16
17fn test_collected_tokens_keep_their_spellings_after_source_release() {
18 source := 'x 1 + x 1'.clone()
19 tokens := tokenize(source) or { panic(err) }
20 unsafe { source.free() }
21 gc_collect()
22 assert tokens.map(it.lexeme) == ['x', '1', '+', 'x', '1', '']
23 for token in tokens {
24 unsafe { token.lexeme.free() }
25 }
26}
27