Files
Ely-GPUI-Components/src/terminal/tests.rs
T
ZacharyZhang-NYandClaude Opus 5.5 94deeaed52 Port · Build: Zed's gpui at 1a28cff
gpui and gpui_platform now come from Zed's repo by git at 1a28cff,
the code gpui-pre 0.3.7 republishes, so the gallery can later build
for the browser. gpui takes stacker, as 0.2.2 always did, and
gpui_platform takes font-kit, without which macOS draws no text;
runtime_shaders moves to gpui_platform.

The API moved: focus, blur and Tab steps take cx, Corner is Anchor,
shaped lines paint with an alignment, defer_draw takes a content
mask, the inspector registers a factory, async updates return their
value, and wrapped lines are shared, not cloned. Updates through a
window context go through the window, so a closed window still ends
them as it did.

Where the new gpui behaves differently, Ely keeps its old intent.
Holds and reveals under a resting pointer survive typing through
gpui's input-modality-independent hover; previews the keyboard also
moves keep the default, and the calendar's leave ignores a key press.
Enter reaches a button inside the code editor, since gpui now arms a
key click on the press. The event logger skips a lone modifier. A
video and an image grid keep their shape in a flex column under
taffy 0.13, as a picture does.

AGENTS.md records the new stack and the rules this port changes; the
rest of the old gpui and taffy rules are re-tested in T44c.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 20:30:17 -04:00

82 lines
2.7 KiB
Rust

use gpui::{Entity, TestAppContext, VisualTestContext};
use super::{Target, Terminal};
use crate::{editor::FindOptions, theme::Theme};
fn replayed<'a>(
bytes: &'static [u8],
cx: &'a mut TestAppContext,
) -> (Entity<Terminal>, &'a mut VisualTestContext) {
cx.update(Theme::init);
let (terminal, cx) = cx.add_window_view(move |_, cx| Terminal::replay(bytes, 30, 4, cx));
cx.run_until_parked();
(terminal, cx)
}
#[gpui::test]
fn replayed_output_shows_without_its_codes(cx: &mut TestAppContext) {
let (terminal, cx) = replayed(b"\x1b[32mok\x1b[0m done\r\n\x1b]0;build\x07next", cx);
terminal.read_with(cx, |terminal, _| {
assert_eq!(terminal.text(), "ok done\nnext");
assert_eq!(terminal.title().as_ref(), "build", "OSC 0 names it");
assert_eq!(terminal.shown.cursor, None, "a replay shows no cursor");
});
}
#[gpui::test]
fn find_counts_matches_and_steps_round(cx: &mut TestAppContext) {
let (terminal, cx) = replayed(b"one two one\r\nthree one", cx);
terminal.update(cx, |terminal, cx| {
assert_eq!(terminal.find("one", FindOptions::default(), cx), Ok(3));
assert_eq!(terminal.matches(), (3, Some(2)), "the newest match first");
terminal.step(true, cx);
assert_eq!(
terminal.matches(),
(3, Some(0)),
"past the last comes the first"
);
assert!(
terminal
.find(
"(",
FindOptions {
regex: true,
..FindOptions::default()
},
cx
)
.is_err()
);
});
}
#[gpui::test]
fn tab_reaches_the_terminal(cx: &mut TestAppContext) {
let (terminal, cx) = replayed(b"ok", cx);
let focused = cx.update(|window, cx| {
window.focus_next(cx);
terminal.read(cx).focus.is_focused(window)
});
assert!(focused);
}
#[gpui::test]
fn clearing_drops_the_matches(cx: &mut TestAppContext) {
let (terminal, cx) = replayed(b"one two one", cx);
terminal.update(cx, |terminal, cx| {
assert_eq!(terminal.find("one", FindOptions::default(), cx), Ok(2));
terminal.clear(cx);
assert_eq!(terminal.matches(), (0, None));
});
}
#[gpui::test]
fn a_link_keeps_its_combining_marks(cx: &mut TestAppContext) {
let (terminal, cx) = replayed("a https://e.dev/cafe\u{301}/x".as_bytes(), cx);
terminal.read_with(cx, |terminal, _| {
let (_, columns, target) = terminal.link_at(0, 10).expect("a link under column 10");
assert_eq!(columns, 2..22);
assert_eq!(target, Target::Url("https://e.dev/cafe\u{301}/x".into()));
});
}