aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/tdewolff/parse/position_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/tdewolff/parse/position_test.go')
-rw-r--r--vendor/github.com/tdewolff/parse/position_test.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/vendor/github.com/tdewolff/parse/position_test.go b/vendor/github.com/tdewolff/parse/position_test.go
new file mode 100644
index 0000000..eb1e4e5
--- /dev/null
+++ b/vendor/github.com/tdewolff/parse/position_test.go
@@ -0,0 +1,42 @@
+package parse
+
+import (
+ "bytes"
+ "fmt"
+ "io"
+ "testing"
+
+ "github.com/tdewolff/test"
+)
+
+func TestPosition(t *testing.T) {
+ var newlineTests = []struct {
+ offset int
+ buf string
+ line int
+ col int
+ err error
+ }{
+ {0, "x", 1, 1, nil},
+ {1, "xx", 1, 2, nil},
+ {2, "x\nx", 2, 1, nil},
+ {2, "\n\nx", 3, 1, nil},
+ {3, "\nxxx", 2, 3, nil},
+ {2, "\r\nx", 2, 1, nil},
+
+ // edge cases
+ {0, "", 1, 1, io.EOF},
+ {0, "\n", 1, 1, nil},
+ {1, "\r\n", 1, 2, nil},
+ {-1, "x", 1, 2, io.EOF}, // continue till the end
+ }
+ for _, tt := range newlineTests {
+ t.Run(fmt.Sprint(tt.buf, " ", tt.offset), func(t *testing.T) {
+ r := bytes.NewBufferString(tt.buf)
+ line, col, _, err := Position(r, tt.offset)
+ test.T(t, err, tt.err)
+ test.T(t, line, tt.line, "line")
+ test.T(t, col, tt.col, "column")
+ })
+ }
+}