8
0

comparearrays.js 1.3 KB

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