| 139 | } |
| 140 | |
| 141 | func TestMatchMain(t *testing.T) { |
| 142 | type TestCase struct { |
| 143 | Name string |
| 144 | |
| 145 | Text1 string |
| 146 | Text2 string |
| 147 | Location int |
| 148 | |
| 149 | Expected int |
| 150 | } |
| 151 | |
| 152 | dmp := New() |
| 153 | |
| 154 | for i, tc := range []TestCase{ |
| 155 | {"Equality", "abcdef", "abcdef", 1000, 0}, |
| 156 | {"Null text", "", "abcdef", 1, -1}, |
| 157 | {"Null pattern", "abcdef", "", 3, 3}, |
| 158 | {"Exact match", "abcdef", "de", 3, 3}, |
| 159 | {"Beyond end match", "abcdef", "defy", 4, 3}, |
| 160 | {"Oversized pattern", "abcdef", "abcdefy", 0, 0}, |
| 161 | } { |
| 162 | actual := dmp.MatchMain(tc.Text1, tc.Text2, tc.Location) |
| 163 | assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %s", i, tc.Name)) |
| 164 | } |
| 165 | |
| 166 | dmp.MatchThreshold = 0.7 |
| 167 | |
| 168 | for i, tc := range []TestCase{ |
| 169 | {"Complex match", "I am the very model of a modern major general.", " that berry ", 5, 4}, |
| 170 | } { |
| 171 | actual := dmp.MatchMain(tc.Text1, tc.Text2, tc.Location) |
| 172 | assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %#v", i, tc)) |
| 173 | } |
| 174 | } |