From 248e754456015170241fc4c02aa0e444a6d861a7 Mon Sep 17 00:00:00 2001 From: Shinichiro Hamaji Date: Thu, 9 Apr 2015 18:12:06 +0900 Subject: Rewrite spliceSpaces without regexp 30 secs => 18 secs --- strutil_test.go | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'strutil_test.go') diff --git a/strutil_test.go b/strutil_test.go index fdcdcd5..0bf7174 100644 --- a/strutil_test.go +++ b/strutil_test.go @@ -1,16 +1,50 @@ package main import ( + "reflect" "testing" ) +func TestSplitSpaces(t *testing.T) { + for _, tc := range []struct { + in string + want []string + }{ + { + in: "foo", + want: []string{"foo"}, + }, + { + in: " ", + want: nil, + }, + { + in: " foo bar ", + want: []string{"foo", "bar"}, + }, + { + in: " foo bar", + want: []string{"foo", "bar"}, + }, + { + in: "foo bar ", + want: []string{"foo", "bar"}, + }, + } { + got := splitSpaces(tc.in) + if !reflect.DeepEqual(got, tc.want) { + t.Errorf(`splitSpaces(%q)=%q, want %q`, tc.in, got, tc.want) + } + } +} + func TestSubstPattern(t *testing.T) { for _, tc := range []struct { pat string repl string in string want string - } { + }{ { pat: "%.c", repl: "%.o", -- cgit v1.2.3