-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bindings/go: Fix bug in RangeText function (#242)
- Loading branch information
1 parent
dc6f8c6
commit 6495bfb
Showing
4 changed files
with
130 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package scip | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hexops/autogold/v2" | ||
) | ||
|
||
const testFileContents = `Mary had a little lamb, | ||
Its fleece was white as snow. | ||
And everywhere that Mary went, | ||
The lamb was sure to go. | ||
` | ||
|
||
func TestRangeText(t *testing.T) { | ||
// Update expect values with `go test ./bindings/go/scip -update` | ||
testCases := []struct { | ||
range_ []int32 | ||
expect autogold.Value | ||
}{ | ||
{range_: []int32{0, 0, 0, 0}, expect: autogold.Expect("")}, | ||
{range_: []int32{0, 0, 0, 8}, expect: autogold.Expect("Mary had")}, | ||
{range_: []int32{0, 0, 1, 0}, expect: autogold.Expect("Mary had a little lamb,\n")}, | ||
{range_: []int32{0, 0, 1, 10}, expect: autogold.Expect("Mary had a little lamb,\nIts fleece")}, | ||
{range_: []int32{0, 0, 4, 0}, expect: autogold.Expect(`Mary had a little lamb, | ||
Its fleece was white as snow. | ||
And everywhere that Mary went, | ||
The lamb was sure to go. | ||
`)}, | ||
} | ||
|
||
sourceFile := NewSourceFile("", "", testFileContents) | ||
|
||
for _, testCase := range testCases { | ||
r := testCase.range_ | ||
range_ := Range{Start: Position{Line: r[0], Character: r[1]}, End: Position{Line: r[2], Character: r[3]}} | ||
t.Run(fmt.Sprintf("%v", range_), func(t *testing.T) { | ||
testCase.expect.Equal(t, sourceFile.RangeText(range_)) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.