twowaysql 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +3 -0
- data/Manifest.txt +2 -14
- data/{README.txt → README.rdoc} +19 -11
- data/issues/issue-ec698dd75fb717a23045852de2fb367cff119b2e.yaml +30 -0
- data/issues/project.yaml +13 -0
- data/lib/twowaysql.rb +4 -0
- data/lib/twowaysql/node.rb +4 -6
- data/lib/twowaysql/parser.rb +8 -6
- data/lib/twowaysql/parser.y +6 -4
- data/lib/twowaysql/template.rb +4 -5
- data/spec/large_sql_spec.rb +7 -7
- data/spec/learning_regex_spec.rb +21 -21
- data/spec/spec_helper.rb +0 -32
- data/spec/twowaysql_spec.rb +4 -4
- metadata +19 -21
- data/Manifest.skip +0 -7
- data/Rakefile +0 -4
- data/config/hoe.rb +0 -73
- data/config/requirements.rb +0 -15
- data/lib/twowaysql/version.rb +0 -9
- data/setup.rb +0 -1585
- data/tasks/deployment.rake +0 -53
- data/tasks/ditz.rake +0 -24
- data/tasks/environment.rake +0 -7
- data/tasks/racc.rake +0 -23
- data/tasks/rcov.rake +0 -5
- data/tasks/rspec.rake +0 -21
- data/tasks/website.rake +0 -17
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
@@ -1,11 +1,7 @@
|
|
1
1
|
History.txt
|
2
2
|
License.txt
|
3
|
-
Manifest.skip
|
4
3
|
Manifest.txt
|
5
|
-
README.
|
6
|
-
Rakefile
|
7
|
-
config/hoe.rb
|
8
|
-
config/requirements.rb
|
4
|
+
README.rdoc
|
9
5
|
issues/issue-001c53236380a42cd8c5a9099bbcc6ec613919c2.yaml
|
10
6
|
issues/issue-1cee7e821865a216674832b0186bd92792680571.yaml
|
11
7
|
issues/issue-25efcfc383f3b0f6c0e2730ae7c2975bb2b3de26.yaml
|
@@ -22,6 +18,7 @@ issues/issue-901f65630639507c8b05b466790e9f22256c6450.yaml
|
|
22
18
|
issues/issue-a185b4247f64c1104bc49ebf823b57b5de3d06f8.yaml
|
23
19
|
issues/issue-bd38c1cdc965d73dd629a81db2de1bcdcf4b10b8.yaml
|
24
20
|
issues/issue-dca4b19aa13de59838b33e03252bf824670a2d12.yaml
|
21
|
+
issues/issue-ec698dd75fb717a23045852de2fb367cff119b2e.yaml
|
25
22
|
issues/issue-f1bd40de5458397d9b142ea3e197e5264e0dcdbf.yaml
|
26
23
|
issues/issue-f2b773020b54f839c03d899b38b5113c8fd991df.yaml
|
27
24
|
issues/issue-f39b907d01d7fa93df8c7a9de2e1b5e27727ee0a.yaml
|
@@ -32,17 +29,8 @@ lib/twowaysql/node.rb
|
|
32
29
|
lib/twowaysql/parser.rb
|
33
30
|
lib/twowaysql/parser.y
|
34
31
|
lib/twowaysql/template.rb
|
35
|
-
lib/twowaysql/version.rb
|
36
|
-
setup.rb
|
37
32
|
spec/large_sql_spec.rb
|
38
33
|
spec/learning_regex_spec.rb
|
39
34
|
spec/spec.opts
|
40
35
|
spec/spec_helper.rb
|
41
36
|
spec/twowaysql_spec.rb
|
42
|
-
tasks/deployment.rake
|
43
|
-
tasks/ditz.rake
|
44
|
-
tasks/environment.rake
|
45
|
-
tasks/racc.rake
|
46
|
-
tasks/rcov.rake
|
47
|
-
tasks/rspec.rake
|
48
|
-
tasks/website.rake
|
data/{README.txt → README.rdoc}
RENAMED
@@ -5,6 +5,8 @@
|
|
5
5
|
* {Project Page}[http://rubyforge.org/projects/twowaysql]
|
6
6
|
* {API Doc}[http://twowaysql.rubyforge.org/rdoc/]
|
7
7
|
* {Issue Tracking}[http://twowaysql.rubyforge.org/issues/]
|
8
|
+
* {Coverage Report}[http://twowaysql.rubyforge.org/coverage/]
|
9
|
+
|
8
10
|
|
9
11
|
=== sources:
|
10
12
|
* http://github.com/twada/twowaysql/tree/master
|
@@ -154,7 +156,7 @@ TwoWaySQL::Template is the class you may only use. TwoWaySQL::Template acts as a
|
|
154
156
|
|
155
157
|
Firstly, In TwoWaySQL, expressions are written within SQL comment such as within "/**/" and "--". SQL may still be executed since TwoWaySQL specific, non-SQL expressions are written within comments. As a best practice, it is better to first write and test SQL and then write expressions within comments.
|
156
158
|
|
157
|
-
To write actual comments in SQL, *insert a space* after "/*" before the comment string. For example, /*
|
159
|
+
To write actual comments in SQL, *insert a space* after "/*" before the comment string. For example, /* foo*/. TwoWaySQL will recognize the space(s) after the comment start ("/*") and treat the enclosed content as an actual comment.
|
158
160
|
|
159
161
|
|
160
162
|
|
@@ -175,9 +177,9 @@ TwoWaySQL may use bind variable as follows. In this case, value of ctx[:empno] i
|
|
175
177
|
sql = "SELECT * FROM emp WHERE job = /*ctx[:job]*/'CLERK' AND deptno = /*ctx[:deptno]*/20"
|
176
178
|
template = TwoWaySQL::Template.parse(sql)
|
177
179
|
|
178
|
-
merged = template.merge(:job => "
|
180
|
+
merged = template.merge(:job => "FOO", :deptno => 30)
|
179
181
|
merged.sql #=> "SELECT * FROM emp WHERE job = ? AND deptno = ?"
|
180
|
-
merged.bound_variables #=> ["
|
182
|
+
merged.bound_variables #=> ["FOO", 30]
|
181
183
|
|
182
184
|
|
183
185
|
|
@@ -211,9 +213,9 @@ acceptable argument for IN clause is an array-like object. Say, Object that resp
|
|
211
213
|
|
212
214
|
If you want to use "LIKE", you may write bind variables:
|
213
215
|
|
214
|
-
ename LIKE /*ctx[:ename]*/'
|
216
|
+
ename LIKE /*ctx[:ename]*/'foo'
|
215
217
|
|
216
|
-
Unfortunately, there is no special support for "LIKE". So, to use a wildcard character, add wildcard
|
218
|
+
Unfortunately, there is no special support for "LIKE". So, to use a wildcard character, add wildcard directly to the data. For example, to specify to include "COT", add wildcard character in the value as follows:
|
217
219
|
|
218
220
|
:ename => "%COT%"
|
219
221
|
|
@@ -226,7 +228,7 @@ You can use Embedded variable comment to embed value directly (say without quoti
|
|
226
228
|
/*$variable name*/Literal
|
227
229
|
|
228
230
|
===== CAUTION:
|
229
|
-
|
231
|
+
Please note, Embedded variable comment has risk for SQL Injection. Like any other 'eval' usage of TwoWaySQL, Embedded variable comment evals the data in safe level 4. Therefore, dangerous actions in Ruby world (ex. system call, variable assignments, tainted strings) are never executed. However, this is not enough. Valid ruby string is still dangerous string as SQL fragments. Do NOT use user input or any other strings outside your code. If you use Embedded variable comment, you should carefully check the data and its origin.
|
230
232
|
|
231
233
|
===== usage
|
232
234
|
|
@@ -247,9 +249,9 @@ To change SQL during execution based on a condition, use IF comments. IF comment
|
|
247
249
|
|
248
250
|
An example of IF comment is as follows:
|
249
251
|
|
250
|
-
/*IF ctx[:foo]*/
|
252
|
+
/*IF ctx[:foo]*/foo = /*ctx[:foo]*/'abc'/*END*/
|
251
253
|
|
252
|
-
When the condition returns a truthy value, TwoWaySQL treats statements in "/*IF*/" and "/*END*/" as active. In the above example, "
|
254
|
+
When the condition returns a truthy value, TwoWaySQL treats statements in "/*IF*/" and "/*END*/" as active. In the above example, "foo = /*ctx[:foo]*/'abc'" will be output only when 'eval(ctx[:foo])' returns an truthy value.
|
253
255
|
|
254
256
|
|
255
257
|
==== usage
|
@@ -275,11 +277,11 @@ When the condition returns a truthy value, TwoWaySQL treats statements in "/*IF*
|
|
275
277
|
|
276
278
|
You can use ELSE comment to activate statements when condition is false. Sn example of IF comment with ELSE is as follows.
|
277
279
|
|
278
|
-
/*IF ctx[:foo]*/
|
279
|
-
-- ELSE
|
280
|
+
/*IF ctx[:foo]*/foo = /*ctx[:foo]*/'abc'
|
281
|
+
-- ELSE foo IS NULL
|
280
282
|
/*END*/
|
281
283
|
|
282
|
-
In this case, when the eval(ctx[:foo]) returns an falsy value, string "
|
284
|
+
In this case, when the eval(ctx[:foo]) returns an falsy value, string "foo IS NULL" will be active.
|
283
285
|
|
284
286
|
|
285
287
|
==== ELSE comment sample
|
@@ -437,6 +439,12 @@ Default is false. When true, parser preserves original actual comments. When fal
|
|
437
439
|
* Takuto Wada(takuto.wada at gmail dot com)
|
438
440
|
|
439
441
|
|
442
|
+
== CONTRIBUTORS:
|
443
|
+
|
444
|
+
* Keiji Muraishi(http://github.com/kjim)
|
445
|
+
* Keiji Yoshimi(http://github.com/walf443)
|
446
|
+
|
447
|
+
|
440
448
|
== LICENSE:
|
441
449
|
|
442
450
|
Copyright 2004-2008 the Seasar Foundation and the Others.
|
@@ -0,0 +1,30 @@
|
|
1
|
+
--- !ditz.rubyforge.org,2008-03-06/issue
|
2
|
+
title: apply latest newgem structure
|
3
|
+
desc: apply latest newgem structure
|
4
|
+
type: :task
|
5
|
+
component: twowaysql
|
6
|
+
release: release_0_4_1
|
7
|
+
reporter: takuto <takuto.wada@gmail.com>
|
8
|
+
status: :closed
|
9
|
+
disposition: :fixed
|
10
|
+
creation_time: 2008-11-02 21:05:36.085228 Z
|
11
|
+
references: []
|
12
|
+
|
13
|
+
id: ec698dd75fb717a23045852de2fb367cff119b2e
|
14
|
+
log_events:
|
15
|
+
- - 2008-11-02 21:05:37.613114 Z
|
16
|
+
- takuto <takuto.wada@gmail.com>
|
17
|
+
- created
|
18
|
+
- ""
|
19
|
+
- - 2008-11-02 21:08:03.079665 Z
|
20
|
+
- takuto <takuto.wada@gmail.com>
|
21
|
+
- changed status from unstarted to in_progress
|
22
|
+
- ""
|
23
|
+
- - 2008-11-02 21:22:12.307551 Z
|
24
|
+
- takuto <takuto.wada@gmail.com>
|
25
|
+
- assigned to release release_0_4_1 from unassigned
|
26
|
+
- ""
|
27
|
+
- - 2008-11-02 22:01:17.787460 Z
|
28
|
+
- takuto <takuto.wada@gmail.com>
|
29
|
+
- closed with disposition fixed
|
30
|
+
- ""
|
data/issues/project.yaml
CHANGED
@@ -57,3 +57,16 @@ releases:
|
|
57
57
|
- takuto <takuto.wada@gmail.com>
|
58
58
|
- released
|
59
59
|
- ""
|
60
|
+
- !ditz.rubyforge.org,2008-03-06/release
|
61
|
+
name: release_0_4_1
|
62
|
+
status: :released
|
63
|
+
release_time: 2008-11-02 22:03:09.020717 Z
|
64
|
+
log_events:
|
65
|
+
- - 2008-11-02 21:19:28.448115 Z
|
66
|
+
- takuto <takuto.wada@gmail.com>
|
67
|
+
- created
|
68
|
+
- release for applying latest newgem structure
|
69
|
+
- - 2008-11-02 22:03:09.020757 Z
|
70
|
+
- takuto <takuto.wada@gmail.com>
|
71
|
+
- released
|
72
|
+
- ""
|
data/lib/twowaysql.rb
CHANGED
data/lib/twowaysql/node.rb
CHANGED
@@ -94,9 +94,6 @@ module TwoWaySQL
|
|
94
94
|
def accept(ctx)
|
95
95
|
exec_list(@tree, ctx)
|
96
96
|
end
|
97
|
-
def children
|
98
|
-
@tree
|
99
|
-
end
|
100
97
|
end
|
101
98
|
|
102
99
|
|
@@ -133,12 +130,12 @@ module TwoWaySQL
|
|
133
130
|
|
134
131
|
|
135
132
|
class SubStatementNode < Node
|
136
|
-
def initialize(
|
137
|
-
@
|
133
|
+
def initialize(first_node, tree)
|
134
|
+
@first_node = first_node
|
138
135
|
@tree = tree
|
139
136
|
end
|
140
137
|
def accept(ctx)
|
141
|
-
ctx.add_sql(@
|
138
|
+
ctx.add_sql(@first_node) if ctx.enabled?
|
142
139
|
exec_list(@tree, ctx)
|
143
140
|
end
|
144
141
|
def each
|
@@ -174,6 +171,7 @@ module TwoWaySQL
|
|
174
171
|
def accept(ctx)
|
175
172
|
result = do_eval(ctx, @exp)
|
176
173
|
return if result.nil?
|
174
|
+
##TODO: is there any better way to handle array-like structure?
|
177
175
|
if result.respond_to?('to_ary')
|
178
176
|
bind_values(ctx, result.to_ary)
|
179
177
|
else
|
data/lib/twowaysql/parser.rb
CHANGED
@@ -11,7 +11,7 @@ module TwoWaySQL
|
|
11
11
|
|
12
12
|
class Parser < Racc::Parser
|
13
13
|
|
14
|
-
module_eval <<'..end lib/twowaysql/parser.y modeval..
|
14
|
+
module_eval <<'..end lib/twowaysql/parser.y modeval..id64138765db', 'lib/twowaysql/parser.y', 134
|
15
15
|
|
16
16
|
require 'strscan'
|
17
17
|
|
@@ -64,10 +64,11 @@ def parse( io )
|
|
64
64
|
# @q.push [ false, nil ]
|
65
65
|
@q.push [ false, [@s.pos, nil] ]
|
66
66
|
|
67
|
-
##
|
67
|
+
## call racc's private parse method
|
68
68
|
do_parse
|
69
69
|
end
|
70
70
|
|
71
|
+
|
71
72
|
## called by racc
|
72
73
|
def next_token
|
73
74
|
@q.shift
|
@@ -116,22 +117,23 @@ def scan_str
|
|
116
117
|
when @s.scan(SEMICOLON_AT_INPUT_END_PATTERN)
|
117
118
|
#drop semicolon at input end
|
118
119
|
else
|
119
|
-
raise Racc::ParseError, "syntax error near line:[#{line_no(@s.pos)}], str:[#{@s.rest}]"
|
120
|
+
raise Racc::ParseError, "syntax error at or near line:[#{line_no(@s.pos)}], str:[#{@s.rest}]"
|
120
121
|
end
|
121
122
|
end
|
122
123
|
end
|
123
124
|
|
124
125
|
|
126
|
+
## override racc's default on_error method
|
125
127
|
def on_error(t, v, vstack)
|
126
128
|
## cursor in value-stack is an array of two items,
|
127
|
-
##
|
129
|
+
## that have position value as 0th item. like [731, "ctx[:limit] "]
|
128
130
|
cursor = vstack.find do |tokens|
|
129
131
|
tokens.size == 2 and tokens[0].kind_of?(Fixnum)
|
130
132
|
end
|
131
133
|
pos = cursor[0]
|
132
134
|
line = line_no(pos)
|
133
135
|
rest = @s.string[pos .. -1]
|
134
|
-
raise Racc::ParseError, "syntax error near line:[#{line}], str:[#{rest}]"
|
136
|
+
raise Racc::ParseError, "syntax error at or near line:[#{line}], str:[#{rest}]"
|
135
137
|
end
|
136
138
|
|
137
139
|
|
@@ -141,7 +143,7 @@ def line_no(pos)
|
|
141
143
|
scanned.each_line { lines += 1 }
|
142
144
|
lines
|
143
145
|
end
|
144
|
-
..end lib/twowaysql/parser.y modeval..
|
146
|
+
..end lib/twowaysql/parser.y modeval..id64138765db
|
145
147
|
|
146
148
|
##### racc 1.4.5 generates ###
|
147
149
|
|
data/lib/twowaysql/parser.y
CHANGED
@@ -183,10 +183,11 @@ def parse( io )
|
|
183
183
|
# @q.push [ false, nil ]
|
184
184
|
@q.push [ false, [@s.pos, nil] ]
|
185
185
|
|
186
|
-
##
|
186
|
+
## call racc's private parse method
|
187
187
|
do_parse
|
188
188
|
end
|
189
189
|
|
190
|
+
|
190
191
|
## called by racc
|
191
192
|
def next_token
|
192
193
|
@q.shift
|
@@ -235,22 +236,23 @@ def scan_str
|
|
235
236
|
when @s.scan(SEMICOLON_AT_INPUT_END_PATTERN)
|
236
237
|
#drop semicolon at input end
|
237
238
|
else
|
238
|
-
raise Racc::ParseError, "syntax error near line:[#{line_no(@s.pos)}], str:[#{@s.rest}]"
|
239
|
+
raise Racc::ParseError, "syntax error at or near line:[#{line_no(@s.pos)}], str:[#{@s.rest}]"
|
239
240
|
end
|
240
241
|
end
|
241
242
|
end
|
242
243
|
|
243
244
|
|
245
|
+
## override racc's default on_error method
|
244
246
|
def on_error(t, v, vstack)
|
245
247
|
## cursor in value-stack is an array of two items,
|
246
|
-
##
|
248
|
+
## that have position value as 0th item. like [731, "ctx[:limit] "]
|
247
249
|
cursor = vstack.find do |tokens|
|
248
250
|
tokens.size == 2 and tokens[0].kind_of?(Fixnum)
|
249
251
|
end
|
250
252
|
pos = cursor[0]
|
251
253
|
line = line_no(pos)
|
252
254
|
rest = @s.string[pos .. -1]
|
253
|
-
raise Racc::ParseError, "syntax error near line:[#{line}], str:[#{rest}]"
|
255
|
+
raise Racc::ParseError, "syntax error at or near line:[#{line}], str:[#{rest}]"
|
254
256
|
end
|
255
257
|
|
256
258
|
|
data/lib/twowaysql/template.rb
CHANGED
@@ -33,9 +33,9 @@ module TwoWaySQL
|
|
33
33
|
#
|
34
34
|
# === Usage
|
35
35
|
#
|
36
|
-
# merged = template.merge(:job => "
|
36
|
+
# merged = template.merge(:job => "MANAGER", :deptno => 30)
|
37
37
|
# merged.sql #=> "SELECT * FROM emp WHERE job = ? AND deptno = ?"
|
38
|
-
# merged.bound_variables #=> ["
|
38
|
+
# merged.bound_variables #=> ["MANAGER", 30]
|
39
39
|
#
|
40
40
|
# === Arguments
|
41
41
|
#
|
@@ -51,7 +51,6 @@ module TwoWaySQL
|
|
51
51
|
@root.accept(c)
|
52
52
|
MergeResult.new(c)
|
53
53
|
end
|
54
|
-
alias mungle merge
|
55
54
|
|
56
55
|
protected
|
57
56
|
def initialize(root)
|
@@ -65,9 +64,9 @@ module TwoWaySQL
|
|
65
64
|
#
|
66
65
|
# === Usage
|
67
66
|
#
|
68
|
-
# merged = template.merge(:job => "
|
67
|
+
# merged = template.merge(:job => "MANAGER", :deptno => 30)
|
69
68
|
# merged.sql #=> "SELECT * FROM emp WHERE job = ? AND deptno = ?"
|
70
|
-
# merged.bound_variables #=> ["
|
69
|
+
# merged.bound_variables #=> ["MANAGER", 30]
|
71
70
|
#
|
72
71
|
class MergeResult
|
73
72
|
def initialize(context)
|
data/spec/large_sql_spec.rb
CHANGED
@@ -34,7 +34,7 @@ EOS
|
|
34
34
|
end
|
35
35
|
|
36
36
|
|
37
|
-
describe do
|
37
|
+
describe '' do
|
38
38
|
before do
|
39
39
|
template = TwoWaySQL::Template.parse(@sql)
|
40
40
|
@result = template.merge(:name => "HOGE", :status => [3, 4])
|
@@ -100,7 +100,7 @@ WHERE
|
|
100
100
|
EOS
|
101
101
|
end
|
102
102
|
|
103
|
-
describe do
|
103
|
+
describe '' do
|
104
104
|
before do
|
105
105
|
template = TwoWaySQL::Template.parse(@sql)
|
106
106
|
data = {
|
@@ -194,7 +194,7 @@ EOS
|
|
194
194
|
|
195
195
|
|
196
196
|
describe "examples in website" do
|
197
|
-
it do
|
197
|
+
it '' do
|
198
198
|
# given SQL string with TwoWaySQL comments
|
199
199
|
sql = <<-EOS
|
200
200
|
SELECT * FROM emp
|
@@ -259,7 +259,7 @@ EOS
|
|
259
259
|
begin
|
260
260
|
TwoWaySQL::Template.parse(sql)
|
261
261
|
rescue Racc::ParseError => e
|
262
|
-
e.to_s.should
|
262
|
+
e.to_s.should =~ /line:\[10\]/
|
263
263
|
end
|
264
264
|
end
|
265
265
|
|
@@ -282,8 +282,8 @@ EOS
|
|
282
282
|
begin
|
283
283
|
TwoWaySQL::Template.parse(sql)
|
284
284
|
rescue Racc::ParseError => e
|
285
|
-
e.to_s.should
|
286
|
-
e.to_s.should
|
285
|
+
e.to_s.should =~ /line:\[12\]/
|
286
|
+
e.to_s.should =~ /OFFSET \/\*ctx\[:offset\]\*\/0/
|
287
287
|
|
288
288
|
end
|
289
289
|
end
|
@@ -319,7 +319,7 @@ EOS
|
|
319
319
|
TwoWaySQL::Template.parse(sql)
|
320
320
|
rescue Racc::ParseError => e
|
321
321
|
# unmatched END is at line 17 but value stack indicates open BEGIN statement
|
322
|
-
e.to_s.should
|
322
|
+
e.to_s.should =~ /line:\[14\]/
|
323
323
|
end
|
324
324
|
end
|
325
325
|
|
data/spec/learning_regex_spec.rb
CHANGED
@@ -44,7 +44,7 @@ EOS
|
|
44
44
|
end
|
45
45
|
|
46
46
|
describe "-- comment start" do
|
47
|
-
it do
|
47
|
+
it '' do
|
48
48
|
(@str_re =~ 'foo-bar--ELSE').should_not be_nil
|
49
49
|
$1.should == 'foo-bar'
|
50
50
|
$'.should == '--ELSE'
|
@@ -83,17 +83,17 @@ EOS
|
|
83
83
|
$1.should == 'foo/bar'
|
84
84
|
$'.should == ' /* hoge */'
|
85
85
|
end
|
86
|
-
it do
|
86
|
+
it '' do
|
87
87
|
(@str_re =~ 'foo/bar/* hoge */').should_not be_nil
|
88
88
|
$1.should == 'foo/bar'
|
89
89
|
$'.should == '/* hoge */'
|
90
90
|
end
|
91
|
-
it do
|
91
|
+
it '' do
|
92
92
|
(@str_re =~ 'foo/bar/* hoge */').should_not be_nil
|
93
93
|
$1.should == 'foo/bar'
|
94
94
|
$'.should == '/* hoge */'
|
95
95
|
end
|
96
|
-
it do
|
96
|
+
it '' do
|
97
97
|
(@str_re =~ 'foobar/* hoge */').should_not be_nil
|
98
98
|
$1.should == 'foobar'
|
99
99
|
$'.should == '/* hoge */'
|
@@ -106,17 +106,17 @@ EOS
|
|
106
106
|
$1.should == 'foo#bar'
|
107
107
|
$'.should == ' #* hoge *#'
|
108
108
|
end
|
109
|
-
it do
|
109
|
+
it '' do
|
110
110
|
(@str_re =~ 'foo#bar#* hoge *#').should_not be_nil
|
111
111
|
$1.should == 'foo#bar'
|
112
112
|
$'.should == '#* hoge *#'
|
113
113
|
end
|
114
|
-
it do
|
114
|
+
it '' do
|
115
115
|
(@str_re =~ 'foo#bar#* hoge *#').should_not be_nil
|
116
116
|
$1.should == 'foo#bar'
|
117
117
|
$'.should == '#* hoge *#'
|
118
118
|
end
|
119
|
-
it do
|
119
|
+
it '' do
|
120
120
|
(@str_re =~ 'foobar#* hoge *#').should_not be_nil
|
121
121
|
$1.should == 'foobar'
|
122
122
|
$'.should == '#* hoge *#'
|
@@ -124,12 +124,12 @@ EOS
|
|
124
124
|
end
|
125
125
|
|
126
126
|
describe "comma" do
|
127
|
-
it do
|
127
|
+
it '' do
|
128
128
|
(@str_re =~ 'foo,bar').should_not be_nil
|
129
129
|
$1.should == 'foo'
|
130
130
|
$'.should == ',bar'
|
131
131
|
end
|
132
|
-
it do
|
132
|
+
it '' do
|
133
133
|
(@str_re =~ 'foo , bar').should_not be_nil
|
134
134
|
$1.should == 'foo'
|
135
135
|
$'.should == ' , bar'
|
@@ -137,12 +137,12 @@ EOS
|
|
137
137
|
end
|
138
138
|
|
139
139
|
describe "left paren" do
|
140
|
-
it do
|
140
|
+
it '' do
|
141
141
|
(@str_re =~ 'foo(bar').should_not be_nil
|
142
142
|
$1.should == 'foo'
|
143
143
|
$'.should == '(bar'
|
144
144
|
end
|
145
|
-
it do
|
145
|
+
it '' do
|
146
146
|
(@str_re =~ 'foo ( bar').should_not be_nil
|
147
147
|
$1.should == 'foo'
|
148
148
|
$'.should == ' ( bar'
|
@@ -150,12 +150,12 @@ EOS
|
|
150
150
|
end
|
151
151
|
|
152
152
|
describe "right paren" do
|
153
|
-
it do
|
153
|
+
it '' do
|
154
154
|
(@str_re =~ 'foo)bar').should_not be_nil
|
155
155
|
$1.should == 'foo'
|
156
156
|
$'.should == ')bar'
|
157
157
|
end
|
158
|
-
it do
|
158
|
+
it '' do
|
159
159
|
(@str_re =~ 'foo ) bar').should_not be_nil
|
160
160
|
$1.should == 'foo'
|
161
161
|
$'.should == ' ) bar'
|
@@ -170,19 +170,19 @@ EOS
|
|
170
170
|
before do
|
171
171
|
@str_re = /(\'(?:[^\']+|\'\')*\')/
|
172
172
|
end
|
173
|
-
it do
|
173
|
+
it '' do
|
174
174
|
(@str_re =~ "he said 'foo bar' then 'baz'").should_not be_nil
|
175
175
|
$1.should == "'foo bar'"
|
176
176
|
end
|
177
|
-
it do
|
177
|
+
it '' do
|
178
178
|
(@str_re =~ "he said 'Let''s go' then went out").should_not be_nil
|
179
179
|
$1.should == "'Let''s go'"
|
180
180
|
end
|
181
|
-
it do
|
181
|
+
it '' do
|
182
182
|
(@str_re =~ "he said 'foo bar'then went out").should_not be_nil
|
183
183
|
$1.should == "'foo bar'"
|
184
184
|
end
|
185
|
-
it do
|
185
|
+
it '' do
|
186
186
|
sql = "SELECT * FROM emp/*BEGIN*/ WHERE /*IF ctx[:job]*/job = /*ctx[:job]*/'CLERK'/*END*//*IF ctx['deptno']*/ AND deptno = /*ctx[:deptno]*/20/*END*//*END*/"
|
187
187
|
(@str_re =~ sql).should_not be_nil
|
188
188
|
$1.should == "'CLERK'"
|
@@ -198,14 +198,14 @@ EOS
|
|
198
198
|
end
|
199
199
|
|
200
200
|
describe "matched pair" do
|
201
|
-
it do
|
201
|
+
it '' do
|
202
202
|
(@str_re =~ '/*ctx[:job]*/').should_not be_nil
|
203
203
|
$1.should == '/'
|
204
204
|
$2.should == 'ctx[:job]'
|
205
205
|
$'.should == ''
|
206
206
|
end
|
207
207
|
|
208
|
-
it do
|
208
|
+
it '' do
|
209
209
|
(@str_re =~ '#*ctx[:job]*#').should_not be_nil
|
210
210
|
$1.should == '#'
|
211
211
|
$2.should == 'ctx[:job]'
|
@@ -214,14 +214,14 @@ EOS
|
|
214
214
|
end
|
215
215
|
|
216
216
|
describe "unmatched pair" do
|
217
|
-
it do
|
217
|
+
it '' do
|
218
218
|
(@str_re =~ '/*ctx[:job]*#').should be_nil
|
219
219
|
$1.should be_nil
|
220
220
|
$2.should be_nil
|
221
221
|
$'.should be_nil
|
222
222
|
end
|
223
223
|
|
224
|
-
it do
|
224
|
+
it '' do
|
225
225
|
(@str_re =~ '/*ctx[:job]*#').should be_nil
|
226
226
|
$1.should be_nil
|
227
227
|
$2.should be_nil
|