Skip to content

Commit

Permalink
fix - exotic count-related bugs along with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
captaincaius committed Oct 11, 2018
1 parent e07f0b2 commit e742c57
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/cmd_line/subparsers/substitute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ function parseSubstituteFlags(scanner: Scanner): number {
flags = flags | node.SubstituteFlags.UsePreviousPattern;
break;
default:
return node.SubstituteFlags.None;
scanner.backup();
return flags;
}

index++;
Expand Down Expand Up @@ -139,7 +140,6 @@ export function parseSubstituteCommandArgs(args: string): node.SubstituteCommand
pattern: undefined,
replace: '', // ignored in this context
flags: node.SubstituteFlags.None,
count: 1,
});
}
let scanner: Scanner;
Expand All @@ -153,7 +153,6 @@ export function parseSubstituteCommandArgs(args: string): node.SubstituteCommand
pattern: '',
replace: '',
flags: node.SubstituteFlags.None,
count: 1,
});
}

Expand All @@ -168,7 +167,6 @@ export function parseSubstituteCommandArgs(args: string): node.SubstituteCommand
pattern: searchPattern,
replace: '',
flags: node.SubstituteFlags.None,
count: 1,
});
}
replaceString = parsePattern('', scanner, delimiter)[0];
Expand Down
21 changes: 21 additions & 0 deletions test/cmd_line/substitute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ suite('Basic substitute', () => {
assertEqualLines(['dbd']);
});

newTest({
title: 'Replace with flags AND count',
start: ['|blah blah', 'blah', 'blah blah', 'blah blah'],
keysPressed: ':.s/blah/yay/g 2\n',
end: ['|yay yay', 'yay', 'blah blah', 'blah blah'],
});

test('Replace with `c` flag', async () => {
const confirmStub = sinon.stub(SubstituteCommand.prototype, 'confirmReplacement').returns(true);
await modeHandler.handleMultipleKeyEvents(['i', 'a', 'b', 'a', '<Esc>']);
Expand Down Expand Up @@ -104,6 +111,20 @@ suite('Basic substitute', () => {
end: ['blah blah', '|yay', 'yay blah', 'yay blah'],
});

newTest({
title: 'Repeat replacement across relative line range',
start: ['|blah blah', 'blah', 'blah blah', 'blah blah'],
keysPressed: ':s/blah/yay\nj3:s\n',
end: ['yay blah', '|yay', 'yay blah', 'yay blah'],
});

newTest({
title: 'Replace with range AND count but no flags',
start: ['|blah blah', 'blah', 'blah blah', 'blah blah'],
keysPressed: '3:s/blah/yay/ 2\n',
end: ['|blah blah', 'blah', 'yay blah', 'yay blah'],
});

newTest({
title: 'Undocumented: operator without LHS assumes dot as LHS',
start: ['blah blah', 'bla|h', 'blah blah', 'blah blah'],
Expand Down

0 comments on commit e742c57

Please sign in to comment.