From ade2a1c8758acb34ff431464ae2c44cd8fe5121b Mon Sep 17 00:00:00 2001 From: Niklas Fasching Date: Tue, 18 Dec 2018 23:50:55 +0100 Subject: [PATCH] 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. --- Makefile | 8 +- ...nerate-html-fixtures => generate-fixtures} | 1 + org/html_test.go | 4 +- org/org_test.go | 4 +- org/testdata/blocks.pretty_org | 50 ++++++++ org/testdata/captions.pretty_org | 16 +++ org/testdata/footnotes.pretty_org | 28 +++++ org/testdata/headlines.pretty_org | 19 +++ org/testdata/inline.pretty_org | 28 +++++ org/testdata/keywords.pretty_org | 14 +++ org/testdata/lists.pretty_org | 38 ++++++ org/testdata/misc.pretty_org | 114 ++++++++++++++++++ org/testdata/paragraphs.pretty_org | 11 ++ org/testdata/tables.pretty_org | 29 +++++ 14 files changed, 356 insertions(+), 8 deletions(-) rename etc/{generate-html-fixtures => generate-fixtures} (62%) create mode 100644 org/testdata/blocks.pretty_org create mode 100644 org/testdata/captions.pretty_org create mode 100644 org/testdata/footnotes.pretty_org create mode 100644 org/testdata/headlines.pretty_org create mode 100644 org/testdata/inline.pretty_org create mode 100644 org/testdata/keywords.pretty_org create mode 100644 org/testdata/lists.pretty_org create mode 100644 org/testdata/misc.pretty_org create mode 100644 org/testdata/paragraphs.pretty_org create mode 100644 org/testdata/tables.pretty_org diff --git a/Makefile b/Makefile index 9def1cb..c0b09f8 100644 --- a/Makefile +++ b/Makefile @@ -23,12 +23,12 @@ render: go run main.go org/testdata/$(case).org html | html2text .PHONY: generate -generate: generate-gh-pages generate-html-fixtures +generate: generate-gh-pages generate-fixtures .PHONY: generate-gh-pages generate-gh-pages: build ./etc/generate-gh-pages -.PHONY: generate-html-fixtures -generate-html-fixtures: build - ./etc/generate-html-fixtures +.PHONY: generate-fixtures +generate-fixtures: build + ./etc/generate-fixtures diff --git a/etc/generate-html-fixtures b/etc/generate-fixtures similarity index 62% rename from etc/generate-html-fixtures rename to etc/generate-fixtures index af1fbeb..39cfbaf 100755 --- a/etc/generate-html-fixtures +++ b/etc/generate-fixtures @@ -2,4 +2,5 @@ for org_file in org/testdata/*.org; do ./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 diff --git a/org/html_test.go b/org/html_test.go index 525767a..6450c44 100644 --- a/org/html_test.go +++ b/org/html_test.go @@ -7,14 +7,14 @@ import ( func TestHTMLWriter(t *testing.T) { for _, path := range orgTestFiles() { + expected := fileString(path[:len(path)-len(".org")] + ".html") reader, writer := strings.NewReader(fileString(path)), NewHTMLWriter() actual, err := NewDocument().SetPath(path).Parse(reader).Write(writer) if err != nil { t.Errorf("%s\n got error: %s", path, err) continue } - expected := fileString(path[:len(path)-len(".org")] + ".html") - if expected != actual { + if actual != expected { t.Errorf("%s:\n%s'", path, diff(actual, expected)) } else { t.Logf("%s: passed!", path) diff --git a/org/org_test.go b/org/org_test.go index 1dd3f97..64f7c41 100644 --- a/org/org_test.go +++ b/org/org_test.go @@ -12,8 +12,8 @@ import ( func TestOrgWriter(t *testing.T) { for _, path := range orgTestFiles() { - expected := fileString(path) - reader, writer := strings.NewReader(expected), NewOrgWriter() + expected := fileString(path[:len(path)-len(".org")] + ".pretty_org") + reader, writer := strings.NewReader(fileString(path)), NewOrgWriter() actual, err := NewDocument().SetPath(path).Parse(reader).Write(writer) if err != nil { t.Errorf("%s\n got error: %s", path, err) diff --git a/org/testdata/blocks.pretty_org b/org/testdata/blocks.pretty_org new file mode 100644 index 0000000..1ed1c7e --- /dev/null +++ b/org/testdata/blocks.pretty_org @@ -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 + +#+END_EXPORT diff --git a/org/testdata/captions.pretty_org b/org/testdata/captions.pretty_org new file mode 100644 index 0000000..fb3f0b5 --- /dev/null +++ b/org/testdata/captions.pretty_org @@ -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? + diff --git a/org/testdata/footnotes.pretty_org b/org/testdata/footnotes.pretty_org new file mode 100644 index 0000000..0730354 --- /dev/null +++ b/org/testdata/footnotes.pretty_org @@ -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. diff --git a/org/testdata/headlines.pretty_org b/org/testdata/headlines.pretty_org new file mode 100644 index 0000000..876f8e8 --- /dev/null +++ b/org/testdata/headlines.pretty_org @@ -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 diff --git a/org/testdata/inline.pretty_org b/org/testdata/inline.pretty_org new file mode 100644 index 0000000..9a11445 --- /dev/null +++ b/org/testdata/inline.pretty_org @@ -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 diff --git a/org/testdata/keywords.pretty_org b/org/testdata/keywords.pretty_org new file mode 100644 index 0000000..e6b8ce9 --- /dev/null +++ b/org/testdata/keywords.pretty_org @@ -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]] diff --git a/org/testdata/lists.pretty_org b/org/testdata/lists.pretty_org new file mode 100644 index 0000000..13948d7 --- /dev/null +++ b/org/testdata/lists.pretty_org @@ -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 diff --git a/org/testdata/misc.pretty_org b/org/testdata/misc.pretty_org new file mode 100644 index 0000000..b3df75b --- /dev/null +++ b/org/testdata/misc.pretty_org @@ -0,0 +1,114 @@ +** issues from goorgeous (free test cases, yay!) +*** DONE [[https://github.com/chaseadamsio/goorgeous/issues/19][#19]]: Support #+HTML +#+HTML:

neato!

+*** 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:
+| *foo* | foo | +| *bar* | bar | +#+HTML:
+*** 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 diff --git a/org/testdata/paragraphs.pretty_org b/org/testdata/paragraphs.pretty_org new file mode 100644 index 0000000..cf0e6e0 --- /dev/null +++ b/org/testdata/paragraphs.pretty_org @@ -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. + diff --git a/org/testdata/tables.pretty_org b/org/testdata/tables.pretty_org new file mode 100644 index 0000000..c2ee86f --- /dev/null +++ b/org/testdata/tables.pretty_org @@ -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 | +|--------------+---------------+----------------| +| | | | +| 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 |