diff options
-rw-r--r-- | Cargo.lock | 42 | ||||
-rw-r--r-- | helix-term/Cargo.toml | 1 | ||||
-rw-r--r-- | helix-term/tests/integration.rs | 1 | ||||
-rw-r--r-- | helix-term/tests/integration/helpers.rs | 13 | ||||
-rw-r--r-- | helix-term/tests/integration/movement.rs | 30 |
5 files changed, 87 insertions, 0 deletions
@@ -222,6 +222,15 @@ dependencies = [ ] [[package]] +name = "fastrand" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3fcf0cee53519c866c09b5de1f6c56ff9d647101f81c1964fa632e148896cdf" +dependencies = [ + "instant", +] + +[[package]] name = "fern" version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -462,6 +471,7 @@ dependencies = [ "signal-hook", "signal-hook-tokio", "smallvec", + "tempfile", "tokio", "tokio-stream", "toml", @@ -556,6 +566,15 @@ dependencies = [ ] [[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if", +] + +[[package]] name = "itoa" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -853,6 +872,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" [[package]] +name = "remove_dir_all" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" +dependencies = [ + "winapi", +] + +[[package]] name = "retain_mut" version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1057,6 +1085,20 @@ dependencies = [ ] [[package]] +name = "tempfile" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" +dependencies = [ + "cfg-if", + "fastrand", + "libc", + "redox_syscall", + "remove_dir_all", + "winapi", +] + +[[package]] name = "textwrap" version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" 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(()) +} |