comparearrays.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. 'use strict';
  6. import compareArrays from '/ckeditor5/utils/comparearrays.js';
  7. describe( 'utils', () => {
  8. describe( 'compareArrays', () => {
  9. it( 'should return SAME flag, when arrays are same', () => {
  10. let a = [ 'abc', 0, 3 ];
  11. let b = [ 'abc', 0, 3 ];
  12. let result = compareArrays( a, b );
  13. expect( result ).to.equal( 'SAME' );
  14. } );
  15. it( 'should return PREFIX flag, when all n elements of first array are same as n first elements of the second array', () => {
  16. let a = [ 'abc', 0 ];
  17. let b = [ 'abc', 0, 3 ];
  18. let result = compareArrays( a, b );
  19. expect( result ).to.equal( 'PREFIX' );
  20. } );
  21. it( 'should return EXTENSION flag, when n first elements of first array are same as all elements of the second array', () => {
  22. let a = [ 'abc', 0, 3 ];
  23. let b = [ 'abc', 0 ];
  24. let result = compareArrays( a, b );
  25. expect( result ).to.equal( 'EXTENSION' );
  26. } );
  27. it( 'should return index on which arrays differ, when arrays are not the same', () => {
  28. let a = [ 'abc', 0, 3 ];
  29. let b = [ 'abc', 1, 3 ];
  30. let result = compareArrays( a, b );
  31. expect( result ).to.equal( 1 );
  32. } );
  33. } );
  34. } );