8
0

utils-diff.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. 'use strict';
  6. const modules = bender.amd.require( 'core/utils-diff' );
  7. describe( 'diff', () => {
  8. let diff;
  9. before( () => {
  10. diff = modules[ 'core/utils-diff' ];
  11. } );
  12. it( 'should diff arrays', () => {
  13. expect( diff( 'aba', 'acca' ) ).to.deep.equals( [ 0, 1, 1, -1, 0 ] );
  14. } );
  15. it( 'should reverse result if the second array is shorter', () => {
  16. expect( diff( 'acca', 'aba' ) ).to.deep.equals( [ 0, -1, -1, 1, 0 ] );
  17. } );
  18. it( 'should diff if arrays are same', () => {
  19. expect( diff( 'abc', 'abc' ) ).to.deep.equals( [ 0, 0, 0 ] );
  20. } );
  21. it( 'should diff if one array is empty', () => {
  22. expect( diff( '', 'abc' ) ).to.deep.equals( [ 1, 1, 1 ] );
  23. } );
  24. it( 'should use custom comparator', () => {
  25. expect( diff( 'aBc', 'abc' ) ).to.deep.equals( [ 0, 1, -1, 0 ] );
  26. expect( diff( 'aBc', 'abc', ( a, b ) => a.toLowerCase() == b.toLowerCase() ) ).to.deep.equals( [ 0, 0, 0 ] );
  27. } );
  28. } );