-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3ba7ec4
commit 29f358e
Showing
18 changed files
with
241 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
spec/ruby/command_line/fixtures/string_literal_frozen_comment.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# frozen_string_literal: true | ||
frozen = "test".frozen? | ||
interned = "test".equal?("test") | ||
puts "frozen:#{frozen} interned:#{interned}" |
4 changes: 4 additions & 0 deletions
4
spec/ruby/command_line/fixtures/string_literal_mutable_comment.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# frozen_string_literal: false | ||
frozen = "test".frozen? | ||
interned = "test".equal?("test") | ||
puts "frozen:#{frozen} interned:#{interned}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
frozen = "test".frozen? | ||
interned = "test".equal?("test") | ||
puts "frozen:#{frozen} interned:#{interned}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
require_relative '../../spec_helper' | ||
|
||
describe "chilled String" do | ||
guard -> { ruby_version_is "3.4" and !"test".equal?("test") } do | ||
describe "#frozen?" do | ||
it "returns true" do | ||
"chilled".frozen?.should == true | ||
end | ||
end | ||
|
||
describe "#-@" do | ||
it "returns a different instance" do | ||
input = "chilled" | ||
interned = (-input) | ||
interned.frozen?.should == true | ||
interned.object_id.should_not == input.object_id | ||
end | ||
end | ||
|
||
describe "#+@" do | ||
it "returns a different instance" do | ||
input = "chilled" | ||
duped = (+input) | ||
duped.frozen?.should == false | ||
duped.object_id.should_not == input.object_id | ||
end | ||
end | ||
|
||
describe "#clone" do | ||
it "preserves chilled status" do | ||
input = "chilled".clone | ||
-> { | ||
input << "-mutated" | ||
}.should complain(/literal string will be frozen in the future/) | ||
input.should == "chilled-mutated" | ||
end | ||
end | ||
|
||
describe "mutation" do | ||
it "emits a warning" do | ||
input = "chilled" | ||
-> { | ||
input << "-mutated" | ||
}.should complain(/literal string will be frozen in the future/) | ||
input.should == "chilled-mutated" | ||
end | ||
|
||
it "emits a warning on singleton_class creaation" do | ||
-> { | ||
"chilled".singleton_class | ||
}.should complain(/literal string will be frozen in the future/) | ||
end | ||
|
||
it "emits a warning on instance variable assignment" do | ||
-> { | ||
"chilled".instance_variable_set(:@ivar, 42) | ||
}.should complain(/literal string will be frozen in the future/) | ||
end | ||
|
||
it "raises FrozenError after the string was explictly frozen" do | ||
input = "chilled" | ||
input.freeze | ||
-> { | ||
input << "mutated" | ||
}.should raise_error(FrozenError) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.