From 42dec85db79ef0bd7b2faaa8878eea55e6fdbb01 Mon Sep 17 00:00:00 2001 From: Xavier Coulon Date: Tue, 29 Sep 2020 22:42:40 +0200 Subject: [PATCH] test(parser/renderer): verify special characters Verifies that special characters are properly handled in paragraphs and delimited blocks Fixes #708 Signed-off-by: Xavier Coulon --- pkg/parser/special_character_test.go | 117 ++++++++++++++++++ .../sgml/html5/special_character_test.go | 50 ++++++++ 2 files changed, 167 insertions(+) create mode 100644 pkg/parser/special_character_test.go create mode 100644 pkg/renderer/sgml/html5/special_character_test.go diff --git a/pkg/parser/special_character_test.go b/pkg/parser/special_character_test.go new file mode 100644 index 00000000..c1496f4a --- /dev/null +++ b/pkg/parser/special_character_test.go @@ -0,0 +1,117 @@ +package parser_test + +import ( + "github.com/bytesparadise/libasciidoc/pkg/types" + . "github.com/bytesparadise/libasciidoc/testsupport" + + . "github.com/onsi/ginkgo" //nolint golint + . "github.com/onsi/gomega" //nolint golint +) + +var _ = Describe("special characters", func() { + + It("should parse in paragraph", func() { + source := "* ' &" + expected := types.DraftDocument{ + Blocks: []interface{}{ + types.Paragraph{ + Lines: []interface{}{ + []interface{}{ + types.SpecialCharacter{ + Name: "<", + }, + types.StringElement{ + Content: "b", + }, + types.SpecialCharacter{ + Name: ">", + }, + types.StringElement{ + Content: "*", + }, + types.SpecialCharacter{ + Name: "<", + }, + types.StringElement{ + Content: "/b", + }, + types.SpecialCharacter{ + Name: ">", + }, + types.StringElement{ + Content: " ", + }, + types.SpecialCharacter{ + Name: "&", + }, + types.StringElement{ + Content: "apos; ", + }, + types.SpecialCharacter{ + Name: "&", + }, + types.StringElement{ + Content: "amp;", + }, + }, + }, + }, + }, + } + Expect(ParseDraftDocument(source)).To(MatchDraftDocument(expected)) + }) + + It("should parse in delimited block", func() { + source := "```" + "\n" + + "* ' &" + "\n" + + "```" + expected := types.DraftDocument{ + Blocks: []interface{}{ + types.DelimitedBlock{ + Kind: types.Fenced, + Elements: []interface{}{ + []interface{}{ + types.SpecialCharacter{ + Name: "<", + }, + types.StringElement{ + Content: "b", + }, + types.SpecialCharacter{ + Name: ">", + }, + types.StringElement{ + Content: "*", + }, + types.SpecialCharacter{ + Name: "<", + }, + types.StringElement{ + Content: "/b", + }, + types.SpecialCharacter{ + Name: ">", + }, + types.StringElement{ + Content: " ", + }, + types.SpecialCharacter{ + Name: "&", + }, + types.StringElement{ + Content: "apos; ", + }, + types.SpecialCharacter{ + Name: "&", + }, + types.StringElement{ + Content: "amp;", + }, + }, + }, + }, + }, + } + Expect(ParseDraftDocument(source)).To(MatchDraftDocument(expected)) + }) +}) diff --git a/pkg/renderer/sgml/html5/special_character_test.go b/pkg/renderer/sgml/html5/special_character_test.go new file mode 100644 index 00000000..36682180 --- /dev/null +++ b/pkg/renderer/sgml/html5/special_character_test.go @@ -0,0 +1,50 @@ +package html5_test + +import ( + . "github.com/bytesparadise/libasciidoc/testsupport" + + . "github.com/onsi/ginkgo" //nolint golint + . "github.com/onsi/gomega" //nolint golint +) + +var _ = Describe("special characters", func() { + + It("should parse in paragraph", func() { + source := "* ' &" + expected := `
+

<b>*</b> &apos; &amp;

+
+` + Expect(RenderHTML(source)).To(MatchHTML(expected)) + }) + + It("should parse in delimited block", func() { + source := "```" + "\n" + + "* ' &" + "\n" + + "```" + expected := `
+
+
<b>*</b> &apos; &amp;
+
+
+` + Expect(RenderHTML(source)).To(MatchHTML(expected)) + }) + + It("should parse in paragraph and delimited block", func() { + source := "* ' &" + "\n\n" + + "```" + "\n" + + "* ' &" + "\n" + + "```" + expected := `
+

<b>*</b> &apos; &amp;

+
+
+
+
<b>*</b> &apos; &amp;
+
+
+` + Expect(RenderHTML(source)).To(MatchHTML(expected)) + }) +})