summaryrefslogtreecommitdiffstats
path: root/hugolib/testhelpers_test.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-02-17 21:14:52 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-02-18 07:53:25 +0100
commit07ab7ae3d2e64dafb8f6dab937986d8e366d1fe5 (patch)
treee208621d1a05c6d1d288445ccaa051bf33fbc92b /hugolib/testhelpers_test.go
parented847ed93d86d0e1c0993adfee787e7fa02e604b (diff)
hugolib: More test helper cleanup
Diffstat (limited to 'hugolib/testhelpers_test.go')
-rw-r--r--hugolib/testhelpers_test.go31
1 files changed, 25 insertions, 6 deletions
diff --git a/hugolib/testhelpers_test.go b/hugolib/testhelpers_test.go
index 3c931ca48..668b46b1d 100644
--- a/hugolib/testhelpers_test.go
+++ b/hugolib/testhelpers_test.go
@@ -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)