// This file is part of ICU4X. For terms of use, please see the file
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
//! Example data useful for testing ZeroVec.
// This module is included directly in tests and can trigger the dead_code
// warning since not all samples are used in each test
#! [allow(dead_code)]
#[ repr(align(
8 ))]
struct Aligned<T>(
pub T);
// This is aligned so that we can test unaligned behavior at odd offsets
const ALIGNED_TEST_BUFFER_LE: Aligned<[u8;
80 ]> = Aligned([
0 x00,
0 x01,
0 x02,
0 x00,
0 x04,
0 x05,
0 x06,
0 x00,
0 x08,
0 x09,
0 x0a,
0 x00,
0 x0c,
0 x0d,
0 x0e,
0 x00,
0 x10,
0 x11,
0 x12,
0 x00,
0 x14,
0 x15,
0 x16,
0 x00,
0 x18,
0 x19,
0 x1a,
0 x00,
0 x1c,
0 x1d,
0 x1e,
0 x00,
0 x20,
0 x21,
0 x22,
0 x00,
0 x24,
0 x25,
0 x26,
0 x00,
0 x28,
0 x29,
0 x2a,
0 x00,
0 x2c,
0 x2d,
0 x2e,
0 x00,
0 x30,
0 x31,
0 x32,
0 x00,
0 x34,
0 x35,
0 x36,
0 x00,
0 x38,
0 x39,
0 x3a,
0 x00,
0 x3c,
0 x3d,
0 x3e,
0 x00,
0 x40,
0 x41,
0 x42,
0 x00,
0 x44,
0 x45,
0 x46,
0 x00,
0 x48,
0 x49,
0 x4a,
0 x00,
0 x4c,
0 x4d,
0 x4e,
0 x00,
]);
/// An example byte array intended to be used in `ZeroVec<u32>`.
pub const TEST_BUFFER_LE: &[u8] = &ALIGNED_TEST_BUFFER_LE.
0 ;
/// u32 numbers corresponding to the above byte array.
pub const TEST_SLICE: &[u32] = &[
0 x020100,
0 x060504,
0 x0a0908,
0 x0e0d0c,
0 x121110,
0 x161514,
0 x1a1918,
0 x1e1d1c,
0 x222120
,
0 x262524, 0 x2a2928, 0 x2e2d2c, 0 x323130, 0 x363534, 0 x3a3938, 0 x3e3d3c, 0 x424140, 0 x464544,
0 x4a4948, 0 x4e4d4c,
];
/// The sum of the numbers in TEST_SLICE.
pub const TEST_SUM: u32 = 52629240 ;
/// Representation of TEST_SLICE in JSON.
pub const JSON_STR: &str = "[131328,394500,657672,920844,1184016,1447188,1710360,1973532,2236704,2499876,2763048,3026220,3289392,3552564,3815736,4078908,4342080,4605252,4868424,5131596]" ;
/// Representation of TEST_SLICE in Bincode.
pub const BINCODE_BUF: &[u8] = &[
80 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 2 , 0 , 4 , 5 , 6 , 0 , 8 , 9 , 10 , 0 , 12 , 13 , 14 , 0 , 16 , 17 , 18 , 0 , 20 ,
21 , 22 , 0 , 24 , 25 , 26 , 0 , 28 , 29 , 30 , 0 , 32 , 33 , 34 , 0 , 36 , 37 , 38 , 0 , 40 , 41 , 42 , 0 , 44 , 45 ,
46 , 0 , 48 , 49 , 50 , 0 , 52 , 53 , 54 , 0 , 56 , 57 , 58 , 0 , 60 , 61 , 62 , 0 , 64 , 65 , 66 , 0 , 68 , 69 , 70 ,
0 , 72 , 73 , 74 , 0 , 76 , 77 , 78 , 0 ,
];
/// Representation of a VarZeroVec<str> with contents ["w", "ω", "文", ""]
pub const TEST_VARZEROSLICE_BYTES: &[u8] = &[
4 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 3 , 0 , 6 , 0 , 119 , 207 , 137 , 230 , 150 , 135 , 240 , 145 , 132 , 131 ,
];
#[ test]
fn validate() {
use crate ::{VarZeroVec, ZeroVec};
assert_eq!(
ZeroVec::<u32>::parse_byte_slice(TEST_BUFFER_LE).unwrap(),
ZeroVec::alloc_from_slice(TEST_SLICE)
);
assert_eq!(TEST_SLICE.iter().sum::<u32>(), TEST_SUM);
assert_eq!(
serde_json::from_str::<ZeroVec::<u32>>(JSON_STR).unwrap(),
ZeroVec::alloc_from_slice(TEST_SLICE)
);
assert_eq!(
bincode::deserialize::<ZeroVec::<u32>>(BINCODE_BUF).unwrap(),
ZeroVec::alloc_from_slice(TEST_SLICE)
);
VarZeroVec::<str>::parse_byte_slice(TEST_VARZEROSLICE_BYTES).unwrap();
}
Messung V0.5 in Prozent C=59 H=100 G=81
¤ Dauer der Verarbeitung: 0.11 Sekunden
(vorverarbeitet am 2026-06-18)
¤
*© Formatika GbR, Deutschland