]> gitweb.factorcode.org Git - factor.git/blob - basis/named-tuples/named-tuples-tests.factor
functors: inline the parts of interpolate this needs
[factor.git] / basis / named-tuples / named-tuples-tests.factor
1 USING: arrays assocs classes.tuple kernel math named-tuples
2 sequences tools.test ;
3 IN: named-tuples.tests
4
5 TUPLE: foo x y z ;
6
7 INSTANCE: foo named-tuple
8
9 { { f f f } } [ T{ foo } >array ] unit-test
10 { { 1 f f } } [ T{ foo f 1 } >array ] unit-test
11 { { 1 2 f } } [ T{ foo f 1 2 } >array ] unit-test
12 { { 1 2 3 } } [ T{ foo f 1 2 3 } >array ] unit-test
13
14 { T{ foo } } [ { } T{ foo } like ] unit-test
15 { T{ foo f 1 } } [ { 1 } T{ foo } like ] unit-test
16 { T{ foo f 1 2 } } [ { 1 2 } T{ foo } like ] unit-test
17 { T{ foo f 1 2 3 } } [ { 1 2 3 } T{ foo } like ] unit-test
18
19 { { { "x" f } { "y" f } { "z" f } } } [ T{ foo } >alist ] unit-test
20 { { { "x" 1 } { "y" f } { "z" f } } } [ T{ foo f 1 } >alist ] unit-test
21 { { { "x" 1 } { "y" 2 } { "z" f } } } [ T{ foo f 1 2 } >alist ] unit-test
22 { { { "x" 1 } { "y" 2 } { "z" 3 } } } [ T{ foo f 1 2 3 } >alist ] unit-test
23
24 { f } [ T{ foo } "x" of ] unit-test
25 { f } [ T{ foo } "y" of ] unit-test
26 { f } [ T{ foo } "z" of ] unit-test
27
28 { f f } [ "not found" T{ foo f 1 2 3 } at* ] unit-test
29
30 { T{ foo f "x" 2 3 } } [ T{ foo f 1 2 3 } "x" dup pick set-at ] unit-test
31
32 [ 1 "not found" T{ foo f 1 2 3 } set-at ] [ no-slot? ] must-fail-with
33
34 { 1 } [ T{ foo f 1 2 3 } "x" of ] unit-test
35 { 2 } [ T{ foo f 1 2 3 } "y" of ] unit-test
36 { 3 } [ T{ foo f 1 2 3 } "z" of ] unit-test
37
38 { 1 } [ 0 >bignum T{ foo f 1 2 3 } nth ] unit-test
39 { 2 } [ 1 >bignum T{ foo f 1 2 3 } nth ] unit-test
40 { 3 } [ 2 >bignum T{ foo f 1 2 3 } nth ] unit-test