vile / lexer / alphabet_scan_test.v
27 lines · 26 sloc · 925 bytes · 76646891b77a3d5c6af4a1e42b122cd61dc1654b
Raw
1module lexer
2
3fn test_identifier_blocks_match_the_full_alphabet_at_every_alignment() {
4 for alignment in 0 .. 32 {
5 for length in [0, 1, 15, 16, 17, 31, 32, 63, 64, 65, 79, 80, 81, 95, 96, 97, 127, 128,
6 129, 1024] {
7 mut bytes := []u8{len: alignment + length + 1, init: `@`}
8 bytes[alignment + length] = ` `
9 source := unsafe { (&char(bytes.data)).vstring_literal_with_len(bytes.len) }
10 assert identifier_end(source, alignment) == alignment + length
11 if length == 0 { continue }
12 for byte in 0 .. 256 {
13 index := alignment + byte % length
14 bytes[index] = u8(byte)
15 expected := if is_subsequent(u8(byte)) { alignment + length } else { index }
16 assert identifier_end(source, alignment) == expected
17 bytes[index] = `@`
18 }
19 for lane in 0 .. length {
20 index := alignment + lane
21 bytes[index] = `;`
22 assert identifier_end(source, alignment) == index
23 bytes[index] = `@`
24 }
25 }
26 }
27}
28