pub const FIELD_SEPARATOR: char = '\t';
pub struct Templates;
impl Templates {
pub fn log() -> &'static str {
concat!(
"change_id.short(8)",
" ++ \"\\t\" ++ ",
"commit_id.short(8)",
" ++ \"\\t\" ++ ",
"author.email()",
" ++ \"\\t\" ++ ",
"author.timestamp().format('%Y-%m-%dT%H:%M:%S%z')",
" ++ \"\\t\" ++ ",
"description.first_line()",
" ++ \"\\t\" ++ ",
"if(current_working_copy, 'true', 'false')",
" ++ \"\\t\" ++ ",
"if(empty, 'true', 'false')",
" ++ \"\\t\" ++ ",
"bookmarks.map(|b| b.name()).join(',')",
" ++ \"\\t\" ++ ",
"if(conflict, 'true', 'false')",
" ++ \"\\n\""
)
}
pub fn op_log() -> &'static str {
concat!(
"self.id().short(12)",
" ++ \"\\t\" ++ ",
"self.user()",
" ++ \"\\t\" ++ ",
"self.time().start().ago()",
" ++ \"\\t\" ++ ",
"self.description().first_line()",
" ++ \"\\n\""
)
}
pub fn change_info() -> &'static str {
concat!(
"change_id.short(8)",
" ++ \"\\t\" ++ ",
"bookmarks.map(|b| b.name()).join(',')",
" ++ \"\\t\" ++ ",
"author.email()",
" ++ \"\\t\" ++ ",
"author.timestamp().format('%Y-%m-%dT%H:%M:%S%z')",
" ++ \"\\t\" ++ ",
"description.first_line()",
" ++ \"\\n\""
)
}
pub fn file_annotate() -> &'static str {
concat!(
"commit.change_id().short(8)",
" ++ \"\\t\" ++ ",
"commit.commit_id().short(8)",
" ++ \" \" ++ ",
"commit.author().name()",
" ++ \" \" ++ ",
"commit.committer().timestamp().format(\"%Y-%m-%d %H:%M:%S\")",
" ++ \" \" ++ ",
"self.line_number()",
" ++ \": \" ++ ",
"self.content()",
)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_log_template_is_valid() {
let template = Templates::log();
assert!(template.contains("change_id"));
assert!(template.contains("commit_id"));
assert!(template.contains("\\t")); assert!(template.contains("\\n")); }
#[test]
fn test_field_separator_is_tab() {
assert_eq!(FIELD_SEPARATOR, '\t');
}
#[test]
fn test_file_annotate_template_uses_short_8() {
let template = Templates::file_annotate();
assert!(template.contains("change_id().short(8)"));
}
#[test]
fn test_file_annotate_template_has_required_fields() {
let template = Templates::file_annotate();
assert!(template.contains("change_id"));
assert!(template.contains("commit_id"));
assert!(template.contains("author"));
assert!(template.contains("line_number"));
assert!(template.contains("content"));
}
}