From 8ffb773f43c8dc54801ca1d111854e7e881c93c9 Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Sun, 19 Nov 2017 21:10:04 -0800 Subject: First commit --- vendor/github.com/tdewolff/parse/xml/util_test.go | 63 +++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 vendor/github.com/tdewolff/parse/xml/util_test.go (limited to 'vendor/github.com/tdewolff/parse/xml/util_test.go') diff --git a/vendor/github.com/tdewolff/parse/xml/util_test.go b/vendor/github.com/tdewolff/parse/xml/util_test.go new file mode 100644 index 0000000..65be6b8 --- /dev/null +++ b/vendor/github.com/tdewolff/parse/xml/util_test.go @@ -0,0 +1,63 @@ +package xml // import "github.com/tdewolff/parse/xml" + +import ( + "testing" + + "github.com/tdewolff/test" +) + +func TestEscapeAttrVal(t *testing.T) { + var attrValTests = []struct { + attrVal string + expected string + }{ + {"xyz", "\"xyz\""}, + {"", "\"\""}, + {"x&z", "\"x&z\""}, + {"x'z", "\"x'z\""}, + {"x\"z", "'x\"z'"}, + {"a'b=\"\"", "'a'b=\"\"'"}, + {"'x'\"'z'", "\"x'"'z\""}, + {"\"x"'"z\"", "'x\"'\"z'"}, + {"a'b=\"\"", "'a'b=\"\"'"}, + } + var buf []byte + for _, tt := range attrValTests { + t.Run(tt.attrVal, func(t *testing.T) { + b := []byte(tt.attrVal) + if len(b) > 1 && (b[0] == '"' || b[0] == '\'') && b[0] == b[len(b)-1] { + b = b[1 : len(b)-1] + } + val := EscapeAttrVal(&buf, []byte(b)) + test.String(t, string(val), tt.expected) + }) + } +} + +func TestEscapeCDATAVal(t *testing.T) { + var CDATAValTests = []struct { + CDATAVal string + expected string + }{ + {"]]>", "<b>"}, + {"", "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"}, + {" ]]>", " <b> "}, + {"", ""}, + {"", "&"}, + {"", ""}, + {"", " a "}, + {"", ""}, + } + var buf []byte + for _, tt := range CDATAValTests { + t.Run(tt.CDATAVal, func(t *testing.T) { + b := []byte(tt.CDATAVal[len("")]) + data, useText := EscapeCDATAVal(&buf, b) + text := string(data) + if !useText { + text = "" + } + test.String(t, text, tt.expected) + }) + } +} -- cgit v1.2.3