From 7b7c2ab8d8a5f9cc1c38e62f66a5aaa2bf2f6366 Mon Sep 17 00:00:00 2001 From: wewoor Date: Thu, 11 May 2023 19:06:19 +0800 Subject: [PATCH] test: drop statment tests --- .../flinksql/syntax/dropStatement.test.ts | 72 ++++++++----------- .../flinksql/syntax/fixtures/dropCatalog.sql | 3 + .../flinksql/syntax/fixtures/dropDatabase.sql | 3 + .../flinksql/syntax/fixtures/dropFunction.sql | 5 ++ .../flinksql/syntax/fixtures/dropTable.sql | 5 ++ .../flinksql/syntax/fixtures/dropView.sql | 3 + 6 files changed, 50 insertions(+), 41 deletions(-) create mode 100644 test/parser/flinksql/syntax/fixtures/dropCatalog.sql create mode 100644 test/parser/flinksql/syntax/fixtures/dropDatabase.sql create mode 100644 test/parser/flinksql/syntax/fixtures/dropFunction.sql create mode 100644 test/parser/flinksql/syntax/fixtures/dropTable.sql create mode 100644 test/parser/flinksql/syntax/fixtures/dropView.sql diff --git a/test/parser/flinksql/syntax/dropStatement.test.ts b/test/parser/flinksql/syntax/dropStatement.test.ts index 3cacce2..3f99f85 100644 --- a/test/parser/flinksql/syntax/dropStatement.test.ts +++ b/test/parser/flinksql/syntax/dropStatement.test.ts @@ -1,49 +1,39 @@ import FlinkSQL from "../../../../src/parser/flinksql"; +import { readSQL } from "../../../helper"; -describe('FlinkSQL Create Table Syntax Tests', () => { +const features = { + table: readSQL(__dirname, 'dropTable.sql'), + view: readSQL(__dirname, 'dropView.sql'), + function: readSQL(__dirname, 'dropFunction.sql'), + catalog: readSQL(__dirname, 'dropCatalog.sql'), + database: readSQL(__dirname, 'dropDatabase.sql'), +}; + +describe('FlinkSQL Drop Statements Tests', () => { const parser = new FlinkSQL(); - // Drop statements - test('Test Simple Drop Catalog Statement', () => { - const sql = ` - DROP CATALOG catalog1; - DROP CATALOG IF EXISTS catalog2; - `; - const result = parser.validate(sql); - expect(result.length).toBe(0); + features.table.forEach((sql) => { + it(sql, () => { + expect(parser.validate(sql).length).toBe(0); + }); }); - test('Test Simple Drop Table Statement', () => { - const sql = ` - DROP TABLE Orders; - DROP TABLE IF EXISTS Orders; - DROP TEMPORARY TABLE IF EXISTS Orders; - `; - const result = parser.validate(sql); - expect(result.length).toBe(0); + features.view.forEach((sql) => { + it(sql, () => { + expect(parser.validate(sql).length).toBe(0); + }); }); - test('Test Simple Drop Database Statement', () => { - const sql = ` - DROP DATABASE Orders; - DROP DATABASE IF EXISTS Orders RESTRICT; - DROP DATABASE IF EXISTS Orders CASCADE; - `; - const result = parser.validate(sql); - expect(result.length).toBe(0); + features.function.forEach((sql) => { + it(sql, () => { + expect(parser.validate(sql).length).toBe(0); + }); }); - test('Test Simple Drop View Statement', () => { - const sql = ` - DROP VIEW Orders; - DROP TEMPORARY VIEW IF EXISTS Orders; - `; - const result = parser.validate(sql); - expect(result.length).toBe(0); - }); - test('Test Simple Drop Function Statement', () => { - const sql = ` - DROP FUNCTION Orders; - DROP TEMPORARY FUNCTION IF EXISTS Orders; - DROP TEMPORARY SYSTEM FUNCTION IF EXISTS Orders; - `; - const result = parser.validate(sql); - expect(result.length).toBe(0); + features.catalog.forEach((sql) => { + it(sql, () => { + expect(parser.validate(sql).length).toBe(0); + }); + }); + features.database.forEach((sql) => { + it(sql, () => { + expect(parser.validate(sql).length).toBe(0); + }); }); }); diff --git a/test/parser/flinksql/syntax/fixtures/dropCatalog.sql b/test/parser/flinksql/syntax/fixtures/dropCatalog.sql new file mode 100644 index 0000000..a88a37a --- /dev/null +++ b/test/parser/flinksql/syntax/fixtures/dropCatalog.sql @@ -0,0 +1,3 @@ +DROP CATALOG catalog1; + +DROP CATALOG IF EXISTS catalog2; \ No newline at end of file diff --git a/test/parser/flinksql/syntax/fixtures/dropDatabase.sql b/test/parser/flinksql/syntax/fixtures/dropDatabase.sql new file mode 100644 index 0000000..b86d2b6 --- /dev/null +++ b/test/parser/flinksql/syntax/fixtures/dropDatabase.sql @@ -0,0 +1,3 @@ +DROP DATABASE Orders; +DROP DATABASE IF EXISTS Orders RESTRICT; +DROP DATABASE IF EXISTS Orders CASCADE; \ No newline at end of file diff --git a/test/parser/flinksql/syntax/fixtures/dropFunction.sql b/test/parser/flinksql/syntax/fixtures/dropFunction.sql new file mode 100644 index 0000000..73d59ff --- /dev/null +++ b/test/parser/flinksql/syntax/fixtures/dropFunction.sql @@ -0,0 +1,5 @@ +DROP FUNCTION Orders; + +DROP TEMPORARY FUNCTION IF EXISTS Orders; + +DROP TEMPORARY SYSTEM FUNCTION IF EXISTS Orders; \ No newline at end of file diff --git a/test/parser/flinksql/syntax/fixtures/dropTable.sql b/test/parser/flinksql/syntax/fixtures/dropTable.sql new file mode 100644 index 0000000..88d37d7 --- /dev/null +++ b/test/parser/flinksql/syntax/fixtures/dropTable.sql @@ -0,0 +1,5 @@ +DROP TABLE Orders; + +DROP TABLE IF EXISTS Orders; + +DROP TEMPORARY TABLE IF EXISTS Orders; \ No newline at end of file diff --git a/test/parser/flinksql/syntax/fixtures/dropView.sql b/test/parser/flinksql/syntax/fixtures/dropView.sql new file mode 100644 index 0000000..e2b55d9 --- /dev/null +++ b/test/parser/flinksql/syntax/fixtures/dropView.sql @@ -0,0 +1,3 @@ +DROP VIEW Orders; + +DROP TEMPORARY VIEW IF EXISTS Orders; \ No newline at end of file