home / client / test / qr.test.mjs
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// The QR encoder: byte mode, EC level M, versions 1-7. Every module of every
// matrix, plus the SVG path.
import test from "node:test";
import assert from "node:assert/strict";
import { boot, serialize, vectors } from "./harness.mjs";

const { lib } = await boot();
const v = vectors("qr");

test("qrMatrix: every payload's modules are identical", () => {
  v.script.forEach((text, i) => {
    const rows = [...lib.qrMatrix(text)];
    assert.equal(rows.length, v.out[i].size, `case ${i} size`);
    assert.deepEqual(rows, v.out[i].rows, `case ${i} (${JSON.stringify(text.slice(0, 24))})`);
  });
});

test("a payload past v7-M throws the same message", () => {
  assert.throws(() => lib.qrMatrix("x".repeat(200)), (e) => e.message === v.tooLong);
});

test("qrSvg: the same element, the same path data", () => {
  const svg = lib.qrSvg("https://ardegazu.ro/#key=" + "A".repeat(43), 4);
  assert.equal(svg.getAttribute("viewBox"), v.svg.viewBox);
  assert.equal(svg.querySelector("path").getAttribute("d"), v.svg.d);
  assert.equal(serialize(svg), v.svg.markup);
});

static mirror of HEAD · about · clone: git clone https://git.ardegazu.ro/home.git