## ## $Release: 2.6.6 $ ## copyright(c) 2006-2010 kuwata-lab.com all rights reserved. ## require "#{File.dirname(__FILE__)}/test.rb" require 'erubis' require 'erubis/engine/eruby' require 'erubis/engine/ephp' require 'erubis/engine/ec' require 'erubis/engine/ejava' require 'erubis/engine/escheme' require 'erubis/engine/eperl' require 'erubis/engine/ejavascript' class EnginesTest < Test::Unit::TestCase #load_yaml_documents(__FILE__) testdata_list = load_yaml_datafile(__FILE__) define_testmethods(testdata_list) def _test() klass = Erubis.const_get(@class) engine = klass.new(@input, @options || {}) actual = engine.src assert_text_equal(@expected, actual) end self.post_definition() end __END__ - name: ruby1 lang: ruby class: Eruby options: input: | <% i = 0 list.each_with_index do |item, i| %> <% end %>
<%= i+1 %> <%== list %>
<%=== i+1 %> expected: | _buf = ''; _buf << ' '; i = 0 list.each_with_index do |item, i| _buf << ' '; end _buf << '
'; _buf << ( i+1 ).to_s; _buf << ' '; _buf << Erubis::XmlHelper.escape_xml( list ); _buf << '
'; $stderr.puts("*** debug: i+1=#{(i+1).inspect}"); _buf << ' '; _buf.to_s ## - name: php1 lang: php class: Ephp options: input: | <% $i = 0; foreach ($list as $item) { $i++; %> <% } %>
<%= $i %> <%== $item %>
<%=== $i %> expected: |
## - name: c1 lang: c class: Ec options: { :filename: foo.html, :indent: ' ' } input: |4 <% for (i = 0; i < list; i++) { %> <% } %>
<%= "%d", i %> <%== list[i] %>
<%=== "%d", i %> expected: | #line 1 "foo.html" fputs("\n" " \n", stdout); for (i = 0; i < list; i++) { fputs(" \n" " \n" " \n" " \n", stdout); } fputs(" \n" "
", stdout); fprintf(stdout, "%d", i); fputs("", stdout); escape(list[i], stdout); fputs("
\n", stdout); fprintf(stderr, "*** debug: i=" "%d", i); fputs("\n", stdout); ## - name: java1 lang: java class: Ejava options: { :buf: _buf, :bufclass: StringBuilder, :indent: ' ' } input: | <% int i = 0; for (Iterator it = list.iterator(); it.hasNext(); ) { String s = (String)it.next(); i++; %> "> <% } %>
<%= i %> <%== s %>
<%=== i %> expected: |4 StringBuilder _buf = new StringBuilder(); _buf.append("\n" + " \n"); int i = 0; for (Iterator it = list.iterator(); it.hasNext(); ) { String s = (String)it.next(); i++; _buf.append(" \n" + " \n" + " \n" + " \n"); } _buf.append(" \n" + "
"); _buf.append(i); _buf.append(""); _buf.append(escape(s)); _buf.append("
\n"); System.err.println("*** debug: i="+(i)); _buf.append("\n"); return _buf.toString(); ## - name: scheme1 lang: scheme class: Escheme options: input: &scheme1_input| <% (let ((i 0)) %> <% (for-each (lambda (item) (set! i (+ i 1)) %> <% ); lambda end list); for-each end %>
<%= i %> <%== item %>
<%=== i %> <% ); let end %> expected: |4 (let ((_buf '())) (define (_add x) (set! _buf (cons x _buf))) (let ((i 0)) (_add "\n") (for-each (lambda (item) (set! i (+ i 1)) (_add " \n") ); lambda end list); for-each end (_add "
")(_add i)(_add " ")(_add (escape item))(_add "
\n") (display "*** debug: i=")(display i)(display "\n")(_add "\n") ); let end (reverse _buf)) ## - name: scheme2 lang: scheme class: Escheme options: { :func: 'display' } input: *scheme1_input expected: |4 (let ((i 0)) (display "\n") (for-each (lambda (item) (set! i (+ i 1)) (display " \n") ); lambda end list); for-each end (display "
")(display i)(display " ")(display (escape item))(display "
\n") (display "*** debug: i=")(display i)(display "\n")(display "\n") ); let end ## - name: perl1 lang: perl class: Eperl options: input: | <% my $user = 'Erubis'; my @list = ('', 'b&b', '"ccc"'); %>

Hello <%= $user %>!

<% $i = 0; %> <% for $item (@list) { %> "> <% } %>
<%= $i %> <%== $item %>
<%=== $i %> expected: |4 use HTML::Entities; my $user = 'Erubis'; my @list = ('', 'b&b', '"ccc"'); print('

Hello '); print($user); print('!

'); $i = 0; for $item (@list) { print(' '); } print('
'); print($i); print(' '); print(encode_entities($item)); print('
'); print('*** debug: $i=', $i, "\n");print(' '); ## - name: javascript1 lang: javascript class: Ejavascript options: input: &javascript_input | <% var user = 'Erubis'; var list = ['', 'b&b', '"ccc"']; %>

Hello <%= user %>!

<% var i; %> <% for (i = 0; i < list.length; i++) { %> "> <% } %>
<%= i %> <%= list[i] %>
<%=== i %> expected: |4 var _buf = []; var user = 'Erubis'; var list = ['', 'b&b', '"ccc"']; _buf.push("

Hello "); _buf.push(user); _buf.push("!

\n\ \n\ \n"); var i; for (i = 0; i < list.length; i++) { _buf.push(" \n\ \n\ \n\ \n"); } _buf.push(" \n\
"); _buf.push(i); _buf.push(""); _buf.push(list[i]); _buf.push("
\n"); alert("*** debug: i="+(i)); _buf.push("\n"); document.write(_buf.join("")); ## - name: javascript2 lang: javascript class: Ejavascript options: { :docwrite: false } input: *javascript_input expected: |4 var _buf = []; var user = 'Erubis'; var list = ['', 'b&b', '"ccc"']; _buf.push("

Hello "); _buf.push(user); _buf.push("!

\n\ \n\ \n"); var i; for (i = 0; i < list.length; i++) { _buf.push(" \n\ \n\ \n\ \n"); } _buf.push(" \n\
"); _buf.push(i); _buf.push(""); _buf.push(list[i]); _buf.push("
\n"); alert("*** debug: i="+(i)); _buf.push("\n"); _buf.join(""); ##