-
Notifications
You must be signed in to change notification settings - Fork 343
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
author
/committer
templates: add a username
method
I haven't used a proper email address parser as I'm not really sure if it's worth the extra dependency and effort -- thoughts?
- Loading branch information
Showing
3 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -257,6 +257,68 @@ fn test_templater_string_method() { | |
insta::assert_snapshot!(render(r#""foo\nbar".first_line()"#), @"foo"); | ||
} | ||
|
||
#[test] | ||
fn test_templater_signature() { | ||
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_template_output(&test_env, &repo_path, "@", template); | ||
|
||
test_env.jj_cmd_success(&repo_path, &["new"]); | ||
|
||
insta::assert_snapshot!(render(r#"author"#), @"Test User <[email protected]>"); | ||
insta::assert_snapshot!(render(r#"author.name()"#), @"Test User"); | ||
insta::assert_snapshot!(render(r#"author.email()"#), @"[email protected]"); | ||
insta::assert_snapshot!(render(r#"author.username()"#), @"test.user"); | ||
|
||
test_env.jj_cmd_success( | ||
&repo_path, | ||
&["--config-toml=user.name='Another Test User'", "new"], | ||
); | ||
|
||
insta::assert_snapshot!(render(r#"author"#), @"Another Test User <[email protected]>"); | ||
insta::assert_snapshot!(render(r#"author.name()"#), @"Another Test User"); | ||
insta::assert_snapshot!(render(r#"author.email()"#), @"[email protected]"); | ||
insta::assert_snapshot!(render(r#"author.username()"#), @"test.user"); | ||
|
||
test_env.jj_cmd_success( | ||
&repo_path, | ||
&[ | ||
"--config-toml=user.email='test.user@[email protected]'", | ||
"new", | ||
], | ||
); | ||
|
||
insta::assert_snapshot!(render(r#"author"#), @"Test User <test.user@[email protected]>"); | ||
insta::assert_snapshot!(render(r#"author.name()"#), @"Test User"); | ||
insta::assert_snapshot!(render(r#"author.email()"#), @"test.user@[email protected]"); | ||
insta::assert_snapshot!(render(r#"author.username()"#), @"test.user"); | ||
|
||
test_env.jj_cmd_success(&repo_path, &["--config-toml=user.email='test.user'", "new"]); | ||
|
||
insta::assert_snapshot!(render(r#"author"#), @"Test User <test.user>"); | ||
insta::assert_snapshot!(render(r#"author.email()"#), @"test.user"); | ||
insta::assert_snapshot!(render(r#"author.username()"#), @"test.user"); | ||
|
||
test_env.jj_cmd_success( | ||
&repo_path, | ||
&[ | ||
"--config-toml=user.email='[email protected]'", | ||
"new", | ||
], | ||
); | ||
|
||
insta::assert_snapshot!(render(r#"author"#), @"Test User <[email protected]>"); | ||
insta::assert_snapshot!(render(r#"author.email()"#), @"[email protected]"); | ||
insta::assert_snapshot!(render(r#"author.username()"#), @"test.user+tag"); | ||
|
||
test_env.jj_cmd_success(&repo_path, &["--config-toml=user.email='x@y'", "new"]); | ||
|
||
insta::assert_snapshot!(render(r#"author"#), @"Test User <x@y>"); | ||
insta::assert_snapshot!(render(r#"author.email()"#), @"x@y"); | ||
insta::assert_snapshot!(render(r#"author.username()"#), @"x"); | ||
} | ||
|
||
#[test] | ||
fn test_templater_label_function() { | ||
let test_env = TestEnvironment::default(); | ||
|