(t *testing.T)
| 302 | } |
| 303 | |
| 304 | func TestDiffLinesToChars(t *testing.T) { |
| 305 | type TestCase struct { |
| 306 | Text1 string |
| 307 | Text2 string |
| 308 | |
| 309 | ExpectedChars1 string |
| 310 | ExpectedChars2 string |
| 311 | ExpectedLines []string |
| 312 | } |
| 313 | |
| 314 | dmp := New() |
| 315 | |
| 316 | for i, tc := range []TestCase{ |
| 317 | {"", "alpha\r\nbeta\r\n\r\n\r\n", "", "\x01\x02\x03\x03", []string{"", "alpha\r\n", "beta\r\n", "\r\n"}}, |
| 318 | {"a", "b", "\x01", "\x02", []string{"", "a", "b"}}, |
| 319 | // Omit final newline. |
| 320 | {"alpha\nbeta\nalpha", "", "\x01\x02\x03", "", []string{"", "alpha\n", "beta\n", "alpha"}}, |
| 321 | // Same lines in Text1 and Text2 |
| 322 | {"abc\ndefg\n12345\n", "abc\ndef\n12345\n678", "\x01\x02\x03", "\x01\x04\x03\x05", []string{"", "abc\n", "defg\n", "12345\n", "def\n", "678"}}, |
| 323 | } { |
| 324 | actualChars1, actualChars2, actualLines := dmp.DiffLinesToChars(tc.Text1, tc.Text2) |
| 325 | assert.Equal(t, tc.ExpectedChars1, actualChars1, fmt.Sprintf("Test case #%d, %#v", i, tc)) |
| 326 | assert.Equal(t, tc.ExpectedChars2, actualChars2, fmt.Sprintf("Test case #%d, %#v", i, tc)) |
| 327 | assert.Equal(t, tc.ExpectedLines, actualLines, fmt.Sprintf("Test case #%d, %#v", i, tc)) |
| 328 | } |
| 329 | |
| 330 | // More than 256 to reveal any 8-bit limitations. |
| 331 | n := 300 |
| 332 | lineList := []string{ |
| 333 | "", // Account for the initial empty element of the lines array. |
| 334 | } |
| 335 | var charList []index |
| 336 | for x := 1; x < n+1; x++ { |
| 337 | lineList = append(lineList, strconv.Itoa(x)+"\n") |
| 338 | charList = append(charList, index(x)) |
| 339 | } |
| 340 | lines := strings.Join(lineList, "") |
| 341 | chars := indexesToString(charList) |
| 342 | assert.Equal(t, n, len(charList)) |
| 343 | |
| 344 | actualChars1, actualChars2, actualLines := dmp.DiffLinesToChars(lines, "") |
| 345 | assert.Equal(t, chars, actualChars1) |
| 346 | assert.Equal(t, "", actualChars2) |
| 347 | assert.Equal(t, lineList, actualLines) |
| 348 | } |
| 349 | |
| 350 | func TestDiffCharsToLines(t *testing.T) { |
| 351 | type TestCase struct { |
nothing calls this directly
no test coverage detected