summaryrefslogtreecommitdiff
path: root/reencode_test.go
blob: 888643248d1ee21a83b64fbedc7c526ef34c8538 (plain)
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
36
// Copyright (C) 2022  Luke Shumaker <lukeshu@lukeshu.com>
//
// SPDX-License-Identifier: GPL-2.0-or-later

package lowmemjson

import (
	"strings"
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestReEncodeCompactIfUnder(t *testing.T) {
	var out strings.Builder
	enc := NewEncoder(&ReEncoder{
		Out:                 &out,
		AllowMultipleValues: true,
		Indent:              "\t",
		CompactIfUnder:      10,
	})

	obj := map[string][]string{
		"a": {"b", "c"},
		"d": {"eeeeeeeeeeeeeee"},
	}

	assert.NoError(t, enc.Encode(obj))
	exp := `{
	"a": ["b","c"],
	"d": [
		"eeeeeeeeeeeeeee"
	]
}`
	assert.Equal(t, exp, out.String())
}