fn test_argsiter()

in src/compiler/args.rs [938:1017]


    fn test_argsiter() {
        ArgData! {
            Bar,
            Foo(OsString),
            Fuga,
            Hoge(PathBuf),
            Plop,
            Qux(OsString),
            Zorglub,
        }

        // Need to explicitly refer to enum because `use` doesn't work if it's in a module
        // https://internals.rust-lang.org/t/pre-rfc-support-use-enum-for-function-local-enums/3853/13
        static ARGS: [ArgInfo<ArgData>; 7] = [
            flag!("-bar", ArgData::Bar),
            take_arg!("-foo", OsString, Separated, ArgData::Foo),
            flag!("-fuga", ArgData::Fuga),
            take_arg!("-hoge", PathBuf, Concatenated, ArgData::Hoge),
            flag!("-plop", ArgData::Plop),
            take_arg!("-qux", OsString, CanBeSeparated('='), ArgData::Qux),
            flag!("-zorglub", ArgData::Zorglub),
        ];

        let args = [
            "-nomatch",
            "-foo",
            "value",
            "-hoge",
            "value",       // -hoge doesn't take a separate value
            "-hoge=value", // = is not recognized as a separator
            "-hogevalue",
            "-zorglub",
            "-qux",
            "value",
            "-plop",
            "-quxbar", // -quxbar is not -qux with a value of bar
            "-qux=value",
            "--",
            "non_flag",
            "-flag-after-double-dashes",
        ];
        let iter = ArgsIter::new(args.iter().map(OsString::from), &ARGS[..]).with_double_dashes();
        let expected = vec![
            arg!(UnknownFlag("-nomatch")),
            arg!(WithValue("-foo", ArgData::Foo("value"), Separated)),
            arg!(WithValue("-hoge", ArgData::Hoge(""), Concatenated)),
            arg!(Raw("value")),
            arg!(WithValue("-hoge", ArgData::Hoge("=value"), Concatenated)),
            arg!(WithValue("-hoge", ArgData::Hoge("value"), Concatenated)),
            arg!(Flag("-zorglub", ArgData::Zorglub)),
            arg!(WithValue(
                "-qux",
                ArgData::Qux("value"),
                CanBeConcatenated('=')
            )),
            arg!(Flag("-plop", ArgData::Plop)),
            arg!(UnknownFlag("-quxbar")),
            arg!(WithValue(
                "-qux",
                ArgData::Qux("value"),
                CanBeSeparated('=')
            )),
            arg!(Raw("--")),
            arg!(Raw("non_flag")),
            arg!(Raw("-flag-after-double-dashes")),
        ];
        match diff_with(iter, expected, |a, b| {
            assert_eq!(a.as_ref().unwrap(), b);
            true
        }) {
            None => {}
            Some(Diff::FirstMismatch(_, _, _)) => unreachable!(),
            Some(Diff::Shorter(_, i)) => {
                assert_eq!(i.map(|a| a.unwrap()).collect::<Vec<_>>(), vec![])
            }
            Some(Diff::Longer(_, i)) => {
                assert_eq!(Vec::<Argument<ArgData>>::new(), i.collect::<Vec<_>>())
            }
        }
    }