mirror of
https://github.com/IBM/fp-go.git
synced 2025-06-17 00:07:49 +02:00
26 lines
634 B
Go
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])))
|
|
}
|