Skip to content

Commit a0e97a1

Browse files
committed
Simplified code and add tests with help of copilot
1 parent 1ee54c8 commit a0e97a1

File tree

3 files changed

+177
-204
lines changed

3 files changed

+177
-204
lines changed

czkawka_cli/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use clap::Parser;
66

77
use commands::Commands;
88
use czkawka_core::big_file::SearchMode;
9-
use czkawka_core::common::{get_number_of_threads, set_default_number_of_threads, set_number_of_threads};
9+
use czkawka_core::common::set_number_of_threads;
1010
#[allow(unused_imports)] // It is used in release for print_results().
1111
use czkawka_core::common_traits::*;
1212
use czkawka_core::similar_images::test_image_conversion_speed;

czkawka_gui/src/help_functions.rs

+56-5
Original file line numberDiff line numberDiff line change
@@ -378,14 +378,34 @@ pub fn get_notebook_enum_from_tree_view(tree_view: &TreeView) -> NotebookMainEnu
378378
}
379379
}
380380
}
381+
pub fn get_tree_view_name_from_notebook_enum(notebook_enum: NotebookMainEnum) -> &'static str {
382+
match notebook_enum {
383+
NotebookMainEnum::Duplicate => "tree_view_duplicate_finder",
384+
NotebookMainEnum::EmptyDirectories => "tree_view_empty_folder_finder",
385+
NotebookMainEnum::EmptyFiles => "tree_view_empty_files_finder",
386+
NotebookMainEnum::Temporary => "tree_view_temporary_files_finder",
387+
NotebookMainEnum::BigFiles => "tree_view_big_files_finder",
388+
NotebookMainEnum::SimilarImages => "tree_view_similar_images_finder",
389+
NotebookMainEnum::SimilarVideos => "tree_view_similar_videos_finder",
390+
NotebookMainEnum::SameMusic => "tree_view_same_music_finder",
391+
NotebookMainEnum::Symlinks => "tree_view_invalid_symlinks",
392+
NotebookMainEnum::BrokenFiles => "tree_view_broken_files",
393+
NotebookMainEnum::BadExtensions => "tree_view_bad_extensions",
394+
}
395+
}
381396

382397
pub fn get_notebook_upper_enum_from_tree_view(tree_view: &TreeView) -> NotebookUpperEnum {
383398
match (*tree_view).widget_name().to_string().as_str() {
384399
"tree_view_upper_included_directories" => NotebookUpperEnum::IncludedDirectories,
385400
"tree_view_upper_excluded_directories" => NotebookUpperEnum::ExcludedDirectories,
386-
e => {
387-
panic!("{}", e)
388-
}
401+
e => panic!("{}", e),
402+
}
403+
}
404+
pub fn get_tree_view_name_from_notebook_upper_enum(notebook_upper_enum: NotebookUpperEnum) -> &'static str {
405+
match notebook_upper_enum {
406+
NotebookUpperEnum::IncludedDirectories => "tree_view_upper_included_directories",
407+
NotebookUpperEnum::ExcludedDirectories => "tree_view_upper_excluded_directories",
408+
_ => panic!(),
389409
}
390410
}
391411

@@ -789,15 +809,46 @@ pub fn scale_step_function(scale: &Scale, _scroll_type: ScrollType, value: f64)
789809
#[cfg(test)]
790810
mod test {
791811
use glib::types::Type;
812+
use glib::Value;
792813
use gtk4::prelude::*;
793-
use gtk4::Orientation;
814+
use gtk4::{Orientation, TreeView};
794815
use image::DynamicImage;
795816

796817
use crate::help_functions::{
797818
change_dimension_to_krotka, check_if_list_store_column_have_all_same_values, check_if_value_is_in_list_store, get_all_boxes_from_widget, get_all_direct_children,
798-
get_max_file_name, get_pixbuf_from_dynamic_image,
819+
get_max_file_name, get_pixbuf_from_dynamic_image, get_string_from_list_store,
799820
};
800821

822+
#[gtk4::test]
823+
fn test_get_string_from_list_store() {
824+
let columns_types: &[Type] = &[Type::STRING];
825+
let list_store = gtk4::ListStore::new(columns_types);
826+
let tree_view = TreeView::with_model(&list_store);
827+
828+
let values_to_add: &[(u32, &dyn ToValue)] = &[(0, &"test"), (0, &"test2"), (0, &"test3")];
829+
for i in values_to_add {
830+
list_store.set(&list_store.append(), &[*i]);
831+
}
832+
assert_eq!(
833+
get_string_from_list_store(&tree_view, 0, None),
834+
vec!["test".to_string(), "test2".to_string(), "test3".to_string()]
835+
);
836+
837+
let columns_types: &[Type] = &[Type::BOOL, Type::STRING];
838+
let list_store = gtk4::ListStore::new(columns_types);
839+
let tree_view = TreeView::with_model(&list_store);
840+
841+
let values_to_add: &[&[(u32, &dyn ToValue)]] = &[
842+
&[(0, &Into::<Value>::into(true)), (1, &Into::<Value>::into("test"))],
843+
&[(0, &Into::<Value>::into(true)), (1, &Into::<Value>::into("test2"))],
844+
&[(0, &Into::<Value>::into(false)), (1, &Into::<Value>::into("test3"))],
845+
];
846+
for i in values_to_add {
847+
list_store.set(&list_store.append(), i);
848+
}
849+
assert_eq!(get_string_from_list_store(&tree_view, 1, Some(0)), vec!["test".to_string(), "test2".to_string()]);
850+
}
851+
801852
#[gtk4::test]
802853
fn test_check_if_list_store_column_have_all_same_values() {
803854
let columns_types: &[Type] = &[Type::BOOL];

0 commit comments

Comments
 (0)