github.com/sandwich-go/boost@v1.3.29/misc/goformat/util_test.go (about) 1 package goformat 2 3 import ( 4 . "github.com/smartystreets/goconvey/convey" 5 "testing" 6 ) 7 8 func TestUtil(t *testing.T) { 9 Convey("cut space", t, func() { 10 for _, test := range []struct { 11 src, before, middle, after []byte 12 }{ 13 {src: []byte{'a', ' ', ' ', 'b'}, before: []byte{}, middle: []byte{'a', ' ', ' ', 'b'}, after: []byte{}}, 14 {src: []byte{' ', 'a', 'b', ' '}, before: []byte{' '}, middle: []byte{'a', 'b'}, after: []byte{' '}}, 15 } { 16 before, middle, after := cutSpace(test.src) 17 So(before, ShouldResemble, test.before) 18 So(middle, ShouldResemble, test.middle) 19 So(after, ShouldResemble, test.after) 20 } 21 }) 22 23 Convey("match space", t, func() { 24 for _, test := range []struct { 25 orig, src, ret []byte 26 }{ 27 { 28 orig: []byte{' ', ' ', '3', '4', ' ', ' ', ' '}, 29 src: []byte{' ', 'a', ' ', ' ', 'b', ' ', ' '}, 30 ret: []byte{' ', ' ', 'a', ' ', ' ', 'b', ' ', ' ', ' '}, 31 }, 32 } { 33 ret := matchSpace(test.orig, test.src) 34 So(ret, ShouldResemble, test.ret) 35 } 36 }) 37 }