Fix unexported Unmarshal
This commit is contained in:
parent
60dd11deee
commit
c160e565ba
@ -36,6 +36,7 @@ func init() {
|
||||
_value = Any(_null, _true, _false, _string, _number, _array, _object)
|
||||
}
|
||||
|
||||
func unmarshal(input string) (interface{}, error) {
|
||||
// Unmarshall json string into map[string]interface{} or []interface{}
|
||||
func Unmarshal(input string) (interface{}, error) {
|
||||
return Run(_value, input, ASCIIWhitespace)
|
||||
}
|
||||
|
@ -11,31 +11,31 @@ import (
|
||||
|
||||
func TestUnmarshal(t *testing.T) {
|
||||
t.Run("basic types", func(t *testing.T) {
|
||||
result, err := unmarshal(`true`)
|
||||
result, err := Unmarshal(`true`)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, true, result)
|
||||
|
||||
result, err = unmarshal(`false`)
|
||||
result, err = Unmarshal(`false`)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, false, result)
|
||||
|
||||
result, err = unmarshal(`null`)
|
||||
result, err = Unmarshal(`null`)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, nil, result)
|
||||
|
||||
result, err = unmarshal(`"true"`)
|
||||
result, err = Unmarshal(`"true"`)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "true", result)
|
||||
})
|
||||
|
||||
t.Run("array", func(t *testing.T) {
|
||||
result, err := unmarshal(`[true, null, false, -1.23e+4]`)
|
||||
result, err := Unmarshal(`[true, null, false, -1.23e+4]`)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, []interface{}{true, nil, false, -1.23e+4}, result)
|
||||
})
|
||||
|
||||
t.Run("object", func(t *testing.T) {
|
||||
result, err := unmarshal(`{"true":true, "false":false, "null": null, "number": 404} `)
|
||||
result, err := Unmarshal(`{"true":true, "false":false, "null": null, "number": 404} `)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, map[string]interface{}{"true": true, "false": false, "null": nil, "number": int64(404)}, result)
|
||||
})
|
||||
@ -54,7 +54,7 @@ func BenchmarkUnmarshalParsec(b *testing.B) {
|
||||
|
||||
func BenchmarkUnmarshalParsify(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
_, err := unmarshal(benchmarkString)
|
||||
_, err := Unmarshal(benchmarkString)
|
||||
require.NoError(b, err)
|
||||
}
|
||||
goparsify.DumpDebugStats()
|
||||
|
@ -48,7 +48,7 @@ func main() {
|
||||
}
|
||||
|
||||
for i := 0; i < max; i++ {
|
||||
_, err := json.unmarshal(benchmarkString)
|
||||
_, err := json.Unmarshal(benchmarkString)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user