Mercurial > vim
comparison src/testing.c @ 20691:b9a6a129b94e v8.2.0899
patch 8.2.0899: assert_equalfile() does not give a hint about the difference
Commit: https://github.com/vim/vim/commit/30cc44a97f0ba1349e1a522dab22b11f47888183
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Jun 4 16:52:40 2020 +0200
patch 8.2.0899: assert_equalfile() does not give a hint about the difference
Problem: Assert_equalfile() does not give a hint about the difference.
Solution: Display the last seen text.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 04 Jun 2020 17:00:04 +0200 |
parents | 1af1d8ff2aa8 |
children | 9a624c1672a3 |
comparison
equal
deleted
inserted
replaced
20690:709b116fb339 | 20691:b9a6a129b94e |
---|---|
307 char_u *fname1 = tv_get_string_buf_chk(&argvars[0], buf1); | 307 char_u *fname1 = tv_get_string_buf_chk(&argvars[0], buf1); |
308 char_u *fname2 = tv_get_string_buf_chk(&argvars[1], buf2); | 308 char_u *fname2 = tv_get_string_buf_chk(&argvars[1], buf2); |
309 garray_T ga; | 309 garray_T ga; |
310 FILE *fd1; | 310 FILE *fd1; |
311 FILE *fd2; | 311 FILE *fd2; |
312 char line1[200]; | |
313 char line2[200]; | |
314 int lineidx = 0; | |
312 | 315 |
313 if (fname1 == NULL || fname2 == NULL) | 316 if (fname1 == NULL || fname2 == NULL) |
314 return 0; | 317 return 0; |
315 | 318 |
316 IObuff[0] = NUL; | 319 IObuff[0] = NUL; |
327 fclose(fd1); | 330 fclose(fd1); |
328 vim_snprintf((char *)IObuff, IOSIZE, (char *)e_notread, fname2); | 331 vim_snprintf((char *)IObuff, IOSIZE, (char *)e_notread, fname2); |
329 } | 332 } |
330 else | 333 else |
331 { | 334 { |
332 int c1, c2; | 335 int c1, c2; |
333 long count = 0; | 336 long count = 0; |
337 long linecount = 1; | |
334 | 338 |
335 for (;;) | 339 for (;;) |
336 { | 340 { |
337 c1 = fgetc(fd1); | 341 c1 = fgetc(fd1); |
338 c2 = fgetc(fd2); | 342 c2 = fgetc(fd2); |
345 else if (c2 == EOF) | 349 else if (c2 == EOF) |
346 { | 350 { |
347 STRCPY(IObuff, "second file is shorter"); | 351 STRCPY(IObuff, "second file is shorter"); |
348 break; | 352 break; |
349 } | 353 } |
350 else if (c1 != c2) | 354 else |
351 { | 355 { |
352 vim_snprintf((char *)IObuff, IOSIZE, | 356 line1[lineidx] = c1; |
353 "difference at byte %ld", count); | 357 line2[lineidx] = c2; |
354 break; | 358 ++lineidx; |
359 if (c1 != c2) | |
360 { | |
361 vim_snprintf((char *)IObuff, IOSIZE, | |
362 "difference at byte %ld, line %ld", | |
363 count, linecount); | |
364 break; | |
365 } | |
355 } | 366 } |
356 ++count; | 367 ++count; |
368 if (c1 == NL) | |
369 { | |
370 ++linecount; | |
371 lineidx = 0; | |
372 } | |
373 else if (lineidx + 2 == (int)sizeof(line1)) | |
374 { | |
375 mch_memmove(line1, line1 + 100, lineidx - 100); | |
376 mch_memmove(line2, line2 + 100, lineidx - 100); | |
377 lineidx -= 100; | |
378 } | |
357 } | 379 } |
358 fclose(fd1); | 380 fclose(fd1); |
359 fclose(fd2); | 381 fclose(fd2); |
360 } | 382 } |
361 } | 383 } |
370 ga_concat(&ga, echo_string(&argvars[2], &tofree, numbuf, 0)); | 392 ga_concat(&ga, echo_string(&argvars[2], &tofree, numbuf, 0)); |
371 vim_free(tofree); | 393 vim_free(tofree); |
372 ga_concat(&ga, (char_u *)": "); | 394 ga_concat(&ga, (char_u *)": "); |
373 } | 395 } |
374 ga_concat(&ga, IObuff); | 396 ga_concat(&ga, IObuff); |
397 if (lineidx > 0) | |
398 { | |
399 line1[lineidx] = NUL; | |
400 line2[lineidx] = NUL; | |
401 ga_concat(&ga, (char_u *)" after \""); | |
402 ga_concat(&ga, (char_u *)line1); | |
403 if (STRCMP(line1, line2) != 0) | |
404 { | |
405 ga_concat(&ga, (char_u *)"\" vs \""); | |
406 ga_concat(&ga, (char_u *)line2); | |
407 } | |
408 ga_concat(&ga, (char_u *)"\""); | |
409 } | |
375 assert_error(&ga); | 410 assert_error(&ga); |
376 ga_clear(&ga); | 411 ga_clear(&ga); |
377 return 1; | 412 return 1; |
378 } | 413 } |
379 return 0; | 414 return 0; |