#![deny(warnings)]
mod other {
#[derive(Debug, PartialEq)]
pub struct Error(pub &'static str);
pub type Result<T> = std::result::Result<T, Error>;
}
use other::*;
use oxijolt::*;
fn other_call(fail: bool) -> Result<u32> {
if fail {
let error: Error = Error("refused");
Err(error)
} else {
Ok(1)
}
}
#[test]
fn the_crate_root_leaves_result_and_error_to_other_globs() {
assert_eq!(other_call(true), Err(Error("refused")));
assert_eq!(other_call(false), Ok(1));
let world = PhysicsWorld::new(WorldSettings::default()).unwrap();
assert!(world.active_body_poses().is_empty());
}
#[test]
fn the_crate_wide_result_is_named_by_the_error_module() -> oxijolt::error::Result<()> {
let shape = Shape::new_sphere(0.5)?;
let mut world = PhysicsWorld::new(WorldSettings::default())?;
world.create_body(&shape, &BodySettings::new_dynamic())?;
let error: oxijolt::error::Error = world.step(0.0).unwrap_err().into();
assert_eq!(
error,
oxijolt::error::Error::Step(StepError::InvalidDeltaTime)
);
Ok(())
}
#[test]
fn the_vehicle_kinds_are_named_at_the_root() {
let kinds: [(Option<VehicleId<WheeledVehicle>>, VehicleType); 3] = [
(None, VehicleType::Wheeled),
(None, VehicleType::Tracked),
(None, VehicleType::Motorcycle),
];
let typed: [Option<VehicleId<TrackedVehicle>>; 1] = [None];
let any: Option<AnyVehicleId> = typed[0].map(AnyVehicleId::from);
assert!(any.is_none());
assert_eq!(kinds.len(), 3);
let _: Option<VehicleId<Motorcycle>> = any.and_then(AnyVehicleId::downcast);
}