| 1 | module lexer |
| 2 | |
| 3 | import arena |
| 4 | |
| 5 | fn test_ascii_comment_native_scan_preserves_every_block_boundary_and_following_location() { |
| 6 | for width in [0, 1, 15, 16, 17, 31, 32, 33, 4095, 4096, 4097, 65536] { |
| 7 | for prefix in ['', 'name '] { |
| 8 | for ending in ['\n', '\r', '\r\n'] { |
| 9 | source := prefix + ';' + 'x'.repeat(width) + ending + '42' |
| 10 | mut scanner := new_scanner(source) or { panic(err) } |
| 11 | assert !scanner.unicode_source |
| 12 | if prefix.len > 0 { |
| 13 | assert (scanner.next() or { panic(err) }).kind == .identifier |
| 14 | } |
| 15 | token := scanner.next() or { panic(err) } |
| 16 | assert token.kind == .number |
| 17 | assert token.start == source.len - 2 && token.end == source.len |
| 18 | assert token.line == 2 && token.column == 1 |
| 19 | assert (scanner.next() or { panic(err) }).kind == .eof |
| 20 | } |
| 21 | } |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | fn test_ascii_comment_without_line_ending_stops_exactly_at_eof() { |
| 26 | for width in [0, 1, 15, 16, 17, 31, 32, 33, 65536] { |
| 27 | source := ';' + 'x'.repeat(width) |
| 28 | mut scanner := new_scanner(source) or { panic(err) } |
| 29 | token := scanner.next() or { panic(err) } |
| 30 | assert token.kind == .eof |
| 31 | assert token.start == source.len && token.end == source.len |
| 32 | assert token.line == 1 && token.column == source.len + 1 |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | fn test_long_ascii_comment_scanning_allocates_nothing() { |
| 37 | source := (';' + 'x'.repeat(65536) + '\r\n').repeat(16) + ';x\r'.repeat(20000) + "#'42" |
| 38 | mut storage := arena.new(chunk_size: 4096) |
| 39 | storage.push() |
| 40 | before := storage.used() |
| 41 | mut scanner := new_scanner(source) or { panic(err) } |
| 42 | assert (scanner.next() or { panic(err) }).kind == .syntax_quote |
| 43 | assert (scanner.next() or { panic(err) }).kind == .number |
| 44 | assert (scanner.next() or { panic(err) }).kind == .eof |
| 45 | assert storage.used() == before, 'comment scanning retained ${storage.used() - before} bytes' |
| 46 | storage.pop() |
| 47 | storage.free() |
| 48 | } |
| 49 | |