use toml::Table;
use crate::types::project::Source;
#[derive(Debug, Clone, PartialEq)]
pub struct PackEntry {
source: Source,
options: Table,
}
impl PackEntry {
#[must_use]
pub(crate) const fn new(source: Source, options: Table) -> Self {
Self { source, options }
}
#[must_use]
pub const fn source(&self) -> &Source {
&self.source
}
#[must_use]
pub(crate) const fn options(&self) -> &Table {
&self.options
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::types::project::LocalPath;
type TestResult = Result<(), Box<dyn std::error::Error>>;
#[test]
fn pack_entry_keeps_its_source_and_raw_options() -> TestResult {
let source = Source::Path(LocalPath::new("packs/team-lint")?);
let options: Table = "archive_keep = 50\nname = \"x\"\n".parse()?;
let entry = PackEntry::new(source.clone(), options.clone());
assert_eq!(entry.source(), &source);
assert_eq!(entry.options(), &options);
assert_eq!(
entry
.options()
.get("archive_keep")
.and_then(toml::Value::as_integer),
Some(50)
);
Ok(())
}
#[test]
fn pack_entry_options_may_be_empty() -> TestResult {
let entry = PackEntry::new(Source::Path(LocalPath::new("p")?), Table::new());
assert!(entry.options().is_empty());
Ok(())
}
}