Debian Codegraph @

tests/ser.rs

raw symbols SCIP
1 use serderust-analyzer cargo serde 1.0.144 crate/::Serializerust-analyzer cargo serde 1.0.144 ser/Serialize#;
2 use serde_cbor_2rust-analyzer cargo serde_cbor_2 0.13.0 crate/::serrust-analyzer cargo serde_cbor_2 0.13.0 ser/::{Serializerrust-analyzer cargo serde_cbor_2 0.13.0 ser/Serializer#, SliceWriterust-analyzer cargo serde_cbor_2 0.13.0 write/SliceWrite#};
3
4 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
5 fn test_strrust-analyzer cargo serde_cbor_2 0.13.0 test_str().() {
6 serialize_and_comparerust-analyzer cargo serde_cbor_2 0.13.0 serialize_and_compare().("foobar", b"ffoobar");
7 }
8
9 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
10 fn test_listrust-analyzer cargo serde_cbor_2 0.13.0 test_list().() {
11 serialize_and_comparerust-analyzer cargo serde_cbor_2 0.13.0 serialize_and_compare().([1, 2, 3], b"\x83\x01\x02\x03");
12 }
13
14 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
15 fn test_floatrust-analyzer cargo serde_cbor_2 0.13.0 test_float().() {
16 serialize_and_comparerust-analyzer cargo serde_cbor_2 0.13.0 serialize_and_compare().(12.3f64, b"\xfb@(\x99\x99\x99\x99\x99\x9a");
17 }
18
19 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
20 fn test_integerrust-analyzer cargo serde_cbor_2 0.13.0 test_integer().() {
21 // u8
22 serialize_and_comparerust-analyzer cargo serde_cbor_2 0.13.0 serialize_and_compare().(24, b"\x18\x18");
23 // i8
24 serialize_and_comparerust-analyzer cargo serde_cbor_2 0.13.0 serialize_and_compare().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().5, b"\x24");
25 // i16
26 serialize_and_comparerust-analyzer cargo serde_cbor_2 0.13.0 serialize_and_compare().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().300, b"\x39\x01\x2b");
27 // i32
28 serialize_and_comparerust-analyzer cargo serde_cbor_2 0.13.0 serialize_and_compare().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().23567997, b"\x3a\x01\x67\x9e\x7c");
29 // u64
30 serialize_and_comparerust-analyzer cargo serde_cbor_2 0.13.0 serialize_and_compare().(u64::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]MAX., b"\x1b\xff\xff\xff\xff\xff\xff\xff\xff");
31 }
32
33 fn serialize_and_comparerust-analyzer cargo serde_cbor_2 0.13.0 serialize_and_compare().<T: Serializerust-analyzer cargo serde 1.0.144 ser/Serialize#>(value: T, expected: &[u8]) {
34 let mut slice = [0u8; 64];
35 let writer = SliceWriterust-analyzer cargo serde_cbor_2 0.13.0 write/SliceWrite#::newrust-analyzer cargo serde_cbor_2 0.13.0 write/impl#[`SliceWrite<'a>`]new().(&mut slice);
36 let mut serializer = Serializerrust-analyzer cargo serde_cbor_2 0.13.0 ser/Serializer#::newrust-analyzer cargo serde_cbor_2 0.13.0 ser/impl#[`Serializer<W>`]new().(writer);
37 value.serializerust-analyzer cargo serde 1.0.144 ser/Serialize#serialize().(&mut serializer).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
38 let writer = serializer.into_innerrust-analyzer cargo serde_cbor_2 0.13.0 ser/impl#[`Serializer<W>`]into_inner().();
39 let end = writer.bytes_writtenrust-analyzer cargo serde_cbor_2 0.13.0 write/impl#[`SliceWrite<'a>`]bytes_written().();
40 let slice = writer.into_innerrust-analyzer cargo serde_cbor_2 0.13.0 write/impl#[`SliceWrite<'a>`]into_inner().();
41 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&slice[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...end]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., expected);
42 }
43
44 #[cfg(feature = "std")]
45 mod std_testsrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/ {
46 use serderust-analyzer cargo serde 1.0.144 crate/::Serializerrust-analyzer cargo serde 1.0.144 ser/Serializer#;
47 use serde_cbor_2rust-analyzer cargo serde_cbor_2 0.13.0 crate/::serrust-analyzer cargo serde_cbor_2 0.13.0 ser/;
48 use serde_cbor_2rust-analyzer cargo serde_cbor_2 0.13.0 crate/::{from_slicerust-analyzer cargo serde_cbor_2 0.13.0 de/from_slice()., to_vecrust-analyzer cargo serde_cbor_2 0.13.0 ser/to_vec().};
49 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#;
50
51 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
52 fn test_stringrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/test_string().() {
53 let value = "foobar".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().();
54 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&to_vecrust-analyzer cargo serde_cbor_2 0.13.0 ser/to_vec().(&value).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., b"ffoobar");
55 }
56
57 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
58 fn test_listrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/test_list().() {
59 let value = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![1, 2, 3];
60 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&to_vecrust-analyzer cargo serde_cbor_2 0.13.0 ser/to_vec().(&value).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., b"\x83\x01\x02\x03");
61 }
62
63 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
64 fn test_objectrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/test_object().() {
65 let mut object = BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V>`]new().();
66 object.insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]insert().("a".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), "A".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().());
67 object.insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]insert().("b".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), "B".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().());
68 object.insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]insert().("c".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), "C".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().());
69 object.insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]insert().("d".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), "D".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().());
70 object.insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]insert().("e".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), "E".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().());
71 let vec = to_vecrust-analyzer cargo serde_cbor_2 0.13.0 ser/to_vec().(&object).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
72 let test_object = from_slicerust-analyzer cargo serde_cbor_2 0.13.0 de/from_slice().(&vec[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
73 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(object, test_object);
74 }
75
76 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
77 fn test_object_list_keysrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/test_object_list_keys().() {
78 let mut object = BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V>`]new().();
79 object.insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]insert().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0i64], ());
80 object.insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]insert().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![100i64], ());
81 object.insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]insert().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().1i64], ());
82 object.insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]insert().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().2i64], ());
83 object.insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]insert().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0i64, 0i64], ());
84 object.insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]insert().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0i64, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().1i64], ());
85 let vec = to_vecrust-analyzer cargo serde_cbor_2 0.13.0 ser/to_vec().(&serde_cbor_2rust-analyzer cargo serde_cbor_2 0.13.0 crate/::valuerust-analyzer cargo serde_cbor_2 0.13.0 value/::to_valuerust-analyzer cargo serde_cbor_2 0.13.0 value/ser/to_value().(object.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`][Clone]clone().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
86 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
87 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
88 166, 129, 0, 246, 129, 24, 100, 246, 129, 32, 246, 129, 33, 246, 130, 0, 0, 246,
89 130, 0, 32, 246
90 ],
91 vec
92 );
93 let test_object = from_slicerust-analyzer cargo serde_cbor_2 0.13.0 de/from_slice().(&vec[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
94 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(object, test_object);
95 }
96
97 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
98 fn test_object_object_keysrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/test_object_object_keys().() {
99 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::FromIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/FromIterator#;
100 let mut object = BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V>`]new().();
101 let keys = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
102 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["a"],
103 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["b"],
104 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["c"],
105 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["d"],
106 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["aa"],
107 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["a", "aa"],
108 ]
109 .into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().()
110 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|v| BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#::from_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V>`][`FromIterator<(K, V)>`]from_iter().(v.into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|s| (s.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), ()))));
111
112 for key in keys {
113 object.insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]insert().(key, ());
114 }
115 let vec = to_vecrust-analyzer cargo serde_cbor_2 0.13.0 ser/to_vec().(&serde_cbor_2rust-analyzer cargo serde_cbor_2 0.13.0 crate/::valuerust-analyzer cargo serde_cbor_2 0.13.0 value/::to_valuerust-analyzer cargo serde_cbor_2 0.13.0 value/ser/to_value().(object.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`][Clone]clone().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
116 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
117 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
118 166, 161, 97, 97, 246, 246, 161, 97, 98, 246, 246, 161, 97, 99, 246, 246, 161, 97,
119 100, 246, 246, 161, 98, 97, 97, 246, 246, 162, 97, 97, 246, 98, 97, 97, 246, 246
120 ],
121 vec
122 );
123 let test_object = from_slicerust-analyzer cargo serde_cbor_2 0.13.0 de/from_slice().(&vec[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
124 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(object, test_object);
125 }
126
127 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
128 fn test_floatrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/test_float().() {
129 let vec = to_vecrust-analyzer cargo serde_cbor_2 0.13.0 ser/to_vec().(&12.3f64).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
130 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(vec, b"\xfb@(\x99\x99\x99\x99\x99\x9a");
131 }
132
133 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
134 fn test_f32rust-analyzer cargo serde_cbor_2 0.13.0 std_tests/test_f32().() {
135 let vec = to_vecrust-analyzer cargo serde_cbor_2 0.13.0 ser/to_vec().(&4000.5f32).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
136 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(vec, b"\xfa\x45\x7a\x08\x00");
137 }
138
139 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
140 fn test_infinityrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/test_infinity().() {
141 let vec = to_vecrust-analyzer cargo serde_cbor_2 0.13.0 ser/to_vec().(&f64::INFINITYrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f64/impl#[f64]INFINITY.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
142 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(vec, b"\xf9|\x00");
143 }
144
145 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
146 fn test_neg_infinityrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/test_neg_infinity().() {
147 let vec = to_vecrust-analyzer cargo serde_cbor_2 0.13.0 ser/to_vec().(&f64::NEG_INFINITYrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f64/impl#[f64]NEG_INFINITY.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
148 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(vec, b"\xf9\xfc\x00");
149 }
150
151 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
152 fn test_nanrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/test_nan().() {
153 let vec = to_vecrust-analyzer cargo serde_cbor_2 0.13.0 ser/to_vec().(&f32::NANrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f32/impl#[f32]NAN.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
154 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(vec, b"\xf9\x7e\x00");
155 }
156
157 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
158 fn test_integerrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/test_integer().() {
159 // u8
160 let vec = to_vecrust-analyzer cargo serde_cbor_2 0.13.0 ser/to_vec().(&24).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
161 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(vec, b"\x18\x18");
162 // i8
163 let vec = to_vecrust-analyzer cargo serde_cbor_2 0.13.0 ser/to_vec().(&-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().5).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
164 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(vec, b"\x24");
165 // i16
166 let vec = to_vecrust-analyzer cargo serde_cbor_2 0.13.0 ser/to_vec().(&-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().300).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
167 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(vec, b"\x39\x01\x2b");
168 // i32
169 let vec = to_vecrust-analyzer cargo serde_cbor_2 0.13.0 ser/to_vec().(&-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().23567997).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
170 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(vec, b"\x3a\x01\x67\x9e\x7c");
171 // u64
172 let vec = to_vecrust-analyzer cargo serde_cbor_2 0.13.0 ser/to_vec().(&u64::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]MAX.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
173 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(vec, b"\x1b\xff\xff\xff\xff\xff\xff\xff\xff");
174 }
175
176 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
177 fn test_self_describingrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/test_self_describing().() {
178 let mut vec = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
179 {
180 let mut serializer = serrust-analyzer cargo serde_cbor_2 0.13.0 ser/::Serializerrust-analyzer cargo serde_cbor_2 0.13.0 ser/Serializer#::newrust-analyzer cargo serde_cbor_2 0.13.0 ser/impl#[`Serializer<W>`]new().(&mut vec);
181 serializer.self_describerust-analyzer cargo serde_cbor_2 0.13.0 ser/impl#[`Serializer<W>`]self_describe().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
182 serializer.serialize_u64rust-analyzer cargo serde_cbor_2 0.13.0 ser/impl#[`&'a mut Serializer<W>`][Serializer]serialize_u64().(9).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
183 }
184 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(vec, b"\xd9\xd9\xf7\x09");
185 }
186
187 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
188 fn test_ip_addrrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/test_ip_addr().() {
189 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::netrust-analyzer cargo std https://github.com/rust-lang/rust/library/std net/::Ipv4Addrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/Ipv4Addr#;
190
191 let addr = Ipv4Addrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/Ipv4Addr#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/impl#[Ipv4Addr]new().(8, 8, 8, 8);
192 let vec = to_vecrust-analyzer cargo serde_cbor_2 0.13.0 ser/to_vec().(&addr).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
193 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{vec:?}");
194 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(vec.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 5);
195 let test_addr: Ipv4Addrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core net/ip_addr/Ipv4Addr# = from_slicerust-analyzer cargo serde_cbor_2 0.13.0 de/from_slice().(&vec).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
196 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(addr, test_addr);
197 }
198
199 /// Test all of CBOR's fixed-length byte string types
200 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
201 fn test_byte_stringrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/test_byte_string().() {
202 // Very short byte strings have 1-byte headers
203 let short = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0, 1, 2, 255];
204 let mut short_s = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
205 serde_cbor_2rust-analyzer cargo serde_cbor_2 0.13.0 crate/::Serializerrust-analyzer cargo serde_cbor_2 0.13.0 ser/Serializer#::newrust-analyzer cargo serde_cbor_2 0.13.0 ser/impl#[`Serializer<W>`]new().(&mut short_s)
206 .serialize_bytesrust-analyzer cargo serde_cbor_2 0.13.0 ser/impl#[`&'a mut Serializer<W>`][Serializer]serialize_bytes().(&short)
207 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
208 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&short_s[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., [0x44, 0, 1, 2, 255]);
209
210 // byte strings > 23 bytes have 2-byte headers
211 let medium = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
212 0u8, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 255,
213 ];
214 let mut medium_s = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
215 serde_cbor_2rust-analyzer cargo serde_cbor_2 0.13.0 crate/::Serializerrust-analyzer cargo serde_cbor_2 0.13.0 ser/Serializer#::newrust-analyzer cargo serde_cbor_2 0.13.0 ser/impl#[`Serializer<W>`]new().(&mut medium_s)
216 .serialize_bytesrust-analyzer cargo serde_cbor_2 0.13.0 ser/impl#[`&'a mut Serializer<W>`][Serializer]serialize_bytes().(&medium)
217 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
218 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
219 &medium_s[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().,
220 [
221 0x58, 24, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
222 21, 22, 255
223 ]
224 );
225
226 // byte strings > 256 bytes have 3-byte headers
227 let long_vec = (0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#256).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|i| (i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i32][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i32][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i32][`BitAnd<Self>`]bitand().0xFF) as u8).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>();
228 let mut long_s = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
229 serde_cbor_2rust-analyzer cargo serde_cbor_2 0.13.0 crate/::Serializerrust-analyzer cargo serde_cbor_2 0.13.0 ser/Serializer#::newrust-analyzer cargo serde_cbor_2 0.13.0 ser/impl#[`Serializer<W>`]new().(&mut long_s)
230 .serialize_bytesrust-analyzer cargo serde_cbor_2 0.13.0 ser/impl#[`&'a mut Serializer<W>`][Serializer]serialize_bytes().(&long_vec)
231 .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!!(&long_s[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0..3]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., [0x59, 1, 0]);
233 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&long_s[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().3..]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., &long_vec[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().);
234
235 // byte strings > 2^16 bytes have 5-byte headers
236 let very_long_vec = (0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#65536).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|i| (i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i32][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i32][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i32][`BitAnd<Self>`]bitand().0xFF) as u8).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>();
237 let mut very_long_s = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
238 serde_cbor_2rust-analyzer cargo serde_cbor_2 0.13.0 crate/::Serializerrust-analyzer cargo serde_cbor_2 0.13.0 ser/Serializer#::newrust-analyzer cargo serde_cbor_2 0.13.0 ser/impl#[`Serializer<W>`]new().(&mut very_long_s)
239 .serialize_bytesrust-analyzer cargo serde_cbor_2 0.13.0 ser/impl#[`&'a mut Serializer<W>`][Serializer]serialize_bytes().(&very_long_vec)
240 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
241 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&very_long_s[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0..5]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., [0x5a, 0, 1, 0, 0]);
242 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&very_long_s[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().5..]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., &very_long_vec[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().);
243
244 // byte strings > 2^32 bytes have 9-byte headers, but they take too much RAM
245 // to test in Travis.
246 }
247
248 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
249 fn test_halfrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/test_half().() {
250 let vec = to_vecrust-analyzer cargo serde_cbor_2 0.13.0 ser/to_vec().(&42.5f32).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!!(vec, b"\xF9\x51\x50");
252 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(from_slicerust-analyzer cargo serde_cbor_2 0.13.0 de/from_slice().::<f32>(&vec[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 42.5f32);
253 }
254 }