1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
package dencoding_test
import (
"bytes"
"github.com/tomwright/dasel/v2/dencoding"
"testing"
)
func TestJSONEncoder_Encode(t *testing.T) {
orig := dencoding.NewMap().
Set("c", "x").
Set("b", "y").
Set("a", "z")
exp := `{
"c": "x",
"b": "y",
"a": "z"
}
`
gotBuffer := new(bytes.Buffer)
encoder := dencoding.NewJSONEncoder(gotBuffer, dencoding.JSONEncodeIndent("", " "))
if err := encoder.Encode(orig); err != nil {
t.Errorf("unexpected error: %v", err)
return
}
got := gotBuffer.String()
if exp != got {
t.Errorf("expected %s, got %s", exp, got)
}
}
|