-
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.
refactor(types/parser): parse by fragment and process in pipeline (#855)
Fragments are blocks of contiguous lines separated by blank lines. Blank lines within delimited blocks are preserved (hence they do not split the fragments) Once a fragment is read, it is sent on a channel to be processed by the next stages of the pipeline until it reaches the "aggregator" which combines all the fragments into the resulting `*types.Document`, which can then be rendered (as before) Also: - removed tests in "raw documents" for quoted text, since it has little to no value. BREAKING CHANGE: - using pointers on (most of) all structs in `pkg/types` - removing `types.Document.Attributes`, holding attributes in context as parsing/rendering progresses. - `types.Paragraph.Lines` (`[][]interface{}`) is replaced by `types.Paragraph.Elements` (`[]interface{}`) - all delimited blocks types are merged into the single `types.DelimitedBlock` type - all lists are merged into the single `types.List` type - removed the `Level` field in `types.ListElement` struct - refactor document structure with header (level 0) and sections (level 1 to 5) Fixes #843 Signed-off-by: Xavier Coulon <[email protected]>
- Loading branch information
Showing
249 changed files
with
112,297 additions
and
90,078 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
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
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
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
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
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
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
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 |
---|---|---|
@@ -1,16 +1,140 @@ | ||
package libasciidoc_test | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/bytesparadise/libasciidoc" | ||
"github.com/bytesparadise/libasciidoc/pkg/configuration" | ||
"github.com/bytesparadise/libasciidoc/pkg/types" | ||
"github.com/bytesparadise/libasciidoc/testsupport" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func BenchmarkLibasciidoc(b *testing.B) { | ||
// TODO: unexclude this bench func | ||
func XBenchmarkRenderRealDocument(b *testing.B) { | ||
filename := "./test/bench/mocking.adoc" | ||
for i := 0; i < b.N; i++ { | ||
_, err := testsupport.RenderHTML5Document(filename) | ||
out := &strings.Builder{} | ||
_, err := libasciidoc.ConvertFile(out, | ||
configuration.NewConfiguration( | ||
configuration.WithFilename(filename), | ||
configuration.WithCSS("path/to/style.css"), | ||
configuration.WithHeaderFooter(true))) | ||
require.NoError(b, err) | ||
} | ||
} | ||
|
||
func BenchmarkParseBasicDocument(b *testing.B) { | ||
content := `== Lorem Ipsum | ||
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, | ||
sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, | ||
sed diam voluptua. | ||
At vero eos et accusam et justo duo dolores et ea rebum. | ||
Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. | ||
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, | ||
sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, | ||
sed diam voluptua. | ||
At vero eos et accusam et justo duo dolores et ea rebum. | ||
Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.` | ||
|
||
for i := 0; i < b.N; i++ { | ||
_, err := testsupport.ParseDocument(content) | ||
require.NoError(b, err) | ||
} | ||
} | ||
|
||
func BenchmarkParseLongDocument(b *testing.B) { | ||
content := strings.Builder{} | ||
for i := 0; i < 50; i++ { | ||
content.WriteString(`== Lorem Ipsum | ||
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, | ||
sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, | ||
sed diam voluptua. | ||
At vero eos et accusam et justo duo dolores et ea rebum. | ||
Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. | ||
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, | ||
sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, | ||
sed diam voluptua. | ||
At vero eos et accusam et justo duo dolores et ea rebum. | ||
Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. | ||
`) | ||
} | ||
for i := 0; i < b.N; i++ { | ||
_, err := testsupport.ParseDocument(content.String()) | ||
require.NoError(b, err) | ||
} | ||
} | ||
|
||
func TestParseBasicDocument(t *testing.T) { | ||
source := `== Lorem Ipsum | ||
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, | ||
sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, | ||
sed diam voluptua. | ||
At vero eos et accusam et justo duo dolores et ea rebum. | ||
Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. | ||
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, | ||
sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, | ||
sed diam voluptua. | ||
At vero eos et accusam et justo duo dolores et ea rebum. | ||
Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit *amet*.` | ||
|
||
title := []interface{}{ | ||
&types.StringElement{ | ||
Content: "Lorem Ipsum", | ||
}, | ||
} | ||
expected := &types.Document{ | ||
Elements: []interface{}{ | ||
&types.Section{ | ||
Level: 1, | ||
Attributes: types.Attributes{ | ||
types.AttrID: "_lorem_ipsum", | ||
}, | ||
Title: title, | ||
Elements: []interface{}{ | ||
&types.Paragraph{ | ||
Elements: []interface{}{ | ||
&types.StringElement{ | ||
Content: `Lorem ipsum dolor sit amet, consetetur sadipscing elitr, | ||
sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, | ||
sed diam voluptua. | ||
At vero eos et accusam et justo duo dolores et ea rebum. | ||
Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. | ||
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, | ||
sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, | ||
sed diam voluptua. | ||
At vero eos et accusam et justo duo dolores et ea rebum. | ||
Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit `, | ||
}, | ||
&types.QuotedText{ | ||
Kind: types.SingleQuoteBold, | ||
Elements: []interface{}{ | ||
&types.StringElement{ | ||
Content: "amet", | ||
}, | ||
}, | ||
}, | ||
&types.StringElement{ | ||
Content: ".", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
ElementReferences: types.ElementReferences{ | ||
"_lorem_ipsum": title, | ||
}, | ||
} | ||
result, err := testsupport.ParseDocument(source) | ||
require.NoError(t, err) | ||
assert.Equal(t, expected, result) | ||
|
||
} |
Oops, something went wrong.