forked from mirrors/jj
cli: make diff stat determine path length in chars, not bytes
This commit is contained in:
parent
0493e2b50e
commit
5ecc95a245
2 changed files with 12 additions and 12 deletions
|
@ -785,7 +785,7 @@ pub fn show_diff_stat(
|
|||
let path = workspace_command.format_file_path(&repo_path);
|
||||
let left_content = diff_content(workspace_command.repo(), &repo_path, &left)?;
|
||||
let right_content = diff_content(workspace_command.repo(), &repo_path, &right)?;
|
||||
max_path_length = max(max_path_length, path.len());
|
||||
max_path_length = max(max_path_length, path.chars().count());
|
||||
let stat = get_diff_stat(path, &left_content, &right_content);
|
||||
max_diffs = max(max_diffs, stat.added + stat.removed);
|
||||
stats.push(stat);
|
||||
|
|
|
@ -805,51 +805,51 @@ fn test_diff_stat_long_name_or_stat() {
|
|||
};
|
||||
|
||||
insta::assert_snapshot!(get_stat(&test_env, 1, 1), @r###"
|
||||
一 | 1 +
|
||||
一 | 1 +
|
||||
1 file changed, 1 insertion(+), 0 deletions(-)
|
||||
"###);
|
||||
insta::assert_snapshot!(get_stat(&test_env, 1, 10), @r###"
|
||||
一 | 10 ++++++++++
|
||||
一 | 10 ++++++++++
|
||||
1 file changed, 10 insertions(+), 0 deletions(-)
|
||||
"###);
|
||||
insta::assert_snapshot!(get_stat(&test_env, 1, 100), @r###"
|
||||
一 | 100 +++++++++++++++++
|
||||
一 | 100 +++++++++++++++++++
|
||||
1 file changed, 100 insertions(+), 0 deletions(-)
|
||||
"###);
|
||||
insta::assert_snapshot!(get_stat(&test_env, 10, 1), @r###"
|
||||
一二三四五六七八九十 | 1
|
||||
一二三四五六七八九十 | 1 +
|
||||
1 file changed, 1 insertion(+), 0 deletions(-)
|
||||
"###);
|
||||
insta::assert_snapshot!(get_stat(&test_env, 10, 10), @r###"
|
||||
一二三四五六七八九十 | 10
|
||||
一二三四五六七八九十 | 10 ++++++++++
|
||||
1 file changed, 10 insertions(+), 0 deletions(-)
|
||||
"###);
|
||||
insta::assert_snapshot!(get_stat(&test_env, 10, 100), @r###"
|
||||
一二三四五六七八九十 | 100
|
||||
一二三四五六七八九十 | 100 ++++++++++
|
||||
1 file changed, 100 insertions(+), 0 deletions(-)
|
||||
"###);
|
||||
insta::assert_snapshot!(get_stat(&test_env, 50, 1), @r###"
|
||||
一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十 | 1
|
||||
一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十 | 1
|
||||
1 file changed, 1 insertion(+), 0 deletions(-)
|
||||
"###);
|
||||
insta::assert_snapshot!(get_stat(&test_env, 50, 10), @r###"
|
||||
一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十 | 10
|
||||
一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十 | 10
|
||||
1 file changed, 10 insertions(+), 0 deletions(-)
|
||||
"###);
|
||||
insta::assert_snapshot!(get_stat(&test_env, 50, 100), @r###"
|
||||
一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十 | 100
|
||||
一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十 | 100
|
||||
1 file changed, 100 insertions(+), 0 deletions(-)
|
||||
"###);
|
||||
|
||||
// Very narrow terminal (doesn't have to fit, just don't crash)
|
||||
test_env.add_env_var("COLUMNS", "10");
|
||||
insta::assert_snapshot!(get_stat(&test_env, 10, 10), @r###"
|
||||
一二三四五六七八九十 | 10
|
||||
一二三四五六七八九十 | 10
|
||||
1 file changed, 10 insertions(+), 0 deletions(-)
|
||||
"###);
|
||||
test_env.add_env_var("COLUMNS", "3");
|
||||
insta::assert_snapshot!(get_stat(&test_env, 10, 10), @r###"
|
||||
一二三四五六七八九十 | 10
|
||||
一二三四五六七八九十 | 10
|
||||
1 file changed, 10 insertions(+), 0 deletions(-)
|
||||
"###);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue