Skip to content

Commit

Permalink
tests!
Browse files Browse the repository at this point in the history
  • Loading branch information
dariooddenino committed Oct 24, 2022
1 parent 5a06a72 commit 14ff34c
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions helix-term/tests/test/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::{

use helix_core::diagnostic::Severity;
use helix_term::application::Application;
use std::ffi::OsStr;

use super::*;

Expand Down Expand Up @@ -131,3 +132,65 @@ async fn test_selection_duplication() -> anyhow::Result<()> {
.await?;
Ok(())
}

#[tokio::test]
async fn test_goto_file_impl() -> anyhow::Result<()> {
let file = helpers::new_readonly_tempfile()?;

fn match_paths(app: &Application, matches: Vec<&str>) -> usize {
app.editor.documents()
.map(|d| d.path())
.flatten()
.map(|p| p.file_name())
.flatten()
.filter(|n| matches.iter().any(|m| &OsStr::new(m) == n))
.count()
}

// Single selection
test_key_sequence(
&mut helpers::app_with_file(file.path())?,
Some("ione.js<esc>%gf"),
Some(&|app| {
assert_eq!(1, match_paths(app, ["one.js"].to_vec()));
}),
false,
)
.await?;

// Multiple selection
test_key_sequence(
&mut helpers::app_with_file(file.path())?,
Some("ione.js<ret>two.js<esc>%<A-s>gf"),
Some(&|app| {
assert_eq!(2, match_paths(app, ["one.js", "two.js"].to_vec()));
}),
false,
)
.await?;

// Cursor on first quote
test_key_sequence(
&mut helpers::app_with_file(file.path())?,
Some("iimport 'one.js'<esc>B;gf"),
Some(&|app| {
assert_eq!(1, match_paths(app, ["one.js"].to_vec()));
}),
false,
)
.await?;

// Cursor on last quote
test_key_sequence(
&mut helpers::app_with_file(file.path())?,
Some("iimport 'one.js'<esc>bgf"),
Some(&|app| {
assert_eq!(1, match_paths(app, ["one.js"].to_vec()));
}),
false,
)
.await?;


Ok(())
}

0 comments on commit 14ff34c

Please sign in to comment.