Skip to content

Commit 03035d4

Browse files
chore: fix clippy collapsible_if and add column-accessor tests
Flatten the nested grid_opacity persistence guards in the settings panel to satisfy clippy::collapsible_if (edition 2021, no let_chains). Cover the new LoadedFile::get_channel_column lazy column-major accessor with unit tests for hot, out-of-bounds, idempotent, and empty-log paths.
1 parent a84caf7 commit 03035d4

2 files changed

Lines changed: 74 additions & 8 deletions

File tree

src/ui/settings_panel.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,13 @@ impl UltraLogApp {
216216
});
217217
// Persist only when the user releases the slider, otherwise
218218
// every drag pixel rewrites settings.json.
219-
if let Some(resp) = slider_response {
220-
if resp.drag_stopped() || resp.lost_focus() {
221-
if self.user_settings.grid_opacity != self.grid_opacity {
222-
self.user_settings.grid_opacity = self.grid_opacity;
223-
if let Err(e) = self.user_settings.save() {
224-
self.show_toast_error(&t!("toast.failed_to_save", error = e));
225-
}
226-
}
219+
let committed = slider_response
220+
.map(|r| r.drag_stopped() || r.lost_focus())
221+
.unwrap_or(false);
222+
if committed && self.user_settings.grid_opacity != self.grid_opacity {
223+
self.user_settings.grid_opacity = self.grid_opacity;
224+
if let Err(e) = self.user_settings.save() {
225+
self.show_toast_error(&t!("toast.failed_to_save", error = e));
227226
}
228227
}
229228
}

tests/core/state_tests.rs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,73 @@ fn test_loaded_file_clone() {
608608
assert_eq!(cloned.channels_with_data, file.channels_with_data);
609609
}
610610

611+
#[test]
612+
fn test_loaded_file_get_channel_column_returns_data() {
613+
let log = create_test_log();
614+
let file = LoadedFile::new(
615+
PathBuf::from("/test/path.csv"),
616+
"path.csv".to_string(),
617+
EcuType::Haltech,
618+
log,
619+
);
620+
621+
// Channel 0: Engine Speed values 5000, 5100, 0
622+
let col0 = file.get_channel_column(0).expect("channel 0 column");
623+
assert_eq!(col0, &[5000.0, 5100.0, 0.0]);
624+
625+
// Channel 1: TPS values 50, 0, 0
626+
let col1 = file.get_channel_column(1).expect("channel 1 column");
627+
assert_eq!(col1, &[50.0, 0.0, 0.0]);
628+
}
629+
630+
#[test]
631+
fn test_loaded_file_get_channel_column_out_of_bounds() {
632+
let log = create_test_log();
633+
let file = LoadedFile::new(
634+
PathBuf::from("/test/path.csv"),
635+
"path.csv".to_string(),
636+
EcuType::Haltech,
637+
log,
638+
);
639+
640+
assert!(file.get_channel_column(999).is_none());
641+
}
642+
643+
#[test]
644+
fn test_loaded_file_get_channel_column_idempotent() {
645+
// Second call should return the same lazily-built columns and produce
646+
// identical slices — exercises the OnceLock memoization path.
647+
let log = create_test_log();
648+
let file = LoadedFile::new(
649+
PathBuf::from("/test/path.csv"),
650+
"path.csv".to_string(),
651+
EcuType::Haltech,
652+
log,
653+
);
654+
655+
let first = file.get_channel_column(0).unwrap().to_vec();
656+
let second = file.get_channel_column(0).unwrap().to_vec();
657+
assert_eq!(first, second);
658+
}
659+
660+
#[test]
661+
fn test_loaded_file_get_channel_column_empty_log() {
662+
let log = Log {
663+
meta: ultralog::parsers::types::Meta::Empty,
664+
channels: vec![],
665+
times: vec![],
666+
data: vec![],
667+
};
668+
let file = LoadedFile::new(
669+
PathBuf::from("/test/path.csv"),
670+
"path.csv".to_string(),
671+
EcuType::Haltech,
672+
log,
673+
);
674+
675+
assert!(file.get_channel_column(0).is_none());
676+
}
677+
611678
// ============================================
612679
// HistogramMode Tests
613680
// ============================================

0 commit comments

Comments
 (0)