rparsec-ruby19 1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/rparsec.rb +3 -0
- data/rparsec/context.rb +83 -0
- data/rparsec/error.rb +28 -0
- data/rparsec/expressions.rb +184 -0
- data/rparsec/functors.rb +274 -0
- data/rparsec/id_monad.rb +17 -0
- data/rparsec/keywords.rb +114 -0
- data/rparsec/locator.rb +40 -0
- data/rparsec/misc.rb +130 -0
- data/rparsec/monad.rb +62 -0
- data/rparsec/operators.rb +103 -0
- data/rparsec/parser.rb +894 -0
- data/rparsec/parser_monad.rb +23 -0
- data/rparsec/parsers.rb +623 -0
- data/rparsec/token.rb +43 -0
- data/test/src/expression_test.rb +124 -0
- data/test/src/full_parser_test.rb +95 -0
- data/test/src/functor_test.rb +66 -0
- data/test/src/import.rb +5 -0
- data/test/src/keyword_test.rb +28 -0
- data/test/src/operator_test.rb +21 -0
- data/test/src/parser_test.rb +53 -0
- data/test/src/perf_benchmark.rb +25 -0
- data/test/src/s_expression_test.rb +33 -0
- data/test/src/scratch.rb +41 -0
- data/test/src/simple_monad_test.rb +22 -0
- data/test/src/simple_parser_test.rb +423 -0
- data/test/src/sql.rb +268 -0
- data/test/src/sql_parser.rb +258 -0
- data/test/src/sql_test.rb +128 -0
- data/test/src/tests.rb +13 -0
- metadata +95 -0
@@ -0,0 +1,128 @@
|
|
1
|
+
require 'parser_test'
|
2
|
+
require 'sql'
|
3
|
+
require 'sql_parser'
|
4
|
+
class SqlTestCase < ParserTestCase
|
5
|
+
include SqlParser
|
6
|
+
def verify_sql(code, expected, parser)
|
7
|
+
assert_equal(expected, make(parser).parse(code).to_s)
|
8
|
+
end
|
9
|
+
def verify_relation(code, expected)
|
10
|
+
verify_sql(code, expected, relation)
|
11
|
+
end
|
12
|
+
def verify_predicate(code, expected)
|
13
|
+
verify_sql(code, expected, predicate)
|
14
|
+
end
|
15
|
+
def testSimpleExpression
|
16
|
+
verify_sql('1+2+3', '((1 + 2) + 3)', expression)
|
17
|
+
end
|
18
|
+
def testExpressionWithBool
|
19
|
+
verify_sql('1+Case 2 when 1: x else dbo.y end',
|
20
|
+
'(1 + case 2 when 1: x else dbo.y end)', expression)
|
21
|
+
end
|
22
|
+
def testExpressionWithWildcard
|
23
|
+
verify_sql('a.*', 'a.*', expression)
|
24
|
+
end
|
25
|
+
def testSimpleRelation
|
26
|
+
verify_relation('select * from table1', 'select * from table1')
|
27
|
+
end
|
28
|
+
def testSimpleRelationWithStringLiteral
|
29
|
+
verify_relation("select 'a',* from table1", "select 'a', * from table1")
|
30
|
+
end
|
31
|
+
def testSimpleRelationWithVar
|
32
|
+
verify_relation("select $a,* from table1", "select $a, * from table1")
|
33
|
+
end
|
34
|
+
def testSimpleRelationWithQuotedName
|
35
|
+
# the print out isn't really valid. but we care about parser, not the printer.
|
36
|
+
verify_relation("select $a,* from [table 1]", "select $a, * from table 1")
|
37
|
+
end
|
38
|
+
def testSubRelation
|
39
|
+
verify_relation('select * from (select a, b, c.* from c)',
|
40
|
+
'select * from (select a, b, c.* from c)')
|
41
|
+
end
|
42
|
+
def testSimpleRelationWithAlias
|
43
|
+
verify_relation('select x.* from table1 x', 'select x.* from table1 AS x')
|
44
|
+
end
|
45
|
+
def testSubRelationWithAlias
|
46
|
+
verify_relation('select * from ((select a, b, c.* from c)) x',
|
47
|
+
'select * from (select a, b, c.* from c) AS x')
|
48
|
+
end
|
49
|
+
def testRelationWithWhere
|
50
|
+
verify_relation('select * from table where x=1',
|
51
|
+
'select * from table where x = 1')
|
52
|
+
end
|
53
|
+
def testRelationWithWhereAndDistinct
|
54
|
+
verify_relation('select distinct * from table where x=1',
|
55
|
+
'select distinct * from table where x = 1')
|
56
|
+
end
|
57
|
+
def testRelationWithCompoundPredicateInWhereClause
|
58
|
+
verify_relation('select * from table where x=1 and y=3',
|
59
|
+
'select * from table where (x = 1 and y = 3)')
|
60
|
+
end
|
61
|
+
def testRelationWithOrderBy
|
62
|
+
verify_relation('select distinct * from table where x=1 order by x asc, y desc',
|
63
|
+
'select distinct * from table where x = 1 order by x, y desc')
|
64
|
+
end
|
65
|
+
def testRelationWithOrderByAndLimit
|
66
|
+
verify_relation('select distinct * from table where x=1 order by x asc, y desc limit 5',
|
67
|
+
'select distinct * from table where x = 1 order by x, y desc limit 5')
|
68
|
+
end
|
69
|
+
def testRelationWithGroupByWithoutHaving
|
70
|
+
verify_relation('select distinct * from table where x=1 group by x, y order by x asc, y desc',
|
71
|
+
'select distinct * from table where x = 1 group by x, y order by x, y desc')
|
72
|
+
end
|
73
|
+
def testRelationWithGroupByWithHaving
|
74
|
+
verify_relation('select distinct * from table where x=1 group by x, y having x!=y order by x asc, y desc',
|
75
|
+
'select distinct * from table where x = 1 group by x, y having x <> y order by x, y desc')
|
76
|
+
end
|
77
|
+
def testRelationWithSimpleJoin
|
78
|
+
verify_relation('select * from table1 t1 inner join table2 t2 on t1.a=t2.b where x=1',
|
79
|
+
'select * from table1 AS t1 inner join table2 AS t2 on t1.a = t2.b where x = 1')
|
80
|
+
end
|
81
|
+
def testRelationWithMultiJoins
|
82
|
+
verify_relation('select * from table1 t1 inner join table2 t2 right outer join table3 on t2.x>t3.y on t1.a=t2.b cross join table3 where x=1',
|
83
|
+
'select * from table1 AS t1 inner join table2 AS t2 right join table3 on t2.x > t3.y on t1.a = t2.b cross join table3 where x = 1')
|
84
|
+
end
|
85
|
+
def testRelationWithExists
|
86
|
+
verify_relation('select 1 from table1 where exists(select id from table2 where x=name)',
|
87
|
+
'select 1 from table1 where exists(select id from table2 where x = name)')
|
88
|
+
end
|
89
|
+
def testRelationWithIn
|
90
|
+
verify_relation('select 1 from table1 where x in(1,2,3)',
|
91
|
+
'select 1 from table1 where x in (1, 2, 3)')
|
92
|
+
end
|
93
|
+
def testRelationWithNotIn
|
94
|
+
verify_relation('select 1 from table1 where x not in(1,2,3)',
|
95
|
+
'select 1 from table1 where x not in (1, 2, 3)')
|
96
|
+
end
|
97
|
+
def testRelationWithInRelation
|
98
|
+
verify_relation('select 1 from table1 where x in(select * from table)',
|
99
|
+
'select 1 from table1 where x in (select * from table)')
|
100
|
+
end
|
101
|
+
def testRelationWithNotInRelation
|
102
|
+
verify_relation('select 1 from table1 where x not in table',
|
103
|
+
'select 1 from table1 where x not in (table)')
|
104
|
+
end
|
105
|
+
def testRelationWithNotInRelationAndAmbiguousSubRelation
|
106
|
+
verify_relation('select 1 from table1 where x not in (table)',
|
107
|
+
'select 1 from table1 where x not in (table)')
|
108
|
+
end
|
109
|
+
def testRelationWithBetween
|
110
|
+
verify_relation('select 1 from table1 where x between a and b',
|
111
|
+
'select 1 from table1 where x between a and b')
|
112
|
+
end
|
113
|
+
def testRelationWithNotBetween
|
114
|
+
verify_relation('select 1 from table1 where x not between (a,b)',
|
115
|
+
'select 1 from table1 where x not between a and b')
|
116
|
+
end
|
117
|
+
def testRelationWithGroupCompare
|
118
|
+
verify_relation('select 1 from table1 where not (a,b,c)>(1,2,3)',
|
119
|
+
'select 1 from table1 where (not (a, b, c) > (1, 2, 3))')
|
120
|
+
end
|
121
|
+
def testUnion
|
122
|
+
verify_relation('select * from table1 where a=2 union select * from table2 where a=1',
|
123
|
+
'select * from table1 where a = 2 union select * from table2 where a = 1')
|
124
|
+
end
|
125
|
+
def testAndOrNot
|
126
|
+
verify_predicate '1>1 or 1<=1 and not true', '(1 > 1 or (1 <= 1 and (not true)))'
|
127
|
+
end
|
128
|
+
end
|
data/test/src/tests.rb
ADDED
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rparsec-ruby19
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.0'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ben Yu
|
9
|
+
- Clinton R. Nixon
|
10
|
+
autorequire: rparsec
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2012-01-26 00:00:00.000000000 Z
|
14
|
+
dependencies: []
|
15
|
+
description: rparsec is a recursive descent parser combinator framework. Declarative
|
16
|
+
API allows creating parser intuitively and dynamically.
|
17
|
+
email:
|
18
|
+
- ajoo.email@gmail.com
|
19
|
+
- crnixon@gmail.com
|
20
|
+
executables: []
|
21
|
+
extensions: []
|
22
|
+
extra_rdoc_files: []
|
23
|
+
files:
|
24
|
+
- rparsec/context.rb
|
25
|
+
- rparsec/error.rb
|
26
|
+
- rparsec/expressions.rb
|
27
|
+
- rparsec/functors.rb
|
28
|
+
- rparsec/id_monad.rb
|
29
|
+
- rparsec/keywords.rb
|
30
|
+
- rparsec/locator.rb
|
31
|
+
- rparsec/misc.rb
|
32
|
+
- rparsec/monad.rb
|
33
|
+
- rparsec/operators.rb
|
34
|
+
- rparsec/parser.rb
|
35
|
+
- rparsec/parser_monad.rb
|
36
|
+
- rparsec/parsers.rb
|
37
|
+
- rparsec/token.rb
|
38
|
+
- rparsec.rb
|
39
|
+
- test/src/expression_test.rb
|
40
|
+
- test/src/full_parser_test.rb
|
41
|
+
- test/src/functor_test.rb
|
42
|
+
- test/src/import.rb
|
43
|
+
- test/src/keyword_test.rb
|
44
|
+
- test/src/operator_test.rb
|
45
|
+
- test/src/parser_test.rb
|
46
|
+
- test/src/perf_benchmark.rb
|
47
|
+
- test/src/s_expression_test.rb
|
48
|
+
- test/src/scratch.rb
|
49
|
+
- test/src/simple_monad_test.rb
|
50
|
+
- test/src/simple_parser_test.rb
|
51
|
+
- test/src/sql.rb
|
52
|
+
- test/src/sql_parser.rb
|
53
|
+
- test/src/sql_test.rb
|
54
|
+
- test/src/tests.rb
|
55
|
+
homepage:
|
56
|
+
licenses: []
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- .
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 1.8.11
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: A Ruby Parser Combinator Framework
|
79
|
+
test_files:
|
80
|
+
- test/src/expression_test.rb
|
81
|
+
- test/src/full_parser_test.rb
|
82
|
+
- test/src/functor_test.rb
|
83
|
+
- test/src/import.rb
|
84
|
+
- test/src/keyword_test.rb
|
85
|
+
- test/src/operator_test.rb
|
86
|
+
- test/src/parser_test.rb
|
87
|
+
- test/src/perf_benchmark.rb
|
88
|
+
- test/src/s_expression_test.rb
|
89
|
+
- test/src/scratch.rb
|
90
|
+
- test/src/simple_monad_test.rb
|
91
|
+
- test/src/simple_parser_test.rb
|
92
|
+
- test/src/sql.rb
|
93
|
+
- test/src/sql_parser.rb
|
94
|
+
- test/src/sql_test.rb
|
95
|
+
- test/src/tests.rb
|