mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Update to ruby/spec@83063a3
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62094 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
1e658d45e1
commit
3fa5bd38af
494 changed files with 4133 additions and 3109 deletions
|
@ -3,6 +3,6 @@ require File.expand_path('../shared/eql', __FILE__)
|
|||
require File.expand_path('../shared/equal_value', __FILE__)
|
||||
|
||||
describe "String#===" do
|
||||
it_behaves_like(:string_eql_value, :===)
|
||||
it_behaves_like(:string_equal_value, :===)
|
||||
it_behaves_like :string_eql_value, :===
|
||||
it_behaves_like :string_equal_value, :===
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ require File.expand_path('../shared/chars', __FILE__)
|
|||
require File.expand_path('../shared/each_char_without_block', __FILE__)
|
||||
|
||||
describe "String#chars" do
|
||||
it_behaves_like(:string_chars, :chars)
|
||||
it_behaves_like :string_chars, :chars
|
||||
|
||||
it "returns an array when no block given" do
|
||||
ary = "hello".send(@method)
|
||||
|
|
|
@ -5,7 +5,7 @@ require File.expand_path('../shared/each_codepoint_without_block', __FILE__)
|
|||
|
||||
with_feature :encoding do
|
||||
describe "String#codepoints" do
|
||||
it_behaves_like(:string_codepoints, :codepoints)
|
||||
it_behaves_like :string_codepoints, :codepoints
|
||||
|
||||
it "returns an Array when no block is given" do
|
||||
"abc".send(@method).should == [?a.ord, ?b.ord, ?c.ord]
|
||||
|
|
|
@ -2,6 +2,6 @@ require File.expand_path('../shared/chars', __FILE__)
|
|||
require File.expand_path('../shared/each_char_without_block', __FILE__)
|
||||
|
||||
describe "String#each_char" do
|
||||
it_behaves_like(:string_chars, :each_char)
|
||||
it_behaves_like(:string_each_char_without_block, :each_char)
|
||||
it_behaves_like :string_chars, :each_char
|
||||
it_behaves_like :string_each_char_without_block, :each_char
|
||||
end
|
||||
|
|
|
@ -4,7 +4,7 @@ require File.expand_path('../shared/each_codepoint_without_block', __FILE__)
|
|||
|
||||
with_feature :encoding do
|
||||
describe "String#each_codepoint" do
|
||||
it_behaves_like(:string_codepoints, :each_codepoint)
|
||||
it_behaves_like(:string_each_codepoint_without_block, :each_codepoint)
|
||||
it_behaves_like :string_codepoints, :each_codepoint
|
||||
it_behaves_like :string_each_codepoint_without_block, :each_codepoint
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,6 +4,6 @@ require File.expand_path('../shared/each_line', __FILE__)
|
|||
require File.expand_path('../shared/each_line_without_block', __FILE__)
|
||||
|
||||
describe "String#each_line" do
|
||||
it_behaves_like(:string_each_line, :each_line)
|
||||
it_behaves_like(:string_each_line_without_block, :each_line)
|
||||
it_behaves_like :string_each_line, :each_line
|
||||
it_behaves_like :string_each_line_without_block, :each_line
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ require File.expand_path('../../../spec_helper', __FILE__)
|
|||
require File.expand_path('../shared/eql', __FILE__)
|
||||
|
||||
describe "String#eql?" do
|
||||
it_behaves_like(:string_eql_value, :eql?)
|
||||
it_behaves_like :string_eql_value, :eql?
|
||||
|
||||
describe "when given a non-String" do
|
||||
it "returns false" do
|
||||
|
|
|
@ -3,6 +3,6 @@ require File.expand_path('../shared/eql', __FILE__)
|
|||
require File.expand_path('../shared/equal_value', __FILE__)
|
||||
|
||||
describe "String#==" do
|
||||
it_behaves_like(:string_eql_value, :==)
|
||||
it_behaves_like(:string_equal_value, :==)
|
||||
it_behaves_like :string_eql_value, :==
|
||||
it_behaves_like :string_equal_value, :==
|
||||
end
|
||||
|
|
|
@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes.rb', __FILE__)
|
|||
require File.expand_path('../shared/to_sym.rb', __FILE__)
|
||||
|
||||
describe "String#intern" do
|
||||
it_behaves_like(:string_to_sym, :intern)
|
||||
it_behaves_like :string_to_sym, :intern
|
||||
end
|
||||
|
|
|
@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes.rb', __FILE__)
|
|||
require File.expand_path('../shared/length', __FILE__)
|
||||
|
||||
describe "String#length" do
|
||||
it_behaves_like(:string_length, :length)
|
||||
it_behaves_like :string_length, :length
|
||||
end
|
||||
|
|
|
@ -4,7 +4,7 @@ require File.expand_path('../shared/each_line', __FILE__)
|
|||
require File.expand_path('../shared/each_line_without_block', __FILE__)
|
||||
|
||||
describe "String#lines" do
|
||||
it_behaves_like(:string_each_line, :lines)
|
||||
it_behaves_like :string_each_line, :lines
|
||||
|
||||
it "returns an array when no block given" do
|
||||
ary = "hello world".send(@method, ' ')
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/classes.rb', __FILE__)
|
||||
require File.expand_path('../../../shared/hash/key_error', __FILE__)
|
||||
|
||||
describe "String#%" do
|
||||
context "when key is missing from passed-in hash" do
|
||||
it_behaves_like :key_error, -> (obj, key) { "%{#{key}}" % obj }, { a: 5 }
|
||||
end
|
||||
|
||||
it "formats multiple expressions" do
|
||||
("%b %x %d %s" % [10, 10, 10, 10]).should == "1010 a 10 10"
|
||||
end
|
||||
|
@ -764,10 +769,6 @@ describe "String#%" do
|
|||
("%{foo}bar" % {foo: 'oof'}).should == "oofbar"
|
||||
end
|
||||
|
||||
it "raises KeyError if key is missing from passed-in hash" do
|
||||
lambda {"%{foo}" % {}}.should raise_error(KeyError)
|
||||
end
|
||||
|
||||
it "should raise ArgumentError if no hash given" do
|
||||
lambda {"%{foo}" % []}.should raise_error(ArgumentError)
|
||||
end
|
||||
|
|
|
@ -3,9 +3,9 @@ require File.expand_path('../fixtures/classes.rb', __FILE__)
|
|||
require File.expand_path('../shared/succ.rb', __FILE__)
|
||||
|
||||
describe "String#next" do
|
||||
it_behaves_like(:string_succ, :next)
|
||||
it_behaves_like :string_succ, :next
|
||||
end
|
||||
|
||||
describe "String#next!" do
|
||||
it_behaves_like(:string_succ_bang, :"next!")
|
||||
it_behaves_like :string_succ_bang, :"next!"
|
||||
end
|
||||
|
|
|
@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes.rb', __FILE__)
|
|||
require File.expand_path('../shared/length', __FILE__)
|
||||
|
||||
describe "String#size" do
|
||||
it_behaves_like(:string_length, :size)
|
||||
it_behaves_like :string_length, :size
|
||||
end
|
||||
|
|
|
@ -42,4 +42,35 @@ describe "String#start_with?" do
|
|||
it "works for multibyte strings" do
|
||||
"céréale".start_with?("cér").should be_true
|
||||
end
|
||||
|
||||
ruby_version_is "2.5" do
|
||||
it "supports regexps" do
|
||||
regexp = /[h1]/
|
||||
"hello".start_with?(regexp).should be_true
|
||||
"1337".start_with?(regexp).should be_true
|
||||
"foxes are 1337".start_with?(regexp).should be_false
|
||||
"chunky\n12bacon".start_with?(/12/).should be_false
|
||||
end
|
||||
|
||||
it "supports regexps with ^ and $ modifiers" do
|
||||
regexp1 = /^\d{2}/
|
||||
regexp2 = /\d{2}$/
|
||||
"12test".start_with?(regexp1).should be_true
|
||||
"test12".start_with?(regexp1).should be_false
|
||||
"12test".start_with?(regexp2).should be_false
|
||||
"test12".start_with?(regexp2).should be_false
|
||||
end
|
||||
|
||||
it "sets Regexp.last_match if it returns true" do
|
||||
regexp = /test-(\d+)/
|
||||
"test-1337".start_with?(regexp).should be_true
|
||||
Regexp.last_match.should_not be_nil
|
||||
Regexp.last_match[1].should == "1337"
|
||||
$1.should == "1337"
|
||||
|
||||
"test-asdf".start_with?(regexp).should be_false
|
||||
Regexp.last_match.should be_nil
|
||||
$1.should be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,9 +3,9 @@ require File.expand_path('../fixtures/classes.rb', __FILE__)
|
|||
require File.expand_path('../shared/succ.rb', __FILE__)
|
||||
|
||||
describe "String#succ" do
|
||||
it_behaves_like(:string_succ, :succ)
|
||||
it_behaves_like :string_succ, :succ
|
||||
end
|
||||
|
||||
describe "String#succ!" do
|
||||
it_behaves_like(:string_succ_bang, :"succ!")
|
||||
it_behaves_like :string_succ_bang, :"succ!"
|
||||
end
|
||||
|
|
|
@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes.rb', __FILE__)
|
|||
require File.expand_path('../shared/to_s.rb', __FILE__)
|
||||
|
||||
describe "String#to_s" do
|
||||
it_behaves_like(:string_to_s, :to_s)
|
||||
it_behaves_like :string_to_s, :to_s
|
||||
end
|
||||
|
|
|
@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes.rb', __FILE__)
|
|||
require File.expand_path('../shared/to_s.rb', __FILE__)
|
||||
|
||||
describe "String#to_str" do
|
||||
it_behaves_like(:string_to_s, :to_str)
|
||||
it_behaves_like :string_to_s, :to_str
|
||||
end
|
||||
|
|
|
@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes.rb', __FILE__)
|
|||
require File.expand_path('../shared/to_sym.rb', __FILE__)
|
||||
|
||||
describe "String#to_sym" do
|
||||
it_behaves_like(:string_to_sym, :to_sym)
|
||||
it_behaves_like :string_to_sym, :to_sym
|
||||
end
|
||||
|
|
|
@ -17,5 +17,30 @@ ruby_version_is "2.3" do
|
|||
output.frozen?.should == true
|
||||
output.should == 'foo'
|
||||
end
|
||||
|
||||
ruby_version_is "2.5" do
|
||||
it "returns the same object for equal unfrozen strings" do
|
||||
origin = "this is a string"
|
||||
dynamic = %w(this is a string).join(' ')
|
||||
|
||||
origin.should_not equal(dynamic)
|
||||
(-origin).should equal(-dynamic)
|
||||
end
|
||||
|
||||
it "returns the same object when it's called on the same String literal" do
|
||||
(-"unfrozen string").should equal(-"unfrozen string")
|
||||
(-"unfrozen string").should_not equal(-"another unfrozen string")
|
||||
end
|
||||
|
||||
it "is an identity function if the string is frozen" do
|
||||
dynamic = %w(this string is frozen).join(' ').freeze
|
||||
|
||||
(-dynamic).should equal(dynamic)
|
||||
|
||||
dynamic.should_not equal("this string is frozen".freeze)
|
||||
(-dynamic).should_not equal("this string is frozen".freeze)
|
||||
(-dynamic).should_not equal(-"this string is frozen".freeze)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue