-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(parser/renderer): verify special characters support (#758)
Verifies that special characters are properly handled in paragraphs and delimited blocks Fixes #751 Signed-off-by: Xavier Coulon <[email protected]>
- Loading branch information
Showing
2 changed files
with
167 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 := "<b>*</b> ' &" | ||
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" + | ||
"<b>*</b> ' &" + "\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)) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 := "<b>*</b> ' &" | ||
expected := `<div class="paragraph"> | ||
<p><b>*</b> &apos; &amp;</p> | ||
</div> | ||
` | ||
Expect(RenderHTML(source)).To(MatchHTML(expected)) | ||
}) | ||
|
||
It("should parse in delimited block", func() { | ||
source := "```" + "\n" + | ||
"<b>*</b> ' &" + "\n" + | ||
"```" | ||
expected := `<div class="listingblock"> | ||
<div class="content"> | ||
<pre class="highlight"><code><b>*</b> &apos; &amp;</code></pre> | ||
</div> | ||
</div> | ||
` | ||
Expect(RenderHTML(source)).To(MatchHTML(expected)) | ||
}) | ||
|
||
It("should parse in paragraph and delimited block", func() { | ||
source := "<b>*</b> ' &" + "\n\n" + | ||
"```" + "\n" + | ||
"<b>*</b> ' &" + "\n" + | ||
"```" | ||
expected := `<div class="paragraph"> | ||
<p><b>*</b> &apos; &amp;</p> | ||
</div> | ||
<div class="listingblock"> | ||
<div class="content"> | ||
<pre class="highlight"><code><b>*</b> &apos; &amp;</code></pre> | ||
</div> | ||
</div> | ||
` | ||
Expect(RenderHTML(source)).To(MatchHTML(expected)) | ||
}) | ||
}) |