mirror of
https://github.com/ilyakooo0/helix.git
synced 2024-09-12 00:07:42 +03: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",
|
||||
]
|
||||
|
||||
[[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"
|
||||
@ -462,6 +471,7 @@ dependencies = [
|
||||
"signal-hook",
|
||||
"signal-hook-tokio",
|
||||
"smallvec",
|
||||
"tempfile",
|
||||
"tokio",
|
||||
"tokio-stream",
|
||||
"toml",
|
||||
@ -555,6 +565,15 @@ dependencies = [
|
||||
"unindent",
|
||||
]
|
||||
|
||||
[[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"
|
||||
@ -852,6 +871,15 @@ version = "0.6.25"
|
||||
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"
|
||||
@ -1056,6 +1084,20 @@ dependencies = [
|
||||
"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]]
|
||||
name = "textwrap"
|
||||
version = "0.15.0"
|
||||
|
@ -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"
|
||||
|
@ -25,4 +25,5 @@ async fn hello_world() -> anyhow::Result<()> {
|
||||
mod auto_indent;
|
||||
mod auto_pairs;
|
||||
mod movement;
|
||||
mod write;
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user