import 'package:sqlparser/sqlparser.dart'; import 'package:sqlparser/src/reader/tokenizer/scanner.dart'; import 'package:test/test.dart'; void main() { test('parses ** as two tokens when not using drift mode', () { final tokens = Scanner('**').scanTokens(); expect(tokens.map((e) => e.type), containsAllInOrder([TokenType.star, TokenType.star])); }); test('throws when seeing an invalid token', () { expect( Scanner('!').scanTokens, throwsA(isA()), ); }); test('scans identifiers with backticks', () { expect( Scanner('`SELECT`').scanTokens(), contains(isA() .having((e) => e.identifier, 'identifier', 'SELECT')), ); }); test('scans identifiers with double quotes', () { expect( Scanner('"SELECT"').scanTokens(), contains(isA() .having((e) => e.identifier, 'identifier', 'SELECT')), ); }); test('scans new tokens for JSON extraction', () { expect(Scanner('- -> ->>').scanTokens(), [ isA().having((e) => e.type, 'tokenType', TokenType.minus), isA().having((e) => e.type, 'tokenType', TokenType.dashRangle), isA() .having((e) => e.type, 'tokenType', TokenType.dashRangleRangle), isA().having((e) => e.type, 'tokenType', TokenType.eof), ]); }); group('reports error message', () { test(r'for missing identifier after `$`', () { expect( Scanner(r'$ order').scanTokens, throwsA( isA().having( (e) => e.errors, 'errors', contains( isA() .having((e) => e.message, 'message', r'Expected identifier after `$`') .having((e) => e.location.offset, 'location.offset', 1), ), ), ), ); }); test('for missing identifier after `@`', () { expect( Scanner(r'@ order').scanTokens, throwsA( isA().having( (e) => e.errors, 'errors', contains( isA() .having((e) => e.message, 'message', r'Expected identifier after `@`') .having((e) => e.location.offset, 'location.offset', 1), ), ), ), ); }); }); }