summaryrefslogtreecommitdiffstats
path: root/utils/markdown/inspect_test.go
blob: 0c5032f2d7c4b062d37e7bd494c65e6e16b3213c (plain)
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
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

package markdown

import (
	"fmt"
	"strings"
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestInspect(t *testing.T) {
	markdown := `
[foo]: bar
- a
  > [![]()]()
  > [![foo]][foo]
- d
`

	visited := []string{}
	level := 0
	Inspect(markdown, func(blockOrInline interface{}) bool {
		if blockOrInline == nil {
			level--
		} else {
			visited = append(visited, strings.Repeat(" ", level*4)+strings.TrimPrefix(fmt.Sprintf("%T", blockOrInline), "*markdown."))
			level++
		}
		return true
	})

	assert.Equal(t, []string{
		"Document",
		"    Paragraph",
		"    List",
		"        ListItem",
		"            Paragraph",
		"                Text",
		"            BlockQuote",
		"                Paragraph",
		"                    InlineLink",
		"                        InlineImage",
		"                    SoftLineBreak",
		"                    ReferenceLink",
		"                        ReferenceImage",
		"                            Text",
		"        ListItem",
		"            Paragraph",
		"                Text",
	}, visited)
}