4
0

location_test.go 985 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package detect
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. )
  6. // TestGetLocation tests the getLocation function.
  7. func TestGetLocation(t *testing.T) {
  8. tests := []struct {
  9. linePairs [][]int
  10. start int
  11. end int
  12. wantLocation Location
  13. }{
  14. {
  15. linePairs: [][]int{
  16. {0, 39},
  17. {40, 55},
  18. {56, 57},
  19. },
  20. start: 35,
  21. end: 38,
  22. wantLocation: Location{
  23. startLine: 1,
  24. startColumn: 36,
  25. endLine: 1,
  26. endColumn: 38,
  27. startLineIndex: 0,
  28. endLineIndex: 40,
  29. },
  30. },
  31. {
  32. linePairs: [][]int{
  33. {0, 39},
  34. {40, 55},
  35. {56, 57},
  36. },
  37. start: 40,
  38. end: 44,
  39. wantLocation: Location{
  40. startLine: 2,
  41. startColumn: 1,
  42. endLine: 2,
  43. endColumn: 4,
  44. startLineIndex: 40,
  45. endLineIndex: 56,
  46. },
  47. },
  48. }
  49. for _, test := range tests {
  50. loc := location(test.linePairs, "", []int{test.start, test.end})
  51. assert.Equal(t, test.wantLocation, loc)
  52. }
  53. }