Improve tests: Add pretty_org fixtures to allow testing pretty printing
Until now we expected the .org file to print back to itself - we can't do that when the input is not pretty printed already - with the introduction of blocks with unindented content that will be the case.
This commit is contained in:
parent
c26d39284c
commit
ade2a1c875
14 changed files with 356 additions and 8 deletions
8
Makefile
8
Makefile
|
@ -23,12 +23,12 @@ render:
|
||||||
go run main.go org/testdata/$(case).org html | html2text
|
go run main.go org/testdata/$(case).org html | html2text
|
||||||
|
|
||||||
.PHONY: generate
|
.PHONY: generate
|
||||||
generate: generate-gh-pages generate-html-fixtures
|
generate: generate-gh-pages generate-fixtures
|
||||||
|
|
||||||
.PHONY: generate-gh-pages
|
.PHONY: generate-gh-pages
|
||||||
generate-gh-pages: build
|
generate-gh-pages: build
|
||||||
./etc/generate-gh-pages
|
./etc/generate-gh-pages
|
||||||
|
|
||||||
.PHONY: generate-html-fixtures
|
.PHONY: generate-fixtures
|
||||||
generate-html-fixtures: build
|
generate-fixtures: build
|
||||||
./etc/generate-html-fixtures
|
./etc/generate-fixtures
|
||||||
|
|
|
@ -2,4 +2,5 @@
|
||||||
|
|
||||||
for org_file in org/testdata/*.org; do
|
for org_file in org/testdata/*.org; do
|
||||||
./go-org $org_file html > org/testdata/$(basename $org_file .org).html
|
./go-org $org_file html > org/testdata/$(basename $org_file .org).html
|
||||||
|
./go-org $org_file org > org/testdata/$(basename $org_file .org).pretty_org
|
||||||
done
|
done
|
|
@ -7,14 +7,14 @@ import (
|
||||||
|
|
||||||
func TestHTMLWriter(t *testing.T) {
|
func TestHTMLWriter(t *testing.T) {
|
||||||
for _, path := range orgTestFiles() {
|
for _, path := range orgTestFiles() {
|
||||||
|
expected := fileString(path[:len(path)-len(".org")] + ".html")
|
||||||
reader, writer := strings.NewReader(fileString(path)), NewHTMLWriter()
|
reader, writer := strings.NewReader(fileString(path)), NewHTMLWriter()
|
||||||
actual, err := NewDocument().SetPath(path).Parse(reader).Write(writer)
|
actual, err := NewDocument().SetPath(path).Parse(reader).Write(writer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("%s\n got error: %s", path, err)
|
t.Errorf("%s\n got error: %s", path, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
expected := fileString(path[:len(path)-len(".org")] + ".html")
|
if actual != expected {
|
||||||
if expected != actual {
|
|
||||||
t.Errorf("%s:\n%s'", path, diff(actual, expected))
|
t.Errorf("%s:\n%s'", path, diff(actual, expected))
|
||||||
} else {
|
} else {
|
||||||
t.Logf("%s: passed!", path)
|
t.Logf("%s: passed!", path)
|
||||||
|
|
|
@ -12,8 +12,8 @@ import (
|
||||||
|
|
||||||
func TestOrgWriter(t *testing.T) {
|
func TestOrgWriter(t *testing.T) {
|
||||||
for _, path := range orgTestFiles() {
|
for _, path := range orgTestFiles() {
|
||||||
expected := fileString(path)
|
expected := fileString(path[:len(path)-len(".org")] + ".pretty_org")
|
||||||
reader, writer := strings.NewReader(expected), NewOrgWriter()
|
reader, writer := strings.NewReader(fileString(path)), NewOrgWriter()
|
||||||
actual, err := NewDocument().SetPath(path).Parse(reader).Write(writer)
|
actual, err := NewDocument().SetPath(path).Parse(reader).Write(writer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("%s\n got error: %s", path, err)
|
t.Errorf("%s\n got error: %s", path, err)
|
||||||
|
|
50
org/testdata/blocks.pretty_org
vendored
Normal file
50
org/testdata/blocks.pretty_org
vendored
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
#+CAPTION: block caption
|
||||||
|
#+BEGIN_SRC bash :results raw
|
||||||
|
echo "a bash source block"
|
||||||
|
|
||||||
|
function hello {
|
||||||
|
echo Hello World!
|
||||||
|
}
|
||||||
|
|
||||||
|
hello
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
#+BEGIN_SRC
|
||||||
|
a source block without a language
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
#+BEGIN_EXAMPLE foo bar baz
|
||||||
|
an example block with
|
||||||
|
multiple lines including
|
||||||
|
|
||||||
|
|
||||||
|
empty lines!
|
||||||
|
|
||||||
|
it also has multiple parameters
|
||||||
|
|
||||||
|
note that /inline/ *markup* ignored
|
||||||
|
#+END_EXAMPLE
|
||||||
|
|
||||||
|
: examples like this
|
||||||
|
: are also supported
|
||||||
|
: note that /inline/ *markup* ignored
|
||||||
|
|
||||||
|
#+BEGIN_QUOTE
|
||||||
|
Mongodb is *webscale*. (source: [[http://www.mongodb-is-web-scale.com/][mongodb-is-web-scale]])
|
||||||
|
|
||||||
|
blocks can contain other elements like
|
||||||
|
- lists
|
||||||
|
- inline /markup/
|
||||||
|
- tables
|
||||||
|
| foo |
|
||||||
|
| bar |
|
||||||
|
| baz |
|
||||||
|
- paragraphs
|
||||||
|
- ...
|
||||||
|
#+END_QUOTE
|
||||||
|
|
||||||
|
#+BEGIN_EXPORT html
|
||||||
|
<script>
|
||||||
|
console.log("Hello World!")
|
||||||
|
</script>
|
||||||
|
#+END_EXPORT
|
16
org/testdata/captions.pretty_org
vendored
Normal file
16
org/testdata/captions.pretty_org
vendored
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
Anything can be captioned. Also captions are not real, correct captions but just a paragraph below the element (bothe wrapped into a div)
|
||||||
|
|
||||||
|
#+CAPTION: captioned soure block
|
||||||
|
#+BEGIN_SRC sh
|
||||||
|
echo "i have a caption!"
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
#+CAPTION: captioned link (image in this case)
|
||||||
|
[[https://placekitten.com/200/200#.png]]
|
||||||
|
|
||||||
|
note that the whole paragraph is captioned, so a linebreak is needed for images to caption correctly
|
||||||
|
|
||||||
|
#+CAPTION: captioned link (image in this case)
|
||||||
|
[[https://placekitten.com/200/200#.png]]
|
||||||
|
see?
|
||||||
|
|
28
org/testdata/footnotes.pretty_org
vendored
Normal file
28
org/testdata/footnotes.pretty_org
vendored
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
* Using some footnotes
|
||||||
|
- normal footnote reference [fn:1] [fn:6]
|
||||||
|
- further references to the same footnote should not [fn:1] render duplicates in the footnote list
|
||||||
|
- inline footnotes are also supported via [fn:2:the inline footnote definition].
|
||||||
|
|
||||||
|
* Footnotes
|
||||||
|
[fn:1] https://www.example.com
|
||||||
|
- footnotes can contain *markup*
|
||||||
|
- and other elements
|
||||||
|
- like blocks
|
||||||
|
#+BEGIN_SRC
|
||||||
|
other non-plain
|
||||||
|
#+END_SRC
|
||||||
|
- and tables
|
||||||
|
| 1 | a |
|
||||||
|
| 2 | b |
|
||||||
|
| 3 | c |
|
||||||
|
|
||||||
|
[fn:3] [[http://example.com/unused-footnote][example.com/unused-footnote]]
|
||||||
|
|
||||||
|
[fn:4] another unused footnote
|
||||||
|
|
||||||
|
[fn:5] another unused footnote
|
||||||
|
|
||||||
|
[fn:6]
|
||||||
|
|
||||||
|
Footnotes break after two consecutive empty lines - just like paragraphs - see https://orgmode.org/worg/dev/org-syntax.html.
|
||||||
|
This shouldn't happen when the definition line and the line after that are empty.
|
19
org/testdata/headlines.pretty_org
vendored
Normal file
19
org/testdata/headlines.pretty_org
vendored
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
* Simple Headline [1/2]
|
||||||
|
- [X] checked
|
||||||
|
- [ ] unchecked
|
||||||
|
- note that statistic tokens are marked up anywhere
|
||||||
|
not just where they are actually meant to be - even here > [100%] <
|
||||||
|
(Org mode proper does the same)
|
||||||
|
* TODO [#B] Headline with todo status & priority
|
||||||
|
* DONE Headline with TODO status
|
||||||
|
:PROPERTIES:
|
||||||
|
:Note: property drawers are not exported as html like other drawers
|
||||||
|
:END:
|
||||||
|
|
||||||
|
the *content*
|
||||||
|
* [#A] Headline with tags & priority :foo:bar:
|
||||||
|
Still outside the drawer
|
||||||
|
:DRAWERNAME:
|
||||||
|
This is inside the drawer
|
||||||
|
:END:
|
||||||
|
Still outside the drawer
|
28
org/testdata/inline.pretty_org
vendored
Normal file
28
org/testdata/inline.pretty_org
vendored
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
- /emphasis/ and a hard line break \\
|
||||||
|
see?
|
||||||
|
- /.emphasis with dot border chars./
|
||||||
|
- /emphasis with a slash/inside/
|
||||||
|
- /emphasis/ followed by raw text with slash /
|
||||||
|
- ->/not an emphasis/<-
|
||||||
|
- links with slashes do not become /emphasis/: [[https://somelinkshouldntrenderaccidentalemphasis.com]]/ /emphasis/
|
||||||
|
- _underlined_ *bold* =verbatim= ~code~ +strikethrough+
|
||||||
|
- *bold string with an *asterisk inside*
|
||||||
|
- =multiline emphasis is
|
||||||
|
supported - and respects MaxEmphasisNewLines (default: 1)=
|
||||||
|
/so this
|
||||||
|
is emphasized/
|
||||||
|
|
||||||
|
/but
|
||||||
|
this
|
||||||
|
is
|
||||||
|
not emphasized/
|
||||||
|
- empty emphasis markers like ++ // __ and so on are ignored
|
||||||
|
- subscript_{sub} and superscript^{super}
|
||||||
|
- links
|
||||||
|
1. regular link [[https://example.com]] link without description
|
||||||
|
2. regular link [[https://example.com][example.com]] link with description
|
||||||
|
3. regular link to a file (image) [[file:my-img.png]]
|
||||||
|
4. regular link to a file (video) [[my-video.mp4]]
|
||||||
|
5. regular link to http (image) [[http://placekitten.com/200/200#.png]]
|
||||||
|
6. regular link to https (image) [[https://placekitten.com/200/200#.png]]
|
||||||
|
7. auto link, i.e. not inside =\[[square brackets]\]= https://www.example.com
|
14
org/testdata/keywords.pretty_org
vendored
Normal file
14
org/testdata/keywords.pretty_org
vendored
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
|
||||||
|
#+CAPTION: and _multiple_
|
||||||
|
#+CAPTION: lines of *captions*!
|
||||||
|
#+ATTR_HTML: :class a b
|
||||||
|
#+ATTR_HTML: :id it :class c d
|
||||||
|
#+BEGIN_SRC sh
|
||||||
|
echo "a bash source block with custom html attributes"
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
and an image with custom html attributes and a caption
|
||||||
|
#+CAPTION: kittens!
|
||||||
|
#+ATTR_HTML: :style height: 100%; :id overwritten
|
||||||
|
#+ATTR_HTML: :style border: 10px solid black; :id kittens
|
||||||
|
[[https://placekitten.com/200/200#.png]]
|
38
org/testdata/lists.pretty_org
vendored
Normal file
38
org/testdata/lists.pretty_org
vendored
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
- [ ] unordered list item 1
|
||||||
|
- unordered list item 2 - with ~inline~ /markup/
|
||||||
|
1. [-] ordered sublist item 1
|
||||||
|
a) [X] ordered sublist item 1
|
||||||
|
b) [ ] ordered sublist item 2
|
||||||
|
c) [X] ordered sublist item 3
|
||||||
|
2. ordered sublist item 2
|
||||||
|
- [X] unordered list item 3 - and a [[https://example.com][link]]
|
||||||
|
and some lines of text
|
||||||
|
1. and another subitem
|
||||||
|
#+BEGIN_SRC sh
|
||||||
|
echo with a block
|
||||||
|
#+END_SRC
|
||||||
|
2. and another one with a table
|
||||||
|
| a | b | c |
|
||||||
|
|---+---+---|
|
||||||
|
| 1 | 2 | 3 |
|
||||||
|
|
||||||
|
and text with an empty line in between as well!
|
||||||
|
- unordered list item 4
|
||||||
|
: with an example
|
||||||
|
:
|
||||||
|
: that spans multiple lines
|
||||||
|
|
||||||
|
|
||||||
|
descriptive lists
|
||||||
|
- [ ] term :: details
|
||||||
|
continued details
|
||||||
|
- [ ] details without a term
|
||||||
|
- [X] term ::
|
||||||
|
details on a new line
|
||||||
|
- term ::
|
||||||
|
|
||||||
|
details on a new line (with an empty line in between)
|
||||||
|
*continued*
|
||||||
|
#+BEGIN_SRC bash
|
||||||
|
echo "Hello World!"
|
||||||
|
#+END_SRC
|
114
org/testdata/misc.pretty_org
vendored
Normal file
114
org/testdata/misc.pretty_org
vendored
Normal file
|
@ -0,0 +1,114 @@
|
||||||
|
** issues from goorgeous (free test cases, yay!)
|
||||||
|
*** DONE [[https://github.com/chaseadamsio/goorgeous/issues/19][#19]]: Support #+HTML
|
||||||
|
#+HTML: <p style="border: 1px dotted grey">neato!</p>
|
||||||
|
*** DONE [[https://github.com/chaseadamsio/goorgeous/issues/29][#29:]] Support verse block
|
||||||
|
#+BEGIN_VERSE
|
||||||
|
This
|
||||||
|
*is*
|
||||||
|
verse
|
||||||
|
#+END_VERSE
|
||||||
|
|
||||||
|
#+BEGIN_CUSTOM
|
||||||
|
or even a *totally* /custom/ kind of block
|
||||||
|
crazy ain't it?
|
||||||
|
#+END_CUSTOM
|
||||||
|
*** DONE [[https://github.com/chaseadamsio/goorgeous/issues/31][#31]]: Support #+INCLUDE
|
||||||
|
Note that only src/example/export block inclusion is supported for now.
|
||||||
|
There's quite a lot more to include (see the [[https://orgmode.org/manual/Include-files.html][org manual for include files]]) but I
|
||||||
|
don't have a use case for this yet and stuff like namespacing footnotes of included files
|
||||||
|
adds quite a bit of complexity.
|
||||||
|
|
||||||
|
for now files can be included as:
|
||||||
|
- src block
|
||||||
|
#+INCLUDE: "./headlines.org" src org
|
||||||
|
- export block
|
||||||
|
#+INCLUDE: "./paragraphs.html" export html
|
||||||
|
- example block
|
||||||
|
#+INCLUDE: "../../.travis.yml" example yaml
|
||||||
|
*** DONE [[https://github.com/chaseadamsio/goorgeous/issues/33][#33]]: Wrong output when mixing html with Org mode
|
||||||
|
#+HTML: <div class="outline-2" id="meta" style="color: green;">
|
||||||
|
| *foo* | foo |
|
||||||
|
| *bar* | bar |
|
||||||
|
#+HTML: </div>
|
||||||
|
*** DONE [[https://github.com/chaseadamsio/goorgeous/issues/46][#46]]: Support for symbols like ndash and mdash
|
||||||
|
- ndash --
|
||||||
|
- mdash ---
|
||||||
|
- ellipsis ...
|
||||||
|
- acute \Aacute and so on
|
||||||
|
- note that ------ is replaced with 2 mdashes and .... becomes ellipsis+. and so on - that's how org also does it
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
*** DONE [[https://github.com/chaseadamsio/goorgeous/issues/47][#47:]] Consecutive ~code~ wrapped text gets joined
|
||||||
|
either ~this~ or ~that~ foo.
|
||||||
|
either ~this~
|
||||||
|
or ~that~ foo.
|
||||||
|
*** DONE [[https://github.com/chaseadamsio/goorgeous/issues/50][#50]]: LineBreaks in lists are preserved
|
||||||
|
- this list item
|
||||||
|
has
|
||||||
|
multiple
|
||||||
|
linbreaks - but it's still just one paragraph (i.e. no line breaks are rendered)
|
||||||
|
- foobar
|
||||||
|
1. same
|
||||||
|
goes
|
||||||
|
for
|
||||||
|
ordered
|
||||||
|
lists
|
||||||
|
2. foo
|
||||||
|
*** DONE [[https://github.com/chaseadamsio/goorgeous/issues/68][#68]]: Quote block with inline markup
|
||||||
|
#+BEGIN_QUOTE
|
||||||
|
[[https://www.example.com][/this/ *is* _markup_!]]
|
||||||
|
#+END_QUOTE
|
||||||
|
*** DONE [[https://github.com/chaseadamsio/goorgeous/issues/72][#72]]: Support for #+ATTR_HTML
|
||||||
|
#+ATTR_HTML: :alt Go is fine though. :id gopher-image
|
||||||
|
#+ATTR_HTML: :width 300 :style border:2px solid black;
|
||||||
|
[[https://golang.org/doc/gopher/pkg.png]]
|
||||||
|
*** DONE [[https://github.com/chaseadamsio/goorgeous/issues/75][#75]]: Not parsing nested lists correctly
|
||||||
|
- bullet 1
|
||||||
|
- sub bullet
|
||||||
|
|
||||||
|
*** DONE [[https://github.com/chaseadamsio/goorgeous/issues/77][#77]]: Recognize =code=--- as code plus dash
|
||||||
|
*** DONE [[https://github.com/chaseadamsio/goorgeous/issues/78][#78]]: Emphasis at beginning of line
|
||||||
|
/italics/
|
||||||
|
|
||||||
|
|
||||||
|
Text
|
||||||
|
/italics/
|
||||||
|
*** DONE [[https://github.com/chaseadamsio/goorgeous/issues/82][#82]]: Crash on empty headline
|
||||||
|
****
|
||||||
|
just a space as title...
|
||||||
|
*** DONE [[https://github.com/chaseadamsio/goorgeous/issues/84][#84]]: Paragraphs that are not followed by an empty line are not parsed correctly
|
||||||
|
**** Foo
|
||||||
|
Foo paragraph.
|
||||||
|
**** Bar
|
||||||
|
Bar paragraph
|
||||||
|
*** DONE [[https://github.com/chaseadamsio/goorgeous/issues/86][#86]]: Multiple hyphens not converted to dashes
|
||||||
|
just like #46
|
||||||
|
- =--= -> -- (en dash)
|
||||||
|
- =---= -> --- (em dash)
|
||||||
|
|
||||||
|
also, consecutive dashes inside
|
||||||
|
- inline code =--= =---= and verbatim ~--~ ~---~
|
||||||
|
- src/example/export blocks should not be converted!
|
||||||
|
#+BEGIN_SRC sh
|
||||||
|
--, ---
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
#+BEGIN_EXAMPLE
|
||||||
|
--, ---
|
||||||
|
#+END_EXAMPLE
|
||||||
|
|
||||||
|
#+BEGIN_EXPORT html
|
||||||
|
--, ---
|
||||||
|
#+END_EXPORT
|
||||||
|
|
||||||
|
: --, ---
|
||||||
|
|
||||||
|
*** DONE [[https://github.com/chaseadamsio/goorgeous/issues/87][#87]]: Markup in footnotes is rendered literally
|
||||||
|
footnotes can contain *markup* - and other elements and stuff [fn:2:that also goes for *inline* footnote /definitions/]
|
||||||
|
|
||||||
|
* Footnotes
|
||||||
|
|
||||||
|
[fn:1] a footnote /with/ *markup*
|
||||||
|
- and a *list*
|
||||||
|
- because that's possible
|
11
org/testdata/paragraphs.pretty_org
vendored
Normal file
11
org/testdata/paragraphs.pretty_org
vendored
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
Paragraphs are the default element.
|
||||||
|
|
||||||
|
Empty lines and other elements end paragraphs - but paragraphs
|
||||||
|
can
|
||||||
|
obviously
|
||||||
|
span
|
||||||
|
multiple
|
||||||
|
lines.
|
||||||
|
|
||||||
|
Paragraphs can contain inline markup like /emphasis/ *strong* and links [[https://www.example.com][example.com]] and stuff.
|
||||||
|
|
29
org/testdata/tables.pretty_org
vendored
Normal file
29
org/testdata/tables.pretty_org
vendored
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
#+CAPTION: table with separator before and after header
|
||||||
|
|---+---+---|
|
||||||
|
| a | b | c |
|
||||||
|
|---+---+---|
|
||||||
|
| 1 | 2 | 3 |
|
||||||
|
|
||||||
|
#+CAPTION: table with separator after header
|
||||||
|
| a | b | c |
|
||||||
|
|---+---+---|
|
||||||
|
| 1 | 2 | 3 |
|
||||||
|
|
||||||
|
#+CAPTION: table without header (but separator before)
|
||||||
|
|---+---+---|
|
||||||
|
| 1 | 2 | 3 |
|
||||||
|
|
||||||
|
#+CAPTION: table without header
|
||||||
|
| 1 | 2 | 3 |
|
||||||
|
|
||||||
|
#+CAPTION: table with aligned columns
|
||||||
|
| left aligned | right aligned | center aligned |
|
||||||
|
|--------------+---------------+----------------|
|
||||||
|
| <l> | <r> | <c> |
|
||||||
|
| 42 | 42 | 42 |
|
||||||
|
| foobar | foobar | foobar |
|
||||||
|
|
||||||
|
#+CAPTION: table with right aligned columns (because numbers)
|
||||||
|
| long column a | long column b | long column c |
|
||||||
|
|---------------+---------------+---------------|
|
||||||
|
| 1 | 2 | 3 |
|
Loading…
Add table
Add a link
Reference in a new issue