@@ -5,19 +5,20 @@ const parser = require('../');
5
5
6
6
const testParser = function ( sql ) {
7
7
let firstAst = parser . parse ( sql ) ;
8
+ debug ( JSON . stringify ( firstAst , null , 2 ) ) ;
8
9
let firstSql = parser . stringify ( firstAst ) ;
10
+ debug ( firstSql ) ;
9
11
let secondAst = parser . parse ( firstSql ) ;
12
+ debug ( parser . stringify ( secondAst ) ) ;
10
13
let secondSql = parser . stringify ( secondAst ) ;
14
+ debug ( JSON . stringify ( secondAst , null , 2 ) ) ;
11
15
12
16
if ( firstSql !== secondSql ) {
13
17
console . log ( 'firstSql' , firstSql ) ;
14
18
console . log ( 'secondSql' , secondSql ) ;
15
19
throw 'err firstSql don\'t equals secondSql. ' ;
16
20
}
17
21
18
- debug ( JSON . stringify ( secondAst , null , 2 ) ) ;
19
- debug ( parser . stringify ( secondAst ) ) ;
20
-
21
22
return secondAst ;
22
23
}
23
24
@@ -360,5 +361,21 @@ describe('select grammar support', function () {
360
361
testParser ( 'SELECT COUNT(*) AS total, a b, b as c, c/2 d, d & e an FROM b' ) ;
361
362
} ) ;
362
363
364
+ it ( 'union support, https://dev.mysql.com/doc/refman/8.0/en/union.html' , function ( ) {
365
+ testParser ( 'select a from dual union select a from foo;' ) ;
366
+ } ) ;
367
+
368
+ it ( 'union Parenthesized support, https://dev.mysql.com/doc/refman/8.0/en/union.html' , function ( ) {
369
+ testParser ( '(select a from dual) union (select a from foo) order by a desc limit 100, 100;' ) ;
370
+ } ) ;
371
+
372
+ it ( 'union all support, https://dev.mysql.com/doc/refman/8.0/en/union.html' , function ( ) {
373
+ testParser ( '(select a from dual) union all (select a from foo) order by a limit 100' ) ;
374
+ } ) ;
375
+
376
+ it ( 'union distinct support, https://dev.mysql.com/doc/refman/8.0/en/union.html' , function ( ) {
377
+ testParser ( 'select a from dual order by a desc limit 1, 1 union distinct select a from foo order by a limit 1' ) ;
378
+ } ) ;
379
+
363
380
} ) ;
364
381
0 commit comments