aboutsummaryrefslogtreecommitdiffhomepage
path: root/minifiers
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2019-11-03 11:34:22 +0100
committerBjørn Erik Pedersen <[email protected]>2019-11-03 11:34:22 +0100
commit3717db1f90797f4e2a5d546472fb6b6df072d435 (patch)
tree7533896a28b3ba33ecae4f8cf87028c3c0e649e5 /minifiers
parentae4fde0866b2a10f0a414e0d76c4ff09bed3776e (diff)
downloadhugo-3717db1f90797f4e2a5d546472fb6b6df072d435.tar.gz
hugo-3717db1f90797f4e2a5d546472fb6b6df072d435.zip
minifiers: Add a JSON roundtrip test
See #6472
Diffstat (limited to 'minifiers')
-rw-r--r--minifiers/minifiers_test.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/minifiers/minifiers_test.go b/minifiers/minifiers_test.go
index d88dab881..87e706320 100644
--- a/minifiers/minifiers_test.go
+++ b/minifiers/minifiers_test.go
@@ -15,6 +15,7 @@ package minifiers
import (
"bytes"
+ "encoding/json"
"strings"
"testing"
@@ -72,6 +73,44 @@ func TestNew(t *testing.T) {
}
+func TestJSONRoundTrip(t *testing.T) {
+ c := qt.New(t)
+ m := New(media.DefaultTypes, output.DefaultFormats)
+
+ for _, test := range []string{`{
+ "glossary": {
+ "title": "example glossary",
+ "GlossDiv": {
+ "title": "S",
+ "GlossList": {
+ "GlossEntry": {
+ "ID": "SGML",
+ "SortAs": "SGML",
+ "GlossTerm": "Standard Generalized Markup Language",
+ "Acronym": "SGML",
+ "Abbrev": "ISO 8879:1986",
+ "GlossDef": {
+ "para": "A meta-markup language, used to create markup languages such as DocBook.",
+ "GlossSeeAlso": ["GML", "XML"]
+ },
+ "GlossSee": "markup"
+ }
+ }
+ }
+ }
+}`} {
+
+ var b bytes.Buffer
+ m1 := make(map[string]interface{})
+ m2 := make(map[string]interface{})
+ c.Assert(json.Unmarshal([]byte(test), &m1), qt.IsNil)
+ c.Assert(m.Minify(media.JSONType, &b, strings.NewReader(test)), qt.IsNil)
+ c.Assert(json.Unmarshal(b.Bytes(), &m2), qt.IsNil)
+ c.Assert(m1, qt.DeepEquals, m2)
+ }
+
+}
+
func TestBugs(t *testing.T) {
c := qt.New(t)
m := New(media.DefaultTypes, output.DefaultFormats)