font.test.js
1.4 kB · javascript · 39 lines
1import { expect, test } from "bun:test";2import * as font from "./font.js";34const bytes = await Bun.file(new URL("./pkg/font/mrlyjs_font_bg.wasm", import.meta.url)).arrayBuffer();5font.initSync({ module: bytes });6const rows = await Bun.file(new URL("../mrlyrs/fixtures/font.json", import.meta.url)).json();7const row = (fn) => rows.find((r) => r.fn === fn);8const sha256 = (text) => new Bun.CryptoHasher("sha256").update(text).digest("hex");910test("font::glyph", () => {11 const r = row("font::glyph");12 expect(font.glyph(r.in.c).rows).toEqual(r.out);13});1415test("font::raster::raster", () => {16 const r = row("font::raster::raster");17 expect(font.raster(r.in.text).map((line) => Array.from(line))).toEqual(r.out);18});1920test("font::path", () => {21 const r = row("font::path");22 expect(font.path(r.in.c)).toEqual(r.out);23});2425test("font::animate::animate", () => {26 const r = row("font::animate::animate");27 const anim = font.animate(r.in.text, r.in.pad);28 expect([anim.rows, anim.cols, anim.fps, anim.frames.length]).toEqual([r.out.rows, r.out.cols, r.out.fps, r.out.frames]);29 expect(anim.frames[anim.frames.length - 1]).toEqual(r.out.last);30});3132test("font::map", () => {33 const r = row("font::map");34 const table = font.map();35 const keys = Object.keys(table).sort();36 const json = "{" + keys.map((key) => JSON.stringify(key) + ":" + JSON.stringify(table[key])).join(",") + "}";37 expect(keys.length).toBe(r.out.len);38 expect(sha256(json)).toBe(r.out.sha256);39});