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

Function TestMutateErrorMulti

internal/source/mutate_test.go:179–210  ·  view source on GitHub ↗

TestMutateErrorMulti tests error that can only happen across multiple errors

(t *testing.T)

Source from the content-addressed store, hash-verified

177
178// TestMutateErrorMulti tests error that can only happen across multiple errors
179func TestMutateErrorMulti(t *testing.T) {
180 type test struct {
181 input string
182 edit1 Edit
183 edit2 Edit
184 }
185
186 tests := []test{
187 // These edits overlap each other, and are therefore undefined
188 {"abcdef", newEdit(0, "a", ""), newEdit(0, "a", "A")},
189 {"abcdef", newEdit(0, "ab", ""), newEdit(1, "ab", "AB")},
190 {"abcdef", newEdit(0, "abc", ""), newEdit(2, "abc", "ABC")},
191
192 // the last edit is longer than the string itself
193 {"abcdef", newEdit(0, "abcdefghi", ""), newEdit(2, "abc", "ABC")},
194
195 // negative indexes
196 {"abcdef", newEdit(-1, "abc", ""), newEdit(3, "abc", "ABC")},
197 {"abcdef", newEdit(0, "abc", ""), newEdit(-1, "abc", "ABC")},
198 }
199
200 for _, spec := range tests {
201 actual, err := Mutate(spec.input, []Edit{spec.edit1, spec.edit2})
202 testName := fmt.Sprintf("Mutate(%s, Edits{(%v, %v -> %v), (%v, %v -> %v)})", spec.input,
203 spec.edit1.Location, spec.edit1.Old, spec.edit1.New,
204 spec.edit2.Location, spec.edit2.Old, spec.edit2.New)
205
206 if err == nil {
207 t.Errorf("%s should error, but got (%v)", testName, actual)
208 }
209 }
210}

Callers

nothing calls this directly

Calls 2

newEditFunction · 0.85
MutateFunction · 0.85

Tested by

no test coverage detected