]> gitweb.factorcode.org Git - factor.git/blob - basis/pack/pack-tests.factor
inverse: Add `under`
[factor.git] / basis / pack / pack-tests.factor
1 USING: alien.c-types io io.streams.string kernel make namespaces
2 pack pack.private strings tools.test ;
3
4 { B{ 1 0 2 0 0 3 0 0 0 4 0 0 0 0 0 0 0 5 } } [
5     { 1 2 3 4 5 }
6     "cstiq" pack-be
7 ] unit-test
8
9 { { 1 2 3 4 5 } } [
10     { 1 2 3 4 5 }
11     "cstiq" [ pack-be ] keep unpack-be
12 ] unit-test
13
14 { B{ 1 2 0 3 0 0 4 0 0 0 5 0 0 0 0 0 0 0 } } [
15     { 1 2 3 4 5 } "cstiq" pack-le
16 ] unit-test
17
18 { { 1 2 3 4 5 } } [
19     { 1 2 3 4 5 }
20     "cstiq" [ pack-le ] keep unpack-le
21 ] unit-test
22
23 { { -1 -2 -3 -4 -5 } } [
24     { -1 -2 -3 -4 -5 }
25     "cstiq" [ pack-le ] keep unpack-le
26 ] unit-test
27
28 { { -1 -2 -3 -4 -5 3.14 } } [
29     { -1 -2 -3 -4 -5 3.14 }
30     "cstiqd" [ pack-be ] keep unpack-be
31 ] unit-test
32
33 { { -1 -2 -3 -4 -5 } } [
34     { -1 -2 -3 -4 -5 }
35     "cstiq" [ pack-native ] keep unpack-native
36 ] unit-test
37
38 { B{ 1 2 3 4 5 0 0 0 } } [ { 1 2 3 4 5 } "4ci" pack-le ] unit-test
39 { { 1 2 3 4 5 } } [ B{ 1 2 3 4 5 0 0 0 } "4ci" unpack-le ] unit-test
40
41 { 9 } [ "iic" packed-length ] unit-test
42 [ "iii" read-packed-le ] must-infer
43 [ "iii" read-packed-be ] must-infer
44 [ "iii" read-packed-native ] must-infer
45 [ "iii" unpack-le ] must-infer
46 [ "iii" unpack-be ] must-infer
47 [ "iii" unpack-native ] must-infer
48 [ "iii" pack ] must-infer
49 [ "iii" unpack ] must-infer
50
51 [ "iii" pack ] must-infer
52
53 { "c" } [ "1c" expand-pack-format ] unit-test
54 { "cccc" } [ "4c" expand-pack-format ] unit-test
55 { "cccccccccccc" } [ "12c" expand-pack-format ] unit-test
56 { "iccqqq" } [ "1i2c3q" expand-pack-format ] unit-test
57
58 { B{ 1 0 0 0 } } [ 1 int32_t >n-byte-array ] unit-test