File: json_encoder_test.go

package info (click to toggle)
dasel 2.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,844 kB
  • sloc: sh: 53; python: 21; makefile: 21; xml: 20
file content (35 lines) | stat: -rw-r--r-- 586 bytes parent folder | download
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)
	}
}