factor/basis/cocoa/cocoa-tests.factor

72 lines
1.3 KiB
Factor
Raw Normal View History

2008-03-01 17:00:45 -05:00
IN: cocoa.tests
2007-09-20 18:09:08 -04:00
USING: cocoa cocoa.messages cocoa.subclassing cocoa.types
2008-02-25 20:37:43 -05:00
compiler kernel namespaces cocoa.classes tools.test memory
compiler.units math core-graphics.types ;
2007-09-20 18:09:08 -04:00
CLASS: {
{ +superclass+ "NSObject" }
{ +name+ "Foo" }
} {
"foo:"
"void"
{ "id" "SEL" "NSRect" }
[ gc "x" set 2drop ]
2007-09-20 18:09:08 -04:00
} ;
: test-foo
Foo -> alloc -> init
dup 1.0 2.0 101.0 102.0 <CGRect> -> foo:
2007-09-20 18:09:08 -04:00
-> release ;
test-foo
[ 1.0 ] [ "x" get CGRect-x ] unit-test
[ 2.0 ] [ "x" get CGRect-y ] unit-test
[ 101.0 ] [ "x" get CGRect-w ] unit-test
[ 102.0 ] [ "x" get CGRect-h ] unit-test
2007-09-20 18:09:08 -04:00
CLASS: {
{ +superclass+ "NSObject" }
{ +name+ "Bar" }
} {
"bar"
"NSRect"
{ "id" "SEL" }
[ 2drop test-foo "x" get ]
} ;
Bar [
-> alloc -> init
dup -> bar "x" set
-> release
] compile-call
2007-09-20 18:09:08 -04:00
[ 1.0 ] [ "x" get CGRect-x ] unit-test
[ 2.0 ] [ "x" get CGRect-y ] unit-test
[ 101.0 ] [ "x" get CGRect-w ] unit-test
[ 102.0 ] [ "x" get CGRect-h ] unit-test
2008-12-04 22:22:48 -05:00
! Make sure that we can add methods
CLASS: {
{ +superclass+ "NSObject" }
{ +name+ "Bar" }
} {
"bar"
"NSRect"
2008-12-04 22:22:48 -05:00
{ "id" "SEL" }
[ 2drop test-foo "x" get ]
} {
"babb"
"int"
{ "id" "SEL" "int" }
[ 2nip sq ]
} ;
[ 144 ] [
Bar [
-> alloc -> init
dup 12 -> babb
swap -> release
] compile-call
] unit-test