package parser import ( "strings" "testing" ) // Bugs found reviewing the inline parser; each test fails on 088606d5. // An email autolink in text after an entity or an escape gets the // offsets of the decoded text, not of the source. func TestReviewEmailOffsets(t *testing.T) { for _, src := range []string{"a & b x@y.com", `a \* b x@y.com`} { d := Parse(src) for _, in := range d.Inlines(1) { if in.Kind == Link { if got := d.Source()[in.Start:in.End]; got != "x@y.com" { t.Errorf("%q: link [%d,%d) is %q, want %q", src, in.Start, in.End, got, "x@y.com") } } } } } // Quadratic time: nested footnote-like brackets, $ math with // ExtDollarMath, and \( without \). func TestReviewQuadratic(t *testing.T) { checkLinear(t, "footnote brackets", Default, func(n int) string { return strings.Repeat("[^a", n) + strings.Repeat("]", n) }) checkLinear(t, "dollar openers", Default|ExtDollarMath, repeat("$a ")) checkLinear(t, "\\( openers", Default, repeat(`\(`)) } // HTML entities are only names of the table followed by ;, not a // legacy name's prefix. func TestReviewEntityPrefix(t *testing.T) { if got, want := render("©right; ¬it;", Default), "

&copyright; &notit;

\n"; got != want { t.Errorf("got %q, want %q", got, want) } } func TestReviewHealing(t *testing.T) { for _, c := range []struct{ src, want string }{ // A tilde for "about" strikes the rest of the paragraph through. {"about ~200 keys. See", "

about ~200 keys. See

\n"}, // Strong next to CJK text is not healed: ** shows. {"这是**重要", "

这是重要

\n"}, // An open code span skips healing emphasis: ** shows. {"Edit **`config.ya", "

Edit config.ya

\n"}, // $$ inside a code span counts as open math: $$ shows. {"Use `$$` for display math", "

Use $$ for display math

\n"}, // A destination with parentheses: raw syntax, and the added ) shows. {"See [Go](https://en.wikipedia.org/wiki/Go_(lang", `

See Go

` + "\n"}, // The text of a link being written shows its [. {"See the [Go blog", "

See the Go blog

\n"}, // Strikethrough being closed shows its tildes. {"a ~~struck~", "

a struck

\n"}, // A < destination: the added ) shows. {"see [a](see a

` + "\n"}, } { if got := streamed(c.src); got != c.want { t.Errorf("%q:\ngot %q\nwant %q", c.src, got, c.want) } } } // Extended autolinks end at punctuation beyond ASCII, such as the CJK // comma, and at spaces beyond ASCII, but not at letters beyond ASCII. func TestReviewAutolinkUnicodePunct(t *testing.T) { for _, c := range []struct{ src, want string }{ {"信中附上链接:https://vishnuai.in/mediakit,并留下电话联系方式。", `

信中附上链接:https://vishnuai.in/mediakit,并留下电话联系方式。

` + "\n"}, {"见 https://example.com/a。", `

见 https://example.com/a。

` + "\n"}, {"“www.example.com”", `

“www.example.com”

` + "\n"}, {"(www.example.com/路径)", `

(www.example.com/路径)

` + "\n"}, {"https://例子.测试/页面", `

https://例子.测试/页面

` + "\n"}, {"https://en.wikipedia.org/wiki/1990–91_season", `

https://en.wikipedia.org/wiki/1990–91_season

` + "\n"}, {"https://example.com\u3000下一句", `

https://example.com` + "\u3000下一句

\n"}, {"https://example.com\u2028下一句", `

https://example.com` + "\u2028下一句

\n"}, {"https://example.com/a\u2028下一句", `

https://example.com/a` + "\u2028下一句

\n"}, {"见\u2029www.example.com", "

见\u2029" + `www.example.com

` + "\n"}, {"邮箱:a@example.com,谢谢", `

邮箱:a@example.com,谢谢

` + "\n"}, // Written links keep their whole destination and text. {"[文档,下载](https://example.org/文档,下载)", `

文档,下载

` + "\n"}, {"[https://example.org/文档,下载](https://example.org/文档,下载)", `

https://example.org/文档,下载

` + "\n"}, {"", `

https://example.org/x,y

` + "\n"}, {"[见 https://example.org/a,b](https://c.org)", `

见 https://example.org/a,b

` + "\n"}, } { if got := render(c.src, Default); got != c.want { t.Errorf("%q:\ngot %q\nwant %q", c.src, got, c.want) } } }