Skip to content

Commit

Permalink
refactor(types): rename func to init AttributeReferences (bytesparadi…
Browse files Browse the repository at this point in the history
…se#1043)

also, add test on attribute refs in links

Signed-off-by: Xavier Coulon <[email protected]>
  • Loading branch information
xcoulon authored Jun 13, 2022
1 parent 8adac29 commit 96db47f
Show file tree
Hide file tree
Showing 4 changed files with 15,252 additions and 15,180 deletions.
76 changes: 74 additions & 2 deletions pkg/parser/attribute_substitution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var _ = Describe("attribute substitutions", func() {

Context("in final documents", func() {

It("paragraph with attribute substitution", func() {
It("paragraph with attribute reference", func() {
source := `:author: Xavier
a paragraph written by {author}.`
Expand Down Expand Up @@ -136,7 +136,7 @@ This journey continues`
Expect(ParseDocument(source)).To(MatchDocument(expected))
})

It("paragraph with attribute substitution from front-matter", func() {
It("paragraph with attribute reference from front-matter", func() {
source := `---
author: Xavier
---
Expand All @@ -160,5 +160,77 @@ a paragraph written by {author}.`
}
Expect(ParseDocument(source)).To(MatchDocument(expected))
})

It("link with attribute reference with hyphen", func() {
source := `:download-version: 1.0.0
a link to https://example.com/version/v{download-version}[here]`

expected := &types.Document{
Elements: []interface{}{
&types.DocumentHeader{
Elements: []interface{}{
&types.AttributeDeclaration{
Name: "download-version",
Value: "1.0.0",
},
},
},
&types.Paragraph{
Elements: []interface{}{
&types.StringElement{
Content: "a link to ",
},
&types.InlineLink{
Attributes: types.Attributes{
types.AttrInlineLinkText: "here",
},
Location: &types.Location{
Scheme: "https://",
Path: "example.com/version/v1.0.0",
},
},
},
},
},
}
Expect(ParseDocument(source)).To(MatchDocument(expected))
})

It("link with unknown attribute reference in URL", func() {
source := `:version: 1.0.0
a link to https://example.com/version/v{unknown}[here]`

expected := &types.Document{
Elements: []interface{}{
&types.DocumentHeader{
Elements: []interface{}{
&types.AttributeDeclaration{
Name: "version",
Value: "1.0.0",
},
},
},
&types.Paragraph{
Elements: []interface{}{
&types.StringElement{
Content: "a link to ",
},
&types.InlineLink{
Attributes: types.Attributes{
types.AttrInlineLinkText: "here",
},
Location: &types.Location{
Scheme: "https://",
Path: "example.com/version/v{unknown}",
},
},
},
},
},
}
Expect(ParseDocument(source)).To(MatchDocument(expected))
})
})
})
Loading

0 comments on commit 96db47f

Please sign in to comment.