on master help sign in
add test for ensuring the initial cursor on a newly opened file
36e5809Skyler Hawthorne
Cargo.lock+42
@@ -221,6 +221,15 @@ dependencies = [
221 "thiserror",
221 "thiserror",
222]
222]
223
223
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+
224[[package]]
233[[package]]
225name = "fern"
234name = "fern"
226version = "0.6.1"
235version = "0.6.1"
@@ -462,6 +471,7 @@ dependencies = [
462 "signal-hook",
471 "signal-hook",
463 "signal-hook-tokio",
472 "signal-hook-tokio",
464 "smallvec",
473 "smallvec",
474+ "tempfile",
465 "tokio",
475 "tokio",
466 "tokio-stream",
476 "tokio-stream",
467 "toml",
477 "toml",
@@ -555,6 +565,15 @@ dependencies = [
555 "unindent",
565 "unindent",
556]
566]
557
567
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+
558[[package]]
577[[package]]
559name = "itoa"
578name = "itoa"
560version = "1.0.1"
579version = "1.0.1"
@@ -852,6 +871,15 @@ version = "0.6.25"
852source = "registry+https://github.com/rust-lang/crates.io-index"
871source = "registry+https://github.com/rust-lang/crates.io-index"
853checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
872checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
854
873
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+
855[[package]]
883[[package]]
856name = "retain_mut"
884name = "retain_mut"
857version = "0.1.7"
885version = "0.1.7"
@@ -1056,6 +1084,20 @@ dependencies = [
1056 "unicode-xid",
1084 "unicode-xid",
1057]
1085]
1058
1086
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+
1059[[package]]
1101[[package]]
1060name = "textwrap"
1102name = "textwrap"
1061version = "0.15.0"
1103version = "0.15.0"
helix-term/Cargo.toml+1
@@ -78,3 +78,4 @@ helix-loader = { version = "0.6", path = "../helix-loader" }
78[dev-dependencies]
78[dev-dependencies]
79smallvec = "1.8"
79smallvec = "1.8"
80indoc = "1.0.3"
80indoc = "1.0.3"
81+tempfile = "3.3.0"
helix-term/tests/integration.rs+1
@@ -25,4 +25,5 @@ mod integration {
25 mod auto_indent;
25 mod auto_indent;
26 mod auto_pairs;
26 mod auto_pairs;
27 mod movement;
27 mod movement;
28+ mod write;
28}
29}
helix-term/tests/integration/helpers.rs+13
@@ -1,3 +1,5 @@
1+use std::io::Write;
2+
1use crossterm::event::{Event, KeyEvent};
3use crossterm::event::{Event, KeyEvent};
2use helix_core::{test, Selection, Transaction};
4use helix_core::{test, Selection, Transaction};
3use helix_term::{application::Application, args::Args, config::Config};
5use helix_term::{application::Application, args::Args, config::Config};
@@ -85,3 +87,14 @@ pub fn test_key_sequence_text_result<T: Into<TestCase>>(
85
87
86 Ok(())
88 Ok(())
87}
89}
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+
1use super::*;
3use super::*;
2
4
3#[tokio::test]
5#[tokio::test]
@@ -94,3 +96,31 @@ async fn insert_to_normal_mode_cursor_position() -> anyhow::Result<()> {
94
96
95 Ok(())
97 Ok(())
96}
98}
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+}