-
Notifications
You must be signed in to change notification settings - Fork 211
/
slots-tests.factor
51 lines (34 loc) · 1.32 KB
/
slots-tests.factor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
USING: accessors arrays generic.single kernel math
math.functions slots tools.test words eval vocabs.parser ;
IN: slots.tests
TUPLE: r/w-test foo ;
TUPLE: r/o-test { foo read-only } ;
[ r/o-test new 123 >>foo ] [ no-method? ] must-fail-with
TUPLE: decl-test { foo array } ;
[ decl-test new "" >>foo ] [ bad-slot-value? ] must-fail-with
TUPLE: hello length ;
{ 3 } [ "xyz" length>> ] unit-test
[ "xyz" 4 >>length ] [ no-method? ] must-fail-with
! Test protocol slots
SLOT: my-protocol-slot-test
TUPLE: protocol-slot-test-tuple x ;
M: protocol-slot-test-tuple my-protocol-slot-test>> x>> sq ;
M: protocol-slot-test-tuple my-protocol-slot-test<< [ sqrt ] dip x<< ;
{ 9 } [ T{ protocol-slot-test-tuple { x 3 } } my-protocol-slot-test>> ] unit-test
{ 4.0 } [
T{ protocol-slot-test-tuple { x 3 } } clone
[ 7 + ] change-my-protocol-slot-test x>>
] unit-test
UNION: comme-ci integer float ;
UNION: comme-ca integer float ;
comme-ca 25.5 "initial-value" set-word-prop
{ 0 t } [ comme-ci initial-value ] unit-test
{ 25.5 t } [ comme-ca initial-value ] unit-test
[
"IN: slots.tuple TUPLE: foobar { foo myfoobarx } ;"
eval( -- )
] [ error>> error>> no-word-error? ] must-fail-with
[
"USING: arrays ; IN: slots.tests TUPLE: foobar { aslot array initial: 5 } ;"
eval( -- )
] [ error>> bad-initial-value? ] must-fail-with