-
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(parser): parse by fragments and process in pipeline
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 the aggregator which combines all the fragments into the resulting `types.Document`, which can thn be rendered Also: - removed tests in "raw documents" for quoted text, since it has little to no value. BREAKING CHANGE: - using pointers on 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 `types.DelimitedBlock` - all lists are merged into `types.List` - 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
250 changed files
with
116,912 additions
and
90,255 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.