Skip to content

Commit

Permalink
parser: add dot in git commit name
Browse files Browse the repository at this point in the history
  • Loading branch information
Pilou97 committed Feb 15, 2024
1 parent 9d3bfb7 commit 7606ffe
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
28 changes: 28 additions & 0 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,31 @@ pub fn instruction_from_string(input: String) -> Option<Vec<Commit>> {

Some(commits)
}

#[cfg(test)]
mod test {
use pest::Parser;

use super::{Rule, YggitParser};

#[test]
fn test_hash() {
let input = "f8fa32837b2f1438a3a55a9341002920ace7978c";
let result = YggitParser::parse(Rule::commit_hash, &input).unwrap();
assert_eq!(result.as_str(), input)
}

#[test]
fn test_commit_title() {
let input = "project: add .vscode in gitignore";
let result = YggitParser::parse(Rule::commit_title, &input).unwrap();
assert_eq!(result.as_str(), input)
}

#[test]
fn test_git_commit() {
let input = "f8fa32837b2f1438a3a55a9341002920ace7978c project: add .vscode in gitignore\n";
let result = YggitParser::parse(Rule::git_commit, &input).unwrap();
assert_eq!(result.as_str(), input)
}
}
14 changes: 7 additions & 7 deletions src/parser/yggit.pest
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
commit_hash = { ASCII_HEX_DIGIT{40} }
commit_title = { (ASCII_ALPHANUMERIC | "@" | "-" | "_" | "/" | ":" | " " | "!" | "(" | ")" | "#")+ }
git_commit = {commit_hash ~ WHITE_SPACE ~ commit_title ~ NEWLINE}
commit_hash = { ASCII_HEX_DIGIT{40} }
commit_title = { (ASCII_ALPHANUMERIC | "@" | "-" | "_" | "/" | ":" | " " | "!" | "(" | ")" | "#" | ".")+ }
git_commit = { commit_hash ~ WHITE_SPACE ~ commit_title ~ NEWLINE }

branch_tag = _{ "->" }
origin = { ASCII_ALPHANUMERIC+ }
branch_name = { (ASCII_ALPHANUMERIC | "@" | "-" | "_" | "/")+ }
target = { branch_tag ~ WHITE_SPACE* ~ (origin ~ ":")? ~ branch_name ~ NEWLINE}
branch_tag = _{ "->" }
origin = { ASCII_ALPHANUMERIC+ }
branch_name = { (ASCII_ALPHANUMERIC | "@" | "-" | "_" | "/")+ }
target = { branch_tag ~ WHITE_SPACE* ~ (origin ~ ":")? ~ branch_name ~ NEWLINE }

commit = {
git_commit ~ (target ~ NEWLINE*){, 1} ~ NEWLINE*
Expand Down

0 comments on commit 7606ffe

Please sign in to comment.