add/fix tests

This commit is contained in:
merelymyself 2022-09-20 19:23:21 +08:00 committed by Abin Simon
parent 81c7c77123
commit 411c9880d2
2 changed files with 61 additions and 7 deletions

View file

@ -423,7 +423,7 @@ mod tests {
("ASCII1234-_", 11), ("ASCII1234-_", 11),
("制作样本。", 10), ("制作样本。", 10),
("日本語", 6), ("日本語", 6),
("샘플은 무료로 드리겠습니다", 26), ("샘플은 무료로 드리겠습니다", 28),
("👩🐩", 4), ("👩🐩", 4),
("🔬", 2), ("🔬", 2),
] { ] {
@ -454,10 +454,10 @@ mod tests {
// Add 3 characters for the icons. // Add 3 characters for the icons.
(",!", 24), (",!", 24),
("ASCII1234-_", 13), ("ASCII1234-_", 13),
("File with space", 17), ("File with space", 19),
("制作样本。", 12), ("制作样本。", 12),
("日本語", 8), ("日本語", 8),
("샘플은 무료로 드리겠습니다", 28), ("샘플은 무료로 드리겠습니다", 30),
("👩🐩", 6), ("👩🐩", 6),
("🔬", 4), ("🔬", 4),
] { ] {
@ -487,10 +487,10 @@ mod tests {
for (s, l) in [ for (s, l) in [
(",!", 22), (",!", 22),
("ASCII1234-_", 11), ("ASCII1234-_", 11),
("File with space", 15), ("File with space", 17),
("制作样本。", 10), ("制作样本。", 10),
("日本語", 6), ("日本語", 6),
("샘플은 무료로 드리겠습니다", 26), ("샘플은 무료로 드리겠습니다", 28),
("👩🐩", 4), ("👩🐩", 4),
("🔬", 2), ("🔬", 2),
] { ] {
@ -528,10 +528,10 @@ mod tests {
for (s, l) in [ for (s, l) in [
(",!", 22), (",!", 22),
("ASCII1234-_", 11), ("ASCII1234-_", 11),
("File with space", 15), ("File with space", 17),
("制作样本。", 10), ("制作样本。", 10),
("日本語", 6), ("日本語", 6),
("샘플은 무료로 드리겠습니다", 26), ("샘플은 무료로 드리겠습니다", 28),
("👩🐩", 4), ("👩🐩", 4),
("🔬", 2), ("🔬", 2),
] { ] {

View file

@ -654,6 +654,60 @@ mod test {
) )
); );
let file_path = tmp_dir.path().join("a$a.txt");
File::create(&file_path).expect("failed to create file");
let meta = file_path.metadata().expect("failed to get metas");
let colors = Colors::new(color::ThemeOption::NoLscolors);
let file_type = FileType::new(&meta, None, &Permissions::from(&meta));
let name = Name::new(&file_path, file_type);
assert_eq!(
"\'a$a.txt\'".to_string().with(Color::AnsiValue(184)),
name.render(
&colors,
&icons,
&DisplayOption::FileName,
HyperlinkOption::Never
)
);
let file_path = tmp_dir.path().join("\\.txt");
File::create(&file_path).expect("failed to create file");
let meta = file_path.metadata().expect("failed to get metas");
let colors = Colors::new(color::ThemeOption::NoLscolors);
let file_type = FileType::new(&meta, None, &Permissions::from(&meta));
let name = Name::new(&file_path, file_type);
assert_eq!(
"\'\\.txt\'".to_string().with(Color::AnsiValue(184)),
name.render(
&colors,
&icons,
&DisplayOption::FileName,
HyperlinkOption::Never
)
);
let file_path = tmp_dir.path().join("\"\'.txt");
File::create(&file_path).expect("failed to create file");
let meta = file_path.metadata().expect("failed to get metas");
let colors = Colors::new(color::ThemeOption::NoLscolors);
let file_type = FileType::new(&meta, None, &Permissions::from(&meta));
let name = Name::new(&file_path, file_type);
assert_eq!(
"\'\"\'\\\'\'.txt\'".to_string().with(Color::AnsiValue(184)),
name.render(
&colors,
&icons,
&DisplayOption::FileName,
HyperlinkOption::Never
)
);
let file_path = tmp_dir.path().join("file\nnewline.txt"); let file_path = tmp_dir.path().join("file\nnewline.txt");
File::create(&file_path).expect("failed to create file"); File::create(&file_path).expect("failed to create file");
let meta = file_path.metadata().expect("failed to get metas"); let meta = file_path.metadata().expect("failed to get metas");