diff options
| -rw-r--r-- | markdown/ast_code_test.go | 33 | ||||
| -rw-r--r-- | markdown/ast_external_test.go | 34 | ||||
| -rw-r--r-- | markdown/ast_list_test.go | 17 | ||||
| -rw-r--r-- | markdown/ast_modifier_test.go | 19 | ||||
| -rw-r--r-- | markdown/ast_paragraph_test.go | 37 | ||||
| -rw-r--r-- | markdown/ast_quote_test.go | 22 | ||||
| -rw-r--r-- | markdown/ast_test.go | 29 |
7 files changed, 58 insertions, 133 deletions
diff --git a/markdown/ast_code_test.go b/markdown/ast_code_test.go index b116544..f9c57f3 100644 --- a/markdown/ast_code_test.go +++ b/markdown/ast_code_test.go @@ -3,31 +3,10 @@ package markdown import "testing" func TestCode(t *testing.T) { - got, err := Parse("`mono`", nil) - if err != nil { - t.Fatal(err) - } - if string(got) != `<p><code>mono</code></p>` { - t.Errorf("invalid value, got %s", got) - } - - got, err = Parse("bonjour `code` !", nil) - if err != nil { - t.Fatal(err) - } - if string(got) != `<p>bonjour <code>code</code> !</p>` { - t.Errorf("invalid value, got %s", got) - } - - got, err = Parse( - "```\n"+"raw\nhehe"+"```", - nil, - ) - if err != nil { - t.Fatal(err) - } - if string(got) != `<pre><code>raw -hehe</code></pre>` { - t.Errorf("invalid value, got %s", got) - } + t.Run("code", func(t *testing.T) { + t.Run("mono", test("`mono`", `<p><code>mono</code></p>`)) + t.Run("combo", test("bonjour `code` !", `<p>bonjour <code>code</code> !</p>`)) + t.Run("mult-line", test("```\n"+"raw\nhehe"+"```", `<pre><code>raw +hehe</code></pre>`)) + }) } diff --git a/markdown/ast_external_test.go b/markdown/ast_external_test.go index c31c233..ec9dd29 100644 --- a/markdown/ast_external_test.go +++ b/markdown/ast_external_test.go @@ -3,35 +3,19 @@ package markdown import "testing" func TestExternal(t *testing.T) { - got, err := Parse("[content](href)", nil) - if err != nil { - t.Fatal(err) - } - if string(got) != `<p><a href="href">content</a></p>` { - t.Errorf("invalid value, got %s", got) - } - - got, err = Parse("", nil) - if err != nil { - t.Fatal(err) - } - if string(got) != `<figure><img alt="image alt" src="image src" /></figure>` { - t.Errorf("invalid value, got %s", got) - } - - got, err = Parse(` + t.Run("link", func(t *testing.T) { + t.Run("simple", test("[content](href)", `<p><a href="href">content</a></p>`)) + t.Run("combo", test("Hey, [link](href)", `<p>Hey, <a href="href">link</a></p>`)) + }) + t.Run("image", func(t *testing.T) { + t.Run("simple", test("", `<figure><img alt="image alt" src="image src" /></figure>`)) + t.Run("combo", test(` Avant la source  source 1 source 2 Hors de la source -`, nil) - if err != nil { - t.Fatal(err) - } - if string(got) != `<p>Avant la source</p><figure><img alt="image alt" src="image src" /><figcaption>source 1 source 2</figcaption></figure><p>Hors de la source</p>` { - t.Errorf("invalid value, got %s", got) - } - +`, `<p>Avant la source</p><figure><img alt="image alt" src="image src" /><figcaption>source 1 source 2</figcaption></figure><p>Hors de la source</p>`)) + }) } diff --git a/markdown/ast_list_test.go b/markdown/ast_list_test.go index 210a83a..6ecfc25 100644 --- a/markdown/ast_list_test.go +++ b/markdown/ast_list_test.go @@ -27,18 +27,7 @@ var expected = ` ` func TestList(t *testing.T) { - lxs := lex(rw, new(Option)) - tree, err := ast(lxs) - if err != nil { - t.Fatal(err) - } - got, err := tree.Eval(nil) - if err != nil { - t.Fatal(err) - } - exp := strings.ReplaceAll(expected, "\n", "") - if string(got) != exp { - t.Errorf("invalid value, got %s", got) - t.Logf("expected %s", exp) - } + t.Run("lists", func(t *testing.T) { + t.Run("combo", test(rw, strings.ReplaceAll(expected, "\n", ""))) + }) } diff --git a/markdown/ast_modifier_test.go b/markdown/ast_modifier_test.go index 3689657..acb9f40 100644 --- a/markdown/ast_modifier_test.go +++ b/markdown/ast_modifier_test.go @@ -3,20 +3,7 @@ package markdown import "testing" func TestModifier(t *testing.T) { - content := ` -**bo*n*soir**, ça ***va* bien** ? -` - lxs := lex(content, new(Option)) - tree, err := ast(lxs) - if err != nil { - t.Fatal(err) - } - c, err := tree.Eval(nil) - if err != nil { - t.Fatal(err) - } - if c != "<p><b>bo<em>n</em>soir</b>, ça <b><em>va</em> bien</b> ?</p>" { - t.Errorf("failed, got %s", c) - t.Logf("lxs: %s\ntree: %s", lxs, tree) - } + t.Run("modifiers", func(t *testing.T) { + t.Run("combo", test(`**bo*n*soir**, ça ***va* bien** ?`, `<p><b>bo<em>n</em>soir</b>, ça <b><em>va</em> bien</b> ?</p>`)) + }) } diff --git a/markdown/ast_paragraph_test.go b/markdown/ast_paragraph_test.go index 2014ab9..ab3ab6c 100644 --- a/markdown/ast_paragraph_test.go +++ b/markdown/ast_paragraph_test.go @@ -3,31 +3,14 @@ package markdown import "testing" func TestParagraph(t *testing.T) { - c, err := Parse("bonsoir", nil) - if err != nil { - t.Fatal(err) - } - if c != "<p>bonsoir</p>" { - t.Errorf("failed, got %s", c) - } -} - -func TestParagraph_Replacer(t *testing.T) { - opt := &Option{ - Replaces: map[rune]string{'~': " "}, - } - c, err := Parse("bonsoir", opt) - if err != nil { - t.Fatal(err) - } - if c != "<p>bonsoir</p>" { - t.Errorf("failed, got %s", c) - } - c, err = Parse("bonsoir~!", opt) - if err != nil { - t.Fatal(err) - } - if c != "<p>bonsoir !</p>" { - t.Errorf("failed, got %s", c) - } + t.Run("paragraph", func(t *testing.T) { + t.Run("simple", test("bonsoir", `<p>bonsoir</p>`)) + }) + t.Run("replacer", func(t *testing.T) { + opt := &Option{ + Replaces: map[rune]string{'~': " "}, + } + t.Run("empty", testWithOptions(opt, "bonsoir", `<p>bonsoir</p>`)) + t.Run("simple", testWithOptions(opt, "bonsoir~!", `<p>bonsoir !</p>`)) + }) } diff --git a/markdown/ast_quote_test.go b/markdown/ast_quote_test.go index 50ff23a..203d4fc 100644 --- a/markdown/ast_quote_test.go +++ b/markdown/ast_quote_test.go @@ -3,21 +3,13 @@ package markdown import "testing" func TestQuote(t *testing.T) { - content := ` + t.Run("quote", func(t *testing.T) { + t.Run("simple", test(` +> Bonsoir +`, `<div class="quote"><blockquote>Bonsoir</blockquote></div>`)) + t.Run("source", test(` > Bonsoir, je suis un **code** avec une source -` - lxs := lex(content, new(Option)) - tree, err := ast(lxs) - if err != nil { - t.Fatal(err) - } - c, err := tree.Eval(nil) - if err != nil { - t.Fatal(err) - } - if c != `<div class="quote"><blockquote>Bonsoir, je suis un <b>code</b></blockquote><p>avec une source</p></div>` { - t.Errorf("failed, got %s", c) - t.Logf("lxs: %s\ntree: %s", lxs, tree) - } +`, `<div class="quote"><blockquote>Bonsoir, je suis un <b>code</b></blockquote><p>avec une source</p></div>`)) + }) } diff --git a/markdown/ast_test.go b/markdown/ast_test.go index 8f701f4..ed2ef87 100644 --- a/markdown/ast_test.go +++ b/markdown/ast_test.go @@ -45,14 +45,25 @@ var parsed = ` </figure> ` -func TestAst(t *testing.T) { - res, err := Parse(raw, nil) - if err != nil { - t.Fatal(err) - } - wanted := strings.ReplaceAll(parsed, "\n", "") - if string(res) != wanted { - t.Errorf("invalid string, got\n%s", res) - t.Logf("wanted\n%s", wanted) +func test(input, expected string) func(*testing.T) { + return testWithOptions(nil, input, expected) +} + +func testWithOptions(opt *Option, input, expected string) func(*testing.T) { + return func(t *testing.T) { + t.Parallel() + got, err := Parse(input, opt) + if err != nil { + t.Fatal(err) + } + if string(got) != expected { + t.Errorf("invalid value, got %s", got) + } } } + +func TestAst(t *testing.T) { + t.Run("ast", func(t *testing.T) { + t.Run("complete", test(raw, strings.ReplaceAll(parsed, "\n", ""))) + }) +} |
