mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	Refactor renders (#15175)
* Refactor renders * Some performance optimization * Fix comment * Transform reader * Fix csv test * Fix test * Fix tests * Improve optimaziation * Fix test * Fix test * Detect file encoding with reader * Improve optimaziation * reduce memory usage * improve code * fix build * Fix test * Fix for go1.15 * Fix render * Fix comment * Fix lint * Fix test * Don't use NormalEOF when unnecessary * revert change on util.go * Apply suggestions from code review Co-authored-by: zeripath <art27@cantab.net> * rename function * Take NormalEOF back Co-authored-by: zeripath <art27@cantab.net>
This commit is contained in:
		
							
								
								
									
										62
									
								
								modules/markup/renderer_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										62
									
								
								modules/markup/renderer_test.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,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]))
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user