package nip54 import ( "fmt" "strings" "testing" ) func TestNormalization(t *testing.T) { for _, vector := range []struct { before string after string }{ {" hello ", "hello"}, {"Goodbye", "goodbye"}, {"the long and winding road / that leads to your door", "the-long-and-winding-road---that-leads-to-your-door"}, {"it's 平仮名", "it-s-平仮名"}, } { if norm := NormalizeIdentifier(vector.before); norm != vector.after { fmt.Println([]byte(vector.after), []byte(norm)) t.Fatalf("%s: %s != %s", vector.before, norm, vector.after) } } } func TestArticleAsHTML(t *testing.T) { tests := []struct { name string input string contains []string }{ { name: "simple paragraph", input: "Hello world", contains: []string{"

", "Hello world", "

"}, }, { name: "emphasis", input: "*Hello* _world_", contains: []string{"", "Hello", "", "", "world", ""}, }, { name: "heading", input: "# Title", contains: []string{"

", "Title", "

"}, }, {name: "example 1", input: "_This is *regular_ not strong* emphasis", contains: []string{"

This is *regular not strong* emphasis

"}}, {name: "example 2", input: "*This is _strong* not regular_ emphasis", contains: []string{"

This is _strong not regular_ emphasis

"}}, {name: "example 3", input: "[Link *](url)*", contains: []string{"

Link **

"}}, {name: "example 4", input: "*Emphasis [*](url)", contains: []string{"

Emphasis [](url)

"}}, {name: "example 5", input: "_This is *strong within* regular emphasis_", contains: []string{"

This is strong within regular emphasis

"}}, {name: "example 6", input: "{_Emphasized_}\n_}not emphasized{_", contains: []string{"

Emphasized\n_}not emphasized{_

"}}, {name: "example 7", input: "*not strong *strong*", contains: []string{"

*not strong strong

"}}, {name: "example 8", input: "[My link text](http://example.com)", contains: []string{"

My link text

"}}, {name: "example 9", input: "[My link text](http://example.com?product_number=234234234234\n234234234234)", contains: []string{"

My link text

"}}, {name: "example 10", input: "[My link text][foo bar]\n\n[foo bar]: http://example.com", contains: []string{"

My link text

"}}, {name: "example 11", input: "[foo][bar]", contains: []string{"

foo

"}}, {name: "example 12", input: "[My link text][]\n\n[My link text]: /url", contains: []string{"

My link text

"}}, {name: "example 13", input: "![picture of a cat](cat.jpg)\n\n![picture of a cat][cat]\n\n![cat][]\n\n[cat]: feline.jpg", contains: []string{"

\"picture

\n

\"picture

\n

\"cat\"

"}}, {name: "example 14", input: "\n", contains: []string{"

https://pandoc.org/lua-filters\nme@example.com

"}}, {name: "example 15", input: "``Verbatim with a backtick` character``\n`Verbatim with three backticks ``` character`", contains: []string{"

Verbatim with a backtick` character\nVerbatim with three backticks ``` character

"}}, {name: "example 16", input: "`` `foo` ``", contains: []string{"

`foo`

"}}, {name: "example 17", input: "`foo bar", contains: []string{"

foo bar

"}}, {name: "example 18", input: "_emphasized text_\n\n*strong emphasis*", contains: []string{"

emphasized text

\n

strong emphasis

"}}, {name: "example 19", input: "_ Not emphasized (spaces). _\n\n___ (not an emphasized `_` character)", contains: []string{"

_ Not emphasized (spaces). _

\n

___ (not an emphasized _ character)

"}}, {name: "example 20", input: "__emphasis inside_ emphasis_", contains: []string{"

emphasis inside emphasis

"}}, {name: "example 21", input: "{_ this is emphasized, despite the spaces! _}", contains: []string{"

this is emphasized, despite the spaces!

"}}, {name: "example 22", input: "This is {=highlighted text=}.", contains: []string{"

This is highlighted text.

"}}, {name: "example 23", input: "H~2~O and djot^TM^", contains: []string{"

H2O and djotTM

"}}, {name: "example 24", input: "H{~one two buckle my shoe~}O", contains: []string{"

Hone two buckle my shoeO

"}}, {name: "example 25", input: "My boss is {-mean-}{+nice+}.", contains: []string{"

My boss is meannice.

"}}, {name: "example 26", input: "\"Hello,\" said the spider.\n\"'Shelob' is my name.\"", contains: []string{"

“Hello,” said the spider.\n“‘Shelob’ is my name.”

"}}, {name: "example 27", input: "'}Tis Socrates' season to be jolly!", contains: []string{"

’Tis Socrates’ season to be jolly!

"}}, {name: "example 28", input: "5\\'11\\\"", contains: []string{"

5'11\"

"}}, {name: "example 29", input: "57--33 oxen---and no sheep...", contains: []string{"

57–33 oxen—and no sheep…

"}}, {name: "example 30", input: "a----b c------d", contains: []string{"

a––b c——d

"}}, {name: "example 31", input: "Einstein derived $`e=mc^2`.\nPythagoras proved\n$$` x^n + y^n = z^n `", contains: []string{"

Einstein derived \\(e=mc^2\\).\nPythagoras proved\n\\[ x^n + y^n = z^n \\]

"}}, {name: "example 32", input: "Here is the reference.[^foo]\n\n[^foo]: And here is the note.", contains: []string{"

Here is the reference.1

\n
\n
\n
    \n
  1. \n

    And here is the note.↩︎︎

    \n
  2. \n
\n
"}}, {name: "example 33", input: "This is a soft\nbreak and this is a hard\\\\\\nbreak.", contains: []string{"This is a soft", "break and this is a hard", "break."}}, {name: "example 34", input: "{#ident % later we'll add a class %}", contains: []string{""}}, {name: "example 35", input: "Foo bar {% This is a comment, spanning\nmultiple lines %} baz.", contains: []string{"

Foo bar baz.

"}}, {name: "example 36", input: "My reaction is :+1: :smiley:.", contains: []string{"

My reaction is :+1: :smiley:.

"}}, {name: "example 37", input: "This is ``{=html}.", contains: []string{"

This is .

"}}, {name: "example 38", input: "It can be helpful to [read the manual]{.big .red}.", contains: []string{"

It can be helpful to read the manual.

"}}, {name: "example 39", input: "An attribute on _emphasized text_{#foo\n.bar .baz key=\"my value\"}", contains: []string{"

An attribute on emphasized text

"}}, {name: "example 40", input: "avant{lang=fr}{.blue}", contains: []string{"

avant

"}}, {name: "example 41", input: "avant{lang=fr .blue}", contains: []string{"

avant

"}}, {name: "example 42", input: "## A level _two_ heading!", contains: []string{"
\n

A level two heading!

\n
"}}, {name: "example 43", input: "# A heading that\n# takes up\n# three lines\n\nA paragraph, finally", contains: []string{"
\n

A heading that\ntakes up\nthree lines

\n

A paragraph, finally

\n
"}}, {name: "example 44", input: "# A heading that\ntakes up\nthree lines\n\nA paragraph, finally.", contains: []string{"
\n

A heading that\ntakes up\nthree lines

\n

A paragraph, finally.

\n
"}}, {name: "example 45", input: "> This is a block quote.\n>\n> 1. with a\n> 2. list in it.", contains: []string{"
\n

This is a block quote.

\n
    \n
  1. \nwith a\n
  2. \n
  3. \nlist in it.\n
  4. \n
\n
"}}, {name: "example 46", input: "> This is a block\nquote.", contains: []string{"
\n

This is a block\nquote.

\n
"}}, {name: "example 47", input: "1. This is a\n list item.\n\n > containing a block quote", contains: []string{"
    \n
  1. \n

    This is a\nlist item.

    \n
    \n

    containing a block quote

    \n
    \n
  2. \n
"}}, {name: "example 48", input: "1. This is a\nlist item.\n\n Second paragraph under the\nlist item.", contains: []string{"
    \n
  1. \n

    This is a\nlist item.

    \n

    Second paragraph under the\nlist item.

    \n
  2. \n
"}}, {name: "example 49", input: ": orange\n\n A citrus fruit.", contains: []string{"
\n
orange
\n
\n

A citrus fruit.

\n
\n
"}}, {name: "example 50", input: "i) one\ni. one (style change)\n+ bullet\n* bullet (style change)", contains: []string{"
    \n
  1. \none\n
  2. \n
\n
    \n
  1. \none (style change)\n
  2. \n
\n\n"}}, {name: "example 51", input: "i. item\nj. next item", contains: []string{"
    \n
  1. \nitem\n
  2. \n
  3. \nnext item\n
  4. \n
"}}, {name: "example 52", input: "5) five\n8) six", contains: []string{"
    \n
  1. \nfive\n
  2. \n
  3. \nsix\n
  4. \n
"}}, {name: "example 53", input: "- one\n- two\n\n - sub\n - sub", contains: []string{""}}, {name: "example 54", input: "- one\n\n- two", contains: []string{""}}, {name: "example 55", input: "````\nThis is how you do a code block:\n\n``` ruby\nx = 5 * 6\n```\n````", contains: []string{"
This is how you do a code block:\n\n``` ruby\nx = 5 * 6\n```\n
"}}, {name: "example 56", input: "> ```\n> code in a\n> block quote\n\nParagraph.", contains: []string{"
\n
code in a\nblock quote\n
\n
\n

Paragraph.

"}}, {name: "example 57", input: "Then they went to sleep.\n\n * * * *\n\nWhen they woke up, ...", contains: []string{"

Then they went to sleep.

\n
\n

When they woke up, …

"}}, {name: "example 58", input: "``` =html\n\n```", contains: []string{""}}, {name: "example 59", input: "::: warning\nHere is a paragraph.\n\nAnd here is another.\n:::", contains: []string{"
\n

Here is a paragraph.

\n

And here is another.

\n
"}}, {name: "example 60", input: "| 1 | 2 |", contains: []string{"\n\n\n\n\n
12
"}}, {name: "example 61", input: "| fruit | price |\n|--------|------:|\n| apple | 4 |\n| banana | 10 |", contains: []string{"\n\n\n\n\n\n\n\n\n\n\n\n\n
fruitprice
apple4
banana10
"}}, {name: "example 62", input: "| a | b |\n|----|:--:|\n| 1 | 2 |\n|:---|---:|\n| 3 | 4 |", contains: []string{"\n\n\n\n\n\n\n\n\n\n\n\n\n
ab
12
34
"}}, {name: "example 63", input: "| just two \\| `|` | cells in this table |", contains: []string{"\n\n\n\n\n
just two | |cells in this table
"}}, {name: "example 64", input: "^ This is the caption. It can contain _inline formatting_\n and can extend over multiple lines, provided they are\n indented relative to the `^`.", contains: []string{""}}, {name: "example 65", input: "[google]: https://google.com\n\n[product page]: http://example.com?item=983459873087120394870128370\n 0981234098123048172304", contains: []string{""}}, {name: "example 66", input: "{title=foo}\n[ref]: /url\n\n[ref][]", contains: []string{"

ref

"}}, {name: "example 67", input: "{title=foo}\n[ref]: /url\n\n[ref][]{title=bar}", contains: []string{"

ref

"}}, {name: "example 68", input: "Here's the reference.[^foo]\n\n[^foo]: This is a note\n with two paragraphs.\n\n Second paragraph.\n\n > a block quote in the note.", contains: []string{"

Here’s the reference.1

\n
\n
\n
    \n
  1. \n

    This is a note\nwith two paragraphs.

    \n

    Second paragraph.

    \n
    \n

    a block quote in the note.

    \n
    \n

    ↩︎︎

    \n
  2. \n
\n
"}}, {name: "example 69", input: "Here's the reference.[^foo]\n\n[^foo]: This is a note\nwith two paragraphs.\n\n Second paragraph must\nbe indented, at least in the first line.", contains: []string{"

Here’s the reference.1

\n
\n
\n
    \n
  1. \n

    This is a note\nwith two paragraphs.

    \n

    Second paragraph must\nbe indented, at least in the first line.↩︎︎

    \n
  2. \n
\n
"}}, {name: "example 70", input: "{#water}\n{.important .large}\nDon't forget to turn off the water!\n\n{source=\"Iliad\"}\n> Sing, muse, of the wrath of Achilles", contains: []string{"

Don’t forget to turn off the water!

\n
\n

Sing, muse, of the wrath of Achilles

\n
"}}, {name: "example 71", input: "## My heading + auto-identifier", contains: []string{"
\n

My heading + auto-identifier

\n
"}}, {name: "example 72", input: "See the [Epilogue][].\n\n * * * *\n\n# Epilogue", contains: []string{"

See the Epilogue.

\n
\n
\n

Epilogue

\n
"}}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { result := ArticleAsHTML(tt.input) t.Log("[input]: " + tt.input) t.Log("[result]: " + result) for _, expected := range tt.contains { t.Log("[expected]: " + expected) if !strings.Contains(result, expected) { t.Errorf("ArticleAsHTML() output does not contain %q\nGot: %s", expected, result) } } }) } }