#![cfg(feature = "mixer")]
#![cfg(feature = "cpal")]
use pikopiko::player::mixer::OutputError;
use pikopiko::text::InLang;
fn has_japanese(s: &str) -> bool {
s.chars()
.any(|c| matches!(c, '\u{3040}'..='\u{30ff}' | '\u{4e00}'..='\u{9fff}'))
}
#[test]
fn backend_errors_use_our_own_text_for_known_kinds() {
use cpal::ErrorKind as K;
for kind in [
K::DeviceBusy,
K::DeviceNotAvailable,
K::HostUnavailable,
K::PermissionDenied,
K::ResourceExhausted,
K::StreamInvalidated,
K::UnsupportedConfig,
K::UnsupportedOperation,
] {
let e = OutputError::Backend(cpal::Error::with_message(kind, "backend says hello"));
let en = InLang(&e, "en").to_string();
let ja = InLang(&e, "ja").to_string();
assert!(
!en.contains("hello") && !has_japanese(&en),
"{kind:?}: {en}"
);
assert!(!ja.contains("hello") && has_japanese(&ja), "{kind:?}: {ja}");
}
let e = OutputError::Backend(cpal::Error::with_message(K::Other, "backend says hello"));
assert!(InLang(&e, "ja").to_string().contains("hello"));
assert!(InLang(&e, "en")
.to_string()
.starts_with("Audio output error:"));
}