summaryrefslogtreecommitdiffstats
path: root/modules/markup/renderer_test.go
blob: 118fa2632ba5829368b105d748b54ea6636239e2 (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
55
56
57
58
59
60
61
62
// Copyright 2017 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package markup_test

import (
	"testing"

	. "code.gitea.io/gitea/modules/markup"
	_ "code.gitea.io/gitea/modules/markup/markdown"

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

func TestMisc_IsReadmeFile(t *testing.T) {
	trueTestCases := []string{
		"readme",
		"README",
		"readME.mdown",
		"README.md",
		"readme.i18n.md",
	}
	falseTestCases := []string{
		"test.md",
		"wow.MARKDOWN",
		"LOL.mDoWn",
		"test",
		"abcdefg",
		"abcdefghijklmnopqrstuvwxyz",
		"test.md.test",
		"readmf",
	}

	for _, testCase := range trueTestCases {
		assert.True(t, IsReadmeFile(testCase))
	}
	for _, testCase := range falseTestCases {
		assert.False(t, IsReadmeFile(testCase))
	}

	trueTestCasesStrict := [][]string{
		{"readme", ""},
		{"readme.md", ".md"},
		{"readme.txt", ".txt"},
	}
	falseTestCasesStrict := [][]string{
		{"readme", ".md"},
		{"readme.md", ""},
		{"readme.md", ".txt"},
		{"readme.md", "md"},
		{"readmee.md", ".md"},
		{"readme.i18n.md", ".md"},
	}

	for _, testCase := range trueTestCasesStrict {
		assert.True(t, IsReadmeFile(testCase[0], testCase[1]))
	}
	for _, testCase := range falseTestCasesStrict {
		assert.False(t, IsReadmeFile(testCase[0], testCase[1]))
	}
}