2019-02-24 00:14:31 +09:00
|
|
|
/* Copyright 2019 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.
|
|
|
|
*/
|
|
|
|
|
2020-01-02 20:00:16 +09:00
|
|
|
import { Dict, Ref } from "../../src/core/primitives.js";
|
2019-02-24 00:14:31 +09:00
|
|
|
import {
|
2021-02-16 22:13:51 +09:00
|
|
|
encodeToXmlString,
|
2020-09-10 01:39:14 +09:00
|
|
|
escapePDFName,
|
2022-11-16 20:18:13 +09:00
|
|
|
escapeString,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
getInheritableProperty,
|
2022-11-16 20:07:24 +09:00
|
|
|
isAscii,
|
2020-02-10 17:38:57 +09:00
|
|
|
isWhiteSpace,
|
2020-01-08 03:59:16 +09:00
|
|
|
log2,
|
2023-01-08 22:49:20 +09:00
|
|
|
numberToString,
|
2020-09-09 18:46:02 +09:00
|
|
|
parseXFAPath,
|
2023-01-08 22:43:07 +09:00
|
|
|
recoverJsURL,
|
2022-11-16 20:39:35 +09:00
|
|
|
stringToUTF16HexString,
|
2022-11-16 20:05:00 +09:00
|
|
|
stringToUTF16String,
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
toRomanNumerals,
|
2021-03-26 17:28:18 +09:00
|
|
|
validateCSSFont,
|
2020-01-02 20:00:16 +09:00
|
|
|
} from "../../src/core/core_utils.js";
|
|
|
|
import { XRefMock } from "./test_utils.js";
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
describe("core_utils", function () {
|
|
|
|
describe("getInheritableProperty", function () {
|
|
|
|
it("handles non-dictionary arguments", function () {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
expect(getInheritableProperty({ dict: null, key: "foo" })).toEqual(
|
|
|
|
undefined
|
|
|
|
);
|
|
|
|
expect(getInheritableProperty({ dict: undefined, key: "foo" })).toEqual(
|
|
|
|
undefined
|
|
|
|
);
|
2019-02-24 00:14:31 +09:00
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("handles dictionaries that do not contain the property", function () {
|
2019-02-24 00:14:31 +09:00
|
|
|
// Empty dictionary.
|
|
|
|
const emptyDict = new Dict();
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
expect(getInheritableProperty({ dict: emptyDict, key: "foo" })).toEqual(
|
|
|
|
undefined
|
|
|
|
);
|
2019-02-24 00:14:31 +09:00
|
|
|
|
|
|
|
// Filled dictionary with a different property.
|
|
|
|
const filledDict = new Dict();
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
filledDict.set("bar", "baz");
|
|
|
|
expect(getInheritableProperty({ dict: filledDict, key: "foo" })).toEqual(
|
|
|
|
undefined
|
|
|
|
);
|
2019-02-24 00:14:31 +09:00
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("fetches the property if it is not inherited", function () {
|
2019-05-26 00:40:14 +09:00
|
|
|
const ref = Ref.get(10, 0);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
const xref = new XRefMock([{ ref, data: "quux" }]);
|
2019-02-24 00:14:31 +09:00
|
|
|
const dict = new Dict(xref);
|
|
|
|
|
|
|
|
// Regular values should be fetched.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
dict.set("foo", "bar");
|
|
|
|
expect(getInheritableProperty({ dict, key: "foo" })).toEqual("bar");
|
2019-02-24 00:14:31 +09:00
|
|
|
|
|
|
|
// Array value should be fetched (with references resolved).
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
dict.set("baz", ["qux", ref]);
|
|
|
|
expect(
|
|
|
|
getInheritableProperty({ dict, key: "baz", getArray: true })
|
|
|
|
).toEqual(["qux", "quux"]);
|
2019-02-24 00:14:31 +09:00
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("fetches the property if it is inherited and present on one level", function () {
|
2019-05-26 00:40:14 +09:00
|
|
|
const ref = Ref.get(10, 0);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
const xref = new XRefMock([{ ref, data: "quux" }]);
|
2019-02-24 00:14:31 +09:00
|
|
|
const firstDict = new Dict(xref);
|
|
|
|
const secondDict = new Dict(xref);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
firstDict.set("Parent", secondDict);
|
2019-02-24 00:14:31 +09:00
|
|
|
|
|
|
|
// Regular values should be fetched.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
secondDict.set("foo", "bar");
|
|
|
|
expect(getInheritableProperty({ dict: firstDict, key: "foo" })).toEqual(
|
|
|
|
"bar"
|
|
|
|
);
|
2019-02-24 00:14:31 +09:00
|
|
|
|
|
|
|
// Array value should be fetched (with references resolved).
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
secondDict.set("baz", ["qux", ref]);
|
|
|
|
expect(
|
|
|
|
getInheritableProperty({ dict: firstDict, key: "baz", getArray: true })
|
|
|
|
).toEqual(["qux", "quux"]);
|
2019-02-24 00:14:31 +09:00
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("fetches the property if it is inherited and present on multiple levels", function () {
|
2019-05-26 00:40:14 +09:00
|
|
|
const ref = Ref.get(10, 0);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
const xref = new XRefMock([{ ref, data: "quux" }]);
|
2019-02-24 00:14:31 +09:00
|
|
|
const firstDict = new Dict(xref);
|
|
|
|
const secondDict = new Dict(xref);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
firstDict.set("Parent", secondDict);
|
2019-02-24 00:14:31 +09:00
|
|
|
|
|
|
|
// Regular values should be fetched.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
firstDict.set("foo", "bar1");
|
|
|
|
secondDict.set("foo", "bar2");
|
|
|
|
expect(getInheritableProperty({ dict: firstDict, key: "foo" })).toEqual(
|
|
|
|
"bar1"
|
|
|
|
);
|
|
|
|
expect(
|
|
|
|
getInheritableProperty({
|
|
|
|
dict: firstDict,
|
|
|
|
key: "foo",
|
|
|
|
getArray: false,
|
|
|
|
stopWhenFound: false,
|
|
|
|
})
|
|
|
|
).toEqual(["bar1", "bar2"]);
|
2019-02-24 00:14:31 +09:00
|
|
|
|
|
|
|
// Array value should be fetched (with references resolved).
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
firstDict.set("baz", ["qux1", ref]);
|
|
|
|
secondDict.set("baz", ["qux2", ref]);
|
|
|
|
expect(
|
|
|
|
getInheritableProperty({
|
|
|
|
dict: firstDict,
|
|
|
|
key: "baz",
|
|
|
|
getArray: true,
|
|
|
|
stopWhenFound: false,
|
|
|
|
})
|
|
|
|
).toEqual([
|
|
|
|
["qux1", "quux"],
|
|
|
|
["qux2", "quux"],
|
|
|
|
]);
|
2019-02-24 00:14:31 +09:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
describe("toRomanNumerals", function () {
|
|
|
|
it("handles invalid arguments", function () {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
for (const input of ["foo", -1, 0]) {
|
2020-04-14 19:28:14 +09:00
|
|
|
expect(function () {
|
2019-02-24 00:14:31 +09:00
|
|
|
toRomanNumerals(input);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
}).toThrow(new Error("The number should be a positive integer."));
|
2019-02-24 00:14:31 +09:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("converts numbers to uppercase Roman numerals", function () {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
expect(toRomanNumerals(1)).toEqual("I");
|
|
|
|
expect(toRomanNumerals(6)).toEqual("VI");
|
|
|
|
expect(toRomanNumerals(7)).toEqual("VII");
|
|
|
|
expect(toRomanNumerals(8)).toEqual("VIII");
|
|
|
|
expect(toRomanNumerals(10)).toEqual("X");
|
|
|
|
expect(toRomanNumerals(40)).toEqual("XL");
|
|
|
|
expect(toRomanNumerals(100)).toEqual("C");
|
|
|
|
expect(toRomanNumerals(500)).toEqual("D");
|
|
|
|
expect(toRomanNumerals(1000)).toEqual("M");
|
|
|
|
expect(toRomanNumerals(2019)).toEqual("MMXIX");
|
2019-02-24 00:14:31 +09:00
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("converts numbers to lowercase Roman numerals", function () {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
expect(toRomanNumerals(1, /* lowercase = */ true)).toEqual("i");
|
|
|
|
expect(toRomanNumerals(6, /* lowercase = */ true)).toEqual("vi");
|
|
|
|
expect(toRomanNumerals(7, /* lowercase = */ true)).toEqual("vii");
|
|
|
|
expect(toRomanNumerals(8, /* lowercase = */ true)).toEqual("viii");
|
|
|
|
expect(toRomanNumerals(10, /* lowercase = */ true)).toEqual("x");
|
|
|
|
expect(toRomanNumerals(40, /* lowercase = */ true)).toEqual("xl");
|
|
|
|
expect(toRomanNumerals(100, /* lowercase = */ true)).toEqual("c");
|
|
|
|
expect(toRomanNumerals(500, /* lowercase = */ true)).toEqual("d");
|
|
|
|
expect(toRomanNumerals(1000, /* lowercase = */ true)).toEqual("m");
|
|
|
|
expect(toRomanNumerals(2019, /* lowercase = */ true)).toEqual("mmxix");
|
2019-02-24 00:14:31 +09:00
|
|
|
});
|
|
|
|
});
|
2020-01-08 03:59:16 +09:00
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
describe("log2", function () {
|
|
|
|
it("handles values smaller than/equal to zero", function () {
|
2020-01-08 03:59:16 +09:00
|
|
|
expect(log2(0)).toEqual(0);
|
|
|
|
expect(log2(-1)).toEqual(0);
|
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("handles values larger than zero", function () {
|
2020-01-08 03:59:16 +09:00
|
|
|
expect(log2(1)).toEqual(0);
|
|
|
|
expect(log2(2)).toEqual(1);
|
|
|
|
expect(log2(3)).toEqual(2);
|
|
|
|
expect(log2(3.14)).toEqual(2);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-01-08 22:49:20 +09:00
|
|
|
describe("numberToString", function () {
|
|
|
|
it("should stringify integers", function () {
|
|
|
|
expect(numberToString(1)).toEqual("1");
|
|
|
|
expect(numberToString(0)).toEqual("0");
|
|
|
|
expect(numberToString(-1)).toEqual("-1");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should stringify floats", function () {
|
|
|
|
expect(numberToString(1.0)).toEqual("1");
|
|
|
|
expect(numberToString(1.2)).toEqual("1.2");
|
|
|
|
expect(numberToString(1.23)).toEqual("1.23");
|
|
|
|
expect(numberToString(1.234)).toEqual("1.23");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
describe("isWhiteSpace", function () {
|
|
|
|
it("handles space characters", function () {
|
2020-02-10 17:38:57 +09:00
|
|
|
expect(isWhiteSpace(0x20)).toEqual(true);
|
|
|
|
expect(isWhiteSpace(0x09)).toEqual(true);
|
|
|
|
expect(isWhiteSpace(0x0d)).toEqual(true);
|
|
|
|
expect(isWhiteSpace(0x0a)).toEqual(true);
|
2020-01-08 03:59:16 +09:00
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("handles non-space characters", function () {
|
2020-02-10 17:38:57 +09:00
|
|
|
expect(isWhiteSpace(0x0b)).toEqual(false);
|
|
|
|
expect(isWhiteSpace(null)).toEqual(false);
|
|
|
|
expect(isWhiteSpace(undefined)).toEqual(false);
|
2020-01-08 03:59:16 +09:00
|
|
|
});
|
|
|
|
});
|
2020-09-09 18:46:02 +09:00
|
|
|
|
|
|
|
describe("parseXFAPath", function () {
|
|
|
|
it("should get a correctly parsed path", function () {
|
|
|
|
const path = "foo.bar[12].oof[3].rab.FOO[123].BAR[456]";
|
|
|
|
expect(parseXFAPath(path)).toEqual([
|
|
|
|
{ name: "foo", pos: 0 },
|
|
|
|
{ name: "bar", pos: 12 },
|
|
|
|
{ name: "oof", pos: 3 },
|
|
|
|
{ name: "rab", pos: 0 },
|
|
|
|
{ name: "FOO", pos: 123 },
|
|
|
|
{ name: "BAR", pos: 456 },
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
2020-09-10 01:39:14 +09:00
|
|
|
|
2023-01-08 22:43:07 +09:00
|
|
|
describe("recoverJsURL", function () {
|
|
|
|
it("should get valid URLs without `newWindow` property", function () {
|
|
|
|
const inputs = [
|
|
|
|
"window.open('https://test.local')",
|
|
|
|
"window.open('https://test.local', true)",
|
|
|
|
"app.launchURL('https://test.local')",
|
|
|
|
"app.launchURL('https://test.local', false)",
|
|
|
|
"xfa.host.gotoURL('https://test.local')",
|
|
|
|
"xfa.host.gotoURL('https://test.local', true)",
|
|
|
|
];
|
|
|
|
|
|
|
|
for (const input of inputs) {
|
|
|
|
expect(recoverJsURL(input)).toEqual({
|
|
|
|
url: "https://test.local",
|
|
|
|
newWindow: false,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should get valid URLs with `newWindow` property", function () {
|
|
|
|
const input = "app.launchURL('https://test.local', true)";
|
|
|
|
expect(recoverJsURL(input)).toEqual({
|
|
|
|
url: "https://test.local",
|
|
|
|
newWindow: true,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should not get invalid URLs", function () {
|
|
|
|
const input = "navigateToUrl('https://test.local')";
|
|
|
|
expect(recoverJsURL(input)).toBeNull();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-09-10 01:39:14 +09:00
|
|
|
describe("escapePDFName", function () {
|
|
|
|
it("should escape PDF name", function () {
|
|
|
|
expect(escapePDFName("hello")).toEqual("hello");
|
|
|
|
expect(escapePDFName("\xfehello")).toEqual("#fehello");
|
|
|
|
expect(escapePDFName("he\xfell\xffo")).toEqual("he#fell#ffo");
|
|
|
|
expect(escapePDFName("\xfehe\xfell\xffo\xff")).toEqual(
|
|
|
|
"#fehe#fell#ffo#ff"
|
|
|
|
);
|
|
|
|
expect(escapePDFName("#h#e#l#l#o")).toEqual("#23h#23e#23l#23l#23o");
|
2020-11-25 02:25:26 +09:00
|
|
|
expect(escapePDFName("#()<>[]{}/%")).toEqual(
|
|
|
|
"#23#28#29#3c#3e#5b#5d#7b#7d#2f#25"
|
|
|
|
);
|
2020-09-10 01:39:14 +09:00
|
|
|
});
|
|
|
|
});
|
2021-02-16 22:13:51 +09:00
|
|
|
|
2022-11-16 20:18:13 +09:00
|
|
|
describe("escapeString", function () {
|
|
|
|
it("should escape (, ), \\n, \\r, and \\", function () {
|
|
|
|
expect(escapeString("((a\\a))\n(b(b\\b)\rb)")).toEqual(
|
|
|
|
"\\(\\(a\\\\a\\)\\)\\n\\(b\\(b\\\\b\\)\\rb\\)"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-02-16 22:13:51 +09:00
|
|
|
describe("encodeToXmlString", function () {
|
|
|
|
it("should get a correctly encoded string with some entities", function () {
|
|
|
|
const str = "\"\u0397ell😂' & <W😂rld>";
|
|
|
|
expect(encodeToXmlString(str)).toEqual(
|
|
|
|
""Ηell😂' & <W😂rld>"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should get a correctly encoded basic ascii string", function () {
|
|
|
|
const str = "hello world";
|
|
|
|
expect(encodeToXmlString(str)).toEqual(str);
|
|
|
|
});
|
|
|
|
});
|
2021-03-26 17:28:18 +09:00
|
|
|
|
|
|
|
describe("validateCSSFont", function () {
|
|
|
|
it("Check font family", function () {
|
|
|
|
const cssFontInfo = {
|
|
|
|
fontFamily: `"blah blah " blah blah"`,
|
|
|
|
fontWeight: 0,
|
|
|
|
italicAngle: 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(validateCSSFont(cssFontInfo)).toEqual(false);
|
|
|
|
|
|
|
|
cssFontInfo.fontFamily = `"blah blah \\" blah blah"`;
|
|
|
|
expect(validateCSSFont(cssFontInfo)).toEqual(true);
|
|
|
|
|
|
|
|
cssFontInfo.fontFamily = `'blah blah ' blah blah'`;
|
|
|
|
expect(validateCSSFont(cssFontInfo)).toEqual(false);
|
|
|
|
|
|
|
|
cssFontInfo.fontFamily = `'blah blah \\' blah blah'`;
|
|
|
|
expect(validateCSSFont(cssFontInfo)).toEqual(true);
|
|
|
|
|
|
|
|
cssFontInfo.fontFamily = `"blah blah `;
|
|
|
|
expect(validateCSSFont(cssFontInfo)).toEqual(false);
|
|
|
|
|
|
|
|
cssFontInfo.fontFamily = `blah blah"`;
|
|
|
|
expect(validateCSSFont(cssFontInfo)).toEqual(false);
|
|
|
|
|
|
|
|
cssFontInfo.fontFamily = `'blah blah `;
|
|
|
|
expect(validateCSSFont(cssFontInfo)).toEqual(false);
|
|
|
|
|
|
|
|
cssFontInfo.fontFamily = `blah blah'`;
|
|
|
|
expect(validateCSSFont(cssFontInfo)).toEqual(false);
|
|
|
|
|
|
|
|
cssFontInfo.fontFamily = "blah blah blah";
|
|
|
|
expect(validateCSSFont(cssFontInfo)).toEqual(true);
|
|
|
|
|
|
|
|
cssFontInfo.fontFamily = "blah 0blah blah";
|
|
|
|
expect(validateCSSFont(cssFontInfo)).toEqual(false);
|
|
|
|
|
|
|
|
cssFontInfo.fontFamily = "blah blah -0blah";
|
|
|
|
expect(validateCSSFont(cssFontInfo)).toEqual(false);
|
|
|
|
|
|
|
|
cssFontInfo.fontFamily = "blah blah --blah";
|
|
|
|
expect(validateCSSFont(cssFontInfo)).toEqual(false);
|
|
|
|
|
|
|
|
cssFontInfo.fontFamily = "blah blah -blah";
|
|
|
|
expect(validateCSSFont(cssFontInfo)).toEqual(true);
|
|
|
|
|
|
|
|
cssFontInfo.fontFamily = "blah fdqAJqjHJK23kl23__--Kj blah";
|
|
|
|
expect(validateCSSFont(cssFontInfo)).toEqual(true);
|
|
|
|
|
|
|
|
cssFontInfo.fontFamily = "blah fdqAJqjH$JK23kl23__--Kj blah";
|
|
|
|
expect(validateCSSFont(cssFontInfo)).toEqual(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Check font weight", function () {
|
|
|
|
const cssFontInfo = {
|
|
|
|
fontFamily: "blah",
|
|
|
|
fontWeight: 100,
|
|
|
|
italicAngle: 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
validateCSSFont(cssFontInfo);
|
|
|
|
expect(cssFontInfo.fontWeight).toEqual("100");
|
|
|
|
|
|
|
|
cssFontInfo.fontWeight = "700";
|
|
|
|
validateCSSFont(cssFontInfo);
|
|
|
|
expect(cssFontInfo.fontWeight).toEqual("700");
|
|
|
|
|
|
|
|
cssFontInfo.fontWeight = "normal";
|
|
|
|
validateCSSFont(cssFontInfo);
|
|
|
|
expect(cssFontInfo.fontWeight).toEqual("normal");
|
|
|
|
|
|
|
|
cssFontInfo.fontWeight = 314;
|
|
|
|
validateCSSFont(cssFontInfo);
|
|
|
|
expect(cssFontInfo.fontWeight).toEqual("400");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Check italic angle", function () {
|
|
|
|
const cssFontInfo = {
|
|
|
|
fontFamily: "blah",
|
|
|
|
fontWeight: 100,
|
|
|
|
italicAngle: 10,
|
|
|
|
};
|
|
|
|
validateCSSFont(cssFontInfo);
|
|
|
|
expect(cssFontInfo.italicAngle).toEqual("10");
|
|
|
|
|
|
|
|
cssFontInfo.italicAngle = -123;
|
|
|
|
validateCSSFont(cssFontInfo);
|
|
|
|
expect(cssFontInfo.italicAngle).toEqual("14");
|
|
|
|
|
|
|
|
cssFontInfo.italicAngle = "91";
|
|
|
|
validateCSSFont(cssFontInfo);
|
|
|
|
expect(cssFontInfo.italicAngle).toEqual("14");
|
|
|
|
|
|
|
|
cssFontInfo.italicAngle = 2.718;
|
|
|
|
validateCSSFont(cssFontInfo);
|
|
|
|
expect(cssFontInfo.italicAngle).toEqual("2.718");
|
|
|
|
});
|
|
|
|
});
|
2022-11-16 20:05:00 +09:00
|
|
|
|
2022-11-16 20:07:24 +09:00
|
|
|
describe("isAscii", function () {
|
|
|
|
it("handles ascii/non-ascii strings", function () {
|
|
|
|
expect(isAscii("hello world")).toEqual(true);
|
|
|
|
expect(isAscii("こんにちは世界の")).toEqual(false);
|
|
|
|
expect(isAscii("hello world in Japanese is こんにちは世界の")).toEqual(
|
|
|
|
false
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-11-16 20:39:35 +09:00
|
|
|
describe("stringToUTF16HexString", function () {
|
|
|
|
it("should encode a string in UTF16 hexadecimal format", function () {
|
|
|
|
expect(stringToUTF16HexString("hello world")).toEqual(
|
|
|
|
"00680065006c006c006f00200077006f0072006c0064"
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(stringToUTF16HexString("こんにちは世界の")).toEqual(
|
|
|
|
"30533093306b3061306f4e16754c306e"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-11-16 20:05:00 +09:00
|
|
|
describe("stringToUTF16String", function () {
|
|
|
|
it("should encode a string in UTF16", function () {
|
|
|
|
expect(stringToUTF16String("hello world")).toEqual(
|
|
|
|
"\0h\0e\0l\0l\0o\0 \0w\0o\0r\0l\0d"
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(stringToUTF16String("こんにちは世界の")).toEqual(
|
|
|
|
"\x30\x53\x30\x93\x30\x6b\x30\x61\x30\x6f\x4e\x16\x75\x4c\x30\x6e"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should encode a string in UTF16BE with a BOM", function () {
|
|
|
|
expect(
|
|
|
|
stringToUTF16String("hello world", /* bigEndian = */ true)
|
|
|
|
).toEqual("\xfe\xff\0h\0e\0l\0l\0o\0 \0w\0o\0r\0l\0d");
|
|
|
|
|
|
|
|
expect(
|
|
|
|
stringToUTF16String("こんにちは世界の", /* bigEndian = */ true)
|
|
|
|
).toEqual(
|
|
|
|
"\xfe\xff\x30\x53\x30\x93\x30\x6b\x30\x61\x30\x6f\x4e\x16\x75\x4c\x30\x6e"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2019-02-24 00:14:31 +09:00
|
|
|
});
|