Skip to content

Commit

Permalink
fix: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DerTiedemann committed Jul 30, 2024
1 parent 7db25f8 commit 32da6d3
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
6 changes: 4 additions & 2 deletions git-cliff-core/src/changelog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,14 +425,16 @@ impl<'a> Changelog<'a> {
serde_json::to_value(self.config.remote.clone())?,
);
#[cfg(feature = "github")]
let (github_commits, github_pull_requests) = if self.config.remote.github.is_set() {
let (github_commits, github_pull_requests) = if self.config.remote.github.is_set()
{
self.get_github_metadata()
.expect("Could not get github metadata")
} else {
(vec![], vec![])
};
#[cfg(feature = "gitlab")]
let (gitlab_commits, gitlab_merge_request) = if self.config.remote.gitlab.is_set() {
let (gitlab_commits, gitlab_merge_request) = if self.config.remote.gitlab.is_set()
{
self.get_gitlab_metadata()
.expect("Could not get gitlab metadata")
} else {
Expand Down
51 changes: 51 additions & 0 deletions git-cliff-core/src/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -727,4 +727,55 @@ mod test {

Ok(())
}

#[test]
fn field_name_regex() -> Result<()> {
let commit = Commit {
message: String::from("feat: do something"),
author: Signature {
name: Some("John Doe".to_string()),
email: None,
timestamp: 0x0,
},
..Default::default()
};
let parsed_commit = commit.clone().parse(
&[CommitParser {
sha: None,
message: None,
body: None,
footer: None,
group: Some(String::from("Test group")),
default_scope: None,
scope: None,
skip: None,
field: Some(String::from("author.name")),
pattern: Regex::new("Something else").ok(),
}],
false,
true,
);

assert!(parsed_commit.is_err());

let parsed_commit = commit.parse(
&[CommitParser {
sha: None,
message: None,
body: None,
footer: None,
group: Some(String::from("Test group")),
default_scope: None,
scope: None,
skip: None,
field: Some(String::from("author.name")),
pattern: Regex::new("John Doe").ok(),
}],
false,
false,
)?;

assert_eq!(Some(String::from("Test group")), parsed_commit.group);
Ok(())
}
}

0 comments on commit 32da6d3

Please sign in to comment.