From be0fb4602b8113ab16b70ab34fe48c0573bd65ef Mon Sep 17 00:00:00 2001 From: Russ Ross Date: Fri, 24 Jun 2011 16:39:50 -0600 Subject: [PATCH] more inline unit tests --- inline.go | 2 +- inline_test.go | 188 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 189 insertions(+), 1 deletion(-) diff --git a/inline.go b/inline.go index 24f793c..8fdf606 100644 --- a/inline.go +++ b/inline.go @@ -692,7 +692,7 @@ func tagLength(data []byte, autolink *int) int { // scheme test *autolink = LINK_TYPE_NOT_AUTOLINK - // try to find the beggining of an URI + // try to find the beginning of an URI for i < len(data) && (isalnum(data[i]) || data[i] == '.' || data[i] == '+' || data[i] == '-') { i++ } diff --git a/inline_test.go b/inline_test.go index 42088d4..aa401ec 100644 --- a/inline_test.go +++ b/inline_test.go @@ -262,3 +262,191 @@ func TestLineBreak(t *testing.T) { } doTests(t, tests) } + +func TestInlineLink(t *testing.T) { + var tests = []string{ + "[foo](/bar/)\n", + "

foo

\n", + + "[foo with a title](/bar/ \"title\")\n", + "

foo with a title

\n", + + "[foo with a title](/bar/\t\"title\")\n", + "

foo with a title

\n", + + "[foo with a title](/bar/ \"title\" )\n", + "

foo with a title

\n", + + "[foo with a title](/bar/ title with no quotes)\n", + "

foo with a title

\n", + + "[foo]()\n", + "

foo

\n", + + "![foo](/bar/)\n", + "

\"foo\"\n

\n", + + "![foo with a title](/bar/ \"title\")\n", + "

\"foo\n

\n", + + "![foo with a title](/bar/\t\"title\")\n", + "

\"foo\n

\n", + + "![foo with a title](/bar/ \"title\" )\n", + "

\"foo\n

\n", + + "![foo with a title](/bar/ title with no quotes)\n", + "

\"foo\n

\n", + + "![foo]()\n", + "

[foo]()

\n", + + "[a link]\t(/with_a_tab/)\n", + "

a link

\n", + + "[a link] (/with_spaces/)\n", + "

a link

\n", + + "[text (with) [[nested] (brackets)]](/url/)\n", + "

text (with) [[nested] (brackets)]

\n", + + "[text (with) [broken nested] (brackets)]](/url/)\n", + "

[text (with) broken nested]](/url/)

\n", + + "[text\nwith a newline](/link/)\n", + "

text\nwith a newline

\n", + + "[text in brackets] [followed](/by a link/)\n", + "

[text in brackets] followed

\n", + + "[link with\\] a closing bracket](/url/)\n", + "

link with] a closing bracket

\n", + + "[link with\\[ an opening bracket](/url/)\n", + "

link with[ an opening bracket

\n", + + "[link with\\) a closing paren](/url/)\n", + "

link with) a closing paren

\n", + + "[link with\\( an opening paren](/url/)\n", + "

link with( an opening paren

\n", + + "[link]( with whitespace)\n", + "

link

\n", + + "[link]( with whitespace )\n", + "

link

\n", + + "[link](url \"one quote)\n", + "

link

\n", + + "[link](url 'one quote)\n", + "

link

\n", + + "[link]()\n", + "

link

\n", + + "[link & ampersand](/url/)\n", + "

link & ampersand

\n", + + "[link & ampersand](/url/)\n", + "

link & ampersand

\n", + + "[link](/url/&query)\n", + "

link

\n", + } + doTests(t, tests) +} + +func TestReferenceLink(t *testing.T) { + var tests = []string{ + "[link][ref]\n", + "

[link][ref]

\n", + + "[link][ref]\n [ref]: /url/ \"title\"\n", + "

link

\n", + + "[link][ref]\n [ref]: /url/\n", + "

link

\n", + + " [ref]: /url/\n", + "", + + " [ref]: /url/\n[ref2]: /url/\n [ref3]: /url/\n", + "", + + " [ref]: /url/\n[ref2]: /url/\n [ref3]: /url/\n [4spaces]: /url/\n", + "
[4spaces]: /url/\n
\n", + + "[hmm](ref2)\n [ref]: /url/\n[ref2]: /url/\n [ref3]: /url/\n", + "

hmm

\n", + + "[ref]\n", + "

[ref]

\n", + + "[ref]\n [ref]: /url/ \"title\"\n", + "

ref

\n", + } + doTests(t, tests) +} + +func TestTags(t *testing.T) { + var tests = []string{ + "a tag\n", + "

a tag

\n", + + "tag\n", + "

tag

\n", + + "mismatch\n", + "

mismatch

\n", + + "a tag\n", + "

a tag

\n", + } + doTests(t, tests) +} + +func TestAutoLink(t *testing.T) { + var tests = []string{ + "go to \n", + "

go to http://foo.com/

\n", + + "a secure \n", + "

a secure https://link.org

\n", + + "an email \n", + "

an email some@one.com

\n", + + "an email \n", + "

an email some@one.com

\n", + + "an email \n", + "

an email some@one.com

\n", + + "an ftp \n", + "

an ftp ftp://old.com

\n", + + "an ftp \n", + "

an ftp ftp:old.com

\n", + + "a link with \n", + "

a link with " + + "http://new.com?query=foo&bar

\n", + + "quotes mean a tag \n", + "

quotes mean a tag

\n", + + "quotes mean a tag \n", + "

quotes mean a tag

\n", + + "unless escaped \n", + "

unless escaped " + + "http://new.com?query="foo"&bar

\n", + + "even a > can be escaped &etc>\n", + "

even a > can be escaped " + + "http://new.com?q=>&etc

\n", + } + doTests(t, tests) +}