use std::error::Error;
use std::fmt;

#[derive(Debug)]
pub(crate) struct StringError(pub String);

impl fmt::Display for StringError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}", self.0)
    }
}

impl Error for StringError {}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn display_shows_inner_message() {
        let msg = "this is an error message".to_string();
        let err = StringError(msg.clone());
        let displayed = format!("{}", err);
        assert_eq!(displayed, msg);
    }

    #[test]
    fn debug_contains_struct_name_and_message() {
        let msg = "debug message".to_string();
        let err = StringError(msg.clone());
        let debug_str = format!("{:?}", err);
        // Should contain struct name and the inner message
        assert!(debug_str.contains("StringError"));
        assert!(debug_str.contains(&msg));
    }

    #[test]
    fn error_source_is_none() {
        let err = StringError("error".to_string());
        // SimpleError does not implement source, so should be None
        assert!(err.source().is_none());
    }
}
