Revert handlebars date tests to string match with local tz+offset

pull/268/head
Oliver Marriott 2 years ago
parent edb09ffe7d
commit 292321876b

@ -45,17 +45,6 @@ func testString(t *testing.T, template string, context interface{}, expected str
assert.Equal(t, actual, expected)
}
func testStringMatch(t *testing.T, template string, context interface{}, pattern string) {
sut := testLoader(LoaderOpts{})
templ, err := sut.LoadTemplate(template)
assert.Nil(t, err)
actual, err := templ.Render(context)
assert.Nil(t, err)
assert.Regexp(t, actual, pattern)
}
func testFile(t *testing.T, name string, context interface{}, expected string) {
sut := testLoader(LoaderOpts{})
@ -249,12 +238,13 @@ func TestDateHelper(t *testing.T) {
testString(t, "{{date now 'timestamp'}}", context, "200911172034")
testString(t, "{{date now 'timestamp-unix'}}", context, "1258490098")
testString(t, "{{date now 'cust: %Y-%m'}}", context, "cust: 2009-11")
testStringMatch(t, "{{date now 'elapsed'}}", context, `[\d]+ years ago`)
testString(t, "{{date now 'elapsed'}}", context, "14 years ago")
}
func TestGetDateHelper(t *testing.T) {
context := map[string]interface{}{"now": time.Date(2009, 11, 17, 20, 34, 58, 651387237, time.UTC)}
testStringMatch(t, "{{get-date \"2009-11-17T20:34:58\"}}", context, `2009-11-17 20:34:58 \+[\d]{4} [A-Z]+`)
localOffsetAndTZ := time.Now().Format("-0700 MST")
testString(t, "{{get-date \"2009-11-17T20:34:58\"}}", context, "2009-11-17 20:34:58 "+localOffsetAndTZ)
}
func TestShellHelper(t *testing.T) {

@ -3,7 +3,6 @@ package assert
import (
"encoding/json"
"reflect"
"regexp"
"strings"
"testing"
@ -62,20 +61,6 @@ func NotEqual(t *testing.T, actual, other interface{}) {
}
}
func Regexp(t *testing.T, actual, pattern string) {
rx := regexp.MustCompile(pattern)
if !(rx.MatchString(actual)) {
t.Errorf("Received (type %v):\n% #v", reflect.TypeOf(actual), pretty.Formatter(actual))
t.Errorf("\n---\n")
t.Errorf("But expected to match regexp:\n% #v", pretty.Formatter(pattern))
t.Errorf("\n---\n")
t.Errorf("Diff:\n")
for _, diff := range pretty.Diff(actual, pattern) {
t.Errorf("\t% #v", diff)
}
}
}
func toJSON(t *testing.T, obj interface{}) string {
json, err := json.Marshal(obj)
// json, err := json.MarshalIndent(obj, "", " ")

Loading…
Cancel
Save