1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2026-01-20 04:01:06 +00:00

Implements swab. Adds odd & even tests.

This commit is contained in:
Tyler 2021-04-22 13:19:51 -07:00
parent 5aabdf854d
commit beb7abcff0
3 changed files with 116 additions and 52 deletions

View file

@ -118,6 +118,18 @@ impl<R: Read> Read for Input<R>
}
}
if self.cf.swab
{
let mut tmp = DEFAULT_FILL_BYTE;
for base in (1..len).step_by(2)
{
tmp = buf[base];
buf[base] = buf[base-1];
buf[base-1] = tmp;
}
}
Ok(len)
}
}

View file

@ -41,35 +41,35 @@ macro_rules! make_spec_test (
( $test_id:ident, $test_name:expr, $src:expr ) =>
{
// When spec not given, output should match input
make_spec_test!($test_id, $test_name, $src, None, $src);
make_spec_test!($test_id, $test_name, $src, $src);
};
( $test_id:ident, $test_name:expr, $src:expr, $spec:expr ) =>
{
make_spec_test!($test_id, $test_name, $src, None, $spec);
make_spec_test!($test_id,
$test_name,
Input {
src: $src,
ibs: 512,
xfer_stats: StatusLevel::None,
cf: cfi!(),
},
Output {
dst: File::create(format!("./test-resources/FAILED-{}.test", $test_name)).unwrap(),
obs: 512,
cf: DEFAULT_CFO,
},
$spec,
format!("./test-resources/FAILED-{}.test", $test_name)
);
};
( $test_id:ident, $test_name:expr, $src:expr, $ctable:expr, $spec:expr ) =>
( $test_id:ident, $test_name:expr, $i:expr, $o:expr, $spec:expr, $tmp_fname:expr ) =>
{
#[test]
fn $test_id()
{
let tmp_fname = format!("./test-resources/FAILED-{}.test", $test_name);
dd($i,$o).unwrap();
let i = Input {
src: $src,
ibs: 512,
xfer_stats: StatusLevel::None,
cf: cfi!($ctable),
};
let o = Output {
dst: File::create(&tmp_fname).unwrap(),
obs: 512,
cf: DEFAULT_CFO,
};
dd(i,o).unwrap();
let res = File::open(&tmp_fname).unwrap();
let res = File::open($tmp_fname).unwrap();
let res = BufReader::new(res);
let spec = BufReader::new($spec);
@ -80,34 +80,56 @@ macro_rules! make_spec_test (
b_spec.unwrap());
}
fs::remove_file(&tmp_fname).unwrap();
fs::remove_file($tmp_fname).unwrap();
}
};
);
#[test]
fn test_input_parser()
{
let args = vec![
String::from("ketchup"),
String::from("mustard"),
String::from("--conv=ibm"),
String::from("relish"),
];
macro_rules! make_conv_test (
( $test_id:ident, $test_name:expr, $src:expr, $ctable:expr, $spec:expr ) =>
{
make_spec_test!($test_id,
$test_name,
Input {
src: $src,
ibs: 512,
xfer_stats: StatusLevel::None,
cf: cfi!($ctable),
},
Output {
dst: File::create(format!("./test-resources/FAILED-{}.test", $test_name)).unwrap(),
obs: 512,
cf: DEFAULT_CFO,
},
$spec,
format!("./test-resources/FAILED-{}.test", $test_name)
);
};
);
let matches = build_app!().parse(args);
// ...
macro_rules! make_cfi_test (
( $test_id:ident, $test_name:expr, $src:expr, $cfi:expr, $spec:expr ) =>
{
make_spec_test!($test_id,
$test_name,
Input {
src: $src,
ibs: 512,
xfer_stats: StatusLevel::None,
cf: $cfi,
},
Output {
dst: File::create(format!("./test-resources/FAILED-{}.test", $test_name)).unwrap(),
obs: 512,
cf: DEFAULT_CFO,
},
$spec,
format!("./test-resources/FAILED-{}.test", $test_name)
);
};
);
unimplemented!()
}
#[test]
fn test_output_parser()
{
unimplemented!()
}
make_spec_test!(
make_spec_test!(
zeros_4k_test,
"zeros-4k",
File::open("./test-resources/zeros-620f0b67a91f7f74151bc5be745b7110.test").unwrap()
@ -131,7 +153,7 @@ make_spec_test!(
File::open("./test-resources/random-5828891cb1230748e146f34223bbd3b5.test").unwrap()
);
make_spec_test!(
make_conv_test!(
atoe_conv_spec_test,
"atoe-conv-spec-test",
File::open("./test-resources/seq-byte-values-b632a992d3aed5d8d1a59cc5a5a455ba.test").unwrap(),
@ -139,7 +161,7 @@ make_spec_test!(
File::open("./test-resources/gnudd-conv-atoe-seq-byte-values.spec").unwrap()
);
make_spec_test!(
make_conv_test!(
etoa_conv_spec_test,
"etoa-conv-spec-test",
File::open("./test-resources/seq-byte-values-b632a992d3aed5d8d1a59cc5a5a455ba.test").unwrap(),
@ -147,7 +169,7 @@ make_spec_test!(
File::open("./test-resources/gnudd-conv-etoa-seq-byte-values.spec").unwrap()
);
make_spec_test!(
make_conv_test!(
atoibm_conv_spec_test,
"atoibm-conv-spec-test",
File::open("./test-resources/seq-byte-values-b632a992d3aed5d8d1a59cc5a5a455ba.test").unwrap(),
@ -155,7 +177,7 @@ make_spec_test!(
File::open("./test-resources/gnudd-conv-atoibm-seq-byte-values.spec").unwrap()
);
make_spec_test!(
make_conv_test!(
lcase_ascii_to_ucase_ascii,
"lcase_ascii_to_ucase_ascii",
File::open("./test-resources/lcase-ascii.test").unwrap(),
@ -163,7 +185,7 @@ make_spec_test!(
File::open("./test-resources/ucase-ascii.test").unwrap()
);
make_spec_test!(
make_conv_test!(
ucase_ascii_to_lcase_ascii,
"ucase_ascii_to_lcase_ascii",
File::open("./test-resources/ucase-ascii.test").unwrap(),
@ -171,7 +193,7 @@ make_spec_test!(
File::open("./test-resources/lcase-ascii.test").unwrap()
);
make_spec_test!(
make_conv_test!(
// conv=ebcdic,ucase
atoe_and_ucase_conv_spec_test,
"atoe-and-ucase-conv-spec-test",
@ -180,7 +202,7 @@ make_spec_test!(
File::open("./test-resources/ucase-ebcdic.test").unwrap()
);
make_spec_test!(
make_conv_test!(
// conv=ebcdic,lcase
atoe_and_lcase_conv_spec_test,
"atoe-and-lcase-conv-spec-test",
@ -189,7 +211,7 @@ make_spec_test!(
File::open("./test-resources/lcase-ebcdic.test").unwrap()
);
make_spec_test!(
make_conv_test!(
// conv=ibm,ucase
atoibm_and_ucase_conv_spec_test,
"atoibm-and-ucase-conv-spec-test",
@ -198,7 +220,7 @@ make_spec_test!(
File::open("./test-resources/lcase-ibm.test").unwrap()
);
make_spec_test!(
make_conv_test!(
// conv=ibm,lcase
atoibm_and_lcase_conv_spec_test,
"atoibm-and-lcase-conv-spec-test",
@ -216,7 +238,7 @@ fn all_valid_ascii_ebcdic_ascii_roundtrip_conv_test()
let i = Input {
src: File::open("./test-resources/all-valid-ascii-chars-37eff01866ba3f538421b30b7cbefcac.test").unwrap(),
ibs: 256,
ibs: 128,
xfer_stats: StatusLevel::None,
cf: cfi!(Some(&ASCII_TO_EBCDIC)),
};
@ -266,3 +288,33 @@ fn all_valid_ascii_ebcdic_ascii_roundtrip_conv_test()
fs::remove_file(&tmp_fname_ae).unwrap();
fs::remove_file(&tmp_fname_ea).unwrap();
}
make_cfi_test!(
swab_256_test,
"swab-256",
File::open("./test-resources/seq-byte-values.test").unwrap(),
ConvFlagInput {
ctable: None,
block: false,
unblock: false,
swab: true,
sync: false,
noerror: false,
},
File::open("./test-resources/seq-byte-values-swapped.test").unwrap()
);
make_cfi_test!(
swab_257_test,
"swab-257",
File::open("./test-resources/seq-byte-values-odd.test").unwrap(),
ConvFlagInput {
ctable: None,
block: false,
unblock: false,
swab: true,
sync: false,
noerror: false,
},
File::open("./test-resources/seq-byte-values-odd.spec").unwrap()
);