mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-18 10:07:28 +00:00
templater: Upper and lowercase ids and strings
This commit is contained in:
parent
643fe9a218
commit
00b18bcd18
3 changed files with 57 additions and 0 deletions
|
@ -382,6 +382,21 @@ impl Template<()> for ShortestIdPrefix {
|
|||
}
|
||||
}
|
||||
|
||||
impl ShortestIdPrefix {
|
||||
fn to_upper(&self) -> Self {
|
||||
Self {
|
||||
prefix: self.prefix.to_ascii_uppercase(),
|
||||
rest: self.rest.to_ascii_uppercase(),
|
||||
}
|
||||
}
|
||||
fn to_lower(&self) -> Self {
|
||||
Self {
|
||||
prefix: self.prefix.to_ascii_lowercase(),
|
||||
rest: self.rest.to_ascii_lowercase(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn build_shortest_id_prefix_method<'repo>(
|
||||
language: &CommitTemplateLanguage<'repo, '_>,
|
||||
self_property: impl TemplateProperty<Commit, Output = ShortestIdPrefix> + 'repo,
|
||||
|
@ -402,6 +417,20 @@ fn build_shortest_id_prefix_method<'repo>(
|
|||
TemplatePropertyFn(|id: &ShortestIdPrefix| id.rest.clone()),
|
||||
))
|
||||
}
|
||||
"upper" => {
|
||||
template_parser::expect_no_arguments(function)?;
|
||||
language.wrap_shortest_id_prefix(template_parser::chain_properties(
|
||||
self_property,
|
||||
TemplatePropertyFn(|id: &ShortestIdPrefix| id.to_upper()),
|
||||
))
|
||||
}
|
||||
"lower" => {
|
||||
template_parser::expect_no_arguments(function)?;
|
||||
language.wrap_shortest_id_prefix(template_parser::chain_properties(
|
||||
self_property,
|
||||
TemplatePropertyFn(|id: &ShortestIdPrefix| id.to_lower()),
|
||||
))
|
||||
}
|
||||
_ => {
|
||||
return Err(TemplateParseError::no_such_method(
|
||||
"ShortestIdPrefix",
|
||||
|
|
|
@ -906,6 +906,20 @@ fn build_string_method<'a, L: TemplateLanguage<'a>>(
|
|||
TemplatePropertyFn(|s: &String| s.lines().next().unwrap_or_default().to_string()),
|
||||
))
|
||||
}
|
||||
"upper" => {
|
||||
expect_no_arguments(function)?;
|
||||
language.wrap_string(chain_properties(
|
||||
self_property,
|
||||
TemplatePropertyFn(|s: &String| s.to_uppercase()),
|
||||
))
|
||||
}
|
||||
"lower" => {
|
||||
expect_no_arguments(function)?;
|
||||
language.wrap_string(chain_properties(
|
||||
self_property,
|
||||
TemplatePropertyFn(|s: &String| s.to_lowercase()),
|
||||
))
|
||||
}
|
||||
_ => return Err(TemplateParseError::no_such_method("String", function)),
|
||||
};
|
||||
Ok(property)
|
||||
|
|
|
@ -388,6 +388,20 @@ fn test_templater_separate_function() {
|
|||
render(r#"separate(author, "X", "Y", "Z")"#), @"X <>Y <>Z");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_templater_upper_lower() {
|
||||
let test_env = TestEnvironment::default();
|
||||
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
|
||||
let repo_path = test_env.env_root().join("repo");
|
||||
let render = |template| get_colored_template_output(&test_env, &repo_path, "@-", template);
|
||||
|
||||
insta::assert_snapshot!(
|
||||
render(r#"change_id.shortest(4).upper() change_id.shortest(4).upper().lower()"#),
|
||||
@"[1m[38;5;5mZ[0m[38;5;8mZZZ[39m[1m[38;5;5mz[0m[38;5;8mzzz[39m");
|
||||
insta::assert_snapshot!(
|
||||
render(r#""Hello".upper() "Hello".lower()"#), @"HELLOhello");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_templater_alias() {
|
||||
let test_env = TestEnvironment::default();
|
||||
|
|
Loading…
Reference in a new issue