From 03d9c3e31fdfac7b01c7f8f3eeb69d4980b7bd50 Mon Sep 17 00:00:00 2001 From: jf-tech Date: Sun, 30 Aug 2020 10:03:13 +1200 Subject: [PATCH] Rename a bunch of packages and rid of "util" suffix --- cache/loadingCache.go | 4 ++-- cache/loadingCache_test.go | 5 ++--- {jsonutil => jsons}/.snapshots/TestBPMInSnapshot | 0 jsonutil/jsonutil.go => jsons/jsons.go | 2 +- jsonutil/jsonutil_test.go => jsons/jsons_test.go | 2 +- mathutil/mathutil.go => maths/maths.go | 2 +- mathutil/mathutil_test.go => maths/maths_test.go | 2 +- .../.snapshots/TestReferenceTestTree | 0 {nodeutil => nodes}/marshal_test.go | 6 +++--- {nodeutil => nodes}/node.go | 2 +- {nodeutil => nodes}/node_test.go | 2 +- {nodeutil => nodes}/query.go | 2 +- {nodeutil => nodes}/query_test.go | 2 +- omniparser/schemaPlugin/header.go | 4 ++-- omniparser/schemaPlugin/header_test.go | 14 +++++++------- strutil/strutil.go => strs/strs.go | 2 +- strutil/strutil_test.go => strs/strs_test.go | 6 +++--- testutil/testutil.go => testlib/testlib.go | 2 +- .../testutil_test.go => testlib/testlib_test.go | 2 +- 19 files changed, 30 insertions(+), 31 deletions(-) rename {jsonutil => jsons}/.snapshots/TestBPMInSnapshot (100%) rename jsonutil/jsonutil.go => jsons/jsons.go (98%) rename jsonutil/jsonutil_test.go => jsons/jsons_test.go (99%) rename mathutil/mathutil.go => maths/maths.go (96%) rename mathutil/mathutil_test.go => maths/maths_test.go (97%) rename {nodeutil => nodes}/.snapshots/TestReferenceTestTree (100%) rename {nodeutil => nodes}/marshal_test.go (95%) rename {nodeutil => nodes}/node.go (98%) rename {nodeutil => nodes}/node_test.go (99%) rename {nodeutil => nodes}/query.go (99%) rename {nodeutil => nodes}/query_test.go (99%) rename strutil/strutil.go => strs/strs.go (86%) rename strutil/strutil_test.go => strs/strs_test.go (54%) rename testutil/testutil.go => testlib/testlib.go (95%) rename testutil/testutil_test.go => testlib/testlib_test.go (94%) diff --git a/cache/loadingCache.go b/cache/loadingCache.go index c2909fa..488b6ef 100644 --- a/cache/loadingCache.go +++ b/cache/loadingCache.go @@ -5,7 +5,7 @@ import ( lru "github.com/hashicorp/golang-lru" - "github.com/jf-tech/omniparser/mathutil" + "github.com/jf-tech/omniparser/maths" ) // LoadingCache is a key/value cache with a user specified loading function and an optional capacity. @@ -34,7 +34,7 @@ func NewLoadingCache(capacity ...int) *LoadingCache { capv = capacity[0] } if capv == 0 { - capv = mathutil.MaxIntValue - 1 + capv = maths.MaxIntValue - 1 } cache, _ := lru.New(capv) return &LoadingCache{capacity: capv, cache: cache} diff --git a/cache/loadingCache_test.go b/cache/loadingCache_test.go index 228e0f1..579a639 100644 --- a/cache/loadingCache_test.go +++ b/cache/loadingCache_test.go @@ -7,9 +7,8 @@ import ( "testing" "github.com/antchfx/xpath" + "github.com/jf-tech/omniparser/maths" "github.com/stretchr/testify/assert" - - "github.com/jf-tech/omniparser/mathutil" ) func TestNewLoadingCache(t *testing.T) { @@ -29,7 +28,7 @@ func TestNewLoadingCache(t *testing.T) { name: "0 capacity specified, no limit", capacity: []int{0, -5}, // the second invalid value -5 is ignored. panicErr: "", - expectedCapacity: mathutil.MaxIntValue - 1, + expectedCapacity: maths.MaxIntValue - 1, }, { name: "> 0 capacity specified", diff --git a/jsonutil/.snapshots/TestBPMInSnapshot b/jsons/.snapshots/TestBPMInSnapshot similarity index 100% rename from jsonutil/.snapshots/TestBPMInSnapshot rename to jsons/.snapshots/TestBPMInSnapshot diff --git a/jsonutil/jsonutil.go b/jsons/jsons.go similarity index 98% rename from jsonutil/jsonutil.go rename to jsons/jsons.go index 63cc393..bb38555 100644 --- a/jsonutil/jsonutil.go +++ b/jsons/jsons.go @@ -1,4 +1,4 @@ -package jsonutil +package jsons import ( "bytes" diff --git a/jsonutil/jsonutil_test.go b/jsons/jsons_test.go similarity index 99% rename from jsonutil/jsonutil_test.go rename to jsons/jsons_test.go index 87499bc..d147322 100644 --- a/jsonutil/jsonutil_test.go +++ b/jsons/jsons_test.go @@ -1,4 +1,4 @@ -package jsonutil +package jsons import ( "testing" diff --git a/mathutil/mathutil.go b/maths/maths.go similarity index 96% rename from mathutil/mathutil.go rename to maths/maths.go index f155741..9015bd7 100644 --- a/mathutil/mathutil.go +++ b/maths/maths.go @@ -1,4 +1,4 @@ -package mathutil +package maths // MaxInt returns the bigger value of the two input ints. func MaxInt(x, y int) int { diff --git a/mathutil/mathutil_test.go b/maths/maths_test.go similarity index 97% rename from mathutil/mathutil_test.go rename to maths/maths_test.go index fa6176b..6759098 100644 --- a/mathutil/mathutil_test.go +++ b/maths/maths_test.go @@ -1,4 +1,4 @@ -package mathutil +package maths import ( "testing" diff --git a/nodeutil/.snapshots/TestReferenceTestTree b/nodes/.snapshots/TestReferenceTestTree similarity index 100% rename from nodeutil/.snapshots/TestReferenceTestTree rename to nodes/.snapshots/TestReferenceTestTree diff --git a/nodeutil/marshal_test.go b/nodes/marshal_test.go similarity index 95% rename from nodeutil/marshal_test.go rename to nodes/marshal_test.go index 8536e2d..f0997b6 100644 --- a/nodeutil/marshal_test.go +++ b/nodes/marshal_test.go @@ -1,4 +1,4 @@ -package nodeutil +package nodes import ( "encoding/json" @@ -6,7 +6,7 @@ import ( node "github.com/antchfx/xmlquery" - "github.com/jf-tech/omniparser/jsonutil" + "github.com/jf-tech/omniparser/jsons" ) func nodeName(n *node.Node) string { @@ -83,5 +83,5 @@ func nodeToInterface(n *node.Node) interface{} { } func jsonify(n *node.Node) string { - return jsonutil.BPM(nodeToInterface(n)) + return jsons.BPM(nodeToInterface(n)) } diff --git a/nodeutil/node.go b/nodes/node.go similarity index 98% rename from nodeutil/node.go rename to nodes/node.go index 2a6f9a8..9f000c7 100644 --- a/nodeutil/node.go +++ b/nodes/node.go @@ -1,4 +1,4 @@ -package nodeutil +package nodes import ( "encoding/xml" diff --git a/nodeutil/node_test.go b/nodes/node_test.go similarity index 99% rename from nodeutil/node_test.go rename to nodes/node_test.go index 883e279..60bbecf 100644 --- a/nodeutil/node_test.go +++ b/nodes/node_test.go @@ -1,4 +1,4 @@ -package nodeutil +package nodes import ( "encoding/xml" diff --git a/nodeutil/query.go b/nodes/query.go similarity index 99% rename from nodeutil/query.go rename to nodes/query.go index c8a3c06..c8a89e5 100644 --- a/nodeutil/query.go +++ b/nodes/query.go @@ -1,4 +1,4 @@ -package nodeutil +package nodes import ( "errors" diff --git a/nodeutil/query_test.go b/nodes/query_test.go similarity index 99% rename from nodeutil/query_test.go rename to nodes/query_test.go index bf82e43..dfe5b26 100644 --- a/nodeutil/query_test.go +++ b/nodes/query_test.go @@ -1,4 +1,4 @@ -package nodeutil +package nodes import ( "strings" diff --git a/omniparser/schemaPlugin/header.go b/omniparser/schemaPlugin/header.go index e3e3600..b434fc8 100644 --- a/omniparser/schemaPlugin/header.go +++ b/omniparser/schemaPlugin/header.go @@ -5,7 +5,7 @@ import ( "golang.org/x/text/encoding/charmap" - "github.com/jf-tech/omniparser/strutil" + "github.com/jf-tech/omniparser/strs" ) // ParserSettings defines the common header (and its JSON format) for all schemas across all schema plugins. @@ -41,7 +41,7 @@ var SupportedEncodingMappings = map[string]encodingMappingFunc{ // GetEncoding returns the encoding of the schema. If no encoding is specified in the schema, which // the most comment default case, it assumes the input stream will be in UTF-8. func (p ParserSettings) GetEncoding() string { - return strutil.StrPtrOrElse(p.Encoding, EncodingUTF8) + return strs.StrPtrOrElse(p.Encoding, EncodingUTF8) } // Header contains the common ParserSettings for all schemas. diff --git a/omniparser/schemaPlugin/header_test.go b/omniparser/schemaPlugin/header_test.go index 18ed65a..ec12c0a 100644 --- a/omniparser/schemaPlugin/header_test.go +++ b/omniparser/schemaPlugin/header_test.go @@ -9,8 +9,8 @@ import ( "github.com/bradleyjkemp/cupaloy" "github.com/stretchr/testify/assert" - "github.com/jf-tech/omniparser/jsonutil" - "github.com/jf-tech/omniparser/testutil" + "github.com/jf-tech/omniparser/jsons" + "github.com/jf-tech/omniparser/testlib" ) func TestSupportedEncodingMappingsDump(t *testing.T) { @@ -19,7 +19,7 @@ func TestSupportedEncodingMappingsDump(t *testing.T) { supported = append(supported, k) } sort.Strings(supported) - cupaloy.SnapshotT(t, jsonutil.BPM(supported)) + cupaloy.SnapshotT(t, jsons.BPM(supported)) } func TestSupportedEncodingMappings(t *testing.T) { @@ -34,13 +34,13 @@ func TestSupportedEncodingMappings(t *testing.T) { func TestGetEncoding(t *testing.T) { assert.Equal( - t, EncodingUTF8, (ParserSettings{Encoding: testutil.StrPtr(EncodingUTF8)}).GetEncoding()) + t, EncodingUTF8, (ParserSettings{Encoding: testlib.StrPtr(EncodingUTF8)}).GetEncoding()) assert.Equal( - t, EncodingISO8859_1, (ParserSettings{Encoding: testutil.StrPtr(EncodingISO8859_1)}).GetEncoding()) + t, EncodingISO8859_1, (ParserSettings{Encoding: testlib.StrPtr(EncodingISO8859_1)}).GetEncoding()) assert.Equal( - t, EncodingWindows1252, (ParserSettings{Encoding: testutil.StrPtr(EncodingWindows1252)}).GetEncoding()) + t, EncodingWindows1252, (ParserSettings{Encoding: testlib.StrPtr(EncodingWindows1252)}).GetEncoding()) assert.Equal( t, EncodingUTF8, (ParserSettings{}).GetEncoding()) assert.Equal( - t, "whatever", (ParserSettings{Encoding: testutil.StrPtr("whatever")}).GetEncoding()) + t, "whatever", (ParserSettings{Encoding: testlib.StrPtr("whatever")}).GetEncoding()) } diff --git a/strutil/strutil.go b/strs/strs.go similarity index 86% rename from strutil/strutil.go rename to strs/strs.go index 78330ba..cfc8dc5 100644 --- a/strutil/strutil.go +++ b/strs/strs.go @@ -1,4 +1,4 @@ -package strutil +package strs func StrPtrOrElse(sp *string, orElse string) string { if sp != nil { diff --git a/strutil/strutil_test.go b/strs/strs_test.go similarity index 54% rename from strutil/strutil_test.go rename to strs/strs_test.go index e3bd632..36480e6 100644 --- a/strutil/strutil_test.go +++ b/strs/strs_test.go @@ -1,14 +1,14 @@ -package strutil +package strs import ( "testing" "github.com/stretchr/testify/assert" - "github.com/jf-tech/omniparser/testutil" + "github.com/jf-tech/omniparser/testlib" ) func TestStrPtrOrElse(t *testing.T) { - assert.Equal(t, "this", StrPtrOrElse(testutil.StrPtr("this"), "that")) + assert.Equal(t, "this", StrPtrOrElse(testlib.StrPtr("this"), "that")) assert.Equal(t, "that", StrPtrOrElse(nil, "that")) } diff --git a/testutil/testutil.go b/testlib/testlib.go similarity index 95% rename from testutil/testutil.go rename to testlib/testlib.go index 9e44c48..4964b94 100644 --- a/testutil/testutil.go +++ b/testlib/testlib.go @@ -1,4 +1,4 @@ -package testutil +package testlib // IntPtr returns an int pointer with a given value. // Tests cases needed inline int pointer declaration can use this. diff --git a/testutil/testutil_test.go b/testlib/testlib_test.go similarity index 94% rename from testutil/testutil_test.go rename to testlib/testlib_test.go index 2a7eb20..7481d56 100644 --- a/testutil/testutil_test.go +++ b/testlib/testlib_test.go @@ -1,4 +1,4 @@ -package testutil +package testlib import ( "testing"