erbse 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (159) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +3 -0
  3. data/Gemfile +3 -0
  4. data/README.md +40 -22
  5. data/Rakefile +13 -0
  6. data/lib/erbse.rb +3 -6
  7. data/lib/erbse/converter.rb +41 -241
  8. data/lib/erbse/eruby.rb +114 -0
  9. data/lib/erbse/template.rb +14 -0
  10. data/lib/erbse/version.rb +1 -1
  11. data/test/erbse_test.rb +14 -0
  12. data/test/test_helper.rb +2 -0
  13. metadata +9 -149
  14. data/CHANGES.txt +0 -828
  15. data/bin/erubis +0 -10
  16. data/lib/erbse/context.rb +0 -83
  17. data/lib/erbse/engine.rb +0 -114
  18. data/lib/erbse/engine/ec.rb +0 -117
  19. data/lib/erbse/engine/ecpp.rb +0 -113
  20. data/lib/erbse/engine/ejava.rb +0 -110
  21. data/lib/erbse/engine/ejavascript.rb +0 -119
  22. data/lib/erbse/engine/enhanced.rb +0 -126
  23. data/lib/erbse/engine/eperl.rb +0 -95
  24. data/lib/erbse/engine/ephp.rb +0 -99
  25. data/lib/erbse/engine/eruby.rb +0 -119
  26. data/lib/erbse/engine/escheme.rb +0 -114
  27. data/lib/erbse/engine/optimized.rb +0 -127
  28. data/lib/erbse/enhancer.rb +0 -723
  29. data/lib/erbse/error.rb +0 -23
  30. data/lib/erbse/evaluator.rb +0 -88
  31. data/lib/erbse/generator.rb +0 -85
  32. data/lib/erbse/helper.rb +0 -47
  33. data/lib/erbse/helpers/rails_form_helper.rb +0 -197
  34. data/lib/erbse/helpers/rails_helper.rb +0 -353
  35. data/lib/erbse/main.rb +0 -516
  36. data/lib/erbse/preprocessing.rb +0 -58
  37. data/lib/erbse/tiny.rb +0 -144
  38. data/lib/erbse/util.rb +0 -22
  39. data/test/assert-text-equal.rb +0 -44
  40. data/test/data/users-guide/Example.ejava +0 -55
  41. data/test/data/users-guide/array_example.result +0 -9
  42. data/test/data/users-guide/arraybuffer_example.result +0 -9
  43. data/test/data/users-guide/bipattern-example.rhtml +0 -4
  44. data/test/data/users-guide/bipattern_example.result +0 -6
  45. data/test/data/users-guide/bufvar-example.rb +0 -10
  46. data/test/data/users-guide/bufvar-example.result +0 -17
  47. data/test/data/users-guide/context.rb +0 -6
  48. data/test/data/users-guide/context.yaml +0 -8
  49. data/test/data/users-guide/def_method.rb +0 -14
  50. data/test/data/users-guide/def_method.result +0 -3
  51. data/test/data/users-guide/escape_example.result +0 -9
  52. data/test/data/users-guide/example.ec +0 -27
  53. data/test/data/users-guide/example.ecpp +0 -30
  54. data/test/data/users-guide/example.ejs +0 -20
  55. data/test/data/users-guide/example.eperl +0 -18
  56. data/test/data/users-guide/example.ephp +0 -18
  57. data/test/data/users-guide/example.eruby +0 -6
  58. data/test/data/users-guide/example.escheme +0 -28
  59. data/test/data/users-guide/example1.eruby +0 -6
  60. data/test/data/users-guide/example1.rb +0 -17
  61. data/test/data/users-guide/example1.result +0 -16
  62. data/test/data/users-guide/example10.rb +0 -4
  63. data/test/data/users-guide/example10.result +0 -17
  64. data/test/data/users-guide/example10.xhtml +0 -14
  65. data/test/data/users-guide/example10_x.result +0 -17
  66. data/test/data/users-guide/example11.php +0 -20
  67. data/test/data/users-guide/example11.result +0 -23
  68. data/test/data/users-guide/example11.rhtml +0 -21
  69. data/test/data/users-guide/example11_C.result +0 -10
  70. data/test/data/users-guide/example11_N.result +0 -16
  71. data/test/data/users-guide/example11_U.result +0 -16
  72. data/test/data/users-guide/example11_php.result +0 -15
  73. data/test/data/users-guide/example1_x.result +0 -9
  74. data/test/data/users-guide/example2.eruby +0 -7
  75. data/test/data/users-guide/example2.rb +0 -10
  76. data/test/data/users-guide/example2.result +0 -27
  77. data/test/data/users-guide/example2_trim.result +0 -10
  78. data/test/data/users-guide/example2_x.result +0 -10
  79. data/test/data/users-guide/example3.eruby +0 -6
  80. data/test/data/users-guide/example3.rb +0 -10
  81. data/test/data/users-guide/example31.result +0 -22
  82. data/test/data/users-guide/example32.result +0 -4
  83. data/test/data/users-guide/example3_e.result +0 -8
  84. data/test/data/users-guide/example4.eruby +0 -3
  85. data/test/data/users-guide/example4.rb +0 -11
  86. data/test/data/users-guide/example4.result +0 -10
  87. data/test/data/users-guide/example4_x.result +0 -5
  88. data/test/data/users-guide/example5.eruby +0 -6
  89. data/test/data/users-guide/example5.rb +0 -16
  90. data/test/data/users-guide/example5.result +0 -7
  91. data/test/data/users-guide/example6.rb +0 -12
  92. data/test/data/users-guide/example6.result +0 -7
  93. data/test/data/users-guide/example7.eruby +0 -8
  94. data/test/data/users-guide/example71.result +0 -13
  95. data/test/data/users-guide/example72.result +0 -13
  96. data/test/data/users-guide/example8.eruby +0 -6
  97. data/test/data/users-guide/example8_ruby.result +0 -7
  98. data/test/data/users-guide/example8_yaml.result +0 -7
  99. data/test/data/users-guide/example9.eruby +0 -3
  100. data/test/data/users-guide/example9.rb +0 -8
  101. data/test/data/users-guide/example9.result +0 -9
  102. data/test/data/users-guide/example91.result +0 -5
  103. data/test/data/users-guide/example92.result +0 -4
  104. data/test/data/users-guide/example_c.result +0 -32
  105. data/test/data/users-guide/example_java.result +0 -56
  106. data/test/data/users-guide/example_js.result +0 -22
  107. data/test/data/users-guide/example_perl.result +0 -20
  108. data/test/data/users-guide/example_php.result +0 -19
  109. data/test/data/users-guide/example_scheme.result +0 -30
  110. data/test/data/users-guide/example_scheme_display.result +0 -29
  111. data/test/data/users-guide/fasteruby-example.rb +0 -8
  112. data/test/data/users-guide/fasteruby-example.result +0 -18
  113. data/test/data/users-guide/fasteruby.rb +0 -11
  114. data/test/data/users-guide/fasteruby.result +0 -38
  115. data/test/data/users-guide/fasteruby.rhtml +0 -15
  116. data/test/data/users-guide/headerfooter-example.eruby +0 -9
  117. data/test/data/users-guide/headerfooter-example2.rb +0 -8
  118. data/test/data/users-guide/headerfooter-example2.rhtml +0 -10
  119. data/test/data/users-guide/headerfooter_example.result +0 -11
  120. data/test/data/users-guide/headerfooter_example2.result +0 -13
  121. data/test/data/users-guide/interpolation_example.result +0 -9
  122. data/test/data/users-guide/main_program1.rb +0 -8
  123. data/test/data/users-guide/main_program1.result +0 -6
  124. data/test/data/users-guide/main_program2.rb +0 -8
  125. data/test/data/users-guide/main_program2.result +0 -6
  126. data/test/data/users-guide/nocode-example.eruby +0 -14
  127. data/test/data/users-guide/nocode-php.result +0 -20
  128. data/test/data/users-guide/nocode_example.result +0 -15
  129. data/test/data/users-guide/normal-eruby-test.eruby +0 -9
  130. data/test/data/users-guide/normal_eruby_test.result +0 -11
  131. data/test/data/users-guide/notext-example.eruby +0 -14
  132. data/test/data/users-guide/notext-example.php +0 -19
  133. data/test/data/users-guide/notext-php.result +0 -20
  134. data/test/data/users-guide/notext_example.result +0 -16
  135. data/test/data/users-guide/percentline-example.rhtml +0 -6
  136. data/test/data/users-guide/percentline_example.result +0 -9
  137. data/test/data/users-guide/prefixedline-example.rb +0 -9
  138. data/test/data/users-guide/prefixedline-example.rhtml +0 -6
  139. data/test/data/users-guide/prefixedline_example.result +0 -9
  140. data/test/data/users-guide/printenable_example.result +0 -4
  141. data/test/data/users-guide/printenabled-example.eruby +0 -3
  142. data/test/data/users-guide/printenabled-example.rb +0 -8
  143. data/test/data/users-guide/printstatement_example.result +0 -8
  144. data/test/data/users-guide/simplify_example.result +0 -9
  145. data/test/data/users-guide/stderr.log +0 -3
  146. data/test/data/users-guide/stdout_exmple.result +0 -9
  147. data/test/data/users-guide/stringbuffer_example.result +0 -9
  148. data/test/data/users-guide/tail_260.result +0 -4
  149. data/test/data/users-guide/tailnewline.rhtml +0 -3
  150. data/test/data/users-guide/template1.rhtml +0 -4
  151. data/test/data/users-guide/template2.rhtml +0 -4
  152. data/test/test-engines.rb +0 -425
  153. data/test/test-enhancers.rb +0 -646
  154. data/test/test-erubis.rb +0 -887
  155. data/test/test-index-cgi.rb +0 -191
  156. data/test/test-main.rb +0 -752
  157. data/test/test-users-guide.rb +0 -73
  158. data/test/test.rb +0 -45
  159. data/test/testutil.rb +0 -111
@@ -1,887 +0,0 @@
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
-