Tests: simplify access to cursor position
diff --git a/src/edit.rs b/src/edit.rs
index 0cce2b6..7dae766 100644
--- a/src/edit.rs
+++ b/src/edit.rs
@@ -22,7 +22,7 @@
prompt: &'prompt str, // Prompt to display (rl_prompt)
prompt_size: Position, // Prompt Unicode/visible width and height
pub line: LineBuffer, // Edited line buffer
- cursor: Position, /* Cursor position (relative to the start of the prompt
+ pub cursor: Position, /* Cursor position (relative to the start of the prompt
* for `row`) */
pub old_rows: usize, // Number of rows used so far (from start of prompt to end of input)
history_index: usize, // The history index we are currently editing
diff --git a/src/lib.rs b/src/lib.rs
index 8f8a061..d2ce92b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -488,6 +488,10 @@
},
// TODO CTRL-_ // undo
Cmd::AcceptLine => {
+ #[cfg(test)]
+ {
+ editor.term.cursor = s.cursor.col;
+ }
// Accept the line regardless of where the cursor is.
try!(s.edit_move_end());
if s.hinter.is_some() {
diff --git a/src/test/common.rs b/src/test/common.rs
index 8205bc2..1dd52ad 100644
--- a/src/test/common.rs
+++ b/src/test/common.rs
@@ -11,7 +11,7 @@
#[test]
fn end_key() {
assert_cursor(("", ""), &[KeyPress::End, KeyPress::Enter], 0);
- //assert_cursor(("H", "i"), &[KeyPress::End, KeyPress::Enter], 2); FIXME
+ assert_cursor(("H", "i"), &[KeyPress::End, KeyPress::Enter], 2);
}
#[test]
diff --git a/src/test/mod.rs b/src/test/mod.rs
index b741868..10c0752 100644
--- a/src/test/mod.rs
+++ b/src/test/mod.rs
@@ -59,7 +59,7 @@
fn assert_cursor(initial: (&str, &str), keys: &[KeyPress], expected_cursor: usize) {
let mut editor = init_editor(keys);
editor.readline_with_initial("", initial).unwrap();
- assert_eq!(expected_cursor, editor.term.cursor.get());
+ assert_eq!(expected_cursor, editor.term.cursor);
}
#[test]
diff --git a/src/tty/test.rs b/src/tty/test.rs
index 3d7933f..29a1e79 100644
--- a/src/tty/test.rs
+++ b/src/tty/test.rs
@@ -1,7 +1,5 @@
//! Tests specific definitions
-use std::cell::Cell;
use std::iter::IntoIterator;
-use std::rc::Rc;
use std::slice::Iter;
use std::vec::IntoIter;
@@ -50,24 +48,16 @@
}
}
-pub struct Sink {
- cursor: Rc<Cell<usize>>, // cursor position before last command
- last: usize,
-}
+pub struct Sink {}
impl Sink {
pub fn new() -> Sink {
- Sink {
- cursor: Rc::new(Cell::new(0)),
- last: 0,
- }
+ Sink {}
}
}
impl Renderer for Sink {
- fn move_cursor(&mut self, _: Position, new: Position) -> Result<()> {
- self.cursor.replace(self.last);
- self.last = new.col;
+ fn move_cursor(&mut self, _: Position, _: Position) -> Result<()> {
Ok(())
}
@@ -81,7 +71,6 @@
_: usize,
) -> Result<(Position, Position)> {
let cursor = self.calculate_position(&line[..line.pos()], prompt_size);
- self.last = cursor.col;
if let Some(hint) = hint {
truncate(&hint, 0, 80);
}
@@ -124,7 +113,7 @@
#[derive(Clone, Debug)]
pub struct DummyTerminal {
pub keys: Vec<KeyPress>,
- pub cursor: Rc<Cell<usize>>, // cursor position before last command
+ pub cursor: usize, // cursor position before last command
}
impl Term for DummyTerminal {
@@ -135,7 +124,7 @@
fn new() -> DummyTerminal {
DummyTerminal {
keys: Vec::new(),
- cursor: Rc::new(Cell::new(0)),
+ cursor: 0,
}
}
@@ -160,10 +149,7 @@
}
fn create_writer(&self) -> Sink {
- Sink {
- cursor: self.cursor.clone(),
- last: 0,
- }
+ Sink {}
}
}