Skip to content

Commit

Permalink
refactor: migrate generic/jison/create_view test to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
NikitaShkaruba committed Nov 29, 2023
1 parent 36bcf08 commit c7e788a
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 118 deletions.
8 changes: 5 additions & 3 deletions src/parsing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ export interface ParseResult {
onlyTables?: boolean;
};
suggestColumns?: ColumnSuggestion;
suggestAggregateFunctions?: {
tables: Table[],
};
suggestAggregateFunctions?: AggregateFunctionsSuggestion;
suggestAnalyticFunctions?: unknown;
suggestColRefKeywords?: unknown;
suggestColumnAliases?: ColumnAliasSuggestion[];
Expand Down Expand Up @@ -87,6 +85,10 @@ export type StatementPart =
qualified: boolean,
};

export interface AggregateFunctionsSuggestion {
tables: Table[],
}

export interface ColumnSuggestion {
source?: string;
tables: Table[];
Expand Down
12 changes: 0 additions & 12 deletions src/parsing/parsers/generic/jison/create/create_common.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,4 @@ test('should suggest CREATE', () => {

const suggestion: KeywordSuggestion = { value: 'CREATE', weight: -1 };
expect(parseResult.suggestKeywords).toContainEqual(suggestion);
})

// TODO: remove, because it's being tested in other tests
test('should suggest CREATE objects', () => {
const parseResult = parseGenericSql('CREATE ', '');

expect(parseResult.errors).toBeUndefined();

const suggestions: KeywordSuggestion[] = [
{ value: 'VIEW', weight: -1 },
];
expect(parseResult.suggestKeywords).toEqual(expect.arrayContaining(suggestions))
})
103 changes: 0 additions & 103 deletions src/parsing/parsers/generic/jison/create/create_view.test.json

This file was deleted.

60 changes: 60 additions & 0 deletions src/parsing/parsers/generic/jison/create/create_view.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import {
KeywordSuggestion,
parseGenericSql, parseGenericSqlWithoutCursor,
} from '../../../../index';
import {expect, test} from '@jest/globals';

test('should suggest creating VIEW', () => {
const parseResult = parseGenericSql('CREATE ', '');

expect(parseResult.errors).toBeUndefined();

const suggestions: KeywordSuggestion[] = [
{ value: 'VIEW', weight: -1 },
];
expect(parseResult.suggestKeywords).toEqual(expect.arrayContaining(suggestions))
})

test('should suggest IF NOT EXISTS', () => {
const parseResult = parseGenericSql('CREATE VIEW ', '');

expect(parseResult.errors).toBeUndefined();

const suggestions: KeywordSuggestion[] = [
{ value: 'IF NOT EXISTS', weight: -1 },
];
expect(parseResult.suggestKeywords).toEqual(expect.arrayContaining(suggestions))
})

test('should suggest AS and COMMENT', () => {
const parseResult = parseGenericSql('CREATE VIEW test_view ', '');

expect(parseResult.errors).toBeUndefined();

const suggestions: KeywordSuggestion[] = [
{ value: 'AS', weight: 1 },
{ value: 'COMMENT', weight: 3 },
];
expect(parseResult.suggestKeywords).toEqual(expect.arrayContaining(suggestions))
})

test('should suggest SELECT', () => {
const parseResult = parseGenericSql('CREATE VIEW test_view AS ', '');

expect(parseResult.errors).toBeUndefined();

const suggestions: KeywordSuggestion[] = [
{ value: 'SELECT', weight: -1 },
];
expect(parseResult.suggestKeywords).toEqual(expect.arrayContaining(suggestions))
})

test('should not report errors on full CREATE VIEW statement', () => {
const parseResult = parseGenericSqlWithoutCursor('CREATE VIEW test_view COMMENT "test" AS SELECT test_field, test_field_2 FROM test_table;');
expect(parseResult.errors).toBeUndefined();
})

test('should not report errors on full CREATE VIEW statement without comment', () => {
const parseResult = parseGenericSqlWithoutCursor('CREATE VIEW test_view AS SELECT test_field, test_field_2 FROM test_table;');
expect(parseResult.errors).toBeUndefined();
})

0 comments on commit c7e788a

Please sign in to comment.