(t *testing.T)
| 51 | } |
| 52 | |
| 53 | func TestPatchFromText(t *testing.T) { |
| 54 | type TestCase struct { |
| 55 | Patch string |
| 56 | |
| 57 | ErrorMessagePrefix string |
| 58 | } |
| 59 | |
| 60 | dmp := New() |
| 61 | |
| 62 | for i, tc := range []TestCase{ |
| 63 | {"", ""}, |
| 64 | {"@@ -21,18 +22,17 @@\n jump\n-s\n+ed\n over \n-the\n+a\n %0Alaz\n", ""}, |
| 65 | {"@@ -1 +1 @@\n-a\n+b\n", ""}, |
| 66 | {"@@ -1,3 +0,0 @@\n-abc\n", ""}, |
| 67 | {"@@ -0,0 +1,3 @@\n+abc\n", ""}, |
| 68 | {"@@ _0,0 +0,0 @@\n+abc\n", "Invalid patch string: @@ _0,0 +0,0 @@"}, |
| 69 | {"Bad\nPatch\n", "Invalid patch string"}, |
| 70 | } { |
| 71 | patches, err := dmp.PatchFromText(tc.Patch) |
| 72 | if tc.ErrorMessagePrefix == "" { |
| 73 | assert.Nil(t, err) |
| 74 | |
| 75 | if tc.Patch == "" { |
| 76 | assert.Equal(t, []Patch{}, patches, fmt.Sprintf("Test case #%d, %#v", i, tc)) |
| 77 | } else { |
| 78 | assert.Equal(t, tc.Patch, patches[0].String(), fmt.Sprintf("Test case #%d, %#v", i, tc)) |
| 79 | } |
| 80 | } else { |
| 81 | e := err.Error() |
| 82 | if strings.HasPrefix(e, tc.ErrorMessagePrefix) { |
| 83 | e = tc.ErrorMessagePrefix |
| 84 | } |
| 85 | assert.Equal(t, tc.ErrorMessagePrefix, e) |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | diffs := []Diff{ |
| 90 | {DiffDelete, "`1234567890-=[]\\;',./"}, |
| 91 | {DiffInsert, "~!@#$%^&*()_+{}|:\"<>?"}, |
| 92 | } |
| 93 | |
| 94 | patches, err := dmp.PatchFromText("@@ -1,21 +1,21 @@\n-%601234567890-=%5B%5D%5C;',./\n+~!@#$%25%5E&*()_+%7B%7D%7C:%22%3C%3E?\n") |
| 95 | assert.Len(t, patches, 1) |
| 96 | assert.Equal(t, diffs, |
| 97 | patches[0].diffs, |
| 98 | ) |
| 99 | assert.Nil(t, err) |
| 100 | } |
| 101 | |
| 102 | func TestPatchToText(t *testing.T) { |
| 103 | type TestCase struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…