mirror of
https://github.com/hanzoai/team.git
synced 2026-09-30 01:57:35 +00:00
43 lines
1.4 KiB
Go
43 lines
1.4 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package markdown
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestBlockQuoteStart(t *testing.T) {
|
|
t.Run("depth at the nesting limit is rejected even for a well-formed block quote", func(t *testing.T) {
|
|
markdown := "> foo"
|
|
blocks := blockQuoteStart(markdown, 0, Range{0, len(markdown)}, maxNestingDepth)
|
|
assert.Nil(t, blocks)
|
|
})
|
|
|
|
t.Run("nesting from a single line is capped at maxNestingDepth", func(t *testing.T) {
|
|
n := maxNestingDepth + 8
|
|
markdown := strings.Repeat("> ", n) + "x"
|
|
blocks := blockQuoteStart(markdown, 0, Range{0, len(markdown)}, 0)
|
|
require.NotEmpty(t, blocks)
|
|
|
|
counts := countBlocksByType(blocks)
|
|
assert.Equal(t, maxNestingDepth, counts["*markdown.BlockQuote"])
|
|
assert.Equal(t, 1, counts["*markdown.Paragraph"])
|
|
assert.IsType(t, &Paragraph{}, blocks[len(blocks)-1])
|
|
})
|
|
|
|
t.Run("nesting is capped relative to the depth already accrued by open ancestor blocks", func(t *testing.T) {
|
|
markdown := "> > > x"
|
|
blocks := blockQuoteStart(markdown, 0, Range{0, len(markdown)}, maxNestingDepth-2)
|
|
require.NotEmpty(t, blocks)
|
|
|
|
counts := countBlocksByType(blocks)
|
|
assert.Equal(t, 2, counts["*markdown.BlockQuote"])
|
|
assert.Equal(t, 1, counts["*markdown.Paragraph"])
|
|
})
|
|
}
|