1 IN: struct-arrays.tests
2 USING: classes.struct struct-arrays tools.test kernel math sequences
3 alien.syntax alien.c-types destructors libc accessors sequences.private
4 compiler.tree.debugger combinators.smart ;
6 STRUCT: test-struct-array
11 1 struct-array{ test-struct-array } new-sequence length
14 [ V{ test-struct-array } ] [
15 [ [ test-struct-array <struct> ] struct-array{ test-struct-array } output>sequence first ] final-classes
18 : make-point ( x y -- struct )
19 test-struct-array <struct-boa> ;
22 2 test-struct-array <struct-array>
23 1 2 make-point over set-first
24 3 4 make-point over set-second
25 0 [ [ x>> ] [ y>> ] bi / + ] reduce
30 2 test-struct-array malloc-struct-array
32 1 2 make-point over set-first
33 3 4 make-point over set-second
34 0 [ [ x>> ] [ y>> ] bi / + ] reduce
38 [ ] [ ALIEN: 123 10 test-struct-array <direct-struct-array> drop ] unit-test
42 10 test-struct-array malloc-struct-array
47 [ 15 ] [ 15 10 test-struct-array <struct-array> resize length ] unit-test
49 [ S{ test-struct-array f 12 20 } ] [
50 struct-array{ test-struct-array
51 S{ test-struct-array f 4 20 }
52 S{ test-struct-array f 12 20 }
53 S{ test-struct-array f 20 20 }
58 STRUCT: fixed-string { text char[100] } ;
60 [ { ALIEN: 123 ALIEN: 223 ALIEN: 323 ALIEN: 423 } ] [
61 ALIEN: 123 4 fixed-string <direct-struct-array> [ (underlying)>> ] { } map-as
64 [ 10 "int" <struct-array> ] must-fail
66 STRUCT: wig { x int } ;
67 : <bacon> ( -- wig ) 0 wig <struct-boa> ; inline
68 : waterfall ( -- a b ) 1 wig <struct-array> <bacon> swap first x>> ; inline
70 [ t ] [ [ waterfall ] { x>> } inlined? ] unit-test