mirror of
https://codeberg.org/demostf/parser.git
synced 2026-06-04 10:34:11 +02:00
game event writing
This commit is contained in:
parent
5573ec5db2
commit
a55217cc55
11 changed files with 1021 additions and 844 deletions
38
src/lib.rs
38
src/lib.rs
|
|
@ -15,7 +15,7 @@ mod nullhasher;
|
|||
|
||||
#[cfg(test)]
|
||||
#[track_caller]
|
||||
fn test_roundtrip_encode<
|
||||
fn test_roundtrip_write<
|
||||
'a,
|
||||
T: bitbuffer::BitRead<'a, bitbuffer::LittleEndian>
|
||||
+ bitbuffer::BitWrite<bitbuffer::LittleEndian>
|
||||
|
|
@ -41,6 +41,40 @@ fn test_roundtrip_encode<
|
|||
assert_eq!(
|
||||
pos,
|
||||
read.pos(),
|
||||
"Failed to assert that all encoded bytes are used for decoding"
|
||||
"Failed to assert that all encoded bits ({}) are used for decoding ({})",
|
||||
pos,
|
||||
read.pos()
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[track_caller]
|
||||
fn test_roundtrip_encode<
|
||||
'a,
|
||||
T: Parse<'a> + crate::demo::parser::Encode + std::fmt::Debug + std::cmp::PartialEq,
|
||||
>(
|
||||
val: T,
|
||||
state: &ParserState,
|
||||
) {
|
||||
let mut data = Vec::with_capacity(128);
|
||||
use bitbuffer::{BitReadBuffer, BitReadStream, BitWriteStream, LittleEndian};
|
||||
let pos = {
|
||||
let mut stream = BitWriteStream::new(&mut data, LittleEndian);
|
||||
val.encode(&mut stream, state).unwrap();
|
||||
stream.bit_len()
|
||||
};
|
||||
|
||||
let mut read = BitReadStream::new(BitReadBuffer::new_owned(data, LittleEndian));
|
||||
assert_eq!(
|
||||
val,
|
||||
T::parse(&mut read, state).unwrap(),
|
||||
"Failed to assert the parsed message is equal to the original"
|
||||
);
|
||||
assert_eq!(
|
||||
pos,
|
||||
read.pos(),
|
||||
"Failed to assert that all encoded bits ({}) are used for decoding ({})",
|
||||
pos,
|
||||
read.pos()
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue