github.com/levb/mattermost-server@v5.3.1+incompatible/utils/markdown/inspect_test.go (about) 1 // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package markdown 5 6 import ( 7 "fmt" 8 "strings" 9 "testing" 10 11 "github.com/stretchr/testify/assert" 12 ) 13 14 func TestInspect(t *testing.T) { 15 markdown := ` 16 [foo]: bar 17 - a 18 > [![]()]() 19 > [![foo]][foo] 20 - d 21 ` 22 23 visited := []string{} 24 level := 0 25 Inspect(markdown, func(blockOrInline interface{}) bool { 26 if blockOrInline == nil { 27 level-- 28 } else { 29 visited = append(visited, strings.Repeat(" ", level*4)+strings.TrimPrefix(fmt.Sprintf("%T", blockOrInline), "*markdown.")) 30 level++ 31 } 32 return true 33 }) 34 35 assert.Equal(t, []string{ 36 "Document", 37 " Paragraph", 38 " List", 39 " ListItem", 40 " Paragraph", 41 " Text", 42 " BlockQuote", 43 " Paragraph", 44 " InlineLink", 45 " InlineImage", 46 " SoftLineBreak", 47 " ReferenceLink", 48 " ReferenceImage", 49 " Text", 50 " ListItem", 51 " Paragraph", 52 " Text", 53 }, visited) 54 }