summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authormakoto kuwata <kwa@kuwata-lab.com>2006-05-06 03:06:55 +0000
committermakoto kuwata <kwa@kuwata-lab.com>2006-05-06 03:06:55 +0000
commit0f4453c60d6f1a1992ac5f7a085c03fc5b77269e (patch)
treeebfd81bb1016e74197362cde800a626d513f6eec /test
parent675a3fd420e4e72b2a9846eb93269ae24c554850 (diff)
downloaderubis-0f4453c60d6f1a1992ac5f7a085c03fc5b77269e.tar.gz
- [enhance] Context#initialize() can take a hash object
- [enhance] Engine#result() can take a hash object - [enhance] TinyEruby#evaluate() added - [change] Engine#evaluate() convert hash into Context object - [change] command-line option '-X' removed and add '-B' (invoke result(binding)) - [enhance] add 'website/' directory
Diffstat (limited to 'test')
-rw-r--r--test/test-bin.rb17
-rw-r--r--test/test-erubis.rb40
2 files changed, 45 insertions, 12 deletions
diff --git a/test/test-bin.rb b/test/test-bin.rb
index f01632b..4e4cde1 100644
--- a/test/test-bin.rb
+++ b/test/test-bin.rb
@@ -16,7 +16,6 @@ end
require 'test/unit'
-#require 'test/unit/ui/console/testrunner'
require 'assert-text-equal'
require 'yaml'
require 'tempfile'
@@ -34,6 +33,7 @@ list:
<% end %>
user: <%= defined?(user) ? user : "(none)" %>
END
+ INPUT2 = INPUT.gsub(/\blist([^:])/, '@list\1').gsub(/\buser([^:])/, '@user\1')
# SRC = <<'END'
#_out = ''; _out << "list:\n"
@@ -54,6 +54,7 @@ _out = []; _out << 'list:
';
_out.join
END
+# SRC2 = SRC.gsub(/\blist /, '@list ').gsub(/\buser /, '@user ')
OUTPUT = <<'END'
list:
@@ -192,7 +193,7 @@ END
def test_yaml1 # -f
yamlfile = "test.context1.yaml"
- @input = INPUT
+ @input = INPUT2
@expected = OUTPUT.gsub(/\(none\)/, 'Hello')
@options = "-f #{yamlfile}"
#
@@ -211,7 +212,7 @@ END
def test_untabify1 # -t
yamlfile = "test.context2.yaml"
- @input = INPUT
+ @input = INPUT2
@expected = OUTPUT.gsub(/\(none\)/, 'Hello')
@options = "-tf #{yamlfile}"
#
@@ -231,7 +232,7 @@ END
def test_symbolify1 # -S
yamlfile = "test.context3.yaml"
@input = <<END
-<% for h in list %>
+<% for h in @list %>
<tr>
<td><%= h[:name] %></td><td><%= h[:mail] %></td>
</tr>
@@ -263,12 +264,12 @@ END
end
- def test_context1 # -X
+ def test_context1 # -B
yamlfile = "test.context4.yaml"
#
@input = <<'END'
-user = <%= @user %>
-<% for item in @list %>
+user = <%= user %>
+<% for item in list %>
- <%= item %>
<% end %>
END
@@ -278,7 +279,7 @@ user = World
- bbb
- ccc
END
- @options = "-f #{yamlfile} -X "
+ @options = "-f #{yamlfile} -B "
#
yaml = <<-END
user: World
diff --git a/test/test-erubis.rb b/test/test-erubis.rb
index 3c6665b..2abbd50 100644
--- a/test/test-erubis.rb
+++ b/test/test-erubis.rb
@@ -68,7 +68,8 @@ class ErubisTest < Test::Unit::TestCase
begin
orig = $stdout
$stdout = stringio = StringIO.new
- actual = eruby.evaluate(context)
+ #actual = eruby.evaluate(context)
+ actual = eruby.result(context)
ensure
$stdout = orig
end
@@ -78,11 +79,14 @@ class ErubisTest < Test::Unit::TestCase
assert_nil(actual)
end
assert_text_equal(@output, stringio.string)
- when 'result'
+ when 'evaluate', 'context'
+ actual = eruby.evaluate(context)
+ assert_text_equal(@output, actual)
+ when 'binding'
actual = eruby.result(binding())
assert_text_equal(@output, actual)
else
- actual = eruby.evaluate(context)
+ actual = eruby.result(context)
assert_text_equal(@output, actual)
end
end
@@ -803,7 +807,7 @@ __END__
##
- name: tiny1
class: TinyEruby
- testopt: result
+ testopt: binding
input: |
<ul>
<% for item in list %>
@@ -829,3 +833,31 @@ __END__
^
</ul>
##
+- name: tiny2
+ class: TinyEruby
+ testopt: evaluate
+ input: |
+ <ul>
+ <% for item in @list %>
+ <li><%= item %></li>
+ <% end %>
+ </ul>
+ src: |
+ _out = []; _out << '<ul>
+ '; for item in @list ; _out << '
+ <li>'; _out << ( item ).to_s; _out << '</li>
+ '; end ; _out << '
+ </ul>
+ ';
+ _out.join
+ output: |
+ <ul>
+ ^
+ <li><aaa></li>
+ ^
+ <li>b&b</li>
+ ^
+ <li>"ccc"</li>
+ ^
+ </ul>
+##