// Copyright 2018 David Roundy // // Licensed under the Apache License, Version 2.0 or the MIT license // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. use auto_args::AutoArgs; #[test] fn simple_generic() { #[derive(AutoArgs, PartialEq, Debug)] struct GenericOpt { first: T, second: String, } println!("help: {}", >::help()); assert!(>::help().contains("--first")); assert!(>::help().contains("--second")); assert_eq!( GenericOpt:: { first: 3, second: "hello".to_string() }, >::from_iter(&["", "--first", "3", "--second=hello"]).unwrap() ); assert!(>::from_iter(&[""]).is_err()); } #[test] fn optional_generic() { #[derive(AutoArgs, PartialEq, Debug)] struct GenericOpt { first: Option, second: String, } println!("help: {}", >::help()); assert!(>::help().contains("--first")); assert!(>::help().contains("--second")); assert_eq!( GenericOpt:: { first: Some(3), second: "hello".to_string() }, >::from_iter(&["", "--first", "3", "--second=hello"]).unwrap() ); assert_eq!( GenericOpt:: { first: None, second: "hello".to_string() }, >::from_iter(&["", "--second=hello"]).unwrap() ); assert!(>::from_iter(&[""]).is_err()); }