unicode_spec.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /* Copyright 2017 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. 'use strict';
  16. var _glyphlist = require('../../core/glyphlist');
  17. var _unicode = require('../../core/unicode');
  18. describe('unicode', function () {
  19. describe('mapSpecialUnicodeValues', function () {
  20. it('should not re-map normal Unicode values', function () {
  21. expect((0, _unicode.mapSpecialUnicodeValues)(0x0041)).toEqual(0x0041);
  22. expect((0, _unicode.mapSpecialUnicodeValues)(0xFB01)).toEqual(0xFB01);
  23. });
  24. it('should re-map special Unicode values', function () {
  25. expect((0, _unicode.mapSpecialUnicodeValues)(0xF8E9)).toEqual(0x00A9);
  26. expect((0, _unicode.mapSpecialUnicodeValues)(0xFFFF)).toEqual(0);
  27. });
  28. });
  29. describe('getUnicodeForGlyph', function () {
  30. var standardMap, dingbatsMap;
  31. beforeAll(function (done) {
  32. standardMap = (0, _glyphlist.getGlyphsUnicode)();
  33. dingbatsMap = (0, _glyphlist.getDingbatsGlyphsUnicode)();
  34. done();
  35. });
  36. afterAll(function () {
  37. standardMap = dingbatsMap = null;
  38. });
  39. it('should get Unicode values for valid glyph names', function () {
  40. expect((0, _unicode.getUnicodeForGlyph)('A', standardMap)).toEqual(0x0041);
  41. expect((0, _unicode.getUnicodeForGlyph)('a1', dingbatsMap)).toEqual(0x2701);
  42. });
  43. it('should recover Unicode values from uniXXXX/uXXXX{XX} glyph names', function () {
  44. expect((0, _unicode.getUnicodeForGlyph)('uni0041', standardMap)).toEqual(0x0041);
  45. expect((0, _unicode.getUnicodeForGlyph)('u0041', standardMap)).toEqual(0x0041);
  46. expect((0, _unicode.getUnicodeForGlyph)('uni2701', dingbatsMap)).toEqual(0x2701);
  47. expect((0, _unicode.getUnicodeForGlyph)('u2701', dingbatsMap)).toEqual(0x2701);
  48. });
  49. it('should not get Unicode values for invalid glyph names', function () {
  50. expect((0, _unicode.getUnicodeForGlyph)('Qwerty', standardMap)).toEqual(-1);
  51. expect((0, _unicode.getUnicodeForGlyph)('Qwerty', dingbatsMap)).toEqual(-1);
  52. });
  53. });
  54. describe('getUnicodeRangeFor', function () {
  55. it('should get correct Unicode range', function () {
  56. expect((0, _unicode.getUnicodeRangeFor)(0x0041)).toEqual(0);
  57. expect((0, _unicode.getUnicodeRangeFor)(0xFB01)).toEqual(62);
  58. });
  59. it('should not get a Unicode range', function () {
  60. expect((0, _unicode.getUnicodeRangeFor)(0x05FF)).toEqual(-1);
  61. });
  62. });
  63. describe('getNormalizedUnicodes', function () {
  64. var NormalizedUnicodes;
  65. beforeAll(function (done) {
  66. NormalizedUnicodes = (0, _unicode.getNormalizedUnicodes)();
  67. done();
  68. });
  69. afterAll(function () {
  70. NormalizedUnicodes = null;
  71. });
  72. it('should get normalized Unicode values for ligatures', function () {
  73. expect(NormalizedUnicodes['\uFB01']).toEqual('fi');
  74. expect(NormalizedUnicodes['\u0675']).toEqual('\u0627\u0674');
  75. });
  76. it('should not normalize standard characters', function () {
  77. expect(NormalizedUnicodes['A']).toEqual(undefined);
  78. });
  79. });
  80. describe('reverseIfRtl', function () {
  81. var NormalizedUnicodes;
  82. function getGlyphUnicode(char) {
  83. if (NormalizedUnicodes[char] !== undefined) {
  84. return NormalizedUnicodes[char];
  85. }
  86. return char;
  87. }
  88. beforeAll(function (done) {
  89. NormalizedUnicodes = (0, _unicode.getNormalizedUnicodes)();
  90. done();
  91. });
  92. afterAll(function () {
  93. NormalizedUnicodes = null;
  94. });
  95. it('should not reverse LTR characters', function () {
  96. var A = getGlyphUnicode('A');
  97. expect((0, _unicode.reverseIfRtl)(A)).toEqual('A');
  98. var fi = getGlyphUnicode('\uFB01');
  99. expect((0, _unicode.reverseIfRtl)(fi)).toEqual('fi');
  100. });
  101. it('should reverse RTL characters', function () {
  102. var heAlef = getGlyphUnicode('\u05D0');
  103. expect((0, _unicode.reverseIfRtl)(heAlef)).toEqual('\u05D0');
  104. var arAlef = getGlyphUnicode('\u0675');
  105. expect((0, _unicode.reverseIfRtl)(arAlef)).toEqual('\u0674\u0627');
  106. });
  107. });
  108. });