Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This implements a Markdown / Gemtext suite, testing the entire renderer at complex Markdown documents, containing the entirety of current Markdown features accessible with gmnhg. The test suite can be expanded by adding a pair of .md/.gmi files. Minor bug fixes in JSON/Org metadata parsing where bugs were detected with the test suite are also included in this patch. Fixes #13.
- Loading branch information
Showing
22 changed files
with
653 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// This file is part of gmnhg. | ||
|
||
// gmnhg is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// gmnhg is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with gmnhg. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
package gemini | ||
|
||
import ( | ||
"bytes" | ||
"io/ioutil" | ||
"os" | ||
"path" | ||
"regexp" | ||
"testing" | ||
|
||
"github.com/hexops/gotextdiff" | ||
"github.com/hexops/gotextdiff/myers" | ||
"github.com/hexops/gotextdiff/span" | ||
"github.com/tdemin/gmnhg/internal/gmnhg" | ||
) | ||
|
||
var fileList []string | ||
|
||
var ( | ||
mdFilenameRegex = regexp.MustCompile(`^(.+)\.md$`) | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
// go test implicitly sets cwd to tested package directory; sadly, | ||
// this fact is undocumented | ||
files, err := ioutil.ReadDir("testdata") | ||
if err != nil { | ||
panic(err) | ||
} | ||
for _, fileInfo := range files { | ||
if match := mdFilenameRegex.FindStringSubmatch(fileInfo.Name()); !fileInfo.IsDir() && match != nil { | ||
fileList = append(fileList, match[1]) | ||
} | ||
} | ||
os.Exit(m.Run()) | ||
} | ||
|
||
func TestRenderer(t *testing.T) { | ||
for _, testName := range fileList { | ||
t.Logf("testing %s", testName) | ||
mdContents, err := ioutil.ReadFile(path.Join("testdata", testName+".md")) | ||
if err != nil { | ||
t.Fatalf("failed to open Markdown test %s: %v", testName, err) | ||
} | ||
gmiContents, err := ioutil.ReadFile(path.Join("testdata", testName+".gmi")) | ||
if err != nil { | ||
t.Logf("%s: cannot open Gemtext file, skipping: %v", testName, err) | ||
continue | ||
} | ||
content, _ := gmnhg.ParseMetadata(mdContents) | ||
geminiContent, err := RenderMarkdown(content, Defaults) | ||
if err != nil { | ||
t.Errorf("failed to convert %s Markdown to Gemtext: %v", testName, err) | ||
} | ||
if !bytes.Equal(geminiContent, gmiContents) { | ||
diff := myers.ComputeEdits(span.URIFromPath("a.gmi"), | ||
string(geminiContent), string(gmiContents)) | ||
t.Errorf("content mismatch on %s, diff:\n%s", testName, | ||
gotextdiff.ToUnified("a.gmi", "b.gmi", string(geminiContent), diff)) | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
gmnhg test suite should parse the metadata above but disregard it. |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"title": "JSON front matter test", | ||
"draft": true | ||
} | ||
|
||
gmnhg test suite should parse the metadata above but disregard it. |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
gmnhg test suite should parse the metadata above but disregard it. |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#+title: "ORG front matter test" | ||
#+draft: true | ||
#+tags[]: org,gmnhg,emacs | ||
|
||
gmnhg test suite should parse the metadata above but disregard it. |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
gmnhg test suite should parse the metadata above but disregard it. |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
+++ | ||
title = "TOML front matter test" | ||
draft = true | ||
+++ | ||
|
||
gmnhg test suite should parse the metadata above but disregard it. |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
gmnhg test suite should parse the metadata above but disregard it. |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
title: "YAML front matter test" | ||
draft: true | ||
--- | ||
|
||
gmnhg test suite should parse the metadata above but disregard it. |
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 |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# General text | ||
|
||
Paragraphs are printed verbatim in gmnhg. | ||
|
||
Single newlines (like in this multi-line paragraph) will get replaced by a space, as Gemini specification p. 5.4.1 recommends this for soft-wrapping text by clients. | ||
|
||
Inline formatting bits (like this **bold** text, *emphasized* text, ~~strikethrough~~ text, `preformatted text`) are kept to make sure Gemini readers still have the stylistic context of your text. | ||
|
||
## Blockquotes | ||
|
||
Newlines in blockquote paragraphs, unlike usual paragraphs, aren't replaced with a space. This facilitates appending authorship information to the quote, or using blockquotes to write poems. | ||
|
||
> "Never trouble another for what you can do yourself" | ||
> — Thomas Jefferson, 3rd president of the US | ||
|
||
> "Wow, writing comprehensive test suites is hard!" | ||
> — Timur Demin, while writing this very test file | ||
|
||
> "Somehow I know these two paragraphs will be broken into two separate | ||
> blockquotes by gmnhg. I think my knowledge of that comes from being | ||
> the author of this program." | ||
|
||
> — also Timur Demin, in the process of writing this test file | ||
|
||
## Code | ||
|
||
gmnhg will use Gemtext preformatted blocks for that. Markdown alt-text for preformatted blocks is supported, and is used to render alt-text as specified by Gemini spec p. 5.4.3. | ||
|
||
```go | ||
package main | ||
func main() { | ||
println("gmnhg is awesome!") | ||
} | ||
``` | ||
|
||
Preformatted Markdown of course isn't rendered: | ||
|
||
``` | ||
# I am a test Markdown document | ||
I contain text in **bold**. | ||
``` | ||
|
||
## Links | ||
|
||
gmnhg supports links, images, and footnotes. Links are a very interesting topic on itself; see a separate document for those. | ||
|
||
=> links.md separate document | ||
|
||
## Lists | ||
|
||
Definition lists, numbered and ordered lists are all supported in gmnhg. There's also a separate document displaying those. | ||
|
||
=> lists.md separate document | ||
|
||
## Tables | ||
|
||
Markdown tables are supported in gmnhg, and are better displayed by a separate document. | ||
|
||
=> tables.md separate document | ||
|
||
## Headings | ||
|
||
Gemini specification allows up to three heading levels, with an optional space after the last heading symbol, `#`. With Markdown, you get 6; gmnhg will simply print the relevant number of #-s, making the client up to parse more heading levels and keeping context of the source document. | ||
|
||
Since clients like Lagrange treat the fourth and the rest of #-s as heading content, it's best to avoid using H4-H6 in Gemini-aware Markdown entirely. Headings from H3 to H6 are provided below so you can test how your client handles that. | ||
|
||
### Heading 3 | ||
|
||
#### Heading 4 | ||
|
||
##### Heading 5 | ||
|
||
###### Heading 6 | ||
|
||
## Misc | ||
|
||
Inline HTML is currently stripped, but HTML contents remain on-screen. This may change in the future. | ||
|
||
> There's currently a bug in gmnhg which prevents it from | ||
> stripping HTML in certain scenarios. HTML is noticeably still present | ||
> inside <span>blockquotes</span>. | ||
|
||
=> https://github.com/tdemin/gmnhg/issues/6 bug in gmnhg | ||
|
||
--- | ||
|
||
The Markdown horizontal line above is rendered as triple dashes. |
Oops, something went wrong.