utils-diff.js 1.1 KB

12345678910111213141516171819202122232425262728293031
  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/engine/utils-diff.js';
  7. describe( 'diff', () => {
  8. it( 'should diff arrays', () => {
  9. expect( diff( 'aba', 'acca' ) ).to.deep.equals( [ 'EQUAL', 'INSERT', 'INSERT', 'DELETE', 'EQUAL' ] );
  10. } );
  11. it( 'should reverse result if the second array is shorter', () => {
  12. expect( diff( 'acca', 'aba' ) ).to.deep.equals( [ 'EQUAL', 'DELETE', 'DELETE', 'INSERT', 'EQUAL' ] );
  13. } );
  14. it( 'should diff if arrays are same', () => {
  15. expect( diff( 'abc', 'abc' ) ).to.deep.equals( [ 'EQUAL', 'EQUAL', 'EQUAL' ] );
  16. } );
  17. it( 'should diff if one array is empty', () => {
  18. expect( diff( '', 'abc' ) ).to.deep.equals( [ 'INSERT', 'INSERT', 'INSERT' ] );
  19. } );
  20. it( 'should use custom comparator', () => {
  21. expect( diff( 'aBc', 'abc' ) ).to.deep.equals( [ 'EQUAL', 'INSERT', 'DELETE', 'EQUAL' ] );
  22. expect( diff( 'aBc', 'abc', ( a, b ) => a.toLowerCase() == b.toLowerCase() ) ).to.deep.equals( [ 'EQUAL', 'EQUAL', 'EQUAL' ] );
  23. } );
  24. } );