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) }