fix: lexer for comment
This commit is contained in:
parent
dc49697302
commit
5f5af0a4ab
@ -82,7 +82,7 @@ function lexer(input: string): Token[] {
|
||||
let value = '';
|
||||
const start = current;
|
||||
|
||||
while (char !== '\n') {
|
||||
while (char !== '\n' && current < input.length) {
|
||||
value += char;
|
||||
char = input[++current];
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { lexer, splitSql, cleanSql } from '../../src';
|
||||
import { TokenType } from '../../src/utils/token';
|
||||
|
||||
describe('utils', () => {
|
||||
test('split single sql', () => {
|
||||
@ -28,6 +29,15 @@ describe('utils', () => {
|
||||
const result = lexer(sql);
|
||||
expect(result.length).toEqual(4);
|
||||
});
|
||||
test('lexer for comments', () => {
|
||||
const sql = `select * from a;--comments`;
|
||||
const expected = `--comments`;
|
||||
const result = lexer(sql);
|
||||
const comments = result.find((token) =>
|
||||
token.type === TokenType.Comment,
|
||||
);
|
||||
expect(comments.value).toEqual(expected);
|
||||
});
|
||||
test('cleanSql', () => {
|
||||
const sql = `-- a ;
|
||||
select * from a;
|
||||
|
Loading…
Reference in New Issue
Block a user