Replace done
callbacks in the font-tests with async/await instead
This commit is contained in:
parent
fd82adccfa
commit
3d55b2b10e
@ -7,13 +7,12 @@ describe("font1", function () {
|
|||||||
);
|
);
|
||||||
|
|
||||||
describe("test harness testing", function () {
|
describe("test harness testing", function () {
|
||||||
it("returns output", function (done) {
|
it("returns output", async function () {
|
||||||
ttx(font1_1, function (output) {
|
const output = await ttx(font1_1);
|
||||||
verifyTtxOutput(output);
|
|
||||||
expect(/<ttFont /.test(output)).toEqual(true);
|
verifyTtxOutput(output);
|
||||||
expect(/<\/ttFont>/.test(output)).toEqual(true);
|
expect(/<ttFont /.test(output)).toEqual(true);
|
||||||
done();
|
expect(/<\/ttFont>/.test(output)).toEqual(true);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -11,26 +11,24 @@ describe("font_fpgm", function () {
|
|||||||
);
|
);
|
||||||
|
|
||||||
describe("Fixes fpgm table", function () {
|
describe("Fixes fpgm table", function () {
|
||||||
it("table was truncated in the middle of functions", function (done) {
|
it("table was truncated in the middle of functions", async function () {
|
||||||
CMapFactory.create({
|
const cMap = await CMapFactory.create({
|
||||||
encoding: Name.get("Identity-H"),
|
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);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -15,7 +15,7 @@ describe("font_post", function () {
|
|||||||
);
|
);
|
||||||
|
|
||||||
describe("OS/2 table removal on bad post table values", 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), {
|
const font = new Font("font", new Stream(font2154), {
|
||||||
loadedName: "font",
|
loadedName: "font",
|
||||||
type: "TrueType",
|
type: "TrueType",
|
||||||
@ -23,31 +23,28 @@ describe("font_post", function () {
|
|||||||
defaultEncoding: [],
|
defaultEncoding: [],
|
||||||
toUnicode: new ToUnicodeMap([]),
|
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);
|
verifyTtxOutput(output);
|
||||||
done();
|
expect(/<OS_2>\s*<version value="3"\/>/.test(output)).toEqual(true);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("has invalid selection attributes presence", function (done) {
|
it("has invalid selection attributes presence", async function () {
|
||||||
CMapFactory.create({
|
const cMap = await CMapFactory.create({
|
||||||
encoding: Name.get("Identity-H"),
|
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);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -19,29 +19,25 @@ describe("font_post", function () {
|
|||||||
);
|
);
|
||||||
|
|
||||||
describe("post table removal on bad post table values", function () {
|
describe("post table removal on bad post table values", function () {
|
||||||
it("has invalid version number", function (done) {
|
it("has invalid version number", async function () {
|
||||||
CMapFactory.create({
|
const cMap = await CMapFactory.create({
|
||||||
encoding: Name.get("Identity-H"),
|
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), {
|
const font = new Font("font", new Stream(font2189), {
|
||||||
loadedName: "font",
|
loadedName: "font",
|
||||||
type: "TrueType",
|
type: "TrueType",
|
||||||
@ -49,16 +45,13 @@ describe("font_post", function () {
|
|||||||
defaultEncoding: [],
|
defaultEncoding: [],
|
||||||
toUnicode: new ToUnicodeMap([]),
|
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(
|
verifyTtxOutput(output);
|
||||||
true
|
expect(/<post>\s*<formatType value="3\.0"\/>/.test(output)).toEqual(true);
|
||||||
);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
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), {
|
const font = new Font("font", new Stream(font2374), {
|
||||||
loadedName: "font",
|
loadedName: "font",
|
||||||
type: "TrueType",
|
type: "TrueType",
|
||||||
@ -66,13 +59,10 @@ describe("font_post", function () {
|
|||||||
defaultEncoding: [],
|
defaultEncoding: [],
|
||||||
toUnicode: new ToUnicodeMap([]),
|
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(
|
verifyTtxOutput(output);
|
||||||
true
|
expect(/<post>\s*<formatType value="3\.0"\/>/.test(output)).toEqual(true);
|
||||||
);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -65,24 +65,26 @@ function encodeFontData(data) {
|
|||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
function ttx(data, callback) {
|
function ttx(data) {
|
||||||
const xhr = new XMLHttpRequest();
|
return new Promise((resolve, reject) => {
|
||||||
xhr.open("POST", "/ttx");
|
const xhr = new XMLHttpRequest();
|
||||||
|
xhr.open("POST", "/ttx");
|
||||||
|
|
||||||
const encodedData = encodeFontData(data);
|
const encodedData = encodeFontData(data);
|
||||||
xhr.setRequestHeader("Content-type", "text/plain");
|
xhr.setRequestHeader("Content-type", "text/plain");
|
||||||
xhr.setRequestHeader("Content-length", encodedData.length);
|
xhr.setRequestHeader("Content-length", encodedData.length);
|
||||||
|
|
||||||
xhr.onreadystatechange = function getPdfOnreadystatechange(e) {
|
xhr.onreadystatechange = function getPdfOnreadystatechange(e) {
|
||||||
if (xhr.readyState === 4) {
|
if (xhr.readyState === 4) {
|
||||||
if (xhr.status === 200) {
|
if (xhr.status === 200) {
|
||||||
callback(xhr.responseText);
|
resolve(xhr.responseText);
|
||||||
} else {
|
} else {
|
||||||
callback("<error>Transport error: " + xhr.statusText + "</error>");
|
reject(new Error(xhr.statusText));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
};
|
xhr.send(encodedData);
|
||||||
xhr.send(encodedData);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function verifyTtxOutput(output) {
|
function verifyTtxOutput(output) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user