pikopiko 0.1.0

MML parser, compiler and chiptune player for games, with diagnostics designed for tools and AI.
Documentation
//! 出力のエラーの文は選んだ言語だけで書き、種類の決まった cpal のエラーに cpal の文(英語)を混ぜない。
#![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}");
    }
    // 種類の決まらないエラーは、決まった文に cpal の文を添える
    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:"));
}