mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Update to ruby/spec@cbe855c
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62602 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
ecf03376ec
commit
37ef87c12b
38 changed files with 185 additions and 177 deletions
|
|
@ -1,5 +1,6 @@
|
|||
require 'erb'
|
||||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../../fixtures/classes', __FILE__)
|
||||
|
||||
describe "ERB::DefMethod.def_erb_method" do
|
||||
|
||||
|
|
@ -50,11 +51,7 @@ END
|
|||
MY_INPUT4_FOR_ERB = input
|
||||
class MyClass4ForErb
|
||||
extend ERB::DefMethod
|
||||
if RUBY_VERSION >= '2.6'
|
||||
erb = ERB.new(MY_INPUT4_FOR_ERB, trim_mode: '<>')
|
||||
else
|
||||
erb = ERB.new(MY_INPUT4_FOR_ERB, nil, '<>')
|
||||
end
|
||||
erb = ERBSpecs.new_erb(MY_INPUT4_FOR_ERB, trim_mode: '<>')
|
||||
def_erb_method('render()', erb)
|
||||
def initialize(items)
|
||||
@items = items
|
||||
|
|
|
|||
9
spec/ruby/library/erb/fixtures/classes.rb
Normal file
9
spec/ruby/library/erb/fixtures/classes.rb
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
module ERBSpecs
|
||||
def self.new_erb(input, trim_mode: nil)
|
||||
if ruby_version_is "2.6"
|
||||
ERB.new(input, trim_mode: trim_mode)
|
||||
else
|
||||
ERB.new(input, nil, trim_mode)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
require 'erb'
|
||||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/classes', __FILE__)
|
||||
|
||||
describe "ERB.new" do
|
||||
before :all do
|
||||
|
|
@ -31,33 +32,21 @@ END
|
|||
it "compiles eRuby script into ruby code when trim mode is 0 or not specified" do
|
||||
expected = "<ul>\n\n\n\n<li>1</li>\n\n\n\n<li>2</li>\n\n\n\n<li>3</li>\n\n\n</ul>\n"
|
||||
[0, '', nil].each do |trim_mode|
|
||||
if RUBY_VERSION >= '2.6'
|
||||
ERB.new(@eruby_str, trim_mode: trim_mode).result.should == expected
|
||||
else
|
||||
ERB.new(@eruby_str, nil, trim_mode).result.should == expected
|
||||
end
|
||||
ERBSpecs.new_erb(@eruby_str, trim_mode: trim_mode).result.should == expected
|
||||
end
|
||||
end
|
||||
|
||||
it "removes '\n' when trim_mode is 1 or '>'" do
|
||||
expected = "<ul>\n<li>1</li>\n<li>2</li>\n<li>3</li>\n</ul>\n"
|
||||
[1, '>'].each do |trim_mode|
|
||||
if RUBY_VERSION >= '2.6'
|
||||
ERB.new(@eruby_str, trim_mode: trim_mode).result.should == expected
|
||||
else
|
||||
ERB.new(@eruby_str, nil, trim_mode).result.should == expected
|
||||
end
|
||||
ERBSpecs.new_erb(@eruby_str, trim_mode: trim_mode).result.should == expected
|
||||
end
|
||||
end
|
||||
|
||||
it "removes spaces at beginning of line and '\n' when trim_mode is 2 or '<>'" do
|
||||
expected = "<ul>\n<li>1</li>\n<li>2</li>\n<li>3</li>\n</ul>\n"
|
||||
[2, '<>'].each do |trim_mode|
|
||||
if RUBY_VERSION >= '2.6'
|
||||
ERB.new(@eruby_str, trim_mode: trim_mode).result.should == expected
|
||||
else
|
||||
ERB.new(@eruby_str, nil, trim_mode).result.should == expected
|
||||
end
|
||||
ERBSpecs.new_erb(@eruby_str, trim_mode: trim_mode).result.should == expected
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -73,11 +62,7 @@ END
|
|||
</ul>
|
||||
END
|
||||
|
||||
if RUBY_VERSION >= '2.6'
|
||||
ERB.new(input, trim_mode: '-').result.should == expected
|
||||
else
|
||||
ERB.new(input, nil, '-').result.should == expected
|
||||
end
|
||||
ERBSpecs.new_erb(input, trim_mode: '-').result.should == expected
|
||||
end
|
||||
|
||||
|
||||
|
|
@ -91,39 +76,23 @@ END
|
|||
END
|
||||
|
||||
lambda {
|
||||
if RUBY_VERSION >= '2.6'
|
||||
ERB.new(input, trim_mode: '-').result
|
||||
else
|
||||
ERB.new(input, nil, '-').result
|
||||
end
|
||||
ERBSpecs.new_erb(input, trim_mode: '-').result
|
||||
}.should raise_error(SyntaxError)
|
||||
end
|
||||
|
||||
it "regards lines starting with '%' as '<% ... %>' when trim_mode is '%'" do
|
||||
expected = "<ul>\n <li>1\n \n <li>2\n \n <li>3\n \n\n</ul>\n%%\n"
|
||||
if RUBY_VERSION >= '2.6'
|
||||
ERB.new(@eruby_str2, trim_mode: "%").result.should == expected
|
||||
else
|
||||
ERB.new(@eruby_str2, nil, "%").result.should == expected
|
||||
end
|
||||
ERBSpecs.new_erb(@eruby_str2, trim_mode: "%").result.should == expected
|
||||
end
|
||||
it "regards lines starting with '%' as '<% ... %>' and remove \"\\n\" when trim_mode is '%>'" do
|
||||
expected = "<ul>\n <li>1 <li>2 <li>3 </ul>\n%%\n"
|
||||
if RUBY_VERSION >= '2.6'
|
||||
ERB.new(@eruby_str2, trim_mode: '%>').result.should == expected
|
||||
else
|
||||
ERB.new(@eruby_str2, nil, '%>').result.should == expected
|
||||
end
|
||||
ERBSpecs.new_erb(@eruby_str2, trim_mode: '%>').result.should == expected
|
||||
end
|
||||
|
||||
|
||||
it "regard lines starting with '%' as '<% ... %>' and remove \"\\n\" when trim_mode is '%<>'" do
|
||||
expected = "<ul>\n <li>1\n \n <li>2\n \n <li>3\n \n</ul>\n%%\n"
|
||||
if RUBY_VERSION >= '2.6'
|
||||
ERB.new(@eruby_str2, trim_mode: '%<>').result.should == expected
|
||||
else
|
||||
ERB.new(@eruby_str2, nil, '%<>').result.should == expected
|
||||
end
|
||||
ERBSpecs.new_erb(@eruby_str2, trim_mode: '%<>').result.should == expected
|
||||
end
|
||||
|
||||
|
||||
|
|
@ -138,11 +107,7 @@ END
|
|||
%%%
|
||||
END
|
||||
|
||||
if RUBY_VERSION >= '2.6'
|
||||
ERB.new(input, trim_mode: '%-').result.should == expected
|
||||
else
|
||||
ERB.new(input, nil, '%-').result.should == expected
|
||||
end
|
||||
ERBSpecs.new_erb(input, trim_mode: '%-').result.should == expected
|
||||
end
|
||||
|
||||
it "changes '_erbout' variable name in the produced source" do
|
||||
|
|
@ -164,12 +129,8 @@ END
|
|||
<b><%#= item %></b>
|
||||
<%# end %>
|
||||
END
|
||||
ERB.new(input).result.should == "\n<b></b>\n\n"
|
||||
if RUBY_VERSION >= '2.6'
|
||||
ERB.new(input, trim_mode: '<>').result.should == "<b></b>\n"
|
||||
else
|
||||
ERB.new(input, nil, '<>').result.should == "<b></b>\n"
|
||||
end
|
||||
ERBSpecs.new_erb(input).result.should == "\n<b></b>\n\n"
|
||||
ERBSpecs.new_erb(input, trim_mode: '<>').result.should == "<b></b>\n"
|
||||
end
|
||||
|
||||
it "forget local variables defined previous one" do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue