From 5ecc95a245eb5fbd4ccb8dcdcb39aa12b9af3b8f Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Wed, 30 Aug 2023 21:17:50 -0700 Subject: [PATCH] cli: make diff stat determine path length in chars, not bytes --- cli/src/diff_util.rs | 2 +- cli/tests/test_diff_command.rs | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cli/src/diff_util.rs b/cli/src/diff_util.rs index 09220fea1..414b77020 100644 --- a/cli/src/diff_util.rs +++ b/cli/src/diff_util.rs @@ -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); diff --git a/cli/tests/test_diff_command.rs b/cli/tests/test_diff_command.rs index b8eca193c..bb96c731a 100644 --- a/cli/tests/test_diff_command.rs +++ b/cli/tests/test_diff_command.rs @@ -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(-) "###); }