Skip to content

Commit f5fbdca

Browse files
alexsnapssylvestre
authored andcommitted
Fixed tests to reflect si's handling of kilos
Signed-off-by: Alex Snaps <alex@wcgw.dev>
1 parent 2162c42 commit f5fbdca

File tree

3 files changed

+48
-48
lines changed

3 files changed

+48
-48
lines changed

tests/by-util/test_numfmt.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ fn test_to_si() {
8888
.args(&["--to=si"])
8989
.pipe_in("1000\n1100000\n100000000")
9090
.succeeds()
91-
.stdout_is("1.0K\n1.1M\n100M\n");
91+
.stdout_is("1.0k\n1.1M\n100M\n");
9292
}
9393

9494
#[test]
@@ -247,15 +247,15 @@ fn test_suffixes() {
247247
// TODO add support for ronna (R) and quetta (Q)
248248
let valid_suffixes = ['K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y' /*'R' , 'Q'*/];
249249

250-
// TODO implement special handling of 'K'
251250
for c in ('A'..='Z').chain('a'..='z') {
252251
let args = ["--from=si", "--to=si", &format!("1{c}")];
253252

254253
if valid_suffixes.contains(&c) {
254+
let s = if c == 'K' { 'k' } else { c };
255255
new_ucmd!()
256256
.args(&args)
257257
.succeeds()
258-
.stdout_only(format!("1.0{c}\n"));
258+
.stdout_only(format!("1.0{s}\n"));
259259
} else {
260260
new_ucmd!()
261261
.args(&args)
@@ -508,7 +508,7 @@ fn test_delimiter_to_si() {
508508
.args(&["-d=,", "--to=si"])
509509
.pipe_in("1234,56")
510510
.succeeds()
511-
.stdout_only("1.3K,56\n");
511+
.stdout_only("1.3k,56\n");
512512
}
513513

514514
#[test]
@@ -517,7 +517,7 @@ fn test_delimiter_skips_leading_whitespace() {
517517
.args(&["-d=,", "--to=si"])
518518
.pipe_in(" \t 1234,56")
519519
.succeeds()
520-
.stdout_only("1.3K,56\n");
520+
.stdout_only("1.3k,56\n");
521521
}
522522

523523
#[test]
@@ -526,7 +526,7 @@ fn test_delimiter_preserves_leading_whitespace_in_unselected_fields() {
526526
.args(&["-d=|", "--to=si"])
527527
.pipe_in(" 1000| 2000")
528528
.succeeds()
529-
.stdout_only("1.0K| 2000\n");
529+
.stdout_only("1.0k| 2000\n");
530530
}
531531

532532
#[test]
@@ -554,7 +554,7 @@ fn test_delimiter_with_padding() {
554554
.args(&["-d=|", "--to=si", "--padding=5"])
555555
.pipe_in("1000|2000")
556556
.succeeds()
557-
.stdout_only(" 1.0K|2000\n");
557+
.stdout_only(" 1.0k|2000\n");
558558
}
559559

560560
#[test]
@@ -563,21 +563,21 @@ fn test_delimiter_with_padding_and_fields() {
563563
.args(&["-d=|", "--to=si", "--padding=5", "--field=-"])
564564
.pipe_in("1000|2000")
565565
.succeeds()
566-
.stdout_only(" 1.0K| 2.0K\n");
566+
.stdout_only(" 1.0k| 2.0k\n");
567567
}
568568

569569
#[test]
570570
fn test_round() {
571571
for (method, exp) in [
572-
("from-zero", ["9.1K", "-9.1K", "9.1K", "-9.1K"]),
573-
("from-zer", ["9.1K", "-9.1K", "9.1K", "-9.1K"]),
574-
("f", ["9.1K", "-9.1K", "9.1K", "-9.1K"]),
575-
("towards-zero", ["9.0K", "-9.0K", "9.0K", "-9.0K"]),
576-
("up", ["9.1K", "-9.0K", "9.1K", "-9.0K"]),
577-
("down", ["9.0K", "-9.1K", "9.0K", "-9.1K"]),
578-
("nearest", ["9.0K", "-9.0K", "9.1K", "-9.1K"]),
579-
("near", ["9.0K", "-9.0K", "9.1K", "-9.1K"]),
580-
("n", ["9.0K", "-9.0K", "9.1K", "-9.1K"]),
572+
("from-zero", ["9.1k", "-9.1k", "9.1k", "-9.1k"]),
573+
("from-zer", ["9.1k", "-9.1k", "9.1k", "-9.1k"]),
574+
("f", ["9.1k", "-9.1k", "9.1k", "-9.1k"]),
575+
("towards-zero", ["9.0k", "-9.0k", "9.0k", "-9.0k"]),
576+
("up", ["9.1k", "-9.0k", "9.1k", "-9.0k"]),
577+
("down", ["9.0k", "-9.1k", "9.0k", "-9.1k"]),
578+
("nearest", ["9.0k", "-9.0k", "9.1k", "-9.1k"]),
579+
("near", ["9.0k", "-9.0k", "9.1k", "-9.1k"]),
580+
("n", ["9.0k", "-9.0k", "9.1k", "-9.1k"]),
581581
] {
582582
new_ucmd!()
583583
.args(&[
@@ -653,7 +653,7 @@ fn test_transform_with_suffix_on_input() {
653653
.args(&["--suffix=b", "--to=si"])
654654
.pipe_in("2000b")
655655
.succeeds()
656-
.stdout_only("2.0Kb\n");
656+
.stdout_only("2.0kb\n");
657657
}
658658

659659
#[test]
@@ -662,7 +662,7 @@ fn test_transform_without_suffix_on_input() {
662662
.args(&["--suffix=b", "--to=si"])
663663
.pipe_in("2000")
664664
.succeeds()
665-
.stdout_only("2.0Kb\n");
665+
.stdout_only("2.0kb\n");
666666
}
667667

668668
#[test]
@@ -671,7 +671,7 @@ fn test_transform_with_suffix_and_delimiter() {
671671
.args(&["--suffix=b", "--to=si", "-d=|"])
672672
.pipe_in("1000b|2000|3000")
673673
.succeeds()
674-
.stdout_only("1.0Kb|2000|3000\n");
674+
.stdout_only("1.0kb|2000|3000\n");
675675
}
676676

677677
#[test]

tests/fixtures/numfmt/df_expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ udev 8.2G 0 8.2G 0% /dev
33
tmpfs 1.7G 2.1M 1.7G 1% /run
44
/dev/nvme0n1p2 1.1T 433G 523G 46% /
55
tmpfs 8.3G 145M 8.1G 2% /dev/shm
6-
tmpfs 5.3M 4.1K 5.3M 1% /run/lock
6+
tmpfs 5.3M 4.1k 5.3M 1% /run/lock
77
tmpfs 8.3G 0 8.3G 0% /sys/fs/cgroup
88
/dev/nvme0n1p1 536M 8.2M 528M 2% /boot/efi

tests/fixtures/numfmt/gnutest_si_result.txt

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
-1.1K
2-
-1.0K
1+
-1.1k
2+
-1.0k
33
-999
44
1
55
500
66
999
7-
1.0K
8-
1.0K
9-
1.1K
10-
1.1K
11-
9.9K
12-
10K
13-
10K
14-
10K
15-
10K
16-
10K
17-
11K
18-
11K
19-
11K
20-
50K
21-
99K
22-
100K
23-
100K
24-
100K
25-
100K
26-
100K
27-
101K
28-
101K
29-
101K
30-
102K
31-
999K
7+
1.0k
8+
1.0k
9+
1.1k
10+
1.1k
11+
9.9k
12+
10k
13+
10k
14+
10k
15+
10k
16+
10k
17+
11k
18+
11k
19+
11k
20+
50k
21+
99k
22+
100k
23+
100k
24+
100k
25+
100k
26+
100k
27+
101k
28+
101k
29+
101k
30+
102k
31+
999k
3232
1.0M
3333
1.0M
3434
1.0M

0 commit comments

Comments
 (0)