Skip to content

Commit 912471d

Browse files
authored
od: hex byte offset case fix (#12175)
* Made hex byte offset lowercase * Added test based on issue * Fixed formatting, moved import to local scope * Fixed failing tests * Forced no wasi test * Revert "Forced no wasi test" This reverts commit 0cd71c6. * Switched linux to unix, to match test_dd * Removed urandom dependency credit @cakebaker
1 parent 48f93ae commit 912471d

2 files changed

Lines changed: 24 additions & 7 deletions

File tree

src/uu/od/src/input_offset.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ impl InputOffset {
5151
match (self.radix, self.label) {
5252
(Radix::Decimal, None) => format!("{:07}", self.byte_pos),
5353
(Radix::Decimal, Some(l)) => format!("{:07} ({l:07})", self.byte_pos),
54-
(Radix::Hexadecimal, None) => format!("{:06X}", self.byte_pos),
55-
(Radix::Hexadecimal, Some(l)) => format!("{:06X} ({l:06X})", self.byte_pos),
54+
(Radix::Hexadecimal, None) => format!("{:06x}", self.byte_pos),
55+
(Radix::Hexadecimal, Some(l)) => format!("{:06x} ({l:06x})", self.byte_pos),
5656
(Radix::Octal, None) => format!("{:07o}", self.byte_pos),
5757
(Radix::Octal, Some(l)) => format!("{:07o} ({l:07o})", self.byte_pos),
5858
(Radix::NoPrefix, None) => String::new(),
@@ -73,7 +73,7 @@ impl InputOffset {
7373
#[test]
7474
fn test_input_offset() {
7575
let mut sut = InputOffset::new(Radix::Hexadecimal, 10, None);
76-
assert_eq!("00000A", &sut.format_byte_offset());
76+
assert_eq!("00000a", &sut.format_byte_offset());
7777
sut.increase_position(10);
7878
assert_eq!("000014", &sut.format_byte_offset());
7979

@@ -98,16 +98,16 @@ fn test_input_offset() {
9898
#[test]
9999
fn test_input_offset_with_label() {
100100
let mut sut = InputOffset::new(Radix::Hexadecimal, 10, Some(20));
101-
assert_eq!("00000A (000014)", &sut.format_byte_offset());
101+
assert_eq!("00000a (000014)", &sut.format_byte_offset());
102102
sut.increase_position(10);
103-
assert_eq!("000014 (00001E)", &sut.format_byte_offset());
103+
assert_eq!("000014 (00001e)", &sut.format_byte_offset());
104104

105105
// note normally the radix will not change after initialization
106106
sut.set_radix(Radix::Decimal);
107107
assert_eq!("0000020 (0000030)", &sut.format_byte_offset());
108108

109109
sut.set_radix(Radix::Hexadecimal);
110-
assert_eq!("000014 (00001E)", &sut.format_byte_offset());
110+
assert_eq!("000014 (00001e)", &sut.format_byte_offset());
111111

112112
sut.set_radix(Radix::Octal);
113113
assert_eq!("0000024 (0000036)", &sut.format_byte_offset());

tests/by-util/test_od.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ fn test_hex_offset() {
689689
00000000 00000000 00000000 00000000
690690
000010 00000000 00000000 00000000 00000000
691691
00000000 00000000 00000000 00000000
692-
00001F
692+
00001f
693693
",
694694
);
695695

@@ -1343,3 +1343,20 @@ fn test_write_error_dev_full() {
13431343
.code_is(1)
13441344
.stderr_contains("No space left on device");
13451345
}
1346+
1347+
#[test]
1348+
fn test_hex_lowercase() {
1349+
let input = [0u8; 10];
1350+
// Test verifies that the output hex byte offset is in lowercase
1351+
new_ucmd!()
1352+
.arg("-Ax")
1353+
.run_piped_stdin(input)
1354+
.success()
1355+
.no_stderr()
1356+
.stdout_only(unindent(
1357+
r"
1358+
000000 000000 000000 000000 000000 000000
1359+
00000a
1360+
",
1361+
));
1362+
}

0 commit comments

Comments
 (0)