github.com/tomwright/dasel@v1.27.3/storage/plain_test.go (about)

     1  package storage_test
     2  
     3  import (
     4  	"errors"
     5  	"github.com/tomwright/dasel/storage"
     6  	"testing"
     7  )
     8  
     9  func TestPlainParser_FromBytes(t *testing.T) {
    10  	_, err := (&storage.PlainParser{}).FromBytes(nil)
    11  	if !errors.Is(err, storage.ErrPlainParserNotImplemented) {
    12  		t.Errorf("unexpected error: %v", err)
    13  	}
    14  }
    15  
    16  func TestPlainParser_ToBytes(t *testing.T) {
    17  	t.Run("Basic", func(t *testing.T) {
    18  		gotVal, err := (&storage.PlainParser{}).ToBytes("asd")
    19  		if err != nil {
    20  			t.Errorf("unexpected error: %s", err)
    21  			return
    22  		}
    23  		exp := `asd
    24  `
    25  		got := string(gotVal)
    26  		if exp != got {
    27  			t.Errorf("expected:\n%s\ngot:\n%s", exp, got)
    28  		}
    29  	})
    30  	t.Run("SingleDocument", func(t *testing.T) {
    31  		gotVal, err := (&storage.PlainParser{}).ToBytes(&storage.BasicSingleDocument{Value: "asd"})
    32  		if err != nil {
    33  			t.Errorf("unexpected error: %s", err)
    34  			return
    35  		}
    36  		exp := `asd
    37  `
    38  		got := string(gotVal)
    39  		if exp != got {
    40  			t.Errorf("expected:\n%s\ngot:\n%s", exp, got)
    41  		}
    42  	})
    43  	t.Run("MultiDocument", func(t *testing.T) {
    44  		gotVal, err := (&storage.PlainParser{}).ToBytes(&storage.BasicMultiDocument{Values: []interface{}{"asd", "123"}})
    45  		if err != nil {
    46  			t.Errorf("unexpected error: %s", err)
    47  			return
    48  		}
    49  		exp := `asd
    50  123
    51  `
    52  		got := string(gotVal)
    53  		if exp != got {
    54  			t.Errorf("expected:\n%s\ngot:\n%s", exp, got)
    55  		}
    56  	})
    57  }