Repository navigation
Expand file tree
/
Copy pathnotes_test.go
More file actions
83 lines (67 loc) · 1.71 KB
/
Copy pathnotes_test.go
File metadata and controls
83 lines (67 loc) · 1.71 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"bytes"
"regexp"
"strings"
"testing"
)
func TestRenderNotes(t *testing.T) {
pr, err := newRenderer(embedFS, func(path string) string { return path }, pageSettings{})
if err != nil {
t.Fatal(err)
}
dir := t.TempDir()
writeFiles(t, dir, map[string]string{
"x.slide": `# Talk
: Welcome **everyone**.
::: notes
- first
- second
:::
Ada Example
## One
Text.
: See [the docs](https://go.dev/doc/).
: A type parameter ` + "`<T>`" + `.
::: notes
## Not a slide
.code not/a/command.go
// a comment in code
:::
### Part
: A note in a subsection.
:::notes
In a subsection too.
:::
## Two
Nothing to say.
`,
})
var buf bytes.Buffer
if err := (&server{renderer: pr}).renderNotes(&buf, dirRoot(dir), "x.slide"); err != nil {
t.Fatal(err)
}
// One block for each slide, and one for slides that present adds.
blocks := regexp.MustCompile(`(?s)<div class='slide-notes' hidden>(.*?)</div>`).FindAllStringSubmatch(buf.String(), -1)
want := []string{
"<p>Welcome <strong>everyone</strong>.</p>\n" +
"<ul>\n<li>first</li>\n<li>second</li>\n</ul>",
`<p>See <a href="https://go.dev/doc/" target="_blank" rel="noopener">the docs</a>.</p>` + "\n" +
"<p>A type parameter <code><T></code>.</p>\n" +
"<h2>Not a slide</h2>\n" +
"<p>.code not/a/command.go</p>\n" +
"<pre><code>// a comment in code\n</code></pre>\n" +
"<p>A note in a subsection.</p>\n" +
"<p>In a subsection too.</p>",
"",
"",
}
if len(blocks) != len(want) {
t.Fatalf("got %d blocks of notes, want %d:\n%s", len(blocks), len(want), buf.String())
}
for i, b := range blocks {
if got := strings.TrimSpace(b[1]); got != want[i] {
t.Errorf("notes of slide %d:\ngot %s\nwant %s", i+1, got, want[i])
}
}
}