Skip to content

Commit 74aaacf

Browse files
bindings/go: Fix bug in range comparison. (#12)
1 parent c979f67 commit 74aaacf

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

bindings/go/scip/testutil/format.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,10 @@ func isSCIPRangeLess(a []int32, b []int32) bool {
152152
return len(a) < len(b)
153153
}
154154
if a[2] != b[2] { // end line
155-
return a[2] < b[1]
155+
return a[2] < b[2]
156156
}
157-
// end character
158-
return a[3] < b[2]
157+
if len(a) == 4 {
158+
return a[3] < b[3]
159+
}
160+
return false
159161
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package testutil
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/require"
7+
)
8+
9+
func TestIsScipRangeLess(t *testing.T) {
10+
testCases := []struct {
11+
lhs []int32
12+
rhs []int32
13+
}{
14+
{[]int32{0, 1, 2}, []int32{1, 0, 0}},
15+
{[]int32{0, 1, 10}, []int32{0, 2, 3}},
16+
{[]int32{0, 1, 2, 3}, []int32{0, 2, 4}},
17+
{[]int32{0, 1, 4}, []int32{0, 1, 2, 3}},
18+
{[]int32{0, 1, 2, 3}, []int32{0, 1, 4, 0}},
19+
{[]int32{0, 1, 2, 3}, []int32{0, 1, 2, 4}},
20+
}
21+
for _, testCase := range testCases {
22+
require.Truef(t, isSCIPRangeLess(testCase.lhs, testCase.rhs),
23+
"%v ≮ %v", testCase.lhs, testCase.rhs)
24+
require.Falsef(t, isSCIPRangeLess(testCase.rhs, testCase.lhs),
25+
"%v < %v", testCase.rhs, testCase.lhs)
26+
27+
require.Falsef(t, isSCIPRangeLess(testCase.lhs, testCase.lhs),
28+
"%v < %v", testCase.lhs, testCase.lhs)
29+
require.Falsef(t, isSCIPRangeLess(testCase.lhs, testCase.lhs),
30+
"%v < %v", testCase.rhs, testCase.rhs)
31+
}
32+
33+
}

0 commit comments

Comments
 (0)