Merge pull request #13263 from Snuffleupagus/font-tests-rm-done

Replace `done` callbacks in the font-tests with async/await instead
This commit is contained in:
Tim van der Meij 2021-04-21 21:07:44 +02:00 committed by GitHub
commit 2d073b91b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 74 additions and 98 deletions

View File

@ -7,13 +7,12 @@ describe("font1", function () {
);
describe("test harness testing", function () {
it("returns output", function (done) {
ttx(font1_1, function (output) {
verifyTtxOutput(output);
expect(/<ttFont /.test(output)).toEqual(true);
expect(/<\/ttFont>/.test(output)).toEqual(true);
done();
});
it("returns output", async function () {
const output = await ttx(font1_1);
verifyTtxOutput(output);
expect(/<ttFont /.test(output)).toEqual(true);
expect(/<\/ttFont>/.test(output)).toEqual(true);
});
});
});

View File

@ -11,26 +11,24 @@ describe("font_fpgm", function () {
);
describe("Fixes fpgm table", function () {
it("table was truncated in the middle of functions", function (done) {
CMapFactory.create({
it("table was truncated in the middle of functions", async function () {
const cMap = await CMapFactory.create({
encoding: Name.get("Identity-H"),
}).then(function (cMap) {
const font = new Font("font", new Stream(font2324), {
loadedName: "font",
type: "CIDFontType2",
differences: [],
defaultEncoding: [],
cMap,
toUnicode: new ToUnicodeMap([]),
});
ttx(font.data, function (output) {
verifyTtxOutput(output);
expect(
/(ENDF\[ \]|SVTCA\[0\])\s*<\/assembly>\s*<\/fpgm>/.test(output)
).toEqual(true);
done();
});
});
const font = new Font("font", new Stream(font2324), {
loadedName: "font",
type: "CIDFontType2",
differences: [],
defaultEncoding: [],
cMap,
toUnicode: new ToUnicodeMap([]),
});
const output = await ttx(font.data);
verifyTtxOutput(output);
expect(
/(ENDF\[ \]|SVTCA\[0\])\s*<\/assembly>\s*<\/fpgm>/.test(output)
).toEqual(true);
});
});
});

View File

@ -15,7 +15,7 @@ describe("font_post", function () {
);
describe("OS/2 table removal on bad post table values", function () {
it("has invalid version number", function (done) {
it("has invalid version number", async function () {
const font = new Font("font", new Stream(font2154), {
loadedName: "font",
type: "TrueType",
@ -23,31 +23,28 @@ describe("font_post", function () {
defaultEncoding: [],
toUnicode: new ToUnicodeMap([]),
});
ttx(font.data, function (output) {
verifyTtxOutput(output);
expect(/<OS_2>\s*<version value="3"\/>/.test(output)).toEqual(true);
done();
});
const output = await ttx(font.data);
verifyTtxOutput(output);
expect(/<OS_2>\s*<version value="3"\/>/.test(output)).toEqual(true);
});
it("has invalid selection attributes presence", function (done) {
CMapFactory.create({
it("has invalid selection attributes presence", async function () {
const cMap = await CMapFactory.create({
encoding: Name.get("Identity-H"),
}).then(function (cMap) {
const font = new Font("font", new Stream(font1282), {
loadedName: "font",
type: "CIDFontType2",
differences: [],
defaultEncoding: [],
cMap,
toUnicode: new ToUnicodeMap([]),
});
ttx(font.data, function (output) {
verifyTtxOutput(output);
expect(/<OS_2>\s*<version value="3"\/>/.test(output)).toEqual(true);
done();
});
});
const font = new Font("font", new Stream(font1282), {
loadedName: "font",
type: "CIDFontType2",
differences: [],
defaultEncoding: [],
cMap,
toUnicode: new ToUnicodeMap([]),
});
const output = await ttx(font.data);
verifyTtxOutput(output);
expect(/<OS_2>\s*<version value="3"\/>/.test(output)).toEqual(true);
});
});
});

View File

@ -19,29 +19,25 @@ describe("font_post", function () {
);
describe("post table removal on bad post table values", function () {
it("has invalid version number", function (done) {
CMapFactory.create({
it("has invalid version number", async function () {
const cMap = await CMapFactory.create({
encoding: Name.get("Identity-H"),
}).then(function (cMap) {
const font = new Font("font", new Stream(font2109), {
loadedName: "font",
type: "CIDFontType2",
differences: [],
defaultEncoding: [],
cMap,
toUnicode: new ToUnicodeMap([]),
});
ttx(font.data, function (output) {
verifyTtxOutput(output);
expect(/<post>\s*<formatType value="3\.0"\/>/.test(output)).toEqual(
true
);
done();
});
});
const font = new Font("font", new Stream(font2109), {
loadedName: "font",
type: "CIDFontType2",
differences: [],
defaultEncoding: [],
cMap,
toUnicode: new ToUnicodeMap([]),
});
const output = await ttx(font.data);
verifyTtxOutput(output);
expect(/<post>\s*<formatType value="3\.0"\/>/.test(output)).toEqual(true);
});
it("has invalid glyph name indexes", function (done) {
it("has invalid glyph name indexes", async function () {
const font = new Font("font", new Stream(font2189), {
loadedName: "font",
type: "TrueType",
@ -49,16 +45,13 @@ describe("font_post", function () {
defaultEncoding: [],
toUnicode: new ToUnicodeMap([]),
});
ttx(font.data, function (output) {
verifyTtxOutput(output);
expect(/<post>\s*<formatType value="3\.0"\/>/.test(output)).toEqual(
true
);
done();
});
const output = await ttx(font.data);
verifyTtxOutput(output);
expect(/<post>\s*<formatType value="3\.0"\/>/.test(output)).toEqual(true);
});
it("has right amount of glyphs specified", function (done) {
it("has right amount of glyphs specified", async function () {
const font = new Font("font", new Stream(font2374), {
loadedName: "font",
type: "TrueType",
@ -66,13 +59,10 @@ describe("font_post", function () {
defaultEncoding: [],
toUnicode: new ToUnicodeMap([]),
});
ttx(font.data, function (output) {
verifyTtxOutput(output);
expect(/<post>\s*<formatType value="3\.0"\/>/.test(output)).toEqual(
true
);
done();
});
const output = await ttx(font.data);
verifyTtxOutput(output);
expect(/<post>\s*<formatType value="3\.0"\/>/.test(output)).toEqual(true);
});
});
});

View File

@ -65,24 +65,16 @@ function encodeFontData(data) {
return buffer;
}
function ttx(data, callback) {
const xhr = new XMLHttpRequest();
xhr.open("POST", "/ttx");
async function ttx(data) {
const response = await fetch("/ttx", {
method: "POST",
body: encodeFontData(data),
});
const encodedData = encodeFontData(data);
xhr.setRequestHeader("Content-type", "text/plain");
xhr.setRequestHeader("Content-length", encodedData.length);
xhr.onreadystatechange = function getPdfOnreadystatechange(e) {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
callback(xhr.responseText);
} else {
callback("<error>Transport error: " + xhr.statusText + "</error>");
}
}
};
xhr.send(encodedData);
if (!response.ok) {
throw new Error(response.statusText);
}
return response.text();
}
function verifyTtxOutput(output) {