TestMutateSingle tests almost every possibility of a single edit
(t *testing.T)
| 12 | |
| 13 | // TestMutateSingle tests almost every possibility of a single edit |
| 14 | func TestMutateSingle(t *testing.T) { |
| 15 | type test struct { |
| 16 | input string |
| 17 | edit Edit |
| 18 | expected string |
| 19 | } |
| 20 | |
| 21 | tests := []test{ |
| 22 | // Simple edits that replace everything |
| 23 | {"", newEdit(0, "", ""), ""}, |
| 24 | {"a", newEdit(0, "a", "A"), "A"}, |
| 25 | {"abcde", newEdit(0, "abcde", "fghij"), "fghij"}, |
| 26 | {"", newEdit(0, "", "fghij"), "fghij"}, |
| 27 | {"abcde", newEdit(0, "abcde", ""), ""}, |
| 28 | |
| 29 | // Edits that start at the very beginning (But don't cover the whole range) |
| 30 | {"abcde", newEdit(0, "a", "A"), "Abcde"}, |
| 31 | {"abcde", newEdit(0, "ab", "AB"), "ABcde"}, |
| 32 | {"abcde", newEdit(0, "abc", "ABC"), "ABCde"}, |
| 33 | {"abcde", newEdit(0, "abcd", "ABCD"), "ABCDe"}, |
| 34 | |
| 35 | // The above repeated, but with different lengths |
| 36 | {"abcde", newEdit(0, "a", ""), "bcde"}, |
| 37 | {"abcde", newEdit(0, "ab", "A"), "Acde"}, |
| 38 | {"abcde", newEdit(0, "abc", "AB"), "ABde"}, |
| 39 | {"abcde", newEdit(0, "abcd", "AB"), "ABe"}, |
| 40 | |
| 41 | // Edits that touch the end (but don't cover the whole range) |
| 42 | {"abcde", newEdit(4, "e", "E"), "abcdE"}, |
| 43 | {"abcde", newEdit(3, "de", "DE"), "abcDE"}, |
| 44 | {"abcde", newEdit(2, "cde", "CDE"), "abCDE"}, |
| 45 | {"abcde", newEdit(1, "bcde", "BCDE"), "aBCDE"}, |
| 46 | |
| 47 | // The above repeated, but with different lengths |
| 48 | {"abcde", newEdit(4, "e", ""), "abcd"}, |
| 49 | {"abcde", newEdit(3, "de", "D"), "abcD"}, |
| 50 | {"abcde", newEdit(2, "cde", "CD"), "abCD"}, |
| 51 | {"abcde", newEdit(1, "bcde", "BC"), "aBC"}, |
| 52 | |
| 53 | // Raw insertions / deletions |
| 54 | {"abcde", newEdit(0, "", "_"), "_abcde"}, |
| 55 | {"abcde", newEdit(1, "", "_"), "a_bcde"}, |
| 56 | {"abcde", newEdit(2, "", "_"), "ab_cde"}, |
| 57 | {"abcde", newEdit(3, "", "_"), "abc_de"}, |
| 58 | {"abcde", newEdit(4, "", "_"), "abcd_e"}, |
| 59 | {"abcde", newEdit(5, "", "_"), "abcde_"}, |
| 60 | } |
| 61 | |
| 62 | origTests := tests |
| 63 | // Generate the reverse mutations, for every edit - the opposite edit that makes it "undo" |
| 64 | for _, spec := range origTests { |
| 65 | tests = append(tests, test{ |
| 66 | input: spec.expected, |
| 67 | edit: newEdit(spec.edit.Location, spec.edit.New, spec.edit.Old), |
| 68 | expected: spec.input, |
| 69 | }) |
| 70 | } |
| 71 |