structure::tests: use error constructors

This commit is contained in:
François Laignel 2019-08-16 15:04:01 +02:00
parent f050750b5e
commit 26423a069c

View file

@ -753,6 +753,8 @@ mod tests {
#[test] #[test]
fn new_set_get() { fn new_set_get() {
use glib::{value, Type};
::init().unwrap(); ::init().unwrap();
let mut s = Structure::new_empty("test"); let mut s = Structure::new_empty("test");
@ -770,37 +772,28 @@ mod tests {
assert_eq!(s.get_optional::<i32>("f3"), Ok(Some(123i32))); assert_eq!(s.get_optional::<i32>("f3"), Ok(Some(123i32)));
assert_eq!(s.get_optional::<i32>("f4"), Ok(None)); assert_eq!(s.get_optional::<i32>("f4"), Ok(None));
// FIXME: use a proper `assert_eq!`, but that requires assert_eq!(
// `glib::value::GetError fields to be public s.get::<i32>("f2"),
// See https://github.com/gtk-rs/glib/issues/515 Err(GetError::from_value_get_error(
match s.get::<i32>("f2") { "f2",
Err(GetError::ValueGetError { name, .. }) if name == "f2" => (), value::GetError::new_type_mismatch(Type::String, Type::I32),
res => panic!( ))
"Expected GetError::ValueGetError{{ \"f2\", .. }} found {:?}", );
res assert_eq!(
), s.get_some::<bool>("f3"),
} Err(GetError::from_value_get_error(
match s.get_some::<bool>("f3") { "f3",
Err(GetError::ValueGetError { name, .. }) if name == "f3" => (), value::GetError::new_type_mismatch(Type::I32, Type::Bool),
res => panic!( ))
"Expected GetError::ValueGetError{{ \"f3\", .. }} found {:?}", );
res assert_eq!(
), s.get::<&str>("f4"),
} Err(GetError::new_field_not_found("f4"))
match s.get::<&str>("f4") { );
Err(GetError::FieldNotFound { name }) if name == "f4" => (), assert_eq!(
res => panic!( s.get_some::<i32>("f4"),
"Expected GetError::FieldNotFound{{ \"f4\" }} found {:?}", Err(GetError::new_field_not_found("f4"))
res );
),
}
match s.get_some::<i32>("f4") {
Err(GetError::FieldNotFound { name }) if name == "f4" => (),
res => panic!(
"Expected GetError::FieldNotFound{{ \"f4\" }} found {:?}",
res
),
}
assert_eq!(s.fields().collect::<Vec<_>>(), vec!["f1", "f2", "f3"]); assert_eq!(s.fields().collect::<Vec<_>>(), vec!["f1", "f2", "f3"]);