on master help sign in
add test for ensuring the initial cursor on a newly opened file
commit36e5809f638028644d8a51e1ed2467ea402de170 authorSkyler Hawthorne <skyler@dead10ck.com> dateSun 17 Apr 2022, 21:04 (5 years ago) parent267605d
5 files changed+87
Cargo.lock+42 helix-term/Cargo.toml+1 helix-term/tests/integration.rs+1 helix-term/tests/integration/helpers.rs+13 helix-term/tests/integration/movement.rs+30
Cargo.lock+42
@@ -221,6 +221,15 @@ dependencies = [
221221 "thiserror",
222222]
223223
224+[[package]]
225+name = "fastrand"
226+version = "1.7.0"
227+source = "registry+https://github.com/rust-lang/crates.io-index"
228+checksum = "c3fcf0cee53519c866c09b5de1f6c56ff9d647101f81c1964fa632e148896cdf"
229+dependencies = [
230+ "instant",
231+]
232+
224233[[package]]
225234name = "fern"
226235version = "0.6.1"
@@ -462,6 +471,7 @@ dependencies = [
462471 "signal-hook",
463472 "signal-hook-tokio",
464473 "smallvec",
474+ "tempfile",
465475 "tokio",
466476 "tokio-stream",
467477 "toml",
@@ -555,6 +565,15 @@ dependencies = [
555565 "unindent",
556566]
557567
568+[[package]]
569+name = "instant"
570+version = "0.1.12"
571+source = "registry+https://github.com/rust-lang/crates.io-index"
572+checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
573+dependencies = [
574+ "cfg-if",
575+]
576+
558577[[package]]
559578name = "itoa"
560579version = "1.0.1"
@@ -852,6 +871,15 @@ version = "0.6.25"
852871source = "registry+https://github.com/rust-lang/crates.io-index"
853872checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
854873
874+[[package]]
875+name = "remove_dir_all"
876+version = "0.5.3"
877+source = "registry+https://github.com/rust-lang/crates.io-index"
878+checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7"
879+dependencies = [
880+ "winapi",
881+]
882+
855883[[package]]
856884name = "retain_mut"
857885version = "0.1.7"
@@ -1056,6 +1084,20 @@ dependencies = [
10561084 "unicode-xid",
10571085]
10581086
1087+[[package]]
1088+name = "tempfile"
1089+version = "3.3.0"
1090+source = "registry+https://github.com/rust-lang/crates.io-index"
1091+checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4"
1092+dependencies = [
1093+ "cfg-if",
1094+ "fastrand",
1095+ "libc",
1096+ "redox_syscall",
1097+ "remove_dir_all",
1098+ "winapi",
1099+]
1100+
10591101[[package]]
10601102name = "textwrap"
10611103version = "0.15.0"
helix-term/Cargo.toml+1
@@ -78,3 +78,4 @@ helix-loader = { version = "0.6", path = "../helix-loader" }
7878[dev-dependencies]
7979smallvec = "1.8"
8080indoc = "1.0.3"
81+tempfile = "3.3.0"
helix-term/tests/integration.rs+1
@@ -25,4 +25,5 @@ mod integration {
2525 mod auto_indent;
2626 mod auto_pairs;
2727 mod movement;
28+ mod write;
2829}
helix-term/tests/integration/helpers.rs+13
@@ -1,3 +1,5 @@
1+use std::io::Write;
2+
13use crossterm::event::{Event, KeyEvent};
24use helix_core::{test, Selection, Transaction};
35use helix_term::{application::Application, args::Args, config::Config};
@@ -85,3 +87,14 @@ pub fn test_key_sequence_text_result<T: Into<TestCase>>(
8587
8688 Ok(())
8789}
90+
91+pub fn temp_file_with_contents<S: AsRef<str>>(content: S) -> tempfile::NamedTempFile {
92+ let mut temp_file = tempfile::NamedTempFile::new().unwrap();
93+ temp_file
94+ .as_file_mut()
95+ .write_all(content.as_ref().as_bytes())
96+ .unwrap();
97+ temp_file.flush().unwrap();
98+ temp_file.as_file_mut().sync_all().unwrap();
99+ temp_file
100+}
helix-term/tests/integration/movement.rs+30
@@ -1,3 +1,5 @@
1+use helix_term::application::Application;
2+
13use super::*;
24
35#[tokio::test]
@@ -94,3 +96,31 @@ async fn insert_to_normal_mode_cursor_position() -> anyhow::Result<()> {
9496
9597 Ok(())
9698}
99+
100+/// Ensure the very initial cursor in an opened file is the width of
101+/// the first grapheme
102+#[tokio::test]
103+async fn cursor_position_newly_opened_file() -> anyhow::Result<()> {
104+ let test = |content: &str, expected_sel: Selection| {
105+ let file = helpers::temp_file_with_contents(content);
106+
107+ let mut app = Application::new(
108+ Args {
109+ files: vec![(file.path().to_path_buf(), Position::default())],
110+ ..Default::default()
111+ },
112+ Config::default(),
113+ )
114+ .unwrap();
115+
116+ let (view, doc) = helix_view::current!(app.editor);
117+ let sel = doc.selection(view.id).clone();
118+ assert_eq!(expected_sel, sel);
119+ };
120+
121+ test("foo", Selection::single(0, 1));
122+ test("๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ foo", Selection::single(0, 7));
123+ test("", Selection::single(0, 0));
124+
125+ Ok(())
126+}