| 1 | import toml.input |
| 2 | import toml.scanner |
| 3 | |
| 4 | const scan_input = input.Config{ |
| 5 | text: 'abc' |
| 6 | } |
| 7 | |
| 8 | fn test_remaining() { |
| 9 | mut s := scanner.new_scanner(input: scan_input) or { panic(err) } |
| 10 | assert s.remaining() == 3 |
| 11 | s.next() |
| 12 | s.next() |
| 13 | assert s.remaining() == 1 |
| 14 | s.next() |
| 15 | assert s.remaining() == 0 |
| 16 | s.next() |
| 17 | s.next() |
| 18 | assert s.remaining() == 0 |
| 19 | s.reset() |
| 20 | assert s.remaining() == 3 |
| 21 | } |
| 22 | |
| 23 | fn test_next() { |
| 24 | mut s := scanner.new_scanner(input: scan_input) or { panic(err) } |
| 25 | assert s.next() == `a` |
| 26 | assert s.next() == `b` |
| 27 | assert s.next() == `c` |
| 28 | assert s.next() == scanner.end_of_text |
| 29 | assert s.next() == scanner.end_of_text |
| 30 | assert s.next() == scanner.end_of_text |
| 31 | } |
| 32 | |
| 33 | fn test_skip() { |
| 34 | mut s := scanner.new_scanner(input: scan_input) or { panic(err) } |
| 35 | assert s.next() == `a` |
| 36 | s.skip() |
| 37 | assert s.next() == `c` |
| 38 | assert s.next() == scanner.end_of_text |
| 39 | } |
| 40 | |
| 41 | fn test_skip_n() { |
| 42 | mut s := scanner.new_scanner(input: scan_input) or { panic(err) } |
| 43 | s.skip_n(2) |
| 44 | assert s.next() == `c` |
| 45 | assert s.next() == scanner.end_of_text |
| 46 | } |
| 47 | |
| 48 | fn test_at() { |
| 49 | mut s := scanner.new_scanner(input: scan_input) or { panic(err) } |
| 50 | assert s.at() == `a` |
| 51 | assert s.at() == `a` |
| 52 | assert s.at() == `a` |
| 53 | |
| 54 | assert s.next() == `a` |
| 55 | assert s.next() == `b` |
| 56 | assert s.next() == `c` |
| 57 | assert s.next() == scanner.end_of_text |
| 58 | } |
| 59 | |
| 60 | fn test_peek() { |
| 61 | mut s := scanner.new_scanner(input: scan_input) or { panic(err) } |
| 62 | assert s.peek(0) == `a` |
| 63 | assert s.peek(1) == `b` |
| 64 | assert s.peek(2) == `c` |
| 65 | assert s.peek(3) == scanner.end_of_text |
| 66 | assert s.peek(4) == scanner.end_of_text |
| 67 | |
| 68 | assert s.next() == `a` |
| 69 | assert s.next() == `b` |
| 70 | assert s.next() == `c` |
| 71 | assert s.next() == scanner.end_of_text |
| 72 | } |
| 73 | |
| 74 | fn test_reset() { |
| 75 | mut s := scanner.new_scanner(input: scan_input) or { panic(err) } |
| 76 | assert s.next() == `a` |
| 77 | s.next() |
| 78 | s.next() |
| 79 | assert s.next() == scanner.end_of_text |
| 80 | s.reset() |
| 81 | assert s.next() == `a` |
| 82 | } |
| 83 | |
| 84 | const multiline_string_input = input.Config{ |
| 85 | text: '"""abc\r\ndef\n123"""' |
| 86 | } |
| 87 | |
| 88 | fn test_multiline_string() { |
| 89 | mut s := scanner.new_scanner(input: multiline_string_input) or { panic(err) } |
| 90 | tok := s.scan()! |
| 91 | assert tok.kind == .quoted |
| 92 | assert tok.lit.contains('abc') |
| 93 | assert tok.lit.contains('def') |
| 94 | assert tok.lit.contains('123') |
| 95 | } |
| 96 | |