use super::*;
fn c(message: &str) -> Classification {
classify(message.as_bytes())
}
#[test]
fn bug_fix_keywords_match() {
assert!(c("fix crash on startup").bug_fix);
assert!(c("Fixed the null deref").bug_fix);
assert!(c("fixes #1234").bug_fix);
assert!(c("bugfix: off-by-one").bug_fix);
assert!(c("address a regression").bug_fix);
}
#[test]
fn bug_fix_avoids_substring_false_positives() {
assert!(!c("rename the prefix handling").bug_fix);
assert!(!c("drop the filename suffix").bug_fix);
assert!(!c("add a new feature").bug_fix);
}
#[test]
fn security_keywords_match() {
assert!(c("patch the XSS hole").security_fix);
assert!(c("Resolve CVE-2021-44228").security_fix);
assert!(c("sanitize user input").security_fix);
assert!(c("fix SQL injection").security_fix);
assert!(c("security hardening").security_fix);
}
#[test]
fn security_avoids_substring_false_positives() {
assert!(!c("address job insecurity in docs").security_fix);
assert!(!c("update the changelog").security_fix);
}
#[test]
fn security_injection_overflow_require_qualifier() {
assert!(!c("add dependency injection container").security_fix);
assert!(!c("fix text overflow in sidebar").security_fix);
assert!(!c("handle integer overflow in the counter").security_fix);
assert!(!c("link to the stack overflow answer").security_fix);
assert!(c("fix SQL injection").security_fix);
assert!(c("buffer overflow fix").security_fix);
assert!(c("patch heap overflow in decoder").security_fix);
assert!(c("command injection in shell wrapper").security_fix);
}
#[test]
fn revert_detected_from_subject_or_rollback() {
assert!(c("Revert \"add the broken feature\"").revert);
assert!(c("revert the bad merge").revert);
assert!(c("rollback the migration").revert);
assert!(!c("we should not revert this change").revert);
assert!(!c("this does not undo anything").revert);
}
#[test]
fn rollback_only_classifies_from_subject() {
assert!(c("Rollback the migration").revert);
assert!(!c("feat: add retry logic\n\nThis avoids a rollback later").revert);
assert!(!c("document the rollback procedure in the runbook").revert);
}
#[test]
fn unrelated_message_classifies_as_nothing() {
let class = c("Add documentation for the parser");
assert_eq!(class, Classification::default());
}