DiffLibTest.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. App::uses('DiffLib', 'Tools.Lib');
  3. App::uses('MyCakeTestCase', 'Tools.TestSuite');
  4. /**
  5. */
  6. class DiffLibTest extends MyCakeTestCase {
  7. public $Diff = null;
  8. public function setUp() {
  9. parent::setUp();
  10. $this->Diff = new DiffLib();
  11. $style = <<<CSS
  12. <style type="text/css">
  13. del {
  14. color: red;
  15. }
  16. ins {
  17. color: green;
  18. }
  19. </style>
  20. CSS;
  21. $this->out($style, true);
  22. }
  23. public function testCompare() {
  24. }
  25. public function testReverse() {
  26. $this->out('String - autodetect', true);
  27. $text = <<<TEXT
  28. ***************
  29. *** 1 ****
  30. ! 99999999777
  31. --- 1 ----
  32. ! 9999944449977
  33. TEXT;
  34. $res = $this->Diff->reverse($text);
  35. $this->out($res);
  36. $this->out('String - Context - render as Unified', true);
  37. }
  38. public function testParseDiff() {
  39. $t1 = [
  40. 'errgrshrth',
  41. 'srhrthrt777 ssshsrjtz jrjtjtjt',
  42. '1dfdf' . PHP_EOL . 'jtzth6h6h6th6' . PHP_EOL . 'xcsdfdf',
  43. '99999999777'
  44. ];
  45. $t2 = [
  46. 'errgrsh3333rth',
  47. 'srhrthrt777 hsrthsrjt888 jrjtjtjt',
  48. '1dfdf' . PHP_EOL . 'jtzh6h6th6' . PHP_EOL . 'xcsdfdf',
  49. '9999944449977'
  50. ];
  51. $this->out('Inline - auto', false);
  52. for ($i = 0; $i < 4; $i++) {
  53. $res = $this->Diff->compare($t1[$i], $t2[$i]);
  54. $this->out($res);
  55. }
  56. }
  57. }