#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
pub enum Aggregate {
#[default]
Author,
Committer,
}
impl Aggregate {
pub fn as_str(self) -> &'static str {
match self {
Self::Author => "author",
Self::Committer => "committer",
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
pub enum Identify {
#[default]
Name,
Email,
}
impl Identify {
pub fn as_str(self) -> &'static str {
match self {
Self::Name => "name",
Self::Email => "email",
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
pub struct Aggregation {
pub aggregate: Aggregate,
pub identify: Identify,
}
impl Aggregation {
pub fn group_col(&self) -> String {
format!(
"canonical_{}_{}",
self.aggregate.as_str(),
self.identify.as_str()
)
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
pub struct FileSelection {
pub include_generated: bool,
pub include_vendored: bool,
pub include_lockfiles: bool,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct ActivityOptions {
pub ignore_merges: bool,
pub first_parent_only: bool,
pub ignore_whitespace: bool,
pub ignore_bots: bool,
}
impl Default for ActivityOptions {
fn default() -> Self {
Self {
ignore_merges: true,
first_parent_only: false,
ignore_whitespace: false,
ignore_bots: false,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn aggregation_group_col_default_is_canonical_author_name() {
assert_eq!(Aggregation::default().group_col(), "canonical_author_name");
}
#[test]
fn aggregation_group_col_committer_email() {
let agg = Aggregation {
aggregate: Aggregate::Committer,
identify: Identify::Email,
};
assert_eq!(agg.group_col(), "canonical_committer_email");
}
#[test]
fn file_selection_default_excludes_all_categories() {
let sel = FileSelection::default();
assert!(!sel.include_generated);
assert!(!sel.include_vendored);
assert!(!sel.include_lockfiles);
}
#[test]
fn activity_options_default_matches_rpo_defaults() {
let opts = ActivityOptions::default();
assert!(opts.ignore_merges, "merges should be excluded by default");
assert!(!opts.first_parent_only);
assert!(!opts.ignore_whitespace);
assert!(!opts.ignore_bots);
}
#[test]
fn activity_options_is_copy() {
fn assert_copy<T: Copy>() {}
assert_copy::<ActivityOptions>();
}
#[test]
fn activity_options_partial_eq_round_trips() {
let a = ActivityOptions::default();
let b = ActivityOptions {
ignore_merges: true,
first_parent_only: false,
ignore_whitespace: false,
ignore_bots: false,
};
assert_eq!(a, b);
}
}