mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-23 21:53:09 +02:00
hugolib: More test helper cleanup
This commit is contained in:
@@ -33,25 +33,44 @@ type testHelper struct {
|
||||
T testing.TB
|
||||
}
|
||||
|
||||
func (th testHelper) assertFileContent(filename string, defaultInSubDir bool, matches ...string) {
|
||||
filename = th.replaceDefaultContentLanguageValue(filename, defaultInSubDir)
|
||||
func (th testHelper) assertFileContent(filename string, matches ...string) {
|
||||
filename = th.replaceDefaultContentLanguageValue(filename)
|
||||
content := readDestination(th.T, th.Fs, filename)
|
||||
for _, match := range matches {
|
||||
match = th.replaceDefaultContentLanguageValue(match, defaultInSubDir)
|
||||
match = th.replaceDefaultContentLanguageValue(match)
|
||||
require.True(th.T, strings.Contains(content, match), fmt.Sprintf("File no match for\n%q in\n%q:\n%s", strings.Replace(match, "%", "%%", -1), filename, strings.Replace(content, "%", "%%", -1)))
|
||||
}
|
||||
}
|
||||
|
||||
func (th testHelper) assertFileContentRegexp(filename string, defaultInSubDir bool, matches ...string) {
|
||||
filename = th.replaceDefaultContentLanguageValue(filename, defaultInSubDir)
|
||||
// TODO(bep) better name for this. It does no magic replacements depending on defaultontentLanguageInSubDir.
|
||||
func (th testHelper) assertFileContentStraight(filename string, matches ...string) {
|
||||
content := readDestination(th.T, th.Fs, filename)
|
||||
for _, match := range matches {
|
||||
match = th.replaceDefaultContentLanguageValue(match, defaultInSubDir)
|
||||
require.True(th.T, strings.Contains(content, match), fmt.Sprintf("File no match for\n%q in\n%q:\n%s", strings.Replace(match, "%", "%%", -1), filename, strings.Replace(content, "%", "%%", -1)))
|
||||
}
|
||||
}
|
||||
|
||||
func (th testHelper) assertFileContentRegexp(filename string, matches ...string) {
|
||||
filename = th.replaceDefaultContentLanguageValue(filename)
|
||||
content := readDestination(th.T, th.Fs, filename)
|
||||
for _, match := range matches {
|
||||
match = th.replaceDefaultContentLanguageValue(match)
|
||||
r := regexp.MustCompile(match)
|
||||
require.True(th.T, r.MatchString(content), fmt.Sprintf("File no match for\n%q in\n%q:\n%s", strings.Replace(match, "%", "%%", -1), filename, strings.Replace(content, "%", "%%", -1)))
|
||||
}
|
||||
}
|
||||
|
||||
func (th testHelper) replaceDefaultContentLanguageValue(value string) string {
|
||||
defaultInSubDir := th.Cfg.GetBool("defaultContentLanguageInSubDir")
|
||||
replace := th.Cfg.GetString("defaultContentLanguage") + "/"
|
||||
|
||||
if !defaultInSubDir {
|
||||
value = strings.Replace(value, replace, "", 1)
|
||||
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
func newTestPathSpec(fs *hugofs.Fs, v *viper.Viper) *helpers.PathSpec {
|
||||
l := helpers.NewDefaultLanguage(v)
|
||||
return helpers.NewPathSpec(fs, l)
|
||||
|
Reference in New Issue
Block a user