ddl_parser 0.0.3 → 0.0.4
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.
- checksums.yaml +5 -13
- data/Rakefile +1 -1
- data/ddl_parser.gemspec +10 -10
- data/lib/ddl_parser/ddl/db2/parser.rb +14 -14
- data/lib/ddl_parser/ddl/db2.rb +1 -1
- data/lib/ddl_parser/ddl.rb +1 -1
- data/lib/ddl_parser/parser.rb +9 -7
- data/lib/ddl_parser/shared_rules/constants.rb +12 -12
- data/lib/ddl_parser/shared_rules/data_types.rb +13 -13
- data/lib/ddl_parser/shared_rules.rb +3 -3
- data/lib/ddl_parser/sql/db2.rb +1 -1
- data/lib/ddl_parser/sql.rb +1 -1
- data/lib/ddl_parser/{translater → translator}/alter_table.rb +1 -1
- data/lib/ddl_parser/{translater → translator}/create_index.rb +1 -1
- data/lib/ddl_parser/{translater → translator}/create_table.rb +1 -1
- data/lib/ddl_parser/translator.rb +6 -0
- data/lib/ddl_parser/version.rb +1 -1
- data/lib/ddl_parser.rb +9 -9
- data/spec/ddl_parser/ddl/db2/alter_table_spec.rb +20 -20
- data/spec/ddl_parser/ddl/db2/create_index_spec.rb +5 -5
- data/spec/ddl_parser/ddl/db2/create_table_spec.rb +170 -171
- data/spec/ddl_parser/parser_spec.rb +39 -39
- data/spec/ddl_parser/shared_rules/constants_spec.rb +65 -65
- data/spec/ddl_parser/shared_rules/data_types_spec.rb +14 -14
- data/spec/ddl_parser/sql/db2/select_parser_spec.rb +58 -58
- data/spec/spec_helper.rb +6 -6
- metadata +14 -14
- data/lib/ddl_parser/translater.rb +0 -6
@@ -1,65 +1,65 @@
|
|
1
|
-
|
1
|
+
require_relative '../../spec/spec_helper'
|
2
2
|
|
3
3
|
describe 'DDLParser::Parser' do
|
4
4
|
|
5
5
|
it "knows if it's valid" do
|
6
|
-
sql =
|
6
|
+
sql = 'CREATE TABLE TEST (ID INT)'
|
7
7
|
parser = DDLParser::Parser.new(sql)
|
8
8
|
parser.valid?.should == true
|
9
9
|
end
|
10
10
|
|
11
11
|
it "knows if it's invalid" do
|
12
|
-
sql =
|
12
|
+
sql = 'CREATE TABLE TEST ()'
|
13
13
|
parser = DDLParser::Parser.new(sql)
|
14
14
|
parser.valid?.should == false
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
18
|
-
sql =
|
17
|
+
it 'can report errors' do
|
18
|
+
sql = 'CREATE TABLE TEST ()'
|
19
19
|
parser = DDLParser::Parser.new(sql)
|
20
|
-
parser.errors.should include(
|
20
|
+
parser.errors.should include('CREATE_TABLE_STATEMENT')
|
21
21
|
end
|
22
22
|
|
23
|
-
it
|
24
|
-
sql =
|
23
|
+
it 'statement_type' do
|
24
|
+
sql = 'CREATE TABLE TEST (ID INT, FOO INT)'
|
25
25
|
parser = DDLParser::Parser.new(sql)
|
26
26
|
parser.statement_type.should == :create_table
|
27
27
|
end
|
28
28
|
|
29
|
-
it
|
30
|
-
sql =
|
29
|
+
it 'returns the parse tree' do
|
30
|
+
sql = 'CREATE TABLE TEST (ID INT, FOO INT)'
|
31
31
|
parser = DDLParser::Parser.new(sql)
|
32
|
-
parser.parse_tree.should == {:operation=>
|
33
|
-
{:column=>{:field=>
|
34
|
-
{:column=>{:field=>
|
32
|
+
parser.parse_tree.should == {:operation=> 'create table', :table_name=> 'test', :elements=>[
|
33
|
+
{:column=>{:field=> 'id', :data_type=> 'int', :options=> ''}},
|
34
|
+
{:column=>{:field=> 'foo', :data_type=> 'int', :options=> ''}}]}
|
35
35
|
end
|
36
36
|
|
37
|
-
context
|
38
|
-
it
|
39
|
-
sql =
|
37
|
+
context 'create table translate' do
|
38
|
+
it 'translate table_name' do
|
39
|
+
sql = 'CREATE TABLE TEST (ID INT, FOO INT)'
|
40
40
|
parser = DDLParser::Parser.new(sql)
|
41
|
-
parser.translate.table_name.should ==
|
41
|
+
parser.translate.table_name.should == 'test'
|
42
42
|
end
|
43
43
|
|
44
44
|
|
45
|
-
it
|
46
|
-
sql =
|
45
|
+
it 'translate columns' do
|
46
|
+
sql = 'CREATE TABLE TEST (ID INT, FOO INT)'
|
47
47
|
parser = DDLParser::Parser.new(sql)
|
48
|
-
parser.translate.columns.should == [{:field=>
|
48
|
+
parser.translate.columns.should == [{:field=> 'id', :data_type=> 'int', :options=> ''}, {:field=> 'foo', :data_type=> 'int', :options=> ''}]
|
49
49
|
|
50
|
-
sql =
|
50
|
+
sql = 'CREATE TABLE TEST (ID INT)'
|
51
51
|
parser = DDLParser::Parser.new(sql)
|
52
|
-
parser.translate.columns.should == [{:field=>
|
52
|
+
parser.translate.columns.should == [{:field=> 'id', :data_type=> 'int', :options=> ''}]
|
53
53
|
end
|
54
54
|
|
55
|
-
it
|
56
|
-
sql =
|
55
|
+
it 'translate primary key' do
|
56
|
+
sql = 'CREATE TABLE TEST (ID INT, PRIMARY KEY (ID))'
|
57
57
|
parser = DDLParser::Parser.new(sql)
|
58
|
-
parser.translate.primary_key.should ==
|
58
|
+
parser.translate.primary_key.should == 'id'
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
-
context
|
62
|
+
context 'alter table translate' do
|
63
63
|
let(:sql) {
|
64
64
|
sql = <<EOF
|
65
65
|
ALTER TABLE BUDGET
|
@@ -69,27 +69,27 @@ EOF
|
|
69
69
|
sql
|
70
70
|
}
|
71
71
|
|
72
|
-
it
|
72
|
+
it 'translate table_name' do
|
73
73
|
parser = DDLParser::Parser.new(sql)
|
74
|
-
parser.translate.table_name.should ==
|
74
|
+
parser.translate.table_name.should == 'budget'
|
75
75
|
end
|
76
76
|
|
77
77
|
|
78
|
-
it
|
78
|
+
it 'translate columns' do
|
79
79
|
parser = DDLParser::Parser.new(sql)
|
80
|
-
parser.translate.add_columns.should == [{:field=>
|
81
|
-
:data_type=>{:decimal=>{:precision=>{:total=>{:integer=>
|
82
|
-
:options=>[{:column_option=>
|
83
|
-
{:default_clause=>[{:integer=>
|
84
|
-
{:field=>
|
85
|
-
:data_type=>{:char=>{:length=>{:integer=>
|
86
|
-
:options=>
|
80
|
+
parser.translate.add_columns.should == [{:field=> 'budget_amount_in_co',
|
81
|
+
:data_type=>{:decimal=>{:precision=>{:total=>{:integer=> '15'}, :scale=>{:integer=> '2'}}}},
|
82
|
+
:options=>[{:column_option=> 'not null'},
|
83
|
+
{:default_clause=>[{:integer=> '0'}]}]},
|
84
|
+
{:field=> 'budget_amount_curr',
|
85
|
+
:data_type=>{:char=>{:length=>{:integer=> '4'}}},
|
86
|
+
:options=> ''}]
|
87
87
|
end
|
88
88
|
|
89
|
-
it
|
90
|
-
sql =
|
89
|
+
it 'translate primary key' do
|
90
|
+
sql = 'CREATE TABLE TEST (ID INT, PRIMARY KEY (ID))'
|
91
91
|
parser = DDLParser::Parser.new(sql)
|
92
|
-
parser.translate.primary_key.should ==
|
92
|
+
parser.translate.primary_key.should == 'id'
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative '../../../spec/spec_helper'
|
2
2
|
|
3
3
|
class DummyParser < Parslet::Parser
|
4
4
|
include DDLParser::SharedRules::Constants
|
@@ -7,120 +7,120 @@ end
|
|
7
7
|
describe DDLParser::SharedRules::Constants do
|
8
8
|
let(:parser) { DummyParser.new }
|
9
9
|
|
10
|
-
it
|
10
|
+
it 'digits' do
|
11
11
|
(0..9).each do |digit|
|
12
12
|
expect(parser.digit).to parse(digit.to_s)
|
13
13
|
end
|
14
|
-
(
|
14
|
+
('a'..'z').each do |non_digit|
|
15
15
|
expect(parser.digit).not_to parse(non_digit.to_s)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
it
|
20
|
-
expect(parser.integer).to parse(
|
21
|
-
expect(parser.integer).to parse(
|
22
|
-
expect(parser.integer).to parse(
|
23
|
-
expect(parser.integer).to parse(
|
24
|
-
expect(parser.integer).not_to parse(
|
19
|
+
it 'integer' do
|
20
|
+
expect(parser.integer).to parse('1')
|
21
|
+
expect(parser.integer).to parse('123456789')
|
22
|
+
expect(parser.integer).to parse('-123456789')
|
23
|
+
expect(parser.integer).to parse('0123')
|
24
|
+
expect(parser.integer).not_to parse('1.2')
|
25
25
|
end
|
26
26
|
|
27
|
-
it
|
28
|
-
expect(parser.float).to parse(
|
29
|
-
expect(parser.float).to parse(
|
30
|
-
expect(parser.float).to parse(
|
31
|
-
expect(parser.float).to parse(
|
32
|
-
expect(parser.float).not_to parse(
|
27
|
+
it 'float' do
|
28
|
+
expect(parser.float).to parse('-1.1')
|
29
|
+
expect(parser.float).to parse('1.1')
|
30
|
+
expect(parser.float).to parse('123456.789')
|
31
|
+
expect(parser.float).to parse('-123456.789')
|
32
|
+
expect(parser.float).not_to parse('12')
|
33
33
|
end
|
34
34
|
|
35
|
-
it
|
36
|
-
expect(parser.space).to parse(
|
37
|
-
expect(parser.space).to parse(
|
35
|
+
it 'space' do
|
36
|
+
expect(parser.space).to parse(' ')
|
37
|
+
expect(parser.space).to parse(' ')
|
38
38
|
expect(parser.space).to parse("\t")
|
39
|
-
expect(parser.space).not_to parse(
|
40
|
-
expect(parser.space).not_to parse(
|
39
|
+
expect(parser.space).not_to parse('')
|
40
|
+
expect(parser.space).not_to parse('1')
|
41
41
|
end
|
42
42
|
|
43
|
-
it
|
44
|
-
expect(parser.space?).to parse(
|
45
|
-
expect(parser.space?).to parse(
|
46
|
-
expect(parser.space?).to parse(
|
47
|
-
expect(parser.space?).not_to parse(
|
43
|
+
it 'space?' do
|
44
|
+
expect(parser.space?).to parse('')
|
45
|
+
expect(parser.space?).to parse(' ')
|
46
|
+
expect(parser.space?).to parse(' ')
|
47
|
+
expect(parser.space?).not_to parse('1')
|
48
48
|
end
|
49
49
|
|
50
|
-
it
|
50
|
+
it 'newline' do
|
51
51
|
expect(parser.newline).to parse("\n")
|
52
|
-
expect(parser.newline).not_to parse(
|
52
|
+
expect(parser.newline).not_to parse(' ')
|
53
53
|
expect(parser.newline).not_to parse("\t")
|
54
54
|
end
|
55
55
|
|
56
|
-
it
|
56
|
+
it 'spaces' do
|
57
57
|
expect(parser.spaces).to parse("\n")
|
58
58
|
expect(parser.spaces).to parse(" \n \n")
|
59
59
|
expect(parser.spaces).to parse("\t ")
|
60
60
|
end
|
61
61
|
|
62
|
-
it
|
63
|
-
expect(parser.comment?).to parse(
|
62
|
+
it 'comment?' do
|
63
|
+
expect(parser.comment?).to parse('-- foobar')
|
64
64
|
expect(parser.comment?).not_to parse("--\nfoobar")
|
65
65
|
end
|
66
66
|
|
67
|
-
it
|
68
|
-
expect(parser.comma).to parse(
|
69
|
-
expect(parser.comma).to parse(
|
70
|
-
expect(parser.comma).not_to parse(
|
67
|
+
it 'comma' do
|
68
|
+
expect(parser.comma).to parse(',')
|
69
|
+
expect(parser.comma).to parse(', ')
|
70
|
+
expect(parser.comma).not_to parse(' , ')
|
71
71
|
end
|
72
72
|
|
73
|
-
it
|
74
|
-
expect(parser.lparen).to parse(
|
75
|
-
expect(parser.lparen).to parse(
|
76
|
-
expect(parser.lparen).not_to parse(
|
73
|
+
it 'lparen' do
|
74
|
+
expect(parser.lparen).to parse('(')
|
75
|
+
expect(parser.lparen).to parse('( ')
|
76
|
+
expect(parser.lparen).not_to parse(' (')
|
77
77
|
end
|
78
78
|
|
79
|
-
it
|
80
|
-
expect(parser.rparen).to parse(
|
81
|
-
expect(parser.rparen).to parse(
|
82
|
-
expect(parser.rparen).not_to parse(
|
79
|
+
it 'rparen' do
|
80
|
+
expect(parser.rparen).to parse(')')
|
81
|
+
expect(parser.rparen).to parse(') ')
|
82
|
+
expect(parser.rparen).not_to parse(' )')
|
83
83
|
end
|
84
84
|
|
85
|
-
it
|
86
|
-
expect(parser.boolean).to parse(
|
87
|
-
expect(parser.boolean).to parse(
|
88
|
-
expect(parser.boolean).not_to parse(
|
85
|
+
it 'boolean' do
|
86
|
+
expect(parser.boolean).to parse('true')
|
87
|
+
expect(parser.boolean).to parse('false')
|
88
|
+
expect(parser.boolean).not_to parse('false ')
|
89
89
|
end
|
90
90
|
|
91
|
-
it
|
92
|
-
expect(parser.datetime).to parse(
|
91
|
+
it 'datetime' do
|
92
|
+
expect(parser.datetime).to parse('2014-02-28T12:01:02Z')
|
93
93
|
end
|
94
94
|
|
95
|
-
it
|
95
|
+
it 'string' do
|
96
96
|
expect(parser.string).to parse("'foobar'")
|
97
97
|
expect(parser.string).to parse("'foo bar'")
|
98
98
|
expect(parser.string).not_to parse("'foo bar")
|
99
99
|
expect(parser.string).not_to parse('"foobar"')
|
100
100
|
end
|
101
101
|
|
102
|
-
it
|
102
|
+
it 'const' do
|
103
103
|
expect(parser.const).to parse("'foobar'")
|
104
|
-
expect(parser.const).to parse(
|
105
|
-
expect(parser.const).to parse(
|
106
|
-
expect(parser.const).to parse(
|
107
|
-
expect(parser.const).to parse(
|
108
|
-
expect(parser.const).not_to parse(
|
104
|
+
expect(parser.const).to parse('1')
|
105
|
+
expect(parser.const).to parse('1.1')
|
106
|
+
expect(parser.const).to parse('true')
|
107
|
+
expect(parser.const).to parse('2014-02-28T12:01:02Z')
|
108
|
+
expect(parser.const).not_to parse('(')
|
109
109
|
expect(parser.const).not_to parse(',')
|
110
110
|
end
|
111
111
|
|
112
|
-
it
|
113
|
-
expect(parser.identifier).to parse(
|
114
|
-
expect(parser.identifier).not_to parse(
|
115
|
-
expect(parser.identifier).to parse(
|
116
|
-
expect(parser.identifier).to parse(
|
117
|
-
expect(parser.identifier).to parse(
|
118
|
-
expect(parser.identifier).to parse(
|
119
|
-
expect(parser.identifier).not_to parse(
|
112
|
+
it 'identifier' do
|
113
|
+
expect(parser.identifier).to parse('foobar')
|
114
|
+
expect(parser.identifier).not_to parse('foo bar')
|
115
|
+
expect(parser.identifier).to parse('a')
|
116
|
+
expect(parser.identifier).to parse('aB')
|
117
|
+
expect(parser.identifier).to parse('A1')
|
118
|
+
expect(parser.identifier).to parse('A1_2')
|
119
|
+
expect(parser.identifier).not_to parse('A B')
|
120
120
|
end
|
121
121
|
|
122
|
-
it
|
123
|
-
expect(parser.current_timestamp).to parse(
|
122
|
+
it 'current_timestamp' do
|
123
|
+
expect(parser.current_timestamp).to parse('current timestamp')
|
124
124
|
end
|
125
125
|
|
126
126
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative '../../../spec/spec_helper'
|
2
2
|
|
3
3
|
class DummyParser < Parslet::Parser
|
4
4
|
include DDLParser::SharedRules::DataTypes
|
@@ -7,19 +7,19 @@ end
|
|
7
7
|
describe DDLParser::SharedRules::DataTypes do
|
8
8
|
let(:parser) { DummyParser.new }
|
9
9
|
|
10
|
-
it
|
11
|
-
parser.data_type.parse(
|
12
|
-
parser.data_type.parse(
|
13
|
-
parser.data_type.parse(
|
14
|
-
parser.data_type.parse(
|
15
|
-
parser.data_type.parse(
|
16
|
-
parser.data_type.parse(
|
17
|
-
parser.data_type.parse(
|
18
|
-
parser.data_type.parse(
|
19
|
-
parser.data_type.parse(
|
20
|
-
parser.data_type.parse(
|
21
|
-
parser.data_type.parse(
|
22
|
-
parser.data_type.parse(
|
10
|
+
it 'parses data types' do
|
11
|
+
parser.data_type.parse('smallint').should == {:data_type=> 'smallint'}
|
12
|
+
parser.data_type.parse('int').should == {:data_type=> 'int'}
|
13
|
+
parser.data_type.parse('decimal(1,2)').should == {:data_type=>{:decimal=>{:precision => {:total=>{:integer=> '1'}, :scale=>{:integer=> '2'}}}}}
|
14
|
+
parser.data_type.parse('float(1)').should == {:data_type=>{:float=>{:precision=>{:integer=> '1'}}}}
|
15
|
+
parser.data_type.parse('real').should == {:data_type=> 'real'}
|
16
|
+
parser.data_type.parse('double').should == {:data_type=> 'double'}
|
17
|
+
parser.data_type.parse('char(1)').should == {:data_type=>{:char=>{:length=>{:integer=> '1'}}}}
|
18
|
+
parser.data_type.parse('varchar(1)').should == {:data_type=>{:varchar=>{:length=>{:integer=> '1'}}}}
|
19
|
+
parser.data_type.parse('clob(50000)').should == {:data_type=>{:clob=>{:length=>{:integer=> '50000'}}}}
|
20
|
+
parser.data_type.parse('date').should == {:data_type=> 'date'}
|
21
|
+
parser.data_type.parse('time').should == {:data_type=> 'time'}
|
22
|
+
parser.data_type.parse('timestamp').should == {:data_type=> 'timestamp'}
|
23
23
|
end
|
24
24
|
|
25
25
|
|
@@ -1,38 +1,38 @@
|
|
1
|
-
|
1
|
+
require_relative '../../../../spec/spec_helper'
|
2
2
|
|
3
3
|
describe DDLParser::SQL::DB2::SelectParser do
|
4
4
|
let(:parser) { DDLParser::SQL::DB2::SelectParser.new }
|
5
5
|
|
6
|
-
context
|
6
|
+
context 'value parsing' do
|
7
7
|
|
8
|
-
it
|
9
|
-
expect(parser.const).to parse(
|
10
|
-
expect(parser.const).to parse(
|
11
|
-
expect(parser.const).to parse(
|
12
|
-
expect(parser.const).to parse(
|
13
|
-
expect(parser.const).to parse(
|
8
|
+
it 'parses integers' do
|
9
|
+
expect(parser.const).to parse('1')
|
10
|
+
expect(parser.const).to parse('-123')
|
11
|
+
expect(parser.const).to parse('120381')
|
12
|
+
expect(parser.const).to parse('181')
|
13
|
+
expect(parser.const).to parse('0181')
|
14
14
|
end
|
15
15
|
|
16
|
-
it
|
17
|
-
expect(parser.const).to parse(
|
18
|
-
expect(parser.const).to parse(
|
19
|
-
expect(parser.const).to parse(
|
20
|
-
expect(parser.const).to_not parse(
|
16
|
+
it 'parses floats' do
|
17
|
+
expect(parser.const).to parse('0.1')
|
18
|
+
expect(parser.const).to parse('3.14159')
|
19
|
+
expect(parser.const).to parse('-0.00001')
|
20
|
+
expect(parser.const).to_not parse('.1')
|
21
21
|
end
|
22
22
|
|
23
|
-
it
|
24
|
-
expect(parser.const).to parse(
|
25
|
-
expect(parser.const).to parse(
|
26
|
-
expect(parser.const).to_not parse(
|
23
|
+
it 'parses booleans' do
|
24
|
+
expect(parser.const).to parse('true')
|
25
|
+
expect(parser.const).to parse('false')
|
26
|
+
expect(parser.const).to_not parse('truefalse')
|
27
27
|
end
|
28
28
|
|
29
|
-
it
|
30
|
-
expect(parser.const).to parse(
|
31
|
-
expect(parser.const).to parse(
|
32
|
-
expect(parser.const).to_not parse(
|
29
|
+
it 'parses datetimes' do
|
30
|
+
expect(parser.const).to parse('1979-05-27T07:32:00Z')
|
31
|
+
expect(parser.const).to parse('2013-02-24T17:26:21Z')
|
32
|
+
expect(parser.const).to_not parse('1979l05-27 07:32:00')
|
33
33
|
end
|
34
34
|
|
35
|
-
it
|
35
|
+
it 'parses strings' do
|
36
36
|
expect(parser.const).to parse("''")
|
37
37
|
expect(parser.const).to parse("'hello world'")
|
38
38
|
expect(parser.const).to parse("'120.0, ~!@#$\%^&*+_\}{ asdfasf'")
|
@@ -41,74 +41,74 @@ describe DDLParser::SQL::DB2::SelectParser do
|
|
41
41
|
|
42
42
|
end
|
43
43
|
|
44
|
-
context
|
45
|
-
it
|
44
|
+
context 'namelist parsing' do
|
45
|
+
it 'simple' do
|
46
46
|
expect(parser.namelist).to parse('a,b,c')
|
47
47
|
expect(parser.namelist).to parse('a, b, C')
|
48
48
|
end
|
49
49
|
|
50
|
-
it
|
50
|
+
it 'not parse invalid' do
|
51
51
|
expect(parser.namelist).not_to parse('a b')
|
52
52
|
expect(parser.namelist).not_to parse('a: b')
|
53
|
-
expect(parser.namelist).not_to parse(
|
53
|
+
expect(parser.namelist).not_to parse('a; b')
|
54
54
|
expect(parser.namelist).not_to parse("a, b, 'foo'" )
|
55
|
-
expect(parser.namelist).not_to parse(
|
55
|
+
expect(parser.namelist).not_to parse('a, b, max(c)')
|
56
56
|
end
|
57
57
|
|
58
58
|
end
|
59
59
|
|
60
|
-
context
|
61
|
-
it
|
60
|
+
context 'arglist parsing' do
|
61
|
+
it 'simple' do
|
62
62
|
expect(parser.arglist).to parse('a,b,c')
|
63
63
|
expect(parser.arglist).to parse('a, b, c')
|
64
64
|
expect(parser.arglist).to parse("a, b, 'foo'" )
|
65
|
-
expect(parser.arglist).to parse(
|
65
|
+
expect(parser.arglist).to parse('a, b, max(c)')
|
66
66
|
end
|
67
67
|
|
68
|
-
it
|
68
|
+
it 'not parse invalid' do
|
69
69
|
expect(parser.arglist).not_to parse('a b')
|
70
70
|
expect(parser.arglist).not_to parse('a: b')
|
71
|
-
expect(parser.arglist).not_to parse(
|
71
|
+
expect(parser.arglist).not_to parse('a; b')
|
72
72
|
end
|
73
73
|
|
74
74
|
end
|
75
75
|
|
76
|
-
context
|
77
|
-
it
|
78
|
-
expect(parser.single_cond).to parse(
|
79
|
-
expect(parser.single_cond).to parse(
|
80
|
-
expect(parser.single_cond.parse(
|
76
|
+
context 'between parsing' do
|
77
|
+
it 'should parse between' do
|
78
|
+
expect(parser.single_cond).to parse('a between 1 and 2')
|
79
|
+
expect(parser.single_cond).to parse('a between 1 and 2')
|
80
|
+
expect(parser.single_cond.parse('a between 1 and 2')).to eq(:lhs=> 'a', :op=> 'between', :rhs=>{:btw_from=>{:integer=> '1'}, :btw_to=>{:integer=> '2'}})
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
|
-
context
|
85
|
-
it
|
84
|
+
context 'like parsing' do
|
85
|
+
it 'should parse' do
|
86
86
|
expect(parser.single_cond).to parse("a like '%foo%bar'")
|
87
87
|
end
|
88
88
|
|
89
89
|
end
|
90
90
|
|
91
|
-
context
|
92
|
-
it
|
93
|
-
expect(parser.condition).to parse(
|
94
|
-
expect(parser.condition).to parse(
|
95
|
-
expect(parser.condition).to parse(
|
96
|
-
expect(parser.condition).to parse(
|
97
|
-
expect(parser.condition).to parse(
|
91
|
+
context 'condition parsing' do
|
92
|
+
it 'should parse single' do
|
93
|
+
expect(parser.condition).to parse('a = a')
|
94
|
+
expect(parser.condition).to parse('a=a')
|
95
|
+
expect(parser.condition).to parse('a > a')
|
96
|
+
expect(parser.condition).to parse('a < a')
|
97
|
+
expect(parser.condition).to parse('a between 1 and 2')
|
98
98
|
expect(parser.condition).to parse("a like '%foo%bar'")
|
99
99
|
end
|
100
100
|
|
101
|
-
it
|
102
|
-
expect(parser.condition).to parse(
|
103
|
-
expect(parser.condition).to parse(
|
101
|
+
it 'should parse multible' do
|
102
|
+
expect(parser.condition).to parse('a = a or b = b')
|
103
|
+
expect(parser.condition).to parse('a = a and b = b')
|
104
104
|
expect(parser.condition).to parse("a > a and a between 'foo' and 'bar'")
|
105
105
|
expect(parser.condition).to parse("a < a and a like '%foo%bar'")
|
106
106
|
end
|
107
107
|
|
108
108
|
end
|
109
109
|
|
110
|
-
context
|
111
|
-
it
|
110
|
+
context 'select statements' do
|
111
|
+
it 'parse simple statements' do
|
112
112
|
[
|
113
113
|
'select a from b',
|
114
114
|
'select a, b from comme',
|
@@ -121,7 +121,7 @@ describe DDLParser::SQL::DB2::SelectParser do
|
|
121
121
|
end
|
122
122
|
end
|
123
123
|
|
124
|
-
it
|
124
|
+
it 'parse statements with where' do
|
125
125
|
[
|
126
126
|
'select a from b where a > 20',
|
127
127
|
'select a,b from c where a = 20',
|
@@ -134,7 +134,7 @@ describe DDLParser::SQL::DB2::SelectParser do
|
|
134
134
|
end
|
135
135
|
end
|
136
136
|
|
137
|
-
it
|
137
|
+
it 'parse statements with group by' do
|
138
138
|
[
|
139
139
|
'select a from b group by c',
|
140
140
|
'select a from b where a > 345 group by c',
|
@@ -144,7 +144,7 @@ describe DDLParser::SQL::DB2::SelectParser do
|
|
144
144
|
end
|
145
145
|
end
|
146
146
|
|
147
|
-
it
|
147
|
+
it 'not to parse bad selects' do
|
148
148
|
[
|
149
149
|
'select',
|
150
150
|
'select a, b from c where a = "120.0, ~!@#$%^&*+_\}{\" asdfa"sf"',
|
@@ -155,10 +155,10 @@ describe DDLParser::SQL::DB2::SelectParser do
|
|
155
155
|
|
156
156
|
end
|
157
157
|
|
158
|
-
context
|
159
|
-
it
|
160
|
-
result = parser.parse(
|
161
|
-
|
158
|
+
context 'extract' do
|
159
|
+
it 'should fetch select' do
|
160
|
+
result = parser.parse('select a from b where a = b')
|
161
|
+
result[:select].should == {:item=> 'a'}
|
162
162
|
end
|
163
163
|
end
|
164
164
|
|
data/spec/spec_helper.rb
CHANGED
@@ -3,9 +3,9 @@ RSpec.configure do |config|
|
|
3
3
|
config.run_all_when_everything_filtered = true
|
4
4
|
config.filter_run :focus
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
config.expect_with :rspec do |c|
|
7
|
+
c.syntax = [:expect, :should]
|
8
|
+
end
|
9
9
|
|
10
10
|
# Run specs in random order to surface order dependencies. If you find an
|
11
11
|
# order dependency and want to debug it, you can fix the order by providing
|
@@ -14,9 +14,9 @@ RSpec.configure do |config|
|
|
14
14
|
config.order = 'random'
|
15
15
|
end
|
16
16
|
|
17
|
-
require
|
18
|
-
require
|
19
|
-
require
|
17
|
+
require 'parslet/rig/rspec'
|
18
|
+
require 'ddl_parser'
|
19
|
+
require 'yaml'
|
20
20
|
|
21
21
|
def fixture(filename)
|
22
22
|
File.read("spec/fixtures/#{filename}")
|