Skip to content

Commit

Permalink
Bugfix for Interval Set
Browse files Browse the repository at this point in the history
This is necessary or else the last else if will never be executed and the function returns wrong results for some cases. For example, these tests will not run without this change:

TestRemoveRangeSameStart() {
	i := NewIntervalSet()
	i.addInterval(antlr.NewInterval(1, 10))
	i.removeRange(antlr.NewInterval(1, 7))

	suite.Len(i.intervals, 1)
	suite.Equal(7, i.intervals[0].Start)
	suite.Equal(10, i.intervals[0].Stop)
}

TestRemoveRangeOverStartBound() {
	i := NewIntervalSet()
	i.addInterval(antlr.NewInterval(5, 15))

	i.removeRange(antlr.NewInterval(1, 10))
	suite.Len(i.intervals, 1)
	suite.Equal(10, i.intervals[0].Start)
	suite.Equal(15, i.intervals[0].Stop)
}


Signed-off-by: Gustavo de Morais <[email protected]>
  • Loading branch information
gustavodemorais authored Dec 6, 2023
1 parent d25d421 commit 5599637
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion runtime/Go/antlr/v4/interval_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (i *IntervalSet) removeRange(v Interval) {
// i.intervals.splice(k, 1)
i.intervals = append(i.intervals[0:k], i.intervals[k+1:]...)
k = k - 1 // need another pass
} else if v.Start < ni.Stop {
} else if v.Start < ni.Stop && v.Start > ni.Start {
i.intervals[k] = NewInterval(ni.Start, v.Start)
} else if v.Stop < ni.Stop {
i.intervals[k] = NewInterval(v.Stop, ni.Stop)
Expand Down

0 comments on commit 5599637

Please sign in to comment.