package main const ( mapperPkg = "./internal/mapa/notionmd/" neutral = "internal/mapa/notionmd/neutral.go" mapperFile = "internal/mapa/notionmd/mapper.go" mapperNormalise = "internal/mapa/notionmd/normalise.go" gateI1 = "TestI1Fidelity" ) // mapper breaks one line of the mapper, and expects gate I1 to notice. func mapper(name, file, from, to string) mutation { return mutation{gate: "I1", name: name, test: gateI1, pkg: mapperPkg, edits: []edit{{file: file, from: from, to: to}}} } // mapperMutations break the Notion mapper's gates (Notion import spec // ยง18: I1, and I5's mapper half), one at a time. Each names its // package: the mapper's tests are in internal/mapa/notionmd/. var mapperMutations = []mutation{ {gate: "R5M1a", name: "a raw-address label written again", pkg: mapperPkg, test: "TestM1LongLinksStayWhole", edits: []edit{{ file: "internal/mapa/notionmd/links.go", from: "if encodeAddress(label) == encoded {", to: "if false {"}}}, {gate: "R5L2", name: "an empty query encoded, not dropped", pkg: mapperPkg, test: "TestM1Long", edits: []edit{{ file: "internal/mapa/notionmd/links.go", from: "if strings.HasSuffix(address, \"?\") &&", to: "if false && strings.HasSuffix(address, \"?\") &&"}}}, {gate: "R5L1", name: "[ written as %5D", pkg: mapperPkg, test: "TestM1LongAddressEncodings", edits: []edit{{ file: "internal/mapa/notionmd/links.go", from: "\t\t\tfmt.Fprintf(&out, \"%%%02X\", char)\n", to: "\t\t\tif char == '[' {\n\t\t\t\tchar = ']'\n\t\t\t}\n" + "\t\t\tfmt.Fprintf(&out, \"%%%02X\", char)\n"}}}, {gate: "R4M1", name: "a long address written without its brackets", pkg: mapperPkg, test: "TestM1LongLinksStayWhole", edits: []edit{{ file: "internal/mapa/notionmd/links.go", from: "return append(out, fixed(\"(\"), " + "part{kind: bare, url: written},\n\t\tfixed(\")\"))", to: "return append(out, part{kind: bare, url: written})"}}}, {gate: "R4M1", name: "a long address's last character left as it is", pkg: mapperPkg, test: "TestM1LongLinksStayWhole", edits: []edit{{ file: "internal/mapa/notionmd/links.go", from: "(last && strings.ContainsRune(", to: "(last && false && strings.ContainsRune("}}}, {gate: "R4M1", name: "brackets and backticks left in a long address", pkg: mapperPkg, test: "TestM1LongLinksStayWhole", edits: []edit{{ file: "internal/mapa/notionmd/links.go", from: "if strings.ContainsRune(\"[]<>`|\", char) ||", to: "if strings.ContainsRune(\"\", char) ||"}}}, mapper("R3M1: an over-long generated link left as a link", "internal/mapa/notionmd/links.go", "if !markup.LinkAddress(encoded) {", "if false {"), {gate: "R3L7", name: "neutralise checks no context", pkg: mapperPkg, test: "TestM1TheDeadlineReachesInsideABlock", edits: []edit{{file: neutral, from: "\t\tif mapper.stopped() != nil {\n\t\t\treturn\n\t\t}\n" + "\t\teach := mergeLiterals", to: "\t\teach := mergeLiterals"}}}, mapper("Low 1: an address the autolink stops short of rewritten", "internal/mapa/notionmd/addresses.go", "\t\t!strings.ContainsAny(rest, \" \\t\\n<>()[]\") &&", ""), mapper("Low 2: a name's line break kept", mapperNormalise, "\t\tblock.Title = oneLine.Replace(block.Title)\n", "\n"), {gate: "Low3", name: "the check ignores a marker", pkg: "./internal/mapa/notionmd/", test: "TestTheCheckRefusesAMarker", edits: []edit{{"internal/mapa/notionmd/check.go", "parsed[0].Kind != block.kind || parsed[0].Marker != \"\" {", "parsed[0].Kind != block.kind {"}}}, {gate: "M1", name: "no bound on a link's address", pkg: mapperPkg, test: "TestM1SharedAddressesAreLinear", edits: []edit{{ file: "internal/mapa/markup/spans.go", from: "if len(address) > MaxAddress {", to: "if false {"}}}, {gate: "M2", name: "openers re-parse the line at each [", pkg: mapperPkg, test: "TestM2NeutralisingIsLinear", edits: []edit{{file: neutral, from: "opens := markup.OpensAt(text)", to: "opens := func(at int) bool {\n" + "\t\t\tspans := markup.Spans(text[at:])\n" + "\t\t\treturn len(spans) > 0 &&\n" + "\t\t\t\tspans[0].Kind != markup.Text\n" + "\t\t}"}}}, mapper("M1: line endings left as Notion sent them", mapperFile, "\tpage = normalisePage(page)\n", "\n"), mapper("L1: a bare address left against generated syntax", neutral, "\t\teach = mapper.addresses(each)\n", "\n"), mapper("L1: an item shaped like a rule left alone", neutral, "\tmapper.ruleItems(block)\n", "\n"), mapper("a block start at a line's beginning left alone", neutral, "if markup.StartsBlock(text) || markup.FenceLike(text) {", "if false {"), mapper("[[ in literal text left alone", neutral, "if text[at] == '[' && at+1 < len(text) && text[at+1] == '[' {", "if false {"), mapper("literal backticks left alone", neutral, "\t\t\tgraveLookAlike)", "\t\t\t\"`\")"), mapper("a literal ! before a generated link left alone", neutral, `if strings.HasSuffix(text, "!") {`, `if strings.HasSuffix(text, "?!") {`), mapper("a literal [label](url) left alone", neutral, "return markup.LinkAddress(address) || "+ `strings.HasPrefix(address, "/i/")`, "return address == \"\\x00\""), mapper("a literal [ opening a link over generated syntax", neutral, "if text[at] == '[' && owners[at] == literal && opens(at) {", "if text[at] == '[' && owners[at] == literal && opens(at) && false {"), mapper("a literal task box left alone", neutral, `markup.TaskBox(block.lines[0].text()); state != "" {`, `markup.TaskBox(block.lines[0].text()); state == "?" {`), mapper("a trailing ^word left alone", neutral, "\tat := markup.MarkerAt(tail)\n\tif at < 0 {", "\tat := markup.MarkerAt(tail)\n\tif true {"), mapper("a marked run holding * keeps its mark", "internal/mapa/notionmd/inline.go", "if (chosen.bold || chosen.italic) && "+ `strings.Contains(run.Text, "*") {`, "if false {"), {gate: "I5", name: "a Notion page address is not resolved", test: gateI1, pkg: mapperPkg, edits: []edit{{ file: "internal/mapa/notionmd/links.go", from: `notion := host == "notion.so" || host == "www.notion.so" ||`, to: `notion := false && host == "www.notion.so" &&`}}}, {gate: "I5", name: "a mention links Notion's text, not the final title", test: gateI1, pkg: mapperPkg, edits: []edit{{ file: "internal/mapa/notionmd/links.go", from: "return []part{mapper.wikiTo(id, title, run.Text)}", to: "return []part{mapper.wikiTo(id, " + "run.Text+title[:0], run.Text)}"}}}, {gate: "I1", name: "the structure check passes everything", test: "TestTheCheckRefusesWhatWasNotMeant", pkg: mapperPkg, edits: []edit{{file: "internal/mapa/notionmd/check.go", from: "func check(block written) bool {\n\tsource", to: "func check(block written) bool {\n" + "\treturn true\n\tsource"}}}, }