// 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. extern crate clapme; use clapme::ClapMe; #[test] fn simple_u64() { println!("help: {}", u64::help_message("foo")); assert!(!u64::help_message("foo").contains("--first")); assert_eq!(7, u64::from_iter(&["","7"]).unwrap()); assert_eq!(7, u64::from_iter(&["","7e0"]).unwrap()); assert_eq!(1000000, u64::from_iter(&["","1e6"]).unwrap()); assert!(u64::from_iter(&[""]).is_err()); assert!(u64::from_iter(&["hello"]).is_err()); } #[test] fn simple_string() { println!("help: {}", String::help_message("foo")); assert!(!String::help_message("foo").contains("--first")); assert_eq!("7".to_string(), String::from_iter(&["","7"]).unwrap()); assert!(String::from_iter(&[""]).is_err()); } #[test] fn simple_option_string() { println!("help: {}", >::help_message("foo")); assert!(!>::help_message("foo").contains("--first")); assert_eq!(Some("7".to_string()), >::from_iter(&["","7"]).unwrap()); assert_eq!(None, >::from_iter(&[""]).unwrap()); } #[test] fn simple_option_vec_i16() { println!("help: {}", >::help_message("vec")); assert!(!>::help_message("vec").contains("--first")); assert_eq!(vec![7], >::from_iter(&["","7"]).unwrap()); assert_eq!(Vec::::new(), >::from_iter(&[""]).unwrap()); } #[test] fn simple_f64_many_ways() { println!("help: {}", ::help_message("vec")); assert_eq!(0.3, ::from_iter(&["","0.3"]).unwrap()); assert_eq!(7.0, ::from_iter(&["","7"]).unwrap()); assert_eq!(1.0/3.0, ::from_iter(&["","1/3"]).unwrap()); assert_eq!(3.0_f64.sqrt(), ::from_iter(&["","sqrt(3)"]).unwrap()); assert_eq!(3.0_f64.sqrt(), ::from_iter(&["","3^(1/2)"]).unwrap()); assert_eq!(1e300, ::from_iter(&["","1e300"]).unwrap()); assert_eq!(1e300_f64.sqrt(), ::from_iter(&["","sqrt(1e300)"]).unwrap()); }