use getopt::{get_opts, get_opts_from_tokens}; use parse::NdRule; use tests::get_nodes; use crate::builtin::echo::ECHO_OPTS; use super::super::*; #[test] fn getopt_from_argv() { let node = get_nodes("echo -n -e foo", |node| { matches!(node.class, NdRule::Command { .. }) }) .pop() .unwrap(); let NdRule::Command { assignments: _, argv, } = node.class else { panic!() }; let (words, opts) = get_opts_from_tokens(argv, &ECHO_OPTS).expect("failed to get opts"); insta::assert_debug_snapshot!(words); insta::assert_debug_snapshot!(opts) } #[test] fn getopt_simple() { let raw = "echo -n foo" .split_whitespace() .map(|s| s.to_string()) .collect::>(); let (words, opts) = get_opts(raw); insta::assert_debug_snapshot!(words); insta::assert_debug_snapshot!(opts); } #[test] fn getopt_multiple_short() { let raw = "echo -nre foo" .split_whitespace() .map(|s| s.to_string()) .collect::>(); let (words, opts) = get_opts(raw); insta::assert_debug_snapshot!(words); insta::assert_debug_snapshot!(opts); }