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

Function TestMutateErrorSingle

internal/source/mutate_test.go:148–176  ·  view source on GitHub ↗

TestMutateErrorSingle test errors are generated for trivially incorrect single edits

(t *testing.T)

Source from the content-addressed store, hash-verified

146
147// TestMutateErrorSingle test errors are generated for trivially incorrect single edits
148func TestMutateErrorSingle(t *testing.T) {
149 type test struct {
150 input string
151 edit Edit
152 }
153
154 tests := []test{
155 // old text is longer than input text
156 {"", newEdit(0, "a", "A")},
157 {"a", newEdit(0, "aa", "A")},
158 {"hello", newEdit(0, "hello!", "A")},
159
160 // negative indexes
161 {"aaa", newEdit(-1, "aa", "A")},
162 {"aaa", newEdit(-2, "aa", "A")},
163 {"aaa", newEdit(-100, "aa", "A")},
164 }
165
166 for _, spec := range tests {
167 edit := spec.edit
168
169 _, err := Mutate(spec.input, []Edit{edit})
170 testName := fmt.Sprintf("Mutate(%s, Edit{%v, %v -> %v})", spec.input, edit.Location, edit.Old, edit.New)
171 if err == nil {
172 t.Errorf("%s should error (%v)", testName, err)
173 continue
174 }
175 }
176}
177
178// TestMutateErrorMulti tests error that can only happen across multiple errors
179func TestMutateErrorMulti(t *testing.T) {

Callers

nothing calls this directly

Calls 2

newEditFunction · 0.85
MutateFunction · 0.85

Tested by

no test coverage detected