diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-01-29 16:08:16 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-01-29 16:08:16 +0000 |
commit | 3fa5bd38af50fb3d98de0ea51043d73f8d06a24b (patch) | |
tree | d473b71cc6925ee1e17727215e9f9a66e3f24802 /spec/ruby/core/string | |
parent | 1e658d45e1f8dbadab18f9c35b5cfb5a5fec98bf (diff) | |
download | ruby-3fa5bd38af50fb3d98de0ea51043d73f8d06a24b.tar.gz |
Update to ruby/spec@83063a3
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62094 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/core/string')
-rw-r--r-- | spec/ruby/core/string/case_compare_spec.rb | 4 | ||||
-rw-r--r-- | spec/ruby/core/string/chars_spec.rb | 2 | ||||
-rw-r--r-- | spec/ruby/core/string/codepoints_spec.rb | 2 | ||||
-rw-r--r-- | spec/ruby/core/string/each_char_spec.rb | 4 | ||||
-rw-r--r-- | spec/ruby/core/string/each_codepoint_spec.rb | 4 | ||||
-rw-r--r-- | spec/ruby/core/string/each_line_spec.rb | 4 | ||||
-rw-r--r-- | spec/ruby/core/string/eql_spec.rb | 2 | ||||
-rw-r--r-- | spec/ruby/core/string/equal_value_spec.rb | 4 | ||||
-rw-r--r-- | spec/ruby/core/string/intern_spec.rb | 2 | ||||
-rw-r--r-- | spec/ruby/core/string/length_spec.rb | 2 | ||||
-rw-r--r-- | spec/ruby/core/string/lines_spec.rb | 2 | ||||
-rw-r--r-- | spec/ruby/core/string/modulo_spec.rb | 9 | ||||
-rw-r--r-- | spec/ruby/core/string/next_spec.rb | 4 | ||||
-rw-r--r-- | spec/ruby/core/string/size_spec.rb | 2 | ||||
-rw-r--r-- | spec/ruby/core/string/start_with_spec.rb | 31 | ||||
-rw-r--r-- | spec/ruby/core/string/succ_spec.rb | 4 | ||||
-rw-r--r-- | spec/ruby/core/string/to_s_spec.rb | 2 | ||||
-rw-r--r-- | spec/ruby/core/string/to_str_spec.rb | 2 | ||||
-rw-r--r-- | spec/ruby/core/string/to_sym_spec.rb | 2 | ||||
-rw-r--r-- | spec/ruby/core/string/uminus_spec.rb | 25 |
20 files changed, 85 insertions, 28 deletions
diff --git a/spec/ruby/core/string/case_compare_spec.rb b/spec/ruby/core/string/case_compare_spec.rb index 930f5bea90..a4f2d7960e 100644 --- a/spec/ruby/core/string/case_compare_spec.rb +++ b/spec/ruby/core/string/case_compare_spec.rb @@ -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 diff --git a/spec/ruby/core/string/chars_spec.rb b/spec/ruby/core/string/chars_spec.rb index 75cef89be1..7f764a3e43 100644 --- a/spec/ruby/core/string/chars_spec.rb +++ b/spec/ruby/core/string/chars_spec.rb @@ -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) diff --git a/spec/ruby/core/string/codepoints_spec.rb b/spec/ruby/core/string/codepoints_spec.rb index 6304513583..bae83ba86d 100644 --- a/spec/ruby/core/string/codepoints_spec.rb +++ b/spec/ruby/core/string/codepoints_spec.rb @@ -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] diff --git a/spec/ruby/core/string/each_char_spec.rb b/spec/ruby/core/string/each_char_spec.rb index 3233c7609d..4894c745c7 100644 --- a/spec/ruby/core/string/each_char_spec.rb +++ b/spec/ruby/core/string/each_char_spec.rb @@ -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 diff --git a/spec/ruby/core/string/each_codepoint_spec.rb b/spec/ruby/core/string/each_codepoint_spec.rb index 4e910f44b5..3ad4b719fc 100644 --- a/spec/ruby/core/string/each_codepoint_spec.rb +++ b/spec/ruby/core/string/each_codepoint_spec.rb @@ -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 diff --git a/spec/ruby/core/string/each_line_spec.rb b/spec/ruby/core/string/each_line_spec.rb index 865ae264d6..ede272a0a0 100644 --- a/spec/ruby/core/string/each_line_spec.rb +++ b/spec/ruby/core/string/each_line_spec.rb @@ -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 diff --git a/spec/ruby/core/string/eql_spec.rb b/spec/ruby/core/string/eql_spec.rb index df094e122f..ccc0bcbaa8 100644 --- a/spec/ruby/core/string/eql_spec.rb +++ b/spec/ruby/core/string/eql_spec.rb @@ -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 diff --git a/spec/ruby/core/string/equal_value_spec.rb b/spec/ruby/core/string/equal_value_spec.rb index bf252d6d30..cec6843fe6 100644 --- a/spec/ruby/core/string/equal_value_spec.rb +++ b/spec/ruby/core/string/equal_value_spec.rb @@ -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 diff --git a/spec/ruby/core/string/intern_spec.rb b/spec/ruby/core/string/intern_spec.rb index 71f3633920..c0196f7e2c 100644 --- a/spec/ruby/core/string/intern_spec.rb +++ b/spec/ruby/core/string/intern_spec.rb @@ -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 diff --git a/spec/ruby/core/string/length_spec.rb b/spec/ruby/core/string/length_spec.rb index 5f51f6bc01..215b5ec854 100644 --- a/spec/ruby/core/string/length_spec.rb +++ b/spec/ruby/core/string/length_spec.rb @@ -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 diff --git a/spec/ruby/core/string/lines_spec.rb b/spec/ruby/core/string/lines_spec.rb index e5f24816af..111cc14508 100644 --- a/spec/ruby/core/string/lines_spec.rb +++ b/spec/ruby/core/string/lines_spec.rb @@ -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, ' ') diff --git a/spec/ruby/core/string/modulo_spec.rb b/spec/ruby/core/string/modulo_spec.rb index 4f26ac5033..7cb3561b17 100644 --- a/spec/ruby/core/string/modulo_spec.rb +++ b/spec/ruby/core/string/modulo_spec.rb @@ -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 diff --git a/spec/ruby/core/string/next_spec.rb b/spec/ruby/core/string/next_spec.rb index 6b4a98d993..185f857cf0 100644 --- a/spec/ruby/core/string/next_spec.rb +++ b/spec/ruby/core/string/next_spec.rb @@ -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 diff --git a/spec/ruby/core/string/size_spec.rb b/spec/ruby/core/string/size_spec.rb index b3172453ea..7e1afd9c54 100644 --- a/spec/ruby/core/string/size_spec.rb +++ b/spec/ruby/core/string/size_spec.rb @@ -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 diff --git a/spec/ruby/core/string/start_with_spec.rb b/spec/ruby/core/string/start_with_spec.rb index 1b27fdaed7..cba40d70f1 100644 --- a/spec/ruby/core/string/start_with_spec.rb +++ b/spec/ruby/core/string/start_with_spec.rb @@ -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 diff --git a/spec/ruby/core/string/succ_spec.rb b/spec/ruby/core/string/succ_spec.rb index 311453702d..52b5a6c1ee 100644 --- a/spec/ruby/core/string/succ_spec.rb +++ b/spec/ruby/core/string/succ_spec.rb @@ -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 diff --git a/spec/ruby/core/string/to_s_spec.rb b/spec/ruby/core/string/to_s_spec.rb index b483b1b138..8551b080a6 100644 --- a/spec/ruby/core/string/to_s_spec.rb +++ b/spec/ruby/core/string/to_s_spec.rb @@ -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 diff --git a/spec/ruby/core/string/to_str_spec.rb b/spec/ruby/core/string/to_str_spec.rb index fb1260a687..a326b52bca 100644 --- a/spec/ruby/core/string/to_str_spec.rb +++ b/spec/ruby/core/string/to_str_spec.rb @@ -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 diff --git a/spec/ruby/core/string/to_sym_spec.rb b/spec/ruby/core/string/to_sym_spec.rb index 7659f266cd..cb41afc636 100644 --- a/spec/ruby/core/string/to_sym_spec.rb +++ b/spec/ruby/core/string/to_sym_spec.rb @@ -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 diff --git a/spec/ruby/core/string/uminus_spec.rb b/spec/ruby/core/string/uminus_spec.rb index 53e73b7e67..f18e6b1234 100644 --- a/spec/ruby/core/string/uminus_spec.rb +++ b/spec/ruby/core/string/uminus_spec.rb @@ -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 |