ddl_parser 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Vagrantfile +9 -0
- data/lib/ddl_parser/ddl/db2/parser.rb +112 -112
- data/lib/ddl_parser/translator/column.rb +132 -99
- data/lib/ddl_parser/version.rb +1 -1
- data/spec/ddl_parser/ddl/db2/create_table_spec.rb +518 -506
- data/spec/ddl_parser/translator/column_spec.rb +110 -99
- metadata +3 -2
@@ -1,100 +1,111 @@
|
|
1
|
-
require_relative '../../../spec/spec_helper'
|
2
|
-
require_relative '../../../lib/ddl_parser/translator/column'
|
3
|
-
|
4
|
-
describe 'DDLParser::Translator::Column' do
|
5
|
-
|
6
|
-
let(:
|
7
|
-
DDLParser::Translator::Column.new({:field=> '
|
8
|
-
}
|
9
|
-
|
10
|
-
let(:
|
11
|
-
DDLParser::Translator::Column.new(
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
1
|
+
require_relative '../../../spec/spec_helper'
|
2
|
+
require_relative '../../../lib/ddl_parser/translator/column'
|
3
|
+
|
4
|
+
describe 'DDLParser::Translator::Column' do
|
5
|
+
|
6
|
+
let(:unique_no_column) {
|
7
|
+
DDLParser::Translator::Column.new({:field=> 'unique_no', :data_type=> 'integer', :options=>[{:column_option=> 'identity'}, {:identity=>{:start_value=>{:integer=> '1'}, :increment_value=>{:integer=> '1'}, :cache_value=>{:integer=> '20'}}}]})
|
8
|
+
}
|
9
|
+
|
10
|
+
let(:int_column) {
|
11
|
+
DDLParser::Translator::Column.new({:field=> 'int_field', :data_type=> 'int', :options=> ''})
|
12
|
+
}
|
13
|
+
|
14
|
+
let(:char_column) {
|
15
|
+
DDLParser::Translator::Column.new(
|
16
|
+
{:field=> 'char_field',
|
17
|
+
:data_type=>{:char=>{:length=>{:integer=> '4'}}},
|
18
|
+
:options=> [{:default_clause=>[{:string => "'foobar'"}]}]}
|
19
|
+
)
|
20
|
+
}
|
21
|
+
|
22
|
+
let(:decimal_column) {
|
23
|
+
DDLParser::Translator::Column.new(
|
24
|
+
{:field=> 'decimal_field',
|
25
|
+
:data_type=>{:decimal=>{:precision=>{:total=>{:integer=> '15'}, :scale=>{:integer=> '2'}}}},
|
26
|
+
:options=>[{:column_option=> 'not null'}, {:default_clause=>[{:integer=> '0'}]}]
|
27
|
+
})
|
28
|
+
}
|
29
|
+
|
30
|
+
let(:decimal_no_scale_column) {
|
31
|
+
DDLParser::Translator::Column.new(
|
32
|
+
{:field=> 'decimal_field',
|
33
|
+
:data_type=>{:decimal=>{:precision=>{:total=>{:integer=> '15'}}}},
|
34
|
+
:options=>[{:column_option=> 'not null'}, {:default_clause=>[{:integer=> '0'}]}]
|
35
|
+
})
|
36
|
+
}
|
37
|
+
|
38
|
+
let(:decimal_no_precision_column) {
|
39
|
+
DDLParser::Translator::Column.new(
|
40
|
+
{:field=> 'decimal_field',
|
41
|
+
:data_type=>{:decimal=>"decimal"},
|
42
|
+
:options=>[{:column_option=> 'not null'}, {:default_clause=>[{:integer=> '0'}]}]
|
43
|
+
})
|
44
|
+
}
|
45
|
+
|
46
|
+
it 'must receive hash' do
|
47
|
+
DDLParser::Translator::Column.new('').to_hash.should == {}
|
48
|
+
DDLParser::Translator::Column.new({:foo => :bar}).to_hash.should == {:foo => :bar}
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should return name' do
|
52
|
+
int_column.name.should == 'int_field'
|
53
|
+
char_column.name.should == 'char_field'
|
54
|
+
decimal_column.name.should == 'decimal_field'
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should return data_type' do
|
58
|
+
int_column.data_type.should == :int
|
59
|
+
char_column.data_type.should == :char
|
60
|
+
decimal_column.data_type.should == :decimal
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should return length' do
|
64
|
+
int_column.length.should == nil
|
65
|
+
char_column.length.should == 4
|
66
|
+
decimal_column.length.should == 15.2
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should return precision' do
|
70
|
+
int_column.precision.should == nil
|
71
|
+
char_column.precision.should == nil
|
72
|
+
decimal_column.precision.should == 15
|
73
|
+
decimal_no_scale_column.precision.should == 15
|
74
|
+
decimal_no_precision_column.precision.should == 5
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'should return scale' do
|
78
|
+
int_column.scale.should == nil
|
79
|
+
char_column.scale.should == nil
|
80
|
+
decimal_column.scale.should == 2
|
81
|
+
decimal_no_scale_column.scale.should == 0
|
82
|
+
decimal_no_precision_column.scale.should == 0
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'should return options' do
|
86
|
+
int_column.options.should == nil
|
87
|
+
char_column.options.should == [{:default_clause=>[{:string =>"'foobar'"}]}]
|
88
|
+
decimal_column.options.should == [{:column_option=> 'not null'}, {:default_clause=>[{:integer=> '0'}]}]
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should return not null' do
|
92
|
+
int_column.not_null.should == false
|
93
|
+
char_column.not_null.should == false
|
94
|
+
decimal_column.not_null.should == true
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'should return default clause' do
|
98
|
+
int_column.default_clause.should == nil
|
99
|
+
char_column.default_clause.should == "'foobar'"
|
100
|
+
decimal_column.default_clause.should == 0
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'should return identity flag' do
|
104
|
+
unique_no_column.identity?.should == true
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'should return start value for identity' do
|
108
|
+
unique_no_column.start_value?.should == 1
|
109
|
+
end
|
110
|
+
|
100
111
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ddl_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-09-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: parslet
|
@@ -88,6 +88,7 @@ files:
|
|
88
88
|
- LICENSE.txt
|
89
89
|
- README.md
|
90
90
|
- Rakefile
|
91
|
+
- Vagrantfile
|
91
92
|
- ddl_parser.gemspec
|
92
93
|
- lib/ddl_parser.rb
|
93
94
|
- lib/ddl_parser/ddl.rb
|