module lexer import arena fn test_ascii_comment_native_scan_preserves_every_block_boundary_and_following_location() { for width in [0, 1, 15, 16, 17, 31, 32, 33, 4095, 4096, 4097, 65536] { for prefix in ['', 'name '] { for ending in ['\n', '\r', '\r\n'] { source := prefix + ';' + 'x'.repeat(width) + ending + '42' mut scanner := new_scanner(source) or { panic(err) } assert !scanner.unicode_source if prefix.len > 0 { assert (scanner.next() or { panic(err) }).kind == .identifier } token := scanner.next() or { panic(err) } assert token.kind == .number assert token.start == source.len - 2 && token.end == source.len assert token.line == 2 && token.column == 1 assert (scanner.next() or { panic(err) }).kind == .eof } } } } fn test_ascii_comment_without_line_ending_stops_exactly_at_eof() { for width in [0, 1, 15, 16, 17, 31, 32, 33, 65536] { source := ';' + 'x'.repeat(width) mut scanner := new_scanner(source) or { panic(err) } token := scanner.next() or { panic(err) } assert token.kind == .eof assert token.start == source.len && token.end == source.len assert token.line == 1 && token.column == source.len + 1 } } fn test_long_ascii_comment_scanning_allocates_nothing() { source := (';' + 'x'.repeat(65536) + '\r\n').repeat(16) + ';x\r'.repeat(20000) + "#'42" mut storage := arena.new(chunk_size: 4096) storage.push() before := storage.used() mut scanner := new_scanner(source) or { panic(err) } assert (scanner.next() or { panic(err) }).kind == .syntax_quote assert (scanner.next() or { panic(err) }).kind == .number assert (scanner.next() or { panic(err) }).kind == .eof assert storage.used() == before, 'comment scanning retained ${storage.used() - before} bytes' storage.pop() storage.free() }