Skip to content

Commit 1010f95

Browse files
committed
Add specs for frozen state of ranges on creation and cloning.
1 parent 184eb4f commit 1010f95

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

spec/ruby/core/range/clone_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
require_relative '../../spec_helper'
2+
3+
describe "Range#clone" do
4+
it "duplicates the range" do
5+
copy = (1..3).clone
6+
copy.begin.should == 1
7+
copy.end.should == 3
8+
copy.should_not.exclude_end?
9+
10+
copy = ("a"..."z").clone
11+
copy.begin.should == "a"
12+
copy.end.should == "z"
13+
copy.should.exclude_end?
14+
end
15+
16+
it "maintains the frozen state" do
17+
(1..2).clone.frozen?.should == (1..2).frozen?
18+
(1..).clone.frozen?.should == (1..).frozen?
19+
Range.new(1, 2).clone.frozen?.should == Range.new(1, 2).frozen?
20+
Class.new(Range).new(1, 2).clone.frozen?.should == Class.new(Range).new(1, 2).frozen?
21+
end
22+
end

spec/ruby/core/range/new_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,15 @@
6565

6666
range_exclude.should_not == range_include
6767
end
68+
69+
ruby_version_is "3.0" do
70+
it "creates a frozen range if the class is Range.class" do
71+
Range.new(1, 2).should.frozen?
72+
end
73+
74+
it "does not create a frozen range if the class is not Range.class" do
75+
Class.new(Range).new(1, 2).should_not.frozen?
76+
end
77+
end
6878
end
6979
end

0 commit comments

Comments
 (0)