MCPcopy Index your code
hub / github.com/sqlc-dev/sqlc / TestMutateMulti

Function TestMutateMulti

internal/source/mutate_test.go:89–145  ·  view source on GitHub ↗

TestMutateMulti tests combinations of edits

(t *testing.T)

Source from the content-addressed store, hash-verified

87
88// TestMutateMulti tests combinations of edits
89func TestMutateMulti(t *testing.T) {
90 type test struct {
91 input string
92 edit1 Edit
93 edit2 Edit
94 expected string
95 }
96
97 tests := []test{
98 // Edits that are >1 character from each other
99 {"abcde", newEdit(0, "a", "A"), newEdit(2, "c", "C"), "AbCde"},
100 {"abcde", newEdit(0, "a", "A"), newEdit(2, "c", "C"), "AbCde"},
101
102 // 2 edits bump right up next to each other
103 {"abcde", newEdit(0, "abc", ""), newEdit(3, "de", "DE"), "DE"},
104 {"abcde", newEdit(0, "abc", "ABC"), newEdit(3, "de", ""), "ABC"},
105 {"abcde", newEdit(0, "abc", "ABC"), newEdit(3, "de", "DE"), "ABCDE"},
106 {"abcde", newEdit(1, "b", "BB"), newEdit(2, "c", "CC"), "aBBCCde"},
107
108 // 2 edits bump next to each other, but don't cover the whole string
109 {"abcdef", newEdit(1, "bc", "C"), newEdit(3, "de", "D"), "aCDf"},
110 {"abcde", newEdit(1, "bc", "CCCC"), newEdit(3, "d", "DDD"), "aCCCCDDDe"},
111
112 // lengthening edits
113 {"abcde", newEdit(1, "b", "BBBB"), newEdit(2, "c", "CCCC"), "aBBBBCCCCde"},
114 }
115
116 origTests := tests
117 // Generate the edits in opposite order mutations, source edits should be independent of
118 // the order the edits are specified
119 for _, spec := range origTests {
120 tests = append(tests, test{
121 input: spec.input,
122 edit1: spec.edit2,
123 edit2: spec.edit1,
124 expected: spec.expected,
125 })
126 }
127
128 for _, spec := range tests {
129 expected := spec.expected
130
131 actual, err := Mutate(spec.input, []Edit{spec.edit1, spec.edit2})
132 testName := fmt.Sprintf("Mutate(%s, Edits{(%v, %v -> %v), (%v, %v -> %v)})", spec.input,
133 spec.edit1.Location, spec.edit1.Old, spec.edit1.New,
134 spec.edit2.Location, spec.edit2.Old, spec.edit2.New)
135
136 if err != nil {
137 t.Errorf("%s should not error (%v)", testName, err)
138 continue
139 }
140
141 if actual != expected {
142 t.Errorf("%s expected %v; got %v", testName, expected, actual)
143 }
144 }
145}
146

Callers

nothing calls this directly

Calls 2

newEditFunction · 0.85
MutateFunction · 0.85

Tested by

no test coverage detected