summaryrefslogtreecommitdiffstats
path: root/hugolib/shortcode.go
diff options
context:
space:
mode:
authorbep <bjorn.erik.pedersen@gmail.com>2014-11-18 10:20:52 +0100
committerspf13 <steve.francia@gmail.com>2014-11-18 10:14:12 -0500
commita6a9df395566f53a1b3aecbf65a2067ec0ea1b12 (patch)
treef749dfac4571a7b5b66a8c2dceff08fee8bc50ab /hugolib/shortcode.go
parent596d67938668126d49cde7b00dc9f345f0f5032e (diff)
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.
Diffstat (limited to 'hugolib/shortcode.go')
-rw-r--r--hugolib/shortcode.go24
1 files changed, 23 insertions, 1 deletions
diff --git a/hugolib/shortcode.go b/hugolib/shortcode.go
index 6dfc4ef02..f90093e7a 100644
--- a/hugolib/shortcode.go
+++ b/hugolib/shortcode.go
@@ -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