mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-29 10:57:44 +09:00 
			
		
		
		
	Move IsReadmeFile* from modules/markup/ to modules/util (#22877)
				
					
				
			These functions don't examine contents, just filenames, so they don't fit in well in a markup module. This was originally part of https://github.com/go-gitea/gitea/pull/22177. Signed-off-by: Nick Guenther <nick.guenther@polymtl.ca>
This commit is contained in:
		| @@ -2,94 +2,3 @@ | ||||
| // SPDX-License-Identifier: MIT | ||||
|  | ||||
| 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)) | ||||
| 	} | ||||
|  | ||||
| 	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) | ||||
| 	} | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user