···11+import { describe, expect, it } from "./suite.ts";
22+import { createTerm } from "../term.ts";
33+import { close, fixed, grow, open, text } from "../ops.ts";
44+import { print } from "./print.ts";
55+66+const decode = (b: Uint8Array) => new TextDecoder().decode(b);
77+88+// Two 1-wide fixed children inside a 10-wide grow row.
99+function row(alignX: number) {
1010+ return [
1111+ open("row", {
1212+ layout: { width: grow(), height: fixed(1), direction: "ltr", alignX },
1313+ }),
1414+ open("a", { layout: { width: fixed(1), height: fixed(1) } }),
1515+ text("A"),
1616+ close(),
1717+ open("b", { layout: { width: fixed(1), height: fixed(1) } }),
1818+ text("B"),
1919+ close(),
2020+ close(),
2121+ ];
2222+}
2323+2424+describe("justifyContent space distribution", () => {
2525+ it("space-between pushes children to opposite edges", async () => {
2626+ let term = await createTerm({ width: 10, height: 1 });
2727+ let res = term.render(row(3)); // 3 = space-between
2828+ // first child hugs the left edge
2929+ expect(res.info.get("a")!.bounds.x).toBe(0);
3030+ // last child hugs the right edge
3131+ expect(res.info.get("b")!.bounds.x).toBe(9);
3232+ // all free space sits between the two children
3333+ expect(print(decode(res.output), 10, 1)).toBe("A B");
3434+ });
3535+3636+ it("space-evenly puts equal gaps on the ends and between", async () => {
3737+ let term = await createTerm({ width: 10, height: 1 });
3838+ let res = term.render(row(5)); // 5 = space-evenly
3939+ // leading gap is non-zero (first child not at the left edge)
4040+ expect(res.info.get("a")!.bounds.x).toBeGreaterThan(0);
4141+ // trailing gap is non-zero (last child not at the right edge)
4242+ expect(res.info.get("b")!.bounds.x).toBeLessThan(9);
4343+ // 3 equal gaps of (10-2)/3 -> A at col 2, B at col 6
4444+ expect(print(decode(res.output), 10, 1)).toBe(" A B");
4545+ });
4646+4747+ it("space-around puts half-size gaps on the ends", async () => {
4848+ let term = await createTerm({ width: 10, height: 1 });
4949+ let res = term.render(row(4)); // 4 = space-around
5050+ // leading gap is non-zero (first child not at the left edge)
5151+ expect(res.info.get("a")!.bounds.x).toBeGreaterThan(0);
5252+ // last child is not pinned to the right edge
5353+ expect(res.info.get("b")!.bounds.x).toBeLessThan(9);
5454+ });
5555+});