2017-04-21 07:01:08 +00:00
|
|
|
// 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.
|
|
|
|
|
2017-09-16 17:17:57 +00:00
|
|
|
package markup_test
|
2017-04-21 07:01:08 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2017-09-16 17:17:57 +00:00
|
|
|
. "code.gitea.io/gitea/modules/markup"
|
2021-11-17 12:34:35 +00:00
|
|
|
|
2017-09-21 05:20:14 +00:00
|
|
|
_ "code.gitea.io/gitea/modules/markup/markdown"
|
2017-09-16 17:17:57 +00:00
|
|
|
|
2017-04-21 07:01:08 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMisc_IsReadmeFile(t *testing.T) {
|
|
|
|
trueTestCases := []string{
|
|
|
|
"readme",
|
|
|
|
"README",
|
|
|
|
"readME.mdown",
|
|
|
|
"README.md",
|
2019-01-14 19:15:06 +00:00
|
|
|
"readme.i18n.md",
|
2017-04-21 07:01:08 +00:00
|
|
|
}
|
|
|
|
falseTestCases := []string{
|
|
|
|
"test.md",
|
|
|
|
"wow.MARKDOWN",
|
|
|
|
"LOL.mDoWn",
|
|
|
|
"test",
|
|
|
|
"abcdefg",
|
|
|
|
"abcdefghijklmnopqrstuvwxyz",
|
|
|
|
"test.md.test",
|
2017-05-09 14:20:22 +00:00
|
|
|
"readmf",
|
2017-04-21 07:01:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, testCase := range trueTestCases {
|
|
|
|
assert.True(t, IsReadmeFile(testCase))
|
|
|
|
}
|
|
|
|
for _, testCase := range falseTestCases {
|
|
|
|
assert.False(t, IsReadmeFile(testCase))
|
|
|
|
}
|
2019-01-14 19:15:06 +00:00
|
|
|
|
2022-07-31 22:36:58 +00:00
|
|
|
type extensionTestcase struct {
|
|
|
|
name string
|
|
|
|
expected bool
|
|
|
|
idx int
|
2019-01-14 19:15:06 +00:00
|
|
|
}
|
|
|
|
|
2022-07-31 22:36:58 +00:00
|
|
|
exts := []string{".md", ".txt", ""}
|
|
|
|
testCasesExtensions := []extensionTestcase{
|
|
|
|
{
|
|
|
|
name: "readme",
|
|
|
|
expected: true,
|
|
|
|
idx: 2,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "readme.md",
|
|
|
|
expected: true,
|
|
|
|
idx: 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "readme.txt",
|
|
|
|
expected: true,
|
|
|
|
idx: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "readme.doc",
|
|
|
|
expected: true,
|
|
|
|
idx: 3,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "readmee.md",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "readme..",
|
|
|
|
expected: true,
|
|
|
|
idx: 3,
|
|
|
|
},
|
2019-01-14 19:15:06 +00:00
|
|
|
}
|
2022-07-31 22:36:58 +00:00
|
|
|
|
|
|
|
for _, testCase := range testCasesExtensions {
|
|
|
|
idx, ok := IsReadmeFileExtension(testCase.name, exts...)
|
|
|
|
assert.Equal(t, testCase.expected, ok)
|
|
|
|
assert.Equal(t, testCase.idx, idx)
|
2019-01-14 19:15:06 +00:00
|
|
|
}
|
2017-04-21 07:01:08 +00:00
|
|
|
}
|