Skip to content

Commit

Permalink
move defaults around for padding
Browse files Browse the repository at this point in the history
  • Loading branch information
tuna-f1sh committed Jan 4, 2023
1 parent d9353b9 commit 456380e
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description = "List system USB buses and devices; a modern and compatible `lsusb
repository = "https://github.com/tuna-f1sh/cyme"
readme = "README.md"
license = "GPL-3.0-or-later"
version = "1.2.0"
version = "1.2.1"
edition = "2021"
keywords = ["usb", "lsusb", "system_profiler", "macos", "libusb"]
categories = ["command-line-utilities"]
Expand Down
17 changes: 17 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,20 @@ impl Config {
dirs::config_dir().map(|x| x.join(CONF_DIR))
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_deserialize_example_file() {
let path = PathBuf::from("./doc").join("cyme_example_config.json");
Config::from_file(path).unwrap();
}

#[test]
fn test_deserialize_config_no_theme() {
let path = PathBuf::from("./tests/data").join("config_no_theme.json");
Config::from_file(path).unwrap();
}
}
12 changes: 6 additions & 6 deletions src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,9 +599,9 @@ impl Block<DeviceBlocks, USBDevice> for DeviceBlocks {
format!("{:^pad$}", "TPos", pad = pad.get(self).unwrap_or(&0))
}
// will be 000 mA = 6
DeviceBlocks::BusPower => "BusPwr".into(),
DeviceBlocks::BusPowerUsed => "PwrUsd".into(),
DeviceBlocks::ExtraCurrentUsed => "PwrExr".into(),
DeviceBlocks::BusPower => "PBus".into(),
DeviceBlocks::BusPowerUsed => "PUsd".into(),
DeviceBlocks::ExtraCurrentUsed => "PExr".into(),
// 00.00 = 5
DeviceBlocks::BcdDevice => "Dev V".into(),
DeviceBlocks::BcdUsb => "USB V".into(),
Expand Down Expand Up @@ -749,18 +749,18 @@ impl Block<ConfigurationBlocks, USBConfiguration> for ConfigurationBlocks {
if verbose {
vec![
ConfigurationBlocks::Number,
ConfigurationBlocks::Name,
ConfigurationBlocks::IconAttributes,
ConfigurationBlocks::Attributes,
ConfigurationBlocks::NumInterfaces,
ConfigurationBlocks::MaxPower,
ConfigurationBlocks::Name,
]
} else {
vec![
ConfigurationBlocks::Number,
ConfigurationBlocks::Name,
ConfigurationBlocks::IconAttributes,
ConfigurationBlocks::MaxPower,
ConfigurationBlocks::Name,
]
}
}
Expand Down Expand Up @@ -841,7 +841,7 @@ impl Block<ConfigurationBlocks, USBConfiguration> for ConfigurationBlocks {
match self {
ConfigurationBlocks::Number => " #".into(),
ConfigurationBlocks::NumInterfaces => "I#".into(),
ConfigurationBlocks::MaxPower => "MaxPwr".into(),
ConfigurationBlocks::MaxPower => "PMax".into(),
ConfigurationBlocks::Name => {
format!("{:^pad$}", "Name", pad = pad.get(self).unwrap_or(&0))
}
Expand Down
13 changes: 10 additions & 3 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,16 @@ impl TestEnv {

// Compare actual output to expected output.
assert_json_diff::assert_json_include!(actual: json!(actual), expected: json!(expected));
// if json!(actual) != json!(expected) {
// panic!("{}", format_output_error(&args, &expected, &actual));
// }
}

/// Parses output back to SPUSBDataType and checks device with `port_path` exists in it
pub fn assert_output_contains_port_path(&self, dump_file: Option<&str>, args: &[&str], port_path: &str) {
// Normalize both expected and actual output.
let output = self.assert_success_and_get_output(dump_file, args);
let actual = String::from_utf8_lossy(&output.stdout).to_string();
let spdata_out = serde_json::from_str::<cyme::system_profiler::SPUSBDataType>(&actual).unwrap();

assert_eq!(spdata_out.get_node(port_path).is_some(), true);
}

/// Similar to assert_output, but able to handle non-utf8 output
Expand Down
51 changes: 51 additions & 0 deletions tests/data/config_no_theme.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"blocks": [
"bus-number",
"device-number",
"icon",
"vendor-id",
"product-id",
"name",
"serial",
"speed"
],
"bus-blocks": [
"name",
"host-controller"
],
"config-blocks": [
"number",
"name",
"icon-attributes",
"max-power"
],
"interface-blocks": [
"port-path",
"icon",
"alt-setting",
"class-code",
"sub-class",
"protocol",
"name"
],
"endpoint-blocks": [
"number",
"direction",
"transfer-type",
"sync-type",
"usage-type",
"max-packet-size"
],
"mask-serials": null,
"lsusb": false,
"tree": false,
"verbose": 0,
"more": false,
"hide-buses": false,
"hide-hubs": false,
"decimal": false,
"no-padding": false,
"ascii": false,
"headings": false,
"force-libusb": false
}

0 comments on commit 456380e

Please sign in to comment.