Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: define useDatabase, add prependQuestionMark and prependFrom to DatabasesSuggestion, migrate use and set tests to typescript #101

Merged
merged 4 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/autocomplete/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface ParseResult {
suggestTables?: TablesSuggestion;
suggestColumns?: ColumnSuggestion;
suggestAggregateFunctions?: AggregateFunctionsSuggestion;
suggestAnalyticFunctions?: unknown;
suggestAnalyticFunctions?: boolean;
suggestColRefKeywords?: {
[type: string]: string[];
};
Expand All @@ -33,6 +33,7 @@ export interface ParseResult {
functionalEngines: Engines;
};
colRef?: ColumnReference;
useDatabase?: string;

// Reasons for those fields are unknown
definitions?: []; // TODO: figure our if it's optional
Expand Down Expand Up @@ -100,6 +101,8 @@ export interface TablesSuggestion {

export interface DatabasesSuggestion {
appendDot?: boolean; // TODO: figure our if it's optional
prependQuestionMark?: boolean;
prependFrom?: boolean;
}

export interface AggregateFunctionsSuggestion {
Expand Down
76 changes: 76 additions & 0 deletions src/autocomplete/parsers/generic/grammar/set/set.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import {expect, test} from '@jest/globals';

import {
KeywordSuggestion,
StatementPart,
parseGenericSql,
parseGenericSqlWithoutCursor,
} from '../../../../index';

test('should suggest SET', () => {
const parseResult = parseGenericSql('', '');

expect(parseResult.errors).toBeUndefined();

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

test('should not report errors when setting string with double quotes', () => {
const parseResult = parseGenericSql('SET test_table.test_column="test";', '');

expect(parseResult.errors).toBeUndefined();
});

test('should not report errors when setting string with single quotes', () => {
const parseResult = parseGenericSql("SET test_table.test_column='test';", '');

expect(parseResult.errors).toBeUndefined();
});

test('should not report errors when setting string without quotes', () => {
const parseResult = parseGenericSql('SET test_table.test_column=test;', '');

expect(parseResult.errors).toBeUndefined();
});

test('should not report errors when setting boolean', () => {
const parseResult = parseGenericSql('SET test_table.test_column=true;', '');

expect(parseResult.errors).toBeUndefined();
});

test('should not report errors when setting number', () => {
const parseResult = parseGenericSql('SET test_table.test_column=900000;', '');

expect(parseResult.errors).toBeUndefined();
});

test('should properly fill locations', () => {
const parseResult = parseGenericSqlWithoutCursor('SET test_table.test_column="test";');

expect(parseResult.errors).toBeUndefined();

const locations: StatementPart[] = [
{
location: {
first_column: 1,
first_line: 1,
last_column: 34,
last_line: 1,
},
type: 'statement',
},
{
identifier: 'SET',
location: {
first_column: 1,
first_line: 1,
last_column: 4,
last_line: 1,
},
type: 'statementType',
},
];
expect(parseResult.locations).toEqual(locations);
});
11 changes: 0 additions & 11 deletions src/autocomplete/parsers/generic/grammar/set/set_common.test.json

This file was deleted.

52 changes: 0 additions & 52 deletions src/autocomplete/parsers/generic/grammar/set/set_option.test.json

This file was deleted.

103 changes: 0 additions & 103 deletions src/autocomplete/parsers/generic/grammar/use/use.test.json

This file was deleted.

Loading
Loading