Initial commit: git-issue-commit CLI tool
This commit is contained in:
121
tests/parser_tests.rs
Normal file
121
tests/parser_tests.rs
Normal file
@@ -0,0 +1,121 @@
|
||||
#[cfg(test)]
|
||||
mod parser_tests {
|
||||
use crate::parser::issue::parse_issue_content;
|
||||
use crate::parser::conventional::ConventionalMessage;
|
||||
use crate::parser::markdown::{parse_markdown, MarkdownParseResult};
|
||||
|
||||
#[test]
|
||||
fn test_parse_issue_content_with_title() {
|
||||
let result = parse_issue_content(
|
||||
"Fix authentication bug",
|
||||
"This fixes the login issue where users couldn't authenticate.",
|
||||
);
|
||||
|
||||
assert_eq!(result.r#type, "fix");
|
||||
assert_eq!(result.description, "Fix authentication bug");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_issue_content_detects_feature() {
|
||||
let result = parse_issue_content(
|
||||
"Add new feature",
|
||||
"This implements a new dashboard feature for users.",
|
||||
);
|
||||
|
||||
assert_eq!(result.r#type, "feat");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_issue_content_detects_docs() {
|
||||
let result = parse_issue_content(
|
||||
"Update README",
|
||||
"Added documentation for the new API endpoints.",
|
||||
);
|
||||
|
||||
assert_eq!(result.r#type, "docs");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_breaking_change_detection() {
|
||||
let result = parse_issue_content(
|
||||
"BREAKING: Change API",
|
||||
"This is a breaking change section.\n\nBREAKING CHANGE: The API endpoint has changed.",
|
||||
);
|
||||
|
||||
assert!(result.breaking);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_markdown_parsing() {
|
||||
let content = r#"
|
||||
# Title
|
||||
|
||||
Some description here.
|
||||
|
||||
```rust
|
||||
fn hello() {
|
||||
println!("Hello");
|
||||
}
|
||||
```
|
||||
|
||||
[Link text](https://example.com)
|
||||
"#;
|
||||
|
||||
let result: MarkdownParseResult = parse_markdown(content);
|
||||
|
||||
assert_eq!(result.title, Some("Title".to_string()));
|
||||
assert!(!result.body.is_empty());
|
||||
assert_eq!(result.code_blocks.len(), 1);
|
||||
assert_eq!(result.code_blocks[0].language, "rust");
|
||||
assert_eq!(result.links.len(), 1);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod conventional_tests {
|
||||
use crate::parser::conventional::ConventionalMessage;
|
||||
|
||||
#[test]
|
||||
fn test_header_without_scope() {
|
||||
let msg = ConventionalMessage {
|
||||
r#type: "feat".to_string(),
|
||||
scope: None,
|
||||
description: "add new feature".to_string(),
|
||||
body: None,
|
||||
breaking: false,
|
||||
breaking_description: None,
|
||||
footer: None,
|
||||
};
|
||||
|
||||
assert_eq!(msg.header(), "feat: add new feature");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_header_with_scope() {
|
||||
let msg = ConventionalMessage {
|
||||
r#type: "fix".to_string(),
|
||||
scope: Some("auth".to_string()),
|
||||
description: "resolve login issue".to_string(),n body: None,
|
||||
breaking: false,
|
||||
breaking_description: None,
|
||||
footer: None,
|
||||
};
|
||||
|
||||
assert_eq!(msg.header(), "fix(auth): resolve login issue");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_header_with_breaking() {
|
||||
let msg = ConventionalMessage {
|
||||
r#type: "feat".to_string(),
|
||||
scope: None,
|
||||
description: "change API".to_string(),
|
||||
body: None,
|
||||
breaking: true,
|
||||
breaking_description: None,
|
||||
footer: None,
|
||||
};
|
||||
|
||||
assert_eq!(msg.header(), "feat!: change API");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user