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 () {
 | 
			
		||||
    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);
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
@ -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);
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
@ -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);
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
@ -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);
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
@ -65,24 +65,26 @@ function encodeFontData(data) {
 | 
			
		||||
  return buffer;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function ttx(data, callback) {
 | 
			
		||||
  const xhr = new XMLHttpRequest();
 | 
			
		||||
  xhr.open("POST", "/ttx");
 | 
			
		||||
function ttx(data) {
 | 
			
		||||
  return new Promise((resolve, reject) => {
 | 
			
		||||
    const xhr = new XMLHttpRequest();
 | 
			
		||||
    xhr.open("POST", "/ttx");
 | 
			
		||||
 | 
			
		||||
  const encodedData = encodeFontData(data);
 | 
			
		||||
  xhr.setRequestHeader("Content-type", "text/plain");
 | 
			
		||||
  xhr.setRequestHeader("Content-length", encodedData.length);
 | 
			
		||||
    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.onreadystatechange = function getPdfOnreadystatechange(e) {
 | 
			
		||||
      if (xhr.readyState === 4) {
 | 
			
		||||
        if (xhr.status === 200) {
 | 
			
		||||
          resolve(xhr.responseText);
 | 
			
		||||
        } else {
 | 
			
		||||
          reject(new Error(xhr.statusText));
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  };
 | 
			
		||||
  xhr.send(encodedData);
 | 
			
		||||
    };
 | 
			
		||||
    xhr.send(encodedData);
 | 
			
		||||
  });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function verifyTtxOutput(output) {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user