Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cache/loadingCache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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}
Expand Down
5 changes: 2 additions & 3 deletions cache/loadingCache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion jsonutil/jsonutil.go → jsons/jsons.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package jsonutil
package jsons

import (
"bytes"
Expand Down
2 changes: 1 addition & 1 deletion jsonutil/jsonutil_test.go → jsons/jsons_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package jsonutil
package jsons

import (
"testing"
Expand Down
2 changes: 1 addition & 1 deletion mathutil/mathutil.go → maths/maths.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mathutil
package maths

// MaxInt returns the bigger value of the two input ints.
func MaxInt(x, y int) int {
Expand Down
2 changes: 1 addition & 1 deletion mathutil/mathutil_test.go → maths/maths_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mathutil
package maths

import (
"testing"
Expand Down
6 changes: 3 additions & 3 deletions nodeutil/marshal_test.go → nodes/marshal_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package nodeutil
package nodes

import (
"encoding/json"
"fmt"

node "github.com/antchfx/xmlquery"

"github.com/jf-tech/omniparser/jsonutil"
"github.com/jf-tech/omniparser/jsons"
)

func nodeName(n *node.Node) string {
Expand Down Expand Up @@ -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))
}
2 changes: 1 addition & 1 deletion nodeutil/node.go → nodes/node.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nodeutil
package nodes

import (
"encoding/xml"
Expand Down
2 changes: 1 addition & 1 deletion nodeutil/node_test.go → nodes/node_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nodeutil
package nodes

import (
"encoding/xml"
Expand Down
2 changes: 1 addition & 1 deletion nodeutil/query.go → nodes/query.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nodeutil
package nodes

import (
"errors"
Expand Down
2 changes: 1 addition & 1 deletion nodeutil/query_test.go → nodes/query_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nodeutil
package nodes

import (
"strings"
Expand Down
4 changes: 2 additions & 2 deletions omniparser/schemaPlugin/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
14 changes: 7 additions & 7 deletions omniparser/schemaPlugin/header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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())
}
2 changes: 1 addition & 1 deletion strutil/strutil.go → strs/strs.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package strutil
package strs

func StrPtrOrElse(sp *string, orElse string) string {
if sp != nil {
Expand Down
6 changes: 3 additions & 3 deletions strutil/strutil_test.go → strs/strs_test.go
Original file line number Diff line number Diff line change
@@ -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"))
}
2 changes: 1 addition & 1 deletion testutil/testutil.go → testlib/testlib.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion testutil/testutil_test.go → testlib/testlib_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package testutil
package testlib

import (
"testing"
Expand Down