Skip to content

Commit

Permalink
add tests for expand_range
Browse files Browse the repository at this point in the history
  • Loading branch information
jhspetersson committed Dec 26, 2024
1 parent 72e1803 commit c8d8735
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,4 +487,42 @@ pub fn success_message(message: String) -> bool {
pub fn error_message(message: String) -> bool {
eprintln!("{message}");
false
}

#[cfg(test)]
mod tests {
use super::ExpandRange;

#[test]
fn test_expand_range_single() {
let input = vec!["1".to_string()];
let expected: Vec<String> = vec!["1".to_string()];
let result: Vec<String> = input.into_iter().expand_range().collect();
assert_eq!(result, expected);
}

#[test]
fn test_expand_range_range() {
let input = vec!["1..3".to_string()];
let expected: Vec<String> = vec!["1".to_string(), "2".to_string(), "3".to_string()];
let result: Vec<String> = input.into_iter().expand_range().collect();
assert_eq!(result, expected);
}

#[test]
fn test_expand_range_mixed() {
let input = vec!["1".to_string(), "3..5".to_string(), "7".to_string()];
let expected: Vec<String> = vec!["1".to_string(), "3".to_string(), "4".to_string(), "5".to_string(), "7".to_string()];
let result: Vec<String> = input.into_iter().expand_range().collect();
assert_eq!(result, expected);
}

#[test]
fn test_expand_range_invalid_range() {
let input = vec!["1..x".to_string()];
let result: Result<Vec<String>, _> = std::panic::catch_unwind(|| {
input.into_iter().expand_range().collect::<Vec<String>>()
});
assert!(result.is_err());
}
}

0 comments on commit c8d8735

Please sign in to comment.