summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-03 01:18:47 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-03 01:18:47 +0000
commit0eb420cc78e5027a2611057a535fd255e87723fb (patch)
tree5e1228276c1167b664d34ec4512554eced7b666a /test
parentd16f9a75df7076a69f94c64608aead438f3e7ffe (diff)
* lib/erb.rb (ERB::Compiler::TrimScanner#scan_line): Fix a bug
where tokens are not yilelded one by one. (ERB::Compiler::TrimScanner#explicit_trim_line): Fix without- strscan problems. [ruby_core:17028]. * test/erb/test_erb.rb (TestERBCore#_test_01) (TestERBCore#test_02_safe_04): The expected value should come first for assert_equal(). (TestERBCoreWOStrScan): Add test class for without-strscan. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_7@16764 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/erb/test_erb.rb65
1 files changed, 38 insertions, 27 deletions
diff --git a/test/erb/test_erb.rb b/test/erb/test_erb.rb
index 5815bdb3c0..48bd7b50b9 100644
--- a/test/erb/test_erb.rb
+++ b/test/erb/test_erb.rb
@@ -44,26 +44,26 @@ class TestERBCore < Test::Unit::TestCase
@erb = ERB
end
- def test_01
- _test_01(nil)
- _test_01(0)
- _test_01(1)
- _test_01(2)
- _test_01(3)
+ def test_core
+ _test_core(nil)
+ _test_core(0)
+ _test_core(1)
+ _test_core(2)
+ _test_core(3)
end
- def _test_01(safe)
+ def _test_core(safe)
erb = @erb.new("hello")
- assert_equal(erb.result, "hello")
+ assert_equal("hello", erb.result)
erb = @erb.new("hello", safe, 0)
- assert_equal(erb.result, "hello")
+ assert_equal("hello", erb.result)
erb = @erb.new("hello", safe, 1)
- assert_equal(erb.result, "hello")
+ assert_equal("hello", erb.result)
erb = @erb.new("hello", safe, 2)
- assert_equal(erb.result, "hello")
+ assert_equal("hello", erb.result)
src = <<EOS
%% hi
@@ -157,14 +157,14 @@ EOS
assert_equal(ans, erb.result)
end
- def test_02_safe_04
+ def test_safe_04
erb = @erb.new('<%=$SAFE%>', 4)
- assert_equal(erb.result(TOPLEVEL_BINDING.taint), '4')
+ assert_equal('4', erb.result(TOPLEVEL_BINDING.taint))
end
class Foo; end
- def test_03_def_class
+ def test_def_class
erb = @erb.new('hello')
cls = erb.def_class
assert_equal(Object, cls.superclass)
@@ -177,7 +177,7 @@ EOS
assert(cls.new.respond_to?('erb'))
end
- def test_04_percent
+ def test_percent
src = <<EOS
%n = 1
<%= n%>
@@ -218,26 +218,24 @@ EOS
assert_equal(ans, ERB.new(src, nil, '%').result)
end
- class Bar; end
-
- def test_05_def_method
- assert(! Bar.new.respond_to?('hello'))
- Bar.module_eval do
+ def test_def_method
+ klass = Class.new
+ klass.module_eval do
extend ERB::DefMethod
fname = File.join(File.dirname(File.expand_path(__FILE__)), 'hello.erb')
def_erb_method('hello', fname)
end
- assert(Bar.new.respond_to?('hello'))
+ assert(klass.new.respond_to?('hello'))
- assert(! Bar.new.respond_to?('hello_world'))
+ assert(! klass.new.respond_to?('hello_world'))
erb = @erb.new('hello, world')
- Bar.module_eval do
+ klass.module_eval do
def_erb_method('hello_world', erb)
end
- assert(Bar.new.respond_to?('hello_world'))
+ assert(klass.new.respond_to?('hello_world'))
end
- def test_06_escape
+ def test_escape
src = <<EOS
1.<%% : <%="<%%"%>
2.%%> : <%="%%>"%>
@@ -274,7 +272,7 @@ EOS
assert_equal(ans, ERB.new(src, nil, '%').result)
end
- def test_07_keep_lineno
+ def test_keep_lineno
src = <<EOS
Hello,
% x = "World"
@@ -378,7 +376,7 @@ EOS
end
end
- def test_08_explicit
+ def test_explicit
src = <<EOS
<% x = %w(hello world) -%>
NotSkip <%- y = x -%> NotSkip
@@ -411,3 +409,16 @@ EOS
assert_equal(ans, ERB.new(src, nil, '-%').result)
end
end
+
+class TestERBCoreWOStrScan < TestERBCore
+ def setup
+ @save_map = ERB::Compiler::Scanner.instance_variable_get('@scanner_map')
+ map = {[nil, false]=>ERB::Compiler::SimpleScanner}
+ ERB::Compiler::Scanner.instance_variable_set('@scanner_map', map)
+ super
+ end
+
+ def teardown
+ ERB::Compiler::Scanner.instance_variable_set('@scanner_map', @save_map)
+ end
+end