1 ! Copyright (C) 2006 Chris Double.
2 ! See http://factorcode.org/license.txt for BSD license.
4 USING: tools.test kernel serialize io io.streams.byte-array
5 alien arrays byte-arrays bit-arrays specialized-arrays
6 sequences math prettyprint parser classes math.constants
7 io.encodings.binary random assocs serialize.private alien.c-types
8 combinators.short-circuit literals ;
9 SPECIALIZED-ARRAY: double
12 : (test-serialize-cell) ( n -- ? )
14 binary [ serialize-cell ] with-byte-writer
15 binary [ deserialize-cell ] with-byte-reader = ;
17 : test-serialize-cell ( a -- ? )
18 2^ random (test-serialize-cell) ;
24 [ 40 [ test-serialize-cell ] all-integers? ]
25 [ 4 [ 40 * test-serialize-cell ] all-integers? ]
26 [ 4 [ 400 * test-serialize-cell ] all-integers? ]
27 [ 4 [ 4000 * test-serialize-cell ] all-integers? ]
33 2^ 3 [ 1 - + (test-serialize-cell) ] with all-integers?
37 TUPLE: serialize-test a b ;
39 C: <serialize-test> serialize-test
56 "hello \u012345 unicode"
59 T{ serialize-test f "a" 2 }
62 double-array{ 1.0 3.0 4.0 1.0 2.35 0.33 }
63 << 1 [ 2 ] curry suffix! >>
64 { { "a" "bc" } { "de" "fg" } }
65 H{ { "a" "bc" } { "de" "fg" } }
68 : check-serialize-1 ( obj -- ? )
77 : check-serialize-2 ( obj -- ? )
78 dup number? over wrapper? or [
79 drop t ! we don't care if numbers aren't interned
89 { t } [ objects [ check-serialize-1 ] all? ] unit-test
91 { t } [ objects [ check-serialize-2 ] all? ] unit-test
93 { t } [ pi check-serialize-1 ] unit-test
94 [ serialize ] must-infer
95 [ deserialize ] must-infer
105 H{ } dup dup dup set-at
111 ! Changed the serialization of numbers in [2^1008;2^1024[
112 ! check backwards compatibility
114 255 1 127 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
115 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
116 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
117 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
118 0 0 0 0 0 0 0 0 0 0 0 0
119 } binary [ deserialize-cell ] with-byte-reader ] unit-test
121 ${ 1024 2^ 1 - } [ B{
122 255 1 128 255 255 255 255 255 255 255 255 255 255 255 255
123 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
124 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
125 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
126 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
127 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
128 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
129 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
130 255 255 255 255 255 255 255 255 255 255 255
131 } binary [ deserialize-cell ] with-byte-reader ] unit-test