summaryrefslogtreecommitdiff
path: root/spec/ruby/core/string/shared
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/string/shared')
-rw-r--r--spec/ruby/core/string/shared/dedup.rb51
-rw-r--r--spec/ruby/core/string/shared/each_codepoint_without_block.rb33
-rw-r--r--spec/ruby/core/string/shared/equal_value.rb29
-rw-r--r--spec/ruby/core/string/shared/length.rb55
-rw-r--r--spec/ruby/core/string/shared/succ.rb87
-rw-r--r--spec/ruby/core/string/shared/to_s.rb13
-rw-r--r--spec/ruby/core/string/shared/to_sym.rb72
7 files changed, 0 insertions, 340 deletions
diff --git a/spec/ruby/core/string/shared/dedup.rb b/spec/ruby/core/string/shared/dedup.rb
deleted file mode 100644
index 59506c2901..0000000000
--- a/spec/ruby/core/string/shared/dedup.rb
+++ /dev/null
@@ -1,51 +0,0 @@
-# frozen_string_literal: false
-describe :string_dedup, shared: true do
- it 'returns self if the String is frozen' do
- input = 'foo'.freeze
- output = input.send(@method)
-
- output.should.equal?(input)
- output.should.frozen?
- end
-
- it 'returns a frozen copy if the String is not frozen' do
- input = 'foo'
- output = input.send(@method)
-
- output.should.frozen?
- output.should_not.equal?(input)
- output.should == 'foo'
- end
-
- 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.send(@method).should.equal?(dynamic.send(@method))
- end
-
- it "returns the same object when it's called on the same String literal" do
- "unfrozen string".send(@method).should.equal?("unfrozen string".send(@method))
- "unfrozen string".send(@method).should_not.equal?("another unfrozen string".send(@method))
- end
-
- it "deduplicates frozen strings" do
- dynamic = %w(this string is frozen).join(' ').freeze
-
- dynamic.should_not.equal?("this string is frozen".freeze)
-
- dynamic.send(@method).should.equal?("this string is frozen".freeze)
- dynamic.send(@method).should.equal?("this string is frozen".send(@method).freeze)
- end
-
- it "does not deduplicate a frozen string when it has instance variables" do
- dynamic = %w(this string is frozen).join(' ')
- dynamic.instance_variable_set(:@a, 1)
- dynamic.freeze
-
- dynamic.send(@method).should_not.equal?("this string is frozen".freeze)
- dynamic.send(@method).should_not.equal?("this string is frozen".send(@method).freeze)
- dynamic.send(@method).should.equal?(dynamic)
- end
-end
diff --git a/spec/ruby/core/string/shared/each_codepoint_without_block.rb b/spec/ruby/core/string/shared/each_codepoint_without_block.rb
deleted file mode 100644
index 60d603954c..0000000000
--- a/spec/ruby/core/string/shared/each_codepoint_without_block.rb
+++ /dev/null
@@ -1,33 +0,0 @@
-# encoding: binary
-describe :string_each_codepoint_without_block, shared: true do
- describe "when no block is given" do
- it "returns an Enumerator" do
- "".send(@method).should.instance_of?(Enumerator)
- end
-
- it "returns an Enumerator even when self has an invalid encoding" do
- s = "\xDF".dup.force_encoding(Encoding::UTF_8)
- s.valid_encoding?.should == false
- s.send(@method).should.instance_of?(Enumerator)
- end
-
- describe "returned Enumerator" do
- describe "size" do
- it "should return the size of the string" do
- str = "hello"
- str.send(@method).size.should == str.size
- str = "ola"
- str.send(@method).size.should == str.size
- str = "\303\207\342\210\202\303\251\306\222g"
- str.send(@method).size.should == str.size
- end
-
- it "should return the size of the string even when the string has an invalid encoding" do
- s = "\xDF".dup.force_encoding(Encoding::UTF_8)
- s.valid_encoding?.should == false
- s.send(@method).size.should == 1
- end
- end
- end
- end
-end
diff --git a/spec/ruby/core/string/shared/equal_value.rb b/spec/ruby/core/string/shared/equal_value.rb
deleted file mode 100644
index dfc5c7cd29..0000000000
--- a/spec/ruby/core/string/shared/equal_value.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-require_relative '../../../spec_helper'
-require_relative '../fixtures/classes'
-
-describe :string_equal_value, shared: true do
- it "returns false if obj does not respond to to_str" do
- 'hello'.send(@method, 5).should == false
- not_supported_on :opal do
- 'hello'.send(@method, :hello).should == false
- end
- 'hello'.send(@method, mock('x')).should == false
- end
-
- it "returns obj == self if obj responds to to_str" do
- obj = Object.new
-
- # String#== merely checks if #to_str is defined. It does
- # not call it.
- obj.stub!(:to_str)
-
- # Don't use @method for :== in `obj.should_receive(:==)`
- obj.should_receive(:==).and_return(true)
-
- 'hello'.send(@method, obj).should == true
- end
-
- it "is not fooled by NUL characters" do
- "abc\0def".send(@method, "abc\0xyz").should == false
- end
-end
diff --git a/spec/ruby/core/string/shared/length.rb b/spec/ruby/core/string/shared/length.rb
deleted file mode 100644
index ae572ba755..0000000000
--- a/spec/ruby/core/string/shared/length.rb
+++ /dev/null
@@ -1,55 +0,0 @@
-# encoding: utf-8
-
-describe :string_length, shared: true do
- it "returns the length of self" do
- "".send(@method).should == 0
- "\x00".send(@method).should == 1
- "one".send(@method).should == 3
- "two".send(@method).should == 3
- "three".send(@method).should == 5
- "four".send(@method).should == 4
- end
-
- it "returns the length of a string in different encodings" do
- utf8_str = 'こにちわ' * 100
- utf8_str.send(@method).should == 400
- utf8_str.encode(Encoding::UTF_32BE).send(@method).should == 400
- utf8_str.encode(Encoding::SHIFT_JIS).send(@method).should == 400
- end
-
- it "returns the length of the new self after encoding is changed" do
- str = +'こにちわ'
- str.send(@method)
-
- str.force_encoding('BINARY').send(@method).should == 12
- end
-
- it "returns the correct length after force_encoding(BINARY)" do
- utf8 = "あ"
- ascii = "a"
- concat = utf8 + ascii
-
- concat.encoding.should == Encoding::UTF_8
- concat.bytesize.should == 4
-
- concat.send(@method).should == 2
- concat.force_encoding(Encoding::ASCII_8BIT)
- concat.send(@method).should == 4
- end
-
- it "adds 1 for every invalid byte in UTF-8" do
- "\xF4\x90\x80\x80".send(@method).should == 4
- "a\xF4\x90\x80\x80b".send(@method).should == 6
- "é\xF4\x90\x80\x80è".send(@method).should == 6
- end
-
- it "adds 1 (and not 2) for a incomplete surrogate in UTF-16" do
- "\x00\xd8".dup.force_encoding("UTF-16LE").send(@method).should == 1
- "\xd8\x00".dup.force_encoding("UTF-16BE").send(@method).should == 1
- end
-
- it "adds 1 for a broken sequence in UTF-32" do
- "\x04\x03\x02\x01".dup.force_encoding("UTF-32LE").send(@method).should == 1
- "\x01\x02\x03\x04".dup.force_encoding("UTF-32BE").send(@method).should == 1
- end
-end
diff --git a/spec/ruby/core/string/shared/succ.rb b/spec/ruby/core/string/shared/succ.rb
deleted file mode 100644
index 8f1d327741..0000000000
--- a/spec/ruby/core/string/shared/succ.rb
+++ /dev/null
@@ -1,87 +0,0 @@
-# encoding: binary
-describe :string_succ, shared: true do
- it "returns an empty string for empty strings" do
- "".send(@method).should == ""
- end
-
- it "returns the successor by increasing the rightmost alphanumeric (digit => digit, letter => letter with same case)" do
- "abcd".send(@method).should == "abce"
- "THX1138".send(@method).should == "THX1139"
-
- "<<koala>>".send(@method).should == "<<koalb>>"
- "==A??".send(@method).should == "==B??"
- end
-
- it "increases non-alphanumerics (via ascii rules) if there are no alphanumerics" do
- "***".send(@method).should == "**+"
- "**`".send(@method).should == "**a"
- end
-
- it "increases the next best alphanumeric (jumping over non-alphanumerics) if there is a carry" do
- "dz".send(@method).should == "ea"
- "HZ".send(@method).should == "IA"
- "49".send(@method).should == "50"
-
- "izz".send(@method).should == "jaa"
- "IZZ".send(@method).should == "JAA"
- "699".send(@method).should == "700"
-
- "6Z99z99Z".send(@method).should == "7A00a00A"
-
- "1999zzz".send(@method).should == "2000aaa"
- "NZ/[]ZZZ9999".send(@method).should == "OA/[]AAA0000"
- end
-
- it "increases the next best character if there is a carry for non-alphanumerics" do
- "(\xFF".send(@method).should == ")\x00"
- "`\xFF".send(@method).should == "a\x00"
- "<\xFF\xFF".send(@method).should == "=\x00\x00"
- end
-
- it "adds an additional character (just left to the last increased one) if there is a carry and no character left to increase" do
- "z".send(@method).should == "aa"
- "Z".send(@method).should == "AA"
- "9".send(@method).should == "10"
-
- "zz".send(@method).should == "aaa"
- "ZZ".send(@method).should == "AAA"
- "99".send(@method).should == "100"
-
- "9Z99z99Z".send(@method).should == "10A00a00A"
-
- "ZZZ9999".send(@method).should == "AAAA0000"
- "/[]9999".send(@method).should == "/[]10000"
- "/[]ZZZ9999".send(@method).should == "/[]AAAA0000"
- "Z/[]ZZZ9999".send(@method).should == "AA/[]AAA0000"
-
- # non-alphanumeric cases
- "\xFF".send(@method).should == "\x01\x00"
- "\xFF\xFF".send(@method).should == "\x01\x00\x00"
- end
-
- it "returns String instances when called on a subclass" do
- StringSpecs::MyString.new("").send(@method).should.instance_of?(String)
- StringSpecs::MyString.new("a").send(@method).should.instance_of?(String)
- StringSpecs::MyString.new("z").send(@method).should.instance_of?(String)
- end
-
- it "returns a String in the same encoding as self" do
- "z".encode("US-ASCII").send(@method).encoding.should == Encoding::US_ASCII
- end
-end
-
-describe :string_succ_bang, shared: true do
- it "is equivalent to succ, but modifies self in place (still returns self)" do
- ["", "abcd", "THX1138"].each do |s|
- s = +s
- r = s.dup.send(@method)
- s.send(@method).should.equal?(s)
- s.should == r
- end
- end
-
- it "raises a FrozenError if self is frozen" do
- -> { "".freeze.send(@method) }.should.raise(FrozenError)
- -> { "abcd".freeze.send(@method) }.should.raise(FrozenError)
- end
-end
diff --git a/spec/ruby/core/string/shared/to_s.rb b/spec/ruby/core/string/shared/to_s.rb
deleted file mode 100644
index 96c59470d6..0000000000
--- a/spec/ruby/core/string/shared/to_s.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-describe :string_to_s, shared: true do
- it "returns self when self.class == String" do
- a = "a string"
- a.should.equal?(a.send(@method))
- end
-
- it "returns a new instance of String when called on a subclass" do
- a = StringSpecs::MyString.new("a string")
- s = a.send(@method)
- s.should == "a string"
- s.should.instance_of?(String)
- end
-end
diff --git a/spec/ruby/core/string/shared/to_sym.rb b/spec/ruby/core/string/shared/to_sym.rb
deleted file mode 100644
index 2a8a2e3182..0000000000
--- a/spec/ruby/core/string/shared/to_sym.rb
+++ /dev/null
@@ -1,72 +0,0 @@
-describe :string_to_sym, shared: true do
- it "returns the symbol corresponding to self" do
- "Koala".send(@method).should.equal? :Koala
- 'cat'.send(@method).should.equal? :cat
- '@cat'.send(@method).should.equal? :@cat
- 'cat and dog'.send(@method).should.equal? :"cat and dog"
- "abc=".send(@method).should.equal? :abc=
- end
-
- it "does not special case +(binary) and -(binary)" do
- "+(binary)".send(@method).should.equal? :"+(binary)"
- "-(binary)".send(@method).should.equal? :"-(binary)"
- end
-
- it "does not special case certain operators" do
- "!@".send(@method).should.equal? :"!@"
- "~@".send(@method).should.equal? :"~@"
- "!(unary)".send(@method).should.equal? :"!(unary)"
- "~(unary)".send(@method).should.equal? :"~(unary)"
- "+(unary)".send(@method).should.equal? :"+(unary)"
- "-(unary)".send(@method).should.equal? :"-(unary)"
- end
-
- it "returns a US-ASCII Symbol for a UTF-8 String containing only US-ASCII characters" do
- sym = "foobar".send(@method)
- sym.encoding.should == Encoding::US_ASCII
- sym.should.equal? :"foobar"
- end
-
- it "returns a US-ASCII Symbol for a binary String containing only US-ASCII characters" do
- sym = "foobar".b.send(@method)
- sym.encoding.should == Encoding::US_ASCII
- sym.should.equal? :"foobar"
- end
-
- it "returns a UTF-8 Symbol for a UTF-8 String containing non US-ASCII characters" do
- sym = "il était une fois".send(@method)
- sym.encoding.should == Encoding::UTF_8
- sym.should.equal? :"il était une #{'fois'}"
- end
-
- it "returns a UTF-16LE Symbol for a UTF-16LE String containing non US-ASCII characters" do
- utf16_str = "UtéF16".encode(Encoding::UTF_16LE)
- sym = utf16_str.send(@method)
- sym.encoding.should == Encoding::UTF_16LE
- sym.to_s.should == utf16_str
- end
-
- it "returns a binary Symbol for a binary String containing non US-ASCII characters" do
- binary_string = "binarí".b
- sym = binary_string.send(@method)
- sym.encoding.should == Encoding::BINARY
- sym.to_s.should == binary_string
- end
-
- it "ignores existing symbols with different encoding" do
- source = "fée"
-
- iso_symbol = source.dup.force_encoding(Encoding::ISO_8859_1).send(@method)
- iso_symbol.encoding.should == Encoding::ISO_8859_1
- binary_symbol = source.dup.force_encoding(Encoding::BINARY).send(@method)
- binary_symbol.encoding.should == Encoding::BINARY
- end
-
- it "raises an EncodingError for UTF-8 String containing invalid bytes" do
- invalid_utf8 = "\xC3"
- invalid_utf8.should_not.valid_encoding?
- -> {
- invalid_utf8.send(@method)
- }.should.raise(EncodingError, 'invalid symbol in encoding UTF-8 :"\xC3"')
- end
-end