srcfile_test.go 461 B

123456789101112131415161718192021222324252627282930
  1. package goja
  2. import "testing"
  3. func TestPosition(t *testing.T) {
  4. const SRC = `line1
  5. line2
  6. line3`
  7. f := NewSrcFile("", SRC)
  8. tests := []struct {
  9. offset int
  10. line int
  11. col int
  12. }{
  13. {12, 3, 1},
  14. {2, 1, 3},
  15. {2, 1, 3},
  16. {7, 2, 2},
  17. {12, 3, 1},
  18. {13, 3, 2},
  19. {13, 3, 2},
  20. }
  21. for i, test := range tests {
  22. if p := f.Position(test.offset); p.Line != test.line || p.Col != test.col {
  23. t.Fatalf("%d. Line: %d, col: %d", i, p.Line, p.Col)
  24. }
  25. }
  26. }