unicode.js 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import { isSurrogateHalf, isCombiningMark, isInsideSurrogatePair, isInsideCombinedSymbol } from '/ckeditor5/utils/unicode.js';
  6. describe( 'utils', () => {
  7. describe( 'unicode', () => {
  8. describe( 'isSurrogateHalf', () => {
  9. it( 'should return true if given character is a surrogate half', () => {
  10. // Half of pile of poo.
  11. expect( isSurrogateHalf( '\uD83D' ) ).to.be.true;
  12. } );
  13. it( 'should return false if given character is not a surrogate half', () => {
  14. expect( isSurrogateHalf( 'a' ) ).to.be.false;
  15. expect( isSurrogateHalf( '𨭎' ) ).to.be.false;
  16. } );
  17. it( 'should return false for falsy values', () => {
  18. expect( isSurrogateHalf( null ) ).to.be.false;
  19. expect( isSurrogateHalf( undefined ) ).to.be.false;
  20. expect( isSurrogateHalf( false ) ).to.be.false;
  21. expect( isSurrogateHalf( 0 ) ).to.be.false;
  22. } );
  23. } );
  24. describe( 'isCombiningMark', () => {
  25. it( 'should return true if given character is a combining mark', () => {
  26. expect( isCombiningMark( '̣' ) ).to.be.true;
  27. } );
  28. it( 'should return false if given character is not a combining mark', () => {
  29. expect( isCombiningMark( 'a' ) ).to.be.false;
  30. expect( isCombiningMark( 'q̣' ) ).to.be.false;
  31. } );
  32. it( 'should return false for falsy values', () => {
  33. expect( isCombiningMark( null ) ).to.be.false;
  34. expect( isCombiningMark( undefined ) ).to.be.false;
  35. expect( isCombiningMark( false ) ).to.be.false;
  36. expect( isCombiningMark( 0 ) ).to.be.false;
  37. } );
  38. } );
  39. describe( 'isInsideSurrogatePair', () => {
  40. const testString = 'a𨭎b';
  41. it( 'should return true if given offset in a string is inside a surrogate pair', () => {
  42. expect( isInsideSurrogatePair( testString, 2 ) ).to.be.true;
  43. } );
  44. it( 'should return false if given offset in a string is not inside a surrogate pair', () => {
  45. expect( isInsideSurrogatePair( testString, 1 ) ).to.be.false;
  46. expect( isInsideSurrogatePair( testString, 3 ) ).to.be.false;
  47. } );
  48. it( 'should return false if given offset in a string is at the string beginning or end', () => {
  49. expect( isInsideSurrogatePair( testString, 0 ) ).to.be.false;
  50. expect( isInsideSurrogatePair( testString, 4 ) ).to.be.false;
  51. } );
  52. } );
  53. describe( 'isInsideCombinedSymbol', () => {
  54. const testString = 'aa̻̐ͩbb';
  55. it( 'should return true if given offset in a string is inside a symbol with combining mark', () => {
  56. expect( isInsideCombinedSymbol( testString, 2 ) ).to.be.true;
  57. expect( isInsideCombinedSymbol( testString, 3 ) ).to.be.true;
  58. expect( isInsideCombinedSymbol( testString, 4 ) ).to.be.true;
  59. } );
  60. it( 'should return false if given offset in a string is not inside a symbol with combining mark', () => {
  61. expect( isInsideCombinedSymbol( testString, 1 ) ).to.be.false;
  62. expect( isInsideCombinedSymbol( testString, 5 ) ).to.be.false;
  63. } );
  64. it( 'should return false if given offset in a string is at the string beginning or end', () => {
  65. expect( isInsideCombinedSymbol( testString, 0 ) ).to.be.false;
  66. expect( isInsideCombinedSymbol( testString, 6 ) ).to.be.false;
  67. } );
  68. } );
  69. } );
  70. } );