mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-19 21:21:39 +02:00
Fix failing shortcode tests on Travis
Some newly added shortcode tests compared maps in assertions. This failed on Travis, as iteration order isn't guaranteed for maps since Go 1. This commit fixes that by do a sort of the keys in the shortcode String() function.
This commit is contained in:
@@ -21,6 +21,7 @@ import (
|
||||
"html/template"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
@@ -90,7 +91,28 @@ type shortcode struct {
|
||||
|
||||
func (sc shortcode) String() string {
|
||||
// for testing (mostly), so any change here will break tests!
|
||||
return fmt.Sprintf("%s(%q, %t){%s}", sc.name, sc.params, sc.doMarkup, sc.inner)
|
||||
var params interface{}
|
||||
switch v := sc.params.(type) {
|
||||
case map[string]string:
|
||||
// sort the keys so test assertions won't fail
|
||||
var keys []string
|
||||
for k := range v {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
var tmp = make([]string, len(keys))
|
||||
|
||||
for i, k := range keys {
|
||||
tmp[i] = k + ":" + v[k]
|
||||
}
|
||||
params = tmp
|
||||
|
||||
default:
|
||||
// use it as is
|
||||
params = sc.params
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%s(%q, %t){%s}", sc.name, params, sc.doMarkup, sc.inner)
|
||||
}
|
||||
|
||||
// all in one go: extract, render and replace
|
||||
|
Reference in New Issue
Block a user