// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package present
import (
"fmt"
"reflect"
"testing"
)
func TestSplit(t *testing.T) {
var tests = []struct {
in string
out []string
}{
{"", []string{}},
{" ", []string{" "}},
{"abc", []string{"abc"}},
{"abc def", []string{"abc", " ", "def"}},
{"abc def ", []string{"abc", " ", "def", " "}},
{"hey [[http://golang.org][Gophers]] around",
[]string{"hey", " ", "[[http://golang.org][Gophers]]", " ", "around"}},
{"A [[http://golang.org/doc][two words]] link",
[]string{"A", " ", "[[http://golang.org/doc][two words]]", " ", "link"}},
{"Visit [[http://golang.org/doc]] now",
[]string{"Visit", " ", "[[http://golang.org/doc]]", " ", "now"}},
{"not [[http://golang.org/doc][a [[link]] ]] around",
[]string{"not", " ", "[[http://golang.org/doc][a [[link]]", " ", "]]", " ", "around"}},
{"[[http://golang.org][foo bar]]",
[]string{"[[http://golang.org][foo bar]]"}},
{"ends with [[http://golang.org][link]]",
[]string{"ends", " ", "with", " ", "[[http://golang.org][link]]"}},
{"my talk ([[http://talks.golang.org/][slides here]])",
[]string{"my", " ", "talk", " ", "(", "[[http://talks.golang.org/][slides here]]", ")"}},
}
for _, test := range tests {
out := split(test.in)
if !reflect.DeepEqual(out, test.out) {
t.Errorf("split(%q):\ngot\t%q\nwant\t%q", test.in, out, test.out)
}
}
}
func TestFont(t *testing.T) {
var tests = []struct {
in string
out string
}{
{"", ""},
{" ", " "},
{"\tx", "\tx"},
{"_a_", "a"},
{"*a*", "a"},
{"`a`", "a
"},
{"_a_b_", "a b"},
{"_a__b_", "a_b"},
{"_a___b_", "a_ b"},
{"*a**b*?", "a*b?"},
{"_a_<>_b_.", "a <> b."},
{"(_a_)", "(a)"},
{"((_a_), _b_, _c_).", "((a), b, c)."},
{"(_a)", "(_a)"},
{"(_a)", "(_a)"},
{"_Why_use_scoped__ptr_? Use plain ***ptr* instead.", "Why use scoped_ptr? Use plain *ptr instead."},
{"_hey_ [[http://golang.org][*Gophers*]] *around*",
`hey Gophers around`},
{"_hey_ [[http://golang.org][so _many_ *Gophers*]] *around*",
`hey so many Gophers around`},
{"Visit [[http://golang.org]] now",
`Visit golang.org now`},
{"my talk ([[http://talks.golang.org/][slides here]])",
`my talk (slides here)`},
{"Markup—_especially_italic_text_—can easily be overused.",
`Markup—especially italic text—can easily be overused.`},
{"`go`get`'s codebase", // ascii U+0027 ' before s
`go get
's codebase`},
{"`go`get`’s codebase", // unicode right single quote U+2019 ’ before s
`go get
’s codebase`},
{"a_variable_name",
`a_variable_name`},
}
for _, test := range tests {
out := font(test.in)
if out != test.out {
t.Errorf("font(%q):\ngot\t%q\nwant\t%q", test.in, out, test.out)
}
}
}
func TestStyle(t *testing.T) {
var tests = []struct {
in string
out string
}{
{"", ""},
{" ", " "},
{"\tx", "\tx"},
{"_a_", "a"},
{"*a*", "a"},
{"`a`", "a
"},
{"_a_b_", "a b"},
{"_a__b_", "a_b"},
{"_a___b_", "a_ b"},
{"*a**b*?", "a*b?"},
{"_a_<>_b_.", "a <> b."},
{"(_a_<>_b_)", "(a <> b)"},
{"((_a_), _b_, _c_).", "((a), b, c)."},
{"(_a)", "(_a)"},
}
for _, test := range tests {
out := string(Style(test.in))
if out != test.out {
t.Errorf("style(%q):\ngot\t%q\nwant\t%q", test.in, out, test.out)
}
}
}
func ExampleStyle() {
const s = "*Gophers* are _clearly_ > *cats*!"
fmt.Println(Style(s))
// Output: Gophers are clearly > cats!
}