Differ.coffee 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. {Differ} = require '..'
  2. suite 'Differ'
  3. test '#_qformat', ->
  4. d = new Differ
  5. results = d._qformat('\tabcDefghiJkl\n', '\tabcdefGhijkl\n',
  6. ' ^ ^ ^ ', ' ^ ^ ^ ')
  7. results.should.eql [
  8. '- \tabcDefghiJkl\n',
  9. '? \t ^ ^ ^\n',
  10. '+ \tabcdefGhijkl\n',
  11. '? \t ^ ^ ^\n'
  12. ]
  13. test '#_fancyReplace', ->
  14. d = new Differ
  15. d._fancyReplace(['abcDefghiJkl\n'], 0, 1,
  16. ['abcdefGhijkl\n'], 0, 1).should.eql [
  17. '- abcDefghiJkl\n',
  18. '? ^ ^ ^\n',
  19. '+ abcdefGhijkl\n',
  20. '? ^ ^ ^\n'
  21. ]
  22. test '#compare', ->
  23. d = new Differ
  24. d.compare(['one\n', 'two\n', 'three\n'],
  25. ['ore\n', 'tree\n', 'emu\n']).should.eql [
  26. '- one\n',
  27. '? ^\n',
  28. '+ ore\n',
  29. '? ^\n',
  30. '- two\n',
  31. '- three\n',
  32. '? -\n',
  33. '+ tree\n',
  34. '+ emu\n'
  35. ]
  36. text1 = [
  37. '1. Beautiful is better than ugly.\n',
  38. '2. Explicit is better than implicit.\n',
  39. '3. Simple is better than complex.\n',
  40. '4. Complex is better than complicated.\n'
  41. ]
  42. text2 = [
  43. '1. Beautiful is better than ugly.\n',
  44. '3. Simple is better than complex.\n',
  45. '4. Complicated is better than complex.\n',
  46. '5. Flat is better than nested.\n'
  47. ]
  48. d = new Differ()
  49. d.compare(text1, text2).should.eql [
  50. ' 1. Beautiful is better than ugly.\n',
  51. '- 2. Explicit is better than implicit.\n',
  52. '- 3. Simple is better than complex.\n',
  53. '+ 3. Simple is better than complex.\n',
  54. '? ++\n',
  55. '- 4. Complex is better than complicated.\n',
  56. '? ^ ---- ^\n',
  57. '+ 4. Complicated is better than complex.\n',
  58. '? ++++ ^ ^\n',
  59. '+ 5. Flat is better than nested.\n'
  60. ]