Files
extypes/tuple_test.go
2026-02-12 13:46:53 +03:00

50 lines
919 B
Go

package extypes
import (
"encoding/json"
"testing"
)
func TestTuple(t *testing.T) {
t1 := NewTupleFrom([]int{1, 2, 3})
t2 := NewTupleFrom([]int{1, 2, 3})
if !t1.Equal(t2) {
t.Error("t1 and t2 should be equal")
}
}
func TestTuple_MarshalJSON(t *testing.T) {
t1 := NewTupleFrom([]int{1, 2, 3})
data, err := json.Marshal(t1)
if err != nil {
t.Fatal(err)
}
s := "[1,2,3]"
if string(data) != s {
t.Error("t1 and t2 should be equal")
}
}
func TestTuple_UnmarshalJSON(t *testing.T) {
s := "[1,2,3]"
t1 := NewTuple[int]()
err := json.Unmarshal([]byte(s), &t1)
if err != nil {
t.Fatal(err)
}
t2 := NewTupleFrom([]int{1, 2, 3})
t.Log(t1, t2)
if !t1.Equal(t2) {
t.Error("t1 and t2 should be equal")
}
st1 := struct {
A int `json:"a"`
B Tuple[int] `json:"b"`
}{}
s2 := `{"a":1,"b":[1,2,3]}`
if err := json.Unmarshal([]byte(s2), &st1); err != nil {
t.Fatal(err)
}
t.Log(st1)
}