Skip to content

Commit b67f7ef

Browse files
committed
test: refactor
1 parent e21612e commit b67f7ef

File tree

1 file changed

+9
-59
lines changed

1 file changed

+9
-59
lines changed

src/menu/menu_functions.rs

Lines changed: 9 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -704,68 +704,22 @@ mod tests {
704704
assert_eq!(res, (1, "e"));
705705
}
706706

707-
#[test]
708-
fn find_common_string_with_ansi() {
709-
use crate::Span;
710-
711-
let input: Vec<_> = ["nushell", "null"]
712-
.into_iter()
713-
.map(|s| Suggestion {
714-
value: s.into(),
715-
description: None,
716-
style: None,
717-
extra: None,
718-
span: Span::new(0, s.len()),
719-
append_whitespace: false,
720-
..Default::default()
721-
})
722-
.collect();
723-
let res = find_common_string(&input);
724-
725-
assert!(matches!(res, (Some(elem), Some(2)) if elem == &input[0]));
726-
}
727-
728-
#[test]
729-
fn find_common_string_with_non_ansi() {
730-
use crate::Span;
731-
732-
let input: Vec<_> = ["nushell", "null"]
733-
.into_iter()
734-
.map(|s| Suggestion {
735-
value: s.into(),
736-
description: None,
737-
style: None,
738-
extra: None,
739-
span: Span::new(0, s.len()),
740-
append_whitespace: false,
741-
..Default::default()
742-
})
743-
.collect();
744-
let res = find_common_string(&input);
745-
746-
assert!(matches!(res, (Some(elem), Some(6)) if elem == &input[0]));
747-
}
748-
749-
#[test]
750-
fn find_common_string_with_unsorted() {
751-
use crate::Span;
752-
753-
// https://github.com/nushell/nushell/pull/16765#issuecomment-3384411809
754-
let input: Vec<_> = ["a", "b", "ab"]
707+
#[rstest]
708+
#[case::ascii(vec!["nushell", "null"], 2)]
709+
#[case::non_ascii(vec!["nushell", "null"], 6)]
710+
// https://github.com/nushell/nushell/pull/16765#issuecomment-3384411809
711+
#[case::unsorted(vec!["a", "b", "ab"], 0)]
712+
fn test_find_common_string(#[case] input: Vec<&str>, #[case] expected: usize) {
713+
let input: Vec<_> = input
755714
.into_iter()
756715
.map(|s| Suggestion {
757716
value: s.into(),
758-
description: None,
759-
style: None,
760-
extra: None,
761-
span: Span::new(0, s.len()),
762-
append_whitespace: false,
763717
..Default::default()
764718
})
765719
.collect();
766-
let (_, index) = find_common_string(&input);
720+
let (_, len) = find_common_string(&input);
767721

768-
assert!(index == Some(0));
722+
assert!(len == Some(expected));
769723
}
770724

771725
#[rstest]
@@ -811,11 +765,7 @@ mod tests {
811765
replace_in_buffer(
812766
Some(Suggestion {
813767
value,
814-
description: None,
815-
style: None,
816-
extra: None,
817768
span: Span::new(start, end),
818-
append_whitespace: false,
819769
..Default::default()
820770
}),
821771
&mut editor,

0 commit comments

Comments
 (0)