tastty-core 0.1.0

Sans-IO core of the tastty terminal session library: VT parser, screen buffer, and byte encoders.
use super::*;

#[test]
fn osc_9_emits_desktop_notification_with_empty_title() {
    let mut parser = crate::Parser::new(TerminalSize { rows: 24, cols: 80 }, 0);
    process(&mut parser, b"\x1b]9;hello\x07");
    let events = parser.screen_mut().drain_events();
    assert!(
        events.contains(&ScreenEvent::DesktopNotification {
            title: String::new(),
            body: "hello".to_string(),
        }),
        "expected DesktopNotification event, got {events:?}",
    );
}

#[test]
fn osc_9_with_empty_body_is_silent() {
    let mut parser = crate::Parser::new(TerminalSize { rows: 24, cols: 80 }, 0);
    process(&mut parser, b"\x1b]9;\x07");
    let events = parser.screen_mut().drain_events();
    assert!(
        events
            .iter()
            .all(|e| !matches!(e, ScreenEvent::DesktopNotification { .. })),
        "no DesktopNotification expected, got {events:?}",
    );
}

#[test]
fn osc_777_notify_emits_desktop_notification() {
    let mut parser = crate::Parser::new(TerminalSize { rows: 24, cols: 80 }, 0);
    process(&mut parser, b"\x1b]777;notify;Build done;Tests passed\x07");
    let events = parser.screen_mut().drain_events();
    assert!(
        events.contains(&ScreenEvent::DesktopNotification {
            title: "Build done".to_string(),
            body: "Tests passed".to_string(),
        }),
        "expected DesktopNotification event, got {events:?}",
    );
}

#[test]
fn osc_777_non_notify_is_ignored() {
    let mut parser = crate::Parser::new(TerminalSize { rows: 24, cols: 80 }, 0);
    process(&mut parser, b"\x1b]777;something_else;arg\x07");
    let events = parser.screen_mut().drain_events();
    assert!(
        events
            .iter()
            .all(|e| !matches!(e, ScreenEvent::DesktopNotification { .. })),
        "no DesktopNotification expected, got {events:?}",
    );
}

#[test]
fn osc_777_notify_empty_body_emits() {
    let mut parser = crate::Parser::new(TerminalSize { rows: 24, cols: 80 }, 0);
    process(&mut parser, b"\x1b]777;notify;Title only;\x07");
    let events = parser.screen_mut().drain_events();
    assert!(
        events.contains(&ScreenEvent::DesktopNotification {
            title: "Title only".to_string(),
            body: String::new(),
        }),
        "expected DesktopNotification event, got {events:?}",
    );
}