erbse 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGES.txt +828 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.md +51 -0
  5. data/benchmark/Makefile +6 -0
  6. data/benchmark/bench.rb +313 -0
  7. data/benchmark/bench_context.yaml +141 -0
  8. data/benchmark/templates/_footer.html +4 -0
  9. data/benchmark/templates/_header.html +52 -0
  10. data/benchmark/templates/bench_erb.rhtml +29 -0
  11. data/benchmark/templates/bench_erubis.rhtml +29 -0
  12. data/benchmark/templates/bench_eruby.rhtml +29 -0
  13. data/bin/erubis +10 -0
  14. data/erbse.gemspec +24 -0
  15. data/lib/erbse.rb +52 -0
  16. data/lib/erbse/context.rb +83 -0
  17. data/lib/erbse/converter.rb +357 -0
  18. data/lib/erbse/engine.rb +114 -0
  19. data/lib/erbse/engine/ec.rb +117 -0
  20. data/lib/erbse/engine/ecpp.rb +113 -0
  21. data/lib/erbse/engine/ejava.rb +110 -0
  22. data/lib/erbse/engine/ejavascript.rb +119 -0
  23. data/lib/erbse/engine/enhanced.rb +126 -0
  24. data/lib/erbse/engine/eperl.rb +95 -0
  25. data/lib/erbse/engine/ephp.rb +99 -0
  26. data/lib/erbse/engine/eruby.rb +119 -0
  27. data/lib/erbse/engine/escheme.rb +114 -0
  28. data/lib/erbse/engine/optimized.rb +127 -0
  29. data/lib/erbse/enhancer.rb +723 -0
  30. data/lib/erbse/error.rb +23 -0
  31. data/lib/erbse/evaluator.rb +88 -0
  32. data/lib/erbse/generator.rb +85 -0
  33. data/lib/erbse/helper.rb +47 -0
  34. data/lib/erbse/helpers/rails_form_helper.rb +197 -0
  35. data/lib/erbse/helpers/rails_helper.rb +353 -0
  36. data/lib/erbse/main.rb +516 -0
  37. data/lib/erbse/preprocessing.rb +58 -0
  38. data/lib/erbse/tiny.rb +144 -0
  39. data/lib/erbse/util.rb +22 -0
  40. data/lib/erbse/version.rb +3 -0
  41. data/test/assert-text-equal.rb +44 -0
  42. data/test/data/users-guide/Example.ejava +55 -0
  43. data/test/data/users-guide/array_example.result +9 -0
  44. data/test/data/users-guide/arraybuffer_example.result +9 -0
  45. data/test/data/users-guide/bipattern-example.rhtml +4 -0
  46. data/test/data/users-guide/bipattern_example.result +6 -0
  47. data/test/data/users-guide/bufvar-example.rb +10 -0
  48. data/test/data/users-guide/bufvar-example.result +17 -0
  49. data/test/data/users-guide/context.rb +6 -0
  50. data/test/data/users-guide/context.yaml +8 -0
  51. data/test/data/users-guide/def_method.rb +14 -0
  52. data/test/data/users-guide/def_method.result +3 -0
  53. data/test/data/users-guide/escape_example.result +9 -0
  54. data/test/data/users-guide/example.ec +27 -0
  55. data/test/data/users-guide/example.ecpp +30 -0
  56. data/test/data/users-guide/example.ejs +20 -0
  57. data/test/data/users-guide/example.eperl +18 -0
  58. data/test/data/users-guide/example.ephp +18 -0
  59. data/test/data/users-guide/example.eruby +6 -0
  60. data/test/data/users-guide/example.escheme +28 -0
  61. data/test/data/users-guide/example1.eruby +6 -0
  62. data/test/data/users-guide/example1.rb +17 -0
  63. data/test/data/users-guide/example1.result +16 -0
  64. data/test/data/users-guide/example10.rb +4 -0
  65. data/test/data/users-guide/example10.result +17 -0
  66. data/test/data/users-guide/example10.xhtml +14 -0
  67. data/test/data/users-guide/example10_x.result +17 -0
  68. data/test/data/users-guide/example11.php +20 -0
  69. data/test/data/users-guide/example11.result +23 -0
  70. data/test/data/users-guide/example11.rhtml +21 -0
  71. data/test/data/users-guide/example11_C.result +10 -0
  72. data/test/data/users-guide/example11_N.result +16 -0
  73. data/test/data/users-guide/example11_U.result +16 -0
  74. data/test/data/users-guide/example11_php.result +15 -0
  75. data/test/data/users-guide/example1_x.result +9 -0
  76. data/test/data/users-guide/example2.eruby +7 -0
  77. data/test/data/users-guide/example2.rb +10 -0
  78. data/test/data/users-guide/example2.result +27 -0
  79. data/test/data/users-guide/example2_trim.result +10 -0
  80. data/test/data/users-guide/example2_x.result +10 -0
  81. data/test/data/users-guide/example3.eruby +6 -0
  82. data/test/data/users-guide/example3.rb +10 -0
  83. data/test/data/users-guide/example31.result +22 -0
  84. data/test/data/users-guide/example32.result +4 -0
  85. data/test/data/users-guide/example3_e.result +8 -0
  86. data/test/data/users-guide/example4.eruby +3 -0
  87. data/test/data/users-guide/example4.rb +11 -0
  88. data/test/data/users-guide/example4.result +10 -0
  89. data/test/data/users-guide/example4_x.result +5 -0
  90. data/test/data/users-guide/example5.eruby +6 -0
  91. data/test/data/users-guide/example5.rb +16 -0
  92. data/test/data/users-guide/example5.result +7 -0
  93. data/test/data/users-guide/example6.rb +12 -0
  94. data/test/data/users-guide/example6.result +7 -0
  95. data/test/data/users-guide/example7.eruby +8 -0
  96. data/test/data/users-guide/example71.result +13 -0
  97. data/test/data/users-guide/example72.result +13 -0
  98. data/test/data/users-guide/example8.eruby +6 -0
  99. data/test/data/users-guide/example8_ruby.result +7 -0
  100. data/test/data/users-guide/example8_yaml.result +7 -0
  101. data/test/data/users-guide/example9.eruby +3 -0
  102. data/test/data/users-guide/example9.rb +8 -0
  103. data/test/data/users-guide/example9.result +9 -0
  104. data/test/data/users-guide/example91.result +5 -0
  105. data/test/data/users-guide/example92.result +4 -0
  106. data/test/data/users-guide/example_c.result +32 -0
  107. data/test/data/users-guide/example_java.result +56 -0
  108. data/test/data/users-guide/example_js.result +22 -0
  109. data/test/data/users-guide/example_perl.result +20 -0
  110. data/test/data/users-guide/example_php.result +19 -0
  111. data/test/data/users-guide/example_scheme.result +30 -0
  112. data/test/data/users-guide/example_scheme_display.result +29 -0
  113. data/test/data/users-guide/fasteruby-example.rb +8 -0
  114. data/test/data/users-guide/fasteruby-example.result +18 -0
  115. data/test/data/users-guide/fasteruby.rb +11 -0
  116. data/test/data/users-guide/fasteruby.result +38 -0
  117. data/test/data/users-guide/fasteruby.rhtml +15 -0
  118. data/test/data/users-guide/headerfooter-example.eruby +9 -0
  119. data/test/data/users-guide/headerfooter-example2.rb +8 -0
  120. data/test/data/users-guide/headerfooter-example2.rhtml +10 -0
  121. data/test/data/users-guide/headerfooter_example.result +11 -0
  122. data/test/data/users-guide/headerfooter_example2.result +13 -0
  123. data/test/data/users-guide/interpolation_example.result +9 -0
  124. data/test/data/users-guide/main_program1.rb +8 -0
  125. data/test/data/users-guide/main_program1.result +6 -0
  126. data/test/data/users-guide/main_program2.rb +8 -0
  127. data/test/data/users-guide/main_program2.result +6 -0
  128. data/test/data/users-guide/nocode-example.eruby +14 -0
  129. data/test/data/users-guide/nocode-php.result +20 -0
  130. data/test/data/users-guide/nocode_example.result +15 -0
  131. data/test/data/users-guide/normal-eruby-test.eruby +9 -0
  132. data/test/data/users-guide/normal_eruby_test.result +11 -0
  133. data/test/data/users-guide/notext-example.eruby +14 -0
  134. data/test/data/users-guide/notext-example.php +19 -0
  135. data/test/data/users-guide/notext-php.result +20 -0
  136. data/test/data/users-guide/notext_example.result +16 -0
  137. data/test/data/users-guide/percentline-example.rhtml +6 -0
  138. data/test/data/users-guide/percentline_example.result +9 -0
  139. data/test/data/users-guide/prefixedline-example.rb +9 -0
  140. data/test/data/users-guide/prefixedline-example.rhtml +6 -0
  141. data/test/data/users-guide/prefixedline_example.result +9 -0
  142. data/test/data/users-guide/printenable_example.result +4 -0
  143. data/test/data/users-guide/printenabled-example.eruby +3 -0
  144. data/test/data/users-guide/printenabled-example.rb +8 -0
  145. data/test/data/users-guide/printstatement_example.result +8 -0
  146. data/test/data/users-guide/simplify_example.result +9 -0
  147. data/test/data/users-guide/stderr.log +3 -0
  148. data/test/data/users-guide/stdout_exmple.result +9 -0
  149. data/test/data/users-guide/stringbuffer_example.result +9 -0
  150. data/test/data/users-guide/tail_260.result +4 -0
  151. data/test/data/users-guide/tailnewline.rhtml +3 -0
  152. data/test/data/users-guide/template1.rhtml +4 -0
  153. data/test/data/users-guide/template2.rhtml +4 -0
  154. data/test/test-engines.rb +425 -0
  155. data/test/test-enhancers.rb +646 -0
  156. data/test/test-erubis.rb +887 -0
  157. data/test/test-index-cgi.rb +191 -0
  158. data/test/test-main.rb +752 -0
  159. data/test/test-users-guide.rb +73 -0
  160. data/test/test.rb +45 -0
  161. data/test/testutil.rb +111 -0
  162. metadata +233 -0
@@ -0,0 +1,887 @@
1
+ ##
2
+ ## $Release: 2.7.0 $
3
+ ## copyright(c) 2006-2011 kuwata-lab.com all rights reserved.
4
+ ##
5
+
6
+ require "#{File.dirname(__FILE__)}/test.rb"
7
+
8
+ require 'stringio'
9
+
10
+ require 'erubis'
11
+ require 'erubis/engine/enhanced'
12
+ require 'erubis/engine/optimized'
13
+ require 'erubis/tiny'
14
+
15
+
16
+ class ErubisTest < Test::Unit::TestCase
17
+
18
+ testdata_list = load_yaml_datafile(__FILE__)
19
+ define_testmethods(testdata_list)
20
+
21
+
22
+ def _test()
23
+ @src.gsub!(/\^/, ' ')
24
+ @output.gsub!(/\^/, ' ') if @output.is_a?(String)
25
+ if @class
26
+ k = Erubis
27
+ @class.split('::').each do |name| k = k.const_get(name) end
28
+ @klass = k
29
+ else
30
+ @klass = Erubis::Eruby
31
+ end
32
+ @options ||= {}
33
+ @chomp.each do |target|
34
+ case target
35
+ when 'src' ; @src.chomp!
36
+ when 'input' ; @input.chomp!
37
+ when 'expected' ; @expected.chomp!
38
+ else
39
+ raise "#{@name}: invalid chomp value: #{@chomp.inspect}"
40
+ end
41
+ end if @chomp
42
+
43
+ if @testopt == 'load_file'
44
+ filename = "tmp.#{@name}.eruby"
45
+ begin
46
+ File.open(filename, 'w') { |f| f.write(@input) }
47
+ eruby = @klass.load_file(filename, @options)
48
+ ensure
49
+ cachename = filename + '.cache'
50
+ File.unlink(cachename) if test(?f, cachename)
51
+ File.unlink(filename) if test(?f, filename)
52
+ end
53
+ else
54
+ if @klass == Erubis::TinyEruby
55
+ eruby = @klass.new(@input)
56
+ else
57
+ eruby = @klass.new(@input, @options)
58
+ end
59
+ end
60
+ assert_text_equal(@src, eruby.src)
61
+
62
+ return if @testopt == 'skip_output'
63
+
64
+ list = ['<aaa>', 'b&b', '"ccc"']
65
+ context = @testopt == 'context' ? Erubis::Context.new : {}
66
+ context[:list] = list
67
+
68
+ case @testopt
69
+ when /\Aeval\(/
70
+ eval eruby.src
71
+ actual = eval @testopt
72
+ assert_text_equal(@output, actual)
73
+ when 'stdout', 'print'
74
+ begin
75
+ orig = $stdout
76
+ $stdout = stringio = StringIO.new
77
+ #actual = eruby.evaluate(context)
78
+ actual = eruby.result(context)
79
+ ensure
80
+ $stdout = orig
81
+ end
82
+ if @testopt == 'stdout'
83
+ assert_equal("", actual)
84
+ else
85
+ assert_nil(actual)
86
+ end
87
+ assert_text_equal(@output, stringio.string)
88
+ when 'evaluate', 'context'
89
+ actual = eruby.evaluate(context)
90
+ assert_text_equal(@output, actual)
91
+ when 'binding'
92
+ actual = eruby.result(binding())
93
+ assert_text_equal(@output, actual)
94
+ else
95
+ actual = eruby.result(context)
96
+ assert_text_equal(@output, actual)
97
+ end
98
+ end
99
+
100
+
101
+ def test_load_file_cache1
102
+ @input = <<END
103
+ <ul>
104
+ <% for item in @list %>
105
+ <li><%= item %></li>
106
+ <% end %>
107
+ </ul>
108
+ END
109
+ @src = <<END
110
+ _buf = ''; _buf << '<ul>
111
+ '; for item in @list
112
+ _buf << ' <li>'; _buf << ( item ).to_s; _buf << '</li>
113
+ '; end
114
+ _buf << '</ul>
115
+ ';
116
+ _buf.to_s
117
+ END
118
+ @klass = Erubis::Eruby
119
+ filename = 'tmp.load_file_timestamp1'
120
+ cachename = filename + '.cache'
121
+ begin
122
+ ## when cache doesn't exist then it is created automatically
123
+ File.open(filename, 'w') { |f| f.write(@input) }
124
+ mtime = Time.now - 2.0
125
+ File.utime(mtime, mtime, filename)
126
+ !test(?f, cachename) or raise "** failed"
127
+ engine = @klass.load_file(filename)
128
+ assert_block() { test(?f, cachename) }
129
+ assert_block() { File.mtime(filename) <= File.mtime(cachename) }
130
+ assert_text_equal(@src, engine.src)
131
+ ## when cache has different timestamp then it is recreated
132
+ input2 = @input.gsub(/ul>/, 'ol>')
133
+ src2 = @src.gsub(/ul>/, 'ol>')
134
+ File.open(filename, 'w') { |f| f.write(input2) }
135
+ t1 = Time.now()
136
+ sleep(1)
137
+ t2 = Time.now()
138
+ #
139
+ File.utime(t1, t1, filename)
140
+ File.utime(t2, t2, cachename)
141
+ File.mtime(filename) < File.mtime(cachename) or raise "** failed"
142
+ engine = @klass.load_file(filename)
143
+ assert_block('cache should have same timestamp') { File.mtime(filename) == File.mtime(cachename) }
144
+ #assert_text_equal(@src, engine.src)
145
+ assert_text_equal(src2, engine.src)
146
+ #
147
+ File.utime(t2, t2, filename)
148
+ File.utime(t1, t1, cachename)
149
+ File.mtime(filename) > File.mtime(cachename) or raise "** failed"
150
+ engine = @klass.load_file(filename)
151
+ assert_block('cache should have same timestamp') { File.mtime(filename) == File.mtime(cachename) }
152
+ assert_text_equal(src2, engine.src)
153
+ ensure
154
+ File.unlink(cachename) if File.file?(cachename)
155
+ File.unlink(filename) if File.file?(filename)
156
+ end
157
+ end
158
+
159
+
160
+ class Dummy
161
+ end
162
+
163
+ def _class_has_instance_method(klass, method)
164
+ return klass.instance_methods.collect{|m| m.to_s}.include?(method.to_s)
165
+ end
166
+
167
+ def test_def_method1
168
+ s = "<%for i in list%>i=<%=i%>\n<%end%>"
169
+ eruby = Erubis::Eruby.new(s)
170
+ assert(! _class_has_instance_method(Dummy, 'render'))
171
+ eruby.def_method(Dummy, 'render(list)', 'foo.rhtml')
172
+ assert(_class_has_instance_method(Dummy, 'render'))
173
+ actual = Dummy.new().render(%w[1 2 3])
174
+ assert_equal("i=1\ni=2\ni=3\n", actual)
175
+ end
176
+
177
+ def test_def_method2
178
+ s = "<%for i in list%>i=<%=i%>\n<%end%>"
179
+ eruby = Erubis::Eruby.new(s)
180
+ assert(! (eruby.respond_to? :render))
181
+ eruby.def_method(eruby, 'render(list)', 'foo.rhtml')
182
+ assert eruby.respond_to?(:render)
183
+ actual = eruby.render([1, 2, 3])
184
+ assert_equal("i=1\ni=2\ni=3\n", actual)
185
+ assert(! _class_has_instance_method(eruby.class, 'render'))
186
+ end
187
+
188
+ def test_evaluate_creates_proc
189
+ s = "hello <%= @name %>"
190
+ eruby = Erubis::Eruby.new(s)
191
+ assert_nil(eruby.instance_variable_get('@_proc'))
192
+ actual1 = eruby.evaluate(:name=>'world')
193
+ assert_not_nil(eruby.instance_variable_get('@_proc'))
194
+ assert_instance_of(Proc, eruby.instance_variable_get('@_proc'))
195
+ actual2 = eruby.evaluate(:name=>'world')
196
+ assert_equal(actual1, actual2)
197
+ # convert() must clear @_proc
198
+ eruby.convert(s)
199
+ assert_nil(eruby.instance_variable_get('@_proc'))
200
+ end
201
+
202
+ #def test_toplevel_binding
203
+ # s = "locals = <%= local_variables().inspect %>\n<% x = 50 %>\n"
204
+ # eruby = Erubis::Eruby.new(s)
205
+ # _x = eval 'x', TOPLEVEL_BINDING
206
+ # _y = eval 'y', TOPLEVEL_BINDING
207
+ # actual = eruby.evaluate(:x=>_x, :y=>_y)
208
+ # _x = eval 'x', TOPLEVEL_BINDING
209
+ # _y = eval 'y', TOPLEVEL_BINDING
210
+ # puts "*** actual=#{actual.inspect}, x=#{_x.inspect}, y=#{_y.inspect}"
211
+ #end
212
+
213
+ self.post_definition()
214
+
215
+ end
216
+
217
+ x = 10
218
+ y = 20
219
+
220
+
221
+ __END__
222
+ - name: basic1
223
+ input: &basic1_input|
224
+ <ul>
225
+ <% for item in list %>
226
+ <li><%= item %></li>
227
+ <% end %>
228
+ </ul>
229
+ src: &basic1_src|
230
+ _buf = ''; _buf << '<ul>
231
+ '; for item in list
232
+ _buf << ' <li>'; _buf << ( item ).to_s; _buf << '</li>
233
+ '; end
234
+ _buf << '</ul>
235
+ ';
236
+ _buf.to_s
237
+ output: &basic1_output|
238
+ <ul>
239
+ <li><aaa></li>
240
+ <li>b&b</li>
241
+ <li>"ccc"</li>
242
+ </ul>
243
+
244
+ ##
245
+ - name: basic2
246
+ input: |
247
+ <ul>
248
+ <% i = 0
249
+ for item in list
250
+ i += 1
251
+ %>
252
+ <li><%= item %></li>
253
+ <% end %>
254
+ </ul>
255
+ src: |
256
+ _buf = ''; _buf << '<ul>
257
+ '; i = 0
258
+ for item in list
259
+ i += 1
260
+ ^^^
261
+ _buf << ' <li>'; _buf << ( item ).to_s; _buf << '</li>
262
+ '; end
263
+ _buf << '</ul>
264
+ ';
265
+ _buf.to_s
266
+ output: *basic1_output
267
+ # <ul>
268
+ # <li><aaa></li>
269
+ # <li>b&b</li>
270
+ # <li>"ccc"</li>
271
+ # </ul>
272
+
273
+ ##
274
+ - name: basic3
275
+ input: |
276
+ <ul><% i = 0
277
+ for item in list
278
+ i += 1 %><li><%= item %></li><% end %>
279
+ </ul>
280
+ src: |
281
+ _buf = ''; _buf << '<ul>'; i = 0
282
+ for item in list
283
+ i += 1 ; _buf << '<li>'; _buf << ( item ).to_s; _buf << '</li>'; end ; _buf << '
284
+ '; _buf << '</ul>
285
+ ';
286
+ _buf.to_s
287
+ output: |
288
+ <ul><li><aaa></li><li>b&b</li><li>"ccc"</li>
289
+ </ul>
290
+
291
+ ##
292
+ - name: context1
293
+ testopt: context
294
+ input: |
295
+ <ul>
296
+ <% for item in @list %>
297
+ <li><%= item %></li>
298
+ <% end %>
299
+ </ul>
300
+ src: |
301
+ _buf = ''; _buf << '<ul>
302
+ '; for item in @list
303
+ _buf << ' <li>'; _buf << ( item ).to_s; _buf << '</li>
304
+ '; end
305
+ _buf << '</ul>
306
+ ';
307
+ _buf.to_s
308
+ output: *basic1_output
309
+
310
+ ##
311
+ - name: ignore1
312
+ input: |
313
+ <ul>
314
+ <%# i = 0 %>
315
+ <% for item in list %>
316
+ <%#
317
+ i += 1
318
+ color = i % 2 == 0 ? '#FFCCCC' : '#CCCCFF'
319
+ %>
320
+ <li> <%#= i %> : <%= item %> </li>
321
+ <% end %>
322
+ </ul>
323
+ src: |
324
+ _buf = ''; _buf << '<ul>
325
+ ';
326
+ for item in list
327
+
328
+
329
+
330
+
331
+ _buf << ' <li> ';; _buf << ' : '; _buf << ( item ).to_s; _buf << ' </li>
332
+ '; end
333
+ _buf << '</ul>
334
+ ';
335
+ _buf.to_s
336
+ output: |
337
+ <ul>
338
+ <li> : <aaa> </li>
339
+ <li> : b&b </li>
340
+ <li> : "ccc" </li>
341
+ </ul>
342
+
343
+ ##
344
+ - name: quotation1
345
+ desc: single quotation and backslash
346
+ class: Eruby
347
+ input: &quotation1_input|
348
+ a = "'"
349
+ b = "\""
350
+ c = '\''
351
+ src: |
352
+ _buf = ''; _buf << 'a = "\'"
353
+ b = "\\""
354
+ c = \'\\\'\'
355
+ ';
356
+ _buf.to_s
357
+ output: *quotation1_input
358
+
359
+ ##
360
+ - name: minus1
361
+ desc: '<%- -%>'
362
+ class: Eruby
363
+ input: |
364
+ <ul>
365
+ <%- for item in list -%>
366
+ <li><%= item -%></li>
367
+ <% end -%>
368
+ </ul>
369
+ src: *basic1_src
370
+ output: *basic1_output
371
+
372
+ ##
373
+ - name: pattern1
374
+ options:
375
+ :pattern : '\[@ @\]'
376
+ input: |
377
+ <ul>
378
+ [@ for item in list @]
379
+ <li>[@= item @]</li>
380
+ [@ end @]
381
+ </ul>
382
+ src: |
383
+ _buf = ''; _buf << '<ul>
384
+ '; for item in list
385
+ _buf << ' <li>'; _buf << ( item ).to_s; _buf << '</li>
386
+ '; end
387
+ _buf << '</ul>
388
+ ';
389
+ _buf.to_s
390
+ output: *basic1_output
391
+ # <ul>
392
+ # <li><aaa></li>
393
+ # <li>b&b</li>
394
+ # <li>"ccc"</li>
395
+ # </ul>
396
+
397
+ ##
398
+ - name: pattern2
399
+ options:
400
+ :pattern : '<(?:!--)?% %(?:--)?>'
401
+ input: |
402
+ <ul>
403
+ <!--% for item in list %-->
404
+ <li><%= item %></li>
405
+ <!--% end %-->
406
+ </ul>
407
+ src: |
408
+ _buf = ''; _buf << '<ul>
409
+ '; for item in list
410
+ _buf << ' <li>'; _buf << ( item ).to_s; _buf << '</li>
411
+ '; end
412
+ _buf << '</ul>
413
+ ';
414
+ _buf.to_s
415
+ output: *basic1_output
416
+ # <ul>
417
+ # <li><aaa></li>
418
+ # <li>b&b</li>
419
+ # <li>"ccc"</li>
420
+ # </ul>
421
+
422
+ ##
423
+ - name: trim1
424
+ options:
425
+ :trim : false
426
+ input: *basic1_input
427
+ # <ul>
428
+ # <% for item in list %>
429
+ # <li><%= item %></li>
430
+ # <% end %>
431
+ # </ul>
432
+ src: |
433
+ _buf = ''; _buf << '<ul>
434
+ '; _buf << ' '; for item in list ; _buf << '
435
+ '; _buf << ' <li>'; _buf << ( item ).to_s; _buf << '</li>
436
+ '; _buf << ' '; end ; _buf << '
437
+ '; _buf << '</ul>
438
+ ';
439
+ _buf.to_s
440
+ output: |
441
+ <ul>
442
+ ^
443
+ <li><aaa></li>
444
+ ^
445
+ <li>b&b</li>
446
+ ^
447
+ <li>"ccc"</li>
448
+ ^
449
+ </ul>
450
+
451
+ ##
452
+ - name: bodyonly1
453
+ testopt: skip_output
454
+ options: { :preamble: no, :postamble: no }
455
+ input: *basic1_input
456
+ src: |4
457
+ _buf << '<ul>
458
+ '; for item in list
459
+ _buf << ' <li>'; _buf << ( item ).to_s; _buf << '</li>
460
+ '; end
461
+ _buf << '</ul>
462
+ ';
463
+ chomp: [src]
464
+ expected: null
465
+
466
+ ##
467
+ - name: loadfile1
468
+ testopt: load_file
469
+ #input: |
470
+ # <ul>
471
+ # <% for item in list %>
472
+ # <li><%= item %></li>
473
+ # <% end %>
474
+ # </ul>
475
+ input:
476
+ "<ul>\r\n <% for item in list %>\r\n <li><%= item %></li>\r\n <% end %>\r\n</ul>\r\n"
477
+ #src: |
478
+ # _buf = ''; _buf << "<ul>\n"
479
+ # for item in list
480
+ # _buf << " <li>"; _buf << ( item ).to_s; _buf << "</li>\n"
481
+ # end
482
+ # _buf << "</ul>\n"
483
+ # _buf
484
+ src:
485
+ "_buf = ''; _buf << '<ul>\r\n'; for item in list \r\n _buf << ' <li>'; _buf << ( item ).to_s; _buf << '</li>\r\n'; end \r\n _buf << '</ul>\r\n';\n_buf.to_s\n"
486
+ #output: |
487
+ # <ul>
488
+ # <li><aaa></li>
489
+ # <li>b&b</li>
490
+ # <li>"ccc"</li>
491
+ # </ul>
492
+ output:
493
+ "<ul>\n <li><aaa></li>\n <li>b&b</li>\n <li>\"ccc\"</li>\n</ul>\n"
494
+ # "<ul>\r\n <li><aaa></li>\r\n <li>b&b</li>\r\n <li>\"ccc\"</li>\r\n</ul>\r\n"
495
+
496
+ ##
497
+ - name: nomatch1
498
+ desc: bug
499
+ input: &nomatch1|
500
+ <ul>
501
+ <li>foo</li>
502
+ </ul>
503
+ src: |
504
+ _buf = ''; _buf << '<ul>
505
+ <li>foo</li>
506
+ </ul>
507
+ ';
508
+ _buf.to_s
509
+ output: *nomatch1
510
+
511
+ ##
512
+ - name: escape1
513
+ options: { :escape: true }
514
+ input: |
515
+ <% str = '<>&"' %>
516
+ <%= str %>
517
+ <%== str %>
518
+ src: |
519
+ _buf = ''; str = '<>&"'
520
+ _buf << Erubis::XmlHelper.escape_xml( str ); _buf << '
521
+ '; _buf << ( str ).to_s; _buf << '
522
+ ';
523
+ _buf.to_s
524
+ output: |
525
+ &lt;&gt;&amp;&quot;
526
+ <>&"
527
+
528
+ ##
529
+ - name: tailch1
530
+ options:
531
+ input: |
532
+ <p>
533
+ <% str = '<>&"' %>
534
+ <%= str %>
535
+ <%= str =%>
536
+ <%= str -%>
537
+ </p>
538
+ src: |
539
+ _buf = ''; _buf << '<p>
540
+ '; str = '<>&"'
541
+ _buf << ' '; _buf << ( str ).to_s; _buf << '
542
+ '; _buf << ' '; _buf << ( str ).to_s; _buf << ' '; _buf << ( str ).to_s; _buf << '</p>
543
+ ';
544
+ _buf.to_s
545
+ output: |
546
+ <p>
547
+ <>&"
548
+ <>&" <>&"</p>
549
+
550
+ ##
551
+ - name: doublepercent1
552
+ options:
553
+ input: |
554
+ <% x1 = 10 %>
555
+ <%% x2 = 20 %>
556
+ <%= x1 %>
557
+ <%%= x2 %>
558
+ src: |
559
+ _buf = ''; x1 = 10
560
+ _buf << '<% x2 = 20 %>
561
+ '; _buf << ( x1 ).to_s; _buf << '
562
+ '; _buf << '<%= x2 %>
563
+ ';
564
+ _buf.to_s
565
+ output: |
566
+ <% x2 = 20 %>
567
+ 10
568
+ <%= x2 %>
569
+
570
+ ##
571
+ - name: optimized1
572
+ class: OptimizedEruby
573
+ input: &optimized1_input|
574
+ <table>
575
+ <% for item in list %>
576
+ <tr>
577
+ <td><%= item %></td>
578
+ <td><%== item %></td>
579
+ </tr>
580
+ <% end %>
581
+ </table>
582
+ <ul><% for item in list %><li><%= item %></li><% end %></ul>
583
+ src: |
584
+ _buf = '<table>
585
+ '; for item in list
586
+ _buf << ' <tr>
587
+ <td>' << ( item ).to_s << '</td>
588
+ <td>' << Erubis::XmlHelper.escape_xml( item ) << '</td>
589
+ </tr>
590
+ '; end
591
+ _buf << '</table>
592
+ <ul>'; for item in list ; _buf << '<li>' << ( item ).to_s << '</li>'; end ; _buf << '</ul>
593
+ '
594
+ _buf
595
+ output: |
596
+ <table>
597
+ <tr>
598
+ <td><aaa></td>
599
+ <td>&lt;aaa&gt;</td>
600
+ </tr>
601
+ <tr>
602
+ <td>b&b</td>
603
+ <td>b&amp;b</td>
604
+ </tr>
605
+ <tr>
606
+ <td>"ccc"</td>
607
+ <td>&quot;ccc&quot;</td>
608
+ </tr>
609
+ </table>
610
+ <ul><li><aaa></li><li>b&b</li><li>"ccc"</li></ul>
611
+
612
+ ##
613
+ - name: optimized2
614
+ class: OptimizedXmlEruby
615
+ input: *optimized1_input
616
+ # <table>
617
+ # <% for item in list %>
618
+ # <tr>
619
+ # <td><%= item %></td>
620
+ # <td><%== item %></td>
621
+ # </tr>
622
+ # <% end %>
623
+ # </table>
624
+ # <ul><% for item in list %><li><%= item %></li><% end %></ul>
625
+ src: |
626
+ _buf = '<table>
627
+ '; for item in list
628
+ _buf << ' <tr>
629
+ <td>' << Erubis::XmlHelper.escape_xml( item ) << '</td>
630
+ <td>' << ( item ).to_s << '</td>
631
+ </tr>
632
+ '; end
633
+ _buf << '</table>
634
+ <ul>'; for item in list ; _buf << '<li>' << Erubis::XmlHelper.escape_xml( item ) << '</li>'; end ; _buf << '</ul>
635
+ '
636
+ _buf
637
+ output: |
638
+ <table>
639
+ <tr>
640
+ <td>&lt;aaa&gt;</td>
641
+ <td><aaa></td>
642
+ </tr>
643
+ <tr>
644
+ <td>b&amp;b</td>
645
+ <td>b&b</td>
646
+ </tr>
647
+ <tr>
648
+ <td>&quot;ccc&quot;</td>
649
+ <td>"ccc"</td>
650
+ </tr>
651
+ </table>
652
+ <ul><li>&lt;aaa&gt;</li><li>b&amp;b</li><li>&quot;ccc&quot;</li></ul>
653
+
654
+ ##
655
+ - name: optimized3
656
+ desc: bug
657
+ class: OptimizedEruby
658
+ input: |
659
+ user = <%= "Foo" %>
660
+ <% for item in list %>
661
+ <%= item %>
662
+ <% end %>
663
+ src: |
664
+ _buf = 'user = '; _buf << ( "Foo" ).to_s << '
665
+ '; for item in list
666
+ _buf << ' ' << ( item ).to_s << '
667
+ '; end
668
+
669
+ _buf
670
+ output: |
671
+ user = Foo
672
+ <aaa>
673
+ b&b
674
+ "ccc"
675
+
676
+ ##
677
+ - name: optimized4
678
+ desc: single quotation and backslash
679
+ class: OptimizedEruby
680
+ input: &optimized4_input|
681
+ a = "'"
682
+ b = "\""
683
+ c = '\''
684
+ src: |
685
+ _buf = 'a = "\'"
686
+ b = "\\""
687
+ c = \'\\\'\'
688
+ ';
689
+ _buf
690
+ output: *optimized4_input
691
+
692
+ ##
693
+ - name: tiny1
694
+ class: TinyEruby
695
+ testopt: binding
696
+ input: |
697
+ <ul>
698
+ <% for item in list %>
699
+ <li><%= item %></li>
700
+ <% end %>
701
+ </ul>
702
+ src: |
703
+ _buf = ''; _buf << '<ul>
704
+ '; for item in list ; _buf << '
705
+ <li>'; _buf << ( item ).to_s; _buf << '</li>
706
+ '; end ; _buf << '
707
+ </ul>
708
+ ';
709
+ _buf.to_s
710
+ output: |
711
+ <ul>
712
+ ^
713
+ <li><aaa></li>
714
+ ^
715
+ <li>b&b</li>
716
+ ^
717
+ <li>"ccc"</li>
718
+ ^
719
+ </ul>
720
+
721
+ ##
722
+ - name: tiny2
723
+ class: TinyEruby
724
+ testopt: evaluate
725
+ input: |
726
+ <ul>
727
+ <% for item in @list %>
728
+ <li><%= item %></li>
729
+ <% end %>
730
+ </ul>
731
+ src: |
732
+ _buf = ''; _buf << '<ul>
733
+ '; for item in @list ; _buf << '
734
+ <li>'; _buf << ( item ).to_s; _buf << '</li>
735
+ '; end ; _buf << '
736
+ </ul>
737
+ ';
738
+ _buf.to_s
739
+ output: |
740
+ <ul>
741
+ ^
742
+ <li><aaa></li>
743
+ ^
744
+ <li>b&b</li>
745
+ ^
746
+ <li>"ccc"</li>
747
+ ^
748
+ </ul>
749
+
750
+ ##
751
+ - name: pi1
752
+ class: PI::Eruby
753
+ testopt: evaluate
754
+ input: &input_pi1|
755
+ <ul>
756
+ <?rb for item in @list ?>
757
+ <li>@{item}@ / @!{item}@</li>
758
+ <li><%= item %> / <%== item %></li>
759
+ <?rb end ?>
760
+ </ul>
761
+ src: &src_pi1|
762
+ _buf = ''; _buf << '<ul>
763
+ '; for item in @list
764
+ _buf << ' <li>'; _buf << Erubis::XmlHelper.escape_xml(item); _buf << ' / '; _buf << (item).to_s; _buf << '</li>
765
+ <li>'; _buf << ( item ).to_s; _buf << ' / '; _buf << Erubis::XmlHelper.escape_xml( item ); _buf << '</li>
766
+ '; end
767
+ _buf << '</ul>
768
+ ';
769
+ _buf.to_s
770
+ output: &output_pi1|
771
+ <ul>
772
+ <li>&lt;aaa&gt; / <aaa></li>
773
+ <li><aaa> / &lt;aaa&gt;</li>
774
+ <li>b&amp;b / b&b</li>
775
+ <li>b&b / b&amp;b</li>
776
+ <li>&quot;ccc&quot; / "ccc"</li>
777
+ <li>"ccc" / &quot;ccc&quot;</li>
778
+ </ul>
779
+
780
+ ##
781
+ - name: pi2
782
+ class: PI::Eruby
783
+ options: { :escape: false }
784
+ testopt: evaluate
785
+ input: *input_pi1
786
+ src: |
787
+ _buf = ''; _buf << '<ul>
788
+ '; for item in @list
789
+ _buf << ' <li>'; _buf << (item).to_s; _buf << ' / '; _buf << Erubis::XmlHelper.escape_xml(item); _buf << '</li>
790
+ <li>'; _buf << Erubis::XmlHelper.escape_xml( item ); _buf << ' / '; _buf << ( item ).to_s; _buf << '</li>
791
+ '; end
792
+ _buf << '</ul>
793
+ ';
794
+ _buf.to_s
795
+ output: |
796
+ <ul>
797
+ <li><aaa> / &lt;aaa&gt;</li>
798
+ <li>&lt;aaa&gt; / <aaa></li>
799
+ <li>b&b / b&amp;b</li>
800
+ <li>b&amp;b / b&b</li>
801
+ <li>"ccc" / &quot;ccc&quot;</li>
802
+ <li>&quot;ccc&quot; / "ccc"</li>
803
+ </ul>
804
+
805
+ ##
806
+ - name: pi3
807
+ class: PI::Eruby
808
+ options: { :pi: hoge, :embchar: '$' }
809
+ testopt: evaluate
810
+ input: |
811
+ <ul>
812
+ <?hoge for item in @list ?>
813
+ <li>${item}$ / $!{item}$</li>
814
+ <li><%= item %> / <%== item %></li>
815
+ <?hoge end ?>
816
+ </ul>
817
+ src: *src_pi1
818
+ output: *output_pi1
819
+
820
+ - name: pi4
821
+ class: PI::Eruby
822
+ testopt: evaluate
823
+ input: |
824
+ <?rb-header
825
+ def show(list)
826
+ ?>
827
+ <ul>
828
+ <?rb for item in list ?>
829
+ <?rb-value item ?>
830
+ <?rb end ?>
831
+ <?rb-comment
832
+ # comment
833
+ # comment
834
+ ?>
835
+ </ul>
836
+ <?rb-footer
837
+ end
838
+ show(@list) ?>
839
+
840
+ src: |4
841
+
842
+ def show(list)
843
+
844
+ _buf = ''; _buf << '<ul>
845
+ '; for item in list
846
+ _buf << ( item
847
+ ).to_s; end
848
+
849
+
850
+
851
+
852
+ _buf << '</ul>
853
+ ';
854
+ _buf.to_s
855
+
856
+ end
857
+ show(@list)
858
+
859
+ output: |
860
+ <ul>
861
+ <aaa>b&b"ccc"</ul>
862
+
863
+
864
+ - name: pitiny1
865
+ class: PI::TinyEruby
866
+ testopt: evaluate
867
+ input: |
868
+ <ul>
869
+ <?rb for item in @list ?>
870
+ <li>@{item}@ / @!{item}@</li>
871
+ <?rb end ?>
872
+ </ul>
873
+ src: |
874
+ _buf = ''; _buf << '<ul>
875
+ '; for item in @list
876
+ _buf << ' <li>'; _buf << Erubis::XmlHelper.escape_xml(item); _buf << ' / '; _buf << (item).to_s; _buf << '</li>
877
+ '; end
878
+ _buf << '</ul>
879
+ ';
880
+ _buf.to_s
881
+ output: |
882
+ <ul>
883
+ <li>&lt;aaa&gt; / <aaa></li>
884
+ <li>b&amp;b / b&b</li>
885
+ <li>&quot;ccc&quot; / "ccc"</li>
886
+ </ul>
887
+