diff options
author | Ting-Wei Lan <tingwei.lan@cobinhood.com> | 2019-01-22 11:26:45 +0800 |
---|---|---|
committer | Jhih-Ming Huang <jm.huang@cobinhood.com> | 2019-05-06 10:44:03 +0800 |
commit | d25ee5f726545b165dba6a45def0e55027b6941b (patch) | |
tree | 4464f182aba472a2e42be742dd73653a9a4485f2 /core/vm/sqlvm/parser/parser_test.go | |
parent | 4d01db0522f7405981a1f18f4ee79a6d1aac067b (diff) | |
download | dexon-d25ee5f726545b165dba6a45def0e55027b6941b.tar dexon-d25ee5f726545b165dba6a45def0e55027b6941b.tar.gz dexon-d25ee5f726545b165dba6a45def0e55027b6941b.tar.bz2 dexon-d25ee5f726545b165dba6a45def0e55027b6941b.tar.lz dexon-d25ee5f726545b165dba6a45def0e55027b6941b.tar.xz dexon-d25ee5f726545b165dba6a45def0e55027b6941b.tar.zst dexon-d25ee5f726545b165dba6a45def0e55027b6941b.zip |
core: vm: sqlvm: move AST and parser to their own packages
In order to avoid putting too many different things in single package
and allow other projects to reuse the syntax tree and the parser, these
two components are moved to different packages and all nodes used in AST
are now exported. A lot of comments are added in this commit to pass
golint checks.
Diffstat (limited to 'core/vm/sqlvm/parser/parser_test.go')
-rw-r--r-- | core/vm/sqlvm/parser/parser_test.go | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/core/vm/sqlvm/parser/parser_test.go b/core/vm/sqlvm/parser/parser_test.go new file mode 100644 index 000000000..a81b1d22d --- /dev/null +++ b/core/vm/sqlvm/parser/parser_test.go @@ -0,0 +1,82 @@ +package parser + +import ( + "testing" + + "github.com/stretchr/testify/suite" +) + +type ParserTestSuite struct{ suite.Suite } + +func (s *ParserTestSuite) requireParseNoError(sql string) { + _, err := ParseString(sql) + s.Require().NoError(err) +} + +func (s *ParserTestSuite) TestParse() { + // Test stmt. + s.requireParseNoError(``) + s.requireParseNoError(`;`) + s.requireParseNoError(`;;;select 1;;;;`) + + // Test expr. + s.requireParseNoError(`select 1 + 2 * 3`) + s.requireParseNoError(`select a(1 + 1)`) + s.requireParseNoError(`select hEx'12'`) + s.requireParseNoError(`select x'12'`) + s.requireParseNoError(`select 0xABC`) + s.requireParseNoError(`select true and false or true and false or true`) + s.requireParseNoError(`SeLeCT '1' NoT LiKe '1';`) + s.requireParseNoError(`select a in (1,2) is not null not in (true)`) + s.requireParseNoError(`select count(*)`) + s.requireParseNoError(`select cast(a as fixed65535X1)`) + s.requireParseNoError(`select "now!" ( not a + b, aa( + 3 + .1 + 1. ) + - .3e-9 + 1.e-10, 'a' || 'b' and true )`) + + // Test where. + s.requireParseNoError(`select * from abc where abc is null`) + s.requireParseNoError(`select * from abc where abc is not null`) + s.requireParseNoError(`select * from abc where abc in (1, 1)`) + s.requireParseNoError(`select * from abc where abc not in (1, 1)`) + s.requireParseNoError(`select * from abc where not true`) + s.requireParseNoError(`select * from abc where a like a + 1`) + + // Test some logic expr and no from. + s.requireParseNoError(`select 1 where a is not null = b`) + s.requireParseNoError(`select 1 where null = null is null and true`) + s.requireParseNoError(`select 1 where null is null = null`) + s.requireParseNoError(`SELECT 1 + 2 WHERE 3 <> 4`) + + // Test order by. + s.requireParseNoError(`select a=b+1 from a order by a desc`) + s.requireParseNoError(`select 1 from a order by b + 1 desc`) + s.requireParseNoError(`select 1 from a order by b + 1 nulls first`) + s.requireParseNoError(`select 1 from a order by b + 1 desc nulls last`) + + // Test group by. + s.requireParseNoError(`select 1 from a group by b + 1`) + + // Test insert. + s.requireParseNoError(`insert into "abc"(a) values (f(a, b),g(a),h())`) + s.requireParseNoError(`insert into "abc"(a) values (1,2,3), (f(a, b),g(a),h())`) + s.requireParseNoError(`insert into a default values`) + s.requireParseNoError(`insert into a values (default)`) + + // Test update. + s.requireParseNoError(`update "~!@#$%^&*()" set b = default where a is null;`) + s.requireParseNoError(`update "~!@#$%^&*()" set b = default, a = 123 where a is null;`) + + // Test delete. + s.requireParseNoError(`delete from a where b is null`) + + // Test create table. + s.requireParseNoError(`create table a (a int32 not null unique primary key default 0)`) + s.requireParseNoError(`create table "~!@#$%^&*()" ( a int32 references b ( a ) , b string primary key, c address not null default 1 + 1 )`) + + // Test create index. + s.requireParseNoError(`create unique index a on a (a)`) + s.requireParseNoError(`create index "~!@#$%^&*()" on ㄅ ( a , b )`) +} + +func TestParser(t *testing.T) { + suite.Run(t, new(ParserTestSuite)) +} |