cli: use non-ascii chars in diff stat test

This shows that there's too much padding because we pad based on
number of bytes.

I had to reduce the path names for the file names not to get too long
for my file system.
This commit is contained in:
Martin von Zweigbergk 2023-08-30 21:17:50 -07:00 committed by Martin von Zweigbergk
parent 4377c08f83
commit 0493e2b50e

View file

@ -13,6 +13,7 @@
// limitations under the License. // limitations under the License.
use common::TestEnvironment; use common::TestEnvironment;
use itertools::Itertools;
pub mod common; pub mod common;
@ -787,65 +788,68 @@ fn test_diff_stat() {
#[test] #[test]
fn test_diff_stat_long_name_or_stat() { fn test_diff_stat_long_name_or_stat() {
let mut test_env = TestEnvironment::default(); let mut test_env = TestEnvironment::default();
test_env.add_env_var("COLUMNS", "50"); test_env.add_env_var("COLUMNS", "30");
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]); test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo"); let repo_path = test_env.env_root().join("repo");
let get_stat = |test_env: &TestEnvironment, path_length: usize, stat_size: usize| { let get_stat = |test_env: &TestEnvironment, path_length: usize, stat_size: usize| {
test_env.jj_cmd_success(&repo_path, &["new", "root"]); test_env.jj_cmd_success(&repo_path, &["new", "root"]);
let mut name = "abcdefghij".repeat(path_length / 10 + 1); let name = "一二三四五六七八九十"
name.truncate(path_length); .chars()
.cycle()
.take(path_length)
.join("");
let content = "content line\n".repeat(stat_size); let content = "content line\n".repeat(stat_size);
std::fs::write(repo_path.join(name), content).unwrap(); std::fs::write(repo_path.join(name), content).unwrap();
test_env.jj_cmd_success(&repo_path, &["diff", "--stat"]) test_env.jj_cmd_success(&repo_path, &["diff", "--stat"])
}; };
insta::assert_snapshot!(get_stat(&test_env, 1, 1), @r###" insta::assert_snapshot!(get_stat(&test_env, 1, 1), @r###"
a | 1 + | 1 +
1 file changed, 1 insertion(+), 0 deletions(-) 1 file changed, 1 insertion(+), 0 deletions(-)
"###); "###);
insta::assert_snapshot!(get_stat(&test_env, 1, 10), @r###" insta::assert_snapshot!(get_stat(&test_env, 1, 10), @r###"
a | 10 ++++++++++ | 10 ++++++++++
1 file changed, 10 insertions(+), 0 deletions(-) 1 file changed, 10 insertions(+), 0 deletions(-)
"###); "###);
insta::assert_snapshot!(get_stat(&test_env, 1, 100), @r###" insta::assert_snapshot!(get_stat(&test_env, 1, 100), @r###"
a | 100 +++++++++++++++++++++++++++++++++++++++ | 100 +++++++++++++++++
1 file changed, 100 insertions(+), 0 deletions(-) 1 file changed, 100 insertions(+), 0 deletions(-)
"###); "###);
insta::assert_snapshot!(get_stat(&test_env, 10, 1), @r###" insta::assert_snapshot!(get_stat(&test_env, 10, 1), @r###"
abcdefghij | 1 + | 1
1 file changed, 1 insertion(+), 0 deletions(-) 1 file changed, 1 insertion(+), 0 deletions(-)
"###); "###);
insta::assert_snapshot!(get_stat(&test_env, 10, 10), @r###" insta::assert_snapshot!(get_stat(&test_env, 10, 10), @r###"
abcdefghij | 10 ++++++++++ | 10
1 file changed, 10 insertions(+), 0 deletions(-) 1 file changed, 10 insertions(+), 0 deletions(-)
"###); "###);
insta::assert_snapshot!(get_stat(&test_env, 10, 100), @r###" insta::assert_snapshot!(get_stat(&test_env, 10, 100), @r###"
abcdefghij | 100 ++++++++++++++++++++++++++++++ | 100
1 file changed, 100 insertions(+), 0 deletions(-) 1 file changed, 100 insertions(+), 0 deletions(-)
"###); "###);
insta::assert_snapshot!(get_stat(&test_env, 100, 1), @r###" insta::assert_snapshot!(get_stat(&test_env, 50, 1), @r###"
abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij | 1 | 1
1 file changed, 1 insertion(+), 0 deletions(-) 1 file changed, 1 insertion(+), 0 deletions(-)
"###); "###);
insta::assert_snapshot!(get_stat(&test_env, 100, 10), @r###" insta::assert_snapshot!(get_stat(&test_env, 50, 10), @r###"
abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij | 10 | 10
1 file changed, 10 insertions(+), 0 deletions(-) 1 file changed, 10 insertions(+), 0 deletions(-)
"###); "###);
insta::assert_snapshot!(get_stat(&test_env, 100, 100), @r###" insta::assert_snapshot!(get_stat(&test_env, 50, 100), @r###"
abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij | 100 | 100
1 file changed, 100 insertions(+), 0 deletions(-) 1 file changed, 100 insertions(+), 0 deletions(-)
"###); "###);
// Very narrow terminal (doesn't have to fit, just don't crash) // Very narrow terminal (doesn't have to fit, just don't crash)
test_env.add_env_var("COLUMNS", "10"); test_env.add_env_var("COLUMNS", "10");
insta::assert_snapshot!(get_stat(&test_env, 10, 10), @r###" insta::assert_snapshot!(get_stat(&test_env, 10, 10), @r###"
abcdefghij | 10 | 10
1 file changed, 10 insertions(+), 0 deletions(-) 1 file changed, 10 insertions(+), 0 deletions(-)
"###); "###);
test_env.add_env_var("COLUMNS", "3"); test_env.add_env_var("COLUMNS", "3");
insta::assert_snapshot!(get_stat(&test_env, 10, 10), @r###" insta::assert_snapshot!(get_stat(&test_env, 10, 10), @r###"
abcdefghij | 10 | 10
1 file changed, 10 insertions(+), 0 deletions(-) 1 file changed, 10 insertions(+), 0 deletions(-)
"###); "###);
} }