mirror of
https://github.com/gohugoio/hugo.git
synced 2024-12-01 18:22:58 -05:00
Fix the time template func test
By making it not depend on the locale setup.
This commit is contained in:
parent
70544f9e62
commit
93f3a85bf8
3 changed files with 32 additions and 27 deletions
|
@ -467,3 +467,27 @@ func NormalizeHugoFlags(f *pflag.FlagSet, name string) pflag.NormalizedName {
|
||||||
}
|
}
|
||||||
return pflag.NormalizedName(name)
|
return pflag.NormalizedName(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DiffStringSlices returns the difference between two string slices.
|
||||||
|
// Useful in tests.
|
||||||
|
// See:
|
||||||
|
// http://stackoverflow.com/questions/19374219/how-to-find-the-difference-between-two-slices-of-strings-in-golang
|
||||||
|
func DiffStringSlices(slice1 []string, slice2 []string) []string {
|
||||||
|
diffStr := []string{}
|
||||||
|
m := map[string]int{}
|
||||||
|
|
||||||
|
for _, s1Val := range slice1 {
|
||||||
|
m[s1Val] = 1
|
||||||
|
}
|
||||||
|
for _, s2Val := range slice2 {
|
||||||
|
m[s2Val] = m[s2Val] + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
for mKey, mVal := range m {
|
||||||
|
if mVal == 1 {
|
||||||
|
diffStr = append(diffStr, mKey)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return diffStr
|
||||||
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ func checkShowPlanExpected(t *testing.T, s *Site, expected string) {
|
||||||
gotList := strings.Split(got, "\n")
|
gotList := strings.Split(got, "\n")
|
||||||
expectedList := strings.Split(expected, "\n")
|
expectedList := strings.Split(expected, "\n")
|
||||||
|
|
||||||
diff := DiffStringSlices(gotList, expectedList)
|
diff := helpers.DiffStringSlices(gotList, expectedList)
|
||||||
|
|
||||||
if len(diff) > 0 {
|
if len(diff) > 0 {
|
||||||
t.Errorf("Got diff in show plan: %s", diff)
|
t.Errorf("Got diff in show plan: %s", diff)
|
||||||
|
@ -146,26 +146,3 @@ func TestFileTargetPublishDir(t *testing.T) {
|
||||||
"section/somecontent.html (renderer: n/a)\n canonical => ../public/section/somecontent/index.html\n\n"
|
"section/somecontent.html (renderer: n/a)\n canonical => ../public/section/somecontent/index.html\n\n"
|
||||||
checkShowPlanExpected(t, s, expected)
|
checkShowPlanExpected(t, s, expected)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DiffStringSlices returns the difference between two string slices.
|
|
||||||
// See:
|
|
||||||
// http://stackoverflow.com/questions/19374219/how-to-find-the-difference-between-two-slices-of-strings-in-golang
|
|
||||||
func DiffStringSlices(slice1 []string, slice2 []string) []string {
|
|
||||||
diffStr := []string{}
|
|
||||||
m := map[string]int{}
|
|
||||||
|
|
||||||
for _, s1Val := range slice1 {
|
|
||||||
m[s1Val] = 1
|
|
||||||
}
|
|
||||||
for _, s2Val := range slice2 {
|
|
||||||
m[s2Val] = m[s2Val] + 1
|
|
||||||
}
|
|
||||||
|
|
||||||
for mKey, mVal := range m {
|
|
||||||
if mVal == 1 {
|
|
||||||
diffStr = append(diffStr, mKey)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return diffStr
|
|
||||||
}
|
|
||||||
|
|
|
@ -28,6 +28,8 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/spf13/hugo/helpers"
|
||||||
|
|
||||||
"github.com/spf13/afero"
|
"github.com/spf13/afero"
|
||||||
"github.com/spf13/cast"
|
"github.com/spf13/cast"
|
||||||
"github.com/spf13/hugo/hugofs"
|
"github.com/spf13/hugo/hugofs"
|
||||||
|
@ -136,7 +138,7 @@ sub: {{sub 3 2}}
|
||||||
substr: {{substr "BatMan" 0 -3}}
|
substr: {{substr "BatMan" 0 -3}}
|
||||||
substr: {{substr "BatMan" 3 3}}
|
substr: {{substr "BatMan" 3 3}}
|
||||||
title: {{title "Bat man"}}
|
title: {{title "Bat man"}}
|
||||||
time: {{ time "2015-01-21" }}
|
time: {{ (time "2015-01-21").Year }}
|
||||||
trim: {{ trim "++Batman--" "+-" }}
|
trim: {{ trim "++Batman--" "+-" }}
|
||||||
upper: {{upper "BatMan"}}
|
upper: {{upper "BatMan"}}
|
||||||
urlize: {{ "Bat Man" | urlize }}
|
urlize: {{ "Bat Man" | urlize }}
|
||||||
|
@ -200,7 +202,7 @@ sub: 1
|
||||||
substr: Bat
|
substr: Bat
|
||||||
substr: Man
|
substr: Man
|
||||||
title: Bat Man
|
title: Bat Man
|
||||||
time: 2015-01-21T00:00:00Z
|
time: 2015
|
||||||
trim: Batman
|
trim: Batman
|
||||||
upper: BATMAN
|
upper: BATMAN
|
||||||
urlize: bat-man
|
urlize: bat-man
|
||||||
|
@ -229,7 +231,9 @@ urlize: bat-man
|
||||||
}
|
}
|
||||||
|
|
||||||
if b.String() != expected {
|
if b.String() != expected {
|
||||||
t.Errorf("Got\n%q\nExpected\n%q", b.String(), expected)
|
sl1 := strings.Split(b.String(), "\n")
|
||||||
|
sl2 := strings.Split(expected, "\n")
|
||||||
|
t.Errorf("Diff:\n%q", helpers.DiffStringSlices(sl1, sl2))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue