cloudflare/pint
Publicmirrored from https://github.com/cloudflare/pintAvailable
internal/output/ranges_test.go
44lines · modecode
| 1 | package output_test |
| 2 | |
| 3 | import ( |
| 4 | "strconv" |
| 5 | "testing" |
| 6 | |
| 7 | "github.com/stretchr/testify/require" |
| 8 | |
| 9 | "github.com/cloudflare/pint/internal/output" |
| 10 | ) |
| 11 | |
| 12 | func TestFormatLineRangeString(t *testing.T) { |
| 13 | type testCaseT struct { |
| 14 | lines []int |
| 15 | output string |
| 16 | } |
| 17 | |
| 18 | testCases := []testCaseT{ |
| 19 | { |
| 20 | lines: []int{1, 2, 3}, |
| 21 | output: "1-3", |
| 22 | }, |
| 23 | { |
| 24 | lines: []int{2, 1, 3}, |
| 25 | output: "1-3", |
| 26 | }, |
| 27 | { |
| 28 | lines: []int{1, 3, 5}, |
| 29 | output: "1 3 5", |
| 30 | }, |
| 31 | { |
| 32 | lines: []int{13, 12, 3, 5, 4, 7}, |
| 33 | output: "3-5 7 12-13", |
| 34 | }, |
| 35 | } |
| 36 | |
| 37 | for i, tc := range testCases { |
| 38 | t.Run(strconv.Itoa(i+1), func(t *testing.T) { |
| 39 | output := output.FormatLineRangeString(tc.lines) |
| 40 | |
| 41 | require.Equal(t, tc.output, output, "FormatLineRangeString() returned wrong output") |
| 42 | }) |
| 43 | } |
| 44 | } |