mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
various: avoid func compare
R=gri, r, bradfitz CC=golang-dev https://golang.org/cl/5371074
This commit is contained in:
parent
c017a8299f
commit
558e7fc332
9 changed files with 136 additions and 107 deletions
|
|
@ -662,48 +662,49 @@ func TestRunes(t *testing.T) {
|
|||
}
|
||||
|
||||
type TrimTest struct {
|
||||
f func([]byte, string) []byte
|
||||
f string
|
||||
in, cutset, out string
|
||||
}
|
||||
|
||||
var trimTests = []TrimTest{
|
||||
{Trim, "abba", "a", "bb"},
|
||||
{Trim, "abba", "ab", ""},
|
||||
{TrimLeft, "abba", "ab", ""},
|
||||
{TrimRight, "abba", "ab", ""},
|
||||
{TrimLeft, "abba", "a", "bba"},
|
||||
{TrimRight, "abba", "a", "abb"},
|
||||
{Trim, "<tag>", "<>", "tag"},
|
||||
{Trim, "* listitem", " *", "listitem"},
|
||||
{Trim, `"quote"`, `"`, "quote"},
|
||||
{Trim, "\u2C6F\u2C6F\u0250\u0250\u2C6F\u2C6F", "\u2C6F", "\u0250\u0250"},
|
||||
{"Trim", "abba", "a", "bb"},
|
||||
{"Trim", "abba", "ab", ""},
|
||||
{"TrimLeft", "abba", "ab", ""},
|
||||
{"TrimRight", "abba", "ab", ""},
|
||||
{"TrimLeft", "abba", "a", "bba"},
|
||||
{"TrimRight", "abba", "a", "abb"},
|
||||
{"Trim", "<tag>", "<>", "tag"},
|
||||
{"Trim", "* listitem", " *", "listitem"},
|
||||
{"Trim", `"quote"`, `"`, "quote"},
|
||||
{"Trim", "\u2C6F\u2C6F\u0250\u0250\u2C6F\u2C6F", "\u2C6F", "\u0250\u0250"},
|
||||
//empty string tests
|
||||
{Trim, "abba", "", "abba"},
|
||||
{Trim, "", "123", ""},
|
||||
{Trim, "", "", ""},
|
||||
{TrimLeft, "abba", "", "abba"},
|
||||
{TrimLeft, "", "123", ""},
|
||||
{TrimLeft, "", "", ""},
|
||||
{TrimRight, "abba", "", "abba"},
|
||||
{TrimRight, "", "123", ""},
|
||||
{TrimRight, "", "", ""},
|
||||
{TrimRight, "☺\xc0", "☺", "☺\xc0"},
|
||||
{"Trim", "abba", "", "abba"},
|
||||
{"Trim", "", "123", ""},
|
||||
{"Trim", "", "", ""},
|
||||
{"TrimLeft", "abba", "", "abba"},
|
||||
{"TrimLeft", "", "123", ""},
|
||||
{"TrimLeft", "", "", ""},
|
||||
{"TrimRight", "abba", "", "abba"},
|
||||
{"TrimRight", "", "123", ""},
|
||||
{"TrimRight", "", "", ""},
|
||||
{"TrimRight", "☺\xc0", "☺", "☺\xc0"},
|
||||
}
|
||||
|
||||
func TestTrim(t *testing.T) {
|
||||
for _, tc := range trimTests {
|
||||
actual := string(tc.f([]byte(tc.in), tc.cutset))
|
||||
var name string
|
||||
switch tc.f {
|
||||
case Trim:
|
||||
name = "Trim"
|
||||
case TrimLeft:
|
||||
name = "TrimLeft"
|
||||
case TrimRight:
|
||||
name = "TrimRight"
|
||||
name := tc.f
|
||||
var f func([]byte, string) []byte
|
||||
switch name {
|
||||
case "Trim":
|
||||
f = Trim
|
||||
case "TrimLeft":
|
||||
f = TrimLeft
|
||||
case "TrimRight":
|
||||
f = TrimRight
|
||||
default:
|
||||
t.Error("Undefined trim function")
|
||||
t.Error("Undefined trim function %s", name)
|
||||
}
|
||||
actual := string(f([]byte(tc.in), tc.cutset))
|
||||
if actual != tc.out {
|
||||
t.Errorf("%s(%q, %q) = %q; want %q", name, tc.in, tc.cutset, actual, tc.out)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue