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