Skip to content

Commit 4c9ddd4

Browse files
committed
Tidy up format package
1 parent 56ae7b8 commit 4c9ddd4

File tree

15 files changed

+67
-39
lines changed

15 files changed

+67
-39
lines changed

format/bash.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func formatBashInternal(in interface{}, buf *bytes.Buffer) {
5050
}
5151
}
5252

53-
func formatBash(in interface{}) (string, error) {
53+
func Bash(in interface{}) (string, error) {
5454
in = internal.ArraysToMaps(in)
5555
in = internal.ForceStringKeys(in)
5656

format/bash_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
package format
1+
package format_test
22

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

59
func TestBash(t *testing.T) {
610
expecteds := []string{
@@ -24,7 +28,7 @@ func TestBash(t *testing.T) {
2428
for i, expected := range expecteds {
2529
testCase := testCases[i]
2630

27-
actual, err := formatBash(testCase)
31+
actual, err := format.Bash(testCase)
2832

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

format/benchmark_test.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
package format
1+
package format_test
22

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

59
var input = map[interface{}]interface{}{
610
"description": "some example json",
@@ -18,36 +22,36 @@ var input = map[interface{}]interface{}{
1822

1923
func BenchmarkBash(b *testing.B) {
2024
for i := 0; i < b.N; i++ {
21-
formatBash(input)
25+
format.Bash(input)
2226
}
2327
}
2428

2529
func BenchmarkDot(b *testing.B) {
2630
for i := 0; i < b.N; i++ {
27-
formatDot(input)
31+
format.Dot(input)
2832
}
2933
}
3034

3135
func BenchmarkJSON(b *testing.B) {
3236
for i := 0; i < b.N; i++ {
33-
formatJSON(input)
37+
format.Json(input)
3438
}
3539
}
3640

3741
func BenchmarkQuery(b *testing.B) {
3842
for i := 0; i < b.N; i++ {
39-
formatQuery(input)
43+
format.Query(input)
4044
}
4145
}
4246

4347
func BenchmarkXML(b *testing.B) {
4448
for i := 0; i < b.N; i++ {
45-
formatXML(input)
49+
format.Xml(input)
4650
}
4751
}
4852

4953
func BenchmarkYAML(b *testing.B) {
5054
for i := 0; i < b.N; i++ {
51-
formatYAML(input)
55+
format.Yaml(input)
5256
}
5357
}

format/dot.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func flatten(in interface{}, parent string, name string, buf *bytes.Buffer) {
7676
}
7777
}
7878

79-
func formatDot(in interface{}) (string, error) {
79+
func Dot(in interface{}) (string, error) {
8080
in = internal.ForceStringKeys(in)
8181

8282
var buf bytes.Buffer

format/dot_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
package format
1+
package format_test
22

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

59
func TestDot(t *testing.T) {
610
expecteds := []string{
@@ -100,7 +104,7 @@ func TestDot(t *testing.T) {
100104
for i, expected := range expecteds {
101105
testCase := testCases[i]
102106

103-
actual, err := formatDot(testCase)
107+
actual, err := format.Dot(testCase)
104108

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

format/test.go renamed to format/format_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package format
1+
package format_test
22

33
var testCases = []interface{}{
44
123,

format/formatters.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ type Formatter func(interface{}) (string, error)
1111
var formatters = make(map[string]Formatter)
1212

1313
func init() {
14-
Register("bash", formatBash)
15-
Register("dot", formatDot)
16-
Register("json", formatJSON)
17-
Register("xml", formatXML)
18-
Register("yaml", formatYAML)
19-
Register("query", formatQuery)
14+
Register("bash", Bash)
15+
Register("dot", Dot)
16+
Register("json", Json)
17+
Register("xml", Xml)
18+
Register("yaml", Yaml)
19+
Register("query", Query)
2020
}
2121

2222
// Names returns a sorted list of valid options for the "format" parameter of Format

format/json.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"github.com/stilvoid/please/internal"
77
)
88

9-
func formatJSON(in interface{}) (string, error) {
9+
func Json(in interface{}) (string, error) {
1010
in = internal.ForceStringKeys(in)
1111

1212
bytes, err := json.MarshalIndent(in, "", " ")

format/json_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
package format
1+
package format_test
22

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

59
func TestJSON(t *testing.T) {
610
expecteds := []string{
@@ -24,7 +28,7 @@ func TestJSON(t *testing.T) {
2428
for i, expected := range expecteds {
2529
testCase := testCases[i]
2630

27-
actual, err := formatJSON(testCase)
31+
actual, err := format.Json(testCase)
2832

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

format/query.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func formatQueryInternal(in interface{}) string {
3636
return output.Encode()
3737
}
3838

39-
func formatQuery(in interface{}) (string, error) {
39+
func Query(in interface{}) (string, error) {
4040
in = internal.ArraysToMaps(in)
4141
in = internal.ForceStringKeys(in)
4242

0 commit comments

Comments
 (0)