@ -2,9 +2,9 @@
mod integration {
mod integration {
use std ::path ::PathBuf ;
use std ::path ::PathBuf ;
use helix_core ::{ syntax ::AutoPairConfig , Position , Selection , T endril, T ransaction} ;
use helix_core ::{ syntax ::AutoPairConfig , Position , Selection , T ransaction} ;
use helix_term ::{ application ::Application , args ::Args , config ::Config } ;
use helix_term ::{ application ::Application , args ::Args , config ::Config } ;
use helix_view ::{ current, doc, input ::parse_macro } ;
use helix_view ::{ doc, input ::parse_macro } ;
use crossterm ::event ::{ Event , KeyEvent } ;
use crossterm ::event ::{ Event , KeyEvent } ;
use indoc ::indoc ;
use indoc ::indoc ;
@ -25,14 +25,14 @@ mod integration {
let mut app =
let mut app =
app . unwrap_or_else ( | | Application ::new ( Args ::default ( ) , Config ::default ( ) ) . unwrap ( ) ) ;
app . unwrap_or_else ( | | Application ::new ( Args ::default ( ) , Config ::default ( ) ) . unwrap ( ) ) ;
let ( view , doc ) = current ! ( app . editor ) ;
let ( view , doc ) = helix_view ::current ! ( app . editor ) ;
let sel = doc . selection ( view . id ) . clone ( ) ;
// replace the initial text with the input text
doc . apply (
doc . apply (
& Transaction ::insert (
& Transaction ::change_by_selection ( & doc . text ( ) , & sel , | _ | {
doc . text ( ) ,
( 0 , doc . text ( ) . len_chars ( ) , Some ( ( & test_case . in_text ) . into ( ) ) )
& Selection ::single ( 1 , 0 ) ,
} )
Tendril ::from ( & test_case . in_text ) ,
)
. with_selection ( test_case . in_selection . clone ( ) ) ,
. with_selection ( test_case . in_selection . clone ( ) ) ,
view . id ,
view . id ,
) ;
) ;
@ -80,12 +80,12 @@ mod integration {
Args ::default ( ) ,
Args ::default ( ) ,
Config ::default ( ) ,
Config ::default ( ) ,
TestCase {
TestCase {
in_text : String ::new ( ) ,
in_text : "\n" . into ( ) ,
in_selection : Selection ::single ( 0 , 1 ) ,
in_selection : Selection ::single ( 0 , 1 ) ,
// TODO: fix incorrect selection on new doc
// TODO: fix incorrect selection on new doc
in_keys : String ::from ( "ihello world<esc> hl ") ,
in_keys : "ihello world<esc> ". into ( ) ,
out_text : String ::from ( "hello world\n" ) ,
out_text : "hello world\n" . into ( ) ,
out_selection : Selection ::single ( 1 1, 12 ) ,
out_selection : Selection ::single ( 1 2, 11 ) ,
} ,
} ,
) ? ;
) ? ;
@ -93,16 +93,74 @@ mod integration {
}
}
#[ tokio::test ]
#[ tokio::test ]
async fn auto_pairs_basic ( ) -> anyhow ::Result < ( ) > {
async fn insert_mode_cursor_position ( ) -> anyhow ::Result < ( ) > {
test_key_sequence_text_result (
test_key_sequence_text_result (
Args ::default ( ) ,
Args ::default ( ) ,
Config ::default ( ) ,
Config ::default ( ) ,
TestCase {
TestCase {
in_text : String ::new ( ) ,
in_text : String ::new ( ) ,
in_selection : Selection ::single ( 0 , 0 ) ,
in_keys : "i" . into ( ) ,
out_text : String ::new ( ) ,
out_selection : Selection ::single ( 0 , 0 ) ,
} ,
) ? ;
test_key_sequence_text_result (
Args ::default ( ) ,
Config ::default ( ) ,
TestCase {
in_text : "\n" . into ( ) ,
in_selection : Selection ::single ( 0 , 1 ) ,
in_keys : "i" . into ( ) ,
out_text : "\n" . into ( ) ,
out_selection : Selection ::single ( 1 , 0 ) ,
} ,
) ? ;
test_key_sequence_text_result (
Args ::default ( ) ,
Config ::default ( ) ,
TestCase {
in_text : "\n" . into ( ) ,
in_selection : Selection ::single ( 0 , 1 ) ,
in_selection : Selection ::single ( 0 , 1 ) ,
in_keys : String ::from ( "i(<esc>hl" ) ,
in_keys : "i<esc>i" . into ( ) ,
out_text : String ::from ( "()\n" ) ,
out_text : "\n" . into ( ) ,
out_selection : Selection ::single ( 1 , 2 ) ,
out_selection : Selection ::single ( 1 , 0 ) ,
} ,
) ? ;
Ok ( ( ) )
}
#[ tokio::test ]
async fn insert_to_normal_mode_cursor_position ( ) -> anyhow ::Result < ( ) > {
test_key_sequence_text_result (
Args ::default ( ) ,
Config ::default ( ) ,
TestCase {
in_text : "\n" . into ( ) ,
in_selection : Selection ::single ( 0 , 1 ) ,
in_keys : "i" . into ( ) ,
out_text : "\n" . into ( ) ,
out_selection : Selection ::single ( 1 , 0 ) ,
} ,
) ? ;
Ok ( ( ) )
}
#[ tokio::test ]
async fn auto_pairs_basic ( ) -> anyhow ::Result < ( ) > {
test_key_sequence_text_result (
Args ::default ( ) ,
Config ::default ( ) ,
TestCase {
in_text : "\n" . into ( ) ,
in_selection : Selection ::single ( 0 , 1 ) ,
in_keys : "i(<esc>" . into ( ) ,
out_text : "()\n" . into ( ) ,
out_selection : Selection ::single ( 2 , 1 ) ,
} ,
} ,
) ? ;
) ? ;
@ -116,11 +174,11 @@ mod integration {
.. Default ::default ( )
.. Default ::default ( )
} ,
} ,
TestCase {
TestCase {
in_text : String ::new ( ) ,
in_text : "\n" . into ( ) ,
in_selection : Selection ::single ( 0 , 1 ) ,
in_selection : Selection ::single ( 0 , 1 ) ,
in_keys : String ::from ( "i(<esc> hl ") ,
in_keys : "i(<esc> ". into ( ) ,
out_text : String ::from ( "(\n" ) ,
out_text : "(\n" . into ( ) ,
out_selection : Selection ::single ( 1, 2 ) ,
out_selection : Selection ::single ( 2, 1 ) ,
} ,
} ,
) ? ;
) ? ;
@ -136,15 +194,17 @@ mod integration {
} ,
} ,
Config ::default ( ) ,
Config ::default ( ) ,
TestCase {
TestCase {
in_text : String ::from ( "void foo() {} ") ,
in_text : "void foo() {} \n ". into ( ) ,
in_selection : Selection ::single ( 1 2, 13 ) ,
in_selection : Selection ::single ( 1 3, 12 ) ,
in_keys : String ::from ( "i<ret><esc>" ) ,
in_keys : "i<ret><esc>" . into ( ) ,
out_text : String ::from ( indoc! { r #"
out_text : indoc! { r #"
void foo ( ) {
void foo ( ) {
}
}
" #} ) ,
" #}
out_selection : Selection ::single ( 15 , 16 ) ,
. trim_start ( )
. into ( ) ,
out_selection : Selection ::single ( 16 , 15 ) ,
} ,
} ,
) ? ;
) ? ;