From 2d8dfb0b6280210a59d97c5926c628b322c7b453 Mon Sep 17 00:00:00 2001 From: maettuu Date: Wed, 6 Aug 2025 12:35:49 +0200 Subject: [PATCH] Add regression test for Unicode mapping Verifies that ToUnicodeMap correctly maps Extension B characters to their full Unicode code points using codePointAt See PR https://github.com/mozilla/pdf.js/pull/19184 --- test/unit/clitests.json | 1 + test/unit/to_unicode_map_spec.js | 33 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 test/unit/to_unicode_map_spec.js diff --git a/test/unit/clitests.json b/test/unit/clitests.json index 1328b612461bc..1440845f8e8c7 100644 --- a/test/unit/clitests.json +++ b/test/unit/clitests.json @@ -46,6 +46,7 @@ "struct_tree_spec.js", "svg_factory_spec.js", "text_layer_spec.js", + "to_unicode_map_spec.js", "type1_parser_spec.js", "ui_utils_spec.js", "unicode_spec.js", diff --git a/test/unit/to_unicode_map_spec.js b/test/unit/to_unicode_map_spec.js new file mode 100644 index 0000000000000..706718bdda6c2 --- /dev/null +++ b/test/unit/to_unicode_map_spec.js @@ -0,0 +1,33 @@ +/* Copyright 2025 Mozilla Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { ToUnicodeMap } from "../../src/core/to_unicode_map.js"; + +describe("ToUnicodeMap", () => { + it("should correctly map Extension B characters using codePointAt", () => { + const cmap = { 0x20: "\uD840\uDC00" }; // Example Extension B character + const toUnicodeMap = new ToUnicodeMap(cmap); + + const expected = 0x20000; // Unicode code point for the character + let actual; + toUnicodeMap.forEach((charCode, unicode) => { + if (charCode === (0x20).toString()) { + actual = unicode; + } + }); + + expect(actual).toBe(expected); + }); +});