2
0
Fork 0
mirror of https://github.com/clap-rs/clap synced 2024-12-14 23:02:31 +00:00
clap/tests/unicode.rs
2015-09-30 23:59:40 -04:00

30 lines
927 B
Rust

extern crate clap;
use std::ffi::OsString;
use std::os::unix::ffi::OsStringExt;
use clap::{App, Arg, ClapErrorType};
#[test]
fn invalid_unicode_safe() {
let m = App::new("bad_unicode")
.arg(Arg::from_usage("<arg> 'some arg'"))
.get_matches_from_safe(vec![OsString::from_vec(vec![0x20]),
OsString::from_vec(vec![0xe9])]);
assert!(m.is_err());
if let Err(e) = m {
assert_eq!(e.error_type, ClapErrorType::InvalidUnicode);
}
}
#[test]
fn invalid_unicode_lossy() {
if let Ok(m) = App::new("bad_unicode")
.arg(Arg::from_usage("<arg> 'some arg'"))
.get_matches_from_safe_lossy(vec![OsString::from_vec(vec![0x20]),
OsString::from_vec(vec![0xe9])]) {
assert!(m.is_present("arg"));
assert_eq!(m.value_of("arg").unwrap(), "\u{FFFD}");
} else {
panic!("FAILED")
}
}