-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix console issues with deleting characters (#471)
- Loading branch information
Showing
4 changed files
with
145 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Runtime.CompilerServices; | ||
|
||
[assembly: InternalsVisibleTo("Microsoft.Repl.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")] | ||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "This is done commonly throughout the codebase to catch unexpected errors.")] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
using Microsoft.HttpRepl.Fakes; | ||
using Microsoft.Repl.Input; | ||
using Xunit; | ||
|
||
namespace Microsoft.Repl.Tests | ||
{ | ||
public class InputManagerTests | ||
{ | ||
[Fact] | ||
public void RemovePreviousCharacter_AtBeginning_DoesNothing() | ||
{ | ||
// Arrange | ||
string initialInput = "echo on"; | ||
int initialPosition = 0; | ||
InputManager inputManager = new(initialInput, initialPosition); | ||
MockedShellState mockedShellState = new(inputManager); | ||
|
||
// Act | ||
inputManager.RemovePreviousCharacter(mockedShellState); | ||
|
||
// Assert | ||
Assert.Equal(initialPosition, inputManager.CaretPosition); | ||
Assert.Equal(initialInput, inputManager.GetCurrentBuffer()); | ||
} | ||
|
||
[Fact] | ||
public void RemovePreviousCharacter_AtEnd_RemovesLastCharacter() | ||
{ | ||
// Arrange | ||
string initialInput = "echo on"; | ||
int initialPosition = 7; | ||
string expectedInput = "echo o"; | ||
int expectedPosition = 6; | ||
InputManager inputManager = new(initialInput, initialPosition); | ||
MockedShellState mockedShellState = new(inputManager); | ||
|
||
// Act | ||
inputManager.RemovePreviousCharacter(mockedShellState); | ||
|
||
// Assert | ||
Assert.Equal(expectedPosition, inputManager.CaretPosition); | ||
Assert.Equal(expectedInput, inputManager.GetCurrentBuffer()); | ||
} | ||
|
||
[Fact] | ||
public void RemovePreviousCharacter_InMiddle_RemovesProperCharacter() | ||
{ | ||
// Arrange | ||
string initialInput = "echo on"; | ||
int initialPosition = 4; | ||
string expectedInput = "ech on"; | ||
int expectedPosition = 3; | ||
InputManager inputManager = new(initialInput, initialPosition); | ||
MockedShellState mockedShellState = new(inputManager); | ||
|
||
// Act | ||
inputManager.RemovePreviousCharacter(mockedShellState); | ||
|
||
// Assert | ||
Assert.Equal(expectedPosition, inputManager.CaretPosition); | ||
Assert.Equal(expectedInput, inputManager.GetCurrentBuffer()); | ||
} | ||
|
||
[Fact] | ||
public void RemoveCurrentCharacter_AtEnd_DoesNothing() | ||
{ | ||
// Arrange | ||
string initialInput = "echo on"; | ||
int initialPosition = 7; | ||
InputManager inputManager = new(initialInput, initialPosition); | ||
MockedShellState mockedShellState = new(inputManager); | ||
|
||
// Act | ||
inputManager.RemoveCurrentCharacter(mockedShellState); | ||
|
||
// Assert | ||
Assert.Equal(initialPosition, inputManager.CaretPosition); | ||
Assert.Equal(initialInput, inputManager.GetCurrentBuffer()); | ||
} | ||
|
||
[Fact] | ||
public void RemoveCurrentCharacter_AtBeginning_RemovesFirstCharacter() | ||
{ | ||
// Arrange | ||
string initialInput = "echo on"; | ||
int initialPosition = 0; | ||
string expectedInput = "cho on"; | ||
int expectedPosition = 0; | ||
InputManager inputManager = new(initialInput, initialPosition); | ||
MockedShellState mockedShellState = new(inputManager); | ||
|
||
// Act | ||
inputManager.RemoveCurrentCharacter(mockedShellState); | ||
|
||
// Assert | ||
Assert.Equal(expectedPosition, inputManager.CaretPosition); | ||
Assert.Equal(expectedInput, inputManager.GetCurrentBuffer()); | ||
} | ||
|
||
[Fact] | ||
public void RemoveCurrentCharacter_InMiddle_RemovesProperCharacter() | ||
{ | ||
// Arrange | ||
string initialInput = "echo on"; | ||
int initialPosition = 4; | ||
string expectedInput = "echoon"; | ||
int expectedPosition = 4; | ||
InputManager inputManager = new(initialInput, initialPosition); | ||
MockedShellState mockedShellState = new(inputManager); | ||
|
||
// Act | ||
inputManager.RemoveCurrentCharacter(mockedShellState); | ||
|
||
// Assert | ||
Assert.Equal(expectedPosition, inputManager.CaretPosition); | ||
Assert.Equal(expectedInput, inputManager.GetCurrentBuffer()); | ||
} | ||
} | ||
} |