10 // This file is a copy of go/doc/comment_test.go with the exception for
11 // the test cases for TestEmphasize and TestCommentEscape
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.
129 in: "Para.\n\tshould not be ``escaped''",
131 {opPara, []string{"Para.\n"}},
132 {opPre, []string{"should not be ``escaped''"}},
134 text: ". Para.\n\n$ should not be ``escaped''",
137 in: "// A very long line of 46 char for line wrapping.",
139 {opPara, []string{"// A very long line of 46 char for line wrapping."}},
141 text: `. // A very long line of 46 char for line
146 in: `/* A very long line of 46 char for line wrapping.
147 A very long line of 46 char for line wrapping. */`,
149 {opPara, []string{"/* A very long line of 46 char for line wrapping.\n", "A very long line of 46 char for line wrapping. */"}},
151 text: `. /* A very long line of 46 char for line
152 . wrapping. A very long line of 46 char
153 . for line wrapping. */
158 func TestBlocks(t *testing.T) {
159 for i, tt := range blocksTests {
161 if !reflect.DeepEqual(b, tt.out) {
162 t.Errorf("#%d: mismatch\nhave: %v\nwant: %v", i, b, tt.out)
167 // This has been modified from go/doc to use markdown links instead of html ones
168 // and use markdown escaping instead oh html
169 var emphasizeTests = []struct {
173 {"http://[::1]:8080/foo.txt", `[http\:\/\/\[\:\:1\]\:8080\/foo\.txt](http://[::1]:8080/foo.txt)`},
174 {"before (https://www.google.com) after", `before \([https\:\/\/www\.google\.com](https://www.google.com)\) after`},
175 {"before https://www.google.com:30/x/y/z:b::c. After", `before [https\:\/\/www\.google\.com\:30\/x\/y\/z\:b\:\:c](https://www.google.com:30/x/y/z:b::c)\. After`},
176 {"http://www.google.com/path/:;!-/?query=%34b#093124", `[http\:\/\/www\.google\.com\/path\/\:\;\!\-\/\?query\=\%34b\#093124](http://www.google.com/path/:;!-/?query=%34b#093124)`},
177 {"http://www.google.com/path/:;!-/?query=%34bar#093124", `[http\:\/\/www\.google\.com\/path\/\:\;\!\-\/\?query\=\%34bar\#093124](http://www.google.com/path/:;!-/?query=%34bar#093124)`},
178 {"http://www.google.com/index.html! After", `[http\:\/\/www\.google\.com\/index\.html](http://www.google.com/index.html)\! After`},
179 {"http://www.google.com/", `[http\:\/\/www\.google\.com\/](http://www.google.com/)`},
180 {"https://www.google.com/", `[https\:\/\/www\.google\.com\/](https://www.google.com/)`},
181 {"http://www.google.com/path.", `[http\:\/\/www\.google\.com\/path](http://www.google.com/path)\.`},
182 {"http://en.wikipedia.org/wiki/Camellia_(cipher)", `[http\:\/\/en\.wikipedia\.org\/wiki\/Camellia\_\(cipher\)](http://en.wikipedia.org/wiki/Camellia_\(cipher\))`},
183 {"(http://www.google.com/)", `\([http\:\/\/www\.google\.com\/](http://www.google.com/)\)`},
184 {"http://gmail.com)", `[http\:\/\/gmail\.com](http://gmail.com)\)`},
185 {"((http://gmail.com))", `\(\([http\:\/\/gmail\.com](http://gmail.com)\)\)`},
186 {"http://gmail.com ((http://gmail.com)) ()", `[http\:\/\/gmail\.com](http://gmail.com) \(\([http\:\/\/gmail\.com](http://gmail.com)\)\) \(\)`},
187 {"Foo bar http://example.com/ quux!", `Foo bar [http\:\/\/example\.com\/](http://example.com/) quux\!`},
188 {"Hello http://example.com/%2f/ /world.", `Hello [http\:\/\/example\.com\/\%2f\/](http://example.com/%2f/) \/world\.`},
189 {"Lorem http: ipsum //host/path", `Lorem http\: ipsum \/\/host\/path`},
190 {"javascript://is/not/linked", `javascript\:\/\/is\/not\/linked`},
191 {"http://foo", `[http\:\/\/foo](http://foo)`},
192 {"art by [[https://www.example.com/person/][Person Name]]", `art by \[\[[https\:\/\/www\.example\.com\/person\/](https://www.example.com/person/)\]\[Person Name\]\]`},
193 {"please visit (http://golang.org/)", `please visit \([http\:\/\/golang\.org\/](http://golang.org/)\)`},
194 {"please visit http://golang.org/hello())", `please visit [http\:\/\/golang\.org\/hello\(\)](http://golang.org/hello\(\))\)`},
195 {"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](http://git.qemu.org/?p=qemu.git;a=blob;f=qapi-schema.json;hb=HEAD)`},
196 {"https://foo.bar/bal/x(])", `[https\:\/\/foo\.bar\/bal\/x\(](https://foo.bar/bal/x\()\]\)`},
197 {"foo [ http://bar(])", `foo \[ [http\:\/\/bar\(](http://bar\()\]\)`},
200 func TestEmphasize(t *testing.T) {
201 for i, tt := range emphasizeTests {
203 emphasize(&buf, tt.in, true)
206 t.Errorf("#%d: mismatch\nhave: %v\nwant: %v", i, out, tt.out)
211 func TestCommentEscape(t *testing.T) {
212 //ldquo -> ulquo and rdquo -> urquo
213 commentTests := []struct {
216 {"typically invoked as ``go tool asm'',", "typically invoked as " + ulquo + "go tool asm" + urquo + ","},
217 {"For more detail, run ``go help test'' and ``go help testflag''", "For more detail, run " + ulquo + "go help test" + urquo + " and " + ulquo + "go help testflag" + urquo}}
218 for i, tt := range commentTests {
219 var buf strings.Builder
220 commentEscape(&buf, tt.in, true)
223 t.Errorf("#%d: mismatch\nhave: %q\nwant: %q", i, out, tt.out)