Skip to content

Commit 14ff34c

Browse files
committed
tests!
1 parent 5a06a72 commit 14ff34c

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

helix-term/tests/test/commands.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::{
55

66
use helix_core::diagnostic::Severity;
77
use helix_term::application::Application;
8+
use std::ffi::OsStr;
89

910
use super::*;
1011

@@ -131,3 +132,65 @@ async fn test_selection_duplication() -> anyhow::Result<()> {
131132
.await?;
132133
Ok(())
133134
}
135+
136+
#[tokio::test]
137+
async fn test_goto_file_impl() -> anyhow::Result<()> {
138+
let file = helpers::new_readonly_tempfile()?;
139+
140+
fn match_paths(app: &Application, matches: Vec<&str>) -> usize {
141+
app.editor.documents()
142+
.map(|d| d.path())
143+
.flatten()
144+
.map(|p| p.file_name())
145+
.flatten()
146+
.filter(|n| matches.iter().any(|m| &OsStr::new(m) == n))
147+
.count()
148+
}
149+
150+
// Single selection
151+
test_key_sequence(
152+
&mut helpers::app_with_file(file.path())?,
153+
Some("ione.js<esc>%gf"),
154+
Some(&|app| {
155+
assert_eq!(1, match_paths(app, ["one.js"].to_vec()));
156+
}),
157+
false,
158+
)
159+
.await?;
160+
161+
// Multiple selection
162+
test_key_sequence(
163+
&mut helpers::app_with_file(file.path())?,
164+
Some("ione.js<ret>two.js<esc>%<A-s>gf"),
165+
Some(&|app| {
166+
assert_eq!(2, match_paths(app, ["one.js", "two.js"].to_vec()));
167+
}),
168+
false,
169+
)
170+
.await?;
171+
172+
// Cursor on first quote
173+
test_key_sequence(
174+
&mut helpers::app_with_file(file.path())?,
175+
Some("iimport 'one.js'<esc>B;gf"),
176+
Some(&|app| {
177+
assert_eq!(1, match_paths(app, ["one.js"].to_vec()));
178+
}),
179+
false,
180+
)
181+
.await?;
182+
183+
// Cursor on last quote
184+
test_key_sequence(
185+
&mut helpers::app_with_file(file.path())?,
186+
Some("iimport 'one.js'<esc>bgf"),
187+
Some(&|app| {
188+
assert_eq!(1, match_paths(app, ["one.js"].to_vec()));
189+
}),
190+
false,
191+
)
192+
.await?;
193+
194+
195+
Ok(())
196+
}

0 commit comments

Comments
 (0)