shithub: hugo

Download patch

ref: 3717db1f90797f4e2a5d546472fb6b6df072d435
parent: ae4fde0866b2a10f0a414e0d76c4ff09bed3776e
author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
date: Sun Nov 3 06:34:22 EST 2019

minifiers: Add a JSON roundtrip test

See #6472

--- a/minifiers/minifiers_test.go
+++ b/minifiers/minifiers_test.go
@@ -15,6 +15,7 @@
 
 import (
 	"bytes"
+	"encoding/json"
 	"strings"
 	"testing"
 
@@ -68,6 +69,44 @@
 
 		c.Assert(m.Minify(test.tp, &b, strings.NewReader(test.rawString)), qt.IsNil)
 		c.Assert(b.String(), qt.Equals, test.expectedMinString)
+	}
+
+}
+
+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)
 	}
 
 }