mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 21:33:09 +00:00
Consistency-fix for word motions (#7354)
* change word motion test to include start cursor in specification * add test case for bug * fix bug
This commit is contained in:
parent
adb1f993a7
commit
ab2cb03189
2 changed files with 19 additions and 12 deletions
|
@ -2479,12 +2479,13 @@ static void test_1_word_motion(word_motion_t motion, move_word_style_t style,
|
|||
|
||||
size_t idx, end;
|
||||
if (motion == word_motion_left) {
|
||||
idx = command.size();
|
||||
idx = *std::max_element(stops.begin(), stops.end());
|
||||
end = 0;
|
||||
} else {
|
||||
idx = 0;
|
||||
idx = *std::min_element(stops.begin(), stops.end());
|
||||
end = command.size();
|
||||
}
|
||||
stops.erase(idx);
|
||||
|
||||
move_word_state_machine_t sm(style);
|
||||
while (idx != end) {
|
||||
|
@ -2521,22 +2522,25 @@ static void test_1_word_motion(word_motion_t motion, move_word_style_t style,
|
|||
/// Test word motion (forward-word, etc.). Carets represent cursor stops.
|
||||
static void test_word_motion() {
|
||||
say(L"Testing word motion");
|
||||
test_1_word_motion(word_motion_left, move_word_style_punctuation, L"^echo ^hello_^world.^txt");
|
||||
test_1_word_motion(word_motion_right, move_word_style_punctuation, L"echo^ hello^_world^.txt^");
|
||||
test_1_word_motion(word_motion_left, move_word_style_punctuation, L"^echo ^hello_^world.^txt^");
|
||||
test_1_word_motion(word_motion_right, move_word_style_punctuation, L"^echo^ hello^_world^.txt^");
|
||||
|
||||
test_1_word_motion(word_motion_left, move_word_style_punctuation,
|
||||
L"echo ^foo_^foo_^foo/^/^/^/^/^ ");
|
||||
L"echo ^foo_^foo_^foo/^/^/^/^/^ ^");
|
||||
test_1_word_motion(word_motion_right, move_word_style_punctuation,
|
||||
L"echo^ foo^_foo^_foo^/^/^/^/^/ ^");
|
||||
L"^echo^ foo^_foo^_foo^/^/^/^/^/ ^");
|
||||
|
||||
test_1_word_motion(word_motion_left, move_word_style_path_components, L"^/^foo/^bar/^baz/");
|
||||
test_1_word_motion(word_motion_left, move_word_style_path_components, L"^echo ^--foo ^--bar");
|
||||
test_1_word_motion(word_motion_left, move_word_style_path_components, L"^/^foo/^bar/^baz/^");
|
||||
test_1_word_motion(word_motion_left, move_word_style_path_components, L"^echo ^--foo ^--bar^");
|
||||
test_1_word_motion(word_motion_left, move_word_style_path_components,
|
||||
L"^echo ^hi ^> /^dev/^null");
|
||||
L"^echo ^hi ^> /^dev/^null^");
|
||||
|
||||
test_1_word_motion(word_motion_left, move_word_style_path_components,
|
||||
L"^echo /^foo/^bar{^aaa,^bbb,^ccc}^bak/");
|
||||
test_1_word_motion(word_motion_right, move_word_style_punctuation, L"a ^bcd^");
|
||||
L"^echo /^foo/^bar{^aaa,^bbb,^ccc}^bak/^");
|
||||
|
||||
test_1_word_motion(word_motion_right, move_word_style_punctuation, L"^a^ bcd^");
|
||||
test_1_word_motion(word_motion_right, move_word_style_punctuation, L"a^b^ cde^");
|
||||
test_1_word_motion(word_motion_right, move_word_style_punctuation, L"^ab^ cde^");
|
||||
}
|
||||
|
||||
/// Test is_potential_path.
|
||||
|
|
|
@ -687,8 +687,11 @@ bool move_word_state_machine_t::consume_char_punctuation(wchar_t c) {
|
|||
consumed = true;
|
||||
if (iswspace(c)) {
|
||||
state = s_whitespace;
|
||||
} else if (iswalnum(c)) {
|
||||
state = s_alphanumeric;
|
||||
} else {
|
||||
// Don't allow switching type (ws->nonws) after non-whitespace.
|
||||
// Don't allow switching type (ws->nonws) after non-whitespace and
|
||||
// non-alphanumeric.
|
||||
state = s_rest;
|
||||
}
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue