Skip to content

Commit

Permalink
Fix compile warnings (#11)
Browse files Browse the repository at this point in the history
* Fix compile warnings

* Fix imports in tests
  • Loading branch information
Szymongib authored Feb 16, 2025
1 parent 0887625 commit 1ef5fd0
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 27 deletions.
10 changes: 0 additions & 10 deletions src/bin/interactive/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use crate::interactive::event::Event;
use ratatui::layout::{Constraint, Direction, Layout};
use termion::event::Key;

// TODO: consider moving to some lib
macro_rules! hashmap {
Expand Down Expand Up @@ -31,14 +29,6 @@ fn to_constraints(vals: Vec<u16>) -> Vec<Constraint> {
vals.iter().map(|h| Constraint::Length(*h)).collect()
}

pub fn to_keys(text: &str) -> Vec<Key> {
text.chars().map(Key::Char).collect()
}

pub fn to_key_events(text: &str) -> Vec<Event<Key>> {
text.chars().map(|c| Event::Input(Key::Char(c))).collect()
}

pub fn to_string(vec: Vec<&str>) -> Vec<String> {
vec.iter().map(|s| s.to_string()).collect()
}
13 changes: 10 additions & 3 deletions src/bin/interactive/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,9 @@ fn columns_with_id_constraints() -> Vec<Constraint> {
}

#[cfg(test)]
mod test {
pub(crate) mod test {
use crate::interactive::bookmarks_table::BookmarksTable;
use crate::interactive::event::{Event, Events, Signal};
use crate::interactive::helpers::to_key_events;
use crate::interactive::interface::{InputMode, Interface, SuppressedAction};
use crate::interactive::table::TableItem;
use bookmark_lib::registry::URLRegistry;
Expand All @@ -242,6 +241,14 @@ mod test {
use std::path::{Path, PathBuf};
use termion::event::Key;

pub fn to_keys(text: &str) -> Vec<Key> {
text.chars().map(Key::Char).collect()
}

pub fn to_key_events(text: &str) -> Vec<Event<Key>> {
text.chars().map(|c| Event::Input(Key::Char(c))).collect()
}

fn fix_url_records() -> Vec<URLRecord> {
vec![
URLRecord::new("one", "one", "one", vec!["tag", "with space"]),
Expand Down Expand Up @@ -298,7 +305,7 @@ mod test {
let interface = Interface::new(bookmarks_table).expect("Failed to initialize interface");

(interface, cleaner)
};
}
);
() => (
init!(vec![])
Expand Down
3 changes: 1 addition & 2 deletions src/bin/interactive/modules/command.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::interactive::bookmarks_table::BookmarksTable;
use crate::interactive::helpers::{horizontal_layout, vertical_layout};
use crate::interactive::interface::InputMode;
use crate::interactive::modules::{Draw, HandleInput, Module};
use ratatui::layout::Rect;
Expand Down Expand Up @@ -188,7 +187,7 @@ impl Command {
mod test {
use crate::interactive::bookmarks_table::BookmarksTable;
use crate::interactive::event::Events;
use crate::interactive::helpers::to_keys;
use crate::interactive::interface::test::to_keys;
use crate::interactive::interface::InputMode;
use crate::interactive::modules::command::{Command, DEFAULT_INFO_MESSAGE};
use crate::interactive::modules::HandleInput;
Expand Down
1 change: 0 additions & 1 deletion src/bin/interactive/modules/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::interactive::interface::{InputMode, SuppressedAction};
use crate::interactive::modules::{Draw, HandleInput, Module};
use crate::interactive::widgets::rect::centered_fixed_rect;
use bookmark_lib::types::URLRecord;
use ratatui::backend::Backend;
use ratatui::layout::Alignment;
use ratatui::style::{Color, Modifier, Style};
use ratatui::text::{Span, Text};
Expand Down
4 changes: 1 addition & 3 deletions src/bin/interactive/modules/search.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::interactive::bookmarks_table::BookmarksTable;
use crate::interactive::helpers::{horizontal_layout, vertical_layout};
use crate::interactive::interface::InputMode;
use crate::interactive::modules::{Draw, HandleInput, Module};
use ratatui::backend::Backend;
use ratatui::layout::Rect;
use ratatui::style::Style;
use ratatui::text::Text;
Expand Down Expand Up @@ -105,7 +103,7 @@ impl Search {
mod test {
use crate::interactive::bookmarks_table::BookmarksTable;
use crate::interactive::event::Events;
use crate::interactive::helpers::to_keys;
use crate::interactive::interface::test::to_keys;
use crate::interactive::modules::search::Search;
use crate::interactive::modules::HandleInput;
use bookmark_lib::registry::URLRegistry;
Expand Down
2 changes: 0 additions & 2 deletions src/bin/interactive/url_table_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ pub fn default_columns() -> Columns {

#[derive(Clone, Debug)]
pub struct URLItem {
visible: bool,
url: URLRecord,
row: Vec<String>,
}
Expand All @@ -23,7 +22,6 @@ impl URLItem {
pub fn new(record: URLRecord, cols: Option<&Columns>) -> URLItem {
URLItem {
url: record.clone(),
visible: true,
row: url_to_row(
&record,
cols.unwrap_or(
Expand Down
12 changes: 6 additions & 6 deletions src/lib/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ mod test {
for tu in &all_urls {
let result = registry
.create(
tu.name.clone(),
tu.url.clone(),
tu.name,
tu.url,
tu.group.clone(),
tu.tags.iter().map(|s| s.to_string()).collect(),
)
Expand Down Expand Up @@ -262,7 +262,7 @@ mod test {

println!("List URLs from specific group...");
let group_to_filter = "test";
let group_filter: Box<dyn Filter> = Box::new(GroupFilter::new(group_to_filter.clone()));
let group_filter: Box<dyn Filter> = Box::new(GroupFilter::new(group_to_filter));

let urls = registry
.list_urls(Some(group_filter.as_ref()), None)
Expand All @@ -274,7 +274,7 @@ mod test {
.clone()
.filter(|t| {
if let Some(group) = &t.group {
return *group == group_to_filter.clone();
return *group == group_to_filter;
}
false
})
Expand Down Expand Up @@ -370,8 +370,8 @@ mod test {
fn assert_urls_match(test_urls: &Vec<&TestUrl>, actual: &Vec<URLRecord>) {
for tu in test_urls {
let exists = actual.iter().any(|rec| {
rec.name == tu.name.clone()
&& rec.url == tu.url.clone()
rec.name == tu.name
&& rec.url == tu.url
&& group_match(&tu.group, &rec.group)
&& tags_match(&tu.tags, &rec.tags)
});
Expand Down

0 comments on commit 1ef5fd0

Please sign in to comment.