Skip to content
Myr

line-hash.test.ts

This file

Path

apps/web/test/line-hash.test.ts

100 lines · 2.6 KiB · TypeScript

Last changed by

Merge build/comments-web-rest into mainoscabrielbefore adoption0eb1248

History of this file

Take it

Give the web its W9 dependencies, components, project nav, line and revision helpers, and a stub for every new pageoscabrielbefore adoption254268a

lines 1–3why, one step back
1import { describe, expect, it } from "@effect/vitest";
2import { Option } from "effect";3

Merge build/1211-code-browseroscabrielbefore adoptiona6808d3

lines 4–9why, one step back
4import {
5 diffLinesHash,6 lineHash,7 parseDiffHash,8 parseLineHash,9} from "../src/features/code/line-hash.ts";

Give the web its W9 dependencies, components, project nav, line and revision helpers, and a stub for every new pageoscabrielbefore adoption254268a

lines 10–51why, one step back
10
11describe("a line anchor", () => {12 it("names one line", () => {13 expect(parseLineHash("#L10")).toStrictEqual(14 Option.some({ end: 10, start: 10 })15 );16 });1718 it("names a range", () => {19 expect(parseLineHash("#L10-L20")).toStrictEqual(20 Option.some({ end: 20, start: 10 })21 );22 });2324 it("names the same range whichever end comes first", () => {25 expect(parseLineHash("#L20-L10")).toStrictEqual(26 Option.some({ end: 20, start: 10 })27 );28 });2930 it("reads the router's hash, which carries no #", () => {31 expect(parseLineHash("L7")).toStrictEqual(32 Option.some({ end: 7, start: 7 })33 );34 });3536 it.each(["#L0", "#Lx", "#foo", "", "#L", "#L1-", "#L1-L0", "#L01", "#L3-7"])(37 "names no line in %j",38 (hash) => {39 expect(parseLineHash(hash)).toStrictEqual(Option.none());40 }41 );4243 it("is written back as #L<a>-L<b>, or #L<n> for one line", () => {44 expect(lineHash({ end: 20, start: 10 })).toBe("#L10-L20");45 expect(lineHash({ end: 7, start: 7 })).toBe("#L7");46 });4748 it("round-trips through its own writing", () => {49 expect(parseLineHash(lineHash({ end: 42, start: 3 }))).toStrictEqual(50 Option.some({ end: 42, start: 3 })51 );

Merge build/1211-code-browseroscabrielbefore adoptiona6808d3

lines 52–98why, one step back
52 });
53});5455describe("a file in a commit's diff, by its anchor", () => {56 it("names the file, its path decoded", () => {57 expect(parseDiffHash("#diff-src%2Fparse.ts")).toStrictEqual(58 Option.some({ lines: Option.none(), path: "src/parse.ts" })59 );60 });6162 it("names lines on the new side, or the old with D", () => {63 expect(parseDiffHash("diff-src%2Fparse.ts:L4-L7")).toStrictEqual(64 Option.some({65 lines: Option.some({66 end: 7,67 path: "src/parse.ts",68 side: "additions",69 start: 4,70 }),71 path: "src/parse.ts",72 })73 );74 expect(75 Option.flatMap(parseDiffHash("#diff-a.ts:D3"), ({ lines }) => lines)76 ).toStrictEqual(77 Option.some({ end: 3, path: "a.ts", side: "deletions", start: 3 })78 );79 });8081 it("is written back as it is read", () => {82 const lines = {83 end: 9,84 path: "src/a b.ts",85 side: "additions",86 start: 2,87 } as const;8889 expect(90 Option.flatMap(91 parseDiffHash(diffLinesHash(lines)),92 (named) => named.lines93 )94 ).toStrictEqual(Option.some(lines));95 });9697 it("names nothing for another anchor", () => {98 expect(parseDiffHash("#L4")).toStrictEqual(Option.none());

Give the web its W9 dependencies, components, project nav, line and revision helpers, and a stub for every new pageoscabrielbefore adoption254268a

lines 99–100why, one step back
99 });
100});