]> gitweb.factorcode.org Git - factor.git/blob - extra/slots/macros/macros-tests.factor
345cd4da892c383aec9663362d7ab6665a64ef1c
[factor.git] / extra / slots / macros / macros-tests.factor
1 ! (c) 2011 Joe Groff bsd license
2 USING: kernel math slots.macros tools.test ;
3 IN: slots.macros.tests
4
5 TUPLE: foo a b c ;
6
7 { 1 } [ T{ foo { a 1 } { b 2 } { c 3 } } "a" slot ] unit-test
8
9 { T{ foo { b 4 } } } [
10     foo new
11     [ 4 swap "b" set-slot ] keep
12 ] unit-test
13
14 { T{ foo { a 7 } { b 5 } { c 6 } } } [
15     foo new
16         5 "b" set-slot*
17         6 "c" set-slot*
18         7 "a" set-slot*
19 ] unit-test
20
21 { T{ foo { a 1 } { b 4 } { c 3 } } } [
22     T{ foo { a 1 } { b 2 } { c 3 } } clone
23     [ "b" [ 2 * ] change-slot ] keep
24 ] unit-test
25
26 { T{ foo { a 1/3 } { b 4 } { c 3 } } } [
27     T{ foo { a 1 } { b 2 } { c 3 } } clone
28     "b" [ 2 * ] change-slot*
29     "a" [ 3 / ] change-slot*
30 ] unit-test
31
32 { T{ foo { a 9 } { b 1 } } } [
33     T{ foo { a 8 } } clone
34     [ "a" inc-slot ]
35     [ "b" inc-slot ]
36     [ ] tri
37 ] unit-test
38
39 { T{ foo { a 12 } { b 3 } } } [
40     T{ foo { a 10 } } clone
41     [ 2 swap "a" slot+ ]
42     [ 3 swap "b" slot+ ]
43     [ ] tri
44 ] unit-test
45
46 { T{ foo { a V{ 1 2 } } { b V{ 3 } } } } [
47     foo new
48     V{ 1 } clone "a" set-slot*
49     [ 2 swap "a" push-slot ]
50     [ 3 swap "b" push-slot ]
51     [ ] tri
52 ] unit-test
53
54 { 2 1 3 } [
55     T{ foo { a 1 } { b 2 } { c 3 } }
56     { "b" "a" "c" } slots
57 ] unit-test
58
59 { { 2 1 3 } } [
60     T{ foo { a 1 } { b 2 } { c 3 } }
61     { "b" "a" "c" } slots>array
62 ] unit-test
63
64 { T{ foo { a "one" } { b "two" } { c "three" } } } [
65     "two" "one" "three"
66     T{ foo { a 1 } { b 2 } { c 3 } } clone
67     [ { "b" "a" "c" } set-slots ] keep
68 ] unit-test
69
70 { T{ foo { a "one" } { b "two" } { c "three" } } } [
71     { "two" "one" "three" }
72     T{ foo { a 1 } { b 2 } { c 3 } } clone
73     [ { "b" "a" "c" } array>set-slots ] keep
74 ] unit-test