Extract Grammaratur, Dregarnuhr, Geduldh, Mestionora, Ordoschnellic, Schutzaria, Kunstzeal and Seheweit behind compatible application contracts. Include accumulated editor resilience, navigation and theme UX, remote CLI, storage/schema and DR groundwork, tests and design/operations documentation. Verified: uncached full Go suite; go vet ./...; race tests for all eight components; 11 targeted Chromium tests; Node suites; 19 Python CLI tests; reproducible editor build. No push, release tag or deployment in this checkpoint.
68 lines
2.4 KiB
Go
68 lines
2.4 KiB
Go
package grammaratur
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestAuthoringRoundTrip(t *testing.T) {
|
|
for _, source := range []string{
|
|
"<h1>Heading</h1><p>Hello <strong>world</strong>.</p>",
|
|
"<p>{{children:/guide}}</p>",
|
|
"<figure data-extra=\"kept\"><img src=\"/photo\" alt=\"Photo\"><figcaption>A caption</figcaption></figure>",
|
|
"<!-- keep comment --><p id=\"anchor\" class=\"custom\">text</p>",
|
|
"<table><tr><td rowspan=\"2\">a</td><td>b</td></tr><tr><td>c</td></tr></table>",
|
|
"<p>a <em>b</em> c</p>",
|
|
"<pre><code class=\"language-python\"> print('x')\n</code></pre>",
|
|
"<custom-element data-x=\"1\">opaque</custom-element>",
|
|
"<div class=\"custom\">\n<p>one</p>\n\n<p>two</p>\n</div>",
|
|
"<script>const x = '<b>untouched</b>';</script>",
|
|
} {
|
|
t.Run(source, func(t *testing.T) {
|
|
md, err := HTMLToMarkdownAuthoring(source)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if htmlStructure(MarkdownAuthoringHTML(md)) != htmlStructure(source) {
|
|
t.Fatalf("lossy conversion: %q", md)
|
|
}
|
|
})
|
|
}
|
|
md, err := HTMLToMarkdownAuthoring("<h1>Hello</h1>")
|
|
if err != nil || md != "# Hello" {
|
|
t.Fatalf("simple Markdown conversion: %q %v", md, err)
|
|
}
|
|
for _, source := range []string{`<p data-custom="yes">Hello</p>`, `<!-- saved --><h1>Title</h1>`, `<p>a <em>b</em> c</p>`} {
|
|
md, err := HTMLToMarkdownAuthoring(source)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if htmlStructure(MarkdownAuthoringHTML(md)) != htmlStructure(source) {
|
|
t.Fatal("whitespace/attributes lost")
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestAuthoringProtectedHTML(t *testing.T) {
|
|
for _, raw := range []string{"<figure data-x='a'>a</figure>", "<pre>```\n{=html}\n````</pre>\n", "<script>const raw = `x`</script>", "<p>line\r\n</p>"} {
|
|
md := rawHTMLBlock(raw)
|
|
if got := MarkdownAuthoringHTML(md); got != raw {
|
|
t.Fatalf("raw bytes changed: %q want %q", got, raw)
|
|
}
|
|
mixed := MarkdownAuthoringHTML("# Added\n\n" + md + "\n\nTail")
|
|
if !strings.Contains(mixed, raw) || !strings.Contains(mixed, "<h1>Added</h1>") || !strings.Contains(mixed, "<p>Tail</p>") {
|
|
t.Fatalf("mixed blocks: %q", mixed)
|
|
}
|
|
}
|
|
code := "````text\n```{=html}\n<script>unsafe()</script>\n```\n````"
|
|
if strings.Contains(MarkdownAuthoringHTML(code), "<script>") {
|
|
t.Fatal("HTML escaped out of ordinary code sample")
|
|
}
|
|
}
|
|
|
|
func TestAuthoringWhitespaceComparisonIsConservative(t *testing.T) {
|
|
if htmlStructure("<p>a <em>b</em> c</p>") == htmlStructure("<p>a<em>b</em>c</p>") {
|
|
t.Fatal("word boundaries ignored")
|
|
}
|
|
}
|