mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-22 01:16:18 +04:00
add test for ensuring the initial cursor on a newly opened file
This commit is contained in:
parent
267605d147
commit
36e5809f63
42
Cargo.lock
generated
42
Cargo.lock
generated
@ -221,6 +221,15 @@ dependencies = [
|
|||||||
"thiserror",
|
"thiserror",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fastrand"
|
||||||
|
version = "1.7.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c3fcf0cee53519c866c09b5de1f6c56ff9d647101f81c1964fa632e148896cdf"
|
||||||
|
dependencies = [
|
||||||
|
"instant",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fern"
|
name = "fern"
|
||||||
version = "0.6.1"
|
version = "0.6.1"
|
||||||
@ -462,6 +471,7 @@ dependencies = [
|
|||||||
"signal-hook",
|
"signal-hook",
|
||||||
"signal-hook-tokio",
|
"signal-hook-tokio",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
|
"tempfile",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tokio-stream",
|
"tokio-stream",
|
||||||
"toml",
|
"toml",
|
||||||
@ -555,6 +565,15 @@ dependencies = [
|
|||||||
"unindent",
|
"unindent",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "instant"
|
||||||
|
version = "0.1.12"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "itoa"
|
name = "itoa"
|
||||||
version = "1.0.1"
|
version = "1.0.1"
|
||||||
@ -852,6 +871,15 @@ version = "0.6.25"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
|
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]]
|
[[package]]
|
||||||
name = "retain_mut"
|
name = "retain_mut"
|
||||||
version = "0.1.7"
|
version = "0.1.7"
|
||||||
@ -1056,6 +1084,20 @@ dependencies = [
|
|||||||
"unicode-xid",
|
"unicode-xid",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[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]]
|
[[package]]
|
||||||
name = "textwrap"
|
name = "textwrap"
|
||||||
version = "0.15.0"
|
version = "0.15.0"
|
||||||
|
@ -78,3 +78,4 @@ helix-loader = { version = "0.6", path = "../helix-loader" }
|
|||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
smallvec = "1.8"
|
smallvec = "1.8"
|
||||||
indoc = "1.0.3"
|
indoc = "1.0.3"
|
||||||
|
tempfile = "3.3.0"
|
||||||
|
@ -25,4 +25,5 @@ async fn hello_world() -> anyhow::Result<()> {
|
|||||||
mod auto_indent;
|
mod auto_indent;
|
||||||
mod auto_pairs;
|
mod auto_pairs;
|
||||||
mod movement;
|
mod movement;
|
||||||
|
mod write;
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use std::io::Write;
|
||||||
|
|
||||||
use crossterm::event::{Event, KeyEvent};
|
use crossterm::event::{Event, KeyEvent};
|
||||||
use helix_core::{test, Selection, Transaction};
|
use helix_core::{test, Selection, Transaction};
|
||||||
use helix_term::{application::Application, args::Args, config::Config};
|
use helix_term::{application::Application, args::Args, config::Config};
|
||||||
@ -85,3 +87,14 @@ pub fn test_key_sequence_text_result<T: Into<TestCase>>(
|
|||||||
|
|
||||||
Ok(())
|
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
|
||||||
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use helix_term::application::Application;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
@ -94,3 +96,31 @@ async fn insert_to_normal_mode_cursor_position() -> anyhow::Result<()> {
|
|||||||
|
|
||||||
Ok(())
|
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(())
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user