diff.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /**
  2. * @license Copyright (c) 2003-20'INSERT'6, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. 'use strict';
  6. import diff from '/ckeditor5/utils/diff.js';
  7. describe( 'diff', () => {
  8. it( 'should diff strings', () => {
  9. expect( diff( 'aba', 'acca' ) ).to.deep.equals( [ 'EQUAL', 'INSERT', 'INSERT', 'DELETE', 'EQUAL' ] );
  10. } );
  11. it( 'should diff arrays', () => {
  12. expect( diff( Array.from( 'aba' ), Array.from( 'acca' ) ) ).to.deep.equals( [ 'EQUAL', 'INSERT', 'INSERT', 'DELETE', 'EQUAL' ] );
  13. } );
  14. it( 'should reverse result if the second string is shorter', () => {
  15. expect( diff( 'acca', 'aba' ) ).to.deep.equals( [ 'EQUAL', 'DELETE', 'DELETE', 'INSERT', 'EQUAL' ] );
  16. } );
  17. it( 'should diff if strings are same', () => {
  18. expect( diff( 'abc', 'abc' ) ).to.deep.equals( [ 'EQUAL', 'EQUAL', 'EQUAL' ] );
  19. } );
  20. it( 'should diff if one string is empty', () => {
  21. expect( diff( '', 'abc' ) ).to.deep.equals( [ 'INSERT', 'INSERT', 'INSERT' ] );
  22. } );
  23. it( 'should use custom comparator', () => {
  24. expect( diff( 'aBc', 'abc' ) ).to.deep.equals( [ 'EQUAL', 'INSERT', 'DELETE', 'EQUAL' ] );
  25. expect( diff( 'aBc', 'abc', ( a, b ) => a.toLowerCase() == b.toLowerCase() ) ).to.deep.equals( [ 'EQUAL', 'EQUAL', 'EQUAL' ] );
  26. } );
  27. } );