1 // Copyright 2012 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 func TestSplit(t *testing.T) {
14 var tests = []struct {
20 {"abc", []string{"abc"}},
21 {"abc def", []string{"abc", " ", "def"}},
22 {"abc def ", []string{"abc", " ", "def", " "}},
23 {"hey [[http://golang.org][Gophers]] around",
24 []string{"hey", " ", "[[http://golang.org][Gophers]]", " ", "around"}},
25 {"A [[http://golang.org/doc][two words]] link",
26 []string{"A", " ", "[[http://golang.org/doc][two words]]", " ", "link"}},
27 {"Visit [[http://golang.org/doc]] now",
28 []string{"Visit", " ", "[[http://golang.org/doc]]", " ", "now"}},
29 {"not [[http://golang.org/doc][a [[link]] ]] around",
30 []string{"not", " ", "[[http://golang.org/doc][a [[link]]", " ", "]]", " ", "around"}},
31 {"[[http://golang.org][foo bar]]",
32 []string{"[[http://golang.org][foo bar]]"}},
33 {"ends with [[http://golang.org][link]]",
34 []string{"ends", " ", "with", " ", "[[http://golang.org][link]]"}},
35 {"my talk ([[http://talks.golang.org/][slides here]])",
36 []string{"my", " ", "talk", " ", "(", "[[http://talks.golang.org/][slides here]]", ")"}},
38 for _, test := range tests {
40 if !reflect.DeepEqual(out, test.out) {
41 t.Errorf("split(%q):\ngot\t%q\nwant\t%q", test.in, out, test.out)
46 func TestFont(t *testing.T) {
47 var tests = []struct {
56 {"`a`", "<code>a</code>"},
57 {"_a_b_", "<i>a b</i>"},
58 {"_a__b_", "<i>a_b</i>"},
59 {"_a___b_", "<i>a_ b</i>"},
60 {"*a**b*?", "<b>a*b</b>?"},
61 {"_a_<>_b_.", "<i>a <> b</i>."},
62 {"(_a_)", "(<i>a</i>)"},
63 {"((_a_), _b_, _c_).", "((<i>a</i>), <i>b</i>, <i>c</i>)."},
66 {"_Why_use_scoped__ptr_? Use plain ***ptr* instead.", "<i>Why use scoped_ptr</i>? Use plain <b>*ptr</b> instead."},
67 {"_hey_ [[http://golang.org][*Gophers*]] *around*",
68 `<i>hey</i> <a href="http://golang.org" target="_blank"><b>Gophers</b></a> <b>around</b>`},
69 {"_hey_ [[http://golang.org][so _many_ *Gophers*]] *around*",
70 `<i>hey</i> <a href="http://golang.org" target="_blank">so <i>many</i> <b>Gophers</b></a> <b>around</b>`},
71 {"Visit [[http://golang.org]] now",
72 `Visit <a href="http://golang.org" target="_blank">golang.org</a> now`},
73 {"my talk ([[http://talks.golang.org/][slides here]])",
74 `my talk (<a href="http://talks.golang.org/" target="_blank">slides here</a>)`},
75 {"Markup—_especially_italic_text_—can easily be overused.",
76 `Markup—<i>especially italic text</i>—can easily be overused.`},
77 {"`go`get`'s codebase", // ascii U+0027 ' before s
78 `<code>go get</code>'s codebase`},
79 {"`go`get`’s codebase", // unicode right single quote U+2019 ’ before s
80 `<code>go get</code>’s codebase`},
84 for _, test := range tests {
87 t.Errorf("font(%q):\ngot\t%q\nwant\t%q", test.in, out, test.out)
92 func TestStyle(t *testing.T) {
93 var tests = []struct {
102 {"`a`", "<code>a</code>"},
103 {"_a_b_", "<i>a b</i>"},
104 {"_a__b_", "<i>a_b</i>"},
105 {"_a___b_", "<i>a_ b</i>"},
106 {"*a**b*?", "<b>a*b</b>?"},
107 {"_a_<>_b_.", "<i>a <> b</i>."},
108 {"(_a_<>_b_)", "(<i>a <> b</i>)"},
109 {"((_a_), _b_, _c_).", "((<i>a</i>), <i>b</i>, <i>c</i>)."},
112 for _, test := range tests {
113 out := string(Style(test.in))
115 t.Errorf("style(%q):\ngot\t%q\nwant\t%q", test.in, out, test.out)
120 func ExampleStyle() {
121 const s = "*Gophers* are _clearly_ > *cats*!"
122 fmt.Println(Style(s))
123 // Output: <b>Gophers</b> are <i>clearly</i> > <b>cats</b>!