Initial commit: git-issue-commit CLI tool
Some checks failed
CI / test (push) Has been cancelled
CI / release (push) Has been cancelled

This commit is contained in:
2026-01-29 19:59:31 +00:00
parent 3a10ac360b
commit 4e78739600

63
tests/generator_tests.rs Normal file
View File

@@ -0,0 +1,63 @@
#[cfg(test)]
mod generator_tests {
use crate::generator::message::MessageGenerator;
use crate::generator::type_detector::{detect_type_from_text, extract_scope_from_labels};
#[test]
fn test_message_generator_basic() {
let mut generator = MessageGenerator::new();
generator.set_type("feat".to_string());
generator.set_scope(Some("api".to_string()));
generator.set_description("add new endpoint".to_string());
let message = generator.format_message();
assert_eq!(message, "feat(api): add new endpoint");
}
#[test]
fn test_message_generator_with_body() {
let mut generator = MessageGenerator::new();
generator.set_type("fix".to_string());
generator.set_description("resolve bug");
generator.set_body("This resolves the issue where users couldn't login.".to_string());
let message = generator.format_message();
assert!(message.contains("fix: resolve bug"));
assert!(message.contains("This resolves the issue"));
}
#[test]
fn test_message_generator_with_breaking() {
let mut generator = MessageGenerator::new();
generator.set_type("feat".to_string());
generator.set_description("change API");
generator.set_breaking(true);
generator.set_breaking_description("API endpoint signature changed".to_string());
let message = generator.format_message();
assert!(message.contains("feat!: change API"));
assert!(message.contains("BREAKING CHANGE"));
assert!(message.contains("API endpoint signature changed"));
}
#[test]
fn test_detect_type_from_text() {
assert_eq!(detect_type_from_text("Fix login bug"), "fix");
assert_eq!(detect_type_from_text("Add new feature"), "feat");
assert_eq!(detect_type_from_text("Update documentation"), "docs");
assert_eq!(detect_type_from_text("Add tests for auth"), "test");
assert_eq!(detect_type_from_text("Refactor the codebase"), "refactor");
}
#[test]
fn test_extract_scope_from_labels() {
let labels = vec!["frontend".to_string(), "bug".to_string()];
assert_eq!(extract_scope_from_labels(&labels), Some("frontend".to_string()));
let labels = vec!["backend".to_string()];
assert_eq!(extract_scope_from_labels(&labels), Some("backend".to_string()));
let labels = vec!["documentation".to_string()];
assert_eq!(extract_scope_from_labels(&labels), Some("docs".to_string()));
}
}