mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
parent
6b8422bb35
commit
4e5b4ac504
2 changed files with 35 additions and 1 deletions
|
@ -1446,6 +1446,17 @@ func chomp(text interface{}) (template.HTML, error) {
|
|||
return template.HTML(strings.TrimRight(s, "\r\n")), nil
|
||||
}
|
||||
|
||||
// lower returns a copy of the input s with all Unicode letters mapped to their
|
||||
// lower case.
|
||||
func lower(s interface{}) (string, error) {
|
||||
ss, err := cast.ToStringE(s)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return strings.ToLower(ss), nil
|
||||
}
|
||||
|
||||
// trim leading/trailing characters defined by b from a
|
||||
func trim(a interface{}, b string) (string, error) {
|
||||
aStr, err := cast.ToStringE(a)
|
||||
|
@ -2090,7 +2101,7 @@ func initFuncMap() {
|
|||
"jsonify": jsonify,
|
||||
"last": last,
|
||||
"le": le,
|
||||
"lower": func(a string) string { return strings.ToLower(a) },
|
||||
"lower": lower,
|
||||
"lt": lt,
|
||||
"markdownify": markdownify,
|
||||
"md5": md5,
|
||||
|
|
|
@ -1999,6 +1999,29 @@ func TestChomp(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestLower(t *testing.T) {
|
||||
cases := []struct {
|
||||
s interface{}
|
||||
want string
|
||||
isErr bool
|
||||
}{
|
||||
{"TEST", "test", false},
|
||||
{template.HTML("LoWeR"), "lower", false},
|
||||
{[]byte("BYTES"), "bytes", false},
|
||||
}
|
||||
|
||||
for i, c := range cases {
|
||||
res, err := lower(c.s)
|
||||
if (err != nil) != c.isErr {
|
||||
t.Fatalf("[%d] unexpected isErr state: want %v, got %v, err = %v", i, c.want, (err != nil), err)
|
||||
}
|
||||
|
||||
if res != c.want {
|
||||
t.Errorf("[%d] lower failed: want %v, got %v", i, c.want, res)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestHighlight(t *testing.T) {
|
||||
code := "func boo() {}"
|
||||
highlighted, err := highlight(code, "go", "")
|
||||
|
|
Loading…
Reference in a new issue