From f4912dbb53e00f3aeb34cf26ca6b5d9588ba3533 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Sun, 29 Mar 2020 04:15:44 +0700 Subject: strings: add function SingleSpace The SingleSpace function convert all sequences of white spaces into single space ' '. --- lib/strings/string_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'lib/strings/string_test.go') diff --git a/lib/strings/string_test.go b/lib/strings/string_test.go index 7ee0c078..d161dfd7 100644 --- a/lib/strings/string_test.go +++ b/lib/strings/string_test.go @@ -117,6 +117,22 @@ func TestReverse(t *testing.T) { } } +func TestSingleSpace(t *testing.T) { + cases := []struct { + in string + exp string + }{{ + in: "", + }, { + in: " \t\v\r\n\r\n\fa \t\v\r\n\r\n\f", + exp: " a ", + }} + for _, c := range cases { + got := SingleSpace(c.in) + test.Assert(t, c.in, c.exp, got, true) + } +} + func TestSplit(t *testing.T) { cases := []struct { text string -- cgit v1.3-6-g1900