mirror of
https://github.com/sharkdp/hexyl.git
synced 2026-10-26 20:16:31 +00:00
added squeeze tests
This commit is contained in:
1 parent
fe65792b96
commit
b1ff8b6ce4
3 files changed
+245
-7
No files matched your search
Generated
+51
-7
@@ -124,6 +124,22 @@ dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ctor"
|
||||
version = "0.1.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6d2301688392eb071b0bf1a37be05c469d3cc4dbbd95df672fe28ab021e6a096"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "diff"
|
||||
version = "0.1.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8"
|
||||
|
||||
[[package]]
|
||||
name = "difflib"
|
||||
version = "0.4.0"
|
||||
@@ -193,6 +209,7 @@ dependencies = [
|
||||
"const_format",
|
||||
"libc",
|
||||
"predicates",
|
||||
"pretty_assertions",
|
||||
"terminal_size",
|
||||
"thiserror",
|
||||
]
|
||||
@@ -263,6 +280,15 @@ version = "6.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "029d8d0b2f198229de29dca79676f2738ff952edf3fde542eb8bf94d8c21b435"
|
||||
|
||||
[[package]]
|
||||
name = "output_vt100"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "628223faebab4e3e40667ee0b2336d34a5b960ff60ea743ddfdbcf7770bcfb66"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "predicates"
|
||||
version = "2.1.1"
|
||||
@@ -294,19 +320,31 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.39"
|
||||
name = "pretty_assertions"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f"
|
||||
checksum = "a25e9bcb20aa780fd0bb16b72403a9064d6b3f22f026946029acb941a50af755"
|
||||
dependencies = [
|
||||
"ctor",
|
||||
"diff",
|
||||
"output_vt100",
|
||||
"yansi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.47"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.18"
|
||||
version = "1.0.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1"
|
||||
checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
@@ -356,9 +394,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.95"
|
||||
version = "1.0.103"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fbaf6116ab8924f39d52792136fb74fd60a80194cf1b1c6ffa6453eef1c3f942"
|
||||
checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -504,3 +542,9 @@ name = "windows_x86_64_msvc"
|
||||
version = "0.36.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680"
|
||||
|
||||
[[package]]
|
||||
name = "yansi"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec"
|
||||
@@ -27,6 +27,7 @@ features = ["std", "suggestions", "color", "wrap_help", "cargo", "help", "usage"
|
||||
[dev-dependencies]
|
||||
assert_cmd = "2.0"
|
||||
predicates = "2.0"
|
||||
pretty_assertions = "1.3.0"
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
|
||||
@@ -5,6 +5,26 @@ fn hexyl() -> Command {
|
||||
cmd.current_dir("tests/examples");
|
||||
cmd
|
||||
}
|
||||
trait PrettyAssert<S>
|
||||
where
|
||||
S: AsRef<str>,
|
||||
{
|
||||
fn pretty_stdout(self, other: S);
|
||||
}
|
||||
|
||||
// https://github.com/assert-rs/assert_cmd/issues/121#issuecomment-849937376
|
||||
//
|
||||
impl<S> PrettyAssert<S> for assert_cmd::assert::Assert
|
||||
where
|
||||
S: AsRef<str>,
|
||||
{
|
||||
fn pretty_stdout(self, other: S) {
|
||||
println!("{}", other.as_ref().len());
|
||||
let self_str = String::from_utf8(self.get_output().stdout.clone()).unwrap();
|
||||
println!("{}", self_str.len());
|
||||
pretty_assertions::assert_eq!(self_str, other.as_ref());
|
||||
}
|
||||
}
|
||||
|
||||
mod basic {
|
||||
use super::hexyl;
|
||||
@@ -274,6 +294,7 @@ mod display_settings {
|
||||
|
||||
mod group {
|
||||
use super::hexyl;
|
||||
use super::PrettyAssert;
|
||||
|
||||
#[test]
|
||||
fn group_2_bytes() {
|
||||
@@ -357,4 +378,176 @@ mod group {
|
||||
.assert()
|
||||
.failure();
|
||||
}
|
||||
#[test]
|
||||
fn squeeze_no_chars() {
|
||||
hexyl()
|
||||
.arg("hello_world_elf64")
|
||||
.arg("--color=never")
|
||||
.arg("--skip=1024")
|
||||
.arg("--length=4096")
|
||||
.arg("--no-characters")
|
||||
.assert()
|
||||
.success()
|
||||
.pretty_stdout(
|
||||
"\
|
||||
┌────────┬─────────────────────────┬─────────────────────────┐
|
||||
│00000400│ 00 00 00 00 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 │
|
||||
│* │ ┊ │
|
||||
│00001000│ ba 0e 00 00 00 b9 00 20 ┊ 40 00 bb 01 00 00 00 b8 │
|
||||
│00001010│ 04 00 00 00 cd 80 b8 01 ┊ 00 00 00 cd 80 00 00 00 │
|
||||
│00001020│ 00 00 00 00 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 │
|
||||
│* │ ┊ │
|
||||
│00001400│ ┊ │
|
||||
└────────┴─────────────────────────┴─────────────────────────┘
|
||||
",
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
fn squeeze_no_chars_one_panel() {
|
||||
hexyl()
|
||||
.arg("hello_world_elf64")
|
||||
.arg("--color=never")
|
||||
.arg("--skip=1024")
|
||||
.arg("--length=4096")
|
||||
.arg("--no-characters")
|
||||
.arg("--panels=1")
|
||||
.assert()
|
||||
.success()
|
||||
.pretty_stdout(
|
||||
"\
|
||||
┌────────┬─────────────────────────┐
|
||||
│00000400│ 00 00 00 00 00 00 00 00 │
|
||||
│* │ │
|
||||
│00001000│ ba 0e 00 00 00 b9 00 20 │
|
||||
│00001008│ 40 00 bb 01 00 00 00 b8 │
|
||||
│00001010│ 04 00 00 00 cd 80 b8 01 │
|
||||
│00001018│ 00 00 00 cd 80 00 00 00 │
|
||||
│00001020│ 00 00 00 00 00 00 00 00 │
|
||||
│* │ │
|
||||
│00001400│ │
|
||||
└────────┴─────────────────────────┘
|
||||
",
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
fn squeeze_no_position() {
|
||||
hexyl()
|
||||
.arg("hello_world_elf64")
|
||||
.arg("--color=never")
|
||||
.arg("--skip=1024")
|
||||
.arg("--length=4096")
|
||||
.arg("--no-position")
|
||||
.assert()
|
||||
.success()
|
||||
.pretty_stdout(
|
||||
"\
|
||||
┌─────────────────────────┬─────────────────────────┬────────┬────────┐
|
||||
│ 00 00 00 00 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 │00000000┊00000000│
|
||||
│* ┊ │ ┊ │
|
||||
│ ba 0e 00 00 00 b9 00 20 ┊ 40 00 bb 01 00 00 00 b8 │ו000×0 ┊@0ו000×│
|
||||
│ 04 00 00 00 cd 80 b8 01 ┊ 00 00 00 cd 80 00 00 00 │•000××ו┊000××000│
|
||||
│ 00 00 00 00 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 │00000000┊00000000│
|
||||
│* ┊ │ ┊ │
|
||||
│* ┊ │ ┊ │
|
||||
└─────────────────────────┴─────────────────────────┴────────┴────────┘
|
||||
",
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
fn squeeze_no_position_one_panel() {
|
||||
hexyl()
|
||||
.arg("hello_world_elf64")
|
||||
.arg("--color=never")
|
||||
.arg("--skip=1024")
|
||||
.arg("--length=4096")
|
||||
.arg("--no-position")
|
||||
.arg("--panels=1")
|
||||
.assert()
|
||||
.success()
|
||||
.pretty_stdout(
|
||||
"\
|
||||
┌─────────────────────────┬────────┐
|
||||
│ 00 00 00 00 00 00 00 00 │00000000│
|
||||
│* │ │
|
||||
│ ba 0e 00 00 00 b9 00 20 │ו000×0 │
|
||||
│ 40 00 bb 01 00 00 00 b8 │@0ו000×│
|
||||
│ 04 00 00 00 cd 80 b8 01 │•000××ו│
|
||||
│ 00 00 00 cd 80 00 00 00 │000××000│
|
||||
│ 00 00 00 00 00 00 00 00 │00000000│
|
||||
│* │ │
|
||||
│* │ │
|
||||
└─────────────────────────┴────────┘
|
||||
",
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
fn squeeze_odd_panels_remainder_bytes() {
|
||||
hexyl()
|
||||
.arg("hello_world_elf64")
|
||||
.arg("--color=never")
|
||||
.arg("--skip=1024")
|
||||
.arg("--length=4092") // 4 byte remainder
|
||||
.arg("--panels=3")
|
||||
.assert()
|
||||
.success()
|
||||
.pretty_stdout(
|
||||
"\
|
||||
┌────────┬─────────────────────────┬─────────────────────────┬─────────────────────────┬────────┬────────┬────────┐
|
||||
│00000400│ 00 00 00 00 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 │00000000┊00000000┊00000000│
|
||||
│* │ ┊ ┊ │ ┊ ┊ │
|
||||
│00001000│ ba 0e 00 00 00 b9 00 20 ┊ 40 00 bb 01 00 00 00 b8 ┊ 04 00 00 00 cd 80 b8 01 │ו000×0 ┊@0ו000×┊•000××ו│
|
||||
│00001018│ 00 00 00 cd 80 00 00 00 ┊ 00 00 00 00 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 │000××000┊00000000┊00000000│
|
||||
│00001030│ 00 00 00 00 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 │00000000┊00000000┊00000000│
|
||||
│* │ ┊ ┊ │ ┊ ┊ │
|
||||
│000013f0│ 00 00 00 00 00 00 00 00 ┊ 00 00 00 00 ┊ │00000000┊0000 ┊ │
|
||||
└────────┴─────────────────────────┴─────────────────────────┴─────────────────────────┴────────┴────────┴────────┘
|
||||
",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn squeeze_plain() {
|
||||
hexyl()
|
||||
.arg("hello_world_elf64")
|
||||
.arg("--color=never")
|
||||
.arg("--skip=1024")
|
||||
.arg("--length=4096")
|
||||
.arg("--plain")
|
||||
.assert()
|
||||
.success()
|
||||
.pretty_stdout(
|
||||
" \
|
||||
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
|
||||
*
|
||||
ba 0e 00 00 00 b9 00 20 40 00 bb 01 00 00 00 b8
|
||||
04 00 00 00 cd 80 b8 01 00 00 00 cd 80 00 00 00
|
||||
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
|
||||
*
|
||||
*
|
||||
",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn squeeze_plain_remainder() {
|
||||
hexyl()
|
||||
.arg("hello_world_elf64")
|
||||
.arg("--color=never")
|
||||
.arg("--skip=1024")
|
||||
.arg("--length=4092") // 4 byte remainder
|
||||
.arg("--plain")
|
||||
.assert()
|
||||
.success()
|
||||
.pretty_stdout(
|
||||
" \
|
||||
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
|
||||
*
|
||||
ba 0e 00 00 00 b9 00 20 40 00 bb 01 00 00 00 b8
|
||||
04 00 00 00 cd 80 b8 01 00 00 00 cd 80 00 00 00
|
||||
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
|
||||
*
|
||||
00 00 00 00 00 00 00 00 00 00 00 00
|
||||
",
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user