~bigbes/sr-ht-spec

ref: 36976713874550ff48b51f954a59dd597c36fa87 sr-ht-spec/doc/table_test.go -rw-r--r-- 1.8 KiB
36976713 — Eugene Blikh feat(db): webhook + user tables (Phase 5a foundation) 25 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package doc

import (
	"strings"
	"testing"
)

// A GFM table must come out inside .table-scroll. Without the wrapper a table of
// bare URLs cannot shrink to its grid column and paints over the document's
// table-of-contents rail.
func TestTableIsWrappedForScrolling(t *testing.T) {
	src := "| Date | URL |\n|---|---|\n| 2026-07-21 | https://example.com/a |\n"
	html := renderMD(t, src).HTML

	if !strings.Contains(html, `<div class="table-block"><div class="table-scroll"><table>`) {
		t.Errorf("table not wrapped:\n%s", html)
	}
	if !strings.Contains(html, "</table></div></div>") {
		t.Errorf("wrapper not closed:\n%s", html)
	}
	// The rows still go through goldmark's own renderer.
	if !strings.Contains(html, "<thead>") || !strings.Contains(html, "<td>") {
		t.Errorf("table body lost:\n%s", html)
	}
}

func TestRenderInline(t *testing.T) {
	r := NewRenderer()
	cases := []struct {
		name string
		in   string
		want string
	}{
		{"wikilink", "[[eatonphil-bookclub]]",
			`<a class="wikilink" href="/p/eatonphil-bookclub">eatonphil-bookclub</a>`},
		{"pdf attachment", "[[paper.pdf]]",
			`<a class="wikilink" href="/assets/paper.pdf">paper.pdf</a>`},
		{"several values", "[[alpha]], [[beta]]",
			`<a class="wikilink" href="/p/alpha">alpha</a>, <a class="wikilink" href="/p/beta">beta</a>`},
		{"bare url is autolinked", "https://example.com/x",
			`<a href="https://example.com/x">https://example.com/x</a>`},
		{"unresolved link stays visible", "[[missing-thing]]",
			`<span class="wikilink-missing" title="unresolved link: missing-thing">missing-thing</span>`},
		{"plain text", "want-to-read", "want-to-read"},
	}
	for _, c := range cases {
		t.Run(c.name, func(t *testing.T) {
			if got := r.RenderInline([]byte(c.in), "specs", fakeResolver{}); got != c.want {
				t.Errorf("RenderInline(%q)\n got: %s\nwant: %s", c.in, got, c.want)
			}
		})
	}
}