Spaces:
Running
Running
File size: 969 Bytes
e0d0231 | 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 28 29 30 31 | import { describe, expect, it } from "vitest";
import { decodeUnitConversion, encodeUnitConversion } from "./unitConversion";
describe("unit conversion header", () => {
it.each([
"16.4041994751 ft",
"100 °C = 212 °F",
"50% of 3 m",
"line one\nline two",
"5 km ≈ 3.1 mi",
])("carries %j through the header unchanged", (answer) => {
const encoded = encodeUnitConversion(answer);
// A header value holds no raw control character or non-ASCII byte.
expect(encoded).toMatch(/^[\x20-\x7e]*$/);
expect(decodeUnitConversion(encoded)).toBe(answer);
});
it.each(["100%", "%E0%A4%A", "%"])(
"returns nothing for %j, which is not a valid encoding",
(value) => {
expect(decodeUnitConversion(value)).toBeUndefined();
},
);
it("returns nothing for a header that holds no text", () => {
expect(decodeUnitConversion("")).toBeUndefined();
expect(decodeUnitConversion("%20%20")).toBeUndefined();
});
});
|