@@ -5,19 +5,20 @@ const parser = require('../');
55
66const testParser = function ( sql ) {
77 let firstAst = parser . parse ( sql ) ;
8+ debug ( JSON . stringify ( firstAst , null , 2 ) ) ;
89 let firstSql = parser . stringify ( firstAst ) ;
10+ debug ( firstSql ) ;
911 let secondAst = parser . parse ( firstSql ) ;
12+ debug ( parser . stringify ( secondAst ) ) ;
1013 let secondSql = parser . stringify ( secondAst ) ;
14+ debug ( JSON . stringify ( secondAst , null , 2 ) ) ;
1115
1216 if ( firstSql !== secondSql ) {
1317 console . log ( 'firstSql' , firstSql ) ;
1418 console . log ( 'secondSql' , secondSql ) ;
1519 throw 'err firstSql don\'t equals secondSql. ' ;
1620 }
1721
18- debug ( JSON . stringify ( secondAst , null , 2 ) ) ;
19- debug ( parser . stringify ( secondAst ) ) ;
20-
2122 return secondAst ;
2223}
2324
@@ -360,5 +361,21 @@ describe('select grammar support', function () {
360361 testParser ( 'SELECT COUNT(*) AS total, a b, b as c, c/2 d, d & e an FROM b' ) ;
361362 } ) ;
362363
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+
363380} ) ;
364381
0 commit comments