Skip to content

Commit 09cd312

Browse files
committed
Add tests for changes to String#+@ in 3.4
1 parent 64a1a40 commit 09cd312

1 file changed

Lines changed: 39 additions & 5 deletions

File tree

core/string/uplus_spec.rb

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,48 @@
1313
output.should == 'foobar'
1414
end
1515

16-
it 'returns self if the String is not frozen' do
17-
input = 'foo'
16+
it 'returns a mutable String itself' do
17+
input = String.new("foo")
1818
output = +input
1919

20-
output.equal?(input).should == true
20+
output.should.equal?(input)
21+
22+
input << "bar"
23+
output.should == "foobar"
24+
end
25+
26+
context 'if file has "frozen_string_literal: true" magic comment' do
27+
it 'returns mutable copy of a literal' do
28+
ruby_exe(fixture(__FILE__, "freeze_magic_comment.rb")).should == 'mutable'
29+
end
2130
end
2231

23-
it 'returns mutable copy despite freeze-magic-comment in file' do
24-
ruby_exe(fixture(__FILE__, "freeze_magic_comment.rb")).should == 'mutable'
32+
context 'if file has "frozen_string_literal: false" magic comment' do
33+
it 'returns literal string itself' do
34+
input = 'foo'
35+
output = +input
36+
37+
output.equal?(input).should == true
38+
end
39+
end
40+
41+
context 'if file has no frozen_string_literal magic comment' do
42+
ruby_version_is ''...'3.4' do
43+
it 'returns literal string itself' do
44+
eval(<<~RUBY).should == true
45+
s = "foo"
46+
s.equal?(+s)
47+
RUBY
48+
end
49+
end
50+
51+
ruby_version_is '3.4' do
52+
it 'returns mutable copy of a literal' do
53+
eval(<<~RUBY).should == false
54+
s = "foo"
55+
s.equal?(+s)
56+
RUBY
57+
end
58+
end
2559
end
2660
end

0 commit comments

Comments
 (0)