Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
quambene committed Mar 11, 2024
1 parent a26236b commit 2fdebcd
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/cmd/configure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,7 @@ fn configure_source_folders(source: &mut RawSource) -> Result<(), anyhow::Error>
let input = input.trim().to_lowercase();
match select_source_folders_from_input(&input) {
Ok(selected_fodlers) => {
break selected_fodlers
.into_iter()
.map(|folder| folder.to_owned())
.collect();
break selected_fodlers;

Check warning on line 174 in src/cmd/configure.rs

View check run for this annotation

Codecov / codecov/patch

src/cmd/configure.rs#L168-L174

Added lines #L168 - L174 were not covered by tests
}
Err(_) => {
println!("Invalid input. Please try again");
Expand All @@ -188,7 +185,7 @@ fn configure_source_folders(source: &mut RawSource) -> Result<(), anyhow::Error>
Ok(())
}

Check warning on line 186 in src/cmd/configure.rs

View check run for this annotation

Codecov / codecov/patch

src/cmd/configure.rs#L183-L186

Added lines #L183 - L186 were not covered by tests

fn select_source_folders_from_input(input: &str) -> Result<Vec<&str>, BogrepError> {
fn select_source_folders_from_input(input: &str) -> Result<Vec<String>, BogrepError> {
let choices: Vec<&str> = input.split_whitespace().collect();

if choices.is_empty() {
Expand All @@ -197,7 +194,10 @@ fn select_source_folders_from_input(input: &str) -> Result<Vec<&str>, BogrepErro
println!("Selected folders: {:?}", choices)
}

Ok(choices)
Ok(choices
.into_iter()
.map(|folder| folder.trim().to_owned())
.collect())
}

fn select_sources_from_input(
Expand Down Expand Up @@ -249,6 +249,18 @@ mod tests {
use super::*;
use std::{io::Cursor, path::PathBuf};

#[test]
fn test_select_source_folders_from_input() {
let selected_folders = select_source_folders_from_input("").unwrap();
assert_eq!(selected_folders, Vec::<String>::new());

let selected_folders = select_source_folders_from_input("dev science").unwrap();
assert_eq!(
selected_folders,
vec!["dev".to_owned(), "science".to_owned()]
);
}

#[test]
fn test_select_sources_from_input() {
let indexed_sources = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
Expand Down

0 comments on commit 2fdebcd

Please sign in to comment.