From d4ac1ae940c6bdfedfce962f7fa63ecee9746f59 Mon Sep 17 00:00:00 2001 From: nankanull <534129087@qq.com> Date: Sat, 24 Dec 2022 14:55:27 +0800 Subject: [PATCH] test: add nested bracket test --- test/utils/index.test.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/utils/index.test.ts b/test/utils/index.test.ts index 0422bef..d127a3a 100644 --- a/test/utils/index.test.ts +++ b/test/utils/index.test.ts @@ -27,6 +27,29 @@ describe('utils', () => { expect(result.length).toEqual(2); }); + // test nested bracket + test('split nested bracket sql', () => { + const sql = `WITH cte_sales_amounts (staff, sales, year) + AS + ( + SELECT + first_name + ' ' + last_name, + SUM(quantity * list_price * (1 - discount)), + YEAR(order_date) + FROM + sales.orders o + INNER JOIN sales.order_items i ON i.order_id = o.order_id + INNER JOIN sales.staffs s ON s.staff_id = o.staff_id + ) + SELECT staff, sales + FROM cte_sales_amounts + WHERE year = 2018; + SELECT * FROM table;`; + const result = splitSql(sql); + console.log(JSON.stringify(result)); + expect(result.length).toEqual(2); + }); + test('lexer', () => { const sql = `-- a ; select * from a;