rparsec 0.4 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -0,0 +1,13 @@
1
+ %w{
2
+ simple_monad
3
+ functor
4
+ simple_parser
5
+ operator
6
+ keyword
7
+ expression
8
+ s_expression
9
+ full_parser
10
+ sql
11
+ }.each do |name|
12
+ require "#{name}_test"
13
+ end
metadata CHANGED
@@ -1,21 +1,21 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.0
2
+ rubygems_version: 0.8.10
3
3
  specification_version: 1
4
4
  name: rparsec
5
5
  version: !ruby/object:Gem::Version
6
- version: "0.4"
7
- date: 2006-11-21 00:00:00.000000 -06:00
6
+ version: 0.4.1
7
+ date: 2006-11-22
8
8
  summary: A Ruby Parser Combinator Framework
9
9
  require_paths:
10
- - lib
10
+ - "."
11
11
  email: ajoo.email@gmail.com
12
12
  homepage:
13
13
  rubyforge_project:
14
14
  description: rparsec is a recursive descent parser combinator framework. Declarative API allows creating parser intuitively and dynamically.
15
- autorequire:
15
+ autorequire: rparsec
16
16
  default_executable:
17
17
  bindir: bin
18
- has_rdoc: false
18
+ has_rdoc: true
19
19
  required_ruby_version: !ruby/object:Gem::Version::Requirement
20
20
  requirements:
21
21
  -
@@ -24,13 +24,41 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
24
24
  version: 0.0.0
25
25
  version:
26
26
  platform: ruby
27
- signing_key:
28
- cert_chain:
29
- post_install_message:
30
27
  authors:
31
28
  - Ben Yu
32
- files: []
33
- test_files: []
29
+ files:
30
+ - rparsec/context.rb
31
+ - rparsec/error.rb
32
+ - rparsec/expressions.rb
33
+ - rparsec/functors.rb
34
+ - rparsec/id_monad.rb
35
+ - rparsec/keywords.rb
36
+ - rparsec/locator.rb
37
+ - rparsec/misc.rb
38
+ - rparsec/monad.rb
39
+ - rparsec/operators.rb
40
+ - rparsec/parser.rb
41
+ - rparsec/parsers.rb
42
+ - rparsec/parser_monad.rb
43
+ - rparsec/token.rb
44
+ - rparsec.rb
45
+ test_files:
46
+ - test/src/expression_test.rb
47
+ - test/src/full_parser_test.rb
48
+ - test/src/functor_test.rb
49
+ - test/src/import.rb
50
+ - test/src/keyword_test.rb
51
+ - test/src/operator_test.rb
52
+ - test/src/parser_test.rb
53
+ - test/src/perf_benchmark.rb
54
+ - test/src/scratch.rb
55
+ - test/src/simple_monad_test.rb
56
+ - test/src/simple_parser_test.rb
57
+ - test/src/sql.rb
58
+ - test/src/sql_parser.rb
59
+ - test/src/sql_test.rb
60
+ - test/src/s_expression_test.rb
61
+ - test/src/tests.rb
34
62
  rdoc_options: []
35
63
  extra_rdoc_files: []
36
64
  executables: []