srcfile_test.go 520 B

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