1
0
mirror of https://github.com/IBM/fp-go.git synced 2025-06-17 00:07:49 +02:00
Files
fp-go/json/type_test.go
Dr. Carsten Leue b25de3c7c3 doc: fix case
Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
2023-07-18 15:57:54 +02:00

26 lines
634 B
Go

package json
import (
"testing"
E "github.com/IBM/fp-go/either"
F "github.com/IBM/fp-go/function"
"github.com/stretchr/testify/assert"
)
type TestType struct {
A string `json:"a"`
B int `json:"b"`
}
func TestToType(t *testing.T) {
generic := map[string]any{"a": "value", "b": 1}
assert.True(t, E.IsRight(ToTypeE[TestType](generic)))
assert.True(t, E.IsRight(ToTypeE[TestType](&generic)))
assert.Equal(t, E.Right[error](&TestType{A: "value", B: 1}), ToTypeE[*TestType](&generic))
assert.Equal(t, E.Right[error](TestType{A: "value", B: 1}), F.Pipe1(ToTypeE[*TestType](&generic), E.Map[error](F.Deref[TestType])))
}