]> gitweb.factorcode.org Git - factor.git/blob - basis/cocoa/cocoa-tests.factor
inverse: Fix docs
[factor.git] / basis / cocoa / cocoa-tests.factor
1 USING: alien.c-types cocoa cocoa.classes cocoa.subclassing
2 cocoa.types compiler.test core-graphics.types kernel math memory
3 namespaces tools.test ;
4 IN: cocoa.tests
5
6 <CLASS: Foo < NSObject
7     METHOD: void foo: NSRect rect [
8         gc rect "x" set
9     ] ;
10 ;CLASS>
11
12 : test-foo ( -- )
13     Foo -> alloc -> init
14     dup 1.0 2.0 101.0 102.0 <CGRect> -> foo:
15     -> release ;
16
17 { } [ test-foo ] unit-test
18
19 { 1.0 } [ "x" get CGRect-x ] unit-test
20 { 2.0 } [ "x" get CGRect-y ] unit-test
21 { 101.0 } [ "x" get CGRect-w ] unit-test
22 { 102.0 } [ "x" get CGRect-h ] unit-test
23
24 <CLASS: Bar < NSObject
25     METHOD: NSRect bar [ test-foo "x" get ] ;
26 ;CLASS>
27
28 { } [
29     Bar [
30         -> alloc -> init
31         dup -> bar "x" set
32         -> release
33     ] compile-call
34 ] unit-test
35
36 { 1.0 } [ "x" get CGRect-x ] unit-test
37 { 2.0 } [ "x" get CGRect-y ] unit-test
38 { 101.0 } [ "x" get CGRect-w ] unit-test
39 { 102.0 } [ "x" get CGRect-h ] unit-test
40
41 ! Make sure that we can add methods
42 <CLASS: Bar < NSObject
43     METHOD: NSRect bar [ test-foo "x" get ] ;
44
45     METHOD: int babb: int x [ x sq ] ;
46 ;CLASS>
47
48 { 144 } [
49     Bar [
50         -> alloc -> init
51         dup 12 -> babb:
52         swap -> release
53     ] compile-call
54 ] unit-test