MCPcopy Create free account
hub / github.com/CrunchyData/postgres-operator / TestDedentLines

Function TestDedentLines

internal/testing/cmp/cmp_test.go:14–66  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestDedentLines(t *testing.T) {
15 for _, tc := range []struct {
16 width int
17 input string
18 expected string
19 }{
20 // empty stays that way
21 {width: 0, input: "", expected: ""},
22 {width: 1, input: "", expected: ""},
23 {width: 2, input: "", expected: ""},
24
25 // adds a missing newline
26 {input: "\n", expected: "\n"},
27 {input: "x", expected: "x\n"},
28 {input: "x\n", expected: "x\n"},
29 {input: "x\n\n", expected: "x\n\n"},
30
31 // width does not affect whats removed
32 {width: 2, input: "x", expected: "x\n"},
33 {width: 2, input: "\tx", expected: "x\n"},
34 {width: 2, input: " x", expected: "x\n"},
35 {width: 2, input: " x", expected: "x\n"},
36 {width: 2, input: " x", expected: "x\n"},
37
38 // positive width changes tabs to spaces
39 {width: 0, input: "\t\t~\n\t~\n", expected: "\t~\n~\n"},
40 {width: 1, input: "\t\t~\n\t~\n", expected: " ~\n~\n"},
41 {width: 2, input: "\t\t~\n\t~\n", expected: " ~\n~\n"},
42
43 // width does not affect spaces
44 {width: 0, input: " ~\n ~\n", expected: " ~\n~\n"},
45 {width: 1, input: " ~\n ~\n", expected: " ~\n~\n"},
46 {width: 2, input: " ~\n ~\n", expected: " ~\n~\n"},
47
48 // smallest indent can be anywhere
49 {input: " ~\n ~\n ~\n", expected: "~\n ~\n ~\n"},
50 {input: " ~\n ~\n ~\n", expected: " ~\n~\n ~\n"},
51 {input: " ~\n ~\n ~\n", expected: " ~\n ~\n~\n"},
52
53 // entirely whitespace becomes newline
54 {input: " ", expected: "\n"},
55 {input: " ", expected: "\n"},
56 {input: "\t", expected: "\n"},
57 {input: "\t\t", expected: "\n"},
58
59 // blank lines preserved
60 {input: " ~\n\n ~\n", expected: "~\n\n~\n"},
61 } {
62 t.Run(fmt.Sprintf("%v:%#v", tc.width, tc.input), func(t *testing.T) {
63 assert.DeepEqual(t, dedentLines(tc.input, tc.width), tc.expected)
64 })
65 }
66}

Callers

nothing calls this directly

Calls 1

dedentLinesFunction · 0.70

Tested by

no test coverage detected