Skip to content

Commit

Permalink
rollback #53 because of #63, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kovetskiy committed Feb 2, 2021
1 parent cb1093d commit e190cdf
Show file tree
Hide file tree
Showing 17 changed files with 267 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/docker
/testdata
.idea/
/mark.test
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@ go 1.14

require (
github.com/BurntSushi/toml v0.3.1 // indirect
github.com/alecthomas/assert v0.0.0-20170929043011-405dbfeb8e38
github.com/alecthomas/colour v0.1.0 // indirect
github.com/alecthomas/repr v0.0.0-20201120212035-bb82daffcca2 // indirect
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815
github.com/go-yaml/yaml v2.1.0+incompatible // indirect
github.com/iancoleman/strcase v0.0.0-20191112232945-16388991a334 // indirect
github.com/kovetskiy/gopencils v0.0.0-20201105104258-2a0bfdd710fb
github.com/kovetskiy/ko v0.0.0-20190324102900-26b8dd0988bf
github.com/kovetskiy/lorg v0.0.0-20200107130803-9a7136a95634
github.com/kovetskiy/toml v0.2.0 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/reconquest/karma-go v0.0.0-20200326104714-79480464fdb5
github.com/reconquest/pkg v0.0.0-20201028091908-8e9a5e0226ef
github.com/reconquest/regexputil-go v0.0.0-20160905154124-38573e70c1f4
github.com/russross/blackfriday v1.5.2
github.com/sergi/go-diff v1.1.0 // indirect
github.com/stretchr/testify v1.5.1
gopkg.in/yaml.v2 v2.2.8
)
20 changes: 20 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/NYTimes/gziphandler v1.1.1/go.mod h1:n/CVRwUEOgIxrgPvAQhUUr9oeUtvrhMomdKFjzJNB0c=
github.com/alecthomas/assert v0.0.0-20170929043011-405dbfeb8e38 h1:smF2tmSOzy2Mm+0dGI2AIUHY+w0BUc+4tn40djz7+6U=
github.com/alecthomas/assert v0.0.0-20170929043011-405dbfeb8e38/go.mod h1:r7bzyVFMNntcxPZXK3/+KdruV1H5KSlyVY0gc+NgInI=
github.com/alecthomas/colour v0.1.0 h1:nOE9rJm6dsZ66RGWYSFrXw461ZIt9A6+nHgL7FRrDUk=
github.com/alecthomas/colour v0.1.0/go.mod h1:QO9JBoKquHd+jz9nshCh40fOfO+JzsoXy8qTHF68zU0=
github.com/alecthomas/repr v0.0.0-20201120212035-bb82daffcca2 h1:G5TeG64Ox4OWq2YwlsxS7nOedU8vbGgNRTRDAjGvDCk=
github.com/alecthomas/repr v0.0.0-20201120212035-bb82daffcca2/go.mod h1:2kn6fqh/zIyPLmm3ugklbEi5hg5wS435eygvNfaDQL8=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815 h1:bWDMxwH3px2JBh6AyO7hdCn/PkvCZXii8TGj7sbtEbQ=
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385/go.mod h1:0vRUJqYpeSZifjYj7uP3BG/gKcuzL9xWVV/Y+cK33KM=
Expand All @@ -19,6 +27,11 @@ github.com/kovetskiy/lorg v0.0.0-20200107130803-9a7136a95634 h1:szpgh20EtHoQhJ38
github.com/kovetskiy/lorg v0.0.0-20200107130803-9a7136a95634/go.mod h1:B8HeKAukXULNzWWsW5k/SQyDkiQZPn7lTBJDB46MZ9I=
github.com/kovetskiy/toml v0.2.0 h1:tMsPGWE3ejTjXop10/17b/tDtbwQJZdBfc0e+l3WndA=
github.com/kovetskiy/toml v0.2.0/go.mod h1:+nh++V8wCesSlfPA3DSXGO1hiAHDVHDqem4ixTsWuRY=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/reconquest/cog v0.0.0-20191208202052-266c2467b936 h1:jSaVCkKLAGc8VWBRVKk0Ffxrv/NKD1ixkOyjwPWrPd4=
Expand All @@ -35,8 +48,11 @@ github.com/reconquest/regexputil-go v0.0.0-20160905154124-38573e70c1f4 h1:bcDXaT
github.com/reconquest/regexputil-go v0.0.0-20160905154124-38573e70c1f4/go.mod h1:OI1di2iiFSwX3D70iZjzdmCPPfssjOl+HX40tI3VaXA=
github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c/go.mod h1:UrdRz5enIKZ63MEE3IF9l2/ebyx59GyGgPi+tICQdmM=
Expand All @@ -49,9 +65,13 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
2 changes: 1 addition & 1 deletion pkg/mark/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func CompileMarkdown(
blackfriday.EXTENSION_TITLEBLOCK |
blackfriday.EXTENSION_BACKSLASH_LINE_BREAK |
blackfriday.EXTENSION_DEFINITION_LISTS |
blackfriday.EXTENSION_JOIN_LINES |
blackfriday.EXTENSION_HARD_LINE_BREAK |
blackfriday.EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK,
},
)
Expand Down
50 changes: 50 additions & 0 deletions pkg/mark/markdown_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package mark

import (
"io/ioutil"
"path/filepath"
"strings"
"testing"

"github.com/kovetskiy/mark/pkg/mark/stdlib"
"github.com/stretchr/testify/assert"
)

const (
NL = "\n"
)

func text(lines ...string) string {
return strings.Join(lines, "\n")
}

func TestCompileMarkdown(t *testing.T) {
test := assert.New(t)

testcases, err := filepath.Glob("testdata/*.md")
if err != nil {
panic(err)
}

for _, filename := range testcases {
basename := filepath.Base(filename)
testname := strings.TrimSuffix(basename, ".md")
htmlname := filepath.Join(filepath.Dir(filename), testname+".html")

markdown, err := ioutil.ReadFile(filename)
if err != nil {
panic(err)
}
html, err := ioutil.ReadFile(htmlname)
if err != nil {
panic(err)
}

lib, err := stdlib.New(nil)
if err != nil {
panic(err)
}
actual := CompileMarkdown(markdown, lib)
test.EqualValues(string(html), actual, filename+" vs "+htmlname)
}
}
52 changes: 52 additions & 0 deletions pkg/mark/testdata/codes.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<p><code>inline</code></p>
<ac:structured-macro ac:name="expand">
<ac:parameter ac:name="title"></ac:parameter>
<ac:rich-text-body>
<ac:structured-macro ac:name="code">
<ac:parameter ac:name="language"></ac:parameter>
<ac:parameter ac:name="collapse">false</ac:parameter>
<ac:parameter ac:name="title"></ac:parameter>
<ac:plain-text-body><![CDATA[some code
]]></ac:plain-text-body>
</ac:structured-macro>
</ac:rich-text-body>
</ac:structured-macro>
<ac:structured-macro ac:name="expand">
<ac:parameter ac:name="title"></ac:parameter>
<ac:rich-text-body>
<ac:structured-macro ac:name="code">
<ac:parameter ac:name="language">bash</ac:parameter>
<ac:parameter ac:name="collapse">false</ac:parameter>
<ac:parameter ac:name="title"></ac:parameter>
<ac:plain-text-body><![CDATA[code bash
]]></ac:plain-text-body>
</ac:structured-macro>
</ac:rich-text-body>
</ac:structured-macro>
<ac:structured-macro ac:name="expand">
<ac:parameter ac:name="title"></ac:parameter>
<ac:rich-text-body>
<ac:structured-macro ac:name="code">
<ac:parameter ac:name="language">unknown</ac:parameter>
<ac:parameter ac:name="collapse">false</ac:parameter>
<ac:parameter ac:name="title"></ac:parameter>
<ac:plain-text-body><![CDATA[unknown code
]]></ac:plain-text-body>
</ac:structured-macro>
</ac:rich-text-body>
</ac:structured-macro>

<p>text<br />
text 2</p>
<ac:structured-macro ac:name="expand">
<ac:parameter ac:name="title"></ac:parameter>
<ac:rich-text-body>
<ac:structured-macro ac:name="code">
<ac:parameter ac:name="language">unknown</ac:parameter>
<ac:parameter ac:name="collapse">false</ac:parameter>
<ac:parameter ac:name="title"></ac:parameter>
<ac:plain-text-body><![CDATA[unknown code 2
]]></ac:plain-text-body>
</ac:structured-macro>
</ac:rich-text-body>
</ac:structured-macro>
17 changes: 17 additions & 0 deletions pkg/mark/testdata/codes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
`inline`

```
some code
```
```bash
code bash
```

```unknown
unknown code
```
text
text 2
```unknown
unknown code 2
```
13 changes: 13 additions & 0 deletions pkg/mark/testdata/header.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<h1 id="a">a</h1>

<h2 id="b">b</h2>

<h3 id="c">c</h3>

<h4 id="d">d</h4>

<h5 id="e">e</h5>

<h1 id="f">f</h1>

<h2 id="g">g</h2>
9 changes: 9 additions & 0 deletions pkg/mark/testdata/header.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# a
## b
### c
#### d
##### e
f
=
g
-
24 changes: 24 additions & 0 deletions pkg/mark/testdata/lists.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<ul>
<li>dash 1-1<br /></li>
<li>dash 1-2<br /></li>
<li>dash 1-3<br />

<ul>
<li>dash 1-3-1<br /></li>
<li>dash 1-3-2<br /></li>
<li>dash 1-3-3<br />

<ul>
<li>dash 1-3-3-1<br />
<br /></li>
</ul></li>
</ul></li>
</ul>

<p>text</p>

<ul>
<li>a<br /></li>
<li>b<br /></li>
<li>c<br /></li>
</ul>
13 changes: 13 additions & 0 deletions pkg/mark/testdata/lists.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
- dash 1-1
- dash 1-2
- dash 1-3
- dash 1-3-1
- dash 1-3-2
- dash 1-3-3
- dash 1-3-3-1

text

* a
* b
* c
16 changes: 16 additions & 0 deletions pkg/mark/testdata/newlines.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<p>one-1<br />
one-2</p>

<p>two-1</p>

<p>two-2</p>

<p>three-1</p>

<p>three-2</p>

<p>space-1<br />
space-2</p>

<p>2space-1<br />
2space-2</p>
17 changes: 17 additions & 0 deletions pkg/mark/testdata/newlines.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
one-1
one-2

two-1

two-2

three-1


three-2

space-1
space-2

2space-1
2space-2
5 changes: 5 additions & 0 deletions pkg/mark/testdata/tags.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<p><b>bold</b><br />
<strong>bold</strong></p>

<p><i>vitalik</i><br />
<em>vitalik</em></p>
5 changes: 5 additions & 0 deletions pkg/mark/testdata/tags.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<b>bold</b>
**bold**

<i>vitalik</i>
*vitalik*
14 changes: 14 additions & 0 deletions test/alice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!-- Space: MARKTEST -->
<!-- Parent: Parent1 -->
<!-- Parent: Parent2 -->
<!-- Parent: Parent3 -->
<!-- Parent: Parent4 -->
<!-- Parent: Parent5 -->
<!-- Parent: Parent6 -->
<!-- Title: Test Page -->

a
b

- a
- b
5 changes: 5 additions & 0 deletions test/bob.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!-- Space: MARKTEST -->
<!-- Parent: mark -->
<!-- Title: Bob -->

Alice: [alice](alice.md)

0 comments on commit e190cdf

Please sign in to comment.