mod types;
pub use types::{catch_panic, ErrorId, RwError, RwResult};
pub mod ffi;
pub use ffi::{c_try_fallback, CAbiSafe};
#[cfg(test)]
mod tests {
use super::*;
use crate::compat::MiniToString;
#[test]
fn rw_error_display() {
let e = RwError::msg("test error");
assert!(e.to_string().contains("test"));
}
#[test]
fn rw_error_not_implemented() {
let e = RwError::not_implemented("feature");
assert!(e.to_string().contains("not implemented"));
assert!(e.to_string().contains("feature"));
}
#[test]
fn rw_error_msg_not_success() {
let e = RwError::msg("test");
assert_ne!(e.id, ErrorId::SUCCESS);
}
#[test]
fn ew_error_alias_values_match() {
assert_eq!(ErrorId::EW_SUCCESS.0, ErrorId::SUCCESS.0);
assert_eq!(ErrorId::EW_INVALID_ARGUMENT.0, ErrorId::INVALID_ARGUMENT.0);
assert_eq!(ErrorId::EW_FILE_NOT_FOUND.0, ErrorId::FILE_NOT_FOUND.0);
}
#[test]
fn rw_error_display_prefix_uses_ew() {
let err = RwError::new(ErrorId::INVALID_ARGUMENT, "bad input");
assert!(err.to_string().starts_with("[EW-"));
}
#[test]
fn a_converted_core_error_keeps_its_cause_in_the_source_chain() {
use core::error::Error;
let err = RwError::from(crate::core::CoreError::NotSupported("no GPU".to_string()));
assert_eq!(err.id, ErrorId::UNSUPPORTED_OPERATION);
let cause = err.source().expect("the converted CoreError must be the source");
assert!(cause.to_string().contains("no GPU"));
}
#[test]
fn an_error_built_from_an_id_has_no_source() {
use core::error::Error;
assert!(RwError::new(ErrorId::INVALID_ARGUMENT, "x").source().is_none());
}
#[test]
fn an_internal_core_error_round_trips_as_internal() {
let err = RwError::from(crate::core::CoreError::Internal("boom".to_string()));
assert_eq!(err.id, ErrorId::GENERAL, "internal is not \"not implemented\"");
assert!(matches!(crate::core::CoreError::from(err), crate::core::CoreError::Internal(_)));
}
}