tuple immutable

This commit is contained in:
2026-02-12 13:46:53 +03:00
parent ce8c5b516e
commit 6d2ef61432
2 changed files with 54 additions and 9 deletions

View File

@@ -1,6 +1,9 @@
package extypes
import "testing"
import (
"encoding/json"
"testing"
)
func TestTuple(t *testing.T) {
t1 := NewTupleFrom([]int{1, 2, 3})
@@ -10,3 +13,37 @@ func TestTuple(t *testing.T) {
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)
}