oficina / mapa Public

Clone
git clone https://amadan.net/oficina/mapa

Plain git — no account needed to clone.

Download

Download this file

1package main
2
3const (
4 mapperPkg = "./internal/mapa/notionmd/"
5 neutral = "internal/mapa/notionmd/neutral.go"
6 mapperFile = "internal/mapa/notionmd/mapper.go"
7 mapperNormalise = "internal/mapa/notionmd/normalise.go"
8 gateI1 = "TestI1Fidelity"
9)
10
11// mapper breaks one line of the mapper, and expects gate I1 to notice.
12func mapper(name, file, from, to string) mutation {
13 return mutation{gate: "I1", name: name, test: gateI1, pkg: mapperPkg,
14 edits: []edit{{file: file, from: from, to: to}}}
15}
16
17// mapperMutations break the Notion mapper's gates (Notion import spec
18// §18: I1, and I5's mapper half), one at a time. Each names its
19// package: the mapper's tests are in internal/mapa/notionmd/.
20var mapperMutations = []mutation{
21 {gate: "R5M1a", name: "a raw-address label written again",
22 pkg: mapperPkg, test: "TestM1LongLinksStayWhole", edits: []edit{{
23 file: "internal/mapa/notionmd/links.go",
24 from: "if encodeAddress(label) == encoded {", to: "if false {"}}},
25 {gate: "R5L2", name: "an empty query encoded, not dropped",
26 pkg: mapperPkg, test: "TestM1Long", edits: []edit{{
27 file: "internal/mapa/notionmd/links.go",
28 from: "if strings.HasSuffix(address, \"?\") &&",
29 to: "if false && strings.HasSuffix(address, \"?\") &&"}}},
30 {gate: "R5L1", name: "[ written as %5D", pkg: mapperPkg,
31 test: "TestM1LongAddressEncodings", edits: []edit{{
32 file: "internal/mapa/notionmd/links.go",
33 from: "\t\t\tfmt.Fprintf(&out, \"%%%02X\", char)\n",
34 to: "\t\t\tif char == '[' {\n\t\t\t\tchar = ']'\n\t\t\t}\n" +
35 "\t\t\tfmt.Fprintf(&out, \"%%%02X\", char)\n"}}},
36 {gate: "R4M1", name: "a long address written without its brackets",
37 pkg: mapperPkg, test: "TestM1LongLinksStayWhole", edits: []edit{{
38 file: "internal/mapa/notionmd/links.go",
39 from: "return append(out, fixed(\"(\"), " +
40 "part{kind: bare, url: written},\n\t\tfixed(\")\"))",
41 to: "return append(out, part{kind: bare, url: written})"}}},
42 {gate: "R4M1", name: "a long address's last character left as it is",
43 pkg: mapperPkg, test: "TestM1LongLinksStayWhole", edits: []edit{{
44 file: "internal/mapa/notionmd/links.go",
45 from: "(last && strings.ContainsRune(",
46 to: "(last && false && strings.ContainsRune("}}},
47 {gate: "R4M1", name: "brackets and backticks left in a long address",
48 pkg: mapperPkg, test: "TestM1LongLinksStayWhole", edits: []edit{{
49 file: "internal/mapa/notionmd/links.go",
50 from: "if strings.ContainsRune(\"[]<>`|\", char) ||",
51 to: "if strings.ContainsRune(\"\", char) ||"}}},
52 mapper("R3M1: an over-long generated link left as a link",
53 "internal/mapa/notionmd/links.go",
54 "if !markup.LinkAddress(encoded) {", "if false {"),
55 {gate: "R3L7", name: "neutralise checks no context",
56 pkg: mapperPkg, test: "TestM1TheDeadlineReachesInsideABlock",
57 edits: []edit{{file: neutral,
58 from: "\t\tif mapper.stopped() != nil {\n\t\t\treturn\n\t\t}\n" +
59 "\t\teach := mergeLiterals",
60 to: "\t\teach := mergeLiterals"}}},
61 mapper("Low 1: an address the autolink stops short of rewritten",
62 "internal/mapa/notionmd/addresses.go",
63 "\t\t!strings.ContainsAny(rest, \" \\t\\n<>()[]\") &&", ""),
64 mapper("Low 2: a name's line break kept", mapperNormalise,
65 "\t\tblock.Title = oneLine.Replace(block.Title)\n", "\n"),
66 {gate: "Low3", name: "the check ignores a marker",
67 pkg: "./internal/mapa/notionmd/", test: "TestTheCheckRefusesAMarker",
68 edits: []edit{{"internal/mapa/notionmd/check.go",
69 "parsed[0].Kind != block.kind || parsed[0].Marker != \"\" {",
70 "parsed[0].Kind != block.kind {"}}},
71 {gate: "M1", name: "no bound on a link's address", pkg: mapperPkg,
72 test: "TestM1SharedAddressesAreLinear", edits: []edit{{
73 file: "internal/mapa/markup/spans.go",
74 from: "if len(address) > MaxAddress {", to: "if false {"}}},
75 {gate: "M2", name: "openers re-parse the line at each [", pkg: mapperPkg,
76 test: "TestM2NeutralisingIsLinear", edits: []edit{{file: neutral,
77 from: "opens := markup.OpensAt(text)",
78 to: "opens := func(at int) bool {\n" +
79 "\t\t\tspans := markup.Spans(text[at:])\n" +
80 "\t\t\treturn len(spans) > 0 &&\n" +
81 "\t\t\t\tspans[0].Kind != markup.Text\n" +
82 "\t\t}"}}},
83 mapper("M1: line endings left as Notion sent them", mapperFile,
84 "\tpage = normalisePage(page)\n", "\n"),
85 mapper("L1: a bare address left against generated syntax", neutral,
86 "\t\teach = mapper.addresses(each)\n", "\n"),
87 mapper("L1: an item shaped like a rule left alone", neutral,
88 "\tmapper.ruleItems(block)\n", "\n"),
89 mapper("a block start at a line's beginning left alone", neutral,
90 "if markup.StartsBlock(text) || markup.FenceLike(text) {",
91 "if false {"),
92 mapper("[[ in literal text left alone", neutral,
93 "if text[at] == '[' && at+1 < len(text) && text[at+1] == '[' {",
94 "if false {"),
95 mapper("literal backticks left alone", neutral,
96 "\t\t\tgraveLookAlike)", "\t\t\t\"`\")"),
97 mapper("a literal ! before a generated link left alone", neutral,
98 `if strings.HasSuffix(text, "!") {`,
99 `if strings.HasSuffix(text, "?!") {`),
100 mapper("a literal [label](url) left alone", neutral,
101 "return markup.LinkAddress(address) || "+
102 `strings.HasPrefix(address, "/i/")`,
103 "return address == \"\\x00\""),
104 mapper("a literal [ opening a link over generated syntax", neutral,
105 "if text[at] == '[' && owners[at] == literal && opens(at) {",
106 "if text[at] == '[' && owners[at] == literal && opens(at) && false {"),
107 mapper("a literal task box left alone", neutral,
108 `markup.TaskBox(block.lines[0].text()); state != "" {`,
109 `markup.TaskBox(block.lines[0].text()); state == "?" {`),
110 mapper("a trailing ^word left alone", neutral,
111 "\tat := markup.MarkerAt(tail)\n\tif at < 0 {",
112 "\tat := markup.MarkerAt(tail)\n\tif true {"),
113 mapper("a marked run holding * keeps its mark",
114 "internal/mapa/notionmd/inline.go",
115 "if (chosen.bold || chosen.italic) && "+
116 `strings.Contains(run.Text, "*") {`, "if false {"),
117 {gate: "I5", name: "a Notion page address is not resolved",
118 test: gateI1, pkg: mapperPkg, edits: []edit{{
119 file: "internal/mapa/notionmd/links.go",
120 from: `notion := host == "notion.so" || host == "www.notion.so" ||`,
121 to: `notion := false && host == "www.notion.so" &&`}}},
122 {gate: "I5", name: "a mention links Notion's text, not the final title",
123 test: gateI1, pkg: mapperPkg, edits: []edit{{
124 file: "internal/mapa/notionmd/links.go",
125 from: "return []part{mapper.wikiTo(id, title, run.Text)}",
126 to: "return []part{mapper.wikiTo(id, " +
127 "run.Text+title[:0], run.Text)}"}}},
128 {gate: "I1", name: "the structure check passes everything",
129 test: "TestTheCheckRefusesWhatWasNotMeant", pkg: mapperPkg,
130 edits: []edit{{file: "internal/mapa/notionmd/check.go",
131 from: "func check(block written) bool {\n\tsource",
132 to: "func check(block written) bool {\n" +
133 "\treturn true\n\tsource"}}},
134}
135