g1t/apps/web/app/lib/branches.test.ts
| 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; |
| 3 | |
| 4 | import { count, drift } from "./branches.ts"; |
| 5 | |
| 6 | test("a branch two ahead of where main was, with main one further on", () => { |
| 7 | // main: m3 m2 m1; the branch left at m2 and added b2 b1. |
| 8 | assert.deepEqual(drift(["b2", "b1", "m2", "m1"], ["m3", "m2", "m1"], 50), { |
| 9 | ahead: 2, |
| 10 | behind: 1, |
| 11 | aheadMore: false, |
| 12 | behindMore: false, |
| 13 | }); |
| 14 | }); |
| 15 | |
| 16 | test("a branch at main's head is level", () => { |
| 17 | assert.deepEqual(drift(["m2", "m1"], ["m2", "m1"], 50), { ahead: 0, behind: 0, aheadMore: false, behindMore: false }); |
| 18 | }); |
| 19 | |
| 20 | test("a branch with no shared commit in reach says how much it read", () => { |
| 21 | assert.deepEqual(drift(["b3", "b2", "b1"], ["m2", "m1"], 3), { ahead: 3, behind: 0, aheadMore: true, behindMore: true }); |
| 22 | assert.equal(count(3, true), "3+"); |
| 23 | assert.equal(count(3, false), "3"); |
| 24 | }); |