use super::Source;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Asset {
pub source: Source,
pub bytes: Vec<u8>,
}
impl Asset {
pub fn new(source: Source, bytes: Vec<u8>) -> Self {
Self { source, bytes }
}
}
#[cfg(test)]
pub mod strategy {
use super::super::source::strategy::relative_path;
use super::Asset;
use proptest::prelude::*;
prop_compose! {
pub fn asset()(
source in relative_path(),
bytes in proptest::collection::vec(any::<u8>(), 0..=32),
) -> Asset {
Asset::new(source, bytes)
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use proptest::prelude::*;
proptest! {
#[test]
fn round_trips_fields(a in strategy::asset()) {
let again = Asset::new(a.source.clone(), a.bytes.clone());
prop_assert_eq!(again, a);
}
}
fn src(s: &str) -> Source {
Source::relative_path(s).unwrap()
}
#[test]
fn carries_source_and_bytes() {
let a = Asset::new(src("css/site.css"), b"body{}".to_vec());
assert_eq!(a.source.as_str(), "css/site.css");
assert_eq!(a.bytes, b"body{}");
}
#[test]
fn accepts_empty_payload() {
let a = Asset::new(src("empty.txt"), Vec::new());
assert!(a.bytes.is_empty());
}
}