use justerm_core::Engine;
#[test]
fn mode_47_switches_to_the_alt_buffer_and_back() {
let mut t = Engine::new(5, 2);
t.feed(b"P"); t.feed(b"\x1b[?47h"); assert_eq!(t.grid().cell(0, 0).c(), ' ', "alt buffer is blank");
t.feed(b"\x1b[?47l"); assert_eq!(t.grid().cell(0, 0).c(), 'P', "primary content restored");
}
#[test]
fn mode_1047_switches_like_47() {
let mut t = Engine::new(5, 2);
t.feed(b"P");
t.feed(b"\x1b[?1047h");
assert_eq!(t.grid().cell(0, 0).c(), ' ');
t.feed(b"\x1b[?1047l");
assert_eq!(t.grid().cell(0, 0).c(), 'P');
}
#[test]
fn mode_47_does_not_save_or_restore_the_cursor() {
let mut t = Engine::new(10, 2);
t.feed(b"\x1b[1;5H"); t.feed(b"\x1b[?47h"); t.feed(b"\x1b[2;1H"); t.feed(b"\x1b[?47l"); t.feed(b"X"); assert_eq!(t.grid().cell(1, 0).c(), 'X');
assert_eq!(t.grid().cell(0, 4).c(), ' ');
}
#[test]
fn mode_1048_saves_and_restores_cursor_without_switching() {
let mut t = Engine::new(10, 2);
t.feed(b"\x1b[1;5H"); t.feed(b"\x1b[?1048h"); t.feed(b"\x1b[2;1HP"); t.feed(b"\x1b[?1048l"); t.feed(b"X");
assert_eq!(
t.grid().cell(0, 4).c(),
'X',
"cursor restored to saved position"
);
assert_eq!(
t.grid().cell(1, 0).c(),
'P',
"no buffer switch — content stays"
);
}
#[test]
fn mode_1049_still_saves_and_restores_the_cursor() {
let mut t = Engine::new(10, 2);
t.feed(b"\x1b[1;5H"); t.feed(b"\x1b[?1049h"); t.feed(b"\x1b[2;1H"); t.feed(b"\x1b[?1049l"); t.feed(b"X");
assert_eq!(t.grid().cell(0, 4).c(), 'X');
}
#[test]
fn decrqm_reports_alt_buffer_for_47_and_1047() {
let mut t = Engine::new(10, 2);
t.feed(b"\x1b[?47$p"); assert_eq!(t.drain_replies(), b"\x1b[?47;2$y");
t.feed(b"\x1b[?47h\x1b[?1047$p"); assert_eq!(t.drain_replies(), b"\x1b[?1047;1$y");
}
#[test]
fn frame_reports_alt_screen_state() {
let mut t = Engine::new(5, 2);
assert!(!t.frame().alt_screen, "primary screen at start");
t.feed(b"\x1b[?1049h");
assert!(t.frame().alt_screen, "alt after ?1049h");
t.feed(b"\x1b[?1049l");
assert!(!t.frame().alt_screen, "primary after ?1049l");
t.feed(b"\x1b[?47h");
assert!(t.frame().alt_screen, "alt after ?47h");
t.feed(b"\x1b[?47l");
assert!(!t.frame().alt_screen, "primary after ?47l");
t.feed(b"\x1b[?1047h");
assert!(t.frame().alt_screen, "alt after ?1047h");
t.feed(b"\x1b[?1047l");
assert!(!t.frame().alt_screen, "primary after ?1047l");
}
#[test]
fn frame_alt_screen_ignores_cursor_only_1048() {
let mut t = Engine::new(5, 2);
t.feed(b"\x1b[?1048h"); assert!(!t.frame().alt_screen, "?1048h is cursor-only");
t.feed(b"\x1b[?1048l");
assert!(!t.frame().alt_screen, "?1048l is cursor-only");
}
#[test]
fn frame_alt_screen_cleared_by_ris() {
let mut t = Engine::new(5, 2);
t.feed(b"\x1b[?1049h");
assert!(t.frame().alt_screen);
t.feed(b"\x1bc"); assert!(!t.frame().alt_screen, "RIS returns to primary");
}