2009-08-13 17:59:38 -04:00
|
|
|
! (c)Joe Groff bsd license
|
2009-08-12 10:01:32 -04:00
|
|
|
USING: accessors alien.c-types classes.c-types classes.struct
|
2009-08-19 21:32:49 -04:00
|
|
|
combinators io.streams.string kernel libc math multiline namespaces
|
|
|
|
prettyprint prettyprint.config see tools.test ;
|
2009-08-12 10:01:32 -04:00
|
|
|
IN: classes.struct.tests
|
2009-08-11 22:13:18 -04:00
|
|
|
|
|
|
|
STRUCT: foo
|
|
|
|
{ x char }
|
|
|
|
{ y int initial: 123 }
|
|
|
|
{ z boolean } ;
|
|
|
|
|
|
|
|
STRUCT: bar
|
|
|
|
{ w ushort initial: HEX: ffff }
|
|
|
|
{ foo foo } ;
|
|
|
|
|
|
|
|
[ 12 ] [ foo heap-size ] unit-test
|
|
|
|
[ 16 ] [ bar heap-size ] unit-test
|
2009-08-14 07:09:37 -04:00
|
|
|
[ 123 ] [ foo <struct> y>> ] unit-test
|
|
|
|
[ 123 ] [ bar <struct> foo>> y>> ] unit-test
|
2009-08-12 10:01:32 -04:00
|
|
|
|
|
|
|
[ 1 2 3 t ] [
|
2009-08-14 07:09:37 -04:00
|
|
|
1 2 3 t foo <struct-boa> bar <struct-boa>
|
2009-08-12 10:01:32 -04:00
|
|
|
{
|
|
|
|
[ w>> ]
|
|
|
|
[ foo>> x>> ]
|
|
|
|
[ foo>> y>> ]
|
|
|
|
[ foo>> z>> ]
|
|
|
|
} cleave
|
|
|
|
] unit-test
|
2009-08-12 16:04:27 -04:00
|
|
|
|
|
|
|
[ 7654 ] [ S{ foo f 98 7654 f } y>> ] unit-test
|
|
|
|
[ 7654 ] [ S{ foo { y 7654 } } y>> ] unit-test
|
2009-08-12 16:09:25 -04:00
|
|
|
|
2009-08-13 16:55:22 -04:00
|
|
|
UNION-STRUCT: float-and-bits
|
|
|
|
{ f single-float }
|
|
|
|
{ bits uint } ;
|
|
|
|
|
|
|
|
[ 1.0 ] [ float-and-bits <struct> 1.0 float>bits >>bits f>> ] unit-test
|
2009-08-18 14:10:52 -04:00
|
|
|
[ 4 ] [ float-and-bits heap-size ] unit-test
|
2009-08-13 16:55:22 -04:00
|
|
|
|
2009-08-18 14:10:52 -04:00
|
|
|
[ ] [ foo malloc-struct free ] unit-test
|
2009-08-19 21:21:57 -04:00
|
|
|
|
|
|
|
[ "S{ foo { y 7654 } }" ]
|
|
|
|
[ f boa-tuples? [ foo <struct> 7654 >>y [ pprint ] with-string-writer ] with-variable ] unit-test
|
|
|
|
|
|
|
|
[ "S{ foo f 0 7654 f }" ]
|
|
|
|
[ t boa-tuples? [ foo <struct> 7654 >>y [ pprint ] with-string-writer ] with-variable ] unit-test
|
|
|
|
|
2009-08-19 21:32:49 -04:00
|
|
|
[ <" USING: classes.c-types classes.struct kernel ;
|
|
|
|
IN: classes.struct.tests
|
|
|
|
STRUCT: foo
|
|
|
|
{ x char initial: 0 } { y int initial: 123 }
|
|
|
|
{ z boolean initial: f } ;
|
|
|
|
"> ]
|
|
|
|
[ [ foo see ] with-string-writer ] unit-test
|
|
|
|
|
|
|
|
[ <" USING: classes.c-types classes.struct ;
|
|
|
|
IN: classes.struct.tests
|
|
|
|
UNION-STRUCT: float-and-bits
|
|
|
|
{ f single-float initial: 0.0 } { bits uint initial: 0 } ;
|
|
|
|
"> ]
|
|
|
|
[ [ float-and-bits see ] with-string-writer ] unit-test
|