/* * Copyright (c) Radim Kolar 2013, 2018, 2023. * SPDX-License-Identifier: MIT * * getopt3 library is licensed under MIT license: * https://spdx.org/licenses/MIT.html */ #![allow(non_snake_case)] mod Example; use getopt3::getopt; use rstest::{fixture, rstest}; macro_rules! to_vec { ($arr:expr) => {{ let vec: Vec = $arr.iter().map(|&s| s.to_string()).collect(); vec }}; } // Example spec use Example::Example; #[fixture] fn main() -> getopt { Example(to_vec!(["one", "-a", "two", "-b", "arg", "-d"])) } #[test] fn real_invoke_main() { Example(to_vec!(["one", "-a", "two", "-b", "arg", "-d"])); } #[rstest] fn real_two_arguments(main: getopt) { assert_eq!(main.arguments.len(), 2); assert_eq!(main.arguments, ["one", "two"]); } #[rstest] fn real_a_option_without_arg(main: getopt) { assert_eq!(main.options.get(&'a'), Some(&"".to_string())); } #[rstest] fn real_should_have_b_option_with_argument(main: getopt) { assert_eq!(main.options.get(&'b'), Some(&"arg".to_string())); } #[rstest] fn real_should_not_have_c_option(main: getopt) { assert_eq!(main.options.get(&'c'), None); } #[rstest] fn real_should_have_unknown_d_option(main: getopt) { assert_eq!(main.options.get(&'d'), Some(&"".to_string())); }