piggly 1.2.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +163 -0
- data/Rakefile +29 -15
- data/bin/piggly +4 -244
- data/lib/piggly.rb +19 -17
- data/lib/piggly/command.rb +9 -0
- data/lib/piggly/command/base.rb +148 -0
- data/lib/piggly/command/report.rb +162 -0
- data/lib/piggly/command/test.rb +157 -0
- data/lib/piggly/command/trace.rb +90 -0
- data/lib/piggly/command/untrace.rb +78 -0
- data/lib/piggly/compiler.rb +7 -5
- data/lib/piggly/compiler/cache_dir.rb +119 -0
- data/lib/piggly/compiler/coverage_report.rb +63 -0
- data/lib/piggly/compiler/trace_compiler.rb +105 -0
- data/lib/piggly/config.rb +47 -22
- data/lib/piggly/dumper.rb +9 -0
- data/lib/piggly/dumper/index.rb +121 -0
- data/lib/piggly/dumper/qualified_name.rb +36 -0
- data/lib/piggly/dumper/qualified_type.rb +81 -0
- data/lib/piggly/dumper/reified_procedure.rb +142 -0
- data/lib/piggly/dumper/skeleton_procedure.rb +102 -0
- data/lib/piggly/installer.rb +84 -42
- data/lib/piggly/parser.rb +43 -49
- data/lib/piggly/parser/grammar.tt +289 -313
- data/lib/piggly/parser/nodes.rb +270 -211
- data/lib/piggly/parser/traversal.rb +35 -33
- data/lib/piggly/parser/treetop_ruby19_patch.rb +1 -1
- data/lib/piggly/profile.rb +81 -60
- data/lib/piggly/reporter.rb +5 -18
- data/lib/piggly/reporter/base.rb +103 -0
- data/lib/piggly/reporter/html_dsl.rb +63 -0
- data/lib/piggly/reporter/index.rb +108 -0
- data/lib/piggly/reporter/procedure.rb +104 -0
- data/lib/piggly/reporter/resources/highlight.js +21 -0
- data/lib/piggly/reporter/{piggly.css → resources/piggly.css} +52 -12
- data/lib/piggly/reporter/{sortable.js → resources/sortable.js} +0 -0
- data/lib/piggly/tags.rb +280 -0
- data/lib/piggly/task.rb +191 -40
- data/lib/piggly/util.rb +8 -27
- data/lib/piggly/util/blankslate.rb +114 -0
- data/lib/piggly/util/cacheable.rb +19 -0
- data/lib/piggly/util/enumerable.rb +44 -0
- data/lib/piggly/util/file.rb +17 -0
- data/lib/piggly/util/process_queue.rb +96 -0
- data/lib/piggly/util/thunk.rb +39 -0
- data/lib/piggly/version.rb +8 -8
- data/spec/examples/compiler/cacheable_spec.rb +190 -0
- data/spec/examples/compiler/report_spec.rb +25 -0
- data/spec/{compiler → examples/compiler}/trace_spec.rb +7 -57
- data/spec/examples/config_spec.rb +61 -0
- data/spec/examples/dumper/index_spec.rb +197 -0
- data/spec/examples/dumper/procedure_spec.rb +116 -0
- data/spec/{grammar → examples/grammar}/expression_spec.rb +60 -60
- data/spec/{grammar → examples/grammar}/statements/assignment_spec.rb +15 -15
- data/spec/examples/grammar/statements/declaration_spec.rb +21 -0
- data/spec/{grammar → examples/grammar}/statements/exception_spec.rb +10 -10
- data/spec/{grammar → examples/grammar}/statements/if_spec.rb +47 -34
- data/spec/{grammar → examples/grammar}/statements/loop_spec.rb +5 -5
- data/spec/{grammar → examples/grammar}/statements/sql_spec.rb +11 -11
- data/spec/{grammar → examples/grammar}/tokens/comment_spec.rb +11 -11
- data/spec/{grammar → examples/grammar}/tokens/datatype_spec.rb +14 -8
- data/spec/{grammar → examples/grammar}/tokens/identifier_spec.rb +26 -10
- data/spec/{grammar → examples/grammar}/tokens/keyword_spec.rb +5 -5
- data/spec/{grammar → examples/grammar}/tokens/label_spec.rb +7 -7
- data/spec/{grammar → examples/grammar}/tokens/literal_spec.rb +1 -1
- data/spec/examples/grammar/tokens/lval_spec.rb +50 -0
- data/spec/{grammar → examples/grammar}/tokens/number_spec.rb +1 -1
- data/spec/{grammar → examples/grammar}/tokens/sqlkeywords_spec.rb +1 -1
- data/spec/{grammar → examples/grammar}/tokens/string_spec.rb +9 -9
- data/spec/{grammar → examples/grammar}/tokens/whitespace_spec.rb +1 -1
- data/spec/examples/installer_spec.rb +59 -0
- data/spec/examples/parser/nodes_spec.rb +73 -0
- data/spec/examples/parser/traversal_spec.rb +14 -0
- data/spec/examples/parser_spec.rb +115 -0
- data/spec/examples/profile_spec.rb +153 -0
- data/spec/{reporter/html_spec.rb → examples/reporter/html/dsl_spec.rb} +0 -0
- data/spec/examples/reporter/html/index_spec.rb +0 -0
- data/spec/examples/reporter/html_spec.rb +1 -0
- data/spec/examples/reporter_spec.rb +0 -0
- data/spec/{compiler → examples}/tags_spec.rb +10 -10
- data/spec/examples/task_spec.rb +0 -0
- data/spec/examples/util/cacheable_spec.rb +41 -0
- data/spec/examples/util/enumerable_spec.rb +64 -0
- data/spec/examples/util/file_spec.rb +40 -0
- data/spec/examples/util/process_queue_spec.rb +16 -0
- data/spec/examples/util/thunk_spec.rb +58 -0
- data/spec/examples/version_spec.rb +0 -0
- data/spec/issues/007_spec.rb +25 -0
- data/spec/issues/008_spec.rb +73 -0
- data/spec/issues/018_spec.rb +25 -0
- data/spec/spec_helper.rb +253 -9
- metadata +136 -93
- data/README.markdown +0 -116
- data/lib/piggly/compiler/cache.rb +0 -151
- data/lib/piggly/compiler/pretty.rb +0 -67
- data/lib/piggly/compiler/queue.rb +0 -46
- data/lib/piggly/compiler/tags.rb +0 -244
- data/lib/piggly/compiler/trace.rb +0 -91
- data/lib/piggly/filecache.rb +0 -40
- data/lib/piggly/parser/parser.rb +0 -11794
- data/lib/piggly/reporter/html.rb +0 -207
- data/spec/compiler/cache_spec.rb +0 -9
- data/spec/compiler/pretty_spec.rb +0 -9
- data/spec/compiler/queue_spec.rb +0 -3
- data/spec/compiler/rewrite_spec.rb +0 -3
- data/spec/config_spec.rb +0 -58
- data/spec/filecache_spec.rb +0 -70
- data/spec/fixtures/snippets.sql +0 -158
- data/spec/grammar/tokens/lval_spec.rb +0 -50
- data/spec/parser_spec.rb +0 -8
- data/spec/profile_spec.rb +0 -5
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
module Piggly
|
4
4
|
|
@@ -6,13 +6,13 @@ module Piggly
|
|
6
6
|
include GrammarHelper
|
7
7
|
|
8
8
|
describe "assignment statements" do
|
9
|
-
it "
|
9
|
+
it "parse successfully" do
|
10
10
|
node = parse(:statement, "a := 10;")
|
11
|
-
node.should
|
12
|
-
node.count{|e| e.
|
13
|
-
|
14
|
-
node.find{|e| e.named? :lval }.should be_a(Assignable)
|
15
|
-
node.find{|e| e.named? :rval }.should
|
11
|
+
node.should be_statement
|
12
|
+
node.count{|e| e.assignment? }.should == 1
|
13
|
+
|
14
|
+
node.find{|e| e.named? :lval }.should be_a(Parser::Nodes::Assignable)
|
15
|
+
node.find{|e| e.named? :rval }.should be_expression
|
16
16
|
end
|
17
17
|
|
18
18
|
it "must end with a semicolon" do
|
@@ -22,18 +22,18 @@ module Piggly
|
|
22
22
|
|
23
23
|
it "can use := or =" do
|
24
24
|
a = parse(:statement, "a := 10;")
|
25
|
-
a.should
|
26
|
-
a.count{|e| e.
|
25
|
+
a.should be_statement
|
26
|
+
a.count{|e| e.assignment? }.should == 1
|
27
27
|
|
28
28
|
b = parse(:statement, "a = 10;")
|
29
|
-
b.should
|
30
|
-
b.count{|e| e.
|
29
|
+
b.should be_statement
|
30
|
+
b.count{|e| e.assignment? }.should == 1
|
31
31
|
end
|
32
32
|
|
33
33
|
it "can assign strings" do
|
34
34
|
node = parse(:statement, "a := 'string';")
|
35
35
|
rval = node.find{|e| e.named? :rval }
|
36
|
-
rval.count{|e| e.
|
36
|
+
rval.count{|e| e.string? }.should == 1
|
37
37
|
end
|
38
38
|
|
39
39
|
it "can assign value expressions containing comments" do
|
@@ -42,14 +42,14 @@ module Piggly
|
|
42
42
|
'a := 10 /* comment */ + 10;'].test_each do |s|
|
43
43
|
node = parse(:statement, s)
|
44
44
|
rval = node.find{|e| e.named? :rval }
|
45
|
-
rval.count{|e| e.
|
45
|
+
rval.count{|e| e.comment? }.should == 1
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
49
|
it "can assign value expressions containing strings" do
|
50
50
|
node = parse(:statement, "a := 'Hello,' || space || 'world';")
|
51
51
|
rval = node.find{|e| e.named? :rval }
|
52
|
-
rval.count{|e| e.
|
52
|
+
rval.count{|e| e.string? }.should == 2
|
53
53
|
end
|
54
54
|
|
55
55
|
it "can assign value expressions containing comments and strings" do
|
@@ -62,7 +62,7 @@ module Piggly
|
|
62
62
|
GROUP BY /* pk ; 'abc' */ fk);
|
63
63
|
SQL
|
64
64
|
rval = node.find{|e| e.named? :rval }
|
65
|
-
rval.count{|e| e.
|
65
|
+
rval.count{|e| e.string? }.should == 2
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Piggly
|
4
|
+
|
5
|
+
describe Parser, "statements" do
|
6
|
+
include GrammarHelper
|
7
|
+
|
8
|
+
describe "single variable declarations" do
|
9
|
+
it "parse successfully" do
|
10
|
+
node = parse(:stmtDeclare, "declare t text;")
|
11
|
+
node.count{|e| e.identifier? }.should == 1
|
12
|
+
node.count{|e| e.datatype? }.should == 1
|
13
|
+
end
|
14
|
+
|
15
|
+
it "allows an initial assignment" do
|
16
|
+
node = parse(:stmtDeclare, "declare a text := 10;")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
module Piggly
|
4
4
|
describe Parser, "control structures" do
|
@@ -8,21 +8,21 @@ module Piggly
|
|
8
8
|
describe "raise" do
|
9
9
|
it "parses successfully" do
|
10
10
|
node, rest = parse_some(:statement, "RAISE EXCEPTION 'message';")
|
11
|
-
node.should
|
11
|
+
node.should be_statement
|
12
12
|
rest.should == ''
|
13
13
|
end
|
14
14
|
|
15
15
|
it "handles exception" do
|
16
16
|
node = parse(:statement, "RAISE EXCEPTION 'message';")
|
17
|
-
node.count{|e| e.is_a?(Throw) }.should == 1
|
18
|
-
node.count{|e| e.is_a?(Raise) }.should == 0
|
17
|
+
node.count{|e| e.is_a?(Parser::Nodes::Throw) }.should == 1
|
18
|
+
node.count{|e| e.is_a?(Parser::Nodes::Raise) }.should == 0
|
19
19
|
end
|
20
20
|
|
21
21
|
it "handles events" do
|
22
22
|
%w(WARNING LOG INFO NOTICE DEBUG).each do |event|
|
23
23
|
node = parse(:statement, "RAISE #{event} 'message';")
|
24
|
-
node.count{|e| e.is_a?(Throw) }.should == 0
|
25
|
-
node.count{|e| e.is_a?(Raise) }.should == 1
|
24
|
+
node.count{|e| e.is_a?(Parser::Nodes::Throw) }.should == 0
|
25
|
+
node.count{|e| e.is_a?(Parser::Nodes::Raise) }.should == 1
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
@@ -34,17 +34,17 @@ module Piggly
|
|
34
34
|
|
35
35
|
it "parses successfully" do
|
36
36
|
node, rest = parse_some(:statement, @text)
|
37
|
-
node.should
|
37
|
+
node.should be_statement
|
38
38
|
rest.should == ''
|
39
39
|
end
|
40
40
|
|
41
41
|
it "has Catch node" do
|
42
42
|
node = parse(:statement, @text)
|
43
|
-
catches = node.select{|e| e.is_a?(Catch) }
|
43
|
+
catches = node.select{|e| e.is_a?(Parser::Nodes::Catch) }
|
44
44
|
catches.size.should == 2
|
45
45
|
|
46
|
-
catches[0].count{|e| e.named?(:cond) and e.
|
47
|
-
catches[1].count{|e| e.named?(:cond) and e.
|
46
|
+
catches[0].count{|e| e.named?(:cond) and e.expression? }.should == 1
|
47
|
+
catches[1].count{|e| e.named?(:cond) and e.expression? }.should == 1
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
module Piggly
|
4
4
|
|
@@ -14,112 +14,125 @@ module Piggly
|
|
14
14
|
|
15
15
|
it "parses successfully" do
|
16
16
|
node, rest = parse_some(:statement, 'IF cond THEN a := 10; END IF;')
|
17
|
-
node.should
|
17
|
+
node.should be_statement
|
18
18
|
rest.should == ''
|
19
19
|
end
|
20
20
|
|
21
21
|
it "does not have an Else node" do
|
22
22
|
node = parse(:statement, 'IF cond THEN a := 10; END IF;')
|
23
|
-
node.count{|e| e.
|
23
|
+
node.count{|e| e.else? }.should == 0
|
24
24
|
node.count{|e| e.named?(:else) and not e.empty? }.should == 0
|
25
25
|
end
|
26
26
|
|
27
27
|
it "has a 'cond' Expression" do
|
28
28
|
node = parse(:statement, 'IF cond THEN a := 10; END IF;')
|
29
29
|
node.count{|e| e.named?(:cond) }.should == 1
|
30
|
-
node.find{|e| e.named?(:cond) }.should
|
30
|
+
node.find{|e| e.named?(:cond) }.should be_expression
|
31
31
|
end
|
32
32
|
|
33
33
|
it "can have missing body" do
|
34
34
|
node = parse(:statement, 'IF cond THEN END IF;')
|
35
|
-
node.
|
35
|
+
node.should be_statement
|
36
|
+
node.count{|e| e.if? }.should == 1
|
37
|
+
node.count{|e| e.named?(:cond) }.should == 1
|
36
38
|
end
|
37
39
|
|
38
40
|
it "can have comment body" do
|
39
41
|
node = parse(:statement, 'IF cond THEN /* removed */ END IF;')
|
40
|
-
node.
|
41
|
-
node.count{|e| e.
|
42
|
-
node.
|
42
|
+
node.should be_statement
|
43
|
+
node.count{|e| e.if? }.should == 1
|
44
|
+
node.count{|e| e.comment? }.should == 1
|
45
|
+
node.find{|e| e.comment? }.source_text.should == '/* removed */'
|
43
46
|
end
|
44
47
|
|
45
48
|
it "can have single statement body" do
|
46
49
|
node = parse(:statement, 'IF cond THEN a := 10; END IF;')
|
47
|
-
node.count{|e| e.
|
50
|
+
node.count{|e| e.if? }.should == 1
|
51
|
+
node.count{|e| e.assignment? }.should == 1
|
48
52
|
end
|
49
53
|
|
50
54
|
it "can have multiple statement body" do
|
51
55
|
node = parse(:statement, 'IF cond THEN a := 10; b := 10; END IF;')
|
52
|
-
node.count{|e| e.
|
56
|
+
node.count{|e| e.if? }.should == 1
|
57
|
+
node.count{|e| e.assignment? }.should == 2
|
53
58
|
end
|
54
59
|
|
55
60
|
it "can contain comments" do
|
56
61
|
node = parse(:statement, "IF cond /* comment */ THEN -- foo\n NULL; /* foo */ END IF;")
|
57
|
-
node.should
|
58
|
-
node.count{|e| e.
|
62
|
+
node.should be_statement
|
63
|
+
node.count{|e| e.comment? }.should == 3
|
59
64
|
end
|
60
65
|
end
|
61
66
|
|
62
67
|
describe "if .. then .. else .. end if" do
|
63
68
|
it "parses successfully" do
|
64
69
|
node, rest = parse_some(:statement, 'IF cond THEN a := 10; ELSE a := 20; END IF;')
|
65
|
-
node.should
|
70
|
+
node.should be_statement
|
66
71
|
rest.should == ''
|
67
72
|
end
|
68
73
|
|
69
74
|
it "has an Else node named 'else'" do
|
70
75
|
node = parse(:statement, 'IF cond THEN a := 10; ELSE a := 20; END IF;')
|
71
|
-
node.count{|e| e.named?(:else) and e.
|
76
|
+
node.count{|e| e.named?(:else) and e.else? }.should == 1
|
72
77
|
node.find{|e| e.named?(:else) }.source_text.should == 'ELSE a := 20; '
|
73
78
|
end
|
74
79
|
|
75
80
|
it "can have missing else body" do
|
76
81
|
node = parse(:statement, 'IF cond THEN a := 10; ELSE END IF;')
|
77
|
-
node.count{|e| e.
|
82
|
+
node.count{|e| e.if? }.should == 1
|
83
|
+
node.count{|e| e.assignment? }.should == 1
|
78
84
|
end
|
79
85
|
|
80
86
|
it "can have comment body" do
|
81
87
|
node = parse(:statement, 'IF cond THEN a := 10; ELSE /* removed */ END IF;')
|
82
|
-
node.count{|e| e.
|
83
|
-
node.count{|e| e.
|
88
|
+
node.count{|e| e.if? }.should == 1
|
89
|
+
node.count{|e| e.comment? }.should == 1
|
90
|
+
node.count{|e| e.assignment? }.should == 1
|
84
91
|
end
|
85
92
|
|
86
93
|
it "can have single statement body" do
|
87
94
|
node = parse(:statement, 'IF cond THEN a := 10; ELSE a := 20; END IF;')
|
88
|
-
node.count{|e| e.
|
95
|
+
node.count{|e| e.if? }.should == 1
|
96
|
+
node.count{|e| e.assignment? }.should == 2
|
89
97
|
end
|
90
98
|
|
91
99
|
it "can have multiple statement body" do
|
92
100
|
node = parse(:statement, 'IF cond THEN a := 10; ELSE a := 20; b := 30; END IF;')
|
93
|
-
node.count{|e| e.
|
101
|
+
node.count{|e| e.if? }.should == 1
|
102
|
+
node.count{|e| e.assignment? }.should == 3
|
94
103
|
end
|
95
104
|
end
|
96
105
|
|
97
106
|
describe "if .. then .. elsif .. then .. end if" do
|
98
107
|
it "parses successfully" do
|
99
108
|
node, rest = parse_some(:statement, 'IF cond THEN a := 10; ELSIF cond THEN a := 20; END IF;')
|
100
|
-
node.should
|
109
|
+
node.should be_statement
|
101
110
|
rest.should == ''
|
102
111
|
end
|
103
112
|
|
104
113
|
it "can have comment body" do
|
105
114
|
node = parse(:statement, 'IF cond THEN a := 10; ELSIF cond THEN /* removed */ END IF;')
|
106
|
-
node.count{|e| e.
|
107
|
-
node.count{|e| e.
|
115
|
+
node.count{|e| e.if? }.should == 2
|
116
|
+
node.count{|e| e.comment? }.should == 1
|
117
|
+
node.count{|e| e.assignment? }.should == 1
|
108
118
|
end
|
109
119
|
|
110
120
|
it "can having missing body" do
|
111
121
|
node = parse(:statement, 'IF cond THEN a := 10; ELSIF cond THEN END IF;')
|
112
|
-
node.count{|e| e.
|
122
|
+
node.count{|e| e.if? }.should == 2
|
123
|
+
node.count{|e| e.assignment? }.should == 1
|
113
124
|
end
|
114
125
|
|
115
126
|
it "can have single statement body" do
|
116
127
|
node = parse(:statement, 'IF cond THEN a := 10; ELSIF cond THEN a := 20; END IF;')
|
117
|
-
node.count{|e| e.
|
128
|
+
node.count{|e| e.if? }.should == 2
|
129
|
+
node.count{|e| e.assignment? }.should == 2
|
118
130
|
end
|
119
131
|
|
120
132
|
it "can have multiple statement body" do
|
121
133
|
node = parse(:statement, 'IF cond THEN a := 10; ELSIF cond THEN a := 20; b := 30; END IF;')
|
122
|
-
node.count{|e| e.
|
134
|
+
node.count{|e| e.if? }.should == 2
|
135
|
+
node.count{|e| e.assignment? }.should == 3
|
123
136
|
end
|
124
137
|
|
125
138
|
it "can have many elsif branches" do
|
@@ -134,13 +147,13 @@ module Piggly
|
|
134
147
|
SQL
|
135
148
|
|
136
149
|
node.count{|e| e.named?(:cond) }.should == 6
|
137
|
-
node.count{|e| e.
|
138
|
-
node.count{|e| e.
|
150
|
+
node.count{|e| e.if? }.should == 6
|
151
|
+
node.count{|e| e.if? and e.named?(:else) }.should == 5
|
139
152
|
end
|
140
153
|
|
141
154
|
it "has no Else nodes" do
|
142
155
|
node = parse(:statement, 'IF cond THEN a := 10; ELSIF cond THEN a := 20; END IF;')
|
143
|
-
node.count{|e| e.
|
156
|
+
node.count{|e| e.else? }.should == 0
|
144
157
|
end
|
145
158
|
end
|
146
159
|
|
@@ -151,25 +164,25 @@ module Piggly
|
|
151
164
|
|
152
165
|
it "parses successfully" do
|
153
166
|
node, rest = parse_some(:statement, @text)
|
154
|
-
node.should
|
167
|
+
node.should be_statement
|
155
168
|
rest.should == ''
|
156
169
|
end
|
157
170
|
|
158
171
|
it "has an If node named 'else'" do
|
159
172
|
node = parse(:statement, @text)
|
160
|
-
node.count{|e| e.named?(:else) and e.
|
161
|
-
node.find{|e| e.named?(:else) and e.
|
173
|
+
node.count{|e| e.named?(:else) and e.if? }.should == 1
|
174
|
+
node.find{|e| e.named?(:else) and e.if? }.source_text.should == 'ELSIF cond THEN a := 20; ELSE a := 30; '
|
162
175
|
end
|
163
176
|
|
164
177
|
it "has an Else node named 'else'" do
|
165
178
|
node = parse(:statement, @text)
|
166
|
-
node.count{|e| e.named?(:else) and e.
|
167
|
-
node.find{|e| e.named?(:else) and e.
|
179
|
+
node.count{|e| e.named?(:else) and e.else? }.should == 1
|
180
|
+
node.find{|e| e.named?(:else) and e.else? }.source_text.should == 'ELSE a := 30; '
|
168
181
|
end
|
169
182
|
|
170
183
|
it "has two If nodes" do
|
171
184
|
node = parse(:statement, @text)
|
172
|
-
node.count{|e| e.
|
185
|
+
node.count{|e| e.if? }.should == 2
|
173
186
|
end
|
174
187
|
end
|
175
188
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
module Piggly
|
4
4
|
describe Parser, "control structures" do
|
@@ -8,20 +8,20 @@ module Piggly
|
|
8
8
|
describe "for loops" do
|
9
9
|
it "can loop over integers" do
|
10
10
|
node = parse(:stmtForLoop, 'FOR x IN 0 .. 100 LOOP a := x; END LOOP;')
|
11
|
-
node.should
|
11
|
+
node.should be_statement
|
12
12
|
|
13
13
|
cond = node.find{|e| e.named?(:cond) }
|
14
14
|
cond.source_text.should == '0 .. 100 '
|
15
|
-
cond.should
|
15
|
+
cond.should be_expression
|
16
16
|
end
|
17
17
|
|
18
18
|
it "can loop over query results" do
|
19
19
|
node = parse(:stmtForLoop, 'FOR x IN SELECT * FROM table LOOP a := x; END LOOP;')
|
20
|
-
node.should
|
20
|
+
node.should be_statement
|
21
21
|
|
22
22
|
cond = node.find{|e| e.named?(:cond) }
|
23
23
|
cond.source_text.should == 'SELECT * FROM table '
|
24
|
-
cond.should
|
24
|
+
cond.should be_sql
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -1,15 +1,15 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
module Piggly
|
4
4
|
describe Parser, "statements" do
|
5
5
|
include GrammarHelper
|
6
6
|
|
7
7
|
describe "SQL statements" do
|
8
|
-
it "
|
8
|
+
it "parse successfully" do
|
9
9
|
node, rest = parse_some(:statement, 'SELECT id FROM users;')
|
10
|
-
node.should
|
11
|
-
node.count{|e| e.
|
12
|
-
node.find{|e| e.
|
10
|
+
node.should be_statement
|
11
|
+
node.count{|e| e.sql? }.should == 1
|
12
|
+
node.find{|e| e.sql? }.source_text.should == 'SELECT id FROM users;'
|
13
13
|
rest.should == ''
|
14
14
|
end
|
15
15
|
|
@@ -26,20 +26,20 @@ module Piggly
|
|
26
26
|
WHERE u.disabled -- can't login
|
27
27
|
AND u.id = 100;
|
28
28
|
SQL
|
29
|
-
sql = node.find{|e| e.
|
30
|
-
sql.count{|e| e.
|
29
|
+
sql = node.find{|e| e.sql? }
|
30
|
+
sql.count{|e| e.comment? }.should == 2
|
31
31
|
end
|
32
32
|
|
33
33
|
it "can be followed by comments" do
|
34
34
|
node, rest = parse_some(:statement, 'SELECT id FROM users; -- comment')
|
35
|
-
node.find{|e| e.
|
35
|
+
node.find{|e| e.sql? }.source_text == 'SELECT id FROM users;'
|
36
36
|
node.tail.source_text.should == ' -- comment'
|
37
37
|
rest.should == ''
|
38
38
|
end
|
39
39
|
|
40
40
|
it "can be followed by whitespace" do
|
41
41
|
node, rest = parse_some(:statement, "SELECT id FROM users; \n")
|
42
|
-
node.find{|e| e.
|
42
|
+
node.find{|e| e.sql? }.source_text == 'SELECT id FROM users;'
|
43
43
|
node.tail.source_text.should == " \n"
|
44
44
|
rest.should == ''
|
45
45
|
end
|
@@ -51,8 +51,8 @@ module Piggly
|
|
51
51
|
WHERE first_name ILIKE '%a%'
|
52
52
|
OR last_name ILIKE '%b%';
|
53
53
|
SQL
|
54
|
-
sql = node.find{|e| e.
|
55
|
-
sql.count{|e| e.
|
54
|
+
sql = node.find{|e| e.sql? }
|
55
|
+
sql.count{|e| e.string? }.should == 2
|
56
56
|
end
|
57
57
|
|
58
58
|
it "can contain strings and comments" do
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
module Piggly
|
4
4
|
describe Parser, "tokens" do
|
@@ -7,52 +7,52 @@ module Piggly
|
|
7
7
|
describe "comments" do
|
8
8
|
it "can begin with -- and terminate at EOF" do
|
9
9
|
GrammarHelper::COMMENTS.map{|s| "-- #{s}" }.test_each do |s|
|
10
|
-
parse(:tComment, s).should
|
10
|
+
parse(:tComment, s).should be_comment
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
14
|
it "can begin with -- and terminate at line ending" do
|
15
15
|
GrammarHelper::COMMENTS.map{|s| "-- #{s}\n" }.test_each do |s|
|
16
|
-
parse(:tComment, s).should
|
16
|
+
parse(:tComment, s).should be_comment
|
17
17
|
end
|
18
18
|
|
19
19
|
GrammarHelper::COMMENTS.map{|s| "-- #{s}\n\n" }.test_each do |s|
|
20
20
|
node, rest = parse_some(:tComment, s)
|
21
|
-
node.should
|
21
|
+
node.should be_comment
|
22
22
|
rest.should == "\n"
|
23
23
|
end
|
24
24
|
|
25
25
|
GrammarHelper::COMMENTS.map{|s| "-- #{s}\nremaining cruft\n" }.test_each do |s|
|
26
26
|
node, rest = parse_some(:tComment, s)
|
27
|
-
node.should
|
27
|
+
node.should be_comment
|
28
28
|
rest.should == "remaining cruft\n"
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
32
|
it "can be /* c-style */" do
|
33
33
|
GrammarHelper::COMMENTS.map{|s| "/* #{s} */" }.test_each do |s|
|
34
|
-
parse(:tComment, s).should
|
34
|
+
parse(:tComment, s).should be_comment
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
it "
|
38
|
+
it "terminates after */ marker" do
|
39
39
|
GrammarHelper::COMMENTS.map{|s| "/* #{s} */remaining cruft\n" }.test_each do |s|
|
40
40
|
node, rest = parse_some(:tComment, s)
|
41
|
-
node.should
|
41
|
+
node.should be_comment
|
42
42
|
rest.should == "remaining cruft\n"
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
46
|
it "cannot be nested" do
|
47
47
|
node, rest = parse_some(:tComment, "/* nested /*INLINE*/ comments */")
|
48
|
-
node.should
|
48
|
+
node.should be_comment
|
49
49
|
rest.should == " comments */"
|
50
50
|
|
51
51
|
node, rest = parse_some(:tComment, "-- nested -- line comments")
|
52
|
-
node.count{|e| e.
|
52
|
+
node.count{|e| e.comment? }.should == 1
|
53
53
|
rest.should == ''
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
57
|
end
|
58
|
-
end
|
58
|
+
end
|