Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 16 additions & 31 deletions test/BasicEditingTest.VI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -494,16 +494,14 @@ public void ViDeletePreviousLines()
{
TestSetup(KeyMode.Vi);

int continuationPrefixLength = PSConsoleReadLineOptions.DefaultContinuationPrompt.Length;

Test("\"\n\"", Keys(
 _.DQuote, _.Enter,
"one", _.Enter,
"two", _.Enter,
"three", _.Enter,
_.DQuote, _.Escape,
"kl", // go to the 'hree' portion of "three"
"2dk", CheckThat(() => AssertCursorLeftIs(continuationPrefixLength + 0))
"2dk", CheckThat(() => AssertCursorLeftIs(ContinuationPromptLength + 0))
));
}

Expand All @@ -512,16 +510,14 @@ public void ViDeletePreviousLines_LastLine()
{
TestSetup(KeyMode.Vi);

int continuationPrefixLength = PSConsoleReadLineOptions.DefaultContinuationPrompt.Length;

Test("\"\none\ntwo\n\"", Keys(
 _.DQuote, _.Enter,
"one", _.Enter,
"two", _.Enter,
"three", _.Enter,
_.DQuote, _.Escape,
"dk",
CheckThat(() => AssertCursorLeftIs(continuationPrefixLength + 0)),
CheckThat(() => AssertCursorLeftIs(ContinuationPromptLength + 0)),
CheckThat(() => AssertCursorTopIs(2)),
CheckThat(() => AssertLineIs("\"\none\ntwo")),
// finish the buffer to close the multiline string
Expand Down Expand Up @@ -571,8 +567,6 @@ public void ViDeleteToEnd()
{
TestSetup(KeyMode.Vi);

int continuationPrefixLength = PSConsoleReadLineOptions.DefaultContinuationPrompt.Length;

Test("\"\no\nthree\n\"", Keys(
_.DQuote, _.Enter,
"one", _.Enter,
Expand All @@ -582,7 +576,7 @@ public void ViDeleteToEnd()
"kkkl", // go to the 'ne' portion of "one"
// delete to the end of the next line
"2d$",
CheckThat(() => AssertCursorLeftIs(continuationPrefixLength + 0))
CheckThat(() => AssertCursorLeftIs(ContinuationPromptLength + 0))
));
}

Expand All @@ -591,18 +585,16 @@ public void ViBackwardDeleteLine()
{
TestSetup(KeyMode.Vi);

int continuationPrefixLength = PSConsoleReadLineOptions.DefaultContinuationPrompt.Length;

Test("\"\nsome words\n\"", Keys(

_.DQuote, _.Enter,
" this is a line with some words", _.Enter,
_.DQuote, _.Escape,
"k6W",
CheckThat(() => AssertCursorLeftIs(continuationPrefixLength + 23)),
CheckThat(() => AssertCursorLeftIs(ContinuationPromptLength + 23)),
// delete from first non blank of line
"d0",
CheckThat(() => AssertCursorLeftIs(continuationPrefixLength))
CheckThat(() => AssertCursorLeftIs(ContinuationPromptLength))
));
}

Expand All @@ -611,17 +603,15 @@ public void ViDeleteLineToFirstChar()
{
TestSetup(KeyMode.Vi);

int continuationPrefixLength = PSConsoleReadLineOptions.DefaultContinuationPrompt.Length;

Test("\"\n some spaces\n\"", Keys(
_.DQuote, _.Enter,
" this is a line with some spaces", _.Enter,
_.DQuote, _.Escape,
"k6W",
CheckThat(() => AssertCursorLeftIs(continuationPrefixLength + 23)),
CheckThat(() => AssertCursorLeftIs(ContinuationPromptLength + 23)),
// delete from first non blank of line
"d^",
CheckThat(() => AssertCursorLeftIs(continuationPrefixLength + 3))
CheckThat(() => AssertCursorLeftIs(ContinuationPromptLength + 3))
));
}

Expand All @@ -630,16 +620,14 @@ public void ViDeleteNextLines()
{
TestSetup(KeyMode.Vi);

int continuationPrefixLength = PSConsoleReadLineOptions.DefaultContinuationPrompt.Length;

Test("\"\n\"", Keys(
 _.DQuote, _.Enter,
"one", _.Enter,
"two", _.Enter,
"three", _.Enter,
_.DQuote, _.Escape,
"kkkl", // go to the 'ne' portion of "one"
"2dj", CheckThat(() => AssertCursorLeftIs(continuationPrefixLength + 0))
"2dj", CheckThat(() => AssertCursorLeftIs(ContinuationPromptLength + 0))
));
}

Expand All @@ -648,8 +636,6 @@ public void ViDeleteRelativeLines()
{
TestSetup(KeyMode.Vi);

var continuationPrefixLength = PSConsoleReadLineOptions.DefaultContinuationPrompt.Length;

Test("\"\nthree\n\"", Keys(
_.DQuote, _.Enter,
"one", _.Enter,
Expand All @@ -659,7 +645,7 @@ public void ViDeleteRelativeLines()
"kkl", // go to the 'wo' portion of "two"
// delete from line 2 to the current line (3)
"2dgg",
CheckThat(() => AssertCursorLeftIs(continuationPrefixLength + 0))
CheckThat(() => AssertCursorLeftIs(ContinuationPromptLength + 0))
));

Test("\"\none\nthree\n\"", Keys(
Expand All @@ -671,7 +657,7 @@ public void ViDeleteRelativeLines()
"kkl", // go to the 'wo' portion of "two"
// delete the current line (3)
"3dgg",
CheckThat(() => AssertCursorLeftIs(continuationPrefixLength + 0))
CheckThat(() => AssertCursorLeftIs(ContinuationPromptLength + 0))
));

Test("\"\none\n\"", Keys(
Expand All @@ -683,7 +669,7 @@ public void ViDeleteRelativeLines()
"kkl", // go to the 'wo' portion of "two"
// delete from the current line (3) to line 4
"4dgg",
CheckThat(() => AssertCursorLeftIs(continuationPrefixLength + 0))
CheckThat(() => AssertCursorLeftIs(ContinuationPromptLength + 0))
));
}

Expand Down Expand Up @@ -977,16 +963,15 @@ public void ViDefect651()
[SkippableFact]
public void ViInsertLine()
{
int adder = PSConsoleReadLineOptions.DefaultContinuationPrompt.Length;
TestSetup(KeyMode.Vi);

Test("line1\n", Keys(
_.Escape, "Oline1", CheckThat(() => AssertCursorLeftIs(5))
));

Test("\nline1", Keys(
_.Escape, "oline1", CheckThat(() => AssertCursorLeftIs(5 + adder)), CheckThat(() => AssertLineIs("\nline1")),
_.Escape, CheckThat(() => AssertCursorLeftIs(4 + adder))
_.Escape, "oline1", CheckThat(() => AssertCursorLeftIs(5 + ContinuationPromptLength)), CheckThat(() => AssertLineIs("\nline1")),
_.Escape, CheckThat(() => AssertCursorLeftIs(4 + ContinuationPromptLength))
));

Test("", Keys(
Expand All @@ -1010,10 +995,10 @@ public void ViInsertLine()
));

Test("", Keys(
_.Escape, "oline4", CheckThat(() => AssertLineIs("\nline4")), CheckThat(() => AssertCursorLeftIs(5 + adder)),
_.Escape, "Oline2", CheckThat(() => AssertLineIs("\nline2\nline4")), CheckThat(() => AssertCursorLeftIs(5 + adder)),
_.Escape, "oline4", CheckThat(() => AssertLineIs("\nline4")), CheckThat(() => AssertCursorLeftIs(5 + ContinuationPromptLength)),
_.Escape, "Oline2", CheckThat(() => AssertLineIs("\nline2\nline4")), CheckThat(() => AssertCursorLeftIs(5 + ContinuationPromptLength)),
_.Escape, "oline3", CheckThat(() => AssertLineIs("\nline2\nline3\nline4")),
_.Escape, CheckThat(() => AssertLineIs("\nline2\nline3\nline4")), CheckThat(() => AssertCursorLeftIs(4 + adder)),
_.Escape, CheckThat(() => AssertLineIs("\nline2\nline3\nline4")), CheckThat(() => AssertCursorLeftIs(4 + ContinuationPromptLength)),
'u', CheckThat(() => AssertLineIs("\nline2\nline4")),
'u', CheckThat(() => AssertLineIs("\nline4")),
'u'
Expand Down
38 changes: 17 additions & 21 deletions test/BasicEditingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,6 @@ public void InsertLineAbove()
{
TestSetup(KeyMode.Cmd);

var continutationPromptLength = PSConsoleReadLineOptions.DefaultContinuationPrompt.Length;

// Test case - start with single line, cursor at end
Test("56\n1234", Keys("1234", _.Ctrl_Enter, CheckThat(() => AssertCursorLeftTopIs(0, 0)), "56"));

Expand All @@ -356,13 +354,13 @@ public void InsertLineAbove()

// Test case - start with multi-line, cursor at end of second line (end of input)
Test("1234\n9ABC\n5678", Keys("1234", _.Shift_Enter, "5678",
_.Ctrl_Enter, CheckThat(() => AssertCursorLeftTopIs(continutationPromptLength, 1)),
_.Ctrl_Enter, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength, 1)),
"9ABC"));

// Test case - start with multi-line, cursor at beginning of second line
Test("1234\n9ABC\n5678", Keys("1234", _.Shift_Enter, "5678",
_.LeftArrow, _.Home, CheckThat(() => AssertCursorLeftTopIs(continutationPromptLength, 1)),
_.Ctrl_Enter, CheckThat(() => AssertCursorLeftTopIs(continutationPromptLength, 1)),
_.LeftArrow, _.Home, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength, 1)),
_.Ctrl_Enter, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength, 1)),
"9ABC"));

// Test case - start with multi-line, cursor at end of first line
Expand All @@ -380,67 +378,65 @@ public void InsertLineAbove()

// Test case - insert multiple blank lines
Test("1234\n9ABC\n\n5678", Keys("1234", _.Shift_Enter, "5678",
_.Ctrl_Enter, CheckThat(() => AssertCursorLeftTopIs(continutationPromptLength, 1)),
_.Ctrl_Enter, CheckThat(() => AssertCursorLeftTopIs(continutationPromptLength, 1)),
_.Ctrl_Enter, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength, 1)),
_.Ctrl_Enter, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength, 1)),
"9ABC"));

// Test case - create leading blank line, cursor to stay on same line
Test("\n\n1234", Keys("1234",
_.Ctrl_Enter, CheckThat(() => AssertCursorLeftTopIs(0,0)),
_.DownArrow, CheckThat(() => AssertCursorLeftTopIs(continutationPromptLength, 1)),
_.Ctrl_Enter, CheckThat(() => AssertCursorLeftTopIs(continutationPromptLength, 1))));
_.DownArrow, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength, 1)),
_.Ctrl_Enter, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength, 1))));
}

[SkippableFact]
public void InsertLineBelow()
{
TestSetup(KeyMode.Cmd);

var continutationPromptLength = PSConsoleReadLineOptions.DefaultContinuationPrompt.Length;

// Test case - start with single line, cursor at end
Test("1234\n56", Keys("1234",
_.Ctrl_Shift_Enter, CheckThat(() => AssertCursorLeftTopIs(continutationPromptLength, 1)),
_.Ctrl_Shift_Enter, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength, 1)),
"56"));

// Test case - start with single line, cursor in home position
Test("1234\n56", Keys("1234",
_.Home, _.Ctrl_Shift_Enter, CheckThat(() => AssertCursorLeftTopIs(continutationPromptLength, 1)),
_.Home, _.Ctrl_Shift_Enter, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength, 1)),
"56"));

// Test case - start with single line, cursor in middle
Test("1234\n56", Keys("1234",
_.LeftArrow, _.LeftArrow, _.Ctrl_Shift_Enter, CheckThat(() => AssertCursorLeftTopIs(continutationPromptLength, 1)),
_.LeftArrow, _.LeftArrow, _.Ctrl_Shift_Enter, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength, 1)),
"56"));

// Test case - start with multi-line, cursor at end of second line (end of input)
Test("1234\n5678\n9ABC", Keys("1234", _.Shift_Enter, "5678",
_.Ctrl_Shift_Enter, CheckThat(() => AssertCursorLeftTopIs(continutationPromptLength, 2)),
_.Ctrl_Shift_Enter, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength, 2)),
"9ABC"));

// Test case - start with multi-line, cursor at beginning of second line
Test("1234\n5678\n9ABC", Keys("1234", _.Shift_Enter, "5678",
_.LeftArrow, _.Home, CheckThat(() => AssertCursorLeftTopIs(continutationPromptLength, 1)),
_.Ctrl_Shift_Enter, CheckThat(() => AssertCursorLeftTopIs(continutationPromptLength, 2)),
_.LeftArrow, _.Home, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength, 1)),
_.Ctrl_Shift_Enter, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength, 2)),
"9ABC"));

// Test case - start with multi-line, cursor at end of first line
Test("1234\n9ABC\n5678", Keys("1234", _.Shift_Enter, "5678",
_.UpArrow, _.LeftArrow, _.End, CheckThat(() => AssertCursorLeftTopIs(4, 0)),
_.Ctrl_Shift_Enter, CheckThat(() => AssertCursorLeftTopIs(continutationPromptLength, 1)),
_.Ctrl_Shift_Enter, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength, 1)),
"9ABC"));

// Test case - start with multi-line, cursor at beginning of first line - temporarily having to press Home twice to
// work around bug in home handler.
Test("1234\n9ABC\n5678", Keys("1234", _.Shift_Enter, "5678",
_.UpArrow, _.LeftArrow, _.Home, _.Home, CheckThat(() => AssertCursorLeftTopIs(0, 0)),
_.Ctrl_Shift_Enter, CheckThat(() => AssertCursorLeftTopIs(continutationPromptLength, 1)),
_.Ctrl_Shift_Enter, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength, 1)),
"9ABC"));

// Test case - insert multiple blank lines
Test("1234\n5678\n\n9ABC", Keys("1234", _.Shift_Enter, "5678",
_.Ctrl_Shift_Enter, CheckThat(() => AssertCursorLeftTopIs(continutationPromptLength, 2)),
_.Ctrl_Shift_Enter, CheckThat(() => AssertCursorLeftTopIs(continutationPromptLength, 3)),
_.Ctrl_Shift_Enter, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength, 2)),
_.Ctrl_Shift_Enter, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength, 3)),
"9ABC"));
}

Expand Down
Loading