Debian Codegraph @

src/tests.rs

raw symbols SCIP
1 // Copyright 2015 Ilkka Rauta
2 //
3 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6 // option. This file may not be copied, modified, or distributed
7 // except according to those terms.
8
9 use superrust-analyzer cargo bitreader 0.3.11 crate/::*;
10
11 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
12 fn read_bufferrust-analyzer cargo bitreader 0.3.11 tests/read_buffer().() {
13 let bytes = &[
14 0b1011_0101, 0b0110_1010, 0b1010_1100, 0b1001_1001,
15 0b1001_1001, 0b1001_1001, 0b1001_1001, 0b1110_0111,
16 ];
17
18 let mut reader = BitReaderrust-analyzer cargo bitreader 0.3.11 BitReader#::newrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]new().(bytes);
19
20 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u8rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u8().(1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0b1);
21 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.peek_u8rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]peek_u8().(3).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0b011);
22 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u8rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u8().(1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0b0);
23 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u8rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u8().(2).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0b11);
24
25 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().reader.is_alignedrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]is_aligned().(1));
26 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().reader.is_alignedrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]is_aligned().(2));
27 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().reader.is_alignedrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]is_aligned().(4));
28
29 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.positionrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]position().(), 4);
30 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.remainingrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]remaining().(), 60);
31
32 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u8rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u8().(4).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0b0101);
33
34 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(reader.is_alignedrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]is_aligned().(1));
35 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().reader.is_alignedrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]is_aligned().(2));
36 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().reader.is_alignedrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]is_aligned().(4));
37
38 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.alignrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]align().(1), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())); // shouldn't do anything if already aligned
39
40 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.peek_u64rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]peek_u64().(16).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0b110_1010_1010_1100);
41 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u8rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u8().(3).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0b11);
42 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.peek_u16rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]peek_u16().(13).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0b1010_1010_1100);
43 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.peek_u32rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]peek_u32().(13).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0b1010_1010_1100);
44 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.peek_u64rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]peek_u64().(13).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0b1010_1010_1100);
45 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.peek_u16rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]peek_u16().(10).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0b01_0101_0101);
46 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.peek_u8rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]peek_u8().(8).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0b0101_0101);
47 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u16rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u16().(10).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0b01_0101_0101);
48 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u8rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u8().(3).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0b100);
49
50 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.positionrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]position().(), 24);
51 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.remainingrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]remaining().(), 40);
52
53 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(reader.is_alignedrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]is_aligned().(1));
54
55 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u32rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u32().(32).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0b1001_1001_1001_1001_1001_1001_1001_1001);
56
57 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.peek_boolrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]peek_bool().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), true);
58 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u8rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u8().(4).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0b1110);
59 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.peek_boolrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]peek_bool().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), false);
60 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u8rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u8().(3).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0b011);
61 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.peek_boolrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]peek_bool().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), true);
62 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_boolrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_bool().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), true);
63
64 // Could also be 8 at this point!
65 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(reader.is_alignedrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]is_aligned().(4));
66
67 // shouldn't do anything if already aligned
68 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.alignrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]align().(1), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()));
69 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.alignrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]align().(2), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()));
70 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.alignrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]align().(4), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()));
71 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.alignrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]align().(8), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()));
72
73 // Start over to test align()
74 let mut reader = BitReaderrust-analyzer cargo bitreader 0.3.11 BitReader#::newrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]new().(bytes);
75
76 // shouldn't do anything if already aligned
77 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.alignrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]align().(1), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()));
78 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.alignrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]align().(2), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()));
79 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.alignrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]align().(4), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()));
80 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.alignrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]align().(8), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()));
81 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.positionrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]position().(), 0);
82
83 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u8rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u8().(1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0b1);
84
85 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.alignrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]align().(1), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()));
86 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.positionrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]position().(), 8);
87
88 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(reader.is_alignedrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]is_aligned().(1));
89 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().reader.is_alignedrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]is_aligned().(2));
90 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().reader.is_alignedrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]is_aligned().(4));
91
92 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.alignrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]align().(2), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()));
93 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.positionrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]position().(), 16);
94 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(reader.is_alignedrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]is_aligned().(1));
95 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(reader.is_alignedrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]is_aligned().(2));
96 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().reader.is_alignedrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]is_aligned().(4));
97
98 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u8rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u8().(7).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0b0101_0110);
99 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.alignrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]align().(4), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()));
100 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.positionrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]position().(), 32);
101 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(reader.is_alignedrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]is_aligned().(1));
102 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(reader.is_alignedrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]is_aligned().(2));
103 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(reader.is_alignedrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]is_aligned().(4));
104
105 let mut reader = BitReaderrust-analyzer cargo bitreader 0.3.11 BitReader#::newrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]new().(bytes);
106 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.positionrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]position().(), 0);
107 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.skiprust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]skip().(1), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()));
108 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.alignrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]align().(4), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()));
109 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.positionrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]position().(), 32);
110 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.skiprust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]skip().(7), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()));
111 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.alignrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]align().(1), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()));
112 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.positionrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]position().(), 40);
113 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.alignrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]align().(2), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()));
114 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.positionrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]position().(), 48);
115 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.skiprust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]skip().(5), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()));
116 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.alignrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]align().(2), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()));
117 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.positionrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]position().(), 64);
118
119 let mut reader = BitReaderrust-analyzer cargo bitreader 0.3.11 BitReader#::newrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]new().(bytes);
120 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.skiprust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]skip().(1), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()));
121 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.alignrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]align().(3), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()));
122 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.positionrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]position().(), 24);
123
124 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().reader.alignrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]align().(128).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
125 }
126
127 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
128 fn try_all_sizesrust-analyzer cargo bitreader 0.3.11 tests/try_all_sizes().() {
129 let bytes = &[
130 0x4a, 0x1e, 0x39, 0xbb, 0xd0, 0x07, 0xca, 0x9a,
131 0xa6, 0xba, 0x25, 0x52, 0x6f, 0x0a, 0x6a, 0xba,
132 ];
133
134 let mut reader = BitReaderrust-analyzer cargo bitreader 0.3.11 BitReader#::newrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]new().(bytes);
135 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u64rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u64().(64).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0x4a1e39bbd007ca9a);
136 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u64rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u64().(64).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0xa6ba25526f0a6aba);
137
138 let mut reader = BitReaderrust-analyzer cargo bitreader 0.3.11 BitReader#::newrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]new().(bytes);
139 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u32rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u32().(32).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0x4a1e39bb);
140 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u32rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u32().(32).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0xd007ca9a);
141 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u32rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u32().(32).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0xa6ba2552);
142 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u32rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u32().(32).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0x6f0a6aba);
143
144 let mut reader = BitReaderrust-analyzer cargo bitreader 0.3.11 BitReader#::newrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]new().(bytes);
145 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u16rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u16().(16).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0x4a1e);
146 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u16rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u16().(16).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0x39bb);
147 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u16rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u16().(16).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0xd007);
148 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u16rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u16().(16).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0xca9a);
149 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u16rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u16().(16).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0xa6ba);
150 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u16rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u16().(16).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0x2552);
151 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u16rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u16().(16).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0x6f0a);
152 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u16rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u16().(16).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0x6aba);
153
154 let mut reader = BitReaderrust-analyzer cargo bitreader 0.3.11 BitReader#::newrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]new().(&bytes[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().);
155 for byte in bytes {
156 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u8rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u8().(8).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().byte);
157 }
158 }
159
160 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
161 fn skipping_and_zero_readsrust-analyzer cargo bitreader 0.3.11 tests/skipping_and_zero_reads().() {
162 let bytes = &[
163 0b1011_0101, 0b1110_1010, 0b1010_1100, 0b0011_0101,
164 ];
165
166 let mut reader = BitReaderrust-analyzer cargo bitreader 0.3.11 BitReader#::newrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]new().(bytes);
167
168 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u8rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u8().(4).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0b1011);
169 // Reading zero bits should be a no-op
170 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u8rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u8().(0).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0b0);
171 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_i8rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_i8().(0).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0b0);
172 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u8rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u8().(4).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0b0101);
173 reader.skiprust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]skip().(3).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); // 0b111
174 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u16rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u16().(10).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0b0101010101);
175 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u8rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u8().(3).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0b100);
176 reader.skiprust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]skip().(4).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); // 0b0011
177 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u32rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u32().(2).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0b01);
178 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_boolrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_bool().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), false);
179 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_boolrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_bool().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), true);
180 }
181
182 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
183 fn errorsrust-analyzer cargo bitreader 0.3.11 tests/errors().() {
184 let bytes = &[
185 0b1011_0101, 0b1110_1010, 0b1010_1100,
186 ];
187
188 let mut reader = BitReaderrust-analyzer cargo bitreader 0.3.11 BitReader#::newrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]new().(bytes);
189 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u8rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u8().(4).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0b1011);
190 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u8rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u8().(9).unwrap_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_err().(), BitReaderErrorrust-analyzer cargo bitreader 0.3.11 BitReaderError#::TooManyBitsForTyperust-analyzer cargo bitreader 0.3.11 BitReaderError#TooManyBitsForType# {
191 positionrust-analyzer cargo bitreader 0.3.11 BitReaderError#TooManyBitsForType#position.: 4,
192 requestedrust-analyzer cargo bitreader 0.3.11 BitReaderError#TooManyBitsForType#requested.: 9,
193 allowedrust-analyzer cargo bitreader 0.3.11 BitReaderError#TooManyBitsForType#allowed.: 8
194 });
195 // If an error happens, it should be possible to resume as if nothing had happened
196 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u8rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u8().(4).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0b0101);
197
198 let mut reader = BitReaderrust-analyzer cargo bitreader 0.3.11 BitReader#::newrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]new().(bytes);
199 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u8rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u8().(4).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0b1011);
200 // Same with this error
201 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u32rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u32().(21).unwrap_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_err().(), BitReaderErrorrust-analyzer cargo bitreader 0.3.11 BitReaderError#::NotEnoughDatarust-analyzer cargo bitreader 0.3.11 BitReaderError#NotEnoughData# {
202 positionrust-analyzer cargo bitreader 0.3.11 BitReaderError#NotEnoughData#position.: 4,
203 lengthrust-analyzer cargo bitreader 0.3.11 BitReaderError#NotEnoughData#length.: (bytes.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). 8) as u64,
204 requestedrust-analyzer cargo bitreader 0.3.11 BitReaderError#NotEnoughData#requested.: 21
205 });
206 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u8rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u8().(4).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0b0101);
207 }
208
209 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
210 fn signed_valuesrust-analyzer cargo bitreader 0.3.11 tests/signed_values().() {
211 let from = -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][Neg]neg().2048;
212 let to = 2048;
213 for x in from..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#to {
214 let bytes = &[
215 (x rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i16][`Shr<i32>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i16][`Shr<i32>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i16][`Shr<i32>`]shr().8) as u8,
216 x as u8,
217 ];
218 let mut reader = BitReaderrust-analyzer cargo bitreader 0.3.11 BitReader#::newrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]new().(bytes);
219 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u8rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u8().(4).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), if x <rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]lt(). 0 { 0b1111 } else { 0 });
220 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_i16rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_i16().(12).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), x);
221 }
222 }
223
224 #[cfg(feature = "std")]
225 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
226 fn boolean_valuesrust-analyzer cargo bitreader 0.3.11 tests/boolean_values().() {
227 let bytes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> = (0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#16).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
228 let mut reader = BitReaderrust-analyzer cargo bitreader 0.3.11 BitReader#::newrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]new().(&bytes);
229 for v in &bytes {
230 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_boolrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_bool().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), false);
231 reader.skiprust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]skip().(3).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
232 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_boolrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_bool().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), v &rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[`&u8`][`BitAnd<u8>`]bitand(). 0x08 == 8);
233 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_boolrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_bool().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), v &rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[`&u8`][`BitAnd<u8>`]bitand(). 0x04 == 4);
234 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_boolrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_bool().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), v &rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[`&u8`][`BitAnd<u8>`]bitand(). 0x02 == 2);
235 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_boolrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_bool().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), v &rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[`&u8`][`BitAnd<u8>`]bitand(). 0x01 == 1);
236 }
237 }
238
239 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
240 fn read_slicerust-analyzer cargo bitreader 0.3.11 tests/read_slice().() {
241 let bytes = &[
242 0b1111_0000, 0b0000_1111, 0b1111_0000,
243 0b0000_1000, 0b0000_0100, 0b0000_0011,
244 0b1111_1100, 0b0000_0011, 0b1101_1000,
245 ];
246 let mut reader = BitReaderrust-analyzer cargo bitreader 0.3.11 BitReader#::newrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]new().(bytes);
247 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u8rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u8().(4).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0b1111);
248 // Just some pattern that's definitely not in the bytes array
249 let mut output = [0b1010_1101; 3];
250 reader.read_u8_slicerust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u8_slice().(&mut output).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
251 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&output, &[0u8, 255u8, 0u8]);
252
253 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u8rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u8().(1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 1);
254
255 reader.read_u8_slicerust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u8_slice().(&mut output[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut().1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#2]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut().).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
256 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&output, &[0u8, 0u8, 0u8]);
257
258 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u8rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u8().(1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 1);
259
260 output = [0b1010_1101; 3];
261 reader.read_u8_slicerust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u8_slice().(&mut output).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
262 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&output, &[0u8, 255u8, 0u8]);
263
264 reader.read_u8_slicerust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u8_slice().(&mut output[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut().0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut().).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
265 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(output[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()., 0b1111_0110);
266
267 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u8rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u8().(2).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0);
268 }
269
270 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
271 fn read_slice_too_muchrust-analyzer cargo bitreader 0.3.11 tests/read_slice_too_much().() {
272 let bytes = &[
273 0b1111_1111, 0b1111_1111, 0b1111_1111, 0b1111_1111,
274 ];
275 let mut reader = BitReaderrust-analyzer cargo bitreader 0.3.11 BitReader#::newrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]new().(bytes);
276 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u8rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u8().(1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 1);
277
278 let mut output = [0u8; 4];
279 let should_be_error = reader.read_u8_slicerust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u8_slice().(&mut output);
280 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(should_be_error.unwrap_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_err().(), BitReaderErrorrust-analyzer cargo bitreader 0.3.11 BitReaderError#::NotEnoughDatarust-analyzer cargo bitreader 0.3.11 BitReaderError#NotEnoughData# {
281 positionrust-analyzer cargo bitreader 0.3.11 BitReaderError#NotEnoughData#position.: 1,
282 lengthrust-analyzer cargo bitreader 0.3.11 BitReaderError#NotEnoughData#length.: (bytes.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). 8) as u64,
283 requestedrust-analyzer cargo bitreader 0.3.11 BitReaderError#NotEnoughData#requested.: (&output.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[`&usize`][`Mul<usize>`]mul(). 8) as u64
284 });
285 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&output, &[0u8; 4]);
286 }
287
288 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
289 fn relative_readerrust-analyzer cargo bitreader 0.3.11 tests/relative_reader().() {
290 let bytes = &[
291 0b0001_0010, 0b0011_0100,
292 ];
293 let mut reader = BitReaderrust-analyzer cargo bitreader 0.3.11 BitReader#::newrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]new().(bytes);
294 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u8rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u8().(4).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0b0001);
295
296 let mut relative_reader = reader.relative_readerrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]relative_reader().();
297
298 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u8rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u8().(4).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0b0010);
299 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u8rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u8().(4).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0b0011);
300 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u8rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u8().(4).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0b0100);
301
302 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u8rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u8().(1).unwrap_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_err().(), BitReaderErrorrust-analyzer cargo bitreader 0.3.11 BitReaderError#::NotEnoughDatarust-analyzer cargo bitreader 0.3.11 BitReaderError#NotEnoughData# {
303 positionrust-analyzer cargo bitreader 0.3.11 BitReaderError#NotEnoughData#position.: 16,
304 lengthrust-analyzer cargo bitreader 0.3.11 BitReaderError#NotEnoughData#length.: 16,
305 requestedrust-analyzer cargo bitreader 0.3.11 BitReaderError#NotEnoughData#requested.: 1
306 });
307
308 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(relative_reader.read_u8rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u8().(4).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0b0010);
309 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(relative_reader.read_u8rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u8().(4).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0b0011);
310 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(relative_reader.read_u8rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u8().(4).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0b0100);
311
312 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(relative_reader.read_u8rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u8().(1).unwrap_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_err().(), BitReaderErrorrust-analyzer cargo bitreader 0.3.11 BitReaderError#::NotEnoughDatarust-analyzer cargo bitreader 0.3.11 BitReaderError#NotEnoughData# {
313 positionrust-analyzer cargo bitreader 0.3.11 BitReaderError#NotEnoughData#position.: 12,
314 lengthrust-analyzer cargo bitreader 0.3.11 BitReaderError#NotEnoughData#length.: 12,
315 requestedrust-analyzer cargo bitreader 0.3.11 BitReaderError#NotEnoughData#requested.: 1
316 });
317 }
318
319 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
320 fn test_read_u64_maxrust-analyzer cargo bitreader 0.3.11 tests/test_read_u64_max().() {
321 let bytes = &[0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF];
322 let mut reader = BitReaderrust-analyzer cargo bitreader 0.3.11 BitReader#::newrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]new().(bytes);
323 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_u64rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_u64().(64).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), u64::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]MAX.);
324 }
325
326 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
327 fn test_read_i64_maxrust-analyzer cargo bitreader 0.3.11 tests/test_read_i64_max().() {
328 let bytes = &[0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF];
329 let mut reader = BitReaderrust-analyzer cargo bitreader 0.3.11 BitReader#::newrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]new().(bytes);
330 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.read_i64rust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]read_i64().(64).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().1);
331 }
332
333 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
334 fn relative_reader_remainingrust-analyzer cargo bitreader 0.3.11 tests/relative_reader_remaining().() {
335 let bytes = &[0b0001_0010, 0b0011_0100];
336 let mut reader = BitReaderrust-analyzer cargo bitreader 0.3.11 BitReader#::newrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]new().(bytes);
337 reader.skiprust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]skip().(2).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
338 let relative_reader = reader.relative_readerrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]relative_reader().();
339 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.remainingrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]remaining().(), 14);
340 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(relative_reader.remainingrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]remaining().(), 14);
341 }
342
343 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
344 fn make_relate_reader_twicerust-analyzer cargo bitreader 0.3.11 tests/make_relate_reader_twice().() {
345 let bytes = &[0b0011_0100, 0b0011_0100];
346 let mut reader = BitReaderrust-analyzer cargo bitreader 0.3.11 BitReader#::newrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]new().(bytes);
347 reader.skiprust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]skip().(9).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
348 let relate_reader_a = reader.relative_readerrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]relative_reader().();
349 let relate_reader_b = relate_reader_a.relative_readerrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]relative_reader().();
350 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(relate_reader_a.positionrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]position().(), 0);
351 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(relate_reader_b.positionrust-analyzer cargo bitreader 0.3.11 impl#[`BitReader<'a>`]position().(), 0);
352 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(relate_reader_a.positionrust-analyzer cargo bitreader 0.3.11 BitReader#position., relate_reader_b.positionrust-analyzer cargo bitreader 0.3.11 BitReader#position.);
353 }