cloudflare/pint

Public

mirrored from https://github.com/cloudflare/pintAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.81.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

internal/output/ranges_test.go

76lines · modecode

1package output_test
2
3import (
4 "strconv"
5 "testing"
6
7 "github.com/stretchr/testify/require"
8
9 "github.com/cloudflare/pint/internal/output"
10)
11
12func TestFormatLineRangeString(t *testing.T) {
13 type testCaseT struct {
14 output string
15 lines []int
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 lines: []int{},
37 output: "",
38 },
39 {
40 lines: []int{1},
41 output: "1",
42 },
43 {
44 lines: []int{-1, 0, 1},
45 output: "",
46 },
47 {
48 lines: []int{1, 2, 4, 5, 6, 8, 10, 11, 12},
49 output: "1-2 4-6 8 10-12",
50 },
51 {
52 lines: []int{100, 101, 102, 200},
53 output: "100-102 200",
54 },
55 {
56 lines: []int{5, 5, 5},
57 output: "5 5 5",
58 },
59 {
60 lines: []int{10, 1, 5, 3, 2},
61 output: "1-3 5 10",
62 },
63 {
64 lines: []int{1, 3, 2, 5, 4},
65 output: "1-5",
66 },
67 }
68
69 for i, tc := range testCases {
70 t.Run(strconv.Itoa(i+1), func(t *testing.T) {
71 output := output.FormatLineRangeString(tc.lines)
72
73 require.Equal(t, tc.output, output, "FormatLineRangeString() returned wrong output")
74 })
75 }
76}