-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathfenced_code_test.go
More file actions
73 lines (55 loc) · 1.7 KB
/
Copy pathfenced_code_test.go
File metadata and controls
73 lines (55 loc) · 1.7 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
package hype
import (
"testing"
"github.com/stretchr/testify/require"
)
func Test_FencedCode_MarshalJSON(t *testing.T) {
t.Parallel()
r := require.New(t)
code := &FencedCode{
Element: NewEl("code", nil),
}
code.Nodes = append(code.Nodes, Text("var x = 1"))
r.NoError(code.Set("language", "go"))
testJSON(t, "fenced_code", code)
}
func Test_FencedCode_MD(t *testing.T) {
t.Parallel()
t.Run("simple content uses backticks", func(t *testing.T) {
r := require.New(t)
code := &FencedCode{
Element: NewEl("code", nil),
}
code.Nodes = Nodes{Text("var x = 1")}
r.NoError(code.Set("language", "go"))
md := code.MD()
r.Contains(md, "```go")
r.Contains(md, "var x = 1")
})
t.Run("content with triple backticks uses tildes", func(t *testing.T) {
r := require.New(t)
// Simulates an indented code block showing mermaid syntax
code := &FencedCode{
Element: NewEl("code", nil),
}
code.Nodes = Nodes{Text("```mermaid\ngraph LR\n A --> B\n```")}
md := code.MD()
// Should use tildes to avoid conflicts
r.True(md[0:3] == "~~~", "should start with tildes, got: %s", md[0:10])
r.Contains(md, "```mermaid")
r.True(md[len(md)-3:] == "~~~", "should end with tildes")
})
t.Run("content with both backticks and tildes uses longer fence", func(t *testing.T) {
r := require.New(t)
// Content has both ``` and ~~~
code := &FencedCode{
Element: NewEl("code", nil),
}
code.Nodes = Nodes{Text("Use ```backticks``` or ~~~tildes~~~ for fences")}
md := code.MD()
// Should use 4+ backticks since content has both ``` and ~~~
r.True(md[0:4] == "````", "should start with 4+ backticks, got: %s", md[0:10])
r.Contains(md, "```backticks```")
r.Contains(md, "~~~tildes~~~")
})
}