From ca75cd7c0a760d963c33a592492fe299d2ee3750 Mon Sep 17 00:00:00 2001 From: Herlon Aguiar Date: Sat, 7 May 2022 22:19:48 +0200 Subject: [PATCH] nu-cli/completions: add tests for flag completions (#5468) --- crates/nu-cli/tests/test_completions.rs | 34 +++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/crates/nu-cli/tests/test_completions.rs b/crates/nu-cli/tests/test_completions.rs index 7ea7b1c93a..ec56a9779c 100644 --- a/crates/nu-cli/tests/test_completions.rs +++ b/crates/nu-cli/tests/test_completions.rs @@ -7,6 +7,40 @@ use nu_test_support::fs; use reedline::{Completer, Suggestion}; const SEP: char = std::path::MAIN_SEPARATOR; +#[test] +fn flag_completions() { + // Create a new engine + let (_, _, engine) = new_engine(); + + let stack = Stack::new(); + + // Instatiate a new completer + let mut completer = NuCompleter::new(std::sync::Arc::new(engine), stack); + + // Test completions for the 'ls' flags + let suggestions = completer.complete("ls -".into(), 4); + + assert_eq!(12, suggestions.len()); + + let expected: Vec = vec![ + "--all".into(), + "--du".into(), + "--full-paths".into(), + "--help".into(), + "--long".into(), + "--short-names".into(), + "-a".into(), + "-d".into(), + "-f".into(), + "-h".into(), + "-l".into(), + "-s".into(), + ]; + + // Match results + match_suggestions(expected, suggestions); +} + #[test] fn file_completions() { // Create a new engine