aboutsummaryrefslogtreecommitdiff
path: root/helix-term
diff options
context:
space:
mode:
authorSkyler Hawthorne2022-04-18 01:04:59 +0000
committerSkyler Hawthorne2022-06-19 03:54:03 +0000
commit36e5809f638028644d8a51e1ed2467ea402de170 (patch)
treef142ae9aea7efd94e9e3f62edb9f7aca27478e0a /helix-term
parent267605d147587e120d765fa62333dd986a3cb5e6 (diff)
add test for ensuring the initial cursor on a newly opened file
Diffstat (limited to 'helix-term')
-rw-r--r--helix-term/Cargo.toml1
-rw-r--r--helix-term/tests/integration.rs1
-rw-r--r--helix-term/tests/integration/helpers.rs13
-rw-r--r--helix-term/tests/integration/movement.rs30
4 files changed, 45 insertions, 0 deletions
diff --git a/helix-term/Cargo.toml b/helix-term/Cargo.toml
index 05f8eed4..f1903f04 100644
--- a/helix-term/Cargo.toml
+++ b/helix-term/Cargo.toml
@@ -78,3 +78,4 @@ helix-loader = { version = "0.6", path = "../helix-loader" }
[dev-dependencies]
smallvec = "1.8"
indoc = "1.0.3"
+tempfile = "3.3.0"
diff --git a/helix-term/tests/integration.rs b/helix-term/tests/integration.rs
index a388cf6b..4b0a2346 100644
--- a/helix-term/tests/integration.rs
+++ b/helix-term/tests/integration.rs
@@ -25,4 +25,5 @@ mod integration {
mod auto_indent;
mod auto_pairs;
mod movement;
+ mod write;
}
diff --git a/helix-term/tests/integration/helpers.rs b/helix-term/tests/integration/helpers.rs
index d22bcc3c..5a853ad1 100644
--- a/helix-term/tests/integration/helpers.rs
+++ b/helix-term/tests/integration/helpers.rs
@@ -1,3 +1,5 @@
+use std::io::Write;
+
use crossterm::event::{Event, KeyEvent};
use helix_core::{test, Selection, Transaction};
use helix_term::{application::Application, args::Args, config::Config};
@@ -85,3 +87,14 @@ pub fn test_key_sequence_text_result<T: Into<TestCase>>(
Ok(())
}
+
+pub fn temp_file_with_contents<S: AsRef<str>>(content: S) -> tempfile::NamedTempFile {
+ let mut temp_file = tempfile::NamedTempFile::new().unwrap();
+ temp_file
+ .as_file_mut()
+ .write_all(content.as_ref().as_bytes())
+ .unwrap();
+ temp_file.flush().unwrap();
+ temp_file.as_file_mut().sync_all().unwrap();
+ temp_file
+}
diff --git a/helix-term/tests/integration/movement.rs b/helix-term/tests/integration/movement.rs
index d2e01e71..fc2583c1 100644
--- a/helix-term/tests/integration/movement.rs
+++ b/helix-term/tests/integration/movement.rs
@@ -1,3 +1,5 @@
+use helix_term::application::Application;
+
use super::*;
#[tokio::test]
@@ -94,3 +96,31 @@ async fn insert_to_normal_mode_cursor_position() -> anyhow::Result<()> {
Ok(())
}
+
+/// Ensure the very initial cursor in an opened file is the width of
+/// the first grapheme
+#[tokio::test]
+async fn cursor_position_newly_opened_file() -> anyhow::Result<()> {
+ let test = |content: &str, expected_sel: Selection| {
+ let file = helpers::temp_file_with_contents(content);
+
+ let mut app = Application::new(
+ Args {
+ files: vec![(file.path().to_path_buf(), Position::default())],
+ ..Default::default()
+ },
+ Config::default(),
+ )
+ .unwrap();
+
+ let (view, doc) = helix_view::current!(app.editor);
+ let sel = doc.selection(view.id).clone();
+ assert_eq!(expected_sel, sel);
+ };
+
+ test("foo", Selection::single(0, 1));
+ test("๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ foo", Selection::single(0, 7));
+ test("", Selection::single(0, 0));
+
+ Ok(())
+}