test/test-erubis.rb in erubis-2.0.1 vs test/test-erubis.rb in erubis-2.1.0
- old
+ new
@@ -1,8 +1,8 @@
##
-## $Rev: 21 $
-## $Release: 2.0.1 $
+## $Rev: 37 $
+## $Release: 2.1.0 $
## copyright(c) 2006 kuwata-lab all rights reserved.
##
require "#{File.dirname(__FILE__)}/test.rb"
@@ -13,20 +13,25 @@
require 'erubis/engine/optimized'
require 'erubis/tiny'
class ErubisTest < Test::Unit::TestCase
- extend TestEnhancer
- testdata_list = load_yaml_document(__FILE__)
+ testdata_list = load_yaml_datafile(__FILE__)
define_testmethods(testdata_list)
def _test()
@src.gsub!(/\^/, ' ')
@output.gsub!(/\^/, ' ') if @output.is_a?(String)
- @klass = @class ? Erubis.const_get(@class) : Erubis::Eruby
+ if @class
+ k = Erubis
+ @class.split('::').each do |name| k = k.const_get(name) end
+ @klass = k
+ else
+ @klass = Erubis::Eruby
+ end
@options ||= {}
@chomp.each do |target|
case target
when 'src' ; @src.chomp!
when 'input' ; @input.chomp!
@@ -51,18 +56,18 @@
File.unlink(filename) if test(?f, filename)
end
end
assert_text_equal(@src, eruby.src)
- return if @testopt == 'skip_bufput'
+ return if @testopt == 'skip_output'
list = ['<aaa>', 'b&b', '"ccc"']
context = @testopt == 'context' ? Erubis::Context.new : {}
context[:list] = list
case @testopt
- when/\Aeval\(/
+ when /\Aeval\(/
eval eruby.src
actual = eval @testopt
assert_text_equal(@output, actual)
when 'stdout', 'print'
begin
@@ -107,16 +112,17 @@
_buf << ' <li>'; _buf << ( item ).to_s; _buf << '</li>
'; end
_buf << '</ul>
';
_buf.join
- output: &basic1_bufput|
+ output: &basic1_output|
<ul>
<li><aaa></li>
<li>b&b</li>
<li>"ccc"</li>
</ul>
+
##
- name: basic2
input: |
<ul>
<% i = 0
@@ -135,16 +141,17 @@
_buf << ' <li>'; _buf << ( item ).to_s; _buf << '</li>
'; end
_buf << '</ul>
';
_buf.join
- output: *basic1_bufput
+ output: *basic1_output
# <ul>
# <li><aaa></li>
# <li>b&b</li>
# <li>"ccc"</li>
# </ul>
+
##
- name: basic3
input: |
<ul><% i = 0
for item in list
@@ -158,10 +165,11 @@
';
_buf.join
output: |
<ul><li><aaa></li><li>b&b</li><li>"ccc"</li>
</ul>
+
##
- name: context1
testopt: context
input: |
<ul>
@@ -175,11 +183,12 @@
_buf << ' <li>'; _buf << ( item ).to_s; _buf << '</li>
'; end
_buf << '</ul>
';
_buf.join
- output: *basic1_bufput
+ output: *basic1_output
+
##
- name: ignore1
input: |
<ul>
<%# i = 0 %>
@@ -208,10 +217,11 @@
<ul>
<li> : <aaa> </li>
<li> : b&b </li>
<li> : "ccc" </li>
</ul>
+
##
- name: quotation1
desc: single quotation and backslash
class: Eruby
input: "ation1_input|
@@ -223,10 +233,11 @@
b = "\\""
c = \'\\\'\'
';
_buf.join
output: *quotation1_input
+
##
- name: pattern1
options:
:pattern : '\[@ @\]'
input: |
@@ -241,16 +252,17 @@
_buf << ' <li>'; _buf << ( item ).to_s; _buf << '</li>
'; end
_buf << '</ul>
';
_buf.join
- output: *basic1_bufput
+ output: *basic1_output
# <ul>
# <li><aaa></li>
# <li>b&b</li>
# <li>"ccc"</li>
# </ul>
+
##
- name: pattern2
options:
:pattern : '<(?:!--)?% %(?:--)?>'
input: |
@@ -265,16 +277,17 @@
_buf << ' <li>'; _buf << ( item ).to_s; _buf << '</li>
'; end
_buf << '</ul>
';
_buf.join
- output: *basic1_bufput
+ output: *basic1_output
# <ul>
# <li><aaa></li>
# <li>b&b</li>
# <li>"ccc"</li>
# </ul>
+
##
- name: trim1
options:
:trim : false
input: *basic1_input
@@ -299,13 +312,14 @@
<li>b&b</li>
^
<li>"ccc"</li>
^
</ul>
+
##
- name: bodyonly1
- testopt: skip_bufput
+ testopt: skip_output
options: { :preamble: no, :postamble: no }
input: *basic1_input
src: |4
_buf << '<ul>
'; for item in list
@@ -313,10 +327,11 @@
'; end
_buf << '</ul>
';
chomp: [src]
expected: null
+
##
- name: loadfile1
testopt: load_file
#input: |
# <ul>
@@ -342,10 +357,11 @@
# <li>"ccc"</li>
# </ul>
output:
"<ul>\n <li><aaa></li>\n <li>b&b</li>\n <li>\"ccc\"</li>\n</ul>\n"
# "<ul>\r\n <li><aaa></li>\r\n <li>b&b</li>\r\n <li>\"ccc\"</li>\r\n</ul>\r\n"
+
##
- name: nomatch1
desc: bug
input: &nomatch1|
<ul>
@@ -356,11 +372,29 @@
<li>foo</li>
</ul>
';
_buf.join
output: *nomatch1
+
##
+- name: escape1
+ options: { :escape: true }
+ input: |
+ <% str = '<>&"' %>
+ <%= str %>
+ <%== str %>
+ src: |
+ _buf = []; str = '<>&"'
+ _buf << Erubis::XmlHelper.escape_xml( str ); _buf << '
+ '; _buf << ( str ).to_s; _buf << '
+ ';
+ _buf.join
+ output: |
+ <>&"
+ <>&"
+
+##
- name: xml1
class: XmlEruby
input: |
<pre>
<% for item in list %>
@@ -384,14 +418,15 @@
b&b
b&b
"ccc"
"ccc"
</pre>
+
##
- name: xml2
class: XmlEruby
- testopt: skip_bufput
+ testopt: skip_output
input: |
<% for item in list %>
<%= item["var#{n}"] %>
<%== item["var#{n}"] %>
<%=== item["var#{n}"] %>
@@ -404,10 +439,11 @@
'; _buf << ' '; $stderr.puts("*** debug: item[\"var\#{n}\"]=#{(item["var#{n}"]).inspect}"); _buf << '
'; _buf << ' '; _buf << '
'; end
_buf.join
output: |
+
##
- name: printout1
class: PrintOutEruby
testopt: print
input: *basic1_input
@@ -416,11 +452,12 @@
'; for item in list
print ' <li>'; print(( item ).to_s); print '</li>
'; end
print '</ul>
';
- output: *basic1_bufput
+ output: *basic1_output
+
##
- name: printenabled1
class: PrintEnabledEruby
input: &printenabled1_input|
<ul>
@@ -434,16 +471,17 @@
_buf << ' <li>'; print item ; _buf << '</li>
'; end
_buf << '</ul>
';
_buf.join
- output: *basic1_bufput
+ output: *basic1_output
# <ul>
# <li><aaa></li>
# <li>b&b</li>
# <li>"ccc"</li>
# </ul>
+
##
- name: stdout1
class: StdoutEruby
testopt: stdout
input: *basic1_input
@@ -458,16 +496,17 @@
_buf << ' <li>'; _buf << ( item ).to_s; _buf << '</li>
'; end
_buf << '</ul>
';
''
- output: *basic1_bufput
+ output: *basic1_output
# <ul>
# <li><aaa></li>
# <li>b&b</li>
# <li>"ccc"</li>
# </ul>
+
##
- name: array1
class: ArrayEruby
input: |
<ul>
@@ -493,10 +532,11 @@
- "</li>\n"
- " <li>"
- "\"ccc\""
- "</li>\n"
- "</ul>\n"
+
##
- name: stringbuffer1
class: StringBufferEruby
input: *basic1_input
# <ul>
@@ -510,16 +550,17 @@
_buf << ' <li>'; _buf << ( item ).to_s; _buf << '</li>
'; end
_buf << '</ul>
';
_buf
- output: *basic1_bufput
+ output: *basic1_output
# <ul>
# <li><aaa></li>
# <li>b&b</li>
# <li>"ccc"</li>
# </ul>
+
##
- name: notext1
class: NoTextEruby
input: *basic1_input
src: |
@@ -528,11 +569,25 @@
_buf << ( item ).to_s;
end
_buf.join
output: '<aaa>b&b"ccc"'
+
##
+- name: nocode1
+ class: NoCodeEruby
+ testopt: skip_output
+ input: *basic1_input
+ src: |
+ <ul>
+
+ <li></li>
+
+ </ul>
+ output:
+
+##
- name: simplified
class: SimplifiedEruby
input: |
<ul>
<% for item in list %>
@@ -565,10 +620,11 @@
<li>
"ccc"
</li>
^
</ul>
+
##
- name: bipattern1
class: BiPatternEruby
#options: { :bipattern : '\[= =\]' }
input: |
@@ -587,10 +643,11 @@
<aaa> = <aaa>
b&b % b&b
b&b = b&b
"ccc" % "ccc"
"ccc" = "ccc"
+
##
- name: bipattern2
class: BiPatternEruby
options: { :bipattern: '\$\{ \}' }
input: |
@@ -609,10 +666,11 @@
<aaa> = <aaa>
b&b % b&b
b&b = b&b
"ccc" % "ccc"
"ccc" = "ccc"
+
##
- name: percentline1
class: PercentLineEruby
options:
input: |
@@ -660,10 +718,11 @@
</table>
<pre>
% double percent
% spaced percent
</pre>
+
##
- name: headerfooter1
class: HeaderFooterEruby
options:
testopt: eval('ordered_list(list)')
@@ -693,10 +752,11 @@
<ol>
<li><aaa></li>
<li>b&b</li>
<li>"ccc"</li>
</ol>
+
##
- name: optimized1
class: OptimizedEruby
input: &optimized1_input|
<table>
@@ -734,10 +794,11 @@
<td>"ccc"</td>
<td>"ccc"</td>
</tr>
</table>
<ul><li><aaa></li><li>b&b</li><li>"ccc"</li></ul>
+
##
- name: optimized2
class: OptimizedXmlEruby
input: *optimized1_input
# <table>
@@ -775,10 +836,11 @@
<td>"ccc"</td>
<td>"ccc"</td>
</tr>
</table>
<ul><li><aaa></li><li>b&b</li><li>"ccc"</li></ul>
+
##
- name: optimized3
desc: bug
class: OptimizedEruby
input: |
@@ -796,10 +858,11 @@
output: |
user = Foo
<aaa>
b&b
"ccc"
+
##
- name: optimized4
desc: single quotation and backslash
class: OptimizedEruby
input: &optimized4_input|
@@ -811,10 +874,11 @@
b = "\\""
c = \'\\\'\'
';
_buf
output: *optimized4_input
+
##
- name: tiny1
class: TinyEruby
testopt: binding
input: |
@@ -839,10 +903,11 @@
<li>b&b</li>
^
<li>"ccc"</li>
^
</ul>
+
##
- name: tiny2
class: TinyEruby
testopt: evaluate
input: |
@@ -867,6 +932,119 @@
<li>b&b</li>
^
<li>"ccc"</li>
^
</ul>
+
##
+- name: pi1
+ class: PI::Eruby
+ testopt: evaluate
+ input: &input_pi1|
+ <ul>
+ <?rb for item in @list ?>
+ <li>@{item}@ / @!{item}@</li>
+ <li><%= item %> / <%== item %></li>
+ <?rb end ?>
+ </ul>
+ src: &src_pi1|
+ _buf = []; _buf << '<ul>
+ '; for item in @list
+ _buf << ' <li>'; _buf << Erubis::XmlHelper.escape_xml(item); _buf << ' / '; _buf << (item).to_s; _buf << '</li>
+ <li>'; _buf << ( item ).to_s; _buf << ' / '; _buf << Erubis::XmlHelper.escape_xml( item ); _buf << '</li>
+ '; end
+ _buf << '</ul>
+ ';
+ _buf.join
+ output: &output_pi1|
+ <ul>
+ <li><aaa> / <aaa></li>
+ <li><aaa> / <aaa></li>
+ <li>b&b / b&b</li>
+ <li>b&b / b&b</li>
+ <li>"ccc" / "ccc"</li>
+ <li>"ccc" / "ccc"</li>
+ </ul>
+
+##
+- name: pi2
+ class: PI::Eruby
+ options: { :escape: false }
+ testopt: evaluate
+ input: *input_pi1
+ src: |
+ _buf = []; _buf << '<ul>
+ '; for item in @list
+ _buf << ' <li>'; _buf << (item).to_s; _buf << ' / '; _buf << Erubis::XmlHelper.escape_xml(item); _buf << '</li>
+ <li>'; _buf << Erubis::XmlHelper.escape_xml( item ); _buf << ' / '; _buf << ( item ).to_s; _buf << '</li>
+ '; end
+ _buf << '</ul>
+ ';
+ _buf.join
+ output: |
+ <ul>
+ <li><aaa> / <aaa></li>
+ <li><aaa> / <aaa></li>
+ <li>b&b / b&b</li>
+ <li>b&b / b&b</li>
+ <li>"ccc" / "ccc"</li>
+ <li>"ccc" / "ccc"</li>
+ </ul>
+
+##
+- name: pi3
+ class: PI::Eruby
+ options: { :pi: hoge, :embchar: '$' }
+ testopt: evaluate
+ input: |
+ <ul>
+ <?hoge for item in @list ?>
+ <li>${item}$ / $!{item}$</li>
+ <li><%= item %> / <%== item %></li>
+ <?hoge end ?>
+ </ul>
+ src: *src_pi1
+ output: *output_pi1
+
+- name: pi4
+ class: PI::Eruby
+ testopt: evaluate
+ input: |
+ <?rb-header
+ def show(list)
+ ?>
+ <ul>
+ <?rb for item in list ?>
+ <?rb-value item ?>
+ <?rb end ?>
+ <?rb-comment
+ # comment
+ # comment
+ ?>
+ </ul>
+ <?rb-footer
+ end
+ show(@list) ?>
+
+ src: |4
+
+ def show(list)
+
+ _buf = []; _buf << '<ul>
+ '; for item in list
+ _buf << ( item
+ ).to_s; end
+
+
+
+
+ _buf << '</ul>
+ ';
+ _buf.join
+
+ end
+ show(@list)
+
+ output: |
+ <ul>
+ <aaa>b&b"ccc"</ul>
+