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

refactor: migrate truncate table tests to typescript #102

Merged
merged 1 commit 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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import {expect, test} from '@jest/globals';

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

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

expect(parseResult.errors).toBeUndefined();

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

test('should suggest databases or tables and IF EXISTS', () => {
const parseResult = parseGenericSql('TRUNCATE TABLE ', '');

expect(parseResult.errors).toBeUndefined();

const tablesSuggestion: TablesSuggestion = {};
expect(parseResult.suggestTables).toEqual(tablesSuggestion);

const databasesSuggestion: DatabasesSuggestion = {
appendDot: true,
};
expect(parseResult.suggestDatabases).toEqual(databasesSuggestion);

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

test('should properly fill locations', () => {
const parseResult = parseGenericSqlWithoutCursor('TRUNCATE TABLE test_database.test_table;');

expect(parseResult.errors).toBeUndefined();

const locations: StatementPart[] = [
{
location: {
first_column: 1,
first_line: 1,
last_column: 40,
last_line: 1,
},
type: 'statement',
},
{
identifier: 'TRUNCATE TABLE',
location: {
first_column: 1,
first_line: 1,
last_column: 9,
last_line: 1,
},
type: 'statementType',
},
{
identifierChain: [
{
name: 'test_database',
},
],
location: {
first_column: 16,
first_line: 1,
last_column: 29,
last_line: 1,
},
type: 'database',
},
{
identifierChain: [
{
name: 'test_database',
},
{
name: 'test_table',
},
],
location: {
first_column: 30,
first_line: 1,
last_column: 40,
last_line: 1,
},
type: 'table',
},
];
expect(parseResult.locations).toEqual(locations);
});
Loading