Skip to content

Commit

Permalink
refactor: fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Oppzippy committed Jan 9, 2025
1 parent 6e67d77 commit 4586679
Show file tree
Hide file tree
Showing 26 changed files with 57 additions and 90 deletions.
2 changes: 1 addition & 1 deletion cli/tests/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn test_set_equalizer() {
cmd.arg("set")
.arg("equalizer")
.arg("--")
.args(&["-120", "-60", "0", "0", "0", "60", "120", "135"]);
.args(["-120", "-60", "0", "0", "0", "60", "120", "135"]);
cmd.assert()
.success()
.stdout(predicate::str::is_empty())
Expand Down
2 changes: 1 addition & 1 deletion gui/src/actions/create_custom_equalizer_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ mod tests {
let dir = tempfile::tempdir().unwrap();
let settings_file = SettingsFile::new(dir.path().join("config.toml"));
let custom_profile = GlibCustomEqualizerProfile::new(
&"custom profile".to_string(),
"custom profile",
Arc::new([0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8]),
);
create_custom_equalizer_profile(&state, &settings_file, &custom_profile).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion gui/src/actions/delete_custom_equalizer_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ mod tests {
let dir = tempfile::tempdir().unwrap();
let settings_file = SettingsFile::<Config>::new(dir.path().join("config.toml"));
let custom_profile = GlibCustomEqualizerProfile::new(
&"custom profile".to_string(),
"custom profile",
Arc::new([0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8]),
);
settings_file
Expand Down
12 changes: 6 additions & 6 deletions gui/src/actions/import_custom_equalizer_profiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ mod tests {
let settings_file = SettingsFile::new(dir.path().join("config.toml"));

let custom_profiles = &[GlibCustomEqualizerProfile::new(
&"custom profile".to_string(),
"custom profile",
Arc::new([-1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0]),
)];
import_custom_equalizer_profiles(&state, &settings_file, custom_profiles, true).unwrap();
Expand All @@ -99,11 +99,11 @@ mod tests {

let custom_profiles = &[
GlibCustomEqualizerProfile::new(
&"custom profile".to_string(),
"custom profile",
Arc::new([-1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0]),
),
GlibCustomEqualizerProfile::new(
&"all zero".to_string(),
"all zero",
Arc::new([-2.0, -2.0, -2.0, -2.0, -2.0, -2.0, -2.0, -2.0]),
),
];
Expand Down Expand Up @@ -134,7 +134,7 @@ mod tests {
insert_test_profiles(&settings_file);

let custom_profiles = &[GlibCustomEqualizerProfile::new(
&"all zero".to_string(),
"all zero",
Arc::new([-2.0, -2.0, -2.0, -2.0, -2.0, -2.0, -2.0, -2.0]),
)];
import_custom_equalizer_profiles(&state, &settings_file, custom_profiles, false).unwrap();
Expand Down Expand Up @@ -173,11 +173,11 @@ mod tests {

let custom_profiles = &[
GlibCustomEqualizerProfile::new(
&"all zero".to_string(),
"all zero",
Arc::new([-2.0, -2.0, -2.0, -2.0, -2.0, -2.0, -2.0, -2.0]),
),
GlibCustomEqualizerProfile::new(
&"all zero".to_string(),
"all zero",
Arc::new([-3.0, -3.0, -3.0, -3.0, -3.0, -3.0, -3.0, -3.0]),
),
];
Expand Down
2 changes: 1 addition & 1 deletion gui/src/actions/select_custom_equalizer_configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ mod tests {
let dir = tempfile::tempdir().unwrap();
let settings_file = SettingsFile::<Config>::new(dir.path().join("config.toml"));
let custom_profile = GlibCustomEqualizerProfile::new(
&"custom profile".to_string(),
"custom profile",
Arc::new([0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8]),
);
let lib_custom_profile = EqualizerConfiguration::new_custom_profile(
Expand Down
8 changes: 4 additions & 4 deletions gui/src/actions/set_equalizer_configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ mod tests {
selected_device
.expect_set_equalizer_configuration()
.once()
.with(predicate::eq(EqualizerConfiguration::from(
.with(predicate::eq(
EqualizerConfiguration::new_from_preset_profile(PresetEqualizerProfile::Acoustic),
)))
))
.return_once(|_ambient_sound_mode| Ok(()));
*state.selected_device.borrow_mut() = Some(Rc::new(selected_device));

Expand All @@ -113,9 +113,9 @@ mod tests {
selected_device
.expect_set_equalizer_configuration()
.once()
.with(predicate::eq(EqualizerConfiguration::from(
.with(predicate::eq(
EqualizerConfiguration::new_from_preset_profile(PresetEqualizerProfile::Acoustic),
)))
))
.return_once(|_ambient_sound_mode| Ok(()));
*state.selected_device.borrow_mut() = Some(Rc::new(selected_device));

Expand Down
6 changes: 3 additions & 3 deletions gui/src/swappable_broadcast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ where

#[cfg(test)]
mod tests {
use std::{sync::Arc, time::Duration};
use std::time::Duration;

use gtk::glib::timeout_future;
use tokio::sync::watch;
Expand All @@ -71,7 +71,7 @@ mod tests {

#[gtk::test]
async fn test_swap_receiver() {
let swappable: Arc<SwappableBroadcast<i8>> = Arc::new(SwappableBroadcast::new());
let swappable: SwappableBroadcast<i8> = SwappableBroadcast::new();
let swappable_receiver = swappable.subscribe().await;

{
Expand Down Expand Up @@ -100,7 +100,7 @@ mod tests {

#[gtk::test]
async fn test_unsubscribes_from_old_receiviers() {
let swappable: Arc<SwappableBroadcast<i8>> = Arc::new(SwappableBroadcast::new());
let swappable: SwappableBroadcast<i8> = SwappableBroadcast::new();
let (sender, receiver) = watch::channel(1);

swappable.replace_receiver(Some(receiver)).await;
Expand Down
10 changes: 3 additions & 7 deletions gui/src/test_utils/walk_children.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ impl<'a, T: IsA<gtk::Widget>> GtkWidgetChildWalker<'a, T> {
}
}

impl<'a, T: IsA<gtk::Widget>> Iterator for GtkWidgetChildWalker<'a, T> {
impl<T: IsA<gtk::Widget>> Iterator for GtkWidgetChildWalker<'_, T> {
type Item = gtk::Widget;

fn next(&mut self) -> Option<Self::Item> {
let Some(mut current) = self.current.to_owned() else {
return None;
};
let mut current = self.current.to_owned()?;

// First visit child node if possible
if let Some(child) = current.first_child() {
Expand All @@ -47,9 +45,7 @@ impl<'a, T: IsA<gtk::Widget>> Iterator for GtkWidgetChildWalker<'a, T> {
// No more next nodes, so go up to the parent, which we visited already, and visit the parent's next sibling
// Repeat if the parent has no next sibling
loop {
let Some(parent) = current.parent() else {
return None;
};
let parent = current.parent()?;
if &parent == self.root {
return None;
}
Expand Down
6 changes: 3 additions & 3 deletions gui/src/ui/widgets/equalizer_settings/equalizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ mod tests {
load_resources();
let equalizer = Equalizer::new();
let expected_volumes = [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7];
equalizer.set_volumes(&expected_volumes.to_owned());
equalizer.set_volumes(expected_volumes.as_ref());
assert_eq!(
expected_volumes,
equalizer.volume_adjustments().adjustments().as_ref()
Expand All @@ -198,7 +198,7 @@ mod tests {
),
);
equalizer.imp().band_100.set_volume(0.1);
assert_eq!(true, received_event.get());
assert!(received_event.get());
}

#[gtk::test]
Expand All @@ -218,7 +218,7 @@ mod tests {
),
);
equalizer.set_volumes(&[0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7]);
assert_eq!(false, received_event.get());
assert!(!received_event.get());
}

#[gtk::test]
Expand Down
30 changes: 6 additions & 24 deletions gui/src/ui/widgets/equalizer_settings/equalizer_settings_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,14 +589,8 @@ mod tests {
settings.set_equalizer_configuration(&EqualizerConfiguration::new_from_preset_profile(
PresetEqualizerProfile::SoundcoreSignature,
));
assert_eq!(
false,
settings.imp().create_custom_profile_button.is_visible(),
);
assert_eq!(
false,
settings.imp().delete_custom_profile_button.is_visible(),
);
assert!(!settings.imp().create_custom_profile_button.is_visible(),);
assert!(!settings.imp().delete_custom_profile_button.is_visible(),);
}

#[gtk::test]
Expand All @@ -608,14 +602,8 @@ mod tests {
settings.set_equalizer_configuration(&EqualizerConfiguration::new_custom_profile(
VolumeAdjustments::new([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]).unwrap(),
));
assert_eq!(
true,
settings.imp().create_custom_profile_button.is_visible(),
);
assert_eq!(
false,
settings.imp().delete_custom_profile_button.is_visible(),
);
assert!(settings.imp().create_custom_profile_button.is_visible(),);
assert!(!settings.imp().delete_custom_profile_button.is_visible(),);
}

#[gtk::test]
Expand All @@ -631,13 +619,7 @@ mod tests {
settings.set_equalizer_configuration(&EqualizerConfiguration::new_custom_profile(
VolumeAdjustments::new([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]).unwrap(),
));
assert_eq!(
false,
settings.imp().create_custom_profile_button.is_visible(),
);
assert_eq!(
true,
settings.imp().delete_custom_profile_button.is_visible(),
);
assert!(!settings.imp().create_custom_profile_button.is_visible(),);
assert!(settings.imp().delete_custom_profile_button.is_visible(),);
}
}
4 changes: 2 additions & 2 deletions gui/src/ui/widgets/import_export/export_profile_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ mod tests {
load_resources();
let volume_adjustments: Arc<[f64]> = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0].into();
let widget = ExportProfileSelection::new();
widget.set_profiles(&vec![
widget.set_profiles(&[
GlibCustomEqualizerProfile::new("test", volume_adjustments.to_owned()),
GlibCustomEqualizerProfile::new("test2", volume_adjustments.to_owned()),
GlibCustomEqualizerProfile::new("test3", volume_adjustments.to_owned()),
Expand All @@ -200,7 +200,7 @@ mod tests {
&widget.imp().profile_list,
HashSet::from(["test2".into(), "test3".into()]),
);
widget.set_profiles(&vec![
widget.set_profiles(&[
GlibCustomEqualizerProfile::new("test", volume_adjustments.to_owned()),
GlibCustomEqualizerProfile::new("test2", volume_adjustments.to_owned()),
]);
Expand Down
25 changes: 8 additions & 17 deletions lib/src/device_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,47 +83,38 @@ mod tests {

#[test]
fn test_center_service_uuid() {
assert_eq!(true, is_soundcore_service_uuid(&SERVICE_UUID));
assert!(is_soundcore_service_uuid(&SERVICE_UUID));
}

#[test]
fn test_valid_service_uuid() {
let uuid = Uuid::from_str("1234f5da-0000-1000-8000-00805f9b34fb").unwrap();
assert_eq!(true, is_soundcore_service_uuid(&uuid));
assert!(is_soundcore_service_uuid(&uuid));
}

#[test]
fn test_invalid_service_uuid() {
let uuid = Uuid::from_str("123455da-0000-1000-8000-00805f9b34fb").unwrap();
assert_eq!(false, is_soundcore_service_uuid(&uuid));
assert!(!is_soundcore_service_uuid(&uuid));
}

#[test]
fn test_service_uuids_are_in_correct_range() {
let uuids = service_uuids();
assert_eq!(
true,
uuids.contains(&uuid!("0100f5da-0000-1000-8000-00805f9b34fb"))
);
assert_eq!(
true,
uuids.contains(&uuid!("011cf5da-0000-1000-8000-00805f9b34fb"))
);
assert_eq!(
true,
uuids.contains(&uuid!("0120f5da-0000-1000-8000-00805f9b34fb"))
);
assert!(uuids.contains(&uuid!("0100f5da-0000-1000-8000-00805f9b34fb")));
assert!(uuids.contains(&uuid!("011cf5da-0000-1000-8000-00805f9b34fb")));
assert!(uuids.contains(&uuid!("0120f5da-0000-1000-8000-00805f9b34fb")));
}

#[test]
fn test_soundcore_device_mac_address() {
let mac_address = [0xAC, 0x12, 0x2F, 0x00, 0x00, 0x00].into();
assert_eq!(true, is_mac_address_soundcore_device(mac_address));
assert!(is_mac_address_soundcore_device(mac_address));
}

#[test]
fn test_not_soundcore_device_mac_address() {
let mac_address = [0xAC, 0x00, 0x00, 0x00, 0x00, 0x00].into();
assert_eq!(false, is_mac_address_soundcore_device(mac_address));
assert!(!is_mac_address_soundcore_device(mac_address));
}
}
2 changes: 1 addition & 1 deletion lib/src/devices/a3933/device_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ mod tests {
.1;
let state: DeviceState = StateUpdatePacket::from(state_update).into();
let implementation = (A3933_DEVICE_PROFILE.implementation)();
let state = (&implementation.packet_handlers()[&STATE_UPDATE])(&body, state);
let state = implementation.packet_handlers()[&STATE_UPDATE](body, state);

let equalizer_configuration =
EqualizerConfiguration::new_from_preset_profile(PresetEqualizerProfile::TrebleReducer);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/devices/a3945/device_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ mod tests {
.1;
let state: DeviceState = StateUpdatePacket::from(state_update).into();
let implementation = (A3945_DEVICE_PROFILE.implementation)();
let state = (&implementation.packet_handlers()[&STATE_UPDATE])(&body, state);
let state = implementation.packet_handlers()[&STATE_UPDATE](body, state);

let equalizer_configuration =
EqualizerConfiguration::new_from_preset_profile(PresetEqualizerProfile::TrebleReducer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ mod tests {
let packet = ChineseVoicePromptStateUpdatePacket::take::<VerboseError<_>>(body)
.unwrap()
.1;
assert_eq!(true, packet.is_enabled);
assert!(packet.is_enabled);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ mod tests {
let packet = GameModeUpdatePacket::take::<VerboseError<_>>(body)
.unwrap()
.1;
assert_eq!(true, packet.is_enabled);
assert!(packet.is_enabled);
}
}
2 changes: 1 addition & 1 deletion lib/src/devices/standard/packets/inbound/inbound_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@ mod tests {
#[test]
fn it_errors_when_nothing_matches() {
let result = take_inbound_packet_header::<VerboseError<_>>(&[1, 2, 3]);
assert_eq!(true, result.is_err());
assert!(result.is_err());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ mod tests {
let packet = LdacStateUpdatePacket::take::<VerboseError<_>>(body)
.unwrap()
.1;
assert_eq!(true, packet.is_enabled);
assert!(packet.is_enabled);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ impl InboundPacket for SoundModeTypeTwoUpdatePacket {
}

#[cfg(test)]

mod tests {
use nom::error::VerboseError;

Expand Down Expand Up @@ -83,7 +82,7 @@ mod tests {
sound_modes.adaptive_noise_canceling
);
assert_eq!(TransparencyMode::VocalMode, sound_modes.transparency_mode);
assert_eq!(true, sound_modes.wind_noise_suppression);
assert!(sound_modes.wind_noise_suppression);
assert_eq!(5, sound_modes.noise_canceling_adaptive_sensitivity_level);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ mod tests {
.unwrap()
.1;
assert_eq!(HostDevice::Left, packet.host_device);
assert_eq!(true, packet.tws_status);
assert!(packet.tws_status);
}
}
Loading

0 comments on commit 4586679

Please sign in to comment.