summaryrefslogtreecommitdiffstats
path: root/modules/util/path_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/util/path_test.go')
-rw-r--r--modules/util/path_test.go81
1 files changed, 81 insertions, 0 deletions
diff --git a/modules/util/path_test.go b/modules/util/path_test.go
index 5794df1ebf..93f4f67cf6 100644
--- a/modules/util/path_test.go
+++ b/modules/util/path_test.go
@@ -55,3 +55,84 @@ func TestFileURLToPath(t *testing.T) {
}
}
}
+
+func TestMisc_IsReadmeFileName(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, IsReadmeFileName(testCase))
+ }
+ for _, testCase := range falseTestCases {
+ assert.False(t, IsReadmeFileName(testCase))
+ }
+
+ type extensionTestcase struct {
+ name string
+ expected bool
+ idx int
+ }
+
+ exts := []string{".md", ".txt", ""}
+ testCasesExtensions := []extensionTestcase{
+ {
+ name: "readme",
+ expected: true,
+ idx: 2,
+ },
+ {
+ name: "readme.md",
+ expected: true,
+ idx: 0,
+ },
+ {
+ name: "README.md",
+ expected: true,
+ idx: 0,
+ },
+ {
+ 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,
+ },
+ }
+
+ for _, testCase := range testCasesExtensions {
+ idx, ok := IsReadmeFileExtension(testCase.name, exts...)
+ assert.Equal(t, testCase.expected, ok)
+ assert.Equal(t, testCase.idx, idx)
+ }
+}