Skip to content

Commit

Permalink
Fix Range#== to ignore generic type arguments (#10309)
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota authored Feb 12, 2021
1 parent 45a5703 commit 6310431
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
13 changes: 13 additions & 0 deletions spec/std/range_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ describe "Range" do
r.excludes_end?.should be_true
end

it "#==" do
((1..1) == (1..1)).should be_true
((1...1) == (1..1)).should be_false
((1...1) == (1...1)).should be_true
((1..1) == (1...1)).should be_false

((1..nil) == (1..nil)).should be_true

(1..1).should eq Range(Int32?, Int32?).new(1, 1)
((1..1) == Range(Int32?, Int32?).new(1, 1)).should be_true
((1.0..1.0) == (1..1)).should be_true
end

it "includes?" do
(1..5).includes?(1).should be_true
(1..5).includes?(5).should be_true
Expand Down
4 changes: 4 additions & 0 deletions src/range.cr
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ struct Range(B, E)
def initialize(@begin : B, @end : E, @exclusive : Bool = false)
end

def ==(other : Range)
@begin == other.@begin && @end == other.@end && @exclusive == other.@exclusive
end

# Returns an `Iterator` that cycles over the values of this range.
#
# ```
Expand Down

0 comments on commit 6310431

Please sign in to comment.