-
-
Notifications
You must be signed in to change notification settings - Fork 59
Refactor key-binding architecture: ConsoleKeyBinding struct, simplified handlers, ESC cancellation, fixed driver lifetime #331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
16603a1
Initial plan
Copilot f627446
Initial plan
Copilot 111653b
Refactor overall architecture: ConsoleKeyBinding, simplified handlers…
Copilot 2b00ec9
Resolve conflicts with master: integrate PromptConfiguration refactor…
Copilot 84ba081
Merge branch 'master' into copilot/refactor-overall-architecture
shibayan 850bbf9
Delete global.json
shibayan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,109 @@ | ||
| using System; | ||
|
|
||
| using Sharprompt.Internal; | ||
|
|
||
| using Xunit; | ||
|
|
||
| namespace Sharprompt.Tests; | ||
|
|
||
| public class ConsoleKeyBindingTests | ||
| { | ||
| [Fact] | ||
| public void Constructor_DefaultModifiers_IsNone() | ||
| { | ||
| var binding = new ConsoleKeyBinding(ConsoleKey.Enter); | ||
|
|
||
| Assert.Equal(ConsoleKey.Enter, binding.Key); | ||
| Assert.Equal(default(ConsoleModifiers), binding.Modifiers); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Constructor_WithModifiers_StoresModifiers() | ||
| { | ||
| var binding = new ConsoleKeyBinding(ConsoleKey.LeftArrow, ConsoleModifiers.Control); | ||
|
|
||
| Assert.Equal(ConsoleKey.LeftArrow, binding.Key); | ||
| Assert.Equal(ConsoleModifiers.Control, binding.Modifiers); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Equals_SameKeyAndModifiers_ReturnsTrue() | ||
| { | ||
| var a = new ConsoleKeyBinding(ConsoleKey.A, ConsoleModifiers.Control); | ||
| var b = new ConsoleKeyBinding(ConsoleKey.A, ConsoleModifiers.Control); | ||
|
|
||
| Assert.Equal(a, b); | ||
| Assert.True(a == b); | ||
| Assert.False(a != b); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Equals_DifferentKey_ReturnsFalse() | ||
| { | ||
| var a = new ConsoleKeyBinding(ConsoleKey.A); | ||
| var b = new ConsoleKeyBinding(ConsoleKey.B); | ||
|
|
||
| Assert.NotEqual(a, b); | ||
| Assert.False(a == b); | ||
| Assert.True(a != b); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Equals_SameKeyDifferentModifiers_ReturnsFalse() | ||
| { | ||
| var plain = new ConsoleKeyBinding(ConsoleKey.LeftArrow); | ||
| var ctrl = new ConsoleKeyBinding(ConsoleKey.LeftArrow, ConsoleModifiers.Control); | ||
|
|
||
| Assert.NotEqual(plain, ctrl); | ||
| Assert.False(plain == ctrl); | ||
| Assert.True(plain != ctrl); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void GetHashCode_SameKeyAndModifiers_SameHash() | ||
| { | ||
| var a = new ConsoleKeyBinding(ConsoleKey.Delete, ConsoleModifiers.Control); | ||
| var b = new ConsoleKeyBinding(ConsoleKey.Delete, ConsoleModifiers.Control); | ||
|
|
||
| Assert.Equal(a.GetHashCode(), b.GetHashCode()); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void GetHashCode_DifferentBindings_DifferentHash() | ||
| { | ||
| var a = new ConsoleKeyBinding(ConsoleKey.Delete); | ||
| var b = new ConsoleKeyBinding(ConsoleKey.Delete, ConsoleModifiers.Control); | ||
|
|
||
| Assert.NotEqual(a.GetHashCode(), b.GetHashCode()); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void CanBeUsedAsDictionaryKey() | ||
| { | ||
| var dict = new System.Collections.Generic.Dictionary<ConsoleKeyBinding, string> | ||
| { | ||
| [new ConsoleKeyBinding(ConsoleKey.LeftArrow)] = "plain left", | ||
| [new ConsoleKeyBinding(ConsoleKey.LeftArrow, ConsoleModifiers.Control)] = "ctrl left" | ||
| }; | ||
|
|
||
| Assert.Equal("plain left", dict[new ConsoleKeyBinding(ConsoleKey.LeftArrow)]); | ||
| Assert.Equal("ctrl left", dict[new ConsoleKeyBinding(ConsoleKey.LeftArrow, ConsoleModifiers.Control)]); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Equals_WithObject_ReturnsTrueForSameBinding() | ||
| { | ||
| var a = new ConsoleKeyBinding(ConsoleKey.Enter); | ||
| object b = new ConsoleKeyBinding(ConsoleKey.Enter); | ||
|
|
||
| Assert.True(a.Equals(b)); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Equals_WithDifferentType_ReturnsFalse() | ||
| { | ||
| var a = new ConsoleKeyBinding(ConsoleKey.Enter); | ||
|
|
||
| Assert.False(a.Equals("Enter")); | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.