2017-04-21 12:31:08 +05:30
|
|
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
2022-11-27 23:50:29 +05:30
|
|
|
// SPDX-License-Identifier: MIT
|
2017-04-21 12:31:08 +05:30
|
|
|
|
2017-09-16 22:47:57 +05:30
|
|
|
package markup_test
|
2017-04-21 12:31:08 +05:30
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2017-09-16 22:47:57 +05:30
|
|
|
. "code.gitea.io/gitea/modules/markup"
|
2021-11-17 18:04:35 +05:30
|
|
|
|
2017-09-21 10:50:14 +05:30
|
|
|
_ "code.gitea.io/gitea/modules/markup/markdown"
|
2017-09-16 22:47:57 +05:30
|
|
|
|
2017-04-21 12:31:08 +05:30
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMisc_IsReadmeFile(t *testing.T) {
|
|
|
|
trueTestCases := []string{
|
|
|
|
"readme",
|
|
|
|
"README",
|
|
|
|
"readME.mdown",
|
|
|
|
"README.md",
|
2019-01-15 00:45:06 +05:30
|
|
|
"readme.i18n.md",
|
2017-04-21 12:31:08 +05:30
|
|
|
}
|
|
|
|
falseTestCases := []string{
|
|
|
|
"test.md",
|
|
|
|
"wow.MARKDOWN",
|
|
|
|
"LOL.mDoWn",
|
|
|
|
"test",
|
|
|
|
"abcdefg",
|
|
|
|
"abcdefghijklmnopqrstuvwxyz",
|
|
|
|
"test.md.test",
|
2017-05-09 19:50:22 +05:30
|
|
|
"readmf",
|
2017-04-21 12:31:08 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
for _, testCase := range trueTestCases {
|
|
|
|
assert.True(t, IsReadmeFile(testCase))
|
|
|
|
}
|
|
|
|
for _, testCase := range falseTestCases {
|
|
|
|
assert.False(t, IsReadmeFile(testCase))
|
|
|
|
}
|
2019-01-15 00:45:06 +05:30
|
|
|
|
2022-08-01 04:06:58 +05:30
|
|
|
type extensionTestcase struct {
|
|
|
|
name string
|
|
|
|
expected bool
|
|
|
|
idx int
|
2019-01-15 00:45:06 +05:30
|
|
|
}
|
|
|
|
|
2022-08-01 04:06:58 +05:30
|
|
|
exts := []string{".md", ".txt", ""}
|
|
|
|
testCasesExtensions := []extensionTestcase{
|
|
|
|
{
|
|
|
|
name: "readme",
|
|
|
|
expected: true,
|
|
|
|
idx: 2,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "readme.md",
|
|
|
|
expected: true,
|
|
|
|
idx: 0,
|
|
|
|
},
|
2022-08-01 17:45:40 +05:30
|
|
|
{
|
|
|
|
name: "README.md",
|
|
|
|
expected: true,
|
|
|
|
idx: 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "ReAdMe.Md",
|
|
|
|
expected: true,
|
|
|
|
idx: 0,
|
|
|
|
},
|
2022-08-01 04:06:58 +05:30
|
|
|
{
|
|
|
|
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-15 00:45:06 +05:30
|
|
|
}
|
2022-08-01 04:06:58 +05:30
|
|
|
|
|
|
|
for _, testCase := range testCasesExtensions {
|
|
|
|
idx, ok := IsReadmeFileExtension(testCase.name, exts...)
|
|
|
|
assert.Equal(t, testCase.expected, ok)
|
|
|
|
assert.Equal(t, testCase.idx, idx)
|
2019-01-15 00:45:06 +05:30
|
|
|
}
|
2017-04-21 12:31:08 +05:30
|
|
|
}
|