github.com/sandwich-go/boost@v1.3.29/xstrings/trim_test.go (about)

     1  package xstrings
     2  
     3  import (
     4  	. "github.com/smartystreets/goconvey/convey"
     5  	"testing"
     6  )
     7  
     8  func TestTrim(t *testing.T) {
     9  	Convey("trim", t, func() {
    10  		for _, test := range []struct {
    11  			s        string
    12  			expected string
    13  			mask     string
    14  		}{
    15  			{s: "a\t", expected: "a"},
    16  			{s: "a\v", expected: "a"},
    17  			{s: "a\n", expected: "a"},
    18  			{s: "a\r", expected: "a"},
    19  			{s: "a\f\f", expected: "a"},
    20  			{s: "a  ", expected: "a"},
    21  			{s: string([]byte{'a', 0x00}), expected: "a"},
    22  			{s: string([]byte{'a', 0x85}), expected: "a"},
    23  			{s: string([]byte{'a', 0xA0}), expected: "a"},
    24  			{s: "ab", mask: "b", expected: "a"},
    25  		} {
    26  			So(Trim(test.s, test.mask), ShouldEqual, test.expected)
    27  		}
    28  
    29  		for _, test := range []struct {
    30  			s         string
    31  			expected  []string
    32  			delimiter string
    33  			mask      string
    34  		}{
    35  			{s: "a\t,b\t", expected: []string{"a", "b"}, delimiter: ","},
    36  			{s: "a\v,b\v", expected: []string{"a", "b"}, delimiter: ","},
    37  			{s: "a\n,a\n", expected: []string{"a", "a"}, delimiter: ","},
    38  			{s: "a\r,a\n", expected: []string{"a", "a"}, delimiter: ","},
    39  			{s: "a\f\f", expected: []string{"a"}, delimiter: ","},
    40  			{s: "a  ,b  ", expected: []string{"a", "b"}, delimiter: ","},
    41  			{s: string([]byte{'a', 0x00, ',', 'b', 0x00}), expected: []string{"a", "b"}, delimiter: ","},
    42  			{s: string([]byte{'a', 0x85, ',', 'b', 0x00}), expected: []string{"a", "b"}, delimiter: ","},
    43  			{s: string([]byte{'a', 0xA0, ',', 'b', 0x85}), expected: []string{"a", "b"}, delimiter: ","},
    44  			{s: "a,b", mask: "b", expected: []string{"a"}, delimiter: ","},
    45  		} {
    46  			So(SplitAndTrim(test.s, test.delimiter, test.mask), ShouldResemble, test.expected)
    47  		}
    48  	})
    49  }