Skip to content

Commit

Permalink
test(parser/renderer): verify quoted text role with specoal chars
Browse files Browse the repository at this point in the history
issue was fixed by bytesparadise#755, verifying it here

Fixes bytesparadise#748

Signed-off-by: Xavier Coulon <[email protected]>
  • Loading branch information
xcoulon committed Sep 28, 2020
1 parent 2179d24 commit 856c40a
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 74 deletions.
186 changes: 112 additions & 74 deletions pkg/parser/quoted_text_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ var _ = Describe("quoted texts", func() {
})
})

Context("Quoted text with double punctuation", func() {
Context("quoted text with double punctuation", func() {

It("bold text of 1 word in double quote", func() {
source := "**hello**"
Expand Down Expand Up @@ -637,7 +637,7 @@ var _ = Describe("quoted texts", func() {
})
})

Context("Quoted text inline", func() {
Context("quoted text inline", func() {

It("inline content with bold text", func() {
source := "a paragraph with *some bold content*"
Expand Down Expand Up @@ -1133,6 +1133,44 @@ var _ = Describe("quoted texts", func() {
Expect(ParseDraftDocument(source)).To(MatchDraftDocument(expected))
})

It("short-hand role with special characters", func() {
source := "[\"a <role>\"]**bold**"
expected := types.DraftDocument{
Blocks: []interface{}{
types.Paragraph{
Lines: []interface{}{
[]interface{}{
types.QuotedText{
Kind: types.Bold,
Attributes: types.Attributes{
types.AttrRole: types.ElementRole{
types.StringElement{
Content: "a ",
},
// wrapping quotes are not preserved
types.SpecialCharacter{
Name: "<",
},
types.StringElement{
Content: "role",
},
types.SpecialCharacter{
Name: ">",
},
},
},
Elements: []interface{}{
types.StringElement{Content: "bold"},
},
},
},
},
},
},
}
Expect(ParseDraftDocument(source)).To(MatchDraftDocument(expected))
})

It("marked short-hand role only", func() {
source := "[.bob]##the builder##"
expected := types.DraftDocument{
Expand Down Expand Up @@ -3794,7 +3832,7 @@ var _ = Describe("quoted texts", func() {

})

Context("Quoted text with double punctuation", func() {
Context("quoted text with double punctuation", func() {

It("bold text of 1 word in double quote", func() {
source := "**hello**"
Expand Down Expand Up @@ -4022,7 +4060,7 @@ var _ = Describe("quoted texts", func() {

})

Context("Quoted text inline", func() {
Context("quoted text inline", func() {

It("inline content with bold text", func() {
source := "a paragraph with *some bold content*"
Expand Down Expand Up @@ -6090,29 +6128,29 @@ var _ = Describe("quoted texts", func() {
})
})
})
})

Context("final document", func() {
Context("nested images", func() {

It("image in bold", func() {
source := "*a image:foo.png[]*"
expected := types.Document{
Elements: []interface{}{
types.Paragraph{
Lines: []interface{}{
[]interface{}{
types.QuotedText{
Kind: types.Bold,
Elements: []interface{}{
types.StringElement{Content: "a "},
types.InlineImage{
Attributes: types.Attributes{
types.AttrImageAlt: "foo",
},
Location: types.Location{
Path: []interface{}{
types.StringElement{
Content: "foo.png",
It("image in bold", func() {
source := "*a image:foo.png[]*"
expected := types.Document{
Elements: []interface{}{
types.Paragraph{
Lines: []interface{}{
[]interface{}{
types.QuotedText{
Kind: types.Bold,
Elements: []interface{}{
types.StringElement{Content: "a "},
types.InlineImage{
Attributes: types.Attributes{
types.AttrImageAlt: "foo",
},
Location: types.Location{
Path: []interface{}{
types.StringElement{
Content: "foo.png",
},
},
},
},
Expand All @@ -6122,30 +6160,30 @@ var _ = Describe("quoted texts", func() {
},
},
},
},
}
Expect(ParseDocument(source)).To(MatchDocument(expected))
})
}
Expect(ParseDocument(source)).To(MatchDocument(expected))
})

It("image in italic", func() {
source := "_a image:foo.png[]_"
expected := types.Document{
Elements: []interface{}{
types.Paragraph{
Lines: []interface{}{
[]interface{}{
types.QuotedText{
Kind: types.Italic,
Elements: []interface{}{
types.StringElement{Content: "a "},
types.InlineImage{
Attributes: types.Attributes{
types.AttrImageAlt: "foo",
},
Location: types.Location{
Path: []interface{}{
types.StringElement{
Content: "foo.png",
It("image in italic", func() {
source := "_a image:foo.png[]_"
expected := types.Document{
Elements: []interface{}{
types.Paragraph{
Lines: []interface{}{
[]interface{}{
types.QuotedText{
Kind: types.Italic,
Elements: []interface{}{
types.StringElement{Content: "a "},
types.InlineImage{
Attributes: types.Attributes{
types.AttrImageAlt: "foo",
},
Location: types.Location{
Path: []interface{}{
types.StringElement{
Content: "foo.png",
},
},
},
},
Expand All @@ -6155,30 +6193,30 @@ var _ = Describe("quoted texts", func() {
},
},
},
},
}
Expect(ParseDocument(source)).To(MatchDocument(expected))
})
}
Expect(ParseDocument(source)).To(MatchDocument(expected))
})

It("image in monospace", func() {
source := "`a image:foo.png[]`"
expected := types.Document{
Elements: []interface{}{
types.Paragraph{
Lines: []interface{}{
[]interface{}{
types.QuotedText{
Kind: types.Monospace,
Elements: []interface{}{
types.StringElement{Content: "a "},
types.InlineImage{
Attributes: types.Attributes{
types.AttrImageAlt: "foo",
},
Location: types.Location{
Path: []interface{}{
types.StringElement{
Content: "foo.png",
It("image in monospace", func() {
source := "`a image:foo.png[]`"
expected := types.Document{
Elements: []interface{}{
types.Paragraph{
Lines: []interface{}{
[]interface{}{
types.QuotedText{
Kind: types.Monospace,
Elements: []interface{}{
types.StringElement{Content: "a "},
types.InlineImage{
Attributes: types.Attributes{
types.AttrImageAlt: "foo",
},
Location: types.Location{
Path: []interface{}{
types.StringElement{
Content: "foo.png",
},
},
},
},
Expand All @@ -6188,9 +6226,9 @@ var _ = Describe("quoted texts", func() {
},
},
},
},
}
Expect(ParseDocument(source)).To(MatchDocument(expected))
}
Expect(ParseDocument(source)).To(MatchDocument(expected))
})
})
})
})
11 changes: 11 additions & 0 deletions pkg/renderer/sgml/html5/quoted_text_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ content</mark>.</p>
})

Context("attributes", func() {

It("simple role italics", func() {
source := "[myrole]_italics_"
expected := `<div class="paragraph">
Expand Down Expand Up @@ -360,6 +361,16 @@ content</mark>.</p>
Expect(RenderHTML(source)).To(MatchHTML(expected))
})

It("short-hand role with special characters", func() {
source := `["a <role>"]**bold**`
// wrapping quotes are not preserved
expected := `<div class="paragraph">
<p><strong class="a &lt;role&gt;">bold</strong></p>
</div>
`
Expect(RenderHTML(source)).To(MatchHTML(expected))
})

It("simple role mono unconstrained", func() {
source := "int[uncle]``eg``rate"
expected := `<div class="paragraph">
Expand Down

0 comments on commit 856c40a

Please sign in to comment.