Files
git-commit-prefix-gen/tests/unit_tests.rs
7000pctAUTO 11baf7ac7b
Some checks failed
CI / test (push) Has been cancelled
Add unit tests
2026-01-31 11:41:30 +00:00

68 lines
3.5 KiB
Rust

#[cfg(test)] mod tests {
use super::*;
#[test] fn test_commit_type_display() {
assert_eq!(super::CommitType::Feat.to_string(), "feat");
assert_eq!(super::CommitType::Fix.to_string(), "fix");
assert_eq!(super::CommitType::Docs.to_string(), "docs");
assert_eq!(super::CommitType::Style.to_string(), "style");
assert_eq!(super::CommitType::Refactor.to_string(), "refactor");
assert_eq!(super::CommitType::Test.to_string(), "test");
assert_eq!(super::CommitType::Chore.to_string(), "chore");
assert_eq!(super::CommitType::Build.to_string(), "build");
assert_eq!(super::CommitType::Ci.to_string(), "ci");
assert_eq!(super::CommitType::Perf.to_string(), "perf");
assert_eq!(super::CommitType::Revert.to_string(), "revert");
}
#[test] fn test_commit_type_from_str() {
use std::str::FromStr;
assert_eq!(CommitType::from_str("feat").unwrap(), CommitType::Feat);
assert_eq!(CommitType::from_str("fix").unwrap(), CommitType::Fix);
assert_eq!(CommitType::from_str("custom").unwrap(), CommitType::Custom("custom".to_string()));
}
#[test] fn test_scope_display() {
assert_eq!(super::Scope::new("auth".to_string()).to_string(), "auth");
assert_eq!(super::Scope::custom("custom".to_string()).to_string(), "custom");
}
#[test] fn test_commit_convention_default() {
let convention = super::CommitConvention::default();
assert!(!convention.type_mapping.is_empty());
assert!(!convention.scope_patterns.is_empty());
assert!(!convention.ignored_patterns.is_empty());
}
#[test] fn test_commit_convention_detect_type() {
let convention = super::CommitConvention::default();
assert_eq!(convention.detect_type("src/auth/login.rs").unwrap().0, super::CommitType::Feat);
assert!(convention.detect_type("README.md").is_some());
}
#[test] fn test_commit_convention_detect_scope() {
let convention = super::CommitConvention::default();
let scope = convention.detect_scope("src/auth/login.rs");
assert!(scope.is_some());
assert_eq!(scope.unwrap().name, "auth");
}
#[test] fn test_commit_convention_should_ignore() {
let convention = super::CommitConvention::default();
assert!(convention.should_ignore("target/debug/main"));
assert!(convention.should_ignore("node_modules/package"));
assert!(!convention.should_ignore("src/main.rs"));
}
#[test] fn test_analyzer_generate_suggestions() {
let analyzer = super::Analyzer::new();
let changes = vec![
super::ChangedFile { path: "src/auth/login.rs".to_string(), old_path: None, status: super::ChangeStatus::Added, additions: 10, deletions: 0 },
super::ChangedFile { path: "src/auth/mod.rs".to_string(), old_path: None, status: super::ChangeStatus::Modified, additions: 5, deletions: 2 },
];
let suggestions = analyzer.generate_suggestions(&changes);
assert_eq!(suggestions.len(), 1);
assert_eq!(suggestions[0].commit_type, super::CommitType::Feat);
}
#[test] fn test_commit_suggestion_display() {
let suggestion = super::CommitSuggestion {
commit_type: super::CommitType::Feat,
scope: Some(super::Scope::new("auth".to_string())),
description: "add login functionality".to_string(), confidence: 0.9, file_count: 2,
};
assert_eq!(suggestion.to_string(), "feat(auth): add login functionality");
}
}