From f90488de1f657abf24026231485c87d3e42ee11d Mon Sep 17 00:00:00 2001 From: Alban Peignier Date: Sun, 17 Dec 2017 15:31:47 +0100 Subject: Move (clean) period split logic into Range#remove. Refs #5299 --- spec/lib/range_ext_spec.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'spec/lib') diff --git a/spec/lib/range_ext_spec.rb b/spec/lib/range_ext_spec.rb index 9c44608b9..cae637e47 100644 --- a/spec/lib/range_ext_spec.rb +++ b/spec/lib/range_ext_spec.rb @@ -15,4 +15,27 @@ RSpec.describe Range do expect( (2..4) & (1..3) ).to eq 2..3 end end + + context "remove" do + it "is unchanged when the given range has no intersection" do + expect( (1..2).remove(3..4) ).to eq 1..2 + expect( (3..4).remove(1..2) ).to eq 3..4 + end + + it "is nil for two equal ranges" do + expect( (1..2).remove(1..2) ).to be_empty + end + + it "is the begin of the range when given range intersect the end" do + expect( (5..10).remove(8..15) ).to eq [5..7] + end + + it "is the end of the range when given range intersect the begin" do + expect( (5..10).remove(1..6) ).to eq [7..10] + end + + it "is the two remaing ranges when given range is the middle" do + expect( (1..10).remove(4..6) ).to eq [1..3, 7..10] + end + end end -- cgit v1.2.3