Skip to content

Commit 395c4ff

Browse files
committed
Tidy up parse package
1 parent 4c9ddd4 commit 395c4ff

File tree

18 files changed

+65
-54
lines changed

18 files changed

+65
-54
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.12
44

55
require (
66
github.com/andrew-d/go-termutil v0.0.0-20150726205930-009166a695a2
7+
github.com/clbanning/mxj v1.8.4
78
github.com/clbanning/x2j v0.0.0-20180326210544-5e605d46809c
89
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af
910
github.com/pborman/getopt v0.0.0-20190409184431-ee0cd42419d3

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
github.com/andrew-d/go-termutil v0.0.0-20150726205930-009166a695a2 h1:axBiC50cNZOs7ygH5BgQp4N+aYrZ2DNpWZ1KG3VOSOM=
22
github.com/andrew-d/go-termutil v0.0.0-20150726205930-009166a695a2/go.mod h1:jnzFpU88PccN/tPPhCpnNU8mZphvKxYM9lLNkd8e+os=
3+
github.com/clbanning/mxj v1.8.4 h1:HuhwZtbyvyOw+3Z1AowPkU87JkJUSv751ELWaiTpj8I=
4+
github.com/clbanning/mxj v1.8.4/go.mod h1:BVjHeAH+rl9rs6f+QIpeRl0tfu10SXn1pUSa5PVGJng=
35
github.com/clbanning/x2j v0.0.0-20180326210544-5e605d46809c h1:gZ7YRTPnL5fRduIw4unEfQWLB/DInK29N2zYza16wfQ=
46
github.com/clbanning/x2j v0.0.0-20180326210544-5e605d46809c/go.mod h1:jMjuTZXRI4dUb/I5gc9Hdhagfvm9+RyrPryS/auMzxE=
57
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM=

parse/benchmark_test.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
package parse
1+
package parse_test
22

3-
import "testing"
3+
import (
4+
"testing"
5+
6+
"github.com/stilvoid/please/parse"
7+
)
48

59
const jsonInput = `{
610
"description": "some example json",
@@ -42,30 +46,30 @@ const queryInput = `an+array=0%3Dfirst%2Bentry%261%3Dnested%253Dobject%262%3D0%2
4246

4347
func BenchmarkJSON(b *testing.B) {
4448
for i := 0; i < b.N; i++ {
45-
parseJSON([]byte(jsonInput))
49+
parse.Json([]byte(jsonInput))
4650
}
4751
}
4852

4953
func BenchmarkYAML(b *testing.B) {
5054
for i := 0; i < b.N; i++ {
51-
parseYAML([]byte(yamlInput))
55+
parse.Yaml([]byte(yamlInput))
5256
}
5357
}
5458

5559
func BenchmarkXML(b *testing.B) {
5660
for i := 0; i < b.N; i++ {
57-
parseXML([]byte(xmlInput))
61+
parse.Xml([]byte(xmlInput))
5862
}
5963
}
6064

6165
func BenchmarkQuery(b *testing.B) {
6266
for i := 0; i < b.N; i++ {
63-
parseQuery([]byte(queryInput))
67+
parse.Query([]byte(queryInput))
6468
}
6569
}
6670

6771
func BenchmarkHTML(b *testing.B) {
6872
for i := 0; i < b.N; i++ {
69-
parseHTML([]byte(xmlInput))
73+
parse.Html([]byte(xmlInput))
7074
}
7175
}

parse/csv.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ import (
55
"encoding/csv"
66
)
77

8-
func parseCSV(input []byte) (interface{}, error) {
8+
func Csv(input []byte) (interface{}, error) {
99
return csv.NewReader(bytes.NewReader(input)).ReadAll()
1010
}

parse/csv_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
package parse
1+
package parse_test
22

33
import (
44
"reflect"
55
"testing"
6+
7+
"github.com/stilvoid/please/parse"
68
)
79

810
func TestCSV(t *testing.T) {
@@ -11,12 +13,12 @@ func TestCSV(t *testing.T) {
1113
"2-1,2-2"
1214

1315
expected := [][]string{
14-
[]string{"col1", "col2"},
15-
[]string{"1-1", "1-2"},
16-
[]string{"2-1", "2-2"},
16+
{"col1", "col2"},
17+
{"1-1", "1-2"},
18+
{"2-1", "2-2"},
1719
}
1820

19-
actual, err := parseCSV([]byte(input))
21+
actual, err := parse.Csv([]byte(input))
2022

2123
if err != nil {
2224
t.Errorf("unexpected error: %v", err)

parse/html.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,7 @@ import (
99
"golang.org/x/net/html"
1010
)
1111

12-
type node struct {
13-
Node interface{} `xml:",any"`
14-
List []interface{} `xml:",any"`
15-
Value interface{} `xml:",any"`
16-
}
17-
18-
func parseHTML(input []byte) (interface{}, error) {
12+
func Html(input []byte) (interface{}, error) {
1913
var parsed interface{}
2014

2115
doc, err := html.Parse(bytes.NewReader(input))

parse/html_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
package parse
1+
package parse_test
22

33
import (
44
"reflect"
55
"testing"
6+
7+
"github.com/stilvoid/please/parse"
68
)
79

810
func TestHTML(t *testing.T) {
@@ -32,7 +34,7 @@ func TestHTML(t *testing.T) {
3234
},
3335
}
3436

35-
actual, err := parseHTML([]byte(input))
37+
actual, err := parse.Html([]byte(input))
3638

3739
if err != nil {
3840
t.Errorf("unexpected error: %v", err)

parse/json.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package parse
22

33
import "encoding/json"
44

5-
func parseJSON(input []byte) (interface{}, error) {
5+
func Json(input []byte) (interface{}, error) {
66
var parsed interface{}
77

88
err := json.Unmarshal(input, &parsed)

parse/json_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
package parse
1+
package parse_test
22

33
import (
44
"reflect"
55
"testing"
6+
7+
"github.com/stilvoid/please/parse"
68
)
79

810
func TestJSON(t *testing.T) {
@@ -47,7 +49,7 @@ func TestJSON(t *testing.T) {
4749
input := inputs[i]
4850
expected := expecteds[i]
4951

50-
actual, err := parseJSON([]byte(input))
52+
actual, err := parse.Json([]byte(input))
5153

5254
if err != nil {
5355
t.Errorf("unexpected error: %v", err)

parse/mime.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"net/textproto"
88
)
99

10-
func parseMIME(input []byte) (interface{}, error) {
10+
func Mime(input []byte) (interface{}, error) {
1111
inputReader := bufio.NewReader(bytes.NewReader(input))
1212

1313
reader := textproto.NewReader(inputReader)

0 commit comments

Comments
 (0)