tdiff.nim 2.0 KB

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