twowaysql 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,7 +12,7 @@ describe TwoWaySQL::Template do
12
12
  describe "when parse SQL without comment nodes, e.g. 'SELECT * FROM emp'" do
13
13
  before do
14
14
  sql = "SELECT * FROM emp"
15
- @template = TwoWaySQL::Template.parse(sql, :preserve_eol => false)
15
+ @template = TwoWaySQL::Template.parse(sql)
16
16
  @result = @template.merge(@ctx)
17
17
  end
18
18
 
@@ -30,7 +30,7 @@ describe TwoWaySQL::Template do
30
30
  describe "when parsed from 'SELECT * FROM emp WHERE job = /*ctx[:job]*/'CLERK' AND deptno = /*ctx[:deptno]*/20'" do
31
31
  before do
32
32
  sql = "SELECT * FROM emp WHERE job = /*ctx[:job]*/'CLERK' AND deptno = /*ctx[:deptno]*/20"
33
- @template = TwoWaySQL::Template.parse(sql, :preserve_eol => false)
33
+ @template = TwoWaySQL::Template.parse(sql)
34
34
  end
35
35
 
36
36
  describe "pass Context with Symbol keys like ctx[:job] = 'HOGE' and ctx[:deptno] = 30" do
@@ -55,7 +55,7 @@ describe TwoWaySQL::Template do
55
55
  describe "when parsed from 'SELECT * FROM emp WHERE job = /*ctx['job']*/'CLERK' AND deptno = /*ctx['deptno']*/20'" do
56
56
  before do
57
57
  sql = "SELECT * FROM emp WHERE job = /*ctx['job']*/'CLERK' AND deptno = /*ctx['deptno']*/20"
58
- @template = TwoWaySQL::Template.parse(sql, :preserve_eol => false)
58
+ @template = TwoWaySQL::Template.parse(sql)
59
59
  end
60
60
 
61
61
  describe "pass Context with String keys like ctx['job'] = 'HOGE' and ctx['deptno'] = 30" do
@@ -80,7 +80,7 @@ describe TwoWaySQL::Template do
80
80
  describe "when parsed from 'SELECT * FROM emp WHERE job = #*ctx[:job]*#'CLERK' AND deptno = #*ctx[:deptno]*#20'" do
81
81
  before do
82
82
  sql = "SELECT * FROM emp WHERE job = #*ctx[:job]*#'CLERK' AND deptno = #*ctx[:deptno]*#20"
83
- @template = TwoWaySQL::Template.parse(sql, :preserve_eol => false)
83
+ @template = TwoWaySQL::Template.parse(sql)
84
84
 
85
85
  @ctx[:job] = "HOGE"
86
86
  @ctx[:deptno] = 30
@@ -102,22 +102,42 @@ describe TwoWaySQL::Template do
102
102
 
103
103
 
104
104
 
105
- describe "when parsed from SQL file with one or more white speces in comment, like 'SELECT * FROM emp WHERE job = /* ctx[:job]*/'CLERK''" do
106
- before do
107
- sql = "SELECT * FROM emp WHERE job = /* ctx[:job]*/'CLERK'"
108
- @template = TwoWaySQL::Template.parse(sql, :preserve_eol => false)
105
+ describe "when parsed from SQL file with one or more white speces in comment, like 'SELECT * FROM emp WHERE job = /* ctx[:job]*/'CLERK''" do
109
106
 
110
- @ctx[:job] = "HOGE"
111
- @result = @template.merge(@ctx)
112
- end
107
+ describe "default is :peserve_comment => true" do
108
+ before do
109
+ sql = "SELECT * FROM emp WHERE job = /* ctx[:job]*/'CLERK'"
110
+ @template = TwoWaySQL::Template.parse(sql)
111
+ @ctx[:job] = "HOGE"
112
+ @result = @template.merge(@ctx)
113
+ end
113
114
 
114
- it "should treat comment node which starts with one or more speces like /* ctx[:job]*/'CLERK' as real comment node, therefore it does *NOT* replace comment node with question mark. so SQL will 'SELECT * FROM emp WHERE job = 'CLERK''" do
115
- @result.sql.should == "SELECT * FROM emp WHERE job = 'CLERK'"
115
+ it "should treat comment node which starts with one or more speces like /* ctx[:job]*/'CLERK' as actual comment node, therefore it does *NOT* replace comment node with question mark. so SQL will 'SELECT * FROM emp WHERE job = 'CLERK''" do
116
+ @result.sql.should == "SELECT * FROM emp WHERE job = 'CLERK'"
117
+ end
118
+
119
+ it "should have no variable nodes, so return empty Array as bound variables" do
120
+ @result.bound_variables.should be_empty
121
+ end
116
122
  end
117
123
 
118
- it "should have no variable nodes, so return empty Array as bound variables" do
119
- @result.bound_variables.should be_empty
124
+ describe "if preserve_comment => true" do
125
+ before do
126
+ sql = "SELECT * FROM emp WHERE job = /* ctx[:job]*/'CLERK'"
127
+ @template = TwoWaySQL::Template.parse(sql, :preserve_comment => true)
128
+ @ctx[:job] = "HOGE"
129
+ @result = @template.merge(@ctx)
130
+ end
131
+
132
+ it "SQL will 'SELECT * FROM emp WHERE job = /* ctx[:job]*/'CLERK''" do
133
+ @result.sql.should == "SELECT * FROM emp WHERE job = /* ctx[:job]*/'CLERK'"
134
+ end
135
+
136
+ it "should have no variable nodes, so return empty Array as bound variables" do
137
+ @result.bound_variables.should be_empty
138
+ end
120
139
  end
140
+
121
141
  end
122
142
 
123
143
 
@@ -125,7 +145,7 @@ describe TwoWaySQL::Template do
125
145
  describe "when parsed from 'SELECT * FROM emp WHERE empno = /*ctx[:empno]*/1 AND 1 = 1'" do
126
146
  before do
127
147
  sql = "SELECT * FROM emp WHERE empno = /*ctx[:empno]*/1 AND 1 = 1"
128
- @template = TwoWaySQL::Template.parse(sql, :preserve_eol => false)
148
+ @template = TwoWaySQL::Template.parse(sql)
129
149
 
130
150
  @ctx[:empno] = 7788
131
151
  @result = @template.merge(@ctx)
@@ -145,7 +165,7 @@ describe TwoWaySQL::Template do
145
165
  describe "when parsed from 'SELECT * FROM emp/*IF ctx[:job] */ WHERE job = /*ctx[:job]*/'CLERK'/*END*/'" do
146
166
  before do
147
167
  sql = "SELECT * FROM emp/*IF ctx[:job] */ WHERE job = /*ctx[:job]*/'CLERK'/*END*/"
148
- @template = TwoWaySQL::Template.parse(sql, :preserve_eol => false)
168
+ @template = TwoWaySQL::Template.parse(sql)
149
169
  end
150
170
 
151
171
  describe "and when :job param exists" do
@@ -179,7 +199,7 @@ describe TwoWaySQL::Template do
179
199
  describe "when parsed from SQL with 'nested if' like '/*IF ctx[:aaa]*/aaa/*IF ctx[:bbb]*/bbb/*END*//*END*/'" do
180
200
  before do
181
201
  sql = "/*IF ctx[:aaa]*/aaa/*IF ctx[:bbb]*/bbb/*END*//*END*/"
182
- @template = TwoWaySQL::Template.parse(sql, :preserve_eol => false)
202
+ @template = TwoWaySQL::Template.parse(sql)
183
203
  end
184
204
 
185
205
  describe "and when inner is true but outer is false" do
@@ -229,7 +249,7 @@ describe TwoWaySQL::Template do
229
249
  describe "when parsed from 'SELECT * FROM emp WHERE /*IF ctx[:job]*/job = /*ctx[:job]*/'CLERK'-- ELSE job is null/*END*/'" do
230
250
  before do
231
251
  sql = "SELECT * FROM emp WHERE /*IF ctx[:job]*/job = /*ctx[:job]*/'CLERK'-- ELSE job is null/*END*/"
232
- @template = TwoWaySQL::Template.parse(sql, :preserve_eol => false)
252
+ @template = TwoWaySQL::Template.parse(sql)
233
253
  end
234
254
 
235
255
  describe "and when :job param exists" do
@@ -263,7 +283,7 @@ describe TwoWaySQL::Template do
263
283
  describe "when parsed from '/*IF false*/aaa--ELSE bbb = /*ctx[:bbb]*/123/*END*/'" do
264
284
  before do
265
285
  sql = "/*IF false*/aaa--ELSE bbb = /*ctx[:bbb]*/123/*END*/"
266
- @template = TwoWaySQL::Template.parse(sql, :preserve_eol => false)
286
+ @template = TwoWaySQL::Template.parse(sql)
267
287
  end
268
288
 
269
289
  describe "and when :bbb param exists" do
@@ -297,7 +317,7 @@ describe TwoWaySQL::Template do
297
317
  describe "when parsed from '/*IF false*/aaa--ELSE bbb/*IF false*/ccc--ELSE ddd/*END*//*END*/'" do
298
318
  before do
299
319
  sql = "/*IF false*/aaa--ELSE bbb/*IF false*/ccc--ELSE ddd/*END*//*END*/"
300
- @template = TwoWaySQL::Template.parse(sql, :preserve_eol => false)
320
+ @template = TwoWaySQL::Template.parse(sql)
301
321
  @result = @template.merge(@ctx)
302
322
  end
303
323
 
@@ -311,24 +331,24 @@ describe TwoWaySQL::Template do
311
331
  describe "when parsed from 'SELECT * FROM emp/*BEGIN*/ WHERE /*IF false*/aaa-- ELSE AND deptno = 10/*END*//*END*/'" do
312
332
  before do
313
333
  sql = "SELECT * FROM emp/*BEGIN*/ WHERE /*IF false*/aaa-- ELSE AND deptno = 10/*END*//*END*/"
314
- @template = TwoWaySQL::Template.parse(sql, :preserve_eol => false)
334
+ @template = TwoWaySQL::Template.parse(sql)
315
335
  @result = @template.merge(@ctx)
316
336
  end
317
337
 
318
- it "parsed SQL should 'SELECT * FROM emp WHERE deptno = 10'" do
319
- @result.sql.should == "SELECT * FROM emp WHERE deptno = 10"
338
+ it "parsed SQL should 'SELECT * FROM emp WHERE deptno = 10'" do
339
+ @result.sql.should == "SELECT * FROM emp WHERE deptno = 10"
320
340
  end
321
341
  end
322
342
 
323
343
  describe "when parsed from 'SELECT * FROM emp/*BEGIN*/ WHERE /*IF false*/aaa--- ELSE AND deptno = 10/*END*//*END*/'" do
324
344
  before do
325
345
  sql = "SELECT * FROM emp/*BEGIN*/ WHERE /*IF false*/aaa--- ELSE AND deptno = 10/*END*//*END*/"
326
- @template = TwoWaySQL::Template.parse(sql, :preserve_eol => false)
346
+ @template = TwoWaySQL::Template.parse(sql)
327
347
  @result = @template.merge(@ctx)
328
348
  end
329
349
 
330
- it "parsed SQL should 'SELECT * FROM emp WHERE deptno = 10'" do
331
- @result.sql.should == "SELECT * FROM emp WHERE deptno = 10"
350
+ it "parsed SQL should 'SELECT * FROM emp WHERE deptno = 10'" do
351
+ @result.sql.should == "SELECT * FROM emp WHERE deptno = 10"
332
352
  end
333
353
  end
334
354
 
@@ -337,7 +357,7 @@ describe TwoWaySQL::Template do
337
357
  describe "when parsed from 'SELECT * FROM emp/*BEGIN*/ WHERE /*IF ctx[:job]*/job = /*ctx[:job]*/'CLERK'/*END*//*IF ctx[:deptno]*/ AND deptno = /*ctx[:deptno]*/20/*END*//*END*/'" do
338
358
  before do
339
359
  sql = "SELECT * FROM emp/*BEGIN*/ WHERE /*IF ctx[:job]*/job = /*ctx[:job]*/'CLERK'/*END*//*IF ctx[:deptno]*/ AND deptno = /*ctx[:deptno]*/20/*END*//*END*/"
340
- @template = TwoWaySQL::Template.parse(sql, :preserve_eol => false)
360
+ @template = TwoWaySQL::Template.parse(sql)
341
361
  end
342
362
 
343
363
  describe "and when context is empty (no param exists)" do
@@ -384,8 +404,8 @@ describe TwoWaySQL::Template do
384
404
  @ctx[:deptno] = 20
385
405
  @result = @template.merge(@ctx)
386
406
  end
387
- it "parsed SQL should 'SELECT * FROM emp WHERE deptno = ?'" do
388
- @result.sql.should == 'SELECT * FROM emp WHERE deptno = ?'
407
+ it "parsed SQL should 'SELECT * FROM emp WHERE deptno = ?'" do
408
+ @result.sql.should == 'SELECT * FROM emp WHERE deptno = ?'
389
409
  end
390
410
  it "should have bound variables in Array [20]" do
391
411
  @result.bound_variables.should == [20]
@@ -398,7 +418,7 @@ describe TwoWaySQL::Template do
398
418
  describe "when parsed from '/*BEGIN*/WHERE /*IF true*/aaa BETWEEN /*ctx[:bbb]*/111 AND /*ctx[:ccc]*/123/*END*//*END*/'" do
399
419
  before do
400
420
  sql = "/*BEGIN*/WHERE /*IF true*/aaa BETWEEN /*ctx[:bbb]*/111 AND /*ctx[:ccc]*/123/*END*//*END*/"
401
- @template = TwoWaySQL::Template.parse(sql, :preserve_eol => false)
421
+ @template = TwoWaySQL::Template.parse(sql)
402
422
  end
403
423
 
404
424
  describe "and when :job and :deptno param exists" do
@@ -434,7 +454,7 @@ describe TwoWaySQL::Template do
434
454
  describe "when parsed from 'SELECT * FROM emp WHERE deptno IN /*ctx[:deptnoList]*/(10, 20) ORDER BY ename'" do
435
455
  before do
436
456
  sql = "SELECT * FROM emp WHERE deptno IN /*ctx[:deptnoList]*/(10, 20) ORDER BY ename"
437
- @template = TwoWaySQL::Template.parse(sql, :preserve_eol => false)
457
+ @template = TwoWaySQL::Template.parse(sql)
438
458
  end
439
459
 
440
460
  describe "and when :deptnoList param is [30,40,50]" do
@@ -495,7 +515,7 @@ describe TwoWaySQL::Template do
495
515
  describe "when parsed from 'SELECT * FROM emp WHERE ename IN /*ctx[:enames]*/('SCOTT','MARY') AND job IN /*ctx[:jobs]*/('ANALYST', 'FREE')'" do
496
516
  before do
497
517
  sql = "SELECT * FROM emp WHERE ename IN /*ctx[:enames]*/('SCOTT','MARY') AND job IN /*ctx[:jobs]*/('ANALYST', 'FREE')"
498
- @template = TwoWaySQL::Template.parse(sql, :preserve_eol => false)
518
+ @template = TwoWaySQL::Template.parse(sql)
499
519
  end
500
520
 
501
521
  describe "and when :enames param is ['DAVE', 'MARY', 'SCOTT'] and :jobs param is ['MANAGER', 'ANALYST']" do
@@ -518,7 +538,7 @@ describe TwoWaySQL::Template do
518
538
  describe "when parsed from 'INSERT INTO ITEM (ID, NUM) VALUES (/*ctx[:id]*/1, /*ctx[:num]*/20)'" do
519
539
  before do
520
540
  sql = "INSERT INTO ITEM (ID, NUM) VALUES (/*ctx[:id]*/1, /*ctx[:num]*/20)"
521
- @template = TwoWaySQL::Template.parse(sql, :preserve_eol => false)
541
+ @template = TwoWaySQL::Template.parse(sql)
522
542
  end
523
543
 
524
544
  describe "and when :id param is 0 and :num param is 1" do
@@ -541,7 +561,7 @@ describe TwoWaySQL::Template do
541
561
  describe "when parsed from SQL with embedded variable comment '/*$ctx[:aaa]*/foo'" do
542
562
  before do
543
563
  sql = "/*$ctx[:aaa]*/foo"
544
- @template = TwoWaySQL::Template.parse(sql, :preserve_eol => false)
564
+ @template = TwoWaySQL::Template.parse(sql)
545
565
  end
546
566
 
547
567
  describe "and :aaa param is 'hoge'" do
@@ -560,7 +580,7 @@ describe TwoWaySQL::Template do
560
580
  describe "when parsed from SQL with embedded variable comment 'BETWEEN sal ? AND ?'" do
561
581
  before do
562
582
  sql = "BETWEEN sal ? AND ?"
563
- @template = TwoWaySQL::Template.parse(sql, :preserve_eol => false)
583
+ @template = TwoWaySQL::Template.parse(sql)
564
584
  end
565
585
 
566
586
  describe "and ctx[1] = 0 and ctx[2] = 1000 (note: key starts with 1, not 0.)" do
@@ -604,7 +624,7 @@ describe TwoWaySQL::Template do
604
624
  describe "that ends with semicolon like 'SELECT * FROM emp;'" do
605
625
  before do
606
626
  sql = "SELECT * FROM emp;"
607
- @template = TwoWaySQL::Template.parse(sql, :preserve_eol => false)
627
+ @template = TwoWaySQL::Template.parse(sql)
608
628
  @result = @template.merge(@ctx)
609
629
  end
610
630
  it "should strip semicolon at input end" do
@@ -615,7 +635,7 @@ describe TwoWaySQL::Template do
615
635
  describe "that ends with semicolon and tab like 'SELECT * FROM emp;\t'" do
616
636
  before do
617
637
  sql = "SELECT * FROM emp;\t"
618
- @template = TwoWaySQL::Template.parse(sql, :preserve_eol => false)
638
+ @template = TwoWaySQL::Template.parse(sql)
619
639
  @result = @template.merge(@ctx)
620
640
  end
621
641
  it "should strip semicolon and tab at input end" do
@@ -626,7 +646,7 @@ describe TwoWaySQL::Template do
626
646
  describe "that ends with semicolon and spaces like 'SELECT * FROM emp; '" do
627
647
  before do
628
648
  sql = "SELECT * FROM emp; "
629
- @template = TwoWaySQL::Template.parse(sql, :preserve_eol => false)
649
+ @template = TwoWaySQL::Template.parse(sql)
630
650
  @result = @template.merge(@ctx)
631
651
  end
632
652
  it "should strip semicolon and spaces at input end" do
@@ -641,7 +661,7 @@ describe TwoWaySQL::Template do
641
661
  describe " '<>' " do
642
662
  before do
643
663
  sql = "SELECT * FROM emp WHERE job <> /*ctx[:job]*/'CLERK'"
644
- @template = TwoWaySQL::Template.parse(sql, :preserve_eol => false)
664
+ @template = TwoWaySQL::Template.parse(sql)
645
665
  @ctx[:job] = "HOGE"
646
666
  @result = @template.merge(@ctx)
647
667
  end
@@ -659,7 +679,7 @@ describe TwoWaySQL::Template do
659
679
  describe "minus, such as -5 " do
660
680
  before do
661
681
  sql = "SELECT * FROM statistics WHERE degree = /*ctx[:degree]*/-5"
662
- @template = TwoWaySQL::Template.parse(sql, :preserve_eol => false)
682
+ @template = TwoWaySQL::Template.parse(sql)
663
683
  @ctx[:degree] = -10
664
684
  @result = @template.merge(@ctx)
665
685
  end
@@ -677,7 +697,7 @@ describe TwoWaySQL::Template do
677
697
  describe "quote escape, such as 'Let''s' " do
678
698
  before do
679
699
  sql = "SELECT * FROM comments WHERE message = /*ctx[:message]*/'Let''s GO'"
680
- @template = TwoWaySQL::Template.parse(sql, :preserve_eol => false)
700
+ @template = TwoWaySQL::Template.parse(sql)
681
701
  @ctx[:message] = "Hang'in there"
682
702
  @result = @template.merge(@ctx)
683
703
  end
@@ -698,7 +718,7 @@ describe TwoWaySQL::Template do
698
718
  describe "when parsed from 'SELECT * FROM emp -- comments here'" do
699
719
  before do
700
720
  sql = "SELECT * FROM emp -- comments here"
701
- @template = TwoWaySQL::Template.parse(sql, :preserve_eol => false)
721
+ @template = TwoWaySQL::Template.parse(sql)
702
722
  end
703
723
 
704
724
  describe "and when 'job' param does not exist" do
@@ -718,7 +738,7 @@ describe TwoWaySQL::Template do
718
738
  describe "when parsed from 'SELECT * FROM emp WHERE empno = /*ctx[:empno]*/5.0 AND 1 = 1'" do
719
739
  before do
720
740
  sql = "SELECT * FROM emp WHERE empno = /*ctx[:empno]*/5.0 AND 1 = 1"
721
- @template = TwoWaySQL::Template.parse(sql, :preserve_eol => false)
741
+ @template = TwoWaySQL::Template.parse(sql)
722
742
 
723
743
  @ctx[:empno] = 7788
724
744
  @result = @template.merge(@ctx)
@@ -733,4 +753,165 @@ describe TwoWaySQL::Template do
733
753
  end
734
754
  end
735
755
 
756
+
757
+
758
+ describe "space compaction mode" do
759
+ describe "compaction of space node" do
760
+ before do
761
+ sql = <<-EOS
762
+ SELECT
763
+ *
764
+ FROM
765
+ emp
766
+ WHERE
767
+ job = /*ctx[:job]*/'CLERK'
768
+ AND deptno = /*ctx[:deptno]*/10
769
+ EOS
770
+ @template = TwoWaySQL::Template.parse(sql, :preserve_space => false)
771
+ @ctx[:job] = 'MANAGER'
772
+ @ctx[:deptno] = 30
773
+ @result = @template.merge(@ctx)
774
+ end
775
+
776
+ it do
777
+ @result.sql.should == "SELECT * FROM emp WHERE job = ? AND deptno = ? "
778
+ @result.bound_variables.should == ["MANAGER", 30]
779
+ end
780
+ end
781
+
782
+ describe "treat line end as one space" do
783
+ before do
784
+ sql = <<-EOS
785
+ SELECT
786
+ *
787
+ FROM
788
+ emp
789
+ WHERE
790
+ job = /*ctx[:job]*/'CLERK'
791
+ AND deptno = /*ctx[:deptno]*/10
792
+ EOS
793
+ @template = TwoWaySQL::Template.parse(sql, :preserve_space => false)
794
+ @ctx[:job] = 'MANAGER'
795
+ @ctx[:deptno] = 30
796
+ @result = @template.merge(@ctx)
797
+ end
798
+
799
+ it do
800
+ @result.sql.should == "SELECT * FROM emp WHERE job = ? AND deptno = ? "
801
+ @result.bound_variables.should == ["MANAGER", 30]
802
+ end
803
+ end
804
+
805
+ describe ":preserve_space => false, :preserve_comment => false" do
806
+ before do
807
+ sql = <<-EOS
808
+ SELECT
809
+ *
810
+ FROM
811
+ emp
812
+ /*
813
+ This is
814
+ multiline comment
815
+ */
816
+ WHERE
817
+ job = /*ctx[:job]*/'CLERK'
818
+ AND deptno = /*ctx[:deptno]*/10
819
+ EOS
820
+ @template = TwoWaySQL::Template.parse(sql, :preserve_space => false, :preserve_comment => false)
821
+ @ctx[:job] = 'MANAGER'
822
+ @ctx[:deptno] = 30
823
+ @result = @template.merge(@ctx)
824
+ end
825
+
826
+ it "handle multiline comment then ignore it if @preserve_comment is falsy" do
827
+ @result.sql.should == "SELECT * FROM emp WHERE job = ? AND deptno = ? "
828
+ @result.bound_variables.should == ["MANAGER", 30]
829
+ end
830
+ end
831
+
832
+ end
833
+
834
+
835
+
836
+ describe "multiline actual comment" do
837
+
838
+ describe ":preserve_comment => false" do
839
+ before do
840
+ sql = <<-EOS
841
+ SELECT
842
+ *
843
+ FROM
844
+ emp
845
+ /*
846
+ This is
847
+ multiline comment
848
+ */
849
+ WHERE
850
+ job = /*ctx[:job]*/'CLERK'
851
+ AND deptno = /*ctx[:deptno]*/10
852
+ EOS
853
+ @template = TwoWaySQL::Template.parse(sql, :preserve_comment => false)
854
+ @ctx[:job] = 'MANAGER'
855
+ @ctx[:deptno] = 30
856
+ @result = @template.merge(@ctx)
857
+ end
858
+
859
+ it "handle multiline comment then remove it if @preserve_comment is falsy" do
860
+ expected = <<-EOS
861
+ SELECT
862
+ *
863
+ FROM
864
+ emp
865
+
866
+ WHERE
867
+ job = ?
868
+ AND deptno = ?
869
+ EOS
870
+ @result.sql.should == expected
871
+ @result.bound_variables.should == ["MANAGER", 30]
872
+ end
873
+ end
874
+
875
+ describe ":preserve_comment => true" do
876
+ before do
877
+ sql = <<-EOS
878
+ SELECT
879
+ *
880
+ FROM
881
+ emp
882
+ /*
883
+ This is
884
+ multiline comment
885
+ */
886
+ WHERE
887
+ job = /*ctx[:job]*/'CLERK'
888
+ AND deptno = /*ctx[:deptno]*/10
889
+ EOS
890
+ @template = TwoWaySQL::Template.parse(sql, :preserve_comment => true)
891
+ @ctx[:job] = 'MANAGER'
892
+ @ctx[:deptno] = 30
893
+ @result = @template.merge(@ctx)
894
+ end
895
+
896
+ it "handle multiline comment then preserve it if @preserve_comment is truthy" do
897
+ expected = <<-EOS
898
+ SELECT
899
+ *
900
+ FROM
901
+ emp
902
+ /*
903
+ This is
904
+ multiline comment
905
+ */
906
+ WHERE
907
+ job = ?
908
+ AND deptno = ?
909
+ EOS
910
+ @result.sql.should == expected
911
+ @result.bound_variables.should == ["MANAGER", 30]
912
+ end
913
+ end
914
+ end
915
+
916
+
736
917
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twowaysql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takuto Wada
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-09-08 00:00:00 +09:00
12
+ date: 2008-09-10 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -42,16 +42,21 @@ files:
42
42
  - Rakefile
43
43
  - config/hoe.rb
44
44
  - config/requirements.rb
45
+ - issues/issue-001c53236380a42cd8c5a9099bbcc6ec613919c2.yaml
45
46
  - issues/issue-1cee7e821865a216674832b0186bd92792680571.yaml
46
47
  - issues/issue-25efcfc383f3b0f6c0e2730ae7c2975bb2b3de26.yaml
48
+ - issues/issue-279105dd0d9f03514d318f5eab5e99c4c2d47fda.yaml
49
+ - issues/issue-28cde89ed3eb306957edc90595b1d16bf43daf42.yaml
47
50
  - issues/issue-39023ea09e17e2d64bcef03aa59cdfe38b78ad5b.yaml
48
51
  - issues/issue-4bc308d55ae91f266e656162a4147d356de1166c.yaml
49
52
  - issues/issue-5c973ef5bb074eacca0c6c84f7d27c4267773ea8.yaml
50
53
  - issues/issue-664986b219202ff1948cab717b56e7540f493561.yaml
54
+ - issues/issue-6daccddf089d11d42bf016897da98f70cf5ab46c.yaml
51
55
  - issues/issue-897995fa10377eabdf597e8e7692f17087c76923.yaml
52
56
  - issues/issue-901f65630639507c8b05b466790e9f22256c6450.yaml
53
57
  - issues/issue-bd38c1cdc965d73dd629a81db2de1bcdcf4b10b8.yaml
54
58
  - issues/issue-dca4b19aa13de59838b33e03252bf824670a2d12.yaml
59
+ - issues/issue-f1bd40de5458397d9b142ea3e197e5264e0dcdbf.yaml
55
60
  - issues/issue-f2b773020b54f839c03d899b38b5113c8fd991df.yaml
56
61
  - issues/issue-f39b907d01d7fa93df8c7a9de2e1b5e27727ee0a.yaml
57
62
  - issues/issue-f64d73ed4f9854f1ded77e6496dbf59cfb3770a7.yaml