tdiff.nim 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. discard """
  2. targets: "c js"
  3. """
  4. import experimental/diff
  5. import std/strutils
  6. import std/assertions
  7. proc testHelper(f: seq[Item]): string =
  8. for it in f:
  9. result.add(
  10. $it.deletedA & "." & $it.insertedB & "." & $it.startA & "." & $it.startB & "*"
  11. )
  12. proc main() =
  13. var a, b: string
  14. # Diff Self Test
  15. # test all changes
  16. a = "a,b,c,d,e,f,g,h,i,j,k,l".replace(',', '\n')
  17. b = "0,1,2,3,4,5,6,7,8,9".replace(',', '\n')
  18. doAssert(testHelper(diffText(a, b)) ==
  19. "12.10.0.0*",
  20. "all-changes test failed.")
  21. # test all same
  22. a = "a,b,c,d,e,f,g,h,i,j,k,l".replace(',', '\n')
  23. b = a
  24. doAssert(testHelper(diffText(a, b)) ==
  25. "",
  26. "all-same test failed.")
  27. # test snake
  28. a = "a,b,c,d,e,f".replace(',', '\n')
  29. b = "b,c,d,e,f,x".replace(',', '\n')
  30. doAssert(testHelper(diffText(a, b)) ==
  31. "1.0.0.0*0.1.6.5*",
  32. "snake test failed.")
  33. # 2002.09.20 - repro
  34. a = "c1,a,c2,b,c,d,e,g,h,i,j,c3,k,l".replace(',', '\n')
  35. b = "C1,a,C2,b,c,d,e,I1,e,g,h,i,j,C3,k,I2,l".replace(',', '\n')
  36. doAssert(testHelper(diffText(a, b)) ==
  37. "1.1.0.0*1.1.2.2*0.2.7.7*1.1.11.13*0.1.13.15*",
  38. "repro20020920 test failed.")
  39. # 2003.02.07 - repro
  40. a = "F".replace(',', '\n')
  41. b = "0,F,1,2,3,4,5,6,7".replace(',', '\n')
  42. doAssert(testHelper(diffText(a, b)) ==
  43. "0.1.0.0*0.7.1.2*",
  44. "repro20030207 test failed.")
  45. # Muegel - repro
  46. a = "HELLO\nWORLD"
  47. b = "\n\nhello\n\n\n\nworld\n"
  48. doAssert(testHelper(diffText(a, b)) ==
  49. "2.8.0.0*",
  50. "repro20030409 test failed.")
  51. # test some differences
  52. a = "a,b,-,c,d,e,f,f".replace(',', '\n')
  53. b = "a,b,x,c,e,f".replace(',', '\n')
  54. doAssert(testHelper(diffText(a, b)) ==
  55. "1.1.2.2*1.0.4.4*1.0.7.6*",
  56. "some-changes test failed.")
  57. # test one change within long chain of repeats
  58. a = "a,a,a,a,a,a,a,a,a,a".replace(',', '\n')
  59. b = "a,a,a,a,-,a,a,a,a,a".replace(',', '\n')
  60. doAssert(testHelper(diffText(a, b)) ==
  61. "0.1.4.4*1.0.9.10*",
  62. "long chain of repeats test failed.")
  63. main()
  64. static: main()