(t *testing.T)
| 223 | } |
| 224 | |
| 225 | func TestDiffHalfMatch(t *testing.T) { |
| 226 | type TestCase struct { |
| 227 | Text1 string |
| 228 | Text2 string |
| 229 | |
| 230 | Expected []string |
| 231 | } |
| 232 | |
| 233 | dmp := New() |
| 234 | dmp.DiffTimeout = 1 |
| 235 | |
| 236 | for i, tc := range []TestCase{ |
| 237 | // No match |
| 238 | {"1234567890", "abcdef", nil}, |
| 239 | {"12345", "23", nil}, |
| 240 | |
| 241 | // Single Match |
| 242 | {"1234567890", "a345678z", []string{"12", "90", "a", "z", "345678"}}, |
| 243 | {"a345678z", "1234567890", []string{"a", "z", "12", "90", "345678"}}, |
| 244 | {"abc56789z", "1234567890", []string{"abc", "z", "1234", "0", "56789"}}, |
| 245 | {"a23456xyz", "1234567890", []string{"a", "xyz", "1", "7890", "23456"}}, |
| 246 | |
| 247 | // Multiple Matches |
| 248 | {"121231234123451234123121", "a1234123451234z", []string{"12123", "123121", "a", "z", "1234123451234"}}, |
| 249 | {"x-=-=-=-=-=-=-=-=-=-=-=-=", "xx-=-=-=-=-=-=-=", []string{"", "-=-=-=-=-=", "x", "", "x-=-=-=-=-=-=-="}}, |
| 250 | {"-=-=-=-=-=-=-=-=-=-=-=-=y", "-=-=-=-=-=-=-=yy", []string{"-=-=-=-=-=", "", "", "y", "-=-=-=-=-=-=-=y"}}, |
| 251 | |
| 252 | // Non-optimal halfmatch, ptimal diff would be -q+x=H-i+e=lloHe+Hu=llo-Hew+y not -qHillo+x=HelloHe-w+Hulloy |
| 253 | {"qHilloHelloHew", "xHelloHeHulloy", []string{"qHillo", "w", "x", "Hulloy", "HelloHe"}}, |
| 254 | } { |
| 255 | actual := dmp.DiffHalfMatch(tc.Text1, tc.Text2) |
| 256 | assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %#v", i, tc)) |
| 257 | } |
| 258 | |
| 259 | dmp.DiffTimeout = 0 |
| 260 | |
| 261 | for i, tc := range []TestCase{ |
| 262 | // Optimal no halfmatch |
| 263 | {"qHilloHelloHew", "xHelloHeHulloy", nil}, |
| 264 | } { |
| 265 | actual := dmp.DiffHalfMatch(tc.Text1, tc.Text2) |
| 266 | assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %#v", i, tc)) |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | func BenchmarkDiffHalfMatch(b *testing.B) { |
| 271 | s1, s2 := speedtestTexts() |
nothing calls this directly
no test coverage detected