2017-01-10 01:40:57 +09:00
|
|
|
/* Copyright 2017 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.
|
|
|
|
*/
|
2012-10-25 00:45:05 +09:00
|
|
|
|
2021-09-12 01:29:31 +09:00
|
|
|
import { Cmd, EOF, Name } from "../../src/core/primitives.js";
|
2020-01-02 20:00:16 +09:00
|
|
|
import { Lexer, Linearization, Parser } from "../../src/core/parser.js";
|
|
|
|
import { FormatError } from "../../src/shared/util.js";
|
|
|
|
import { StringStream } from "../../src/core/stream.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("parser", function () {
|
|
|
|
describe("Parser", function () {
|
|
|
|
describe("inlineStreamSkipEI", function () {
|
|
|
|
it("should skip over the EI marker if it is found", function () {
|
2019-03-10 23:33:45 +09:00
|
|
|
const string =
|
|
|
|
"q 1 0 0 1 0 0 cm BI /W 10 /H 10 /BPC 1 " +
|
|
|
|
"/F /A85 ID abc123~> EI Q";
|
|
|
|
const input = new StringStream(string);
|
2019-06-23 23:01:45 +09:00
|
|
|
const parser = new Parser({
|
|
|
|
lexer: new Lexer(input),
|
|
|
|
xref: null,
|
|
|
|
allowStreams: true,
|
|
|
|
});
|
|
|
|
|
2019-03-10 23:33:45 +09:00
|
|
|
parser.inlineStreamSkipEI(input);
|
|
|
|
expect(input.pos).toEqual(string.indexOf("Q"));
|
|
|
|
expect(input.peekByte()).toEqual(0x51); // 'Q'
|
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("should skip to the end of stream if the EI marker is not found", function () {
|
2019-03-10 23:33:45 +09:00
|
|
|
const string =
|
2019-12-26 04:03:46 +09:00
|
|
|
"q 1 0 0 1 0 0 cm BI /W 10 /H 10 /BPC 1 /F /A85 ID abc123~> Q";
|
2019-03-10 23:33:45 +09:00
|
|
|
const input = new StringStream(string);
|
2019-06-23 23:01:45 +09:00
|
|
|
const parser = new Parser({
|
|
|
|
lexer: new Lexer(input),
|
|
|
|
xref: null,
|
|
|
|
allowStreams: true,
|
|
|
|
});
|
|
|
|
|
2019-03-10 23:33:45 +09:00
|
|
|
parser.inlineStreamSkipEI(input);
|
|
|
|
expect(input.pos).toEqual(string.length);
|
|
|
|
expect(input.peekByte()).toEqual(-1);
|
|
|
|
});
|
2014-02-02 05:46:09 +09:00
|
|
|
});
|
2019-03-10 23:33:45 +09:00
|
|
|
});
|
2014-02-02 05:46:09 +09:00
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
describe("Lexer", function () {
|
|
|
|
describe("nextChar", function () {
|
|
|
|
it("should return and set -1 when the end of the stream is reached", function () {
|
2019-03-10 23:33:45 +09:00
|
|
|
const input = new StringStream("");
|
|
|
|
const lexer = new Lexer(input);
|
|
|
|
expect(lexer.nextChar()).toEqual(-1);
|
|
|
|
expect(lexer.currentChar).toEqual(-1);
|
|
|
|
});
|
2014-02-02 05:46:09 +09:00
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("should return and set the character after the current position", function () {
|
2019-03-10 23:33:45 +09:00
|
|
|
const input = new StringStream("123");
|
|
|
|
const lexer = new Lexer(input);
|
|
|
|
expect(lexer.nextChar()).toEqual(0x32); // '2'
|
|
|
|
expect(lexer.currentChar).toEqual(0x32); // '2'
|
|
|
|
});
|
2017-05-02 21:14:03 +09:00
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
describe("peekChar", function () {
|
|
|
|
it("should only return -1 when the end of the stream is reached", function () {
|
2019-03-10 23:33:45 +09:00
|
|
|
const input = new StringStream("");
|
|
|
|
const lexer = new Lexer(input);
|
|
|
|
expect(lexer.peekChar()).toEqual(-1);
|
|
|
|
expect(lexer.currentChar).toEqual(-1);
|
|
|
|
});
|
2018-06-19 16:12:24 +09:00
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("should only return the character after the current position", function () {
|
2019-03-10 23:33:45 +09:00
|
|
|
const input = new StringStream("123");
|
|
|
|
const lexer = new Lexer(input);
|
|
|
|
expect(lexer.peekChar()).toEqual(0x32); // '2'
|
|
|
|
expect(lexer.currentChar).toEqual(0x31); // '1'
|
|
|
|
});
|
2017-05-02 21:14:03 +09:00
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
describe("getNumber", function () {
|
|
|
|
it("should stop parsing numbers at the end of stream", function () {
|
2019-03-10 23:33:45 +09:00
|
|
|
const input = new StringStream("11.234");
|
|
|
|
const lexer = new Lexer(input);
|
|
|
|
expect(lexer.getNumber()).toEqual(11.234);
|
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("should parse PostScript numbers", function () {
|
2019-03-10 23:33:45 +09:00
|
|
|
const numbers = [
|
|
|
|
"-.002",
|
|
|
|
"34.5",
|
|
|
|
"-3.62",
|
|
|
|
"123.6e10",
|
|
|
|
"1E-5",
|
|
|
|
"-1.",
|
|
|
|
"0.0",
|
|
|
|
"123",
|
|
|
|
"-98",
|
|
|
|
"43445",
|
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
|
|
|
"0",
|
2019-03-10 23:33:45 +09:00
|
|
|
"+17",
|
|
|
|
];
|
|
|
|
for (const number of numbers) {
|
|
|
|
const input = new StringStream(number);
|
|
|
|
const lexer = new Lexer(input);
|
2019-05-08 20:58:16 +09:00
|
|
|
|
|
|
|
const result = lexer.getNumber(),
|
|
|
|
expected = parseFloat(number);
|
|
|
|
|
|
|
|
if (result !== expected && Math.abs(result - expected) < 1e-15) {
|
|
|
|
console.error(
|
|
|
|
`Fuzzy matching "${result}" with "${expected}" to ` +
|
|
|
|
"work-around rounding bugs in Chromium browsers."
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(true).toEqual(true);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
expect(result).toEqual(expected);
|
2019-03-10 23:33:45 +09:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("should ignore double negative before number", function () {
|
2019-03-10 23:33:45 +09:00
|
|
|
const input = new StringStream("--205.88");
|
|
|
|
const lexer = new Lexer(input);
|
|
|
|
expect(lexer.getNumber()).toEqual(-205.88);
|
|
|
|
});
|
2018-06-19 16:37:56 +09:00
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("should ignore minus signs in the middle of number", function () {
|
2019-03-10 23:33:45 +09:00
|
|
|
const input = new StringStream("205--.88");
|
|
|
|
const lexer = new Lexer(input);
|
|
|
|
expect(lexer.getNumber()).toEqual(205.88);
|
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("should ignore line-breaks between operator and digit in number", function () {
|
2019-03-10 23:33:45 +09:00
|
|
|
const minusInput = new StringStream("-\r\n205.88");
|
|
|
|
const minusLexer = new Lexer(minusInput);
|
|
|
|
expect(minusLexer.getNumber()).toEqual(-205.88);
|
|
|
|
|
|
|
|
const plusInput = new StringStream("+\r\n205.88");
|
|
|
|
const plusLexer = new Lexer(plusInput);
|
|
|
|
expect(plusLexer.getNumber()).toEqual(205.88);
|
|
|
|
});
|
|
|
|
|
2022-10-21 02:40:25 +09:00
|
|
|
it("should treat a single decimal point, or minus/plus sign, as zero", function () {
|
|
|
|
const validNums = [".", "-", "+", "-.", "+.", "-\r\n.", "+\r\n."];
|
|
|
|
for (const number of validNums) {
|
|
|
|
const validInput = new StringStream(number);
|
|
|
|
const validLexer = new Lexer(validInput);
|
2022-02-08 00:14:45 +09:00
|
|
|
|
2022-10-21 02:40:25 +09:00
|
|
|
expect(validLexer.getNumber()).toEqual(0);
|
|
|
|
}
|
2018-06-19 16:37:56 +09:00
|
|
|
|
2022-10-21 02:40:25 +09:00
|
|
|
const invalidNums = ["..", ".-", ".+"];
|
|
|
|
for (const number of invalidNums) {
|
2020-03-24 18:44:17 +09:00
|
|
|
const invalidInput = new StringStream(number);
|
|
|
|
const invalidLexer = new Lexer(invalidInput);
|
2018-06-19 16:37:56 +09:00
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
expect(function () {
|
2020-03-24 18:44:17 +09:00
|
|
|
return invalidLexer.getNumber();
|
2019-03-10 23:33:45 +09:00
|
|
|
}).toThrowError(FormatError, /^Invalid number:\s/);
|
|
|
|
}
|
|
|
|
});
|
2014-02-02 05:46:09 +09:00
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("should handle glued numbers and operators", function () {
|
2019-03-10 23:33:45 +09:00
|
|
|
const input = new StringStream("123ET");
|
|
|
|
const lexer = new Lexer(input);
|
|
|
|
expect(lexer.getNumber()).toEqual(123);
|
|
|
|
// The lexer must not have consumed the 'E'
|
|
|
|
expect(lexer.currentChar).toEqual(0x45); // 'E'
|
|
|
|
});
|
2013-02-24 02:35:18 +09:00
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
describe("getString", function () {
|
|
|
|
it("should stop parsing strings at the end of stream", function () {
|
2019-03-10 23:33:45 +09:00
|
|
|
const input = new StringStream("(1$4)");
|
2020-04-14 19:28:14 +09:00
|
|
|
input.getByte = function (super_getByte) {
|
2019-03-10 23:33:45 +09:00
|
|
|
// Simulating end of file using null (see issue 2766).
|
|
|
|
const ch = super_getByte.call(input);
|
|
|
|
return ch === 0x24 /* '$' */ ? -1 : ch;
|
|
|
|
}.bind(input, input.getByte);
|
|
|
|
const lexer = new Lexer(input);
|
|
|
|
expect(lexer.getString()).toEqual("1");
|
|
|
|
});
|
2014-03-21 01:50:12 +09:00
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("should ignore escaped CR and LF", function () {
|
2019-03-10 23:33:45 +09:00
|
|
|
// '(\101\<CR><LF>\102)' should be parsed as 'AB'.
|
|
|
|
const input = new StringStream("(\\101\\\r\n\\102\\\r\\103\\\n\\104)");
|
|
|
|
const lexer = new Lexer(input);
|
|
|
|
expect(lexer.getString()).toEqual("ABCD");
|
|
|
|
});
|
2014-03-21 01:50:12 +09:00
|
|
|
});
|
2015-11-26 21:27:12 +09:00
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
describe("getHexString", function () {
|
|
|
|
it("should not throw exception on bad input", function () {
|
2019-03-10 23:33:45 +09:00
|
|
|
// '7 0 2 15 5 2 2 2 4 3 2 4' should be parsed as '70 21 55 22 24 32'.
|
|
|
|
const input = new StringStream("<7 0 2 15 5 2 2 2 4 3 2 4>");
|
2019-03-10 23:29:24 +09:00
|
|
|
const lexer = new Lexer(input);
|
2019-03-10 23:33:45 +09:00
|
|
|
expect(lexer.getHexString()).toEqual('p!U"$2');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
describe("getName", function () {
|
|
|
|
it("should handle Names with invalid usage of NUMBER SIGN (#)", function () {
|
2019-03-10 23:33:45 +09:00
|
|
|
const inputNames = ["/# 680 0 R", "/#AQwerty", "/#A<</B"];
|
|
|
|
const expectedNames = ["#", "#AQwerty", "#A"];
|
|
|
|
|
|
|
|
for (let i = 0, ii = inputNames.length; i < ii; i++) {
|
|
|
|
const input = new StringStream(inputNames[i]);
|
|
|
|
const lexer = new Lexer(input);
|
|
|
|
expect(lexer.getName()).toEqual(Name.get(expectedNames[i]));
|
|
|
|
}
|
|
|
|
});
|
2015-11-26 21:27:12 +09:00
|
|
|
});
|
2021-09-12 01:29:31 +09:00
|
|
|
|
|
|
|
describe("getObj", function () {
|
|
|
|
it(
|
|
|
|
"should stop immediately when the start of a command is " +
|
|
|
|
"a non-visible ASCII character (issue 13999)",
|
|
|
|
function () {
|
|
|
|
const input = new StringStream("\x14q\nQ");
|
|
|
|
const lexer = new Lexer(input);
|
|
|
|
|
|
|
|
let obj = lexer.getObj();
|
|
|
|
expect(obj instanceof Cmd).toEqual(true);
|
|
|
|
expect(obj.cmd).toEqual("\x14");
|
|
|
|
|
|
|
|
obj = lexer.getObj();
|
|
|
|
expect(obj instanceof Cmd).toEqual(true);
|
|
|
|
expect(obj.cmd).toEqual("q");
|
|
|
|
|
|
|
|
obj = lexer.getObj();
|
|
|
|
expect(obj instanceof Cmd).toEqual(true);
|
|
|
|
expect(obj.cmd).toEqual("Q");
|
|
|
|
|
|
|
|
obj = lexer.getObj();
|
|
|
|
expect(obj).toEqual(EOF);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2012-10-25 00:45:05 +09:00
|
|
|
});
|
2015-08-30 21:03:21 +09:00
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
describe("Linearization", function () {
|
|
|
|
it("should not find a linearization dictionary", function () {
|
2015-08-30 21:03:21 +09:00
|
|
|
// Not an actual linearization dictionary.
|
2019-12-25 23:54:34 +09:00
|
|
|
// prettier-ignore
|
2019-03-10 23:29:24 +09:00
|
|
|
const stream1 = new StringStream(
|
2015-08-30 21:03:21 +09:00
|
|
|
"3 0 obj\n" +
|
|
|
|
"<<\n" +
|
|
|
|
"/Length 4622\n" +
|
|
|
|
"/Filter /FlateDecode\n" +
|
|
|
|
">>\n" +
|
|
|
|
"endobj"
|
|
|
|
);
|
|
|
|
expect(Linearization.create(stream1)).toEqual(null);
|
|
|
|
|
|
|
|
// Linearization dictionary with invalid version number.
|
2019-12-25 23:54:34 +09:00
|
|
|
// prettier-ignore
|
2019-03-10 23:29:24 +09:00
|
|
|
const stream2 = new StringStream(
|
2015-08-30 21:03:21 +09:00
|
|
|
"1 0 obj\n" +
|
|
|
|
"<<\n" +
|
|
|
|
"/Linearized 0\n" +
|
|
|
|
">>\n" +
|
|
|
|
"endobj"
|
|
|
|
);
|
|
|
|
expect(Linearization.create(stream2)).toEqual(null);
|
|
|
|
});
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
it("should accept a valid linearization dictionary", function () {
|
2019-12-25 23:54:34 +09:00
|
|
|
// prettier-ignore
|
2019-03-10 23:29:24 +09:00
|
|
|
const stream = new StringStream(
|
2015-08-30 21:03:21 +09:00
|
|
|
"131 0 obj\n" +
|
|
|
|
"<<\n" +
|
|
|
|
"/Linearized 1\n" +
|
|
|
|
"/O 133\n" +
|
|
|
|
"/H [ 1388 863 ]\n" +
|
|
|
|
"/L 90\n" +
|
|
|
|
"/E 43573\n" +
|
|
|
|
"/N 18\n" +
|
|
|
|
"/T 193883\n" +
|
|
|
|
">>\n" +
|
|
|
|
"endobj"
|
|
|
|
);
|
2019-03-10 23:29:24 +09:00
|
|
|
const expectedLinearizationDict = {
|
2015-08-30 21:03:21 +09:00
|
|
|
length: 90,
|
|
|
|
hints: [1388, 863],
|
|
|
|
objectNumberFirst: 133,
|
|
|
|
endFirst: 43573,
|
|
|
|
numPages: 18,
|
|
|
|
mainXRefEntriesOffset: 193883,
|
|
|
|
pageFirst: 0,
|
|
|
|
};
|
|
|
|
expect(Linearization.create(stream)).toEqual(expectedLinearizationDict);
|
|
|
|
});
|
|
|
|
|
|
|
|
it(
|
|
|
|
"should reject a linearization dictionary with invalid " +
|
2019-03-10 23:29:24 +09:00
|
|
|
"integer parameters",
|
2020-04-14 19:28:14 +09:00
|
|
|
function () {
|
2015-08-30 21:03:21 +09:00
|
|
|
// The /L parameter should be equal to the stream length.
|
2019-12-25 23:54:34 +09:00
|
|
|
// prettier-ignore
|
2019-03-10 23:29:24 +09:00
|
|
|
const stream1 = new StringStream(
|
2015-08-30 21:03:21 +09:00
|
|
|
"1 0 obj\n" +
|
|
|
|
"<<\n" +
|
|
|
|
"/Linearized 1\n" +
|
|
|
|
"/O 133\n" +
|
|
|
|
"/H [ 1388 863 ]\n" +
|
|
|
|
"/L 196622\n" +
|
|
|
|
"/E 43573\n" +
|
|
|
|
"/N 18\n" +
|
|
|
|
"/T 193883\n" +
|
|
|
|
">>\n" +
|
|
|
|
"endobj"
|
|
|
|
);
|
2020-04-14 19:28:14 +09:00
|
|
|
expect(function () {
|
2015-08-30 21:03:21 +09:00
|
|
|
return Linearization.create(stream1);
|
|
|
|
}).toThrow(
|
|
|
|
new Error(
|
|
|
|
'The "L" parameter in the linearization ' +
|
|
|
|
"dictionary does not equal the stream length."
|
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
|
|
|
)
|
2015-08-30 21:03:21 +09:00
|
|
|
);
|
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
|
|
|
|
2015-08-30 21:03:21 +09:00
|
|
|
// The /E parameter should not be zero.
|
2019-12-25 23:54:34 +09:00
|
|
|
// prettier-ignore
|
2019-03-10 23:29:24 +09:00
|
|
|
const stream2 = new StringStream(
|
2015-08-30 21:03:21 +09:00
|
|
|
"1 0 obj\n" +
|
|
|
|
"<<\n" +
|
|
|
|
"/Linearized 1\n" +
|
|
|
|
"/O 133\n" +
|
|
|
|
"/H [ 1388 863 ]\n" +
|
|
|
|
"/L 84\n" +
|
|
|
|
"/E 0\n" +
|
|
|
|
"/N 18\n" +
|
|
|
|
"/T 193883\n" +
|
|
|
|
">>\n" +
|
|
|
|
"endobj"
|
|
|
|
);
|
2020-04-14 19:28:14 +09:00
|
|
|
expect(function () {
|
2015-08-30 21:03:21 +09:00
|
|
|
return Linearization.create(stream2);
|
|
|
|
}).toThrow(
|
|
|
|
new Error(
|
2019-12-26 04:03:46 +09:00
|
|
|
'The "E" parameter in the linearization dictionary is invalid.'
|
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
|
|
|
)
|
2015-08-30 21:03:21 +09:00
|
|
|
);
|
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
|
|
|
|
2015-08-30 21:03:21 +09:00
|
|
|
// The /O parameter should be an integer.
|
2019-12-25 23:54:34 +09:00
|
|
|
// prettier-ignore
|
2019-03-10 23:29:24 +09:00
|
|
|
const stream3 = new StringStream(
|
2015-08-30 21:03:21 +09:00
|
|
|
"1 0 obj\n" +
|
|
|
|
"<<\n" +
|
|
|
|
"/Linearized 1\n" +
|
|
|
|
"/O /abc\n" +
|
|
|
|
"/H [ 1388 863 ]\n" +
|
|
|
|
"/L 89\n" +
|
|
|
|
"/E 43573\n" +
|
|
|
|
"/N 18\n" +
|
|
|
|
"/T 193883\n" +
|
|
|
|
">>\n" +
|
|
|
|
"endobj"
|
|
|
|
);
|
2020-04-14 19:28:14 +09:00
|
|
|
expect(function () {
|
2015-08-30 21:03:21 +09:00
|
|
|
return Linearization.create(stream3);
|
|
|
|
}).toThrow(
|
|
|
|
new Error(
|
2019-12-26 04:03:46 +09:00
|
|
|
'The "O" parameter in the linearization dictionary is invalid.'
|
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
|
|
|
)
|
2015-08-30 21:03:21 +09:00
|
|
|
);
|
|
|
|
}
|
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
|
|
|
it("should reject a linearization dictionary with invalid hint parameters", function () {
|
2015-08-30 21:03:21 +09:00
|
|
|
// The /H parameter should be an array.
|
2019-12-25 23:54:34 +09:00
|
|
|
// prettier-ignore
|
2019-03-10 23:29:24 +09:00
|
|
|
const stream1 = new StringStream(
|
2015-08-30 21:03:21 +09:00
|
|
|
"1 0 obj\n" +
|
|
|
|
"<<\n" +
|
|
|
|
"/Linearized 1\n" +
|
|
|
|
"/O 133\n" +
|
|
|
|
"/H 1388\n" +
|
|
|
|
"/L 80\n" +
|
|
|
|
"/E 43573\n" +
|
|
|
|
"/N 18\n" +
|
|
|
|
"/T 193883\n" +
|
|
|
|
">>\n" +
|
|
|
|
"endobj"
|
|
|
|
);
|
2020-04-14 19:28:14 +09:00
|
|
|
expect(function () {
|
2015-08-30 21:03:21 +09:00
|
|
|
return Linearization.create(stream1);
|
|
|
|
}).toThrow(
|
2019-12-26 04:03:46 +09:00
|
|
|
new Error("Hint array in the linearization dictionary is invalid.")
|
2015-08-30 21:03:21 +09:00
|
|
|
);
|
|
|
|
|
|
|
|
// The hint array should contain two, or four, elements.
|
2019-12-25 23:54:34 +09:00
|
|
|
// prettier-ignore
|
2019-03-10 23:29:24 +09:00
|
|
|
const stream2 = new StringStream(
|
2015-08-30 21:03:21 +09:00
|
|
|
"1 0 obj\n" +
|
|
|
|
"<<\n" +
|
|
|
|
"/Linearized 1\n" +
|
|
|
|
"/O 133\n" +
|
|
|
|
"/H [ 1388 ]\n" +
|
|
|
|
"/L 84\n" +
|
|
|
|
"/E 43573\n" +
|
|
|
|
"/N 18\n" +
|
|
|
|
"/T 193883\n" +
|
|
|
|
">>\n" +
|
|
|
|
"endobj"
|
|
|
|
);
|
2020-04-14 19:28:14 +09:00
|
|
|
expect(function () {
|
2015-08-30 21:03:21 +09:00
|
|
|
return Linearization.create(stream2);
|
|
|
|
}).toThrow(
|
2019-12-26 04:03:46 +09:00
|
|
|
new Error("Hint array in the linearization dictionary is invalid.")
|
2015-08-30 21:03:21 +09:00
|
|
|
);
|
|
|
|
|
|
|
|
// The hint array should not contain zero.
|
2019-12-25 23:54:34 +09:00
|
|
|
// prettier-ignore
|
2019-03-10 23:29:24 +09:00
|
|
|
const stream3 = new StringStream(
|
2015-08-30 21:03:21 +09:00
|
|
|
"1 0 obj\n" +
|
|
|
|
"<<\n" +
|
|
|
|
"/Linearized 1\n" +
|
|
|
|
"/O 133\n" +
|
|
|
|
"/H [ 1388 863 0 234]\n" +
|
|
|
|
"/L 93\n" +
|
|
|
|
"/E 43573\n" +
|
|
|
|
"/N 18\n" +
|
|
|
|
"/T 193883\n" +
|
|
|
|
">>\n" +
|
|
|
|
"endobj"
|
|
|
|
);
|
2020-04-14 19:28:14 +09:00
|
|
|
expect(function () {
|
2015-08-30 21:03:21 +09:00
|
|
|
return Linearization.create(stream3);
|
|
|
|
}).toThrow(
|
2019-12-26 04:03:46 +09:00
|
|
|
new Error("Hint (2) in the linearization dictionary is invalid.")
|
2015-08-30 21:03:21 +09:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2012-10-25 00:45:05 +09:00
|
|
|
});
|