on master help sign in
use test terminal backend for integration tests
commit652cdda8338bee55eeff58066cd20e68bb0b5a44 authorSkyler Hawthorne <skyler@dead10ck.com> dateWed 27 Apr 2022, 00:07 (5 years ago) parented950fc
3 files changed+30−18
helix-term/src/application.rs+7−13 helix-term/src/commands.rs+4−4 helix-term/src/compositor.rs+19−1
helix-term/src/application.rs+7−13
@@ -216,21 +216,15 @@ impl Application {
216216 }
217217
218218 fn render(&mut self) {
219− #[cfg(feature = "integration")]
220− return;
221−
222− #[allow(unreachable_code)]
223− {
224− let compositor = &mut self.compositor;
219+ let compositor = &mut self.compositor;
225220
226− let mut cx = crate::compositor::Context {
227− editor: &mut self.editor,
228− jobs: &mut self.jobs,
229− scroll: None,
230− };
221+ let mut cx = crate::compositor::Context {
222+ editor: &mut self.editor,
223+ jobs: &mut self.jobs,
224+ scroll: None,
225+ };
231226
232− compositor.render(&mut cx);
233− }
227+ compositor.render(&mut cx);
234228 }
235229
236230 pub async fn event_loop<S>(&mut self, input_stream: &mut S)
helix-term/src/commands.rs+4−4
@@ -2100,10 +2100,10 @@ fn insert_mode(cx: &mut Context) {
21002100 doc.text().to_string()
21012101 );
21022102
2103− let selection = doc.selection(view.id).clone().transform(|range| {
2104− let new_range = Range::new(range.to(), range.from());
2105− new_range
2106− });
2103+ let selection = doc
2104+ .selection(view.id)
2105+ .clone()
2106+ .transform(|range| Range::new(range.to(), range.from()));
21072107
21082108 doc.set_selection(view.id, selection);
21092109}
helix-term/src/compositor.rs+19−1
@@ -5,6 +5,9 @@ use helix_core::Position;
55use helix_view::graphics::{CursorKind, Rect};
66
77use crossterm::event::Event;
8+
9+#[cfg(feature = "integration")]
10+use tui::backend::TestBackend;
811use tui::buffer::Buffer as Surface;
912
1013pub type Callback = Box<dyn FnOnce(&mut Compositor, &mut Context)>;
@@ -64,10 +67,20 @@ pub trait Component: Any + AnyComponent {
6467}
6568
6669use anyhow::Context as AnyhowContext;
70+use tui::backend::Backend;
71+
72+#[cfg(not(feature = "integration"))]
73+use tui::backend::CrosstermBackend;
74+
75+#[cfg(not(feature = "integration"))]
6776use std::io::stdout;
68−use tui::backend::{Backend, CrosstermBackend};
77+
78+#[cfg(not(feature = "integration"))]
6979type Terminal = tui::terminal::Terminal<CrosstermBackend<std::io::Stdout>>;
7080
81+#[cfg(feature = "integration")]
82+type Terminal = tui::terminal::Terminal<TestBackend>;
83+
7184pub struct Compositor {
7285 layers: Vec<Box<dyn Component>>,
7386 terminal: Terminal,
@@ -77,7 +90,12 @@ pub struct Compositor {
7790
7891impl Compositor {
7992 pub fn new() -> anyhow::Result<Self> {
93+ #[cfg(not(feature = "integration"))]
8094 let backend = CrosstermBackend::new(stdout());
95+
96+ #[cfg(feature = "integration")]
97+ let backend = TestBackend::new(120, 150);
98+
8199 let terminal = Terminal::new(backend).context("build terminal")?;
82100 Ok(Self {
83101 layers: Vec::new(),