...
1
16
17 package fixture
18
19 import (
20 "fmt"
21 "testing"
22
23 "sigs.k8s.io/structured-merge-diff/v4/typed"
24 )
25
26 func TestFixTabs(t *testing.T) {
27 cases := []struct {
28 in, out typed.YAMLObject
29 shouldPanic bool
30 }{{
31 in: "a\n b\n",
32 out: "a\n b\n",
33 }, {
34 in: "\t\ta\n\t\t\tb\n",
35 out: "a\n\tb\n",
36 }, {
37 in: "\n\t\ta\n\t\tb\n",
38 out: "a\nb\n",
39 }, {
40 in: "\n\t\ta\n\t\t\tb\n\t",
41 out: "a\n\tb\n",
42 }, {
43 in: "\t\ta\n\t\t b\n",
44 out: "a\n b\n",
45 }, {
46 in: "\t\ta\n\tb\n",
47 shouldPanic: true,
48 }}
49
50 for i := range cases {
51 tt := cases[i]
52 t.Run(fmt.Sprintf("%v-%v", i, []byte(tt.in)), func(t *testing.T) {
53 if tt.shouldPanic {
54 defer func() {
55 if x := recover(); x == nil {
56 t.Errorf("expected a panic, but didn't get one")
57 }
58 }()
59 }
60 got := FixTabsOrDie(tt.in)
61 if e, a := tt.out, got; e != a {
62 t.Errorf("mismatch\n got %v\nwanted %v", []byte(a), []byte(e))
63 }
64 })
65 }
66 }
67
View as plain text