unicode_spec.js 4.6 KB

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