// 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. #[macro_use] extern crate clapme; use clapme::ClapMe; #[test] fn simple_generic() { #[derive(ClapMe, PartialEq, Debug)] struct GenericOpt { first: T, second: String, } println!("help: {}", >::help_message("foo")); assert!(>::help_message("foo").contains("--first")); assert!(>::help_message("foo").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(ClapMe, PartialEq, Debug)] struct GenericOpt { first: Option, second: String, } println!("help: {}", >::help_message("foo")); assert!(>::help_message("foo").contains("--first")); assert!(>::help_message("foo").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()); }