Replace done callbacks in the font-tests with async/await instead

This commit is contained in:
Jonas Jenwald 2021-04-19 13:26:39 +02:00
parent fd82adccfa
commit 3d55b2b10e
5 changed files with 82 additions and 96 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) {
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);
done();
});
});
});
});

View File

@ -11,10 +11,10 @@ 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",
@ -23,14 +23,12 @@ describe("font_fpgm", function () {
cMap,
toUnicode: new ToUnicodeMap([]),
});
ttx(font.data, function (output) {
const output = await ttx(font.data);
verifyTtxOutput(output);
expect(
/(ENDF\[ \]|SVTCA\[0\])\s*<\/assembly>\s*<\/fpgm>/.test(output)
).toEqual(true);
done();
});
});
});
});
});

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,17 +23,16 @@ describe("font_post", function () {
defaultEncoding: [],
toUnicode: new ToUnicodeMap([]),
});
ttx(font.data, function (output) {
const output = await ttx(font.data);
verifyTtxOutput(output);
expect(/<OS_2>\s*<version value="3"\/>/.test(output)).toEqual(true);
done();
});
});
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",
@ -42,12 +41,10 @@ describe("font_post", function () {
cMap,
toUnicode: new ToUnicodeMap([]),
});
ttx(font.data, function (output) {
const output = await ttx(font.data);
verifyTtxOutput(output);
expect(/<OS_2>\s*<version value="3"\/>/.test(output)).toEqual(true);
done();
});
});
});
});
});

View File

@ -19,10 +19,10 @@ 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",
@ -31,17 +31,13 @@ describe("font_post", function () {
cMap,
toUnicode: new ToUnicodeMap([]),
});
ttx(font.data, function (output) {
const output = await ttx(font.data);
verifyTtxOutput(output);
expect(/<post>\s*<formatType value="3\.0"\/>/.test(output)).toEqual(
true
);
done();
});
});
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) {
const output = await ttx(font.data);
verifyTtxOutput(output);
expect(/<post>\s*<formatType value="3\.0"\/>/.test(output)).toEqual(
true
);
done();
});
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) {
const output = await ttx(font.data);
verifyTtxOutput(output);
expect(/<post>\s*<formatType value="3\.0"\/>/.test(output)).toEqual(
true
);
done();
});
expect(/<post>\s*<formatType value="3\.0"\/>/.test(output)).toEqual(true);
});
});
});

View File

@ -65,7 +65,8 @@ function encodeFontData(data) {
return buffer;
}
function ttx(data, callback) {
function ttx(data) {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.open("POST", "/ttx");
@ -76,13 +77,14 @@ function ttx(data, callback) {
xhr.onreadystatechange = function getPdfOnreadystatechange(e) {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
callback(xhr.responseText);
resolve(xhr.responseText);
} else {
callback("<error>Transport error: " + xhr.statusText + "</error>");
reject(new Error(xhr.statusText));
}
}
};
xhr.send(encodedData);
});
}
function verifyTtxOutput(output) {