-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode_block_test.go
More file actions
68 lines (57 loc) · 1.35 KB
/
code_block_test.go
File metadata and controls
68 lines (57 loc) · 1.35 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
package remark
import (
"html/template"
"testing"
"github.com/stretchr/testify/require"
)
func Test_CodeBlock_Name(t *testing.T) {
t.Parallel()
r := require.New(t)
var code CodeBlock
r.Equal("code", code.Name())
}
func Test_CodeBlock_HTML(t *testing.T) {
t.Parallel()
r := require.New(t)
code := CodeBlock{
Generic: &Generic{
Attributes: Attributes{
"src": "./src/foo.go",
"snippet": "snip",
},
Children: Tags{
String("hello"),
},
},
}
code.Set("k1", "one")
code.Set("k2", "two")
code.Set("k3", "three")
exp := template.HTML(`<pre><code id="src-foo.go#snip" k1="one" k2="two" k3="three" language="plain" snippet="snip" src="./src/foo.go"></code></pre>`)
act := code.HTML()
r.Equal(exp, act)
}
func Test_CodeBlock_String(t *testing.T) {
t.Parallel()
r := require.New(t)
code := CodeBlock{
Generic: &Generic{
Attributes: Attributes{
"src": "./src/foo.go",
"snippet": "snip",
},
Children: Tags{
String("fmt.Println(\"Hello\")"),
},
},
}
result := code.String()
// String() should return unescaped HTML
r.Contains(result, "<pre>")
r.Contains(result, "<code")
r.Contains(result, `src="./src/foo.go"`)
r.Contains(result, `snippet="snip"`)
// Note: CodeBlock.String() may not include the children content in the output
r.Contains(result, "</code>")
r.Contains(result, "</pre>")
}