@@ -52,4 +52,63 @@ func TestTuple(t *testing.T) {
5252 t .Error ("Expected C, got" , v )
5353 }
5454 }
55+ if ! tuple .CanContain (new (List )) {
56+ t .Error ("Tuple must be able to contain anything" )
57+ }
58+ }
59+
60+ func TestList (t * testing.T ) {
61+ list := new (List )
62+ list .AddValues (Int (1 ), Int (2 ), Int (3 ))
63+ if ! list .Type ().Is (NewListType (IntType )) {
64+ t .Error ("Expected int, got" , list .Type ())
65+ }
66+ val := list .Value ().([]Value )
67+ for i , value := range list .GetValues () {
68+ if val [i ] != value {
69+ t .Error ("Expected" , value , "got" , val [i ])
70+ }
71+ }
72+ if len (val ) != 3 {
73+ t .Error ("Expected 3, got" , len (val ))
74+ }
75+ if ! val [0 ].Type ().Is (IntType ) {
76+ t .Error ("Expected string, got" , val [0 ].Type ())
77+ }
78+ v , ok := val [0 ].Value ().(int )
79+ if ! ok {
80+ t .Error ("Cannot convert value to string" )
81+ } else {
82+ if v != 1 {
83+ t .Error ("Expected 1, got" , v )
84+ }
85+ }
86+ if ! val [1 ].Type ().Is (IntType ) {
87+ t .Error ("Expected int, got" , val [1 ].Type ())
88+ }
89+ vi , ok := val [1 ].Value ().(int )
90+ if ! ok {
91+ t .Error ("Cannot convert value to int" )
92+ } else {
93+ if vi != 2 {
94+ t .Error ("Expected 2, got" , vi )
95+ }
96+ }
97+ if ! val [2 ].Type ().Is (IntType ) {
98+ t .Error ("Expected int, got" , val [2 ].Type ())
99+ }
100+ v , ok = val [2 ].Value ().(int )
101+ if ! ok {
102+ t .Error ("Cannot convert value to string" )
103+ } else {
104+ if v != 3 {
105+ t .Error ("Expected 3, got" , v )
106+ }
107+ }
108+ if ! list .CanContain (Int (0 )) {
109+ t .Error ("List must be able to contain the same type" )
110+ }
111+ if list .CanContain (String ("A" )) {
112+ t .Error ("List must contain only values with the same type" )
113+ }
55114}
0 commit comments