2008-12-03 10:41:48 -05:00
|
|
|
IN: struct-arrays.tests
|
2009-08-26 18:38:33 -04:00
|
|
|
USING: classes.struct struct-arrays tools.test kernel math sequences
|
2009-07-07 20:15:50 -04:00
|
|
|
alien.syntax alien.c-types destructors libc accessors sequences.private ;
|
2008-12-03 10:41:48 -05:00
|
|
|
|
2009-08-26 18:38:33 -04:00
|
|
|
STRUCT: test-struct-array
|
|
|
|
{ x int }
|
|
|
|
{ y int } ;
|
2008-12-03 10:41:48 -05:00
|
|
|
|
|
|
|
: make-point ( x y -- struct )
|
2009-08-26 18:38:33 -04:00
|
|
|
test-struct-array <struct-boa> ;
|
2008-12-03 10:41:48 -05:00
|
|
|
|
|
|
|
[ 5/4 ] [
|
2009-08-26 18:38:33 -04:00
|
|
|
2 test-struct-array <struct-array>
|
2008-12-03 10:41:48 -05:00
|
|
|
1 2 make-point over set-first
|
|
|
|
3 4 make-point over set-second
|
2009-08-26 18:38:33 -04:00
|
|
|
0 [ [ x>> ] [ y>> ] bi / + ] reduce
|
2008-12-03 10:41:48 -05:00
|
|
|
] unit-test
|
2008-12-03 10:54:59 -05:00
|
|
|
|
|
|
|
[ 5/4 ] [
|
|
|
|
[
|
2009-08-26 18:38:33 -04:00
|
|
|
2 test-struct-array malloc-struct-array
|
2009-02-06 05:37:28 -05:00
|
|
|
dup &free drop
|
2008-12-03 10:54:59 -05:00
|
|
|
1 2 make-point over set-first
|
|
|
|
3 4 make-point over set-second
|
2009-08-26 18:38:33 -04:00
|
|
|
0 [ [ x>> ] [ y>> ] bi / + ] reduce
|
2008-12-03 10:54:59 -05:00
|
|
|
] with-destructors
|
|
|
|
] unit-test
|
2008-12-18 22:17:24 -05:00
|
|
|
|
2009-08-26 18:38:33 -04:00
|
|
|
[ ] [ ALIEN: 123 10 test-struct-array <direct-struct-array> drop ] unit-test
|
2008-12-18 22:17:24 -05:00
|
|
|
|
|
|
|
[ ] [
|
|
|
|
[
|
2009-08-26 18:38:33 -04:00
|
|
|
10 test-struct-array malloc-struct-array
|
2009-02-06 05:37:28 -05:00
|
|
|
&free drop
|
2008-12-18 22:17:24 -05:00
|
|
|
] with-destructors
|
2009-07-07 16:01:30 -04:00
|
|
|
] unit-test
|
|
|
|
|
2009-08-26 18:38:33 -04:00
|
|
|
[ 15 ] [ 15 10 test-struct-array <struct-array> resize length ] unit-test
|
|
|
|
|
2009-08-26 19:09:02 -04:00
|
|
|
[ S{ test-struct-array f 12 20 } ] [
|
|
|
|
struct-array{ test-struct-array
|
|
|
|
S{ test-struct-array f 4 20 }
|
|
|
|
S{ test-struct-array f 12 20 }
|
|
|
|
S{ test-struct-array f 20 20 }
|
|
|
|
} second
|
|
|
|
] unit-test
|
2009-08-30 06:11:08 -04:00
|
|
|
|
|
|
|
! Regression
|
|
|
|
STRUCT: fixed-string { text char[100] } ;
|
|
|
|
|
|
|
|
[ { ALIEN: 123 ALIEN: 223 ALIEN: 323 ALIEN: 423 } ] [
|
|
|
|
ALIEN: 123 4 fixed-string <direct-struct-array> [ (underlying)>> ] { } map-as
|
|
|
|
] unit-test
|
2009-09-01 15:58:49 -04:00
|
|
|
|
|
|
|
[ 10 "int" <struct-array> ] must-fail
|