1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
#[cfg(not(feature = "std"))]
#[test]
fn test_errors_capacity() {
use num_format::utils::SeparatorStr;
use num_format::{CustomFormat, ErrorKind};
let s = "123456789";
match SeparatorStr::new(s) {
Ok(_) => panic!(),
Err(e) => match e.kind() {
ErrorKind::Capacity { len, cap } => {
assert_eq!(*len, 9);
assert_eq!(*cap, 8);
}
_ => panic!(),
},
}
match CustomFormat::builder().separator(s).build() {
Ok(_) => panic!(),
Err(e) => match e.kind() {
ErrorKind::Capacity { len, cap } => {
assert_eq!(*len, 9);
assert_eq!(*cap, 8);
}
_ => panic!(),
},
}
}
#[cfg(feature = "std")]
#[test]
fn test_errors_capacity() {
use num_format::utils::SeparatorStr;
use num_format::CustomFormat;
let s = "123456789";
match SeparatorStr::new(s) {
Ok(_) => panic!(),
Err(e) => assert_eq!(
"Attempted to write input of length 9 bytes into a buffer with capacity 8 bytes.",
&e.to_string(),
),
}
match CustomFormat::builder().separator(s).build() {
Ok(_) => panic!(),
Err(e) => assert_eq!(
"Attempted to write input of length 9 bytes into a buffer with capacity 8 bytes.",
&e.to_string(),
),
}
}
#[cfg(all(feature = "with-system-locale", any(unix, windows)))]
#[test]
fn test_errors_interior_null_byte() {
use std::str;
use num_format::SystemLocale;
let b = b"Hello\0World";
let s = str::from_utf8(&b[..]).unwrap();
match SystemLocale::from_name(s) {
Ok(_) => panic!(),
Err(e) => assert_eq!(
"Locale name Hello\u{0}World contains an interior nul byte, which is not allowed.",
&e.to_string()
),
}
}
#[cfg(not(feature = "std"))]
#[test]
fn test_errors_parse_locale() {
use num_format::{ErrorKind, Locale};
let s = "123456789";
match Locale::from_name(s) {
Ok(_) => panic!(),
Err(e) => match e.kind() {
ErrorKind::ParseLocale(array_string) => assert_eq!(s, array_string.as_str()),
_ => panic!(),
},
}
}
#[cfg(feature = "std")]
#[test]
fn test_errors_parse_locale() {
use num_format::Locale;
let s = "123456789";
match Locale::from_name(s) {
Ok(_) => panic!(),
Err(e) => assert_eq!(
"Failed to parse 123456789 into a valid locale.",
&e.to_string(),
),
}
}
#[cfg(all(feature = "with-system-locale", any(unix, windows)))]
#[test]
fn test_errors_parse_system_locale() {
use num_format::SystemLocale;
let s = "123456789";
match SystemLocale::from_name(s) {
Ok(_) => panic!(),
Err(e) => assert_eq!(
"Failed to parse 123456789 into a valid locale.",
&e.to_string(),
),
}
}
|