Skip to content

Commit b31e955

Browse files
committed
chore: better testing
1 parent 026c87d commit b31e955

File tree

2 files changed

+33
-13
lines changed

2 files changed

+33
-13
lines changed

crates/league-modpkg/src/builder.rs

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,10 @@ impl ModpkgLayerBuilder {
316316

317317
#[cfg(test)]
318318
mod tests {
319+
use crate::ModpkgLayer;
320+
319321
use super::*;
320-
use binrw::BinRead;
322+
use binrw::{BinRead, NullString};
321323
use std::io::Cursor;
322324

323325
#[test]
@@ -347,13 +349,30 @@ mod tests {
347349
let modpkg = Modpkg::<Cursor<Vec<u8>>>::read(&mut cursor).unwrap();
348350

349351
assert_eq!(modpkg.chunks().len(), 1);
352+
353+
let chunk = modpkg
354+
.chunks()
355+
.get(&xxh64("test.png".as_bytes(), 0))
356+
.unwrap();
357+
358+
assert_eq!(
359+
modpkg.chunk_paths.get(&xxh64("test.png".as_bytes(), 0)),
360+
Some(&NullString::from("test.png"))
361+
);
362+
363+
assert_eq!(chunk.compression, ModpkgCompression::Zstd);
364+
assert_eq!(chunk.uncompressed_size, 100);
365+
assert_eq!(chunk.compressed_size, 17);
366+
assert_eq!(chunk.uncompressed_checksum, xxh3_64(&[0xAA; 100]));
367+
assert_eq!(chunk.path_index, 0);
368+
369+
assert_eq!(modpkg.layers.len(), 1);
350370
assert_eq!(
351-
modpkg
352-
.chunks()
353-
.get(&xxh64("test.png".as_bytes(), 0))
354-
.unwrap()
355-
.compression,
356-
ModpkgCompression::Zstd
371+
modpkg.layers.get(&xxh3_64("base".as_bytes())),
372+
Some(&ModpkgLayer {
373+
name: "base".to_string(),
374+
priority: 0,
375+
})
357376
);
358377
}
359378
}

crates/league-modpkg/src/lib.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::{
88
fmt::Display,
99
io::{Read, Seek},
1010
};
11-
use xxhash_rust::xxh3::xxh3_64;
11+
use xxhash_rust::{xxh3::xxh3_64, xxh64::xxh64};
1212

1313
mod builder;
1414
mod chunk;
@@ -39,21 +39,22 @@ pub struct Modpkg<TSource: Read + Seek + Default> {
3939
layer_count: u32,
4040
#[br(count = layer_count, map = |m: Vec<ModpkgLayer>| m.into_iter().map(|c| (xxh3_64(c.name.as_bytes()), c)).collect())]
4141
#[bw(map = |m| m.values().cloned().collect_vec())]
42-
layers: HashMap<u64, ModpkgLayer>,
42+
pub layers: HashMap<u64, ModpkgLayer>,
4343

4444
#[br(temp)]
4545
#[bw(calc = chunk_paths.len() as u32)]
4646
chunk_path_count: u32,
47-
#[br(count = chunk_path_count)]
48-
chunk_paths: Vec<NullString>,
47+
#[br(count = chunk_path_count, map = |m: Vec<NullString>| m.into_iter().map(|c| (xxh64(&c.0, 0), c)).collect())]
48+
#[bw(map = |m| m.values().cloned().collect_vec())]
49+
pub chunk_paths: HashMap<u64, NullString>,
4950

50-
metadata: ModpkgMetadata,
51+
pub metadata: ModpkgMetadata,
5152

5253
// alan: pretty sure this works to align the individual chunks - https://github.com/jam1garner/binrw/issues/68
5354
#[brw(align_before = 8)]
5455
#[br(count = chunk_count, map = |m: Vec<ModpkgChunk>| m.into_iter().map(|c| (c.path_hash, c)).collect())]
5556
#[bw(map = |m| m.values().copied().collect_vec())]
56-
chunks: HashMap<u64, ModpkgChunk>,
57+
pub chunks: HashMap<u64, ModpkgChunk>,
5758

5859
#[brw(ignore)]
5960
/// The original byte source.

0 commit comments

Comments
 (0)