2018-03-04 10:09:32 -05:00
|
|
|
require_relative '../../spec_helper'
|
2017-05-07 08:04:49 -04:00
|
|
|
|
2018-04-28 15:50:06 -04:00
|
|
|
describe 'String#-@' do
|
|
|
|
it 'returns self if the String is frozen' do
|
|
|
|
input = 'foo'.freeze
|
|
|
|
output = -input
|
2017-05-07 08:04:49 -04:00
|
|
|
|
2018-04-28 15:50:06 -04:00
|
|
|
output.equal?(input).should == true
|
|
|
|
output.frozen?.should == true
|
|
|
|
end
|
2017-05-07 08:04:49 -04:00
|
|
|
|
2018-04-28 15:50:06 -04:00
|
|
|
it 'returns a frozen copy if the String is not frozen' do
|
|
|
|
input = 'foo'
|
|
|
|
output = -input
|
2018-01-29 11:08:16 -05:00
|
|
|
|
2018-04-28 15:50:06 -04:00
|
|
|
output.frozen?.should == true
|
|
|
|
output.should == 'foo'
|
|
|
|
end
|
2018-01-29 11:08:16 -05:00
|
|
|
|
2018-04-28 15:50:06 -04:00
|
|
|
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(' ')
|
2018-01-29 11:08:16 -05:00
|
|
|
|
2018-04-28 15:50:06 -04:00
|
|
|
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
|
2018-01-29 11:08:16 -05:00
|
|
|
|
2018-04-28 15:50:06 -04:00
|
|
|
it "is an identity function if the string is frozen" do
|
|
|
|
dynamic = %w(this string is frozen).join(' ').freeze
|
2018-01-29 11:08:16 -05:00
|
|
|
|
2018-04-28 15:50:06 -04:00
|
|
|
(-dynamic).should equal(dynamic)
|
2018-01-29 11:08:16 -05:00
|
|
|
|
2018-04-28 15:50:06 -04:00
|
|
|
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)
|
2018-01-29 11:08:16 -05:00
|
|
|
end
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
end
|