tdiff.nim 1.9 KB

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