1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
13 var headingTests
= []struct {
18 {"A typical usage", true},
19 {"ΔΛΞ is Greek", true},
23 {"A typical usage:", false},
24 {"This code:", false},
25 {"δ is Greek", false},
27 {"Fermat's Last Sentence", true},
30 {"Ted 'Too' Bar", false},
36 func TestIsHeading(t
*testing
.T
) {
37 for _
, tt
:= range headingTests
{
38 if h
:= heading(tt
.line
); (len(h
) > 0) != tt
.ok
{
39 t
.Errorf("isHeading(%q) = %v, want %v", tt
.line
, h
, tt
.ok
)
44 var blocksTests
= []struct {
83 {opPara
, []string{"Para 1.\n", "Para 1 line 2.\n"}},
84 {opPara
, []string{"Para 2.\n"}},
85 {opHead
, []string{"Section"}},
86 {opPara
, []string{"Para 3.\n"}},
87 {opPre
, []string{"pre\n", "pre1\n"}},
88 {opPara
, []string{"Para 4.\n"}},
89 {opPre
, []string{"pre\n", "pre1\n", "\n", "pre2\n"}},
90 {opPara
, []string{"Para 5.\n"}},
91 {opPre
, []string{"pre\n", "\n", "\n", "pre1\n", "pre2\n"}},
92 {opPara
, []string{"Para 6.\n"}},
93 {opPre
, []string{"pre\n", "pre2\n"}},
95 text
: `. Para 1. Para 1 line 2.
130 func TestBlocks(t
*testing
.T
) {
131 for i
, tt
:= range blocksTests
{
133 if !reflect
.DeepEqual(b
, tt
.out
) {
134 t
.Errorf("#%d: mismatch\nhave: %v\nwant: %v", i
, b
, tt
.out
)
139 func TestToText(t
*testing
.T
) {
141 for i
, tt
:= range blocksTests
{
142 ToText(&buf
, tt
.in
, ". ", "$\t", 40)
143 if have
:= buf
.String(); have
!= tt
.text
{
144 t
.Errorf("#%d: mismatch\nhave: %s\nwant: %s\nhave vs want:\n%q\n%q", i
, have
, tt
.text
, have
, tt
.text
)
150 var emphasizeTests
= []struct {
153 {"http://[::1]:8080/foo.txt", `<a href="http://[::1]:8080/foo.txt">http://[::1]:8080/foo.txt</a>`},
154 {"before (https://www.google.com) after", `before (<a href="https://www.google.com">https://www.google.com</a>) after`},
155 {"before https://www.google.com:30/x/y/z:b::c. After", `before <a href="https://www.google.com:30/x/y/z:b::c">https://www.google.com:30/x/y/z:b::c</a>. After`},
156 {"http://www.google.com/path/:;!-/?query=%34b#093124", `<a href="http://www.google.com/path/:;!-/?query=%34b#093124">http://www.google.com/path/:;!-/?query=%34b#093124</a>`},
157 {"http://www.google.com/path/:;!-/?query=%34bar#093124", `<a href="http://www.google.com/path/:;!-/?query=%34bar#093124">http://www.google.com/path/:;!-/?query=%34bar#093124</a>`},
158 {"http://www.google.com/index.html! After", `<a href="http://www.google.com/index.html">http://www.google.com/index.html</a>! After`},
159 {"http://www.google.com/", `<a href="http://www.google.com/">http://www.google.com/</a>`},
160 {"https://www.google.com/", `<a href="https://www.google.com/">https://www.google.com/</a>`},
161 {"http://www.google.com/path.", `<a href="http://www.google.com/path">http://www.google.com/path</a>.`},
162 {"http://en.wikipedia.org/wiki/Camellia_(cipher)", `<a href="http://en.wikipedia.org/wiki/Camellia_(cipher)">http://en.wikipedia.org/wiki/Camellia_(cipher)</a>`},
163 {"(http://www.google.com/)", `(<a href="http://www.google.com/">http://www.google.com/</a>)`},
164 {"http://gmail.com)", `<a href="http://gmail.com">http://gmail.com</a>)`},
165 {"((http://gmail.com))", `((<a href="http://gmail.com">http://gmail.com</a>))`},
166 {"http://gmail.com ((http://gmail.com)) ()", `<a href="http://gmail.com">http://gmail.com</a> ((<a href="http://gmail.com">http://gmail.com</a>)) ()`},
167 {"Foo bar http://example.com/ quux!", `Foo bar <a href="http://example.com/">http://example.com/</a> quux!`},
168 {"Hello http://example.com/%2f/ /world.", `Hello <a href="http://example.com/%2f/">http://example.com/%2f/</a> /world.`},
169 {"Lorem http: ipsum //host/path", "Lorem http: ipsum //host/path"},
170 {"javascript://is/not/linked", "javascript://is/not/linked"},
171 {"http://git.qemu.org/?p=qemu.git;a=blob;f=qapi-schema.json;hb=HEAD", `<a href="http://git.qemu.org/?p=qemu.git;a=blob;f=qapi-schema.json;hb=HEAD">http://git.qemu.org/?p=qemu.git;a=blob;f=qapi-schema.json;hb=HEAD</a>`},
174 func TestEmphasize(t
*testing
.T
) {
175 for i
, tt
:= range emphasizeTests
{
177 emphasize(&buf
, tt
.in
, nil, true)
180 t
.Errorf("#%d: mismatch\nhave: %v\nwant: %v", i
, out
, tt
.out
)
185 var pairedParensPrefixLenTests
= []struct {
192 {"foo()()()", "foo()()()"},
193 {"foo()((()()))", "foo()((()()))"},
194 {"foo()((()()))bar", "foo()((()()))bar"},
202 {"((((foo))))", "((((foo))))"},
203 {"foo()())", "foo()()"},
204 {"foo((()())", "foo"},
205 {"foo((()())) (() foo ", "foo((()())) "},
208 func TestPairedParensPrefixLen(t
*testing
.T
) {
209 for i
, tt
:= range pairedParensPrefixLenTests
{
210 if out
:= tt
.in
[:pairedParensPrefixLen(tt
.in
)]; out
!= tt
.out
{
211 t
.Errorf("#%d: mismatch\nhave: %q\nwant: %q", i
, out
, tt
.out
)