TestMutateErrorSingle test errors are generated for trivially incorrect single edits
(t *testing.T)
| 146 | |
| 147 | // TestMutateErrorSingle test errors are generated for trivially incorrect single edits |
| 148 | func 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 |
| 179 | func TestMutateErrorMulti(t *testing.T) { |