use std::ops::Deref; use glib::*; // FIXME all .get::() should be replaced with .get(); the compiler is totally able to infer the type itself. // But somehow without some tests are failing on Windows because the type inference doesn't work or something. // Test that `ToValue` (and conversely, `FromValue`) uphold the promised invariants #[test] pub fn to_value_invariants() { // Inverse assert_eq!(0i32, 0i32.to_value().get::().unwrap()); assert_eq!(0i32, 0i32.to_value().get::().unwrap()); // Idempotence assert_eq!( &0i32.to_value().type_(), &0i32.to_value().to_value().type_() ); assert_eq!(0i32, 0i32.to_value().to_value().get::().unwrap()); assert_eq!( 0i32, 0i32.to_value() .get::() .unwrap() .get::() .unwrap() ); assert_eq!( 0i32, 0i32.to_value() .get::() .unwrap() .get::() .unwrap() ); } // Test that `ToValue` and `FromValue` handle nexted boxed values correctly (as per the documentation) #[test] pub fn to_value_boxed() { let x = 0i32.to_value(); let boxed = BoxedValue(x); assert_eq!( 0i32, boxed .to_value() .to_value() .get::() .unwrap() .deref() .get::() .unwrap() ); assert_eq!( 0i32, boxed .to_value() .get::() .unwrap() .get::() .unwrap() .deref() .get::() .unwrap() ); }