use std::fmt;
use std::sync::Arc;
use clawless_core::event::Artifact;
#[derive(Clone, Debug)]
pub enum Entry {
Message(String),
Detail(String),
Artifact(Arc<dyn Artifact>),
}
impl fmt::Display for Entry {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Entry::Message(text) => f.write_str(text),
Entry::Detail(text) => f.write_str(text),
Entry::Artifact(artifact) => fmt::Display::fmt(artifact, f),
}
}
}
#[cfg(test)]
mod tests {
#![allow(clippy::missing_panics_doc)]
use std::sync::Arc;
use serde::Serialize;
use super::*;
#[derive(Clone, Debug, Serialize)]
struct TestArtifact {
value: String,
}
impl fmt::Display for TestArtifact {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.value)
}
}
fn test_artifact() -> TestArtifact {
TestArtifact {
value: "result".to_string(),
}
}
#[test]
fn clone_detail_produces_equal_value() {
let entry = Entry::Detail("info".to_string());
let cloned = entry.clone();
let Entry::Detail(s) = &cloned else {
panic!("expected Entry::Detail");
};
assert_eq!(s, "info");
}
#[test]
fn clone_message_produces_equal_value() {
let entry = Entry::Message("hello".to_string());
let cloned = entry.clone();
let Entry::Message(s) = &cloned else {
panic!("expected Entry::Message");
};
assert_eq!(s, "hello");
}
#[test]
fn display_artifact_renders_via_display_trait() {
let entry = Entry::Artifact(Arc::new(test_artifact()));
let text = entry.to_string();
assert_eq!(text, "result");
}
#[test]
fn display_detail_renders_text() {
let entry = Entry::Detail("info".to_string());
let text = entry.to_string();
assert_eq!(text, "info");
}
#[test]
fn display_message_renders_text() {
let entry = Entry::Message("hello".to_string());
let text = entry.to_string();
assert_eq!(text, "hello");
}
#[test]
fn trait_send() {
fn assert_send<T: Send>() {}
assert_send::<Entry>();
}
#[test]
fn trait_sync() {
fn assert_sync<T: Sync>() {}
assert_sync::<Entry>();
}
#[test]
fn trait_unpin() {
fn assert_unpin<T: Unpin>() {}
assert_unpin::<Entry>();
}
}