From 8d5ffba2d9483f049385d37bc468f2a114548eb0 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Fri, 14 Jun 2019 19:02:22 +0700 Subject: ascii: new library for working with ASCII characters This library previously part of bytes package. To make it bytes package consistent (only working with slice of byte), we move all ASCII related constants, variables, and functions into new package. --- lib/bytes/bytes_test.go | 58 ++----------------------------------------------- 1 file changed, 2 insertions(+), 56 deletions(-) (limited to 'lib/bytes/bytes_test.go') diff --git a/lib/bytes/bytes_test.go b/lib/bytes/bytes_test.go index e5eb2ac4..938f4ca1 100644 --- a/lib/bytes/bytes_test.go +++ b/lib/bytes/bytes_test.go @@ -1,9 +1,9 @@ package bytes import ( - "bytes" "testing" + "github.com/shuLhan/share/lib/ascii" "github.com/shuLhan/share/lib/test" ) @@ -280,33 +280,6 @@ func TestSkipAfterToken(t *testing.T) { } } -func TestToLower(t *testing.T) { - cases := []struct { - in []byte - exp []byte - }{{ - in: []byte("@ABCDEFG"), - exp: []byte("@abcdefg"), - }, { - in: []byte("@ABCDEFG12345678"), - exp: []byte("@abcdefg12345678"), - }, { - in: []byte("@ABCDEFGhijklmno12345678"), - exp: []byte("@abcdefghijklmno12345678"), - }, { - in: []byte("@ABCDEFGhijklmnoPQRSTUVW12345678"), - exp: []byte("@abcdefghijklmnopqrstuvw12345678"), - }, { - in: []byte("@ABCDEFGhijklmnoPQRSTUVWxyz{12345678"), - exp: []byte("@abcdefghijklmnopqrstuvwxyz{12345678"), - }} - - for _, c := range cases { - ToLower(&c.in) - test.Assert(t, "ToLower", c.exp, c.in, true) - } -} - func testTokenFind(t *testing.T, line, token []byte, startat int, exp []int) { got := []int{} tokenlen := len(token) @@ -354,35 +327,8 @@ func TestInReplace(t *testing.T) { }} for _, c := range cases { - got := InReplace([]byte(c.in), []byte(ASCIILettersNumber), '_') + got := InReplace([]byte(c.in), []byte(ascii.LettersNumber), '_') test.Assert(t, "InReplace", c.exp, string(got), true) } } - -func BenchmarkToLowerStd(b *testing.B) { - randomInput256 := Random([]byte(HexaLetters), 256) - - in := make([]byte, len(randomInput256)) - copy(in, randomInput256) - - b.ResetTimer() - - for x := 0; x < b.N; x++ { - bytes.ToLower(in) - } -} - -func BenchmarkToLower(b *testing.B) { - randomInput256 := Random([]byte(HexaLetters), 256) - - in := make([]byte, len(randomInput256)) - copy(in, randomInput256) - - b.ResetTimer() - - for x := 0; x < b.N; x++ { - ToLower(&in) - copy(in, randomInput256) - } -} -- cgit v1.3