File: plain_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 (61 lines) | stat: -rw-r--r-- 1,443 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package storage_test

import (
	"errors"
	"github.com/tomwright/dasel/v2"
	"github.com/tomwright/dasel/v2/storage"
	"testing"
)

func TestPlainParser_FromBytes(t *testing.T) {
	_, err := (&storage.PlainParser{}).FromBytes(nil)
	if !errors.Is(err, storage.ErrPlainParserNotImplemented) {
		t.Errorf("unexpected error: %v", err)
	}
}

func TestPlainParser_ToBytes(t *testing.T) {
	t.Run("Basic", func(t *testing.T) {
		gotVal, err := (&storage.PlainParser{}).ToBytes(dasel.ValueOf("asd"))
		if err != nil {
			t.Errorf("unexpected error: %s", err)
			return
		}
		exp := `asd
`
		got := string(gotVal)
		if exp != got {
			t.Errorf("expected:\n%s\ngot:\n%s", exp, got)
		}
	})
	t.Run("SingleDocument", func(t *testing.T) {
		gotVal, err := (&storage.PlainParser{}).ToBytes(dasel.ValueOf("asd").WithMetadata("isSingleDocument", true))
		if err != nil {
			t.Errorf("unexpected error: %s", err)
			return
		}
		exp := `asd
`
		got := string(gotVal)
		if exp != got {
			t.Errorf("expected:\n%s\ngot:\n%s", exp, got)
		}
	})
	t.Run("MultiDocument", func(t *testing.T) {
		val := dasel.ValueOf([]interface{}{"asd", "123"})
		daselVal := dasel.ValueOf(val).WithMetadata("isMultiDocument", true)

		gotVal, err := (&storage.PlainParser{}).ToBytes(daselVal)
		if err != nil {
			t.Errorf("unexpected error: %s", err)
			return
		}
		exp := `asd
123
`
		got := string(gotVal)
		if exp != got {
			t.Errorf("expected:\n%s\ngot:\n%s", exp, got)
		}
	})
}