on master help sign in
use test terminal backend for integration tests
652cddaSkyler Hawthorne
helix-term/src/application.rs+7−13
@@ -216,21 +216,15 @@ impl Application {
216 }
216 }
217
217
218 fn render(&mut self) {
218 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;
225
220
226− let mut cx = crate::compositor::Context {
221+ let mut cx = crate::compositor::Context {
227− editor: &mut self.editor,
222+ editor: &mut self.editor,
228− jobs: &mut self.jobs,
223+ jobs: &mut self.jobs,
229− scroll: None,
224+ scroll: None,
230− };
225+ };
231
226
232− compositor.render(&mut cx);
227+ compositor.render(&mut cx);
233− }
234 }
228 }
235
229
236 pub async fn event_loop<S>(&mut self, input_stream: &mut S)
230 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) {
2100 doc.text().to_string()
2100 doc.text().to_string()
2101 );
2101 );
2102
2102
2103− let selection = doc.selection(view.id).clone().transform(|range| {
2103+ let selection = doc
2104+ .selection(view.id)
2105+ .clone()
2104− let new_range = Range::new(range.to(), range.from());
2106+ .transform(|range| Range::new(range.to(), range.from()));
2105− new_range
2106− });
2107
2107
2108 doc.set_selection(view.id, selection);
2108 doc.set_selection(view.id, selection);
2109}
2109}
helix-term/src/compositor.rs+19−1
@@ -5,6 +5,9 @@ use helix_core::Position;
5use helix_view::graphics::{CursorKind, Rect};
5use helix_view::graphics::{CursorKind, Rect};
6
6
7use crossterm::event::Event;
7use crossterm::event::Event;
8+
9+#[cfg(feature = "integration")]
10+use tui::backend::TestBackend;
8use tui::buffer::Buffer as Surface;
11use tui::buffer::Buffer as Surface;
9
12
10pub type Callback = Box<dyn FnOnce(&mut Compositor, &mut Context)>;
13pub type Callback = Box<dyn FnOnce(&mut Compositor, &mut Context)>;
@@ -64,10 +67,20 @@ pub trait Component: Any + AnyComponent {
64}
67}
65
68
66use anyhow::Context as AnyhowContext;
69use 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"))]
67use std::io::stdout;
76use std::io::stdout;
68−use tui::backend::{Backend, CrosstermBackend};
77+
78+#[cfg(not(feature = "integration"))]
69type Terminal = tui::terminal::Terminal<CrosstermBackend<std::io::Stdout>>;
79type Terminal = tui::terminal::Terminal<CrosstermBackend<std::io::Stdout>>;
70
80
81+#[cfg(feature = "integration")]
82+type Terminal = tui::terminal::Terminal<TestBackend>;
83+
71pub struct Compositor {
84pub struct Compositor {
72 layers: Vec<Box<dyn Component>>,
85 layers: Vec<Box<dyn Component>>,
73 terminal: Terminal,
86 terminal: Terminal,
@@ -77,7 +90,12 @@ pub struct Compositor {
77
90
78impl Compositor {
91impl Compositor {
79 pub fn new() -> anyhow::Result<Self> {
92 pub fn new() -> anyhow::Result<Self> {
93+ #[cfg(not(feature = "integration"))]
80 let backend = CrosstermBackend::new(stdout());
94 let backend = CrosstermBackend::new(stdout());
95+
96+ #[cfg(feature = "integration")]
97+ let backend = TestBackend::new(120, 150);
98+
81 let terminal = Terminal::new(backend).context("build terminal")?;
99 let terminal = Terminal::new(backend).context("build terminal")?;
82 Ok(Self {
100 Ok(Self {
83 layers: Vec::new(),
101 layers: Vec::new(),