\n"), "{}", text); } /// Multiple positionals render as "[a] [b]" in the usage line. #[test] fn print_help_multiple_positionals() { let mut p = CommandLineParser::new(); p.add_positional_argument("in", "", true).unwrap(); p.add_positional_argument("out", "", false).unwrap(); let mut buf = Vec::new(); p.write_help(&mut buf, "oak").unwrap(); let text = String::from_utf8(buf).unwrap(); assert!( text.contains("Usage: oak [options] [in] [out]\n"), "{}", text ); } /// Hidden options are omitted from help but still parse. #[test] fn hidden_option_parses_but_hidden_from_help() { let mut p = CommandLineParser::new(); p.add_option(&[cstr("secret")], "shh", false, "", true) .unwrap(); let mut buf = Vec::new(); p.write_help(&mut buf, "oak").unwrap(); let text = String::from_utf8(buf).unwrap(); assert!(!text.contains("secret"), "{}", text); p.process(&[cstr("p"), cstr("-secret")]).unwrap(); assert!(p.option(0).unwrap().is_set()); } /// Out-of-range index accessors return None. #[test] fn index_accessors_out_of_range() { let p = CommandLineParser::new(); assert!(p.option(0).is_none()); assert!(p.positional(0).is_none()); } /// add_option with zero names registers an option that can never /// match (the C++ ABI layer rejects name_count == 0 before reaching /// the domain type). #[test] fn add_option_empty_names_never_matches() { let mut p = CommandLineParser::new(); p.add_option(&[], "no names", false, "", false).unwrap(); assert_eq!(p.option_count(), 1); p.process(&[cstr("p"), cstr("-anything")]).unwrap(); assert!(!p.option(0).unwrap().is_set()); } }